docs: 优化 types 类型定义,使得类型注释能在 VSCode 中正确被提示

This commit is contained in:
humphry.hy 2021-12-13 16:14:08 +08:00
parent 3ef5b7ff41
commit c04ec1255d
6 changed files with 288 additions and 100 deletions

View File

@ -2,34 +2,100 @@ import { NpmInfo } from './npm';
import { PropConfig } from './prop-config'; import { PropConfig } from './prop-config';
import { Snippet, ComponentMetadata } from './metadata'; import { Snippet, ComponentMetadata } from './metadata';
export interface Package { // 应该被编辑器默认加载定义组件大包及external资源的信息 /**
package: string; // 包名 * external资源的信息
version: string; // 包版本号 */
urls?: string[] | any; // 组件渲染态视图打包后的 CDN url 列表,包含 js 和 css export interface Package {
editUrls?: string[] | any; // 组件编辑态视图打包后的 CDN url 列表,包含 js 和 css /**
library: string; // 作为全局变量引用时的名称和webpack output.library字段含义一样用来定义全局变量名 *
async?: boolean, */
package: string;
/**
*
*/
version: string;
/**
* CDN url js css
*/
urls?: string[] | any;
/**
* CDN url js css
*/
editUrls?: string[] | any;
/**
* webpack output.library字段含义一样
*/
library: string;
/**
*
*/
async?: boolean;
/**
*
*/
exportName?: string; exportName?: string;
} }
export interface ComponentCategory { // 组件分类 /**
title: string; // 组件分类title *
icon?: string; // 组件分类icon */
children?: ComponentItem[] | ComponentCategory[]; // 可能有子分类 export interface ComponentCategory {
/**
* title
*/
title: string;
/**
* icon
*/
icon?: string;
/**
*
*/
children?: ComponentItem[] | ComponentCategory[];
} }
export interface ComponentItem { // 组件 /**
title: string; // 组件title *
componentName?: string; // 组件名 */
icon?: string; // 组件icon export interface ComponentItem {
/**
* title
*/
title: string;
/**
*
*/
componentName?: string;
/**
* icon
*/
icon?: string;
/**
*
*/
snippets?: Snippet[]; snippets?: Snippet[];
} }
/**
*
*/
export interface ComponentDescription extends ComponentMetadata { export interface ComponentDescription extends ComponentMetadata {
/**
*
*/
keywords: string[]; keywords: string[];
} }
/**
*
*/
export interface RemoteComponentDescription { export interface RemoteComponentDescription {
/**
*
*/
exportName: string; exportName: string;
/**
*
*/
url: string; url: string;
} }

View File

@ -1,6 +1,7 @@
import { TitleContent } from './title'; import { TitleContent } from './title';
import { SetterType, DynamicSetter } from './setter-config'; import { SetterType, DynamicSetter } from './setter-config';
import { SettingTarget } from './setting-target'; import { SettingTarget } from './setting-target';
import { LiveTextEditingConfig } from './metadata';
export interface FieldExtraProps { export interface FieldExtraProps {
/** /**
@ -49,13 +50,8 @@ export interface FieldExtraProps {
* compatiable vision display * compatiable vision display
*/ */
display?: 'accordion' | 'inline' | 'block' | 'plain' | 'popup' | 'entry'; display?: 'accordion' | 'inline' | 'block' | 'plain' | 'popup' | 'entry';
liveTextEditing?: { // todo 这个 omit 是否合理?
selector: string; liveTextEditing?: Omit<LiveTextEditingConfig, 'propTarget'>;
// 编辑模式 纯文本|段落编辑|文章编辑(默认纯文本,无跟随工具条)
mode?: 'plaintext' | 'paragraph' | 'article';
// 从 contentEditable 获取内容并设置到属性
onSaveContent?: (content: string, prop: any) => any;
};
} }
export interface FieldConfig extends FieldExtraProps { export interface FieldConfig extends FieldExtraProps {

View File

@ -11,15 +11,25 @@ import { I18nData } from './i18n';
export type NestingFilter = (testNode: any, currentNode: any) => boolean; export type NestingFilter = (testNode: any, currentNode: any) => boolean;
export interface NestingRule { export interface NestingRule {
// 子级白名单 /**
*
*/
childWhitelist?: string[] | string | RegExp | NestingFilter; childWhitelist?: string[] | string | RegExp | NestingFilter;
// 父级白名单 /**
*
*/
parentWhitelist?: string[] | string | RegExp | NestingFilter; parentWhitelist?: string[] | string | RegExp | NestingFilter;
// 后裔白名单 /**
*
*/
descendantWhitelist?: string[] | string | RegExp | NestingFilter; descendantWhitelist?: string[] | string | RegExp | NestingFilter;
// 后裔黑名单 /**
*
*/
descendantBlacklist?: string[] | string | RegExp | NestingFilter; descendantBlacklist?: string[] | string | RegExp | NestingFilter;
// 祖先白名单 可用来做区域高亮 /**
*
*/
ancestorWhitelist?: string[] | string | RegExp | NestingFilter; ancestorWhitelist?: string[] | string | RegExp | NestingFilter;
} }
@ -33,15 +43,18 @@ export interface ComponentConfigure {
isMinimalRenderUnit?: boolean; isMinimalRenderUnit?: boolean;
rootSelector?: string; rootSelector?: string;
// copy, move, remove | * /**
* copy, move, remove | *
*/
disableBehaviors?: string[] | string; disableBehaviors?: string[] | string;
actions?: ComponentAction[]; actions?: ComponentAction[];
} }
export interface Snippet { export interface Snippet {
screenshot: string; title?: string;
label: string; screenshot?: string;
schema: NodeSchema; label?: string;
schema?: NodeSchema;
} }
export interface InitialItem { export interface InitialItem {
@ -62,47 +75,65 @@ export interface Experimental {
context?: { [contextInfoName: string]: any }; context?: { [contextInfoName: string]: any };
snippets?: Snippet[]; snippets?: Snippet[];
view?: ComponentType<any>; view?: ComponentType<any>;
transducers?: any; // ? should support transducers?: any;
/**
* @deprecated
*/
initials?: InitialItem[]; initials?: InitialItem[];
filters?: FilterItem[]; filters?: FilterItem[];
autoruns?: AutorunItem[]; autoruns?: AutorunItem[];
callbacks?: Callbacks; callbacks?: Callbacks;
initialChildren?: NodeData[] | ((target: SettingTarget) => NodeData[]); initialChildren?: NodeData[] | ((target: SettingTarget) => NodeData[]);
isAbsoluteLayoutContainer: boolean; isAbsoluteLayoutContainer?: boolean;
hideSelectTools?: boolean; hideSelectTools?: boolean;
// 样式 及 位置handle上必须有明确的标识以便事件路由判断或者主动设置事件独占模式 /**
// NWSE 是交给引擎计算放置位置ReactElement 必须自己控制初始位置 * handle上必须有明确的标识以便事件路由判断
* NWSE ReactElement
* - hover
* - mousedown
* - dragstart resizing hud
* - drag
*/
getResizingHandlers?: ( getResizingHandlers?: (
currentNode: any, currentNode: any,
) => ) => (
| Array<{ | Array<{
type: 'N' | 'W' | 'S' | 'E' | 'NW' | 'NE' | 'SE' | 'SW'; type: 'N' | 'W' | 'S' | 'E' | 'NW' | 'NE' | 'SE' | 'SW';
content?: ReactElement; content?: ReactElement;
propTarget?: string; propTarget?: string;
appearOn?: 'mouse-enter' | 'mouse-hover' | 'selected' | 'always'; appearOn?: 'mouse-enter' | 'mouse-hover' | 'selected' | 'always';
}> }>
| ReactElement[]; | ReactElement[]
// hover时 控制柄高亮 );
// mousedown 时请求独占
// dragstart 请求 通用 resizing 控制
// 请求 hud 显示
// drag 时 计算 并 设置效果
// 更新控制柄位置
// 纯文本编辑:如果 children 内容是 /**
// 文本编辑:配置 * Live Text Editing children
*/
liveTextEditing?: LiveTextEditingConfig[]; liveTextEditing?: LiveTextEditingConfig[];
isTopFixed?: boolean; isTopFixed?: boolean;
} }
// thinkof Array // thinkof Array
/**
* Live Text Editing children
*/
export interface LiveTextEditingConfig { export interface LiveTextEditingConfig {
/**
*
*/
propTarget: string; propTarget: string;
/**
*
*/
selector?: string; selector?: string;
// 编辑模式 纯文本|段落编辑|文章编辑(默认纯文本,无跟随工具条) /**
* ||
*/
mode?: 'plaintext' | 'paragraph' | 'article'; mode?: 'plaintext' | 'paragraph' | 'article';
// 从 contentEditable 获取内容并设置到属性 /**
* contentEditable
*/
onSaveContent?: (content: string, prop: any) => any; onSaveContent?: (content: string, prop: any) => any;
} }
@ -129,24 +160,41 @@ export interface Configure {
} }
export interface ActionContentObject { export interface ActionContentObject {
// 图标 /**
*
*/
icon?: IconType; icon?: IconType;
// 描述 /**
*
*/
title?: TipContent; title?: TipContent;
// 执行动作 /**
*
*/
action?: (currentNode: any) => void; action?: (currentNode: any) => void;
} }
export interface ComponentAction { export interface ComponentAction {
// behaviorName /**
* behaviorName
*/
name: string; name: string;
// 菜单名称 /**
*
*/
content: string | ReactNode | ActionContentObject; content: string | ReactNode | ActionContentObject;
// 子集 /**
*
*/
items?: ComponentAction[]; items?: ComponentAction[];
// 显示与否always: 无法禁用 /**
*
* always: 无法禁用
*/
condition?: boolean | ((currentNode: any) => boolean) | 'always'; condition?: boolean | ((currentNode: any) => boolean) | 'always';
// 显示在工具条上 /**
*
*/
important?: boolean; important?: boolean;
} }
@ -188,21 +236,32 @@ export interface TransformedComponentMetadata extends ComponentMetadata {
configure: Configure & { combined?: FieldConfig[] }; configure: Configure & { combined?: FieldConfig[] };
} }
// handleResizing /**
* handleResizing
*/
// hooks & events /**
* hooks & events
*/
export interface Callbacks { export interface Callbacks {
// hooks /**
* hooks
*/
onMouseDownHook?: (e: MouseEvent, currentNode: any) => any; onMouseDownHook?: (e: MouseEvent, currentNode: any) => any;
onDblClickHook?: (e: MouseEvent, currentNode: any) => any; onDblClickHook?: (e: MouseEvent, currentNode: any) => any;
onClickHook?: (e: MouseEvent, currentNode: any) => any; onClickHook?: (e: MouseEvent, currentNode: any) => any;
// onLocateHook?: (e: any, currentNode: any) => any; // onLocateHook?: (e: any, currentNode: any) => any;
// onAcceptHook?: (currentNode: any, locationData: any) => any; // onAcceptHook?: (currentNode: any, locationData: any) => any;
onMoveHook?: (currentNode: any) => boolean; // thinkof 限制性拖拽 onMoveHook?: (currentNode: any) => boolean;
// thinkof 限制性拖拽
onHoverHook?: (currentNode: any) => boolean; onHoverHook?: (currentNode: any) => boolean;
onChildMoveHook?: (childNode: any, currentNode: any) => boolean; onChildMoveHook?: (childNode: any, currentNode: any) => boolean;
// events /**
* events
*/
onNodeRemove?: (removedNode: any, currentNode: any) => void; onNodeRemove?: (removedNode: any, currentNode: any) => void;
onNodeAdd?: (addedNode: any, currentNode: any) => void; onNodeAdd?: (addedNode: any, currentNode: any) => void;
onSubtreeModified?: (currentNode: any, options: any) => void; onSubtreeModified?: (currentNode: any, options: any) => void;

View File

@ -11,20 +11,48 @@ import { I18nMap } from './i18n';
import { UtilsMap } from './utils'; import { UtilsMap } from './utils';
import { AppConfig } from './app-config'; import { AppConfig } from './app-config';
// 搭建基础协议 - 单个组件树节点描述
// 转换成一个 .jsx 文件内 React Class 类 render 函数返回的 jsx 代码 // 转换成一个 .jsx 文件内 React Class 类 render 函数返回的 jsx 代码
/**
* -
*/
export interface NodeSchema { export interface NodeSchema {
id?: string; id?: string;
componentName: string; // 组件名称 必填、首字母大写 /**
props?: PropsMap | PropsList; // 组件属性对象 *
*/
componentName: string;
/**
*
*/
props?: PropsMap | PropsList;
/**
*
*/
leadingComponents?: string; leadingComponents?: string;
condition?: CompositeValue; // 渲染条件 /**
loop?: CompositeValue; // 循环数据 *
loopArgs?: [string, string]; // 循环迭代对象、索引名称 ["item", "index"] */
children?: NodeData | NodeData[]; // 子节点 condition?: CompositeValue;
isLocked?: boolean; // 是否锁定 /**
*
*/
loop?: CompositeValue;
/**
* ["item", "index"]
*/
loopArgs?: [string, string];
/**
*
*/
children?: NodeData | NodeData[];
/**
*
*/
isLocked?: boolean;
// ------- future support ----- /**
* ------- future support -----
*/
conditionGroup?: string; conditionGroup?: string;
title?: string; title?: string;
ignore?: boolean; ignore?: boolean;
@ -50,7 +78,10 @@ export function isDOMText(data: any): data is DOMText {
export type DOMText = string; export type DOMText = string;
export interface ContainerSchema extends NodeSchema { export interface ContainerSchema extends NodeSchema {
componentName: string; // 'Block' | 'Page' | 'Component'; /**
* 'Block' | 'Page' | 'Component';
*/
componentName: string;
fileName: string; fileName: string;
meta?: Record<string, unknown>; meta?: Record<string, unknown>;
state?: { state?: {

View File

@ -31,31 +31,55 @@ export interface SettingTarget {
*/ */
readonly top: SettingTarget; readonly top: SettingTarget;
// 父级 /**
*
*/
readonly parent: SettingTarget; readonly parent: SettingTarget;
// 获取当前值 /**
getValue(): any; *
*/
getValue: () => any;
// 设置当前值 /**
setValue(value: any): void; *
*/
setValue: (value: any) => void;
// 取得子项 /**
get(propName: string | number): SettingTarget | null; *
*/
get: (propName: string | number) => SettingTarget | null;
// 获取子项属性值 /**
getPropValue(propName: string | number): any; *
*/
getPropValue: (propName: string | number) => any;
// 设置子项属性值 /**
setPropValue(propName: string | number, value: any): void; *
*/
setPropValue: (propName: string | number, value: any) => void;
// 清除已设置值 /**
clearPropValue(propName: string | number): void; *
*/
clearPropValue: (propName: string | number) => void;
// 获取顶层附属属性值 /**
getExtraPropValue(propName: string): any; *
*/
getExtraPropValue: (propName: string) => any;
// 设置顶层附属属性值 /**
setExtraPropValue(propName: string, value: any): void; *
*/
setExtraPropValue: (propName: string, value: any) => void;
// todo 补充 node 定义
/**
* node
*/
getNode: () => any;
} }

View File

@ -1,6 +1,8 @@
import { NodeSchema, NodeData } from './schema'; import { NodeSchema, NodeData } from './schema';
// 表达式 /**
*
*/
export interface JSExpression { export interface JSExpression {
type: 'JSExpression'; type: 'JSExpression';
/** /**
@ -15,7 +17,9 @@ export interface JSExpression {
compiled?: string; compiled?: string;
} }
// 函数 /**
*
*/
export interface JSFunction { export interface JSFunction {
type: 'JSFunction'; type: 'JSFunction';
/** /**
@ -40,7 +44,9 @@ export interface JSFunction {
compiled?: string; compiled?: string;
} }
// 函数 /**
*
*/
export interface JSFunction { export interface JSFunction {
type: 'JSFunction'; type: 'JSFunction';
/** /**
@ -60,7 +66,9 @@ export interface JSFunction {
export interface JSSlot { export interface JSSlot {
type: 'JSSlot'; type: 'JSSlot';
title?: string; title?: string;
// 函数的入参 /**
*
*/
params?: string[]; params?: string[];
value?: NodeData[] | NodeData; value?: NodeData[] | NodeData;
name?: string; name?: string;
@ -71,7 +79,9 @@ export interface JSBlock {
value: NodeSchema; value: NodeSchema;
} }
// JSON 基本类型 /**
* JSON
*/
export type JSONValue = export type JSONValue =
| boolean | boolean
| string | string
@ -85,7 +95,9 @@ export interface JSONObject {
[key: string]: JSONValue; [key: string]: JSONValue;
} }
// 复合类型 /**
*
*/
export type CompositeValue = export type CompositeValue =
| JSONValue | JSONValue
| JSExpression | JSExpression