@tmagic/editor 1.8.2 → 1.8.4-beta.1
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/es/Editor.vue_vue_type_script_setup_true_lang.js +23 -25
- package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DataSourceInput.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/configs.js +1 -1
- package/dist/es/fields/configs/codeSelect.js +5 -7
- package/dist/es/fields/configs/displayConds.js +8 -9
- package/dist/es/fields/configs/eventSelect.js +30 -27
- package/dist/es/headless.js +1 -2
- package/dist/es/hooks/use-stage.js +19 -18
- package/dist/es/index.js +9 -16
- package/dist/es/initService.js +33 -106
- package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/NavMenuColumn.vue_vue_type_script_setup_true_lang.js +12 -2
- package/dist/es/layouts/page-bar/AddButton.vue_vue_type_script_setup_true_lang.js +4 -6
- package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/props-panel/use-style-panel.js +1 -1
- package/dist/es/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/es/layouts/workspace/viewer/Stage.vue_vue_type_script_setup_true_lang.js +3 -0
- package/dist/es/sdk/index.js +151 -0
- package/dist/es/{services → sdk/services}/BaseService.js +1 -1
- package/dist/es/{services/codeBlock.js → sdk/services/CodeBlock.js} +37 -40
- package/dist/es/{services/componentList.js → sdk/services/ComponentList.js} +5 -6
- package/dist/es/{services/dataSource.js → sdk/services/DataSource.js} +38 -37
- package/dist/es/{services/dep.js → sdk/services/Dep.js} +27 -17
- package/dist/es/{services/editor.js → sdk/services/Editor.js} +124 -87
- package/dist/es/{services/events.js → sdk/services/Events.js} +13 -13
- package/dist/es/{services/history.js → sdk/services/History.js} +86 -33
- package/dist/es/{services/props.js → sdk/services/Props.js} +25 -26
- package/dist/es/{services/storage.js → sdk/services/WebStorage.js} +31 -8
- package/dist/es/sdk/utils/dep.js +100 -0
- package/dist/es/sdk/utils/operator.js +70 -0
- package/dist/es/sdk/utils/position.js +8 -0
- package/dist/es/sdk/utils/props.js +281 -0
- package/dist/es/sdk/validate/index.js +286 -0
- package/dist/es/sdk/wiring.js +163 -0
- package/dist/es/sdk.js +15 -0
- package/dist/es/services/keybinding.js +21 -21
- package/dist/es/services/sdk-instance.js +37 -0
- package/dist/es/services/stageOverlay.js +14 -14
- package/dist/es/services/ui.js +6 -6
- package/dist/es/style.css +31 -6
- package/dist/es/utils/data-source/formConfigs/base.js +1 -1
- package/dist/es/utils/data-source/formConfigs/http.js +1 -1
- package/dist/es/utils/dep/worker.js +1 -1
- package/dist/es/utils/editor.js +2 -2
- package/dist/es/utils/event.js +25 -21
- package/dist/es/utils/operator.js +11 -57
- package/dist/es/utils/props.js +12 -282
- package/dist/es/utils/type-match-rules.js +10 -12
- package/dist/style.css +31 -6
- package/dist/themes/magic-admin.css +31 -6
- package/dist/tmagic-editor-headless.umd.cjs +4690 -2891
- package/dist/tmagic-editor-sdk.umd.cjs +9911 -0
- package/dist/tmagic-editor.umd.cjs +14155 -13319
- package/package.json +13 -8
- package/src/Editor.vue +14 -9
- package/src/editorProps.ts +23 -0
- package/src/fields/configs/codeSelect.ts +6 -9
- package/src/fields/configs/displayConds.ts +10 -9
- package/src/fields/configs/eventSelect.ts +40 -25
- package/src/hooks/use-stage.ts +2 -1
- package/src/index.ts +11 -9
- package/src/initService.ts +59 -188
- package/src/layouts/Framework.vue +1 -1
- package/src/layouts/NavMenuColumn.vue +16 -4
- package/src/layouts/page-bar/AddButton.vue +5 -6
- package/src/layouts/props-panel/PropsPanel.vue +1 -1
- package/src/layouts/props-panel/use-style-panel.ts +1 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +7 -1
- package/src/layouts/workspace/viewer/Stage.vue +5 -0
- package/src/sdk/index.ts +264 -0
- package/src/{services/codeBlock.ts → sdk/services/CodeBlock.ts} +43 -38
- package/src/{services/componentList.ts → sdk/services/ComponentList.ts} +8 -7
- package/src/{services/dataSource.ts → sdk/services/DataSource.ts} +38 -32
- package/src/{services/dep.ts → sdk/services/Dep.ts} +29 -12
- package/src/{services/editor.ts → sdk/services/Editor.ts} +175 -86
- package/src/{services/events.ts → sdk/services/Events.ts} +15 -12
- package/src/{services/history.ts → sdk/services/History.ts} +100 -28
- package/src/{services/props.ts → sdk/services/Props.ts} +25 -25
- package/src/{services/storage.ts → sdk/services/WebStorage.ts} +41 -7
- package/src/sdk/type.ts +191 -0
- package/src/sdk/utils/dep.ts +196 -0
- package/src/sdk/utils/operator.ts +114 -0
- package/src/sdk/utils/position.ts +23 -0
- package/src/sdk/utils/props.ts +368 -0
- package/src/sdk/validate/index.ts +501 -0
- package/src/sdk/wiring.ts +211 -0
- package/src/sdk.ts +19 -0
- package/src/services/keybinding.ts +2 -2
- package/src/services/sdk-instance.ts +66 -0
- package/src/services/stageOverlay.ts +2 -2
- package/src/services/ui.ts +3 -3
- package/src/theme/nav-menu.scss +29 -2
- package/src/type.ts +33 -9
- package/src/utils/data-source/formConfigs/base.ts +1 -1
- package/src/utils/data-source/formConfigs/http.ts +1 -1
- package/src/utils/dep/collect-worker-client.ts +9 -6
- package/src/utils/dep/worker.ts +5 -0
- package/src/utils/editor.ts +2 -1
- package/src/utils/event.ts +36 -18
- package/src/utils/operator.ts +21 -87
- package/src/utils/props.ts +17 -332
- package/src/utils/type-match-rules.ts +1 -3
- package/types/index.d.ts +797 -540
- package/types/sdk.d.ts +2594 -0
- /package/src/{services → sdk/services}/BaseService.ts +0 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.8.
|
|
2
|
+
"version": "1.8.4-beta.1",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
"import": "./dist/es/headless.js",
|
|
23
23
|
"require": "./dist/tmagic-editor-headless.umd.cjs"
|
|
24
24
|
},
|
|
25
|
+
"./sdk": {
|
|
26
|
+
"types": "./types/sdk.d.ts",
|
|
27
|
+
"import": "./dist/es/sdk.js",
|
|
28
|
+
"require": "./dist/tmagic-editor-sdk.umd.cjs"
|
|
29
|
+
},
|
|
25
30
|
"./dist/style.css": {
|
|
26
31
|
"import": "./dist/style.css",
|
|
27
32
|
"require": "./dist/style.css"
|
|
@@ -63,11 +68,11 @@
|
|
|
63
68
|
"moveable": "^0.53.0",
|
|
64
69
|
"serialize-javascript": "^7.1.1",
|
|
65
70
|
"sortablejs": "^1.15.7",
|
|
66
|
-
"@tmagic/design": "1.8.
|
|
67
|
-
"@tmagic/form": "1.8.
|
|
68
|
-
"@tmagic/stage": "1.8.
|
|
69
|
-
"@tmagic/
|
|
70
|
-
"@tmagic/
|
|
71
|
+
"@tmagic/design": "1.8.4-beta.1",
|
|
72
|
+
"@tmagic/form": "1.8.4-beta.1",
|
|
73
|
+
"@tmagic/stage": "1.8.4-beta.1",
|
|
74
|
+
"@tmagic/utils": "1.8.4-beta.1",
|
|
75
|
+
"@tmagic/table": "1.8.4-beta.1"
|
|
71
76
|
},
|
|
72
77
|
"devDependencies": {
|
|
73
78
|
"@types/events": "^3.0.3",
|
|
@@ -80,8 +85,8 @@
|
|
|
80
85
|
"monaco-editor": "^0.55.1 ",
|
|
81
86
|
"type-fest": "^5.2.0",
|
|
82
87
|
"typescript": "^6.0.3",
|
|
83
|
-
"vue": "^3.5.
|
|
84
|
-
"@tmagic/core": "1.8.
|
|
88
|
+
"vue": "^3.5.44",
|
|
89
|
+
"@tmagic/core": "1.8.4-beta.1"
|
|
85
90
|
},
|
|
86
91
|
"peerDependenciesMeta": {
|
|
87
92
|
"typescript": {
|
package/src/Editor.vue
CHANGED
|
@@ -148,17 +148,19 @@ import FormPanel from './layouts/props-panel/FormPanel.vue';
|
|
|
148
148
|
import PropsPanel from './layouts/props-panel/PropsPanel.vue';
|
|
149
149
|
import Sidebar from './layouts/sidebar/Sidebar.vue';
|
|
150
150
|
import Workspace from './layouts/workspace/Workspace.vue';
|
|
151
|
-
import codeBlockService from './services/codeBlock';
|
|
152
|
-
import componentListService from './services/componentList';
|
|
153
|
-
import dataSourceService from './services/dataSource';
|
|
154
|
-
import depService from './services/dep';
|
|
155
|
-
import editorService from './services/editor';
|
|
156
|
-
import eventsService from './services/events';
|
|
157
|
-
import historyService from './services/history';
|
|
158
151
|
import keybindingService from './services/keybinding';
|
|
159
|
-
import
|
|
152
|
+
import {
|
|
153
|
+
codeBlockService,
|
|
154
|
+
componentListService,
|
|
155
|
+
dataSourceService,
|
|
156
|
+
depService,
|
|
157
|
+
editorService,
|
|
158
|
+
eventsService,
|
|
159
|
+
historyService,
|
|
160
|
+
propsService,
|
|
161
|
+
storageService,
|
|
162
|
+
} from './services/sdk-instance';
|
|
160
163
|
import stageOverlayService from './services/stageOverlay';
|
|
161
|
-
import storageService from './services/storage';
|
|
162
164
|
import uiService from './services/ui';
|
|
163
165
|
import keybindingConfig from './utils/keybinding-config';
|
|
164
166
|
import { defaultEditorProps, EditorProps, ENABLE_PROPS_FORM_VALIDATE } from './editorProps';
|
|
@@ -222,11 +224,14 @@ const stageOptions: StageOptions = {
|
|
|
222
224
|
containerHighlightAddOnly: props.containerHighlightAddOnly,
|
|
223
225
|
disabledDragStart: props.disabledDragStart,
|
|
224
226
|
renderType: props.renderType,
|
|
227
|
+
iframeSandbox: props.iframeSandbox,
|
|
225
228
|
guidesOptions: props.guidesOptions,
|
|
226
229
|
disabledMultiSelect: props.disabledMultiSelect,
|
|
227
230
|
alwaysMultiSelect: props.alwaysMultiSelect,
|
|
228
231
|
disabledFlashTip: props.disabledFlashTip,
|
|
229
232
|
beforeDblclick: props.beforeDblclick,
|
|
233
|
+
beforeAppendComponent: props.beforeAppendComponent,
|
|
234
|
+
beforeDropComponent: props.beforeDropComponent,
|
|
230
235
|
};
|
|
231
236
|
|
|
232
237
|
stageOverlayService.set('stageOptions', stageOptions);
|
package/src/editorProps.ts
CHANGED
|
@@ -13,6 +13,8 @@ import StageCore, {
|
|
|
13
13
|
import { getIdFromEl } from '@tmagic/utils';
|
|
14
14
|
|
|
15
15
|
import type {
|
|
16
|
+
BeforeAppendComponent,
|
|
17
|
+
BeforeDropComponent,
|
|
16
18
|
CanDropInFunction,
|
|
17
19
|
ComponentGroup,
|
|
18
20
|
CustomContentMenuFunction,
|
|
@@ -62,6 +64,16 @@ export interface EditorProps {
|
|
|
62
64
|
runtimeUrl?: string;
|
|
63
65
|
/** 是用iframe渲染还是直接渲染 */
|
|
64
66
|
renderType?: RenderType;
|
|
67
|
+
/**
|
|
68
|
+
* 画布 iframe 的 sandbox 属性值(仅 iframe 渲染时生效)
|
|
69
|
+
*
|
|
70
|
+
* - 不传 / `false`:不设置 sandbox 属性(默认)
|
|
71
|
+
* - 字符串:原样写入,token 空格分隔,如 `'allow-scripts allow-same-origin allow-downloads'`
|
|
72
|
+
*
|
|
73
|
+
* 需要注意编辑器自身依赖 `allow-scripts` + `allow-same-origin`(读写 iframe 内 DOM),
|
|
74
|
+
* 其余 token(`allow-downloads`、`allow-popups`、`allow-forms` 等)按业务需要放开。
|
|
75
|
+
*/
|
|
76
|
+
iframeSandbox?: string | false;
|
|
65
77
|
/** 选中时是否自动滚动到可视区域 */
|
|
66
78
|
autoScrollIntoView?: boolean;
|
|
67
79
|
/** 组件的属性配置表单的dsl */
|
|
@@ -150,6 +162,17 @@ export interface EditorProps {
|
|
|
150
162
|
canDropIn?: CanDropInFunction;
|
|
151
163
|
/** 画布双击前的钩子函数,返回 false 则阻止默认的双击行为 */
|
|
152
164
|
beforeDblclick?: (event: MouseEvent) => Promise<boolean | void> | boolean | void;
|
|
165
|
+
/**
|
|
166
|
+
* 点击组件列表新增组件前的钩子,入参为当前组件列表项,允许异步函数。
|
|
167
|
+
* 仅点击新增时调用,拖入画布不走该钩子;返回 false 取消本次新增。
|
|
168
|
+
* 可直接修改入参(例如补全 data),修改会反映到最终新增的节点上。
|
|
169
|
+
*/
|
|
170
|
+
beforeAppendComponent?: BeforeAppendComponent;
|
|
171
|
+
/**
|
|
172
|
+
* 组件列表拖入画布、写入节点前的钩子,入参为即将新增的节点和父节点,允许异步函数。
|
|
173
|
+
* 仅当拖拽类型为组件列表时,在位置计算完成之后调用;返回 false 取消本次拖入。
|
|
174
|
+
*/
|
|
175
|
+
beforeDropComponent?: BeforeDropComponent;
|
|
153
176
|
/** 组件树节点双击前的钩子函数,返回 false 则阻止默认的双击行为 */
|
|
154
177
|
beforeLayerNodeDblclick?: (event: MouseEvent, data: TreeNodeData) => Promise<boolean | void> | boolean | void;
|
|
155
178
|
/** 历史记录面板的自定义扩展 tab,追加在内置的页面/数据源/代码块 tab 之后 */
|
|
@@ -19,10 +19,7 @@
|
|
|
19
19
|
import { isEmpty } from 'lodash-es';
|
|
20
20
|
|
|
21
21
|
import { HookCodeType, HookType } from '@tmagic/core';
|
|
22
|
-
import type { CodeSelectConfig, FormValue, GroupListConfig } from '@tmagic/form/headless';
|
|
23
|
-
|
|
24
|
-
import codeBlockService from '@editor/services/codeBlock';
|
|
25
|
-
import dataSourceService from '@editor/services/dataSource';
|
|
22
|
+
import type { CodeSelectConfig, FormState, FormValue, GroupListConfig } from '@tmagic/form/headless';
|
|
26
23
|
|
|
27
24
|
import { stickyAddButton } from './stickyAddButton';
|
|
28
25
|
|
|
@@ -42,21 +39,21 @@ export const createCodeSelectConfig = (config: CodeSelectConfig): GroupListConfi
|
|
|
42
39
|
codeId: '',
|
|
43
40
|
}),
|
|
44
41
|
...stickyAddButton(`添加${config.text || ''}`),
|
|
45
|
-
title: (
|
|
42
|
+
title: (mForm: FormState | undefined, { model, index }: any) => {
|
|
46
43
|
if (model.codeType === HookCodeType.DATA_SOURCE_METHOD) {
|
|
47
44
|
if (Array.isArray(model.codeId)) {
|
|
48
45
|
if (model.codeId.length < 2) {
|
|
49
46
|
return index;
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
const ds = dataSourceService.getDataSourceById(model.codeId[0]);
|
|
49
|
+
const ds = mForm?.services?.dataSourceService.getDataSourceById(model.codeId[0]);
|
|
53
50
|
return `${ds?.title} / ${model.codeId[1]}`;
|
|
54
51
|
}
|
|
55
52
|
|
|
56
53
|
return Array.isArray(model.codeId) ? model.codeId.join('/') : index;
|
|
57
54
|
}
|
|
58
55
|
|
|
59
|
-
const codeContent = codeBlockService.getCodeContentById(model.codeId);
|
|
56
|
+
const codeContent = mForm?.services?.codeBlockService.getCodeContentById(model.codeId);
|
|
60
57
|
|
|
61
58
|
if (codeContent) {
|
|
62
59
|
return codeContent.name;
|
|
@@ -92,7 +89,7 @@ export const createCodeSelectConfig = (config: CodeSelectConfig): GroupListConfi
|
|
|
92
89
|
rules: [{ typeMatch: true, trigger: 'change' }],
|
|
93
90
|
|
|
94
91
|
display: (_mForm: any, { model }: any) => model.codeType !== HookCodeType.DATA_SOURCE_METHOD,
|
|
95
|
-
notEditable: () => !codeBlockService.getEditStatus(),
|
|
92
|
+
notEditable: (mForm: FormState | undefined) => !mForm?.services?.codeBlockService.getEditStatus(),
|
|
96
93
|
},
|
|
97
94
|
{
|
|
98
95
|
type: 'data-source-method-select',
|
|
@@ -100,7 +97,7 @@ export const createCodeSelectConfig = (config: CodeSelectConfig): GroupListConfi
|
|
|
100
97
|
text: '数据源字段',
|
|
101
98
|
rules: [{ typeMatch: true, trigger: 'change' }],
|
|
102
99
|
display: (_mForm: any, { model }: any) => model.codeType === HookCodeType.DATA_SOURCE_METHOD,
|
|
103
|
-
notEditable: () => !dataSourceService.get('editable'),
|
|
100
|
+
notEditable: (mForm: FormState | undefined) => !mForm?.services?.dataSourceService.get('editable'),
|
|
104
101
|
},
|
|
105
102
|
],
|
|
106
103
|
} as any as GroupListConfig;
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
import type { DisplayCondsConfig, FormState, GroupListConfig } from '@tmagic/form/headless';
|
|
20
20
|
import { removeDataSourceFieldPrefix } from '@tmagic/utils';
|
|
21
21
|
|
|
22
|
-
import dataSourceService from '@editor/services/dataSource';
|
|
23
22
|
import { getCascaderOptionsFromFields, getFieldType, resolveFieldByPath } from '@editor/utils/data-source';
|
|
24
23
|
|
|
25
24
|
import { stickyAddButton } from './stickyAddButton';
|
|
@@ -38,15 +37,17 @@ export const createDisplayCondsConfig = (
|
|
|
38
37
|
name: string,
|
|
39
38
|
parentFields: string[],
|
|
40
39
|
): GroupListConfig => {
|
|
41
|
-
const resolveFieldPath = (path: Array<string | number>) => {
|
|
40
|
+
const resolveFieldPath = (formState: FormState | undefined, path: Array<string | number>) => {
|
|
42
41
|
const [id, ...fieldNames] = path;
|
|
43
|
-
const ds = id
|
|
42
|
+
const ds = id
|
|
43
|
+
? formState?.services?.dataSourceService.getDataSourceById(removeDataSourceFieldPrefix(`${id}`))
|
|
44
|
+
: undefined;
|
|
44
45
|
return { ds, fieldNames };
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
// 字段变更后按新字段的类型把已填的值转成对应类型,避免类型校验与运行期取值不一致
|
|
48
|
-
const fieldOnChange = (
|
|
49
|
-
const { ds, fieldNames } = resolveFieldPath([...parentFields, ...v]);
|
|
49
|
+
const fieldOnChange = (formState: FormState | undefined, v: string[], { model }: { model: Record<string, any> }) => {
|
|
50
|
+
const { ds, fieldNames } = resolveFieldPath(formState, [...parentFields, ...v]);
|
|
50
51
|
const type = getFieldType(ds, fieldNames);
|
|
51
52
|
if (type === 'number') {
|
|
52
53
|
model.value = Number(model.value);
|
|
@@ -63,8 +64,8 @@ export const createDisplayCondsConfig = (
|
|
|
63
64
|
const fieldItem = parentFields.length
|
|
64
65
|
? {
|
|
65
66
|
type: 'cascader',
|
|
66
|
-
options: () => {
|
|
67
|
-
const { ds, fieldNames } = resolveFieldPath(parentFields);
|
|
67
|
+
options: (formState: FormState | undefined) => {
|
|
68
|
+
const { ds, fieldNames } = resolveFieldPath(formState, parentFields);
|
|
68
69
|
if (!ds) {
|
|
69
70
|
return [];
|
|
70
71
|
}
|
|
@@ -141,8 +142,8 @@ export const createDisplayCondsConfig = (
|
|
|
141
142
|
{
|
|
142
143
|
name: 'value',
|
|
143
144
|
text: '值',
|
|
144
|
-
type: (
|
|
145
|
-
const { ds, fieldNames } = resolveFieldPath([...parentFields, ...(model.field || [])]);
|
|
145
|
+
type: (mForm: FormState | undefined, { model }: any) => {
|
|
146
|
+
const { ds, fieldNames } = resolveFieldPath(mForm, [...parentFields, ...(model.field || [])]);
|
|
146
147
|
const type = getFieldType(ds, fieldNames);
|
|
147
148
|
|
|
148
149
|
if (type === 'number') {
|
|
@@ -31,18 +31,14 @@ import type {
|
|
|
31
31
|
} from '@tmagic/form/headless';
|
|
32
32
|
import { defineFormItem } from '@tmagic/form/headless';
|
|
33
33
|
|
|
34
|
-
import
|
|
35
|
-
import dataSourceService from '@editor/services/dataSource';
|
|
36
|
-
import editorService from '@editor/services/editor';
|
|
37
|
-
import eventsService from '@editor/services/events';
|
|
38
|
-
import propsService from '@editor/services/props';
|
|
34
|
+
import type { Services } from '@editor/type';
|
|
39
35
|
import {
|
|
40
36
|
getCompActionAllowedValues,
|
|
41
37
|
getCompActionOptions,
|
|
42
38
|
getEventNameAllowedValues,
|
|
43
39
|
getEventNameOptions,
|
|
44
40
|
normalizeCompActionValue,
|
|
45
|
-
} from '@editor/utils';
|
|
41
|
+
} from '@editor/utils/event';
|
|
46
42
|
|
|
47
43
|
import { stickyAddButton } from './stickyAddButton';
|
|
48
44
|
|
|
@@ -67,11 +63,14 @@ export const createEventNameConfig = (config: EventSelectConfig) => {
|
|
|
67
63
|
labelWidth: '70px',
|
|
68
64
|
checkStrictly: () => config.src !== 'component',
|
|
69
65
|
valueSeparator: '.',
|
|
70
|
-
options: (
|
|
66
|
+
options: (mForm: FormState, { formValue }: any) =>
|
|
67
|
+
mForm?.services ? getEventNameOptions(config.src, formValue, mForm.services) : [],
|
|
71
68
|
rules: [
|
|
72
69
|
{
|
|
73
|
-
validator: ({ value, callback }: any, { formValue }: any) => {
|
|
74
|
-
const allowedNames =
|
|
70
|
+
validator: ({ value, callback }: any, { formValue }: any, mForm?: FormState) => {
|
|
71
|
+
const allowedNames = mForm?.services
|
|
72
|
+
? getEventNameAllowedValues(config as any, formValue, mForm.services)
|
|
73
|
+
: null;
|
|
75
74
|
if (allowedNames && allowedNames.size > 0 && value && !allowedNames.has(value)) {
|
|
76
75
|
return callback(`事件名(${value})不存在`);
|
|
77
76
|
}
|
|
@@ -84,7 +83,7 @@ export const createEventNameConfig = (config: EventSelectConfig) => {
|
|
|
84
83
|
return { ...defaultEventNameConfig, ...config.eventNameConfig };
|
|
85
84
|
};
|
|
86
85
|
|
|
87
|
-
const createActionTypeOptions = () => {
|
|
86
|
+
const createActionTypeOptions = (services?: Services) => {
|
|
88
87
|
const o: {
|
|
89
88
|
text: string;
|
|
90
89
|
label: string;
|
|
@@ -98,6 +97,12 @@ const createActionTypeOptions = () => {
|
|
|
98
97
|
},
|
|
99
98
|
];
|
|
100
99
|
|
|
100
|
+
if (!services) {
|
|
101
|
+
return o;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const { propsService, codeBlockService } = services;
|
|
105
|
+
|
|
101
106
|
if (!propsService.getDisabledCodeBlock()) {
|
|
102
107
|
o.push({
|
|
103
108
|
text: '代码',
|
|
@@ -125,7 +130,7 @@ const createActionTypeConfig = (config: EventSelectConfig) => {
|
|
|
125
130
|
text: '联动类型',
|
|
126
131
|
type: 'select',
|
|
127
132
|
defaultValue: ActionType.COMP,
|
|
128
|
-
options: createActionTypeOptions(),
|
|
133
|
+
options: (mForm: FormState | undefined) => createActionTypeOptions(mForm?.services),
|
|
129
134
|
rules: [
|
|
130
135
|
{
|
|
131
136
|
required: true,
|
|
@@ -171,8 +176,8 @@ const createCompActionConfig = (config: EventSelectConfig) => {
|
|
|
171
176
|
const defaultCompActionConfig: DynamicTypeConfig = {
|
|
172
177
|
name: 'method',
|
|
173
178
|
text: '动作',
|
|
174
|
-
type: (
|
|
175
|
-
const to = editorService.getNodeById(model.to);
|
|
179
|
+
type: (mForm: FormState | undefined, { model }: any) => {
|
|
180
|
+
const to = mForm?.services?.editorService.getNodeById(model.to);
|
|
176
181
|
|
|
177
182
|
if (to?.type === 'page-fragment-container' && to.pageFragmentId) {
|
|
178
183
|
return 'cascader';
|
|
@@ -182,12 +187,15 @@ const createCompActionConfig = (config: EventSelectConfig) => {
|
|
|
182
187
|
},
|
|
183
188
|
checkStrictly: () => config.src !== 'component',
|
|
184
189
|
display: (_mForm: FormState | undefined, { model }: any) => model.actionType === ActionType.COMP,
|
|
185
|
-
options: (
|
|
190
|
+
options: (mForm: FormState, { model }: any) =>
|
|
191
|
+
mForm?.services ? getCompActionOptions(model.to, mForm.services) : [],
|
|
186
192
|
rules: [
|
|
187
193
|
{
|
|
188
194
|
trigger: 'blur',
|
|
189
|
-
validator: ({ value, callback }: any, { model }: any) => {
|
|
190
|
-
const allowedMethods =
|
|
195
|
+
validator: ({ value, callback }: any, { model }: any, mForm?: FormState) => {
|
|
196
|
+
const allowedMethods = mForm?.services
|
|
197
|
+
? getCompActionAllowedValues(config as any, model, mForm.services)
|
|
198
|
+
: null;
|
|
191
199
|
const normalized = normalizeCompActionValue(value);
|
|
192
200
|
if (allowedMethods && allowedMethods.size > 0 && normalized && !allowedMethods.has(normalized)) {
|
|
193
201
|
return callback(`动作名(${normalized})不存在`);
|
|
@@ -206,7 +214,7 @@ const createCodeActionConfig = (config: EventSelectConfig) => {
|
|
|
206
214
|
type: 'code-select-col',
|
|
207
215
|
text: '代码块',
|
|
208
216
|
name: 'codeId',
|
|
209
|
-
notEditable: () => !codeBlockService.getEditStatus(),
|
|
217
|
+
notEditable: (mForm: FormState | undefined) => !mForm?.services?.codeBlockService.getEditStatus(),
|
|
210
218
|
display: (_mForm, { model }) => model.actionType === ActionType.CODE,
|
|
211
219
|
};
|
|
212
220
|
return { ...defaultCodeActionConfig, ...config.codeActionConfig };
|
|
@@ -218,7 +226,7 @@ const createDataSourceActionConfig = (config: EventSelectConfig) => {
|
|
|
218
226
|
type: 'data-source-method-select',
|
|
219
227
|
text: '数据源方法',
|
|
220
228
|
name: 'dataSourceMethod',
|
|
221
|
-
notEditable: () => !dataSourceService.get('editable'),
|
|
229
|
+
notEditable: (mForm: FormState | undefined) => !mForm?.services?.dataSourceService.get('editable'),
|
|
222
230
|
display: (_mForm, { model }) => model.actionType === ActionType.DATA_SOURCE,
|
|
223
231
|
};
|
|
224
232
|
return { ...defaultDataSourceActionConfig, ...config.dataSourceActionConfig };
|
|
@@ -272,13 +280,17 @@ export const createLegacyTableConfig = (config: EventSelectConfig): TableConfig
|
|
|
272
280
|
name: 'name',
|
|
273
281
|
label: '事件名',
|
|
274
282
|
type: createEventNameConfig(config).type,
|
|
275
|
-
options: (
|
|
276
|
-
|
|
277
|
-
|
|
283
|
+
options: (mForm: FormState, { formValue }: any) => {
|
|
284
|
+
const services = mForm?.services;
|
|
285
|
+
if (!services) return [];
|
|
286
|
+
|
|
287
|
+
return services.eventsService
|
|
288
|
+
.getEvent(formValue.type, { node: services.editorService.getNodeById(formValue.id) })
|
|
278
289
|
.map((option: any) => ({
|
|
279
290
|
text: option.label,
|
|
280
291
|
value: option.value,
|
|
281
|
-
}))
|
|
292
|
+
}));
|
|
293
|
+
},
|
|
282
294
|
},
|
|
283
295
|
{
|
|
284
296
|
name: 'to',
|
|
@@ -289,11 +301,14 @@ export const createLegacyTableConfig = (config: EventSelectConfig): TableConfig
|
|
|
289
301
|
name: 'method',
|
|
290
302
|
label: '动作',
|
|
291
303
|
type: createCompActionConfig(config).type,
|
|
292
|
-
options: (
|
|
293
|
-
const
|
|
304
|
+
options: (mForm: FormState, { model, formValue }: any) => {
|
|
305
|
+
const services = mForm?.services;
|
|
306
|
+
if (!services) return [];
|
|
307
|
+
|
|
308
|
+
const node = services.editorService.getNodeById(model.to) || (formValue as MNode);
|
|
294
309
|
if (!node?.type) return [];
|
|
295
310
|
|
|
296
|
-
return eventsService.getMethod(node.type, { targetId: model.to, node }).map((option: any) => ({
|
|
311
|
+
return services.eventsService.getMethod(node.type, { targetId: model.to, node }).map((option: any) => ({
|
|
297
312
|
text: option.label,
|
|
298
313
|
value: option.value,
|
|
299
314
|
}));
|
package/src/hooks/use-stage.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { MNode } from '@tmagic/core';
|
|
|
4
4
|
import StageCore, { GuidesType, RemoveEventData, SortEventData, UpdateEventData } from '@tmagic/stage';
|
|
5
5
|
import { getIdFromEl } from '@tmagic/utils';
|
|
6
6
|
|
|
7
|
-
import editorService from '@editor/services/
|
|
7
|
+
import { editorService } from '@editor/services/sdk-instance';
|
|
8
8
|
import uiService from '@editor/services/ui';
|
|
9
9
|
import type { StageOptions } from '@editor/type';
|
|
10
10
|
import { H_GUIDE_LINE_STORAGE_KEY, UI_SELECT_MODE_EVENT_NAME, V_GUIDE_LINE_STORAGE_KEY } from '@editor/utils/const';
|
|
@@ -31,6 +31,7 @@ export const useStage = (stageOptions: StageOptions) => {
|
|
|
31
31
|
containerHighlightAddOnly: stageOptions.containerHighlightAddOnly,
|
|
32
32
|
disabledDragStart: stageOptions.disabledDragStart,
|
|
33
33
|
renderType: stageOptions.renderType,
|
|
34
|
+
iframeSandbox: stageOptions.iframeSandbox,
|
|
34
35
|
canSelect: (el, event, stop) => {
|
|
35
36
|
if (!stageOptions.canSelect) return true;
|
|
36
37
|
|
package/src/index.ts
CHANGED
|
@@ -37,17 +37,19 @@ export * from './utils';
|
|
|
37
37
|
export { isGlobalFlat } from './utils/config';
|
|
38
38
|
export { default as TMagicEditor } from './Editor.vue';
|
|
39
39
|
export { default as TMagicCodeEditor } from './layouts/CodeEditor.vue';
|
|
40
|
-
export {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
export {
|
|
41
|
+
codeBlockService,
|
|
42
|
+
componentListService,
|
|
43
|
+
dataSourceService,
|
|
44
|
+
depService,
|
|
45
|
+
editorService,
|
|
46
|
+
eventsService,
|
|
47
|
+
historyService,
|
|
48
|
+
propsService,
|
|
49
|
+
storageService,
|
|
50
|
+
} from './services/sdk-instance';
|
|
46
51
|
export { default as stageOverlayService } from './services/stageOverlay';
|
|
47
52
|
export { default as uiService } from './services/ui';
|
|
48
|
-
export { default as codeBlockService } from './services/codeBlock';
|
|
49
|
-
export { default as depService } from './services/dep';
|
|
50
|
-
export { default as componentListService } from './services/componentList';
|
|
51
53
|
export { default as keybindingService } from './services/keybinding';
|
|
52
54
|
export { default as ComponentListPanel } from './layouts/sidebar/ComponentListPanel.vue';
|
|
53
55
|
export { default as LayerPanel } from './layouts/sidebar/layer/LayerPanel.vue';
|