attaform 0.31.1 → 0.31.2

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 (44) hide show
  1. package/dist/abstract.d.mts +5 -5
  2. package/dist/abstract.mjs +3 -2
  3. package/dist/dev/abstract.mjs +3 -2
  4. package/dist/dev/directive.mjs +1 -1
  5. package/dist/dev/history.mjs +118 -11
  6. package/dist/dev/index.mjs +4 -3
  7. package/dist/dev/shared/{attaform-dev.OceE0X3v.mjs → attaform-dev.BKWPjEB2.mjs} +4 -3
  8. package/dist/dev/shared/{attaform-dev.D7lKyM_7.mjs → attaform-dev.BnLLxX2l.mjs} +3 -3
  9. package/dist/dev/shared/{attaform-dev.Cbx0AiQF.mjs → attaform-dev.CKSqs_xQ.mjs} +1 -1
  10. package/dist/dev/shared/{attaform-dev.BpVGFSFa.mjs → attaform-dev.Cf_hZfbT.mjs} +3 -3
  11. package/dist/dev/shared/{attaform-dev.3uTCYwy8.mjs → attaform-dev.DLk51W7-.mjs} +111 -909
  12. package/dist/dev/shared/{attaform-dev.CwYTWyPX.mjs → attaform-dev.DoG8mZTq.mjs} +8 -1
  13. package/dist/dev/shared/attaform-dev.G-3XDl9F.mjs +1192 -0
  14. package/dist/dev/shared/{attaform-dev.PTGM9KE1.mjs → attaform-dev.oguHqv1W.mjs} +7 -6
  15. package/dist/dev/zod-v3.mjs +5 -4
  16. package/dist/dev/zod-v4.mjs +5 -4
  17. package/dist/dev/zod.mjs +4 -3
  18. package/dist/directive.d.mts +2 -2
  19. package/dist/directive.mjs +1 -1
  20. package/dist/history.d.mts +1 -1
  21. package/dist/history.mjs +118 -11
  22. package/dist/index.d.mts +6 -6
  23. package/dist/index.mjs +4 -3
  24. package/dist/shared/{attaform.j9xI_ObC.mjs → attaform.3kV6PqVJ.mjs} +7 -6
  25. package/dist/shared/{attaform.KEfNRDot.mjs → attaform.BJeiuJE2.mjs} +3 -3
  26. package/dist/shared/{attaform._1Zp3mDG.mjs → attaform.BNUhW4qC.mjs} +8 -1
  27. package/dist/shared/{attaform.B5b-HmhH.mjs → attaform.BlAmZ-WU.mjs} +3 -3
  28. package/dist/shared/{attaform.u6jfHoed.mjs → attaform.CMzc4bPI.mjs} +4 -3
  29. package/dist/shared/attaform.CgyyJVuq.mjs +1187 -0
  30. package/dist/shared/{attaform.CYlF4P6X.d.mts → attaform.CibLYe9-.d.mts} +185 -165
  31. package/dist/shared/{attaform.DAf4ehIe.mjs → attaform.DCUJCKyG.mjs} +111 -909
  32. package/dist/shared/{attaform.DZOynI6c.d.mts → attaform.DCyZT7u-.d.mts} +1 -1
  33. package/dist/shared/{attaform.B9PYKlhB.d.mts → attaform.DD0Y8krq.d.mts} +1 -1
  34. package/dist/shared/{attaform.BPMOl562.mjs → attaform.T0YjhjPU.mjs} +1 -1
  35. package/dist/shared/{attaform.i13OEHJF.d.mts → attaform.bI_4nKZp.d.mts} +61 -3
  36. package/dist/zod-v3.d.mts +4 -4
  37. package/dist/zod-v3.mjs +5 -4
  38. package/dist/zod-v4.d.mts +6 -6
  39. package/dist/zod-v4.mjs +5 -4
  40. package/dist/zod.d.mts +4 -4
  41. package/dist/zod.mjs +4 -3
  42. package/package.json +1 -1
  43. package/dist/dev/shared/attaform-dev.n6n00owJ.mjs +0 -279
  44. package/dist/shared/attaform.BPSqtU7a.mjs +0 -274
@@ -1,274 +0,0 @@
1
- import { s as safeAssign, a as safeOwnRead, r as readConsumerIndex, c as consumerKeys, b as readConsumerProp } from './attaform._1Zp3mDG.mjs';
2
- import { m as mapSegmentKeys, f as pathsEqual, i as isPathPrefix } from './attaform.BhtAZysa.mjs';
3
-
4
- const DEFAULT_FIELD_VALIDATION_DEBOUNCE_MS = 0;
5
- const DEFAULT_HISTORY_MAX_SNAPSHOTS = 128;
6
- const RESERVED_KEY_PREFIX = "__atta:";
7
- const ANONYMOUS_FORM_KEY_PREFIX = `${RESERVED_KEY_PREFIX}anon:`;
8
- const ANONYMOUS_WIZARD_KEY_PREFIX = `${RESERVED_KEY_PREFIX}anon-wizard:`;
9
- const DEFAULT_MAX_RECURSION_DEPTH = 64;
10
- function normalizeNumericOption(config) {
11
- const { value, source, min, defaultValue } = config;
12
- if (typeof value !== "number" || !Number.isFinite(value)) {
13
- return defaultValue;
14
- }
15
- return Math.max(min, Math.floor(value));
16
- }
17
- function pickDefined(bag) {
18
- const out = {};
19
- for (const key of Object.keys(bag)) {
20
- if (bag[key] !== void 0) out[key] = bag[key];
21
- }
22
- return out;
23
- }
24
-
25
- function isDescendable(value) {
26
- if (value === null || typeof value !== "object") return false;
27
- if (Array.isArray(value)) return true;
28
- if (value instanceof Map) return mapSegmentKeys(value) !== null;
29
- const proto = Object.getPrototypeOf(value);
30
- return proto === null || proto === Object.prototype;
31
- }
32
- function isBarePatch(patch) {
33
- return patch.kind === "added" ? isDescendable(patch.newValue) : patch.kind === "removed" && isDescendable(patch.oldValue);
34
- }
35
- function appendSegment(prefix, segment) {
36
- const next = new Array(prefix.length + 1);
37
- for (let i = 0; i < prefix.length; i++) {
38
- const s = prefix[i];
39
- next[i] = s;
40
- }
41
- next[prefix.length] = segment;
42
- return next;
43
- }
44
- function diffAndApply(oldValue, newValue, prefix, visit) {
45
- if (Object.is(oldValue, newValue)) return;
46
- const oldIsDescendable = isDescendable(oldValue);
47
- const newIsDescendable = isDescendable(newValue);
48
- if (oldValue === void 0 && newIsDescendable) {
49
- walkDescendable(newValue, prefix, visit, true);
50
- return;
51
- }
52
- if (oldIsDescendable && newValue === void 0) {
53
- walkDescendable(oldValue, prefix, visit, false);
54
- return;
55
- }
56
- if (oldIsDescendable && newIsDescendable) {
57
- const oldIsMap = oldValue instanceof Map;
58
- const newIsMap = newValue instanceof Map;
59
- if (oldIsMap && newIsMap) {
60
- diffMapsLockstep(oldValue, newValue, prefix, visit);
61
- return;
62
- }
63
- if (oldIsMap !== newIsMap) {
64
- visit({ kind: "changed", path: prefix, oldValue, newValue });
65
- return;
66
- }
67
- const oldIsArray = Array.isArray(oldValue);
68
- const newIsArray = Array.isArray(newValue);
69
- if (oldIsArray && newIsArray) {
70
- diffArraysLockstep(oldValue, newValue, prefix, visit);
71
- return;
72
- }
73
- if (!oldIsArray && !newIsArray) {
74
- diffObjectsLockstep(
75
- oldValue,
76
- newValue,
77
- prefix,
78
- visit
79
- );
80
- return;
81
- }
82
- visit({ kind: "changed", path: prefix, oldValue, newValue });
83
- return;
84
- }
85
- if (oldIsDescendable && !newIsDescendable) {
86
- visit({ kind: "changed", path: prefix, oldValue, newValue });
87
- return;
88
- }
89
- if (!oldIsDescendable && newIsDescendable) {
90
- visit({ kind: "changed", path: prefix, oldValue, newValue });
91
- return;
92
- }
93
- if (oldValue === void 0) {
94
- visit({ kind: "added", path: prefix, newValue });
95
- return;
96
- }
97
- if (newValue === void 0) {
98
- visit({ kind: "removed", path: prefix, oldValue });
99
- return;
100
- }
101
- visit({ kind: "changed", path: prefix, oldValue, newValue });
102
- }
103
- function walkDescendable(value, prefix, visit, arrived) {
104
- let reported = false;
105
- if (Array.isArray(value)) {
106
- for (let i = 0; i < value.length; i++) {
107
- diffSlot(readConsumerIndex(value, i), appendSegment(prefix, i), visit, arrived);
108
- }
109
- reported = value.length > 0;
110
- } else if (value instanceof Map) {
111
- for (const [key, entry] of value) {
112
- diffSlot(entry, appendSegment(prefix, key), visit, arrived);
113
- }
114
- reported = value.size > 0;
115
- } else {
116
- const rec = value;
117
- for (const k of consumerKeys(rec)) {
118
- const entry = readConsumerProp(rec, k);
119
- if (entry === void 0) continue;
120
- reported = true;
121
- if (arrived) diffAndApply(void 0, entry, appendSegment(prefix, k), visit);
122
- else diffAndApply(entry, void 0, appendSegment(prefix, k), visit);
123
- }
124
- }
125
- if (!reported) visit(presencePatch(arrived, prefix, value));
126
- }
127
- function diffSlot(entry, path, visit, arrived) {
128
- if (entry === void 0) visit(presencePatch(arrived, path, entry));
129
- else if (arrived) diffAndApply(void 0, entry, path, visit);
130
- else diffAndApply(entry, void 0, path, visit);
131
- }
132
- function presencePatch(arrived, path, value) {
133
- return arrived ? { kind: "added", path, newValue: value } : { kind: "removed", path, oldValue: value };
134
- }
135
- function diffMapsLockstep(oldMap, newMap, prefix, visit) {
136
- for (const [key, entry] of newMap) {
137
- const path = appendSegment(prefix, key);
138
- if (oldMap.has(key)) diffAndApply(oldMap.get(key), entry, path, visit);
139
- else diffSlot(entry, path, visit, true);
140
- }
141
- for (const [key, entry] of oldMap) {
142
- if (!newMap.has(key)) diffSlot(entry, appendSegment(prefix, key), visit, false);
143
- }
144
- }
145
- function diffArraysLockstep(oldArr, newArr, prefix, visit) {
146
- const min = Math.min(oldArr.length, newArr.length);
147
- for (let i = 0; i < min; i++) {
148
- diffAndApply(
149
- readConsumerIndex(oldArr, i),
150
- readConsumerIndex(newArr, i),
151
- appendSegment(prefix, i),
152
- visit
153
- );
154
- }
155
- for (let i = min; i < newArr.length; i++) {
156
- diffSlot(readConsumerIndex(newArr, i), appendSegment(prefix, i), visit, true);
157
- }
158
- for (let i = min; i < oldArr.length; i++) {
159
- diffSlot(readConsumerIndex(oldArr, i), appendSegment(prefix, i), visit, false);
160
- }
161
- }
162
- function diffObjectsLockstep(oldRec, newRec, prefix, visit) {
163
- const seen = /* @__PURE__ */ new Set();
164
- for (const k of consumerKeys(oldRec)) {
165
- seen.add(k);
166
- diffAndApply(
167
- readConsumerProp(oldRec, k),
168
- readConsumerProp(newRec, k),
169
- appendSegment(prefix, k),
170
- visit
171
- );
172
- }
173
- for (const k of consumerKeys(newRec)) {
174
- if (seen.has(k)) continue;
175
- diffAndApply(
176
- readConsumerProp(oldRec, k),
177
- readConsumerProp(newRec, k),
178
- appendSegment(prefix, k),
179
- visit
180
- );
181
- }
182
- }
183
- function applyChangedKeys(target, source, arrayOpPath, currentPath, patches) {
184
- if (!isDescendable(target) || !isDescendable(source)) return false;
185
- if (target instanceof Map || source instanceof Map) return false;
186
- const targetIsArray = Array.isArray(target);
187
- const sourceIsArray = Array.isArray(source);
188
- if (targetIsArray !== sourceIsArray) return false;
189
- const depth = currentPath.length;
190
- const changedFirstSegments = /* @__PURE__ */ new Set();
191
- for (const patch of patches) {
192
- if (patch.path.length === depth) return false;
193
- changedFirstSegments.add(patch.path[depth]);
194
- }
195
- if (targetIsArray) {
196
- const t = target;
197
- const s = source;
198
- if (arrayOpPath === null || pathsEqual(currentPath, arrayOpPath)) {
199
- if (t.length > s.length) t.length = s.length;
200
- for (const idx of changedFirstSegments) {
201
- const i = typeof idx === "number" ? idx : Number(idx);
202
- if (i >= s.length) continue;
203
- t[i] = s[i];
204
- }
205
- } else {
206
- for (const idx of changedFirstSegments) {
207
- const i = typeof idx === "number" ? idx : Number(idx);
208
- if (i >= s.length) continue;
209
- const childPath = appendSegment(currentPath, i);
210
- const curEl = t[i];
211
- const nextEl = s[i];
212
- if (isPathPrefix(childPath, arrayOpPath) && isDescendable(curEl) && isDescendable(nextEl) && applyChangedKeys(
213
- curEl,
214
- nextEl,
215
- arrayOpPath,
216
- childPath,
217
- patches.filter((p) => isPathPrefix(childPath, p.path))
218
- )) {
219
- continue;
220
- }
221
- t[i] = nextEl;
222
- }
223
- }
224
- } else {
225
- const t = target;
226
- const s = source;
227
- const sourceKeys = new Set(Object.keys(s));
228
- for (const k of Object.keys(t)) {
229
- if (!sourceKeys.has(k)) delete t[k];
230
- }
231
- for (const k of changedFirstSegments) {
232
- const key = String(k);
233
- const nextVal = safeOwnRead(s, key);
234
- if (arrayOpPath !== null) {
235
- const curVal = safeOwnRead(t, key);
236
- const childPath = appendSegment(currentPath, key);
237
- if (isDescendable(curVal) && isDescendable(nextVal) && applyChangedKeys(
238
- curVal,
239
- nextVal,
240
- arrayOpPath,
241
- childPath,
242
- patches.filter((p) => isPathPrefix(childPath, p.path))
243
- )) {
244
- continue;
245
- }
246
- }
247
- safeAssign(t, key, nextVal);
248
- }
249
- }
250
- return true;
251
- }
252
- function structuralSnapshot(value) {
253
- if (!isDescendable(value)) return value;
254
- if (value instanceof Map) {
255
- const out2 = /* @__PURE__ */ new Map();
256
- for (const [k, v] of value) out2.set(k, structuralSnapshot(v));
257
- return out2;
258
- }
259
- if (Array.isArray(value)) {
260
- const out2 = new Array(value.length);
261
- for (let i = 0; i < value.length; i++) {
262
- out2[i] = structuralSnapshot(value[i]);
263
- }
264
- return out2;
265
- }
266
- const src = value;
267
- const out = {};
268
- for (const k of Object.keys(src)) {
269
- safeAssign(out, k, structuralSnapshot(safeOwnRead(src, k)));
270
- }
271
- return out;
272
- }
273
-
274
- export { ANONYMOUS_FORM_KEY_PREFIX as A, DEFAULT_HISTORY_MAX_SNAPSHOTS as D, RESERVED_KEY_PREFIX as R, DEFAULT_FIELD_VALIDATION_DEBOUNCE_MS as a, isDescendable as b, applyChangedKeys as c, diffAndApply as d, DEFAULT_MAX_RECURSION_DEPTH as e, ANONYMOUS_WIZARD_KEY_PREFIX as f, isBarePatch as i, normalizeNumericOption as n, pickDefined as p, structuralSnapshot as s };