@atscript/vue-form 0.1.58

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 (190) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -0
  3. package/dist/as-action-71f9E_bL.cjs +208 -0
  4. package/dist/as-action-DU17rykn.mjs +203 -0
  5. package/dist/as-action.cjs +2 -0
  6. package/dist/as-action.d.cts +2 -0
  7. package/dist/as-action.d.mts +2 -0
  8. package/dist/as-action.mjs +2 -0
  9. package/dist/as-action.vue-BdbAOZCL.d.cts +13 -0
  10. package/dist/as-action.vue-CmY3eil1.d.mts +13 -0
  11. package/dist/as-adornment-shell-9UmdNIPR.cjs +97 -0
  12. package/dist/as-adornment-shell-knFiB7Ct.mjs +92 -0
  13. package/dist/as-array-Bn27x9cq.cjs +466 -0
  14. package/dist/as-array-DwarTaKP.mjs +455 -0
  15. package/dist/as-array-clear-btn-DAGervXL.cjs +48 -0
  16. package/dist/as-array-clear-btn-DIhzCKC9.mjs +43 -0
  17. package/dist/as-array.cjs +11 -0
  18. package/dist/as-array.d.cts +2 -0
  19. package/dist/as-array.d.mts +2 -0
  20. package/dist/as-array.mjs +11 -0
  21. package/dist/as-array.vue-C5r_ycIa.d.mts +9 -0
  22. package/dist/as-array.vue-CeBZRVm7.d.cts +9 -0
  23. package/dist/as-checkbox-B_9mwla6.mjs +285 -0
  24. package/dist/as-checkbox-DXGTVHPE.cjs +296 -0
  25. package/dist/as-checkbox.cjs +6 -0
  26. package/dist/as-checkbox.d.cts +2 -0
  27. package/dist/as-checkbox.d.mts +2 -0
  28. package/dist/as-checkbox.mjs +6 -0
  29. package/dist/as-checkbox.vue-BL53Xjmi.d.mts +9 -0
  30. package/dist/as-checkbox.vue-Da1KVG5J.d.cts +9 -0
  31. package/dist/as-collapsible-CqxeJut7.cjs +148 -0
  32. package/dist/as-collapsible-DtNCofNT.mjs +143 -0
  33. package/dist/as-date-C7tFQDkh.mjs +253 -0
  34. package/dist/as-date-k3MW3dmA.cjs +258 -0
  35. package/dist/as-date.cjs +8 -0
  36. package/dist/as-date.d.cts +2 -0
  37. package/dist/as-date.d.mts +2 -0
  38. package/dist/as-date.mjs +8 -0
  39. package/dist/as-date.vue-C5JaS3Sd.d.mts +9 -0
  40. package/dist/as-date.vue-e2ewS_V4.d.cts +9 -0
  41. package/dist/as-datetime-C030mzI5.cjs +258 -0
  42. package/dist/as-datetime-elcOoDT5.mjs +253 -0
  43. package/dist/as-datetime.cjs +8 -0
  44. package/dist/as-datetime.d.cts +2 -0
  45. package/dist/as-datetime.d.mts +2 -0
  46. package/dist/as-datetime.mjs +8 -0
  47. package/dist/as-datetime.vue-ClsSnJSV.d.mts +9 -0
  48. package/dist/as-datetime.vue-vfHFsby6.d.cts +9 -0
  49. package/dist/as-decimal-BJIGgPXU.cjs +711 -0
  50. package/dist/as-decimal-DtXjFPhe.mjs +694 -0
  51. package/dist/as-decimal.cjs +7 -0
  52. package/dist/as-decimal.d.cts +2 -0
  53. package/dist/as-decimal.d.mts +2 -0
  54. package/dist/as-decimal.mjs +7 -0
  55. package/dist/as-decimal.vue-B1pEKdjM.d.cts +25 -0
  56. package/dist/as-decimal.vue-CSCtYRRa.d.mts +25 -0
  57. package/dist/as-field-CXVjrEPQ.mjs +481 -0
  58. package/dist/as-field-shell-B2iTn-iM.cjs +346 -0
  59. package/dist/as-field-shell-Pdy3sAvr.mjs +341 -0
  60. package/dist/as-field-shell.cjs +5 -0
  61. package/dist/as-field-shell.d.cts +2 -0
  62. package/dist/as-field-shell.d.mts +2 -0
  63. package/dist/as-field-shell.mjs +5 -0
  64. package/dist/as-field-shell.vue-Ddnp8KxY.d.mts +37 -0
  65. package/dist/as-field-shell.vue-Dmt05vGD.d.cts +37 -0
  66. package/dist/as-field-wLYoaZnT.cjs +498 -0
  67. package/dist/as-field.cjs +4 -0
  68. package/dist/as-field.d.cts +25 -0
  69. package/dist/as-field.d.mts +26 -0
  70. package/dist/as-field.mjs +4 -0
  71. package/dist/as-form-CWwgyvfw.mjs +425 -0
  72. package/dist/as-form-DAIkyt7H.cjs +448 -0
  73. package/dist/as-form.cjs +7 -0
  74. package/dist/as-form.d.cts +2 -0
  75. package/dist/as-form.d.mts +2 -0
  76. package/dist/as-form.mjs +7 -0
  77. package/dist/as-form.vue-B4Bn0pbC.d.cts +158 -0
  78. package/dist/as-form.vue-DRrb_yoj.d.mts +158 -0
  79. package/dist/as-input-CpbV2k3s.cjs +231 -0
  80. package/dist/as-input-DIa8BzLv.mjs +226 -0
  81. package/dist/as-input-control-BzELjheN.mjs +266 -0
  82. package/dist/as-input-control-C5-DelZT.cjs +271 -0
  83. package/dist/as-input.cjs +8 -0
  84. package/dist/as-input.d.cts +2 -0
  85. package/dist/as-input.d.mts +2 -0
  86. package/dist/as-input.mjs +8 -0
  87. package/dist/as-input.vue-11ldp9uT.d.cts +17 -0
  88. package/dist/as-input.vue-fUhcvfv2.d.mts +17 -0
  89. package/dist/as-iterator-BYMNe6UJ.cjs +61 -0
  90. package/dist/as-iterator-CT5y1jyn.mjs +56 -0
  91. package/dist/as-iterator.cjs +5 -0
  92. package/dist/as-iterator.d.cts +14 -0
  93. package/dist/as-iterator.d.mts +15 -0
  94. package/dist/as-iterator.mjs +5 -0
  95. package/dist/as-number-BA55JIq1.cjs +387 -0
  96. package/dist/as-number-JPEwPK8Q.mjs +376 -0
  97. package/dist/as-number.cjs +8 -0
  98. package/dist/as-number.d.cts +2 -0
  99. package/dist/as-number.d.mts +2 -0
  100. package/dist/as-number.mjs +8 -0
  101. package/dist/as-number.vue-Bk-W7Vwv.d.mts +26 -0
  102. package/dist/as-number.vue-C2Aih98s.d.cts +26 -0
  103. package/dist/as-object-CT6lNEqt.mjs +300 -0
  104. package/dist/as-object-qUL7l8V1.cjs +305 -0
  105. package/dist/as-object.cjs +11 -0
  106. package/dist/as-object.d.cts +2 -0
  107. package/dist/as-object.d.mts +2 -0
  108. package/dist/as-object.mjs +11 -0
  109. package/dist/as-object.vue-CKwMyM_F.d.cts +13 -0
  110. package/dist/as-object.vue-Cg52b61-.d.mts +13 -0
  111. package/dist/as-paragraph-BGO-j4US.cjs +203 -0
  112. package/dist/as-paragraph-jIG_dg7_.mjs +198 -0
  113. package/dist/as-paragraph.cjs +2 -0
  114. package/dist/as-paragraph.d.cts +2 -0
  115. package/dist/as-paragraph.d.mts +2 -0
  116. package/dist/as-paragraph.mjs +2 -0
  117. package/dist/as-paragraph.vue-BDt0pBG-.d.cts +9 -0
  118. package/dist/as-paragraph.vue-C3FgTEt5.d.mts +9 -0
  119. package/dist/as-radio-B1N-gmoI.mjs +242 -0
  120. package/dist/as-radio-U3OK7bTg.cjs +247 -0
  121. package/dist/as-radio.cjs +6 -0
  122. package/dist/as-radio.d.cts +2 -0
  123. package/dist/as-radio.d.mts +2 -0
  124. package/dist/as-radio.mjs +6 -0
  125. package/dist/as-radio.vue-D_fweoN1.d.mts +9 -0
  126. package/dist/as-radio.vue-ZC4kLBnT.d.cts +9 -0
  127. package/dist/as-ref-CIifSSCQ.mjs +337 -0
  128. package/dist/as-ref-SImaIrwK.cjs +342 -0
  129. package/dist/as-ref.cjs +7 -0
  130. package/dist/as-ref.d.cts +2 -0
  131. package/dist/as-ref.d.mts +2 -0
  132. package/dist/as-ref.mjs +7 -0
  133. package/dist/as-ref.vue-BNeQeQpO.d.cts +9 -0
  134. package/dist/as-ref.vue-Cr5jeNDn.d.mts +9 -0
  135. package/dist/as-select-BB3uxACS.cjs +246 -0
  136. package/dist/as-select-UBGCVhku.mjs +241 -0
  137. package/dist/as-select.cjs +6 -0
  138. package/dist/as-select.d.cts +2 -0
  139. package/dist/as-select.d.mts +2 -0
  140. package/dist/as-select.mjs +6 -0
  141. package/dist/as-select.vue-Dd7huPq2.d.cts +9 -0
  142. package/dist/as-select.vue-RYpbZbKt.d.mts +9 -0
  143. package/dist/as-time-C24rvslH.cjs +258 -0
  144. package/dist/as-time-CQsxUs8P.mjs +253 -0
  145. package/dist/as-time.cjs +8 -0
  146. package/dist/as-time.d.cts +2 -0
  147. package/dist/as-time.d.mts +2 -0
  148. package/dist/as-time.mjs +8 -0
  149. package/dist/as-time.vue-huLx2B4l.d.mts +9 -0
  150. package/dist/as-time.vue-nMEHLXke.d.cts +9 -0
  151. package/dist/as-tuple-BU--cuuI.cjs +351 -0
  152. package/dist/as-tuple-DkI9swlW.mjs +340 -0
  153. package/dist/as-tuple.cjs +11 -0
  154. package/dist/as-tuple.d.cts +2 -0
  155. package/dist/as-tuple.d.mts +2 -0
  156. package/dist/as-tuple.mjs +11 -0
  157. package/dist/as-tuple.vue-CQhzOJsn.d.mts +9 -0
  158. package/dist/as-tuple.vue-DyskCkf-.d.cts +9 -0
  159. package/dist/as-union-BGvdxr3G.mjs +351 -0
  160. package/dist/as-union-C0btoJn3.cjs +368 -0
  161. package/dist/as-union.cjs +6 -0
  162. package/dist/as-union.d.cts +2 -0
  163. package/dist/as-union.d.mts +2 -0
  164. package/dist/as-union.mjs +6 -0
  165. package/dist/as-union.vue-BjlDPZn0.d.mts +9 -0
  166. package/dist/as-union.vue-CqjU3O10.d.cts +9 -0
  167. package/dist/as-variant-picker-BVs0AvjK.mjs +96 -0
  168. package/dist/as-variant-picker-DObQZHmm.cjs +107 -0
  169. package/dist/index.cjs +173 -0
  170. package/dist/index.d.cts +966 -0
  171. package/dist/index.d.mts +966 -0
  172. package/dist/index.mjs +105 -0
  173. package/dist/types-C4HRSxgV.d.cts +233 -0
  174. package/dist/types-Czm-Gtud.d.mts +233 -0
  175. package/dist/use-as-date-B7CtcRQd.cjs +329 -0
  176. package/dist/use-as-date-C39i9mzE.mjs +318 -0
  177. package/dist/use-as-dropdown-BMnEm6jF.mjs +82 -0
  178. package/dist/use-as-dropdown-C-Qy7Vt0.cjs +105 -0
  179. package/dist/use-as-locale-BrFdAgnU.mjs +23 -0
  180. package/dist/use-as-locale-C4z5stwD.cjs +34 -0
  181. package/dist/use-as-nested-sections-store-jdMRxjBE.cjs +80 -0
  182. package/dist/use-as-nested-sections-store-lhi0z5z1.mjs +63 -0
  183. package/dist/use-as-optional-add-flow-CuXEir_i.mjs +43 -0
  184. package/dist/use-as-optional-add-flow-STOaQWo9.cjs +48 -0
  185. package/dist/use-as-value-help-CBykDEjZ.mjs +89 -0
  186. package/dist/use-as-value-help-uANI3zWa.cjs +100 -0
  187. package/dist/use-form-context-Dwr8Ai1v.cjs +207 -0
  188. package/dist/use-form-context-bAj7UoSe.mjs +106 -0
  189. package/package.json +180 -0
  190. package/styles.d.ts +2 -0
@@ -0,0 +1,694 @@
1
+ import { n as useAsLocale } from "./use-as-locale-BrFdAgnU.mjs";
2
+ import { t as as_field_shell_default } from "./as-field-shell-Pdy3sAvr.mjs";
3
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, guardReactiveProps, nextTick, normalizeClass, normalizeProps, openBlock, ref, toDisplayString, unref, watch, withCtx } from "vue";
4
+ import { enforceScale, formatDecimalForDisplay, getDecimalSeparator, getThousandsSeparator, groupInteger, joinDecimalString, parseDecimalInput, splitDecimalString } from "@atscript/ui";
5
+ //#region src/composables/_shape.ts
6
+ /**
7
+ * Match the input shape on commit: `null`/`undefined` model → write the
8
+ * canonical string (first-ever commit); pre-existing string → string;
9
+ * pre-existing number → number (caller opted into float; the precision
10
+ * loss is on them).
11
+ *
12
+ * Shared by `useAsDecimal` and `useAsNumber`. Not exported from the
13
+ * package barrel — internal helper, no public surface.
14
+ */
15
+ function preserveShape(original, normalized) {
16
+ if (original === null || original === void 0) return normalized;
17
+ if (typeof original === "string") return normalized;
18
+ return Number(normalized);
19
+ }
20
+ //#endregion
21
+ //#region src/composables/use-as-decimal.ts
22
+ /**
23
+ * Reactive composable for decimal-typed inputs (the `AsDecimal` SFC and
24
+ * customer swaps built against `TAsComponentProps`).
25
+ *
26
+ * Currency-agnostic: the SFC owns prefix/suffix render concerns and
27
+ * resolves the effective scale via the `scale` prop set by AsField. This
28
+ * composable just operates on the model with the scale given to it.
29
+ *
30
+ * Storage shape is preserved on commit — string `modelValue` commits a
31
+ * string padded to `storageScale`; number `modelValue` commits a number.
32
+ * A change to the effective `scale` getter that shrinks it below the
33
+ * model's actual precision triggers a re-round + re-commit (the same
34
+ * "currency-change" behaviour as before).
35
+ */
36
+ function useAsDecimal(opts) {
37
+ const localeCtx = useAsLocale();
38
+ const locale = computed(() => {
39
+ const explicit = opts.locale?.();
40
+ if (explicit) return explicit;
41
+ return localeCtx.locale.value;
42
+ });
43
+ const scale = computed(() => {
44
+ const s = opts.scale?.();
45
+ if (s !== void 0) return s;
46
+ const storage = opts.storageScale?.();
47
+ if (storage !== void 0) return storage;
48
+ return 2;
49
+ });
50
+ const storageScale = computed(() => {
51
+ const storage = opts.storageScale?.();
52
+ if (storage !== void 0) return storage;
53
+ const s = opts.scale?.();
54
+ if (s !== void 0) return s;
55
+ return 2;
56
+ });
57
+ const decimalSeparator = computed(() => getDecimalSeparator(locale.value));
58
+ const thousandsSeparator = computed(() => getThousandsSeparator(locale.value));
59
+ const rawValue = computed(() => {
60
+ const v = opts.modelValue();
61
+ if (v === null || v === void 0) return "";
62
+ const s = typeof v === "number" ? Number.isFinite(v) ? String(v) : "" : v;
63
+ if (s === "") return "";
64
+ return enforceScale(s, scale.value);
65
+ });
66
+ const displayValue = computed(() => {
67
+ if (rawValue.value === "") return "";
68
+ return formatDecimalForDisplay({
69
+ value: rawValue.value,
70
+ scale: scale.value,
71
+ locale: locale.value
72
+ });
73
+ });
74
+ const parts = computed(() => {
75
+ const raw = rawValue.value;
76
+ if (raw === "") return {
77
+ sign: "",
78
+ integer: "",
79
+ decimal: ""
80
+ };
81
+ const split = splitDecimalString(raw);
82
+ return {
83
+ sign: split.sign,
84
+ integer: groupInteger(split.integer, locale.value),
85
+ decimal: split.decimal
86
+ };
87
+ });
88
+ function commit(canonical) {
89
+ const padded = enforceScale(canonical, storageScale.value);
90
+ const shaped = preserveShape(opts.modelValue(), padded);
91
+ opts.onCommit(shaped);
92
+ }
93
+ function setFromInput(raw) {
94
+ if (raw.trim() === "") {
95
+ opts.onCommit(null);
96
+ return;
97
+ }
98
+ const parsed = parseDecimalInput(raw, locale.value);
99
+ if (parsed === null) return;
100
+ commit(enforceScale(parsed, scale.value));
101
+ }
102
+ function setFromParts(sign, integer, decimal) {
103
+ if (integer === "" && decimal === "") {
104
+ opts.onCommit(null);
105
+ return;
106
+ }
107
+ const intDigits = integer.replace(/\D/g, "");
108
+ const decDigits = decimal.replace(/\D/g, "");
109
+ commit(enforceScale(joinDecimalString({
110
+ sign,
111
+ integer: intDigits === "" ? "0" : intDigits,
112
+ decimal: decDigits
113
+ }), scale.value));
114
+ }
115
+ watch(scale, (newScale, oldScale) => {
116
+ if (oldScale === void 0) return;
117
+ if (newScale >= oldScale) return;
118
+ const v = opts.modelValue();
119
+ if (v === null || v === void 0) return;
120
+ const s = typeof v === "number" ? Number.isFinite(v) ? String(v) : "" : v;
121
+ if (s === "") return;
122
+ if (splitDecimalString(s).decimal.length <= newScale) return;
123
+ const shaped = preserveShape(v, enforceScale(enforceScale(s, newScale), storageScale.value));
124
+ opts.onCommit(shaped);
125
+ }, { flush: "sync" });
126
+ return {
127
+ scale,
128
+ storageScale,
129
+ decimalSeparator,
130
+ thousandsSeparator,
131
+ displayValue,
132
+ rawValue,
133
+ parts,
134
+ setFromInput,
135
+ setFromParts
136
+ };
137
+ }
138
+ //#endregion
139
+ //#region src/composables/use-as-dual-input.ts
140
+ function digitsOnly(s) {
141
+ return s.replace(/\D/g, "");
142
+ }
143
+ function useAsDualInput(opts) {
144
+ const integerInput = ref(null);
145
+ const decimalInput = ref(null);
146
+ const focusActive = ref(false);
147
+ const decimalDirty = ref(false);
148
+ const decimalEdit = ref(null);
149
+ const integerDisplay = computed(() => {
150
+ const parts = opts.parts();
151
+ if (focusActive.value) {
152
+ const raw = opts.rawValue();
153
+ if (raw === "") return "";
154
+ const p = splitDecimalString(raw);
155
+ return `${p.sign}${p.integer}`;
156
+ }
157
+ return parts.sign + parts.integer;
158
+ });
159
+ const decimalDisplay = computed(() => {
160
+ if (decimalEdit.value !== null) return decimalEdit.value;
161
+ if (opts.rawValue() === "") return "";
162
+ const parts = opts.parts();
163
+ const d = parts.decimal;
164
+ if (!/^0*$/.test(d)) return d;
165
+ const isZeroShaped = /^-?0*$/.test(parts.integer);
166
+ if (focusActive.value && !decimalDirty.value) return "";
167
+ if (isZeroShaped && !decimalDirty.value) return "";
168
+ return d;
169
+ });
170
+ function onIntegerFocus(e) {
171
+ focusActive.value = true;
172
+ decimalEdit.value = null;
173
+ if (e?.relatedTarget !== decimalInput.value) selectAllOnFocus(e?.target);
174
+ }
175
+ function onDecimalFocus(e) {
176
+ focusActive.value = true;
177
+ const parts = opts.parts();
178
+ const d = parts.decimal;
179
+ const i = parts.integer;
180
+ const isZeroShaped = i === "" || /^-?0*$/.test(i);
181
+ if (/^0*$/.test(d) && (isZeroShaped || !decimalDirty.value)) decimalEdit.value = "";
182
+ else decimalEdit.value = d;
183
+ if (e?.relatedTarget !== integerInput.value) selectAllOnFocus(e?.target);
184
+ }
185
+ /**
186
+ * UX polish: numeric inputs always select-all on focus so the next
187
+ * keystroke replaces the existing value. Without this, typing `5` into
188
+ * "1" produces "15" / "51" depending on where the caret lands —
189
+ * confusing for a numeric field where most edits replace rather than
190
+ * append. Synchronous: selecting the pre-render value is fine because
191
+ * (a) Vue's :value re-binding preserves the selection range, and
192
+ * (b) the user only sees one frame either way.
193
+ */
194
+ function selectAllOnFocus(target) {
195
+ const el = target;
196
+ if (!el || typeof el.select !== "function") return;
197
+ el.select();
198
+ }
199
+ function onBlurAll(e) {
200
+ const next = e.relatedTarget;
201
+ if (next === integerInput.value || next === decimalInput.value) return;
202
+ focusActive.value = false;
203
+ decimalDirty.value = false;
204
+ decimalEdit.value = null;
205
+ opts.onBlur?.();
206
+ }
207
+ function commitIntegerHalf(rawInteger) {
208
+ let sign = "";
209
+ let body = rawInteger;
210
+ if (body.startsWith("-")) {
211
+ sign = "-";
212
+ body = body.slice(1);
213
+ }
214
+ const intDigits = digitsOnly(body);
215
+ const curDec = opts.parts().decimal;
216
+ opts.setFromParts(sign, intDigits, curDec);
217
+ }
218
+ function commitDecimalHalf(rawDecimal) {
219
+ const decDigits = digitsOnly(rawDecimal).slice(0, opts.scale());
220
+ const p = splitDecimalString(opts.rawValue());
221
+ opts.setFromParts(p.sign, p.integer, decDigits);
222
+ }
223
+ async function focusDecimal(at) {
224
+ await nextTick();
225
+ const el = decimalInput.value;
226
+ if (!el) return;
227
+ el.focus();
228
+ if (typeof at === "number") {
229
+ const pos = Math.max(0, Math.min(at, el.value.length));
230
+ try {
231
+ el.setSelectionRange(pos, pos);
232
+ } catch {}
233
+ } else try {
234
+ el.select();
235
+ } catch {}
236
+ }
237
+ async function focusInteger(atEnd) {
238
+ await nextTick();
239
+ const el = integerInput.value;
240
+ if (!el) return;
241
+ el.focus();
242
+ if (atEnd) {
243
+ const pos = el.value.length;
244
+ try {
245
+ el.setSelectionRange(pos, pos);
246
+ } catch {}
247
+ }
248
+ }
249
+ function onIntegerKeydown(e) {
250
+ const el = e.target;
251
+ const sc = opts.scale();
252
+ if (e.key === "ArrowRight" && el.selectionStart === el.value.length && sc > 0) {
253
+ e.preventDefault();
254
+ focusDecimal(0);
255
+ return;
256
+ }
257
+ if ((e.key === "." || e.key === ",") && sc > 0) {
258
+ e.preventDefault();
259
+ focusDecimal();
260
+ return;
261
+ }
262
+ if (e.key === "-") {
263
+ e.preventDefault();
264
+ const p = splitDecimalString(opts.rawValue());
265
+ const newSign = p.sign === "-" ? "" : "-";
266
+ opts.setFromParts(newSign, p.integer, p.decimal);
267
+ return;
268
+ }
269
+ }
270
+ function onDecimalKeydown(e) {
271
+ const el = e.target;
272
+ if (e.key === "ArrowLeft" && el.selectionStart === 0) {
273
+ e.preventDefault();
274
+ focusInteger(true);
275
+ return;
276
+ }
277
+ if (e.key === "Backspace" && el.selectionStart === 0 && el.selectionEnd === 0) {
278
+ e.preventDefault();
279
+ focusInteger(true);
280
+ return;
281
+ }
282
+ if (/^[0-9]$/.test(e.key) && !e.ctrlKey && !e.metaKey && !e.altKey) {
283
+ e.preventDefault();
284
+ const start = el.selectionStart ?? 0;
285
+ const end = el.selectionEnd ?? 0;
286
+ const current = el.value;
287
+ const cap = opts.scale();
288
+ if (start === end && start >= cap) return;
289
+ let next;
290
+ let newCursor;
291
+ if (start !== end) {
292
+ next = current.slice(0, start) + e.key + current.slice(end);
293
+ newCursor = start + 1;
294
+ } else if (start < current.length) {
295
+ next = current.slice(0, start) + e.key + current.slice(start + 1);
296
+ newCursor = start + 1;
297
+ } else {
298
+ next = current + e.key;
299
+ newCursor = next.length;
300
+ }
301
+ if (next.length > cap) next = next.slice(0, cap);
302
+ decimalDirty.value = true;
303
+ decimalEdit.value = next;
304
+ commitDecimalHalf(next);
305
+ nextTick().then(() => {
306
+ try {
307
+ el.setSelectionRange(newCursor, newCursor);
308
+ } catch {}
309
+ });
310
+ return;
311
+ }
312
+ if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
313
+ e.preventDefault();
314
+ return;
315
+ }
316
+ }
317
+ function onIntegerInput(e) {
318
+ const el = e.target;
319
+ let raw = el.value;
320
+ let sign = "";
321
+ if (raw.startsWith("-")) {
322
+ sign = "-";
323
+ raw = raw.slice(1);
324
+ }
325
+ const cleaned = `${sign}${digitsOnly(raw)}`;
326
+ if (cleaned !== el.value) el.value = cleaned;
327
+ commitIntegerHalf(cleaned);
328
+ }
329
+ function onDecimalInput(e) {
330
+ const el = e.target;
331
+ decimalDirty.value = true;
332
+ const cleaned = digitsOnly(el.value).slice(0, opts.scale());
333
+ if (cleaned !== el.value) el.value = cleaned;
334
+ decimalEdit.value = cleaned;
335
+ commitDecimalHalf(cleaned);
336
+ }
337
+ function onIntegerPaste(e) {
338
+ const text = e.clipboardData?.getData("text") ?? "";
339
+ if (!text) return;
340
+ const sep = opts.decimalSeparator();
341
+ if (text.includes(sep) || sep !== "." && text.includes(".") || sep !== "," && text.includes(",")) {
342
+ e.preventDefault();
343
+ opts.setFromInput(text);
344
+ focusDecimal(opts.scale());
345
+ return;
346
+ }
347
+ }
348
+ function onDecimalPaste(e) {
349
+ const text = e.clipboardData?.getData("text") ?? "";
350
+ if (!text) return;
351
+ e.preventDefault();
352
+ decimalDirty.value = true;
353
+ const cleaned = digitsOnly(text).slice(0, opts.scale());
354
+ const el = e.target;
355
+ el.value = cleaned;
356
+ decimalEdit.value = cleaned;
357
+ commitDecimalHalf(cleaned);
358
+ }
359
+ return {
360
+ integerInput,
361
+ decimalInput,
362
+ integerDisplay,
363
+ decimalDisplay,
364
+ focusActive,
365
+ onIntegerFocus,
366
+ onDecimalFocus,
367
+ onBlurAll,
368
+ onIntegerInput,
369
+ onIntegerKeydown,
370
+ onIntegerPaste,
371
+ onDecimalInput,
372
+ onDecimalKeydown,
373
+ onDecimalPaste
374
+ };
375
+ }
376
+ //#endregion
377
+ //#region src/components/defaults/as-decimal.vue?vue&type=script&setup=true&lang.ts
378
+ const _hoisted_1 = ["title"];
379
+ const _hoisted_2 = {
380
+ key: 1,
381
+ class: "as-prefix",
382
+ "aria-hidden": "true"
383
+ };
384
+ const _hoisted_3 = [
385
+ "id",
386
+ "value",
387
+ "placeholder",
388
+ "name",
389
+ "disabled",
390
+ "readonly",
391
+ "aria-required",
392
+ "aria-invalid",
393
+ "aria-describedby",
394
+ "aria-label"
395
+ ];
396
+ const _hoisted_4 = {
397
+ class: "as-decimal-sep",
398
+ "aria-hidden": "true"
399
+ };
400
+ const _hoisted_5 = [
401
+ "value",
402
+ "maxlength",
403
+ "size",
404
+ "disabled",
405
+ "readonly",
406
+ "aria-label"
407
+ ];
408
+ const _hoisted_6 = {
409
+ key: 3,
410
+ class: "as-suffix",
411
+ "aria-hidden": "true"
412
+ };
413
+ //#endregion
414
+ //#region src/components/defaults/as-decimal.vue
415
+ var as_decimal_default = /* @__PURE__ */ defineComponent({
416
+ __name: "as-decimal",
417
+ props: {
418
+ onBlur: {
419
+ type: Function,
420
+ required: true
421
+ },
422
+ error: {
423
+ type: String,
424
+ required: false
425
+ },
426
+ model: {
427
+ type: Object,
428
+ required: true
429
+ },
430
+ value: {
431
+ type: null,
432
+ required: false
433
+ },
434
+ label: {
435
+ type: String,
436
+ required: false
437
+ },
438
+ description: {
439
+ type: String,
440
+ required: false
441
+ },
442
+ hint: {
443
+ type: String,
444
+ required: false
445
+ },
446
+ placeholder: {
447
+ type: String,
448
+ required: false
449
+ },
450
+ prefixIcon: {
451
+ type: String,
452
+ required: false
453
+ },
454
+ suffixIcon: {
455
+ type: String,
456
+ required: false
457
+ },
458
+ class: {
459
+ type: [Object, String],
460
+ required: false
461
+ },
462
+ style: {
463
+ type: [Object, String],
464
+ required: false
465
+ },
466
+ optional: {
467
+ type: Boolean,
468
+ required: false,
469
+ skipCheck: true
470
+ },
471
+ onToggleOptional: {
472
+ type: Function,
473
+ required: false
474
+ },
475
+ required: {
476
+ type: Boolean,
477
+ required: false,
478
+ skipCheck: true
479
+ },
480
+ readonly: {
481
+ type: Boolean,
482
+ required: false,
483
+ skipCheck: true
484
+ },
485
+ type: {
486
+ type: String,
487
+ required: true
488
+ },
489
+ formAction: {
490
+ type: Object,
491
+ required: false
492
+ },
493
+ name: {
494
+ type: String,
495
+ required: false
496
+ },
497
+ field: {
498
+ type: Object,
499
+ required: false
500
+ },
501
+ options: {
502
+ type: Array,
503
+ required: false
504
+ },
505
+ maxLength: {
506
+ type: Number,
507
+ required: false
508
+ },
509
+ autocomplete: {
510
+ type: String,
511
+ required: false
512
+ },
513
+ title: {
514
+ type: String,
515
+ required: false
516
+ },
517
+ level: {
518
+ type: Number,
519
+ required: false
520
+ },
521
+ onRemove: {
522
+ type: Function,
523
+ required: false
524
+ },
525
+ canRemove: {
526
+ type: Boolean,
527
+ required: false
528
+ },
529
+ removeLabel: {
530
+ type: String,
531
+ required: false
532
+ },
533
+ arrayIndex: {
534
+ type: Number,
535
+ required: false
536
+ },
537
+ path: {
538
+ type: String,
539
+ required: true
540
+ },
541
+ valueHelp: {
542
+ type: Object,
543
+ required: false
544
+ },
545
+ singularLabel: {
546
+ type: String,
547
+ required: false
548
+ },
549
+ inputId: {
550
+ type: String,
551
+ required: true
552
+ },
553
+ errorId: {
554
+ type: String,
555
+ required: true
556
+ },
557
+ descId: {
558
+ type: String,
559
+ required: true
560
+ },
561
+ ariaDescribedBy: {
562
+ type: String,
563
+ required: false
564
+ },
565
+ currencyCode: {
566
+ type: String,
567
+ required: false
568
+ },
569
+ unitCode: {
570
+ type: String,
571
+ required: false
572
+ },
573
+ precisionScale: {
574
+ type: Number,
575
+ required: false
576
+ },
577
+ prefix: {
578
+ type: String,
579
+ required: false
580
+ },
581
+ suffix: {
582
+ type: String,
583
+ required: false
584
+ },
585
+ scale: {
586
+ type: Number,
587
+ required: false
588
+ },
589
+ hasAdornment: {
590
+ type: Boolean,
591
+ required: false
592
+ },
593
+ disabled: {
594
+ type: Boolean,
595
+ required: false
596
+ },
597
+ hidden: {
598
+ type: Boolean,
599
+ required: false
600
+ }
601
+ },
602
+ setup(__props) {
603
+ const props = __props;
604
+ const { scale, decimalSeparator, rawValue, parts, setFromInput, setFromParts } = useAsDecimal({
605
+ modelValue: () => props.model.value,
606
+ scale: () => props.scale,
607
+ storageScale: () => props.precisionScale,
608
+ onCommit: (v) => {
609
+ props.model.value = v;
610
+ }
611
+ });
612
+ const { integerInput, decimalInput, integerDisplay, decimalDisplay, onIntegerFocus, onDecimalFocus, onBlurAll, onIntegerInput, onIntegerKeydown, onIntegerPaste, onDecimalInput, onDecimalKeydown, onDecimalPaste } = useAsDualInput({
613
+ scale: () => scale.value,
614
+ decimalSeparator: () => decimalSeparator.value,
615
+ parts: () => parts.value,
616
+ rawValue: () => rawValue.value,
617
+ setFromParts,
618
+ setFromInput,
619
+ onBlur: () => props.onBlur()
620
+ });
621
+ const isNegative = computed(() => parts.value.sign === "-");
622
+ const shellTitle = computed(() => props.currencyCode ?? props.unitCode ?? void 0);
623
+ return (_ctx, _cache) => {
624
+ return openBlock(), createBlock(as_field_shell_default, normalizeProps(guardReactiveProps(_ctx.$props)), {
625
+ default: withCtx(({ inputId }) => [createElementVNode("div", {
626
+ class: normalizeClass(["as-decimal", {
627
+ "as-decimal-negative": isNegative.value,
628
+ error: !!__props.error,
629
+ required: __props.required
630
+ }]),
631
+ title: shellTitle.value
632
+ }, [
633
+ __props.prefixIcon ? (openBlock(), createElementBlock("span", {
634
+ key: 0,
635
+ class: normalizeClass(["as-prefix-icon", __props.prefixIcon]),
636
+ "aria-hidden": "true"
637
+ }, null, 2)) : createCommentVNode("v-if", true),
638
+ __props.prefix ? (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString(__props.prefix), 1)) : createCommentVNode("v-if", true),
639
+ createElementVNode("input", {
640
+ id: inputId,
641
+ ref_key: "integerInput",
642
+ ref: integerInput,
643
+ class: "as-decimal-integer",
644
+ type: "text",
645
+ inputmode: "decimal",
646
+ autocomplete: "off",
647
+ value: unref(integerDisplay),
648
+ onInput: _cache[0] || (_cache[0] = (...args) => unref(onIntegerInput) && unref(onIntegerInput)(...args)),
649
+ onKeydown: _cache[1] || (_cache[1] = (...args) => unref(onIntegerKeydown) && unref(onIntegerKeydown)(...args)),
650
+ onPaste: _cache[2] || (_cache[2] = (...args) => unref(onIntegerPaste) && unref(onIntegerPaste)(...args)),
651
+ onFocus: _cache[3] || (_cache[3] = (...args) => unref(onIntegerFocus) && unref(onIntegerFocus)(...args)),
652
+ onBlur: _cache[4] || (_cache[4] = (...args) => unref(onBlurAll) && unref(onBlurAll)(...args)),
653
+ placeholder: __props.placeholder,
654
+ name: __props.name,
655
+ disabled: __props.disabled,
656
+ readonly: __props.readonly,
657
+ "aria-required": __props.required || void 0,
658
+ "aria-invalid": !!__props.error || void 0,
659
+ "aria-describedby": __props.ariaDescribedBy,
660
+ "aria-label": !__props.label ? __props.name : void 0
661
+ }, null, 40, _hoisted_3),
662
+ unref(scale) > 0 ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [createElementVNode("span", _hoisted_4, toDisplayString(unref(decimalSeparator)), 1), createElementVNode("input", {
663
+ ref_key: "decimalInput",
664
+ ref: decimalInput,
665
+ class: "as-decimal-decimal",
666
+ type: "text",
667
+ inputmode: "numeric",
668
+ autocomplete: "off",
669
+ value: unref(decimalDisplay),
670
+ maxlength: unref(scale),
671
+ size: unref(scale),
672
+ onInput: _cache[5] || (_cache[5] = (...args) => unref(onDecimalInput) && unref(onDecimalInput)(...args)),
673
+ onKeydown: _cache[6] || (_cache[6] = (...args) => unref(onDecimalKeydown) && unref(onDecimalKeydown)(...args)),
674
+ onPaste: _cache[7] || (_cache[7] = (...args) => unref(onDecimalPaste) && unref(onDecimalPaste)(...args)),
675
+ onFocus: _cache[8] || (_cache[8] = (...args) => unref(onDecimalFocus) && unref(onDecimalFocus)(...args)),
676
+ onBlur: _cache[9] || (_cache[9] = (...args) => unref(onBlurAll) && unref(onBlurAll)(...args)),
677
+ disabled: __props.disabled,
678
+ readonly: __props.readonly,
679
+ "aria-label": `decimals of ${__props.label ?? __props.name ?? ""}`
680
+ }, null, 40, _hoisted_5)], 64)) : createCommentVNode("v-if", true),
681
+ __props.suffix ? (openBlock(), createElementBlock("span", _hoisted_6, toDisplayString(__props.suffix), 1)) : createCommentVNode("v-if", true),
682
+ __props.suffixIcon ? (openBlock(), createElementBlock("span", {
683
+ key: 4,
684
+ class: normalizeClass(["as-suffix-icon", __props.suffixIcon]),
685
+ "aria-hidden": "true"
686
+ }, null, 2)) : createCommentVNode("v-if", true)
687
+ ], 10, _hoisted_1)]),
688
+ _: 1
689
+ }, 16);
690
+ };
691
+ }
692
+ });
693
+ //#endregion
694
+ export { useAsDualInput as n, useAsDecimal as r, as_decimal_default as t };
@@ -0,0 +1,7 @@
1
+ require("./use-form-context-Dwr8Ai1v.cjs");
2
+ require("./use-as-locale-C4z5stwD.cjs");
3
+ require("./use-as-dropdown-C-Qy7Vt0.cjs");
4
+ require("./as-field-shell-B2iTn-iM.cjs");
5
+ require("./as-variant-picker-DObQZHmm.cjs");
6
+ const require_as_decimal = require("./as-decimal-BJIGgPXU.cjs");
7
+ module.exports = require_as_decimal.as_decimal_default;
@@ -0,0 +1,2 @@
1
+ import { t as _default } from "./as-decimal.vue-B1pEKdjM.cjs";
2
+ export = _default;
@@ -0,0 +1,2 @@
1
+ import { t as _default } from "./as-decimal.vue-CSCtYRRa.mjs";
2
+ export { _default as default };
@@ -0,0 +1,7 @@
1
+ import "./use-form-context-bAj7UoSe.mjs";
2
+ import "./use-as-locale-BrFdAgnU.mjs";
3
+ import "./use-as-dropdown-BMnEm6jF.mjs";
4
+ import "./as-field-shell-Pdy3sAvr.mjs";
5
+ import "./as-variant-picker-BVs0AvjK.mjs";
6
+ import { t as as_decimal_default } from "./as-decimal-DtXjFPhe.mjs";
7
+ export { as_decimal_default as default };