@tmagic/editor 1.8.0-beta.24 → 1.8.0-beta.26
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 +10 -16
- package/dist/es/components/CodeParams.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +5 -8
- package/dist/es/components/ViewForm.vue_vue_type_script_setup_true_lang.js +3 -5
- package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +3 -11
- package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +29 -124
- package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +5 -6
- package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +3 -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 +7 -6
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +6 -10
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +5 -7
- package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +1 -4
- package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +4 -6
- package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DisplayConds.vue_vue_type_script_setup_true_lang.js +9 -137
- package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +51 -326
- package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +2 -4
- package/dist/es/fields/StyleSetter/components/Border.vue_vue_type_script_setup_true_lang.js +3 -34
- package/dist/es/fields/StyleSetter/configs.js +663 -0
- package/dist/es/fields/StyleSetter/pro/Background.vue_vue_type_script_setup_true_lang.js +5 -108
- package/dist/es/fields/StyleSetter/pro/Border.vue_vue_type_script_setup_true_lang.js +3 -9
- package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +6 -103
- package/dist/es/fields/StyleSetter/pro/Layout.vue_vue_type_script_setup_true_lang.js +5 -265
- package/dist/es/fields/StyleSetter/pro/Position.vue_vue_type_script_setup_true_lang.js +5 -85
- package/dist/es/fields/StyleSetter/pro/Transform.vue_vue_type_script_setup_true_lang.js +3 -22
- package/dist/es/fields/configs/codeSelect.js +98 -0
- package/dist/es/fields/configs/displayConds.js +158 -0
- package/dist/es/fields/configs/eventSelect.js +225 -0
- package/dist/es/fields/configs/stickyAddButton.js +20 -0
- package/dist/es/fields/headless-validation.js +139 -0
- package/dist/es/headless.js +2 -0
- package/dist/es/hooks/use-compare-form.js +6 -23
- package/dist/es/hooks/use-form-context.js +19 -0
- package/dist/es/index.js +3 -2
- package/dist/es/initService.js +17 -1
- package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +1 -7
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +1 -11
- package/dist/es/layouts/history-list/useHistoryRevert.js +3 -11
- package/dist/es/layouts/props-panel/FormPanel.vue_vue_type_script_setup_true_lang.js +10 -23
- package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +3 -13
- package/dist/es/layouts/sidebar/code-block/CodeBlockListPanel.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/code-block/useContentMenu.js +1 -1
- package/dist/es/layouts/sidebar/data-source/DataSourceListPanel.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/data-source/useContentMenu.js +1 -1
- package/dist/es/plugin.js +33 -32
- package/dist/es/style.css +120 -60
- package/dist/es/utils/data-source/index.js +2 -1
- package/dist/es/utils/props.js +1 -4
- package/dist/es/utils/type-match-rules.js +23 -22
- package/dist/style.css +120 -60
- package/dist/themes/magic-admin.css +132 -67
- package/dist/tmagic-editor-headless.umd.cjs +10867 -0
- package/dist/tmagic-editor.umd.cjs +2151 -2034
- package/package.json +12 -7
- package/src/Editor.vue +12 -16
- package/src/components/CodeParams.vue +10 -4
- package/src/components/CompareForm.vue +4 -5
- package/src/components/ViewForm.vue +2 -3
- package/src/editorProps.ts +1 -2
- package/src/fields/Code.vue +2 -10
- package/src/fields/CodeSelect.vue +20 -116
- package/src/fields/CodeSelectCol.vue +3 -5
- package/src/fields/CondOpSelect.vue +3 -2
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +1 -1
- package/src/fields/DataSourceFieldSelect/Index.vue +7 -6
- package/src/fields/DataSourceFields.vue +0 -7
- package/src/fields/DataSourceMethodSelect.vue +2 -5
- package/src/fields/DataSourceMethods.vue +1 -6
- package/src/fields/DataSourceMocks.vue +1 -10
- package/src/fields/DataSourceSelect.vue +1 -1
- package/src/fields/DisplayConds.vue +17 -153
- package/src/fields/EventSelect.vue +28 -375
- package/src/fields/KeyValue.vue +3 -4
- package/src/fields/StyleSetter/components/Border.vue +4 -38
- package/src/fields/StyleSetter/configs.ts +690 -0
- package/src/fields/StyleSetter/pro/Background.vue +4 -104
- package/src/fields/StyleSetter/pro/Border.vue +3 -12
- package/src/fields/StyleSetter/pro/Font.vue +5 -124
- package/src/fields/StyleSetter/pro/Layout.vue +4 -219
- package/src/fields/StyleSetter/pro/Position.vue +6 -110
- package/src/fields/StyleSetter/pro/Transform.vue +4 -30
- package/src/fields/configs/codeSelect.ts +127 -0
- package/src/fields/configs/displayConds.ts +184 -0
- package/src/fields/configs/eventSelect.ts +309 -0
- package/src/fields/configs/stickyAddButton.ts +31 -0
- package/src/fields/headless-validation.ts +177 -0
- package/src/headless.ts +33 -0
- package/src/hooks/use-compare-form.ts +7 -25
- package/src/hooks/use-form-context.ts +40 -0
- package/src/index.ts +2 -0
- package/src/initService.ts +23 -1
- package/src/layouts/history-list/HistoryDiffDialog.vue +0 -10
- package/src/layouts/history-list/HistoryListPanel.vue +1 -13
- package/src/layouts/history-list/useHistoryRevert.ts +7 -13
- package/src/layouts/props-panel/FormPanel.vue +17 -28
- package/src/layouts/props-panel/PropsPanel.vue +1 -4
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +1 -1
- package/src/layouts/sidebar/code-block/useContentMenu.ts +1 -1
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +1 -1
- package/src/layouts/sidebar/data-source/useContentMenu.ts +1 -1
- package/src/plugin.ts +32 -33
- package/src/theme/code-block.scss +0 -37
- package/src/theme/display-conds.scss +4 -0
- package/src/theme/event.scss +22 -45
- package/src/theme/props-panel.scss +17 -3
- package/src/theme/themes/magic-admin/index.scss +12 -1
- package/src/type.ts +10 -29
- package/src/utils/data-source/index.ts +1 -0
- package/src/utils/props.ts +1 -4
- package/src/utils/type-match-rules.ts +37 -31
- package/types/headless.d.ts +18 -0
- package/types/index.d.ts +155 -180
|
@@ -18,9 +18,14 @@
|
|
|
18
18
|
|
|
19
19
|
import type { DataSourceFieldType, DataSourceSchema, Id } from '@tmagic/core';
|
|
20
20
|
import { NodeType } from '@tmagic/core';
|
|
21
|
-
import { appendValidateSuggestion } from '@tmagic/design';
|
|
22
|
-
import type { TypeMatchValidateContext, TypeMatchValidator } from '@tmagic/form';
|
|
23
|
-
import {
|
|
21
|
+
import { appendValidateSuggestion } from '@tmagic/design/headless';
|
|
22
|
+
import type { TypeMatchValidateContext, TypeMatchValidator } from '@tmagic/form/headless';
|
|
23
|
+
import {
|
|
24
|
+
MAX_SUGGESTION_OPTIONS,
|
|
25
|
+
optionSuggestion,
|
|
26
|
+
stringifyExampleValue,
|
|
27
|
+
validateTypeMatch,
|
|
28
|
+
} from '@tmagic/form/headless';
|
|
24
29
|
import {
|
|
25
30
|
DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX,
|
|
26
31
|
DATA_SOURCE_SET_DATA_METHOD_NAME,
|
|
@@ -209,7 +214,6 @@ const validateDataSourceFieldPath = (
|
|
|
209
214
|
path: string[],
|
|
210
215
|
options: {
|
|
211
216
|
dataSourceId?: string;
|
|
212
|
-
valueMode?: 'key' | 'value';
|
|
213
217
|
dataSourceFieldType?: DataSourceFieldType[];
|
|
214
218
|
message?: string;
|
|
215
219
|
} = {},
|
|
@@ -219,19 +223,11 @@ const validateDataSourceFieldPath = (
|
|
|
219
223
|
return undefined;
|
|
220
224
|
}
|
|
221
225
|
|
|
222
|
-
|
|
223
|
-
let fieldNames = path;
|
|
224
|
-
|
|
226
|
+
const dsId = options.dataSourceId;
|
|
225
227
|
if (!dsId) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const rawDsId = path[0];
|
|
230
|
-
dsId =
|
|
231
|
-
options.valueMode === 'key' || !`${rawDsId}`.startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)
|
|
232
|
-
? `${rawDsId}`
|
|
233
|
-
: removeDataSourceFieldPrefix(`${rawDsId}`);
|
|
234
|
-
fieldNames = path.slice(1);
|
|
228
|
+
// 仅当取值为空数组或首项为空串时命中。表单校验管道里 validateTypeMatch 对空数组会短路,
|
|
229
|
+
// 因此这里只可能来自直接调用 validateDataSourceFieldSelect 的自定义 validator
|
|
230
|
+
return defaultMessage(options.message, '数据源不存在', dataSourceIdSuggestion());
|
|
235
231
|
}
|
|
236
232
|
|
|
237
233
|
const ds = findDataSource(`${dsId}`);
|
|
@@ -239,11 +235,11 @@ const validateDataSourceFieldPath = (
|
|
|
239
235
|
return defaultMessage(options.message, `数据源(${dsId})不存在`, dataSourceIdSuggestion());
|
|
240
236
|
}
|
|
241
237
|
|
|
242
|
-
if (!
|
|
238
|
+
if (!path.length) {
|
|
243
239
|
return undefined;
|
|
244
240
|
}
|
|
245
241
|
|
|
246
|
-
const { field, ok, fields, failedName } = resolveFieldByPath(ds.fields,
|
|
242
|
+
const { field, ok, fields, failedName } = resolveFieldByPath(ds.fields, path);
|
|
247
243
|
if (!ok) {
|
|
248
244
|
return defaultMessage(
|
|
249
245
|
options.message,
|
|
@@ -258,11 +254,15 @@ const validateDataSourceFieldPath = (
|
|
|
258
254
|
}
|
|
259
255
|
|
|
260
256
|
const leafType = field?.type || 'any';
|
|
261
|
-
if (leafType
|
|
262
|
-
|
|
263
|
-
}
|
|
257
|
+
if (leafType !== 'any' && !allowedTypes.includes(leafType)) {
|
|
258
|
+
const fieldName = field?.name || path[path.length - 1];
|
|
264
259
|
|
|
265
|
-
|
|
260
|
+
// 文案已点明当前字段类型与要求类型,无需再列同级可选字段
|
|
261
|
+
return defaultMessage(
|
|
262
|
+
options.message,
|
|
263
|
+
`请选择类型为${allowedTypes.join('或')}的字段,字段(${fieldName})的类型为${leafType}`,
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
266
|
};
|
|
267
267
|
|
|
268
268
|
const validateDataSourceMethodTuple = (value: any, message?: string): string | undefined => {
|
|
@@ -367,7 +367,7 @@ const validateCondOpSelect: TypeMatchValidator = (value, { message, props }) =>
|
|
|
367
367
|
const parentFields = props.config?.parentFields || [];
|
|
368
368
|
const fieldPath = Array.isArray(props.model?.field) ? props.model.field : [];
|
|
369
369
|
const [id, ...fieldNames] = [...parentFields, ...fieldPath];
|
|
370
|
-
const ds = id ? findDataSource(`${id}`) : undefined;
|
|
370
|
+
const ds = id ? findDataSource(removeDataSourceFieldPrefix(`${id}`)) : undefined;
|
|
371
371
|
const fieldType = getFieldType(ds, fieldNames);
|
|
372
372
|
const allowed = getCondOpsByFieldType(fieldType);
|
|
373
373
|
|
|
@@ -464,7 +464,7 @@ export type ValidateDataSourceFieldSelectOptions = {
|
|
|
464
464
|
/**
|
|
465
465
|
* data-source-field-select 的 typeMatch 校验逻辑,可供自定义 rules.validator 复用。
|
|
466
466
|
*/
|
|
467
|
-
export const
|
|
467
|
+
export const validateDataSourceFieldSelect = (
|
|
468
468
|
value: any,
|
|
469
469
|
context: TypeMatchValidateContext,
|
|
470
470
|
options?: ValidateDataSourceFieldSelectOptions,
|
|
@@ -492,17 +492,22 @@ export const validateDataSourceFieldSelectValue = (
|
|
|
492
492
|
return defaultMessage(message, `${value}类型应为字符串数组`, dataSourceFieldPathSuggestion());
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
495
|
+
// 未指定 dataSourceId 时,路径首项为数据源 id,其余为字段名。
|
|
496
|
+
// value 模式的首项带 ds-field:: 前缀、key 模式不带,removeDataSourceFieldPrefix 对后者是幂等的,无需分支。
|
|
497
|
+
let dataSourceId = config.dataSourceId ? `${config.dataSourceId}` : undefined;
|
|
498
|
+
let fieldNames = value;
|
|
499
|
+
if (!dataSourceId) {
|
|
500
|
+
dataSourceId = value.length ? removeDataSourceFieldPrefix(value[0]) : undefined;
|
|
501
|
+
fieldNames = value.slice(1);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return validateDataSourceFieldPath(fieldNames, {
|
|
505
|
+
dataSourceId,
|
|
498
506
|
dataSourceFieldType: config.dataSourceFieldType,
|
|
499
507
|
message,
|
|
500
508
|
});
|
|
501
509
|
};
|
|
502
510
|
|
|
503
|
-
const validateDataSourceFieldSelect: TypeMatchValidator = (value, context) =>
|
|
504
|
-
validateDataSourceFieldSelectValue(value, context);
|
|
505
|
-
|
|
506
511
|
const validateDataSourceSelect: TypeMatchValidator = (value, { message, props }) => {
|
|
507
512
|
const config = props.config || {};
|
|
508
513
|
const dataSources = getDataSources();
|
|
@@ -678,7 +683,8 @@ export const editorTypeMatchRules: Record<string, TypeMatchValidator> = {
|
|
|
678
683
|
'ui-select': validateUiSelect,
|
|
679
684
|
'data-source-input': validateDataSourceInput,
|
|
680
685
|
'data-source-method-select': validateDataSourceMethodSelect,
|
|
681
|
-
|
|
686
|
+
/** 注册进 typeMatch 规则表的入口,收窄为 TypeMatchValidator,避免调用方误传第三个参数 */
|
|
687
|
+
'data-source-field-select': (value, context) => validateDataSourceFieldSelect(value, context),
|
|
682
688
|
'data-source-select': validateDataSourceSelect,
|
|
683
689
|
'code-select': validateCodeSelect,
|
|
684
690
|
'data-source-fields': validateDataSourceFields,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HeadlessFieldOptions } from "@tmagic/form/headless";
|
|
2
|
+
//#region temp/packages/editor/src/fields/headless-validation.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* 编辑器字段的无渲染登记表(不含 Vue 组件)。
|
|
5
|
+
*
|
|
6
|
+
* Node 里 `registerFields(editorFields)` 即可配合 `validateForm` / `submitForm`。
|
|
7
|
+
* 安装编辑器时由 plugin 把 `component` 叠上去再传给 `@tmagic/form`。
|
|
8
|
+
*
|
|
9
|
+
* - 叶子:内部只渲染叶子 UI,或把子表单渲染在独立的 MForm / MFormBox 实例里
|
|
10
|
+
* - innerConfig:内部再渲染 MContainer / MPanel / MGroupList,把运行期配置交出来
|
|
11
|
+
* - typeMatch:该 type 自身的类型匹配校验
|
|
12
|
+
*
|
|
13
|
+
* innerConfig 返回的 config / model / prop 与组件模板里传给内部容器的那一组保持一一对应,
|
|
14
|
+
* 且配置本身与组件共用同一份工厂(`fields/configs/`)。
|
|
15
|
+
*/
|
|
16
|
+
declare const editorFields: Record<string, HeadlessFieldOptions>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { editorFields };
|