@homebound/form-state 2.25.0 → 2.25.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/FormStateApp.js +2 -3
- package/dist/configBuilders.d.ts +4 -4
- package/dist/fields/deepEquals.d.ts +7 -0
- package/dist/fields/deepEquals.js +41 -0
- package/dist/fields/fragmentField.js +1 -2
- package/dist/fields/listField.js +1 -2
- package/dist/fields/objectField.js +3 -4
- package/dist/fields/valueField.js +1 -2
- package/dist/formState.stories.d.ts +2 -1
- package/dist/formState.stories.js +1 -2
- package/dist/formState.test.js +16 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -2
- package/dist/proxies.js +1 -2
- package/dist/useFormState.js +1 -2
- package/dist/useFormStates.js +1 -2
- package/dist/utils.js +15 -19
- package/package.json +34 -39
package/dist/FormStateApp.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FormStateApp = FormStateApp;
|
|
4
|
+
exports.TextField = TextField;
|
|
4
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
6
|
const mobx_react_1 = require("mobx-react");
|
|
6
7
|
const index_1 = require("./index");
|
|
@@ -33,7 +34,6 @@ function FormStateApp() {
|
|
|
33
34
|
})] }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("strong", { children: "Rows" }), (0, jsx_runtime_1.jsxs)("table", { cellPadding: "4px", children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("th", { children: "touched" }), (0, jsx_runtime_1.jsx)("th", { children: "valid" }), (0, jsx_runtime_1.jsx)("th", { children: "dirty" }), (0, jsx_runtime_1.jsx)("th", { children: "errors" })] }) }), (0, jsx_runtime_1.jsx)("tbody", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("td", { children: formState.books.touched.toString() }), (0, jsx_runtime_1.jsx)("td", { children: formState.books.valid.toString() }), (0, jsx_runtime_1.jsx)("td", { children: formState.books.dirty.toString() }), (0, jsx_runtime_1.jsx)("td", { children: formState.books.errors })] }) })] })] }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("strong", { children: "Form" }), (0, jsx_runtime_1.jsxs)("table", { cellPadding: "4px", children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("th", { children: "touched" }), (0, jsx_runtime_1.jsx)("th", { children: "valid" }), (0, jsx_runtime_1.jsx)("th", { children: "dirty" })] }) }), (0, jsx_runtime_1.jsx)("tbody", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("td", { children: formState.touched.toString() }), (0, jsx_runtime_1.jsx)("td", { children: formState.valid.toString() }), (0, jsx_runtime_1.jsx)("td", { children: formState.dirty.toString() })] }) })] }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("button", { "data-testid": "touch", onClick: () => (formState.touched = !formState.touched), children: "touch" }), (0, jsx_runtime_1.jsx)("button", { "data-testid": "revertChanges", onClick: () => formState.revertChanges(), children: "revert" }), (0, jsx_runtime_1.jsx)("button", { "data-testid": "commitChanges", onClick: () => formState.commitChanges(), children: "commit" }), (0, jsx_runtime_1.jsx)("button", { "data-testid": "set", onClick: () => formState.set({ firstName: "a2" }), children: "set" })] })] })] }) }));
|
|
34
35
|
} }));
|
|
35
36
|
}
|
|
36
|
-
exports.FormStateApp = FormStateApp;
|
|
37
37
|
// Configure the fields/behavior for AuthorInput's fields
|
|
38
38
|
const formConfig = index_1.f.config({
|
|
39
39
|
firstName: index_1.f.value().req(),
|
|
@@ -52,4 +52,3 @@ function TextField(props) {
|
|
|
52
52
|
field.set(e.target.value);
|
|
53
53
|
} }) }), (0, jsx_runtime_1.jsxs)("table", { cellPadding: "4px", children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("th", { children: "touched" }), (0, jsx_runtime_1.jsx)("th", { children: "valid" }), (0, jsx_runtime_1.jsx)("th", { children: "dirty" }), (0, jsx_runtime_1.jsx)("th", { children: "readOnly" }), (0, jsx_runtime_1.jsx)("th", { children: "errors" }), (0, jsx_runtime_1.jsx)("th", { children: "original value" })] }) }), (0, jsx_runtime_1.jsx)("tbody", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("td", { "data-testid": `${field.key}_touched`, children: field.touched.toString() }), (0, jsx_runtime_1.jsx)("td", { "data-testid": `${field.key}_valid`, children: field.valid.toString() }), (0, jsx_runtime_1.jsx)("td", { "data-testid": `${field.key}_dirty`, children: field.dirty.toString() }), (0, jsx_runtime_1.jsx)("td", { "data-testid": `${field.key}_readOnly`, children: field.readOnly.toString() }), (0, jsx_runtime_1.jsx)("td", { "data-testid": `${field.key}_errors`, children: field.errors }), (0, jsx_runtime_1.jsx)("td", { "data-testid": `${field.key}_original`, children: field.originalValue })] }) })] })] })) }));
|
|
54
54
|
}
|
|
55
|
-
exports.TextField = TextField;
|
package/dist/configBuilders.d.ts
CHANGED
|
@@ -9,17 +9,17 @@ export declare const f: {
|
|
|
9
9
|
/** Creates the top-level config for a form, like an author or book. */
|
|
10
10
|
config<T>(fields: ObjectConfigBuilderFields<T>): ObjectConfig<T>;
|
|
11
11
|
/** Creates the config DSL for an object, like an author or book. */
|
|
12
|
-
object<
|
|
12
|
+
object<T>(fields: ObjectConfigBuilderFields<T>): ObjectConfigBuilder<T>;
|
|
13
13
|
/** Creates the config DSL for an list of objects, like an author's list of books. */
|
|
14
14
|
list<U>(fields: ObjectConfigBuilderFields<U>): ListFieldConfigBuilder<U>;
|
|
15
15
|
/** Creates the config DSL for a primitive value, like a first name or phone number. */
|
|
16
16
|
value<V>(): ValueFieldConfigBuilder<V>;
|
|
17
17
|
/** A shortcut for creating a child object with a single `id` key. */
|
|
18
|
-
reference<
|
|
18
|
+
reference<V extends {
|
|
19
19
|
id?: unknown;
|
|
20
|
-
}>(fields?: ObjectConfigBuilderFields<
|
|
20
|
+
}>(fields?: ObjectConfigBuilderFields<V>): ObjectConfigBuilder<V>;
|
|
21
21
|
/** A shorthand for creating a computed value. */
|
|
22
|
-
computed<
|
|
22
|
+
computed<V>(): ValueFieldConfigBuilder<V>;
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Defines the fields that should be passed into `f.object({ ... })` for fhe form type `T`.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Our own `deepEquals` because either `fast-deep-equals` or `dequal` or etc actually
|
|
3
|
+
* handle cyclic data structures, despite ChatGTP's assertions/hallucinations.
|
|
4
|
+
*
|
|
5
|
+
* Ported from https://github.com/KoryNunn/cyclic-deep-equal which is ISC.
|
|
6
|
+
*/
|
|
7
|
+
export declare function deepEquals(a: any, b: any, visited?: Set<any>): boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepEquals = deepEquals;
|
|
4
|
+
/**
|
|
5
|
+
* Our own `deepEquals` because either `fast-deep-equals` or `dequal` or etc actually
|
|
6
|
+
* handle cyclic data structures, despite ChatGTP's assertions/hallucinations.
|
|
7
|
+
*
|
|
8
|
+
* Ported from https://github.com/KoryNunn/cyclic-deep-equal which is ISC.
|
|
9
|
+
*/
|
|
10
|
+
function deepEquals(a, b, visited = new Set()) {
|
|
11
|
+
const aType = typeof a;
|
|
12
|
+
if (aType !== typeof b)
|
|
13
|
+
return false;
|
|
14
|
+
if (a == null || b == null || !(aType === "object" || aType === "function")) {
|
|
15
|
+
if (aType === "number" && isNaN(a) && isNaN(b))
|
|
16
|
+
return true;
|
|
17
|
+
return a === b;
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
20
|
+
return false;
|
|
21
|
+
const aKeys = Object.keys(a), bKeys = Object.keys(b);
|
|
22
|
+
if (aKeys.length !== bKeys.length)
|
|
23
|
+
return false;
|
|
24
|
+
let equal = true;
|
|
25
|
+
for (const key of aKeys) {
|
|
26
|
+
if (!(key in b)) {
|
|
27
|
+
equal = false;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
if (a[key] && a[key] instanceof Object) {
|
|
31
|
+
if (visited.has(a[key]))
|
|
32
|
+
break;
|
|
33
|
+
visited.add(a[key]);
|
|
34
|
+
}
|
|
35
|
+
if (!deepEquals(a[key], b[key], visited)) {
|
|
36
|
+
equal = false;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return equal;
|
|
41
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.newFragmentField =
|
|
3
|
+
exports.newFragmentField = newFragmentField;
|
|
4
4
|
const mobx_1 = require("mobx");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
function newFragmentField(parentInstance, key) {
|
|
@@ -23,4 +23,3 @@ function newFragmentField(parentInstance, key) {
|
|
|
23
23
|
};
|
|
24
24
|
return (0, mobx_1.makeAutoObservable)(obj, { value: false });
|
|
25
25
|
}
|
|
26
|
-
exports.newFragmentField = newFragmentField;
|
package/dist/fields/listField.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.newListFieldState =
|
|
3
|
+
exports.newListFieldState = newListFieldState;
|
|
4
4
|
const mobx_1 = require("mobx");
|
|
5
5
|
const objectField_1 = require("./objectField");
|
|
6
6
|
const rules_1 = require("../rules");
|
|
@@ -245,4 +245,3 @@ function newListFieldState(parentCopy, parentInstance, parentState, key, rules,
|
|
|
245
245
|
(0, mobx_1.reaction)(() => proxy.rows.map((r) => r.value), () => _childTick.value++);
|
|
246
246
|
return proxy;
|
|
247
247
|
}
|
|
248
|
-
exports.newListFieldState = newListFieldState;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.fragment = fragment;
|
|
4
|
+
exports.createObjectState = createObjectState;
|
|
5
|
+
exports.newObjectState = newObjectState;
|
|
4
6
|
const mobx_1 = require("mobx");
|
|
5
7
|
const fragmentField_1 = require("./fragmentField");
|
|
6
8
|
const listField_1 = require("./listField");
|
|
@@ -10,7 +12,6 @@ const fragmentSym = Symbol("fragment");
|
|
|
10
12
|
function fragment(value) {
|
|
11
13
|
return value;
|
|
12
14
|
}
|
|
13
|
-
exports.fragment = fragment;
|
|
14
15
|
/**
|
|
15
16
|
* Creates a new `ObjectState` for a given form object `T` given config rules in `config`.
|
|
16
17
|
*
|
|
@@ -22,7 +23,6 @@ function createObjectState(config, instance, opts = {}) {
|
|
|
22
23
|
const noop = () => { };
|
|
23
24
|
return newObjectState({ type: "object", config }, undefined, undefined, undefined, instance, undefined, opts.maybeAutoSave || noop);
|
|
24
25
|
}
|
|
25
|
-
exports.createObjectState = createObjectState;
|
|
26
26
|
/** A more internal version of `createObjectState`. */
|
|
27
27
|
function newObjectState(config, parentState, parentInstance, parentListState, instance, key, maybeAutoSave) {
|
|
28
28
|
// This is what we return, but we only know it's value until we call `observable`, so
|
|
@@ -247,4 +247,3 @@ function newObjectState(config, parentState, parentInstance, parentListState, in
|
|
|
247
247
|
(0, mobx_1.reaction)(() => getFields(proxy).map((f) => f.value), () => _tick.value++);
|
|
248
248
|
return proxy;
|
|
249
249
|
}
|
|
250
|
-
exports.newObjectState = newObjectState;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.newValueFieldState =
|
|
3
|
+
exports.newValueFieldState = newValueFieldState;
|
|
4
4
|
const is_plain_object_1 = require("is-plain-object");
|
|
5
5
|
const mobx_1 = require("mobx");
|
|
6
6
|
const proxies_1 = require("../proxies");
|
|
@@ -183,7 +183,6 @@ function newValueFieldState(parentCopy, parentInstance, parentState, key, rules,
|
|
|
183
183
|
}
|
|
184
184
|
return field;
|
|
185
185
|
}
|
|
186
|
-
exports.newValueFieldState = newValueFieldState;
|
|
187
186
|
/**
|
|
188
187
|
* Returns a proxy that looks exactly like the original `field`, in terms of valid/touched/errors/etc., but
|
|
189
188
|
* has any methods that use `V` overridden to use be `V2`.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { Meta } from "@storybook/react";
|
|
2
|
+
declare const _default: Meta;
|
|
2
3
|
export default _default;
|
|
3
4
|
export declare function AppExample(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppExample =
|
|
3
|
+
exports.AppExample = AppExample;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const FormStateApp_1 = require("./FormStateApp");
|
|
6
6
|
exports.default = {
|
|
@@ -10,4 +10,3 @@ exports.default = {
|
|
|
10
10
|
function AppExample() {
|
|
11
11
|
return (0, jsx_runtime_1.jsx)(FormStateApp_1.FormStateApp, {});
|
|
12
12
|
}
|
|
13
|
-
exports.AppExample = AppExample;
|
package/dist/formState.test.js
CHANGED
|
@@ -1468,6 +1468,22 @@ describe("formState", () => {
|
|
|
1468
1468
|
a.address.set({ street: "123", city: "nyc" });
|
|
1469
1469
|
expect(a.value).toEqual({ address: { street: "123", city: "nyc" } });
|
|
1470
1470
|
});
|
|
1471
|
+
it("can have child object states with cycles", () => {
|
|
1472
|
+
// Given an author with an address child
|
|
1473
|
+
// And two addresses that are basically identical and both have cycles
|
|
1474
|
+
const address1 = { city: "city2" };
|
|
1475
|
+
address1.someCycle = address1;
|
|
1476
|
+
const address2 = { city: "city2" };
|
|
1477
|
+
address2.someCycle = address2;
|
|
1478
|
+
const a = (0, objectField_1.createObjectState)({
|
|
1479
|
+
id: { type: "value" },
|
|
1480
|
+
address: { type: "value" },
|
|
1481
|
+
}, { address: address1 });
|
|
1482
|
+
// When we change the address
|
|
1483
|
+
a.address.set(address2);
|
|
1484
|
+
// Then it doesn't error on dirty checks
|
|
1485
|
+
expect(a.address.dirty).toBe(false);
|
|
1486
|
+
});
|
|
1471
1487
|
it("provides isNewEntity", () => {
|
|
1472
1488
|
// Given an author without an id
|
|
1473
1489
|
const formState = (0, objectField_1.createObjectState)(authorWithAddressConfig, {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { ObjectConfig } from "./config";
|
|
2
1
|
export { f } from "./configBuilders";
|
|
3
|
-
export { FragmentField } from "./fields/fragmentField";
|
|
4
|
-
export { ListFieldState } from "./fields/listField";
|
|
5
|
-
export { Fragment, ObjectState,
|
|
6
|
-
export { FieldState, ValueAdapter } from "./fields/valueField";
|
|
7
|
-
export {
|
|
2
|
+
export { type FragmentField } from "./fields/fragmentField";
|
|
3
|
+
export { type ListFieldState } from "./fields/listField";
|
|
4
|
+
export { createObjectState, type Fragment, type ObjectState, type fragment } from "./fields/objectField";
|
|
5
|
+
export { type FieldState, type ValueAdapter } from "./fields/valueField";
|
|
6
|
+
export { required, type Rule } from "./rules";
|
|
8
7
|
export { useFormState } from "./useFormState";
|
|
9
8
|
export { useFormStates } from "./useFormStates";
|
|
9
|
+
export { type ObjectConfig } from "./config";
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useFormStates = exports.useFormState = exports.required = exports.
|
|
3
|
+
exports.useFormStates = exports.useFormState = exports.required = exports.createObjectState = exports.f = void 0;
|
|
4
4
|
var configBuilders_1 = require("./configBuilders");
|
|
5
5
|
Object.defineProperty(exports, "f", { enumerable: true, get: function () { return configBuilders_1.f; } });
|
|
6
6
|
var objectField_1 = require("./fields/objectField");
|
|
7
7
|
Object.defineProperty(exports, "createObjectState", { enumerable: true, get: function () { return objectField_1.createObjectState; } });
|
|
8
|
-
Object.defineProperty(exports, "fragment", { enumerable: true, get: function () { return objectField_1.fragment; } });
|
|
9
8
|
var rules_1 = require("./rules");
|
|
10
9
|
Object.defineProperty(exports, "required", { enumerable: true, get: function () { return rules_1.required; } });
|
|
11
10
|
var useFormState_1 = require("./useFormState");
|
package/dist/proxies.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.newDelegateProxy =
|
|
3
|
+
exports.newDelegateProxy = newDelegateProxy;
|
|
4
4
|
/**
|
|
5
5
|
* Creates a new combined object with keys in `overrides` taking precedence, and then
|
|
6
6
|
* any other keys falling back to `delegate`.
|
|
@@ -18,4 +18,3 @@ function newDelegateProxy(delegate, overrides) {
|
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
exports.newDelegateProxy = newDelegateProxy;
|
package/dist/useFormState.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useFormState =
|
|
3
|
+
exports.useFormState = useFormState;
|
|
4
4
|
const is_plain_object_1 = require("is-plain-object");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const objectField_1 = require("./fields/objectField");
|
|
@@ -118,7 +118,6 @@ function useFormState(opts) {
|
|
|
118
118
|
}, [form, readOnly, loading]);
|
|
119
119
|
return form;
|
|
120
120
|
}
|
|
121
|
-
exports.useFormState = useFormState;
|
|
122
121
|
function setLoading(form, opts) {
|
|
123
122
|
const { loading, init } = opts;
|
|
124
123
|
if (loading !== undefined) {
|
package/dist/useFormStates.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useFormStates =
|
|
3
|
+
exports.useFormStates = useFormStates;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const objectField_1 = require("./fields/objectField");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
@@ -95,7 +95,6 @@ function useFormStates(opts) {
|
|
|
95
95
|
[objectStateCache, config]);
|
|
96
96
|
return { getFormState };
|
|
97
97
|
}
|
|
98
|
-
exports.useFormStates = useFormStates;
|
|
99
98
|
// If the user's autoSave hook makes some last-minute `.set` calls to sneak
|
|
100
99
|
// in some business logic right before their GraphQL mutation call, ignore it
|
|
101
100
|
// so that we don't infinite loop.
|
package/dist/utils.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
3
|
+
exports.fail = fail;
|
|
4
|
+
exports.assertNever = assertNever;
|
|
5
|
+
exports.initValue = initValue;
|
|
6
|
+
exports.isInput = isInput;
|
|
7
|
+
exports.isQuery = isQuery;
|
|
8
|
+
exports.pickFields = pickFields;
|
|
9
|
+
exports.isNotUndefined = isNotUndefined;
|
|
10
|
+
exports.isEmpty = isEmpty;
|
|
11
|
+
exports.areEqual = areEqual;
|
|
12
|
+
exports.hasToJSON = hasToJSON;
|
|
13
|
+
exports.deepClone = deepClone;
|
|
8
14
|
const is_plain_object_1 = require("is-plain-object");
|
|
9
15
|
const mobx_1 = require("mobx");
|
|
16
|
+
const deepEquals_1 = require("./fields/deepEquals");
|
|
10
17
|
function fail(message) {
|
|
11
18
|
throw new Error(message || "Failed");
|
|
12
19
|
}
|
|
13
|
-
exports.fail = fail;
|
|
14
20
|
function assertNever(x) {
|
|
15
21
|
throw new Error("Unexpected object: " + x);
|
|
16
22
|
}
|
|
17
|
-
exports.assertNever = assertNever;
|
|
18
23
|
/** Introspects the `init` prop to see if it has a `map` function/etc. and returns the form value. */
|
|
19
24
|
function initValue(config, init) {
|
|
20
25
|
let value;
|
|
@@ -33,15 +38,12 @@ function initValue(config, init) {
|
|
|
33
38
|
// Given our form config, pick out only the subset of fields out of `value` (unless it's a mobx class)
|
|
34
39
|
return pickFields(config, value !== null && value !== void 0 ? value : {});
|
|
35
40
|
}
|
|
36
|
-
exports.initValue = initValue;
|
|
37
41
|
function isInput(init) {
|
|
38
42
|
return !!init && typeof init === "object" && "input" in init;
|
|
39
43
|
}
|
|
40
|
-
exports.isInput = isInput;
|
|
41
44
|
function isQuery(init) {
|
|
42
45
|
return !!init && typeof init === "object" && "query" in init && "map" in init;
|
|
43
46
|
}
|
|
44
|
-
exports.isQuery = isQuery;
|
|
45
47
|
/**
|
|
46
48
|
* Picks ony fields out of `instance` that are in the `formConfig`.
|
|
47
49
|
*
|
|
@@ -88,15 +90,12 @@ function pickFields(formConfig, instance) {
|
|
|
88
90
|
}
|
|
89
91
|
}));
|
|
90
92
|
}
|
|
91
|
-
exports.pickFields = pickFields;
|
|
92
93
|
function isNotUndefined(value) {
|
|
93
94
|
return value !== undefined;
|
|
94
95
|
}
|
|
95
|
-
exports.isNotUndefined = isNotUndefined;
|
|
96
96
|
function isEmpty(value) {
|
|
97
97
|
return value === undefined || value === null || value === "";
|
|
98
98
|
}
|
|
99
|
-
exports.isEmpty = isEmpty;
|
|
100
99
|
/**
|
|
101
100
|
* An equals that does deep-ish equality.
|
|
102
101
|
*
|
|
@@ -108,16 +107,16 @@ exports.isEmpty = isEmpty;
|
|
|
108
107
|
*/
|
|
109
108
|
function areEqual(a, b, strictOrder) {
|
|
110
109
|
if ((0, is_plain_object_1.isPlainObject)(a)) {
|
|
111
|
-
return (0,
|
|
110
|
+
return (0, deepEquals_1.deepEquals)((0, mobx_1.toJS)(a), (0, mobx_1.toJS)(b));
|
|
112
111
|
}
|
|
113
112
|
if (hasToJSON(a) || hasToJSON(b)) {
|
|
114
113
|
const a1 = hasToJSON(a) ? a.toJSON() : a;
|
|
115
114
|
const b1 = hasToJSON(b) ? b.toJSON() : b;
|
|
116
|
-
return (0,
|
|
115
|
+
return (0, deepEquals_1.deepEquals)(a1, b1);
|
|
117
116
|
}
|
|
118
117
|
if (a && b && a instanceof Array && b instanceof Array) {
|
|
119
118
|
if (strictOrder !== false) {
|
|
120
|
-
return (0,
|
|
119
|
+
return (0, deepEquals_1.deepEquals)(a, b);
|
|
121
120
|
}
|
|
122
121
|
if (a.length !== b.length)
|
|
123
122
|
return false;
|
|
@@ -125,11 +124,9 @@ function areEqual(a, b, strictOrder) {
|
|
|
125
124
|
}
|
|
126
125
|
return a === b;
|
|
127
126
|
}
|
|
128
|
-
exports.areEqual = areEqual;
|
|
129
127
|
function hasToJSON(o) {
|
|
130
128
|
return !!(o && typeof o === "object" && "toJSON" in o);
|
|
131
129
|
}
|
|
132
|
-
exports.hasToJSON = hasToJSON;
|
|
133
130
|
/** Make a clone of `obj`, but only recurse into POJOs and Arrays...and stores. */
|
|
134
131
|
function deepClone(obj, map = new WeakMap()) {
|
|
135
132
|
if (obj && typeof obj === "object" && ((0, is_plain_object_1.isPlainObject)(obj) || Array.isArray(obj) || (0, mobx_1.isObservable)(obj))) {
|
|
@@ -144,7 +141,6 @@ function deepClone(obj, map = new WeakMap()) {
|
|
|
144
141
|
return obj;
|
|
145
142
|
}
|
|
146
143
|
}
|
|
147
|
-
exports.deepClone = deepClone;
|
|
148
144
|
/** Returns all property names, including mobx computeds (non-enumerable) & inherited. */
|
|
149
145
|
function getAllPropertyNames(obj) {
|
|
150
146
|
const proto = Object.getPrototypeOf(obj);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homebound/form-state",
|
|
3
|
-
"version": "2.25.
|
|
3
|
+
"version": "2.25.2",
|
|
4
4
|
"author": "Homebound",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"src/**/*.{ts,tsx,css,md}": "prettier --write"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"fast-deep-equal": "^3.1.3",
|
|
34
33
|
"is-plain-object": "^5.0.0"
|
|
35
34
|
},
|
|
36
35
|
"peerDependencies": {
|
|
@@ -38,30 +37,24 @@
|
|
|
38
37
|
"react": ">=16"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@babel/preset-env": "^7.22.15",
|
|
43
|
-
"@babel/preset-react": "^7.22.15",
|
|
44
|
-
"@babel/preset-typescript": "^7.22.15",
|
|
45
|
-
"@homebound/rtl-utils": "2.65.0",
|
|
40
|
+
"@homebound/rtl-utils": "2.66.2",
|
|
46
41
|
"@semantic-release/exec": "^6.0.3",
|
|
47
42
|
"@semantic-release/git": "^10.0.1",
|
|
48
|
-
"@storybook/addon-essentials": "^
|
|
49
|
-
"@storybook/addon-links": "^
|
|
50
|
-
"@storybook/
|
|
51
|
-
"@storybook/react": "^
|
|
52
|
-
"@storybook/
|
|
53
|
-
"@testing-library/dom": "^
|
|
54
|
-
"@testing-library/jest-dom": "^6.
|
|
55
|
-
"@testing-library/react": "^
|
|
56
|
-
"@tsconfig/recommended": "^1.0.
|
|
57
|
-
"@types/jest": "^29.5.
|
|
58
|
-
"@types/react": "^18.
|
|
59
|
-
"@types/react-dom": "^18.
|
|
43
|
+
"@storybook/addon-essentials": "^8.3.5",
|
|
44
|
+
"@storybook/addon-links": "^8.3.5",
|
|
45
|
+
"@storybook/react": "^8.3.5",
|
|
46
|
+
"@storybook/react-vite": "^8.3.5",
|
|
47
|
+
"@storybook/types": "^8.3.5",
|
|
48
|
+
"@testing-library/dom": "^10.4.0",
|
|
49
|
+
"@testing-library/jest-dom": "^6.6.2",
|
|
50
|
+
"@testing-library/react": "^16.0.1",
|
|
51
|
+
"@tsconfig/recommended": "^1.0.7",
|
|
52
|
+
"@types/jest": "^29.5.13",
|
|
53
|
+
"@types/react": "^18.3.11",
|
|
54
|
+
"@types/react-dom": "^18.3.1",
|
|
60
55
|
"@typescript-eslint/eslint-plugin": "^4.17.0",
|
|
61
56
|
"@typescript-eslint/parser": "^4.17.0",
|
|
62
|
-
"
|
|
63
|
-
"babel-loader": "^8.2.2",
|
|
64
|
-
"conventional-changelog-conventionalcommits": "^4.5.0",
|
|
57
|
+
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
65
58
|
"eslint": "^7.21.0",
|
|
66
59
|
"eslint-config-prettier": "^8.1.0",
|
|
67
60
|
"eslint-config-react-app": "^6.0.0",
|
|
@@ -71,23 +64,25 @@
|
|
|
71
64
|
"eslint-plugin-react": "^7.22.0",
|
|
72
65
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
73
66
|
"husky": "^3.1.0",
|
|
74
|
-
"jest": "^29.
|
|
75
|
-
"jest-environment-jsdom": "^29.
|
|
76
|
-
"lint-staged": "^
|
|
77
|
-
"mobx": "^6.
|
|
78
|
-
"mobx-react": "^9.
|
|
79
|
-
"prettier": "
|
|
80
|
-
"prettier-plugin-organize-imports": "^
|
|
81
|
-
"react": "^18.
|
|
82
|
-
"react-dom": "^18.
|
|
83
|
-
"semantic-release": "^
|
|
84
|
-
"storybook": "^
|
|
85
|
-
"ts-jest": "^29.
|
|
86
|
-
"ts-node": "^10.9.
|
|
87
|
-
"ts-patch": "^3.
|
|
88
|
-
"tslib": "^2.
|
|
89
|
-
"typescript": "
|
|
90
|
-
"typescript-transform-paths": "^3.
|
|
67
|
+
"jest": "^29.7.0",
|
|
68
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
69
|
+
"lint-staged": "^15.2.10",
|
|
70
|
+
"mobx": "^6.13.5",
|
|
71
|
+
"mobx-react": "^9.1.1",
|
|
72
|
+
"prettier": "3.3.3",
|
|
73
|
+
"prettier-plugin-organize-imports": "^4.1.0",
|
|
74
|
+
"react": "^18.3.1",
|
|
75
|
+
"react-dom": "^18.3.1",
|
|
76
|
+
"semantic-release": "^24.1.2",
|
|
77
|
+
"storybook": "^8.3.5",
|
|
78
|
+
"ts-jest": "^29.2.5",
|
|
79
|
+
"ts-node": "^10.9.2",
|
|
80
|
+
"ts-patch": "^3.2.1",
|
|
81
|
+
"tslib": "^2.8.0",
|
|
82
|
+
"typescript": "5.5.4",
|
|
83
|
+
"typescript-transform-paths": "^3.5.1",
|
|
84
|
+
"vite": "^5.4.9",
|
|
85
|
+
"vite-tsconfig-paths": "^5.0.1"
|
|
91
86
|
},
|
|
92
87
|
"packageManager": "yarn@3.6.3"
|
|
93
88
|
}
|