Browse Source

enhance: types for lsp

Peng Xiao 4 years ago
parent
commit
8561acb57f
4 changed files with 13 additions and 8 deletions
  1. 1 0
      libs/package.json
  2. 5 7
      libs/src/LSPlugin.d.ts
  3. 2 1
      libs/src/LSPlugin.user.ts
  4. 5 0
      libs/yarn.lock

+ 1 - 0
libs/package.json

@@ -13,6 +13,7 @@
     "build": "tsc && rm dist/*.js && cp src/*.d.ts dist/ && npm run build:user"
   },
   "dependencies": {
+    "csstype": "^3.0.8",
     "debug": "^4.3.1",
     "dompurify": "^2.2.7",
     "eventemitter3": "^4.0.7",

+ 5 - 7
libs/src/LSPlugin.d.ts

@@ -1,4 +1,5 @@
 import EventEmitter from 'eventemitter3'
+import * as CSS from 'csstype';
 import { LSPluginCaller } from './LSPlugin.caller'
 import { LSPluginUser } from './LSPlugin.user'
 
@@ -13,11 +14,8 @@ type ThemeOptions = {
   [key: string]: any
 }
 
-type StyleString = string
-type StyleOptions = {
-  key?: string
-  style: StyleString
-}
+type StyleString = string;
+type StyleOptions = CSS.Properties;
 
 type UIBaseOptions = {
   key?: string
@@ -35,7 +33,7 @@ type UISlotIdentity = {
 
 type UISlotOptions = UIBaseOptions & UISlotIdentity
 type UIPathOptions = UIBaseOptions & UIPathIdentity
-type UIOptions = UIPathOptions & UISlotOptions
+type UIOptions = UIPathOptions | UISlotOptions
 
 interface LSPluginPkgConfig {
   id: PluginLocalIdentity
@@ -214,7 +212,7 @@ interface ILSPluginUser extends EventEmitter<LSPluginUserEvents> {
    */
   setMainUIAttrs (attrs: Record<string, any>): void
 
-  setMainUIInlineStyle (style: CSSStyleDeclaration): void
+  setMainUIInlineStyle (style: StyleOptions): void
 
   showMainUI (): void
 

+ 2 - 1
libs/src/LSPlugin.user.ts

@@ -5,6 +5,7 @@ import {
   IEditorProxy,
   ILSPluginUser,
   LSPluginBaseInfo, LSPluginUserEvents, SlashCommandAction,
+  StyleOptions,
   StyleString,
   ThemeOptions,
   UIOptions
@@ -185,7 +186,7 @@ export class LSPluginUser extends EventEmitter<LSPluginUserEvents> implements IL
     this.caller.call('main-ui:attrs', attrs)
   }
 
-  setMainUIInlineStyle (style: CSSStyleDeclaration): void {
+  setMainUIInlineStyle (style: StyleOptions): void {
     this.caller.call('main-ui:style', style)
   }
 

+ 5 - 0
libs/yarn.lock

@@ -365,6 +365,11 @@ cross-spawn@^7.0.3:
     shebang-command "^2.0.0"
     which "^2.0.1"
 
+csstype@^3.0.8:
+  version "3.0.8"
+  resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.8.tgz#d2266a792729fb227cd216fb572f43728e1ad340"
+  integrity sha512-jXKhWqXPmlUeoQnF/EhTtTl4C9SnrxSH/jZUih3jmO6lBKr99rP3/+FmrMj4EFpOXzMtXHAZkd3x0E6h6Fgflw==
+
 debug@^4.3.1:
   version "4.3.1"
   resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"