@tmagic/editor 1.5.0-beta.1 → 1.5.0-beta.10
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 +276 -3
- package/dist/tmagic-editor.js +268 -218
- package/dist/tmagic-editor.umd.cjs +496 -421
- package/package.json +13 -14
- package/src/Editor.vue +18 -4
- package/src/components/CodeBlockEditor.vue +5 -5
- package/src/components/SearchInput.vue +1 -0
- package/src/components/Tree.vue +10 -2
- package/src/components/TreeNode.vue +4 -2
- package/src/editorProps.ts +6 -3
- package/src/fields/CodeLink.vue +2 -2
- package/src/fields/CodeSelect.vue +1 -1
- package/src/fields/CodeSelectCol.vue +1 -1
- package/src/fields/CondOpSelect.vue +1 -1
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +2 -8
- package/src/fields/DataSourceFieldSelect/Index.vue +2 -2
- package/src/fields/DataSourceFields.vue +1 -1
- package/src/fields/DataSourceInput.vue +4 -4
- package/src/fields/DataSourceMethodSelect.vue +1 -1
- package/src/fields/DataSourceMethods.vue +1 -1
- package/src/fields/DataSourceMocks.vue +1 -1
- package/src/fields/DisplayConds.vue +1 -1
- package/src/fields/EventSelect.vue +4 -4
- package/src/fields/PageFragmentSelect.vue +1 -1
- package/src/fields/UISelect.vue +1 -1
- package/src/hooks/use-code-block-edit.ts +1 -1
- package/src/hooks/use-data-source-edit.ts +1 -1
- package/src/hooks/use-data-source-method.ts +3 -3
- package/src/hooks/use-filter.ts +2 -2
- package/src/hooks/use-node-status.ts +3 -3
- package/src/hooks/use-stage.ts +2 -2
- package/src/index.ts +28 -8
- package/src/initService.ts +17 -10
- package/src/layouts/AddPageBox.vue +1 -1
- package/src/layouts/CodeEditor.vue +5 -5
- package/src/layouts/Framework.vue +2 -2
- package/src/layouts/NavMenu.vue +1 -1
- package/src/layouts/PropsPanel.vue +1 -1
- package/src/layouts/page-bar/AddButton.vue +1 -1
- package/src/layouts/page-bar/PageBar.vue +8 -2
- package/src/layouts/page-bar/PageBarScrollContainer.vue +1 -1
- package/src/layouts/page-bar/PageList.vue +8 -2
- package/src/layouts/page-bar/SwitchTypeButton.vue +1 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +1 -1
- package/src/layouts/sidebar/Sidebar.vue +13 -1
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +11 -3
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +11 -2
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +1 -1
- package/src/layouts/sidebar/data-source/DataSourceList.vue +13 -3
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +19 -2
- package/src/layouts/sidebar/layer/LayerNodeTool.vue +1 -1
- package/src/layouts/sidebar/layer/LayerPanel.vue +5 -1
- package/src/layouts/sidebar/layer/use-click.ts +1 -1
- package/src/layouts/sidebar/layer/use-drag.ts +1 -1
- package/src/layouts/sidebar/layer/use-node-status.ts +3 -4
- package/src/layouts/workspace/Breadcrumb.vue +1 -1
- package/src/layouts/workspace/viewer/NodeListMenu.vue +2 -2
- package/src/layouts/workspace/viewer/Stage.vue +9 -5
- package/src/layouts/workspace/viewer/StageOverlay.vue +9 -4
- package/src/layouts/workspace/viewer/ViewerMenu.vue +1 -1
- package/src/services/codeBlock.ts +7 -7
- package/src/services/dataSource.ts +3 -4
- package/src/services/dep.ts +2 -2
- package/src/services/editor.ts +10 -11
- package/src/services/history.ts +1 -1
- package/src/services/props.ts +3 -3
- package/src/services/stageOverlay.ts +15 -7
- package/src/services/storage.ts +2 -2
- package/src/theme/index.scss +3 -0
- package/src/theme/page-bar.scss +2 -1
- package/src/type.ts +14 -11
- package/src/utils/config.ts +5 -5
- package/src/utils/content-menu.ts +3 -3
- package/src/utils/data-source/index.ts +1 -1
- package/src/utils/editor.ts +13 -35
- package/src/utils/operator.ts +2 -1
- package/src/utils/props.ts +1 -1
- package/src/utils/tree.ts +1 -1
- package/types/index.d.ts +1554 -3130
|
@@ -20,15 +20,15 @@ import { reactive } from 'vue';
|
|
|
20
20
|
import { cloneDeep, get, keys, pick } from 'lodash-es';
|
|
21
21
|
import type { Writable } from 'type-fest';
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
import
|
|
25
|
-
import type {
|
|
23
|
+
import type { CodeBlockContent, CodeBlockDSL, Id, MNode, TargetOptions } from '@tmagic/core';
|
|
24
|
+
import { Target, Watcher } from '@tmagic/core';
|
|
25
|
+
import type { TableColumnConfig } from '@tmagic/form';
|
|
26
26
|
|
|
27
27
|
import editorService from '@editor/services/editor';
|
|
28
28
|
import storageService, { Protocol } from '@editor/services/storage';
|
|
29
29
|
import type { AsyncHookPlugin, CodeState } from '@editor/type';
|
|
30
30
|
import { CODE_DRAFT_STORAGE_KEY } from '@editor/type';
|
|
31
|
-
import {
|
|
31
|
+
import { getEditorConfig } from '@editor/utils/config';
|
|
32
32
|
import { COPY_CODE_STORAGE_KEY } from '@editor/utils/editor';
|
|
33
33
|
|
|
34
34
|
import BaseService from './BaseService';
|
|
@@ -117,7 +117,7 @@ class CodeBlock extends BaseService {
|
|
|
117
117
|
const codeConfigProcessed = cloneDeep(codeConfig);
|
|
118
118
|
if (codeConfigProcessed.content) {
|
|
119
119
|
// 在保存的时候转换代码内容
|
|
120
|
-
const parseDSL =
|
|
120
|
+
const parseDSL = getEditorConfig('parseDSL');
|
|
121
121
|
if (typeof codeConfigProcessed.content === 'string') {
|
|
122
122
|
codeConfigProcessed.content = parseDSL<(...args: any[]) => any>(codeConfigProcessed.content);
|
|
123
123
|
}
|
|
@@ -231,11 +231,11 @@ class CodeBlock extends BaseService {
|
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
public setParamsColConfig(config:
|
|
234
|
+
public setParamsColConfig(config: TableColumnConfig): void {
|
|
235
235
|
this.state.paramsColConfig = config;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
public getParamsColConfig():
|
|
238
|
+
public getParamsColConfig(): TableColumnConfig | undefined {
|
|
239
239
|
return this.state.paramsColConfig;
|
|
240
240
|
}
|
|
241
241
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { reactive } from 'vue';
|
|
2
2
|
import { cloneDeep, get } from 'lodash-es';
|
|
3
|
-
import { Writable } from 'type-fest';
|
|
3
|
+
import type { Writable } from 'type-fest';
|
|
4
4
|
|
|
5
|
-
import type { EventOption } from '@tmagic/core';
|
|
6
|
-
import { Target,
|
|
5
|
+
import type { DataSourceSchema, EventOption, Id, MNode, TargetOptions } from '@tmagic/core';
|
|
6
|
+
import { Target, Watcher } from '@tmagic/core';
|
|
7
7
|
import type { FormConfig } from '@tmagic/form';
|
|
8
|
-
import type { DataSourceSchema, Id, MNode } from '@tmagic/schema';
|
|
9
8
|
import { guid, toLine } from '@tmagic/utils';
|
|
10
9
|
|
|
11
10
|
import editorService from '@editor/services/editor';
|
package/src/services/dep.ts
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { reactive } from 'vue';
|
|
19
19
|
|
|
20
|
-
import {
|
|
21
|
-
import
|
|
20
|
+
import type { DepExtendedData, Id, MNode, Target, TargetNode } from '@tmagic/core';
|
|
21
|
+
import { DepTargetType, Watcher } from '@tmagic/core';
|
|
22
22
|
import { isPage } from '@tmagic/utils';
|
|
23
23
|
|
|
24
24
|
import { IdleTask } from '@editor/utils/idle-task';
|
package/src/services/editor.ts
CHANGED
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
|
|
19
19
|
import { reactive, toRaw } from 'vue';
|
|
20
20
|
import { cloneDeep, get, isObject, mergeWith, uniq } from 'lodash-es';
|
|
21
|
-
import { Writable } from 'type-fest';
|
|
21
|
+
import type { Writable } from 'type-fest';
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
import
|
|
25
|
-
import {
|
|
23
|
+
import type { Id, MApp, MComponent, MContainer, MNode, MPage, MPageFragment, TargetOptions } from '@tmagic/core';
|
|
24
|
+
import { NodeType, Target, Watcher } from '@tmagic/core';
|
|
25
|
+
import { isFixed } from '@tmagic/stage';
|
|
26
26
|
import { calcValueByFontsize, getElById, getNodePath, isNumber, isPage, isPageFragment, isPop } from '@tmagic/utils';
|
|
27
27
|
|
|
28
28
|
import BaseService from '@editor/services//BaseService';
|
|
@@ -48,7 +48,6 @@ import {
|
|
|
48
48
|
getNodeIndex,
|
|
49
49
|
getPageFragmentList,
|
|
50
50
|
getPageList,
|
|
51
|
-
isFixed,
|
|
52
51
|
moveItemsInContainer,
|
|
53
52
|
setChildrenLayout,
|
|
54
53
|
setLayout,
|
|
@@ -234,7 +233,7 @@ class Editor extends BaseService {
|
|
|
234
233
|
* 只有容器拥有布局
|
|
235
234
|
*/
|
|
236
235
|
public async getLayout(parent: MNode, node?: MNode | null): Promise<Layout> {
|
|
237
|
-
if (node && typeof node !== 'function' && isFixed(node)) return Layout.FIXED;
|
|
236
|
+
if (node && typeof node !== 'function' && isFixed(node.style || {})) return Layout.FIXED;
|
|
238
237
|
|
|
239
238
|
if (parent.layout) {
|
|
240
239
|
return parent.layout;
|
|
@@ -267,7 +266,7 @@ class Editor extends BaseService {
|
|
|
267
266
|
|
|
268
267
|
if (node?.id) {
|
|
269
268
|
this.get('stage')
|
|
270
|
-
?.renderer
|
|
269
|
+
?.renderer?.runtime?.getApp?.()
|
|
271
270
|
?.page?.emit(
|
|
272
271
|
'editor:select',
|
|
273
272
|
{
|
|
@@ -737,7 +736,7 @@ class Editor extends BaseService {
|
|
|
737
736
|
|
|
738
737
|
public async doPaste(config: MNode[], position: PastePosition = {}): Promise<MNode[]> {
|
|
739
738
|
propsService.clearRelateId();
|
|
740
|
-
const doc = this.get('stage')?.renderer
|
|
739
|
+
const doc = this.get('stage')?.renderer?.contentWindow?.document;
|
|
741
740
|
const pasteConfigs = beforePaste(position, cloneDeep(config), doc);
|
|
742
741
|
return pasteConfigs;
|
|
743
742
|
}
|
|
@@ -756,7 +755,7 @@ class Editor extends BaseService {
|
|
|
756
755
|
if (!node.style) return config;
|
|
757
756
|
|
|
758
757
|
const stage = this.get('stage');
|
|
759
|
-
const doc = stage?.renderer
|
|
758
|
+
const doc = stage?.renderer?.contentWindow?.document;
|
|
760
759
|
|
|
761
760
|
if (doc) {
|
|
762
761
|
const el = getElById()(doc, node.id);
|
|
@@ -1106,9 +1105,9 @@ class Editor extends BaseService {
|
|
|
1106
1105
|
const newConfig = cloneDeep(dist);
|
|
1107
1106
|
|
|
1108
1107
|
if (!isPop(src) && newConfig.style?.position) {
|
|
1109
|
-
if (isFixed(newConfig) && !isFixed(src)) {
|
|
1108
|
+
if (isFixed(newConfig.style) && !isFixed(src.style || {})) {
|
|
1110
1109
|
newConfig.style = change2Fixed(newConfig, root);
|
|
1111
|
-
} else if (!isFixed(newConfig) && isFixed(src)) {
|
|
1110
|
+
} else if (!isFixed(newConfig.style) && isFixed(src.style || {})) {
|
|
1112
1111
|
newConfig.style = await Fixed2Other(newConfig, root, this.getLayout);
|
|
1113
1112
|
}
|
|
1114
1113
|
}
|
package/src/services/history.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import { reactive } from 'vue';
|
|
20
20
|
|
|
21
|
-
import type { MPage, MPageFragment } from '@tmagic/
|
|
21
|
+
import type { MPage, MPageFragment } from '@tmagic/core';
|
|
22
22
|
|
|
23
23
|
import type { HistoryState, StepValue } from '@editor/type';
|
|
24
24
|
import { UndoRedo } from '@editor/utils/undo-redo';
|
package/src/services/props.ts
CHANGED
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
|
|
19
19
|
import { reactive } from 'vue';
|
|
20
20
|
import { cloneDeep, mergeWith } from 'lodash-es';
|
|
21
|
-
import { Writable } from 'type-fest';
|
|
21
|
+
import type { Writable } from 'type-fest';
|
|
22
22
|
|
|
23
|
-
import {
|
|
23
|
+
import type { Id, MComponent, MNode, TargetOptions } from '@tmagic/core';
|
|
24
|
+
import { Target, Watcher } from '@tmagic/core';
|
|
24
25
|
import type { FormConfig } from '@tmagic/form';
|
|
25
|
-
import type { Id, MComponent, MNode } from '@tmagic/schema';
|
|
26
26
|
import { getNodePath, getValueByKeyPath, guid, setValueByKeyPath, toLine } from '@tmagic/utils';
|
|
27
27
|
|
|
28
28
|
import editorService from '@editor/services/editor';
|
|
@@ -64,6 +64,12 @@ class StageOverlay extends BaseService {
|
|
|
64
64
|
const subStage = this.get('stage');
|
|
65
65
|
const wrapDiv = this.get('wrapDiv');
|
|
66
66
|
subStage?.destroy();
|
|
67
|
+
|
|
68
|
+
for (let i = 0, l = wrapDiv.children.length; i < l; i++) {
|
|
69
|
+
const child = wrapDiv.children[i];
|
|
70
|
+
child.remove();
|
|
71
|
+
}
|
|
72
|
+
|
|
67
73
|
wrapDiv.remove();
|
|
68
74
|
|
|
69
75
|
this.set('stage', null);
|
|
@@ -97,7 +103,7 @@ class StageOverlay extends BaseService {
|
|
|
97
103
|
render: async (stage: StageCore) => {
|
|
98
104
|
this.copyDocumentElement();
|
|
99
105
|
|
|
100
|
-
const rootEls = stage.renderer
|
|
106
|
+
const rootEls = stage.renderer?.getDocument()?.body.children;
|
|
101
107
|
if (rootEls) {
|
|
102
108
|
Array.from(rootEls).forEach((element) => {
|
|
103
109
|
if (['SCRIPT', 'STYLE'].includes(element.tagName)) {
|
|
@@ -135,8 +141,8 @@ class StageOverlay extends BaseService {
|
|
|
135
141
|
const subStage = this.get('stage');
|
|
136
142
|
const stage = editorService.get('stage');
|
|
137
143
|
|
|
138
|
-
const doc = subStage?.renderer
|
|
139
|
-
const documentElement = stage?.renderer
|
|
144
|
+
const doc = subStage?.renderer?.getDocument();
|
|
145
|
+
const documentElement = stage?.renderer?.getDocument()?.documentElement;
|
|
140
146
|
|
|
141
147
|
if (doc && documentElement) {
|
|
142
148
|
doc.replaceChild(documentElement.cloneNode(true), doc.documentElement);
|
|
@@ -160,13 +166,15 @@ class StageOverlay extends BaseService {
|
|
|
160
166
|
background-color: #fff;
|
|
161
167
|
`;
|
|
162
168
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
for (let i = 0, l = wrapDiv.children.length; i < l; i++) {
|
|
170
|
+
const child = wrapDiv.children[i];
|
|
171
|
+
child.remove();
|
|
172
|
+
}
|
|
173
|
+
|
|
166
174
|
wrapDiv.appendChild(contentEl);
|
|
167
175
|
|
|
168
176
|
setTimeout(() => {
|
|
169
|
-
subStage?.renderer
|
|
177
|
+
subStage?.renderer?.contentWindow?.magic.onPageElUpdate(wrapDiv);
|
|
170
178
|
});
|
|
171
179
|
|
|
172
180
|
if (await stageOptions?.canSelect?.(contentEl)) {
|
package/src/services/storage.ts
CHANGED
|
@@ -2,7 +2,7 @@ import serialize from 'serialize-javascript';
|
|
|
2
2
|
import type { Writable } from 'type-fest';
|
|
3
3
|
|
|
4
4
|
import type { SyncHookPlugin } from '@editor/type';
|
|
5
|
-
import {
|
|
5
|
+
import { getEditorConfig } from '@editor/utils/config';
|
|
6
6
|
|
|
7
7
|
import BaseService from './BaseService';
|
|
8
8
|
|
|
@@ -76,7 +76,7 @@ export class WebStorage extends BaseService {
|
|
|
76
76
|
|
|
77
77
|
switch (protocol) {
|
|
78
78
|
case Protocol.OBJECT:
|
|
79
|
-
return
|
|
79
|
+
return getEditorConfig('parseDSL')(`(${item})`);
|
|
80
80
|
case Protocol.JSON:
|
|
81
81
|
return JSON.parse(item);
|
|
82
82
|
case Protocol.NUMBER:
|
package/src/theme/index.scss
CHANGED
package/src/theme/page-bar.scss
CHANGED
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
width: 100%;
|
|
6
6
|
|
|
7
7
|
.tmagic-design-button.m-editor-page-bar-switch-type-button {
|
|
8
|
-
margin-left:
|
|
8
|
+
margin-left: 10px;
|
|
9
9
|
position: relative;
|
|
10
10
|
top: 1px;
|
|
11
11
|
border-radius: 3px 3px 0 0;
|
|
12
12
|
border: 1px solid $--border-color;
|
|
13
13
|
border-bottom: 1px solid transparent;
|
|
14
|
+
padding: 5px 10px;
|
|
14
15
|
|
|
15
16
|
&.active {
|
|
16
17
|
background-color: #f3f3f3;
|
package/src/type.ts
CHANGED
|
@@ -18,10 +18,9 @@
|
|
|
18
18
|
|
|
19
19
|
import type { Component } from 'vue';
|
|
20
20
|
import type EventEmitter from 'events';
|
|
21
|
-
import Sortable, { Options, SortableEvent } from 'sortablejs';
|
|
21
|
+
import Sortable, { type Options, type SortableEvent } from 'sortablejs';
|
|
22
22
|
import type { PascalCasedProperties } from 'type-fest';
|
|
23
23
|
|
|
24
|
-
import type { ChildConfig, ColumnConfig, FilterFunction, FormConfig, FormItem, FormState, Input } from '@tmagic/form';
|
|
25
24
|
import type {
|
|
26
25
|
CodeBlockContent,
|
|
27
26
|
CodeBlockDSL,
|
|
@@ -33,7 +32,16 @@ import type {
|
|
|
33
32
|
MNode,
|
|
34
33
|
MPage,
|
|
35
34
|
MPageFragment,
|
|
36
|
-
} from '@tmagic/
|
|
35
|
+
} from '@tmagic/core';
|
|
36
|
+
import type {
|
|
37
|
+
ChildConfig,
|
|
38
|
+
FilterFunction,
|
|
39
|
+
FormConfig,
|
|
40
|
+
FormItem,
|
|
41
|
+
FormState,
|
|
42
|
+
Input,
|
|
43
|
+
TableColumnConfig,
|
|
44
|
+
} from '@tmagic/form';
|
|
37
45
|
import type StageCore from '@tmagic/stage';
|
|
38
46
|
import type {
|
|
39
47
|
ContainerHighlightType,
|
|
@@ -118,7 +126,7 @@ export type SidebarSlots = LayerPanelSlots & CodeBlockListPanelSlots & Component
|
|
|
118
126
|
export type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> | MNode;
|
|
119
127
|
export type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
|
|
120
128
|
|
|
121
|
-
export interface
|
|
129
|
+
export interface EditorInstallOptions {
|
|
122
130
|
parseDSL: <T = any>(dsl: string) => T;
|
|
123
131
|
[key: string]: any;
|
|
124
132
|
}
|
|
@@ -145,7 +153,7 @@ export interface StageOptions {
|
|
|
145
153
|
containerHighlightDuration?: number;
|
|
146
154
|
containerHighlightType?: ContainerHighlightType;
|
|
147
155
|
disabledDragStart?: boolean;
|
|
148
|
-
render?: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
|
|
156
|
+
render?: (stage: StageCore) => HTMLDivElement | void | Promise<HTMLDivElement | void>;
|
|
149
157
|
moveableOptions?: MoveableOptions | ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions);
|
|
150
158
|
canSelect?: (el: HTMLElement) => boolean | Promise<boolean>;
|
|
151
159
|
isContainer?: (el: HTMLElement) => boolean | Promise<boolean>;
|
|
@@ -445,11 +453,6 @@ export interface ComponentGroup {
|
|
|
445
453
|
items: ComponentItem[];
|
|
446
454
|
}
|
|
447
455
|
|
|
448
|
-
export interface UpdateData {
|
|
449
|
-
id: Id;
|
|
450
|
-
[key: string]: any;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
456
|
export enum LayerOffset {
|
|
454
457
|
TOP = 'top',
|
|
455
458
|
BOTTOM = 'bottom',
|
|
@@ -486,7 +489,7 @@ export type CodeState = {
|
|
|
486
489
|
combineIds: string[];
|
|
487
490
|
/** 为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除) */
|
|
488
491
|
undeletableList: Id[];
|
|
489
|
-
paramsColConfig?:
|
|
492
|
+
paramsColConfig?: TableColumnConfig;
|
|
490
493
|
};
|
|
491
494
|
|
|
492
495
|
export type CodeRelation = {
|
package/src/utils/config.ts
CHANGED
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import { EditorInstallOptions } from '@editor/type';
|
|
20
20
|
|
|
21
|
-
let $TMAGIC_EDITOR:
|
|
21
|
+
let $TMAGIC_EDITOR: EditorInstallOptions = {} as any;
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const setEditorConfig = (option: EditorInstallOptions): void => {
|
|
24
24
|
$TMAGIC_EDITOR = option;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const
|
|
27
|
+
const getEditorConfig = <K extends keyof EditorInstallOptions>(key: K): EditorInstallOptions[K] => $TMAGIC_EDITOR[key];
|
|
28
28
|
|
|
29
|
-
export {
|
|
29
|
+
export { getEditorConfig, setEditorConfig };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { computed, markRaw, Ref } from 'vue';
|
|
2
2
|
import { CopyDocument, Delete, DocumentCopy } from '@element-plus/icons-vue';
|
|
3
3
|
|
|
4
|
-
import { Id, MContainer, NodeType } from '@tmagic/
|
|
4
|
+
import { Id, MContainer, NodeType } from '@tmagic/core';
|
|
5
5
|
import { calcValueByFontsize, isPage, isPageFragment } from '@tmagic/utils';
|
|
6
6
|
|
|
7
7
|
import ContentMenu from '@editor/components/ContentMenu.vue';
|
|
@@ -47,10 +47,10 @@ export const usePasteMenu = (menu?: Ref<InstanceType<typeof ContentMenu> | undef
|
|
|
47
47
|
const rect = menu.value.$el.getBoundingClientRect();
|
|
48
48
|
const parentRect = stage?.container?.getBoundingClientRect();
|
|
49
49
|
const initialLeft =
|
|
50
|
-
calcValueByFontsize(stage?.renderer
|
|
50
|
+
calcValueByFontsize(stage?.renderer?.getDocument(), (rect.left || 0) - (parentRect?.left || 0)) /
|
|
51
51
|
services.uiService.get('zoom');
|
|
52
52
|
const initialTop =
|
|
53
|
-
calcValueByFontsize(stage?.renderer
|
|
53
|
+
calcValueByFontsize(stage?.renderer?.getDocument(), (rect.top || 0) - (parentRect?.top || 0)) /
|
|
54
54
|
services.uiService.get('zoom');
|
|
55
55
|
services?.editorService?.paste({ left: initialLeft, top: initialTop });
|
|
56
56
|
} else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { DataSchema, DataSourceFieldType, DataSourceSchema } from '@tmagic/core';
|
|
1
2
|
import { CascaderOption, FormConfig, FormState } from '@tmagic/form';
|
|
2
|
-
import { DataSchema, DataSourceFieldType, DataSourceSchema } from '@tmagic/schema';
|
|
3
3
|
import {
|
|
4
4
|
DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX,
|
|
5
5
|
dataSourceTemplateRegExp,
|
package/src/utils/editor.ts
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
|
|
19
19
|
import serialize from 'serialize-javascript';
|
|
20
20
|
|
|
21
|
-
import type { Id, MApp, MContainer, MNode, MPage, MPageFragment } from '@tmagic/
|
|
22
|
-
import { NodeType } from '@tmagic/
|
|
21
|
+
import type { Id, MApp, MContainer, MNode, MPage, MPageFragment } from '@tmagic/core';
|
|
22
|
+
import { NodeType } from '@tmagic/core';
|
|
23
23
|
import type StageCore from '@tmagic/stage';
|
|
24
24
|
import { calcValueByFontsize, getElById, getNodePath, isNumber, isPage, isPageFragment, isPop } from '@tmagic/utils';
|
|
25
25
|
|
|
@@ -81,12 +81,6 @@ export const generatePageName = (pageNameList: string[], type: NodeType.PAGE | N
|
|
|
81
81
|
export const generatePageNameByApp = (app: MApp, type: NodeType.PAGE | NodeType.PAGE_FRAGMENT): string =>
|
|
82
82
|
generatePageName(getPageNameList(type === 'page' ? getPageList(app) : getPageFragmentList(app)), type);
|
|
83
83
|
|
|
84
|
-
/**
|
|
85
|
-
* @param {Object} node
|
|
86
|
-
* @returns {boolean}
|
|
87
|
-
*/
|
|
88
|
-
export const isFixed = (node: MNode): boolean => node.style?.position === 'fixed';
|
|
89
|
-
|
|
90
84
|
export const getNodeIndex = (id: Id, parent: MContainer | MApp): number => {
|
|
91
85
|
const items = parent?.items || [];
|
|
92
86
|
return items.findIndex((item: MNode) => `${item.id}` === `${id}`);
|
|
@@ -109,12 +103,16 @@ const getMiddleTop = (node: MNode, parentNode: MNode, stage: StageCore | null) =
|
|
|
109
103
|
}
|
|
110
104
|
|
|
111
105
|
const { height: parentHeight } = parentNode.style;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
|
|
107
|
+
let wrapperHeightDeal = parentHeight;
|
|
108
|
+
if (stage.mask && stage.renderer) {
|
|
109
|
+
// wrapperHeight 是未 calcValue的高度, 所以要将其calcValueByFontsize一下, 否则在pad or pc端计算的结果有误
|
|
110
|
+
const { scrollTop = 0, wrapperHeight } = stage.mask;
|
|
111
|
+
wrapperHeightDeal = calcValueByFontsize(stage.renderer.getDocument()!, wrapperHeight);
|
|
112
|
+
const scrollTopDeal = calcValueByFontsize(stage.renderer.getDocument()!, scrollTop);
|
|
113
|
+
if (isPage(parentNode)) {
|
|
114
|
+
return (wrapperHeightDeal - height) / 2 + scrollTopDeal;
|
|
115
|
+
}
|
|
118
116
|
}
|
|
119
117
|
|
|
120
118
|
// 如果容器的元素高度大于当前视口高度的2倍, 添加的元素居中位置也会看不见, 所以要取最小值计算
|
|
@@ -263,7 +261,7 @@ export const fixNodePosition = (config: MNode, parent: MContainer, stage: StageC
|
|
|
263
261
|
return {
|
|
264
262
|
...(config.style || {}),
|
|
265
263
|
top: getMiddleTop(config, parent, stage),
|
|
266
|
-
left: fixNodeLeft(config, parent, stage?.renderer
|
|
264
|
+
left: fixNodeLeft(config, parent, stage?.renderer?.contentWindow?.document),
|
|
267
265
|
};
|
|
268
266
|
};
|
|
269
267
|
|
|
@@ -274,26 +272,6 @@ export const serializeConfig = (config: any) =>
|
|
|
274
272
|
unsafe: true,
|
|
275
273
|
}).replace(/"(\w+)":\s/g, '$1: ');
|
|
276
274
|
|
|
277
|
-
export interface NodeItem {
|
|
278
|
-
items?: NodeItem[];
|
|
279
|
-
[key: string]: any;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export const traverseNode = <T extends NodeItem = NodeItem>(
|
|
283
|
-
node: T,
|
|
284
|
-
cb: (node: T, parents: T[]) => void,
|
|
285
|
-
parents: T[] = [],
|
|
286
|
-
) => {
|
|
287
|
-
cb(node, parents);
|
|
288
|
-
|
|
289
|
-
if (Array.isArray(node.items) && node.items.length) {
|
|
290
|
-
parents.push(node);
|
|
291
|
-
node.items.forEach((item) => {
|
|
292
|
-
traverseNode(item as T, cb, [...parents]);
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
|
|
297
275
|
export const moveItemsInContainer = (sourceIndices: number[], parent: MContainer, targetIndex: number) => {
|
|
298
276
|
sourceIndices.sort((a, b) => a - b);
|
|
299
277
|
for (let i = sourceIndices.length - 1; i >= 0; i--) {
|
package/src/utils/operator.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { toRaw } from 'vue';
|
|
2
2
|
import { isEmpty } from 'lodash-es';
|
|
3
3
|
|
|
4
|
-
import { Id, MContainer, MNode
|
|
4
|
+
import type { Id, MContainer, MNode } from '@tmagic/core';
|
|
5
|
+
import { NodeType } from '@tmagic/core';
|
|
5
6
|
import { calcValueByFontsize, getElById, isPage, isPageFragment } from '@tmagic/utils';
|
|
6
7
|
|
|
7
8
|
import editorService from '@editor/services/editor';
|
package/src/utils/props.ts
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
import { NODE_CONDS_KEY } from '@tmagic/core';
|
|
20
21
|
import type { FormConfig, FormState, TabPaneConfig } from '@tmagic/form';
|
|
21
|
-
import { NODE_CONDS_KEY } from '@tmagic/schema';
|
|
22
22
|
|
|
23
23
|
export const arrayOptions = [
|
|
24
24
|
{ text: '包含', value: 'include' },
|
package/src/utils/tree.ts
CHANGED