@stonecrop/aform 0.62.6 → 0.62.8

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/aform.js CHANGED
@@ -2858,6 +2858,45 @@ function wordErrors(errors, validation) {
2858
2858
  const messages = errors.map((error) => error || validation?.errorMessage || "").filter(Boolean);
2859
2859
  return [...new Set(messages)];
2860
2860
  }
2861
+ // src/utils/reportedRecords.ts
2862
+ var pending = /* @__PURE__ */ new WeakMap();
2863
+ /** The record an edit to `handed` builds on: `handed` with the changes reported for it this tick laid over it. */
2864
+ var latestRecord = (handed) => {
2865
+ const changes = pending.get(handed);
2866
+ return changes ? {
2867
+ ...handed,
2868
+ ...changes
2869
+ } : handed;
2870
+ };
2871
+ /**
2872
+ * The changes reported for `handed` this tick: what a form handed it has changed. A nested form's edit is taken
2873
+ * from these, not from comparing the record it reports with `handed`, which cannot tell a field set back to its
2874
+ * handed value, such as a SKU cleared and retyped in one go, from a field left alone.
2875
+ */
2876
+ var reportedChanges = (handed) => pending.get(handed) ?? {};
2877
+ /** Notes `changes` as reported for `handed`, until the next tick, and returns the record to report. */
2878
+ var noteReported = (handed, changes) => {
2879
+ const kept = {
2880
+ ...pending.get(handed),
2881
+ ...changes
2882
+ };
2883
+ pending.set(handed, kept);
2884
+ nextTick(() => {
2885
+ if (pending.get(handed) === kept) pending.delete(handed);
2886
+ });
2887
+ return {
2888
+ ...handed,
2889
+ ...kept
2890
+ };
2891
+ };
2892
+ /**
2893
+ * The fields of `reported` that differ from `handed`: what a nested form changed, out of the whole record it
2894
+ * reports. A fieldset's form reports its whole record, laid over the record it was handed; taking all of it as
2895
+ * changes would put back that record's old value of a field the host has since filled in itself, such as a City
2896
+ * it fills when Name changes. A field it sets back to its handed value is still kept: its form is handed this
2897
+ * same record, so that edit is already among the changes reported for it.
2898
+ */
2899
+ var changedFields = (reported, handed) => Object.fromEntries(Object.entries(reported).filter(([key, value]) => !Object.is(value, handed[key])));
2861
2900
  // src/components/AForm.vue?vue&type=script&setup=true&lang.ts
2862
2901
  var _hoisted_1$14 = { class: "aform" };
2863
2902
  var _hoisted_2$10 = {
@@ -2894,10 +2933,9 @@ var AForm_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__
2894
2933
  const isLinkSection = (componentObj) => componentObj.kind === "link" && hasChildSchema(componentObj);
2895
2934
  const isFieldsetSection = (componentObj) => componentObj.kind === "fieldset" && hasChildSchema(componentObj);
2896
2935
  const applyChanges = (changes) => {
2897
- if (dataModel.value) dataModel.value = {
2898
- ...dataModel.value,
2899
- ...changes
2900
- };
2936
+ const handed = dataModel.value;
2937
+ if (!handed) return;
2938
+ dataModel.value = noteReported(handed, changes);
2901
2939
  };
2902
2940
  const nestedData = ref({});
2903
2941
  watch(() => dataModel.value, (newData) => {
@@ -2910,7 +2948,9 @@ var AForm_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__
2910
2948
  nestedData.value[fieldname] = val;
2911
2949
  applyChanges({ [fieldname]: val });
2912
2950
  };
2913
- const updateFieldsetData = (val) => applyChanges(val);
2951
+ const updateFieldsetData = (val) => {
2952
+ if (dataModel.value) applyChanges(changedFields(val, dataModel.value));
2953
+ };
2914
2954
  const isListExpansionTable = (componentObj) => componentObj.kind === "table" && componentObj.config?.view === "list-expansion";
2915
2955
  const tableExpansionSchema = (table) => table.schema.filter((col) => Boolean(col.component)).map(({ fieldname, component, ...rest }) => Object.assign(rest, {
2916
2956
  kind: "field",
@@ -2918,11 +2958,12 @@ var AForm_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__
2918
2958
  component
2919
2959
  }));
2920
2960
  const updateTableRows = (fieldname, rows) => applyChanges({ [fieldname]: rows });
2921
- const updateTableRow = (fieldname, rowIndex, val) => {
2922
- const rows = Array.isArray(dataModel.value?.[fieldname]) ? [...dataModel.value[fieldname]] : [];
2961
+ const updateTableRow = (fieldname, rowIndex, handedRow) => {
2962
+ const current = dataModel.value ? latestRecord(dataModel.value) : void 0;
2963
+ const rows = Array.isArray(current?.[fieldname]) ? [...current[fieldname]] : [];
2923
2964
  rows[rowIndex] = {
2924
2965
  ...rows[rowIndex],
2925
- ...val
2966
+ ...reportedChanges(handedRow)
2926
2967
  };
2927
2968
  updateTableRows(fieldname, rows);
2928
2969
  };
@@ -3052,7 +3093,7 @@ var AForm_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__
3052
3093
  data: row,
3053
3094
  schema: tableExpansionSchema(componentObj),
3054
3095
  mode: resolvedMode(componentObj)
3055
- }, toHandlers(listenersWhenHeard((val) => updateTableRow(componentObj.fieldname, rowIndex, val)))), null, 16, [
3096
+ }, toHandlers(listenersWhenHeard(() => updateTableRow(componentObj.fieldname, rowIndex, row)))), null, 16, [
3056
3097
  "data",
3057
3098
  "schema",
3058
3099
  "mode"
@@ -3070,7 +3111,7 @@ var AForm_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__
3070
3111
  }), 128))]);
3071
3112
  };
3072
3113
  }
3073
- }), [["__scopeId", "data-v-4db17a4f"]]);
3114
+ }), [["__scopeId", "data-v-0bcb72e3"]]);
3074
3115
  // src/components/base/CollapseButton.vue
3075
3116
  var CollapseButton_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__ */ defineComponent({
3076
3117
  __name: "CollapseButton",