@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
@@ -0,0 +1,32 @@
1
+ <template>
2
+ <div v-if="nodes.length === 1" class="m-editor-breadcrumb">
3
+ <template v-for="(item, index) in path" :key="item.id">
4
+ <TMagicButton text :disabled="item.id === node?.id" @click="select(item)">{{ item.name }}</TMagicButton
5
+ ><span v-if="index < path.length - 1">/</span>
6
+ </template>
7
+ </div>
8
+ </template>
9
+
10
+ <script setup lang="ts" name="MEditorBreadcrumb">
11
+ import { computed, inject } from 'vue';
12
+
13
+ import { TMagicButton } from '@tmagic/design';
14
+ import type { MApp, MNode } from '@tmagic/schema';
15
+ import type StageCore from '@tmagic/stage';
16
+ import { getNodePath } from '@tmagic/utils';
17
+
18
+ import type { Services } from '../../type';
19
+
20
+ const services = inject<Services>('services');
21
+ const editorService = services?.editorService;
22
+
23
+ const node = computed(() => editorService?.get<MNode>('node'));
24
+ const nodes = computed(() => editorService?.get<MNode[]>('nodes') || []);
25
+ const root = computed(() => editorService?.get<MApp>('root'));
26
+ const path = computed(() => getNodePath(node.value?.id || '', root.value?.items || []));
27
+
28
+ const select = async (node: MNode) => {
29
+ await editorService?.select(node);
30
+ editorService?.get<StageCore>('stage')?.select(node.id);
31
+ };
32
+ </script>
@@ -9,47 +9,48 @@
9
9
  >
10
10
  <div class="m-editor-page-bar-title">
11
11
  <slot name="page-bar-title" :page="item">
12
- <el-tooltip effect="dark" placement="top-start" :content="item.name">
12
+ <TMagicTooltip effect="dark" placement="top-start" :content="item.name">
13
13
  <span>{{ item.name || item.id }}</span>
14
- </el-tooltip>
14
+ </TMagicTooltip>
15
15
  </slot>
16
16
  </div>
17
17
 
18
- <el-popover popper-class="page-bar-popover" placement="top" :width="160" trigger="hover">
18
+ <TMagicPopover popper-class="page-bar-popover" placement="top" :width="160" trigger="hover">
19
19
  <div>
20
20
  <slot name="page-bar-popover" :page="item">
21
- <tool-button
21
+ <ToolButton
22
22
  :data="{
23
23
  type: 'button',
24
24
  text: '复制',
25
25
  icon: DocumentCopy,
26
26
  handler: () => copy(item),
27
27
  }"
28
- ></tool-button>
29
- <tool-button
28
+ ></ToolButton>
29
+ <ToolButton
30
30
  :data="{
31
31
  type: 'button',
32
32
  text: '删除',
33
33
  icon: Delete,
34
34
  handler: () => remove(item),
35
35
  }"
36
- ></tool-button>
36
+ ></ToolButton>
37
37
  </slot>
38
38
  </div>
39
39
  <template #reference>
40
- <el-icon class="m-editor-page-bar-menu-icon">
40
+ <TMagicIcon class="m-editor-page-bar-menu-icon">
41
41
  <CaretBottom></CaretBottom>
42
- </el-icon>
42
+ </TMagicIcon>
43
43
  </template>
44
- </el-popover>
44
+ </TMagicPopover>
45
45
  </div>
46
46
  </PageBarScrollContainer>
47
47
  </template>
48
48
 
49
- <script lang="ts" setup>
49
+ <script lang="ts" setup name="MEditorPageBar">
50
50
  import { computed, inject } from 'vue';
51
51
  import { CaretBottom, Delete, DocumentCopy } from '@element-plus/icons-vue';
52
52
 
53
+ import { TMagicIcon, TMagicPopover, TMagicTooltip } from '@tmagic/design';
53
54
  import type { MApp, MPage } from '@tmagic/schema';
54
55
 
55
56
  import ToolButton from '../../components/ToolButton.vue';
@@ -26,7 +26,7 @@
26
26
  </div>
27
27
  </template>
28
28
 
29
- <script setup lang="ts">
29
+ <script setup lang="ts" name="MEditorPageBarScrollContainer">
30
30
  import { computed, inject, nextTick, onMounted, onUnmounted, ref, toRaw, watch } from 'vue';
31
31
  import { ArrowLeftBold, ArrowRightBold, Plus } from '@element-plus/icons-vue';
32
32
 
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <scroll-viewer
2
+ <ScrollViewer
3
3
  class="m-editor-stage"
4
4
  ref="stageWrap"
5
5
  :width="stageRect?.width"
@@ -7,6 +7,10 @@
7
7
  :wrap-width="stageContainerRect?.width"
8
8
  :wrap-height="stageContainerRect?.height"
9
9
  :zoom="zoom"
10
+ :correction-scroll-size="{
11
+ width: 60,
12
+ height: 50,
13
+ }"
10
14
  >
11
15
  <div
12
16
  class="m-editor-stage-container"
@@ -16,25 +20,29 @@
16
20
  @drop="dropHandler"
17
21
  @dragover="dragoverHandler"
18
22
  ></div>
19
- <teleport to="body">
20
- <viewer-menu ref="menu" :is-multi-select="isMultiSelect"></viewer-menu>
21
- </teleport>
22
- </scroll-viewer>
23
+ <Teleport to="body">
24
+ <ViewerMenu ref="menu" :is-multi-select="isMultiSelect" :stage-content-menu="stageContentMenu"></ViewerMenu>
25
+ </Teleport>
26
+ </ScrollViewer>
23
27
  </template>
24
28
 
25
- <script lang="ts" setup>
26
- import { computed, inject, markRaw, onMounted, onUnmounted, ref, toRaw, watch, watchEffect } from 'vue';
29
+ <script lang="ts" setup name="MEditorStage">
30
+ import { computed, inject, markRaw, nextTick, onMounted, onUnmounted, ref, toRaw, watch, watchEffect } from 'vue';
27
31
  import { cloneDeep } from 'lodash-es';
28
32
 
29
33
  import type { MApp, MContainer, MNode, MPage } from '@tmagic/schema';
30
34
  import StageCore, { calcValueByFontsize, getOffset, Runtime } from '@tmagic/stage';
31
35
 
32
36
  import ScrollViewer from '../../components/ScrollViewer.vue';
33
- import { Layout, Services, StageOptions, StageRect } from '../../type';
37
+ import { Layout, MenuButton, MenuComponent, Services, StageOptions, StageRect } from '../../type';
34
38
  import { useStage } from '../../utils/stage';
35
39
 
36
40
  import ViewerMenu from './ViewerMenu.vue';
37
41
 
42
+ defineProps<{
43
+ stageContentMenu: (MenuButton | MenuComponent)[];
44
+ }>();
45
+
38
46
  let stage: StageCore | null = null;
39
47
  let runtime: Runtime | null = null;
40
48
 
@@ -54,7 +62,7 @@ const zoom = computed(() => services?.uiService.get<number>('zoom') || 1);
54
62
  const node = computed(() => services?.editorService.get<MNode>('node'));
55
63
 
56
64
  watchEffect(() => {
57
- if (stage) return;
65
+ if (stage || !page.value) return;
58
66
 
59
67
  if (!stageContainer.value) return;
60
68
  if (!(stageOptions?.runtimeUrl || stageOptions?.render) || !root.value) return;
@@ -88,6 +96,15 @@ watch(root, (root) => {
88
96
  }
89
97
  });
90
98
 
99
+ watch(page, (page) => {
100
+ if (runtime && page) {
101
+ runtime.updatePageId?.(page.id);
102
+ nextTick(() => {
103
+ stage?.select(page.id);
104
+ });
105
+ }
106
+ });
107
+
91
108
  const resizeObserver = new ResizeObserver((entries) => {
92
109
  for (const { contentRect } of entries) {
93
110
  services?.uiService.set('stageContainerRect', {
@@ -2,9 +2,9 @@
2
2
  <content-menu :menu-data="menuData" ref="menu"></content-menu>
3
3
  </template>
4
4
 
5
- <script lang="ts" setup>
6
- import { computed, inject, markRaw, reactive, ref, watch } from 'vue';
7
- import { Bottom, Delete, DocumentCopy, Top } from '@element-plus/icons-vue';
5
+ <script lang="ts" setup name="MEditorViewerMenu">
6
+ import { computed, inject, markRaw, ref, watch } from 'vue';
7
+ import { Bottom, CopyDocument, Delete, DocumentCopy, Top } from '@element-plus/icons-vue';
8
8
 
9
9
  import { MNode, NodeType } from '@tmagic/schema';
10
10
  import StageCore from '@tmagic/stage';
@@ -15,7 +15,10 @@ import storageService from '../../services/storage';
15
15
  import { LayerOffset, Layout, MenuButton, MenuComponent, Services } from '../../type';
16
16
  import { COPY_STORAGE_KEY } from '../../utils/editor';
17
17
 
18
- const props = withDefaults(defineProps<{ isMultiSelect?: boolean }>(), { isMultiSelect: false });
18
+ const props = withDefaults(
19
+ defineProps<{ isMultiSelect?: boolean; stageContentMenu: (MenuButton | MenuComponent)[] }>(),
20
+ { isMultiSelect: false },
21
+ );
19
22
 
20
23
  const services = inject<Services>('services');
21
24
  const editorService = services?.editorService;
@@ -28,9 +31,7 @@ const nodes = computed(() => editorService?.get<MNode[]>('nodes'));
28
31
  const parent = computed(() => editorService?.get('parent'));
29
32
  const stage = computed(() => editorService?.get<StageCore>('stage'));
30
33
 
31
- const stageContentMenu = inject<(MenuButton | MenuComponent)[]>('stageContentMenu', []);
32
-
33
- const menuData = reactive<(MenuButton | MenuComponent)[]>([
34
+ const menuData = computed<(MenuButton | MenuComponent)[]>(() => [
34
35
  {
35
36
  type: 'button',
36
37
  text: '水平居中',
@@ -43,7 +44,7 @@ const menuData = reactive<(MenuButton | MenuComponent)[]>([
43
44
  {
44
45
  type: 'button',
45
46
  text: '复制',
46
- icon: markRaw(DocumentCopy),
47
+ icon: markRaw(CopyDocument),
47
48
  handler: () => {
48
49
  nodes.value && editorService?.copy(nodes.value);
49
50
  canPaste.value = true;
@@ -52,6 +53,7 @@ const menuData = reactive<(MenuButton | MenuComponent)[]>([
52
53
  {
53
54
  type: 'button',
54
55
  text: '粘贴',
56
+ icon: markRaw(DocumentCopy),
55
57
  display: () => canPaste.value,
56
58
  handler: () => {
57
59
  const rect = menu.value?.$el.getBoundingClientRect();
@@ -130,7 +132,7 @@ const menuData = reactive<(MenuButton | MenuComponent)[]>([
130
132
  editorService?.get<StageCore>('stage').clearGuides();
131
133
  },
132
134
  },
133
- ...stageContentMenu,
135
+ ...props.stageContentMenu,
134
136
  ]);
135
137
 
136
138
  watch(
@@ -1,7 +1,9 @@
1
1
  <template>
2
2
  <div class="m-editor-workspace" tabindex="-1" ref="workspace">
3
+ <Breadcrumb></Breadcrumb>
4
+
3
5
  <slot name="stage">
4
- <MagicStage :key="page?.id"></MagicStage>
6
+ <MagicStage v-if="page" :stage-content-menu="stageContentMenu"></MagicStage>
5
7
  </slot>
6
8
 
7
9
  <slot name="workspace-content"></slot>
@@ -13,18 +15,23 @@
13
15
  </div>
14
16
  </template>
15
17
 
16
- <script lang="ts" setup>
18
+ <script lang="ts" setup name="MEditorWorkspace">
17
19
  import { computed, inject, onMounted, onUnmounted, ref } from 'vue';
18
20
  import KeyController from 'keycon';
19
21
 
20
22
  import type { MNode, MPage } from '@tmagic/schema';
21
23
  import { isPage } from '@tmagic/utils';
22
24
 
23
- import type { Services } from '../../type';
25
+ import type { MenuButton, MenuComponent, Services } from '../../type';
24
26
 
27
+ import Breadcrumb from './Breadcrumb.vue';
25
28
  import PageBar from './PageBar.vue';
26
29
  import MagicStage from './Stage.vue';
27
30
 
31
+ defineProps<{
32
+ stageContentMenu: (MenuButton | MenuComponent)[];
33
+ }>();
34
+
28
35
  const services = inject<Services>('services');
29
36
  const workspace = ref<HTMLDivElement>();
30
37
  const nodes = computed(() => services?.editorService.get<MNode[]>('nodes'));
@@ -77,7 +77,7 @@ const doAction = async (
77
77
  *
78
78
  * editorService.usePlugin({
79
79
  * beforeAdd(value) { return [value] },
80
- * afterAdd(value, result) {},
80
+ * afterAdd(result, value) { return result },
81
81
  * });
82
82
  *
83
83
  * editorService.add(); 最终会变成 () => {
@@ -169,6 +169,11 @@ export default class extends EventEmitter {
169
169
  });
170
170
  }
171
171
 
172
+ public removeAllPlugins() {
173
+ this.pluginOptionsList = {};
174
+ this.middleware = {};
175
+ }
176
+
172
177
  private async doTask() {
173
178
  this.doingTask = true;
174
179
  let task = this.taskList.shift();