@tmagic/editor 1.1.1 → 1.1.2
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 +7 -4
- package/dist/tmagic-editor.mjs +198 -174
- package/dist/tmagic-editor.mjs.map +1 -1
- package/dist/tmagic-editor.umd.js +198 -174
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/package.json +7 -7
- package/src/Editor.vue +4 -0
- package/src/components/Icon.vue +6 -4
- package/src/index.ts +0 -2
- package/src/layouts/sidebar/ComponentListPanel.vue +78 -90
- package/src/layouts/sidebar/Sidebar.vue +4 -0
- package/src/layouts/sidebar/TabPane.vue +12 -0
- package/src/layouts/workspace/PageBar.vue +1 -1
- package/src/layouts/workspace/PageBarScrollContainer.vue +13 -3
- package/src/layouts/workspace/Stage.vue +2 -2
- package/src/services/ui.ts +1 -0
- package/src/theme/component-list-panel.scss +0 -5
- package/src/theme/content-menu.scss +4 -0
- package/src/theme/icon.scss +6 -0
- package/src/theme/index.scss +1 -0
- package/src/type.ts +2 -0
- package/types/Editor.vue.d.ts +1 -1
- package/types/index.d.ts +0 -1
- package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +50 -12
- package/types/services/ui.d.ts +1 -0
- package/types/type.d.ts +2 -0
- package/src/utils/polyfills.ts +0 -8
- package/types/utils/polyfills.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.1.
|
|
2
|
+
"version": "1.1.2",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"dist/*",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/core": "^7.18.0",
|
|
47
47
|
"@element-plus/icons-vue": "^2.0.9",
|
|
48
|
-
"@tmagic/core": "1.1.
|
|
49
|
-
"@tmagic/form": "1.1.
|
|
50
|
-
"@tmagic/schema": "1.1.
|
|
51
|
-
"@tmagic/stage": "1.1.
|
|
52
|
-
"@tmagic/utils": "1.1.
|
|
48
|
+
"@tmagic/core": "1.1.2",
|
|
49
|
+
"@tmagic/form": "1.1.2",
|
|
50
|
+
"@tmagic/schema": "1.1.2",
|
|
51
|
+
"@tmagic/stage": "1.1.2",
|
|
52
|
+
"@tmagic/utils": "1.1.2",
|
|
53
53
|
"buffer": "^6.0.3",
|
|
54
54
|
"color": "^3.1.3",
|
|
55
55
|
"element-plus": "^2.2.6",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vue": "^3.2.37"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@tmagic/form": "1.1.
|
|
65
|
+
"@tmagic/form": "1.1.2",
|
|
66
66
|
"element-plus": "^2.2.6",
|
|
67
67
|
"monaco-editor": "^0.34.0",
|
|
68
68
|
"vue": "^3.2.37"
|
package/src/Editor.vue
CHANGED
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
<template #component-list-panel-header>
|
|
15
15
|
<slot name="component-list-panel-header"></slot>
|
|
16
16
|
</template>
|
|
17
|
+
|
|
18
|
+
<template #component-list-item="{ component }">
|
|
19
|
+
<slot name="component-list-item" :component="component"></slot>
|
|
20
|
+
</template>
|
|
17
21
|
</sidebar>
|
|
18
22
|
</slot>
|
|
19
23
|
</template>
|
package/src/components/Icon.vue
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<el-icon v-if="!icon"><Edit></Edit></el-icon>
|
|
3
|
-
<el-icon v-else-if="typeof icon === 'string' && icon.startsWith('http')"
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
<el-icon v-if="!icon" class="magic-editor-icon"><Edit></Edit></el-icon>
|
|
3
|
+
<el-icon v-else-if="typeof icon === 'string' && icon.startsWith('http')" class="magic-editor-icon"
|
|
4
|
+
><img :src="icon"
|
|
5
|
+
/></el-icon>
|
|
6
|
+
<i v-else-if="typeof icon === 'string'" class="magic-editor-icon" :class="icon"></i>
|
|
7
|
+
<el-icon v-else class="magic-editor-icon"><component :is="toRaw(icon)"></component></el-icon>
|
|
6
8
|
</template>
|
|
7
9
|
|
|
8
10
|
<script lang="ts" setup>
|
package/src/index.ts
CHANGED
|
@@ -24,11 +24,13 @@
|
|
|
24
24
|
@dragend="dragendHandler"
|
|
25
25
|
@drag="dragHandler"
|
|
26
26
|
>
|
|
27
|
-
<
|
|
27
|
+
<slot name="component-list-item" :component="item">
|
|
28
|
+
<MIcon :icon="item.icon"></MIcon>
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
<el-tooltip effect="dark" placement="bottom" :content="item.text">
|
|
31
|
+
<span>{{ item.text }}</span>
|
|
32
|
+
</el-tooltip>
|
|
33
|
+
</slot>
|
|
32
34
|
</div>
|
|
33
35
|
</el-collapse-item>
|
|
34
36
|
</template>
|
|
@@ -36,8 +38,8 @@
|
|
|
36
38
|
</el-scrollbar>
|
|
37
39
|
</template>
|
|
38
40
|
|
|
39
|
-
<script lang="ts">
|
|
40
|
-
import { computed,
|
|
41
|
+
<script lang="ts" setup>
|
|
42
|
+
import { computed, inject, ref } from 'vue';
|
|
41
43
|
import serialize from 'serialize-javascript';
|
|
42
44
|
|
|
43
45
|
import type StageCore from '@tmagic/stage';
|
|
@@ -46,89 +48,75 @@ import { removeClassNameByClassName } from '@tmagic/utils';
|
|
|
46
48
|
import MIcon from '../../components/Icon.vue';
|
|
47
49
|
import type { ComponentGroup, ComponentItem, Services, StageOptions } from '../../type';
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
const searchText = ref('');
|
|
52
|
+
const services = inject<Services>('services');
|
|
53
|
+
const stageOptions = inject<StageOptions>('stageOptions');
|
|
54
|
+
|
|
55
|
+
const stage = computed(() => services?.editorService.get<StageCore>('stage'));
|
|
56
|
+
const list = computed(() =>
|
|
57
|
+
services?.componentListService.getList().map((group: ComponentGroup) => ({
|
|
58
|
+
...group,
|
|
59
|
+
items: group.items.filter((item: ComponentItem) => item.text.includes(searchText.value)),
|
|
60
|
+
})),
|
|
61
|
+
);
|
|
62
|
+
const collapseValue = computed(() =>
|
|
63
|
+
Array(list.value?.length)
|
|
64
|
+
.fill(1)
|
|
65
|
+
.map((x, i) => i),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
let timeout: NodeJS.Timeout | undefined;
|
|
69
|
+
let clientX: number;
|
|
70
|
+
let clientY: number;
|
|
71
|
+
|
|
72
|
+
const appendComponent = ({ text, type, data = {} }: ComponentItem): void => {
|
|
73
|
+
services?.editorService.add({
|
|
74
|
+
name: text,
|
|
75
|
+
type,
|
|
76
|
+
...data,
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const dragstartHandler = ({ text, type, data = {} }: ComponentItem, e: DragEvent) => {
|
|
81
|
+
if (e.dataTransfer) {
|
|
82
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
83
|
+
e.dataTransfer.setData(
|
|
84
|
+
'data',
|
|
85
|
+
serialize({
|
|
86
|
+
name: text,
|
|
87
|
+
type,
|
|
88
|
+
...data,
|
|
89
|
+
}).replace(/"(\w+)":\s/g, '$1: '),
|
|
65
90
|
);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
...data,
|
|
98
|
-
}).replace(/"(\w+)":\s/g, '$1: '),
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
dragendHandler() {
|
|
104
|
-
if (timeout) {
|
|
105
|
-
globalThis.clearTimeout(timeout);
|
|
106
|
-
timeout = undefined;
|
|
107
|
-
}
|
|
108
|
-
const doc = stage.value?.renderer.contentWindow?.document;
|
|
109
|
-
if (doc && stageOptions) {
|
|
110
|
-
removeClassNameByClassName(doc, stageOptions.containerHighlightClassName);
|
|
111
|
-
}
|
|
112
|
-
clientX = 0;
|
|
113
|
-
clientY = 0;
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
dragHandler(e: DragEvent) {
|
|
117
|
-
if (e.clientX !== clientX || e.clientY !== clientY) {
|
|
118
|
-
clientX = e.clientX;
|
|
119
|
-
clientY = e.clientY;
|
|
120
|
-
if (timeout) {
|
|
121
|
-
globalThis.clearTimeout(timeout);
|
|
122
|
-
timeout = undefined;
|
|
123
|
-
}
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (timeout || !stage.value) return;
|
|
128
|
-
|
|
129
|
-
timeout = stage.value.getAddContainerHighlightClassNameTimeout(e);
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const dragendHandler = () => {
|
|
95
|
+
if (timeout) {
|
|
96
|
+
globalThis.clearTimeout(timeout);
|
|
97
|
+
timeout = undefined;
|
|
98
|
+
}
|
|
99
|
+
const doc = stage.value?.renderer.contentWindow?.document;
|
|
100
|
+
if (doc && stageOptions) {
|
|
101
|
+
removeClassNameByClassName(doc, stageOptions.containerHighlightClassName);
|
|
102
|
+
}
|
|
103
|
+
clientX = 0;
|
|
104
|
+
clientY = 0;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const dragHandler = (e: DragEvent) => {
|
|
108
|
+
if (e.clientX !== clientX || e.clientY !== clientY) {
|
|
109
|
+
clientX = e.clientX;
|
|
110
|
+
clientY = e.clientY;
|
|
111
|
+
if (timeout) {
|
|
112
|
+
globalThis.clearTimeout(timeout);
|
|
113
|
+
timeout = undefined;
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (timeout || !stage.value) return;
|
|
119
|
+
|
|
120
|
+
timeout = stage.value.getAddContainerHighlightClassNameTimeout(e);
|
|
121
|
+
};
|
|
134
122
|
</script>
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
<template #component-list-panel-header v-if="item === 'component-list'">
|
|
15
15
|
<slot name="component-list-panel-header"></slot>
|
|
16
16
|
</template>
|
|
17
|
+
|
|
18
|
+
<template #component-list-item="{ component }" v-if="item === 'component-list'">
|
|
19
|
+
<slot name="component-list-item" :component="component"></slot>
|
|
20
|
+
</template>
|
|
17
21
|
</tab-pane>
|
|
18
22
|
</el-tabs>
|
|
19
23
|
</template>
|
|
@@ -13,6 +13,18 @@
|
|
|
13
13
|
<component v-else-if="config.slots?.componentListPanelHeader" :is="config.slots.componentListPanelHeader" />
|
|
14
14
|
</template>
|
|
15
15
|
|
|
16
|
+
<template
|
|
17
|
+
#component-list-item="{ component }"
|
|
18
|
+
v-if="data === 'component-list' || config.slots?.componentListItem"
|
|
19
|
+
>
|
|
20
|
+
<slot v-if="data === 'component-list'" name="component-list-item" :component="component"></slot>
|
|
21
|
+
<component
|
|
22
|
+
v-else-if="config.slots?.componentListItem"
|
|
23
|
+
:is="config.slots.componentListItem"
|
|
24
|
+
:component="component"
|
|
25
|
+
/>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
16
28
|
<template #layer-panel-header v-if="data === 'layer' || config.slots?.layerPanelHeader">
|
|
17
29
|
<slot v-if="data === 'layer'" name="layer-panel-header"></slot>
|
|
18
30
|
<component v-else-if="config.slots?.layerPanelHeader" :is="config.slots.layerPanelHeader" />
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="m-editor-page-bar" ref="pageBar">
|
|
3
|
-
<div
|
|
3
|
+
<div
|
|
4
|
+
v-if="showAddPageButton"
|
|
5
|
+
id="m-editor-page-bar-add-icon"
|
|
6
|
+
class="m-editor-page-bar-item m-editor-page-bar-item-icon"
|
|
7
|
+
@click="addPage"
|
|
8
|
+
>
|
|
4
9
|
<el-icon><plus></plus></el-icon>
|
|
5
10
|
</div>
|
|
11
|
+
<div v-else style="width: 21px"></div>
|
|
6
12
|
<div v-if="canScroll" class="m-editor-page-bar-item m-editor-page-bar-item-icon" @click="scroll('left')">
|
|
7
13
|
<el-icon><arrow-left-bold></arrow-left-bold></el-icon>
|
|
8
14
|
</div>
|
|
@@ -26,13 +32,17 @@ import { generatePageNameByApp } from '../../utils/editor';
|
|
|
26
32
|
|
|
27
33
|
const services = inject<Services>('services');
|
|
28
34
|
const editorService = services?.editorService;
|
|
35
|
+
const uiService = services?.uiService;
|
|
29
36
|
|
|
30
37
|
const pageBar = ref<HTMLDivElement>();
|
|
31
38
|
const itemsContainer = ref<HTMLDivElement>();
|
|
32
39
|
const pageBarWidth = ref(0);
|
|
33
40
|
const canScroll = ref(false);
|
|
34
41
|
|
|
35
|
-
const
|
|
42
|
+
const showAddPageButton = computed(() => uiService?.get('showAddPageButton'));
|
|
43
|
+
|
|
44
|
+
// 减去新增、左移、右移三个按钮的宽度
|
|
45
|
+
const itemsContainerWidth = computed(() => pageBarWidth.value - 35 * 2 - (showAddPageButton.value ? 35 : 21));
|
|
36
46
|
|
|
37
47
|
let translateLeft = 0;
|
|
38
48
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
@@ -46,7 +56,7 @@ const resizeObserver = new ResizeObserver((entries) => {
|
|
|
46
56
|
|
|
47
57
|
const setCanScroll = () => {
|
|
48
58
|
if (itemsContainer.value) {
|
|
49
|
-
canScroll.value = itemsContainer.value.scrollWidth >
|
|
59
|
+
canScroll.value = itemsContainer.value.scrollWidth > itemsContainerWidth.value;
|
|
50
60
|
}
|
|
51
61
|
};
|
|
52
62
|
|
package/src/services/ui.ts
CHANGED
package/src/theme/index.scss
CHANGED
package/src/type.ts
CHANGED
package/types/Editor.vue.d.ts
CHANGED
|
@@ -196,9 +196,9 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
196
196
|
}, {
|
|
197
197
|
menu: MenuBarData;
|
|
198
198
|
codeOptions: Record<string, any>;
|
|
199
|
+
modelValue: MApp;
|
|
199
200
|
layerContentMenu: (MenuButton | MenuComponent)[];
|
|
200
201
|
stageContentMenu: (MenuButton | MenuComponent)[];
|
|
201
|
-
modelValue: MApp;
|
|
202
202
|
componentGroupList: ComponentGroup[];
|
|
203
203
|
autoScrollIntoView: boolean;
|
|
204
204
|
propsConfigs: Record<string, FormConfig>;
|
package/types/index.d.ts
CHANGED
|
@@ -1,14 +1,52 @@
|
|
|
1
1
|
import type { ComponentItem } from '../../type';
|
|
2
|
-
declare const _default:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
declare const _default: {
|
|
3
|
+
new (...args: any[]): {
|
|
4
|
+
$: import("vue").ComponentInternalInstance;
|
|
5
|
+
$data: {};
|
|
6
|
+
$props: Partial<{}> & Omit<Readonly<import("vue").ExtractPropTypes<{}>> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>;
|
|
7
|
+
$attrs: {
|
|
8
|
+
[x: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
$refs: {
|
|
11
|
+
[x: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
$slots: Readonly<{
|
|
14
|
+
[name: string]: import("vue").Slot | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
$root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null;
|
|
17
|
+
$parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null;
|
|
18
|
+
$emit: ((event: string, ...args: any[]) => void) | ((event: string, ...args: any[]) => void);
|
|
19
|
+
$el: any;
|
|
20
|
+
$options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, {}> & {
|
|
21
|
+
beforeCreate?: ((() => void) | (() => void)[]) | undefined;
|
|
22
|
+
created?: ((() => void) | (() => void)[]) | undefined;
|
|
23
|
+
beforeMount?: ((() => void) | (() => void)[]) | undefined;
|
|
24
|
+
mounted?: ((() => void) | (() => void)[]) | undefined;
|
|
25
|
+
beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
|
|
26
|
+
updated?: ((() => void) | (() => void)[]) | undefined;
|
|
27
|
+
activated?: ((() => void) | (() => void)[]) | undefined;
|
|
28
|
+
deactivated?: ((() => void) | (() => void)[]) | undefined;
|
|
29
|
+
beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
|
|
30
|
+
beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
|
|
31
|
+
destroyed?: ((() => void) | (() => void)[]) | undefined;
|
|
32
|
+
unmounted?: ((() => void) | (() => void)[]) | undefined;
|
|
33
|
+
renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
|
|
34
|
+
renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
|
|
35
|
+
errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null, info: string) => boolean | void)[]) | undefined;
|
|
36
|
+
};
|
|
37
|
+
$forceUpdate: () => void;
|
|
38
|
+
$nextTick: typeof import("vue").nextTick;
|
|
39
|
+
$watch(source: string | Function, cb: Function, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
|
|
40
|
+
} & Readonly<import("vue").ExtractPropTypes<{}>> & import("vue").ShallowUnwrapRef<{}> & {} & import("vue").ComponentCustomProperties;
|
|
41
|
+
__isFragment?: undefined;
|
|
42
|
+
__isTeleport?: undefined;
|
|
43
|
+
__isSuspense?: undefined;
|
|
44
|
+
} & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, {}> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
|
45
|
+
$slots: {
|
|
46
|
+
'component-list-panel-header': (_: {}) => any;
|
|
47
|
+
'component-list-item': (_: {
|
|
48
|
+
component: ComponentItem;
|
|
49
|
+
}) => any;
|
|
50
|
+
};
|
|
51
|
+
});
|
|
14
52
|
export default _default;
|
package/types/services/ui.d.ts
CHANGED
package/types/type.d.ts
CHANGED
package/src/utils/polyfills.ts
DELETED
|
File without changes
|