@stonecrop/aform 0.47.0 → 0.48.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/README.md CHANGED
@@ -147,7 +147,7 @@ Provide `filterFunction` to enable the search dropdown. The function receives a
147
147
  The function is called in two distinct situations:
148
148
 
149
149
  1. **On user interaction** — when the user focuses or types into the field, the current input text is passed as the search string.
150
- 2. **On mount (and on id change)** — when the field has an `id` but no `displayText`, the function is called automatically with the existing `id` string so the display name can be resolved without user interaction. The first result whose `id` matches is used.
150
+ 2. **On mount (and on id change)** — when the field has an `id` but no `displayText`, the function is called automatically with the existing `id` string so the display name can be resolved without user interaction. The first result whose `id` matches is shown; the bound value keeps its bare `id`, since a lookup is not an edit.
151
151
 
152
152
  Because of case 2, implementations should handle both name-based searches (partial strings typed by the user) and exact id lookups (full id strings passed on mount). A common pattern is to attempt both:
153
153
 
package/dist/aform.js CHANGED
@@ -1,7 +1,7 @@
1
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
- import { currencyAmountEntryPattern, currencyInputFractionDigits, formatCurrencyAmount, formatCurrencyAmountInput, fromISODate, isSemver, isSemverPrefix, parseCurrencyAmountInput } from "@stonecrop/utilities";
4
+ import { currencyAmountEntryPattern, currencyInputFractionDigits, formatCurrencyAmount, formatCurrencyAmountInput, formatCurrencySymbol, fromISODate, isSemver, isSemverPrefix, parseCurrencyAmountInput } from "@stonecrop/utilities";
5
5
  import { vOnClickOutside } from "@vueuse/components";
6
6
  import { Temporal } from "temporal-polyfill";
7
7
  import { onClickOutside, useElementBounding, useFileDialog } from "@vueuse/core";
@@ -537,7 +537,18 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
537
537
  const record = asLinkValue(value);
538
538
  return __props.formatter ? __props.formatter(record) : linkDisplayText(record) ?? String(record.id);
539
539
  };
540
- const linkDisplayedText = computed(() => linkId(linkModel.value) === void 0 ? "—" : linkText(linkModel.value));
540
+ const knownLink = ref();
541
+ watch(() => linkModel.value, (value) => {
542
+ if (linkPicker.value && linkDisplayText(value)) knownLink.value = asLinkValue(value);
543
+ }, { immediate: true });
544
+ const shownLink = computed(() => {
545
+ const value = linkModel.value;
546
+ if (linkDisplayText(value)) return value;
547
+ const id = linkId(value);
548
+ const known = knownLink.value;
549
+ return known && id !== void 0 && String(known.id) === String(id) ? known : value;
550
+ });
551
+ const linkDisplayedText = computed(() => linkId(shownLink.value) === void 0 ? "—" : linkText(shownLink.value));
541
552
  const search = ref("");
542
553
  watch(modelValue, (value) => {
543
554
  if (linkPicker.value) return;
@@ -545,16 +556,12 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
545
556
  search.value = next;
546
557
  if (next === "" || choiceList.value.includes(next)) committedValue.value = next;
547
558
  }, { immediate: true });
548
- watch(() => linkModel.value, (value) => {
559
+ watch(shownLink, (value) => {
549
560
  if (!linkPicker.value) return;
550
561
  search.value = linkId(value) ? linkText(value) : "";
551
562
  }, { immediate: true });
552
- watch(() => linkPicker.value ? linkId(linkModel.value) : void 0, async (id) => {
563
+ watch(() => linkPicker.value && !linkDisplayText(shownLink.value) ? linkId(linkModel.value) : void 0, async (id) => {
553
564
  if (!linkPicker.value || !id) return;
554
- if (linkDisplayText(linkModel.value)) {
555
- search.value = linkText(linkModel.value);
556
- return;
557
- }
558
565
  try {
559
566
  let match;
560
567
  let displayText;
@@ -562,16 +569,12 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
562
569
  match = (await (typeof __props.linkFilterFunction === "string" ? deserializeFunction(__props.linkFilterFunction) : __props.linkFilterFunction)(String(id))).find((r) => String(r.id) === String(id));
563
570
  displayText = match?.displayText;
564
571
  } else if (resolver && __props.doctype) displayText = await resolver(__props.doctype, id.toString()) ?? void 0;
565
- if (displayText) {
566
- const resolved = {
567
- ...asLinkValue(linkModel.value),
568
- ...match,
569
- id,
570
- displayText
571
- };
572
- search.value = linkText(resolved);
573
- linkModel.value = resolved;
574
- }
572
+ if (displayText) knownLink.value = {
573
+ ...asLinkValue(linkModel.value),
574
+ ...match,
575
+ id,
576
+ displayText
577
+ };
575
578
  } catch {}
576
579
  }, { immediate: true });
577
580
  const onClickOutside = () => closeDropdown();
@@ -580,7 +583,7 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
580
583
  const id = linkId(linkModel.value);
581
584
  return id !== void 0 && String(option.id) === String(id);
582
585
  };
583
- const embeddedLinkDisplayText = computed(() => linkId(linkModel.value) ? linkText(linkModel.value) : __props.placeholder ?? "");
586
+ const embeddedLinkDisplayText = computed(() => linkId(shownLink.value) ? linkText(shownLink.value) : __props.placeholder ?? "");
584
587
  const embeddedLinkInputSize = computed(() => {
585
588
  if (!__props.embedded || !linkPicker.value) return void 0;
586
589
  const text = embeddedLinkDisplayText.value;
@@ -607,8 +610,8 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
607
610
  };
608
611
  const embeddedLinkFilterQuery = () => {
609
612
  if (!__props.embedded || !linkPicker.value) return search.value;
610
- if (linkId(linkModel.value) && __props.formatter) {
611
- const formatted = __props.formatter(asLinkValue(linkModel.value));
613
+ if (linkId(shownLink.value) && __props.formatter) {
614
+ const formatted = __props.formatter(asLinkValue(shownLink.value));
612
615
  if (search.value === formatted) return "";
613
616
  }
614
617
  return search.value;
@@ -654,7 +657,7 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
654
657
  dropdown.activeItemIndex = null;
655
658
  dropdown.open = false;
656
659
  if (linkPicker.value) {
657
- search.value = linkId(linkModel.value) ? linkText(linkModel.value) : "";
660
+ search.value = linkId(shownLink.value) ? linkText(shownLink.value) : "";
658
661
  return;
659
662
  }
660
663
  const typed = result || search.value || "";
@@ -859,7 +862,7 @@ var ADropdown_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
859
862
  }, toDisplayString(errorText.value), 9, _hoisted_11$5)), [[vShow, errorText.value]]) : createCommentVNode("", true)], 64))], 2);
860
863
  };
861
864
  }
862
- }), [["__scopeId", "data-v-32a34889"]]);
865
+ }), [["__scopeId", "data-v-a96ab394"]]);
863
866
  //#endregion
864
867
  //#region src/components/form/ACurrencyInput.vue?vue&type=script&setup=true&lang.ts
865
868
  var _hoisted_1$23 = { class: "aform_form-element acurrency" };
@@ -932,7 +935,6 @@ var ACurrencyInput_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/*
932
935
  });
933
936
  const helperDescribedBy = computed(() => showBase.value && !errorText.value ? helperId.value : void 0);
934
937
  const { errorId, describedBy, invalid } = fieldErrorA11y(__props.uuid, errorText, helperDescribedBy);
935
- const currencySymbol = (value) => value.symbol ?? value.displayText ?? String(value.id);
936
938
  const currencyDropdownRef = useTemplateRef("currencyDropdownRef");
937
939
  const openCurrencyList = () => {
938
940
  currencyDropdownRef.value?.openCurrencyList?.();
@@ -1097,7 +1099,7 @@ var ACurrencyInput_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/*
1097
1099
  required: __props.required,
1098
1100
  placeholder: __props.currencyLabel,
1099
1101
  "aria-label": __props.currencyLabel,
1100
- formatter: currencySymbol,
1102
+ formatter: unref(formatCurrencySymbol),
1101
1103
  doctype: __props.options.doctype,
1102
1104
  "link-filter-function": __props.options.filterFunction,
1103
1105
  "is-async": __props.options.isAsync
@@ -1110,6 +1112,7 @@ var ACurrencyInput_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/*
1110
1112
  "required",
1111
1113
  "placeholder",
1112
1114
  "aria-label",
1115
+ "formatter",
1113
1116
  "doctype",
1114
1117
  "link-filter-function",
1115
1118
  "is-async"
@@ -1172,7 +1175,7 @@ var ACurrencyInput_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/*
1172
1175
  ], 64))]);
1173
1176
  };
1174
1177
  }
1175
- }), [["__scopeId", "data-v-066d286c"]]);
1178
+ }), [["__scopeId", "data-v-f934faab"]]);
1176
1179
  //#endregion
1177
1180
  //#region src/utils/typedDay.ts
1178
1181
  var TYPED_DAY_FORMAT = {
@@ -3102,11 +3105,22 @@ var AFormLink_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
3102
3105
  const listboxId = `${__props.uuid ?? `aform-link-${useId()}`}-listbox`;
3103
3106
  const modelValue = useModel(__props, "modelValue");
3104
3107
  const hasValidId = computed(() => linkId(modelValue.value) !== void 0);
3108
+ const knownLink = ref();
3109
+ watch(() => modelValue.value, (value) => {
3110
+ if (linkDisplayText(value)) knownLink.value = asLinkValue(value);
3111
+ }, { immediate: true });
3112
+ const shownLink = computed(() => {
3113
+ const value = modelValue.value;
3114
+ if (linkDisplayText(value)) return value;
3115
+ const id = linkId(value);
3116
+ const known = knownLink.value;
3117
+ return known && id !== void 0 && String(known.id) === String(id) ? known : value;
3118
+ });
3105
3119
  const displayedText = computed(() => {
3106
- const id = linkId(modelValue.value);
3120
+ const id = linkId(shownLink.value);
3107
3121
  if (id === void 0) return "—";
3108
- if (__props.formatter) return __props.formatter(asLinkValue(modelValue.value));
3109
- return linkDisplayText(modelValue.value) ?? id;
3122
+ if (__props.formatter) return __props.formatter(asLinkValue(shownLink.value));
3123
+ return linkDisplayText(shownLink.value) ?? id;
3110
3124
  });
3111
3125
  const searchText = ref(hasValidId.value ? displayedText.value : "");
3112
3126
  const dropdownOpen = ref(false);
@@ -3116,7 +3130,7 @@ var AFormLink_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
3116
3130
  const navigator = inject("aformLinkNavigator", null);
3117
3131
  const resolver = inject("aformLinkResolver", null);
3118
3132
  watch(() => linkId(modelValue.value), async (id) => {
3119
- if (id && linkDisplayText(modelValue.value)) {
3133
+ if (id && linkDisplayText(shownLink.value)) {
3120
3134
  searchText.value = displayedText.value;
3121
3135
  return;
3122
3136
  }
@@ -3130,14 +3144,13 @@ var AFormLink_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
3130
3144
  if (displayText === void 0) console.warn(`[AFormLink] filterFunction returned no matching result for id "${id}". The function must return an item whose \`id\` exactly matches the search string.`);
3131
3145
  } else if (resolver && __props.doctype) displayText = await resolver(__props.doctype, id.toString()) ?? void 0;
3132
3146
  if (displayText) {
3133
- const resolved = {
3147
+ knownLink.value = {
3134
3148
  ...asLinkValue(modelValue.value),
3135
3149
  ...match,
3136
3150
  id,
3137
3151
  displayText
3138
3152
  };
3139
- searchText.value = __props.formatter ? __props.formatter(resolved) : displayText;
3140
- modelValue.value = resolved;
3153
+ searchText.value = displayedText.value;
3141
3154
  }
3142
3155
  } catch {}
3143
3156
  }, { immediate: true });
@@ -3260,7 +3273,7 @@ var AFormLink_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PU
3260
3273
  ])) : createCommentVNode("", true)])), [[unref(vOnClickOutside), onClickOutside]]), __props.label && !__props.embedded ? (openBlock(), createElementBlock("label", _hoisted_13, toDisplayString(__props.label), 1)) : createCommentVNode("", true)], 64))], 2);
3261
3274
  };
3262
3275
  }
3263
- }), [["__scopeId", "data-v-e784f691"]]);
3276
+ }), [["__scopeId", "data-v-7e0002c9"]]);
3264
3277
  //#endregion
3265
3278
  //#region src/components/form/ANumericInput.vue?vue&type=script&setup=true&lang.ts
3266
3279
  var _hoisted_1$11 = { class: "aform_form-element" };