@tmagic/editor 1.2.9 → 1.2.11

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 (39) hide show
  1. package/dist/style.css +26 -32
  2. package/dist/tmagic-editor.js +1694 -1342
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +1699 -1344
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +9 -9
  7. package/src/Editor.vue +10 -240
  8. package/src/components/CodeDraftEditor.vue +10 -6
  9. package/src/components/FunctionEditor.vue +1 -1
  10. package/src/editorProps.ts +135 -0
  11. package/src/fields/CodeSelect.vue +24 -13
  12. package/src/fields/CodeSelectCol.vue +117 -0
  13. package/src/fields/EventSelect.vue +216 -0
  14. package/src/index.ts +7 -0
  15. package/src/initService.ts +198 -0
  16. package/src/layouts/sidebar/code-block/CodeBlockList.vue +49 -127
  17. package/src/services/codeBlock.ts +29 -150
  18. package/src/services/dep.ts +328 -0
  19. package/src/services/editor.ts +2 -28
  20. package/src/theme/code-block.scss +5 -33
  21. package/src/theme/event.scss +24 -0
  22. package/src/theme/theme.scss +1 -0
  23. package/src/type.ts +18 -3
  24. package/src/utils/dep.ts +21 -0
  25. package/src/utils/props.ts +1 -35
  26. package/types/Editor.vue.d.ts +49 -82
  27. package/types/editorProps.d.ts +109 -0
  28. package/types/fields/CodeSelect.vue.d.ts +28 -5
  29. package/types/fields/CodeSelectCol.vue.d.ts +30 -0
  30. package/types/fields/EventSelect.vue.d.ts +26 -0
  31. package/types/index.d.ts +3 -0
  32. package/types/initService.d.ts +8 -0
  33. package/types/services/codeBlock.d.ts +3 -36
  34. package/types/services/dep.d.ts +130 -0
  35. package/types/services/editor.d.ts +1 -13
  36. package/types/services/props.d.ts +1 -15
  37. package/types/type.d.ts +17 -3
  38. package/types/utils/dep.d.ts +3 -0
  39. package/types/utils/props.d.ts +2 -16
@@ -0,0 +1,130 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { MNode } from '@tmagic/schema';
4
+ declare type IsTarget = (key: string | number, value: any) => boolean;
5
+ interface TargetOptions {
6
+ isTarget: IsTarget;
7
+ id: string | number;
8
+ type?: string;
9
+ name: string;
10
+ }
11
+ interface Dep {
12
+ [key: string | number]: {
13
+ name: string;
14
+ keys: (string | number)[];
15
+ };
16
+ }
17
+ interface TargetList {
18
+ [key: string]: {
19
+ [key: string | number]: Target;
20
+ };
21
+ }
22
+ /**
23
+ * 需要收集依赖的目标
24
+ * 例如:一个代码块可以为一个目标
25
+ */
26
+ export declare class Target extends EventEmitter {
27
+ /**
28
+ * 如何识别目标
29
+ */
30
+ isTarget: IsTarget;
31
+ /**
32
+ * 目标id,不可重复
33
+ * 例如目标是代码块,则为代码块id
34
+ */
35
+ id: string | number;
36
+ /**
37
+ * 目标名称,用于显示在依赖列表中
38
+ */
39
+ name: string;
40
+ /**
41
+ * 不同的目标可以进行分类,例如代码块,数据源可以为两个不同的type
42
+ */
43
+ type: string;
44
+ /**
45
+ * 依赖详情
46
+ * 实例:{ 'node_id': { name: 'node_name', keys: [ created, mounted ] } }
47
+ */
48
+ deps: Dep;
49
+ constructor(options: TargetOptions);
50
+ /**
51
+ * 更新依赖
52
+ * @param node 节点配置
53
+ * @param key 哪个key配置了这个目标的id
54
+ */
55
+ updateDep(node: MNode, key: string | number): void;
56
+ /**
57
+ * 删除依赖
58
+ * @param node 哪个节点的依赖需要移除,如果为空,则移除所有依赖
59
+ * @param key 节点下哪个key需要移除,如果为空,则移除改节点下的所有依赖key
60
+ * @returns void
61
+ */
62
+ removeDep(node?: MNode, key?: string | number): void;
63
+ /**
64
+ * 判断指定节点下的指定key是否存在在依赖列表中
65
+ * @param node 哪个节点
66
+ * @param key 哪个key
67
+ * @returns boolean
68
+ */
69
+ hasDep(node: MNode, key: string | number): boolean;
70
+ destroy(): void;
71
+ }
72
+ export declare class Watcher extends EventEmitter {
73
+ targets: TargetList;
74
+ /**
75
+ * 获取指定类型中的所有target
76
+ * @param type 分类
77
+ * @returns Target[]
78
+ */
79
+ getTargets(type?: string): {
80
+ [key: string]: Target;
81
+ [key: number]: Target;
82
+ };
83
+ /**
84
+ * 添加新的目标
85
+ * @param target Target
86
+ */
87
+ addTarget(target: Target): void;
88
+ /**
89
+ * 获取指定id的target
90
+ * @param id target id
91
+ * @returns Target
92
+ */
93
+ getTarget(id: string | number): Target | undefined;
94
+ /**
95
+ * 判断是否存在指定id的target
96
+ * @param id target id
97
+ * @returns boolean
98
+ */
99
+ hasTarget(id: string | number): boolean;
100
+ /**
101
+ * 删除指定id的target
102
+ * @param id target id
103
+ */
104
+ removeTarget(id: string | number): void;
105
+ /**
106
+ * 删除指定分类的所有target
107
+ * @param type 分类
108
+ * @returns void
109
+ */
110
+ removeTargets(type?: string): void;
111
+ /**
112
+ * 删除所有target
113
+ */
114
+ clearTargets(): void;
115
+ /**
116
+ * 收集依赖
117
+ * @param nodes 需要收集的节点
118
+ * @param deep 是否需要收集子节点
119
+ */
120
+ collect(nodes: MNode[], deep?: boolean): void;
121
+ /**
122
+ * 清除依赖
123
+ * @param nodes 需要清除依赖的节点
124
+ */
125
+ clear(nodes?: MNode[]): void;
126
+ private collectItem;
127
+ }
128
+ export declare type DepService = Watcher;
129
+ declare const _default: Watcher;
130
+ export default _default;
@@ -1,4 +1,4 @@
1
- import type { CodeBlockDSL, Id, MContainer, MNode } from '@tmagic/schema';
1
+ import type { Id, MContainer, MNode } from '@tmagic/schema';
2
2
  import type { AddMNode, EditorNodeInfo, PastePosition, StepValue, StoreState, StoreStateKey } from '../type';
3
3
  import { LayerOffset, Layout } from '../type';
4
4
  import BaseService from './BaseService';
@@ -136,18 +136,6 @@ declare class Editor extends BaseService {
136
136
  resetState(): void;
137
137
  destroy(): void;
138
138
  resetModifiedNodeId(): void;
139
- /**
140
- * 从dsl中的codeBlocks字段读取活动的代码块
141
- * @returns {CodeBlockDSL | null}
142
- */
143
- getCodeDsl(): Promise<CodeBlockDSL | null>;
144
- getCodeDslSync(): CodeBlockDSL | null;
145
- /**
146
- * 设置代码块到dsl的codeBlocks字段
147
- * @param {CodeBlockDSL} codeDsl 代码DSL
148
- * @returns {void}
149
- */
150
- setCodeDsl(codeDsl: CodeBlockDSL): Promise<void>;
151
139
  private addModifiedNodeId;
152
140
  private pushHistoryState;
153
141
  private changeHistoryState;
@@ -17,22 +17,8 @@ declare class Props extends BaseService {
17
17
  } | {
18
18
  title: string;
19
19
  items: {
20
- type: string;
21
20
  name: string;
22
- items: ({
23
- name: string;
24
- label: string;
25
- type: string;
26
- options: (mForm: import("@tmagic/form").FormState, { formValue }: any) => {
27
- text: string;
28
- value: string;
29
- }[];
30
- } | {
31
- name: string;
32
- label: string;
33
- type: string;
34
- options?: undefined;
35
- })[];
21
+ type: string;
36
22
  }[];
37
23
  labelWidth?: undefined;
38
24
  lazy?: undefined;
package/types/type.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import type { Component } from 'vue';
2
- import type { FormConfig } from '@tmagic/form';
2
+ import type { FormConfig, FormItem } from '@tmagic/form';
3
3
  import type { CodeBlockContent, CodeBlockDSL, Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
4
4
  import type StageCore from '@tmagic/stage';
5
5
  import type { ContainerHighlightType, CustomizeMoveableOptionsCallbackConfig, MoveableOptions, UpdateDragEl } from '@tmagic/stage';
6
6
  import type { CodeBlockService } from './services/codeBlock';
7
7
  import type { ComponentListService } from './services/componentList';
8
+ import type { DepService } from './services/dep';
8
9
  import type { EditorService } from './services/editor';
9
10
  import type { EventsService } from './services/events';
10
11
  import type { HistoryService } from './services/history';
@@ -26,6 +27,7 @@ export interface Services {
26
27
  componentListService: ComponentListService;
27
28
  uiService: UiService;
28
29
  codeBlockService: CodeBlockService;
30
+ depService: DepService;
29
31
  }
30
32
  export interface StageOptions {
31
33
  runtimeUrl: string;
@@ -268,8 +270,6 @@ export declare type CodeState = {
268
270
  combineIds: string[];
269
271
  /** 为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除) */
270
272
  undeletableList: Id[];
271
- /** 代码块和组件的绑定关系 */
272
- relations: CodeRelation;
273
273
  };
274
274
  export declare type HookData = {
275
275
  /** 代码块id */
@@ -328,3 +328,17 @@ export interface HistoryState {
328
328
  canRedo: boolean;
329
329
  canUndo: boolean;
330
330
  }
331
+ export interface EventSelectConfig {
332
+ name: string;
333
+ type: 'event-select';
334
+ /** 事件名称表单配置 */
335
+ eventNameConfig?: FormItem;
336
+ /** 动作类型配置 */
337
+ actionTypeConfig?: FormItem;
338
+ /** 联动组件配置 */
339
+ targetCompConfig?: FormItem;
340
+ /** 联动组件动作配置 */
341
+ compActionConfig?: FormItem;
342
+ /** 联动代码配置 */
343
+ codeActionConfig?: FormItem;
344
+ }
@@ -0,0 +1,3 @@
1
+ import { CodeBlockContent, Id } from '@tmagic/schema';
2
+ import { Target } from '../services/dep';
3
+ export declare const createCodeBlockTarget: (id: Id, codeBlock: CodeBlockContent) => Target;
@@ -1,4 +1,4 @@
1
- import { FormConfig, FormState } from '@tmagic/form';
1
+ import { FormConfig } from '@tmagic/form';
2
2
  /**
3
3
  * 统一为组件属性表单加上事件、高级、样式配置
4
4
  * @param config 组件属性配置
@@ -16,22 +16,8 @@ export declare const fillConfig: (config?: FormConfig) => {
16
16
  } | {
17
17
  title: string;
18
18
  items: {
19
- type: string;
20
19
  name: string;
21
- items: ({
22
- name: string;
23
- label: string;
24
- type: string;
25
- options: (mForm: FormState, { formValue }: any) => {
26
- text: string;
27
- value: string;
28
- }[];
29
- } | {
30
- name: string;
31
- label: string;
32
- type: string;
33
- options?: undefined;
34
- })[];
20
+ type: string;
35
21
  }[];
36
22
  labelWidth?: undefined;
37
23
  lazy?: undefined;