amis 1.9.0-beta.12 → 1.9.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Schema.d.ts +4 -2
- package/lib/Schema.js.map +1 -1
- package/lib/SchemaRenderer.d.ts +2 -2
- package/lib/SchemaRenderer.js +3 -3
- package/lib/SchemaRenderer.js.map +2 -2
- package/lib/actions/Action.d.ts +8 -6
- package/lib/actions/Action.js.map +2 -2
- package/lib/actions/AjaxAction.d.ts +10 -7
- package/lib/actions/AjaxAction.js +27 -21
- package/lib/actions/AjaxAction.js.map +2 -2
- package/lib/actions/BreakAction.d.ts +2 -2
- package/lib/actions/BreakAction.js.map +1 -1
- package/lib/actions/BroadcastAction.d.ts +3 -3
- package/lib/actions/BroadcastAction.js +3 -2
- package/lib/actions/BroadcastAction.js.map +2 -2
- package/lib/actions/CmptAction.d.ts +2 -2
- package/lib/actions/CmptAction.js +7 -9
- package/lib/actions/CmptAction.js.map +2 -2
- package/lib/actions/ContinueAction.d.ts +2 -2
- package/lib/actions/ContinueAction.js.map +1 -1
- package/lib/actions/CopyAction.d.ts +7 -4
- package/lib/actions/CopyAction.js +8 -6
- package/lib/actions/CopyAction.js.map +2 -2
- package/lib/actions/CustomAction.d.ts +2 -2
- package/lib/actions/CustomAction.js.map +1 -1
- package/lib/actions/DialogAction.d.ts +14 -8
- package/lib/actions/DialogAction.js +6 -6
- package/lib/actions/DialogAction.js.map +2 -2
- package/lib/actions/DrawerAction.d.ts +3 -3
- package/lib/actions/DrawerAction.js.map +1 -1
- package/lib/actions/EmailAction.d.ts +10 -7
- package/lib/actions/EmailAction.js +4 -5
- package/lib/actions/EmailAction.js.map +2 -2
- package/lib/actions/LinkAction.d.ts +19 -11
- package/lib/actions/LinkAction.js +6 -5
- package/lib/actions/LinkAction.js.map +2 -2
- package/lib/actions/LoopAction.d.ts +6 -3
- package/lib/actions/LoopAction.js +22 -20
- package/lib/actions/LoopAction.js.map +2 -2
- package/lib/actions/PageAction.d.ts +8 -5
- package/lib/actions/PageAction.js +3 -2
- package/lib/actions/PageAction.js.map +2 -2
- package/lib/actions/ParallelAction.d.ts +2 -2
- package/lib/actions/ParallelAction.js.map +1 -1
- package/lib/actions/SwitchAction.d.ts +2 -2
- package/lib/actions/SwitchAction.js.map +1 -1
- package/lib/actions/ToastAction.d.ts +2 -2
- package/lib/actions/ToastAction.js +6 -4
- package/lib/actions/ToastAction.js.map +2 -2
- package/lib/components/Editor.d.ts +84 -84
- package/lib/components/InputBox.js +1 -1
- package/lib/components/InputBox.js.map +2 -2
- package/lib/components/Pagination.d.ts +1175 -0
- package/lib/components/Pagination.js +274 -0
- package/lib/components/Pagination.js.map +13 -0
- package/lib/components/PickerContainer.d.ts +1 -0
- package/lib/components/PickerContainer.js +3 -2
- package/lib/components/PickerContainer.js.map +2 -2
- package/lib/components/Rating.js +11 -9
- package/lib/components/Rating.js.map +2 -2
- package/lib/components/Select.js +3 -3
- package/lib/components/Select.js.map +2 -2
- package/lib/components/Tag.d.ts +148 -0
- package/lib/components/Tag.js +96 -0
- package/lib/components/Tag.js.map +13 -0
- package/lib/components/TooltipWrapper.d.ts +25 -21
- package/lib/components/TooltipWrapper.js +11 -1
- package/lib/components/TooltipWrapper.js.map +2 -2
- package/lib/components/TransferDropDown.d.ts +85 -84
- package/lib/components/TransferDropDown.js +2 -2
- package/lib/components/TransferDropDown.js.map +2 -2
- package/lib/components/Tree.d.ts +84 -84
- package/lib/components/formula/VariableList.d.ts +1 -0
- package/lib/components/formula/VariableList.js.map +2 -2
- package/lib/components/icons.js +2 -0
- package/lib/components/icons.js.map +2 -2
- package/lib/components/index.d.ts +4 -1
- package/lib/components/index.js +7 -1
- package/lib/components/index.js.map +2 -2
- package/lib/components/schema-editor/Array.d.ts +11 -0
- package/lib/components/schema-editor/Array.js +66 -0
- package/lib/components/schema-editor/Array.js.map +13 -0
- package/lib/components/schema-editor/Common.d.ts +29 -0
- package/lib/components/schema-editor/Common.js +69 -0
- package/lib/components/schema-editor/Common.js.map +13 -0
- package/lib/components/schema-editor/Item.d.ts +9 -0
- package/lib/components/schema-editor/Item.js +31 -0
- package/lib/components/schema-editor/Item.js.map +13 -0
- package/lib/components/schema-editor/Object.d.ts +44 -0
- package/lib/components/schema-editor/Object.js +191 -0
- package/lib/components/schema-editor/Object.js.map +13 -0
- package/lib/components/schema-editor/SchemaVariableList.d.ts +316 -0
- package/lib/components/schema-editor/SchemaVariableList.js +74 -0
- package/lib/components/schema-editor/SchemaVariableList.js.map +13 -0
- package/lib/components/schema-editor/SchemaVariableListPicker.d.ts +305 -0
- package/lib/components/schema-editor/SchemaVariableListPicker.js +32 -0
- package/lib/components/schema-editor/SchemaVariableListPicker.js.map +13 -0
- package/lib/components/schema-editor/index.d.ts +520 -0
- package/lib/components/schema-editor/index.js +118 -0
- package/lib/components/schema-editor/index.js.map +13 -0
- package/lib/components/table/Cell.d.ts +930 -0
- package/lib/components/table/Cell.js +36 -0
- package/lib/components/table/Cell.js.map +13 -0
- package/lib/components/table/HeadCellDropDown.d.ts +514 -0
- package/lib/components/table/HeadCellDropDown.js +52 -0
- package/lib/components/table/HeadCellDropDown.js.map +13 -0
- package/lib/components/table/HeadCellFilter.d.ts +771 -0
- package/lib/components/table/HeadCellFilter.js +106 -0
- package/lib/components/table/HeadCellFilter.js.map +13 -0
- package/lib/components/table/HeadCellSelect.d.ts +672 -0
- package/lib/components/table/HeadCellSelect.js +46 -0
- package/lib/components/table/HeadCellSelect.js.map +13 -0
- package/lib/components/table/HeadCellSort.d.ts +498 -0
- package/lib/components/table/HeadCellSort.js +67 -0
- package/lib/components/table/HeadCellSort.js.map +13 -0
- package/lib/components/table/index.d.ts +1355 -0
- package/lib/components/table/index.js +1095 -0
- package/lib/components/table/index.js.map +13 -0
- package/lib/env.d.ts +2 -4
- package/lib/env.js.map +2 -2
- package/lib/factory.js +0 -95
- package/lib/factory.js.map +2 -2
- package/lib/icons/dot.js +11 -0
- package/lib/index.d.ts +6 -1
- package/lib/index.js +9 -2
- package/lib/index.js.map +2 -2
- package/lib/locale/de-DE.js +18 -1
- package/lib/locale/de-DE.js.map +2 -2
- package/lib/locale/en-US.js +18 -1
- package/lib/locale/en-US.js.map +2 -2
- package/lib/locale/zh-CN.js +20 -1
- package/lib/locale/zh-CN.js.map +2 -2
- package/lib/renderers/Action.js +0 -2
- package/lib/renderers/Action.js.map +2 -2
- package/lib/renderers/Carousel.d.ts +5 -1
- package/lib/renderers/Carousel.js +18 -5
- package/lib/renderers/Carousel.js.map +2 -2
- package/lib/renderers/Form/ButtonGroupSelect.d.ts +2 -0
- package/lib/renderers/Form/ButtonGroupSelect.js +7 -0
- package/lib/renderers/Form/ButtonGroupSelect.js.map +2 -2
- package/lib/renderers/Form/Checkbox.js +3 -4
- package/lib/renderers/Form/Checkbox.js.map +2 -2
- package/lib/renderers/Form/Checkboxes.d.ts +2 -1
- package/lib/renderers/Form/Checkboxes.js +19 -14
- package/lib/renderers/Form/Checkboxes.js.map +2 -2
- package/lib/renderers/Form/Combo.js +23 -4
- package/lib/renderers/Form/Combo.js.map +2 -2
- package/lib/renderers/Form/DiffEditor.d.ts +126 -18
- package/lib/renderers/Form/Editor.d.ts +412 -112
- package/lib/renderers/Form/Editor.js +10 -1
- package/lib/renderers/Form/Editor.js.map +2 -2
- package/lib/renderers/Form/InputExcel.js +6 -1
- package/lib/renderers/Form/InputExcel.js.map +2 -2
- package/lib/renderers/Form/InputFile.js +1 -2
- package/lib/renderers/Form/InputFile.js.map +2 -2
- package/lib/renderers/Form/InputTree.js +1 -1
- package/lib/renderers/Form/InputTree.js.map +2 -2
- package/lib/renderers/Form/Item.d.ts +0 -6
- package/lib/renderers/Form/JSONSchemaEditor.d.ts +41 -0
- package/lib/renderers/Form/JSONSchemaEditor.js +33 -0
- package/lib/renderers/Form/JSONSchemaEditor.js.map +13 -0
- package/lib/renderers/Form/ListSelect.d.ts +2 -0
- package/lib/renderers/Form/ListSelect.js +7 -0
- package/lib/renderers/Form/ListSelect.js.map +2 -2
- package/lib/renderers/Form/Options.js +1 -0
- package/lib/renderers/Form/Options.js.map +2 -2
- package/lib/renderers/Form/Select.js +12 -1
- package/lib/renderers/Form/Select.js.map +2 -2
- package/lib/renderers/Form/TabsTransfer.d.ts +1 -1
- package/lib/renderers/Form/TabsTransfer.js +2 -2
- package/lib/renderers/Form/TabsTransfer.js.map +2 -2
- package/lib/renderers/Form/TreeSelect.d.ts +4 -0
- package/lib/renderers/Form/TreeSelect.js +2 -2
- package/lib/renderers/Form/TreeSelect.js.map +2 -2
- package/lib/renderers/Form/wrapControl.js +10 -5
- package/lib/renderers/Form/wrapControl.js.map +2 -2
- package/lib/renderers/Pagination.d.ts +49 -30
- package/lib/renderers/Pagination.js +3 -132
- package/lib/renderers/Pagination.js.map +2 -2
- package/lib/renderers/Table/HeadCellSearchDropdown.js +0 -1
- package/lib/renderers/Table/HeadCellSearchDropdown.js.map +2 -2
- package/lib/renderers/Table-v2/HeadCellSearchDropdown.d.ts +29 -0
- package/lib/renderers/Table-v2/HeadCellSearchDropdown.js +158 -0
- package/lib/renderers/Table-v2/HeadCellSearchDropdown.js.map +13 -0
- package/lib/renderers/Table-v2/TableCell.d.ts +6 -0
- package/lib/renderers/Table-v2/TableCell.js +28 -0
- package/lib/renderers/Table-v2/TableCell.js.map +13 -0
- package/lib/renderers/Table-v2/index.d.ts +256 -0
- package/lib/renderers/Table-v2/index.js +548 -0
- package/lib/renderers/Table-v2/index.js.map +13 -0
- package/lib/renderers/Tabs.js +1 -1
- package/lib/renderers/Tabs.js.map +2 -2
- package/lib/renderers/Tag.d.ts +66 -0
- package/lib/renderers/Tag.js +53 -0
- package/lib/renderers/Tag.js.map +13 -0
- package/lib/renderers/Wizard.js +3 -3
- package/lib/renderers/Wizard.js.map +2 -2
- package/lib/schemaExtend.js +24 -30
- package/lib/schemaExtend.js.map +2 -2
- package/lib/store/combo.d.ts +140 -20
- package/lib/store/form.d.ts +56 -8
- package/lib/store/formItem.d.ts +3 -1
- package/lib/store/formItem.js +3 -1
- package/lib/store/formItem.js.map +2 -2
- package/lib/store/index.js +2 -0
- package/lib/store/index.js.map +2 -2
- package/lib/store/table-v2.d.ts +308 -0
- package/lib/store/table-v2.js +452 -0
- package/lib/store/table-v2.js.map +13 -0
- package/lib/store/table.d.ts +112 -16
- package/lib/store/table.js +1 -1
- package/lib/store/table.js.map +2 -2
- package/lib/themes/ang-ie11.css +1686 -120
- package/lib/themes/ang.css +1807 -208
- package/lib/themes/ang.css.map +1 -1
- package/lib/themes/antd-ie11.css +1667 -101
- package/lib/themes/antd.css +1789 -201
- package/lib/themes/antd.css.map +1 -1
- package/lib/themes/cxd-ie11.css +1662 -97
- package/lib/themes/cxd.css +1983 -394
- package/lib/themes/cxd.css.map +1 -1
- package/lib/themes/dark-ie11.css +1667 -101
- package/lib/themes/dark.css +1789 -201
- package/lib/themes/dark.css.map +1 -1
- package/lib/themes/default-ie11.css +1662 -97
- package/lib/themes/default.css +1983 -394
- package/lib/themes/default.css.map +1 -1
- package/lib/utils/DataSchema.d.ts +25 -0
- package/lib/utils/DataSchema.js +104 -0
- package/lib/utils/DataSchema.js.map +13 -0
- package/lib/utils/DataScope.d.ts +23 -0
- package/lib/utils/DataScope.js +140 -0
- package/lib/utils/DataScope.js.map +13 -0
- package/lib/utils/handleAction.js +1 -1
- package/lib/utils/handleAction.js.map +2 -2
- package/lib/utils/renderer-event.d.ts +8 -2
- package/lib/utils/renderer-event.js +102 -1
- package/lib/utils/renderer-event.js.map +2 -2
- package/package.json +3 -2
- package/schema.json +1476 -469
- package/scss/_properties.scss +69 -0
- package/scss/components/_button.scss +37 -39
- package/scss/components/_context-menu.scss +3 -18
- package/scss/components/_json-schema-editor.scss +126 -0
- package/scss/components/_pagination.scss +104 -23
- package/scss/components/_result-box.scss +2 -2
- package/scss/components/_table-v2.scss +912 -0
- package/scss/components/_tag.scss +177 -0
- package/scss/components/form/_selection.scss +1 -14
- package/scss/components/form/_text.scss +1 -1
- package/scss/themes/_antd-variables.scss +0 -13
- package/scss/themes/_common.scss +3 -0
- package/scss/themes/_cxd-variables.scss +7 -17
- package/scss/themes/_dark-variables.scss +0 -13
- package/scss/themes/cxd.scss +1 -1
- package/sdk/ang-ie11.css +2240 -227
- package/sdk/ang.css +2905 -859
- package/sdk/antd-ie11.css +2233 -220
- package/sdk/antd.css +2905 -870
- package/sdk/barcode.js +51 -51
- package/sdk/charts.js +14 -14
- package/sdk/codemirror.js +7 -7
- package/sdk/color-picker.js +65 -65
- package/sdk/cropperjs.js +2 -2
- package/sdk/cxd-ie11.css +2223 -211
- package/sdk/cxd.css +2911 -875
- package/sdk/dark-ie11.css +2233 -220
- package/sdk/dark.css +2905 -870
- package/sdk/exceljs.js +1 -1
- package/sdk/locale/de-DE.js +18 -1
- package/sdk/markdown.js +69 -69
- package/sdk/papaparse.js +1 -1
- package/sdk/renderers/Form/CityDB.js +1 -1
- package/sdk/rest.js +16 -16
- package/sdk/rich-text.js +62 -62
- package/sdk/sdk-ie11.css +2223 -211
- package/sdk/sdk.css +2911 -875
- package/sdk/sdk.js +1326 -1270
- package/sdk/thirds/hls.js/hls.js +1 -1
- package/sdk/thirds/mpegts.js/mpegts.js +1 -1
- package/sdk/tinymce.js +57 -57
- package/src/Schema.ts +7 -0
- package/src/SchemaRenderer.tsx +4 -5
- package/src/actions/Action.ts +7 -6
- package/src/actions/AjaxAction.ts +33 -24
- package/src/actions/BreakAction.ts +2 -2
- package/src/actions/BroadcastAction.ts +6 -5
- package/src/actions/CmptAction.ts +5 -6
- package/src/actions/ContinueAction.ts +2 -2
- package/src/actions/CopyAction.ts +14 -8
- package/src/actions/CustomAction.ts +2 -2
- package/src/actions/DialogAction.ts +16 -10
- package/src/actions/DrawerAction.ts +3 -3
- package/src/actions/EmailAction.ts +12 -12
- package/src/actions/LinkAction.ts +34 -14
- package/src/actions/LoopAction.ts +13 -8
- package/src/actions/PageAction.ts +9 -6
- package/src/actions/ParallelAction.ts +2 -2
- package/src/actions/SwitchAction.ts +2 -2
- package/src/actions/ToastAction.ts +9 -5
- package/src/components/InputBox.tsx +1 -0
- package/src/components/Pagination.tsx +446 -0
- package/src/components/PickerContainer.tsx +8 -5
- package/src/components/Rating.tsx +16 -9
- package/src/components/Select.tsx +3 -3
- package/src/components/Tag.tsx +179 -0
- package/src/components/TooltipWrapper.tsx +14 -1
- package/src/components/TransferDropDown.tsx +3 -0
- package/src/components/formula/VariableList.tsx +1 -0
- package/src/components/icons.tsx +2 -0
- package/src/components/index.tsx +7 -1
- package/src/components/schema-editor/Array.tsx +95 -0
- package/src/components/schema-editor/Common.tsx +138 -0
- package/src/components/schema-editor/Item.tsx +36 -0
- package/src/components/schema-editor/Object.tsx +299 -0
- package/src/components/schema-editor/SchemaVariableList.tsx +97 -0
- package/src/components/schema-editor/SchemaVariableListPicker.tsx +66 -0
- package/src/components/schema-editor/index.tsx +211 -0
- package/src/components/table/Cell.tsx +70 -0
- package/src/components/table/HeadCellDropDown.tsx +115 -0
- package/src/components/table/HeadCellFilter.tsx +193 -0
- package/src/components/table/HeadCellSelect.tsx +86 -0
- package/src/components/table/HeadCellSort.tsx +102 -0
- package/src/components/table/index.tsx +1681 -0
- package/src/env.tsx +7 -14
- package/src/factory.tsx +3 -106
- package/src/icons/dot.svg +11 -0
- package/src/index.tsx +8 -1
- package/src/locale/de-DE.ts +18 -1
- package/src/locale/en-US.ts +18 -1
- package/src/locale/zh-CN.ts +20 -1
- package/src/renderers/Action.tsx +1 -1
- package/src/renderers/Carousel.tsx +21 -6
- package/src/renderers/Form/ButtonGroupSelect.tsx +10 -1
- package/src/renderers/Form/Checkbox.tsx +4 -4
- package/src/renderers/Form/Checkboxes.tsx +31 -25
- package/src/renderers/Form/Combo.tsx +20 -4
- package/src/renderers/Form/Editor.tsx +15 -1
- package/src/renderers/Form/InputExcel.tsx +6 -1
- package/src/renderers/Form/InputFile.tsx +1 -2
- package/src/renderers/Form/InputTree.tsx +1 -1
- package/src/renderers/Form/JSONSchemaEditor.tsx +67 -0
- package/src/renderers/Form/ListSelect.tsx +9 -1
- package/src/renderers/Form/Options.tsx +1 -1
- package/src/renderers/Form/Select.tsx +7 -0
- package/src/renderers/Form/TabsTransfer.tsx +2 -2
- package/src/renderers/Form/TreeSelect.tsx +8 -1
- package/src/renderers/Form/wrapControl.tsx +11 -5
- package/src/renderers/Pagination.tsx +65 -253
- package/src/renderers/Table/HeadCellSearchDropdown.tsx +0 -1
- package/src/renderers/Table-v2/HeadCellSearchDropdown.tsx +244 -0
- package/src/renderers/Table-v2/TableCell.tsx +19 -0
- package/src/renderers/Table-v2/index.tsx +1140 -0
- package/src/renderers/Tabs.tsx +1 -1
- package/src/renderers/Tag.tsx +128 -0
- package/src/renderers/Wizard.tsx +3 -3
- package/src/schemaExtend.ts +24 -28
- package/src/store/formItem.ts +5 -1
- package/src/store/index.ts +2 -0
- package/src/store/table-v2.ts +646 -0
- package/src/store/table.ts +1 -1
- package/src/utils/DataSchema.ts +131 -0
- package/src/utils/DataScope.ts +190 -0
- package/src/utils/handleAction.ts +1 -1
- package/src/utils/renderer-event.ts +113 -2
@@ -0,0 +1,131 @@
|
|
1
|
+
import {DataScope} from './DataScope';
|
2
|
+
import type {JSONSchema} from './DataScope';
|
3
|
+
import {guid} from './helper';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* 用来定义数据本身的数据结构,比如有类型是什么,有哪些属性。
|
7
|
+
*/
|
8
|
+
export class DataSchema {
|
9
|
+
// 指向顶级数据作用域
|
10
|
+
readonly root: DataScope;
|
11
|
+
|
12
|
+
readonly idMap: {
|
13
|
+
[propName: string]: DataScope;
|
14
|
+
} = {};
|
15
|
+
|
16
|
+
// 这个经常变动,游离于整个链中
|
17
|
+
current: DataScope;
|
18
|
+
|
19
|
+
constructor(schema: JSONSchema | Array<JSONSchema>) {
|
20
|
+
this.root = new DataScope(schema, 'root');
|
21
|
+
this.idMap['root'] = this.root;
|
22
|
+
this.current = this.root;
|
23
|
+
}
|
24
|
+
|
25
|
+
setSchema(schemas: Array<JSONSchema>) {
|
26
|
+
this.current.setSchemas(schemas);
|
27
|
+
return this;
|
28
|
+
}
|
29
|
+
|
30
|
+
addSchema(schema: JSONSchema) {
|
31
|
+
this.current.addSchema(schema);
|
32
|
+
return this;
|
33
|
+
}
|
34
|
+
|
35
|
+
removeSchema(id: string) {
|
36
|
+
this.current.removeSchema(id);
|
37
|
+
delete this.idMap[id];
|
38
|
+
return this;
|
39
|
+
}
|
40
|
+
|
41
|
+
getSchemas() {
|
42
|
+
const schemas: Array<JSONSchema> = [];
|
43
|
+
let current: DataScope | void = this.current;
|
44
|
+
|
45
|
+
while (current) {
|
46
|
+
schemas.push(...current.schemas);
|
47
|
+
current = current.parent;
|
48
|
+
}
|
49
|
+
|
50
|
+
return schemas;
|
51
|
+
}
|
52
|
+
|
53
|
+
addScope(schema?: JSONSchema | Array<JSONSchema>, id: string = guid()) {
|
54
|
+
if (this.idMap[id]) {
|
55
|
+
throw new Error('scope id `' + id + '` already exists');
|
56
|
+
}
|
57
|
+
|
58
|
+
this.current = this.current.addChild(id, schema);
|
59
|
+
this.idMap[id] = this.current;
|
60
|
+
return this;
|
61
|
+
}
|
62
|
+
|
63
|
+
removeScope(idOrScope: string | DataScope) {
|
64
|
+
const scope = this.getScope(idOrScope);
|
65
|
+
|
66
|
+
if (!scope.parent) {
|
67
|
+
throw new Error('cannot remove root scope');
|
68
|
+
}
|
69
|
+
|
70
|
+
if (scope.contains(this.current)) {
|
71
|
+
this.current = scope.parent!;
|
72
|
+
}
|
73
|
+
|
74
|
+
scope.parent?.removeChild(scope);
|
75
|
+
return this;
|
76
|
+
}
|
77
|
+
|
78
|
+
hasScope(idOrScope: string | DataScope): idOrScope is string | DataScope {
|
79
|
+
const id = typeof idOrScope === 'string' ? idOrScope : idOrScope.id;
|
80
|
+
const scope = this.idMap[id];
|
81
|
+
return !!scope;
|
82
|
+
}
|
83
|
+
|
84
|
+
getScope(idOrScope: string | DataScope) {
|
85
|
+
const id = typeof idOrScope === 'string' ? idOrScope : idOrScope.id;
|
86
|
+
const scope = this.idMap[id];
|
87
|
+
|
88
|
+
if (!scope) {
|
89
|
+
throw new Error('scope not found!');
|
90
|
+
}
|
91
|
+
|
92
|
+
return scope;
|
93
|
+
}
|
94
|
+
|
95
|
+
switchToRoot() {
|
96
|
+
this.current = this.root;
|
97
|
+
return this;
|
98
|
+
}
|
99
|
+
|
100
|
+
switchTo(idOrScope: string | DataScope) {
|
101
|
+
const scope = this.getScope(idOrScope);
|
102
|
+
this.current = scope;
|
103
|
+
return this;
|
104
|
+
}
|
105
|
+
|
106
|
+
getDataPropsAsOptions() {
|
107
|
+
const variables: Array<any> = [];
|
108
|
+
let current: DataScope | void = this.current;
|
109
|
+
|
110
|
+
while (current) {
|
111
|
+
variables.push(...current.getDataPropsAsOptions());
|
112
|
+
current = current.parent;
|
113
|
+
}
|
114
|
+
|
115
|
+
return variables;
|
116
|
+
}
|
117
|
+
|
118
|
+
getSchemaByPath(path: string) {
|
119
|
+
let current: DataScope | void = this.current;
|
120
|
+
|
121
|
+
while (current) {
|
122
|
+
const schema = current.getSchemaByPath(path);
|
123
|
+
if (schema) {
|
124
|
+
return schema;
|
125
|
+
}
|
126
|
+
current = current.parent;
|
127
|
+
}
|
128
|
+
|
129
|
+
return null;
|
130
|
+
}
|
131
|
+
}
|
@@ -0,0 +1,190 @@
|
|
1
|
+
import type {JSONSchema7} from 'json-schema';
|
2
|
+
import {guid, keyToPath} from './helper';
|
3
|
+
|
4
|
+
// 先只支持 JSONSchema draft07 好了
|
5
|
+
// https://json-schema.org/draft-07/json-schema-release-notes.html
|
6
|
+
export type JSONSchema = JSONSchema7;
|
7
|
+
|
8
|
+
export class DataScope {
|
9
|
+
// 指向父级
|
10
|
+
parent?: DataScope;
|
11
|
+
readonly children: Array<DataScope> = [];
|
12
|
+
|
13
|
+
// 全局不能重复,用来快速定位
|
14
|
+
readonly id: string;
|
15
|
+
|
16
|
+
// todo 如果想要跨过层级直接获取某一层的数据域,用这个字段
|
17
|
+
ref?: string;
|
18
|
+
|
19
|
+
// scope 的名字,同一个层级不允许重名
|
20
|
+
name?: string;
|
21
|
+
|
22
|
+
// scope 分类
|
23
|
+
tag?: string;
|
24
|
+
|
25
|
+
// scope 的描述信息
|
26
|
+
description?: string;
|
27
|
+
|
28
|
+
readonly schemas: Array<JSONSchema> = [];
|
29
|
+
|
30
|
+
constructor(schemas: JSONSchema | Array<JSONSchema>, id: string) {
|
31
|
+
this.setSchemas(Array.isArray(schemas) ? schemas : [schemas]);
|
32
|
+
this.id = id;
|
33
|
+
}
|
34
|
+
|
35
|
+
addChild(id: string, schema?: JSONSchema | Array<JSONSchema>): DataScope {
|
36
|
+
const child = new DataScope(
|
37
|
+
schema || {
|
38
|
+
type: 'object',
|
39
|
+
properties: {}
|
40
|
+
},
|
41
|
+
id
|
42
|
+
);
|
43
|
+
|
44
|
+
this.children.push(child);
|
45
|
+
child.parent = this;
|
46
|
+
return child;
|
47
|
+
}
|
48
|
+
|
49
|
+
removeChild(idOrScope: string | DataScope) {
|
50
|
+
const idx = this.children.findIndex(item =>
|
51
|
+
typeof idOrScope === 'string'
|
52
|
+
? idOrScope === item.id
|
53
|
+
: idOrScope === idOrScope
|
54
|
+
);
|
55
|
+
|
56
|
+
if (~idx) {
|
57
|
+
const scope = this.children[idx];
|
58
|
+
delete scope.parent;
|
59
|
+
this.children.splice(idx, 1);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
setSchemas(schemas: Array<JSONSchema>) {
|
64
|
+
this.schemas.splice(0, this.schemas.length);
|
65
|
+
|
66
|
+
for (let schema of schemas) {
|
67
|
+
if (schema.type !== 'object') {
|
68
|
+
throw new TypeError('data scope accept only object');
|
69
|
+
}
|
70
|
+
this.schemas.push({
|
71
|
+
$id: guid(),
|
72
|
+
...schema
|
73
|
+
});
|
74
|
+
}
|
75
|
+
return this;
|
76
|
+
}
|
77
|
+
|
78
|
+
addSchema(schema: JSONSchema) {
|
79
|
+
schema = {
|
80
|
+
$id: guid(),
|
81
|
+
...schema
|
82
|
+
};
|
83
|
+
this.schemas.push(schema);
|
84
|
+
return this;
|
85
|
+
}
|
86
|
+
|
87
|
+
removeSchema(id: string) {
|
88
|
+
const idx = this.schemas.findIndex(schema => schema.$id === id);
|
89
|
+
if (~idx) {
|
90
|
+
this.schemas.splice(idx, 1);
|
91
|
+
}
|
92
|
+
return this;
|
93
|
+
}
|
94
|
+
|
95
|
+
contains(scope: DataScope) {
|
96
|
+
let from: DataScope | undefined = scope;
|
97
|
+
while (from) {
|
98
|
+
if (this === from) {
|
99
|
+
return true;
|
100
|
+
}
|
101
|
+
from = from.parent;
|
102
|
+
}
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
|
106
|
+
getMergedSchema() {
|
107
|
+
const mergedSchema: any = {
|
108
|
+
type: 'object',
|
109
|
+
properties: {}
|
110
|
+
};
|
111
|
+
|
112
|
+
// todo 以后再来细化这一块,先粗略的写个大概
|
113
|
+
this.schemas.forEach(schema => {
|
114
|
+
const properties: any = schema.properties || {};
|
115
|
+
Object.keys(properties).forEach(key => {
|
116
|
+
const value = properties[key];
|
117
|
+
if (mergedSchema.properties[key]) {
|
118
|
+
if (Array.isArray(mergedSchema.properties[key].oneOf)) {
|
119
|
+
mergedSchema.properties[key].oneOf.push();
|
120
|
+
} else if (
|
121
|
+
mergedSchema.properties[key].type &&
|
122
|
+
mergedSchema.properties[key].type !== value.type
|
123
|
+
) {
|
124
|
+
mergedSchema.properties[key] = {
|
125
|
+
oneOf: [mergedSchema.properties[key], value]
|
126
|
+
};
|
127
|
+
}
|
128
|
+
} else {
|
129
|
+
mergedSchema.properties[key] = value;
|
130
|
+
}
|
131
|
+
});
|
132
|
+
});
|
133
|
+
|
134
|
+
return mergedSchema;
|
135
|
+
}
|
136
|
+
|
137
|
+
protected buildOptions(
|
138
|
+
options: Array<any>,
|
139
|
+
schema: JSONSchema,
|
140
|
+
path: string
|
141
|
+
) {
|
142
|
+
if (schema.type === 'object' && schema.properties) {
|
143
|
+
const keys = Object.keys(schema.properties);
|
144
|
+
|
145
|
+
keys.forEach(key => {
|
146
|
+
const child: any = schema.properties![key];
|
147
|
+
|
148
|
+
// todo 支持 oneOf, anyOf
|
149
|
+
const option: any = {
|
150
|
+
label: child.title || key,
|
151
|
+
value: path + key,
|
152
|
+
type: child.type,
|
153
|
+
description: child.description
|
154
|
+
};
|
155
|
+
|
156
|
+
if (child.type === 'object') {
|
157
|
+
option.children = [];
|
158
|
+
this.buildOptions(option.children, child, path + key + '.');
|
159
|
+
}
|
160
|
+
|
161
|
+
options.push(option);
|
162
|
+
});
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
getDataPropsAsOptions() {
|
167
|
+
const variables: Array<any> = [];
|
168
|
+
this.buildOptions(variables, this.getMergedSchema(), '');
|
169
|
+
return variables;
|
170
|
+
}
|
171
|
+
|
172
|
+
getSchemaByPath(path: string) {
|
173
|
+
const parts = keyToPath(path);
|
174
|
+
|
175
|
+
for (let schema of this.schemas) {
|
176
|
+
const result = parts.reduce((schema: JSONSchema, key: string) => {
|
177
|
+
if (schema && schema.type === 'object' && schema.properties) {
|
178
|
+
return schema.properties[key] as JSONSchema;
|
179
|
+
}
|
180
|
+
|
181
|
+
return null;
|
182
|
+
}, schema);
|
183
|
+
|
184
|
+
if (result) {
|
185
|
+
return result;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
return null;
|
189
|
+
}
|
190
|
+
}
|
@@ -13,7 +13,7 @@ export default function handleAction(
|
|
13
13
|
data?: any
|
14
14
|
) {
|
15
15
|
// https://reactjs.org/docs/legacy-event-pooling.html
|
16
|
-
e.persist();
|
16
|
+
// e.persist(); // react 17之后去掉 event pooling 了,这个应该没用了
|
17
17
|
|
18
18
|
const onAction = props.onAction;
|
19
19
|
let onClick: any = action.onClick;
|
@@ -1,4 +1,6 @@
|
|
1
|
-
import {ListenerAction, ListenerContext} from '../actions/Action';
|
1
|
+
import {ListenerAction, ListenerContext, runActions} from '../actions/Action';
|
2
|
+
import {RendererProps} from '../factory';
|
3
|
+
import {IScopedContext} from '../Scoped';
|
2
4
|
|
3
5
|
// 事件监听器
|
4
6
|
export interface EventListeners {
|
@@ -20,7 +22,7 @@ export interface OnEventProps {
|
|
20
22
|
|
21
23
|
// 渲染器事件监听器
|
22
24
|
export interface RendererEventListener {
|
23
|
-
renderer:
|
25
|
+
renderer: React.Component<RendererProps>;
|
24
26
|
type: string;
|
25
27
|
weight: number;
|
26
28
|
actions: ListenerAction[];
|
@@ -43,6 +45,8 @@ export interface RendererEventContext {
|
|
43
45
|
[propName: string]: any;
|
44
46
|
}
|
45
47
|
|
48
|
+
let rendererEventListeners: RendererEventListener[] = [];
|
49
|
+
|
46
50
|
// 创建渲染器事件对象
|
47
51
|
export function createRendererEvent<T extends RendererEventContext>(
|
48
52
|
type: string,
|
@@ -72,4 +76,111 @@ export function createRendererEvent<T extends RendererEventContext>(
|
|
72
76
|
return rendererEvent;
|
73
77
|
}
|
74
78
|
|
79
|
+
// 绑定事件
|
80
|
+
export const bindEvent = (renderer: any) => {
|
81
|
+
if (!renderer) {
|
82
|
+
return undefined;
|
83
|
+
}
|
84
|
+
const listeners: EventListeners = renderer.props.$schema.onEvent;
|
85
|
+
if (listeners) {
|
86
|
+
// 暂存
|
87
|
+
for (let key of Object.keys(listeners)) {
|
88
|
+
const listener = rendererEventListeners.some(
|
89
|
+
(item: RendererEventListener) =>
|
90
|
+
item.renderer === renderer && item.type === key
|
91
|
+
);
|
92
|
+
if (!listener) {
|
93
|
+
rendererEventListeners.push({
|
94
|
+
renderer,
|
95
|
+
type: key,
|
96
|
+
weight: listeners[key].weight || 0,
|
97
|
+
actions: listeners[key].actions
|
98
|
+
});
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
return () => {
|
103
|
+
rendererEventListeners = rendererEventListeners.filter(
|
104
|
+
(item: RendererEventListener) => item.renderer !== renderer
|
105
|
+
);
|
106
|
+
};
|
107
|
+
}
|
108
|
+
|
109
|
+
return undefined;
|
110
|
+
};
|
111
|
+
|
112
|
+
// 触发事件
|
113
|
+
export async function dispatchEvent(
|
114
|
+
e: string | React.MouseEvent<any>,
|
115
|
+
renderer: React.Component<RendererProps>,
|
116
|
+
scoped: IScopedContext,
|
117
|
+
data: any,
|
118
|
+
broadcast?: RendererEvent<any>
|
119
|
+
): Promise<RendererEvent<any> | void> {
|
120
|
+
let unbindEvent = null;
|
121
|
+
const eventName = typeof e === 'string' ? e : e.type;
|
122
|
+
|
123
|
+
renderer?.props?.env?.beforeDispatchEvent?.(
|
124
|
+
e,
|
125
|
+
renderer,
|
126
|
+
scoped,
|
127
|
+
data,
|
128
|
+
broadcast
|
129
|
+
);
|
130
|
+
|
131
|
+
if (!broadcast) {
|
132
|
+
const eventConfig = renderer?.props?.onEvent?.[eventName];
|
133
|
+
|
134
|
+
if (!eventConfig) {
|
135
|
+
// 没命中也没关系
|
136
|
+
return Promise.resolve();
|
137
|
+
}
|
138
|
+
|
139
|
+
unbindEvent = bindEvent(renderer);
|
140
|
+
}
|
141
|
+
|
142
|
+
// 没有可处理的监听
|
143
|
+
if (!rendererEventListeners.length) {
|
144
|
+
return Promise.resolve();
|
145
|
+
}
|
146
|
+
// 如果是广播动作,就直接复用
|
147
|
+
const rendererEvent =
|
148
|
+
broadcast ||
|
149
|
+
createRendererEvent(eventName, {
|
150
|
+
env: renderer?.props?.env,
|
151
|
+
nativeEvent: e,
|
152
|
+
data,
|
153
|
+
scoped
|
154
|
+
});
|
155
|
+
|
156
|
+
// 过滤&排序
|
157
|
+
const listeners = rendererEventListeners
|
158
|
+
.filter(
|
159
|
+
(item: RendererEventListener) =>
|
160
|
+
item.type === eventName &&
|
161
|
+
(broadcast ? true : item.renderer === renderer)
|
162
|
+
)
|
163
|
+
.sort(
|
164
|
+
(prev: RendererEventListener, next: RendererEventListener) =>
|
165
|
+
next.weight - prev.weight
|
166
|
+
);
|
167
|
+
|
168
|
+
for (let listener of listeners) {
|
169
|
+
await runActions(listener.actions, listener.renderer, rendererEvent);
|
170
|
+
|
171
|
+
// 停止后续监听器执行
|
172
|
+
if (rendererEvent.stoped) {
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
unbindEvent?.();
|
178
|
+
|
179
|
+
return Promise.resolve(rendererEvent);
|
180
|
+
}
|
181
|
+
|
182
|
+
export const getRendererEventListeners = () => {
|
183
|
+
return rendererEventListeners;
|
184
|
+
};
|
185
|
+
|
75
186
|
export default {};
|