chore: 增加方法注释

This commit is contained in:
lihao.ylh 2022-01-05 15:11:25 +08:00
parent 9f8bb613b9
commit c59eee0cca
19 changed files with 461 additions and 12 deletions

View File

@ -15,6 +15,7 @@
"lint": "eslint --ext .ts,.tsx,.js,.jsx ./ --quiet",
"lint:fix": "eslint --ext .ts,.tsx,.js,.jsx ./ --quiet --fix",
"pub": "tnpm run watchdog:build && lerna publish patch --force-publish --exact --no-changelog",
"pub:premajor": "tnpm run watchdog:build && lerna publish premajor --force-publish --exact --dist-tag beta --preid beta --no-changelog",
"pub:prepatch": "tnpm run watchdog:build && lerna publish prepatch --force-publish --exact --dist-tag beta --preid beta --no-changelog",
"pub:prerelease": "tnpm run watchdog:build && lerna publish prerelease --force-publish --exact --dist-tag beta --preid beta --no-changelog",
"setup": "./scripts/setup.sh",

View File

@ -29,46 +29,77 @@ export default class ComponentMeta {
return new ComponentMeta(componentMeta);
}
/**
*
*/
get componentName(): string {
return this[componentMetaSymbol].componentName;
}
/**
*
*/
get isContainer(): boolean {
return this[componentMetaSymbol].isContainer;
}
/**
*
*
*
*
*/
get isMinimalRenderUnit(): boolean {
return this[componentMetaSymbol].isMinimalRenderUnit;
}
/**
*
*/
get isModal(): boolean {
return this[componentMetaSymbol].isModal;
}
/**
*
*/
get configure() {
return this[componentMetaSymbol].configure;
}
/**
*
*/
get title() {
return this[componentMetaSymbol].title;
}
/**
*
*/
get icon() {
return this[componentMetaSymbol].icon;
}
/**
* npm
*/
get npm() {
return this[componentMetaSymbol].npm;
}
get acceptable(): boolean {
return this[componentMetaSymbol].acceptable;
}
/**
* npm
* @param npm
*/
setNpm(npm: any) {
this[componentMetaSymbol].setNpm(npm);
}
/**
*
* @returns
*/
getMetadata() {
return this[componentMetaSymbol].getMetadata();
}

View File

@ -13,14 +13,25 @@ export default class Detecting {
this[detectingSymbol] = document.designer.detecting;
}
/**
* hover
* @param id id
*/
capture(id: string) {
this[detectingSymbol].capture(this[documentSymbol].getNode(id));
}
/**
* hover
* @param id id
*/
release(id: string) {
this[detectingSymbol].release(this[documentSymbol].getNode(id));
}
/**
* hover
*/
leave() {
this[detectingSymbol].leave(this[documentSymbol]);
}

View File

@ -101,7 +101,7 @@ export default class DocumentModel {
* @param stage
* @returns
*/
exportSchema(stage?: TransformStage) {
exportSchema(stage: TransformStage = TransformStage.Render) {
return this[documentSymbol].export(stage);
}

View File

@ -25,10 +25,30 @@ export default class Event {
}
}
/**
*
* @param event
* @param listener
*/
on(event: string, listener: (...args: unknown[]) => void) {
this[editorSymbol].on(event, listener);
}
/**
*
* @param event
* @param listener
*/
off(event: string, listener: (...args: unknown[]) => void) {
this[editorSymbol].off(event, listener);
}
/**
*
* @param event
* @param args
* @returns
*/
emit(event: string, ...args: unknown[]) {
if (!this.options.prefix) {
logger.warn('Event#emit has been forbidden while prefix is not specified');

View File

@ -10,34 +10,65 @@ export default class History {
this[historySymbol] = this[documentSymbol].getHistory();
}
/**
*
* @param cursor
*/
go(cursor: number) {
this[historySymbol].go(cursor);
}
/**
* 退
*/
back() {
this[historySymbol].back();
}
/**
*
*/
forward() {
this[historySymbol].forward();
}
/**
*
*/
savePoint() {
this[historySymbol].savePoint();
}
/**
*
* @returns
*/
isSavePoint() {
return this[historySymbol].isSavePoint();
}
/**
* state退
* @returns
*/
getState() {
return this[historySymbol].getState();
}
/**
* state
* @param func
* @returns
*/
onChangeState(func: () => any) {
return this[historySymbol].onStateChange(func);
}
/**
*
* @param func
* @returns
*/
onChangeCursor(func: () => any) {
return this[historySymbol].onCursor(func);
}

View File

@ -2,6 +2,13 @@ import { hotkey, HotkeyCallback } from '@ali/lowcode-editor-core';
import { Disposable } from '@ali/lowcode-types';
export default class Hotkey {
/**
*
* @param combos ['command + s'] ['ctrl + shift + s']
* @param callback
* @param action
* @returns
*/
bind(combos: string[] | string, callback: HotkeyCallback, action?: string): Disposable {
hotkey.bind(combos, callback, action);
return () => {

View File

@ -22,22 +22,45 @@ export default class Material {
this[designerSymbol] = editor.get('designer')!;
}
/**
* map
*/
get componentsMap() {
return this[designerSymbol].componentsMap;
}
/**
*
* @param assets
* @returns
*/
setAssets(assets: AssetsJson) {
return this[editorSymbol].setAssets(assets);
}
/**
*
* @returns
*/
getAssets() {
return this[editorSymbol].get('assets');
}
/**
*
* @param incrementalAssets
* @returns
*/
loadIncrementalAssets(incrementalAssets: AssetsJson) {
return this[designerSymbol].loadIncrementalAssets(incrementalAssets);
}
/**
*
* @param transducer
* @param level
* @param id
*/
registerMetadataTransducer(
transducer: MetadataTransducer,
level?: number,
@ -46,14 +69,27 @@ export default class Material {
registerMetadataTransducer(transducer, level, id);
}
/**
*
* @returns
*/
getRegisteredMetadataTransducers() {
return getRegisteredMetadataTransducers();
}
/**
*
* @param componentName
* @returns
*/
getComponentMeta(componentName: string) {
return ComponentMeta.create(this[designerSymbol].getComponentMeta(componentName));
}
/**
*
* @returns
*/
getComponentMetasMap() {
const map = new Map<string, ComponentMeta>();
const originalMap = this[designerSymbol].getComponentMetasMap();
@ -63,14 +99,27 @@ export default class Material {
return map;
}
/**
* action
* @param action
*/
addBuiltinComponentAction(action: ComponentAction) {
addBuiltinComponentAction(action);
}
/**
* action
* @param name
*/
removeBuiltinComponentAction(name: string) {
removeBuiltinComponentAction(name);
}
/**
* action
* @param actionName
* @param handle
*/
modifyBuiltinComponentAction(actionName: string, handle: (action: ComponentAction) => void) {
modifyBuiltinComponentAction(actionName, handle);
}

View File

@ -15,66 +15,128 @@ export default class NodeChildren {
return new NodeChildren(nodeChldren);
}
/**
* children
*/
get owner(): Node | null {
return Node.create(this[nodeChildrenSymbol].owner);
}
/**
* children
*/
get size() {
return this[nodeChildrenSymbol].size;
}
/**
*
* @returns
*/
isEmpty() {
return this[nodeChildrenSymbol].isEmpty();
}
/**
*
* @param node
* @returns
*/
delete(node: Node) {
return this[nodeChildrenSymbol].delete(node[nodeSymbol]);
}
insert(node: Node, at?: number | null | undefined, useMutator?: boolean) {
return this[nodeChildrenSymbol].insert(node[nodeSymbol], at, useMutator);
/**
*
* @param node
* @param at
* @returns
*/
insert(node: Node, at?: number | null) {
return this[nodeChildrenSymbol].insert(node[nodeSymbol], at, true);
}
/**
*
* @param node
* @returns
*/
indexOf(node: Node) {
return this[nodeChildrenSymbol].indexOf(node[nodeSymbol]);
}
/**
* splice
* @param start
* @param deleteCount
* @param node
*/
splice(start: number, deleteCount: number, node?: Node) {
this[nodeChildrenSymbol].splice(start, deleteCount, node?.[nodeSymbol]);
}
/**
*
* @param index
* @returns
*/
get(index: number) {
return this[nodeChildrenSymbol].get(index);
}
/**
*
* @param node
* @returns
*/
has(node: Node) {
return this[nodeChildrenSymbol].has(node[nodeSymbol]);
}
/**
* forEach
* @param fn
*/
forEach(fn: (node: Node, index: number) => void) {
this[nodeChildrenSymbol].forEach((item: InnerNode<NodeSchema>, index: number) => {
fn(Node.create(item)!, index);
});
}
/**
* map
* @param fn
*/
map<T>(fn: (node: Node, index: number) => T[]) {
return this[nodeChildrenSymbol].map((item: InnerNode<NodeSchema>, index: number) => {
return fn(Node.create(item)!, index);
});
}
/**
* every
* @param fn
*/
every(fn: (node: Node, index: number) => boolean) {
return this[nodeChildrenSymbol].every((item: InnerNode<NodeSchema>, index: number) => {
return fn(Node.create(item)!, index);
});
}
/**
* some
* @param fn
*/
some(fn: (node: Node, index: number) => boolean) {
return this[nodeChildrenSymbol].some((item: InnerNode<NodeSchema>, index: number) => {
return fn(Node.create(item)!, index);
});
}
/**
* filter
* @param fn
*/
filter(fn: (node: Node, index: number) => boolean) {
return this[nodeChildrenSymbol]
.filter((item: InnerNode<NodeSchema>, index: number) => {
@ -83,6 +145,10 @@ export default class NodeChildren {
.map((item: InnerNode<NodeSchema>) => Node.create(item)!);
}
/**
* find
* @param fn
*/
find(fn: (node: Node, index: number) => boolean) {
return Node.create(
this[nodeChildrenSymbol].find((item: InnerNode<NodeSchema>, index: number) => {
@ -91,20 +157,39 @@ export default class NodeChildren {
);
}
/**
* reduce
* @param fn
*/
reduce(fn: (acc: any, cur: Node) => any, initialValue: any) {
return this[nodeChildrenSymbol].reduce((acc: any, cur: InnerNode) => {
return fn(acc, Node.create(cur)!);
}, initialValue);
}
/**
* schema
* @param data
*/
importSchema(data?: NodeData | NodeData[]) {
this[nodeChildrenSymbol].import(data);
}
exportSchema(stage?: TransformStage) {
/**
* schema
* @param stage
* @returns
*/
exportSchema(stage: TransformStage = TransformStage.Render) {
return this[nodeChildrenSymbol].export(stage);
}
/**
*
* @param remover
* @param adder
* @param sorter
*/
mergeChildren(
remover: (node: Node, idx: number) => boolean,
adder: (children: Node[]) => any,

View File

@ -26,63 +26,99 @@ export default class Node {
}
/**
* id
* id
*/
get id() {
return this[nodeSymbol].id;
}
/**
*
*/
get title() {
return this[nodeSymbol].title;
}
/**
*
*/
get isContainer() {
return this[nodeSymbol].isContainer();
}
/**
*
*/
get isRoot() {
return this[nodeSymbol].isRoot();
}
/**
* Page
*/
get isPage() {
return this[nodeSymbol].isPage();
}
/**
* Component
*/
get isComponent() {
return this[nodeSymbol].isComponent();
}
/**
*
*/
get isSlot() {
return this[nodeSymbol].isSlot();
}
/**
* /
*/
get isParental() {
return this[nodeSymbol].isParental();
}
/**
*
*/
get isLeaf() {
return this[nodeSymbol].isLeaf();
}
/**
*
*/
get index() {
return this[nodeSymbol].index;
}
/**
*
*/
get icon() {
return this[nodeSymbol].icon;
}
/**
* 0
*/
get zLevel() {
return this[nodeSymbol].zLevel;
}
/**
* componentName
* componentName
*/
get componentName() {
return this[nodeSymbol].componentName;
}
/**
*
*/
get componentMeta() {
return ComponentMeta.create(this[nodeSymbol].componentMeta);
}
@ -127,14 +163,23 @@ export default class Node {
return NodeChildren.create(this[nodeSymbol].children);
}
/**
*
*/
get slots(): Node[] {
return this[nodeSymbol].slots.map((node: InnerNode) => Node.create(node)!);
}
/**
*
*/
get slotFor() {
return Prop.create(this[nodeSymbol].slotFor);
}
/**
*
*/
get props() {
return Props.create(this[nodeSymbol].props);
}
@ -153,18 +198,34 @@ export default class Node {
return this[nodeSymbol].getDOMNode();
}
/**
*
* @returns
*/
getRect() {
return this[nodeSymbol].getRect();
}
/**
*
* @returns
*/
hasSlots() {
return this[nodeSymbol].hasSlots();
}
/**
*
* @returns
*/
hasCondition() {
return this[nodeSymbol].hasCondition();
}
/**
*
* @returns
*/
hasLoop() {
return this[nodeSymbol].hasLoop();
}
@ -248,7 +309,7 @@ export default class Node {
* @param options
* @returns
*/
exportSchema(stage?: TransformStage, options?: any) {
exportSchema(stage: TransformStage = TransformStage.Render, options?: any) {
return this[nodeSymbol].export(stage, options);
}

View File

@ -30,6 +30,9 @@ export default class Project {
return this[projectSymbol].documents.map((doc) => DocumentModel.create(doc)!);
}
/**
* host
*/
get simulatorHost() {
return SimulatorHost.create(this[projectSymbol].simulator as any || this[simulatorHostSymbol]);
}

View File

@ -15,27 +15,56 @@ export default class Prop {
return new Prop(prop);
}
/**
* id
*/
get id() {
return this[propSymbol].id;
}
/**
* key
*/
get key() {
return this[propSymbol].key;
}
/**
* prop
*/
get path() {
return this[propSymbol].path;
}
/**
*
*/
get node(): Node | null {
return Node.create(this[propSymbol].getNode());
}
/**
*
* @param val
*/
setValue(val: CompositeValue) {
this[propSymbol].setValue(val);
}
/**
*
* @returns
*/
getValue() {
return this[propSymbol].getValue();
}
exportSchema(stage: TransformStage) {
/**
*
* @param stage
* @returns
*/
exportSchema(stage: TransformStage = TransformStage.Render) {
return this[propSymbol].export(stage);
}
}

View File

@ -16,10 +16,16 @@ export default class Props {
return new Props(props);
}
/**
* id
*/
get id() {
return this[propsSymbol].id;
}
/**
* props
*/
get path() {
return this[propsSymbol].path;
}

View File

@ -15,34 +15,65 @@ export default class Selection {
this[selectionSymbol] = document.selection;
}
/**
* id
*/
get selected() {
return this[selectionSymbol].selected;
}
/**
*
* @param id
*/
select(id: string) {
this[selectionSymbol].select(id);
}
/**
*
* @param ids
*/
selectAll(ids: string[]) {
this[selectionSymbol].selectAll(ids);
}
/**
*
* @param id
*/
remove(id: string) {
this[selectionSymbol].remove(id);
}
/**
*
*/
clear() {
this[selectionSymbol].clear();
}
/**
*
* @param id
* @returns
*/
has(id: string) {
return this[selectionSymbol].has(id);
}
/**
*
* @param id
*/
add(id: string) {
this[selectionSymbol].add(id);
}
/**
*
* @returns
*/
getNodes() {
return this[selectionSymbol].getNodes().map((node: InnerNode) => Node.create(node));
}

View File

@ -2,14 +2,29 @@ import { getSetter, registerSetter, getSettersMap, RegisteredSetter } from '@ali
import { CustomView } from '@ali/lowcode-types';
export default class Setters {
/**
* setter
* @param type
* @returns
*/
getSetter(type: string) {
return getSetter(type);
}
/**
* settersMap
* @returns
*/
getSettersMap() {
return getSettersMap();
}
/**
* setter
* @param typeOrMaps
* @param setter
* @returns
*/
registerSetter(
typeOrMaps: string | { [key: string]: CustomView | RegisteredSetter },
setter?: CustomView | RegisteredSetter | undefined,

View File

@ -26,30 +26,59 @@ export default class SettingPropEntry {
return this.node;
}
/**
*
* @param val
*/
setValue(val: CompositeValue) {
this[settingPropEntrySymbol].setValue(val);
}
/**
*
* @returns
*/
getValue() {
return this[settingPropEntrySymbol].getValue();
}
/**
*
* @returns
*/
getProps() {
return SettingTopEntry.create(this[settingPropEntrySymbol].getProps() as SettingEntry) as any;
}
/**
*
* @returns
*/
isUseVariable() {
return this[settingPropEntrySymbol].isUseVariable();
}
/**
*
* @param flag
*/
setUseVariable(flag: boolean) {
this[settingPropEntrySymbol].setUseVariable(flag);
}
/**
* field
* @param config
* @returns
*/
createField(config: FieldConfig) {
return SettingPropEntry.create(this[settingPropEntrySymbol].createField(config));
}
/**
* mock
* @returns
*/
getMockOrValue() {
return this[settingPropEntrySymbol].getMockOrValue();
}

View File

@ -13,6 +13,9 @@ export default class SettingTopEntry {
return new SettingTopEntry(prop);
}
/**
*
*/
get node(): Node | null {
return Node.create(this[settingTopEntrySymbol].getNode());
}
@ -24,10 +27,20 @@ export default class SettingTopEntry {
return this.node;
}
/**
* propName
* @param propName
* @returns
*/
getPropValue(propName: string | number) {
return this[settingTopEntrySymbol].getPropValue(propName);
}
/**
* propName
* @param propName
* @param value
*/
setPropValue(propName: string | number, value: any) {
this[settingTopEntrySymbol].setPropValue(propName, value);
}

View File

@ -15,18 +15,34 @@ export default class SimulatorHost {
return new SimulatorHost(host);
}
/**
* contentWindow
*/
get contentWindow() {
return this[simulatorHostSymbol].contentWindow;
}
/**
* contentDocument
*/
get contentDocument() {
return this[simulatorHostSymbol].contentDocument;
}
/**
* host
* @param key
* @param value
*/
set(key: string, value: any) {
this[simulatorHostSymbol].set(key, value);
}
/**
* host
* @param key
* @returns
*/
get(key: string) {
return this[simulatorHostSymbol].get(key);
}

View File

@ -12,10 +12,21 @@ export default class Skeleton {
this[skeletonSymbol] = skeleton;
}
/**
*
* @param config
* @param extraConfig
* @returns
*/
add(config: IWidgetBaseConfig, extraConfig?: Record<string, any>) {
return this[skeletonSymbol].add(config, extraConfig);
}
/**
*
* @param config
* @returns
*/
remove(config: IWidgetBaseConfig) {
const { area, name } = config;
const skeleton = this[skeletonSymbol];