@tmagic/editor 1.2.0-beta.9 → 1.2.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 (98) hide show
  1. package/dist/style.css +59 -35
  2. package/dist/{tmagic-editor.mjs → tmagic-editor.js} +1473 -1154
  3. package/dist/tmagic-editor.js.map +1 -0
  4. package/dist/{tmagic-editor.umd.js → tmagic-editor.umd.cjs} +1483 -1159
  5. package/dist/tmagic-editor.umd.cjs.map +1 -0
  6. package/package.json +16 -14
  7. package/src/Editor.vue +66 -40
  8. package/src/components/CodeDraftEditor.vue +145 -0
  9. package/src/components/ContentMenu.vue +1 -1
  10. package/src/components/FunctionEditor.vue +145 -0
  11. package/src/components/Icon.vue +1 -1
  12. package/src/{layouts → components}/Layout.vue +54 -15
  13. package/src/components/ScrollBar.vue +1 -1
  14. package/src/components/ScrollViewer.vue +10 -1
  15. package/src/components/ToolButton.vue +1 -1
  16. package/src/fields/Code.vue +1 -1
  17. package/src/fields/CodeLink.vue +1 -1
  18. package/src/fields/CodeSelect.vue +89 -102
  19. package/src/fields/UISelect.vue +1 -1
  20. package/src/index.ts +1 -0
  21. package/src/layouts/AddPageBox.vue +1 -1
  22. package/src/layouts/CodeEditor.vue +2 -3
  23. package/src/layouts/Framework.vue +2 -2
  24. package/src/layouts/NavMenu.vue +2 -2
  25. package/src/layouts/PropsPanel.vue +13 -6
  26. package/src/layouts/Resizer.vue +1 -1
  27. package/src/layouts/sidebar/ComponentListPanel.vue +1 -1
  28. package/src/layouts/sidebar/LayerMenu.vue +9 -7
  29. package/src/layouts/sidebar/LayerPanel.vue +127 -174
  30. package/src/layouts/sidebar/Sidebar.vue +110 -26
  31. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +27 -83
  32. package/src/layouts/sidebar/code-block/CodeBlockList.vue +90 -122
  33. package/src/layouts/workspace/Breadcrumb.vue +1 -1
  34. package/src/layouts/workspace/PageBar.vue +1 -1
  35. package/src/layouts/workspace/PageBarScrollContainer.vue +1 -1
  36. package/src/layouts/workspace/Stage.vue +26 -9
  37. package/src/layouts/workspace/ViewerMenu.vue +11 -9
  38. package/src/layouts/workspace/Workspace.vue +7 -3
  39. package/src/services/BaseService.ts +10 -1
  40. package/src/services/codeBlock.ts +124 -125
  41. package/src/services/componentList.ts +6 -1
  42. package/src/services/editor.ts +54 -18
  43. package/src/services/events.ts +6 -1
  44. package/src/services/history.ts +7 -16
  45. package/src/services/props.ts +7 -2
  46. package/src/services/storage.ts +1 -0
  47. package/src/services/ui.ts +12 -0
  48. package/src/theme/code-block.scss +43 -24
  49. package/src/theme/component-list-panel.scss +8 -5
  50. package/src/type.ts +77 -50
  51. package/src/utils/editor.ts +9 -1
  52. package/src/utils/index.ts +1 -0
  53. package/src/utils/props.ts +2 -2
  54. package/src/utils/scroll-viewer.ts +18 -2
  55. package/src/utils/stage.ts +4 -3
  56. package/types/Editor.vue.d.ts +47 -27
  57. package/types/components/CodeDraftEditor.vue.d.ts +56 -0
  58. package/types/components/ContentMenu.vue.d.ts +11 -87
  59. package/types/components/FunctionEditor.vue.d.ts +43 -0
  60. package/types/components/Icon.vue.d.ts +4 -50
  61. package/types/{layouts → components}/Layout.vue.d.ts +12 -1
  62. package/types/components/ScrollBar.vue.d.ts +7 -65
  63. package/types/components/ScrollViewer.vue.d.ts +45 -1
  64. package/types/components/ToolButton.vue.d.ts +12 -78
  65. package/types/fields/Code.vue.d.ts +11 -77
  66. package/types/fields/CodeLink.vue.d.ts +12 -82
  67. package/types/fields/CodeSelect.vue.d.ts +13 -77
  68. package/types/fields/UISelect.vue.d.ts +7 -65
  69. package/types/index.d.ts +1 -0
  70. package/types/layouts/AddPageBox.vue.d.ts +1 -43
  71. package/types/layouts/CodeEditor.vue.d.ts +22 -130
  72. package/types/layouts/NavMenu.vue.d.ts +9 -69
  73. package/types/layouts/sidebar/LayerMenu.vue.d.ts +16 -48
  74. package/types/layouts/sidebar/LayerPanel.vue.d.ts +24 -7
  75. package/types/layouts/sidebar/Sidebar.vue.d.ts +10 -5
  76. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +1 -1
  77. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +6 -5
  78. package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -43
  79. package/types/layouts/workspace/Stage.vue.d.ts +15 -43
  80. package/types/layouts/workspace/ViewerMenu.vue.d.ts +11 -66
  81. package/types/layouts/workspace/Workspace.vue.d.ts +23 -5
  82. package/types/services/BaseService.d.ts +2 -1
  83. package/types/services/codeBlock.d.ts +57 -36
  84. package/types/services/componentList.d.ts +1 -0
  85. package/types/services/editor.d.ts +5 -6
  86. package/types/services/events.d.ts +1 -0
  87. package/types/services/history.d.ts +5 -15
  88. package/types/services/props.d.ts +3 -2
  89. package/types/services/ui.d.ts +2 -1
  90. package/types/type.d.ts +65 -48
  91. package/types/utils/editor.d.ts +1 -0
  92. package/types/utils/index.d.ts +1 -0
  93. package/types/utils/props.d.ts +1 -1
  94. package/types/utils/scroll-viewer.d.ts +5 -0
  95. package/dist/tmagic-editor.mjs.map +0 -1
  96. package/dist/tmagic-editor.umd.js.map +0 -1
  97. package/src/layouts/sidebar/TabPane.vue +0 -118
  98. package/types/layouts/sidebar/TabPane.vue.d.ts +0 -82
package/types/type.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { Component } from 'vue';
2
2
  import type { FormConfig } from '@tmagic/form';
3
- import type { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
3
+ import type { CodeBlockContent, CodeBlockDSL, Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
4
4
  import type StageCore from '@tmagic/stage';
5
- import type { ContainerHighlightType, MoveableOptions } from '@tmagic/stage';
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
8
  import type { EditorService } from './services/editor';
@@ -11,6 +11,7 @@ import type { HistoryService } from './services/history';
11
11
  import type { PropsService } from './services/props';
12
12
  import type { StorageService } from './services/storage';
13
13
  import type { UiService } from './services/ui';
14
+ import type { UndoRedo } from './utils/undo-redo';
14
15
  export declare type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> | MNode;
15
16
  export declare type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
16
17
  export interface InstallOptions {
@@ -32,11 +33,12 @@ export interface StageOptions {
32
33
  containerHighlightClassName: string;
33
34
  containerHighlightDuration: number;
34
35
  containerHighlightType: ContainerHighlightType;
35
- render: () => HTMLDivElement;
36
- moveableOptions: MoveableOptions | ((core?: StageCore) => MoveableOptions);
36
+ disabledDragStart?: boolean;
37
+ render: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
38
+ moveableOptions: MoveableOptions | ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions);
37
39
  canSelect: (el: HTMLElement) => boolean | Promise<boolean>;
38
40
  isContainer: (el: HTMLElement) => boolean | Promise<boolean>;
39
- updateDragEl: (el: HTMLDivElement) => void;
41
+ updateDragEl: UpdateDragEl;
40
42
  }
41
43
  export interface StoreState {
42
44
  root: MApp | null;
@@ -128,18 +130,17 @@ export interface MenuButton {
128
130
  * 按钮类型
129
131
  * button: 只有文字不带边框的按钮
130
132
  * text: 纯文本
133
+ * divider: 分割线
131
134
  * dropdown: 下拉菜单
132
- * divider: 分隔线
133
- * zoom: 放大缩小
134
135
  */
135
- type: 'button' | 'dropdown' | 'text' | 'divider' | 'zoom';
136
+ type: 'button' | 'text' | 'divider' | 'dropdown';
136
137
  /** 当type为divider时有效,分割线方向, 默认vertical */
137
138
  direction?: 'horizontal' | 'vertical';
138
139
  /** 展示的文案 */
139
140
  text?: string;
140
141
  /** 鼠标悬浮是显示的气泡中的文案 */
141
142
  tooltip?: string;
142
- /** element-plus icon class */
143
+ /** Vue组件或url */
143
144
  icon?: string | Component<{}, {}, any>;
144
145
  /** 是否置灰,默认为false */
145
146
  disabled?: boolean | ((data?: Services) => boolean);
@@ -147,8 +148,8 @@ export interface MenuButton {
147
148
  display?: boolean | ((data?: Services) => boolean);
148
149
  /** type为button/dropdown时点击运行的方法 */
149
150
  handler?: (data: Services, event: MouseEvent) => Promise<any> | any;
150
- /** type为dropdown时,下拉的菜单列表, 或者有子菜单时 */
151
151
  className?: string;
152
+ /** type为dropdown时,下拉的菜单列表, 或者有子菜单时 */
152
153
  items?: MenuButton[];
153
154
  }
154
155
  export interface MenuComponent {
@@ -163,16 +164,22 @@ export interface MenuComponent {
163
164
  /** 是否显示,默认为true */
164
165
  className?: string;
165
166
  display?: boolean | ((data?: Services) => Promise<boolean> | boolean);
167
+ [key: string]: any;
166
168
  }
167
169
  /**
168
170
  * '/': 分隔符
169
171
  * 'delete': 删除按钮
170
172
  * 'undo': 撤销按钮
171
173
  * 'redo': 恢复按钮
174
+ * 'zoom': 'zoom-in', 'zoom-out', 'scale-to-original', 'scale-to-fit' 的集合
172
175
  * 'zoom-in': 放大按钮
173
176
  * 'zoom-out': 缩小按钮
177
+ * 'guides': 显示隐藏参考线
178
+ * 'rule': 显示隐藏标尺
179
+ * 'scale-to-original': 缩放到实际大小
180
+ * 'scale-to-fit': 缩放以适应
174
181
  */
175
- export declare type MenuItem = '/' | 'delete' | 'undo' | 'redo' | 'zoom' | 'zoom-in' | 'zoom-out' | 'guides' | 'rule' | MenuButton | MenuComponent | string;
182
+ export declare type MenuItem = '/' | 'delete' | 'undo' | 'redo' | 'zoom' | 'zoom-in' | 'zoom-out' | 'guides' | 'rule' | 'scale-to-original' | 'scale-to-fit' | MenuButton | MenuComponent | string;
176
183
  /** 工具栏 */
177
184
  export interface MenuBarData {
178
185
  /** 顶部工具栏左边项 */
@@ -185,12 +192,13 @@ export interface MenuBarData {
185
192
  export interface SideComponent extends MenuComponent {
186
193
  /** 显示文案 */
187
194
  text: string;
188
- /** element-plus icon class */
195
+ /** vue组件或url */
189
196
  icon: Component<{}, {}, any>;
190
197
  }
191
198
  /**
192
199
  * component-list: 组件列表
193
200
  * layer: 已选组件树
201
+ * code-block: 代码块
194
202
  */
195
203
  export declare type SideItem = 'component-list' | 'layer' | 'code-block' | SideComponent;
196
204
  /** 工具栏 */
@@ -207,8 +215,9 @@ export interface ComponentItem {
207
215
  text: string;
208
216
  /** 组件类型 */
209
217
  type: string;
210
- /** element-plus icon class */
211
- icon?: string | Component;
218
+ /** Vue组件或url */
219
+ icon?: string | Component<{}, {}, any>;
220
+ /** 新增组件时需要透传到组价节点上的数据 */
212
221
  data?: {
213
222
  [key: string]: any;
214
223
  };
@@ -245,26 +254,13 @@ export interface ScrollViewerEvent {
245
254
  scrollHeight: number;
246
255
  scrollWidth: number;
247
256
  }
248
- export interface CodeBlockDSL {
249
- [id: string]: CodeBlockContent;
250
- }
251
- export interface CodeBlockContent {
252
- /** 代码块名称 */
253
- name: string;
254
- /** 代码块内容 */
255
- content: string;
256
- /** 代码块与组件的绑定关系 */
257
- comps?: CodeRelation;
258
- /** 扩展字段 */
259
- [propName: string]: any;
260
- }
261
257
  export declare type CodeState = {
262
258
  /** 是否展示代码块编辑区 */
263
259
  isShowCodeEditor: boolean;
264
260
  /** 代码块DSL数据源 */
265
261
  codeDsl: CodeBlockDSL | null;
266
262
  /** 当前选中的代码块id */
267
- id: string;
263
+ id: Id;
268
264
  /** 代码块是否可编辑 */
269
265
  editable: boolean;
270
266
  /** 代码编辑面板的展示模式 */
@@ -272,11 +268,21 @@ export declare type CodeState = {
272
268
  /** list模式下左侧展示的代码列表 */
273
269
  combineIds: string[];
274
270
  /** 为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除) */
275
- undeletableList: string[];
271
+ undeletableList: Id[];
272
+ /** 代码块和组件的绑定关系 */
273
+ relations: CodeRelation;
274
+ };
275
+ export declare type HookData = {
276
+ /** 代码块id */
277
+ codeId: Id;
278
+ /** 参数 */
279
+ params?: object;
276
280
  };
277
281
  export declare type CodeRelation = {
278
- /** 组件id:['created'] */
279
- [compId: string | number]: string[];
282
+ [codeId: Id]: {
283
+ /** 组件id:['created'] */
284
+ [compId: Id]: string[];
285
+ };
280
286
  };
281
287
  export declare enum CodeEditorMode {
282
288
  /** 左侧菜单,右侧代码 */
@@ -284,26 +290,27 @@ export declare enum CodeEditorMode {
284
290
  /** 全屏代码 */
285
291
  EDITOR = "editor"
286
292
  }
287
- export interface CodeDslList {
293
+ export interface CodeDslItem {
288
294
  /** 代码块id */
289
- id: string;
295
+ id: Id;
290
296
  /** 代码块名称 */
291
297
  name: string;
292
298
  /** 代码块函数内容 */
293
299
  codeBlockContent?: CodeBlockContent;
294
300
  /** 是否展示代码绑定关系 */
295
301
  showRelation?: boolean;
302
+ /** 代码块对应绑定的组件信息 */
303
+ combineInfo?: CombineInfo[];
304
+ }
305
+ export interface CombineInfo {
306
+ /** 组件id */
307
+ compId: Id;
308
+ /** 组件名称 */
309
+ compName: string;
296
310
  }
297
311
  export interface ListState {
298
312
  /** 代码块列表 */
299
- codeList: CodeDslList[];
300
- }
301
- export interface ListRelationState extends ListState {
302
- /** 与代码块绑定的组件id信息 */
303
- bindComps: {
304
- /** 代码块id : 组件信息 */
305
- [id: string]: MNode[];
306
- };
313
+ codeList: CodeDslItem[];
307
314
  }
308
315
  export declare enum CodeDeleteErrorType {
309
316
  /** 代码块存在于不可删除列表中 */
@@ -311,11 +318,21 @@ export declare enum CodeDeleteErrorType {
311
318
  /** 代码块存在绑定关系 */
312
319
  BIND = "bind"
313
320
  }
314
- export declare enum CodeSelectOp {
315
- /** 增加 */
316
- ADD = "add",
317
- /** 删除 */
318
- DELETE = "delete",
319
- /** 单选修改 */
320
- CHANGE = "change"
321
+ export declare const CODE_DRAFT_STORAGE_KEY = "magicCodeDraft";
322
+ export interface CodeParamStatement {
323
+ /** 参数名称 */
324
+ name: string;
325
+ /** 参数类型 */
326
+ type?: string;
327
+ }
328
+ export interface StepValue {
329
+ data: MPage;
330
+ modifiedNodeIds: Map<Id, Id>;
331
+ nodeId: Id;
332
+ }
333
+ export interface HistoryState {
334
+ pageId?: Id;
335
+ pageSteps: Record<Id, UndoRedo<StepValue>>;
336
+ canRedo: boolean;
337
+ canUndo: boolean;
321
338
  }
@@ -45,3 +45,4 @@ export declare const fixNodeLeft: (config: MNode, parent: MContainer, doc?: Docu
45
45
  export declare const fixNodePosition: (config: MNode, parent: MContainer, stage: StageCore | null) => {
46
46
  [key: string]: any;
47
47
  } | undefined;
48
+ export declare const serializeConfig: (config: any) => string;
@@ -3,3 +3,4 @@ export * from './props';
3
3
  export * from './logger';
4
4
  export * from './editor';
5
5
  export * from './stage';
6
+ export * from './operator';
@@ -41,8 +41,8 @@ export declare const fillConfig: (config?: FormConfig) => {
41
41
  items: {
42
42
  name: string;
43
43
  text: string;
44
- type: string;
45
44
  labelWidth: string;
45
+ type: string;
46
46
  }[];
47
47
  labelWidth?: undefined;
48
48
  })[];
@@ -4,6 +4,10 @@ interface ScrollViewerOptions {
4
4
  container: HTMLDivElement;
5
5
  target: HTMLDivElement;
6
6
  zoom: number;
7
+ correctionScrollSize?: {
8
+ width: number;
9
+ height: number;
10
+ };
7
11
  }
8
12
  export declare class ScrollViewer extends EventEmitter {
9
13
  private container;
@@ -17,6 +21,7 @@ export declare class ScrollViewer extends EventEmitter {
17
21
  private height;
18
22
  private translateXCorrectionValue;
19
23
  private translateYCorrectionValue;
24
+ private correctionScrollSize;
20
25
  private resizeObserver;
21
26
  constructor(options: ScrollViewerOptions);
22
27
  destroy(): void;