@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,212 +0,0 @@
|
|
|
1
|
-
import { reactive } from 'vue';
|
|
2
|
-
import type { Writable } from 'type-fest';
|
|
3
|
-
|
|
4
|
-
import StageCore from '@tmagic/stage';
|
|
5
|
-
|
|
6
|
-
import { useStage } from '@editor/hooks/use-stage';
|
|
7
|
-
import BaseService from '@editor/services//BaseService';
|
|
8
|
-
import editorService from '@editor/services//editor';
|
|
9
|
-
import type { StageOptions, StageOverlayState, SyncHookPlugin } from '@editor/type';
|
|
10
|
-
|
|
11
|
-
const canUsePluginMethods = {
|
|
12
|
-
async: [],
|
|
13
|
-
sync: ['openOverlay', 'closeOverlay', 'updateOverlay', 'createStage'] as const,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type SyncMethodName = Writable<(typeof canUsePluginMethods)['sync']>;
|
|
17
|
-
|
|
18
|
-
class StageOverlay extends BaseService {
|
|
19
|
-
private state: StageOverlayState = reactive({
|
|
20
|
-
wrapDiv: document.createElement('div'),
|
|
21
|
-
sourceEl: null,
|
|
22
|
-
contentEl: null,
|
|
23
|
-
stage: null,
|
|
24
|
-
stageOptions: null,
|
|
25
|
-
wrapWidth: 0,
|
|
26
|
-
wrapHeight: 0,
|
|
27
|
-
stageOverlayVisible: false,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
constructor() {
|
|
31
|
-
super(canUsePluginMethods.sync.map((methodName) => ({ name: methodName, isAsync: false })));
|
|
32
|
-
|
|
33
|
-
this.get('wrapDiv').classList.add('tmagic-editor-sub-stage-wrap');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public get<K extends keyof StageOverlayState>(name: K): StageOverlayState[K] {
|
|
37
|
-
return this.state[name];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public set<K extends keyof StageOverlayState, T extends StageOverlayState[K]>(name: K, value: T) {
|
|
41
|
-
this.state[name] = value;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public openOverlay(el: HTMLElement | null) {
|
|
45
|
-
const stageOptions = this.get('stageOptions');
|
|
46
|
-
if (!el || !stageOptions) return;
|
|
47
|
-
|
|
48
|
-
this.set('sourceEl', el);
|
|
49
|
-
|
|
50
|
-
this.createContentEl();
|
|
51
|
-
|
|
52
|
-
this.set('stageOverlayVisible', true);
|
|
53
|
-
|
|
54
|
-
editorService.on('update', this.updateHandler);
|
|
55
|
-
editorService.on('add', this.addHandler);
|
|
56
|
-
editorService.on('remove', this.removeHandler);
|
|
57
|
-
editorService.on('drag-to', this.updateHandler);
|
|
58
|
-
editorService.on('move-layer', this.updateHandler);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public closeOverlay() {
|
|
62
|
-
this.set('stageOverlayVisible', false);
|
|
63
|
-
const subStage = this.get('stage');
|
|
64
|
-
const wrapDiv = this.get('wrapDiv');
|
|
65
|
-
subStage?.destroy();
|
|
66
|
-
wrapDiv.remove();
|
|
67
|
-
|
|
68
|
-
this.set('stage', null);
|
|
69
|
-
this.set('sourceEl', null);
|
|
70
|
-
this.set('contentEl', null);
|
|
71
|
-
|
|
72
|
-
editorService.off('update', this.updateHandler);
|
|
73
|
-
editorService.off('add', this.addHandler);
|
|
74
|
-
editorService.off('remove', this.removeHandler);
|
|
75
|
-
editorService.off('drag-to', this.updateHandler);
|
|
76
|
-
editorService.off('move-layer', this.updateHandler);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public updateOverlay() {
|
|
80
|
-
const sourceEl = this.get('sourceEl');
|
|
81
|
-
|
|
82
|
-
if (!sourceEl) return;
|
|
83
|
-
|
|
84
|
-
const { scrollWidth, scrollHeight } = sourceEl;
|
|
85
|
-
|
|
86
|
-
this.set('wrapWidth', scrollWidth);
|
|
87
|
-
this.set('wrapHeight', scrollHeight);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public createStage(stageOptions: StageOptions = {}) {
|
|
91
|
-
return useStage({
|
|
92
|
-
...stageOptions,
|
|
93
|
-
zoom: 1,
|
|
94
|
-
runtimeUrl: '',
|
|
95
|
-
autoScrollIntoView: false,
|
|
96
|
-
render: async (stage: StageCore) => {
|
|
97
|
-
this.copyDocumentElement();
|
|
98
|
-
|
|
99
|
-
const rootEls = stage.renderer.getDocument()?.body.children;
|
|
100
|
-
if (rootEls) {
|
|
101
|
-
Array.from(rootEls).forEach((element) => {
|
|
102
|
-
if (['SCRIPT', 'STYLE'].includes(element.tagName)) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
element.remove();
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const wrapDiv = this.get('wrapDiv');
|
|
110
|
-
|
|
111
|
-
await this.render();
|
|
112
|
-
|
|
113
|
-
return wrapDiv;
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
public usePlugin(options: SyncHookPlugin<SyncMethodName, StageOverlay>): void {
|
|
119
|
-
super.usePlugin(options);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
private createContentEl() {
|
|
123
|
-
const sourceEl = this.get('sourceEl');
|
|
124
|
-
if (!sourceEl) return;
|
|
125
|
-
|
|
126
|
-
const contentEl = sourceEl.cloneNode(true) as HTMLElement;
|
|
127
|
-
this.set('contentEl', contentEl);
|
|
128
|
-
|
|
129
|
-
contentEl.style.position = 'static';
|
|
130
|
-
contentEl.style.overflow = 'visible';
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private copyDocumentElement() {
|
|
134
|
-
const subStage = this.get('stage');
|
|
135
|
-
const stage = editorService.get('stage');
|
|
136
|
-
|
|
137
|
-
const doc = subStage?.renderer.getDocument();
|
|
138
|
-
const documentElement = stage?.renderer.getDocument()?.documentElement;
|
|
139
|
-
|
|
140
|
-
if (doc && documentElement) {
|
|
141
|
-
doc.replaceChild(documentElement.cloneNode(true), doc.documentElement);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private async render() {
|
|
146
|
-
this.createContentEl();
|
|
147
|
-
|
|
148
|
-
const contentEl = this.get('contentEl');
|
|
149
|
-
const sourceEl = this.get('sourceEl');
|
|
150
|
-
const wrapDiv = this.get('wrapDiv');
|
|
151
|
-
const subStage = this.get('stage');
|
|
152
|
-
const stageOptions = this.get('stageOptions');
|
|
153
|
-
|
|
154
|
-
if (!contentEl) return;
|
|
155
|
-
|
|
156
|
-
wrapDiv.style.cssText = `
|
|
157
|
-
width: ${sourceEl?.scrollWidth}px;
|
|
158
|
-
height: ${sourceEl?.scrollHeight}px;
|
|
159
|
-
background-color: #fff;
|
|
160
|
-
`;
|
|
161
|
-
|
|
162
|
-
Array.from(wrapDiv.children).forEach((element) => {
|
|
163
|
-
element.remove();
|
|
164
|
-
});
|
|
165
|
-
wrapDiv.appendChild(contentEl);
|
|
166
|
-
|
|
167
|
-
setTimeout(() => {
|
|
168
|
-
subStage?.renderer.contentWindow?.magic.onPageElUpdate(wrapDiv);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
if (await stageOptions?.canSelect?.(contentEl)) {
|
|
172
|
-
subStage?.select(contentEl.id);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
private updateHandler = () => {
|
|
177
|
-
setTimeout(() => {
|
|
178
|
-
this.render();
|
|
179
|
-
this.updateOverlay();
|
|
180
|
-
|
|
181
|
-
this.updateSelectStatus();
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
private addHandler = () => {
|
|
186
|
-
this.render();
|
|
187
|
-
this.updateOverlay();
|
|
188
|
-
|
|
189
|
-
this.updateSelectStatus();
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
private removeHandler = () => {
|
|
193
|
-
this.render();
|
|
194
|
-
this.updateOverlay();
|
|
195
|
-
|
|
196
|
-
this.updateSelectStatus();
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
private updateSelectStatus() {
|
|
200
|
-
const subStage = this.get('stage');
|
|
201
|
-
const nodes = editorService.get('nodes');
|
|
202
|
-
if (nodes.length > 1) {
|
|
203
|
-
subStage?.multiSelect(nodes.map((n) => n.id));
|
|
204
|
-
} else {
|
|
205
|
-
subStage?.select(nodes[0].id);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export type StageOverlayService = StageOverlay;
|
|
211
|
-
|
|
212
|
-
export default new StageOverlay();
|
package/src/services/storage.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import serialize from 'serialize-javascript';
|
|
2
|
-
import type { Writable } from 'type-fest';
|
|
3
|
-
|
|
4
|
-
import type { SyncHookPlugin } from '@editor/type';
|
|
5
|
-
import { getConfig } from '@editor/utils/config';
|
|
6
|
-
|
|
7
|
-
import BaseService from './BaseService';
|
|
8
|
-
|
|
9
|
-
interface Options {
|
|
10
|
-
namespace?: string;
|
|
11
|
-
protocol?: Protocol;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export enum Protocol {
|
|
15
|
-
OBJECT = 'object',
|
|
16
|
-
JSON = 'json',
|
|
17
|
-
STRING = 'string',
|
|
18
|
-
NUMBER = 'number',
|
|
19
|
-
BOOLEAN = 'boolean',
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const canUsePluginMethods = {
|
|
23
|
-
async: [],
|
|
24
|
-
sync: ['getStorage', 'getNamespace', 'clear', 'getItem', 'removeItem', 'setItem'] as const,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type SyncMethodName = Writable<(typeof canUsePluginMethods)['sync']>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 数据存储服务
|
|
31
|
-
*/
|
|
32
|
-
export class WebStorage extends BaseService {
|
|
33
|
-
private storage: Storage = globalThis.localStorage;
|
|
34
|
-
private namespace = 'tmagic';
|
|
35
|
-
|
|
36
|
-
constructor() {
|
|
37
|
-
super(canUsePluginMethods.sync.map((methodName) => ({ name: methodName, isAsync: false })));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 获取数据存储对象,可以通过
|
|
42
|
-
* const storageService = new StorageService();
|
|
43
|
-
* storageService.usePlugin({
|
|
44
|
-
* // 替换存储对象为 sessionStorage
|
|
45
|
-
* async afterGetStorage(): Promise<Storage> {
|
|
46
|
-
* return window.sessionStorage;
|
|
47
|
-
* },
|
|
48
|
-
* });
|
|
49
|
-
*/
|
|
50
|
-
public getStorage(): Storage {
|
|
51
|
-
return this.storage;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public getNamespace(): string {
|
|
55
|
-
return this.namespace;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 清理,支持storageService.usePlugin
|
|
60
|
-
*/
|
|
61
|
-
public clear(): void {
|
|
62
|
-
const storage = this.getStorage();
|
|
63
|
-
storage.clear();
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* 获取存储项,支持storageService.usePlugin
|
|
67
|
-
*/
|
|
68
|
-
public getItem(key: string, options: Options = {}): any {
|
|
69
|
-
const storage = this.getStorage();
|
|
70
|
-
const namespace = this.getNamespace();
|
|
71
|
-
const { protocol = options.protocol, item } = this.getValueAndProtocol(
|
|
72
|
-
storage.getItem(`${options.namespace || namespace}:${key}`),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
if (item === null) return null;
|
|
76
|
-
|
|
77
|
-
switch (protocol) {
|
|
78
|
-
case Protocol.OBJECT:
|
|
79
|
-
return getConfig('parseDSL')(`(${item})`);
|
|
80
|
-
case Protocol.JSON:
|
|
81
|
-
return JSON.parse(item);
|
|
82
|
-
case Protocol.NUMBER:
|
|
83
|
-
return Number(item);
|
|
84
|
-
case Protocol.BOOLEAN:
|
|
85
|
-
return Boolean(item);
|
|
86
|
-
default:
|
|
87
|
-
return item;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* 获取指定索引位置的key
|
|
92
|
-
*/
|
|
93
|
-
public key(index: number): string | null {
|
|
94
|
-
const storage = this.getStorage();
|
|
95
|
-
return storage.key(index);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* 移除存储项,支持storageService.usePlugin
|
|
100
|
-
*/
|
|
101
|
-
public removeItem(key: string, options: Options = {}): void {
|
|
102
|
-
const storage = this.getStorage();
|
|
103
|
-
const namespace = this.getNamespace();
|
|
104
|
-
storage.removeItem(`${options.namespace || namespace}:${key}`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* 设置存储项,支持storageService.usePlugin
|
|
109
|
-
*/
|
|
110
|
-
public setItem(key: string, value: any, options: Options = {}): void {
|
|
111
|
-
const storage = this.getStorage();
|
|
112
|
-
const namespace = this.getNamespace();
|
|
113
|
-
let item = value;
|
|
114
|
-
const protocol = options.protocol ? `${options.protocol}:` : '';
|
|
115
|
-
if (typeof value === Protocol.STRING || typeof value === Protocol.NUMBER) {
|
|
116
|
-
item = `${protocol}${value}`;
|
|
117
|
-
} else {
|
|
118
|
-
item = `${protocol}${serialize(value)}`;
|
|
119
|
-
}
|
|
120
|
-
storage.setItem(`${options.namespace || namespace}:${key}`, item);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
public destroy() {
|
|
124
|
-
this.removeAllListeners();
|
|
125
|
-
this.removeAllPlugins();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
public usePlugin(options: SyncHookPlugin<SyncMethodName, WebStorage>): void {
|
|
129
|
-
super.usePlugin(options);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private getValueAndProtocol(value: string | null) {
|
|
133
|
-
let protocol = '';
|
|
134
|
-
|
|
135
|
-
if (value === null) {
|
|
136
|
-
return {
|
|
137
|
-
item: value,
|
|
138
|
-
protocol,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const item = value.replace(new RegExp(`^(${Object.values(Protocol).join('|')})(:)(.+)`), (_$0, $1, _$2, $3) => {
|
|
143
|
-
protocol = $1;
|
|
144
|
-
return $3;
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
protocol,
|
|
149
|
-
item,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export type StorageService = WebStorage;
|
|
155
|
-
export default new WebStorage();
|
package/src/services/ui.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
|
-
*
|
|
4
|
-
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { reactive } from 'vue';
|
|
20
|
-
import type { Writable } from 'type-fest';
|
|
21
|
-
|
|
22
|
-
import { convertToNumber } from '@tmagic/utils';
|
|
23
|
-
|
|
24
|
-
import editorService from '@editor/services/editor';
|
|
25
|
-
import type { AsyncHookPlugin, StageRect, UiState } from '@editor/type';
|
|
26
|
-
|
|
27
|
-
import BaseService from './BaseService';
|
|
28
|
-
|
|
29
|
-
const state = reactive<UiState>({
|
|
30
|
-
uiSelectMode: false,
|
|
31
|
-
showSrc: false,
|
|
32
|
-
zoom: 1,
|
|
33
|
-
stageContainerRect: {
|
|
34
|
-
width: 0,
|
|
35
|
-
height: 0,
|
|
36
|
-
},
|
|
37
|
-
stageRect: {
|
|
38
|
-
width: 375,
|
|
39
|
-
height: 817,
|
|
40
|
-
},
|
|
41
|
-
columnWidth: {
|
|
42
|
-
left: 0,
|
|
43
|
-
right: 0,
|
|
44
|
-
center: 0,
|
|
45
|
-
},
|
|
46
|
-
showGuides: true,
|
|
47
|
-
showRule: true,
|
|
48
|
-
propsPanelSize: 'small',
|
|
49
|
-
showAddPageButton: true,
|
|
50
|
-
hideSlideBar: false,
|
|
51
|
-
sideBarItems: [],
|
|
52
|
-
navMenuRect: {
|
|
53
|
-
left: 0,
|
|
54
|
-
top: 0,
|
|
55
|
-
width: 0,
|
|
56
|
-
height: 0,
|
|
57
|
-
},
|
|
58
|
-
frameworkRect: {
|
|
59
|
-
width: 0,
|
|
60
|
-
height: 0,
|
|
61
|
-
left: 0,
|
|
62
|
-
top: 0,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const canUsePluginMethods = {
|
|
67
|
-
async: ['zoom', 'calcZoom'] as const,
|
|
68
|
-
sync: [] as const,
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
type AsyncMethodName = Writable<(typeof canUsePluginMethods)['async']>;
|
|
72
|
-
|
|
73
|
-
class Ui extends BaseService {
|
|
74
|
-
constructor() {
|
|
75
|
-
super(canUsePluginMethods.async.map((methodName) => ({ name: methodName, isAsync: true })));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public set<K extends keyof UiState, T extends UiState[K]>(name: K, value: T) {
|
|
79
|
-
const mask = editorService.get('stage')?.mask;
|
|
80
|
-
|
|
81
|
-
if (name === 'stageRect') {
|
|
82
|
-
this.setStageRect(value as unknown as StageRect);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (name === 'showGuides') {
|
|
87
|
-
mask?.showGuides(value as unknown as boolean);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (name === 'showRule') {
|
|
91
|
-
mask?.showRule(value as unknown as boolean);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
state[name] = value;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public get<K extends keyof UiState>(name: K) {
|
|
98
|
-
return state[name];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
public async zoom(zoom: number) {
|
|
102
|
-
this.set('zoom', (this.get('zoom') * 100 + zoom * 100) / 100);
|
|
103
|
-
if (this.get('zoom') < 0.1) this.set('zoom', 0.1);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
public async calcZoom() {
|
|
107
|
-
const { stageRect, stageContainerRect } = state;
|
|
108
|
-
const { height, width } = stageContainerRect;
|
|
109
|
-
if (!width || !height) return 1;
|
|
110
|
-
|
|
111
|
-
let stageWidth: number = convertToNumber(stageRect.width, width);
|
|
112
|
-
let stageHeight: number = convertToNumber(stageRect.height, height);
|
|
113
|
-
|
|
114
|
-
// 30为标尺的大小
|
|
115
|
-
stageWidth = stageWidth + 30;
|
|
116
|
-
stageHeight = stageHeight + 30;
|
|
117
|
-
|
|
118
|
-
if (width > stageWidth && height > stageHeight) {
|
|
119
|
-
return 1;
|
|
120
|
-
}
|
|
121
|
-
// 60/80是为了不要让画布太过去贴住四周(这样好看些)
|
|
122
|
-
return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public resetState() {
|
|
126
|
-
this.set('showSrc', false);
|
|
127
|
-
this.set('uiSelectMode', false);
|
|
128
|
-
this.set('zoom', 1);
|
|
129
|
-
this.set('stageContainerRect', {
|
|
130
|
-
width: 0,
|
|
131
|
-
height: 0,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
public destroy() {
|
|
136
|
-
this.resetState();
|
|
137
|
-
this.removeAllListeners();
|
|
138
|
-
this.removeAllPlugins();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public usePlugin(options: AsyncHookPlugin<AsyncMethodName, Ui>): void {
|
|
142
|
-
super.usePlugin(options);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private async setStageRect(value: StageRect) {
|
|
146
|
-
state.stageRect = {
|
|
147
|
-
...state.stageRect,
|
|
148
|
-
...value,
|
|
149
|
-
};
|
|
150
|
-
state.zoom = await this.calcZoom();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export type UiService = Ui;
|
|
155
|
-
|
|
156
|
-
export default new Ui();
|
package/src/shims-vue.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
.m-container-vs-code {
|
|
2
|
-
.el-form-item {
|
|
3
|
-
margin-bottom: 0;
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.magic-code-editor {
|
|
8
|
-
width: 100%;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.magic-code-editor-wrapper {
|
|
12
|
-
width: 100%;
|
|
13
|
-
height: 100%;
|
|
14
|
-
position: relative;
|
|
15
|
-
|
|
16
|
-
&.full-screen {
|
|
17
|
-
position: fixed;
|
|
18
|
-
z-index: 10000;
|
|
19
|
-
top: 0;
|
|
20
|
-
left: 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.magic-code-editor-content {
|
|
24
|
-
width: 100%;
|
|
25
|
-
height: 100%;
|
|
26
|
-
|
|
27
|
-
.margin {
|
|
28
|
-
margin: 0;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.magic-code-editor-full-screen-icon {
|
|
33
|
-
position: absolute;
|
|
34
|
-
top: 5px;
|
|
35
|
-
right: 0;
|
|
36
|
-
z-index: 11;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
$--theme-color: #2882e0;
|
|
2
|
-
|
|
3
|
-
$--font-color: #313a40;
|
|
4
|
-
$--border-color: #d9dbdd;
|
|
5
|
-
$--hover-color: #f3f5f9;
|
|
6
|
-
|
|
7
|
-
$--nav-height: 35px;
|
|
8
|
-
$--nav-color: #313a40;
|
|
9
|
-
$--nav--background-color: #ffffff;
|
|
10
|
-
|
|
11
|
-
$--sidebar-heder-background-color: $--theme-color;
|
|
12
|
-
$--sidebar-content-background-color: #ffffff;
|
|
13
|
-
|
|
14
|
-
$--page-bar-height: 32px;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
.ui-component-panel {
|
|
2
|
-
&.tmagic-design-collapse {
|
|
3
|
-
border-top: 0 !important;
|
|
4
|
-
margin-top: 48px;
|
|
5
|
-
background-color: $--sidebar-content-background-color;
|
|
6
|
-
|
|
7
|
-
.tmagic-design-collapse-item {
|
|
8
|
-
> div:first-of-type {
|
|
9
|
-
border-bottom: 1px solid $--border-color;
|
|
10
|
-
margin-bottom: 10px;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.el-collapse-item__header,
|
|
15
|
-
.t-collapse-panel__header {
|
|
16
|
-
background: $--sidebar-content-background-color;
|
|
17
|
-
color: $--font-color;
|
|
18
|
-
height: 25px;
|
|
19
|
-
line-height: 25px;
|
|
20
|
-
padding-left: 10px;
|
|
21
|
-
font-size: 12px;
|
|
22
|
-
|
|
23
|
-
i {
|
|
24
|
-
margin-right: 5px;
|
|
25
|
-
font-size: 14px;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.el-collapse-item__wrap,
|
|
30
|
-
.t-collapse-panel__body {
|
|
31
|
-
background: $--sidebar-content-background-color;
|
|
32
|
-
border-bottom: 0;
|
|
33
|
-
|
|
34
|
-
.el-collapse-item__content,
|
|
35
|
-
.t-collapse-panel__content {
|
|
36
|
-
padding: 10px;
|
|
37
|
-
display: flex;
|
|
38
|
-
flex-wrap: wrap;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.component-item {
|
|
42
|
-
display: flex;
|
|
43
|
-
overflow: hidden;
|
|
44
|
-
text-overflow: ellipsis;
|
|
45
|
-
margin: 5px 10px;
|
|
46
|
-
box-sizing: border-box;
|
|
47
|
-
color: $--font-color;
|
|
48
|
-
flex-direction: column;
|
|
49
|
-
width: 42px;
|
|
50
|
-
cursor: pointer;
|
|
51
|
-
|
|
52
|
-
i {
|
|
53
|
-
font-size: 20px;
|
|
54
|
-
background: #fff;
|
|
55
|
-
height: 40px;
|
|
56
|
-
width: 40px;
|
|
57
|
-
line-height: 40px;
|
|
58
|
-
border-radius: 5px;
|
|
59
|
-
color: #909090;
|
|
60
|
-
border: 1px solid $--border-color;
|
|
61
|
-
display: flex;
|
|
62
|
-
justify-content: space-evenly;
|
|
63
|
-
align-items: center;
|
|
64
|
-
margin-bottom: 5px;
|
|
65
|
-
|
|
66
|
-
&:hover {
|
|
67
|
-
background: #2882e0;
|
|
68
|
-
color: #fff;
|
|
69
|
-
border-color: #4e8be1;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
span {
|
|
74
|
-
font-size: 12px;
|
|
75
|
-
text-align: center;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.el-tooltip {
|
|
79
|
-
width: 50px;
|
|
80
|
-
height: 30px;
|
|
81
|
-
line-height: 15px;
|
|
82
|
-
display: block;
|
|
83
|
-
white-space: normal;
|
|
84
|
-
margin: 0;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
.t-collapse {
|
|
91
|
-
margin-top: 0;
|
|
92
|
-
padding-top: 48px;
|
|
93
|
-
position: relative;
|
|
94
|
-
}
|
|
95
|
-
}
|