@tmagic/editor 1.0.0-rc.12 → 1.0.0-rc.13
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 +35 -5
- package/dist/tmagic-editor.es.js.map +1 -1
- package/dist/tmagic-editor.umd.js +36 -3
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/dist/types/src/type.d.ts +2 -0
- package/dist/types/src/utils/editor.d.ts +1 -0
- package/package.json +7 -7
- package/src/layouts/workspace/Stage.vue +29 -4
- package/src/services/ui.ts +4 -2
- package/src/type.ts +3 -0
- package/src/utils/editor.ts +15 -0
package/dist/types/src/type.d.ts
CHANGED
|
@@ -206,3 +206,5 @@ export declare enum Layout {
|
|
|
206
206
|
export declare enum Keys {
|
|
207
207
|
ESCAPE = "Space"
|
|
208
208
|
}
|
|
209
|
+
export declare const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
|
|
210
|
+
export declare const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
|
|
@@ -37,3 +37,4 @@ export declare const initPosition: (node: MNode, layout: Layout, parentNode: MNo
|
|
|
37
37
|
export declare const setLayout: (node: MNode, layout: Layout) => MNode;
|
|
38
38
|
export declare const change2Fixed: (node: MNode, root: MApp) => MNode;
|
|
39
39
|
export declare const Fixed2Other: (node: MNode, root: MApp, getLayout: (parent: MNode, node?: MNode | undefined) => Promise<Layout>) => Promise<MNode>;
|
|
40
|
+
export declare const getGuideLineFromCache: (key: string) => number[];
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-rc.
|
|
2
|
+
"version": "1.0.0-rc.13",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"dist/*",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/core": "^7.18.0",
|
|
45
45
|
"@element-plus/icons": "0.0.11",
|
|
46
|
-
"@tmagic/core": "1.0.0-rc.
|
|
47
|
-
"@tmagic/form": "1.0.0-rc.
|
|
48
|
-
"@tmagic/schema": "1.0.0-rc.
|
|
49
|
-
"@tmagic/stage": "1.0.0-rc.
|
|
50
|
-
"@tmagic/utils": "1.0.0-rc.
|
|
46
|
+
"@tmagic/core": "1.0.0-rc.13",
|
|
47
|
+
"@tmagic/form": "1.0.0-rc.13",
|
|
48
|
+
"@tmagic/schema": "1.0.0-rc.13",
|
|
49
|
+
"@tmagic/stage": "1.0.0-rc.13",
|
|
50
|
+
"@tmagic/utils": "1.0.0-rc.13",
|
|
51
51
|
"buffer": "^6.0.3",
|
|
52
52
|
"color": "^3.1.3",
|
|
53
53
|
"element-plus": "^2.2.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"vue": "^3.2.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@tmagic/form": "1.0.0-rc.
|
|
63
|
+
"@tmagic/form": "1.0.0-rc.13",
|
|
64
64
|
"element-plus": "^2.2.0",
|
|
65
65
|
"monaco-editor": "^0.32.1",
|
|
66
66
|
"vue": "^3.2.0"
|
|
@@ -36,11 +36,18 @@ import {
|
|
|
36
36
|
import { cloneDeep } from 'lodash-es';
|
|
37
37
|
|
|
38
38
|
import type { MApp, MNode, MPage } from '@tmagic/schema';
|
|
39
|
-
import
|
|
40
|
-
import StageCore from '@tmagic/stage';
|
|
39
|
+
import StageCore, { GuidesType, Runtime, SortEventData, UpdateEventData } from '@tmagic/stage';
|
|
41
40
|
|
|
42
41
|
import ScrollViewer from '@editor/components/ScrollViewer.vue';
|
|
43
|
-
import {
|
|
42
|
+
import {
|
|
43
|
+
H_GUIDE_LINE_STORAGE_KEY,
|
|
44
|
+
Layout,
|
|
45
|
+
Services,
|
|
46
|
+
StageOptions,
|
|
47
|
+
StageRect,
|
|
48
|
+
V_GUIDE_LINE_STORAGE_KEY,
|
|
49
|
+
} from '@editor/type';
|
|
50
|
+
import { getGuideLineFromCache } from '@editor/utils';
|
|
44
51
|
|
|
45
52
|
import ViewerMenu from './ViewerMenu.vue';
|
|
46
53
|
|
|
@@ -70,6 +77,8 @@ export default defineComponent({
|
|
|
70
77
|
let stage: StageCore | null = null;
|
|
71
78
|
let runtime: Runtime | null = null;
|
|
72
79
|
|
|
80
|
+
const getGuideLineKey = (key: string) => `${key}_${root.value?.id}_${page.value?.id}`;
|
|
81
|
+
|
|
73
82
|
watchEffect(() => {
|
|
74
83
|
if (stage) return;
|
|
75
84
|
|
|
@@ -99,6 +108,11 @@ export default defineComponent({
|
|
|
99
108
|
|
|
100
109
|
stage?.mount(stageContainer.value);
|
|
101
110
|
|
|
111
|
+
stage.mask.setGuides([
|
|
112
|
+
getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
|
|
113
|
+
getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY)),
|
|
114
|
+
]);
|
|
115
|
+
|
|
102
116
|
stage?.on('select', (el: HTMLElement) => {
|
|
103
117
|
services?.editorService.select(el.id);
|
|
104
118
|
});
|
|
@@ -115,8 +129,19 @@ export default defineComponent({
|
|
|
115
129
|
services?.editorService.sort(ev.src, ev.dist);
|
|
116
130
|
});
|
|
117
131
|
|
|
118
|
-
stage?.on('changeGuides', () => {
|
|
132
|
+
stage?.on('changeGuides', (e) => {
|
|
119
133
|
services?.uiService.set('showGuides', true);
|
|
134
|
+
|
|
135
|
+
if (!root.value || !page.value) return;
|
|
136
|
+
|
|
137
|
+
const storageKey = getGuideLineKey(
|
|
138
|
+
e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY,
|
|
139
|
+
);
|
|
140
|
+
if (e.guides.length) {
|
|
141
|
+
globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
|
|
142
|
+
} else {
|
|
143
|
+
globalThis.localStorage.removeItem(storageKey);
|
|
144
|
+
}
|
|
120
145
|
});
|
|
121
146
|
|
|
122
147
|
if (!node.value?.id) return;
|
package/src/services/ui.ts
CHANGED
|
@@ -26,7 +26,9 @@ import type { GetColumnWidth, SetColumnWidth, StageRect, UiState } from '@editor
|
|
|
26
26
|
import BaseService from './BaseService';
|
|
27
27
|
|
|
28
28
|
const DEFAULT_LEFT_COLUMN_WIDTH = 310;
|
|
29
|
+
const MIN_LEFT_COLUMN_WIDTH = 45;
|
|
29
30
|
const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
|
|
31
|
+
const MIN_RIGHT_COLUMN_WIDTH = 1;
|
|
30
32
|
|
|
31
33
|
const COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorColumnWidthData';
|
|
32
34
|
|
|
@@ -117,11 +119,11 @@ class Ui extends BaseService {
|
|
|
117
119
|
};
|
|
118
120
|
|
|
119
121
|
if (left) {
|
|
120
|
-
columnWidth.left = left;
|
|
122
|
+
columnWidth.left = Math.max(left, MIN_LEFT_COLUMN_WIDTH);
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
if (right) {
|
|
124
|
-
columnWidth.right = right;
|
|
126
|
+
columnWidth.right = Math.max(right, MIN_RIGHT_COLUMN_WIDTH);
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
if (!center || center === 'auto') {
|
package/src/type.ts
CHANGED
package/src/utils/editor.ts
CHANGED
|
@@ -204,3 +204,18 @@ export const Fixed2Other = async (
|
|
|
204
204
|
|
|
205
205
|
return toRelative(node);
|
|
206
206
|
};
|
|
207
|
+
|
|
208
|
+
export const getGuideLineFromCache = (key: string): number[] => {
|
|
209
|
+
if (!key) return [];
|
|
210
|
+
|
|
211
|
+
const guideLineCacheData = globalThis.localStorage.getItem(key);
|
|
212
|
+
if (guideLineCacheData) {
|
|
213
|
+
try {
|
|
214
|
+
return JSON.parse(guideLineCacheData) || [];
|
|
215
|
+
} catch (e) {
|
|
216
|
+
console.error(e);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return [];
|
|
221
|
+
};
|