@tmagic/editor 1.8.0-beta.21 → 1.8.0-beta.23

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.
Files changed (37) hide show
  1. package/dist/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +2 -1
  2. package/dist/es/components/Resizer.vue_vue_type_script_setup_true_lang.js +2 -1
  3. package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +3 -1
  4. package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +2 -1
  5. package/dist/es/fields/DataSourceInput.vue_vue_type_script_setup_true_lang.js +2 -1
  6. package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +2 -1
  7. package/dist/es/fields/DisplayConds.vue_vue_type_script_setup_true_lang.js +4 -2
  8. package/dist/es/fields/StyleSetter/components/Box.vue_vue_type_script_setup_true_lang.js +2 -2
  9. package/dist/es/fields/StyleSetter/pro/Background.vue_vue_type_script_setup_true_lang.js +6 -1
  10. package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +35 -3
  11. package/dist/es/fields/StyleSetter/pro/Position.vue_vue_type_script_setup_true_lang.js +26 -5
  12. package/dist/es/index.js +2 -2
  13. package/dist/es/initService.js +2 -1
  14. package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +23 -12
  15. package/dist/es/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +1 -1
  16. package/dist/es/layouts/sidebar/Sidebar.vue_vue_type_script_setup_true_lang.js +2 -1
  17. package/dist/es/layouts/sidebar/data-source/DataSourceConfigPanel.vue_vue_type_script_setup_true_lang.js +2 -1
  18. package/dist/es/layouts/sidebar/layer/LayerPanel.vue_vue_type_script_setup_true_lang.js +3 -2
  19. package/dist/es/services/codeBlock.js +4 -2
  20. package/dist/es/services/editor.js +12 -8
  21. package/dist/es/utils/dep/collect-worker-client.js +67 -27
  22. package/dist/es/utils/dep/worker.js +1 -1
  23. package/dist/es/utils/type-match-rules.js +24 -36
  24. package/dist/tmagic-editor.umd.cjs +413 -306
  25. package/package.json +12 -12
  26. package/src/fields/StyleSetter/components/Box.vue +1 -1
  27. package/src/fields/StyleSetter/components/Position.vue +1 -1
  28. package/src/fields/StyleSetter/pro/Background.vue +7 -0
  29. package/src/fields/StyleSetter/pro/Font.vue +57 -0
  30. package/src/fields/StyleSetter/pro/Position.vue +31 -0
  31. package/src/layouts/props-panel/PropsPanel.vue +30 -16
  32. package/src/layouts/sidebar/ComponentListPanel.vue +5 -1
  33. package/src/layouts/sidebar/layer/LayerPanel.vue +1 -1
  34. package/src/services/editor.ts +27 -8
  35. package/src/utils/dep/collect-worker-client.ts +97 -31
  36. package/src/utils/type-match-rules.ts +41 -34
  37. package/types/index.d.ts +106 -153
@@ -20,7 +20,7 @@ import type { DataSourceFieldType, DataSourceSchema, Id } from '@tmagic/core';
20
20
  import { NodeType } from '@tmagic/core';
21
21
  import { appendValidateSuggestion } from '@tmagic/design';
22
22
  import type { TypeMatchValidateContext, TypeMatchValidator } from '@tmagic/form';
23
- import { validateTypeMatch } from '@tmagic/form';
23
+ import { MAX_SUGGESTION_OPTIONS, optionSuggestion, stringifyExampleValue, validateTypeMatch } from '@tmagic/form';
24
24
  import {
25
25
  DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX,
26
26
  DATA_SOURCE_SET_DATA_METHOD_NAME,
@@ -41,35 +41,9 @@ import {
41
41
  numberOptions,
42
42
  } from '@editor/utils/props';
43
43
 
44
- /**
45
- * 将值格式化为可读的参考示例字符串。
46
- */
47
- const stringifyExampleValue = (value: any): string => {
48
- if (typeof value === 'string') return `"${value}"`;
49
- if (value === null || value === undefined) return String(value);
50
- if (typeof value === 'object') {
51
- try {
52
- return JSON.stringify(value);
53
- } catch {
54
- return String(value);
55
- }
56
- }
57
- return String(value);
58
- };
59
-
60
- // 参考建议中最多展示的可选值个数,超出以「等」省略。
61
- const MAX_SUGGESTION_OPTIONS = 20;
62
-
63
- /**
64
- * 生成「请使用以下某一个值:xxx;xxx」形式的参考建议;无可选值时返回空字符串(不追加建议)。
65
- */
66
- const listSuggestion = (values: any[]): string => {
67
- const list = values.filter((item) => typeof item !== 'undefined' && item !== null && item !== '');
68
- if (!list.length) return '';
69
- const shown = list.slice(0, MAX_SUGGESTION_OPTIONS).map(stringifyExampleValue);
70
- const suffix = list.length > MAX_SUGGESTION_OPTIONS ? ' 等' : '';
71
- return `请使用以下某一个值:${shown.join(';')}${suffix}`;
72
- };
44
+ /** 复用 form 的可选项建议文案;额外过滤 null / 空串,避免业务侧无效枚举污染提示。 */
45
+ const listSuggestion = (values: any[]): string =>
46
+ optionSuggestion(values.filter((item) => item !== null && item !== ''));
73
47
 
74
48
  /**
75
49
  * 列出当前可用数据源 id 的参考建议。
@@ -476,12 +450,42 @@ const isDataSourceFieldPathValue = (value: any, config: any): value is string[]
476
450
  return `${value[0]}`.startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX);
477
451
  };
478
452
 
479
- const validateDataSourceFieldSelect: TypeMatchValidator = (value, { mForm, message, props }) => {
453
+ export type ValidateDataSourceFieldSelectOptions = {
454
+ /**
455
+ * 覆盖「非数据源字段路径」时的校验。
456
+ * 不传则按 fieldConfig 走内置 typeMatch(与表单项自身 typeMatch 行为一致)。
457
+ */
458
+ validatePlainValue?: (
459
+ value: any,
460
+ context: TypeMatchValidateContext,
461
+ ) => string | undefined | Promise<string | undefined>;
462
+ };
463
+
464
+ /**
465
+ * data-source-field-select 的 typeMatch 校验逻辑,可供自定义 rules.validator 复用。
466
+ */
467
+ export const validateDataSourceFieldSelectValue = (
468
+ value: any,
469
+ context: TypeMatchValidateContext,
470
+ options?: ValidateDataSourceFieldSelectOptions,
471
+ ): string | undefined | Promise<string | undefined> => {
472
+ const { mForm, message, props } = context;
480
473
  const config = props.config || {};
481
474
 
482
- if (config.fieldConfig && !isDataSourceFieldPathValue(value, config)) {
483
- // 值不是数据源字段路径时,按 fieldConfig 的类型校验(与表单项自身 typeMatch 行为一致)
484
- return validateTypeMatch(value, mForm, { ...props, config: { name: config.name, ...config.fieldConfig } }, message);
475
+ if (!isDataSourceFieldPathValue(value, config)) {
476
+ if (options?.validatePlainValue) {
477
+ return options.validatePlainValue(value, context);
478
+ }
479
+
480
+ if (config.fieldConfig) {
481
+ // 值不是数据源字段路径时,按 fieldConfig 的类型校验(与表单项自身 typeMatch 行为一致)
482
+ return validateTypeMatch(
483
+ value,
484
+ mForm,
485
+ { ...props, config: { name: config.name, ...config.fieldConfig } },
486
+ message,
487
+ );
488
+ }
485
489
  }
486
490
 
487
491
  if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) {
@@ -496,6 +500,9 @@ const validateDataSourceFieldSelect: TypeMatchValidator = (value, { mForm, messa
496
500
  });
497
501
  };
498
502
 
503
+ const validateDataSourceFieldSelect: TypeMatchValidator = (value, context) =>
504
+ validateDataSourceFieldSelectValue(value, context);
505
+
499
506
  const validateDataSourceSelect: TypeMatchValidator = (value, { message, props }) => {
500
507
  const config = props.config || {};
501
508
  const dataSources = getDataSources();