@tmagic/editor 1.8.1 → 1.8.3
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 +17 -25
- package/dist/es/editorProps.js +3 -0
- 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/hooks/use-stage.js +18 -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/props-panel/FormPanel.vue_vue_type_script_setup_true_lang.js +8 -6
- package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/es/layouts/props-panel/use-style-panel.js +1 -1
- 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} +24 -14
- 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/utils/data-source/formConfigs/base.js +1 -1
- package/dist/es/utils/data-source/formConfigs/http.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/tmagic-editor-headless.umd.cjs +4690 -2891
- package/dist/tmagic-editor-sdk.umd.cjs +9911 -0
- package/dist/tmagic-editor.umd.cjs +14200 -13381
- package/package.json +12 -7
- package/src/Editor.vue +17 -10
- package/src/editorProps.ts +5 -2
- 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 +1 -1
- package/src/index.ts +11 -9
- package/src/initService.ts +59 -188
- package/src/layouts/Framework.vue +1 -1
- package/src/layouts/props-panel/FormPanel.vue +8 -5
- package/src/layouts/props-panel/PropsPanel.vue +8 -3
- package/src/layouts/props-panel/use-style-panel.ts +1 -1
- 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} +24 -11
- 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/type.ts +9 -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 +742 -528
- package/types/sdk.d.ts +2572 -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.3",
|
|
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/
|
|
69
|
-
"@tmagic/
|
|
70
|
-
"@tmagic/
|
|
71
|
+
"@tmagic/design": "1.8.3",
|
|
72
|
+
"@tmagic/form": "1.8.3",
|
|
73
|
+
"@tmagic/utils": "1.8.3",
|
|
74
|
+
"@tmagic/stage": "1.8.3",
|
|
75
|
+
"@tmagic/table": "1.8.3"
|
|
71
76
|
},
|
|
72
77
|
"devDependencies": {
|
|
73
78
|
"@types/events": "^3.0.3",
|
|
@@ -81,7 +86,7 @@
|
|
|
81
86
|
"type-fest": "^5.2.0",
|
|
82
87
|
"typescript": "^6.0.3",
|
|
83
88
|
"vue": "^3.5.43",
|
|
84
|
-
"@tmagic/core": "1.8.
|
|
89
|
+
"@tmagic/core": "1.8.3"
|
|
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';
|
|
@@ -236,7 +238,12 @@ provide('services', services);
|
|
|
236
238
|
provide('codeOptions', props.codeOptions);
|
|
237
239
|
provide('stageOptions', stageOptions);
|
|
238
240
|
/** 是否启用「属性配置表单校验」联动能力,供 PropsPanel / FormPanel 判断校验失败时是否仍更新节点并记录错误 */
|
|
239
|
-
|
|
241
|
+
// 同 isLargeStageContainer:用 computed 包一层,否则传下去的是 provide 那一刻的值快照,
|
|
242
|
+
// props.enablePropsFormValidate 后续变化不会同步到子孙。
|
|
243
|
+
provide(
|
|
244
|
+
ENABLE_PROPS_FORM_VALIDATE,
|
|
245
|
+
computed(() => props.enablePropsFormValidate ?? false),
|
|
246
|
+
);
|
|
240
247
|
/**
|
|
241
248
|
* 编辑器注入给整棵表单树的业务上下文(`services` / `stage`),属性面板、对比表单、
|
|
242
249
|
* 侧边栏里的嵌套 MForm 都通过 inject 自动继承。
|
package/src/editorProps.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InjectionKey } from 'vue';
|
|
1
|
+
import type { ComputedRef, InjectionKey } from 'vue';
|
|
2
2
|
|
|
3
3
|
import type { DataSourceSchema, EventOption, Id, MApp, MNode, MPage, MPageFragment } from '@tmagic/core';
|
|
4
4
|
import type { FormConfig } from '@tmagic/form';
|
|
@@ -31,8 +31,11 @@ import type {
|
|
|
31
31
|
/**
|
|
32
32
|
* 「属性配置表单校验」联动能力的 provide/inject 注入键。
|
|
33
33
|
* 使用 Symbol 避免与其它字符串键冲突,供 PropsPanel / FormPanel 注入判断校验失败时是否仍更新节点并记录错误。
|
|
34
|
+
*
|
|
35
|
+
* 注入值是 ComputedRef:Editor 用 `computed(() => props.enablePropsFormValidate ?? false)` 提供,
|
|
36
|
+
* 保证外部动态切换该 prop 时子孙组件能同步拿到最新值;子孙侧用 `.value` 读取。
|
|
34
37
|
*/
|
|
35
|
-
export const ENABLE_PROPS_FORM_VALIDATE: InjectionKey<boolean
|
|
38
|
+
export const ENABLE_PROPS_FORM_VALIDATE: InjectionKey<ComputedRef<boolean>> = Symbol('enablePropsFormValidate');
|
|
36
39
|
|
|
37
40
|
export interface EditorProps {
|
|
38
41
|
/** 是否是大屏模拟器容器,大屏容器时,左侧属性面板会扩展为两列(正常3列),颜色表单不扩展两列等 */
|
|
@@ -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';
|
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';
|