@cicctencent/low-code-editor 0.0.0-stage → 1.1.9-beta.5

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.
Files changed (97) hide show
  1. package/README.md +2 -2
  2. package/api-extractor.json +36 -0
  3. package/dist/ActivityBar/index.vue.d.ts +29 -0
  4. package/dist/ComponentTree/components/List.vue.d.ts +29 -0
  5. package/dist/ComponentTree/index.vue.d.ts +32 -0
  6. package/dist/DataSource/index.vue.d.ts +34 -0
  7. package/dist/HeaderBar/components/BarTooltip.vue.d.ts +37 -0
  8. package/dist/HeaderBar/index.vue.d.ts +49 -0
  9. package/dist/NavTree/index.vue.d.ts +48 -0
  10. package/dist/SchemaConfig/index.vue.d.ts +36 -0
  11. package/dist/SidebarPane/index.vue.d.ts +38 -0
  12. package/dist/components/ComponentTreeFavorites/components/List.vue.d.ts +41 -0
  13. package/dist/components/ComponentTreeFavorites/components/Tips.vue.d.ts +16 -0
  14. package/dist/components/ComponentTreeFavorites/index.vue.d.ts +44 -0
  15. package/dist/components/ImageGuide/index.vue.d.ts +45 -0
  16. package/dist/components.d.ts +7 -0
  17. package/dist/composables/useComponentTree.d.ts +13 -0
  18. package/dist/config/ace.config.d.ts +3 -0
  19. package/dist/domain/EditorDomain.d.ts +89 -0
  20. package/dist/editor.d.ts +286 -0
  21. package/dist/editor.vue.d.ts +104 -0
  22. package/dist/formily/ActivityBar/index.d.ts +4 -0
  23. package/dist/formily/ComponentTree/index.d.ts +4 -0
  24. package/dist/formily/DataBinding/index.d.ts +4 -0
  25. package/dist/formily/DataBinding/index.vue.d.ts +26 -0
  26. package/dist/formily/DataSource/index.d.ts +4 -0
  27. package/dist/formily/MenuTable/PageList.vue.d.ts +28 -0
  28. package/dist/formily/MenuTable/index.d.ts +4 -0
  29. package/dist/formily/MenuTable/index.vue.d.ts +30 -0
  30. package/dist/formily/MenuTable/useMenuTable.d.ts +227 -0
  31. package/dist/formily/NavTree/index.d.ts +4 -0
  32. package/dist/formily/SidebarPane/index.d.ts +4 -0
  33. package/dist/formily/index.d.ts +2 -0
  34. package/dist/index.css +1167 -0
  35. package/dist/index.d.ts +250 -0
  36. package/dist/index.js +34171 -0
  37. package/dist/utils/base64.d.ts +4 -0
  38. package/dist/utils/index.d.ts +27 -0
  39. package/package.json +58 -4
  40. package/rollup.config.js +3 -0
  41. package/src/ActivityBar/index.vue +71 -0
  42. package/src/ComponentTree/components/List.vue +310 -0
  43. package/src/ComponentTree/index.vue +77 -0
  44. package/src/DataSource/index.vue +640 -0
  45. package/src/HeaderBar/components/BarDialog.vue +43 -0
  46. package/src/HeaderBar/components/BarTooltip.vue +33 -0
  47. package/src/HeaderBar/index.vue +513 -0
  48. package/src/NavTree/index.vue +345 -0
  49. package/src/SchemaConfig/index.vue +150 -0
  50. package/src/SidebarPane/index.vue +199 -0
  51. package/src/SynBarComponent/index.vue +31 -0
  52. package/src/assets/font/NotoSansSC.ttf +0 -0
  53. package/src/assets/img/header/edit.png +0 -0
  54. package/src/assets/img/header/link.png +0 -0
  55. package/src/assets/img/header/link.svg +9 -0
  56. package/src/assets/img/header/preview.png +0 -0
  57. package/src/assets/img/header/preview.svg +9 -0
  58. package/src/assets/img/header/redo.svg +1 -0
  59. package/src/assets/img/header/undo.svg +1 -0
  60. package/src/assets/img/tool/all-select.svg +9 -0
  61. package/src/assets/img/tool/all.svg +9 -0
  62. package/src/assets/img/tool/collect.svg +6 -0
  63. package/src/assets/img/tool/collection-select.svg +3 -0
  64. package/src/assets/img/tool/collection-tag.svg +5 -0
  65. package/src/assets/img/tool/info.svg +4 -0
  66. package/src/assets/img/tool/union.svg +4 -0
  67. package/src/components/ComponentTreeFavorites/components/List.vue +452 -0
  68. package/src/components/ComponentTreeFavorites/components/Tips.vue +108 -0
  69. package/src/components/ComponentTreeFavorites/index.vue +180 -0
  70. package/src/components/ImageGuide/index.vue +100 -0
  71. package/src/components.ts +23 -0
  72. package/src/composables/useComponentTree.ts +38 -0
  73. package/src/config/ace.config.ts +22 -0
  74. package/src/domain/EditorDomain.ts +265 -0
  75. package/src/editor.ts +645 -0
  76. package/src/editor.vue +380 -0
  77. package/src/formily/ActivityBar/index.ts +23 -0
  78. package/src/formily/ActivityBar/index.vue +121 -0
  79. package/src/formily/ComponentTree/index.ts +22 -0
  80. package/src/formily/DataBinding/index.ts +22 -0
  81. package/src/formily/DataBinding/index.vue +285 -0
  82. package/src/formily/DataSource/index.ts +22 -0
  83. package/src/formily/MenuTable/PageList.vue +132 -0
  84. package/src/formily/MenuTable/index.ts +19 -0
  85. package/src/formily/MenuTable/index.vue +218 -0
  86. package/src/formily/MenuTable/useMenuTable.ts +147 -0
  87. package/src/formily/NavTree/index.ts +20 -0
  88. package/src/formily/SidebarPane/index.ts +23 -0
  89. package/src/formily/SidebarPane/index.vue +174 -0
  90. package/src/formily/index.ts +12 -0
  91. package/src/index.ts +29 -0
  92. package/src/typings/vue-shim.d.ts +13 -0
  93. package/src/utils/base64.ts +5 -0
  94. package/src/utils/index.ts +57 -0
  95. package/test/case.ts +67 -0
  96. package/test/utils/index.test.ts +27 -0
  97. package/tsconfig.json +8 -0
@@ -0,0 +1,265 @@
1
+ // 编辑器
2
+ import {
3
+ log,
4
+ Entity,
5
+ toPlainObject,
6
+ isEqual,
7
+ isPlainObject,
8
+ } from '@jt/ark-util';
9
+ import { Communicator } from '@jt/postmessage-channel';
10
+
11
+ import { CheckResponseItem, EditorConfig, LowCodeKey } from '@jt/low-code-core';
12
+
13
+ const logTag = '[low-code-editor EditorDomain]';
14
+ const logInfo = log(logTag);
15
+
16
+ /**
17
+ * @public
18
+ */
19
+ export interface EditorDomainState {
20
+ /**
21
+ * @public 项目数据
22
+ */
23
+ project: any;
24
+ /**
25
+ * @public
26
+ * 编辑器展示配置
27
+ */
28
+ config: EditorConfig;
29
+ /**
30
+ * @public
31
+ * 用于和模拟器通讯的通讯器
32
+ */
33
+ communicator: Communicator;
34
+ /**
35
+ * @public
36
+ * 用于数据请求
37
+ */
38
+ request: Function;
39
+ }
40
+ export default class EditorDomain extends Entity<EditorDomainState> {
41
+ // 初始化标识,update触发后再触发set
42
+ initFlag = false;
43
+ constructor(state: EditorDomainState) {
44
+ super(state);
45
+ this.state = state;
46
+ Object.entries(this.subscribe).forEach(([key, value]) => {
47
+ this.state.communicator.subscribe(key, value.bind(this));
48
+ });
49
+ }
50
+ /* 模拟器返回的是配置数据时直接调用这个方法 */
51
+ /**
52
+ * @public
53
+ * @param cmd 命令字
54
+ * @param payload 传输内容
55
+ * @returns
56
+ */
57
+ async commit(cmd, payload) {
58
+ logInfo('publish begin', cmd, payload);
59
+ const { data, ret } = await this.state.communicator.publish(
60
+ cmd,
61
+ toPlainObject(payload)
62
+ );
63
+ logInfo('publish end', cmd, payload, data);
64
+ // update方法已经更新过了 这里不必再更新 -> addHistory会判断前后数据是否变化 但是点击导航树不会改变数据 所以无法更新配置
65
+ if (ret === 0 && data && typeof data === 'object' && 'schemaData' in data) {
66
+ this.setConfig(data);
67
+ }
68
+ return data;
69
+ }
70
+ // 需要更新schema的情况
71
+ needRefreshSchema(newObj: any, oldObj: any) {
72
+ if (!newObj || !oldObj) {
73
+ return false;
74
+ }
75
+ if (Object.keys(newObj).length !== Object.keys(oldObj).length) return true;
76
+ for (const key of Object.keys(newObj)) {
77
+ if (Array.isArray(newObj[key])) {
78
+ // 数组长度不一样,或者一个是数组 一个非数组 需要更新表单
79
+ if (
80
+ !Array.isArray(oldObj[key]) ||
81
+ newObj[key].length !== oldObj[key].length
82
+ ) {
83
+ return true;
84
+ }
85
+ } else if (isPlainObject(newObj[key])) {
86
+ if (this.needRefreshSchema(newObj[key], oldObj[key])) {
87
+ return true;
88
+ }
89
+ }
90
+ }
91
+ return false;
92
+ }
93
+ /**
94
+ * @public
95
+ * @param newConfig 新配置
96
+ * @param refresh 是否强制刷新
97
+ * @returns
98
+ */
99
+ setConfig(newConfig, refresh = false) {
100
+ if (!newConfig || !('schemaData' in newConfig)) {
101
+ return;
102
+ }
103
+ newConfig = { ...this.state.config, ...newConfig };
104
+ if (refresh) {
105
+ this.state.config = newConfig;
106
+ return;
107
+ }
108
+ const config = { ...this.state.config };
109
+
110
+ // 两个对象相同,不需要更新
111
+ if (isEqual(toPlainObject(config), toPlainObject(newConfig))) {
112
+ return;
113
+ }
114
+
115
+ for (const key of Object.keys(newConfig)) {
116
+ if (!isEqual(config[key], newConfig[key])) {
117
+ if (
118
+ key === 'schemaData' &&
119
+ isEqual(config[key]?.key, newConfig[key]?.key)
120
+ ) {
121
+ // 判断初始化的场景 (不要直接写在if里,那样写不方便调试)
122
+ const dataRes = this.needRefreshSchema(
123
+ newConfig[key]?.data,
124
+ config[key]?.data
125
+ );
126
+ const schemaRes = this.needRefreshSchema(
127
+ newConfig[key]?.schema,
128
+ config[key]?.schema
129
+ );
130
+ if (!dataRes && !schemaRes) {
131
+ // 表单数据变化不需要重新渲染表单,数组变化除外。解决边输入表单边更新的问题
132
+ if (
133
+ !isEqual(config[key]?.data, {}) &&
134
+ !isEqual(newConfig[key]?.data, {})
135
+ ) {
136
+ continue;
137
+ }
138
+ }
139
+ }
140
+ config[key] = newConfig[key];
141
+ }
142
+ }
143
+ this.state.config = config;
144
+ }
145
+
146
+ publish = {
147
+ // project数据初始化成功,把数据传给模拟器
148
+ init: () => this.commit('init', this.state.project),
149
+ // 编辑器元素被点击,通知模拟器 value: 当前元素相关的value
150
+ click: (key: LowCodeKey, value: any) =>
151
+ this.commit('click', {
152
+ key,
153
+ value,
154
+ }),
155
+ // 拖拽组件到模拟器区域 value: {x, y, component}
156
+ drag: (key: LowCodeKey, { x, y, name }: any) =>
157
+ this.commit('drag', {
158
+ key,
159
+ value: { x, y, name },
160
+ }),
161
+ // 设置组件数据 在Schema表单数据变化时
162
+ set: (key: LowCodeKey, value: any) => {
163
+ if (!this.initFlag) {
164
+ return;
165
+ }
166
+ return this.commit('set', {
167
+ key,
168
+ value,
169
+ });
170
+ },
171
+ // 在NavTree选中元素右键 value: 当前元素相关的value
172
+ contextmenu: async (key: LowCodeKey, value: any): Promise<void> => {
173
+ const {
174
+ data: { config, menus },
175
+ } = await this.state.communicator.publish(
176
+ 'contextmenu',
177
+ toPlainObject({ key, value })
178
+ );
179
+ logInfo('contextmenu', key, menus);
180
+ this.setConfig(config);
181
+ // 从模拟器拿到菜单数据后在编辑器中监听contextmenu事件获取它
182
+ this.emit('contextmenu', menus);
183
+ },
184
+ // 让模拟器检查数据
185
+ validate: async (
186
+ responseItem: CheckResponseItem[] = null
187
+ ): Promise<any> => {
188
+ const {
189
+ data: { config, result },
190
+ } = await this.state.communicator.publish('validate', responseItem);
191
+ logInfo('validate', result);
192
+ if (!isEqual(config, this.state.config)) {
193
+ this.setConfig(config, true);
194
+ }
195
+
196
+ return result;
197
+ },
198
+ // 拖动导航树
199
+ splice: (data: any): void => {
200
+ logInfo('splice', data);
201
+ this.state.communicator.publish('splice', toPlainObject(data));
202
+ },
203
+ };
204
+
205
+ timer = 0;
206
+ subscribe = {
207
+ // 监听模拟器加载完成
208
+ load: ({ data }): void => {
209
+ this.setConfig(data);
210
+ console.log('🔥editor load');
211
+ this.emit('load', this.state.config);
212
+ },
213
+ // 监听交互行为,这里把事件emit给视图处理
214
+ action: ({ data: { key, value } }): any => {
215
+ this.emit(key, value);
216
+ // 可能需要返回数据
217
+ },
218
+ // 更新编辑器视图,这里需要检查project是否发生变化,如果发生变化,需要emit给视图处理
219
+ update: ({ data: { config, project, forceUpdate } }): void => {
220
+ logInfo('update', config, project);
221
+ this.initFlag = true;
222
+ // config
223
+ this.setConfig(config, forceUpdate);
224
+ // project
225
+ if (!isEqual(this.state.project, project)) {
226
+ clearTimeout(this.timer);
227
+ // 这里做防抖,避免多次触发
228
+ //@ts-ignore
229
+ this.timer = setTimeout(() => {
230
+ this.state.project = { ...project };
231
+ this.emit('update', project);
232
+ }, 50);
233
+ }
234
+ },
235
+ // 获取截图
236
+ updateScreenShot: ({ data }) => {
237
+ // 初始化完成再进行截图
238
+ if (this.initFlag) {
239
+ this.emit('updateScreenShot', data);
240
+ }
241
+ },
242
+ // 打开上传图片对话框
243
+ openUpload: ({ data: { key, name } }) => {
244
+ this.emit('openUpload', { key, name });
245
+ },
246
+ // 远程调用方法
247
+ fetch: ({ data: { url, queryParam } }) => {
248
+ return this.state.request(url, queryParam);
249
+ },
250
+ };
251
+
252
+ // 方法:
253
+ // pushlish.init project数据初始化成功,把数据传给模拟器
254
+ // pushlish.click 编辑器元素被点击,通知模拟器
255
+ // pushlish.drag 拖拽组件到模拟器区域
256
+ // pushlish.set 设置组件数据
257
+ // pushlish.contextmenu 在编辑器元素上点击右键
258
+ // pushlish.validate 让模拟器检查数据
259
+ // pushlish.updateScreenShot 获取页面dom截图
260
+ // pushlish.insert 插入多张图片
261
+
262
+ // subscribe.load 监听模拟器加载完成
263
+ // subscribe.action 监听交互行为,这里把事件emit给视图处理
264
+ // subscribe.update 更新编辑器视图,这里需要检查project是否发生变化,如果发生变化,需要emit给视图处理。
265
+ }