@tmagic/editor 1.4.5 → 1.4.7

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 (38) hide show
  1. package/dist/tmagic-editor.js +2293 -1984
  2. package/dist/tmagic-editor.umd.cjs +2294 -1982
  3. package/package.json +19 -14
  4. package/src/components/TreeNode.vue +3 -1
  5. package/src/editorProps.ts +0 -3
  6. package/src/fields/DataSourceInput.vue +7 -1
  7. package/src/fields/EventSelect.vue +90 -16
  8. package/src/hooks/use-code-block-edit.ts +0 -2
  9. package/src/hooks/use-stage.ts +1 -1
  10. package/src/index.ts +1 -0
  11. package/src/initService.ts +24 -18
  12. package/src/layouts/sidebar/code-block/CodeBlockList.vue +34 -16
  13. package/src/layouts/sidebar/data-source/DataSourceList.vue +17 -5
  14. package/src/services/codeBlock.ts +80 -9
  15. package/src/services/dataSource.ts +60 -4
  16. package/src/services/dep.ts +77 -5
  17. package/src/services/editor.ts +23 -14
  18. package/src/services/props.ts +19 -8
  19. package/src/services/stageOverlay.ts +1 -0
  20. package/src/type.ts +1 -0
  21. package/src/utils/data-source/index.ts +20 -13
  22. package/src/utils/editor.ts +2 -0
  23. package/src/utils/idle-task.ts +72 -0
  24. package/src/utils/operator.ts +6 -6
  25. package/types/editorProps.d.ts +0 -3
  26. package/types/index.d.ts +1 -0
  27. package/types/layouts/PropsPanel.vue.d.ts +33 -33
  28. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +1 -1
  29. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +1 -1
  30. package/types/services/codeBlock.d.ts +23 -2
  31. package/types/services/dataSource.d.ts +13 -1
  32. package/types/services/dep.d.ts +12 -2
  33. package/types/services/editor.d.ts +3 -2
  34. package/types/services/props.d.ts +2 -1
  35. package/types/type.d.ts +1 -0
  36. package/types/utils/editor.d.ts +2 -0
  37. package/types/utils/idle-task.d.ts +14 -0
  38. package/types/utils/operator.d.ts +2 -2
@@ -5,17 +5,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
5
5
  extendState?: ((state: FormState) => Record<string, any> | Promise<Record<string, any>>) | undefined;
6
6
  }>, {
7
7
  configForm: import("vue").Ref<import("vue").CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
8
- labelWidth: {
9
- type: import("vue").PropType<string>;
10
- default: string;
11
- };
12
- disabled: {
13
- type: import("vue").PropType<boolean>;
14
- default: boolean;
15
- };
16
- size: {
17
- type: import("vue").PropType<"default" | "small" | "large">;
18
- };
19
8
  popperClass: {
20
9
  type: import("vue").PropType<string>;
21
10
  };
@@ -23,11 +12,22 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
23
12
  type: import("vue").PropType<string>;
24
13
  default: string;
25
14
  };
15
+ size: {
16
+ type: import("vue").PropType<"default" | "small" | "large">;
17
+ };
18
+ disabled: {
19
+ type: import("vue").PropType<boolean>;
20
+ default: boolean;
21
+ };
26
22
  config: {
27
23
  type: import("vue").PropType<import("@tmagic/form").FormConfig>;
28
24
  required: true;
29
25
  default: () => never[];
30
26
  };
27
+ labelWidth: {
28
+ type: import("vue").PropType<string>;
29
+ default: string;
30
+ };
31
31
  initValues: {
32
32
  type: import("vue").PropType<Record<string, any>>;
33
33
  required: true;
@@ -83,17 +83,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
83
83
  "field-input": (...args: any[]) => void;
84
84
  "field-change": (...args: any[]) => void;
85
85
  }, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
86
- labelWidth: {
87
- type: import("vue").PropType<string>;
88
- default: string;
89
- };
90
- disabled: {
91
- type: import("vue").PropType<boolean>;
92
- default: boolean;
93
- };
94
- size: {
95
- type: import("vue").PropType<"default" | "small" | "large">;
96
- };
97
86
  popperClass: {
98
87
  type: import("vue").PropType<string>;
99
88
  };
@@ -101,11 +90,22 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
101
90
  type: import("vue").PropType<string>;
102
91
  default: string;
103
92
  };
93
+ size: {
94
+ type: import("vue").PropType<"default" | "small" | "large">;
95
+ };
96
+ disabled: {
97
+ type: import("vue").PropType<boolean>;
98
+ default: boolean;
99
+ };
104
100
  config: {
105
101
  type: import("vue").PropType<import("@tmagic/form").FormConfig>;
106
102
  required: true;
107
103
  default: () => never[];
108
104
  };
105
+ labelWidth: {
106
+ type: import("vue").PropType<string>;
107
+ default: string;
108
+ };
109
109
  initValues: {
110
110
  type: import("vue").PropType<Record<string, any>>;
111
111
  required: true;
@@ -168,17 +168,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
168
168
  M: {};
169
169
  Defaults: {};
170
170
  }, Readonly<import("vue").ExtractPropTypes<{
171
- labelWidth: {
172
- type: import("vue").PropType<string>;
173
- default: string;
174
- };
175
- disabled: {
176
- type: import("vue").PropType<boolean>;
177
- default: boolean;
178
- };
179
- size: {
180
- type: import("vue").PropType<"default" | "small" | "large">;
181
- };
182
171
  popperClass: {
183
172
  type: import("vue").PropType<string>;
184
173
  };
@@ -186,11 +175,22 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
186
175
  type: import("vue").PropType<string>;
187
176
  default: string;
188
177
  };
178
+ size: {
179
+ type: import("vue").PropType<"default" | "small" | "large">;
180
+ };
181
+ disabled: {
182
+ type: import("vue").PropType<boolean>;
183
+ default: boolean;
184
+ };
189
185
  config: {
190
186
  type: import("vue").PropType<import("@tmagic/form").FormConfig>;
191
187
  required: true;
192
188
  default: () => never[];
193
189
  };
190
+ labelWidth: {
191
+ type: import("vue").PropType<string>;
192
+ default: string;
193
+ };
194
194
  initValues: {
195
195
  type: import("vue").PropType<Record<string, any>>;
196
196
  required: true;
@@ -10,8 +10,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
10
10
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<{
11
11
  customError?: ((id: Id, errorType: CodeDeleteErrorType) => any) | undefined;
12
12
  }>>> & {
13
- onEdit?: ((id: string) => any) | undefined;
14
13
  onRemove?: ((id: string) => any) | undefined;
14
+ onEdit?: ((id: string) => any) | undefined;
15
15
  }, {}, {}>, Readonly<CodeBlockListSlots> & CodeBlockListSlots>;
16
16
  export default _default;
17
17
  type __VLS_WithTemplateSlots<T, S> = T & {
@@ -5,8 +5,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}
5
5
  remove: (id: string) => void;
6
6
  edit: (id: string) => void;
7
7
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>> & {
8
- onEdit?: ((id: string) => any) | undefined;
9
8
  onRemove?: ((id: string) => any) | undefined;
9
+ onEdit?: ((id: string) => any) | undefined;
10
10
  }, {}, {}>, Readonly<DataSourceListSlots> & DataSourceListSlots>;
11
11
  export default _default;
12
12
  type __VLS_WithTemplateSlots<T, S> = T & {
@@ -1,11 +1,12 @@
1
1
  import type { Writable } from 'type-fest';
2
+ import { type TargetOptions } from '@tmagic/dep';
2
3
  import type { ColumnConfig } from '@tmagic/form';
3
- import type { CodeBlockContent, CodeBlockDSL, Id } from '@tmagic/schema';
4
+ import type { CodeBlockContent, CodeBlockDSL, Id, MNode } from '@tmagic/schema';
4
5
  import type { AsyncHookPlugin } from '../type';
5
6
  import BaseService from './BaseService';
6
7
  declare const canUsePluginMethods: {
7
8
  async: readonly ["setCodeDslById", "setEditStatus", "setCombineIds", "setUndeleteableList", "deleteCodeDslByIds"];
8
- sync: never[];
9
+ sync: string[];
9
10
  };
10
11
  type AsyncMethodName = Writable<(typeof canUsePluginMethods)['async']>;
11
12
  declare class CodeBlock extends BaseService {
@@ -37,6 +38,15 @@ declare class CodeBlock extends BaseService {
37
38
  * @returns {void}
38
39
  */
39
40
  setCodeDslById(id: Id, codeConfig: Partial<CodeBlockContent>): Promise<void>;
41
+ /**
42
+ * 为了兼容历史原因
43
+ * 设置代码块ID和代码内容到源dsl
44
+ * @param {Id} id 代码块id
45
+ * @param {CodeBlockContent} codeConfig 代码块内容配置信息
46
+ * @param {boolean} force 是否强制写入,默认true
47
+ * @returns {void}
48
+ */
49
+ setCodeDslByIdSync(id: Id, codeConfig: Partial<CodeBlockContent>, force?: boolean): void;
40
50
  /**
41
51
  * 根据代码块id数组获取代码dsl
42
52
  * @param {string[]} ids 代码块id数组
@@ -100,6 +110,17 @@ declare class CodeBlock extends BaseService {
100
110
  * @returns {Id} 代码块唯一id
101
111
  */
102
112
  getUniqueId(): Promise<string>;
113
+ /**
114
+ * 复制时会带上组件关联的代码块
115
+ * @param config 组件节点配置
116
+ * @returns
117
+ */
118
+ copyWithRelated(config: MNode | MNode[], collectorOptions?: TargetOptions): void;
119
+ /**
120
+ * 粘贴代码块
121
+ * @returns
122
+ */
123
+ paste(): void;
103
124
  resetState(): void;
104
125
  destroy(): void;
105
126
  usePlugin(options: AsyncHookPlugin<AsyncMethodName, CodeBlock>): void;
@@ -1,7 +1,8 @@
1
1
  import { Writable } from 'type-fest';
2
2
  import type { EventOption } from '@tmagic/core';
3
+ import { type TargetOptions } from '@tmagic/dep';
3
4
  import type { FormConfig } from '@tmagic/form';
4
- import type { DataSourceSchema } from '@tmagic/schema';
5
+ import type { DataSourceSchema, MNode } from '@tmagic/schema';
5
6
  import type { DatasourceTypeOption, SyncHookPlugin } from '../type';
6
7
  import BaseService from './BaseService';
7
8
  interface State {
@@ -50,6 +51,17 @@ declare class DataSource extends BaseService {
50
51
  resetState(): void;
51
52
  destroy(): void;
52
53
  usePlugin(options: SyncHookPlugin<SyncMethodName, DataSource>): void;
54
+ /**
55
+ * 复制时会带上组件关联的数据源
56
+ * @param config 组件节点配置
57
+ * @returns
58
+ */
59
+ copyWithRelated(config: MNode | MNode[], collectorOptions?: TargetOptions): void;
60
+ /**
61
+ * 粘贴数据源
62
+ * @returns
63
+ */
64
+ paste(): void;
53
65
  }
54
66
  export type DataSourceService = DataSource;
55
67
  declare const _default: DataSource;
@@ -1,6 +1,11 @@
1
- import { DepTargetType, type Target } from '@tmagic/dep';
1
+ import { type DepExtendedData, DepTargetType, type Target } from '@tmagic/dep';
2
2
  import type { Id, MNode } from '@tmagic/schema';
3
3
  import BaseService from './BaseService';
4
+ export interface DepEvents {
5
+ 'add-target': [target: Target];
6
+ 'remove-target': [id: string | number];
7
+ collected: [nodes: MNode[], deep: boolean];
8
+ }
4
9
  declare class Dep extends BaseService {
5
10
  private watcher;
6
11
  removeTargets(type?: string): void;
@@ -12,11 +17,16 @@ declare class Dep extends BaseService {
12
17
  addTarget(target: Target): void;
13
18
  removeTarget(id: Id, type?: string): void;
14
19
  clearTargets(): void;
15
- collect(nodes: MNode[], deep?: boolean, type?: DepTargetType): void;
20
+ collect(nodes: MNode[], depExtendedData?: DepExtendedData, deep?: boolean, type?: DepTargetType): void;
21
+ collectIdle(nodes: MNode[], depExtendedData?: DepExtendedData, deep?: boolean, type?: DepTargetType): void;
22
+ collectNode(node: MNode, target: Target, depExtendedData?: DepExtendedData, deep?: boolean): void;
16
23
  clear(nodes?: MNode[]): void;
17
24
  clearByType(type: DepTargetType, nodes?: MNode[]): void;
18
25
  hasTarget(id: Id, type?: string): boolean;
19
26
  hasSpecifiedTypeTarget(type?: string): boolean;
27
+ on<Name extends keyof DepEvents, Param extends DepEvents[Name]>(eventName: Name, listener: (...args: Param) => void | Promise<void>): this;
28
+ once<Name extends keyof DepEvents, Param extends DepEvents[Name]>(eventName: Name, listener: (...args: Param) => void | Promise<void>): this;
29
+ emit<Name extends keyof DepEvents, Param extends DepEvents[Name]>(eventName: Name, ...args: Param): boolean;
20
30
  }
21
31
  export type DepService = Dep;
22
32
  declare const _default: Dep;
@@ -1,4 +1,5 @@
1
1
  import { Writable } from 'type-fest';
2
+ import { type TargetOptions } from '@tmagic/dep';
2
3
  import type { Id, MContainer, MNode } from '@tmagic/schema';
3
4
  import BaseService from '../services/BaseService';
4
5
  import type { AddMNode, AsyncHookPlugin, EditorNodeInfo, PastePosition, StepValue, StoreState, StoreStateKey } from '../type';
@@ -109,13 +110,13 @@ declare class Editor extends BaseService {
109
110
  * @param config 组件节点配置
110
111
  * @returns
111
112
  */
112
- copyWithRelated(config: MNode | MNode[]): void;
113
+ copyWithRelated(config: MNode | MNode[], collectorOptions?: TargetOptions): void;
113
114
  /**
114
115
  * 从localStorage中获取节点,然后添加到当前容器中
115
116
  * @param position 粘贴的坐标
116
117
  * @returns 添加后的组件节点配置
117
118
  */
118
- paste(position?: PastePosition): Promise<MNode | MNode[] | void>;
119
+ paste(position?: PastePosition, collectorOptions?: TargetOptions): Promise<MNode | MNode[] | void>;
119
120
  doPaste(config: MNode[], position?: PastePosition): Promise<MNode[]>;
120
121
  doAlignCenter(config: MNode): Promise<MNode>;
121
122
  /**
@@ -1,4 +1,5 @@
1
1
  import { Writable } from 'type-fest';
2
+ import { type TargetOptions } from '@tmagic/dep';
2
3
  import type { FormConfig } from '@tmagic/form';
3
4
  import type { MNode } from '@tmagic/schema';
4
5
  import type { AsyncHookPlugin, SyncHookPlugin } from '../type';
@@ -66,7 +67,7 @@ declare class Props extends BaseService {
66
67
  * @param originConfigs 原组件配置
67
68
  * @param targetConfigs 待替换的组件配置
68
69
  */
69
- replaceRelateId(originConfigs: MNode[], targetConfigs: MNode[]): void;
70
+ replaceRelateId(originConfigs: MNode[], targetConfigs: MNode[], collectorOptions: TargetOptions): void;
70
71
  /**
71
72
  * 清除setNewItemId前后映射关系
72
73
  */
package/types/type.d.ts CHANGED
@@ -117,6 +117,7 @@ export interface StageOptions {
117
117
  renderType?: RenderType;
118
118
  guidesOptions?: Partial<GuidesOptions>;
119
119
  disabledMultiSelect?: boolean;
120
+ zoom?: number;
120
121
  }
121
122
  export interface StoreState {
122
123
  root: MApp | null;
@@ -3,6 +3,8 @@ import { NodeType } from '@tmagic/schema';
3
3
  import type StageCore from '@tmagic/stage';
4
4
  import { Layout } from '../type';
5
5
  export declare const COPY_STORAGE_KEY = "$MagicEditorCopyData";
6
+ export declare const COPY_CODE_STORAGE_KEY = "$MagicEditorCopyCode";
7
+ export declare const COPY_DS_STORAGE_KEY = "$MagicEditorCopyDataSource";
6
8
  /**
7
9
  * 获取所有页面配置
8
10
  * @param root DSL跟节点
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ export interface IdleTaskEvents {
4
+ finish: [];
5
+ }
6
+ export declare class IdleTask<T = any> extends EventEmitter {
7
+ private taskList;
8
+ private taskHandle;
9
+ enqueueTask(taskHandler: (data: T) => void, taskData: T): void;
10
+ on<Name extends keyof IdleTaskEvents, Param extends IdleTaskEvents[Name]>(eventName: Name, listener: (...args: Param) => void | Promise<void>): this;
11
+ once<Name extends keyof IdleTaskEvents, Param extends IdleTaskEvents[Name]>(eventName: Name, listener: (...args: Param) => void | Promise<void>): this;
12
+ emit<Name extends keyof IdleTaskEvents, Param extends IdleTaskEvents[Name]>(eventName: Name, ...args: Param): boolean;
13
+ private runTaskQueue;
14
+ }
@@ -6,14 +6,14 @@ import type { AddMNode, PastePosition } from '../type';
6
6
  * @param config 待粘贴的元素配置(复制时保存的那份配置)
7
7
  * @returns
8
8
  */
9
- export declare const beforePaste: (position: PastePosition, config: MNode[]) => MNode[];
9
+ export declare const beforePaste: (position: PastePosition, config: MNode[], doc?: Document) => MNode[];
10
10
  /**
11
11
  * 将元素粘贴到容器内时,将相对于画布坐标转换为相对于容器的坐标
12
12
  * @param position PastePosition 粘贴时相对于画布的坐标
13
13
  * @param id 元素id
14
14
  * @returns PastePosition 转换后的坐标
15
15
  */
16
- export declare const getPositionInContainer: (position: PastePosition | undefined, id: Id) => {
16
+ export declare const getPositionInContainer: (position: PastePosition | undefined, id: Id, doc?: Document) => {
17
17
  left: number;
18
18
  top: number;
19
19
  };