@homebound/form-state 2.26.6 → 2.26.7

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.
@@ -7,6 +7,7 @@ const mobx_1 = require("mobx");
7
7
  const mobx_react_1 = require("mobx-react");
8
8
  const react_2 = require("react");
9
9
  const FormStateApp_1 = require("./FormStateApp");
10
+ const objectField_1 = require("./fields/objectField");
10
11
  const rules_1 = require("./rules");
11
12
  const useFormState_1 = require("./useFormState");
12
13
  describe("useFormState", () => {
@@ -109,6 +110,25 @@ describe("useFormState", () => {
109
110
  (0, rtl_utils_1.click)(r.change);
110
111
  expect(r.firstName).toHaveTextContent("0");
111
112
  });
113
+ it("can init with fragments", async () => {
114
+ // Given a component
115
+ function TestComponent() {
116
+ var _a, _b, _c, _d;
117
+ // And we have query data that may or may not be defined
118
+ const form = (0, useFormState_1.useFormState)({
119
+ config: authorWithBookFragments,
120
+ init: {
121
+ input: {},
122
+ map: () => ({ firstName: "a1", books: [{ id: "b:1", data: (0, objectField_1.fragment)({ misc: "data" }) }] }),
123
+ },
124
+ });
125
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { "data-testid": "fieldValue", children: form.books.rows[0].data.value.misc }), (0, jsx_runtime_1.jsx)("div", { "data-testid": "rowValue", children: (_b = (_a = form.books.rows[0].value.data) === null || _a === void 0 ? void 0 : _a.misc) !== null && _b !== void 0 ? _b : "unset" }), (0, jsx_runtime_1.jsx)("div", { "data-testid": "listValue", children: (_d = (_c = form.books.value[0].data) === null || _c === void 0 ? void 0 : _c.misc) !== null && _d !== void 0 ? _d : "unset" })] }));
126
+ }
127
+ const r = await (0, rtl_utils_1.render)((0, jsx_runtime_1.jsx)(TestComponent, {}));
128
+ expect(r.fieldValue).toHaveTextContent("data");
129
+ expect(r.rowValue).toHaveTextContent("unset");
130
+ expect(r.listValue).toHaveTextContent("unset");
131
+ });
112
132
  it("keeps local changed values when a query refreshes", async () => {
113
133
  // Given a component
114
134
  function TestComponent() {
@@ -567,7 +587,7 @@ describe("useFormState", () => {
567
587
  });
568
588
  return (0, jsx_runtime_1.jsx)("button", { "data-testid": "set", onClick: () => form.firstName.set("f2") });
569
589
  }
570
- const r = await (0, rtl_utils_1.render)((0, jsx_runtime_1.jsx)(TestComponent, {}));
590
+ await (0, rtl_utils_1.render)((0, jsx_runtime_1.jsx)(TestComponent, {}));
571
591
  // When we change a field, and try to commit, it blows up
572
592
  // await expect(clickAndWait(r.set)).rejects.toThrow(
573
593
  // "When using autoSave, you should not manually call commitChanges",
@@ -620,6 +640,17 @@ const authorWithAddressAndBooksConfig = {
620
640
  },
621
641
  },
622
642
  };
643
+ const authorWithBookFragments = {
644
+ id: { type: "value" },
645
+ firstName: { type: "value" },
646
+ books: {
647
+ type: "list",
648
+ config: {
649
+ id: { type: "value" },
650
+ data: { type: "fragment" },
651
+ },
652
+ },
653
+ };
623
654
  /** Emulates a user focusing and then blurring a field. */
624
655
  function focusAndBlur(state) {
625
656
  state.focus();
package/dist/utils.js CHANGED
@@ -85,6 +85,9 @@ function pickFields(formConfig, instance) {
85
85
  else if (keyConfig.type === "value") {
86
86
  return [key, value];
87
87
  }
88
+ else if (keyConfig.type === "fragment") {
89
+ return [key, value];
90
+ }
88
91
  else {
89
92
  return assertNever(keyConfig);
90
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/form-state",
3
- "version": "2.26.6",
3
+ "version": "2.26.7",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",