@tmagic/editor 1.8.0-beta.20 → 1.8.0-beta.22

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 (31) hide show
  1. package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +5 -2
  2. package/dist/es/fields/StyleSetter/components/Box.vue_vue_type_script_setup_true_lang.js +2 -2
  3. package/dist/es/fields/StyleSetter/pro/Background.vue_vue_type_script_setup_true_lang.js +6 -1
  4. package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +35 -3
  5. package/dist/es/fields/StyleSetter/pro/Position.vue_vue_type_script_setup_true_lang.js +26 -5
  6. package/dist/es/index.js +2 -2
  7. package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +23 -12
  8. package/dist/es/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +1 -1
  9. package/dist/es/layouts/sidebar/layer/LayerPanel.vue_vue_type_script_setup_true_lang.js +1 -1
  10. package/dist/es/services/editor.js +12 -8
  11. package/dist/es/services/events.js +2 -2
  12. package/dist/es/utils/dep/idle-task.js +28 -5
  13. package/dist/es/utils/event.js +19 -7
  14. package/dist/es/utils/type-match-rules.js +17 -9
  15. package/dist/tmagic-editor.umd.cjs +173 -57
  16. package/package.json +7 -7
  17. package/src/fields/EventSelect.vue +7 -5
  18. package/src/fields/StyleSetter/components/Box.vue +1 -1
  19. package/src/fields/StyleSetter/components/Position.vue +1 -1
  20. package/src/fields/StyleSetter/pro/Background.vue +7 -0
  21. package/src/fields/StyleSetter/pro/Font.vue +57 -0
  22. package/src/fields/StyleSetter/pro/Position.vue +31 -0
  23. package/src/layouts/props-panel/PropsPanel.vue +30 -16
  24. package/src/layouts/sidebar/ComponentListPanel.vue +5 -1
  25. package/src/layouts/sidebar/layer/LayerPanel.vue +1 -1
  26. package/src/services/editor.ts +27 -8
  27. package/src/services/events.ts +3 -3
  28. package/src/utils/dep/idle-task.ts +43 -11
  29. package/src/utils/event.ts +25 -12
  30. package/src/utils/type-match-rules.ts +37 -4
  31. package/types/index.d.ts +33 -4
@@ -15,6 +15,7 @@
15
15
  </template>
16
16
 
17
17
  <script lang="ts" setup>
18
+ import { appendValidateSuggestion } from '@tmagic/design';
18
19
  import { type ContainerChangeEventData, defineFormConfig, MContainer } from '@tmagic/form';
19
20
  import type { StyleSchema } from '@tmagic/schema';
20
21
 
@@ -66,6 +67,12 @@ const formConfig = defineFormConfig([
66
67
  fieldConfig: {
67
68
  type: 'text',
68
69
  },
70
+ rules: [
71
+ {
72
+ typeMatch: true,
73
+ message: appendValidateSuggestion('left 应为字符串', '请参考以下示例值:"10"'),
74
+ },
75
+ ],
69
76
  },
70
77
  {
71
78
  name: 'top',
@@ -74,6 +81,12 @@ const formConfig = defineFormConfig([
74
81
  fieldConfig: {
75
82
  type: 'text',
76
83
  },
84
+ rules: [
85
+ {
86
+ typeMatch: true,
87
+ message: appendValidateSuggestion('top 应为字符串', '请参考以下示例值:"10"'),
88
+ },
89
+ ],
77
90
  },
78
91
  ],
79
92
  },
@@ -89,6 +102,12 @@ const formConfig = defineFormConfig([
89
102
  fieldConfig: {
90
103
  type: 'text',
91
104
  },
105
+ rules: [
106
+ {
107
+ typeMatch: true,
108
+ message: appendValidateSuggestion('right 应为字符串', '请参考以下示例值:"10"'),
109
+ },
110
+ ],
92
111
  },
93
112
  {
94
113
  name: 'bottom',
@@ -97,6 +116,12 @@ const formConfig = defineFormConfig([
97
116
  fieldConfig: {
98
117
  type: 'text',
99
118
  },
119
+ rules: [
120
+ {
121
+ typeMatch: true,
122
+ message: appendValidateSuggestion('bottom 应为字符串', '请参考以下示例值:"10"'),
123
+ },
124
+ ],
100
125
  },
101
126
  ],
102
127
  },
@@ -108,6 +133,12 @@ const formConfig = defineFormConfig([
108
133
  fieldConfig: {
109
134
  type: 'text',
110
135
  },
136
+ rules: [
137
+ {
138
+ typeMatch: true,
139
+ message: appendValidateSuggestion('zIndex 应为数字', '请参考以下示例值:10'),
140
+ },
141
+ ],
111
142
  },
112
143
  ]);
113
144
 
@@ -158,14 +158,34 @@ const submit = async (
158
158
  v.id = values.value.id;
159
159
  }
160
160
 
161
- const newValue: MNode = {
162
- ...v,
163
- style: {},
164
- };
165
-
166
- if (v.style) {
167
- // 空字符串样式值表示「清除该样式」,需保留才能在 doUpdate 的 mergeWith 中覆盖旧值。
168
- if (eventData) {
161
+ // 区分操作途径:表单字段编辑(MForm @change)会带上 eventData(含 changeRecords);
162
+ // 源码编辑器(CodeEditor @save → saveCode)保存时不带 eventData,据此标记为「源码编辑器」。
163
+ const historySource = eventData ? 'props' : 'code';
164
+ // 源码编辑统一走整节点 replace,避免 merge 保留已删除字段。
165
+ const replace = historySource === 'code';
166
+
167
+ let newValue: MNode;
168
+
169
+ if (replace) {
170
+ if (source === 'style') {
171
+ // 样式面板源码仅提交 { style }:先把新 style 替换到原节点上,再整节点覆盖。
172
+ newValue = {
173
+ ...values.value,
174
+ id: v.id || values.value.id,
175
+ style: { ...(v.style || {}) },
176
+ };
177
+ } else {
178
+ // 属性面板源码提交完整节点 DSL
179
+ newValue = { ...v };
180
+ }
181
+ } else {
182
+ newValue = {
183
+ ...v,
184
+ style: {},
185
+ };
186
+
187
+ if (v.style) {
188
+ // 空字符串样式值表示「清除该样式」,需保留才能在 doUpdate 的 mergeWith 中覆盖旧值。
169
189
  // 表单编辑:先过滤掉空字符串(避免表单默认空值污染 DSL),
170
190
  // 再按 changeRecords 恢复被主动清空的字段。
171
191
  Object.entries(v.style).forEach(([key, value]) => {
@@ -174,24 +194,18 @@ const submit = async (
174
194
  }
175
195
  });
176
196
 
177
- eventData.changeRecords?.forEach((record) => {
197
+ eventData?.changeRecords?.forEach((record) => {
178
198
  if (record.propPath?.startsWith('style') && record.value === '') {
179
199
  setValueByKeyPath(record.propPath, record.value, newValue);
180
200
  }
181
201
  });
182
- } else {
183
- // 源码编辑器保存(无 eventData):style 原样保留,其中的空字符串视为用户主动清除该样式。
184
- newValue.style = { ...v.style };
185
202
  }
186
203
  }
187
204
 
188
- // 区分操作途径:表单字段编辑(MForm @change)会带上 eventData(含 changeRecords);
189
- // 源码编辑器(CodeEditor @save → saveCode)保存时不带 eventData,据此标记为「源码编辑器」。
190
- const historySource = eventData ? 'props' : 'code';
191
-
192
205
  editorService.update(newValue, {
193
206
  changeRecords: eventData?.changeRecords,
194
207
  historySource,
208
+ replace,
195
209
  // 启用校验联动时,仅校验失败(error 存在)才把错误信息随更新传入 editorService 记录;
196
210
  // 其余情况(含表单校验成功、CodeEditor 源码保存)不携带 invalidInfo,由 editorService 在执行 update 时统一清除该节点错误。
197
211
  ...(enablePropsFormValidate && error ? { invalidInfo: { id: newValue.id, source, error: error?.message } } : {}),
@@ -71,7 +71,11 @@ const stage = computed(() => editorService.get('stage'));
71
71
  const list = computed<ComponentGroup[]>(() =>
72
72
  componentListService.getList().map((group: ComponentGroup) => ({
73
73
  ...group,
74
- items: group.items.filter((item: ComponentItem) => item.text.includes(searchText.value)),
74
+ items: group.items.filter((item: ComponentItem) =>
75
+ `${item.text || ''}${item.desc || ''}${item.type}`
76
+ .toLocaleLowerCase()
77
+ .includes(searchText.value.toLocaleLowerCase()),
78
+ ),
75
79
  })),
76
80
  );
77
81
 
@@ -120,7 +120,7 @@ const filterNodeMethod = (v: string, data: MNode): boolean => {
120
120
  name = 'container';
121
121
  }
122
122
 
123
- return `${data.id}${name}${data.type}`.includes(v);
123
+ return `${data.id}${name}${data.type || ''}`.toLocaleLowerCase().includes(v.toLocaleLowerCase());
124
124
  };
125
125
 
126
126
  const { filterTextChangeHandler } = useFilter(nodeData, nodeStatusMap, filterNodeMethod);
@@ -720,7 +720,11 @@ class Editor extends BaseService {
720
720
 
721
721
  public async doUpdate(
722
722
  config: MNode,
723
- { changeRecords = [], historySource }: { changeRecords?: ChangeRecord[]; historySource?: HistoryOpSource } = {},
723
+ {
724
+ changeRecords = [],
725
+ historySource,
726
+ replace = false,
727
+ }: { changeRecords?: ChangeRecord[]; historySource?: HistoryOpSource; replace?: boolean } = {},
724
728
  ): Promise<{ newNode: MNode; oldNode: MNode; changeRecords?: ChangeRecord[] }> {
725
729
  const root = this.get('root');
726
730
  if (!root) throw new Error('root为空');
@@ -733,9 +737,14 @@ class Editor extends BaseService {
733
737
 
734
738
  const node = toRaw(info.node);
735
739
 
736
- let newConfig = await toggleFixedPosition(toRaw(config), node, info.path, this.getLayout);
740
+ // replace=true 时跳过 toggleFixedPosition / mergeWith / setChildrenLayout,直接用传入配置整节点替换
741
+ let newConfig = replace
742
+ ? cloneDeep(toRaw(config))
743
+ : await toggleFixedPosition(toRaw(config), node, info.path, this.getLayout);
737
744
 
738
- newConfig = mergeWith(cloneDeep(node), newConfig, editorNodeMergeCustomizer);
745
+ if (!replace) {
746
+ newConfig = mergeWith(cloneDeep(node), newConfig, editorNodeMergeCustomizer);
747
+ }
739
748
 
740
749
  if (!newConfig.type) throw new Error('配置缺少type值');
741
750
 
@@ -756,10 +765,12 @@ class Editor extends BaseService {
756
765
 
757
766
  if (!parentNodeItems || typeof index === 'undefined' || index === -1) throw new Error('更新的节点未找到');
758
767
 
759
- const newLayout = await this.getLayout(newConfig);
760
- const layout = await this.getLayout(node);
761
- if (Array.isArray(newConfig.items) && newLayout !== layout) {
762
- newConfig = setChildrenLayout(newConfig as MContainer, newLayout);
768
+ if (!replace) {
769
+ const newLayout = await this.getLayout(newConfig);
770
+ const layout = await this.getLayout(node);
771
+ if (Array.isArray(newConfig.items) && newLayout !== layout) {
772
+ newConfig = setChildrenLayout(newConfig as MContainer, newLayout);
773
+ }
763
774
  }
764
775
 
765
776
  parentNodeItems[index] = newConfig;
@@ -798,6 +809,7 @@ class Editor extends BaseService {
798
809
  * @param data.changeRecordList 多节点 form 端变更记录列表,按 config 数组同序对应每个节点;优先级高于 changeRecords
799
810
  * @param data.doNotPushHistory 是否不写入历史记录(默认 false)
800
811
  * @param data.historyDescription 入栈时附带的人类可读描述,用于历史面板展示(不影响 undo/redo 行为)
812
+ * @param data.replace 是否整节点替换:为 true 时跳过 mergeWith / toggleFixedPosition / setChildrenLayout,直接用传入配置覆盖(默认 false)
801
813
  * @returns 更新后的节点配置
802
814
  */
803
815
  public async update(
@@ -808,6 +820,11 @@ class Editor extends BaseService {
808
820
  doNotPushHistory?: boolean;
809
821
  historyDescription?: string;
810
822
  historySource?: HistoryOpSource;
823
+ /**
824
+ * 为 true 时不做深合并等变换,直接用传入配置整节点替换现有节点。
825
+ * 适用于源码编辑、历史整节点快照回放等「完整 DSL」场景;默认 false(局部属性更新走 merge)。
826
+ */
827
+ replace?: boolean;
811
828
  /**
812
829
  * 属性面板提交时携带的校验错误信息,在写入历史记录之前落库,
813
830
  * 使历史快照与本次变更对齐,从而 undo/redo 能正确还原错误标记。
@@ -823,6 +840,7 @@ class Editor extends BaseService {
823
840
  changeRecords,
824
841
  historyDescription,
825
842
  historySource,
843
+ replace = false,
826
844
  invalidInfo,
827
845
  } = data;
828
846
 
@@ -833,7 +851,7 @@ class Editor extends BaseService {
833
851
  const updateData = await Promise.all(
834
852
  nodes.map((node, index) => {
835
853
  const recordsForNode = changeRecordList ? (changeRecordList[index] ?? []) : (changeRecords ?? []);
836
- return this.doUpdate(node, { changeRecords: recordsForNode, historySource });
854
+ return this.doUpdate(node, { changeRecords: recordsForNode, historySource, replace });
837
855
  }),
838
856
  );
839
857
 
@@ -1348,6 +1366,7 @@ class Editor extends BaseService {
1348
1366
  doNotPushHistory?: boolean;
1349
1367
  historyDescription?: string;
1350
1368
  historySource?: HistoryOpSource;
1369
+ replace?: boolean;
1351
1370
  } = {},
1352
1371
  ): Promise<DslOpWithHistoryIdsResult<MNode | MNode[]>> {
1353
1372
  this.lastPushedHistoryId = null;
@@ -20,7 +20,7 @@ import { reactive } from 'vue';
20
20
  import { cloneDeep } from 'lodash-es';
21
21
  import type { Writable } from 'type-fest';
22
22
 
23
- import { type EventOption, type Id } from '@tmagic/core';
23
+ import type { EventOption, Id, MNode } from '@tmagic/core';
24
24
  import { toLine } from '@tmagic/utils';
25
25
 
26
26
  import type { AsyncHookPlugin, SyncHookPlugin } from '@editor/type';
@@ -56,7 +56,7 @@ class Events extends BaseService {
56
56
  eventMap[toLine(type)] = [...events];
57
57
  }
58
58
 
59
- public getEvent(type: string): EventOption[] {
59
+ public getEvent(type: string, _data: { node?: MNode | null } = {}): EventOption[] {
60
60
  return cloneDeep(eventMap[toLine(type)]) || [];
61
61
  }
62
62
 
@@ -70,7 +70,7 @@ class Events extends BaseService {
70
70
  methodMap[toLine(type)] = [...method];
71
71
  }
72
72
 
73
- public getMethod(type: string, _targetId: Id) {
73
+ public getMethod(type: string, _data: { node?: MNode | null; targetId?: Id } = {}) {
74
74
  return cloneDeep(methodMap[toLine(type)]) || [];
75
75
  }
76
76
 
@@ -13,6 +13,18 @@ type TaskList<T> = {
13
13
  data: T;
14
14
  }[];
15
15
 
16
+ /**
17
+ * 回调因 timeout 触发(主线程一直没有空闲)时,单次回调执行任务的时间预算,单位 ms
18
+ * 参考一帧内可让出的余量:既保证队列有进展,又不长时间阻塞主线程
19
+ */
20
+ const TIMEOUT_RUN_BUDGET = 5;
21
+
22
+ /**
23
+ * 回调因 timeout 触发时,每两次读取时钟之间执行的任务数
24
+ * 与空闲时间 <=5ms 时的批量保持一致,避免每个任务都读一次时钟
25
+ */
26
+ const TIMEOUT_BATCH_SIZE = 10;
27
+
16
28
  globalThis.requestIdleCallback =
17
29
  globalThis.requestIdleCallback ||
18
30
  function (cb) {
@@ -94,6 +106,19 @@ export class IdleTask<T = any> extends EventEmitter {
94
106
  this.taskHandle = null;
95
107
 
96
108
  try {
109
+ // 主线程一直没有空闲时,回调只会因 timeout 触发,此时 deadline.timeRemaining() 恒为 0(规范行为)。
110
+ // 若仍以它作为循环条件,一个任务都执行不了,而 finishRun 又会接着重新调度,
111
+ // 队列就会无限空转下去:依赖收集永远不结束,collecting 卡在 true,画布也不再更新。
112
+ // 这种情况下改用自有时间预算推进,既保证有进展,又不会像放开循环那样长时间阻塞主线程。
113
+ if (deadline.didTimeout) {
114
+ const start = Date.now();
115
+ do {
116
+ this.runTaskBatch(TIMEOUT_BATCH_SIZE);
117
+ } while (this.getTaskLength() && Date.now() - start < TIMEOUT_RUN_BUDGET);
118
+
119
+ return;
120
+ }
121
+
97
122
  // 动画会占用空闲时间,当任务一直无法执行时,看看是否有动画正在播放
98
123
  // 根据空闲时间的多少来决定执行的任务数,保证页面不卡死的情况下尽量多执行任务,不然当任务数巨大时,执行时间会很久
99
124
  // 执行不完不会影响配置,但是会影响画布渲染
@@ -110,17 +135,7 @@ export class IdleTask<T = any> extends EventEmitter {
110
135
  times = 600;
111
136
  }
112
137
 
113
- for (let i = 0; i < times; i++) {
114
- // 每次都从实例上取队列,任务执行过程中调用 clearTasks 能立即生效,不会继续消费已被清空的旧队列
115
- const task = this.hightLevelTaskList.length > 0 ? this.hightLevelTaskList.shift() : this.taskList.shift();
116
- if (task) {
117
- this.runTask(task);
118
- }
119
-
120
- if (!this.getTaskLength()) {
121
- break;
122
- }
123
- }
138
+ this.runTaskBatch(times);
124
139
  }
125
140
  } finally {
126
141
  // 必须放在 finally 中:一旦这里被跳过,taskHandle 会一直是真值,
@@ -129,6 +144,23 @@ export class IdleTask<T = any> extends EventEmitter {
129
144
  }
130
145
  }
131
146
 
147
+ /**
148
+ * 执行一批任务,队列被清空时提前结束
149
+ */
150
+ private runTaskBatch(times: number) {
151
+ for (let i = 0; i < times; i++) {
152
+ // 每次都从实例上取队列,任务执行过程中调用 clearTasks 能立即生效,不会继续消费已被清空的旧队列
153
+ const task = this.hightLevelTaskList.length > 0 ? this.hightLevelTaskList.shift() : this.taskList.shift();
154
+ if (task) {
155
+ this.runTask(task);
156
+ }
157
+
158
+ if (!this.getTaskLength()) {
159
+ break;
160
+ }
161
+ }
162
+ }
163
+
132
164
  /**
133
165
  * 单个任务失败不能中断整个队列,否则后续任务永远不会被执行,
134
166
  * 依赖收集会停在半路(收集中状态与剩余任务数都不再变化)
@@ -56,7 +56,8 @@ export const getEventNameOptions = (
56
56
  }
57
57
 
58
58
  if (src === 'component') {
59
- let events: EventOption[] | CascaderOption[] = eventsService.getEvent(formValue.type) || [];
59
+ const sourceNode = editorService.getNodeById(formValue.id);
60
+ let events: EventOption[] | CascaderOption[] = eventsService.getEvent(formValue.type, { node: sourceNode }) || [];
60
61
 
61
62
  if (formValue.type === 'page-fragment-container' && formValue.pageFragmentId) {
62
63
  const pageFragment = editorService.get('root')?.items?.find((page) => page.id === formValue.pageFragmentId);
@@ -72,9 +73,14 @@ export const getEventNameOptions = (
72
73
  },
73
74
  ];
74
75
 
75
- (pageFragment.items || []).forEach((node) => {
76
- traverseNode<MComponent | MContainer>(node, (current) => {
77
- const nodeEvents = (current.type && eventsService.getEvent(current.type)) || [];
76
+ (pageFragment.items || []).forEach((item) => {
77
+ traverseNode<MComponent | MContainer>(item, (current) => {
78
+ if (!current.type) {
79
+ return;
80
+ }
81
+
82
+ const node = editorService.getNodeById(current.id) || current;
83
+ const nodeEvents = eventsService.getEvent(current.type, { node }) || [];
78
84
  (events as CascaderOption[]).push({
79
85
  label: `${current.name}_${current.id}`,
80
86
  value: `${current.id}`,
@@ -176,7 +182,7 @@ export const getCompActionOptions = (toId?: Id): EventNameOption[] => {
176
182
  return [];
177
183
  }
178
184
 
179
- let methods: EventOption[] | CascaderOption[] = eventsService.getMethod(node.type, toId) || [];
185
+ let methods: EventOption[] | CascaderOption[] = eventsService.getMethod(node.type, { targetId: toId, node }) || [];
180
186
 
181
187
  if (node.type === 'page-fragment-container' && node.pageFragmentId) {
182
188
  const pageFragment = editorService.get('root')?.items?.find((page) => page.id === node.pageFragmentId);
@@ -187,15 +193,22 @@ export const getCompActionOptions = (toId?: Id): EventNameOption[] => {
187
193
  methods = [];
188
194
  (pageFragment.items || []).forEach((item: MComponent | MContainer) => {
189
195
  traverseNode<MComponent | MContainer>(item, (current) => {
190
- const nodeMethods = (current.type && eventsService.getMethod(current.type, current.id)) || [];
196
+ const node = editorService.getNodeById(current.id) || current;
191
197
 
192
- if (nodeMethods.length) {
193
- (methods as CascaderOption[]).push({
194
- label: `${current.name}_${current.id}`,
195
- value: `${current.id}`,
196
- children: nodeMethods,
197
- });
198
+ if (!current.type) {
199
+ return;
198
200
  }
201
+
202
+ const nodeMethods = eventsService.getMethod(current.type, { targetId: current.id, node }) || [];
203
+ if (!nodeMethods.length) {
204
+ return;
205
+ }
206
+
207
+ (methods as CascaderOption[]).push({
208
+ label: `${current.name}_${current.id}`,
209
+ value: `${current.id}`,
210
+ children: nodeMethods,
211
+ });
199
212
  });
200
213
  });
201
214
 
@@ -476,12 +476,42 @@ const isDataSourceFieldPathValue = (value: any, config: any): value is string[]
476
476
  return `${value[0]}`.startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX);
477
477
  };
478
478
 
479
- const validateDataSourceFieldSelect: TypeMatchValidator = (value, { mForm, message, props }) => {
479
+ export type ValidateDataSourceFieldSelectOptions = {
480
+ /**
481
+ * 覆盖「非数据源字段路径」时的校验。
482
+ * 不传则按 fieldConfig 走内置 typeMatch(与表单项自身 typeMatch 行为一致)。
483
+ */
484
+ validatePlainValue?: (
485
+ value: any,
486
+ context: TypeMatchValidateContext,
487
+ ) => string | undefined | Promise<string | undefined>;
488
+ };
489
+
490
+ /**
491
+ * data-source-field-select 的 typeMatch 校验逻辑,可供自定义 rules.validator 复用。
492
+ */
493
+ export const validateDataSourceFieldSelectValue = (
494
+ value: any,
495
+ context: TypeMatchValidateContext,
496
+ options?: ValidateDataSourceFieldSelectOptions,
497
+ ): string | undefined | Promise<string | undefined> => {
498
+ const { mForm, message, props } = context;
480
499
  const config = props.config || {};
481
500
 
482
- if (config.fieldConfig && !isDataSourceFieldPathValue(value, config)) {
483
- // 值不是数据源字段路径时,按 fieldConfig 的类型校验(与表单项自身 typeMatch 行为一致)
484
- return validateTypeMatch(value, mForm, { ...props, config: { name: config.name, ...config.fieldConfig } }, message);
501
+ if (!isDataSourceFieldPathValue(value, config)) {
502
+ if (options?.validatePlainValue) {
503
+ return options.validatePlainValue(value, context);
504
+ }
505
+
506
+ if (config.fieldConfig) {
507
+ // 值不是数据源字段路径时,按 fieldConfig 的类型校验(与表单项自身 typeMatch 行为一致)
508
+ return validateTypeMatch(
509
+ value,
510
+ mForm,
511
+ { ...props, config: { name: config.name, ...config.fieldConfig } },
512
+ message,
513
+ );
514
+ }
485
515
  }
486
516
 
487
517
  if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) {
@@ -496,6 +526,9 @@ const validateDataSourceFieldSelect: TypeMatchValidator = (value, { mForm, messa
496
526
  });
497
527
  };
498
528
 
529
+ const validateDataSourceFieldSelect: TypeMatchValidator = (value, context) =>
530
+ validateDataSourceFieldSelectValue(value, context);
531
+
499
532
  const validateDataSourceSelect: TypeMatchValidator = (value, { message, props }) => {
500
533
  const config = props.config || {};
501
534
  const dataSources = getDataSources();
package/types/index.d.ts CHANGED
@@ -713,10 +713,12 @@ declare class Editor extends BaseService {
713
713
  }?: DslOpOptions): Promise<void>;
714
714
  doUpdate(config: MNode, {
715
715
  changeRecords,
716
- historySource
716
+ historySource,
717
+ replace
717
718
  }?: {
718
719
  changeRecords?: ChangeRecord[];
719
720
  historySource?: HistoryOpSource;
721
+ replace?: boolean;
720
722
  }): Promise<{
721
723
  newNode: MNode;
722
724
  oldNode: MNode;
@@ -731,6 +733,7 @@ declare class Editor extends BaseService {
731
733
  * @param data.changeRecordList 多节点 form 端变更记录列表,按 config 数组同序对应每个节点;优先级高于 changeRecords
732
734
  * @param data.doNotPushHistory 是否不写入历史记录(默认 false)
733
735
  * @param data.historyDescription 入栈时附带的人类可读描述,用于历史面板展示(不影响 undo/redo 行为)
736
+ * @param data.replace 是否整节点替换:为 true 时跳过 mergeWith / toggleFixedPosition / setChildrenLayout,直接用传入配置覆盖(默认 false)
734
737
  * @returns 更新后的节点配置
735
738
  */
736
739
  update(config: MNode | MNode[], data?: {
@@ -739,6 +742,11 @@ declare class Editor extends BaseService {
739
742
  doNotPushHistory?: boolean;
740
743
  historyDescription?: string;
741
744
  historySource?: HistoryOpSource;
745
+ /**
746
+ * 为 true 时不做深合并等变换,直接用传入配置整节点替换现有节点。
747
+ * 适用于源码编辑、历史整节点快照回放等「完整 DSL」场景;默认 false(局部属性更新走 merge)。
748
+ */
749
+ replace?: boolean;
742
750
  /**
743
751
  * 属性面板提交时携带的校验错误信息,在写入历史记录之前落库,
744
752
  * 使历史快照与本次变更对齐,从而 undo/redo 能正确还原错误标记。
@@ -865,6 +873,7 @@ declare class Editor extends BaseService {
865
873
  doNotPushHistory?: boolean;
866
874
  historyDescription?: string;
867
875
  historySource?: HistoryOpSource;
876
+ replace?: boolean;
868
877
  }): Promise<DslOpWithHistoryIdsResult<MNode | MNode[]>>;
869
878
  /** 等价于 {@link moveLayer},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
870
879
  moveLayerAndGetHistoryId(offset: number | LayerOffset, options?: DslOpOptions): Promise<DslOpWithHistoryIdsResult<void>>;
@@ -1023,10 +1032,15 @@ declare class Events extends BaseService {
1023
1032
  constructor();
1024
1033
  setEvents(events: Record<string, EventOption[]>): void;
1025
1034
  setEvent(type: string, events: EventOption[]): void;
1026
- getEvent(type: string): EventOption[];
1035
+ getEvent(type: string, _data?: {
1036
+ node?: MNode | null;
1037
+ }): EventOption[];
1027
1038
  setMethods(methods: Record<string, EventOption[]>): void;
1028
1039
  setMethod(type: string, method: EventOption[]): void;
1029
- getMethod(type: string, _targetId: Id): EventOption[];
1040
+ getMethod(type: string, _data?: {
1041
+ node?: MNode | null;
1042
+ targetId?: Id;
1043
+ }): EventOption[];
1030
1044
  resetState(): void;
1031
1045
  destroy(): void;
1032
1046
  usePlugin(options: AsyncHookPlugin<AsyncMethodName$3, Events> & SyncHookPlugin<SyncMethodName$4, Events>): void;
@@ -3395,6 +3409,10 @@ declare class IdleTask<T = any> extends EventEmitter {
3395
3409
  once<Name extends keyof IdleTaskEvents, Param extends IdleTaskEvents[Name]>(eventName: Name, listener: (...args: Param) => void | Promise<void>): this;
3396
3410
  emit<Name extends keyof IdleTaskEvents, Param extends IdleTaskEvents[Name]>(eventName: Name, ...args: Param): boolean;
3397
3411
  private runTaskQueue;
3412
+ /**
3413
+ * 执行一批任务,队列被清空时提前结束
3414
+ */
3415
+ private runTaskBatch;
3398
3416
  /**
3399
3417
  * 单个任务失败不能中断整个队列,否则后续任务永远不会被执行,
3400
3418
  * 依赖收集会停在半路(收集中状态与剩余任务数都不再变化)
@@ -3574,6 +3592,17 @@ declare const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
3574
3592
  //#endregion
3575
3593
  //#region temp/packages/editor/src/utils/type-match-rules.d.ts
3576
3594
  declare const ALL_COND_OPS: Set<string>;
3595
+ type ValidateDataSourceFieldSelectOptions = {
3596
+ /**
3597
+ * 覆盖「非数据源字段路径」时的校验。
3598
+ * 不传则按 fieldConfig 走内置 typeMatch(与表单项自身 typeMatch 行为一致)。
3599
+ */
3600
+ validatePlainValue?: (value: any, context: TypeMatchValidateContext) => string | undefined | Promise<string | undefined>;
3601
+ };
3602
+ /**
3603
+ * data-source-field-select 的 typeMatch 校验逻辑,可供自定义 rules.validator 复用。
3604
+ */
3605
+ declare const validateDataSourceFieldSelectValue: (value: any, context: TypeMatchValidateContext, options?: ValidateDataSourceFieldSelectOptions) => string | undefined | Promise<string | undefined>;
3577
3606
  declare const editorTypeMatchRules: Record<string, TypeMatchValidator>;
3578
3607
  //#endregion
3579
3608
  //#region temp/packages/editor/src/utils/event.d.ts
@@ -6940,4 +6969,4 @@ declare const _default$43: {
6940
6969
  install: (app: App, opt?: Partial<EditorInstallOptions | DesignPluginOptions | FormInstallOptions>) => void;
6941
6970
  };
6942
6971
  //#endregion
6943
- export { ALL_COND_OPS, AddMNode, AddPrefixToObject, AsyncAfterHook, AsyncBeforeHook, AsyncHookPlugin, AsyncMethodName, BaseStepValue, BeforeAdd, CODE_DRAFT_STORAGE_KEY, COPY_CODE_STORAGE_KEY, COPY_DS_STORAGE_KEY, COPY_STORAGE_KEY, CanDropInFunction, CanDropInScene, _default as CodeBlockEditor, _default$1 as CodeBlockList, _default$2 as CodeBlockListPanel, CodeBlockListPanelSlots, CodeBlockListSlots, CodeBlockStepValue, CodeDeleteErrorType, CodeDslItem, CodeParamStatement, CodeRelation, _default$3 as CodeSelect, _default$4 as CodeSelectCol, CodeState, ColumnLayout, CombineInfo, CompareCategory, _default$5 as CompareForm, CompareFormBaseProps, CompareFormLoadConfig, CompareFormLoadConfigContext, ComponentGroup, ComponentGroupState, ComponentItem, _default$6 as ComponentListPanel, ComponentListPanelSlots, _default$7 as CondOpSelect, ConfirmAndRevertOptions, _default$8 as ContentMenu, ContentMenuTarget, ContentMenuType, CustomContentMenuFunction, CustomDiffFormOptions, DEFAULT_LEFT_COLUMN_WIDTH, DEFAULT_RIGHT_COLUMN_WIDTH, _default$9 as DataSourceAddButton, _default$10 as DataSourceConfigPanel, _default$11 as DataSourceFieldSelect, _default$12 as DataSourceFields, _default$13 as DataSourceInput, DataSourceListSlots, _default$14 as DataSourceMethodSelect, _default$15 as DataSourceMethods, _default$16 as DataSourceMocks, _default$17 as DataSourceSelect, DataSourceStepValue, DatasourceTypeOption, DepTargetType, DiffDialogPayload, _default$18 as DisplayConds, DragClassification, DragType, DslOpOptions, DslOpWithHistoryIdsResult, EVENT_NAME_VALUE_SEPARATOR, EditorChangeEvent, EditorChangeEventHistoryMeta, EditorChangeItem, EditorEvents, EditorInstallOptions, EditorNodeInfo, EditorSlots, EditorUpdateChangeItem, EventBus, EventBusEvent, EventNameOption, EventNameSelectOption, _default$19 as EventSelect, Fixed2Other, _default$20 as FloatingBox, FrameworkSlots, GetCodeBlockFormConfigOptions, GetColumnWidth, GetConfig, H_GUIDE_LINE_STORAGE_KEY, HistoryBucketConfig, _default$21 as HistoryDiffDialog, HistoryEvents, HistoryGroup, _default$22 as HistoryListBucket, _default$23 as HistoryListBucketTab, HistoryListExtraTab, HistoryOpOptions, HistoryOpOptionsWithChangeRecords, HistoryOpSource, HistoryOpType, HistoryPersistOptions, HistoryRowDescriptor, HistoryState, HistoryStepEntry, HistoryStepType, HistorySteps, _default$24 as Icon, IdleTask, IdleTaskEvents, IsExpandableFunction, KeyBindingCacheItem, KeyBindingCommand, KeyBindingItem, _default$25 as KeyValue, Keys, LEFT_COLUMN_WIDTH_STORAGE_KEY, _default$26 as LayerNodeContent, LayerNodeSlots, LayerNodeStatus, LayerOffset, _default$27 as LayerPanel, LayerPanelSlots, Layout, _default$28 as LayoutContainer, _default$28 as SplitView, ListState, MIN_CENTER_COLUMN_WIDTH, MIN_LEFT_COLUMN_WIDTH, MIN_RIGHT_COLUMN_WIDTH, MenuBarData, MenuButton, MenuComponent, MenuItem, NodeInvalidInfo, NodeInvalidSource, type OnDrag, PROPS_PANEL_WIDTH_STORAGE_KEY, PageBarSortOptions, _default$29 as PageFragmentSelect, PartSortableOptions, PastePosition, PersistedHistoryState, PropsFormConfigFunction, _default$30 as PropsFormPanel, PropsFormValueFunction, _default$31 as PropsPanel, PropsPanelSlots, PropsState, RIGHT_COLUMN_WIDTH_STORAGE_KEY, _default$32 as Resizer, ScrollViewer, ScrollViewerEvent, ScrollViewerSlots, SerializedUndoRedo, Services, SetColumnWidth, SideBarData, SideComponent, SideItem, SideItemKey, SidebarSlots, StageCore, StageOptions, StageOverlayState, StageRect, StageSlots, StepDiffItem, StepExtra, StepValue, StoreState, StoreStateKey, _default$33 as StyleSetter, SyncAfterHook, SyncBeforeHook, SyncHookPlugin, _default$34 as TMagicCodeEditor, _default$35 as TMagicEditor, _default$36 as ToolButton, _default$37 as Tree, _default$38 as TreeNode, TreeNodeData, type TypeMatchValidateContext, UI_SELECT_MODE_EVENT_NAME, UiState, UndoRedo, UseCompareFormReturn, UseHistoryRevertOptions, V_GUIDE_LINE_STORAGE_KEY, _default$39 as ViewForm, WorkspaceSlots, advancedTabConfig, arrayOptions, beforePaste, booleanOptions, buildChangeRecords, calcAlignCenterStyle, calcLayerTargetIndex, calcMoveStyle, canUsePluginMethods, change2Fixed, classifyDragSources, _default$40 as codeBlockService, collectEventNameOptionValues, collectRelatedNodes, _default$41 as componentListService, confirmHistoryAction, createStackStep, _default$42 as dataSourceService, debug, _default$43 as default, defaultIsExpandable, _default$44 as depService, describeRevertStep, describeStepForRevert, deserializeStacks, designPlugin, detectStackOpType, detectTargetId, detectTargetName, displayTabConfig, editorNodeMergeCustomizer, _default$45 as editorService, editorTypeMatchRules, eqOptions, error, eventTabConfig, _default$46 as eventsService, fillConfig, fixNodeLeft, fixNodePosition, formPlugin, generatePageName, generatePageNameByApp, getAddParent, getCascaderOptionsFromFields, getCodeBlockFormConfig, getCompActionAllowedValues, getCompActionOptions, getCondOpOptionsByFieldType, getDefaultConfig, getDisplayField, getEditorConfig, getEventNameAllowedValues, getEventNameOptions, getFieldType, getFormConfig, getFormValue, getGuideLineFromCache, getInitPositionStyle, getLastPushedHistoryIds, getNodeIndex, getOrCreateStack, getPageFragmentList, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, _default$47 as historyService, idbDelete, idbGet, idbSet, info, isEventNameCheckStrictly, isGlobalFlat, isIncludeDataSource, isIndexedDBSupported, _default$48 as keybindingService, _default$49 as loadMonaco, log, markStackSaved, mergeSteps, moveItemsInContainer, normalizeCompActionValue, numberOptions, openIndexedDB, _default$50 as propsService, removeStyleDisplayConfig, resolveFieldByPath, resolveSelectedNode, serializeConfig, serializeStacks, setChildrenLayout, setEditorConfig, setLayout, _default$51 as stageOverlayService, _default$52 as storageService, styleTabConfig, tablePlugin, toggleFixedPosition, _default$53 as uiService, undoFloor, updateStatus, useCodeBlockEdit, useCompareForm, useEditorContentHeight, useFilter, useFloatBox, useGetSo, useHistoryRevert, useNextFloatBoxPosition, useNodeStatus, useServices, useStage, useWindowRect, warn };
6972
+ export { ALL_COND_OPS, AddMNode, AddPrefixToObject, AsyncAfterHook, AsyncBeforeHook, AsyncHookPlugin, AsyncMethodName, BaseStepValue, BeforeAdd, CODE_DRAFT_STORAGE_KEY, COPY_CODE_STORAGE_KEY, COPY_DS_STORAGE_KEY, COPY_STORAGE_KEY, CanDropInFunction, CanDropInScene, _default as CodeBlockEditor, _default$1 as CodeBlockList, _default$2 as CodeBlockListPanel, CodeBlockListPanelSlots, CodeBlockListSlots, CodeBlockStepValue, CodeDeleteErrorType, CodeDslItem, CodeParamStatement, CodeRelation, _default$3 as CodeSelect, _default$4 as CodeSelectCol, CodeState, ColumnLayout, CombineInfo, CompareCategory, _default$5 as CompareForm, CompareFormBaseProps, CompareFormLoadConfig, CompareFormLoadConfigContext, ComponentGroup, ComponentGroupState, ComponentItem, _default$6 as ComponentListPanel, ComponentListPanelSlots, _default$7 as CondOpSelect, ConfirmAndRevertOptions, _default$8 as ContentMenu, ContentMenuTarget, ContentMenuType, CustomContentMenuFunction, CustomDiffFormOptions, DEFAULT_LEFT_COLUMN_WIDTH, DEFAULT_RIGHT_COLUMN_WIDTH, _default$9 as DataSourceAddButton, _default$10 as DataSourceConfigPanel, _default$11 as DataSourceFieldSelect, _default$12 as DataSourceFields, _default$13 as DataSourceInput, DataSourceListSlots, _default$14 as DataSourceMethodSelect, _default$15 as DataSourceMethods, _default$16 as DataSourceMocks, _default$17 as DataSourceSelect, DataSourceStepValue, DatasourceTypeOption, DepTargetType, DiffDialogPayload, _default$18 as DisplayConds, DragClassification, DragType, DslOpOptions, DslOpWithHistoryIdsResult, EVENT_NAME_VALUE_SEPARATOR, EditorChangeEvent, EditorChangeEventHistoryMeta, EditorChangeItem, EditorEvents, EditorInstallOptions, EditorNodeInfo, EditorSlots, EditorUpdateChangeItem, EventBus, EventBusEvent, EventNameOption, EventNameSelectOption, _default$19 as EventSelect, Fixed2Other, _default$20 as FloatingBox, FrameworkSlots, GetCodeBlockFormConfigOptions, GetColumnWidth, GetConfig, H_GUIDE_LINE_STORAGE_KEY, HistoryBucketConfig, _default$21 as HistoryDiffDialog, HistoryEvents, HistoryGroup, _default$22 as HistoryListBucket, _default$23 as HistoryListBucketTab, HistoryListExtraTab, HistoryOpOptions, HistoryOpOptionsWithChangeRecords, HistoryOpSource, HistoryOpType, HistoryPersistOptions, HistoryRowDescriptor, HistoryState, HistoryStepEntry, HistoryStepType, HistorySteps, _default$24 as Icon, IdleTask, IdleTaskEvents, IsExpandableFunction, KeyBindingCacheItem, KeyBindingCommand, KeyBindingItem, _default$25 as KeyValue, Keys, LEFT_COLUMN_WIDTH_STORAGE_KEY, _default$26 as LayerNodeContent, LayerNodeSlots, LayerNodeStatus, LayerOffset, _default$27 as LayerPanel, LayerPanelSlots, Layout, _default$28 as LayoutContainer, _default$28 as SplitView, ListState, MIN_CENTER_COLUMN_WIDTH, MIN_LEFT_COLUMN_WIDTH, MIN_RIGHT_COLUMN_WIDTH, MenuBarData, MenuButton, MenuComponent, MenuItem, NodeInvalidInfo, NodeInvalidSource, type OnDrag, PROPS_PANEL_WIDTH_STORAGE_KEY, PageBarSortOptions, _default$29 as PageFragmentSelect, PartSortableOptions, PastePosition, PersistedHistoryState, PropsFormConfigFunction, _default$30 as PropsFormPanel, PropsFormValueFunction, _default$31 as PropsPanel, PropsPanelSlots, PropsState, RIGHT_COLUMN_WIDTH_STORAGE_KEY, _default$32 as Resizer, ScrollViewer, ScrollViewerEvent, ScrollViewerSlots, SerializedUndoRedo, Services, SetColumnWidth, SideBarData, SideComponent, SideItem, SideItemKey, SidebarSlots, StageCore, StageOptions, StageOverlayState, StageRect, StageSlots, StepDiffItem, StepExtra, StepValue, StoreState, StoreStateKey, _default$33 as StyleSetter, SyncAfterHook, SyncBeforeHook, SyncHookPlugin, _default$34 as TMagicCodeEditor, _default$35 as TMagicEditor, _default$36 as ToolButton, _default$37 as Tree, _default$38 as TreeNode, TreeNodeData, type TypeMatchValidateContext, UI_SELECT_MODE_EVENT_NAME, UiState, UndoRedo, UseCompareFormReturn, UseHistoryRevertOptions, V_GUIDE_LINE_STORAGE_KEY, ValidateDataSourceFieldSelectOptions, _default$39 as ViewForm, WorkspaceSlots, advancedTabConfig, arrayOptions, beforePaste, booleanOptions, buildChangeRecords, calcAlignCenterStyle, calcLayerTargetIndex, calcMoveStyle, canUsePluginMethods, change2Fixed, classifyDragSources, _default$40 as codeBlockService, collectEventNameOptionValues, collectRelatedNodes, _default$41 as componentListService, confirmHistoryAction, createStackStep, _default$42 as dataSourceService, debug, _default$43 as default, defaultIsExpandable, _default$44 as depService, describeRevertStep, describeStepForRevert, deserializeStacks, designPlugin, detectStackOpType, detectTargetId, detectTargetName, displayTabConfig, editorNodeMergeCustomizer, _default$45 as editorService, editorTypeMatchRules, eqOptions, error, eventTabConfig, _default$46 as eventsService, fillConfig, fixNodeLeft, fixNodePosition, formPlugin, generatePageName, generatePageNameByApp, getAddParent, getCascaderOptionsFromFields, getCodeBlockFormConfig, getCompActionAllowedValues, getCompActionOptions, getCondOpOptionsByFieldType, getDefaultConfig, getDisplayField, getEditorConfig, getEventNameAllowedValues, getEventNameOptions, getFieldType, getFormConfig, getFormValue, getGuideLineFromCache, getInitPositionStyle, getLastPushedHistoryIds, getNodeIndex, getOrCreateStack, getPageFragmentList, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, _default$47 as historyService, idbDelete, idbGet, idbSet, info, isEventNameCheckStrictly, isGlobalFlat, isIncludeDataSource, isIndexedDBSupported, _default$48 as keybindingService, _default$49 as loadMonaco, log, markStackSaved, mergeSteps, moveItemsInContainer, normalizeCompActionValue, numberOptions, openIndexedDB, _default$50 as propsService, removeStyleDisplayConfig, resolveFieldByPath, resolveSelectedNode, serializeConfig, serializeStacks, setChildrenLayout, setEditorConfig, setLayout, _default$51 as stageOverlayService, _default$52 as storageService, styleTabConfig, tablePlugin, toggleFixedPosition, _default$53 as uiService, undoFloor, updateStatus, useCodeBlockEdit, useCompareForm, useEditorContentHeight, useFilter, useFloatBox, useGetSo, useHistoryRevert, useNextFloatBoxPosition, useNodeStatus, useServices, useStage, useWindowRect, validateDataSourceFieldSelectValue, warn };