@atscript/vue-form 0.1.102 → 0.1.103

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 (97) hide show
  1. package/dist/{as-array-B_LjJ0oi.mjs → as-array-4rQYVD9_.mjs} +4 -4
  2. package/dist/{as-array-DAeDxzYV.cjs → as-array-C6tCzZir.cjs} +4 -4
  3. package/dist/as-array.cjs +1 -1
  4. package/dist/as-array.mjs +1 -1
  5. package/dist/{as-checkbox-dN1K-rJ_.mjs → as-checkbox-C3i6ZmRk.mjs} +1 -1
  6. package/dist/{as-checkbox-Cva4XHFW.cjs → as-checkbox-oxG8_Isu.cjs} +1 -1
  7. package/dist/as-checkbox.cjs +1 -1
  8. package/dist/as-checkbox.mjs +1 -1
  9. package/dist/{as-collapsible-B0rlXU0x.cjs → as-collapsible-BQ-eYR0v.cjs} +2 -2
  10. package/dist/{as-collapsible-DQOxKGGj.mjs → as-collapsible-DFTzB5Ar.mjs} +2 -2
  11. package/dist/as-collapsible.cjs +1 -1
  12. package/dist/as-collapsible.mjs +1 -1
  13. package/dist/{as-date-CsBBqja_.mjs → as-date-BfISLr-e.mjs} +1 -1
  14. package/dist/{as-date-Cizo8gZx.cjs → as-date-C7pJIpe-.cjs} +1 -1
  15. package/dist/as-date.cjs +1 -1
  16. package/dist/as-date.mjs +1 -1
  17. package/dist/{as-datetime-Cjbprmxg.cjs → as-datetime-DFTI8Wcr.cjs} +1 -1
  18. package/dist/{as-datetime-D_Wbrj9t.mjs → as-datetime-F3In2A6l.mjs} +1 -1
  19. package/dist/as-datetime.cjs +1 -1
  20. package/dist/as-datetime.mjs +1 -1
  21. package/dist/{as-decimal-DhrdOvUQ.cjs → as-decimal-CJAHWYjW.cjs} +1 -1
  22. package/dist/{as-decimal-DtQuZmPA.mjs → as-decimal-DIO8bD2Y.mjs} +1 -1
  23. package/dist/as-decimal.cjs +1 -1
  24. package/dist/as-decimal.mjs +1 -1
  25. package/dist/{as-field-DGnC4dew.cjs → as-field-BKa4D63r.cjs} +1 -1
  26. package/dist/{as-field-CDB-HIfz.mjs → as-field-DLW-csEu.mjs} +1 -1
  27. package/dist/{as-field-shell-D0mNXfQZ.mjs → as-field-shell-BHYEjGcn.mjs} +1 -1
  28. package/dist/{as-field-shell-zeno02I1.cjs → as-field-shell-CW3DDHnq.cjs} +1 -1
  29. package/dist/as-field-shell.cjs +1 -1
  30. package/dist/as-field-shell.mjs +1 -1
  31. package/dist/as-field.cjs +1 -1
  32. package/dist/as-field.mjs +1 -1
  33. package/dist/{as-form-DaAnsFVF.cjs → as-form-CrMA0HdQ.cjs} +196 -10
  34. package/dist/{as-form-8YNdb-49.mjs → as-form-OsyP7m-A.mjs} +193 -13
  35. package/dist/as-form.cjs +1 -1
  36. package/dist/as-form.d.cts +1 -1
  37. package/dist/as-form.d.mts +1 -1
  38. package/dist/as-form.mjs +1 -1
  39. package/dist/{as-form.vue-ZykHT4gZ.d.mts → as-form.vue-2NZSk1F9.d.mts} +48 -2
  40. package/dist/{as-form.vue-5FyX_1CQ.d.cts → as-form.vue-Dg_5GYWG.d.cts} +48 -2
  41. package/dist/{as-input-CwPkK9qR.cjs → as-input-CqxNYh5q.cjs} +1 -1
  42. package/dist/{as-input-VOGvI31W.mjs → as-input-D7aA22Yx.mjs} +1 -1
  43. package/dist/as-input.cjs +1 -1
  44. package/dist/as-input.mjs +1 -1
  45. package/dist/{as-iterator---gxkT-L.mjs → as-iterator-DW7giLlz.mjs} +2 -2
  46. package/dist/{as-iterator-BWXIzbJF.cjs → as-iterator-DsDKfpTh.cjs} +2 -2
  47. package/dist/as-iterator.cjs +1 -1
  48. package/dist/as-iterator.mjs +1 -1
  49. package/dist/{as-multi-select-DGipqqGz.mjs → as-multi-select-Bsf4Y_mv.mjs} +1 -1
  50. package/dist/{as-multi-select-D7XGZS3L.cjs → as-multi-select-DQUInqwY.cjs} +1 -1
  51. package/dist/as-multi-select.cjs +1 -1
  52. package/dist/as-multi-select.mjs +1 -1
  53. package/dist/{as-number-BIhBVXih.mjs → as-number-B8MCg-ph.mjs} +1 -1
  54. package/dist/{as-number-BQWwSipg.cjs → as-number-CFdK5xjM.cjs} +1 -1
  55. package/dist/as-number.cjs +1 -1
  56. package/dist/as-number.mjs +1 -1
  57. package/dist/{as-object-BJxJJM13.cjs → as-object-B4sF9sIh.cjs} +4 -4
  58. package/dist/{as-object-Dr7CttaK.mjs → as-object-CN3KZFXO.mjs} +4 -4
  59. package/dist/as-object.cjs +1 -1
  60. package/dist/as-object.mjs +1 -1
  61. package/dist/{as-radio-CdK8gCkN.cjs → as-radio-BeOQdoeq.cjs} +1 -1
  62. package/dist/{as-radio-DBW6XzlW.mjs → as-radio-CFaDbRPe.mjs} +1 -1
  63. package/dist/as-radio.cjs +1 -1
  64. package/dist/as-radio.mjs +1 -1
  65. package/dist/{as-ref-D6zp_PIG.mjs → as-ref-CNQgr6zE.mjs} +2 -2
  66. package/dist/{as-ref-BOAHVeR-.cjs → as-ref-RawBvR6v.cjs} +2 -2
  67. package/dist/as-ref.cjs +1 -1
  68. package/dist/as-ref.mjs +1 -1
  69. package/dist/{as-select-BiS6USZW.mjs → as-select-Cr00CPKf.mjs} +1 -1
  70. package/dist/{as-select-B2jqgF38.cjs → as-select-LJIvBPiv.cjs} +1 -1
  71. package/dist/as-select.cjs +1 -1
  72. package/dist/as-select.mjs +1 -1
  73. package/dist/{as-time-BN-Vc-iw.mjs → as-time-CE2FaqZ3.mjs} +1 -1
  74. package/dist/{as-time-DdQnNIQX.cjs → as-time-CqCF0pKQ.cjs} +1 -1
  75. package/dist/as-time.cjs +1 -1
  76. package/dist/as-time.mjs +1 -1
  77. package/dist/{as-tuple-DaY_Mw-y.cjs → as-tuple-B3ysbvxB.cjs} +4 -4
  78. package/dist/{as-tuple-BUzs7nm6.mjs → as-tuple-CeJWgP6l.mjs} +4 -4
  79. package/dist/as-tuple.cjs +1 -1
  80. package/dist/as-tuple.mjs +1 -1
  81. package/dist/{as-union-B5OFQLJX.mjs → as-union-BPlYyGVk.mjs} +2 -2
  82. package/dist/{as-union-Cz5cm7BP.cjs → as-union-Djhjo69H.cjs} +2 -2
  83. package/dist/as-union.cjs +1 -1
  84. package/dist/as-union.mjs +1 -1
  85. package/dist/index.cjs +25 -24
  86. package/dist/index.d.cts +90 -5
  87. package/dist/index.d.mts +90 -5
  88. package/dist/index.mjs +25 -25
  89. package/dist/{use-as-optional-add-flow-C85F2VoU.cjs → use-as-optional-add-flow-BXKiK1Kb.cjs} +1 -1
  90. package/dist/{use-as-optional-add-flow-CQctXLZI.mjs → use-as-optional-add-flow-B_gr8sX-.mjs} +1 -1
  91. package/dist/{use-form-context-bAj7UoSe.mjs → use-form-context-D6J1WTyG.mjs} +2 -1
  92. package/dist/{use-form-context-Dwr8Ai1v.cjs → use-form-context-DpGiGUvJ.cjs} +7 -0
  93. package/package.json +4 -4
  94. /package/dist/{use-as-nested-sections-store-jdMRxjBE.cjs → use-as-nested-sections-store--E0Ijpt5.cjs} +0 -0
  95. /package/dist/{use-as-nested-sections-store-lhi0z5z1.mjs → use-as-nested-sections-store-DVRmG7V0.mjs} +0 -0
  96. /package/dist/{use-as-value-help-uANI3zWa.cjs → use-as-value-help-BsAriqCI.cjs} +0 -0
  97. /package/dist/{use-as-value-help-CBykDEjZ.mjs → use-as-value-help-DrISSxCz.mjs} +0 -0
@@ -1,10 +1,158 @@
1
- import { a as CHANGE_HANDLER_KEY, c as ERRORS_KEY, d as FORM_STATE_KEY, f as HIDE_ROOT_TITLE_KEY, g as TYPES_KEY, h as ROOT_DATA_KEY, i as ACTION_HANDLER_KEY, l as FORM_CONTEXT_KEY, m as PATH_PREFIX_KEY, o as COMPONENTS_KEY, s as DISMISS_EXTERNAL_AT_KEY, u as FORM_DATA_KEY } from "./use-form-context-bAj7UoSe.mjs";
2
- import { n as provideAsNestedSectionsStore, r as useAsNestedSectionsStore, t as DESCENDANT_ERROR_COUNTS_KEY } from "./use-as-nested-sections-store-lhi0z5z1.mjs";
3
- import { t as CLIENT_FACTORY_KEY } from "./use-as-value-help-CBykDEjZ.mjs";
4
- import { t as as_field_default } from "./as-field-CDB-HIfz.mjs";
5
- import { t as as_iterator_default } from "./as-iterator---gxkT-L.mjs";
6
- import { computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, guardReactiveProps, mergeProps, nextTick, normalizeProps, openBlock, provide, reactive, ref, renderSlot, toDisplayString, toRaw, toValue, unref, watch, watchEffect, withModifiers } from "vue";
7
- import { META_DESCRIPTION, META_LABEL, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_SUBMIT_TEXT, buildDescendantErrorCounts, getDeclaredFormActions, getFormValidator, iteratePathAncestors, mergeErrorMaps, resolveFormProp } from "@atscript/ui";
1
+ import { _ as TYPES_KEY, a as CHANGE_HANDLER_KEY, c as ERRORS_KEY, d as FORM_PATCH_KEY, f as FORM_STATE_KEY, g as ROOT_DATA_KEY, h as PATH_PREFIX_KEY, i as ACTION_HANDLER_KEY, l as FORM_CONTEXT_KEY, o as COMPONENTS_KEY, p as HIDE_ROOT_TITLE_KEY, s as DISMISS_EXTERNAL_AT_KEY, u as FORM_DATA_KEY } from "./use-form-context-D6J1WTyG.mjs";
2
+ import { n as provideAsNestedSectionsStore, r as useAsNestedSectionsStore, t as DESCENDANT_ERROR_COUNTS_KEY } from "./use-as-nested-sections-store-DVRmG7V0.mjs";
3
+ import { t as CLIENT_FACTORY_KEY } from "./use-as-value-help-DrISSxCz.mjs";
4
+ import { t as as_field_default } from "./as-field-DLW-csEu.mjs";
5
+ import { t as as_iterator_default } from "./as-iterator-DW7giLlz.mjs";
6
+ import { computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, guardReactiveProps, inject, mergeProps, nextTick, normalizeProps, openBlock, provide, reactive, ref, renderSlot, toDisplayString, toRaw, toValue, unref, watch, watchEffect, withModifiers } from "vue";
7
+ import { META_DESCRIPTION, META_LABEL, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_SUBMIT_TEXT, buildDescendantErrorCounts, buildFormDiff, getDeclaredFormActions, getFormValidator, iteratePathAncestors, mergeErrorMaps, resolveFormProp } from "@atscript/ui";
8
+ //#region src/composables/use-as-form-patch.ts
9
+ /**
10
+ * Internal factory invoked by `useAsForm` when `trackChanges` is enabled. Owns
11
+ * the deep-clone baseline lifecycle:
12
+ *
13
+ * - captures a DEEP CLONE of the wrapped form-data the moment tracking becomes
14
+ * active (and, if data is not yet available, when it first arrives),
15
+ * - re-baselines on `reset()` (the form's own reset path calls `rebase()`),
16
+ * - exposes `rebase()` so a consumer can re-baseline after a successful save.
17
+ *
18
+ * The clone is mandatory: `buildFormDiff` keeps LIVE references into the
19
+ * supplied baseline, so a shared reference would be mutated by subsequent
20
+ * edits and the diff would always come back empty.
21
+ *
22
+ * Reactivity: a single revert-aware `diff` computed drives `isDirty` /
23
+ * `changes`. `buildFormDiff` reads most reactive leaves of the live container
24
+ * (via `getByPath` + the `deepEqual` walk), so the computed auto-tracks scalar
25
+ * edits, nested-object edits, and `$update` edits to EXISTING keyed-array items.
26
+ * But the `$insert` branch pushes a freshly-added (not-yet-saved) keyed-array
27
+ * element BY REFERENCE without reading its leaves, so editing such a row's
28
+ * non-key leaves (qty/description) would NOT invalidate the computed. To close
29
+ * that blind spot we add a single deep `watch` on the live data — created ONLY
30
+ * when tracking is active, owned by the component scope (it disposes on unmount)
31
+ * — that bumps `dataRev`; the `diff` computed reads `dataRev` so every leaf
32
+ * mutation, including an inserted row's, re-evaluates it. OFF stays zero-cost:
33
+ * `createAsFormPatch` is never called when tracking is disabled, so neither the
34
+ * baseline nor this watcher is ever created. It recomputes only when the live
35
+ * data (`dataRev`) or the baseline (`baselineRev`) changes, and Vue caches the
36
+ * result between reads.
37
+ *
38
+ * @param def getter for the form's `FormDef`
39
+ * @param getData getter for the WRAPPED form-data container `{ value }`. Before
40
+ * real domain data arrives `useAsForm` yields the empty internal
41
+ * fallback `{}` (no `value` key); the tracker treats that as
42
+ * "no data yet" and defers the baseline until a `{ value: … }`
43
+ * container appears (the fetch-then-fill flow).
44
+ */
45
+ function createAsFormPatch(def, getData) {
46
+ let baseline;
47
+ const baselineRev = ref(0);
48
+ const dataRev = ref(0);
49
+ /**
50
+ * Deep-clones the current wrapped container, or returns `undefined` when no
51
+ * real domain data exists yet. "No data yet" = the container has no `value`
52
+ * key or its `value` is `undefined` (the `{}` internal fallback, or a
53
+ * `:form-data` ref that has not resolved). Capturing the empty fallback as the
54
+ * baseline would make every field read as dirty once real data replaces it,
55
+ * so we wait for a genuine `{ value: … }` container.
56
+ */
57
+ function snapshot() {
58
+ const cur = getData();
59
+ if (cur.value === void 0) return void 0;
60
+ return deepClone(toRaw(cur));
61
+ }
62
+ function capture() {
63
+ baseline = snapshot();
64
+ baselineRev.value++;
65
+ }
66
+ capture();
67
+ if (baseline === void 0) {
68
+ const stop = watch(() => getData().value, () => {
69
+ if (baseline !== void 0) return;
70
+ capture();
71
+ if (baseline !== void 0) stop();
72
+ });
73
+ }
74
+ watch(() => getData(), () => dataRev.value++, { deep: true });
75
+ const diff = computed(() => {
76
+ dataRev.value;
77
+ baselineRev.value;
78
+ if (baseline === void 0) return {
79
+ isDirty: false,
80
+ changes: []
81
+ };
82
+ const result = buildFormDiff(def(), baseline, getData());
83
+ return {
84
+ isDirty: result.isDirty,
85
+ changes: result.changes
86
+ };
87
+ });
88
+ const isDirty = computed(() => diff.value.isDirty);
89
+ const changes = computed(() => diff.value.changes);
90
+ function getPatch(opts) {
91
+ if (baseline === void 0) return {};
92
+ const frozen = deepClone(toRaw(getData()));
93
+ return buildFormDiff(def(), baseline, frozen, opts).patch;
94
+ }
95
+ function getChanges() {
96
+ if (baseline === void 0) return [];
97
+ const frozen = deepClone(toRaw(getData()));
98
+ return buildFormDiff(def(), baseline, frozen).changes;
99
+ }
100
+ function rebase() {
101
+ capture();
102
+ }
103
+ return {
104
+ isDirty,
105
+ changes,
106
+ getPatch,
107
+ getChanges,
108
+ rebase
109
+ };
110
+ }
111
+ /**
112
+ * Structural deep clone of plain JSON-ish data (objects / arrays / primitives /
113
+ * Date). Used to freeze the baseline so later edits to the live form data don't
114
+ * mutate it. `structuredClone` would throw on Vue proxies / functions; this
115
+ * walks own-enumerable keys and copies leaves by value.
116
+ */
117
+ function deepClone(value) {
118
+ if (value === null || typeof value !== "object") return value;
119
+ if (value instanceof Date) return new Date(value.getTime());
120
+ if (Array.isArray(value)) {
121
+ const out = [];
122
+ for (let i = 0; i < value.length; i++) out.push(deepClone(toRaw(value[i])));
123
+ return out;
124
+ }
125
+ const src = value;
126
+ const out = {};
127
+ for (const k of Object.keys(src)) out[k] = deepClone(toRaw(src[k]));
128
+ return out;
129
+ }
130
+ const NOT_TRACKING_MSG = "useAsFormPatch(): change tracking is not enabled on this form. Pass `track-changes` to <AsForm> (or `trackChanges: true` to useAsForm).";
131
+ /**
132
+ * Reactive read-only access to the form's change-tracking handle from any
133
+ * descendant of an `<AsForm track-changes>`. Mirrors the `useAsData` /
134
+ * `useAsPath` injector pattern.
135
+ *
136
+ * THROWS when called outside a form, or inside a form that did not enable
137
+ * `track-changes` — fail loud rather than silently report "not dirty".
138
+ *
139
+ * @example
140
+ * ```vue
141
+ * <script setup lang="ts">
142
+ * import { useAsFormPatch } from "@atscript/vue-form";
143
+ * const { isDirty, getPatch } = useAsFormPatch();
144
+ * <\/script>
145
+ * <template>
146
+ * <button :disabled="!isDirty" @click="save(getPatch())">Save</button>
147
+ * </template>
148
+ * ```
149
+ */
150
+ function useAsFormPatch() {
151
+ const handle = inject(FORM_PATCH_KEY, void 0);
152
+ if (!handle) throw new Error(NOT_TRACKING_MSG);
153
+ return handle;
154
+ }
155
+ //#endregion
8
156
  //#region src/composables/use-as-external-errors.ts
9
157
  /**
10
158
  * Local dismissal state for externally-supplied errors.
@@ -144,6 +292,9 @@ function useAsState(opts) {
144
292
  }
145
293
  //#endregion
146
294
  //#region src/composables/use-as-form.ts
295
+ const EMPTY_CHANGES = Object.freeze([]);
296
+ const EMPTY_GET_PATCH = () => ({});
297
+ const EMPTY_GET_CHANGES = () => [];
147
298
  /**
148
299
  * Composable backing `<AsForm>`. Owns the entire form state machine —
149
300
  * data container, internal validator, external-error dismissal, action
@@ -179,6 +330,12 @@ function useAsForm(options) {
179
330
  context: formContext.value ?? {}
180
331
  })
181
332
  });
333
+ const patch = options.trackChanges?.() ? createAsFormPatch(() => options.def(), () => data.value) : void 0;
334
+ if (patch) provide(FORM_PATCH_KEY, patch);
335
+ const reset = patch ? async () => {
336
+ await resetState();
337
+ patch.rebase();
338
+ } : resetState;
182
339
  provide(ROOT_DATA_KEY, data);
183
340
  provide(PATH_PREFIX_KEY, computed(() => ""));
184
341
  provide(TYPES_KEY, computed(() => options.types()));
@@ -220,12 +377,16 @@ function useAsForm(options) {
220
377
  loading: options.loading?.() === true,
221
378
  submitText: submitText.value,
222
379
  submit: onSubmit,
223
- reset: resetState,
380
+ reset,
224
381
  clearErrors,
225
382
  setErrors,
226
383
  dismissError: ext.dismissAt,
227
384
  dismissFormError: ext.dismissForm,
228
- formContext: formContext.value
385
+ formContext: formContext.value,
386
+ isDirty: patch?.isDirty.value ?? false,
387
+ changes: patch ? patch.changes.value : EMPTY_CHANGES,
388
+ getPatch: patch ? patch.getPatch : EMPTY_GET_PATCH,
389
+ getChanges: patch ? patch.getChanges : EMPTY_GET_CHANGES
229
390
  }));
230
391
  function supportsAction(def, actionId) {
231
392
  return getDeclaredFormActions(def).some((a) => a.id === actionId);
@@ -271,7 +432,7 @@ function useAsForm(options) {
271
432
  errors: ext.effective,
272
433
  formError: ext.formError,
273
434
  internalErrors,
274
- reset: resetState,
435
+ reset,
275
436
  clearErrors,
276
437
  setErrors,
277
438
  onSubmit,
@@ -284,7 +445,8 @@ function useAsForm(options) {
284
445
  dismissError: ext.dismissAt,
285
446
  dismissFormError: ext.dismissForm,
286
447
  formContext,
287
- handleChange
448
+ handleChange,
449
+ patch
288
450
  };
289
451
  }
290
452
  //#endregion
@@ -352,6 +514,10 @@ var as_form_default = /* @__PURE__ */ defineComponent({
352
514
  loading: {
353
515
  type: Boolean,
354
516
  required: false
517
+ },
518
+ trackChanges: {
519
+ type: Boolean,
520
+ required: false
355
521
  }
356
522
  },
357
523
  emits: [
@@ -361,7 +527,7 @@ var as_form_default = /* @__PURE__ */ defineComponent({
361
527
  "unsupported-action",
362
528
  "change"
363
529
  ],
364
- setup(__props, { emit: __emit }) {
530
+ setup(__props, { expose: __expose, emit: __emit }) {
365
531
  const props = __props;
366
532
  const emit = __emit;
367
533
  const form = useAsForm({
@@ -375,6 +541,7 @@ var as_form_default = /* @__PURE__ */ defineComponent({
375
541
  clientFactory: () => props.clientFactory,
376
542
  hideRootTitle: () => props.hideRootTitle,
377
543
  loading: () => props.loading,
544
+ trackChanges: () => props.trackChanges,
378
545
  emits: {
379
546
  submit: (data) => emit("submit", data),
380
547
  error: (errors) => emit("error", errors),
@@ -383,6 +550,19 @@ var as_form_default = /* @__PURE__ */ defineComponent({
383
550
  change: (type, path, value, formData) => emit("change", type, path, value, formData)
384
551
  }
385
552
  });
553
+ __expose({
554
+ submit: form.onSubmit,
555
+ reset: form.reset,
556
+ get isDirty() {
557
+ return form.patch?.isDirty.value ?? false;
558
+ },
559
+ get changes() {
560
+ return form.patch?.changes.value ?? [];
561
+ },
562
+ getPatch: form.patch ? form.patch.getPatch : () => ({}),
563
+ getChanges: form.patch ? form.patch.getChanges : () => [],
564
+ rebase: form.patch ? form.patch.rebase : () => {}
565
+ });
386
566
  return (_ctx, _cache) => {
387
567
  return openBlock(), createElementBlock("form", {
388
568
  class: "as-form",
@@ -420,4 +600,4 @@ var as_form_default = /* @__PURE__ */ defineComponent({
420
600
  }
421
601
  });
422
602
  //#endregion
423
- export { useAsExternalErrors as i, useAsForm as n, useAsState as r, as_form_default as t };
603
+ export { useAsFormPatch as a, useAsExternalErrors as i, useAsForm as n, useAsState as r, as_form_default as t };
package/dist/as-form.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const require_as_form = require("./as-form-DaAnsFVF.cjs");
1
+ const require_as_form = require("./as-form-CrMA0HdQ.cjs");
2
2
  module.exports = require_as_form.as_form_default;
@@ -1,2 +1,2 @@
1
- import { n as _default, t as Props } from "./as-form.vue-5FyX_1CQ.cjs";
1
+ import { n as _default, t as Props } from "./as-form.vue-Dg_5GYWG.cjs";
2
2
  export { Props, _default as default };
@@ -1,2 +1,2 @@
1
- import { n as _default, t as Props } from "./as-form.vue-ZykHT4gZ.mjs";
1
+ import { n as _default, t as Props } from "./as-form.vue-2NZSk1F9.mjs";
2
2
  export { Props, _default as default };
package/dist/as-form.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as as_form_default } from "./as-form-8YNdb-49.mjs";
1
+ import { t as as_form_default } from "./as-form-OsyP7m-A.mjs";
2
2
  export { as_form_default as default };
@@ -1,6 +1,7 @@
1
1
  import { n as TAsChangeType, o as TAsComponentProps, s as TAsTypeComponents } from "./types-CV9ss4UN.mjs";
2
2
  import * as vue from "vue";
3
3
  import { Component } from "vue";
4
+ import * as _atscript_ui0 from "@atscript/ui";
4
5
  import { ClientFactory, FormDef } from "@atscript/ui";
5
6
 
6
7
  //#region src/composables/types.d.ts
@@ -74,21 +75,38 @@ interface Props<TF, TC> {
74
75
  * `inner-loading`.
75
76
  */
76
77
  loading?: boolean;
78
+ /**
79
+ * Enable change tracking. When set, the form captures a deep-clone baseline
80
+ * of its data and surfaces both a changed-fields list and an `@atscript/db`
81
+ * patch object. The tracking surface (`isDirty` / `changes` / `getPatch` /
82
+ * `getChanges`) is spread into every slot AND exposed on the component
83
+ * instance (template ref → `asForm.value.getPatch()`); descendants read it
84
+ * with `useAsFormPatch()`. Off by default — zero overhead when unset.
85
+ */
86
+ trackChanges?: boolean;
77
87
  }
78
88
  declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
79
89
  props: vue.PublicProps & __VLS_PrettifyLocal<Props<TFormData, TFormContext> & {
80
- onSubmit?: ((data: TFormData) => any) | undefined;
81
90
  onError?: ((errors: {
82
91
  path: string;
83
92
  message: string;
84
93
  }[]) => any) | undefined;
85
94
  onAction?: ((name: string, data: TFormData) => any) | undefined;
95
+ onSubmit?: ((data: TFormData) => any) | undefined;
86
96
  "onUnsupported-action"?: ((name: string, data: TFormData) => any) | undefined;
87
97
  onChange?: ((type: TAsChangeType, path: string, value: unknown, formData: TFormData) => any) | undefined;
88
98
  }> & (typeof globalThis extends {
89
99
  __VLS_PROPS_FALLBACK: infer P;
90
100
  } ? P : {});
91
- expose: (exposed: {}) => void;
101
+ expose: (exposed: vue.ShallowUnwrapRef<{
102
+ submit: () => void;
103
+ reset: () => Promise<void>; /** True when `track-changes` is on AND data differs from baseline. */
104
+ readonly isDirty: boolean; /** Revert-aware per-field change list (empty when tracking is off). */
105
+ readonly changes: _atscript_ui0.FormFieldChange[]; /** Build the `@atscript/db` patch object on demand (`{}` when off). */
106
+ getPatch: ((opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>) | (() => {}); /** Build the per-field change list on demand (`[]` when off). */
107
+ getChanges: () => _atscript_ui0.FormFieldChange[]; /** Re-baseline to current data after a successful save (no-op when off). */
108
+ rebase: () => void;
109
+ }>) => void;
92
110
  attrs: any;
93
111
  slots: {
94
112
  'form.header'?: (props: {
@@ -107,6 +125,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
107
125
  dismissError: (path: string) => void;
108
126
  dismissFormError: () => void;
109
127
  formContext: TFormContext | undefined;
128
+ isDirty: boolean;
129
+ changes: readonly _atscript_ui0.FormFieldChange[];
130
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
131
+ getChanges: () => _atscript_ui0.FormFieldChange[];
110
132
  }) => any;
111
133
  } & {
112
134
  'form.before'?: (props: {
@@ -125,6 +147,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
125
147
  dismissError: (path: string) => void;
126
148
  dismissFormError: () => void;
127
149
  formContext: TFormContext | undefined;
150
+ isDirty: boolean;
151
+ changes: readonly _atscript_ui0.FormFieldChange[];
152
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
153
+ getChanges: () => _atscript_ui0.FormFieldChange[];
128
154
  }) => any;
129
155
  } & {
130
156
  'form.after'?: (props: {
@@ -143,6 +169,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
143
169
  dismissError: (path: string) => void;
144
170
  dismissFormError: () => void;
145
171
  formContext: TFormContext | undefined;
172
+ isDirty: boolean;
173
+ changes: readonly _atscript_ui0.FormFieldChange[];
174
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
175
+ getChanges: () => _atscript_ui0.FormFieldChange[];
146
176
  }) => any;
147
177
  } & {
148
178
  'form.error'?: (props: {
@@ -163,6 +193,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
163
193
  dismissError: (path: string) => void;
164
194
  dismissFormError: () => void;
165
195
  formContext: TFormContext | undefined;
196
+ isDirty: boolean;
197
+ changes: readonly _atscript_ui0.FormFieldChange[];
198
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
199
+ getChanges: () => _atscript_ui0.FormFieldChange[];
166
200
  }) => any;
167
201
  } & {
168
202
  'form.submit'?: (props: {
@@ -182,6 +216,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
182
216
  dismissError: (path: string) => void;
183
217
  dismissFormError: () => void;
184
218
  formContext: TFormContext | undefined;
219
+ isDirty: boolean;
220
+ changes: readonly _atscript_ui0.FormFieldChange[];
221
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
222
+ getChanges: () => _atscript_ui0.FormFieldChange[];
185
223
  }) => any;
186
224
  } & {
187
225
  'form.footer'?: (props: {
@@ -200,6 +238,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
200
238
  dismissError: (path: string) => void;
201
239
  dismissFormError: () => void;
202
240
  formContext: TFormContext | undefined;
241
+ isDirty: boolean;
242
+ changes: readonly _atscript_ui0.FormFieldChange[];
243
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
244
+ getChanges: () => _atscript_ui0.FormFieldChange[];
203
245
  }) => any;
204
246
  } & {
205
247
  'form.loading'?: (props: {
@@ -218,6 +260,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
218
260
  dismissError: (path: string) => void;
219
261
  dismissFormError: () => void;
220
262
  formContext: TFormContext | undefined;
263
+ isDirty: boolean;
264
+ changes: readonly _atscript_ui0.FormFieldChange[];
265
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
266
+ getChanges: () => _atscript_ui0.FormFieldChange[];
221
267
  }) => any;
222
268
  };
223
269
  emit: {
@@ -1,6 +1,7 @@
1
1
  import { n as TAsChangeType, o as TAsComponentProps, s as TAsTypeComponents } from "./types-BYfe1QEF.cjs";
2
2
  import * as vue from "vue";
3
3
  import { Component } from "vue";
4
+ import * as _atscript_ui0 from "@atscript/ui";
4
5
  import { ClientFactory, FormDef } from "@atscript/ui";
5
6
 
6
7
  //#region src/composables/types.d.ts
@@ -74,21 +75,38 @@ interface Props<TF, TC> {
74
75
  * `inner-loading`.
75
76
  */
76
77
  loading?: boolean;
78
+ /**
79
+ * Enable change tracking. When set, the form captures a deep-clone baseline
80
+ * of its data and surfaces both a changed-fields list and an `@atscript/db`
81
+ * patch object. The tracking surface (`isDirty` / `changes` / `getPatch` /
82
+ * `getChanges`) is spread into every slot AND exposed on the component
83
+ * instance (template ref → `asForm.value.getPatch()`); descendants read it
84
+ * with `useAsFormPatch()`. Off by default — zero overhead when unset.
85
+ */
86
+ trackChanges?: boolean;
77
87
  }
78
88
  declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
79
89
  props: vue.PublicProps & __VLS_PrettifyLocal<Props<TFormData, TFormContext> & {
80
- onSubmit?: ((data: TFormData) => any) | undefined;
81
90
  onError?: ((errors: {
82
91
  path: string;
83
92
  message: string;
84
93
  }[]) => any) | undefined;
85
94
  onAction?: ((name: string, data: TFormData) => any) | undefined;
95
+ onSubmit?: ((data: TFormData) => any) | undefined;
86
96
  "onUnsupported-action"?: ((name: string, data: TFormData) => any) | undefined;
87
97
  onChange?: ((type: TAsChangeType, path: string, value: unknown, formData: TFormData) => any) | undefined;
88
98
  }> & (typeof globalThis extends {
89
99
  __VLS_PROPS_FALLBACK: infer P;
90
100
  } ? P : {});
91
- expose: (exposed: {}) => void;
101
+ expose: (exposed: vue.ShallowUnwrapRef<{
102
+ submit: () => void;
103
+ reset: () => Promise<void>; /** True when `track-changes` is on AND data differs from baseline. */
104
+ readonly isDirty: boolean; /** Revert-aware per-field change list (empty when tracking is off). */
105
+ readonly changes: _atscript_ui0.FormFieldChange[]; /** Build the `@atscript/db` patch object on demand (`{}` when off). */
106
+ getPatch: ((opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>) | (() => {}); /** Build the per-field change list on demand (`[]` when off). */
107
+ getChanges: () => _atscript_ui0.FormFieldChange[]; /** Re-baseline to current data after a successful save (no-op when off). */
108
+ rebase: () => void;
109
+ }>) => void;
92
110
  attrs: any;
93
111
  slots: {
94
112
  'form.header'?: (props: {
@@ -107,6 +125,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
107
125
  dismissError: (path: string) => void;
108
126
  dismissFormError: () => void;
109
127
  formContext: TFormContext | undefined;
128
+ isDirty: boolean;
129
+ changes: readonly _atscript_ui0.FormFieldChange[];
130
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
131
+ getChanges: () => _atscript_ui0.FormFieldChange[];
110
132
  }) => any;
111
133
  } & {
112
134
  'form.before'?: (props: {
@@ -125,6 +147,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
125
147
  dismissError: (path: string) => void;
126
148
  dismissFormError: () => void;
127
149
  formContext: TFormContext | undefined;
150
+ isDirty: boolean;
151
+ changes: readonly _atscript_ui0.FormFieldChange[];
152
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
153
+ getChanges: () => _atscript_ui0.FormFieldChange[];
128
154
  }) => any;
129
155
  } & {
130
156
  'form.after'?: (props: {
@@ -143,6 +169,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
143
169
  dismissError: (path: string) => void;
144
170
  dismissFormError: () => void;
145
171
  formContext: TFormContext | undefined;
172
+ isDirty: boolean;
173
+ changes: readonly _atscript_ui0.FormFieldChange[];
174
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
175
+ getChanges: () => _atscript_ui0.FormFieldChange[];
146
176
  }) => any;
147
177
  } & {
148
178
  'form.error'?: (props: {
@@ -163,6 +193,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
163
193
  dismissError: (path: string) => void;
164
194
  dismissFormError: () => void;
165
195
  formContext: TFormContext | undefined;
196
+ isDirty: boolean;
197
+ changes: readonly _atscript_ui0.FormFieldChange[];
198
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
199
+ getChanges: () => _atscript_ui0.FormFieldChange[];
166
200
  }) => any;
167
201
  } & {
168
202
  'form.submit'?: (props: {
@@ -182,6 +216,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
182
216
  dismissError: (path: string) => void;
183
217
  dismissFormError: () => void;
184
218
  formContext: TFormContext | undefined;
219
+ isDirty: boolean;
220
+ changes: readonly _atscript_ui0.FormFieldChange[];
221
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
222
+ getChanges: () => _atscript_ui0.FormFieldChange[];
185
223
  }) => any;
186
224
  } & {
187
225
  'form.footer'?: (props: {
@@ -200,6 +238,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
200
238
  dismissError: (path: string) => void;
201
239
  dismissFormError: () => void;
202
240
  formContext: TFormContext | undefined;
241
+ isDirty: boolean;
242
+ changes: readonly _atscript_ui0.FormFieldChange[];
243
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
244
+ getChanges: () => _atscript_ui0.FormFieldChange[];
203
245
  }) => any;
204
246
  } & {
205
247
  'form.loading'?: (props: {
@@ -218,6 +260,10 @@ declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: N
218
260
  dismissError: (path: string) => void;
219
261
  dismissFormError: () => void;
220
262
  formContext: TFormContext | undefined;
263
+ isDirty: boolean;
264
+ changes: readonly _atscript_ui0.FormFieldChange[];
265
+ getPatch: (opts?: _atscript_ui0.FormDiffOptions) => Record<string, unknown>;
266
+ getChanges: () => _atscript_ui0.FormFieldChange[];
221
267
  }) => any;
222
268
  };
223
269
  emit: {
@@ -1,4 +1,4 @@
1
- const require_as_field_shell = require("./as-field-shell-zeno02I1.cjs");
1
+ const require_as_field_shell = require("./as-field-shell-CW3DDHnq.cjs");
2
2
  const require_as_input_control = require("./as-input-control-BYo_dfQA.cjs");
3
3
  const require_as_adornment_shell = require("./as-adornment-shell-DptUMWNk.cjs");
4
4
  let vue = require("vue");
@@ -1,4 +1,4 @@
1
- import { t as as_field_shell_default } from "./as-field-shell-D0mNXfQZ.mjs";
1
+ import { t as as_field_shell_default } from "./as-field-shell-BHYEjGcn.mjs";
2
2
  import { t as as_input_control_default } from "./as-input-control-Bx-isLZN.mjs";
3
3
  import { t as as_adornment_shell_default } from "./as-adornment-shell-C4A2fnDp.mjs";
4
4
  import { computed, createBlock, createVNode, defineComponent, guardReactiveProps, mergeProps, normalizeProps, openBlock, withCtx } from "vue";
package/dist/as-input.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const require_as_input = require("./as-input-CwPkK9qR.cjs");
1
+ const require_as_input = require("./as-input-CqxNYh5q.cjs");
2
2
  module.exports = require_as_input.as_input_default;
package/dist/as-input.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as as_input_default } from "./as-input-VOGvI31W.mjs";
1
+ import { t as as_input_default } from "./as-input-D7aA22Yx.mjs";
2
2
  export { as_input_default as default };
@@ -1,5 +1,5 @@
1
- import { m as PATH_PREFIX_KEY } from "./use-form-context-bAj7UoSe.mjs";
2
- import { t as as_field_default } from "./as-field-CDB-HIfz.mjs";
1
+ import { h as PATH_PREFIX_KEY } from "./use-form-context-D6J1WTyG.mjs";
2
+ import { t as as_field_default } from "./as-field-DLW-csEu.mjs";
3
3
  import { Fragment, computed, createBlock, createElementBlock, defineComponent, inject, openBlock, provide, renderList } from "vue";
4
4
  //#endregion
5
5
  //#region src/components/as-iterator.vue
@@ -1,5 +1,5 @@
1
- const require_use_form_context = require("./use-form-context-Dwr8Ai1v.cjs");
2
- const require_as_field = require("./as-field-DGnC4dew.cjs");
1
+ const require_use_form_context = require("./use-form-context-DpGiGUvJ.cjs");
2
+ const require_as_field = require("./as-field-BKa4D63r.cjs");
3
3
  let vue = require("vue");
4
4
  //#endregion
5
5
  //#region src/components/as-iterator.vue
@@ -1,2 +1,2 @@
1
- const require_as_iterator = require("./as-iterator-BWXIzbJF.cjs");
1
+ const require_as_iterator = require("./as-iterator-DsDKfpTh.cjs");
2
2
  module.exports = require_as_iterator.as_iterator_default;
@@ -1,2 +1,2 @@
1
- import { t as as_iterator_default } from "./as-iterator---gxkT-L.mjs";
1
+ import { t as as_iterator_default } from "./as-iterator-DW7giLlz.mjs";
2
2
  export { as_iterator_default as default };
@@ -1,4 +1,4 @@
1
- import { t as as_field_shell_default } from "./as-field-shell-D0mNXfQZ.mjs";
1
+ import { t as as_field_shell_default } from "./as-field-shell-BHYEjGcn.mjs";
2
2
  import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, mergeProps, openBlock, ref, renderList, toDisplayString, unref, withCtx, withModifiers } from "vue";
3
3
  import { optKey, optLabel } from "@atscript/ui";
4
4
  import { ComboboxAnchor, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxPortal, ComboboxRoot, ComboboxViewport } from "reka-ui";
@@ -1,4 +1,4 @@
1
- const require_as_field_shell = require("./as-field-shell-zeno02I1.cjs");
1
+ const require_as_field_shell = require("./as-field-shell-CW3DDHnq.cjs");
2
2
  let vue = require("vue");
3
3
  let _atscript_ui = require("@atscript/ui");
4
4
  let reka_ui = require("reka-ui");
@@ -1,2 +1,2 @@
1
- const require_as_multi_select = require("./as-multi-select-D7XGZS3L.cjs");
1
+ const require_as_multi_select = require("./as-multi-select-DQUInqwY.cjs");
2
2
  module.exports = require_as_multi_select.as_multi_select_default;
@@ -1,2 +1,2 @@
1
- import { t as as_multi_select_default } from "./as-multi-select-DGipqqGz.mjs";
1
+ import { t as as_multi_select_default } from "./as-multi-select-Bsf4Y_mv.mjs";
2
2
  export { as_multi_select_default as default };
@@ -1,5 +1,5 @@
1
1
  import { n as useAsLocale } from "./use-as-locale-BrFdAgnU.mjs";
2
- import { t as as_field_shell_default } from "./as-field-shell-D0mNXfQZ.mjs";
2
+ import { t as as_field_shell_default } from "./as-field-shell-BHYEjGcn.mjs";
3
3
  import { t as as_input_control_default } from "./as-input-control-Bx-isLZN.mjs";
4
4
  import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, guardReactiveProps, mergeProps, normalizeClass, normalizeProps, openBlock, ref, toDisplayString, withCtx } from "vue";
5
5
  import { getDecimalSeparator, parseDecimalInput } from "@atscript/ui";
@@ -1,5 +1,5 @@
1
1
  const require_use_as_locale = require("./use-as-locale-C4z5stwD.cjs");
2
- const require_as_field_shell = require("./as-field-shell-zeno02I1.cjs");
2
+ const require_as_field_shell = require("./as-field-shell-CW3DDHnq.cjs");
3
3
  const require_as_input_control = require("./as-input-control-BYo_dfQA.cjs");
4
4
  let vue = require("vue");
5
5
  let _atscript_ui = require("@atscript/ui");
@@ -1,2 +1,2 @@
1
- const require_as_number = require("./as-number-BQWwSipg.cjs");
1
+ const require_as_number = require("./as-number-CFdK5xjM.cjs");
2
2
  module.exports = require_as_number.as_number_default;
@@ -1,2 +1,2 @@
1
- import { t as as_number_default } from "./as-number-BIhBVXih.mjs";
1
+ import { t as as_number_default } from "./as-number-B8MCg-ph.mjs";
2
2
  export { as_number_default as default };