@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,351 @@
1
+ import { _ as UNION_CONTEXT_KEY, a as CHANGE_HANDLER_KEY, g as TYPES_KEY, m as PATH_PREFIX_KEY, r as useFormContext } from "./use-form-context-bAj7UoSe.mjs";
2
+ import { t as useAsDropdown } from "./use-as-dropdown-BMnEm6jF.mjs";
3
+ import { t as useAsOptionalAddFlow } from "./use-as-optional-add-flow-CuXEir_i.mjs";
4
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, defineComponent, inject, mergeProps, normalizeClass, openBlock, provide, ref, renderList, resolveDynamicComponent, toDisplayString, unref, vShow, withDirectives } from "vue";
5
+ import { createFormData, createFormValueResolver, detectUnionVariant, isUnionField } from "@atscript/ui";
6
+ //#region src/composables/use-as-union.ts
7
+ /** Composable for union field state. Switching variants stashes per-index data so toggling back restores user's work instead of fresh defaults. */
8
+ function useAsUnion(props) {
9
+ const unionPath = inject(PATH_PREFIX_KEY, computed(() => ""));
10
+ const { rootFormData, formContext } = useFormContext("useAsUnion");
11
+ const handleChange = inject(CHANGE_HANDLER_KEY, () => {});
12
+ const unionField = computed(() => props.field && isUnionField(props.field) ? props.field : void 0);
13
+ const hasMultipleVariants = computed(() => unionField.value !== void 0 && unionField.value.unionVariants.length > 1);
14
+ const localUnionIndex = ref(unionField.value ? detectUnionVariant(props.model?.value, unionField.value.unionVariants) : 0);
15
+ const currentVariant = computed(() => {
16
+ const variants = unionField.value?.unionVariants;
17
+ if (!variants) return void 0;
18
+ return variants[localUnionIndex.value] ?? variants[0];
19
+ });
20
+ const innerField = computed(() => {
21
+ const variant = currentVariant.value;
22
+ if (!variant) return void 0;
23
+ const fieldName = unionField.value?.name ?? "";
24
+ if (variant.def) return {
25
+ ...variant.def.rootField,
26
+ path: "",
27
+ name: fieldName
28
+ };
29
+ if (variant.itemField) return {
30
+ ...variant.itemField,
31
+ path: "",
32
+ name: ""
33
+ };
34
+ });
35
+ const variantDataStash = /* @__PURE__ */ new Map();
36
+ function changeVariant(newIndex) {
37
+ if (props.model?.value != null) variantDataStash.set(localUnionIndex.value, props.model.value);
38
+ localUnionIndex.value = newIndex;
39
+ const variant = unionField.value?.unionVariants[newIndex];
40
+ if (variant && props.model) {
41
+ const stashed = variantDataStash.get(newIndex);
42
+ props.model.value = stashed !== void 0 ? stashed : createFormData(variant.type, createFormValueResolver(rootFormData().value, formContext.value)).value;
43
+ }
44
+ handleChange("union-switch", unionPath.value, props.model?.value);
45
+ }
46
+ return {
47
+ unionField,
48
+ hasMultipleVariants,
49
+ localUnionIndex,
50
+ innerField,
51
+ changeVariant,
52
+ optionalEnabled: computed(() => props.model?.value != null)
53
+ };
54
+ }
55
+ //#endregion
56
+ //#region src/composables/use-as-type-map.ts
57
+ const EMPTY_TYPES = computed(() => ({}));
58
+ /**
59
+ * Reactive read-only access to the type-to-component map provided by the
60
+ * nearest `<AsForm>`. Returns an empty map when called outside a form so
61
+ * call sites do not need a null-check.
62
+ */
63
+ function useAsTypeMap() {
64
+ return { types: inject(TYPES_KEY, EMPTY_TYPES) };
65
+ }
66
+ //#endregion
67
+ //#region src/components/defaults/as-union.vue?vue&type=script&setup=true&lang.ts
68
+ const _hoisted_1 = {
69
+ key: 0,
70
+ class: "as-dropdown-menu"
71
+ };
72
+ const _hoisted_2 = ["onClick"];
73
+ const _hoisted_3 = {
74
+ key: 2,
75
+ class: "as-collapsible-description"
76
+ };
77
+ //#endregion
78
+ //#region src/components/defaults/as-union.vue
79
+ var as_union_default = /* @__PURE__ */ defineComponent({
80
+ __name: "as-union",
81
+ props: {
82
+ onBlur: {
83
+ type: Function,
84
+ required: true
85
+ },
86
+ error: {
87
+ type: String,
88
+ required: false
89
+ },
90
+ model: {
91
+ type: Object,
92
+ required: true
93
+ },
94
+ value: {
95
+ type: null,
96
+ required: false
97
+ },
98
+ label: {
99
+ type: String,
100
+ required: false
101
+ },
102
+ description: {
103
+ type: String,
104
+ required: false
105
+ },
106
+ hint: {
107
+ type: String,
108
+ required: false
109
+ },
110
+ placeholder: {
111
+ type: String,
112
+ required: false
113
+ },
114
+ prefixIcon: {
115
+ type: String,
116
+ required: false
117
+ },
118
+ suffixIcon: {
119
+ type: String,
120
+ required: false
121
+ },
122
+ class: {
123
+ type: [Object, String],
124
+ required: false
125
+ },
126
+ style: {
127
+ type: [Object, String],
128
+ required: false
129
+ },
130
+ optional: {
131
+ type: Boolean,
132
+ required: false,
133
+ skipCheck: true
134
+ },
135
+ onToggleOptional: {
136
+ type: Function,
137
+ required: false
138
+ },
139
+ required: {
140
+ type: Boolean,
141
+ required: false,
142
+ skipCheck: true
143
+ },
144
+ readonly: {
145
+ type: Boolean,
146
+ required: false,
147
+ skipCheck: true
148
+ },
149
+ type: {
150
+ type: String,
151
+ required: true
152
+ },
153
+ formAction: {
154
+ type: Object,
155
+ required: false
156
+ },
157
+ name: {
158
+ type: String,
159
+ required: false
160
+ },
161
+ field: {
162
+ type: Object,
163
+ required: false
164
+ },
165
+ options: {
166
+ type: Array,
167
+ required: false
168
+ },
169
+ maxLength: {
170
+ type: Number,
171
+ required: false
172
+ },
173
+ autocomplete: {
174
+ type: String,
175
+ required: false
176
+ },
177
+ title: {
178
+ type: String,
179
+ required: false
180
+ },
181
+ level: {
182
+ type: Number,
183
+ required: false
184
+ },
185
+ onRemove: {
186
+ type: Function,
187
+ required: false
188
+ },
189
+ canRemove: {
190
+ type: Boolean,
191
+ required: false
192
+ },
193
+ removeLabel: {
194
+ type: String,
195
+ required: false
196
+ },
197
+ arrayIndex: {
198
+ type: Number,
199
+ required: false
200
+ },
201
+ path: {
202
+ type: String,
203
+ required: true
204
+ },
205
+ valueHelp: {
206
+ type: Object,
207
+ required: false
208
+ },
209
+ singularLabel: {
210
+ type: String,
211
+ required: false
212
+ },
213
+ inputId: {
214
+ type: String,
215
+ required: true
216
+ },
217
+ errorId: {
218
+ type: String,
219
+ required: true
220
+ },
221
+ descId: {
222
+ type: String,
223
+ required: true
224
+ },
225
+ ariaDescribedBy: {
226
+ type: String,
227
+ required: false
228
+ },
229
+ currencyCode: {
230
+ type: String,
231
+ required: false
232
+ },
233
+ unitCode: {
234
+ type: String,
235
+ required: false
236
+ },
237
+ precisionScale: {
238
+ type: Number,
239
+ required: false
240
+ },
241
+ prefix: {
242
+ type: String,
243
+ required: false
244
+ },
245
+ suffix: {
246
+ type: String,
247
+ required: false
248
+ },
249
+ scale: {
250
+ type: Number,
251
+ required: false
252
+ },
253
+ hasAdornment: {
254
+ type: Boolean,
255
+ required: false
256
+ },
257
+ disabled: {
258
+ type: Boolean,
259
+ required: false
260
+ },
261
+ hidden: {
262
+ type: Boolean,
263
+ required: false
264
+ }
265
+ },
266
+ setup(__props) {
267
+ const props = __props;
268
+ const { unionField, hasMultipleVariants, localUnionIndex, innerField, changeVariant, optionalEnabled } = useAsUnion(props);
269
+ const { types } = useAsTypeMap();
270
+ const unionCtx = unionField.value ? {
271
+ variants: unionField.value.unionVariants,
272
+ currentIndex: localUnionIndex,
273
+ changeVariant
274
+ } : void 0;
275
+ if (unionCtx) provide(UNION_CONTEXT_KEY, unionCtx);
276
+ const variantComponent = computed(() => innerField.value ? types.value?.[innerField.value.type] : void 0);
277
+ const fieldLabel = computed(() => props.title ?? props.label ?? props.name ?? "");
278
+ const rootRef = ref(null);
279
+ const rootEl = () => {
280
+ const r = rootRef.value;
281
+ if (!r) return null;
282
+ if (typeof r.querySelectorAll === "function") return r;
283
+ return r.$el ?? null;
284
+ };
285
+ const pickerDropdownRef = ref(null);
286
+ const { isOpen: pickerOpen, toggle: togglePicker, select: selectPicker } = useAsDropdown(pickerDropdownRef);
287
+ const { runAndFocusNew } = useAsOptionalAddFlow({ path: () => props.path });
288
+ function pickAndFocus(vi) {
289
+ runAndFocusNew(rootEl, () => changeVariant(vi), 2);
290
+ }
291
+ function handleEmptyClick() {
292
+ if (hasMultipleVariants.value) {
293
+ togglePicker();
294
+ return;
295
+ }
296
+ pickAndFocus(0);
297
+ }
298
+ function handleVariantPick(vi) {
299
+ selectPicker(() => pickAndFocus(vi));
300
+ }
301
+ return (_ctx, _cache) => {
302
+ return __props.optional && !unref(optionalEnabled) ? withDirectives((openBlock(), createElementBlock("div", {
303
+ key: 0,
304
+ ref_key: "rootRef",
305
+ ref: rootRef,
306
+ class: normalizeClass(["as-object-empty as-grid-item", _ctx.$props.class])
307
+ }, [unref(hasMultipleVariants) ? (openBlock(), createElementBlock("div", {
308
+ key: 0,
309
+ ref_key: "pickerDropdownRef",
310
+ ref: pickerDropdownRef,
311
+ class: "as-dropdown"
312
+ }, [createElementVNode("button", {
313
+ type: "button",
314
+ class: "as-object-empty-add",
315
+ onClick: handleEmptyClick
316
+ }, [_cache[0] || (_cache[0] = createElementVNode("span", {
317
+ class: "i-as-field-fill as-object-empty-add-icon",
318
+ "aria-hidden": "true"
319
+ }, null, -1)), createTextVNode(" Add " + toDisplayString(fieldLabel.value), 1)]), unref(pickerOpen) ? (openBlock(), createElementBlock("div", _hoisted_1, [(openBlock(true), createElementBlock(Fragment, null, renderList(unref(unionField).unionVariants, (v, vi) => {
320
+ return openBlock(), createElementBlock("button", {
321
+ key: vi,
322
+ type: "button",
323
+ class: "as-dropdown-item",
324
+ onClick: ($event) => handleVariantPick(vi)
325
+ }, toDisplayString(v.label), 9, _hoisted_2);
326
+ }), 128))])) : createCommentVNode("v-if", true)], 512)) : (openBlock(), createElementBlock("button", {
327
+ key: 1,
328
+ type: "button",
329
+ class: "as-object-empty-add",
330
+ onClick: handleEmptyClick
331
+ }, [_cache[1] || (_cache[1] = createElementVNode("span", {
332
+ class: "i-as-field-fill as-object-empty-add-icon",
333
+ "aria-hidden": "true"
334
+ }, null, -1)), createTextVNode(" Add " + toDisplayString(fieldLabel.value), 1)])), __props.description ? (openBlock(), createElementBlock("p", _hoisted_3, toDisplayString(__props.description), 1)) : createCommentVNode("v-if", true)], 2)), [[vShow, !__props.hidden]]) : variantComponent.value && unref(innerField) ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [createCommentVNode(" Active: dispatch to variant's component, forwarding the field's @meta.label\n as title so the variant's chrome shows it (innerField.type overrides \"union\"). "), (openBlock(), createBlock(resolveDynamicComponent(variantComponent.value), mergeProps({
335
+ ref_key: "rootRef",
336
+ ref: rootRef
337
+ }, _ctx.$props, {
338
+ field: unref(innerField),
339
+ type: unref(innerField).type,
340
+ title: fieldLabel.value,
341
+ key: unref(localUnionIndex)
342
+ }), null, 16, [
343
+ "field",
344
+ "type",
345
+ "title"
346
+ ]))], 2112)) : createCommentVNode("v-if", true);
347
+ };
348
+ }
349
+ });
350
+ //#endregion
351
+ export { useAsTypeMap as n, useAsUnion as r, as_union_default as t };
@@ -0,0 +1,368 @@
1
+ const require_use_form_context = require("./use-form-context-Dwr8Ai1v.cjs");
2
+ const require_use_as_dropdown = require("./use-as-dropdown-C-Qy7Vt0.cjs");
3
+ const require_use_as_optional_add_flow = require("./use-as-optional-add-flow-STOaQWo9.cjs");
4
+ let vue = require("vue");
5
+ let _atscript_ui = require("@atscript/ui");
6
+ //#region src/composables/use-as-union.ts
7
+ /** Composable for union field state. Switching variants stashes per-index data so toggling back restores user's work instead of fresh defaults. */
8
+ function useAsUnion(props) {
9
+ const unionPath = (0, vue.inject)(require_use_form_context.PATH_PREFIX_KEY, (0, vue.computed)(() => ""));
10
+ const { rootFormData, formContext } = require_use_form_context.useFormContext("useAsUnion");
11
+ const handleChange = (0, vue.inject)(require_use_form_context.CHANGE_HANDLER_KEY, () => {});
12
+ const unionField = (0, vue.computed)(() => props.field && (0, _atscript_ui.isUnionField)(props.field) ? props.field : void 0);
13
+ const hasMultipleVariants = (0, vue.computed)(() => unionField.value !== void 0 && unionField.value.unionVariants.length > 1);
14
+ const localUnionIndex = (0, vue.ref)(unionField.value ? (0, _atscript_ui.detectUnionVariant)(props.model?.value, unionField.value.unionVariants) : 0);
15
+ const currentVariant = (0, vue.computed)(() => {
16
+ const variants = unionField.value?.unionVariants;
17
+ if (!variants) return void 0;
18
+ return variants[localUnionIndex.value] ?? variants[0];
19
+ });
20
+ const innerField = (0, vue.computed)(() => {
21
+ const variant = currentVariant.value;
22
+ if (!variant) return void 0;
23
+ const fieldName = unionField.value?.name ?? "";
24
+ if (variant.def) return {
25
+ ...variant.def.rootField,
26
+ path: "",
27
+ name: fieldName
28
+ };
29
+ if (variant.itemField) return {
30
+ ...variant.itemField,
31
+ path: "",
32
+ name: ""
33
+ };
34
+ });
35
+ const variantDataStash = /* @__PURE__ */ new Map();
36
+ function changeVariant(newIndex) {
37
+ if (props.model?.value != null) variantDataStash.set(localUnionIndex.value, props.model.value);
38
+ localUnionIndex.value = newIndex;
39
+ const variant = unionField.value?.unionVariants[newIndex];
40
+ if (variant && props.model) {
41
+ const stashed = variantDataStash.get(newIndex);
42
+ props.model.value = stashed !== void 0 ? stashed : (0, _atscript_ui.createFormData)(variant.type, (0, _atscript_ui.createFormValueResolver)(rootFormData().value, formContext.value)).value;
43
+ }
44
+ handleChange("union-switch", unionPath.value, props.model?.value);
45
+ }
46
+ return {
47
+ unionField,
48
+ hasMultipleVariants,
49
+ localUnionIndex,
50
+ innerField,
51
+ changeVariant,
52
+ optionalEnabled: (0, vue.computed)(() => props.model?.value != null)
53
+ };
54
+ }
55
+ //#endregion
56
+ //#region src/composables/use-as-type-map.ts
57
+ const EMPTY_TYPES = (0, vue.computed)(() => ({}));
58
+ /**
59
+ * Reactive read-only access to the type-to-component map provided by the
60
+ * nearest `<AsForm>`. Returns an empty map when called outside a form so
61
+ * call sites do not need a null-check.
62
+ */
63
+ function useAsTypeMap() {
64
+ return { types: (0, vue.inject)(require_use_form_context.TYPES_KEY, EMPTY_TYPES) };
65
+ }
66
+ //#endregion
67
+ //#region src/components/defaults/as-union.vue?vue&type=script&setup=true&lang.ts
68
+ const _hoisted_1 = {
69
+ key: 0,
70
+ class: "as-dropdown-menu"
71
+ };
72
+ const _hoisted_2 = ["onClick"];
73
+ const _hoisted_3 = {
74
+ key: 2,
75
+ class: "as-collapsible-description"
76
+ };
77
+ //#endregion
78
+ //#region src/components/defaults/as-union.vue
79
+ var as_union_default = /* @__PURE__ */ (0, vue.defineComponent)({
80
+ __name: "as-union",
81
+ props: {
82
+ onBlur: {
83
+ type: Function,
84
+ required: true
85
+ },
86
+ error: {
87
+ type: String,
88
+ required: false
89
+ },
90
+ model: {
91
+ type: Object,
92
+ required: true
93
+ },
94
+ value: {
95
+ type: null,
96
+ required: false
97
+ },
98
+ label: {
99
+ type: String,
100
+ required: false
101
+ },
102
+ description: {
103
+ type: String,
104
+ required: false
105
+ },
106
+ hint: {
107
+ type: String,
108
+ required: false
109
+ },
110
+ placeholder: {
111
+ type: String,
112
+ required: false
113
+ },
114
+ prefixIcon: {
115
+ type: String,
116
+ required: false
117
+ },
118
+ suffixIcon: {
119
+ type: String,
120
+ required: false
121
+ },
122
+ class: {
123
+ type: [Object, String],
124
+ required: false
125
+ },
126
+ style: {
127
+ type: [Object, String],
128
+ required: false
129
+ },
130
+ optional: {
131
+ type: Boolean,
132
+ required: false,
133
+ skipCheck: true
134
+ },
135
+ onToggleOptional: {
136
+ type: Function,
137
+ required: false
138
+ },
139
+ required: {
140
+ type: Boolean,
141
+ required: false,
142
+ skipCheck: true
143
+ },
144
+ readonly: {
145
+ type: Boolean,
146
+ required: false,
147
+ skipCheck: true
148
+ },
149
+ type: {
150
+ type: String,
151
+ required: true
152
+ },
153
+ formAction: {
154
+ type: Object,
155
+ required: false
156
+ },
157
+ name: {
158
+ type: String,
159
+ required: false
160
+ },
161
+ field: {
162
+ type: Object,
163
+ required: false
164
+ },
165
+ options: {
166
+ type: Array,
167
+ required: false
168
+ },
169
+ maxLength: {
170
+ type: Number,
171
+ required: false
172
+ },
173
+ autocomplete: {
174
+ type: String,
175
+ required: false
176
+ },
177
+ title: {
178
+ type: String,
179
+ required: false
180
+ },
181
+ level: {
182
+ type: Number,
183
+ required: false
184
+ },
185
+ onRemove: {
186
+ type: Function,
187
+ required: false
188
+ },
189
+ canRemove: {
190
+ type: Boolean,
191
+ required: false
192
+ },
193
+ removeLabel: {
194
+ type: String,
195
+ required: false
196
+ },
197
+ arrayIndex: {
198
+ type: Number,
199
+ required: false
200
+ },
201
+ path: {
202
+ type: String,
203
+ required: true
204
+ },
205
+ valueHelp: {
206
+ type: Object,
207
+ required: false
208
+ },
209
+ singularLabel: {
210
+ type: String,
211
+ required: false
212
+ },
213
+ inputId: {
214
+ type: String,
215
+ required: true
216
+ },
217
+ errorId: {
218
+ type: String,
219
+ required: true
220
+ },
221
+ descId: {
222
+ type: String,
223
+ required: true
224
+ },
225
+ ariaDescribedBy: {
226
+ type: String,
227
+ required: false
228
+ },
229
+ currencyCode: {
230
+ type: String,
231
+ required: false
232
+ },
233
+ unitCode: {
234
+ type: String,
235
+ required: false
236
+ },
237
+ precisionScale: {
238
+ type: Number,
239
+ required: false
240
+ },
241
+ prefix: {
242
+ type: String,
243
+ required: false
244
+ },
245
+ suffix: {
246
+ type: String,
247
+ required: false
248
+ },
249
+ scale: {
250
+ type: Number,
251
+ required: false
252
+ },
253
+ hasAdornment: {
254
+ type: Boolean,
255
+ required: false
256
+ },
257
+ disabled: {
258
+ type: Boolean,
259
+ required: false
260
+ },
261
+ hidden: {
262
+ type: Boolean,
263
+ required: false
264
+ }
265
+ },
266
+ setup(__props) {
267
+ const props = __props;
268
+ const { unionField, hasMultipleVariants, localUnionIndex, innerField, changeVariant, optionalEnabled } = useAsUnion(props);
269
+ const { types } = useAsTypeMap();
270
+ const unionCtx = unionField.value ? {
271
+ variants: unionField.value.unionVariants,
272
+ currentIndex: localUnionIndex,
273
+ changeVariant
274
+ } : void 0;
275
+ if (unionCtx) (0, vue.provide)(require_use_form_context.UNION_CONTEXT_KEY, unionCtx);
276
+ const variantComponent = (0, vue.computed)(() => innerField.value ? types.value?.[innerField.value.type] : void 0);
277
+ const fieldLabel = (0, vue.computed)(() => props.title ?? props.label ?? props.name ?? "");
278
+ const rootRef = (0, vue.ref)(null);
279
+ const rootEl = () => {
280
+ const r = rootRef.value;
281
+ if (!r) return null;
282
+ if (typeof r.querySelectorAll === "function") return r;
283
+ return r.$el ?? null;
284
+ };
285
+ const pickerDropdownRef = (0, vue.ref)(null);
286
+ const { isOpen: pickerOpen, toggle: togglePicker, select: selectPicker } = require_use_as_dropdown.useAsDropdown(pickerDropdownRef);
287
+ const { runAndFocusNew } = require_use_as_optional_add_flow.useAsOptionalAddFlow({ path: () => props.path });
288
+ function pickAndFocus(vi) {
289
+ runAndFocusNew(rootEl, () => changeVariant(vi), 2);
290
+ }
291
+ function handleEmptyClick() {
292
+ if (hasMultipleVariants.value) {
293
+ togglePicker();
294
+ return;
295
+ }
296
+ pickAndFocus(0);
297
+ }
298
+ function handleVariantPick(vi) {
299
+ selectPicker(() => pickAndFocus(vi));
300
+ }
301
+ return (_ctx, _cache) => {
302
+ return __props.optional && !(0, vue.unref)(optionalEnabled) ? (0, vue.withDirectives)(((0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
303
+ key: 0,
304
+ ref_key: "rootRef",
305
+ ref: rootRef,
306
+ class: (0, vue.normalizeClass)(["as-object-empty as-grid-item", _ctx.$props.class])
307
+ }, [(0, vue.unref)(hasMultipleVariants) ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
308
+ key: 0,
309
+ ref_key: "pickerDropdownRef",
310
+ ref: pickerDropdownRef,
311
+ class: "as-dropdown"
312
+ }, [(0, vue.createElementVNode)("button", {
313
+ type: "button",
314
+ class: "as-object-empty-add",
315
+ onClick: handleEmptyClick
316
+ }, [_cache[0] || (_cache[0] = (0, vue.createElementVNode)("span", {
317
+ class: "i-as-field-fill as-object-empty-add-icon",
318
+ "aria-hidden": "true"
319
+ }, null, -1)), (0, vue.createTextVNode)(" Add " + (0, vue.toDisplayString)(fieldLabel.value), 1)]), (0, vue.unref)(pickerOpen) ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_1, [((0, vue.openBlock)(true), (0, vue.createElementBlock)(vue.Fragment, null, (0, vue.renderList)((0, vue.unref)(unionField).unionVariants, (v, vi) => {
320
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)("button", {
321
+ key: vi,
322
+ type: "button",
323
+ class: "as-dropdown-item",
324
+ onClick: ($event) => handleVariantPick(vi)
325
+ }, (0, vue.toDisplayString)(v.label), 9, _hoisted_2);
326
+ }), 128))])) : (0, vue.createCommentVNode)("v-if", true)], 512)) : ((0, vue.openBlock)(), (0, vue.createElementBlock)("button", {
327
+ key: 1,
328
+ type: "button",
329
+ class: "as-object-empty-add",
330
+ onClick: handleEmptyClick
331
+ }, [_cache[1] || (_cache[1] = (0, vue.createElementVNode)("span", {
332
+ class: "i-as-field-fill as-object-empty-add-icon",
333
+ "aria-hidden": "true"
334
+ }, null, -1)), (0, vue.createTextVNode)(" Add " + (0, vue.toDisplayString)(fieldLabel.value), 1)])), __props.description ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("p", _hoisted_3, (0, vue.toDisplayString)(__props.description), 1)) : (0, vue.createCommentVNode)("v-if", true)], 2)), [[vue.vShow, !__props.hidden]]) : variantComponent.value && (0, vue.unref)(innerField) ? ((0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, { key: 1 }, [(0, vue.createCommentVNode)(" Active: dispatch to variant's component, forwarding the field's @meta.label\n as title so the variant's chrome shows it (innerField.type overrides \"union\"). "), ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.resolveDynamicComponent)(variantComponent.value), (0, vue.mergeProps)({
335
+ ref_key: "rootRef",
336
+ ref: rootRef
337
+ }, _ctx.$props, {
338
+ field: (0, vue.unref)(innerField),
339
+ type: (0, vue.unref)(innerField).type,
340
+ title: fieldLabel.value,
341
+ key: (0, vue.unref)(localUnionIndex)
342
+ }), null, 16, [
343
+ "field",
344
+ "type",
345
+ "title"
346
+ ]))], 2112)) : (0, vue.createCommentVNode)("v-if", true);
347
+ };
348
+ }
349
+ });
350
+ //#endregion
351
+ Object.defineProperty(exports, "as_union_default", {
352
+ enumerable: true,
353
+ get: function() {
354
+ return as_union_default;
355
+ }
356
+ });
357
+ Object.defineProperty(exports, "useAsTypeMap", {
358
+ enumerable: true,
359
+ get: function() {
360
+ return useAsTypeMap;
361
+ }
362
+ });
363
+ Object.defineProperty(exports, "useAsUnion", {
364
+ enumerable: true,
365
+ get: function() {
366
+ return useAsUnion;
367
+ }
368
+ });