@tmagic/editor 1.1.0-beta.4 → 1.1.0-beta.7
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/{tmagic-editor.es.js → tmagic-editor.mjs} +1361 -1144
- package/dist/tmagic-editor.mjs.map +1 -0
- package/dist/tmagic-editor.umd.js +1375 -1158
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/package.json +21 -19
- package/src/Editor.vue +14 -12
- package/src/components/ContentMenu.vue +87 -99
- package/src/components/ScrollViewer.vue +1 -1
- package/src/components/ToolButton.vue +150 -167
- package/src/fields/UISelect.vue +49 -70
- package/src/index.ts +2 -1
- package/src/layouts/AddPageBox.vue +2 -2
- package/src/layouts/Framework.vue +1 -1
- package/src/layouts/NavMenu.vue +2 -2
- package/src/layouts/PropsPanel.vue +1 -1
- package/src/layouts/Resizer.vue +1 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +2 -2
- package/src/layouts/sidebar/LayerMenu.vue +2 -2
- package/src/layouts/sidebar/LayerPanel.vue +13 -4
- package/src/layouts/sidebar/Sidebar.vue +1 -1
- package/src/layouts/sidebar/TabPane.vue +2 -2
- package/src/layouts/workspace/PageBar.vue +63 -192
- package/src/layouts/workspace/PageBarScrollContainer.vue +111 -0
- package/src/layouts/workspace/Stage.vue +195 -222
- package/src/layouts/workspace/ViewerMenu.vue +142 -146
- package/src/layouts/workspace/Workspace.vue +11 -11
- package/src/services/BaseService.ts +1 -1
- package/src/services/componentList.ts +3 -3
- package/src/services/editor.ts +117 -135
- package/src/services/events.ts +1 -1
- package/src/services/history.ts +1 -1
- package/src/services/props.ts +62 -10
- package/src/services/storage.ts +133 -0
- package/src/services/ui.ts +2 -2
- package/src/type.ts +22 -6
- package/src/utils/config.ts +1 -1
- package/src/utils/editor.ts +1 -1
- package/src/utils/operator.ts +210 -0
- package/src/utils/props.ts +2 -24
- package/src/utils/scroll-viewer.ts +1 -1
- package/tsconfig.build.json +13 -0
- package/{dist/types/src → types}/Editor.vue.d.ts +7 -8
- package/types/components/ContentMenu.vue.d.ts +116 -0
- package/types/components/Icon.vue.d.ts +13 -0
- package/types/components/ScrollViewer.vue.d.ts +22 -0
- package/types/components/ToolButton.vue.d.ts +109 -0
- package/types/fields/Code.vue.d.ts +23 -0
- package/{dist/types/src → types}/fields/CodeLink.vue.d.ts +4 -6
- package/types/fields/UISelect.vue.d.ts +83 -0
- package/{dist/types/src → types}/index.d.ts +4 -1
- package/types/layouts/AddPageBox.vue.d.ts +4 -0
- package/{dist/types/src → types}/layouts/CodeEditor.vue.d.ts +11 -13
- package/types/layouts/Framework.vue.d.ts +22 -0
- package/types/layouts/NavMenu.vue.d.ts +25 -0
- package/types/layouts/PropsPanel.vue.d.ts +245 -0
- package/types/layouts/Resizer.vue.d.ts +12 -0
- package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +14 -0
- package/types/layouts/sidebar/LayerMenu.vue.d.ts +100 -0
- package/types/layouts/sidebar/LayerPanel.vue.d.ts +1099 -0
- package/{dist/types/src → types}/layouts/sidebar/Sidebar.vue.d.ts +3 -5
- package/types/layouts/sidebar/TabPane.vue.d.ts +14 -0
- package/types/layouts/workspace/PageBar.vue.d.ts +54 -0
- package/types/layouts/workspace/PageBarScrollContainer.vue.d.ts +48 -0
- package/types/layouts/workspace/Stage.vue.d.ts +46 -0
- package/types/layouts/workspace/ViewerMenu.vue.d.ts +88 -0
- package/types/layouts/workspace/Workspace.vue.d.ts +6 -0
- package/{dist/types/src → types}/services/BaseService.d.ts +0 -0
- package/types/services/componentList.d.ts +14 -0
- package/{dist/types/src → types}/services/editor.d.ts +26 -11
- package/{dist/types/src → types}/services/events.d.ts +0 -0
- package/{dist/types/src → types}/services/history.d.ts +0 -0
- package/{dist/types/src → types}/services/props.d.ts +25 -1
- package/types/services/storage.d.ts +56 -0
- package/{dist/types/src → types}/services/ui.d.ts +1 -1
- package/{dist/types/src → types}/type.d.ts +15 -0
- package/{dist/types/src → types}/utils/compose.d.ts +1 -1
- package/{dist/types/src → types}/utils/config.d.ts +0 -0
- package/{dist/types/src → types}/utils/editor.d.ts +2 -2
- package/{dist/types/src → types}/utils/index.d.ts +0 -0
- package/{dist/types/src → types}/utils/logger.d.ts +0 -0
- package/types/utils/operator.d.ts +44 -0
- package/{dist/types/src → types}/utils/polyfills.d.ts +0 -0
- package/{dist/types/src → types}/utils/props.d.ts +2 -22
- package/{dist/types/src → types}/utils/scroll-viewer.d.ts +0 -0
- package/{dist/types/src → types}/utils/undo-redo.d.ts +0 -0
- package/dist/tmagic-editor.es.js.map +0 -1
- package/dist/types/src/components/Icon.vue.d.ts +0 -14
- package/dist/types/src/components/ScrollViewer.vue.d.ts +0 -24
- package/dist/types/src/fields/Code.vue.d.ts +0 -25
- package/dist/types/src/layouts/AddPageBox.vue.d.ts +0 -5
- package/dist/types/src/layouts/Framework.vue.d.ts +0 -24
- package/dist/types/src/layouts/NavMenu.vue.d.ts +0 -27
- package/dist/types/src/layouts/PropsPanel.vue.d.ts +0 -13
- package/dist/types/src/layouts/Resizer.vue.d.ts +0 -14
- package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +0 -16
- package/dist/types/src/layouts/sidebar/TabPane.vue.d.ts +0 -16
- package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +0 -8
- package/dist/types/src/shims-vue.d.ts +0 -6
- package/dist/types/src/vite-env.d.ts +0 -1
- package/src/vite-env.d.ts +0 -1
package/src/fields/UISelect.vue
CHANGED
|
@@ -12,89 +12,68 @@
|
|
|
12
12
|
</div>
|
|
13
13
|
</template>
|
|
14
14
|
|
|
15
|
-
<script lang="ts">
|
|
16
|
-
import { computed,
|
|
17
|
-
import { Close, Delete
|
|
15
|
+
<script lang="ts" setup>
|
|
16
|
+
import { computed, inject, ref } from 'vue';
|
|
17
|
+
import { Close, Delete } from '@element-plus/icons-vue';
|
|
18
18
|
|
|
19
19
|
import { FormState } from '@tmagic/form';
|
|
20
20
|
|
|
21
|
-
import { Services } from '
|
|
21
|
+
import { Services } from '../type';
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const props = defineProps<{
|
|
24
|
+
config: any;
|
|
25
|
+
model: any;
|
|
26
|
+
prop: string;
|
|
27
|
+
name: string;
|
|
28
|
+
}>();
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
labelWidth: String,
|
|
28
|
-
config: Object,
|
|
29
|
-
model: Object,
|
|
30
|
-
prop: {
|
|
31
|
-
type: String,
|
|
32
|
-
default() {
|
|
33
|
-
return '';
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
name: String,
|
|
37
|
-
},
|
|
30
|
+
const emit = defineEmits(['change']);
|
|
38
31
|
|
|
39
|
-
|
|
32
|
+
const services = inject<Services>('services');
|
|
33
|
+
const mForm = inject<FormState>('mForm');
|
|
34
|
+
const val = computed(() => props.model[props.name]);
|
|
35
|
+
const uiSelectMode = ref(false);
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
const cancelHandler = () => {
|
|
38
|
+
if (!services?.uiService) return;
|
|
39
|
+
services.uiService.set<boolean>('uiSelectMode', false);
|
|
40
|
+
uiSelectMode.value = false;
|
|
41
|
+
globalThis.document.removeEventListener('ui-select', clickHandler as EventListener);
|
|
42
|
+
};
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const clickHandler = ({ detail }: Event & { detail: any }) => {
|
|
55
|
-
if (detail.id) {
|
|
56
|
-
props.model[props.name] = detail.id;
|
|
57
|
-
emit('change', detail.id);
|
|
58
|
-
mForm?.$emit('field-change', props.prop, detail.id);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (cancelHandler) {
|
|
62
|
-
cancelHandler();
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
Delete: markRaw(Delete),
|
|
68
|
-
Pointer: markRaw(Pointer),
|
|
69
|
-
Close: markRaw(Close),
|
|
44
|
+
const clickHandler = ({ detail }: Event & { detail: any }) => {
|
|
45
|
+
if (detail.id) {
|
|
46
|
+
props.model[props.name] = detail.id;
|
|
47
|
+
emit('change', detail.id);
|
|
48
|
+
mForm?.$emit('field-change', props.prop, detail.id);
|
|
49
|
+
}
|
|
70
50
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return config?.name || '';
|
|
76
|
-
}),
|
|
51
|
+
if (cancelHandler) {
|
|
52
|
+
cancelHandler();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
77
55
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
globalThis.document.addEventListener('ui-select', clickHandler as EventListener);
|
|
83
|
-
},
|
|
56
|
+
const toName = computed(() => {
|
|
57
|
+
const config = services?.editorService.getNodeById(val.value);
|
|
58
|
+
return config?.name || '';
|
|
59
|
+
});
|
|
84
60
|
|
|
85
|
-
|
|
61
|
+
const startSelect = () => {
|
|
62
|
+
if (!services?.uiService) return;
|
|
63
|
+
services.uiService.set<boolean>('uiSelectMode', true);
|
|
64
|
+
uiSelectMode.value = true;
|
|
65
|
+
globalThis.document.addEventListener('ui-select', clickHandler as EventListener);
|
|
66
|
+
};
|
|
86
67
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
},
|
|
96
|
-
});
|
|
68
|
+
const deleteHandler = () => {
|
|
69
|
+
if (props.model) {
|
|
70
|
+
props.model[props.name] = '';
|
|
71
|
+
emit('change', '');
|
|
72
|
+
mForm?.$emit('field-change', props.prop, '');
|
|
73
|
+
}
|
|
74
|
+
};
|
|
97
75
|
</script>
|
|
76
|
+
|
|
98
77
|
<style lang="scss">
|
|
99
78
|
.m-fields-ui-select {
|
|
100
79
|
cursor: pointer;
|
package/src/index.ts
CHANGED
|
@@ -37,6 +37,7 @@ export { default as TMagicCodeEditor } from './layouts/CodeEditor.vue';
|
|
|
37
37
|
export { default as editorService } from './services/editor';
|
|
38
38
|
export { default as propsService } from './services/props';
|
|
39
39
|
export { default as historyService } from './services/history';
|
|
40
|
+
export { default as storageService } from './services/storage';
|
|
40
41
|
export { default as eventsService } from './services/events';
|
|
41
42
|
export { default as uiService } from './services/ui';
|
|
42
43
|
export { default as ComponentListPanel } from './layouts/sidebar/ComponentListPanel.vue';
|
|
@@ -57,7 +58,7 @@ export default {
|
|
|
57
58
|
setConfig(option);
|
|
58
59
|
|
|
59
60
|
app.component(Editor.name, Editor);
|
|
60
|
-
app.component(
|
|
61
|
+
app.component('m-fields-ui-select', uiSelect);
|
|
61
62
|
app.component(CodeLink.name, CodeLink);
|
|
62
63
|
app.component(Code.name, Code);
|
|
63
64
|
app.component(CodeEditor.name, CodeEditor);
|
|
@@ -17,8 +17,8 @@ import { Plus } from '@element-plus/icons-vue';
|
|
|
17
17
|
|
|
18
18
|
import { NodeType } from '@tmagic/schema';
|
|
19
19
|
|
|
20
|
-
import type { Services } from '
|
|
21
|
-
import { generatePageNameByApp } from '
|
|
20
|
+
import type { Services } from '../type';
|
|
21
|
+
import { generatePageNameByApp } from '../utils';
|
|
22
22
|
|
|
23
23
|
export default defineComponent({
|
|
24
24
|
components: { Plus },
|
|
@@ -43,7 +43,7 @@ import { computed, defineComponent, inject } from 'vue';
|
|
|
43
43
|
|
|
44
44
|
import type { MApp } from '@tmagic/schema';
|
|
45
45
|
|
|
46
|
-
import { GetColumnWidth, Services } from '
|
|
46
|
+
import { GetColumnWidth, Services } from '../type';
|
|
47
47
|
|
|
48
48
|
import AddPageBox from './AddPageBox.vue';
|
|
49
49
|
import Resizer from './Resizer.vue';
|
package/src/layouts/NavMenu.vue
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
<script lang="ts">
|
|
10
10
|
import { computed, defineComponent, inject, PropType } from 'vue';
|
|
11
11
|
|
|
12
|
-
import ToolButton from '
|
|
13
|
-
import { GetColumnWidth, MenuBarData, Services } from '
|
|
12
|
+
import ToolButton from '../components/ToolButton.vue';
|
|
13
|
+
import { GetColumnWidth, MenuBarData, Services } from '../type';
|
|
14
14
|
|
|
15
15
|
export default defineComponent({
|
|
16
16
|
name: 'nav-menu',
|
|
@@ -20,7 +20,7 @@ import { ElMessage } from 'element-plus';
|
|
|
20
20
|
import type { FormValue, MForm } from '@tmagic/form';
|
|
21
21
|
import type { MNode } from '@tmagic/schema';
|
|
22
22
|
|
|
23
|
-
import type { Services } from '
|
|
23
|
+
import type { Services } from '../type';
|
|
24
24
|
|
|
25
25
|
export default defineComponent({
|
|
26
26
|
name: 'm-editor-props-panel',
|
package/src/layouts/Resizer.vue
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { defineComponent, inject, onMounted, onUnmounted, ref, toRaw } from 'vue';
|
|
9
9
|
import Gesto from 'gesto';
|
|
10
10
|
|
|
11
|
-
import { Services } from '
|
|
11
|
+
import { Services } from '../type';
|
|
12
12
|
|
|
13
13
|
export default defineComponent({
|
|
14
14
|
name: 'm-editor-resize',
|
|
@@ -43,8 +43,8 @@ import serialize from 'serialize-javascript';
|
|
|
43
43
|
import type StageCore from '@tmagic/stage';
|
|
44
44
|
import { removeClassNameByClassName } from '@tmagic/utils';
|
|
45
45
|
|
|
46
|
-
import MIcon from '
|
|
47
|
-
import type { ComponentGroup, ComponentItem, Services, StageOptions } from '
|
|
46
|
+
import MIcon from '../../components/Icon.vue';
|
|
47
|
+
import type { ComponentGroup, ComponentItem, Services, StageOptions } from '../../type';
|
|
48
48
|
|
|
49
49
|
export default defineComponent({
|
|
50
50
|
name: 'ui-component-panel',
|
|
@@ -8,8 +8,8 @@ import { Delete, DocumentCopy, Files, Plus } from '@element-plus/icons-vue';
|
|
|
8
8
|
|
|
9
9
|
import { NodeType } from '@tmagic/schema';
|
|
10
10
|
|
|
11
|
-
import ContentMenu from '
|
|
12
|
-
import type { ComponentGroup, MenuButton, MenuItem, Services } from '
|
|
11
|
+
import ContentMenu from '../../components/ContentMenu.vue';
|
|
12
|
+
import type { ComponentGroup, MenuButton, MenuItem, Services } from '../../type';
|
|
13
13
|
|
|
14
14
|
export default defineComponent({
|
|
15
15
|
components: { ContentMenu },
|
|
@@ -61,11 +61,12 @@ import type { ElTree } from 'element-plus';
|
|
|
61
61
|
import { throttle } from 'lodash-es';
|
|
62
62
|
|
|
63
63
|
import type { MNode, MPage } from '@tmagic/schema';
|
|
64
|
-
import { NodeType } from '@tmagic/schema';
|
|
64
|
+
import { MContainer, NodeType } from '@tmagic/schema';
|
|
65
65
|
import StageCore from '@tmagic/stage';
|
|
66
66
|
|
|
67
|
-
import type { EditorService } from '
|
|
68
|
-
import type { Services } from '
|
|
67
|
+
import type { EditorService } from '../../services/editor';
|
|
68
|
+
import type { Services } from '../../type';
|
|
69
|
+
import { Layout } from '../../type';
|
|
69
70
|
|
|
70
71
|
import LayerMenu from './LayerMenu.vue';
|
|
71
72
|
|
|
@@ -104,8 +105,16 @@ const useDrop = (tree: Ref<InstanceType<typeof ElTree> | undefined>, editorServi
|
|
|
104
105
|
return false;
|
|
105
106
|
},
|
|
106
107
|
|
|
107
|
-
handleDragEnd() {
|
|
108
|
+
async handleDragEnd(e: any) {
|
|
108
109
|
if (!tree.value) return;
|
|
110
|
+
const { data: node } = e;
|
|
111
|
+
const parent = editorService?.getParentById(node.id, false) as MContainer;
|
|
112
|
+
const layout = await editorService?.getLayout(parent);
|
|
113
|
+
node.style.position = layout;
|
|
114
|
+
if (layout === Layout.RELATIVE) {
|
|
115
|
+
node.style.top = 0;
|
|
116
|
+
node.style.left = 0;
|
|
117
|
+
}
|
|
109
118
|
const { data } = tree.value;
|
|
110
119
|
const [page] = data as [MPage];
|
|
111
120
|
editorService?.update(page);
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
import { computed, defineComponent, PropType } from 'vue';
|
|
30
30
|
import { Coin, Files } from '@element-plus/icons-vue';
|
|
31
31
|
|
|
32
|
-
import MIcon from '
|
|
33
|
-
import { SideComponent, SideItem } from '
|
|
32
|
+
import MIcon from '../../components/Icon.vue';
|
|
33
|
+
import { SideComponent, SideItem } from '../../type';
|
|
34
34
|
|
|
35
35
|
import ComponentListPanel from './ComponentListPanel.vue';
|
|
36
36
|
import LayerPanel from './LayerPanel.vue';
|
|
@@ -1,211 +1,82 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<div
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<div
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
<PageBarScrollContainer>
|
|
3
|
+
<div
|
|
4
|
+
v-for="item in (root && root.items) || []"
|
|
5
|
+
class="m-editor-page-bar-item"
|
|
6
|
+
:key="item.key"
|
|
7
|
+
:class="{ active: page?.id === item.id }"
|
|
8
|
+
@click="switchPage(item)"
|
|
9
|
+
>
|
|
10
|
+
<div class="m-editor-page-bar-title">
|
|
11
|
+
<slot name="page-bar-title" :page="item">
|
|
12
|
+
<el-tooltip effect="dark" placement="top-start" :content="item.name">
|
|
13
|
+
<span>{{ item.name }}</span>
|
|
14
|
+
</el-tooltip>
|
|
15
|
+
</slot>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<el-popover popper-class="page-bar-popover" placement="top" :width="160" trigger="hover">
|
|
19
|
+
<div>
|
|
20
|
+
<slot name="page-bar-popover" :page="item">
|
|
21
|
+
<tool-button
|
|
22
|
+
:data="{
|
|
23
|
+
type: 'button',
|
|
24
|
+
text: '复制',
|
|
25
|
+
icon: DocumentCopy,
|
|
26
|
+
handler: () => copy(item),
|
|
27
|
+
}"
|
|
28
|
+
></tool-button>
|
|
29
|
+
<tool-button
|
|
30
|
+
:data="{
|
|
31
|
+
type: 'button',
|
|
32
|
+
text: '删除',
|
|
33
|
+
icon: Delete,
|
|
34
|
+
handler: () => remove(item),
|
|
35
|
+
}"
|
|
36
|
+
></tool-button>
|
|
22
37
|
</slot>
|
|
23
38
|
</div>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type: 'button',
|
|
31
|
-
text: '复制',
|
|
32
|
-
icon: DocumentCopy,
|
|
33
|
-
handler: () => copy(item),
|
|
34
|
-
}"
|
|
35
|
-
></tool-button>
|
|
36
|
-
<tool-button
|
|
37
|
-
:data="{
|
|
38
|
-
type: 'button',
|
|
39
|
-
text: '删除',
|
|
40
|
-
icon: Delete,
|
|
41
|
-
handler: () => remove(item),
|
|
42
|
-
}"
|
|
43
|
-
></tool-button>
|
|
44
|
-
</slot>
|
|
45
|
-
</div>
|
|
46
|
-
<template #reference>
|
|
47
|
-
<el-icon class="m-editor-page-bar-menu-icon">
|
|
48
|
-
<caret-bottom></caret-bottom>
|
|
49
|
-
</el-icon>
|
|
50
|
-
</template>
|
|
51
|
-
</el-popover>
|
|
52
|
-
</div>
|
|
39
|
+
<template #reference>
|
|
40
|
+
<el-icon class="m-editor-page-bar-menu-icon">
|
|
41
|
+
<caret-bottom></caret-bottom>
|
|
42
|
+
</el-icon>
|
|
43
|
+
</template>
|
|
44
|
+
</el-popover>
|
|
53
45
|
</div>
|
|
54
|
-
|
|
55
|
-
<el-icon><arrow-right-bold></arrow-right-bold></el-icon>
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
46
|
+
</PageBarScrollContainer>
|
|
58
47
|
</template>
|
|
59
48
|
|
|
60
|
-
<script lang="ts">
|
|
61
|
-
import {
|
|
62
|
-
|
|
63
|
-
ComputedRef,
|
|
64
|
-
defineComponent,
|
|
65
|
-
inject,
|
|
66
|
-
markRaw,
|
|
67
|
-
onMounted,
|
|
68
|
-
onUnmounted,
|
|
69
|
-
ref,
|
|
70
|
-
toRaw,
|
|
71
|
-
watch,
|
|
72
|
-
} from 'vue';
|
|
73
|
-
import { ArrowLeftBold, ArrowRightBold, CaretBottom, Delete, DocumentCopy, Plus } from '@element-plus/icons-vue';
|
|
49
|
+
<script lang="ts" setup>
|
|
50
|
+
import { computed, inject } from 'vue';
|
|
51
|
+
import { CaretBottom, Delete, DocumentCopy } from '@element-plus/icons-vue';
|
|
74
52
|
|
|
75
53
|
import type { MApp, MPage } from '@tmagic/schema';
|
|
76
|
-
import { NodeType } from '@tmagic/schema';
|
|
77
|
-
|
|
78
|
-
import ToolButton from '@editor/components/ToolButton.vue';
|
|
79
|
-
import type { Services } from '@editor/type';
|
|
80
|
-
import { generatePageNameByApp } from '@editor/utils/editor';
|
|
81
|
-
|
|
82
|
-
const useScroll = (root: ComputedRef<MApp | undefined>) => {
|
|
83
|
-
const pageBar = ref<HTMLDivElement>();
|
|
84
|
-
const itemsContainer = ref<HTMLDivElement>();
|
|
85
|
-
|
|
86
|
-
const pageBarWidth = ref(0);
|
|
87
|
-
const canScroll = ref(false);
|
|
88
|
-
|
|
89
|
-
const itemsContainerWidth = computed(() => pageBarWidth.value - 105);
|
|
90
|
-
|
|
91
|
-
let translateLeft = 0;
|
|
92
|
-
const resizeObserver = new ResizeObserver((entries) => {
|
|
93
|
-
for (const { contentRect } of entries) {
|
|
94
|
-
const { width } = contentRect;
|
|
95
|
-
pageBarWidth.value = width || 0;
|
|
96
|
-
|
|
97
|
-
setCanScroll();
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const setCanScroll = () => {
|
|
102
|
-
if (itemsContainer.value) {
|
|
103
|
-
canScroll.value = itemsContainer.value.scrollWidth > pageBarWidth.value - 105;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const scroll = (type: 'left' | 'right' | 'start' | 'end') => {
|
|
108
|
-
if (!itemsContainer.value) return;
|
|
109
54
|
|
|
110
|
-
|
|
55
|
+
import ToolButton from '../../components/ToolButton.vue';
|
|
56
|
+
import type { Services } from '../../type';
|
|
111
57
|
|
|
112
|
-
|
|
113
|
-
translateLeft += 100;
|
|
58
|
+
import PageBarScrollContainer from './PageBarScrollContainer.vue';
|
|
114
59
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
} else if (type === 'right') {
|
|
119
|
-
translateLeft -= 100;
|
|
60
|
+
const services = inject<Services>('services');
|
|
61
|
+
const editorService = services?.editorService;
|
|
120
62
|
|
|
121
|
-
|
|
122
|
-
translateLeft = -maxScrollLeft;
|
|
123
|
-
}
|
|
124
|
-
} else if (type === 'start') {
|
|
125
|
-
translateLeft = 0;
|
|
126
|
-
} else if (type === 'end') {
|
|
127
|
-
translateLeft = -maxScrollLeft;
|
|
128
|
-
}
|
|
63
|
+
const root = computed(() => editorService?.get<MApp>('root'));
|
|
129
64
|
|
|
130
|
-
|
|
131
|
-
};
|
|
65
|
+
const page = computed(() => editorService?.get('page'));
|
|
132
66
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
67
|
+
const switchPage = (page: MPage) => {
|
|
68
|
+
editorService?.select(page);
|
|
69
|
+
};
|
|
136
70
|
|
|
137
|
-
|
|
138
|
-
|
|
71
|
+
const copy = (node: MPage) => {
|
|
72
|
+
node && editorService?.copy(node);
|
|
73
|
+
editorService?.paste({
|
|
74
|
+
left: 0,
|
|
75
|
+
top: 0,
|
|
139
76
|
});
|
|
140
|
-
|
|
141
|
-
watch(
|
|
142
|
-
() => root.value?.items.length,
|
|
143
|
-
(length = 0, preLength = 0) => {
|
|
144
|
-
setTimeout(() => {
|
|
145
|
-
setCanScroll();
|
|
146
|
-
if (length < preLength) {
|
|
147
|
-
scroll('start');
|
|
148
|
-
} else {
|
|
149
|
-
scroll('end');
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
},
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
pageBar,
|
|
157
|
-
itemsContainer,
|
|
158
|
-
canScroll,
|
|
159
|
-
|
|
160
|
-
itemsContainerWidth,
|
|
161
|
-
|
|
162
|
-
scroll,
|
|
163
|
-
};
|
|
164
77
|
};
|
|
165
78
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
setup() {
|
|
170
|
-
const services = inject<Services>('services');
|
|
171
|
-
const editorService = services?.editorService;
|
|
172
|
-
|
|
173
|
-
const root = computed(() => editorService?.get<MApp>('root'));
|
|
174
|
-
|
|
175
|
-
return {
|
|
176
|
-
Delete: markRaw(Delete),
|
|
177
|
-
DocumentCopy: markRaw(DocumentCopy),
|
|
178
|
-
|
|
179
|
-
...useScroll(root),
|
|
180
|
-
|
|
181
|
-
root,
|
|
182
|
-
page: computed(() => editorService?.get('page')),
|
|
183
|
-
|
|
184
|
-
switchPage(page: MPage) {
|
|
185
|
-
editorService?.select(page);
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
addPage() {
|
|
189
|
-
if (!editorService) return;
|
|
190
|
-
const pageConfig = {
|
|
191
|
-
type: NodeType.PAGE,
|
|
192
|
-
name: generatePageNameByApp(toRaw(editorService.get('root'))),
|
|
193
|
-
};
|
|
194
|
-
editorService.add(pageConfig);
|
|
195
|
-
},
|
|
196
|
-
|
|
197
|
-
copy(node: MPage) {
|
|
198
|
-
node && editorService?.copy(node);
|
|
199
|
-
editorService?.paste({
|
|
200
|
-
left: 0,
|
|
201
|
-
top: 0,
|
|
202
|
-
});
|
|
203
|
-
},
|
|
204
|
-
|
|
205
|
-
remove(node: MPage) {
|
|
206
|
-
editorService?.remove(node);
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
},
|
|
210
|
-
});
|
|
79
|
+
const remove = (node: MPage) => {
|
|
80
|
+
editorService?.remove(node);
|
|
81
|
+
};
|
|
211
82
|
</script>
|