@mapples/form 1.2.0 → 1.2.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.
- package/dist/components/Form.d.ts +2 -1
- package/dist/components/Form.d.ts.map +1 -1
- package/dist/components/Form.js +3 -2
- package/dist/components/Form.js.map +1 -1
- package/dist/hooks/useFormFieldToggle.d.ts +2 -0
- package/dist/hooks/useFormFieldToggle.d.ts.map +1 -1
- package/dist/hooks/useFormFieldToggle.js +13 -7
- package/dist/hooks/useFormFieldToggle.js.map +1 -1
- package/dist/state/index.d.ts +37 -1
- package/dist/state/index.d.ts.map +1 -1
- package/dist/state/index.js +107 -28
- package/dist/state/index.js.map +1 -1
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ import { FormProps } from '../types';
|
|
|
13
13
|
* @param props.ref - Optional ref to access the FormState instance directly
|
|
14
14
|
* @param props.historyItems - Number of history states to keep for undo/redo (0 to disable)
|
|
15
15
|
* @param props.historyItemThrottle - Save a history entry every Nth change
|
|
16
|
+
* @param props.historyCoalesceMs - Coalesce write bursts into one history entry
|
|
16
17
|
* @param props.filterHistoryKeys - Field paths to exclude from history tracking
|
|
17
18
|
* @param props.onChange - Callback invoked whenever any form value changes
|
|
18
19
|
* @returns JSX element that provides form context to children
|
|
@@ -41,6 +42,6 @@ import { FormProps } from '../types';
|
|
|
41
42
|
*
|
|
42
43
|
* @public
|
|
43
44
|
*/
|
|
44
|
-
declare const Form: <T extends object>({ children, initialValues, validationSchema, onSubmit, ref, historyItems, filterHistoryKeys, historyItemThrottle, onChange, }: PropsWithChildren<FormProps<T>>) => import("react").JSX.Element;
|
|
45
|
+
declare const Form: <T extends object>({ children, initialValues, validationSchema, onSubmit, ref, historyItems, filterHistoryKeys, historyItemThrottle, historyCoalesceMs, onChange, }: PropsWithChildren<FormProps<T>>) => import("react").JSX.Element;
|
|
45
46
|
export default Form;
|
|
46
47
|
//# sourceMappingURL=Form.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../src/components/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAOf,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../src/components/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAOf,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,QAAA,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,EAAE,kJAW7B,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,gCAuGjC,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
package/dist/components/Form.js
CHANGED
|
@@ -15,6 +15,7 @@ import FormState from '../state';
|
|
|
15
15
|
* @param props.ref - Optional ref to access the FormState instance directly
|
|
16
16
|
* @param props.historyItems - Number of history states to keep for undo/redo (0 to disable)
|
|
17
17
|
* @param props.historyItemThrottle - Save a history entry every Nth change
|
|
18
|
+
* @param props.historyCoalesceMs - Coalesce write bursts into one history entry
|
|
18
19
|
* @param props.filterHistoryKeys - Field paths to exclude from history tracking
|
|
19
20
|
* @param props.onChange - Callback invoked whenever any form value changes
|
|
20
21
|
* @returns JSX element that provides form context to children
|
|
@@ -43,7 +44,7 @@ import FormState from '../state';
|
|
|
43
44
|
*
|
|
44
45
|
* @public
|
|
45
46
|
*/
|
|
46
|
-
const Form = ({ children, initialValues, validationSchema, onSubmit, ref, historyItems, filterHistoryKeys, historyItemThrottle, onChange, }) => {
|
|
47
|
+
const Form = ({ children, initialValues, validationSchema, onSubmit, ref, historyItems, filterHistoryKeys, historyItemThrottle, historyCoalesceMs, onChange, }) => {
|
|
47
48
|
const [touched, setTouched] = useState({});
|
|
48
49
|
const [submitting, setSubmitting] = useState(false);
|
|
49
50
|
const [validationErrors, setValidationErrors] = useState(null);
|
|
@@ -52,7 +53,7 @@ const Form = ({ children, initialValues, validationSchema, onSubmit, ref, histor
|
|
|
52
53
|
// when initialValues/schema change identity (e.g. inline object literals on
|
|
53
54
|
// every parent render), which would otherwise wipe edited values back to the
|
|
54
55
|
// initial state. We never call the setter, so this never triggers a re-render.
|
|
55
|
-
const [form] = useState(() => new FormState(initialValues, validationSchema, historyItems, historyItemThrottle, filterHistoryKeys));
|
|
56
|
+
const [form] = useState(() => new FormState(initialValues, validationSchema, historyItems, historyItemThrottle, filterHistoryKeys, historyCoalesceMs));
|
|
56
57
|
useEffect(() => {
|
|
57
58
|
if (!onChange)
|
|
58
59
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.js","sourceRoot":"","sources":["../../src/components/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,QAAQ,GACT,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,SAAS,MAAM,UAAU,CAAC;AAGjC
|
|
1
|
+
{"version":3,"file":"Form.js","sourceRoot":"","sources":["../../src/components/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,QAAQ,GACT,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,SAAS,MAAM,UAAU,CAAC;AAGjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAA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,CACL,CAAC,mBAAmB,CAClB,KAAK,CAAC,CAAC;YACL,OAAO;YACP,IAAI,EAAE,IAAyB;YAC/B,UAAU,EAAE,YAAY;YACxB,UAAU;YACV,gBAAgB;YAChB,QAAQ;YACR,KAAK;SACN,CAAC,CAEF;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,mBAAmB,CAAC,CACvB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hook to manage boolean toggle fields.
|
|
3
3
|
* This hook provides a simple way to handle boolean fields with toggle functionality.
|
|
4
|
+
* The value follows the stored field (an existing `true` renders as on), not
|
|
5
|
+
* only the toggles made through this hook.
|
|
4
6
|
*
|
|
5
7
|
* @param fieldPath - Dot notation path to the boolean field
|
|
6
8
|
* @returns Object containing current value and toggle function
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormFieldToggle.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormFieldToggle.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"useFormFieldToggle.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormFieldToggle.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,QAAA,MAAM,kBAAkB,GAAI,WAAW,MAAM;;;CA4B5C,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
2
|
import useForm from './useForm';
|
|
3
3
|
/**
|
|
4
4
|
* Hook to manage boolean toggle fields.
|
|
5
5
|
* This hook provides a simple way to handle boolean fields with toggle functionality.
|
|
6
|
+
* The value follows the stored field (an existing `true` renders as on), not
|
|
7
|
+
* only the toggles made through this hook.
|
|
6
8
|
*
|
|
7
9
|
* @param fieldPath - Dot notation path to the boolean field
|
|
8
10
|
* @returns Object containing current value and toggle function
|
|
@@ -29,13 +31,17 @@ import useForm from './useForm';
|
|
|
29
31
|
*/
|
|
30
32
|
const useFormFieldToggle = (fieldPath) => {
|
|
31
33
|
const { form } = useForm();
|
|
32
|
-
const [value, setValue] = useState(
|
|
34
|
+
const [value, setValue] = useState(() => !!form?.getValue(fieldPath));
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const unsubscribe = form?.subscribeOnChange((next) => setValue(!!next), fieldPath);
|
|
37
|
+
return () => {
|
|
38
|
+
unsubscribe?.();
|
|
39
|
+
};
|
|
40
|
+
}, [fieldPath, form]);
|
|
33
41
|
const handleToggleValue = () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return nextValue;
|
|
38
|
-
});
|
|
42
|
+
const nextValue = !value;
|
|
43
|
+
setValue(nextValue);
|
|
44
|
+
form?.setValue(fieldPath, nextValue);
|
|
39
45
|
};
|
|
40
46
|
return {
|
|
41
47
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormFieldToggle.js","sourceRoot":"","sources":["../../src/hooks/useFormFieldToggle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useFormFieldToggle.js","sourceRoot":"","sources":["../../src/hooks/useFormFieldToggle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,kBAAkB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC/C,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC;IAE3B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAChC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAsB,SAAS,CAAC,CACvD,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,WAAW,GAAG,IAAI,EAAE,iBAAiB,CACzC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,EAC1B,SAAS,CACV,CAAC;QAEF,OAAO,GAAG,EAAE;YACV,WAAW,EAAE,EAAE,CAAC;QAClB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IAEtB,MAAM,iBAAiB,GAAG,GAAG,EAAE;QAC7B,MAAM,SAAS,GAAG,CAAC,KAAK,CAAC;QACzB,QAAQ,CAAC,SAAS,CAAC,CAAC;QACpB,IAAI,EAAE,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO;QACL,KAAK;QACL,WAAW,EAAE,iBAAiB;KAC/B,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
package/dist/state/index.d.ts
CHANGED
|
@@ -20,6 +20,10 @@ declare class FormState<T extends object> {
|
|
|
20
20
|
private readonly historyItemThrottle;
|
|
21
21
|
private saveCounter;
|
|
22
22
|
private readonly filterHistoryKeys;
|
|
23
|
+
private readonly historyCoalesceMs;
|
|
24
|
+
private lastHistoryWriteAt;
|
|
25
|
+
private historyDirty;
|
|
26
|
+
private listenerSeq;
|
|
23
27
|
/**
|
|
24
28
|
* Creates a new FormState instance.
|
|
25
29
|
*
|
|
@@ -28,8 +32,11 @@ declare class FormState<T extends object> {
|
|
|
28
32
|
* @param historyItems - Number of history items to keep for undo/redo (0 to disable)
|
|
29
33
|
* @param historyItemThrottle - Throttle for saving history items (every Nth change)
|
|
30
34
|
* @param filterHistoryKeys - Array of field paths to exclude from history tracking
|
|
35
|
+
* @param historyCoalesceMs - Coalesce writes closer together than this into
|
|
36
|
+
* one history entry (a typing or drag burst becomes a single undo step).
|
|
37
|
+
* 0 keeps the counter-throttle behavior.
|
|
31
38
|
*/
|
|
32
|
-
constructor(initialValues: T, validationSchema?: ObjectSchema<T>, historyItems?: number, historyItemThrottle?: number, filterHistoryKeys?: string[]);
|
|
39
|
+
constructor(initialValues: T, validationSchema?: ObjectSchema<T>, historyItems?: number, historyItemThrottle?: number, filterHistoryKeys?: string[], historyCoalesceMs?: number);
|
|
33
40
|
/**
|
|
34
41
|
* Gets a deep copy of all form values.
|
|
35
42
|
*
|
|
@@ -63,6 +70,14 @@ declare class FormState<T extends object> {
|
|
|
63
70
|
* @param value - The value to set at the specified path
|
|
64
71
|
*/
|
|
65
72
|
setValue<V>(path: string, value?: V): void;
|
|
73
|
+
/**
|
|
74
|
+
* Whether a write to `writePath` affects a subscriber at `subscriptionPath`.
|
|
75
|
+
* Segment-aware in both directions: a write below the subscription changes
|
|
76
|
+
* the subscribed value's contents; a write at or above it replaces the
|
|
77
|
+
* subscribed value outright. Root subscribers (no path) see every write.
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
private pathsIntersect;
|
|
66
81
|
/**
|
|
67
82
|
* Subscribes to form value changes.
|
|
68
83
|
*
|
|
@@ -93,7 +108,16 @@ declare class FormState<T extends object> {
|
|
|
93
108
|
* @throws Throws validation errors if validation fails
|
|
94
109
|
*/
|
|
95
110
|
validate(): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Commits the end state of a coalescing burst that has gone quiet. MUST run
|
|
113
|
+
* before the next mutation lands in `this.values` — afterwards the burst's
|
|
114
|
+
* true end state is gone. Called at the top of `setValue`/`setValues`, and
|
|
115
|
+
* from `prev()` so an undo taken mid-burst leaves the burst redoable.
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
private finalizeStaleHistoryBurst;
|
|
96
119
|
private saveToHistory;
|
|
120
|
+
private pushHistoryEntry;
|
|
97
121
|
/**
|
|
98
122
|
* Moves to the previous state in the form history (undo operation).
|
|
99
123
|
*
|
|
@@ -118,6 +142,18 @@ declare class FormState<T extends object> {
|
|
|
118
142
|
* @returns True if redo operation is possible
|
|
119
143
|
*/
|
|
120
144
|
canNext(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Delivers the current values to subscribers — all of them, or only those
|
|
147
|
+
* whose path intersects `changedPath` when one is given.
|
|
148
|
+
*
|
|
149
|
+
* Cost discipline: the editor holds hundreds of subscriptions on one large
|
|
150
|
+
* document, and this runs on every write. Pathed subscribers get a clone of
|
|
151
|
+
* just their subtree; root subscribers share ONE lazily-created full clone
|
|
152
|
+
* per pass. Subscribers must therefore treat delivered values as read-only.
|
|
153
|
+
* Fresh clones (not `this.values` references) are still required so React
|
|
154
|
+
* state setters see a new identity per delivery.
|
|
155
|
+
* @private
|
|
156
|
+
*/
|
|
121
157
|
private notifySubscriptions;
|
|
122
158
|
private notifyHistorySubscriptions;
|
|
123
159
|
private remapValidationError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAEpD,OAAO,KAAK,EAEV,oBAAoB,EAErB,MAAM,UAAU,CAAC;AAElB;;;;;;;GAOG;AACH,cAAM,SAAS,CAAC,CAAC,SAAS,MAAM;IAC9B,OAAO,CAAC,MAAM,CAAI;IAElB,OAAO,CAAC,gBAAgB,CAAC,CAAkB;IAC3C,OAAO,CAAC,aAAa,CAA6C;IAClE,OAAO,CAAC,wBAAwB,CAAsC;IACtE,OAAO,CAAC,MAAM,CAAkD;IAEhE,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAW;
|
|
1
|
+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KAAK,IAAI;IAQpD;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;IA2BnC;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IAQtB;;;;;;;OAOG;IACH,iBAAiB,CAAC,CAAC,EAAE,EAAE,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM;IAa/D;;;;;OAKG;IACH,wBAAwB,CAAC,EAAE,EAAE,MAAM,IAAI;IAQvC;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC;IAI7B;;;;OAIG;IACG,QAAQ;IAYd;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IAQjC,OAAO,CAAC,aAAa;IAuCrB,OAAO,CAAC,gBAAgB;IAaxB;;;;OAIG;IACH,IAAI;IAgBJ;;;;OAIG;IACH,IAAI;IASJ;;;;OAIG;IACH,OAAO;IAIP;;;;OAIG;IACH,OAAO;IAIP;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,mBAAmB;IAyB3B,OAAO,CAAC,0BAA0B;IAMlC,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,0BAA0B;IAIlC,OAAO,CAAC,kBAAkB;CAK3B;AAED,eAAe,SAAS,CAAC"}
|
package/dist/state/index.js
CHANGED
|
@@ -19,6 +19,10 @@ class FormState {
|
|
|
19
19
|
historyItemThrottle;
|
|
20
20
|
saveCounter = 0;
|
|
21
21
|
filterHistoryKeys;
|
|
22
|
+
historyCoalesceMs;
|
|
23
|
+
lastHistoryWriteAt = 0;
|
|
24
|
+
historyDirty = false;
|
|
25
|
+
listenerSeq = 0;
|
|
22
26
|
/**
|
|
23
27
|
* Creates a new FormState instance.
|
|
24
28
|
*
|
|
@@ -27,13 +31,17 @@ class FormState {
|
|
|
27
31
|
* @param historyItems - Number of history items to keep for undo/redo (0 to disable)
|
|
28
32
|
* @param historyItemThrottle - Throttle for saving history items (every Nth change)
|
|
29
33
|
* @param filterHistoryKeys - Array of field paths to exclude from history tracking
|
|
34
|
+
* @param historyCoalesceMs - Coalesce writes closer together than this into
|
|
35
|
+
* one history entry (a typing or drag burst becomes a single undo step).
|
|
36
|
+
* 0 keeps the counter-throttle behavior.
|
|
30
37
|
*/
|
|
31
|
-
constructor(initialValues, validationSchema, historyItems = 0, historyItemThrottle = 5, filterHistoryKeys = []) {
|
|
38
|
+
constructor(initialValues, validationSchema, historyItems = 0, historyItemThrottle = 5, filterHistoryKeys = [], historyCoalesceMs = 0) {
|
|
32
39
|
this.values = cloneDeep(initialValues);
|
|
33
40
|
this.validationSchema = validationSchema;
|
|
34
41
|
this.historyItems = historyItems;
|
|
35
42
|
this.historyItemThrottle = historyItemThrottle;
|
|
36
43
|
this.filterHistoryKeys = filterHistoryKeys;
|
|
44
|
+
this.historyCoalesceMs = historyCoalesceMs;
|
|
37
45
|
if (this.historyItems > 0) {
|
|
38
46
|
this.history = [cloneDeep(initialValues)];
|
|
39
47
|
this.historyIndex = 0;
|
|
@@ -70,13 +78,10 @@ class FormState {
|
|
|
70
78
|
* @param cb - Optional callback invoked with `true` after the values and subscriptions have been updated
|
|
71
79
|
*/
|
|
72
80
|
setValues(values, cb) {
|
|
81
|
+
this.finalizeStaleHistoryBurst();
|
|
73
82
|
this.values = cloneDeep(values);
|
|
74
83
|
this.saveToHistory();
|
|
75
|
-
this.
|
|
76
|
-
subscription.cb(subscription.path
|
|
77
|
-
? get(this.getValues(), subscription.path)
|
|
78
|
-
: this.getValues());
|
|
79
|
-
});
|
|
84
|
+
this.notifySubscriptions();
|
|
80
85
|
cb?.(true);
|
|
81
86
|
}
|
|
82
87
|
/**
|
|
@@ -97,20 +102,32 @@ class FormState {
|
|
|
97
102
|
if (value === undefined && !has(this.values, path)) {
|
|
98
103
|
return;
|
|
99
104
|
}
|
|
105
|
+
this.finalizeStaleHistoryBurst();
|
|
100
106
|
set(this.values, path, value);
|
|
101
107
|
if (!some(this.filterHistoryKeys, (value) => {
|
|
102
108
|
return path.includes(value);
|
|
103
109
|
})) {
|
|
104
110
|
this.saveToHistory();
|
|
105
111
|
}
|
|
106
|
-
this.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
this.notifySubscriptions(path);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Whether a write to `writePath` affects a subscriber at `subscriptionPath`.
|
|
116
|
+
* Segment-aware in both directions: a write below the subscription changes
|
|
117
|
+
* the subscribed value's contents; a write at or above it replaces the
|
|
118
|
+
* subscribed value outright. Root subscribers (no path) see every write.
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
pathsIntersect(writePath, subscriptionPath) {
|
|
122
|
+
if (!subscriptionPath)
|
|
123
|
+
return true;
|
|
124
|
+
if (writePath === subscriptionPath)
|
|
125
|
+
return true;
|
|
126
|
+
if (writePath.startsWith(subscriptionPath + '.'))
|
|
127
|
+
return true;
|
|
128
|
+
if (subscriptionPath.startsWith(writePath + '.'))
|
|
129
|
+
return true;
|
|
130
|
+
return false;
|
|
114
131
|
}
|
|
115
132
|
/**
|
|
116
133
|
* Subscribes to form value changes.
|
|
@@ -148,7 +165,7 @@ class FormState {
|
|
|
148
165
|
* @returns The value at the specified path or all form values
|
|
149
166
|
*/
|
|
150
167
|
getValue(path) {
|
|
151
|
-
return cloneDeep(path ? get(this.
|
|
168
|
+
return cloneDeep(path ? get(this.values, path) : this.values);
|
|
152
169
|
}
|
|
153
170
|
/**
|
|
154
171
|
* Validates the form using the provided validation schema.
|
|
@@ -167,9 +184,40 @@ class FormState {
|
|
|
167
184
|
throw errors;
|
|
168
185
|
}
|
|
169
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Commits the end state of a coalescing burst that has gone quiet. MUST run
|
|
189
|
+
* before the next mutation lands in `this.values` — afterwards the burst's
|
|
190
|
+
* true end state is gone. Called at the top of `setValue`/`setValues`, and
|
|
191
|
+
* from `prev()` so an undo taken mid-burst leaves the burst redoable.
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
finalizeStaleHistoryBurst() {
|
|
195
|
+
if (!this.historyDirty)
|
|
196
|
+
return;
|
|
197
|
+
if (Date.now() - this.lastHistoryWriteAt <= this.historyCoalesceMs)
|
|
198
|
+
return;
|
|
199
|
+
this.history[this.historyIndex] = cloneDeep(this.values);
|
|
200
|
+
this.historyDirty = false;
|
|
201
|
+
}
|
|
170
202
|
saveToHistory() {
|
|
171
203
|
if (this.historyItems === 0)
|
|
172
204
|
return;
|
|
205
|
+
if (this.historyCoalesceMs > 0) {
|
|
206
|
+
this.lastHistoryWriteAt = Date.now();
|
|
207
|
+
// `finalizeStaleHistoryBurst` ran before this write landed, so a
|
|
208
|
+
// still-dirty entry means this write continues the current burst: its
|
|
209
|
+
// end state is captured when the burst finalizes. No clone, no compare.
|
|
210
|
+
if (this.historyDirty)
|
|
211
|
+
return;
|
|
212
|
+
const currentValues = cloneDeep(this.values);
|
|
213
|
+
if (this.history.length > 0 &&
|
|
214
|
+
isEqual(this.history[this.historyIndex], currentValues)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
this.pushHistoryEntry(currentValues);
|
|
218
|
+
this.historyDirty = true;
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
173
221
|
this.saveCounter++;
|
|
174
222
|
if (this.saveCounter % this.historyItemThrottle !== 0)
|
|
175
223
|
return;
|
|
@@ -178,17 +226,17 @@ class FormState {
|
|
|
178
226
|
if (this.history.length > 0 && diff) {
|
|
179
227
|
return;
|
|
180
228
|
}
|
|
229
|
+
this.pushHistoryEntry(currentValues);
|
|
230
|
+
}
|
|
231
|
+
pushHistoryEntry(currentValues) {
|
|
181
232
|
if (this.historyIndex < this.history.length - 1) {
|
|
182
233
|
this.history = this.history.slice(0, this.historyIndex + 1);
|
|
183
234
|
}
|
|
184
235
|
this.history.push(currentValues);
|
|
185
236
|
if (this.history.length > this.historyItems) {
|
|
186
237
|
this.history = this.history.slice(-this.historyItems);
|
|
187
|
-
this.historyIndex = this.history.length - 1;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
this.historyIndex = this.history.length - 1;
|
|
191
238
|
}
|
|
239
|
+
this.historyIndex = this.history.length - 1;
|
|
192
240
|
}
|
|
193
241
|
/**
|
|
194
242
|
* Moves to the previous state in the form history (undo operation).
|
|
@@ -196,6 +244,12 @@ class FormState {
|
|
|
196
244
|
* @returns True if the operation was successful, false if no previous state exists
|
|
197
245
|
*/
|
|
198
246
|
prev() {
|
|
247
|
+
// An undo mid-burst first commits the burst's end state, so a redo can
|
|
248
|
+
// return to what the user actually last saw.
|
|
249
|
+
if (this.historyDirty) {
|
|
250
|
+
this.history[this.historyIndex] = cloneDeep(this.values);
|
|
251
|
+
this.historyDirty = false;
|
|
252
|
+
}
|
|
199
253
|
if (!this.canPrev())
|
|
200
254
|
return false;
|
|
201
255
|
this.historyIndex--;
|
|
@@ -234,12 +288,37 @@ class FormState {
|
|
|
234
288
|
canNext() {
|
|
235
289
|
return this.historyItems > 0 && this.historyIndex < this.history.length - 1;
|
|
236
290
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Delivers the current values to subscribers — all of them, or only those
|
|
293
|
+
* whose path intersects `changedPath` when one is given.
|
|
294
|
+
*
|
|
295
|
+
* Cost discipline: the editor holds hundreds of subscriptions on one large
|
|
296
|
+
* document, and this runs on every write. Pathed subscribers get a clone of
|
|
297
|
+
* just their subtree; root subscribers share ONE lazily-created full clone
|
|
298
|
+
* per pass. Subscribers must therefore treat delivered values as read-only.
|
|
299
|
+
* Fresh clones (not `this.values` references) are still required so React
|
|
300
|
+
* state setters see a new identity per delivery.
|
|
301
|
+
* @private
|
|
302
|
+
*/
|
|
303
|
+
notifySubscriptions(changedPath) {
|
|
304
|
+
// Snapshot: callbacks may (un)subscribe or write back into the form
|
|
305
|
+
// mid-pass; iterating the live map would tangle delivery with those
|
|
306
|
+
// mutations.
|
|
307
|
+
const subscribers = Array.from(this.subscriptions.values());
|
|
308
|
+
let fullClone;
|
|
309
|
+
for (const subscription of subscribers) {
|
|
310
|
+
if (changedPath !== undefined &&
|
|
311
|
+
!this.pathsIntersect(changedPath, subscription.path)) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (subscription.path) {
|
|
315
|
+
subscription.cb(cloneDeep(get(this.values, subscription.path)));
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
fullClone ??= cloneDeep(this.values);
|
|
319
|
+
subscription.cb(fullClone);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
243
322
|
}
|
|
244
323
|
notifyHistorySubscriptions() {
|
|
245
324
|
this.formHistorySubscriptions.forEach((callback) => {
|
|
@@ -256,9 +335,9 @@ class FormState {
|
|
|
256
335
|
return () => this.formHistorySubscriptions.delete(id);
|
|
257
336
|
}
|
|
258
337
|
generateListenerId() {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return
|
|
338
|
+
// Monotonic — timestamp+random ids could collide, silently replacing a
|
|
339
|
+
// live subscription in the Map and orphaning its callback.
|
|
340
|
+
return `listener-${++this.listenerSeq}`;
|
|
262
341
|
}
|
|
263
342
|
}
|
|
264
343
|
export default FormState;
|
package/dist/state/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAS1E;;;;;;;GAOG;AACH,MAAM,SAAS;IACL,MAAM,CAAI;IAEV,gBAAgB,CAAmB;IACnC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AAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAEO,0BAA0B,CAAC,EAAU;QAC3C,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACxD,CAAC;IAEO,kBAAkB;QACxB,uEAAuE;QACvE,2DAA2D;QAC3D,OAAO,YAAY,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;IAC1C,CAAC;CACF;AAED,eAAe,SAAS,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -67,6 +67,12 @@ export interface FormProps<T extends object> {
|
|
|
67
67
|
historyItems?: number;
|
|
68
68
|
/** Throttle for saving history items (every Nth change) */
|
|
69
69
|
historyItemThrottle?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Coalesce writes closer together than this into one history entry, so a
|
|
72
|
+
* typing or drag burst becomes a single undo step. 0 (default) keeps the
|
|
73
|
+
* counter-throttle behavior.
|
|
74
|
+
*/
|
|
75
|
+
historyCoalesceMs?: number;
|
|
70
76
|
/** Array of field paths to exclude from history tracking */
|
|
71
77
|
filterHistoryKeys?: string[];
|
|
72
78
|
/** Callback function called whenever form values change */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAEpD,OAAO,SAAS,MAAM,UAAU,CAAC;AAEjC;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAEzD;;;;GAIG;AACH,MAAM,WAAW,iBAAiB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