@tmagic/editor 1.5.5 → 1.5.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/style.css +1 -1
- package/dist/tmagic-editor.js +2749 -1870
- package/dist/tmagic-editor.umd.cjs +7728 -1958
- package/package.json +8 -18
- package/src/components/SplitView.vue +16 -7
- package/src/fields/StyleSetter/Index.vue +4 -1
- package/src/fields/StyleSetter/pro/Layout.vue +37 -21
- package/src/fields/StyleSetter/pro/Position.vue +47 -4
- package/src/initService.ts +47 -15
- package/src/layouts/Framework.vue +26 -27
- package/src/layouts/props-panel/PropsPanel.vue +52 -7
- package/src/layouts/props-panel/use-style-panel.ts +12 -1
- package/src/services/dep.ts +17 -0
- package/src/services/ui.ts +8 -2
- package/src/theme/style-setter/layout.scss +1 -1
- package/src/utils/const.ts +5 -0
- package/src/utils/idle-task.ts +1 -0
- package/types/index.d.ts +10435 -2685
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.5.
|
|
2
|
+
"version": "1.5.7",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -58,39 +58,29 @@
|
|
|
58
58
|
"moveable": "^0.53.0",
|
|
59
59
|
"serialize-javascript": "^6.0.0",
|
|
60
60
|
"sortablejs": "^1.15.2",
|
|
61
|
-
"@tmagic/design": "1.5.
|
|
62
|
-
"@tmagic/
|
|
63
|
-
"@tmagic/stage": "1.5.
|
|
64
|
-
"@tmagic/
|
|
65
|
-
"@tmagic/table": "1.5.
|
|
61
|
+
"@tmagic/design": "1.5.7",
|
|
62
|
+
"@tmagic/form": "1.5.7",
|
|
63
|
+
"@tmagic/stage": "1.5.7",
|
|
64
|
+
"@tmagic/utils": "1.5.7",
|
|
65
|
+
"@tmagic/table": "1.5.7"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/events": "^3.0.0",
|
|
69
69
|
"@types/lodash-es": "^4.17.4",
|
|
70
|
-
"@types/node": "^18.19.0",
|
|
71
70
|
"@types/serialize-javascript": "^5.0.1",
|
|
72
71
|
"@types/sortablejs": "^1.15.8",
|
|
73
|
-
"@vitejs/plugin-vue": "^5.2.1",
|
|
74
|
-
"@vue/compiler-sfc": "^3.5.12",
|
|
75
72
|
"@vue/test-utils": "^2.4.6",
|
|
76
|
-
"
|
|
77
|
-
"sass": "^1.83.0",
|
|
78
|
-
"tsc-alias": "^1.8.5",
|
|
79
|
-
"type-fest": "^4.10.3",
|
|
80
|
-
"vite": "^6.0.3"
|
|
73
|
+
"type-fest": "^4.10.3"
|
|
81
74
|
},
|
|
82
75
|
"peerDependencies": {
|
|
83
76
|
"monaco-editor": "^0.48.0",
|
|
84
77
|
"typescript": "*",
|
|
85
78
|
"vue": ">=3.5.0",
|
|
86
|
-
"@tmagic/core": "1.5.
|
|
79
|
+
"@tmagic/core": "1.5.7"
|
|
87
80
|
},
|
|
88
81
|
"peerDependenciesMeta": {
|
|
89
82
|
"typescript": {
|
|
90
83
|
"optional": true
|
|
91
84
|
}
|
|
92
|
-
},
|
|
93
|
-
"scripts": {
|
|
94
|
-
"build": "vite build"
|
|
95
85
|
}
|
|
96
86
|
}
|
|
@@ -45,7 +45,7 @@ const props = withDefaults(
|
|
|
45
45
|
centerClass?: string;
|
|
46
46
|
}>(),
|
|
47
47
|
{
|
|
48
|
-
minLeft:
|
|
48
|
+
minLeft: 1,
|
|
49
49
|
minRight: 1,
|
|
50
50
|
minCenter: 5,
|
|
51
51
|
},
|
|
@@ -65,12 +65,21 @@ const getCenterWidth = (l = 0, r = 0) => {
|
|
|
65
65
|
let center = clientWidth - left - right;
|
|
66
66
|
|
|
67
67
|
if (center < props.minCenter) {
|
|
68
|
+
const diff = props.minCenter - center;
|
|
69
|
+
|
|
68
70
|
center = props.minCenter;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
} else {
|
|
71
|
+
|
|
72
|
+
if (right - diff < props.minRight) {
|
|
72
73
|
right = props.minRight;
|
|
73
|
-
|
|
74
|
+
} else {
|
|
75
|
+
right -= diff;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
left = clientWidth - right - center;
|
|
79
|
+
|
|
80
|
+
if (left < props.minLeft) {
|
|
81
|
+
left -= diff / 2;
|
|
82
|
+
right -= diff / 2;
|
|
74
83
|
}
|
|
75
84
|
}
|
|
76
85
|
return {
|
|
@@ -86,8 +95,8 @@ const widthChange = (width: number) => {
|
|
|
86
95
|
}
|
|
87
96
|
|
|
88
97
|
clientWidth = width;
|
|
89
|
-
let left = props.left || 0;
|
|
90
|
-
let right = props.right || 0;
|
|
98
|
+
let left = props.left || props.minLeft || 0;
|
|
99
|
+
let right = props.right || props.minRight || 0;
|
|
91
100
|
|
|
92
101
|
if (left > clientWidth) {
|
|
93
102
|
left = clientWidth / 3;
|
|
@@ -27,7 +27,7 @@ defineOptions({
|
|
|
27
27
|
name: 'MFieldsStyleSetter',
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
defineProps<FieldProps<StyleSchema>>();
|
|
30
|
+
const props = defineProps<FieldProps<StyleSchema>>();
|
|
31
31
|
|
|
32
32
|
const emit = defineEmits<{
|
|
33
33
|
change: [v: any, eventData: ContainerChangeEventData];
|
|
@@ -64,6 +64,9 @@ const collapseValue = shallowRef(
|
|
|
64
64
|
);
|
|
65
65
|
|
|
66
66
|
const change = (v: any, eventData: ContainerChangeEventData) => {
|
|
67
|
+
eventData.changeRecords?.forEach((record) => {
|
|
68
|
+
record.propPath = `${props.name}.${record.propPath}`;
|
|
69
|
+
});
|
|
67
70
|
emit('change', v, eventData);
|
|
68
71
|
};
|
|
69
72
|
</script>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<MContainer :config="config" :model="values" @change="change"></MContainer>
|
|
3
|
-
<Box :model="values" @change="change"></Box>
|
|
3
|
+
<Box v-show="!['fixed', 'absolute'].includes(values.position)" :model="values" @change="change"></Box>
|
|
4
4
|
</template>
|
|
5
5
|
|
|
6
6
|
<script lang="ts" setup>
|
|
@@ -125,7 +125,7 @@ const config = {
|
|
|
125
125
|
},
|
|
126
126
|
{
|
|
127
127
|
name: 'height',
|
|
128
|
-
text: '
|
|
128
|
+
text: '高度',
|
|
129
129
|
labelWidth: '68px',
|
|
130
130
|
type: 'data-source-field-select',
|
|
131
131
|
fieldConfig: {
|
|
@@ -135,25 +135,41 @@ const config = {
|
|
|
135
135
|
],
|
|
136
136
|
},
|
|
137
137
|
{
|
|
138
|
-
type: '
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
138
|
+
type: 'row',
|
|
139
|
+
items: [
|
|
140
|
+
{
|
|
141
|
+
type: 'data-source-field-select',
|
|
142
|
+
text: 'overflow',
|
|
143
|
+
name: 'overflow',
|
|
144
|
+
labelWidth: '68px',
|
|
145
|
+
checkStrictly: false,
|
|
146
|
+
dataSourceFieldType: ['string'],
|
|
147
|
+
fieldConfig: {
|
|
148
|
+
type: 'select',
|
|
149
|
+
clearable: true,
|
|
150
|
+
allowCreate: true,
|
|
151
|
+
options: [
|
|
152
|
+
{ text: 'visible', value: 'visible' },
|
|
153
|
+
{ text: 'hidden', value: 'hidden' },
|
|
154
|
+
{ text: 'clip', value: 'clip' },
|
|
155
|
+
{ text: 'scroll', value: 'scroll' },
|
|
156
|
+
{ text: 'auto', value: 'auto' },
|
|
157
|
+
{ text: 'overlay', value: 'overlay' },
|
|
158
|
+
{ text: 'initial', value: 'initial' },
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
type: 'data-source-field-select',
|
|
164
|
+
text: '透明度',
|
|
165
|
+
name: 'opacity',
|
|
166
|
+
labelWidth: '68px',
|
|
167
|
+
dataSourceFieldType: ['string', 'number'],
|
|
168
|
+
fieldConfig: {
|
|
169
|
+
type: 'text',
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
],
|
|
157
173
|
},
|
|
158
174
|
],
|
|
159
175
|
};
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<MContainer :config="config" :model="values" @change="change"></MContainer>
|
|
3
|
-
<Position v-show="values['position'] !== 'static'" :model="values" @change="change"></Position>
|
|
4
3
|
</template>
|
|
5
4
|
|
|
6
5
|
<script lang="ts" setup>
|
|
7
6
|
import { ContainerChangeEventData, MContainer } from '@tmagic/form';
|
|
8
7
|
import type { StyleSchema } from '@tmagic/schema';
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
defineProps<{ values: Partial<StyleSchema> }>();
|
|
9
|
+
const props = defineProps<{ values: Partial<StyleSchema> }>();
|
|
13
10
|
|
|
14
11
|
const emit = defineEmits<{
|
|
15
12
|
change: [v: string | StyleSchema, eventData: ContainerChangeEventData];
|
|
@@ -30,6 +27,52 @@ const config = {
|
|
|
30
27
|
})),
|
|
31
28
|
},
|
|
32
29
|
},
|
|
30
|
+
{
|
|
31
|
+
type: 'row',
|
|
32
|
+
labelWidth: '68px',
|
|
33
|
+
display: () => props.values.position !== 'static',
|
|
34
|
+
items: [
|
|
35
|
+
{
|
|
36
|
+
name: 'left',
|
|
37
|
+
type: 'data-source-field-select',
|
|
38
|
+
text: 'left',
|
|
39
|
+
fieldConfig: {
|
|
40
|
+
type: 'text',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'top',
|
|
45
|
+
type: 'data-source-field-select',
|
|
46
|
+
text: 'top',
|
|
47
|
+
fieldConfig: {
|
|
48
|
+
type: 'text',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: 'row',
|
|
55
|
+
labelWidth: '68px',
|
|
56
|
+
display: () => props.values.position !== 'static',
|
|
57
|
+
items: [
|
|
58
|
+
{
|
|
59
|
+
name: 'right',
|
|
60
|
+
type: 'data-source-field-select',
|
|
61
|
+
text: 'right',
|
|
62
|
+
fieldConfig: {
|
|
63
|
+
type: 'text',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'bottom',
|
|
68
|
+
type: 'data-source-field-select',
|
|
69
|
+
text: 'bottom',
|
|
70
|
+
fieldConfig: {
|
|
71
|
+
type: 'text',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
33
76
|
{
|
|
34
77
|
labelWidth: '68px',
|
|
35
78
|
name: 'zIndex',
|
package/src/initService.ts
CHANGED
|
@@ -45,6 +45,7 @@ export const initServiceState = (
|
|
|
45
45
|
codeBlockService,
|
|
46
46
|
keybindingService,
|
|
47
47
|
dataSourceService,
|
|
48
|
+
depService,
|
|
48
49
|
}: Services,
|
|
49
50
|
) => {
|
|
50
51
|
// 初始值变化,重新设置节点信息
|
|
@@ -203,6 +204,7 @@ export const initServiceState = (
|
|
|
203
204
|
componentListService.resetState();
|
|
204
205
|
codeBlockService.resetState();
|
|
205
206
|
keybindingService.reset();
|
|
207
|
+
depService.reset();
|
|
206
208
|
});
|
|
207
209
|
};
|
|
208
210
|
|
|
@@ -265,10 +267,6 @@ export const initServiceEvents = (
|
|
|
265
267
|
if (app.dsl) {
|
|
266
268
|
app.dsl.dataSources = root.dataSources;
|
|
267
269
|
}
|
|
268
|
-
|
|
269
|
-
if (root.dataSources) {
|
|
270
|
-
app.dataSourceManager?.updateSchema(root.dataSources);
|
|
271
|
-
}
|
|
272
270
|
};
|
|
273
271
|
|
|
274
272
|
const dsDepCollectedHandler = async () => {
|
|
@@ -459,13 +457,39 @@ export const initServiceEvents = (
|
|
|
459
457
|
const dataSourceAddHandler = async (config: DataSourceSchema) => {
|
|
460
458
|
initDataSourceDepTarget(config);
|
|
461
459
|
const app = await getTMagicApp();
|
|
462
|
-
|
|
460
|
+
|
|
461
|
+
if (!app?.dataSourceManager) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
app.dataSourceManager.addDataSource(config);
|
|
466
|
+
|
|
467
|
+
const newDs = app.dataSourceManager.get(config.id);
|
|
468
|
+
|
|
469
|
+
if (newDs) {
|
|
470
|
+
app.dataSourceManager.init(newDs);
|
|
471
|
+
}
|
|
463
472
|
};
|
|
464
473
|
|
|
465
474
|
const dataSourceUpdateHandler = async (
|
|
466
475
|
config: DataSourceSchema,
|
|
467
476
|
{ changeRecords }: { changeRecords: ChangeRecord[] },
|
|
468
477
|
) => {
|
|
478
|
+
const updateDsData = async () => {
|
|
479
|
+
const app = await getTMagicApp();
|
|
480
|
+
|
|
481
|
+
if (!app?.dataSourceManager) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const ds = app.dataSourceManager.get(config.id);
|
|
486
|
+
|
|
487
|
+
if (!ds) return;
|
|
488
|
+
|
|
489
|
+
ds.setFields(config.fields);
|
|
490
|
+
ds.setData(config.mocks?.find((mock) => mock.useInEditor)?.data || ds.getDefaultData());
|
|
491
|
+
};
|
|
492
|
+
|
|
469
493
|
let needRecollectDep = false;
|
|
470
494
|
let isModifyField = false;
|
|
471
495
|
let isModifyMock = false;
|
|
@@ -515,12 +539,12 @@ export const initServiceEvents = (
|
|
|
515
539
|
}
|
|
516
540
|
Promise.all(collectIdlePromises).then(() => {
|
|
517
541
|
updateDataSourceSchema();
|
|
542
|
+
updateDsData();
|
|
518
543
|
updateStageNodes(root.items);
|
|
519
544
|
});
|
|
520
545
|
}
|
|
521
546
|
} else if (root?.dataSources) {
|
|
522
|
-
|
|
523
|
-
app?.dataSourceManager?.updateSchema(root.dataSources);
|
|
547
|
+
updateDsData();
|
|
524
548
|
}
|
|
525
549
|
};
|
|
526
550
|
|
|
@@ -530,20 +554,28 @@ export const initServiceEvents = (
|
|
|
530
554
|
depService.removeTarget(id, DepTargetType.DATA_SOURCE_METHOD);
|
|
531
555
|
};
|
|
532
556
|
|
|
533
|
-
const dataSourceRemoveHandler = (id: string) => {
|
|
557
|
+
const dataSourceRemoveHandler = async (id: string) => {
|
|
534
558
|
const root = editorService.get('root');
|
|
535
|
-
const nodeIds = Object.keys(root?.dataSourceDeps?.[id] || {});
|
|
536
|
-
const nodes = getNodes(nodeIds, root?.items);
|
|
537
559
|
|
|
538
|
-
|
|
560
|
+
if (!root) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const nodeIds = Object.keys(root.dataSourceDeps?.[id] || {});
|
|
565
|
+
const nodes = getNodes(nodeIds, root.items);
|
|
566
|
+
|
|
567
|
+
await Promise.all([
|
|
539
568
|
collectIdle(nodes, false, DepTargetType.DATA_SOURCE),
|
|
540
569
|
collectIdle(nodes, false, DepTargetType.DATA_SOURCE_COND),
|
|
541
570
|
collectIdle(nodes, false, DepTargetType.DATA_SOURCE_METHOD),
|
|
542
|
-
])
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
});
|
|
571
|
+
]);
|
|
572
|
+
|
|
573
|
+
updateDataSourceSchema();
|
|
546
574
|
|
|
575
|
+
const app = await getTMagicApp();
|
|
576
|
+
app?.dataSourceManager?.removeDataSource(id);
|
|
577
|
+
|
|
578
|
+
updateStageNodes(nodes);
|
|
547
579
|
removeDataSourceTarget(id);
|
|
548
580
|
};
|
|
549
581
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="m-editor" ref="content" style="min-width:
|
|
2
|
+
<div class="m-editor" ref="content" style="min-width: 900px">
|
|
3
3
|
<slot name="header"></slot>
|
|
4
4
|
|
|
5
5
|
<slot name="nav"></slot>
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
left-class="m-editor-framework-left"
|
|
18
18
|
center-class="m-editor-framework-center"
|
|
19
19
|
right-class="m-editor-framework-right"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
:min-left="
|
|
23
|
-
:min-right="
|
|
24
|
-
:min-center="
|
|
20
|
+
:left="columnWidth.left"
|
|
21
|
+
:right="columnWidth.right"
|
|
22
|
+
:min-left="200"
|
|
23
|
+
:min-right="300"
|
|
24
|
+
:min-center="400"
|
|
25
25
|
:width="frameworkRect?.width || 0"
|
|
26
26
|
@change="columnWidthChange"
|
|
27
27
|
>
|
|
@@ -60,13 +60,18 @@
|
|
|
60
60
|
</template>
|
|
61
61
|
|
|
62
62
|
<script lang="ts" setup>
|
|
63
|
-
import { computed, inject, onBeforeUnmount, onMounted,
|
|
63
|
+
import { computed, inject, onBeforeUnmount, onMounted, useTemplateRef, watch } from 'vue';
|
|
64
64
|
|
|
65
65
|
import type { MPage, MPageFragment } from '@tmagic/core';
|
|
66
66
|
|
|
67
67
|
import SplitView from '@editor/components/SplitView.vue';
|
|
68
68
|
import type { FrameworkSlots, GetColumnWidth, PageBarSortOptions, Services } from '@editor/type';
|
|
69
69
|
import { getEditorConfig } from '@editor/utils/config';
|
|
70
|
+
import {
|
|
71
|
+
DEFAULT_LEFT_COLUMN_WIDTH,
|
|
72
|
+
LEFT_COLUMN_WIDTH_STORAGE_KEY,
|
|
73
|
+
RIGHT_COLUMN_WIDTH_STORAGE_KEY,
|
|
74
|
+
} from '@editor/utils/const';
|
|
70
75
|
|
|
71
76
|
import PageBar from './page-bar/PageBar.vue';
|
|
72
77
|
import AddPageBox from './AddPageBox.vue';
|
|
@@ -84,9 +89,6 @@ defineProps<{
|
|
|
84
89
|
pageFilterFunction?: (page: MPage | MPageFragment, keyword: string) => boolean;
|
|
85
90
|
}>();
|
|
86
91
|
|
|
87
|
-
const DEFAULT_LEFT_COLUMN_WIDTH = 310;
|
|
88
|
-
const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
|
|
89
|
-
|
|
90
92
|
const codeOptions = inject('codeOptions', {});
|
|
91
93
|
const { editorService, uiService } = inject<Services>('services') || {};
|
|
92
94
|
|
|
@@ -99,20 +101,14 @@ const page = computed(() => editorService?.get('page'));
|
|
|
99
101
|
const pageLength = computed(() => editorService?.get('pageLength') || 0);
|
|
100
102
|
const showSrc = computed(() => uiService?.get('showSrc'));
|
|
101
103
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const columnWidth = ref<Partial<GetColumnWidth>>({
|
|
112
|
-
left: getLeftColumnWidthCacheData(),
|
|
113
|
-
center: 0,
|
|
114
|
-
right: getRightColumnWidthCacheData(),
|
|
115
|
-
});
|
|
104
|
+
const columnWidth = computed(
|
|
105
|
+
() =>
|
|
106
|
+
uiService?.get('columnWidth') || {
|
|
107
|
+
left: 0,
|
|
108
|
+
center: 0,
|
|
109
|
+
right: 0,
|
|
110
|
+
},
|
|
111
|
+
);
|
|
116
112
|
|
|
117
113
|
watch(pageLength, () => {
|
|
118
114
|
splitViewRef.value?.updateWidth();
|
|
@@ -121,13 +117,16 @@ watch(pageLength, () => {
|
|
|
121
117
|
watch(
|
|
122
118
|
() => uiService?.get('hideSlideBar'),
|
|
123
119
|
(hideSlideBar) => {
|
|
124
|
-
columnWidth
|
|
120
|
+
uiService?.set('columnWidth', {
|
|
121
|
+
...columnWidth.value,
|
|
122
|
+
left: hideSlideBar
|
|
123
|
+
? 0
|
|
124
|
+
: Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_LEFT_COLUMN_WIDTH,
|
|
125
|
+
});
|
|
125
126
|
},
|
|
126
127
|
);
|
|
127
128
|
|
|
128
129
|
const columnWidthChange = (columnW: GetColumnWidth) => {
|
|
129
|
-
columnWidth.value = columnW;
|
|
130
|
-
|
|
131
130
|
globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${columnW.left}`);
|
|
132
131
|
globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${columnW.right}`);
|
|
133
132
|
uiService?.set('columnWidth', columnW);
|
|
@@ -41,10 +41,9 @@
|
|
|
41
41
|
</FormPanel>
|
|
42
42
|
|
|
43
43
|
<TMagicButton
|
|
44
|
-
v-if="!showStylePanel"
|
|
44
|
+
v-if="showStylePanelToggleButton && !showStylePanel"
|
|
45
45
|
class="m-editor-props-panel-style-icon"
|
|
46
46
|
circle
|
|
47
|
-
:type="showStylePanel ? 'primary' : ''"
|
|
48
47
|
@click="showStylePanelHandler"
|
|
49
48
|
>
|
|
50
49
|
<MIcon :icon="Sugar"></MIcon>
|
|
@@ -53,18 +52,20 @@
|
|
|
53
52
|
</template>
|
|
54
53
|
|
|
55
54
|
<script lang="ts" setup>
|
|
56
|
-
import { computed, inject, onBeforeUnmount, ref, useTemplateRef, watchEffect } from 'vue';
|
|
55
|
+
import { computed, inject, onBeforeUnmount, ref, useTemplateRef, watch, watchEffect } from 'vue';
|
|
57
56
|
import { Close, Sugar } from '@element-plus/icons-vue';
|
|
58
57
|
import type { OnDrag } from 'gesto';
|
|
59
58
|
|
|
60
|
-
import type
|
|
59
|
+
import { type MNode } from '@tmagic/core';
|
|
61
60
|
import { TMagicButton } from '@tmagic/design';
|
|
62
61
|
import type { ContainerChangeEventData, FormState, FormValue } from '@tmagic/form';
|
|
62
|
+
import { setValueByKeyPath } from '@tmagic/utils';
|
|
63
63
|
|
|
64
64
|
import MIcon from '@editor/components/Icon.vue';
|
|
65
65
|
import Resizer from '@editor/components/Resizer.vue';
|
|
66
66
|
import type { PropsPanelSlots, Services } from '@editor/type';
|
|
67
67
|
import { styleTabConfig } from '@editor/utils';
|
|
68
|
+
import { RIGHT_COLUMN_WIDTH_STORAGE_KEY } from '@editor/utils/const';
|
|
68
69
|
|
|
69
70
|
import FormPanel from './FormPanel.vue';
|
|
70
71
|
import { useStylePanel } from './use-style-panel';
|
|
@@ -136,6 +137,12 @@ const submit = async (v: MNode, eventData?: ContainerChangeEventData) => {
|
|
|
136
137
|
newValue.style[key] = value;
|
|
137
138
|
}
|
|
138
139
|
});
|
|
140
|
+
|
|
141
|
+
eventData?.changeRecords?.forEach((record) => {
|
|
142
|
+
if (record.propPath?.startsWith('style') && record.value === '') {
|
|
143
|
+
setValueByKeyPath(record.propPath, record.value, newValue);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
139
146
|
}
|
|
140
147
|
|
|
141
148
|
services?.editorService.update(newValue, { changeRecords: eventData?.changeRecords });
|
|
@@ -156,17 +163,55 @@ const mountedHandler = () => {
|
|
|
156
163
|
|
|
157
164
|
const propsPanelEl = useTemplateRef('propsPanel');
|
|
158
165
|
const widthChange = ({ deltaX }: OnDrag) => {
|
|
159
|
-
if (!propsPanelEl.value) {
|
|
166
|
+
if (!propsPanelEl.value || !services) {
|
|
160
167
|
return;
|
|
161
168
|
}
|
|
162
169
|
|
|
163
170
|
const width = globalThis.parseFloat(
|
|
164
171
|
getComputedStyle(propsPanelEl.value).getPropertyValue('--props-style-panel-width'),
|
|
165
172
|
);
|
|
166
|
-
|
|
173
|
+
|
|
174
|
+
let value = width - deltaX;
|
|
175
|
+
if (value > services.uiService.get('columnWidth').right) {
|
|
176
|
+
value = services.uiService.get('columnWidth').right - 40;
|
|
177
|
+
}
|
|
178
|
+
propsPanelEl.value.style.setProperty('--props-style-panel-width', `${value}px`);
|
|
167
179
|
};
|
|
168
180
|
|
|
169
|
-
const { showStylePanel, showStylePanelHandler, closeStylePanelHandler } =
|
|
181
|
+
const { showStylePanel, showStylePanelToggleButton, showStylePanelHandler, closeStylePanelHandler } =
|
|
182
|
+
useStylePanel(services);
|
|
183
|
+
|
|
184
|
+
watch(showStylePanel, (showStylePanel) => {
|
|
185
|
+
if (!propsPanelEl.value || !services) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const columnWidth = {
|
|
190
|
+
...services.uiService.get('columnWidth'),
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const width = globalThis.parseFloat(
|
|
194
|
+
getComputedStyle(propsPanelEl.value).getPropertyValue('--props-style-panel-width'),
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
if (showStylePanel) {
|
|
198
|
+
columnWidth.right += width;
|
|
199
|
+
columnWidth.center -= width;
|
|
200
|
+
} else {
|
|
201
|
+
columnWidth.right -= width;
|
|
202
|
+
columnWidth.center += width;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (columnWidth.center < 0) {
|
|
206
|
+
columnWidth.right = columnWidth.right + columnWidth.center - 400;
|
|
207
|
+
columnWidth.center = 400;
|
|
208
|
+
|
|
209
|
+
propsPanelEl.value.style.setProperty('--props-style-panel-width', `${columnWidth.right / 2}px`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${columnWidth.right}`);
|
|
213
|
+
services.uiService.set('columnWidth', columnWidth);
|
|
214
|
+
});
|
|
170
215
|
|
|
171
216
|
const propertyFormPanelRef = useTemplateRef<InstanceType<typeof FormPanel>>('propertyFormPanel');
|
|
172
217
|
defineExpose({
|
|
@@ -8,14 +8,24 @@ export const useStylePanel = (services?: Services) => {
|
|
|
8
8
|
const showStylePanelStorageValue = services?.storageService.getItem(showStylePanelStorageKey, {
|
|
9
9
|
protocol: Protocol.BOOLEAN,
|
|
10
10
|
});
|
|
11
|
+
|
|
11
12
|
if (typeof showStylePanelStorageValue === 'boolean') {
|
|
12
13
|
services?.uiService.set('showStylePanel', showStylePanelStorageValue);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
const showStylePanel = computed(
|
|
17
|
+
() => showStylePanelToggleButton.value && (services?.uiService.get('showStylePanel') ?? true),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const showStylePanelToggleButton = computed(
|
|
21
|
+
() => !(services && services.uiService.get('frameworkRect').width < 1280),
|
|
22
|
+
);
|
|
23
|
+
|
|
15
24
|
const showStylePanelHandler = () => {
|
|
16
25
|
services?.uiService.set('showStylePanel', true);
|
|
17
26
|
services?.storageService.setItem(showStylePanelStorageKey, true, { protocol: Protocol.BOOLEAN });
|
|
18
27
|
};
|
|
28
|
+
|
|
19
29
|
const closeStylePanelHandler = () => {
|
|
20
30
|
services?.uiService.set('showStylePanel', false);
|
|
21
31
|
services?.storageService.setItem(showStylePanelStorageKey, false, { protocol: Protocol.BOOLEAN });
|
|
@@ -23,6 +33,7 @@ export const useStylePanel = (services?: Services) => {
|
|
|
23
33
|
|
|
24
34
|
return {
|
|
25
35
|
showStylePanel,
|
|
36
|
+
showStylePanelToggleButton,
|
|
26
37
|
showStylePanelHandler,
|
|
27
38
|
closeStylePanelHandler,
|
|
28
39
|
};
|
package/src/services/dep.ts
CHANGED
|
@@ -176,6 +176,23 @@ class Dep extends BaseService {
|
|
|
176
176
|
return super.once(eventName, listener as any);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
public reset() {
|
|
180
|
+
idleTask.removeAllListeners();
|
|
181
|
+
idleTask.clearTasks();
|
|
182
|
+
|
|
183
|
+
for (const type of Object.keys(this.watcher.getTargetsList())) {
|
|
184
|
+
this.removeTargets(type);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
this.set('collecting', false);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public destroy() {
|
|
191
|
+
this.removeAllListeners();
|
|
192
|
+
this.reset();
|
|
193
|
+
this.removeAllPlugins();
|
|
194
|
+
}
|
|
195
|
+
|
|
179
196
|
public emit<Name extends keyof DepEvents, Param extends DepEvents[Name]>(eventName: Name, ...args: Param) {
|
|
180
197
|
return super.emit(eventName, ...args);
|
|
181
198
|
}
|
package/src/services/ui.ts
CHANGED
|
@@ -23,6 +23,12 @@ import { convertToNumber } from '@tmagic/utils';
|
|
|
23
23
|
|
|
24
24
|
import editorService from '@editor/services/editor';
|
|
25
25
|
import type { AsyncHookPlugin, StageRect, UiState } from '@editor/type';
|
|
26
|
+
import {
|
|
27
|
+
DEFAULT_LEFT_COLUMN_WIDTH,
|
|
28
|
+
DEFAULT_RIGHT_COLUMN_WIDTH,
|
|
29
|
+
LEFT_COLUMN_WIDTH_STORAGE_KEY,
|
|
30
|
+
RIGHT_COLUMN_WIDTH_STORAGE_KEY,
|
|
31
|
+
} from '@editor/utils/const';
|
|
26
32
|
|
|
27
33
|
import BaseService from './BaseService';
|
|
28
34
|
|
|
@@ -40,9 +46,9 @@ const state = shallowReactive<UiState>({
|
|
|
40
46
|
height: 817,
|
|
41
47
|
},
|
|
42
48
|
columnWidth: {
|
|
43
|
-
left:
|
|
44
|
-
right: 0,
|
|
49
|
+
left: Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_LEFT_COLUMN_WIDTH,
|
|
45
50
|
center: 0,
|
|
51
|
+
right: Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_RIGHT_COLUMN_WIDTH,
|
|
46
52
|
},
|
|
47
53
|
showGuides: true,
|
|
48
54
|
showRule: true,
|