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 { Snippet, ComponentMetadata } from './metadata';
export interface Package { // 应该被编辑器默认加载定义组件大包及external资源的信息
package: string; // 包名
version: string; // 包版本号
urls?: string[] | any; // 组件渲染态视图打包后的 CDN url 列表,包含 js 和 css
editUrls?: string[] | any; // 组件编辑态视图打包后的 CDN url 列表,包含 js 和 css
library: string; // 作为全局变量引用时的名称和webpack output.library字段含义一样用来定义全局变量名
async?: boolean,
/**
* external资源的信息
*/
export interface Package {
/**
*
*/
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;
}
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[];
}
/**
*
*/
export interface ComponentDescription extends ComponentMetadata {
/**
*
*/
keywords: string[];
}
/**
*
*/
export interface RemoteComponentDescription {
/**
*
*/
exportName: string;
/**
*
*/
url: string;
}

View File

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

View File

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

View File

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

View File

@ -31,31 +31,55 @@ export interface SettingTarget {
*/
readonly top: 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';
// 表达式
/**
*
*/
export interface JSExpression {
type: 'JSExpression';
/**
@ -15,7 +17,9 @@ export interface JSExpression {
compiled?: string;
}
// 函数
/**
*
*/
export interface JSFunction {
type: 'JSFunction';
/**
@ -40,7 +44,9 @@ export interface JSFunction {
compiled?: string;
}
// 函数
/**
*
*/
export interface JSFunction {
type: 'JSFunction';
/**
@ -60,7 +66,9 @@ export interface JSFunction {
export interface JSSlot {
type: 'JSSlot';
title?: string;
// 函数的入参
/**
*
*/
params?: string[];
value?: NodeData[] | NodeData;
name?: string;
@ -71,7 +79,9 @@ export interface JSBlock {
value: NodeSchema;
}
// JSON 基本类型
/**
* JSON
*/
export type JSONValue =
| boolean
| string
@ -85,7 +95,9 @@ export interface JSONObject {
[key: string]: JSONValue;
}
// 复合类型
/**
*
*/
export type CompositeValue =
| JSONValue
| JSExpression