@tmagic/editor 1.1.6 → 1.2.0-beta.10

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 (82) hide show
  1. package/dist/style.css +191 -8
  2. package/dist/tmagic-editor.mjs +2104 -1027
  3. package/dist/tmagic-editor.mjs.map +1 -1
  4. package/dist/tmagic-editor.umd.js +2136 -1053
  5. package/dist/tmagic-editor.umd.js.map +1 -1
  6. package/package.json +11 -10
  7. package/src/Editor.vue +27 -12
  8. package/src/components/ContentMenu.vue +4 -4
  9. package/src/components/Icon.vue +7 -5
  10. package/src/{layouts → components}/Layout.vue +15 -5
  11. package/src/components/ScrollBar.vue +1 -1
  12. package/src/components/ScrollViewer.vue +10 -1
  13. package/src/components/ToolButton.vue +30 -15
  14. package/src/fields/Code.vue +5 -2
  15. package/src/fields/CodeLink.vue +20 -12
  16. package/src/fields/CodeSelect.vue +131 -0
  17. package/src/fields/UISelect.vue +9 -8
  18. package/src/index.ts +7 -2
  19. package/src/layouts/AddPageBox.vue +13 -20
  20. package/src/layouts/CodeEditor.vue +106 -120
  21. package/src/layouts/Framework.vue +62 -40
  22. package/src/layouts/NavMenu.vue +1 -1
  23. package/src/layouts/PropsPanel.vue +5 -10
  24. package/src/layouts/Resizer.vue +1 -1
  25. package/src/layouts/sidebar/ComponentListPanel.vue +15 -13
  26. package/src/layouts/sidebar/LayerMenu.vue +89 -92
  27. package/src/layouts/sidebar/LayerPanel.vue +273 -178
  28. package/src/layouts/sidebar/Sidebar.vue +129 -37
  29. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +169 -0
  30. package/src/layouts/sidebar/code-block/CodeBlockList.vue +267 -0
  31. package/src/layouts/workspace/Breadcrumb.vue +32 -0
  32. package/src/layouts/workspace/PageBar.vue +12 -11
  33. package/src/layouts/workspace/PageBarScrollContainer.vue +1 -1
  34. package/src/layouts/workspace/Stage.vue +15 -7
  35. package/src/layouts/workspace/ViewerMenu.vue +8 -7
  36. package/src/layouts/workspace/Workspace.vue +10 -3
  37. package/src/services/codeBlock.ts +415 -0
  38. package/src/services/editor.ts +35 -5
  39. package/src/theme/breadcrumb.scss +6 -0
  40. package/src/theme/code-block.scss +184 -0
  41. package/src/theme/component-list-panel.scss +3 -7
  42. package/src/theme/index.scss +1 -13
  43. package/src/theme/layer-panel.scss +7 -2
  44. package/src/theme/layout.scss +5 -0
  45. package/src/theme/theme.scss +16 -0
  46. package/src/type.ts +88 -1
  47. package/src/utils/props.ts +9 -3
  48. package/src/utils/scroll-viewer.ts +18 -2
  49. package/src/utils/stage.ts +7 -0
  50. package/types/Editor.vue.d.ts +2 -2
  51. package/types/components/ContentMenu.vue.d.ts +1 -3
  52. package/types/components/Icon.vue.d.ts +1 -3
  53. package/types/{layouts → components}/Layout.vue.d.ts +0 -0
  54. package/types/components/ScrollBar.vue.d.ts +1 -3
  55. package/types/components/ScrollViewer.vue.d.ts +45 -1
  56. package/types/components/ToolButton.vue.d.ts +1 -3
  57. package/types/fields/Code.vue.d.ts +9 -3
  58. package/types/fields/CodeLink.vue.d.ts +5 -3
  59. package/types/fields/CodeSelect.vue.d.ts +94 -0
  60. package/types/fields/UISelect.vue.d.ts +1 -3
  61. package/types/index.d.ts +4 -0
  62. package/types/layouts/AddPageBox.vue.d.ts +43 -3
  63. package/types/layouts/CodeEditor.vue.d.ts +158 -45
  64. package/types/layouts/NavMenu.vue.d.ts +1 -3
  65. package/types/layouts/sidebar/LayerMenu.vue.d.ts +31 -63
  66. package/types/layouts/sidebar/LayerPanel.vue.d.ts +38 -1074
  67. package/types/layouts/sidebar/Sidebar.vue.d.ts +119 -17
  68. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +50 -0
  69. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +73 -0
  70. package/types/layouts/workspace/Breadcrumb.vue.d.ts +44 -0
  71. package/types/layouts/workspace/Stage.vue.d.ts +23 -7
  72. package/types/layouts/workspace/ViewerMenu.vue.d.ts +6 -3
  73. package/types/layouts/workspace/Workspace.vue.d.ts +23 -5
  74. package/types/services/codeBlock.d.ts +155 -0
  75. package/types/services/editor.d.ts +12 -1
  76. package/types/services/props.d.ts +12 -0
  77. package/types/services/ui.d.ts +1 -1
  78. package/types/type.d.ts +78 -1
  79. package/types/utils/props.d.ts +12 -0
  80. package/types/utils/scroll-viewer.d.ts +5 -0
  81. package/src/layouts/sidebar/TabPane.vue +0 -99
  82. package/types/layouts/sidebar/TabPane.vue.d.ts +0 -14
@@ -1,4 +1,4 @@
1
- import type { Id, MContainer, MNode } from '@tmagic/schema';
1
+ import type { CodeBlockDSL, Id, MContainer, MNode } from '@tmagic/schema';
2
2
  import { StepValue } from '../services/history';
3
3
  import type { AddMNode, EditorNodeInfo, PastePosition, StoreState } from '../type';
4
4
  import { LayerOffset, Layout } from '../type';
@@ -138,6 +138,17 @@ declare class Editor extends BaseService {
138
138
  move(left: number, top: number): Promise<void>;
139
139
  destroy(): void;
140
140
  resetModifiedNodeId(): void;
141
+ /**
142
+ * 从dsl中的codeBlocks字段读取活动的代码块
143
+ * @returns {CodeBlockDSL | null}
144
+ */
145
+ getCodeDsl(): Promise<CodeBlockDSL | null>;
146
+ /**
147
+ * 设置代码块到dsl的codeBlocks字段
148
+ * @param {CodeBlockDSL} codeDsl 代码DSL
149
+ * @returns {void}
150
+ */
151
+ setCodeDsl(codeDsl: CodeBlockDSL): Promise<void>;
141
152
  private addModifiedNodeId;
142
153
  private pushHistoryState;
143
154
  private changeHistoryState;
@@ -13,6 +13,7 @@ declare class Props extends BaseService {
13
13
  items: (import("@tmagic/form").ChildConfig & {
14
14
  [key: string]: any;
15
15
  })[];
16
+ lazy?: undefined;
16
17
  } | {
17
18
  title: string;
18
19
  items: {
@@ -34,6 +35,17 @@ declare class Props extends BaseService {
34
35
  })[];
35
36
  }[];
36
37
  labelWidth?: undefined;
38
+ lazy?: undefined;
39
+ } | {
40
+ title: string;
41
+ lazy: boolean;
42
+ items: {
43
+ name: string;
44
+ text: string;
45
+ type: string;
46
+ labelWidth: string;
47
+ }[];
48
+ labelWidth?: undefined;
37
49
  })[];
38
50
  }[]>;
39
51
  /**
@@ -19,7 +19,7 @@ declare const state: {
19
19
  };
20
20
  showGuides: boolean;
21
21
  showRule: boolean;
22
- propsPanelSize: "small" | "large" | "default";
22
+ propsPanelSize: "small" | "default" | "large";
23
23
  showAddPageButton: boolean;
24
24
  };
25
25
  declare class Ui extends BaseService {
package/types/type.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { FormConfig } from '@tmagic/form';
3
3
  import type { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
4
4
  import type StageCore from '@tmagic/stage';
5
5
  import type { ContainerHighlightType, MoveableOptions } from '@tmagic/stage';
6
+ import type { CodeBlockService } from './services/codeBlock';
6
7
  import type { ComponentListService } from './services/componentList';
7
8
  import type { EditorService } from './services/editor';
8
9
  import type { EventsService } from './services/events';
@@ -23,6 +24,7 @@ export interface Services {
23
24
  propsService: PropsService;
24
25
  componentListService: ComponentListService;
25
26
  uiService: UiService;
27
+ codeBlockService: CodeBlockService;
26
28
  }
27
29
  export interface StageOptions {
28
30
  runtimeUrl: string;
@@ -161,6 +163,7 @@ export interface MenuComponent {
161
163
  /** 是否显示,默认为true */
162
164
  className?: string;
163
165
  display?: boolean | ((data?: Services) => Promise<boolean> | boolean);
166
+ [key: string]: any;
164
167
  }
165
168
  /**
166
169
  * '/': 分隔符
@@ -190,7 +193,7 @@ export interface SideComponent extends MenuComponent {
190
193
  * component-list: 组件列表
191
194
  * layer: 已选组件树
192
195
  */
193
- export declare type SideItem = 'component-list' | 'layer' | SideComponent;
196
+ export declare type SideItem = 'component-list' | 'layer' | 'code-block' | SideComponent;
194
197
  /** 工具栏 */
195
198
  export interface SideBarData {
196
199
  /** 容器类型 */
@@ -243,3 +246,77 @@ export interface ScrollViewerEvent {
243
246
  scrollHeight: number;
244
247
  scrollWidth: number;
245
248
  }
249
+ export interface CodeBlockDSL {
250
+ [id: string]: CodeBlockContent;
251
+ }
252
+ export interface CodeBlockContent {
253
+ /** 代码块名称 */
254
+ name: string;
255
+ /** 代码块内容 */
256
+ content: string;
257
+ /** 代码块与组件的绑定关系 */
258
+ comps?: CodeRelation;
259
+ /** 扩展字段 */
260
+ [propName: string]: any;
261
+ }
262
+ export declare type CodeState = {
263
+ /** 是否展示代码块编辑区 */
264
+ isShowCodeEditor: boolean;
265
+ /** 代码块DSL数据源 */
266
+ codeDsl: CodeBlockDSL | null;
267
+ /** 当前选中的代码块id */
268
+ id: string;
269
+ /** 代码块是否可编辑 */
270
+ editable: boolean;
271
+ /** 代码编辑面板的展示模式 */
272
+ mode: CodeEditorMode;
273
+ /** list模式下左侧展示的代码列表 */
274
+ combineIds: string[];
275
+ /** 为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除) */
276
+ undeletableList: string[];
277
+ };
278
+ export declare type CodeRelation = {
279
+ /** 组件id:['created'] */
280
+ [compId: string | number]: string[];
281
+ };
282
+ export declare enum CodeEditorMode {
283
+ /** 左侧菜单,右侧代码 */
284
+ LIST = "list",
285
+ /** 全屏代码 */
286
+ EDITOR = "editor"
287
+ }
288
+ export interface CodeDslList {
289
+ /** 代码块id */
290
+ id: string;
291
+ /** 代码块名称 */
292
+ name: string;
293
+ /** 代码块函数内容 */
294
+ codeBlockContent?: CodeBlockContent;
295
+ /** 是否展示代码绑定关系 */
296
+ showRelation?: boolean;
297
+ }
298
+ export interface ListState {
299
+ /** 代码块列表 */
300
+ codeList: CodeDslList[];
301
+ }
302
+ export interface ListRelationState extends ListState {
303
+ /** 与代码块绑定的组件id信息 */
304
+ bindComps: {
305
+ /** 代码块id : 组件信息 */
306
+ [id: string]: MNode[];
307
+ };
308
+ }
309
+ export declare enum CodeDeleteErrorType {
310
+ /** 代码块存在于不可删除列表中 */
311
+ UNDELETEABLE = "undeleteable",
312
+ /** 代码块存在绑定关系 */
313
+ BIND = "bind"
314
+ }
315
+ export declare enum CodeSelectOp {
316
+ /** 增加 */
317
+ ADD = "add",
318
+ /** 删除 */
319
+ DELETE = "delete",
320
+ /** 单选修改 */
321
+ CHANGE = "change"
322
+ }
@@ -12,6 +12,7 @@ export declare const fillConfig: (config?: FormConfig) => {
12
12
  items: (import("@tmagic/form").ChildConfig & {
13
13
  [key: string]: any;
14
14
  })[];
15
+ lazy?: undefined;
15
16
  } | {
16
17
  title: string;
17
18
  items: {
@@ -33,5 +34,16 @@ export declare const fillConfig: (config?: FormConfig) => {
33
34
  })[];
34
35
  }[];
35
36
  labelWidth?: undefined;
37
+ lazy?: undefined;
38
+ } | {
39
+ title: string;
40
+ lazy: boolean;
41
+ items: {
42
+ name: string;
43
+ text: string;
44
+ type: string;
45
+ labelWidth: string;
46
+ }[];
47
+ labelWidth?: undefined;
36
48
  })[];
37
49
  }[];
@@ -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;
@@ -1,99 +0,0 @@
1
- <template>
2
- <el-tab-pane v-if="config" :name="config.text">
3
- <template #label>
4
- <div :key="config.text">
5
- <m-icon v-if="config.icon" :icon="config.icon"></m-icon>
6
- <div v-if="config.text" class="magic-editor-tab-panel-title">{{ config.text }}</div>
7
- </div>
8
- </template>
9
-
10
- <component :is="config.component" v-bind="config.props || {}" v-on="config?.listeners || {}">
11
- <template #component-list-panel-header v-if="data === 'component-list' || config.slots?.componentListPanelHeader">
12
- <slot v-if="data === 'component-list'" name="component-list-panel-header"></slot>
13
- <component v-else-if="config.slots?.componentListPanelHeader" :is="config.slots.componentListPanelHeader" />
14
- </template>
15
-
16
- <template
17
- #component-list-item="{ component }"
18
- v-if="data === 'component-list' || config.slots?.componentListItem"
19
- >
20
- <slot v-if="data === 'component-list'" name="component-list-item" :component="component"></slot>
21
- <component
22
- v-else-if="config.slots?.componentListItem"
23
- :is="config.slots.componentListItem"
24
- :component="component"
25
- />
26
- </template>
27
-
28
- <template #layer-panel-header v-if="data === 'layer' || config.slots?.layerPanelHeader">
29
- <slot v-if="data === 'layer'" name="layer-panel-header"></slot>
30
- <component v-else-if="config.slots?.layerPanelHeader" :is="config.slots.layerPanelHeader" />
31
- </template>
32
-
33
- <template
34
- #layer-node-content="{ data: nodeData, node }"
35
- v-if="data === 'layer' || config.slots?.layerNodeContent"
36
- >
37
- <slot v-if="data === 'layer'" name="layer-node-content" :data="nodeData" :node="node"></slot>
38
- <component
39
- v-else-if="config.slots?.layerNodeContent"
40
- :is="config.slots.layerNodeContent"
41
- :data="nodeData"
42
- :node="node"
43
- />
44
- </template>
45
- </component>
46
- </el-tab-pane>
47
- </template>
48
-
49
- <script lang="ts">
50
- import { computed, defineComponent, PropType } from 'vue';
51
- import { Coin, Files } from '@element-plus/icons-vue';
52
-
53
- import MIcon from '../../components/Icon.vue';
54
- import { SideComponent, SideItem } from '../../type';
55
-
56
- import ComponentListPanel from './ComponentListPanel.vue';
57
- import LayerPanel from './LayerPanel.vue';
58
-
59
- export default defineComponent({
60
- components: { MIcon },
61
-
62
- props: {
63
- data: {
64
- type: [Object, String] as PropType<SideItem>,
65
- },
66
- },
67
-
68
- setup(props) {
69
- return {
70
- config: computed<SideComponent | undefined>(() => {
71
- if (typeof props.data !== 'string') {
72
- return props.data;
73
- }
74
-
75
- switch (props.data) {
76
- case 'component-list':
77
- return {
78
- type: 'component',
79
- icon: Coin,
80
- text: '组件',
81
- component: ComponentListPanel,
82
- slots: {},
83
- };
84
- case 'layer':
85
- return {
86
- type: 'component',
87
- icon: Files,
88
- text: '已选组件',
89
- component: LayerPanel,
90
- slots: {},
91
- };
92
- default:
93
- return undefined;
94
- }
95
- }),
96
- };
97
- },
98
- });
99
- </script>
@@ -1,14 +0,0 @@
1
- import { PropType } from 'vue';
2
- import { SideComponent, SideItem } from '../../type';
3
- declare const _default: import("vue").DefineComponent<{
4
- data: {
5
- type: PropType<SideItem>;
6
- };
7
- }, {
8
- config: import("vue").ComputedRef<SideComponent | undefined>;
9
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
10
- data: {
11
- type: PropType<SideItem>;
12
- };
13
- }>>, {}>;
14
- export default _default;