@tmagic/editor 1.2.0-beta.2 → 1.2.0-beta.21

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 (101) hide show
  1. package/dist/style.css +41 -28
  2. package/dist/{tmagic-editor.mjs → tmagic-editor.js} +1693 -1272
  3. package/dist/tmagic-editor.js.map +1 -0
  4. package/dist/{tmagic-editor.umd.js → tmagic-editor.umd.cjs} +1700 -1274
  5. package/dist/tmagic-editor.umd.cjs.map +1 -0
  6. package/package.json +16 -14
  7. package/src/Editor.vue +54 -37
  8. package/src/components/CodeDraftEditor.vue +145 -0
  9. package/src/components/ContentMenu.vue +4 -4
  10. package/src/components/FunctionEditor.vue +145 -0
  11. package/src/components/Icon.vue +7 -5
  12. package/src/components/Layout.vue +149 -0
  13. package/src/components/ScrollBar.vue +1 -1
  14. package/src/components/ScrollViewer.vue +10 -1
  15. package/src/components/ToolButton.vue +30 -15
  16. package/src/fields/Code.vue +1 -1
  17. package/src/fields/CodeLink.vue +1 -1
  18. package/src/fields/CodeSelect.vue +89 -110
  19. package/src/fields/UISelect.vue +9 -8
  20. package/src/index.ts +1 -0
  21. package/src/layouts/AddPageBox.vue +3 -2
  22. package/src/layouts/CodeEditor.vue +2 -3
  23. package/src/layouts/Framework.vue +62 -40
  24. package/src/layouts/NavMenu.vue +1 -1
  25. package/src/layouts/PropsPanel.vue +11 -13
  26. package/src/layouts/Resizer.vue +1 -1
  27. package/src/layouts/sidebar/ComponentListPanel.vue +15 -13
  28. package/src/layouts/sidebar/LayerMenu.vue +9 -7
  29. package/src/layouts/sidebar/LayerPanel.vue +277 -177
  30. package/src/layouts/sidebar/Sidebar.vue +113 -27
  31. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +34 -85
  32. package/src/layouts/sidebar/code-block/CodeBlockList.vue +55 -89
  33. package/src/layouts/workspace/Breadcrumb.vue +32 -0
  34. package/src/layouts/workspace/PageBar.vue +12 -11
  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 +10 -3
  39. package/src/services/BaseService.ts +6 -1
  40. package/src/services/codeBlock.ts +124 -125
  41. package/src/services/componentList.ts +6 -1
  42. package/src/services/editor.ts +43 -19
  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/breadcrumb.scss +6 -0
  49. package/src/theme/code-block.scss +30 -21
  50. package/src/theme/component-list-panel.scss +3 -7
  51. package/src/theme/layer-panel.scss +7 -2
  52. package/src/theme/theme.scss +1 -0
  53. package/src/type.ts +76 -50
  54. package/src/utils/editor.ts +9 -1
  55. package/src/utils/index.ts +1 -0
  56. package/src/utils/props.ts +2 -2
  57. package/src/utils/scroll-viewer.ts +18 -2
  58. package/src/utils/stage.ts +9 -2
  59. package/types/Editor.vue.d.ts +42 -29
  60. package/types/components/CodeDraftEditor.vue.d.ts +148 -0
  61. package/types/components/ContentMenu.vue.d.ts +1 -3
  62. package/types/components/FunctionEditor.vue.d.ts +120 -0
  63. package/types/components/Icon.vue.d.ts +1 -3
  64. package/types/{layouts → components}/Layout.vue.d.ts +12 -1
  65. package/types/components/ScrollBar.vue.d.ts +1 -3
  66. package/types/components/ScrollViewer.vue.d.ts +45 -1
  67. package/types/components/ToolButton.vue.d.ts +1 -3
  68. package/types/fields/Code.vue.d.ts +1 -3
  69. package/types/fields/CodeLink.vue.d.ts +1 -3
  70. package/types/fields/CodeSelect.vue.d.ts +10 -12
  71. package/types/fields/UISelect.vue.d.ts +1 -3
  72. package/types/index.d.ts +1 -0
  73. package/types/layouts/AddPageBox.vue.d.ts +1 -3
  74. package/types/layouts/CodeEditor.vue.d.ts +6 -15
  75. package/types/layouts/NavMenu.vue.d.ts +1 -3
  76. package/types/layouts/sidebar/LayerMenu.vue.d.ts +25 -9
  77. package/types/layouts/sidebar/LayerPanel.vue.d.ts +38 -886
  78. package/types/layouts/sidebar/Sidebar.vue.d.ts +10 -5
  79. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +1 -1
  80. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +6 -5
  81. package/types/layouts/{sidebar/TabPane.vue.d.ts → workspace/Breadcrumb.vue.d.ts} +5 -43
  82. package/types/layouts/workspace/Stage.vue.d.ts +25 -8
  83. package/types/layouts/workspace/ViewerMenu.vue.d.ts +6 -3
  84. package/types/layouts/workspace/Workspace.vue.d.ts +23 -5
  85. package/types/services/BaseService.d.ts +2 -1
  86. package/types/services/codeBlock.d.ts +57 -36
  87. package/types/services/componentList.d.ts +1 -0
  88. package/types/services/editor.d.ts +5 -6
  89. package/types/services/events.d.ts +1 -0
  90. package/types/services/history.d.ts +5 -15
  91. package/types/services/props.d.ts +3 -2
  92. package/types/services/ui.d.ts +2 -1
  93. package/types/type.d.ts +64 -48
  94. package/types/utils/editor.d.ts +1 -0
  95. package/types/utils/index.d.ts +1 -0
  96. package/types/utils/props.d.ts +1 -1
  97. package/types/utils/scroll-viewer.d.ts +5 -0
  98. package/dist/tmagic-editor.mjs.map +0 -1
  99. package/dist/tmagic-editor.umd.js.map +0 -1
  100. package/src/layouts/Layout.vue +0 -100
  101. package/src/layouts/sidebar/TabPane.vue +0 -116
@@ -10,7 +10,7 @@
10
10
  @save="saveCode"
11
11
  ></magic-code-editor>
12
12
 
13
- <layout
13
+ <Layout
14
14
  v-else
15
15
  class="m-editor-content"
16
16
  left-class="m-editor-framework-left"
@@ -29,28 +29,29 @@
29
29
  <template #center>
30
30
  <slot v-if="pageLength > 0" name="workspace"></slot>
31
31
  <slot v-else name="empty">
32
- <add-page-box></add-page-box>
32
+ <AddPageBox></AddPageBox>
33
33
  </slot>
34
34
  </template>
35
35
 
36
- <template v-if="pageLength > 0" #right>
37
- <el-scrollbar>
36
+ <template v-if="pageLength > 0 && nodes.length === 1" #right>
37
+ <TMagicScrollbar>
38
38
  <slot name="props-panel"></slot>
39
- </el-scrollbar>
39
+ </TMagicScrollbar>
40
40
  </template>
41
- </layout>
41
+ </Layout>
42
42
  </div>
43
43
  </template>
44
44
 
45
- <script lang="ts" setup>
46
- import { computed, inject, ref, watchEffect } from 'vue';
45
+ <script lang="ts" setup name="MEditorFramework">
46
+ import { computed, inject, ref, watch } from 'vue';
47
47
 
48
+ import { TMagicScrollbar } from '@tmagic/design';
48
49
  import type { MApp } from '@tmagic/schema';
49
50
 
51
+ import Layout from '../components/Layout.vue';
50
52
  import { GetColumnWidth, Services } from '../type';
51
53
 
52
54
  import AddPageBox from './AddPageBox.vue';
53
- import Layout from './Layout.vue';
54
55
 
55
56
  const DEFAULT_LEFT_COLUMN_WIDTH = 310;
56
57
  const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
@@ -67,27 +68,65 @@ withDefaults(
67
68
  const { editorService, uiService } = inject<Services>('services') || {};
68
69
 
69
70
  const root = computed(() => editorService?.get<MApp>('root'));
71
+ const nodes = computed(() => editorService?.get<Node[]>('nodes') || []);
70
72
 
71
73
  const pageLength = computed(() => editorService?.get<number>('pageLength') || 0);
72
74
  const showSrc = computed(() => uiService?.get<boolean>('showSrc'));
75
+
76
+ const LEFT_COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorLeftColumnWidthData';
77
+ const RIGHT_COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorRightColumnWidthData';
78
+
79
+ const leftColumnWidthCacheData = Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY));
80
+ const RightColumnWidthCacheData = Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY));
81
+
73
82
  const columnWidth = ref<Partial<GetColumnWidth>>({
74
- left: DEFAULT_LEFT_COLUMN_WIDTH,
83
+ left: leftColumnWidthCacheData,
75
84
  center: 0,
76
- right: 0,
77
- });
78
- uiService?.set('columnWidth', columnWidth.value);
79
-
80
- watchEffect(() => {
81
- if (pageLength.value <= 0) {
82
- columnWidth.value.right = undefined;
83
- columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH;
84
- } else {
85
- columnWidth.value.right = columnWidth.value.right || DEFAULT_RIGHT_COLUMN_WIDTH;
86
- columnWidth.value.center =
87
- globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH;
88
- }
85
+ right: RightColumnWidthCacheData,
89
86
  });
90
87
 
88
+ watch(
89
+ pageLength,
90
+ (length) => {
91
+ const left = columnWidth.value.left || DEFAULT_LEFT_COLUMN_WIDTH;
92
+
93
+ columnWidth.value.left = left;
94
+
95
+ if (length <= 0) {
96
+ columnWidth.value.right = undefined;
97
+ columnWidth.value.center = globalThis.document.body.clientWidth - left;
98
+ } else {
99
+ const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
100
+ columnWidth.value.right = right;
101
+ columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
102
+ }
103
+
104
+ uiService?.set('columnWidth', columnWidth);
105
+ },
106
+ {
107
+ immediate: true,
108
+ },
109
+ );
110
+
111
+ watch(
112
+ () => columnWidth.value.right,
113
+ (right) => {
114
+ if (typeof right === 'undefined') return;
115
+ globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${right}`);
116
+ },
117
+ );
118
+
119
+ watch(
120
+ () => columnWidth.value.left,
121
+ (left) => {
122
+ globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${left}`);
123
+ },
124
+ );
125
+
126
+ const columnWidthChange = (columnWidth: GetColumnWidth) => {
127
+ uiService?.set('columnWidth', columnWidth);
128
+ };
129
+
91
130
  const saveCode = (value: string) => {
92
131
  try {
93
132
  // eslint-disable-next-line no-eval
@@ -96,21 +135,4 @@ const saveCode = (value: string) => {
96
135
  console.error(e);
97
136
  }
98
137
  };
99
-
100
- const COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorColumnWidthData';
101
-
102
- const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
103
- if (columnWidthCacheData) {
104
- try {
105
- const columnWidthCache = JSON.parse(columnWidthCacheData);
106
- columnWidth.value = columnWidthCache;
107
- } catch (e) {
108
- console.error(e);
109
- }
110
- }
111
-
112
- const columnWidthChange = (columnWidth: GetColumnWidth) => {
113
- uiService?.set('columnWidth', columnWidth);
114
- globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
115
- };
116
138
  </script>
@@ -6,7 +6,7 @@
6
6
  </div>
7
7
  </template>
8
8
 
9
- <script lang="ts" setup>
9
+ <script lang="ts" setup name="MEditorNavMenu">
10
10
  import { computed, inject, markRaw } from 'vue';
11
11
  import { Back, Delete, FullScreen, Grid, Memo, Right, ScaleToOriginal, ZoomIn, ZoomOut } from '@element-plus/icons-vue';
12
12
 
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div class="m-editor-props-panel">
3
3
  <slot name="props-panel-header"></slot>
4
- <m-form
4
+ <MForm
5
5
  ref="configForm"
6
6
  :class="`m-editor-props-panel ${propsPanelSize}`"
7
7
  :popper-class="`m-editor-props-panel-popper ${propsPanelSize}`"
@@ -9,15 +9,16 @@
9
9
  :init-values="values"
10
10
  :config="curFormConfig"
11
11
  @change="submit"
12
- ></m-form>
12
+ ></MForm>
13
13
  </div>
14
14
  </template>
15
15
 
16
- <script lang="ts" setup>
16
+ <script lang="ts" setup name="MEditorPropsPanel">
17
17
  import { computed, getCurrentInstance, inject, onMounted, ref, watchEffect } from 'vue';
18
- import { ElMessage } from 'element-plus';
19
18
 
20
- import type { FormValue, MForm } from '@tmagic/form';
19
+ import { tMagicMessage } from '@tmagic/design';
20
+ import type { FormValue } from '@tmagic/form';
21
+ import { MForm } from '@tmagic/form';
21
22
  import type { MNode } from '@tmagic/schema';
22
23
  import type StageCore from '@tmagic/stage';
23
24
 
@@ -32,7 +33,9 @@ const configForm = ref<InstanceType<typeof MForm>>();
32
33
  const curFormConfig = ref<any>([]);
33
34
  const services = inject<Services>('services');
34
35
  const node = computed(() => services?.editorService.get<MNode | null>('node'));
35
- const propsPanelSize = computed(() => services?.uiService.get('propsPanelSize') || 'small');
36
+ const propsPanelSize = computed(
37
+ () => services?.uiService.get<'large' | 'default' | 'small'>('propsPanelSize') || 'small',
38
+ );
36
39
  const stage = computed(() => services?.editorService.get<StageCore>('stage'));
37
40
 
38
41
  const init = async () => {
@@ -65,13 +68,8 @@ const submit = async () => {
65
68
  services?.editorService.update(values);
66
69
  } catch (e: any) {
67
70
  console.error(e);
68
- ElMessage.closeAll();
69
- ElMessage.error({
70
- duration: 10000,
71
- showClose: true,
72
- message: e.message,
73
- dangerouslyUseHTMLString: true,
74
- });
71
+ tMagicMessage.closeAll();
72
+ tMagicMessage.error(e.message);
75
73
  }
76
74
  };
77
75
 
@@ -4,7 +4,7 @@
4
4
  </span>
5
5
  </template>
6
6
 
7
- <script lang="ts" setup>
7
+ <script lang="ts" setup name="MEditorResizer">
8
8
  import { onMounted, onUnmounted, ref } from 'vue';
9
9
  import Gesto from 'gesto';
10
10
 
@@ -1,19 +1,19 @@
1
1
  <template>
2
- <el-scrollbar>
2
+ <TMagicScrollbar>
3
3
  <slot name="component-list-panel-header"></slot>
4
4
 
5
- <el-collapse class="ui-component-panel" :model-value="collapseValue">
6
- <el-input
7
- prefix-icon="el-icon-search"
5
+ <TMagicCollapse class="ui-component-panel" :model-value="collapseValue">
6
+ <TMagicInput
8
7
  placeholder="输入关键字进行过滤"
9
8
  class="search-input"
10
9
  size="small"
11
10
  clearable
11
+ :prefix-icon="Search"
12
12
  v-model="searchText"
13
13
  />
14
14
  <template v-for="(group, index) in list">
15
- <el-collapse-item v-if="group.items && group.items.length" :key="index" :name="index">
16
- <template #title><i class="el-icon-s-grid"></i>{{ group.title }}</template>
15
+ <TMagicCollapseItem v-if="group.items && group.items.length" :key="index" :name="`${index}`">
16
+ <template #title><MIcon :icon="Grid"></MIcon>{{ group.title }}</template>
17
17
  <div
18
18
  v-for="item in group.items"
19
19
  class="component-item"
@@ -27,21 +27,23 @@
27
27
  <slot name="component-list-item" :component="item">
28
28
  <MIcon :icon="item.icon"></MIcon>
29
29
 
30
- <el-tooltip effect="dark" placement="bottom" :content="item.text">
30
+ <TMagicTooltip effect="dark" placement="bottom" :content="item.text">
31
31
  <span>{{ item.text }}</span>
32
- </el-tooltip>
32
+ </TMagicTooltip>
33
33
  </slot>
34
34
  </div>
35
- </el-collapse-item>
35
+ </TMagicCollapseItem>
36
36
  </template>
37
- </el-collapse>
38
- </el-scrollbar>
37
+ </TMagicCollapse>
38
+ </TMagicScrollbar>
39
39
  </template>
40
40
 
41
- <script lang="ts" setup>
41
+ <script lang="ts" setup name="MEditorComponentListPanel">
42
42
  import { computed, inject, ref } from 'vue';
43
+ import { Grid, Search } from '@element-plus/icons-vue';
43
44
  import serialize from 'serialize-javascript';
44
45
 
46
+ import { TMagicCollapse, TMagicCollapseItem, TMagicInput, TMagicScrollbar, TMagicTooltip } from '@tmagic/design';
45
47
  import type StageCore from '@tmagic/stage';
46
48
  import { removeClassNameByClassName } from '@tmagic/utils';
47
49
 
@@ -62,7 +64,7 @@ const list = computed(() =>
62
64
  const collapseValue = computed(() =>
63
65
  Array(list.value?.length)
64
66
  .fill(1)
65
- .map((x, i) => i),
67
+ .map((x, i) => `${i}`),
66
68
  );
67
69
 
68
70
  let timeout: NodeJS.Timeout | undefined;
@@ -1,16 +1,20 @@
1
1
  <template>
2
- <content-menu :menu-data="menuData" ref="menu" style="overflow: initial"></content-menu>
2
+ <ContentMenu :menu-data="menuData" ref="menu" style="overflow: initial"></ContentMenu>
3
3
  </template>
4
4
 
5
- <script lang="ts" setup>
5
+ <script lang="ts" setup name="MEditorLayerMenu">
6
6
  import { computed, inject, markRaw, ref } from 'vue';
7
- import { Delete, DocumentCopy, Files, Plus } from '@element-plus/icons-vue';
7
+ import { CopyDocument, Delete, Files, Plus } from '@element-plus/icons-vue';
8
8
 
9
9
  import { NodeType } from '@tmagic/schema';
10
10
 
11
11
  import ContentMenu from '../../components/ContentMenu.vue';
12
12
  import type { ComponentGroup, MenuButton, MenuComponent, Services } from '../../type';
13
13
 
14
+ const props = defineProps<{
15
+ layerContentMenu: (MenuButton | MenuComponent)[];
16
+ }>();
17
+
14
18
  const services = inject<Services>('services');
15
19
  const menu = ref<InstanceType<typeof ContentMenu>>();
16
20
  const node = computed(() => services?.editorService.get('node'));
@@ -18,8 +22,6 @@ const isRoot = computed(() => node.value?.type === NodeType.ROOT);
18
22
  const isPage = computed(() => node.value?.type === NodeType.PAGE);
19
23
  const componentList = computed(() => services?.componentListService.getList() || []);
20
24
 
21
- const layerContentMenu = inject<(MenuComponent | MenuButton)[]>('layerContentMenu', []);
22
-
23
25
  const createMenuItems = (group: ComponentGroup): MenuButton[] =>
24
26
  group.items.map((component) => ({
25
27
  text: component.text,
@@ -82,7 +84,7 @@ const menuData = computed<(MenuButton | MenuComponent)[]>(() => [
82
84
  {
83
85
  type: 'button',
84
86
  text: '复制',
85
- icon: markRaw(DocumentCopy),
87
+ icon: markRaw(CopyDocument),
86
88
  display: () => !isRoot.value,
87
89
  handler: () => {
88
90
  node.value && services?.editorService.copy(node.value);
@@ -97,7 +99,7 @@ const menuData = computed<(MenuButton | MenuComponent)[]>(() => [
97
99
  node.value && services?.editorService.remove(node.value);
98
100
  },
99
101
  },
100
- ...layerContentMenu,
102
+ ...props.layerContentMenu,
101
103
  ]);
102
104
 
103
105
  const show = (e: MouseEvent) => {