@tmagic/form 1.8.0-beta.1 → 1.8.0-beta.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.
@@ -1,7 +1,8 @@
1
+ import { FORM_DIFF_CONFIG_KEY } from "./schema.js";
1
2
  import { getConfig } from "./utils/config.js";
2
3
  import { initValue } from "./utils/form.js";
3
4
  import Container_default from "./containers/Container.js";
4
- import { Fragment, createBlock, createCommentVNode, createElementBlock, defineComponent, normalizeStyle, openBlock, provide, reactive, ref, renderList, shallowRef, toRaw, unref, useTemplateRef, watch, watchEffect, withCtx } from "vue";
5
+ import { Fragment, createBlock, createCommentVNode, createElementBlock, createSlots, defineComponent, mergeProps, normalizeStyle, openBlock, provide, reactive, ref, renderList, renderSlot, shallowRef, toRaw, unref, useTemplateRef, watch, watchEffect, withCtx } from "vue";
5
6
  import { cloneDeep, isEqual } from "lodash-es";
6
7
  import { TMagicForm, tMagicMessage, tMagicMessageBox } from "@tmagic/design";
7
8
  import { setValueByKeyPath } from "@tmagic/utils";
@@ -34,7 +35,9 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
34
35
  keyProp: { default: "__key" },
35
36
  popperClass: {},
36
37
  preventSubmitDefault: { type: Boolean },
37
- extendState: {}
38
+ extendState: {},
39
+ showDiff: {},
40
+ selfDiffFieldTypes: {}
38
41
  },
39
42
  emits: [
40
43
  "change",
@@ -150,6 +153,14 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
150
153
  }
151
154
  });
152
155
  provide("mForm", formState);
156
+ provide(FORM_DIFF_CONFIG_KEY, {
157
+ get showDiff() {
158
+ return props.showDiff;
159
+ },
160
+ get selfDiffFieldTypes() {
161
+ return props.selfDiffFieldTypes;
162
+ }
163
+ });
153
164
  const changeRecords = shallowRef([]);
154
165
  watch([() => props.config, () => props.initValues], ([config], [preConfig]) => {
155
166
  changeRecords.value = [];
@@ -266,7 +277,11 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
266
277
  "step-active": __props.stepActive,
267
278
  size: __props.size,
268
279
  onChange: changeHandler
269
- }, null, 8, [
280
+ }, createSlots({ _: 2 }, [_ctx.$slots.label ? {
281
+ name: "label",
282
+ fn: withCtx((labelProps) => [renderSlot(_ctx.$slots, "label", mergeProps({ ref_for: true }, labelProps))]),
283
+ key: "0"
284
+ } : void 0]), 1032, [
270
285
  "disabled",
271
286
  "config",
272
287
  "model",
@@ -277,7 +292,7 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
277
292
  "size"
278
293
  ]);
279
294
  }), 128)) : createCommentVNode("v-if", true)]),
280
- _: 1
295
+ _: 3
281
296
  }, 8, [
282
297
  "model",
283
298
  "label-width",
@@ -1,8 +1,9 @@
1
+ import { FORM_DIFF_CONFIG_KEY } from "../schema.js";
1
2
  import Hidden_default from "../fields/Hidden.js";
2
3
  import { getField } from "../utils/config.js";
3
4
  import { createObjectProp, display, filterFunction, getRules } from "../utils/form.js";
4
5
  import FormLabel_default from "./FormLabel.js";
5
- import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, inject, mergeProps, normalizeClass, normalizeStyle, openBlock, readonly, ref, renderList, resolveComponent, resolveDynamicComponent, toDisplayString, toRaw, unref, watch, watchEffect, withCtx } from "vue";
6
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, inject, mergeProps, normalizeClass, normalizeStyle, openBlock, readonly, ref, renderList, renderSlot, resolveComponent, resolveDynamicComponent, toDisplayString, toRaw, unref, watch, watchEffect, withCtx } from "vue";
6
7
  import { isEqual } from "lodash-es";
7
8
  import { TMagicButton, TMagicFormItem, TMagicIcon, TMagicTooltip } from "@tmagic/design";
8
9
  import { getValueByKeyPath } from "@tmagic/utils";
@@ -15,7 +16,8 @@ var _hoisted_4 = ["innerHTML"];
15
16
  var _hoisted_5 = ["innerHTML"];
16
17
  var _hoisted_6 = ["innerHTML"];
17
18
  var _hoisted_7 = ["innerHTML"];
18
- var _hoisted_8 = {
19
+ var _hoisted_8 = ["innerHTML"];
20
+ var _hoisted_9 = {
19
21
  key: 5,
20
22
  style: { "text-align": "center" }
21
23
  };
@@ -45,11 +47,21 @@ var Container_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
45
47
  const props = __props;
46
48
  const emit = __emit;
47
49
  const mForm = inject("mForm");
50
+ const diffConfig = inject(FORM_DIFF_CONFIG_KEY, {});
48
51
  const expand = ref(false);
49
52
  const name = computed(() => props.config.name || "");
50
53
  const showDiff = computed(() => {
51
54
  if (!props.isCompare) return false;
52
- return !isEqual(name.value ? props.model[name.value] : props.model, name.value ? props.lastValues[name.value] : props.lastValues);
55
+ if (!name.value) return false;
56
+ const curValue = props.model[name.value];
57
+ const lastValue = props.lastValues[name.value];
58
+ const customShowDiff = diffConfig.showDiff;
59
+ if (typeof customShowDiff === "function") return Boolean(customShowDiff({
60
+ curValue,
61
+ lastValue,
62
+ config: props.config
63
+ }));
64
+ return !isEqual(curValue, lastValue);
53
65
  });
54
66
  const items = computed(() => props.config.items);
55
67
  const itemProp = computed(() => {
@@ -70,6 +82,35 @@ var Container_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
70
82
  if (type.value === "component" && props.config.component) return props.config.component;
71
83
  return getField(type.value || "container") || `m-${items.value ? "form" : "fields"}-${type.value}`;
72
84
  });
85
+ /**
86
+ * 自接管对比的字段类型白名单。
87
+ *
88
+ * 这类字段在 `isCompare === true` 且存在差异时,不再由 Container 渲染前后两份独立组件来对比,
89
+ * 而是只渲染一次组件,将 `model` / `lastValues` / `isCompare` 一并传给字段组件,
90
+ * 由字段组件内部自行展示前后差异(典型场景:vs-code 字段使用 monaco 自带的 diff 编辑器)。
91
+ *
92
+ * 这样做的好处:
93
+ * 1. 避免重型字段(如 monaco 编辑器)在对比模式下被实例化两次,节省资源;
94
+ * 2. 提供更专业的对比视觉效果(如 monaco diff 的行级高亮、左右滚动同步等)。
95
+ *
96
+ * 注意:像 `event-select` / `code-select-col` 这类内部由列表 / 嵌套子表单组成的复合字段,若按默认逻辑
97
+ * 渲染前后两份独立组件,会出现两套下拉框 + 两份参数表单(或两套「添加事件」按钮、两份完整面板),
98
+ * 体验很差。这类字段在内部把 `is-compare`/`lastValues` 透传给子级容器,由子级逐项展示差异,
99
+ * 因此同样归类为自接管对比字段。
100
+ */
101
+ const DEFAULT_SELF_DIFF_FIELD_TYPES = [
102
+ "vs-code",
103
+ "event-select",
104
+ "code-select-col",
105
+ "code-select"
106
+ ];
107
+ const effectiveSelfDiffFieldTypes = computed(() => {
108
+ const custom = diffConfig.selfDiffFieldTypes;
109
+ if (typeof custom === "function") return new Set(custom([...DEFAULT_SELF_DIFF_FIELD_TYPES]));
110
+ if (Array.isArray(custom)) return new Set([...DEFAULT_SELF_DIFF_FIELD_TYPES, ...custom]);
111
+ return new Set(DEFAULT_SELF_DIFF_FIELD_TYPES);
112
+ });
113
+ const isSelfDiffField = computed(() => effectiveSelfDiffFieldTypes.value.has(type.value));
73
114
  const disabled = computed(() => props.disabled || filterFunction(mForm, props.config.disabled, props));
74
115
  const text = computed(() => filterFunction(mForm, props.config.text, props));
75
116
  const tooltip = computed(() => {
@@ -238,7 +279,13 @@ var Container_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
238
279
  "label-width",
239
280
  "style"
240
281
  ])) : type.value && display$1.value && !showDiff.value ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [createVNode(unref(TMagicFormItem), mergeProps(formItemProps.value, { class: { "tmagic-form-hidden": `${itemLabelWidth.value}` === "0" || !text.value } }), {
241
- label: withCtx(() => [createVNode(FormLabel_default, {
282
+ label: withCtx(() => [renderSlot(_ctx.$slots, "label", {
283
+ config: __props.config,
284
+ type: type.value,
285
+ text: text.value,
286
+ prop: itemProp.value,
287
+ disabled: disabled.value
288
+ }, () => [createVNode(FormLabel_default, {
242
289
  tip: __props.config.tip,
243
290
  type: type.value,
244
291
  "use-label": __props.config.useLabel,
@@ -250,7 +297,7 @@ var Container_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
250
297
  "use-label",
251
298
  "label-title",
252
299
  "text"
253
- ])]),
300
+ ])])]),
254
301
  default: withCtx(() => [tooltip.value.text ? (openBlock(), createBlock(unref(TMagicTooltip), {
255
302
  key: 0,
256
303
  placement: tooltip.value.placement
@@ -279,7 +326,7 @@ var Container_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
279
326
  "last-values",
280
327
  "is-compare"
281
328
  ]))]),
282
- _: 1
329
+ _: 3
283
330
  }, 16, ["class"]), __props.config.tip && type.value === "checkbox" && !__props.config.useLabel ? (openBlock(), createBlock(unref(TMagicTooltip), {
284
331
  key: 0,
285
332
  placement: "top"
@@ -295,12 +342,18 @@ var Container_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
295
342
  _: 1
296
343
  })) : createCommentVNode("v-if", true)], 64)) : type.value && display$1.value && showDiff.value ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
297
344
  createCommentVNode(" 对比 "),
298
- createCommentVNode(" 上次内容 "),
299
- createVNode(unref(TMagicFormItem), mergeProps(formItemProps.value, { class: {
345
+ createCommentVNode(" 自接管对比的字段类型(如 vs-code):只渲染一次组件,由字段内部用 diff 编辑器/视图自行展示前后差异 "),
346
+ isSelfDiffField.value ? (openBlock(), createBlock(unref(TMagicFormItem), mergeProps({ key: 0 }, formItemProps.value, { class: {
300
347
  "tmagic-form-hidden": `${itemLabelWidth.value}` === "0" || !text.value,
301
- "show-diff": true
348
+ "self-diff": true
302
349
  } }), {
303
- label: withCtx(() => [createVNode(FormLabel_default, {
350
+ label: withCtx(() => [renderSlot(_ctx.$slots, "label", {
351
+ config: __props.config,
352
+ type: type.value,
353
+ text: text.value,
354
+ prop: itemProp.value,
355
+ disabled: disabled.value
356
+ }, () => [createVNode(FormLabel_default, {
304
357
  tip: __props.config.tip,
305
358
  type: type.value,
306
359
  "use-label": __props.config.useLabel,
@@ -312,88 +365,148 @@ var Container_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
312
365
  "use-label",
313
366
  "label-title",
314
367
  "text"
315
- ])]),
368
+ ])])]),
316
369
  default: withCtx(() => [tooltip.value.text ? (openBlock(), createBlock(unref(TMagicTooltip), {
317
370
  key: 0,
318
371
  placement: tooltip.value.placement
319
372
  }, {
320
373
  content: withCtx(() => [createElementVNode("div", { innerHTML: tooltip.value.text }, null, 8, _hoisted_4)]),
321
374
  default: withCtx(() => [(openBlock(), createBlock(resolveDynamicComponent(tagName.value), mergeProps(fieldsProps.value, {
322
- model: __props.lastValues,
375
+ model: __props.model,
376
+ "last-values": __props.lastValues,
377
+ "is-compare": __props.isCompare,
323
378
  onChange: onChangeHandler
324
- }), null, 16, ["model"]))]),
379
+ }), null, 16, [
380
+ "model",
381
+ "last-values",
382
+ "is-compare"
383
+ ]))]),
325
384
  _: 1
326
385
  }, 8, ["placement"])) : (openBlock(), createBlock(resolveDynamicComponent(tagName.value), mergeProps({ key: 1 }, fieldsProps.value, {
327
- model: __props.lastValues,
386
+ model: __props.model,
387
+ "last-values": __props.lastValues,
388
+ "is-compare": __props.isCompare,
328
389
  onChange: onChangeHandler
329
- }), null, 16, ["model"]))]),
330
- _: 1
331
- }, 16, ["class"]),
332
- __props.config.tip && type.value === "checkbox" && !__props.config.useLabel ? (openBlock(), createBlock(unref(TMagicTooltip), {
333
- key: 0,
334
- placement: "top"
335
- }, {
336
- content: withCtx(() => [createElementVNode("div", { innerHTML: __props.config.tip }, null, 8, _hoisted_5)]),
337
- default: withCtx(() => [createVNode(unref(TMagicIcon), { style: {
338
- "line-height": "40px",
339
- "margin-left": "5px"
340
- } }, {
341
- default: withCtx(() => [createVNode(unref(WarningFilled))]),
342
- _: 1
343
- })]),
344
- _: 1
345
- })) : createCommentVNode("v-if", true),
346
- createCommentVNode(" 当前内容 "),
347
- createVNode(unref(TMagicFormItem), mergeProps(formItemProps.value, {
348
- style: __props.config.tip ? "flex: 1" : "",
349
- class: {
390
+ }), null, 16, [
391
+ "model",
392
+ "last-values",
393
+ "is-compare"
394
+ ]))]),
395
+ _: 3
396
+ }, 16, ["class"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
397
+ createCommentVNode(" 普通字段:渲染前后两份独立的组件用于对比 "),
398
+ createCommentVNode(" 上次内容 "),
399
+ createVNode(unref(TMagicFormItem), mergeProps(formItemProps.value, { class: {
350
400
  "tmagic-form-hidden": `${itemLabelWidth.value}` === "0" || !text.value,
351
- "show-diff": true
352
- }
353
- }), {
354
- label: withCtx(() => [createVNode(FormLabel_default, {
355
- tip: __props.config.tip,
356
- type: type.value,
357
- "use-label": __props.config.useLabel,
358
- "label-title": __props.config.labelTitle,
359
- text: text.value
360
- }, null, 8, [
361
- "tip",
362
- "type",
363
- "use-label",
364
- "label-title",
365
- "text"
366
- ])]),
367
- default: withCtx(() => [tooltip.value.text ? (openBlock(), createBlock(unref(TMagicTooltip), {
401
+ "show-before-diff": true
402
+ } }), {
403
+ label: withCtx(() => [renderSlot(_ctx.$slots, "label", {
404
+ config: __props.config,
405
+ type: type.value,
406
+ text: text.value,
407
+ prop: itemProp.value,
408
+ disabled: disabled.value
409
+ }, () => [createVNode(FormLabel_default, {
410
+ tip: __props.config.tip,
411
+ type: type.value,
412
+ "use-label": __props.config.useLabel,
413
+ "label-title": __props.config.labelTitle,
414
+ text: text.value
415
+ }, null, 8, [
416
+ "tip",
417
+ "type",
418
+ "use-label",
419
+ "label-title",
420
+ "text"
421
+ ])])]),
422
+ default: withCtx(() => [tooltip.value.text ? (openBlock(), createBlock(unref(TMagicTooltip), {
423
+ key: 0,
424
+ placement: tooltip.value.placement
425
+ }, {
426
+ content: withCtx(() => [createElementVNode("div", { innerHTML: tooltip.value.text }, null, 8, _hoisted_5)]),
427
+ default: withCtx(() => [(openBlock(), createBlock(resolveDynamicComponent(tagName.value), mergeProps(fieldsProps.value, {
428
+ model: __props.lastValues,
429
+ onChange: onChangeHandler
430
+ }), null, 16, ["model"]))]),
431
+ _: 1
432
+ }, 8, ["placement"])) : (openBlock(), createBlock(resolveDynamicComponent(tagName.value), mergeProps({ key: 1 }, fieldsProps.value, {
433
+ model: __props.lastValues,
434
+ onChange: onChangeHandler
435
+ }), null, 16, ["model"]))]),
436
+ _: 3
437
+ }, 16, ["class"]),
438
+ __props.config.tip && type.value === "checkbox" && !__props.config.useLabel ? (openBlock(), createBlock(unref(TMagicTooltip), {
368
439
  key: 0,
369
- placement: tooltip.value.placement
440
+ placement: "top"
370
441
  }, {
371
- content: withCtx(() => [createElementVNode("div", { innerHTML: tooltip.value.text }, null, 8, _hoisted_6)]),
372
- default: withCtx(() => [(openBlock(), createBlock(resolveDynamicComponent(tagName.value), mergeProps(fieldsProps.value, {
442
+ content: withCtx(() => [createElementVNode("div", { innerHTML: __props.config.tip }, null, 8, _hoisted_6)]),
443
+ default: withCtx(() => [createVNode(unref(TMagicIcon), { style: {
444
+ "line-height": "40px",
445
+ "margin-left": "5px"
446
+ } }, {
447
+ default: withCtx(() => [createVNode(unref(WarningFilled))]),
448
+ _: 1
449
+ })]),
450
+ _: 1
451
+ })) : createCommentVNode("v-if", true),
452
+ createCommentVNode(" 当前内容 "),
453
+ createVNode(unref(TMagicFormItem), mergeProps(formItemProps.value, {
454
+ style: __props.config.tip ? "flex: 1" : "",
455
+ class: {
456
+ "tmagic-form-hidden": `${itemLabelWidth.value}` === "0" || !text.value,
457
+ "show-after-diff": true
458
+ }
459
+ }), {
460
+ label: withCtx(() => [renderSlot(_ctx.$slots, "label", {
461
+ config: __props.config,
462
+ type: type.value,
463
+ text: text.value,
464
+ prop: itemProp.value,
465
+ disabled: disabled.value
466
+ }, () => [createVNode(FormLabel_default, {
467
+ tip: __props.config.tip,
468
+ type: type.value,
469
+ "use-label": __props.config.useLabel,
470
+ "label-title": __props.config.labelTitle,
471
+ text: text.value
472
+ }, null, 8, [
473
+ "tip",
474
+ "type",
475
+ "use-label",
476
+ "label-title",
477
+ "text"
478
+ ])])]),
479
+ default: withCtx(() => [tooltip.value.text ? (openBlock(), createBlock(unref(TMagicTooltip), {
480
+ key: 0,
481
+ placement: tooltip.value.placement
482
+ }, {
483
+ content: withCtx(() => [createElementVNode("div", { innerHTML: tooltip.value.text }, null, 8, _hoisted_7)]),
484
+ default: withCtx(() => [(openBlock(), createBlock(resolveDynamicComponent(tagName.value), mergeProps(fieldsProps.value, {
485
+ model: __props.model,
486
+ onChange: onChangeHandler
487
+ }), null, 16, ["model"]))]),
488
+ _: 1
489
+ }, 8, ["placement"])) : (openBlock(), createBlock(resolveDynamicComponent(tagName.value), mergeProps({ key: 1 }, fieldsProps.value, {
373
490
  model: __props.model,
374
491
  onChange: onChangeHandler
375
492
  }), null, 16, ["model"]))]),
493
+ _: 3
494
+ }, 16, ["style", "class"]),
495
+ __props.config.tip && type.value === "checkbox" && !__props.config.useLabel ? (openBlock(), createBlock(unref(TMagicTooltip), {
496
+ key: 1,
497
+ placement: "top"
498
+ }, {
499
+ content: withCtx(() => [createElementVNode("div", { innerHTML: __props.config.tip }, null, 8, _hoisted_8)]),
500
+ default: withCtx(() => [createVNode(unref(TMagicIcon), { style: {
501
+ "line-height": "40px",
502
+ "margin-left": "5px"
503
+ } }, {
504
+ default: withCtx(() => [createVNode(unref(WarningFilled))]),
505
+ _: 1
506
+ })]),
376
507
  _: 1
377
- }, 8, ["placement"])) : (openBlock(), createBlock(resolveDynamicComponent(tagName.value), mergeProps({ key: 1 }, fieldsProps.value, {
378
- model: __props.model,
379
- onChange: onChangeHandler
380
- }), null, 16, ["model"]))]),
381
- _: 1
382
- }, 16, ["style", "class"]),
383
- __props.config.tip && type.value === "checkbox" && !__props.config.useLabel ? (openBlock(), createBlock(unref(TMagicTooltip), {
384
- key: 1,
385
- placement: "top"
386
- }, {
387
- content: withCtx(() => [createElementVNode("div", { innerHTML: __props.config.tip }, null, 8, _hoisted_7)]),
388
- default: withCtx(() => [createVNode(unref(TMagicIcon), { style: {
389
- "line-height": "40px",
390
- "margin-left": "5px"
391
- } }, {
392
- default: withCtx(() => [createVNode(unref(WarningFilled))]),
393
- _: 1
394
- })]),
395
- _: 1
396
- })) : createCommentVNode("v-if", true)
508
+ })) : createCommentVNode("v-if", true)
509
+ ], 64))
397
510
  ], 64)) : items.value && display$1.value ? (openBlock(), createElementBlock(Fragment, { key: 4 }, [(isValidName() ? __props.model[name.value] : __props.model) ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(items.value, (item) => {
398
511
  return openBlock(), createBlock(_component_Container, {
399
512
  key: key(item),
@@ -409,7 +522,11 @@ var Container_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
409
522
  prop: itemProp.value,
410
523
  onChange: onChangeHandler,
411
524
  onAddDiffCount
412
- }, null, 8, [
525
+ }, createSlots({ _: 2 }, [_ctx.$slots.label ? {
526
+ name: "label",
527
+ fn: withCtx((labelProps) => [renderSlot(_ctx.$slots, "label", mergeProps({ ref_for: true }, labelProps))]),
528
+ key: "0"
529
+ } : void 0]), 1032, [
413
530
  "model",
414
531
  "last-values",
415
532
  "is-compare",
@@ -421,7 +538,7 @@ var Container_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
421
538
  "label-width",
422
539
  "prop"
423
540
  ]);
424
- }), 128)) : createCommentVNode("v-if", true)], 64)) : createCommentVNode("v-if", true), __props.config.expand && type.value !== "fieldset" ? (openBlock(), createElementBlock("div", _hoisted_8, [createVNode(unref(TMagicButton), {
541
+ }), 128)) : createCommentVNode("v-if", true)], 64)) : createCommentVNode("v-if", true), __props.config.expand && type.value !== "fieldset" ? (openBlock(), createElementBlock("div", _hoisted_9, [createVNode(unref(TMagicButton), {
425
542
  type: "primary",
426
543
  size: "small",
427
544
  disabled: false,
@@ -1,3 +1,4 @@
1
+ import { filterFunction } from "../utils/form.js";
1
2
  import Container_default from "./Container.js";
2
3
  import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, inject, normalizeStyle, openBlock, renderList, resolveDynamicComponent, unref, withCtx } from "vue";
3
4
  import { TMagicCheckbox } from "@tmagic/design";
@@ -36,6 +37,7 @@ var Fieldset_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defin
36
37
  const emit = __emit;
37
38
  const mForm = inject("mForm");
38
39
  const name = computed(() => props.config.name || "");
40
+ const legend = computed(() => filterFunction(mForm, props.config.legend, props));
39
41
  const checkboxName = computed(() => {
40
42
  if (typeof props.config.checkbox === "object" && typeof props.config.checkbox.name === "string") return props.config.checkbox.name;
41
43
  return "value";
@@ -75,7 +77,7 @@ var Fieldset_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defin
75
77
  "false-value": checkboxFalseValue.value,
76
78
  "onUpdate:modelValue": valueChangeHandler
77
79
  }, {
78
- default: withCtx(() => [createElementVNode("span", { innerHTML: __props.config.legend }, null, 8, _hoisted_1), __props.config.extra ? (openBlock(), createElementBlock("span", {
80
+ default: withCtx(() => [createElementVNode("span", { innerHTML: legend.value }, null, 8, _hoisted_1), __props.config.extra ? (openBlock(), createElementBlock("span", {
79
81
  key: 0,
80
82
  innerHTML: __props.config.extra,
81
83
  class: "m-form-tip"
@@ -88,7 +90,7 @@ var Fieldset_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defin
88
90
  "false-value"
89
91
  ])]),
90
92
  _: 1
91
- })) : (openBlock(), createElementBlock("legend", _hoisted_3, [createElementVNode("span", { innerHTML: __props.config.legend }, null, 8, _hoisted_4), __props.config.extra ? (openBlock(), createElementBlock("span", {
93
+ })) : (openBlock(), createElementBlock("legend", _hoisted_3, [createElementVNode("span", { innerHTML: legend.value }, null, 8, _hoisted_4), __props.config.extra ? (openBlock(), createElementBlock("span", {
92
94
  key: 0,
93
95
  innerHTML: __props.config.extra,
94
96
  class: "m-form-tip"
@@ -8,7 +8,10 @@ var _hoisted_3 = {
8
8
  key: 1,
9
9
  class: "el-table__empty-block"
10
10
  };
11
- var _hoisted_4 = { class: "m-fields-group-list-footer" };
11
+ var _hoisted_4 = {
12
+ key: 3,
13
+ class: "m-fields-group-list-footer"
14
+ };
12
15
  var _hoisted_5 = { style: {
13
16
  "display": "flex",
14
17
  "justify-content": "flex-end",
@@ -91,7 +94,7 @@ var GroupList_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
91
94
  "group-model"
92
95
  ]);
93
96
  }), 128)),
94
- createElementVNode("div", _hoisted_4, [renderSlot(_ctx.$slots, "toggle-button"), createElementVNode("div", _hoisted_5, [renderSlot(_ctx.$slots, "add-button")])])
97
+ !__props.isCompare ? (openBlock(), createElementBlock("div", _hoisted_4, [renderSlot(_ctx.$slots, "toggle-button"), createElementVNode("div", _hoisted_5, [renderSlot(_ctx.$slots, "add-button")])])) : createCommentVNode("v-if", true)
95
98
  ]);
96
99
  };
97
100
  }
@@ -99,16 +99,17 @@ var GroupListItem_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */
99
99
  }), createElementVNode("span", { innerHTML: title.value }, null, 8, _hoisted_1)]),
100
100
  _: 1
101
101
  }, 8, ["disabled"]),
102
- withDirectives(createVNode(unref(TMagicButton), {
102
+ !__props.isCompare ? withDirectives((openBlock(), createBlock(unref(TMagicButton), {
103
+ key: 0,
103
104
  type: "danger",
104
105
  size: "small",
105
106
  link: "",
106
107
  icon: unref(Delete),
107
108
  disabled: __props.disabled,
108
109
  onClick: removeHandler
109
- }, null, 8, ["icon", "disabled"]), [[vShow, showDelete.value]]),
110
- copyable.value ? (openBlock(), createBlock(unref(TMagicButton), {
111
- key: 0,
110
+ }, null, 8, ["icon", "disabled"])), [[vShow, showDelete.value]]) : createCommentVNode("v-if", true),
111
+ copyable.value && !__props.isCompare ? (openBlock(), createBlock(unref(TMagicButton), {
112
+ key: 1,
112
113
  link: "",
113
114
  size: "small",
114
115
  type: "primary",
@@ -119,7 +120,7 @@ var GroupListItem_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */
119
120
  default: withCtx(() => [..._cache[6] || (_cache[6] = [createTextVNode("复制", -1)])]),
120
121
  _: 1
121
122
  }, 8, ["icon", "disabled"])) : createCommentVNode("v-if", true),
122
- movable.value ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [withDirectives(createVNode(unref(TMagicButton), {
123
+ movable.value && !__props.isCompare ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [withDirectives(createVNode(unref(TMagicButton), {
123
124
  link: "",
124
125
  size: "small",
125
126
  disabled: __props.disabled,
@@ -138,8 +139,8 @@ var GroupListItem_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */
138
139
  default: withCtx(() => [..._cache[8] || (_cache[8] = [createTextVNode("下移", -1)])]),
139
140
  _: 1
140
141
  }, 8, ["disabled", "icon"]), [[vShow, __props.index !== length.value - 1]])], 64)) : createCommentVNode("v-if", true),
141
- __props.config.moveSpecifyLocation ? (openBlock(), createBlock(unref(TMagicPopover), {
142
- key: 2,
142
+ __props.config.moveSpecifyLocation && !__props.isCompare ? (openBlock(), createBlock(unref(TMagicPopover), {
143
+ key: 3,
143
144
  trigger: "click",
144
145
  placement: "top",
145
146
  width: "200",
@@ -185,7 +186,7 @@ var GroupListItem_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */
185
186
  _: 1
186
187
  }, 8, ["visible"])) : createCommentVNode("v-if", true),
187
188
  itemExtra.value ? (openBlock(), createElementBlock("span", {
188
- key: 3,
189
+ key: 4,
189
190
  innerHTML: itemExtra.value,
190
191
  class: "m-form-tip"
191
192
  }, null, 8, _hoisted_3)) : createCommentVNode("v-if", true)
@@ -1,6 +1,6 @@
1
1
  import { display, filterFunction, initValue } from "../utils/form.js";
2
2
  import Container_default from "./Container.js";
3
- import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, inject, mergeProps, openBlock, ref, renderList, resolveDynamicComponent, toDisplayString, unref, watchEffect, withCtx } from "vue";
3
+ import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, inject, mergeProps, openBlock, ref, renderList, resolveDynamicComponent, toDisplayString, unref, watch, watchEffect, withCtx } from "vue";
4
4
  import { isEmpty } from "lodash-es";
5
5
  import { TMagicBadge, getDesignConfig } from "@tmagic/design";
6
6
  //#region packages/form/src/containers/Tabs.vue?vue&type=script&setup=true&lang.ts
@@ -74,6 +74,9 @@ var Tabs_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
74
74
  prop: props.prop
75
75
  });
76
76
  });
77
+ watch([() => props.model, () => props.lastValues], () => {
78
+ diffCount.value = {};
79
+ });
77
80
  const tabItems = (tab) => props.config.dynamic ? props.config.items : tab.items;
78
81
  const tabClickHandler = (tab) => {
79
82
  if (typeof tab === "object") tabClick(mForm, tab, props);
@@ -148,7 +151,7 @@ var Tabs_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
148
151
  default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(tabs.value, (tab, tabIndex) => {
149
152
  return openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), mergeProps({ key: tab[unref(mForm)?.keyProp || "__key"] ?? tabIndex }, { ref_for: true }, unref(tabPaneComponent)?.props({
150
153
  name: filter(tab.status) || tabIndex.toString(),
151
- lazy: tab.lazy || false
154
+ lazy: __props.isCompare ? false : tab.lazy || false
152
155
  }) || {}), {
153
156
  label: withCtx(() => [createElementVNode("span", null, [createTextVNode(toDisplayString(filter(tab.title)), 1), createVNode(unref(TMagicBadge), {
154
157
  hidden: !diffCount.value[Number(tabIndex)],
@@ -122,7 +122,7 @@ var Table_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
122
122
  default: withCtx(() => [createTextVNode(toDisplayString(unref(isFullscreen) ? "退出全屏" : "全屏编辑"), 1)]),
123
123
  _: 1
124
124
  }, 8, ["icon", "onClick"])) : createCommentVNode("v-if", true),
125
- unref(importable) ? (openBlock(), createBlock(unref(TMagicUpload), {
125
+ unref(importable) && !__props.isCompare ? (openBlock(), createBlock(unref(TMagicUpload), {
126
126
  key: 2,
127
127
  style: { "display": "inline-block" },
128
128
  ref: "excelBtn",
@@ -142,7 +142,7 @@ var Table_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
142
142
  }, 8, ["disabled"])]),
143
143
  _: 1
144
144
  }, 8, ["disabled", "on-change"])) : createCommentVNode("v-if", true),
145
- unref(importable) ? (openBlock(), createBlock(unref(TMagicButton), {
145
+ unref(importable) && !__props.isCompare ? (openBlock(), createBlock(unref(TMagicButton), {
146
146
  key: 3,
147
147
  size: "small",
148
148
  type: "warning",
@@ -153,7 +153,7 @@ var Table_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
153
153
  default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("清空", -1)])]),
154
154
  _: 1
155
155
  }, 8, ["disabled", "onClick"])) : createCommentVNode("v-if", true)
156
- ]), renderSlot(_ctx.$slots, "add-button")]),
156
+ ]), !__props.isCompare ? renderSlot(_ctx.$slots, "add-button", { key: 0 }) : createCommentVNode("v-if", true)]),
157
157
  __props.config.pagination ? (openBlock(), createElementBlock("div", _hoisted_4, [createVNode(unref(TMagicPagination), {
158
158
  layout: "total, sizes, prev, pager, next, jumper",
159
159
  "hide-on-single-page": __props.model[modelName.value].length < unref(pageSize),
package/dist/es/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import "./_virtual/_rolldown/runtime.js";
2
+ import { FORM_DIFF_CONFIG_KEY } from "./schema.js";
2
3
  import { useAddField } from "./utils/useAddField.js";
3
4
  import Hidden_default from "./fields/Hidden.js";
4
5
  import { deleteField, getField, registerField } from "./utils/config.js";
@@ -38,4 +39,4 @@ import plugin_default from "./plugin.js";
38
39
  export * from "@tmagic/form-schema";
39
40
  var createForm = (config) => config;
40
41
  //#endregion
41
- export { Cascader_default as MCascader, Checkbox_default as MCheckbox, CheckboxGroup_default as MCheckboxGroup, ColorPicker_default as MColorPicker, Container_default as MContainer, Date_default as MDate, DateTime_default as MDateTime, Daterange_default as MDaterange, Display_default as MDisplay, DynamicField_default as MDynamicField, Fieldset_default as MFieldset, FlexLayout_default as MFlexLayout, Form_default as MForm, FormBox_default as MFormBox, FormDialog_default as MFormDialog, FormDrawer_default as MFormDrawer, TableGroupList_default as MGroupList, Hidden_default as MHidden, Link_default as MLink, Number_default as MNumber, NumberRange_default as MNumberRange, Panel_default as MPanel, RadioGroup_default as MRadioGroup, Row_default as MRow, Select_default as MSelect, Switch_default as MSwitch, TableGroupList_default as MTable, TableGroupList_default as MTableGroupList, Tabs_default as MTabs, Text_default as MText, Textarea_default as MTextarea, Time_default as MTime, Timerange_default as MTimerange, createForm, createObjectProp, createValues, datetimeFormatter, plugin_default as default, deleteField as deleteFormField, display, filterFunction, getDataByPage, getField as getFormField, getRules, initValue, registerField as registerFormField, sortArray, sortChange, submitForm, useAddField };
42
+ export { FORM_DIFF_CONFIG_KEY, Cascader_default as MCascader, Checkbox_default as MCheckbox, CheckboxGroup_default as MCheckboxGroup, ColorPicker_default as MColorPicker, Container_default as MContainer, Date_default as MDate, DateTime_default as MDateTime, Daterange_default as MDaterange, Display_default as MDisplay, DynamicField_default as MDynamicField, Fieldset_default as MFieldset, FlexLayout_default as MFlexLayout, Form_default as MForm, FormBox_default as MFormBox, FormDialog_default as MFormDialog, FormDrawer_default as MFormDrawer, TableGroupList_default as MGroupList, Hidden_default as MHidden, Link_default as MLink, Number_default as MNumber, NumberRange_default as MNumberRange, Panel_default as MPanel, RadioGroup_default as MRadioGroup, Row_default as MRow, Select_default as MSelect, Switch_default as MSwitch, TableGroupList_default as MTable, TableGroupList_default as MTableGroupList, Tabs_default as MTabs, Text_default as MText, Textarea_default as MTextarea, Time_default as MTime, Timerange_default as MTimerange, createForm, createObjectProp, createValues, datetimeFormatter, plugin_default as default, deleteField as deleteFormField, display, filterFunction, getDataByPage, getField as getFormField, getRules, initValue, registerField as registerFormField, sortArray, sortChange, submitForm, useAddField };
package/dist/es/schema.js CHANGED
@@ -1,2 +1,6 @@
1
1
  import "./_virtual/_rolldown/runtime.js";
2
2
  export * from "@tmagic/form-schema";
3
+ //#region packages/form/src/schema.ts
4
+ var FORM_DIFF_CONFIG_KEY = Symbol("mFormDiffConfig");
5
+ //#endregion
6
+ export { FORM_DIFF_CONFIG_KEY };
package/dist/es/style.css CHANGED
@@ -10,7 +10,10 @@
10
10
  .m-form-container.has-tip .tmagic-design-form-item {
11
11
  flex: 1;
12
12
  }
13
- .m-form-container .tmagic-design-form-item.show-diff {
13
+ .m-form-container .tmagic-design-form-item.show-after-diff {
14
+ background: rgb(225, 243, 216);
15
+ }
16
+ .m-form-container .tmagic-design-form-item.show-before-diff {
14
17
  background: #f7dadd;
15
18
  }
16
19