@stonecrop/aform 0.46.1 → 0.47.0

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
@@ -1,4 +1,4 @@
1
- import { hasBadgeOptions, isBadgeDescriptor, lookupBadge, selectChoices } from "@stonecrop/schema";
1
+ import { hasBadgeOptions, isBadgeDescriptor, lookupBadge, partsPatch, readParts, selectChoices } from "@stonecrop/schema";
2
2
  import { TABLE_TUPLE_CURRENCY_PICKER, TABLE_TUPLE_QUANTITY_PICKER, install as install$1, isTableTuplePickerModal } from "@stonecrop/atable";
3
3
  import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, inject, mergeModels, mergeProps, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, provide, reactive, ref, renderList, renderSlot, resolveComponent, resolveDynamicComponent, toDisplayString, unref, useId, useModel, useTemplateRef, vModelCheckbox, vModelRadio, vModelSelect, vModelText, vShow, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers } from "vue";
4
4
  import { currencyAmountEntryPattern, currencyInputFractionDigits, formatCurrencyAmount, formatCurrencyAmountInput, fromISODate, isSemver, isSemverPrefix, parseCurrencyAmountInput } from "@stonecrop/utilities";
@@ -207,6 +207,27 @@ var _plugin_vue_export_helper_default = (sfc, props) => {
207
207
  //#region src/components/form/ACheckbox.vue
208
208
  var ACheckbox_default = /*#__PURE__*/ _plugin_vue_export_helper_default(ACheckbox_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-f28e7db6"]]);
209
209
  //#endregion
210
+ //#region src/utils/linkValue.ts
211
+ function linkId(value) {
212
+ if (value == null) return void 0;
213
+ if (typeof value === "string") return value === "" ? void 0 : value;
214
+ if (typeof value === "number") return String(value);
215
+ const id = value.id;
216
+ if (id === null || id === void 0 || id === "") return void 0;
217
+ return String(id);
218
+ }
219
+ function linkDisplayText(value) {
220
+ if (value == null || typeof value !== "object") return void 0;
221
+ const text = value.displayText;
222
+ if (typeof text === "string") return text;
223
+ if (typeof text === "number") return String(text);
224
+ }
225
+ function asLinkValue(value) {
226
+ if (value != null && typeof value === "object") return value;
227
+ const id = linkId(value);
228
+ return id !== void 0 ? { id } : { id: "" };
229
+ }
230
+ //#endregion
210
231
  //#region src/utils/currencyValue.ts
211
232
  var FLOAT_NOISE_DECIMALS = 6;
212
233
  function normalizeBaseCurrency(options, current) {
@@ -222,7 +243,7 @@ function baseAmountDecimals(options) {
222
243
  function resolveCurrencyExchangeRate(currencyId, options, baseCurrency, current) {
223
244
  const baseId = baseCurrency.id;
224
245
  if (!currencyId || String(currencyId) === String(baseId)) return 1;
225
- if (String(currencyId) === String(current?.currency?.id)) return current?.exchangeRate ?? options.exchangeRates?.[String(currencyId)] ?? 1;
246
+ if (String(currencyId) === linkId(current?.currency)) return current?.exchangeRate ?? options.exchangeRates?.[String(currencyId)] ?? 1;
226
247
  return options.exchangeRates?.[String(currencyId)] ?? 1;
227
248
  }
228
249
  var roundAmount = (value, decimals) => Number(value.toFixed(decimals));
@@ -238,7 +259,12 @@ function recomputeCurrencyValue(amount, currencyValue, options, baseCurrency, cu
238
259
  };
239
260
  }
240
261
  function patchCurrencyAmount(current, amount, options, baseCurrency) {
241
- return recomputeCurrencyValue(amount, current?.currency ?? { id: "" }, options, baseCurrency, current);
262
+ if (!current) return recomputeCurrencyValue(amount, { id: "" }, options, baseCurrency, current);
263
+ return {
264
+ ...recomputeCurrencyValue(amount, current.currency ?? { id: "" }, options, baseCurrency, current),
265
+ currency: current.currency,
266
+ exchangeRate: current.exchangeRate
267
+ };
242
268
  }
243
269
  function patchCurrencyCurrency(current, currencyValue, options, baseCurrency) {
244
270
  return recomputeCurrencyValue(current?.amount ?? null, currencyValue, options, baseCurrency, current);
@@ -283,25 +309,14 @@ function numberFromBox(value) {
283
309
  return value === "" ? null : value;
284
310
  }
285
311
  //#endregion
286
- //#region src/utils/linkValue.ts
287
- function linkId(value) {
288
- if (value == null) return void 0;
289
- if (typeof value === "string") return value === "" ? void 0 : value;
290
- if (typeof value === "number") return String(value);
291
- const id = value.id;
292
- if (id === null || id === void 0 || id === "") return void 0;
293
- return String(id);
294
- }
295
- function linkDisplayText(value) {
296
- if (value == null || typeof value !== "object") return void 0;
297
- const text = value.displayText;
298
- if (typeof text === "string") return text;
299
- if (typeof text === "number") return String(text);
300
- }
301
- function asLinkValue(value) {
302
- if (value != null && typeof value === "object") return value;
303
- const id = linkId(value);
304
- return id !== void 0 ? { id } : { id: "" };
312
+ //#region src/utils/recordNumber.ts
313
+ /**
314
+ * A number part of a box's value as a number, or null when it holds none. A part read from a record's
315
+ * own field holds what the server sent, and Postgres sends a `numeric` column as its decimal text.
316
+ */
317
+ function numberFromRecord(value) {
318
+ if (value === null || value === void 0 || value === "") return null;
319
+ return typeof value === "number" ? value : Number(value);
305
320
  }
306
321
  //#endregion
307
322
  //#region src/composables/dropdownList.ts
@@ -902,9 +917,18 @@ var ACurrencyInput_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/*
902
917
  const errorText = computed(() => __props.errors?.length ? __props.errors.join("; ") : __props.validation.errorMessage ?? "");
903
918
  const helperId = computed(() => __props.uuid ? `${__props.uuid}-helper` : void 0);
904
919
  const modelValue = useModel(__props, "modelValue");
920
+ const shown = computed(() => {
921
+ const boxValue = modelValue.value;
922
+ if (!boxValue) return null;
923
+ const readValue = {
924
+ ...boxValue,
925
+ currency: asLinkValue(boxValue.currency)
926
+ };
927
+ return recomputeCurrencyValue(numberFromRecord(boxValue.amount), readValue.currency, __props.options, normalizeBaseCurrency(__props.options, boxValue), readValue);
928
+ });
905
929
  const showBase = computed(() => {
906
- const v = modelValue.value;
907
- return !!v?.baseCurrency?.id && (v.currency?.id !== v.baseCurrency?.id || v.amount !== v.baseAmount);
930
+ const shownValue = shown.value;
931
+ return !!shownValue?.baseCurrency?.id && (shownValue.currency?.id !== shownValue.baseCurrency?.id || shownValue.amount !== shownValue.baseAmount);
908
932
  });
909
933
  const helperDescribedBy = computed(() => showBase.value && !errorText.value ? helperId.value : void 0);
910
934
  const { errorId, describedBy, invalid } = fieldErrorA11y(__props.uuid, errorText, helperDescribedBy);
@@ -925,7 +949,7 @@ var ACurrencyInput_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/*
925
949
  const amountMaskEnabled = computed(() => __props.options.amountMask !== false);
926
950
  const amountFocused = ref(false);
927
951
  const amountText = ref("");
928
- const selectedCurrencyId = computed(() => String(modelValue.value?.currency?.id ?? ""));
952
+ const selectedCurrencyId = computed(() => linkId(modelValue.value?.currency) ?? "");
929
953
  const syncAmountTextFromModel = () => {
930
954
  amountText.value = formatCurrencyAmountInput(modelValue.value?.amount ?? null, selectedCurrencyId.value);
931
955
  };
@@ -1041,19 +1065,19 @@ var ACurrencyInput_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/*
1041
1065
  if (!currencyAmountEntryPattern(selectedCurrencyId.value).test(text)) event.preventDefault();
1042
1066
  };
1043
1067
  const conversionHelperText = computed(() => {
1044
- const v = modelValue.value;
1045
- if (!v || v.baseAmount === null || v.amount === null) return "";
1046
- const baseLabel = baseCurrencyText.value || String(v.baseCurrency?.id ?? "");
1047
- const enteredId = String(v.currency?.id ?? "");
1048
- const rate = v.exchangeRate;
1049
- return `≈ ${formatCurrencyAmount(v.baseAmount, v.baseCurrency)} · 1 ${enteredId} = ${rate} ${baseLabel}`;
1068
+ const shownValue = shown.value;
1069
+ if (!shownValue || shownValue.baseAmount === null || shownValue.amount === null) return "";
1070
+ const baseLabel = baseCurrencyText.value || String(shownValue.baseCurrency?.id ?? "");
1071
+ const enteredId = String(shownValue.currency?.id ?? "");
1072
+ const rate = shownValue.exchangeRate;
1073
+ return `≈ ${formatCurrencyAmount(shownValue.baseAmount, shownValue.baseCurrency)} · 1 ${enteredId} = ${rate} ${baseLabel}`;
1050
1074
  });
1051
1075
  const displayText = computed(() => {
1052
- const v = modelValue.value;
1053
- if (!v || !v.currency?.id || v.amount === null) return "—";
1054
- const base = formatCurrencyAmount(v.amount, v.currency);
1076
+ const shownValue = shown.value;
1077
+ if (!shownValue || !shownValue.currency?.id || shownValue.amount === null) return "—";
1078
+ const base = formatCurrencyAmount(shownValue.amount, shownValue.currency);
1055
1079
  if (!showBase.value) return base;
1056
- return `${base} (≈ ${formatCurrencyAmount(v.baseAmount, v.baseCurrency)})`;
1080
+ return `${base} (≈ ${formatCurrencyAmount(shownValue.baseAmount, shownValue.baseCurrency)})`;
1057
1081
  });
1058
1082
  return (_ctx, _cache) => {
1059
1083
  return openBlock(), createElementBlock("div", _hoisted_1$23, [__props.mode === "display" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createElementVNode("span", _hoisted_2$19, toDisplayString(displayText.value), 1), createElementVNode("label", _hoisted_3$16, toDisplayString(__props.label), 1)], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
@@ -1148,7 +1172,7 @@ var ACurrencyInput_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/*
1148
1172
  ], 64))]);
1149
1173
  };
1150
1174
  }
1151
- }), [["__scopeId", "data-v-7de4a96e"]]);
1175
+ }), [["__scopeId", "data-v-066d286c"]]);
1152
1176
  //#endregion
1153
1177
  //#region src/utils/typedDay.ts
1154
1178
  var TYPED_DAY_FORMAT = {
@@ -2732,7 +2756,8 @@ var AForm_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__
2732
2756
  "hidden",
2733
2757
  "mode",
2734
2758
  "width",
2735
- "height"
2759
+ "height",
2760
+ "parts"
2736
2761
  ].includes(key)) propsToPass[key] = value;
2737
2762
  propsToPass["uuid"] ??= `${formId}-${componentObj.fieldname}`;
2738
2763
  if (componentObj.kind === "table") {
@@ -2762,17 +2787,29 @@ var AForm_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__
2762
2787
  if (fieldMode) return fieldMode;
2763
2788
  return effectiveFormMode.value;
2764
2789
  }
2790
+ const fieldParts = (field) => field.kind === "field" ? field.parts : void 0;
2791
+ const fieldErrors = (field) => {
2792
+ const parts = fieldParts(field);
2793
+ if (!parts) return __props.errors?.[field.fieldname];
2794
+ return Object.values(parts).flatMap((fieldname) => __props.errors?.[fieldname] ?? []);
2795
+ };
2765
2796
  const childModelsCache = ref([]);
2766
2797
  watchEffect(() => {
2767
2798
  if (!__props.schema) return;
2768
- if (childModelsCache.value.length !== __props.schema.length) childModelsCache.value = __props.schema.map((_val, i) => {
2799
+ if (childModelsCache.value.length !== __props.schema.length) childModelsCache.value = __props.schema.map((_field, index) => {
2769
2800
  return computed({
2770
2801
  get() {
2771
- return dataModel.value?.[__props.schema[i].fieldname];
2802
+ const parts = fieldParts(__props.schema[index]);
2803
+ if (parts) return readParts(parts, dataModel.value ?? {});
2804
+ return dataModel.value?.[__props.schema[index].fieldname];
2772
2805
  },
2773
2806
  set: (newValue) => {
2774
- const fieldname = __props.schema[i].fieldname;
2775
- if (fieldname && dataModel.value) {
2807
+ const parts = fieldParts(__props.schema[index]);
2808
+ const fieldname = __props.schema[index].fieldname;
2809
+ if (parts && dataModel.value) {
2810
+ Object.assign(dataModel.value, partsPatch(parts, dataModel.value, newValue));
2811
+ emit("update:data", { ...dataModel.value });
2812
+ } else if (fieldname && dataModel.value) {
2776
2813
  dataModel.value[fieldname] = newValue;
2777
2814
  emit("update:data", { ...dataModel.value });
2778
2815
  }
@@ -2822,7 +2859,7 @@ var AForm_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__
2822
2859
  schema: componentObj,
2823
2860
  data: dataModel.value[componentObj.fieldname],
2824
2861
  mode: resolvedMode(componentObj),
2825
- errors: __props.errors?.[componentObj.fieldname]
2862
+ errors: fieldErrors(componentObj)
2826
2863
  }, { ref_for: true }, componentProps(componentObj)), createSlots({ _: 2 }, [isListExpansionTable(componentObj) ? {
2827
2864
  name: "content",
2828
2865
  fn: withCtx(({ row, rowIndex }) => [createVNode(_component_AForm, {
@@ -2850,7 +2887,7 @@ var AForm_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__
2850
2887
  }), 128))]);
2851
2888
  };
2852
2889
  }
2853
- }), [["__scopeId", "data-v-648dd570"]]);
2890
+ }), [["__scopeId", "data-v-e40cafaf"]]);
2854
2891
  //#endregion
2855
2892
  //#region src/components/base/CollapseButton.vue
2856
2893
  var CollapseButton_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__ */ defineComponent({
@@ -3314,7 +3351,7 @@ function recomputeQuantityValue(qty, uom, options, current) {
3314
3351
  };
3315
3352
  }
3316
3353
  function patchQuantityQty(current, qty, options) {
3317
- return recomputeQuantityValue(qty, current?.uom ?? "", options, current);
3354
+ return recomputeQuantityValue(qty, current ? current.uom : "", options, current);
3318
3355
  }
3319
3356
  function patchQuantityUom(current, uom, options) {
3320
3357
  return recomputeQuantityValue(current?.qty ?? null, uom, options, current);
@@ -3400,21 +3437,25 @@ var AQuantityInput_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/*
3400
3437
  const pasted = event.clipboardData?.getData("text") ?? "";
3401
3438
  if (!quantityEntryPattern.test(pasted)) event.preventDefault();
3402
3439
  };
3440
+ const shown = computed(() => {
3441
+ const boxValue = modelValue.value;
3442
+ return boxValue ? recomputeQuantityValue(numberFromRecord(boxValue.qty), boxValue.uom, __props.options, boxValue) : null;
3443
+ });
3403
3444
  const showStock = computed(() => {
3404
- const v = modelValue.value;
3405
- return !!v?.stockUom && (v.uom !== v.stockUom || v.qty !== v.stockQty);
3445
+ const shownValue = shown.value;
3446
+ return !!shownValue?.stockUom && (shownValue.uom !== shownValue.stockUom || shownValue.qty !== shownValue.stockQty);
3406
3447
  });
3407
3448
  const conversionHelperText = computed(() => {
3408
- const v = modelValue.value;
3409
- if (!v || v.stockQty === null || v.qty === null) return "";
3410
- const factor = v.conversionFactor;
3411
- return `= ${v.stockQty} ${v.stockUom} · 1 ${v.uom} = ${factor} ${v.stockUom}`;
3449
+ const shownValue = shown.value;
3450
+ if (!shownValue || shownValue.stockQty === null || shownValue.qty === null) return "";
3451
+ const factor = shownValue.conversionFactor;
3452
+ return `= ${shownValue.stockQty} ${shownValue.stockUom} · 1 ${shownValue.uom} = ${factor} ${shownValue.stockUom}`;
3412
3453
  });
3413
3454
  const displayText = computed(() => {
3414
- const v = modelValue.value;
3415
- if (!v || !v.uom || v.qty === null) return "—";
3416
- const base = `${v.qty} ${v.uom}`;
3417
- return showStock.value ? `${base} (${v.stockQty} ${v.stockUom})` : base;
3455
+ const shownValue = shown.value;
3456
+ if (!shownValue || !shownValue.uom || shownValue.qty === null) return "—";
3457
+ const base = `${shownValue.qty} ${shownValue.uom}`;
3458
+ return showStock.value ? `${base} (${shownValue.stockQty} ${shownValue.stockUom})` : base;
3418
3459
  });
3419
3460
  return (_ctx, _cache) => {
3420
3461
  return openBlock(), createElementBlock("div", _hoisted_1$10, [__props.mode === "display" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createElementVNode("span", _hoisted_2$6, toDisplayString(displayText.value), 1), createElementVNode("label", _hoisted_3$4, toDisplayString(__props.label), 1)], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
@@ -3473,7 +3514,7 @@ var AQuantityInput_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/*
3473
3514
  ], 64))]);
3474
3515
  };
3475
3516
  }
3476
- }), [["__scopeId", "data-v-3d289084"]]);
3517
+ }), [["__scopeId", "data-v-9bdbcd8c"]]);
3477
3518
  //#endregion
3478
3519
  //#region src/components/form/ASemverInput.vue?vue&type=script&setup=true&lang.ts
3479
3520
  var _hoisted_1$9 = { class: "aform_form-element" };