@tmagic/editor 1.4.6 → 1.4.8
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 +1 -1
- package/dist/tmagic-editor.js +636 -589
- package/dist/tmagic-editor.umd.cjs +634 -586
- package/package.json +15 -11
- package/types/editorProps.d.ts +0 -7
- package/types/layouts/PropsPanel.vue.d.ts +9 -9
- package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
- package/types/services/codeBlock.d.ts +2 -1
- package/types/services/dataSource.d.ts +2 -1
- package/types/services/dep.d.ts +12 -2
- package/types/services/editor.d.ts +22 -4
- package/types/services/props.d.ts +7 -6
- package/types/type.d.ts +6 -0
- package/types/utils/editor.d.ts +1 -0
- package/types/utils/idle-task.d.ts +14 -0
- package/types/utils/operator.d.ts +2 -2
- package/src/Editor.vue +0 -211
- package/src/components/CodeBlockEditor.vue +0 -268
- package/src/components/CodeParams.vue +0 -60
- package/src/components/ContentMenu.vue +0 -193
- package/src/components/FloatingBox.vue +0 -178
- package/src/components/Icon.vue +0 -27
- package/src/components/Resizer.vue +0 -23
- package/src/components/ScrollBar.vue +0 -151
- package/src/components/ScrollViewer.vue +0 -128
- package/src/components/SearchInput.vue +0 -37
- package/src/components/SplitView.vue +0 -186
- package/src/components/ToolButton.vue +0 -138
- package/src/components/Tree.vue +0 -71
- package/src/components/TreeNode.vue +0 -148
- package/src/editorProps.ts +0 -124
- package/src/fields/Code.vue +0 -50
- package/src/fields/CodeLink.vue +0 -80
- package/src/fields/CodeSelect.vue +0 -132
- package/src/fields/CodeSelectCol.vue +0 -139
- package/src/fields/DataSourceFieldSelect.vue +0 -149
- package/src/fields/DataSourceFields.vue +0 -323
- package/src/fields/DataSourceInput.vue +0 -325
- package/src/fields/DataSourceMethodSelect.vue +0 -153
- package/src/fields/DataSourceMethods.vue +0 -104
- package/src/fields/DataSourceMocks.vue +0 -255
- package/src/fields/DataSourceSelect.vue +0 -98
- package/src/fields/EventSelect.vue +0 -301
- package/src/fields/KeyValue.vue +0 -137
- package/src/fields/PageFragmentSelect.vue +0 -63
- package/src/fields/UISelect.vue +0 -135
- package/src/hooks/index.ts +0 -24
- package/src/hooks/use-code-block-edit.ts +0 -83
- package/src/hooks/use-data-source-edit.ts +0 -46
- package/src/hooks/use-data-source-method.ts +0 -100
- package/src/hooks/use-editor-content-height.ts +0 -26
- package/src/hooks/use-filter.ts +0 -55
- package/src/hooks/use-float-box.ts +0 -76
- package/src/hooks/use-getso.ts +0 -35
- package/src/hooks/use-next-float-box-position.ts +0 -29
- package/src/hooks/use-node-status.ts +0 -48
- package/src/hooks/use-stage.ts +0 -129
- package/src/hooks/use-window-rect.ts +0 -20
- package/src/icons/AppManageIcon.vue +0 -15
- package/src/icons/CenterIcon.vue +0 -13
- package/src/icons/CodeIcon.vue +0 -28
- package/src/icons/FolderMinusIcon.vue +0 -22
- package/src/icons/PinIcon.vue +0 -25
- package/src/icons/PinnedIcon.vue +0 -25
- package/src/index.ts +0 -118
- package/src/initService.ts +0 -447
- package/src/layouts/AddPageBox.vue +0 -55
- package/src/layouts/CodeEditor.vue +0 -226
- package/src/layouts/Framework.vue +0 -163
- package/src/layouts/NavMenu.vue +0 -200
- package/src/layouts/PropsPanel.vue +0 -130
- package/src/layouts/page-bar/AddButton.vue +0 -48
- package/src/layouts/page-bar/PageBar.vue +0 -159
- package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
- package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
- package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
- package/src/layouts/sidebar/Sidebar.vue +0 -278
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -142
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
- package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -160
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
- package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
- package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
- package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
- package/src/layouts/sidebar/layer/use-click.ts +0 -110
- package/src/layouts/sidebar/layer/use-drag.ts +0 -161
- package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
- package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
- package/src/layouts/workspace/Breadcrumb.vue +0 -35
- package/src/layouts/workspace/Workspace.vue +0 -46
- package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
- package/src/layouts/workspace/viewer/Stage.vue +0 -246
- package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
- package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
- package/src/services/BaseService.ts +0 -230
- package/src/services/codeBlock.ts +0 -324
- package/src/services/componentList.ts +0 -58
- package/src/services/dataSource.ts +0 -209
- package/src/services/dep.ts +0 -80
- package/src/services/editor.ts +0 -1087
- package/src/services/events.ts +0 -93
- package/src/services/history.ts +0 -126
- package/src/services/keybinding.ts +0 -220
- package/src/services/props.ts +0 -265
- package/src/services/stageOverlay.ts +0 -212
- package/src/services/storage.ts +0 -155
- package/src/services/ui.ts +0 -156
- package/src/shims-vue.d.ts +0 -6
- package/src/theme/breadcrumb.scss +0 -6
- package/src/theme/code-block.scss +0 -6
- package/src/theme/code-editor.scss +0 -38
- package/src/theme/common/var.scss +0 -14
- package/src/theme/component-list-panel.scss +0 -95
- package/src/theme/content-menu.scss +0 -76
- package/src/theme/data-source-field.scss +0 -12
- package/src/theme/data-source-fields.scss +0 -13
- package/src/theme/data-source-input.scss +0 -18
- package/src/theme/data-source-methods.scss +0 -13
- package/src/theme/data-source.scss +0 -28
- package/src/theme/event.scss +0 -37
- package/src/theme/floating-box.scss +0 -32
- package/src/theme/framework.scss +0 -69
- package/src/theme/icon.scss +0 -12
- package/src/theme/index.scss +0 -10
- package/src/theme/key-value.scss +0 -20
- package/src/theme/layer-panel.scss +0 -26
- package/src/theme/layout.scss +0 -9
- package/src/theme/nav-menu.scss +0 -78
- package/src/theme/page-bar.scss +0 -89
- package/src/theme/page-fragment-select.scss +0 -14
- package/src/theme/props-panel.scss +0 -55
- package/src/theme/resizer.scss +0 -66
- package/src/theme/ruler.scss +0 -38
- package/src/theme/search-input.scss +0 -14
- package/src/theme/sidebar.scss +0 -79
- package/src/theme/stage.scss +0 -76
- package/src/theme/theme.scss +0 -27
- package/src/theme/tree.scss +0 -89
- package/src/theme/workspace.scss +0 -9
- package/src/type.ts +0 -746
- package/src/utils/compose.ts +0 -52
- package/src/utils/config.ts +0 -29
- package/src/utils/content-menu.ts +0 -95
- package/src/utils/data-source/formConfigs/base.ts +0 -30
- package/src/utils/data-source/formConfigs/http.ts +0 -60
- package/src/utils/data-source/index.ts +0 -236
- package/src/utils/editor.ts +0 -294
- package/src/utils/index.ts +0 -24
- package/src/utils/keybinding-config.ts +0 -125
- package/src/utils/logger.ts +0 -47
- package/src/utils/monaco-editor.ts +0 -8
- package/src/utils/operator.ts +0 -106
- package/src/utils/props.ts +0 -504
- package/src/utils/scroll-viewer.ts +0 -165
- package/src/utils/tree.ts +0 -15
- package/src/utils/undo-redo.ts +0 -76
- package/tsconfig.build.json +0 -16
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="m-editor-props-panel" v-show="nodes.length === 1">
|
|
3
|
-
<slot name="props-panel-header"></slot>
|
|
4
|
-
<MForm
|
|
5
|
-
ref="configForm"
|
|
6
|
-
:class="propsPanelSize"
|
|
7
|
-
:popper-class="`m-editor-props-panel-popper ${propsPanelSize}`"
|
|
8
|
-
:size="propsPanelSize"
|
|
9
|
-
:init-values="values"
|
|
10
|
-
:config="curFormConfig"
|
|
11
|
-
:extend-state="extendState"
|
|
12
|
-
@change="submit"
|
|
13
|
-
@error="errorHandler"
|
|
14
|
-
></MForm>
|
|
15
|
-
|
|
16
|
-
<TMagicButton
|
|
17
|
-
v-if="!disabledShowSrc"
|
|
18
|
-
class="m-editor-props-panel-src-icon"
|
|
19
|
-
circle
|
|
20
|
-
size="large"
|
|
21
|
-
title="源码"
|
|
22
|
-
:type="showSrc ? 'primary' : ''"
|
|
23
|
-
@click="showSrc = !showSrc"
|
|
24
|
-
>
|
|
25
|
-
<MIcon :icon="DocumentIcon"></MIcon>
|
|
26
|
-
</TMagicButton>
|
|
27
|
-
|
|
28
|
-
<CodeEditor
|
|
29
|
-
v-if="showSrc"
|
|
30
|
-
:height="`${editorContentHeight}px`"
|
|
31
|
-
:init-values="values"
|
|
32
|
-
:options="codeOptions"
|
|
33
|
-
:parse="true"
|
|
34
|
-
@save="saveCode"
|
|
35
|
-
></CodeEditor>
|
|
36
|
-
</div>
|
|
37
|
-
</template>
|
|
38
|
-
|
|
39
|
-
<script lang="ts" setup>
|
|
40
|
-
import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted, ref, watchEffect } from 'vue';
|
|
41
|
-
import { Document as DocumentIcon } from '@element-plus/icons-vue';
|
|
42
|
-
|
|
43
|
-
import { TMagicButton } from '@tmagic/design';
|
|
44
|
-
import type { FormState, FormValue } from '@tmagic/form';
|
|
45
|
-
import { MForm } from '@tmagic/form';
|
|
46
|
-
import type { MNode } from '@tmagic/schema';
|
|
47
|
-
|
|
48
|
-
import MIcon from '@editor/components/Icon.vue';
|
|
49
|
-
import { useEditorContentHeight } from '@editor/hooks/use-editor-content-height';
|
|
50
|
-
import type { PropsPanelSlots, Services } from '@editor/type';
|
|
51
|
-
|
|
52
|
-
import CodeEditor from './CodeEditor.vue';
|
|
53
|
-
|
|
54
|
-
defineSlots<PropsPanelSlots>();
|
|
55
|
-
|
|
56
|
-
defineOptions({
|
|
57
|
-
name: 'MEditorPropsPanel',
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
defineProps<{
|
|
61
|
-
disabledShowSrc?: boolean;
|
|
62
|
-
extendState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
|
63
|
-
}>();
|
|
64
|
-
|
|
65
|
-
const codeOptions = inject('codeOptions', {});
|
|
66
|
-
|
|
67
|
-
const emit = defineEmits(['mounted', 'submit-error', 'form-error']);
|
|
68
|
-
|
|
69
|
-
const showSrc = ref(false);
|
|
70
|
-
|
|
71
|
-
const internalInstance = getCurrentInstance();
|
|
72
|
-
const values = ref<FormValue>({});
|
|
73
|
-
const configForm = ref<InstanceType<typeof MForm>>();
|
|
74
|
-
// ts类型应该是FormConfig, 但是打包时会出错,所以暂时用any
|
|
75
|
-
const curFormConfig = ref<any>([]);
|
|
76
|
-
const services = inject<Services>('services');
|
|
77
|
-
const node = computed(() => services?.editorService.get('node'));
|
|
78
|
-
const nodes = computed(() => services?.editorService.get('nodes') || []);
|
|
79
|
-
const propsPanelSize = computed(() => services?.uiService.get('propsPanelSize') || 'small');
|
|
80
|
-
const stage = computed(() => services?.editorService.get('stage'));
|
|
81
|
-
|
|
82
|
-
const { height: editorContentHeight } = useEditorContentHeight();
|
|
83
|
-
|
|
84
|
-
const init = async () => {
|
|
85
|
-
if (!node.value) {
|
|
86
|
-
curFormConfig.value = [];
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const type = node.value.type || (node.value.items ? 'container' : 'text');
|
|
91
|
-
curFormConfig.value = (await services?.propsService.getPropsConfig(type)) || [];
|
|
92
|
-
values.value = node.value;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
watchEffect(init);
|
|
96
|
-
services?.propsService.on('props-configs-change', init);
|
|
97
|
-
|
|
98
|
-
onMounted(() => {
|
|
99
|
-
emit('mounted', internalInstance);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
onBeforeUnmount(() => {
|
|
103
|
-
services?.propsService.off('props-configs-change', init);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
watchEffect(() => {
|
|
107
|
-
if (configForm.value && stage.value) {
|
|
108
|
-
configForm.value.formState.stage = stage.value;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const submit = async () => {
|
|
113
|
-
try {
|
|
114
|
-
const values = await configForm.value?.submitForm();
|
|
115
|
-
services?.editorService.update(values);
|
|
116
|
-
} catch (e: any) {
|
|
117
|
-
emit('submit-error', e);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const errorHandler = (e: any) => {
|
|
122
|
-
emit('form-error', e);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const saveCode = (values: MNode) => {
|
|
126
|
-
services?.editorService.update(values);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
defineExpose({ configForm, submit });
|
|
130
|
-
</script>
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
v-if="showAddPageButton"
|
|
4
|
-
id="m-editor-page-bar-add-icon"
|
|
5
|
-
class="m-editor-page-bar-item m-editor-page-bar-item-icon"
|
|
6
|
-
@click="addPage"
|
|
7
|
-
>
|
|
8
|
-
<Icon :icon="Plus"></Icon>
|
|
9
|
-
</div>
|
|
10
|
-
<div v-else style="width: 21px"></div>
|
|
11
|
-
</template>
|
|
12
|
-
|
|
13
|
-
<script setup lang="ts">
|
|
14
|
-
import { computed, inject, toRaw } from 'vue';
|
|
15
|
-
import { Plus } from '@element-plus/icons-vue';
|
|
16
|
-
|
|
17
|
-
import { NodeType } from '@tmagic/schema';
|
|
18
|
-
|
|
19
|
-
import Icon from '@editor/components/Icon.vue';
|
|
20
|
-
import type { Services } from '@editor/type';
|
|
21
|
-
import { generatePageNameByApp } from '@editor/utils/editor';
|
|
22
|
-
|
|
23
|
-
defineOptions({
|
|
24
|
-
name: 'MEditorPageBarAddButton',
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const props = defineProps<{
|
|
28
|
-
type: NodeType.PAGE | NodeType.PAGE_FRAGMENT;
|
|
29
|
-
}>();
|
|
30
|
-
|
|
31
|
-
const services = inject<Services>('services');
|
|
32
|
-
const uiService = services?.uiService;
|
|
33
|
-
const editorService = services?.editorService;
|
|
34
|
-
|
|
35
|
-
const showAddPageButton = computed(() => uiService?.get('showAddPageButton'));
|
|
36
|
-
|
|
37
|
-
const addPage = () => {
|
|
38
|
-
if (!editorService) return;
|
|
39
|
-
const root = toRaw(editorService.get('root'));
|
|
40
|
-
if (!root) throw new Error('root 不能为空');
|
|
41
|
-
const pageConfig = {
|
|
42
|
-
type: props.type,
|
|
43
|
-
name: generatePageNameByApp(root, props.type),
|
|
44
|
-
items: [],
|
|
45
|
-
};
|
|
46
|
-
editorService.add(pageConfig);
|
|
47
|
-
};
|
|
48
|
-
</script>
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="m-editor-page-bar-tabs">
|
|
3
|
-
<SwitchTypeButton v-if="!disabledPageFragment" v-model="active" />
|
|
4
|
-
|
|
5
|
-
<PageBarScrollContainer :type="active">
|
|
6
|
-
<template #prepend>
|
|
7
|
-
<AddButton :type="active"></AddButton>
|
|
8
|
-
</template>
|
|
9
|
-
|
|
10
|
-
<div
|
|
11
|
-
v-for="item in list"
|
|
12
|
-
class="m-editor-page-bar-item"
|
|
13
|
-
:key="item.id"
|
|
14
|
-
:class="{ active: page?.id === item.id }"
|
|
15
|
-
@click="switchPage(item.id)"
|
|
16
|
-
>
|
|
17
|
-
<div class="m-editor-page-bar-title">
|
|
18
|
-
<slot name="page-bar-title" :page="item">
|
|
19
|
-
<span :title="item.name">{{ item.name || item.id }}</span>
|
|
20
|
-
</slot>
|
|
21
|
-
</div>
|
|
22
|
-
|
|
23
|
-
<TMagicPopover popper-class="page-bar-popover" placement="top" :width="160" trigger="hover">
|
|
24
|
-
<div>
|
|
25
|
-
<slot name="page-bar-popover" :page="item">
|
|
26
|
-
<ToolButton
|
|
27
|
-
:data="{
|
|
28
|
-
type: 'button',
|
|
29
|
-
text: '复制',
|
|
30
|
-
icon: DocumentCopy,
|
|
31
|
-
handler: () => copy(item),
|
|
32
|
-
}"
|
|
33
|
-
></ToolButton>
|
|
34
|
-
<ToolButton
|
|
35
|
-
:data="{
|
|
36
|
-
type: 'button',
|
|
37
|
-
text: '删除',
|
|
38
|
-
icon: Delete,
|
|
39
|
-
handler: () => remove(item),
|
|
40
|
-
}"
|
|
41
|
-
></ToolButton>
|
|
42
|
-
</slot>
|
|
43
|
-
</div>
|
|
44
|
-
<template #reference>
|
|
45
|
-
<TMagicIcon class="m-editor-page-bar-menu-icon">
|
|
46
|
-
<CaretBottom></CaretBottom>
|
|
47
|
-
</TMagicIcon>
|
|
48
|
-
</template>
|
|
49
|
-
</TMagicPopover>
|
|
50
|
-
</div>
|
|
51
|
-
</PageBarScrollContainer>
|
|
52
|
-
</div>
|
|
53
|
-
</template>
|
|
54
|
-
|
|
55
|
-
<script lang="ts" setup>
|
|
56
|
-
import { computed, inject, ref, watch } from 'vue';
|
|
57
|
-
import { CaretBottom, Delete, DocumentCopy } from '@element-plus/icons-vue';
|
|
58
|
-
|
|
59
|
-
import { TMagicIcon, TMagicPopover } from '@tmagic/design';
|
|
60
|
-
import { Id, type MPage, type MPageFragment, NodeType } from '@tmagic/schema';
|
|
61
|
-
import { isPage, isPageFragment } from '@tmagic/utils';
|
|
62
|
-
|
|
63
|
-
import ToolButton from '@editor/components/ToolButton.vue';
|
|
64
|
-
import type { Services } from '@editor/type';
|
|
65
|
-
import { getPageFragmentList, getPageList } from '@editor/utils';
|
|
66
|
-
|
|
67
|
-
import AddButton from './AddButton.vue';
|
|
68
|
-
import PageBarScrollContainer from './PageBarScrollContainer.vue';
|
|
69
|
-
import SwitchTypeButton from './SwitchTypeButton.vue';
|
|
70
|
-
|
|
71
|
-
defineOptions({
|
|
72
|
-
name: 'MEditorPageBar',
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
defineProps<{
|
|
76
|
-
disabledPageFragment: boolean;
|
|
77
|
-
}>();
|
|
78
|
-
|
|
79
|
-
const active = ref<NodeType.PAGE | NodeType.PAGE_FRAGMENT>(NodeType.PAGE);
|
|
80
|
-
|
|
81
|
-
const services = inject<Services>('services');
|
|
82
|
-
const editorService = services?.editorService;
|
|
83
|
-
|
|
84
|
-
const root = computed(() => editorService?.get('root'));
|
|
85
|
-
const page = computed(() => editorService?.get('page'));
|
|
86
|
-
const pageList = computed(() => getPageList(root.value));
|
|
87
|
-
const pageFragmentList = computed(() => getPageFragmentList(root.value));
|
|
88
|
-
|
|
89
|
-
const list = computed(() => (active.value === NodeType.PAGE ? pageList.value : pageFragmentList.value));
|
|
90
|
-
|
|
91
|
-
const activePage = ref<Id>('');
|
|
92
|
-
const activePageFragment = ref<Id>('');
|
|
93
|
-
|
|
94
|
-
watch(
|
|
95
|
-
page,
|
|
96
|
-
(page) => {
|
|
97
|
-
if (!page) {
|
|
98
|
-
if (active.value === NodeType.PAGE) {
|
|
99
|
-
activePage.value = '';
|
|
100
|
-
}
|
|
101
|
-
if (active.value === NodeType.PAGE_FRAGMENT) {
|
|
102
|
-
activePageFragment.value = '';
|
|
103
|
-
}
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (isPage(page)) {
|
|
108
|
-
activePage.value = page?.id;
|
|
109
|
-
if (active.value !== NodeType.PAGE) {
|
|
110
|
-
active.value = NodeType.PAGE;
|
|
111
|
-
}
|
|
112
|
-
} else if (isPageFragment(page)) {
|
|
113
|
-
activePageFragment.value = page?.id;
|
|
114
|
-
if (active.value !== NodeType.PAGE_FRAGMENT) {
|
|
115
|
-
active.value = NodeType.PAGE_FRAGMENT;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
immediate: true,
|
|
121
|
-
},
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
watch(active, (active) => {
|
|
125
|
-
if (active === NodeType.PAGE) {
|
|
126
|
-
if (!activePage.value && !pageList.value.length) {
|
|
127
|
-
editorService?.selectRoot();
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
switchPage(activePage.value);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (active === NodeType.PAGE_FRAGMENT) {
|
|
135
|
-
// 之前没有选中过页面片并且当前没有页面片
|
|
136
|
-
if (!activePageFragment.value && !pageFragmentList.value.length) {
|
|
137
|
-
editorService?.selectRoot();
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
switchPage(activePageFragment.value || pageFragmentList.value[0].id);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const switchPage = (id: Id) => {
|
|
145
|
-
editorService?.select(id);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const copy = (node: MPage | MPageFragment) => {
|
|
149
|
-
node && editorService?.copy(node);
|
|
150
|
-
editorService?.paste({
|
|
151
|
-
left: 0,
|
|
152
|
-
top: 0,
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const remove = (node: MPage | MPageFragment) => {
|
|
157
|
-
editorService?.remove(node);
|
|
158
|
-
};
|
|
159
|
-
</script>
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="m-editor-page-bar" ref="pageBar">
|
|
3
|
-
<slot name="prepend"></slot>
|
|
4
|
-
|
|
5
|
-
<div v-if="canScroll" class="m-editor-page-bar-item m-editor-page-bar-item-icon" @click="scroll('left')">
|
|
6
|
-
<Icon :icon="ArrowLeftBold"></Icon>
|
|
7
|
-
</div>
|
|
8
|
-
|
|
9
|
-
<div
|
|
10
|
-
v-if="(type === NodeType.PAGE && pageLength) || (type === NodeType.PAGE_FRAGMENT && pageFragmentLength)"
|
|
11
|
-
class="m-editor-page-bar-items"
|
|
12
|
-
ref="itemsContainer"
|
|
13
|
-
:style="`width: ${itemsContainerWidth}px`"
|
|
14
|
-
>
|
|
15
|
-
<slot></slot>
|
|
16
|
-
</div>
|
|
17
|
-
|
|
18
|
-
<div v-if="canScroll" class="m-editor-page-bar-item m-editor-page-bar-item-icon" @click="scroll('right')">
|
|
19
|
-
<Icon :icon="ArrowRightBold"></Icon>
|
|
20
|
-
</div>
|
|
21
|
-
</div>
|
|
22
|
-
</template>
|
|
23
|
-
|
|
24
|
-
<script setup lang="ts">
|
|
25
|
-
import {
|
|
26
|
-
computed,
|
|
27
|
-
type ComputedRef,
|
|
28
|
-
inject,
|
|
29
|
-
nextTick,
|
|
30
|
-
onBeforeUnmount,
|
|
31
|
-
onMounted,
|
|
32
|
-
ref,
|
|
33
|
-
watch,
|
|
34
|
-
type WatchStopHandle,
|
|
35
|
-
} from 'vue';
|
|
36
|
-
import { ArrowLeftBold, ArrowRightBold } from '@element-plus/icons-vue';
|
|
37
|
-
|
|
38
|
-
import { NodeType } from '@tmagic/schema';
|
|
39
|
-
|
|
40
|
-
import Icon from '@editor/components/Icon.vue';
|
|
41
|
-
import type { Services } from '@editor/type';
|
|
42
|
-
|
|
43
|
-
defineOptions({
|
|
44
|
-
name: 'MEditorPageBarScrollContainer',
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const props = defineProps<{
|
|
48
|
-
type: NodeType.PAGE | NodeType.PAGE_FRAGMENT;
|
|
49
|
-
}>();
|
|
50
|
-
|
|
51
|
-
const services = inject<Services>('services');
|
|
52
|
-
const editorService = services?.editorService;
|
|
53
|
-
const uiService = services?.uiService;
|
|
54
|
-
|
|
55
|
-
const itemsContainer = ref<HTMLDivElement>();
|
|
56
|
-
const canScroll = ref(false);
|
|
57
|
-
|
|
58
|
-
const showAddPageButton = computed(() => uiService?.get('showAddPageButton'));
|
|
59
|
-
|
|
60
|
-
const itemsContainerWidth = ref(0);
|
|
61
|
-
|
|
62
|
-
const setCanScroll = () => {
|
|
63
|
-
// 减去新增、左移、右移三个按钮的宽度
|
|
64
|
-
// 37 = icon width 16 + padding 10 * 2 + border-right 1
|
|
65
|
-
itemsContainerWidth.value = (pageBar.value?.clientWidth || 0) - 37 * 2 - (showAddPageButton.value ? 37 : 21);
|
|
66
|
-
|
|
67
|
-
nextTick(() => {
|
|
68
|
-
if (itemsContainer.value) {
|
|
69
|
-
canScroll.value = itemsContainer.value.scrollWidth - itemsContainerWidth.value > 1;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const resizeObserver = new ResizeObserver(() => {
|
|
75
|
-
setCanScroll();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const pageBar = ref<HTMLDivElement>();
|
|
79
|
-
onMounted(() => {
|
|
80
|
-
pageBar.value && resizeObserver.observe(pageBar.value);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
onBeforeUnmount(() => {
|
|
84
|
-
resizeObserver.disconnect();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
let translateLeft = 0;
|
|
88
|
-
|
|
89
|
-
const scroll = (type: 'left' | 'right' | 'start' | 'end') => {
|
|
90
|
-
if (!itemsContainer.value) return;
|
|
91
|
-
|
|
92
|
-
const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
|
|
93
|
-
|
|
94
|
-
if (type === 'left') {
|
|
95
|
-
translateLeft += 100;
|
|
96
|
-
|
|
97
|
-
if (translateLeft > 0) {
|
|
98
|
-
translateLeft = 0;
|
|
99
|
-
}
|
|
100
|
-
} else if (type === 'right') {
|
|
101
|
-
translateLeft -= 100;
|
|
102
|
-
|
|
103
|
-
if (-translateLeft > maxScrollLeft) {
|
|
104
|
-
translateLeft = -maxScrollLeft;
|
|
105
|
-
}
|
|
106
|
-
} else if (type === 'start') {
|
|
107
|
-
translateLeft = 0;
|
|
108
|
-
} else if (type === 'end') {
|
|
109
|
-
translateLeft = -maxScrollLeft;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const pageLength = computed(() => editorService?.get('pageLength') || 0);
|
|
116
|
-
const pageFragmentLength = computed(() => editorService?.get('pageFragmentLength') || 0);
|
|
117
|
-
|
|
118
|
-
const crateWatchLength = (length: ComputedRef<number>) =>
|
|
119
|
-
watch(
|
|
120
|
-
length,
|
|
121
|
-
(length = 0, preLength = 0) => {
|
|
122
|
-
setTimeout(() => {
|
|
123
|
-
setCanScroll();
|
|
124
|
-
if (length < preLength) {
|
|
125
|
-
scroll('start');
|
|
126
|
-
} else {
|
|
127
|
-
scroll('end');
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
immediate: true,
|
|
133
|
-
},
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
let unWatchPageLength: WatchStopHandle | null;
|
|
137
|
-
let unWatchPageFragmentLength: WatchStopHandle | null;
|
|
138
|
-
|
|
139
|
-
watch(
|
|
140
|
-
() => props.type,
|
|
141
|
-
(type) => {
|
|
142
|
-
if (type === NodeType.PAGE) {
|
|
143
|
-
unWatchPageFragmentLength?.();
|
|
144
|
-
unWatchPageFragmentLength = null;
|
|
145
|
-
unWatchPageLength = crateWatchLength(pageLength);
|
|
146
|
-
} else {
|
|
147
|
-
unWatchPageLength?.();
|
|
148
|
-
unWatchPageLength = null;
|
|
149
|
-
unWatchPageFragmentLength = crateWatchLength(pageFragmentLength);
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
immediate: true,
|
|
154
|
-
},
|
|
155
|
-
);
|
|
156
|
-
</script>
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<TMagicButton
|
|
3
|
-
v-for="item in data"
|
|
4
|
-
class="m-editor-page-bar-switch-type-button"
|
|
5
|
-
size="small"
|
|
6
|
-
:key="item.type"
|
|
7
|
-
link
|
|
8
|
-
:class="{ active: modelValue === item.type }"
|
|
9
|
-
:type="modelValue === item.type ? 'primary' : ''"
|
|
10
|
-
@click="clickHandler(item.type)"
|
|
11
|
-
>{{ item.text }}</TMagicButton
|
|
12
|
-
>
|
|
13
|
-
</template>
|
|
14
|
-
|
|
15
|
-
<script setup lang="ts">
|
|
16
|
-
import { TMagicButton } from '@tmagic/design';
|
|
17
|
-
import { NodeType } from '@tmagic/schema';
|
|
18
|
-
|
|
19
|
-
defineOptions({
|
|
20
|
-
name: 'MEditorPageBarSwitchTypeButton',
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
defineProps<{
|
|
24
|
-
modelValue: NodeType.PAGE | NodeType.PAGE_FRAGMENT;
|
|
25
|
-
}>();
|
|
26
|
-
|
|
27
|
-
const data: { type: NodeType.PAGE | NodeType.PAGE_FRAGMENT; text: string }[] = [
|
|
28
|
-
{
|
|
29
|
-
type: NodeType.PAGE,
|
|
30
|
-
text: '页面',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
type: NodeType.PAGE_FRAGMENT,
|
|
34
|
-
text: '页面片',
|
|
35
|
-
},
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
const emit = defineEmits<{
|
|
39
|
-
'update:modelValue': [value: NodeType.PAGE | NodeType.PAGE_FRAGMENT];
|
|
40
|
-
}>();
|
|
41
|
-
|
|
42
|
-
const clickHandler = (value: NodeType.PAGE | NodeType.PAGE_FRAGMENT) => {
|
|
43
|
-
emit('update:modelValue', value);
|
|
44
|
-
};
|
|
45
|
-
</script>
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<TMagicScrollbar>
|
|
3
|
-
<slot name="component-list-panel-header"></slot>
|
|
4
|
-
|
|
5
|
-
<TMagicCollapse class="ui-component-panel" :model-value="collapseValue">
|
|
6
|
-
<SearchInput @search="filterTextChangeHandler"></SearchInput>
|
|
7
|
-
<template v-for="(group, index) in list">
|
|
8
|
-
<TMagicCollapseItem v-if="group.items && group.items.length" :key="index" :name="`${index}`">
|
|
9
|
-
<template #title><MIcon :icon="Grid"></MIcon>{{ group.title }}</template>
|
|
10
|
-
<div
|
|
11
|
-
v-for="item in group.items"
|
|
12
|
-
class="component-item"
|
|
13
|
-
draggable="true"
|
|
14
|
-
:key="item.type"
|
|
15
|
-
@click="appendComponent(item)"
|
|
16
|
-
@dragstart="dragstartHandler(item, $event)"
|
|
17
|
-
@dragend="dragendHandler"
|
|
18
|
-
@drag="dragHandler"
|
|
19
|
-
>
|
|
20
|
-
<slot name="component-list-item" :component="item">
|
|
21
|
-
<TMagicTooltip placement="right" :disabled="!Boolean(item.desc)" :content="item.desc">
|
|
22
|
-
<MIcon :icon="item.icon"></MIcon>
|
|
23
|
-
</TMagicTooltip>
|
|
24
|
-
<span :title="item.text">{{ item.text }}</span>
|
|
25
|
-
</slot>
|
|
26
|
-
</div>
|
|
27
|
-
</TMagicCollapseItem>
|
|
28
|
-
</template>
|
|
29
|
-
</TMagicCollapse>
|
|
30
|
-
</TMagicScrollbar>
|
|
31
|
-
</template>
|
|
32
|
-
|
|
33
|
-
<script lang="ts" setup>
|
|
34
|
-
import { computed, inject, ref } from 'vue';
|
|
35
|
-
import { Grid } from '@element-plus/icons-vue';
|
|
36
|
-
import serialize from 'serialize-javascript';
|
|
37
|
-
|
|
38
|
-
import { TMagicCollapse, TMagicCollapseItem, TMagicScrollbar, TMagicTooltip } from '@tmagic/design';
|
|
39
|
-
import { removeClassNameByClassName } from '@tmagic/utils';
|
|
40
|
-
|
|
41
|
-
import MIcon from '@editor/components/Icon.vue';
|
|
42
|
-
import SearchInput from '@editor/components/SearchInput.vue';
|
|
43
|
-
import {
|
|
44
|
-
type ComponentGroup,
|
|
45
|
-
type ComponentItem,
|
|
46
|
-
ComponentListPanelSlots,
|
|
47
|
-
DragType,
|
|
48
|
-
type Services,
|
|
49
|
-
type StageOptions,
|
|
50
|
-
} from '@editor/type';
|
|
51
|
-
|
|
52
|
-
defineSlots<ComponentListPanelSlots>();
|
|
53
|
-
|
|
54
|
-
defineOptions({
|
|
55
|
-
name: 'MEditorComponentListPanel',
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const searchText = ref('');
|
|
59
|
-
|
|
60
|
-
const filterTextChangeHandler = (v: string) => {
|
|
61
|
-
searchText.value = v;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const services = inject<Services>('services');
|
|
65
|
-
const stageOptions = inject<StageOptions>('stageOptions');
|
|
66
|
-
|
|
67
|
-
const stage = computed(() => services?.editorService.get('stage'));
|
|
68
|
-
const list = computed(() =>
|
|
69
|
-
services?.componentListService.getList().map((group: ComponentGroup) => ({
|
|
70
|
-
...group,
|
|
71
|
-
items: group.items.filter((item: ComponentItem) => item.text.includes(searchText.value)),
|
|
72
|
-
})),
|
|
73
|
-
);
|
|
74
|
-
const collapseValue = computed(() =>
|
|
75
|
-
Array(list.value?.length)
|
|
76
|
-
.fill(1)
|
|
77
|
-
.map((x, i) => `${i}`),
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
let timeout: NodeJS.Timeout | undefined;
|
|
81
|
-
let clientX: number;
|
|
82
|
-
let clientY: number;
|
|
83
|
-
|
|
84
|
-
const appendComponent = ({ text, type, data = {} }: ComponentItem): void => {
|
|
85
|
-
services?.editorService.add({
|
|
86
|
-
name: text,
|
|
87
|
-
type,
|
|
88
|
-
...data,
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const dragstartHandler = ({ text, type, data = {} }: ComponentItem, e: DragEvent) => {
|
|
93
|
-
e.dataTransfer?.setData(
|
|
94
|
-
'text/json',
|
|
95
|
-
serialize({
|
|
96
|
-
dragType: DragType.COMPONENT_LIST,
|
|
97
|
-
data: {
|
|
98
|
-
name: text,
|
|
99
|
-
type,
|
|
100
|
-
...data,
|
|
101
|
-
},
|
|
102
|
-
}),
|
|
103
|
-
);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const dragendHandler = () => {
|
|
107
|
-
if (timeout) {
|
|
108
|
-
globalThis.clearTimeout(timeout);
|
|
109
|
-
timeout = undefined;
|
|
110
|
-
}
|
|
111
|
-
const doc = stage.value?.renderer.getDocument();
|
|
112
|
-
if (doc && stageOptions?.containerHighlightClassName) {
|
|
113
|
-
removeClassNameByClassName(doc, stageOptions.containerHighlightClassName);
|
|
114
|
-
}
|
|
115
|
-
clientX = 0;
|
|
116
|
-
clientY = 0;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const dragHandler = (e: DragEvent) => {
|
|
120
|
-
if (e.clientX !== clientX || e.clientY !== clientY) {
|
|
121
|
-
clientX = e.clientX;
|
|
122
|
-
clientY = e.clientY;
|
|
123
|
-
if (timeout) {
|
|
124
|
-
globalThis.clearTimeout(timeout);
|
|
125
|
-
timeout = undefined;
|
|
126
|
-
}
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (timeout || !stage.value) return;
|
|
131
|
-
|
|
132
|
-
timeout = stage.value.delayedMarkContainer(e);
|
|
133
|
-
};
|
|
134
|
-
</script>
|