@homebound/form-state 2.3.0 → 2.5.1
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 +1 -1
- package/dist/formState.d.ts +4 -2
- package/dist/formState.js +25 -20
- package/dist/formState.test.js +114 -39
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/setupTests.js +7 -2
- package/dist/useFormState.d.ts +1 -13
- package/dist/useFormState.js +41 -72
- package/dist/useFormState.test.js +95 -97
- package/dist/useFormStates.d.ts +12 -0
- package/dist/useFormStates.js +58 -0
- package/dist/useFormStates.test.d.ts +1 -0
- package/dist/useFormStates.test.js +136 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +60 -1
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +102 -0
- package/package.json +15 -6
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mobx_1 = require("mobx");
|
|
4
|
+
const formState_1 = require("./formState");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
describe("utils", () => {
|
|
7
|
+
describe("pickFields", () => {
|
|
8
|
+
it("can pick a value field", () => {
|
|
9
|
+
const a = utils_1.pickFields(
|
|
10
|
+
//
|
|
11
|
+
{ firstName: { type: "value" } }, { firstName: "a", b: "ignored" });
|
|
12
|
+
expect(a).toMatchInlineSnapshot(`
|
|
13
|
+
Object {
|
|
14
|
+
"firstName": "a",
|
|
15
|
+
}
|
|
16
|
+
`);
|
|
17
|
+
});
|
|
18
|
+
it("can pick an unset object fields", () => {
|
|
19
|
+
const a = utils_1.pickFields(authorWithAddressConfig, { firstName: "a", b: "ignored" });
|
|
20
|
+
expect(a).toMatchInlineSnapshot(`
|
|
21
|
+
Object {
|
|
22
|
+
"address": undefined,
|
|
23
|
+
"firstName": "a",
|
|
24
|
+
"id": undefined,
|
|
25
|
+
"lastName": undefined,
|
|
26
|
+
}
|
|
27
|
+
`);
|
|
28
|
+
});
|
|
29
|
+
it("can pick a set object field", () => {
|
|
30
|
+
const a = utils_1.pickFields(authorWithAddressConfig, { firstName: "a", b: "ignored", address: {} });
|
|
31
|
+
expect(a).toMatchInlineSnapshot(`
|
|
32
|
+
Object {
|
|
33
|
+
"address": Object {
|
|
34
|
+
"city": undefined,
|
|
35
|
+
"street": undefined,
|
|
36
|
+
},
|
|
37
|
+
"firstName": "a",
|
|
38
|
+
"id": undefined,
|
|
39
|
+
"lastName": undefined,
|
|
40
|
+
}
|
|
41
|
+
`);
|
|
42
|
+
});
|
|
43
|
+
it("can pick an unset list field", () => {
|
|
44
|
+
const a = utils_1.pickFields(authorWithBooksConfig, { firstName: "a", b: "ignored" });
|
|
45
|
+
expect(a).toMatchInlineSnapshot(`
|
|
46
|
+
Object {
|
|
47
|
+
"books": undefined,
|
|
48
|
+
"firstName": "a",
|
|
49
|
+
"id": undefined,
|
|
50
|
+
"lastName": undefined,
|
|
51
|
+
}
|
|
52
|
+
`);
|
|
53
|
+
});
|
|
54
|
+
it("can pick a set list field", () => {
|
|
55
|
+
const a = utils_1.pickFields(authorWithBooksConfig, { firstName: "a", b: "ignored", books: [{}] });
|
|
56
|
+
expect(a).toMatchInlineSnapshot(`
|
|
57
|
+
Object {
|
|
58
|
+
"books": Array [
|
|
59
|
+
Object {
|
|
60
|
+
"classification": undefined,
|
|
61
|
+
"id": undefined,
|
|
62
|
+
"title": undefined,
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
"firstName": "a",
|
|
66
|
+
"id": undefined,
|
|
67
|
+
"lastName": undefined,
|
|
68
|
+
}
|
|
69
|
+
`);
|
|
70
|
+
});
|
|
71
|
+
it("can pick a set observable list field", () => {
|
|
72
|
+
const books = mobx_1.observable([]);
|
|
73
|
+
const a = utils_1.pickFields(authorWithBooksConfig, { firstName: "a", b: "ignored", books });
|
|
74
|
+
expect(mobx_1.isObservable(a.books)).toEqual(true);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
const authorWithAddressConfig = {
|
|
79
|
+
id: { type: "value" },
|
|
80
|
+
firstName: { type: "value" },
|
|
81
|
+
lastName: { type: "value" },
|
|
82
|
+
address: {
|
|
83
|
+
type: "object",
|
|
84
|
+
config: {
|
|
85
|
+
street: { type: "value", rules: [formState_1.required] },
|
|
86
|
+
city: { type: "value" },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const authorWithBooksConfig = {
|
|
91
|
+
id: { type: "value" },
|
|
92
|
+
firstName: { type: "value" },
|
|
93
|
+
lastName: { type: "value" },
|
|
94
|
+
books: {
|
|
95
|
+
type: "list",
|
|
96
|
+
config: {
|
|
97
|
+
id: { type: "value" },
|
|
98
|
+
title: { type: "value", rules: [formState_1.required] },
|
|
99
|
+
classification: { type: "value" },
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homebound/form-state",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"author": "Homebound",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,6 +21,14 @@
|
|
|
21
21
|
"format": "prettier --loglevel warn --write \"**/*.{ts,tsx,css,md}\"",
|
|
22
22
|
"semantic-release": "semantic-release"
|
|
23
23
|
},
|
|
24
|
+
"husky": {
|
|
25
|
+
"hooks": {
|
|
26
|
+
"pre-commit": "lint-staged --allow-empty"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"lint-staged": {
|
|
30
|
+
"src/**/*.{ts,tsx,css,md}": "prettier --write"
|
|
31
|
+
},
|
|
24
32
|
"dependencies": {
|
|
25
33
|
"fast-deep-equal": "^3.1.3",
|
|
26
34
|
"is-plain-object": "^5.0.0",
|
|
@@ -32,16 +40,16 @@
|
|
|
32
40
|
},
|
|
33
41
|
"devDependencies": {
|
|
34
42
|
"@babel/core": "^7.13.1",
|
|
35
|
-
"@homebound/rtl-utils": "^2.
|
|
43
|
+
"@homebound/rtl-utils": "^2.59.2",
|
|
36
44
|
"@semantic-release/git": "^9.0.0",
|
|
37
45
|
"@storybook/addon-essentials": "^6.2.9",
|
|
38
46
|
"@storybook/addon-info": "^5.3.21",
|
|
39
47
|
"@storybook/addon-links": "^6.2.9",
|
|
40
48
|
"@storybook/addons": "^6.2.9",
|
|
41
49
|
"@storybook/react": "^6.2.9",
|
|
42
|
-
"@testing-library/dom": "^
|
|
43
|
-
"@testing-library/jest-dom": "^5.
|
|
44
|
-
"@testing-library/react": "^
|
|
50
|
+
"@testing-library/dom": "^8.11.3",
|
|
51
|
+
"@testing-library/jest-dom": "^5.16.2",
|
|
52
|
+
"@testing-library/react": "^12.1.2",
|
|
45
53
|
"@tsconfig/recommended": "^1.0.1",
|
|
46
54
|
"@types/jest": "^26.0.20",
|
|
47
55
|
"@types/react": "^16.14.5",
|
|
@@ -59,8 +67,9 @@
|
|
|
59
67
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
60
68
|
"eslint-plugin-react": "^7.22.0",
|
|
61
69
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
62
|
-
"husky": "^
|
|
70
|
+
"husky": "^3.0.9",
|
|
63
71
|
"jest": "^27.0.2",
|
|
72
|
+
"lint-staged": "^10.1.2",
|
|
64
73
|
"mobx": "^6.3.2",
|
|
65
74
|
"mobx-react": "^7.2.0",
|
|
66
75
|
"prettier": "^2.2.1",
|