@tmagic/editor 1.5.0-beta.9 → 1.5.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 (52) hide show
  1. package/dist/style.css +75 -16
  2. package/dist/tmagic-editor.js +797 -518
  3. package/dist/tmagic-editor.umd.cjs +802 -525
  4. package/package.json +12 -10
  5. package/src/Editor.vue +6 -1
  6. package/src/components/CodeBlockEditor.vue +11 -5
  7. package/src/components/CodeParams.vue +3 -3
  8. package/src/editorProps.ts +3 -1
  9. package/src/fields/Code.vue +1 -2
  10. package/src/fields/CodeSelect.vue +13 -11
  11. package/src/fields/CodeSelectCol.vue +32 -5
  12. package/src/fields/CondOpSelect.vue +5 -2
  13. package/src/fields/DataSourceFields.vue +31 -12
  14. package/src/fields/DataSourceMethods.vue +72 -14
  15. package/src/fields/DisplayConds.vue +8 -3
  16. package/src/fields/EventSelect.vue +28 -11
  17. package/src/fields/KeyValue.vue +15 -10
  18. package/src/fields/UISelect.vue +6 -3
  19. package/src/hooks/index.ts +0 -1
  20. package/src/hooks/use-code-block-edit.ts +1 -1
  21. package/src/hooks/use-data-source-edit.ts +3 -2
  22. package/src/hooks/use-filter.ts +1 -1
  23. package/src/hooks/use-node-status.ts +2 -2
  24. package/src/initService.ts +177 -74
  25. package/src/layouts/Framework.vue +8 -4
  26. package/src/layouts/PropsPanel.vue +3 -3
  27. package/src/layouts/page-bar/AddButton.vue +29 -9
  28. package/src/layouts/page-bar/PageBar.vue +78 -65
  29. package/src/layouts/page-bar/PageBarScrollContainer.vue +82 -96
  30. package/src/layouts/page-bar/PageList.vue +5 -3
  31. package/src/layouts/page-bar/Search.vue +67 -0
  32. package/src/layouts/sidebar/Sidebar.vue +3 -0
  33. package/src/layouts/sidebar/code-block/CodeBlockList.vue +6 -1
  34. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +7 -5
  35. package/src/layouts/sidebar/data-source/DataSourceList.vue +6 -1
  36. package/src/layouts/sidebar/layer/use-node-status.ts +2 -3
  37. package/src/layouts/workspace/Workspace.vue +5 -2
  38. package/src/layouts/workspace/viewer/Stage.vue +23 -5
  39. package/src/services/dataSource.ts +12 -5
  40. package/src/services/dep.ts +61 -13
  41. package/src/services/editor.ts +46 -51
  42. package/src/theme/page-bar.scss +38 -16
  43. package/src/theme/search-input.scss +1 -0
  44. package/src/type.ts +2 -1
  45. package/src/utils/data-source/formConfigs/http.ts +2 -0
  46. package/src/utils/data-source/index.ts +2 -2
  47. package/src/utils/editor.ts +78 -22
  48. package/src/utils/idle-task.ts +36 -4
  49. package/src/utils/props.ts +3 -3
  50. package/types/index.d.ts +835 -1169
  51. package/src/hooks/use-data-source-method.ts +0 -100
  52. package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
@@ -16,12 +16,23 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
+ import { detailedDiff } from 'deep-object-diff';
20
+ import { isObject } from 'lodash-es';
19
21
  import serialize from 'serialize-javascript';
20
22
 
21
23
  import type { Id, MApp, MContainer, MNode, MPage, MPageFragment } from '@tmagic/core';
22
- import { NodeType } from '@tmagic/core';
24
+ import { NODE_CONDS_KEY, NodeType } from '@tmagic/core';
23
25
  import type StageCore from '@tmagic/stage';
24
- import { calcValueByFontsize, getElById, getNodePath, isNumber, isPage, isPageFragment, isPop } from '@tmagic/utils';
26
+ import {
27
+ calcValueByFontsize,
28
+ getElById,
29
+ getNodePath,
30
+ isNumber,
31
+ isPage,
32
+ isPageFragment,
33
+ isPop,
34
+ isValueIncludeDataSource,
35
+ } from '@tmagic/utils';
25
36
 
26
37
  import { Layout } from '@editor/type';
27
38
 
@@ -272,26 +283,6 @@ export const serializeConfig = (config: any) =>
272
283
  unsafe: true,
273
284
  }).replace(/"(\w+)":\s/g, '$1: ');
274
285
 
275
- export interface NodeItem {
276
- items?: NodeItem[];
277
- [key: string]: any;
278
- }
279
-
280
- export const traverseNode = <T extends NodeItem = NodeItem>(
281
- node: T,
282
- cb: (node: T, parents: T[]) => void,
283
- parents: T[] = [],
284
- ) => {
285
- cb(node, parents);
286
-
287
- if (Array.isArray(node.items) && node.items.length) {
288
- parents.push(node);
289
- node.items.forEach((item) => {
290
- traverseNode(item as T, cb, [...parents]);
291
- });
292
- }
293
- };
294
-
295
286
  export const moveItemsInContainer = (sourceIndices: number[], parent: MContainer, targetIndex: number) => {
296
287
  sourceIndices.sort((a, b) => a - b);
297
288
  for (let i = sourceIndices.length - 1; i >= 0; i--) {
@@ -310,3 +301,68 @@ export const moveItemsInContainer = (sourceIndices: number[], parent: MContainer
310
301
  }
311
302
  }
312
303
  };
304
+
305
+ const isIncludeDataSourceByDiffAddResult = (diffResult: any) => {
306
+ for (const value of Object.values(diffResult)) {
307
+ const result = isValueIncludeDataSource(value);
308
+
309
+ if (result) {
310
+ return true;
311
+ }
312
+
313
+ if (isObject(value)) {
314
+ return isIncludeDataSourceByDiffAddResult(value);
315
+ }
316
+ }
317
+ return false;
318
+ };
319
+
320
+ const isIncludeDataSourceByDiffUpdatedResult = (diffResult: any, oldNode: any) => {
321
+ for (const [key, value] of Object.entries<any>(diffResult)) {
322
+ if (isValueIncludeDataSource(value)) {
323
+ return true;
324
+ }
325
+
326
+ if (isValueIncludeDataSource(oldNode[key])) {
327
+ return true;
328
+ }
329
+
330
+ if (isObject(value)) {
331
+ return isIncludeDataSourceByDiffUpdatedResult(value, oldNode[key]);
332
+ }
333
+ }
334
+ return false;
335
+ };
336
+
337
+ export const isIncludeDataSource = (node: MNode, oldNode: MNode) => {
338
+ const diffResult = detailedDiff(oldNode, node);
339
+
340
+ let isIncludeDataSource = false;
341
+
342
+ if (diffResult.updated) {
343
+ // 修改了显示条件
344
+ if ((diffResult.updated as any)[NODE_CONDS_KEY]) {
345
+ return true;
346
+ }
347
+
348
+ isIncludeDataSource = isIncludeDataSourceByDiffUpdatedResult(diffResult.updated, oldNode);
349
+ if (isIncludeDataSource) return true;
350
+ }
351
+
352
+ if (diffResult.added) {
353
+ isIncludeDataSource = isIncludeDataSourceByDiffAddResult(diffResult.added);
354
+ if (isIncludeDataSource) return true;
355
+ }
356
+
357
+ if (diffResult.deleted) {
358
+ // 删除了显示条件
359
+ if ((diffResult.deleted as any)[NODE_CONDS_KEY]) {
360
+ return true;
361
+ }
362
+
363
+ isIncludeDataSource = isIncludeDataSourceByDiffAddResult(diffResult.deleted);
364
+ if (isIncludeDataSource) return true;
365
+ }
366
+
367
+ return isIncludeDataSource;
368
+ };
@@ -26,6 +26,11 @@ export class IdleTask<T = any> extends EventEmitter {
26
26
 
27
27
  private taskHandle: number | null = null;
28
28
 
29
+ constructor() {
30
+ super();
31
+ this.setMaxListeners(1000);
32
+ }
33
+
29
34
  public enqueueTask(taskHandler: (data: T) => void, taskData: T) {
30
35
  this.taskList.push({
31
36
  handler: taskHandler,
@@ -37,6 +42,10 @@ export class IdleTask<T = any> extends EventEmitter {
37
42
  }
38
43
  }
39
44
 
45
+ public clearTasks() {
46
+ this.taskList = [];
47
+ }
48
+
40
49
  public on<Name extends keyof IdleTaskEvents, Param extends IdleTaskEvents[Name]>(
41
50
  eventName: Name,
42
51
  listener: (...args: Param) => void | Promise<void>,
@@ -56,13 +65,36 @@ export class IdleTask<T = any> extends EventEmitter {
56
65
  }
57
66
 
58
67
  private runTaskQueue(deadline: IdleDeadline) {
59
- while ((deadline.timeRemaining() > 15 || deadline.didTimeout) && this.taskList.length) {
60
- const task = this.taskList.shift();
61
- task!.handler(task!.data);
68
+ // 动画会占用空闲时间,当任务一直无法执行时,看看是否有动画正在播放
69
+ // 根据空闲时间的多少来决定执行的任务数,保证页面不卡死的情况下尽量多执行任务,不然当任务数巨大时,执行时间会很久
70
+ // 执行不完不会影响配置,但是会影响画布渲染
71
+ while (deadline.timeRemaining() > 0 && this.taskList.length) {
72
+ const timeRemaining = deadline.timeRemaining();
73
+ let times = 0;
74
+ if (timeRemaining <= 5) {
75
+ times = 10;
76
+ } else if (timeRemaining <= 10) {
77
+ times = 100;
78
+ } else if (timeRemaining <= 15) {
79
+ times = 300;
80
+ } else {
81
+ times = 600;
82
+ }
83
+
84
+ for (let i = 0; i < times; i++) {
85
+ const task = this.taskList.shift();
86
+ if (task) {
87
+ task.handler(task.data);
88
+ }
89
+
90
+ if (this.taskList.length === 0) {
91
+ break;
92
+ }
93
+ }
62
94
  }
63
95
 
64
96
  if (this.taskList.length) {
65
- this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 10000 });
97
+ this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 300 });
66
98
  } else {
67
99
  this.taskHandle = 0;
68
100
 
@@ -81,7 +81,7 @@ export const styleTabConfig: TabPaneConfig = {
81
81
  fieldConfig: {
82
82
  type: 'text',
83
83
  },
84
- disabled: (vm: FormState, { model }: any) =>
84
+ disabled: (_vm: FormState, { model }: any) =>
85
85
  model.position === 'fixed' && model._magic_position === 'fixedBottom',
86
86
  },
87
87
  {
@@ -103,7 +103,7 @@ export const styleTabConfig: TabPaneConfig = {
103
103
  fieldConfig: {
104
104
  type: 'text',
105
105
  },
106
- disabled: (vm: FormState, { model }: any) =>
106
+ disabled: (_vm: FormState, { model }: any) =>
107
107
  model.position === 'fixed' && model._magic_position === 'fixedTop',
108
108
  },
109
109
  ],
@@ -356,7 +356,7 @@ export const advancedTabConfig: TabPaneConfig = {
356
356
 
357
357
  export const displayTabConfig: TabPaneConfig = {
358
358
  title: '显示条件',
359
- display: (vm: FormState, { model }: any) => model.type !== 'page',
359
+ display: (_vm: FormState, { model }: any) => model.type !== 'page',
360
360
  items: [
361
361
  {
362
362
  type: 'display-conds',