starfish-editor-custom 1.0.0

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 (108) hide show
  1. package/auto-imports.d.ts +10 -0
  2. package/babel.config.js +8 -0
  3. package/components.d.ts +46 -0
  4. package/dist/ConditionModule.js +892 -0
  5. package/dist/ConditionSelect.js +483 -0
  6. package/dist/CustomDialog.js +105 -0
  7. package/dist/formStyle.js +245 -0
  8. package/dist/globalFormList.js +59 -0
  9. package/dist/jsonCode.js +74 -0
  10. package/dist/jsonEditor.js +71 -0
  11. package/dist/main.js +3319 -0
  12. package/dist/starfish-editor.es.js +30 -0
  13. package/dist/style.css +1 -0
  14. package/dist/types/editor/src/common/ConditionSelect/ConditionGroup.vue.d.ts +61 -0
  15. package/dist/types/editor/src/common/ConditionSelect/ConditionModule.vue.d.ts +43 -0
  16. package/dist/types/editor/src/common/ConditionSelect/ConditionTanc.vue.d.ts +48 -0
  17. package/dist/types/editor/src/common/ConditionSelect.vue.d.ts +72 -0
  18. package/dist/types/editor/src/common/CustomDialog.vue.d.ts +25 -0
  19. package/dist/types/editor/src/common/Loading.vue.d.ts +3 -0
  20. package/dist/types/editor/src/common/formJson.d.ts +80 -0
  21. package/dist/types/editor/src/common/jsonCode.vue.d.ts +110 -0
  22. package/dist/types/editor/src/components/ComponentList.vue.d.ts +32 -0
  23. package/dist/types/editor/src/components/FormPreview.vue.d.ts +25 -0
  24. package/dist/types/editor/src/components/Nav.vue.d.ts +9 -0
  25. package/dist/types/editor/src/components/PropsPanel.vue.d.ts +53 -0
  26. package/dist/types/editor/src/components/Shape.vue.d.ts +40 -0
  27. package/dist/types/editor/src/components/Workspace.vue.d.ts +22 -0
  28. package/dist/types/editor/src/components/globalFormList.vue.d.ts +6 -0
  29. package/dist/types/editor/src/components/jsonEditor.vue.d.ts +6 -0
  30. package/dist/types/editor/src/controller/action.d.ts +18 -0
  31. package/dist/types/editor/src/controller/form.d.ts +24 -0
  32. package/dist/types/editor/src/controller/history.d.ts +12 -0
  33. package/dist/types/editor/src/controller/shortcut.d.ts +20 -0
  34. package/dist/types/editor/src/controller/ui.d.ts +10 -0
  35. package/dist/types/editor/src/layouts/ControlEditSize.vue.d.ts +17 -0
  36. package/dist/types/editor/src/layouts/Framework.vue.d.ts +33 -0
  37. package/dist/types/editor/src/layouts/Resizer.vue.d.ts +13 -0
  38. package/dist/types/editor/src/layouts/ShortcutKey.vue.d.ts +8 -0
  39. package/dist/types/editor/src/main.d.ts +5 -0
  40. package/dist/types/editor/src/shims-vue.d.ts +23 -0
  41. package/dist/types/editor/src/starfish-editor.vue.d.ts +109 -0
  42. package/dist/types/editor/src/type.d.ts +224 -0
  43. package/dist/types/editor/src/utils/_.d.ts +33 -0
  44. package/dist/types/editor/src/utils/formKeycon.d.ts +18 -0
  45. package/dist/types/editor/src/utils/shortcutKey.d.ts +3 -0
  46. package/dist/types/editor/src/utils/vm.d.ts +3 -0
  47. package/dist/types/starfish-editor.d.ts +3 -0
  48. package/package.json +55 -0
  49. package/src/common/ConditionSelect/ConditionGroup.vue +167 -0
  50. package/src/common/ConditionSelect/ConditionModule.vue +118 -0
  51. package/src/common/ConditionSelect/ConditionTanc.vue +319 -0
  52. package/src/common/ConditionSelect.vue +268 -0
  53. package/src/common/CustomDialog.vue +77 -0
  54. package/src/common/Loading.vue +10 -0
  55. package/src/common/formJson.ts +143 -0
  56. package/src/common/formStyle.vue +170 -0
  57. package/src/common/jsonCode.vue +45 -0
  58. package/src/components/ComponentList.vue +156 -0
  59. package/src/components/FormPreview.vue +197 -0
  60. package/src/components/Nav.vue +128 -0
  61. package/src/components/NavList.vue +560 -0
  62. package/src/components/PropsPanel.vue +376 -0
  63. package/src/components/Shape.vue +178 -0
  64. package/src/components/Workspace.vue +258 -0
  65. package/src/components/globalFormList.vue +30 -0
  66. package/src/components/jsonEditor.vue +41 -0
  67. package/src/controller/action.ts +37 -0
  68. package/src/controller/form.ts +207 -0
  69. package/src/controller/history.ts +57 -0
  70. package/src/controller/shortcut.ts +81 -0
  71. package/src/controller/ui.ts +91 -0
  72. package/src/layouts/ControlEditSize.vue +52 -0
  73. package/src/layouts/Framework.vue +76 -0
  74. package/src/layouts/Resizer.vue +54 -0
  75. package/src/layouts/ShortcutKey.vue +61 -0
  76. package/src/main.ts +56 -0
  77. package/src/shims-vue.d.ts +23 -0
  78. package/src/starfish-editor.vue +176 -0
  79. package/src/styles/common/normalize.css +455 -0
  80. package/src/styles/component-list.scss +64 -0
  81. package/src/styles/condition-select.scss +176 -0
  82. package/src/styles/control_edit_size.scss +36 -0
  83. package/src/styles/custom-dialog.scss +110 -0
  84. package/src/styles/form-preview.scss +47 -0
  85. package/src/styles/framework.scss +150 -0
  86. package/src/styles/iconfont/iconfont.css +247 -0
  87. package/src/styles/iconfont/iconfont.js +1 -0
  88. package/src/styles/iconfont/iconfont.json +415 -0
  89. package/src/styles/iconfont/iconfont.ttf +0 -0
  90. package/src/styles/iconfont/iconfont.woff +0 -0
  91. package/src/styles/iconfont/iconfont.woff2 +0 -0
  92. package/src/styles/index.scss +18 -0
  93. package/src/styles/nav-list.scss +59 -0
  94. package/src/styles/nav.scss +46 -0
  95. package/src/styles/props-panel.scss +115 -0
  96. package/src/styles/resizer.scss +15 -0
  97. package/src/styles/shape.scss +101 -0
  98. package/src/styles/shortcutkey.scss +44 -0
  99. package/src/styles/variables.scss +36 -0
  100. package/src/styles/work-space.scss +126 -0
  101. package/src/type.ts +240 -0
  102. package/src/utils/_.ts +349 -0
  103. package/src/utils/formKeycon.ts +42 -0
  104. package/src/utils/shortcutKey.ts +46 -0
  105. package/src/utils/vm.ts +3 -0
  106. package/stats.html +4949 -0
  107. package/tsconfig.json +19 -0
  108. package/vite.config.ts +111 -0
package/src/utils/_.ts ADDED
@@ -0,0 +1,349 @@
1
+ import { ElNotification } from "element-plus";
2
+ import { nanoid } from "nanoid";
3
+ import { AllFormItem, BaseComponentItem, PartialKey } from "@/type";
4
+ import formStore from "@/controller/form";
5
+ class Flex {
6
+ lastClickTime: number;
7
+ openTanc: boolean;
8
+
9
+ constructor() {
10
+ this.lastClickTime = 0;
11
+ this.openTanc = false; // 是否有弹窗
12
+ }
13
+ // 防止用户多次点击
14
+ public clickCountLimit(): boolean {
15
+ let isCanGo = false;
16
+
17
+ if (window.clickCountLimitMock) {
18
+ return true;
19
+ }
20
+ if (!this.lastClickTime) {
21
+ this.lastClickTime = new Date().getTime();
22
+ isCanGo = true;
23
+ } else {
24
+ const shicha = new Date().getTime() - this.lastClickTime;
25
+ this.lastClickTime = new Date().getTime();
26
+ isCanGo = shicha >= 1000;
27
+ }
28
+ if (!isCanGo) {
29
+ console.log("手残党点击太快了");
30
+ }
31
+ return isCanGo;
32
+ }
33
+ public generateMixed(size?: number) {
34
+ // let res = "";
35
+ // for (let i = 0; i < n; i++) {
36
+ // const id = Math.ceil(Math.random() * 35);
37
+ // res += chars[id];
38
+ // }
39
+ return nanoid(size);
40
+ }
41
+ public controlFormRule(controlItems: any[]): any {
42
+ const rules: any = {};
43
+ controlItems.forEach((item: any) => {
44
+ const rule: any[] = [];
45
+ if (item.data.required) {
46
+ rule.push({
47
+ required: true,
48
+ message: "请输入" + item.data.label,
49
+ trigger: "blur",
50
+ });
51
+ rules[item.data.fieldName] = rule;
52
+ }
53
+ if (item.ControlType === "JsonEditor") {
54
+ rules[item.data.fieldName] = this.getJsonValidate();
55
+ }
56
+ });
57
+ return rules;
58
+ }
59
+ public deepClone(target: any): any {
60
+ // 定义一个变量
61
+ let result: any;
62
+ // 如果当前需要深拷贝的是一个对象的话
63
+ if (typeof target === "object") {
64
+ // 如果是一个数组的话
65
+ if (Array.isArray(target)) {
66
+ result = []; // 将result赋值为一个数组,并且执行遍历
67
+ for (let i = 0; i < target.length; i++) {
68
+ // 递归克隆数组中的每一项
69
+ if (Object.prototype.hasOwnProperty.call(target, i)) {
70
+ result.push(this.deepClone(target[i]));
71
+ }
72
+ }
73
+ // 判断如果当前的值是null的话;直接赋值为null
74
+ } else if (target === null) {
75
+ result = null;
76
+ // 判断如果当前的值是一个RegExp对象的话,直接赋值
77
+ } else if (target.constructor === RegExp) {
78
+ result = target;
79
+ } else {
80
+ // 否则是普通对象,直接for in循环,递归赋值对象的所有值
81
+ result = {};
82
+ for (const i in target) {
83
+ if (Object.prototype.hasOwnProperty.call(target, i)) {
84
+ result[i] = this.deepClone(target[i]);
85
+ }
86
+ }
87
+ }
88
+ // 如果不是对象的话,就是基本数据类型,那么直接赋值
89
+ } else {
90
+ result = target;
91
+ }
92
+ // 返回最终结果
93
+ return result;
94
+ }
95
+
96
+ public tryParseJson(json: string) {
97
+ try {
98
+ return JSON.parse(json);
99
+ } catch (E) {
100
+ if (json && json.startsWith && json.startsWith('"[')) {
101
+ return [];
102
+ }
103
+ return {};
104
+ }
105
+ }
106
+ public open(message: string, title = "Success", type: any = "success") {
107
+ ElNotification({
108
+ title: title || "Success",
109
+ message: message,
110
+ type,
111
+ });
112
+ }
113
+ public getJsonValidate() {
114
+ return this.deepClone([
115
+ {
116
+ validator: (rule: any, value: any, callback: (a?: any | undefined) => any) => {
117
+ try {
118
+ JSON.parse(value);
119
+ callback();
120
+ } catch (e) {
121
+ console.error(e);
122
+ return callback(new Error("请输入正确的json格式"));
123
+ }
124
+ },
125
+ trigger: "blur",
126
+ },
127
+ ]);
128
+ }
129
+ // 获取数据类型
130
+ public getDataType(data: any): any {
131
+ const str: any = Object.prototype.toString.call(data);
132
+ const reg = /\[object (.*)\]/;
133
+ return str.match(reg)[1];
134
+ }
135
+ /**
136
+ * json转标准数据格式进行收口
137
+ */
138
+ public jsonToForm(item: AllFormItem) {
139
+ if (!item.data || !item.controlItems) {
140
+ item = this.deepClone(item);
141
+ const currentComponent = window.VApp.$formcomponents[item.ControlType as any];
142
+ item.formConfig = window.VApp.$formcomponents[item.ControlType as any]?.formConfig || {};
143
+ if (!item.data) {
144
+ item.data = item.formConfig.data();
145
+ }
146
+
147
+ if (!item.data.fieldName) {
148
+ item.data.fieldName = item.ControlType + "_" + this.generateMixed();
149
+ }
150
+ if (item.layout) {
151
+ if (item.ControlType == "Grid" && item.data.columns && item.data.columns.length > 0) {
152
+ item.data.columns = item.data.columns.map((colItem: any) => {
153
+ if (colItem.list && colItem.list.length > 0) {
154
+ colItem.list = this.jsonToForm(colItem.list);
155
+ }
156
+ return colItem;
157
+ });
158
+ } else if (item.ControlType == "TableLayout" && item.data.trs && item.data.trs.length > 0) {
159
+ /**
160
+ * 需要自测一下
161
+ */
162
+ item.data.trs = item.data.trs.map((trItem: any) => {
163
+ trItem.tds.forEach((tdItem: any) => {
164
+ if (tdItem.list && tdItem.list.length > 0) {
165
+ tdItem.list = this.jsonToForm(tdItem.list);
166
+ }
167
+ return tdItem;
168
+ });
169
+ return trItem;
170
+ });
171
+ } else if ((item.ControlType == "Collapse" || item.ControlType == "Tabs") && item.data.items && item.data.items.length > 0) {
172
+ item.data.items = item.data.items.map((colItem: any) => {
173
+ if (colItem.list && colItem.list.length > 0) {
174
+ colItem.list = this.jsonToForm(colItem.list);
175
+ }
176
+ return colItem;
177
+ });
178
+ }
179
+ }
180
+ /**
181
+ * 全局动态配置
182
+ */
183
+ const dynamicList = formStore?.get("globalFormList")?.filter((item: any) => {
184
+ if (item.dynamic) {
185
+ return item;
186
+ }
187
+ });
188
+ item.id = this.generateMixed();
189
+ let controlItems = item.formConfig.morenConfig().concat(dynamicList);
190
+ /**
191
+ * 兼容动作面板,不同表单可能需要的事件不一样
192
+ */
193
+ if (currentComponent.actionType && currentComponent.actionType.length > 0) {
194
+ console.log(controlItems);
195
+ controlItems.find((item: any) => {
196
+ if (item.ControlType == "Action") {
197
+ item.data.formConfig = {
198
+ value: {},
199
+ items: [],
200
+ };
201
+ currentComponent.actionType.forEach((action: string, index: number) => {
202
+ item.data.formConfig.items.push({
203
+ label: action,
204
+ value: action,
205
+ id: index + 1,
206
+ });
207
+ });
208
+ }
209
+ });
210
+ } else {
211
+ controlItems = controlItems.filter((item: any) => {
212
+ if (item.ControlType !== "Action") {
213
+ return item;
214
+ }
215
+ });
216
+ }
217
+ item.rules = this.controlFormRule(controlItems);
218
+ item.controlItems = controlItems;
219
+ }
220
+ return item;
221
+ }
222
+
223
+ /**
224
+ * 完整的表单列表数据进行删减,方便展示
225
+ */
226
+ public initFormToJson(formlist: AllFormItem[]) {
227
+ const jsonData: PartialKey<BaseComponentItem, "icon">[] = [];
228
+ formlist.forEach((item: AllFormItem) => {
229
+ if (item.layout) {
230
+ if (item.ControlType == "Grid" && item.data.columns && item.data.columns.length > 0) {
231
+ item.data.columns = item.data.columns.map((colItem: any) => {
232
+ colItem.list = this.initFormToJson(colItem.list);
233
+ return colItem;
234
+ });
235
+ } else if (item.ControlType == "TableLayout" && item.data.trs && item.data.trs.length > 0) {
236
+ item.data.trs = item.data.trs.map((trItem: any) => {
237
+ trItem.tds.forEach((tdItem: any) => {
238
+ if (tdItem.list && tdItem.list.length > 0) {
239
+ tdItem.list = this.initFormToJson(tdItem.list);
240
+ }
241
+ return tdItem;
242
+ });
243
+ return trItem;
244
+ });
245
+ } else if ((item.ControlType == "Collapse" || item.ControlType == "Tabs") && item.data.items && item.data.items.length > 0) {
246
+ item.data.items = item.data.items.map((colItem: any) => {
247
+ colItem.list = this.initFormToJson(colItem.list);
248
+ return colItem;
249
+ });
250
+ }
251
+ }
252
+ const obj = {
253
+ ControlType: item.ControlType,
254
+ nameCn: item.nameCn,
255
+ id: item.id,
256
+ layout: !!item.layout,
257
+ data: item.data,
258
+ };
259
+ jsonData.push(obj);
260
+ });
261
+ return jsonData;
262
+ }
263
+
264
+ public funcExec(action: string, proxy: any, argus: any = []) {
265
+ const actionObj = JSON.parse(action || "{}");
266
+ const funcStr = actionObj.funcStr;
267
+ eval(`(function(${this.getField(actionObj.methods)}){${funcStr}}).apply(proxy, argus)`);
268
+ }
269
+
270
+ public getField(methods: string) {
271
+ if (methods == "onChange") {
272
+ return "value, oldValue, subFormData";
273
+ } else if (["onForce", "onBlur", "onClick"].includes(methods)) {
274
+ return "field";
275
+ } else {
276
+ return "";
277
+ }
278
+ }
279
+
280
+ /**
281
+ * 获取显示条件所有字段列表
282
+ * item: 其他表单数据
283
+ * result 最终的结果
284
+ * fieldName 过滤当前选中表单的字段(显示规则不能根据自身的值进行展示)
285
+ */
286
+ public getFormDataList(item: AllFormItem, result: any = [], fieldName: string) {
287
+ if (!item.layout) {
288
+ if (item.data.fieldName != fieldName) {
289
+ if (item.nameCn == "开关") {
290
+ result.push({
291
+ value: item?.data?.fieldName,
292
+ label: item?.data?.label + "-" + item?.data?.fieldName,
293
+ switch: true,
294
+ });
295
+ return;
296
+ }
297
+ if (item.data.itemConfig) {
298
+ let multiple = false;
299
+ if (Array.isArray(item.data.itemConfig.value)) {
300
+ multiple = true;
301
+ }
302
+ const options = item.data.itemConfig.items;
303
+ result.push({
304
+ value: item?.data?.fieldName,
305
+ label: item?.data?.label + "-" + item?.data?.fieldName,
306
+ multiple,
307
+ options,
308
+ });
309
+ return;
310
+ }
311
+ result.push({
312
+ value: item?.data?.fieldName,
313
+ label: item?.data?.label + "-" + item?.data?.fieldName,
314
+ });
315
+ }
316
+ } else {
317
+ if (item.data.fieldName != fieldName) {
318
+ // 容器组件整个部分也可以作为显示条件的一部分
319
+ result.push({
320
+ value: item?.data?.fieldName,
321
+ label: item?.data?.label + "-" + item?.data?.fieldName,
322
+ });
323
+ if (item.ControlType == "Grid" && item.data.columns) {
324
+ item.data.columns.forEach((colItem: any) => {
325
+ colItem.list.forEach((listItem: AllFormItem) => {
326
+ this.getFormDataList(listItem, result, fieldName);
327
+ });
328
+ });
329
+ } else if (item.ControlType == "TableLayout" && item.data.trs) {
330
+ item.data.trs.forEach((trItem: any) => {
331
+ trItem.tds.forEach((tdItem: any) => {
332
+ tdItem.list.forEach((listItem: AllFormItem) => {
333
+ this.getFormDataList(listItem, result, fieldName);
334
+ });
335
+ });
336
+ });
337
+ } else if ((item.ControlType == "Collapse" || item.ControlType == "Tabs") && item.data.items) {
338
+ item.data.items.forEach((colItem: any) => {
339
+ colItem.list.forEach((listItem: AllFormItem) => {
340
+ this.getFormDataList(listItem, result, fieldName);
341
+ });
342
+ });
343
+ }
344
+ }
345
+ }
346
+ }
347
+ }
348
+
349
+ export default new Flex();
@@ -0,0 +1,42 @@
1
+ import store from "@/controller/shortcut";
2
+
3
+ export function clearCanvas() {
4
+ store.commit("clear");
5
+ }
6
+
7
+ export function copy() {
8
+ store.commit("copy");
9
+ }
10
+
11
+ export function paste() {
12
+ store.commit("paste");
13
+ }
14
+
15
+ export function cut() {
16
+ store.commit("copy");
17
+ store.commit("delete");
18
+ }
19
+
20
+ export function onDelete() {
21
+ store.commit("delete");
22
+ }
23
+
24
+ export function onTop() {
25
+ store.commit("onTop");
26
+ }
27
+
28
+ export function onBottom() {
29
+ store.commit("onBottom");
30
+ }
31
+
32
+ const result = {
33
+ copy,
34
+ paste,
35
+ cut,
36
+ delete: onDelete,
37
+ onTop,
38
+ onBottom,
39
+ clearCanvas
40
+ }
41
+ export type shortCutType = typeof result;
42
+ export default result
@@ -0,0 +1,46 @@
1
+ import KeyController from "keycon";
2
+ import history from "@/controller/history";
3
+ import type {shortCutType} from './formKeycon'
4
+ export function listenGlobalKeyDown(list: shortCutType, dom: HTMLDivElement | any) {
5
+ const keycons:KeyController = new KeyController(dom);
6
+ const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
7
+ const ctrl = isMac ? "meta" : "ctrl";
8
+ keycons
9
+ .keyup("delete", (e) => {
10
+ e.inputEvent.preventDefault();
11
+ list.delete();
12
+ })
13
+ .keyup("backspace", (e) => {
14
+ e.inputEvent.preventDefault();
15
+ list.delete();
16
+ })
17
+ .keydown([ctrl, "c"], (e) => {
18
+ e.inputEvent.preventDefault();
19
+ list.copy();
20
+ })
21
+ .keydown([ctrl, "e"], (e) => {
22
+ e.inputEvent.preventDefault();
23
+ list.clearCanvas();
24
+ })
25
+ .keydown([ctrl, "v"], (e) => {
26
+ e.inputEvent.preventDefault();
27
+ list.paste();
28
+ })
29
+ .keydown([ctrl, "z"], (e) => {
30
+ e.inputEvent.preventDefault();
31
+ history?.back();
32
+ })
33
+ .keydown([ctrl, "x"], (e) => {
34
+ e.inputEvent.preventDefault();
35
+ list.cut();
36
+ })
37
+ .keydown([ctrl, "up"], (e) => {
38
+ e.inputEvent.preventDefault();
39
+ list.onTop();
40
+ })
41
+ .keydown([ctrl, "down"], (e) => {
42
+ e.inputEvent.preventDefault();
43
+ list.onBottom();
44
+ });
45
+ return keycons;
46
+ }
@@ -0,0 +1,3 @@
1
+ import mitt from 'mitt'
2
+
3
+ export default mitt()