@tmagic/editor 1.4.16 → 1.5.0-beta.0
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 +2 -2
- package/dist/tmagic-editor.js +274 -265
- package/dist/tmagic-editor.umd.cjs +275 -262
- package/package.json +11 -15
- package/src/components/CodeParams.vue +1 -1
- package/src/editorProps.ts +2 -1
- package/src/fields/DataSourceInput.vue +2 -2
- package/src/fields/UISelect.vue +20 -15
- package/src/hooks/use-stage.ts +13 -7
- package/src/initService.ts +50 -53
- package/src/layouts/workspace/viewer/NodeListMenu.vue +2 -1
- package/src/layouts/workspace/viewer/Stage.vue +4 -3
- package/src/services/editor.ts +2 -2
- package/src/services/stageOverlay.ts +3 -1
- package/src/theme/page-bar.scss +2 -2
- package/src/utils/data-source/index.ts +25 -23
- package/src/utils/editor.ts +4 -3
- package/src/utils/index.ts +4 -0
- package/src/utils/operator.ts +3 -2
- package/src/utils/props.ts +2 -1
- package/types/index.d.ts +6484 -49
- package/src/shims-vue.d.ts +0 -6
- package/types/Editor.vue.d.ts +0 -2313
- package/types/components/CodeBlockEditor.vue.d.ts +0 -33
- package/types/components/CodeParams.vue.d.ts +0 -28
- package/types/components/ContentMenu.vue.d.ts +0 -81
- package/types/components/FloatingBox.vue.d.ts +0 -70
- package/types/components/Icon.vue.d.ts +0 -15
- package/types/components/Resizer.vue.d.ts +0 -16
- package/types/components/ScrollBar.vue.d.ts +0 -25
- package/types/components/ScrollViewer.vue.d.ts +0 -81
- package/types/components/SearchInput.vue.d.ts +0 -6
- package/types/components/SplitView.vue.d.ts +0 -72
- package/types/components/ToolButton.vue.d.ts +0 -41
- package/types/components/Tree.vue.d.ts +0 -83
- package/types/components/TreeNode.vue.d.ts +0 -83
- package/types/editorProps.d.ts +0 -111
- package/types/fields/Code.vue.d.ts +0 -44
- package/types/fields/CodeLink.vue.d.ts +0 -24
- package/types/fields/CodeSelect.vue.d.ts +0 -28
- package/types/fields/CodeSelectCol.vue.d.ts +0 -31
- package/types/fields/CondOpSelect.vue.d.ts +0 -17
- package/types/fields/DataSourceFieldSelect/FieldSelect.vue.d.ts +0 -36
- package/types/fields/DataSourceFieldSelect/Index.vue.d.ts +0 -31
- package/types/fields/DataSourceFields.vue.d.ts +0 -44
- package/types/fields/DataSourceInput.vue.d.ts +0 -34
- package/types/fields/DataSourceMethodSelect.vue.d.ts +0 -31
- package/types/fields/DataSourceMethods.vue.d.ts +0 -34
- package/types/fields/DataSourceMocks.vue.d.ts +0 -41
- package/types/fields/DataSourceSelect.vue.d.ts +0 -31
- package/types/fields/DisplayConds.vue.d.ts +0 -37
- package/types/fields/EventSelect.vue.d.ts +0 -17
- package/types/fields/KeyValue.vue.d.ts +0 -36
- package/types/fields/PageFragmentSelect.vue.d.ts +0 -31
- package/types/fields/UISelect.vue.d.ts +0 -20
- package/types/hooks/index.d.ts +0 -6
- package/types/hooks/use-code-block-edit.d.ts +0 -189
- package/types/hooks/use-data-source-edit.d.ts +0 -176
- package/types/hooks/use-data-source-method.d.ts +0 -187
- package/types/hooks/use-editor-content-height.d.ts +0 -3
- package/types/hooks/use-filter.d.ts +0 -7
- package/types/hooks/use-float-box.d.ts +0 -17
- package/types/hooks/use-getso.d.ts +0 -5
- package/types/hooks/use-next-float-box-position.d.ts +0 -15
- package/types/hooks/use-node-status.d.ts +0 -16
- package/types/hooks/use-stage.d.ts +0 -3
- package/types/hooks/use-window-rect.d.ts +0 -6
- package/types/icons/AppManageIcon.vue.d.ts +0 -2
- package/types/icons/CenterIcon.vue.d.ts +0 -2
- package/types/icons/CodeIcon.vue.d.ts +0 -2
- package/types/icons/FolderMinusIcon.vue.d.ts +0 -2
- package/types/icons/PinIcon.vue.d.ts +0 -2
- package/types/icons/PinnedIcon.vue.d.ts +0 -2
- package/types/initService.d.ts +0 -9
- package/types/layouts/AddPageBox.vue.d.ts +0 -15
- package/types/layouts/CodeEditor.vue.d.ts +0 -80
- package/types/layouts/Framework.vue.d.ts +0 -25
- package/types/layouts/NavMenu.vue.d.ts +0 -35
- package/types/layouts/PropsPanel.vue.d.ts +0 -535
- package/types/layouts/page-bar/AddButton.vue.d.ts +0 -16
- package/types/layouts/page-bar/PageBar.vue.d.ts +0 -36
- package/types/layouts/page-bar/PageBarScrollContainer.vue.d.ts +0 -29
- package/types/layouts/page-bar/PageList.vue.d.ts +0 -27
- package/types/layouts/page-bar/SwitchTypeButton.vue.d.ts +0 -20
- package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +0 -10
- package/types/layouts/sidebar/Sidebar.vue.d.ts +0 -51
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +0 -32
- package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +0 -24
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +0 -31
- package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +0 -18
- package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +0 -10
- package/types/layouts/sidebar/layer/LayerMenu.vue.d.ts +0 -41
- package/types/layouts/sidebar/layer/LayerNodeTool.vue.d.ts +0 -16
- package/types/layouts/sidebar/layer/LayerPanel.vue.d.ts +0 -25
- package/types/layouts/sidebar/layer/use-click.d.ts +0 -119
- package/types/layouts/sidebar/layer/use-drag.d.ts +0 -14
- package/types/layouts/sidebar/layer/use-keybinding.d.ts +0 -6
- package/types/layouts/sidebar/layer/use-node-status.d.ts +0 -16
- package/types/layouts/workspace/Breadcrumb.vue.d.ts +0 -2
- package/types/layouts/workspace/Workspace.vue.d.ts +0 -41
- package/types/layouts/workspace/viewer/NodeListMenu.vue.d.ts +0 -2
- package/types/layouts/workspace/viewer/Stage.vue.d.ts +0 -34
- package/types/layouts/workspace/viewer/StageOverlay.vue.d.ts +0 -2
- package/types/layouts/workspace/viewer/ViewerMenu.vue.d.ts +0 -42
- package/types/services/BaseService.d.ts +0 -65
- package/types/services/codeBlock.d.ts +0 -130
- package/types/services/componentList.d.ts +0 -16
- package/types/services/dataSource.d.ts +0 -68
- package/types/services/dep.d.ts +0 -33
- package/types/services/editor.d.ts +0 -180
- package/types/services/events.d.ts +0 -18
- package/types/services/history.d.ts +0 -26
- package/types/services/keybinding.d.ts +0 -40
- package/types/services/props.d.ts +0 -92
- package/types/services/stageOverlay.d.ts +0 -30
- package/types/services/storage.d.ts +0 -65
- package/types/services/ui.d.ts +0 -77
- package/types/type.d.ts +0 -657
- package/types/utils/compose.d.ts +0 -5
- package/types/utils/config.d.ts +0 -4
- package/types/utils/content-menu.d.ts +0 -7
- package/types/utils/data-source/formConfigs/base.d.ts +0 -2
- package/types/utils/data-source/formConfigs/http.d.ts +0 -3
- package/types/utils/data-source/index.d.ts +0 -10
- package/types/utils/editor.d.ts +0 -59
- package/types/utils/idle-task.d.ts +0 -13
- package/types/utils/index.d.ts +0 -6
- package/types/utils/keybinding-config.d.ts +0 -7
- package/types/utils/logger.d.ts +0 -5
- package/types/utils/monaco-editor.d.ts +0 -2
- package/types/utils/operator.d.ts +0 -21
- package/types/utils/props.d.ts +0 -23
- package/types/utils/scroll-viewer.d.ts +0 -37
- package/types/utils/tree.d.ts +0 -3
- package/types/utils/undo-redo.d.ts +0 -12
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.5.0-beta.0",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"moveable": "^0.53.0",
|
|
56
56
|
"serialize-javascript": "^6.0.0",
|
|
57
57
|
"sortablejs": "^1.15.2",
|
|
58
|
-
"@tmagic/dep": "1.
|
|
59
|
-
"@tmagic/table": "1.
|
|
58
|
+
"@tmagic/dep": "1.5.0-beta.0",
|
|
59
|
+
"@tmagic/table": "1.5.0-beta.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/events": "^3.0.0",
|
|
@@ -71,19 +71,18 @@
|
|
|
71
71
|
"sass": "^1.77.0",
|
|
72
72
|
"tsc-alias": "^1.8.5",
|
|
73
73
|
"type-fest": "^4.10.3",
|
|
74
|
-
"vite": "^5.3.5"
|
|
75
|
-
"vue-tsc": "^2.0.19"
|
|
74
|
+
"vite": "^5.3.5"
|
|
76
75
|
},
|
|
77
76
|
"peerDependencies": {
|
|
78
77
|
"monaco-editor": "^0.48.0",
|
|
79
78
|
"typescript": "*",
|
|
80
79
|
"vue": "^3.4.35",
|
|
81
|
-
"@tmagic/
|
|
82
|
-
"@tmagic/
|
|
83
|
-
"@tmagic/schema": "1.
|
|
84
|
-
"@tmagic/stage": "1.
|
|
85
|
-
"@tmagic/
|
|
86
|
-
"@tmagic/
|
|
80
|
+
"@tmagic/form": "1.5.0-beta.0",
|
|
81
|
+
"@tmagic/core": "1.5.0-beta.0",
|
|
82
|
+
"@tmagic/schema": "1.5.0-beta.0",
|
|
83
|
+
"@tmagic/stage": "1.5.0-beta.0",
|
|
84
|
+
"@tmagic/design": "1.5.0-beta.0",
|
|
85
|
+
"@tmagic/utils": "1.5.0-beta.0"
|
|
87
86
|
},
|
|
88
87
|
"peerDependenciesMeta": {
|
|
89
88
|
"typescript": {
|
|
@@ -91,9 +90,6 @@
|
|
|
91
90
|
}
|
|
92
91
|
},
|
|
93
92
|
"scripts": {
|
|
94
|
-
"build": "
|
|
95
|
-
"build:type": "npm run clear:type && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
96
|
-
"clear:type": "rimraf ./types",
|
|
97
|
-
"check:type": "vue-tsc --noEmit --project tsconfig.build.json"
|
|
93
|
+
"build": "vite build"
|
|
98
94
|
}
|
|
99
95
|
}
|
package/src/editorProps.ts
CHANGED
|
@@ -10,6 +10,7 @@ import StageCore, {
|
|
|
10
10
|
RenderType,
|
|
11
11
|
type UpdateDragEl,
|
|
12
12
|
} from '@tmagic/stage';
|
|
13
|
+
import { getIdFromEl } from '@tmagic/utils';
|
|
13
14
|
|
|
14
15
|
import type {
|
|
15
16
|
ComponentGroup,
|
|
@@ -114,7 +115,7 @@ export const defaultEditorProps = {
|
|
|
114
115
|
eventMethodList: () => ({}),
|
|
115
116
|
datasourceValues: () => ({}),
|
|
116
117
|
datasourceConfigs: () => ({}),
|
|
117
|
-
canSelect: (el: HTMLElement) => Boolean(el
|
|
118
|
+
canSelect: (el: HTMLElement) => Boolean(getIdFromEl()(el)),
|
|
118
119
|
isContainer: (el: HTMLElement) => el.classList.contains('magic-ui-container'),
|
|
119
120
|
codeOptions: () => ({}),
|
|
120
121
|
};
|
|
@@ -54,7 +54,7 @@ import { Coin } from '@element-plus/icons-vue';
|
|
|
54
54
|
import { getConfig, TMagicAutocomplete, TMagicTag } from '@tmagic/design';
|
|
55
55
|
import type { FieldProps, FormItem } from '@tmagic/form';
|
|
56
56
|
import type { DataSchema, DataSourceSchema } from '@tmagic/schema';
|
|
57
|
-
import { isNumber } from '@tmagic/utils';
|
|
57
|
+
import { getKeysArray, isNumber } from '@tmagic/utils';
|
|
58
58
|
|
|
59
59
|
import Icon from '@editor/components/Icon.vue';
|
|
60
60
|
import type { Services } from '@editor/type';
|
|
@@ -218,7 +218,7 @@ const fieldQuerySearch = (
|
|
|
218
218
|
const dsKey = queryString.substring(leftAngleIndex + 1, dotIndex);
|
|
219
219
|
|
|
220
220
|
// 可能是xx.xx.xx,存在链式调用
|
|
221
|
-
const keys = dsKey
|
|
221
|
+
const keys = getKeysArray(dsKey);
|
|
222
222
|
|
|
223
223
|
// 最前的是数据源id
|
|
224
224
|
const dsId = keys.shift();
|
package/src/fields/UISelect.vue
CHANGED
|
@@ -48,8 +48,9 @@ import { throttle } from 'lodash-es';
|
|
|
48
48
|
import { TMagicButton, TMagicTooltip } from '@tmagic/design';
|
|
49
49
|
import type { FieldProps, FormItem, FormState } from '@tmagic/form';
|
|
50
50
|
import type { Id } from '@tmagic/schema';
|
|
51
|
+
import { getIdFromEl } from '@tmagic/utils';
|
|
51
52
|
|
|
52
|
-
import { Services, UI_SELECT_MODE_EVENT_NAME } from '@editor/type';
|
|
53
|
+
import { type Services, UI_SELECT_MODE_EVENT_NAME } from '@editor/type';
|
|
53
54
|
|
|
54
55
|
defineOptions({
|
|
55
56
|
name: 'MFieldsUISelect',
|
|
@@ -71,11 +72,12 @@ const cancelHandler = () => {
|
|
|
71
72
|
globalThis.document.removeEventListener(UI_SELECT_MODE_EVENT_NAME, clickHandler as EventListener);
|
|
72
73
|
};
|
|
73
74
|
|
|
74
|
-
const clickHandler = ({ detail }: Event & { detail:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
const clickHandler = ({ detail }: Event & { detail: HTMLElement }) => {
|
|
76
|
+
const id = getIdFromEl()(detail);
|
|
77
|
+
if (id) {
|
|
78
|
+
props.model[props.name] = id;
|
|
79
|
+
emit('change', id);
|
|
80
|
+
mForm?.$emit('field-change', props.prop, id);
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
if (cancelHandler) {
|
|
@@ -104,21 +106,24 @@ const deleteHandler = () => {
|
|
|
104
106
|
};
|
|
105
107
|
|
|
106
108
|
const selectNode = async (id: Id) => {
|
|
107
|
-
|
|
108
|
-
services
|
|
109
|
-
services
|
|
109
|
+
if (!services) return;
|
|
110
|
+
await services.editorService.select(id);
|
|
111
|
+
services.editorService.get('stage')?.select(id);
|
|
112
|
+
services.stageOverlayService.get('stage')?.select(id);
|
|
110
113
|
};
|
|
111
114
|
|
|
112
115
|
const highlight = throttle((id: Id) => {
|
|
113
|
-
services
|
|
114
|
-
services
|
|
115
|
-
services
|
|
116
|
+
if (!services) return;
|
|
117
|
+
services.editorService.highlight(id);
|
|
118
|
+
services.editorService.get('stage')?.highlight(id);
|
|
119
|
+
services.stageOverlayService.get('stage')?.highlight(id);
|
|
116
120
|
}, 150);
|
|
117
121
|
|
|
118
122
|
const unhighlight = () => {
|
|
119
|
-
services
|
|
120
|
-
services
|
|
121
|
-
services
|
|
123
|
+
if (!services) return;
|
|
124
|
+
services.editorService.set('highlightNode', null);
|
|
125
|
+
services.editorService.get('stage')?.clearHighlight();
|
|
126
|
+
services.stageOverlayService.get('stage')?.clearHighlight();
|
|
122
127
|
};
|
|
123
128
|
</script>
|
|
124
129
|
|
package/src/hooks/use-stage.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { computed, watch } from 'vue';
|
|
|
2
2
|
|
|
3
3
|
import type { MNode } from '@tmagic/schema';
|
|
4
4
|
import StageCore, { GuidesType, RemoveEventData, SortEventData, UpdateEventData } from '@tmagic/stage';
|
|
5
|
+
import { getIdFromEl } from '@tmagic/utils';
|
|
5
6
|
|
|
6
7
|
import editorService from '@editor/services/editor';
|
|
7
8
|
import uiService from '@editor/services/ui';
|
|
@@ -71,27 +72,32 @@ export const useStage = (stageOptions: StageOptions) => {
|
|
|
71
72
|
});
|
|
72
73
|
|
|
73
74
|
stage.on('select', (el: HTMLElement) => {
|
|
74
|
-
|
|
75
|
-
editorService.
|
|
75
|
+
const id = getIdFromEl()(el);
|
|
76
|
+
if (`${editorService.get('node')?.id}` === id && editorService.get('nodes').length === 1) return;
|
|
77
|
+
id && editorService.select(id);
|
|
76
78
|
});
|
|
77
79
|
|
|
78
80
|
stage.on('highlight', (el: HTMLElement) => {
|
|
79
|
-
|
|
81
|
+
const id = getIdFromEl()(el);
|
|
82
|
+
id && editorService.highlight(id);
|
|
80
83
|
});
|
|
81
84
|
|
|
82
85
|
stage.on('multi-select', (els: HTMLElement[]) => {
|
|
83
|
-
|
|
86
|
+
const ids = els.map((el) => getIdFromEl()(el)).filter((id) => Boolean(id)) as string[];
|
|
87
|
+
editorService.multiSelect(ids);
|
|
84
88
|
});
|
|
85
89
|
|
|
86
90
|
stage.on('update', (ev: UpdateEventData) => {
|
|
87
91
|
if (ev.parentEl) {
|
|
88
92
|
for (const data of ev.data) {
|
|
89
|
-
|
|
93
|
+
const id = getIdFromEl()(data.el);
|
|
94
|
+
const pId = getIdFromEl()(ev.parentEl);
|
|
95
|
+
id && pId && editorService.moveToContainer({ id, style: data.style }, pId);
|
|
90
96
|
}
|
|
91
97
|
return;
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
editorService.update(ev.data.map((data) => ({ id: data.el
|
|
100
|
+
editorService.update(ev.data.map((data) => ({ id: getIdFromEl()(data.el) || '', style: data.style })));
|
|
95
101
|
});
|
|
96
102
|
|
|
97
103
|
stage.on('sort', (ev: SortEventData) => {
|
|
@@ -99,7 +105,7 @@ export const useStage = (stageOptions: StageOptions) => {
|
|
|
99
105
|
});
|
|
100
106
|
|
|
101
107
|
stage.on('remove', (ev: RemoveEventData) => {
|
|
102
|
-
const nodes = ev.data.map(({ el }) => editorService.getNodeById(el
|
|
108
|
+
const nodes = ev.data.map(({ el }) => editorService.getNodeById(getIdFromEl()(el) || ''));
|
|
103
109
|
editorService.remove(nodes.filter((node) => Boolean(node)) as MNode[]);
|
|
104
110
|
});
|
|
105
111
|
|
package/src/initService.ts
CHANGED
|
@@ -192,6 +192,54 @@ export const initServiceEvents = (
|
|
|
192
192
|
((event: 'update:modelValue', value: MApp | null) => void),
|
|
193
193
|
{ editorService, codeBlockService, dataSourceService, depService }: Services,
|
|
194
194
|
) => {
|
|
195
|
+
const rootChangeHandler = async (value: MApp | null, preValue?: MApp | null) => {
|
|
196
|
+
if (!value) return;
|
|
197
|
+
|
|
198
|
+
value.codeBlocks = value.codeBlocks || {};
|
|
199
|
+
value.dataSources = value.dataSources || [];
|
|
200
|
+
|
|
201
|
+
codeBlockService.setCodeDsl(value.codeBlocks);
|
|
202
|
+
dataSourceService.set('dataSources', value.dataSources);
|
|
203
|
+
|
|
204
|
+
depService.removeTargets(DepTargetType.CODE_BLOCK);
|
|
205
|
+
|
|
206
|
+
Object.entries(value.codeBlocks).forEach(([id, code]) => {
|
|
207
|
+
depService.addTarget(createCodeBlockTarget(id, code));
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
dataSourceService.get('dataSources').forEach((ds) => {
|
|
211
|
+
initDataSourceDepTarget(ds);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
if (Array.isArray(value.items)) {
|
|
215
|
+
collectIdle(value.items, true);
|
|
216
|
+
} else {
|
|
217
|
+
depService.clear();
|
|
218
|
+
delete value.dataSourceDeps;
|
|
219
|
+
delete value.dataSourceCondDeps;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const nodeId = editorService.get('node')?.id || props.defaultSelected;
|
|
223
|
+
let node;
|
|
224
|
+
if (nodeId) {
|
|
225
|
+
node = editorService.getNodeById(nodeId);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (node && node !== value) {
|
|
229
|
+
await editorService.select(node.id);
|
|
230
|
+
} else if (value.items?.length) {
|
|
231
|
+
await editorService.select(value.items[0]);
|
|
232
|
+
} else if (value.id) {
|
|
233
|
+
editorService.set('nodes', [value]);
|
|
234
|
+
editorService.set('parent', null);
|
|
235
|
+
editorService.set('page', null);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (toRaw(value) !== toRaw(preValue)) {
|
|
239
|
+
emit('update:modelValue', value);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
195
243
|
const getApp = () => {
|
|
196
244
|
const stage = editorService.get('stage');
|
|
197
245
|
return stage?.renderer.runtime?.getApp?.();
|
|
@@ -292,55 +340,6 @@ export const initServiceEvents = (
|
|
|
292
340
|
depService.addTarget(createDataSourceCondTarget(ds, reactive({})));
|
|
293
341
|
};
|
|
294
342
|
|
|
295
|
-
const rootChangeHandler = async (value: MApp | null, preValue?: MApp | null) => {
|
|
296
|
-
if (!value) return;
|
|
297
|
-
|
|
298
|
-
value.codeBlocks = value.codeBlocks || {};
|
|
299
|
-
value.dataSources = value.dataSources || [];
|
|
300
|
-
|
|
301
|
-
codeBlockService.setCodeDsl(value.codeBlocks);
|
|
302
|
-
dataSourceService.set('dataSources', value.dataSources);
|
|
303
|
-
|
|
304
|
-
depService.removeTargets(DepTargetType.CODE_BLOCK);
|
|
305
|
-
|
|
306
|
-
Object.entries(value.codeBlocks).forEach(([id, code]) => {
|
|
307
|
-
depService.addTarget(createCodeBlockTarget(id, code));
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
dataSourceService.get('dataSources').forEach((ds) => {
|
|
311
|
-
initDataSourceDepTarget(ds);
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
if (Array.isArray(value.items)) {
|
|
315
|
-
value.items.forEach((page) => {
|
|
316
|
-
depService.collectIdle([page], { pageId: page.id }, true);
|
|
317
|
-
});
|
|
318
|
-
} else {
|
|
319
|
-
depService.clear();
|
|
320
|
-
delete value.dataSourceDeps;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const nodeId = editorService.get('node')?.id || props.defaultSelected;
|
|
324
|
-
let node;
|
|
325
|
-
if (nodeId) {
|
|
326
|
-
node = editorService.getNodeById(nodeId);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (node && node !== value) {
|
|
330
|
-
await editorService.select(node.id);
|
|
331
|
-
} else if (value.items?.length) {
|
|
332
|
-
await editorService.select(value.items[0]);
|
|
333
|
-
} else if (value.id) {
|
|
334
|
-
editorService.set('nodes', [value]);
|
|
335
|
-
editorService.set('parent', null);
|
|
336
|
-
editorService.set('page', null);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (toRaw(value) !== toRaw(preValue)) {
|
|
340
|
-
emit('update:modelValue', value);
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
|
|
344
343
|
const collectIdle = (nodes: MNode[], deep: boolean) => {
|
|
345
344
|
nodes.forEach((node) => {
|
|
346
345
|
let pageId: Id | undefined;
|
|
@@ -372,7 +371,7 @@ export const initServiceEvents = (
|
|
|
372
371
|
|
|
373
372
|
// 由于历史记录变化是更新整个page,所以历史记录变化时,需要重新收集依赖
|
|
374
373
|
const historyChangeHandler = (page: MPage | MPageFragment) => {
|
|
375
|
-
|
|
374
|
+
collectIdle([page], true);
|
|
376
375
|
};
|
|
377
376
|
|
|
378
377
|
editorService.on('history-change', historyChangeHandler);
|
|
@@ -407,9 +406,7 @@ export const initServiceEvents = (
|
|
|
407
406
|
removeDataSourceTarget(config.id);
|
|
408
407
|
initDataSourceDepTarget(config);
|
|
409
408
|
|
|
410
|
-
(root?.items || [])
|
|
411
|
-
depService.collectIdle([page], { pageId: page.id }, true);
|
|
412
|
-
});
|
|
409
|
+
collectIdle(root?.items || [], true);
|
|
413
410
|
};
|
|
414
411
|
|
|
415
412
|
const removeDataSourceTarget = (id: string) => {
|
|
@@ -26,6 +26,7 @@ import { computed, inject, nextTick, ref, watch } from 'vue';
|
|
|
26
26
|
|
|
27
27
|
import { TMagicTooltip } from '@tmagic/design';
|
|
28
28
|
import type { MNode } from '@tmagic/schema';
|
|
29
|
+
import { getIdFromEl } from '@tmagic/utils';
|
|
29
30
|
|
|
30
31
|
import FloatingBox from '@editor/components/FloatingBox.vue';
|
|
31
32
|
import Tree from '@editor/components/Tree.vue';
|
|
@@ -61,7 +62,7 @@ const unWatch = watch(
|
|
|
61
62
|
|
|
62
63
|
stage.on('select', (el: HTMLElement, event: MouseEvent) => {
|
|
63
64
|
const els = stage.renderer.getElementsFromPoint(event) || [];
|
|
64
|
-
const ids = els.map((el) => el
|
|
65
|
+
const ids = els.map((el) => getIdFromEl()(el)).filter((id) => Boolean(id)) as string[];
|
|
65
66
|
|
|
66
67
|
buttonVisible.value = ids.length > 3;
|
|
67
68
|
|
|
@@ -46,7 +46,7 @@ import { cloneDeep } from 'lodash-es';
|
|
|
46
46
|
|
|
47
47
|
import type { MApp, MContainer } from '@tmagic/schema';
|
|
48
48
|
import StageCore, { getOffset, Runtime } from '@tmagic/stage';
|
|
49
|
-
import { calcValueByFontsize } from '@tmagic/utils';
|
|
49
|
+
import { calcValueByFontsize, getIdFromEl } from '@tmagic/utils';
|
|
50
50
|
|
|
51
51
|
import ScrollViewer from '@editor/components/ScrollViewer.vue';
|
|
52
52
|
import { useStage } from '@editor/hooks/use-stage';
|
|
@@ -200,8 +200,9 @@ const dropHandler = async (e: DragEvent) => {
|
|
|
200
200
|
const parentEl: HTMLElement | null | undefined = doc?.querySelector(`.${stageOptions?.containerHighlightClassName}`);
|
|
201
201
|
|
|
202
202
|
let parent: MContainer | undefined | null = page.value;
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
const parentId = getIdFromEl()(parentEl);
|
|
204
|
+
if (parentId) {
|
|
205
|
+
parent = services?.editorService.getNodeById(parentId, false) as MContainer;
|
|
205
206
|
}
|
|
206
207
|
|
|
207
208
|
if (parent && stageContainer.value && stage) {
|
package/src/services/editor.ts
CHANGED
|
@@ -23,7 +23,7 @@ import { Writable } from 'type-fest';
|
|
|
23
23
|
import { Target, type TargetOptions, Watcher } from '@tmagic/dep';
|
|
24
24
|
import type { Id, MApp, MComponent, MContainer, MNode, MPage, MPageFragment } from '@tmagic/schema';
|
|
25
25
|
import { NodeType } from '@tmagic/schema';
|
|
26
|
-
import { calcValueByFontsize, getNodePath, isNumber, isPage, isPageFragment, isPop } from '@tmagic/utils';
|
|
26
|
+
import { calcValueByFontsize, getElById, getNodePath, isNumber, isPage, isPageFragment, isPop } from '@tmagic/utils';
|
|
27
27
|
|
|
28
28
|
import BaseService from '@editor/services//BaseService';
|
|
29
29
|
import propsService from '@editor/services//props';
|
|
@@ -759,7 +759,7 @@ class Editor extends BaseService {
|
|
|
759
759
|
const doc = stage?.renderer.contentWindow?.document;
|
|
760
760
|
|
|
761
761
|
if (doc) {
|
|
762
|
-
const el = doc
|
|
762
|
+
const el = getElById()(doc, node.id);
|
|
763
763
|
const parentEl = layout === Layout.FIXED ? doc.body : el?.offsetParent;
|
|
764
764
|
if (parentEl && el) {
|
|
765
765
|
node.style.left = calcValueByFontsize(doc, (parentEl.clientWidth - el.clientWidth) / 2);
|
|
@@ -2,6 +2,7 @@ import { reactive } from 'vue';
|
|
|
2
2
|
import type { Writable } from 'type-fest';
|
|
3
3
|
|
|
4
4
|
import StageCore from '@tmagic/stage';
|
|
5
|
+
import { getIdFromEl } from '@tmagic/utils';
|
|
5
6
|
|
|
6
7
|
import { useStage } from '@editor/hooks/use-stage';
|
|
7
8
|
import BaseService from '@editor/services//BaseService';
|
|
@@ -169,7 +170,8 @@ class StageOverlay extends BaseService {
|
|
|
169
170
|
});
|
|
170
171
|
|
|
171
172
|
if (await stageOptions?.canSelect?.(contentEl)) {
|
|
172
|
-
|
|
173
|
+
const id = getIdFromEl()(contentEl);
|
|
174
|
+
id && subStage?.select(id);
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
177
|
|
package/src/theme/page-bar.scss
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { CascaderOption, FormConfig, FormState } from '@tmagic/form';
|
|
2
2
|
import { DataSchema, DataSourceFieldType, DataSourceSchema } from '@tmagic/schema';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX,
|
|
5
|
+
dataSourceTemplateRegExp,
|
|
6
|
+
getKeysArray,
|
|
7
|
+
isNumber,
|
|
8
|
+
} from '@tmagic/utils';
|
|
4
9
|
|
|
5
10
|
import BaseFormConfig from './formConfigs/base';
|
|
6
11
|
import HttpFormConfig from './formConfigs/http';
|
|
@@ -118,7 +123,7 @@ export const getFormValue = (type: string, values: Partial<DataSourceSchema>): P
|
|
|
118
123
|
* context:上下文对象
|
|
119
124
|
*
|
|
120
125
|
* interface Content {
|
|
121
|
-
* app:
|
|
126
|
+
* app: TMagicApp;
|
|
122
127
|
* dataSource: HttpDataSource;
|
|
123
128
|
* }
|
|
124
129
|
*
|
|
@@ -135,7 +140,7 @@ export const getFormValue = (type: string, values: Partial<DataSourceSchema>): P
|
|
|
135
140
|
* context:上下文对象
|
|
136
141
|
*
|
|
137
142
|
* interface Content {
|
|
138
|
-
* app:
|
|
143
|
+
* app: TMagicApp;
|
|
139
144
|
* dataSource: HttpDataSource;
|
|
140
145
|
* }
|
|
141
146
|
*
|
|
@@ -152,7 +157,7 @@ export const getDisplayField = (dataSources: DataSourceSchema[], key: string) =>
|
|
|
152
157
|
const displayState: { value: string; type: 'var' | 'text' }[] = [];
|
|
153
158
|
|
|
154
159
|
// 匹配es6字符串模块
|
|
155
|
-
const matches = key.matchAll(
|
|
160
|
+
const matches = key.matchAll(dataSourceTemplateRegExp);
|
|
156
161
|
let index = 0;
|
|
157
162
|
for (const match of matches) {
|
|
158
163
|
if (typeof match.index === 'undefined') break;
|
|
@@ -167,25 +172,22 @@ export const getDisplayField = (dataSources: DataSourceSchema[], key: string) =>
|
|
|
167
172
|
let ds: DataSourceSchema | undefined;
|
|
168
173
|
let fields: DataSchema[] | undefined;
|
|
169
174
|
// 将模块解析成数据源对应的值
|
|
170
|
-
match[1]
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
dsText += `.${field?.title || item}`;
|
|
187
|
-
}
|
|
188
|
-
});
|
|
175
|
+
getKeysArray(match[1]).forEach((item, index) => {
|
|
176
|
+
if (index === 0) {
|
|
177
|
+
ds = dataSources.find((ds) => ds.id === item);
|
|
178
|
+
dsText += ds?.title || item;
|
|
179
|
+
fields = ds?.fields;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (isNumber(item)) {
|
|
184
|
+
dsText += `[${item}]`;
|
|
185
|
+
} else {
|
|
186
|
+
const field = fields?.find((field) => field.name === item);
|
|
187
|
+
fields = field?.fields;
|
|
188
|
+
dsText += `.${field?.title || item}`;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
189
191
|
|
|
190
192
|
displayState.push({
|
|
191
193
|
type: 'var',
|
package/src/utils/editor.ts
CHANGED
|
@@ -21,9 +21,10 @@ import serialize from 'serialize-javascript';
|
|
|
21
21
|
import type { Id, MApp, MContainer, MNode, MPage, MPageFragment } from '@tmagic/schema';
|
|
22
22
|
import { NodeType } from '@tmagic/schema';
|
|
23
23
|
import type StageCore from '@tmagic/stage';
|
|
24
|
-
import { calcValueByFontsize, getNodePath, isNumber, isPage, isPageFragment, isPop } from '@tmagic/utils';
|
|
24
|
+
import { calcValueByFontsize, getElById, getNodePath, isNumber, isPage, isPageFragment, isPop } from '@tmagic/utils';
|
|
25
25
|
|
|
26
26
|
import { Layout } from '@editor/type';
|
|
27
|
+
|
|
27
28
|
export const COPY_STORAGE_KEY = '$MagicEditorCopyData';
|
|
28
29
|
export const COPY_CODE_STORAGE_KEY = '$MagicEditorCopyCode';
|
|
29
30
|
export const COPY_DS_STORAGE_KEY = '$MagicEditorCopyDataSource';
|
|
@@ -239,8 +240,8 @@ export const getGuideLineFromCache = (key: string): number[] => {
|
|
|
239
240
|
export const fixNodeLeft = (config: MNode, parent: MContainer, doc?: Document) => {
|
|
240
241
|
if (!doc || !config.style || !isNumber(config.style.left)) return config.style?.left;
|
|
241
242
|
|
|
242
|
-
const el = doc
|
|
243
|
-
const parentEl = doc
|
|
243
|
+
const el = getElById()(doc, `${config.id}`);
|
|
244
|
+
const parentEl = getElById()(doc, `${parent.id}`);
|
|
244
245
|
|
|
245
246
|
const left = Number(config.style?.left) || 0;
|
|
246
247
|
if (el && parentEl) {
|
package/src/utils/index.ts
CHANGED
package/src/utils/operator.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { toRaw } from 'vue';
|
|
|
2
2
|
import { isEmpty } from 'lodash-es';
|
|
3
3
|
|
|
4
4
|
import { Id, MContainer, MNode, NodeType } from '@tmagic/schema';
|
|
5
|
-
import { calcValueByFontsize, isPage, isPageFragment } from '@tmagic/utils';
|
|
5
|
+
import { calcValueByFontsize, getElById, isPage, isPageFragment } from '@tmagic/utils';
|
|
6
6
|
|
|
7
7
|
import editorService from '@editor/services/editor';
|
|
8
8
|
import propsService from '@editor/services/props';
|
|
@@ -73,7 +73,8 @@ export const beforePaste = (position: PastePosition, config: MNode[], doc?: Docu
|
|
|
73
73
|
*/
|
|
74
74
|
export const getPositionInContainer = (position: PastePosition = {}, id: Id, doc?: Document) => {
|
|
75
75
|
let { left = 0, top = 0 } = position;
|
|
76
|
-
const
|
|
76
|
+
const stageDoc = editorService.get('stage')?.renderer?.contentWindow?.document;
|
|
77
|
+
const parentEl = stageDoc && getElById()(stageDoc, `${id}`);
|
|
77
78
|
const parentElRect = parentEl?.getBoundingClientRect();
|
|
78
79
|
left = left - calcValueByFontsize(doc, parentElRect?.left || 0);
|
|
79
80
|
top = top - calcValueByFontsize(doc, parentElRect?.top || 0);
|
package/src/utils/props.ts
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import type { FormConfig, FormState, TabPaneConfig } from '@tmagic/form';
|
|
21
|
+
import { NODE_CONDS_KEY } from '@tmagic/schema';
|
|
21
22
|
|
|
22
23
|
export const arrayOptions = [
|
|
23
24
|
{ text: '包含', value: 'include' },
|
|
@@ -359,7 +360,7 @@ export const displayTabConfig: TabPaneConfig = {
|
|
|
359
360
|
items: [
|
|
360
361
|
{
|
|
361
362
|
type: 'display-conds',
|
|
362
|
-
name:
|
|
363
|
+
name: NODE_CONDS_KEY,
|
|
363
364
|
titlePrefix: '条件组',
|
|
364
365
|
defaultValue: [],
|
|
365
366
|
},
|