@tmagic/editor 1.4.6 → 1.4.8

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 (158) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/tmagic-editor.js +636 -589
  3. package/dist/tmagic-editor.umd.cjs +634 -586
  4. package/package.json +15 -11
  5. package/types/editorProps.d.ts +0 -7
  6. package/types/layouts/PropsPanel.vue.d.ts +9 -9
  7. package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
  8. package/types/services/codeBlock.d.ts +2 -1
  9. package/types/services/dataSource.d.ts +2 -1
  10. package/types/services/dep.d.ts +12 -2
  11. package/types/services/editor.d.ts +22 -4
  12. package/types/services/props.d.ts +7 -6
  13. package/types/type.d.ts +6 -0
  14. package/types/utils/editor.d.ts +1 -0
  15. package/types/utils/idle-task.d.ts +14 -0
  16. package/types/utils/operator.d.ts +2 -2
  17. package/src/Editor.vue +0 -211
  18. package/src/components/CodeBlockEditor.vue +0 -268
  19. package/src/components/CodeParams.vue +0 -60
  20. package/src/components/ContentMenu.vue +0 -193
  21. package/src/components/FloatingBox.vue +0 -178
  22. package/src/components/Icon.vue +0 -27
  23. package/src/components/Resizer.vue +0 -23
  24. package/src/components/ScrollBar.vue +0 -151
  25. package/src/components/ScrollViewer.vue +0 -128
  26. package/src/components/SearchInput.vue +0 -37
  27. package/src/components/SplitView.vue +0 -186
  28. package/src/components/ToolButton.vue +0 -138
  29. package/src/components/Tree.vue +0 -71
  30. package/src/components/TreeNode.vue +0 -148
  31. package/src/editorProps.ts +0 -124
  32. package/src/fields/Code.vue +0 -50
  33. package/src/fields/CodeLink.vue +0 -80
  34. package/src/fields/CodeSelect.vue +0 -132
  35. package/src/fields/CodeSelectCol.vue +0 -139
  36. package/src/fields/DataSourceFieldSelect.vue +0 -149
  37. package/src/fields/DataSourceFields.vue +0 -323
  38. package/src/fields/DataSourceInput.vue +0 -325
  39. package/src/fields/DataSourceMethodSelect.vue +0 -153
  40. package/src/fields/DataSourceMethods.vue +0 -104
  41. package/src/fields/DataSourceMocks.vue +0 -255
  42. package/src/fields/DataSourceSelect.vue +0 -98
  43. package/src/fields/EventSelect.vue +0 -301
  44. package/src/fields/KeyValue.vue +0 -137
  45. package/src/fields/PageFragmentSelect.vue +0 -63
  46. package/src/fields/UISelect.vue +0 -135
  47. package/src/hooks/index.ts +0 -24
  48. package/src/hooks/use-code-block-edit.ts +0 -83
  49. package/src/hooks/use-data-source-edit.ts +0 -46
  50. package/src/hooks/use-data-source-method.ts +0 -100
  51. package/src/hooks/use-editor-content-height.ts +0 -26
  52. package/src/hooks/use-filter.ts +0 -55
  53. package/src/hooks/use-float-box.ts +0 -76
  54. package/src/hooks/use-getso.ts +0 -35
  55. package/src/hooks/use-next-float-box-position.ts +0 -29
  56. package/src/hooks/use-node-status.ts +0 -48
  57. package/src/hooks/use-stage.ts +0 -129
  58. package/src/hooks/use-window-rect.ts +0 -20
  59. package/src/icons/AppManageIcon.vue +0 -15
  60. package/src/icons/CenterIcon.vue +0 -13
  61. package/src/icons/CodeIcon.vue +0 -28
  62. package/src/icons/FolderMinusIcon.vue +0 -22
  63. package/src/icons/PinIcon.vue +0 -25
  64. package/src/icons/PinnedIcon.vue +0 -25
  65. package/src/index.ts +0 -118
  66. package/src/initService.ts +0 -447
  67. package/src/layouts/AddPageBox.vue +0 -55
  68. package/src/layouts/CodeEditor.vue +0 -226
  69. package/src/layouts/Framework.vue +0 -163
  70. package/src/layouts/NavMenu.vue +0 -200
  71. package/src/layouts/PropsPanel.vue +0 -130
  72. package/src/layouts/page-bar/AddButton.vue +0 -48
  73. package/src/layouts/page-bar/PageBar.vue +0 -159
  74. package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
  75. package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
  76. package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
  77. package/src/layouts/sidebar/Sidebar.vue +0 -278
  78. package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -142
  79. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
  80. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
  81. package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -160
  82. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
  83. package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
  84. package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
  85. package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
  86. package/src/layouts/sidebar/layer/use-click.ts +0 -110
  87. package/src/layouts/sidebar/layer/use-drag.ts +0 -161
  88. package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
  89. package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
  90. package/src/layouts/workspace/Breadcrumb.vue +0 -35
  91. package/src/layouts/workspace/Workspace.vue +0 -46
  92. package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
  93. package/src/layouts/workspace/viewer/Stage.vue +0 -246
  94. package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
  95. package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
  96. package/src/services/BaseService.ts +0 -230
  97. package/src/services/codeBlock.ts +0 -324
  98. package/src/services/componentList.ts +0 -58
  99. package/src/services/dataSource.ts +0 -209
  100. package/src/services/dep.ts +0 -80
  101. package/src/services/editor.ts +0 -1087
  102. package/src/services/events.ts +0 -93
  103. package/src/services/history.ts +0 -126
  104. package/src/services/keybinding.ts +0 -220
  105. package/src/services/props.ts +0 -265
  106. package/src/services/stageOverlay.ts +0 -212
  107. package/src/services/storage.ts +0 -155
  108. package/src/services/ui.ts +0 -156
  109. package/src/shims-vue.d.ts +0 -6
  110. package/src/theme/breadcrumb.scss +0 -6
  111. package/src/theme/code-block.scss +0 -6
  112. package/src/theme/code-editor.scss +0 -38
  113. package/src/theme/common/var.scss +0 -14
  114. package/src/theme/component-list-panel.scss +0 -95
  115. package/src/theme/content-menu.scss +0 -76
  116. package/src/theme/data-source-field.scss +0 -12
  117. package/src/theme/data-source-fields.scss +0 -13
  118. package/src/theme/data-source-input.scss +0 -18
  119. package/src/theme/data-source-methods.scss +0 -13
  120. package/src/theme/data-source.scss +0 -28
  121. package/src/theme/event.scss +0 -37
  122. package/src/theme/floating-box.scss +0 -32
  123. package/src/theme/framework.scss +0 -69
  124. package/src/theme/icon.scss +0 -12
  125. package/src/theme/index.scss +0 -10
  126. package/src/theme/key-value.scss +0 -20
  127. package/src/theme/layer-panel.scss +0 -26
  128. package/src/theme/layout.scss +0 -9
  129. package/src/theme/nav-menu.scss +0 -78
  130. package/src/theme/page-bar.scss +0 -89
  131. package/src/theme/page-fragment-select.scss +0 -14
  132. package/src/theme/props-panel.scss +0 -55
  133. package/src/theme/resizer.scss +0 -66
  134. package/src/theme/ruler.scss +0 -38
  135. package/src/theme/search-input.scss +0 -14
  136. package/src/theme/sidebar.scss +0 -79
  137. package/src/theme/stage.scss +0 -76
  138. package/src/theme/theme.scss +0 -27
  139. package/src/theme/tree.scss +0 -89
  140. package/src/theme/workspace.scss +0 -9
  141. package/src/type.ts +0 -746
  142. package/src/utils/compose.ts +0 -52
  143. package/src/utils/config.ts +0 -29
  144. package/src/utils/content-menu.ts +0 -95
  145. package/src/utils/data-source/formConfigs/base.ts +0 -30
  146. package/src/utils/data-source/formConfigs/http.ts +0 -60
  147. package/src/utils/data-source/index.ts +0 -236
  148. package/src/utils/editor.ts +0 -294
  149. package/src/utils/index.ts +0 -24
  150. package/src/utils/keybinding-config.ts +0 -125
  151. package/src/utils/logger.ts +0 -47
  152. package/src/utils/monaco-editor.ts +0 -8
  153. package/src/utils/operator.ts +0 -106
  154. package/src/utils/props.ts +0 -504
  155. package/src/utils/scroll-viewer.ts +0 -165
  156. package/src/utils/tree.ts +0 -15
  157. package/src/utils/undo-redo.ts +0 -76
  158. package/tsconfig.build.json +0 -16
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.6",
2
+ "version": "1.4.8",
3
3
  "name": "@tmagic/editor",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -22,6 +22,10 @@
22
22
  },
23
23
  "./*": "./*"
24
24
  },
25
+ "files": [
26
+ "dist",
27
+ "types"
28
+ ],
25
29
  "license": "Apache-2.0",
26
30
  "engines": {
27
31
  "node": ">=18"
@@ -50,8 +54,8 @@
50
54
  "lodash-es": "^4.17.21",
51
55
  "moveable": "^0.53.0",
52
56
  "serialize-javascript": "^6.0.0",
53
- "@tmagic/dep": "1.4.6",
54
- "@tmagic/table": "1.4.6"
57
+ "@tmagic/dep": "1.4.8",
58
+ "@tmagic/table": "1.4.8"
55
59
  },
56
60
  "devDependencies": {
57
61
  "@types/events": "^3.0.0",
@@ -65,19 +69,19 @@
65
69
  "sass": "^1.77.0",
66
70
  "tsc-alias": "^1.8.5",
67
71
  "type-fest": "^4.10.3",
68
- "vite": "^5.2.11",
69
- "vue-tsc": "^2.0.16"
72
+ "vite": "^5.3.1",
73
+ "vue-tsc": "^2.0.19"
70
74
  },
71
75
  "peerDependencies": {
72
76
  "monaco-editor": "^0.48.0",
73
77
  "vue": "^3.4.27",
74
78
  "typescript": "*",
75
- "@tmagic/form": "1.4.6",
76
- "@tmagic/schema": "1.4.6",
77
- "@tmagic/design": "1.4.6",
78
- "@tmagic/core": "1.4.6",
79
- "@tmagic/utils": "1.4.6",
80
- "@tmagic/stage": "1.4.6"
79
+ "@tmagic/core": "1.4.8",
80
+ "@tmagic/design": "1.4.8",
81
+ "@tmagic/form": "1.4.8",
82
+ "@tmagic/stage": "1.4.8",
83
+ "@tmagic/schema": "1.4.8",
84
+ "@tmagic/utils": "1.4.8"
81
85
  },
82
86
  "peerDependenciesMeta": {
83
87
  "typescript": {
@@ -1,5 +1,4 @@
1
1
  import type { EventOption } from '@tmagic/core';
2
- import type { CustomTargetOptions } from '@tmagic/dep';
3
2
  import type { FormConfig, FormState } from '@tmagic/form';
4
3
  import type { DataSourceSchema, Id, MApp, MNode } from '@tmagic/schema';
5
4
  import StageCore, { ContainerHighlightType, type CustomizeMoveableOptionsCallbackConfig, type GuidesOptions, type MoveableOptions, RenderType, type UpdateDragEl } from '@tmagic/stage';
@@ -60,12 +59,6 @@ export interface EditorProps {
60
59
  };
61
60
  /** 禁用鼠标左键按下时就开始拖拽,需要先选中再可以拖拽 */
62
61
  disabledDragStart?: boolean;
63
- /** 自定义依赖收集器,复制组件时会将关联组件一并复制 */
64
- collectorOptions?: CustomTargetOptions;
65
- /** 自定义依赖收集器,复制组件时会将关联代码块一并复制 */
66
- collectorOptionsForCode?: CustomTargetOptions;
67
- /** 自定义依赖收集器,复制组件时会将关联数据源一并复制 */
68
- collectorOptionsForDataSource?: CustomTargetOptions;
69
62
  /** 标尺配置 */
70
63
  guidesOptions?: Partial<GuidesOptions>;
71
64
  /** 禁止多选 */
@@ -5,9 +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
- size: {
9
- type: import("vue").PropType<"default" | "small" | "large">;
10
- };
11
8
  popperClass: {
12
9
  type: import("vue").PropType<string>;
13
10
  };
@@ -15,6 +12,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
15
12
  type: import("vue").PropType<string>;
16
13
  default: string;
17
14
  };
15
+ size: {
16
+ type: import("vue").PropType<"default" | "small" | "large">;
17
+ };
18
18
  disabled: {
19
19
  type: import("vue").PropType<boolean>;
20
20
  default: boolean;
@@ -83,9 +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
- size: {
87
- type: import("vue").PropType<"default" | "small" | "large">;
88
- };
89
86
  popperClass: {
90
87
  type: import("vue").PropType<string>;
91
88
  };
@@ -93,6 +90,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
93
90
  type: import("vue").PropType<string>;
94
91
  default: string;
95
92
  };
93
+ size: {
94
+ type: import("vue").PropType<"default" | "small" | "large">;
95
+ };
96
96
  disabled: {
97
97
  type: import("vue").PropType<boolean>;
98
98
  default: boolean;
@@ -168,9 +168,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
168
168
  M: {};
169
169
  Defaults: {};
170
170
  }, Readonly<import("vue").ExtractPropTypes<{
171
- size: {
172
- type: import("vue").PropType<"default" | "small" | "large">;
173
- };
174
171
  popperClass: {
175
172
  type: import("vue").PropType<string>;
176
173
  };
@@ -178,6 +175,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
178
175
  type: import("vue").PropType<string>;
179
176
  default: string;
180
177
  };
178
+ size: {
179
+ type: import("vue").PropType<"default" | "small" | "large">;
180
+ };
181
181
  disabled: {
182
182
  type: import("vue").PropType<boolean>;
183
183
  default: boolean;
@@ -60,5 +60,5 @@ export declare const useClick: (services: Services | undefined, isCtrlKeyDown: R
60
60
  }> | undefined>;
61
61
  nodeClickHandler: (event: MouseEvent, data: TreeNodeData) => void;
62
62
  nodeContentMenuHandler(event: MouseEvent, data: TreeNodeData): void;
63
- highlightHandler: import("lodash-es").DebouncedFunc<(event: MouseEvent, data: TreeNodeData) => void>;
63
+ highlightHandler: (event: MouseEvent, data: TreeNodeData) => void;
64
64
  };
@@ -1,4 +1,5 @@
1
1
  import type { Writable } from 'type-fest';
2
+ import { type TargetOptions } from '@tmagic/dep';
2
3
  import type { ColumnConfig } from '@tmagic/form';
3
4
  import type { CodeBlockContent, CodeBlockDSL, Id, MNode } from '@tmagic/schema';
4
5
  import type { AsyncHookPlugin } from '../type';
@@ -114,7 +115,7 @@ declare class CodeBlock extends BaseService {
114
115
  * @param config 组件节点配置
115
116
  * @returns
116
117
  */
117
- copyWithRelated(config: MNode | MNode[]): void;
118
+ copyWithRelated(config: MNode | MNode[], collectorOptions?: TargetOptions): void;
118
119
  /**
119
120
  * 粘贴代码块
120
121
  * @returns
@@ -1,5 +1,6 @@
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
5
  import type { DataSourceSchema, MNode } from '@tmagic/schema';
5
6
  import type { DatasourceTypeOption, SyncHookPlugin } from '../type';
@@ -55,7 +56,7 @@ declare class DataSource extends BaseService {
55
56
  * @param config 组件节点配置
56
57
  * @returns
57
58
  */
58
- copyWithRelated(config: MNode | MNode[]): void;
59
+ copyWithRelated(config: MNode | MNode[], collectorOptions?: TargetOptions): void;
59
60
  /**
60
61
  * 粘贴数据源
61
62
  * @returns
@@ -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,8 +1,23 @@
1
1
  import { Writable } from 'type-fest';
2
- import type { Id, MContainer, MNode } from '@tmagic/schema';
2
+ import { type TargetOptions } from '@tmagic/dep';
3
+ import type { Id, MContainer, MNode, MPage, MPageFragment } from '@tmagic/schema';
3
4
  import BaseService from '../services/BaseService';
4
5
  import type { AddMNode, AsyncHookPlugin, EditorNodeInfo, PastePosition, StepValue, StoreState, StoreStateKey } from '../type';
5
6
  import { LayerOffset, Layout } from '../type';
7
+ export interface EditorEvents {
8
+ 'root-change': [value: StoreState['root'], preValue?: StoreState['root']];
9
+ select: [node: MNode | null];
10
+ add: [nodes: MNode[]];
11
+ remove: [nodes: MNode[]];
12
+ update: [nodes: MNode[]];
13
+ 'move-layer': [offset: number | LayerOffset];
14
+ 'drag-to': [data: {
15
+ targetIndex: number;
16
+ configs: MNode | MNode[];
17
+ targetParent: MContainer;
18
+ }];
19
+ 'history-change': [data: MPage | MPageFragment];
20
+ }
6
21
  declare const canUsePluginMethods: {
7
22
  async: readonly ["getLayout", "highlight", "select", "multiSelect", "doAdd", "add", "doRemove", "remove", "doUpdate", "update", "sort", "copy", "paste", "doPaste", "doAlignCenter", "alignCenter", "moveLayer", "moveToContainer", "dragTo", "undo", "redo", "move"];
8
23
  sync: never[];
@@ -109,13 +124,13 @@ declare class Editor extends BaseService {
109
124
  * @param config 组件节点配置
110
125
  * @returns
111
126
  */
112
- copyWithRelated(config: MNode | MNode[]): void;
127
+ copyWithRelated(config: MNode | MNode[], collectorOptions?: TargetOptions): void;
113
128
  /**
114
129
  * 从localStorage中获取节点,然后添加到当前容器中
115
130
  * @param position 粘贴的坐标
116
131
  * @returns 添加后的组件节点配置
117
132
  */
118
- paste(position?: PastePosition): Promise<MNode | MNode[] | void>;
133
+ paste(position?: PastePosition, collectorOptions?: TargetOptions): Promise<MNode | MNode[] | void>;
119
134
  doPaste(config: MNode[], position?: PastePosition): Promise<MNode[]>;
120
135
  doAlignCenter(config: MNode): Promise<MNode>;
121
136
  /**
@@ -135,7 +150,7 @@ declare class Editor extends BaseService {
135
150
  * @param targetId 容器ID
136
151
  */
137
152
  moveToContainer(config: MNode, targetId: Id): Promise<MNode | undefined>;
138
- dragTo(config: MNode, targetParent: MContainer, targetIndex: number): Promise<void>;
153
+ dragTo(config: MNode | MNode[], targetParent: MContainer, targetIndex: number): Promise<void>;
139
154
  /**
140
155
  * 撤销当前操作
141
156
  * @returns 上一次数据
@@ -151,6 +166,9 @@ declare class Editor extends BaseService {
151
166
  destroy(): void;
152
167
  resetModifiedNodeId(): void;
153
168
  usePlugin(options: AsyncHookPlugin<AsyncMethodName, Editor>): void;
169
+ on<Name extends keyof EditorEvents, Param extends EditorEvents[Name]>(eventName: Name, listener: (...args: Param) => void | Promise<void>): this;
170
+ once<Name extends keyof EditorEvents, Param extends EditorEvents[Name]>(eventName: Name, listener: (...args: Param) => void | Promise<void>): this;
171
+ emit<Name extends keyof EditorEvents, Param extends EditorEvents[Name]>(eventName: Name, ...args: Param): boolean;
154
172
  private addModifiedNodeId;
155
173
  private pushHistoryState;
156
174
  private changeHistoryState;
@@ -1,7 +1,8 @@
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
- import type { AsyncHookPlugin, SyncHookPlugin } from '../type';
5
+ import type { AsyncHookPlugin, PropsFormConfigFunction, PropsFormValueFunction, SyncHookPlugin } from '../type';
5
6
  import BaseService from './BaseService';
6
7
  declare const canUsePluginMethods: {
7
8
  async: readonly ["setPropsConfig", "getPropsConfig", "setPropsValue", "getPropsValue", "fillConfig", "getDefaultPropsValue"];
@@ -12,22 +13,22 @@ type SyncMethodName = Writable<(typeof canUsePluginMethods)['sync']>;
12
13
  declare class Props extends BaseService {
13
14
  private state;
14
15
  constructor();
15
- setPropsConfigs(configs: Record<string, FormConfig>): void;
16
+ setPropsConfigs(configs: Record<string, FormConfig | PropsFormConfigFunction>): void;
16
17
  fillConfig(config: FormConfig, labelWidth?: string): Promise<FormConfig>;
17
- setPropsConfig(type: string, config: FormConfig): Promise<void>;
18
+ setPropsConfig(type: string, config: FormConfig | PropsFormConfigFunction): Promise<void>;
18
19
  /**
19
20
  * 获取指点类型的组件属性表单配置
20
21
  * @param type 组件类型
21
22
  * @returns 组件属性表单配置
22
23
  */
23
24
  getPropsConfig(type: string): Promise<FormConfig>;
24
- setPropsValues(values: Record<string, Partial<MNode>>): void;
25
+ setPropsValues(values: Record<string, Partial<MNode> | PropsFormValueFunction>): void;
25
26
  /**
26
27
  * 为指点类型组件设置组件初始值
27
28
  * @param type 组件类型
28
29
  * @param value 组件初始值
29
30
  */
30
- setPropsValue(type: string, value: Partial<MNode>): Promise<void>;
31
+ setPropsValue(type: string, value: Partial<MNode> | PropsFormValueFunction): Promise<void>;
31
32
  /**
32
33
  * 获取指定类型的组件初始值
33
34
  * @param 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
@@ -617,3 +617,9 @@ export interface EventBus extends EventEmitter {
617
617
  on<Name extends keyof EventBusEvent, Param extends EventBusEvent[Name]>(eventName: Name, listener: (...args: Param) => void): this;
618
618
  emit<Name extends keyof EventBusEvent, Param extends EventBusEvent[Name]>(eventName: Name, ...args: Param): boolean;
619
619
  }
620
+ export type PropsFormConfigFunction = (data: {
621
+ editorService: EditorService;
622
+ }) => FormConfig;
623
+ export type PropsFormValueFunction = (data: {
624
+ editorService: EditorService;
625
+ }) => Partial<MNode>;
@@ -56,3 +56,4 @@ export interface NodeItem {
56
56
  [key: string]: any;
57
57
  }
58
58
  export declare const traverseNode: <T extends NodeItem = NodeItem>(node: T, cb: (node: T, parents: T[]) => void, parents?: T[]) => void;
59
+ export declare const moveItemsInContainer: (sourceIndices: number[], parent: MContainer, targetIndex: number) => void;
@@ -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
  };
package/src/Editor.vue DELETED
@@ -1,211 +0,0 @@
1
- <template>
2
- <Framework :disabled-page-fragment="disabledPageFragment">
3
- <template #header>
4
- <slot name="header"></slot>
5
- </template>
6
-
7
- <template #nav>
8
- <slot name="nav" :editorService="editorService"><TMagicNavMenu :data="menu"></TMagicNavMenu></slot>
9
- </template>
10
-
11
- <template #content-before>
12
- <slot name="content-before"></slot>
13
- </template>
14
-
15
- <template #src-code><slot name="src-code" :editorService="editorService"></slot></template>
16
-
17
- <template #sidebar>
18
- <slot name="sidebar" :editorService="editorService">
19
- <Sidebar :data="sidebar" :layer-content-menu="layerContentMenu" :custom-content-menu="customContentMenu">
20
- <template #layer-panel-header>
21
- <slot name="layer-panel-header"></slot>
22
- </template>
23
-
24
- <template #layer-node-content="{ data }">
25
- <slot name="layer-node-content" :data="data"></slot>
26
- </template>
27
-
28
- <template #layer-node-label="{ data }">
29
- <slot name="layer-node-label" :data="data"></slot>
30
- </template>
31
-
32
- <template #layer-node-tool="{ data }">
33
- <slot name="layer-node-tool" :data="data"></slot>
34
- </template>
35
-
36
- <template #component-list-panel-header>
37
- <slot name="component-list-panel-header"></slot>
38
- </template>
39
-
40
- <template #component-list-item="{ component }">
41
- <slot name="component-list-item" :component="component"></slot>
42
- </template>
43
-
44
- <template #code-block-panel-header>
45
- <slot name="code-block-panel-header"></slot>
46
- </template>
47
-
48
- <template #code-block-panel-tool="{ id, data }">
49
- <slot name="code-block-panel-tool" :id="id" :data="data"></slot>
50
- </template>
51
-
52
- <template #code-block-panel-search>
53
- <slot name="code-block-panel-search"></slot>
54
- </template>
55
-
56
- <template #data-source-panel-tool="{ data }">
57
- <slot name="data-source-panel-tool" :data="data"></slot>
58
- </template>
59
-
60
- <template #data-source-panel-search>
61
- <slot name="data-source-panel-search"></slot>
62
- </template>
63
- </Sidebar>
64
- </slot>
65
- </template>
66
-
67
- <template #workspace>
68
- <slot name="workspace" :editorService="editorService">
69
- <Workspace
70
- :disabled-stage-overlay="disabledStageOverlay"
71
- :stage-content-menu="stageContentMenu"
72
- :custom-content-menu="customContentMenu"
73
- >
74
- <template #stage><slot name="stage"></slot></template>
75
- <template #workspace-content><slot name="workspace-content" :editorService="editorService"></slot></template>
76
- </Workspace>
77
- </slot>
78
- </template>
79
-
80
- <template #props-panel>
81
- <slot name="props-panel">
82
- <PropsPanel
83
- :extend-state="extendFormState"
84
- :disabled-show-src="disabledShowSrc"
85
- @mounted="(instance: any) => $emit('props-panel-mounted', instance)"
86
- @form-error="(e: any) => $emit('props-form-error', e)"
87
- @submit-error="(e: any) => $emit('props-submit-error', e)"
88
- >
89
- <template #props-panel-header>
90
- <slot name="props-panel-header"></slot>
91
- </template>
92
- </PropsPanel>
93
- </slot>
94
- </template>
95
-
96
- <template #empty><slot name="empty" :editorService="editorService"></slot></template>
97
-
98
- <template #content-after>
99
- <slot name="content-after"></slot>
100
- </template>
101
-
102
- <template #footer>
103
- <slot name="footer"></slot>
104
- </template>
105
-
106
- <template #page-bar><slot name="page-bar"></slot></template>
107
- <template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
108
- <template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
109
- </Framework>
110
- </template>
111
-
112
- <script lang="ts" setup>
113
- import { EventEmitter } from 'events';
114
-
115
- import { provide } from 'vue';
116
-
117
- import type { MApp } from '@tmagic/schema';
118
-
119
- import Framework from './layouts/Framework.vue';
120
- import TMagicNavMenu from './layouts/NavMenu.vue';
121
- import PropsPanel from './layouts/PropsPanel.vue';
122
- import Sidebar from './layouts/sidebar/Sidebar.vue';
123
- import Workspace from './layouts/workspace/Workspace.vue';
124
- import codeBlockService from './services/codeBlock';
125
- import componentListService from './services/componentList';
126
- import dataSourceService from './services/dataSource';
127
- import depService from './services/dep';
128
- import editorService, { type EditorService } from './services/editor';
129
- import eventsService from './services/events';
130
- import historyService from './services/history';
131
- import keybindingService from './services/keybinding';
132
- import propsService from './services/props';
133
- import stageOverlayService from './services/stageOverlay';
134
- import storageService from './services/storage';
135
- import uiService from './services/ui';
136
- import keybindingConfig from './utils/keybinding-config';
137
- import { defaultEditorProps, EditorProps } from './editorProps';
138
- import { initServiceEvents, initServiceState } from './initService';
139
- import type { EventBus, FrameworkSlots, PropsPanelSlots, Services, SidebarSlots, WorkspaceSlots } from './type';
140
-
141
- defineSlots<
142
- FrameworkSlots &
143
- WorkspaceSlots &
144
- SidebarSlots &
145
- PropsPanelSlots & {
146
- workspace(props: { editorService: EditorService }): any;
147
- 'workspace-content'(props: { editorService: EditorService }): any;
148
- }
149
- >();
150
-
151
- defineOptions({
152
- name: 'MEditor',
153
- });
154
-
155
- const emit = defineEmits<{
156
- 'props-panel-mounted': [instance: InstanceType<typeof PropsPanel>];
157
- 'update:modelValue': [value: MApp | null];
158
- 'props-form-error': [e: any];
159
- 'props-submit-error': [e: any];
160
- }>();
161
-
162
- const props = withDefaults(defineProps<EditorProps>(), defaultEditorProps);
163
-
164
- const services: Services = {
165
- componentListService,
166
- eventsService,
167
- historyService,
168
- propsService,
169
- editorService,
170
- uiService,
171
- storageService,
172
- codeBlockService,
173
- depService,
174
- dataSourceService,
175
- keybindingService,
176
- stageOverlayService,
177
- };
178
-
179
- initServiceEvents(props, emit, services);
180
- initServiceState(props, services);
181
- keybindingService.register(keybindingConfig);
182
- keybindingService.registerEl('global');
183
-
184
- const stageOptions = {
185
- runtimeUrl: props.runtimeUrl,
186
- autoScrollIntoView: props.autoScrollIntoView,
187
- render: props.render,
188
- moveableOptions: props.moveableOptions,
189
- canSelect: props.canSelect,
190
- updateDragEl: props.updateDragEl,
191
- isContainer: props.isContainer,
192
- containerHighlightClassName: props.containerHighlightClassName,
193
- containerHighlightDuration: props.containerHighlightDuration,
194
- containerHighlightType: props.containerHighlightType,
195
- disabledDragStart: props.disabledDragStart,
196
- renderType: props.renderType,
197
- guidesOptions: props.guidesOptions,
198
- disabledMultiSelect: props.disabledMultiSelect,
199
- };
200
-
201
- stageOverlayService.set('stageOptions', stageOptions);
202
-
203
- provide('services', services);
204
-
205
- provide('codeOptions', props.codeOptions);
206
- provide('stageOptions', stageOptions);
207
-
208
- provide<EventBus>('eventBus', new EventEmitter());
209
-
210
- defineExpose(services);
211
- </script>