From 6dbda7b5655ed7b53b0b56ee5dd08dfec4a9034e Mon Sep 17 00:00:00 2001 From: roymondchen Date: Wed, 30 Mar 2022 19:33:54 +0800 Subject: [PATCH] =?UTF-8?q?style(editor):=20=E5=B0=86=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=94=B9=E6=88=90=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor/src/components/ToolButton.vue | 4 +++- packages/editor/src/layouts/AddPageBox.vue | 4 +++- .../editor/src/layouts/sidebar/LayerPanel.vue | 5 +++-- .../editor/src/layouts/workspace/PageBar.vue | 3 ++- .../editor/src/layouts/workspace/ViewerMenu.vue | 8 +++++--- packages/editor/src/services/editor.ts | 13 +++++++------ packages/editor/src/utils/editor.ts | 7 ++++--- packages/editor/tests/unit/Editor.spec.ts | 7 ++++--- .../unit/layouts/wordspace/PageBar.spec.ts | 8 +++++--- .../tests/unit/layouts/wordspace/Stage.spec.ts | 6 ++++-- .../editor/tests/unit/services/editor.spec.ts | 13 +++++++------ packages/editor/tests/unit/utils/editor.spec.ts | 17 +++++++++-------- packages/schema/src/index.ts | 12 +++++++++--- playground/src/pages/Editor.vue | 3 ++- 14 files changed, 67 insertions(+), 43 deletions(-) diff --git a/packages/editor/src/components/ToolButton.vue b/packages/editor/src/components/ToolButton.vue index bdabd848..7b26737f 100644 --- a/packages/editor/src/components/ToolButton.vue +++ b/packages/editor/src/components/ToolButton.vue @@ -41,6 +41,8 @@ import { computed, defineComponent, inject, PropType } from 'vue'; import { ArrowDown, Back, Delete, Grid, Right, ScaleToOriginal, ZoomIn, ZoomOut } from '@element-plus/icons'; +import { NodeType } from '@tmagic/schema'; + import MIcon from '@editor/components/Icon.vue'; import type { MenuButton, MenuComponent, MenuItem, Services } from '@editor/type'; @@ -87,7 +89,7 @@ export default defineComponent({ type: 'button', icon: Delete, tooltip: '刪除', - disabled: () => services?.editorService.get('node')?.type === 'page', + disabled: () => services?.editorService.get('node')?.type === NodeType.PAGE, handler: () => services?.editorService.remove(services?.editorService.get('node')), }; case 'undo': diff --git a/packages/editor/src/layouts/AddPageBox.vue b/packages/editor/src/layouts/AddPageBox.vue index 9eb2cd5e..92def631 100644 --- a/packages/editor/src/layouts/AddPageBox.vue +++ b/packages/editor/src/layouts/AddPageBox.vue @@ -15,6 +15,8 @@ import { defineComponent, inject, toRaw } from 'vue'; import { Plus } from '@element-plus/icons'; +import { NodeType } from '@tmagic/schema'; + import { Services } from '@editor/type'; import { generatePageNameByApp } from '@editor/utils'; @@ -31,7 +33,7 @@ export default defineComponent({ if (!editorService) return; editorService.add({ - type: 'page', + type: NodeType.PAGE, name: generatePageNameByApp(toRaw(editorService.get('root'))), }); }, diff --git a/packages/editor/src/layouts/sidebar/LayerPanel.vue b/packages/editor/src/layouts/sidebar/LayerPanel.vue index dce3e7ea..a7c0ec8f 100644 --- a/packages/editor/src/layouts/sidebar/LayerPanel.vue +++ b/packages/editor/src/layouts/sidebar/LayerPanel.vue @@ -58,6 +58,7 @@ import type { ElTree } from 'element-plus'; import { throttle } from 'lodash-es'; import type { MNode, MPage } from '@tmagic/schema'; +import { NodeType } from '@tmagic/schema'; import type { EditorService } from '@editor/services/editor'; import type { Services } from '@editor/type'; @@ -88,8 +89,8 @@ const useDrop = (tree: Ref | undefined>, editorServi const { type: ingType } = ingData; - if (ingType !== 'page' && data.type === 'page') return false; - if (ingType === 'page' && data.type !== 'page') return false; + if (ingType !== NodeType.PAGE && data.type === NodeType.PAGE) return false; + if (ingType === NodeType.PAGE && data.type !== NodeType.PAGE) return false; if (!data || !data.type) return false; if (['prev', 'next'].includes(type)) return true; if (data.items || data.type === 'container') return true; diff --git a/packages/editor/src/layouts/workspace/PageBar.vue b/packages/editor/src/layouts/workspace/PageBar.vue index 1ad13e42..d34265f7 100644 --- a/packages/editor/src/layouts/workspace/PageBar.vue +++ b/packages/editor/src/layouts/workspace/PageBar.vue @@ -38,6 +38,7 @@ import { computed, defineComponent, inject, toRaw } from 'vue'; import { CaretBottom, Plus } from '@element-plus/icons'; import type { MPage } from '@tmagic/schema'; +import { NodeType } from '@tmagic/schema'; import type { Services } from '@editor/type'; import { generatePageNameByApp } from '@editor/utils/editor'; @@ -60,7 +61,7 @@ export default defineComponent({ addPage() { if (!editorService) return; const pageConfig = { - type: 'page', + type: NodeType.PAGE, name: generatePageNameByApp(toRaw(editorService.get('root'))), }; editorService.add(pageConfig); diff --git a/packages/editor/src/layouts/workspace/ViewerMenu.vue b/packages/editor/src/layouts/workspace/ViewerMenu.vue index 7772c984..05fd3d83 100644 --- a/packages/editor/src/layouts/workspace/ViewerMenu.vue +++ b/packages/editor/src/layouts/workspace/ViewerMenu.vue @@ -24,6 +24,7 @@