@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.
- package/dist/style.css +41 -28
- package/dist/{tmagic-editor.mjs → tmagic-editor.js} +1693 -1272
- package/dist/tmagic-editor.js.map +1 -0
- package/dist/{tmagic-editor.umd.js → tmagic-editor.umd.cjs} +1700 -1274
- package/dist/tmagic-editor.umd.cjs.map +1 -0
- package/package.json +16 -14
- package/src/Editor.vue +54 -37
- package/src/components/CodeDraftEditor.vue +145 -0
- package/src/components/ContentMenu.vue +4 -4
- package/src/components/FunctionEditor.vue +145 -0
- package/src/components/Icon.vue +7 -5
- package/src/components/Layout.vue +149 -0
- package/src/components/ScrollBar.vue +1 -1
- package/src/components/ScrollViewer.vue +10 -1
- package/src/components/ToolButton.vue +30 -15
- package/src/fields/Code.vue +1 -1
- package/src/fields/CodeLink.vue +1 -1
- package/src/fields/CodeSelect.vue +89 -110
- package/src/fields/UISelect.vue +9 -8
- package/src/index.ts +1 -0
- package/src/layouts/AddPageBox.vue +3 -2
- package/src/layouts/CodeEditor.vue +2 -3
- package/src/layouts/Framework.vue +62 -40
- package/src/layouts/NavMenu.vue +1 -1
- package/src/layouts/PropsPanel.vue +11 -13
- package/src/layouts/Resizer.vue +1 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +15 -13
- package/src/layouts/sidebar/LayerMenu.vue +9 -7
- package/src/layouts/sidebar/LayerPanel.vue +277 -177
- package/src/layouts/sidebar/Sidebar.vue +113 -27
- package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +34 -85
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +55 -89
- package/src/layouts/workspace/Breadcrumb.vue +32 -0
- package/src/layouts/workspace/PageBar.vue +12 -11
- package/src/layouts/workspace/PageBarScrollContainer.vue +1 -1
- package/src/layouts/workspace/Stage.vue +26 -9
- package/src/layouts/workspace/ViewerMenu.vue +11 -9
- package/src/layouts/workspace/Workspace.vue +10 -3
- package/src/services/BaseService.ts +6 -1
- package/src/services/codeBlock.ts +124 -125
- package/src/services/componentList.ts +6 -1
- package/src/services/editor.ts +43 -19
- package/src/services/events.ts +6 -1
- package/src/services/history.ts +7 -16
- package/src/services/props.ts +7 -2
- package/src/services/storage.ts +1 -0
- package/src/services/ui.ts +12 -0
- package/src/theme/breadcrumb.scss +6 -0
- package/src/theme/code-block.scss +30 -21
- package/src/theme/component-list-panel.scss +3 -7
- package/src/theme/layer-panel.scss +7 -2
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +76 -50
- package/src/utils/editor.ts +9 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/props.ts +2 -2
- package/src/utils/scroll-viewer.ts +18 -2
- package/src/utils/stage.ts +9 -2
- package/types/Editor.vue.d.ts +42 -29
- package/types/components/CodeDraftEditor.vue.d.ts +148 -0
- package/types/components/ContentMenu.vue.d.ts +1 -3
- package/types/components/FunctionEditor.vue.d.ts +120 -0
- package/types/components/Icon.vue.d.ts +1 -3
- package/types/{layouts → components}/Layout.vue.d.ts +12 -1
- package/types/components/ScrollBar.vue.d.ts +1 -3
- package/types/components/ScrollViewer.vue.d.ts +45 -1
- package/types/components/ToolButton.vue.d.ts +1 -3
- package/types/fields/Code.vue.d.ts +1 -3
- package/types/fields/CodeLink.vue.d.ts +1 -3
- package/types/fields/CodeSelect.vue.d.ts +10 -12
- package/types/fields/UISelect.vue.d.ts +1 -3
- package/types/index.d.ts +1 -0
- package/types/layouts/AddPageBox.vue.d.ts +1 -3
- package/types/layouts/CodeEditor.vue.d.ts +6 -15
- package/types/layouts/NavMenu.vue.d.ts +1 -3
- package/types/layouts/sidebar/LayerMenu.vue.d.ts +25 -9
- package/types/layouts/sidebar/LayerPanel.vue.d.ts +38 -886
- package/types/layouts/sidebar/Sidebar.vue.d.ts +10 -5
- package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +1 -1
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +6 -5
- package/types/layouts/{sidebar/TabPane.vue.d.ts → workspace/Breadcrumb.vue.d.ts} +5 -43
- package/types/layouts/workspace/Stage.vue.d.ts +25 -8
- package/types/layouts/workspace/ViewerMenu.vue.d.ts +6 -3
- package/types/layouts/workspace/Workspace.vue.d.ts +23 -5
- package/types/services/BaseService.d.ts +2 -1
- package/types/services/codeBlock.d.ts +57 -36
- package/types/services/componentList.d.ts +1 -0
- package/types/services/editor.d.ts +5 -6
- package/types/services/events.d.ts +1 -0
- package/types/services/history.d.ts +5 -15
- package/types/services/props.d.ts +3 -2
- package/types/services/ui.d.ts +2 -1
- package/types/type.d.ts +64 -48
- package/types/utils/editor.d.ts +1 -0
- package/types/utils/index.d.ts +1 -0
- package/types/utils/props.d.ts +1 -1
- package/types/utils/scroll-viewer.d.ts +5 -0
- package/dist/tmagic-editor.mjs.map +0 -1
- package/dist/tmagic-editor.umd.js.map +0 -1
- package/src/layouts/Layout.vue +0 -100
- 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
|
-
<
|
|
12
|
+
<TMagicTooltip effect="dark" placement="top-start" :content="item.name">
|
|
13
13
|
<span>{{ item.name || item.id }}</span>
|
|
14
|
-
</
|
|
14
|
+
</TMagicTooltip>
|
|
15
15
|
</slot>
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
|
-
<
|
|
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
|
-
<
|
|
21
|
+
<ToolButton
|
|
22
22
|
:data="{
|
|
23
23
|
type: 'button',
|
|
24
24
|
text: '复制',
|
|
25
25
|
icon: DocumentCopy,
|
|
26
26
|
handler: () => copy(item),
|
|
27
27
|
}"
|
|
28
|
-
></
|
|
29
|
-
<
|
|
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
|
-
></
|
|
36
|
+
></ToolButton>
|
|
37
37
|
</slot>
|
|
38
38
|
</div>
|
|
39
39
|
<template #reference>
|
|
40
|
-
<
|
|
40
|
+
<TMagicIcon class="m-editor-page-bar-menu-icon">
|
|
41
41
|
<CaretBottom></CaretBottom>
|
|
42
|
-
</
|
|
42
|
+
</TMagicIcon>
|
|
43
43
|
</template>
|
|
44
|
-
</
|
|
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
|
-
<
|
|
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
|
-
<
|
|
20
|
-
<
|
|
21
|
-
</
|
|
22
|
-
</
|
|
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,
|
|
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(
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
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();
|