@tmagic/editor 1.2.0 → 1.2.1

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 (56) hide show
  1. package/dist/style.css +4 -0
  2. package/dist/tmagic-editor.js +305 -249
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +308 -253
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +9 -9
  7. package/src/Editor.vue +1 -1
  8. package/src/components/CodeDraftEditor.vue +2 -10
  9. package/src/components/FunctionEditor.vue +58 -13
  10. package/src/components/Layout.vue +1 -1
  11. package/src/fields/CodeSelect.vue +23 -7
  12. package/src/fields/UISelect.vue +2 -2
  13. package/src/index.ts +1 -1
  14. package/src/layouts/AddPageBox.vue +4 -1
  15. package/src/layouts/Framework.vue +10 -8
  16. package/src/layouts/NavMenu.vue +9 -6
  17. package/src/layouts/PropsPanel.vue +3 -7
  18. package/src/layouts/sidebar/ComponentListPanel.vue +1 -2
  19. package/src/layouts/sidebar/LayerPanel.vue +8 -9
  20. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +10 -39
  21. package/src/layouts/sidebar/code-block/CodeBlockList.vue +5 -6
  22. package/src/layouts/workspace/Breadcrumb.vue +5 -6
  23. package/src/layouts/workspace/PageBar.vue +2 -2
  24. package/src/layouts/workspace/PageBarScrollContainer.vue +4 -2
  25. package/src/layouts/workspace/Stage.vue +11 -10
  26. package/src/layouts/workspace/ViewerMenu.vue +5 -6
  27. package/src/layouts/workspace/Workspace.vue +2 -3
  28. package/src/services/BaseService.ts +1 -1
  29. package/src/services/codeBlock.ts +15 -24
  30. package/src/services/componentList.ts +1 -1
  31. package/src/services/editor.ts +119 -79
  32. package/src/services/events.ts +1 -1
  33. package/src/services/history.ts +1 -1
  34. package/src/services/props.ts +1 -1
  35. package/src/services/ui.ts +8 -10
  36. package/src/theme/code-block.scss +4 -0
  37. package/src/type.ts +7 -13
  38. package/src/utils/config.ts +1 -1
  39. package/src/utils/editor.ts +8 -2
  40. package/src/utils/index.ts +1 -1
  41. package/src/utils/logger.ts +1 -1
  42. package/src/utils/operator.ts +12 -12
  43. package/src/utils/props.ts +1 -1
  44. package/src/utils/stage.ts +6 -6
  45. package/src/utils/undo-redo.ts +1 -1
  46. package/types/Editor.vue.d.ts +1 -1
  47. package/types/components/CodeDraftEditor.vue.d.ts +1 -2
  48. package/types/components/FunctionEditor.vue.d.ts +17 -0
  49. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +23 -5
  50. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +5 -0
  51. package/types/layouts/workspace/Workspace.vue.d.ts +2 -3
  52. package/types/services/codeBlock.d.ts +0 -12
  53. package/types/services/editor.d.ts +6 -6
  54. package/types/services/ui.d.ts +23 -24
  55. package/types/type.d.ts +5 -11
  56. package/types/utils/operator.d.ts +1 -1
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Tencent is pleased to support the open source community by making TMagicEditor available.
3
3
  *
4
- * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
4
+ * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Tencent is pleased to support the open source community by making TMagicEditor available.
3
3
  *
4
- * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
4
+ * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -1,8 +1,7 @@
1
1
  import { toRaw } from 'vue';
2
2
  import { isEmpty } from 'lodash-es';
3
3
 
4
- import { Id, MApp, MContainer, MNode } from '@tmagic/schema';
5
- import StageCore from '@tmagic/stage';
4
+ import { Id, MContainer, MNode } from '@tmagic/schema';
6
5
  import { isPage } from '@tmagic/utils';
7
6
 
8
7
  import editorService from '../services/editor';
@@ -18,7 +17,7 @@ import { generatePageNameByApp, getInitPositionStyle } from '../utils/editor';
18
17
  */
19
18
  export const beforePaste = async (position: PastePosition, config: MNode[]): Promise<MNode[]> => {
20
19
  if (!config[0]?.style) return config;
21
- const curNode = editorService.get<MContainer>('node');
20
+ const curNode = editorService.get('node');
22
21
  // 将数组中第一个元素的坐标作为参照点
23
22
  const { left: referenceLeft, top: referenceTop } = config[0].style;
24
23
  // 坐标校准后的粘贴数据
@@ -28,7 +27,7 @@ export const beforePaste = async (position: PastePosition, config: MNode[]): Pro
28
27
  const { offsetX = 0, offsetY = 0, ...positionClone } = position;
29
28
  let pastePosition = positionClone;
30
29
 
31
- if (!isEmpty(pastePosition) && curNode.items) {
30
+ if (!isEmpty(pastePosition) && curNode?.items) {
32
31
  // 如果没有传入粘贴坐标则可能为键盘操作,不再转换
33
32
  // 如果粘贴时选中了容器,则将元素粘贴到容器内,坐标需要转换为相对于容器的坐标
34
33
  pastePosition = getPositionInContainer(pastePosition, curNode.id);
@@ -59,8 +58,9 @@ export const beforePaste = async (position: PastePosition, config: MNode[]): Pro
59
58
  ...pastePosition,
60
59
  };
61
60
  }
62
- if (isPage(pasteConfig)) {
63
- pasteConfig.name = generatePageNameByApp(editorService.get('root'));
61
+ const root = editorService.get('root');
62
+ if (isPage(pasteConfig) && root) {
63
+ pasteConfig.name = generatePageNameByApp(root);
64
64
  }
65
65
  return pasteConfig as MNode;
66
66
  }),
@@ -76,7 +76,7 @@ export const beforePaste = async (position: PastePosition, config: MNode[]): Pro
76
76
  */
77
77
  export const getPositionInContainer = (position: PastePosition = {}, id: Id) => {
78
78
  let { left = 0, top = 0 } = position;
79
- const parentEl = editorService.get<StageCore>('stage')?.renderer?.contentWindow?.document.getElementById(`${id}`);
79
+ const parentEl = editorService.get('stage')?.renderer?.contentWindow?.document.getElementById(`${id}`);
80
80
  const parentElRect = parentEl?.getBoundingClientRect();
81
81
  left = left - (parentElRect?.left || 0);
82
82
  top = top - (parentElRect?.top || 0);
@@ -87,14 +87,14 @@ export const getPositionInContainer = (position: PastePosition = {}, id: Id) =>
87
87
  };
88
88
 
89
89
  export const getAddParent = (node: MNode) => {
90
- const curNode = editorService.get<MContainer>('node');
90
+ const curNode = editorService.get('node');
91
91
 
92
92
  let parentNode;
93
93
  if (isPage(node)) {
94
- parentNode = editorService.get<MApp>('root');
95
- } else if (curNode.items) {
96
- parentNode = curNode;
97
- } else {
94
+ parentNode = editorService.get('root');
95
+ } else if (curNode?.items) {
96
+ parentNode = curNode as MContainer;
97
+ } else if (curNode?.id) {
98
98
  parentNode = editorService.getParentById(curNode.id, false);
99
99
  }
100
100
  return parentNode;
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Tencent is pleased to support the open source community by making TMagicEditor available.
3
3
  *
4
- * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
4
+ * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,5 @@
1
1
  import { computed } from 'vue';
2
2
 
3
- import { MApp, MPage } from '@tmagic/schema';
4
3
  import StageCore, { GuidesType, SortEventData, UpdateEventData } from '@tmagic/stage';
5
4
 
6
5
  import editorService from '../services/editor';
@@ -9,10 +8,10 @@ import { H_GUIDE_LINE_STORAGE_KEY, StageOptions, V_GUIDE_LINE_STORAGE_KEY } from
9
8
 
10
9
  import { getGuideLineFromCache } from './editor';
11
10
 
12
- const root = computed(() => editorService.get<MApp>('root'));
13
- const page = computed(() => editorService.get<MPage>('page'));
14
- const zoom = computed(() => uiService.get<number>('zoom') || 1);
15
- const uiSelectMode = computed(() => uiService.get<boolean>('uiSelectMode'));
11
+ const root = computed(() => editorService.get('root'));
12
+ const page = computed(() => editorService.get('page'));
13
+ const zoom = computed(() => uiService.get('zoom') || 1);
14
+ const uiSelectMode = computed(() => uiService.get('uiSelectMode'));
16
15
 
17
16
  const getGuideLineKey = (key: string) => `${key}_${root.value?.id}_${page.value?.id}`;
18
17
 
@@ -76,8 +75,9 @@ export const useStage = (stageOptions: StageOptions) => {
76
75
 
77
76
  stage.on('select-parent', () => {
78
77
  const parent = editorService.get('parent');
78
+ if (!parent) throw new Error('父节点为空');
79
79
  editorService.select(parent);
80
- editorService.get<StageCore>('stage').select(parent.id);
80
+ editorService.get('stage')?.select(parent.id);
81
81
  });
82
82
 
83
83
  stage.on('change-guides', (e) => {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Tencent is pleased to support the open source community by making TMagicEditor available.
3
3
  *
4
- * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
4
+ * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -211,12 +211,12 @@ declare const _default: import("vue").DefineComponent<{
211
211
  "onProps-panel-mounted"?: ((...args: any[]) => any) | undefined;
212
212
  }, {
213
213
  menu: MenuBarData;
214
+ autoScrollIntoView: boolean;
214
215
  codeOptions: Record<string, any>;
215
216
  modelValue: MApp;
216
217
  layerContentMenu: (MenuButton | MenuComponent)[];
217
218
  stageContentMenu: (MenuButton | MenuComponent)[];
218
219
  componentGroupList: ComponentGroup[];
219
- autoScrollIntoView: boolean;
220
220
  propsConfigs: Record<string, FormConfig>;
221
221
  propsValues: Record<string, MNode>;
222
222
  eventMethodList: Record<string, {
@@ -15,7 +15,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
15
15
  }>, {
16
16
  editable: boolean;
17
17
  autoSaveDraft: boolean;
18
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("save" | "close" | "saveAndClose")[], "save" | "close" | "saveAndClose", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
18
+ }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("close" | "saveAndClose")[], "close" | "saveAndClose", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
19
19
  /** 代码id */
20
20
  id: Id;
21
21
  /** 代码内容 */
@@ -32,7 +32,6 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
32
32
  editable: boolean;
33
33
  autoSaveDraft: boolean;
34
34
  }>>> & {
35
- onSave?: ((...args: any[]) => any) | undefined;
36
35
  onClose?: ((...args: any[]) => any) | undefined;
37
36
  onSaveAndClose?: ((...args: any[]) => any) | undefined;
38
37
  }, {
@@ -1,21 +1,38 @@
1
+ import { ColumnConfig } from '@tmagic/form';
1
2
  import { Id } from '@tmagic/schema';
2
3
  declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
4
+ /** 代码块id */
3
5
  id: Id;
6
+ /** 代码块名称 */
4
7
  name: string;
8
+ /** 代码内容 */
5
9
  content: string;
10
+ /** 是否可编辑 */
6
11
  editable?: boolean | undefined;
12
+ /** 是否自动保存草稿 */
7
13
  autoSaveDraft?: boolean | undefined;
14
+ /** 编辑器扩展参数 */
8
15
  codeOptions?: object | undefined;
16
+ /** 代码参数扩展配置 */
17
+ paramsColConfig?: ColumnConfig | undefined;
9
18
  }>, {
10
19
  editable: boolean;
11
20
  autoSaveDraft: boolean;
12
21
  }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("change" | "field-input")[], "change" | "field-input", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
22
+ /** 代码块id */
13
23
  id: Id;
24
+ /** 代码块名称 */
14
25
  name: string;
26
+ /** 代码内容 */
15
27
  content: string;
28
+ /** 是否可编辑 */
16
29
  editable?: boolean | undefined;
30
+ /** 是否自动保存草稿 */
17
31
  autoSaveDraft?: boolean | undefined;
32
+ /** 编辑器扩展参数 */
18
33
  codeOptions?: object | undefined;
34
+ /** 代码参数扩展配置 */
35
+ paramsColConfig?: ColumnConfig | undefined;
19
36
  }>, {
20
37
  editable: boolean;
21
38
  autoSaveDraft: boolean;
@@ -1,8 +1,11 @@
1
+ import { ColumnConfig } from '@tmagic/form';
1
2
  declare const _default: {
2
3
  new (...args: any[]): {
3
4
  $: import("vue").ComponentInternalInstance;
4
5
  $data: {};
5
- $props: Partial<{}> & Omit<Readonly<import("vue").ExtractPropTypes<{}>> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>;
6
+ $props: Partial<{}> & Omit<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
7
+ paramsColConfig?: ColumnConfig | undefined;
8
+ }>>> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>;
6
9
  $attrs: {
7
10
  [x: string]: unknown;
8
11
  };
@@ -14,9 +17,11 @@ declare const _default: {
14
17
  }>;
15
18
  $root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null;
16
19
  $parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null;
17
- $emit: ((event: string, ...args: any[]) => void) | ((event: string, ...args: any[]) => void);
20
+ $emit: (event: string, ...args: any[]) => void;
18
21
  $el: any;
19
- $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, {}> & {
22
+ $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
23
+ paramsColConfig?: ColumnConfig | undefined;
24
+ }>>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, {}> & {
20
25
  beforeCreate?: ((() => void) | (() => void)[]) | undefined;
21
26
  created?: ((() => void) | (() => void)[]) | undefined;
22
27
  beforeMount?: ((() => void) | (() => void)[]) | undefined;
@@ -36,11 +41,15 @@ declare const _default: {
36
41
  $forceUpdate: () => void;
37
42
  $nextTick: typeof import("vue").nextTick;
38
43
  $watch(source: string | Function, cb: Function, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
39
- } & Readonly<import("vue").ExtractPropTypes<{}>> & import("vue").ShallowUnwrapRef<{}> & {} & import("vue").ComponentCustomProperties;
44
+ } & Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
45
+ paramsColConfig?: ColumnConfig | undefined;
46
+ }>>> & import("vue").ShallowUnwrapRef<{}> & {} & import("vue").ComponentCustomProperties;
40
47
  __isFragment?: undefined;
41
48
  __isTeleport?: undefined;
42
49
  __isSuspense?: undefined;
43
- } & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, {}> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
50
+ } & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
51
+ paramsColConfig?: ColumnConfig | undefined;
52
+ }>>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, {}> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
44
53
  $slots: {
45
54
  'code-block-edit-panel-header': (_: {
46
55
  id: import("@tmagic/schema").Id;
@@ -48,3 +57,12 @@ declare const _default: {
48
57
  };
49
58
  });
50
59
  export default _default;
60
+ declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
61
+ declare type __VLS_TypePropsToRuntimeProps<T> = {
62
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
63
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
64
+ } : {
65
+ type: import('vue').PropType<T[K]>;
66
+ required: true;
67
+ };
68
+ };
@@ -1,3 +1,4 @@
1
+ import { ColumnConfig } from '@tmagic/form';
1
2
  import { Id } from '@tmagic/schema';
2
3
  import { CodeDeleteErrorType } from '../../../type';
3
4
  declare const _default: {
@@ -6,6 +7,7 @@ declare const _default: {
6
7
  $data: {};
7
8
  $props: Partial<{}> & Omit<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
8
9
  customError?: ((id: Id, errorType: CodeDeleteErrorType) => any) | undefined;
10
+ paramsColConfig?: ColumnConfig | undefined;
9
11
  }>>> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>;
10
12
  $attrs: {
11
13
  [x: string]: unknown;
@@ -22,6 +24,7 @@ declare const _default: {
22
24
  $el: any;
23
25
  $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
24
26
  customError?: ((id: Id, errorType: CodeDeleteErrorType) => any) | undefined;
27
+ paramsColConfig?: ColumnConfig | undefined;
25
28
  }>>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, {}> & {
26
29
  beforeCreate?: ((() => void) | (() => void)[]) | undefined;
27
30
  created?: ((() => void) | (() => void)[]) | undefined;
@@ -44,12 +47,14 @@ declare const _default: {
44
47
  $watch(source: string | Function, cb: Function, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
45
48
  } & Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
46
49
  customError?: ((id: Id, errorType: CodeDeleteErrorType) => any) | undefined;
50
+ paramsColConfig?: ColumnConfig | undefined;
47
51
  }>>> & import("vue").ShallowUnwrapRef<{}> & {} & import("vue").ComponentCustomProperties;
48
52
  __isFragment?: undefined;
49
53
  __isTeleport?: undefined;
50
54
  __isSuspense?: undefined;
51
55
  } & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
52
56
  customError?: ((id: Id, errorType: CodeDeleteErrorType) => any) | undefined;
57
+ paramsColConfig?: ColumnConfig | undefined;
53
58
  }>>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, {}> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
54
59
  $slots: {
55
60
  'code-block-panel-header': (_: {}) => any;
@@ -1,4 +1,3 @@
1
- import type { MPage } from '@tmagic/schema';
2
1
  import type { MenuButton, MenuComponent } from '../../type';
3
2
  declare const _default: {
4
3
  new (...args: any[]): {
@@ -55,10 +54,10 @@ declare const _default: {
55
54
  stage: (_: {}) => any;
56
55
  'workspace-content': (_: {}) => any;
57
56
  'page-bar-title': (_: {
58
- page: MPage;
57
+ page: import("@tmagic/schema").MPage;
59
58
  }) => any;
60
59
  'page-bar-popover': (_: {
61
- page: MPage;
60
+ page: import("@tmagic/schema").MPage;
62
61
  }) => any;
63
62
  };
64
63
  });
@@ -1,6 +1,5 @@
1
1
  import { CodeBlockContent, CodeBlockDSL, Id, MNode } from '@tmagic/schema';
2
2
  import type { CodeRelation } from '../type';
3
- import { CodeEditorMode } from '../type';
4
3
  import BaseService from './BaseService';
5
4
  declare class CodeBlock extends BaseService {
6
5
  private state;
@@ -83,17 +82,6 @@ declare class CodeBlock extends BaseService {
83
82
  * @returns {Id} id 代码块id
84
83
  */
85
84
  getId(): Id;
86
- /**
87
- * 获取当前模式
88
- * @returns {CodeEditorMode}
89
- */
90
- getMode(): CodeEditorMode;
91
- /**
92
- * 设置当前模式
93
- * @param {CodeEditorMode} mode 模式
94
- * @returns {void}
95
- */
96
- setMode(mode: CodeEditorMode): Promise<void>;
97
85
  /**
98
86
  * 设置当前选中组件已关联绑定的代码块id数组
99
87
  * @param {string[]} ids 代码块id数组
@@ -1,5 +1,5 @@
1
1
  import type { CodeBlockDSL, Id, MContainer, MNode } from '@tmagic/schema';
2
- import type { AddMNode, EditorNodeInfo, PastePosition, StepValue, StoreState } from '../type';
2
+ import type { AddMNode, EditorNodeInfo, PastePosition, StepValue, StoreState, StoreStateKey } from '../type';
3
3
  import { LayerOffset, Layout } from '../type';
4
4
  import BaseService from './BaseService';
5
5
  declare class Editor extends BaseService {
@@ -11,13 +11,13 @@ declare class Editor extends BaseService {
11
11
  * @param name 'root' | 'page' | 'parent' | 'node' | 'highlightNode' | 'nodes' | 'stage' | 'modifiedNodeIds' | 'pageLength'
12
12
  * @param value MNode
13
13
  */
14
- set<T = MNode>(name: keyof StoreState, value: T): void;
14
+ set<K extends StoreStateKey, T extends StoreState[K]>(name: K, value: T): void;
15
15
  /**
16
16
  * 获取当前指点节点配置
17
17
  * @param name 'root' | 'page' | 'parent' | 'node' | 'highlightNode' | 'nodes' | 'stage' | 'modifiedNodeIds' | 'pageLength'
18
18
  * @returns MNode
19
19
  */
20
- get<T = MNode>(name: keyof StoreState): T;
20
+ get<K extends StoreStateKey>(name: K): StoreState[K];
21
21
  /**
22
22
  * 根据id获取组件、组件的父组件以及组件所属的页面节点
23
23
  * @param {number | string} id 组件id
@@ -31,14 +31,14 @@ declare class Editor extends BaseService {
31
31
  * @param {boolean} raw 是否使用toRaw
32
32
  * @returns 组件节点配置
33
33
  */
34
- getNodeById(id: Id, raw?: boolean): MNode | undefined;
34
+ getNodeById(id: Id, raw?: boolean): MNode | null;
35
35
  /**
36
36
  * 根据ID获取指点节点的父节点配置
37
37
  * @param id 组件ID
38
38
  * @param {boolean} raw 是否使用toRaw
39
39
  * @returns 指点组件的父节点配置
40
40
  */
41
- getParentById(id: Id, raw?: boolean): MContainer | undefined;
41
+ getParentById(id: Id, raw?: boolean): MContainer | null;
42
42
  /**
43
43
  * 只有容器拥有布局
44
44
  */
@@ -49,7 +49,7 @@ declare class Editor extends BaseService {
49
49
  * @returns 当前选中的节点配置
50
50
  */
51
51
  select(config: MNode | Id): Promise<MNode> | never;
52
- selectNextNode(): Promise<MNode> | never;
52
+ selectNextNode(): Promise<MNode | null> | never;
53
53
  selectNextPage(): Promise<MNode> | never;
54
54
  /**
55
55
  * 高亮指定节点
@@ -1,31 +1,30 @@
1
1
  import type { UiState } from '../type';
2
2
  import BaseService from './BaseService';
3
- declare const state: {
4
- uiSelectMode: boolean;
5
- showSrc: boolean;
6
- zoom: number;
7
- stageContainerRect: {
8
- width: number;
9
- height: number;
10
- };
11
- stageRect: {
12
- width: number;
13
- height: number;
14
- };
15
- columnWidth: {
16
- left: number;
17
- center: number;
18
- right: number;
19
- };
20
- showGuides: boolean;
21
- showRule: boolean;
22
- propsPanelSize: "small" | "default" | "large";
23
- showAddPageButton: boolean;
24
- };
25
3
  declare class Ui extends BaseService {
26
4
  constructor();
27
- set<T = any>(name: keyof UiState, value: T): void;
28
- get<T>(name: keyof typeof state): T;
5
+ set<K extends keyof UiState, T extends UiState[K]>(name: K, value: T): void;
6
+ get<K extends keyof UiState>(name: K): {
7
+ uiSelectMode: boolean;
8
+ showSrc: boolean;
9
+ zoom: number;
10
+ stageContainerRect: {
11
+ width: number;
12
+ height: number;
13
+ };
14
+ stageRect: {
15
+ width: number;
16
+ height: number;
17
+ };
18
+ columnWidth: {
19
+ left: number;
20
+ center: number;
21
+ right: number;
22
+ };
23
+ showGuides: boolean;
24
+ showRule: boolean;
25
+ propsPanelSize: "small" | "default" | "large";
26
+ showAddPageButton: boolean;
27
+ }[K];
29
28
  zoom(zoom: number): Promise<void>;
30
29
  calcZoom(): Promise<number>;
31
30
  resetState(): void;
package/types/type.d.ts CHANGED
@@ -51,6 +51,7 @@ export interface StoreState {
51
51
  modifiedNodeIds: Map<Id, Id>;
52
52
  pageLength: number;
53
53
  }
54
+ export declare type StoreStateKey = keyof StoreState;
54
55
  export interface PropsState {
55
56
  propsConfigMap: Record<string, FormConfig>;
56
57
  propsValueMap: Record<string, MNode>;
@@ -100,9 +101,9 @@ export interface UiState {
100
101
  showAddPageButton: boolean;
101
102
  }
102
103
  export interface EditorNodeInfo {
103
- node?: MNode;
104
- parent?: MContainer;
105
- page?: MPage;
104
+ node: MNode | null;
105
+ parent: MContainer | null;
106
+ page: MPage | null;
106
107
  }
107
108
  export interface AddMNode {
108
109
  type: string;
@@ -263,8 +264,6 @@ export declare type CodeState = {
263
264
  id: Id;
264
265
  /** 代码块是否可编辑 */
265
266
  editable: boolean;
266
- /** 代码编辑面板的展示模式 */
267
- mode: CodeEditorMode;
268
267
  /** list模式下左侧展示的代码列表 */
269
268
  combineIds: string[];
270
269
  /** 为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除) */
@@ -284,12 +283,6 @@ export declare type CodeRelation = {
284
283
  [compId: Id]: string[];
285
284
  };
286
285
  };
287
- export declare enum CodeEditorMode {
288
- /** 左侧菜单,右侧代码 */
289
- LIST = "list",
290
- /** 全屏代码 */
291
- EDITOR = "editor"
292
- }
293
286
  export interface CodeDslItem {
294
287
  /** 代码块id */
295
288
  id: Id;
@@ -324,6 +317,7 @@ export interface CodeParamStatement {
324
317
  name: string;
325
318
  /** 参数类型 */
326
319
  type?: string;
320
+ [key: string]: any;
327
321
  }
328
322
  export interface StepValue {
329
323
  data: MPage;
@@ -17,5 +17,5 @@ export declare const getPositionInContainer: (position: PastePosition | undefine
17
17
  left: number;
18
18
  top: number;
19
19
  };
20
- export declare const getAddParent: (node: MNode) => MContainer | undefined;
20
+ export declare const getAddParent: (node: MNode) => MContainer | null | undefined;
21
21
  export declare const getDefaultConfig: (addNode: AddMNode, parentNode: MContainer) => Promise<any>;