@mittwald/flow-react-components 0.1.0-alpha.139 → 0.1.0-alpha.140

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.
@@ -1,49 +1,49 @@
1
1
  "use client"
2
2
  /* */
3
- var S = Object.defineProperty;
4
- var B = (o, t, e) => t in o ? S(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
5
- var a = (o, t, e) => (B(o, typeof t != "symbol" ? t + "" : t, e), e);
6
- import A, { createContext as F, useRef as k, useContext as y } from "react";
7
- import { makeObservable as O, observable as M, action as I, computed as E } from "mobx";
8
- import { u as w } from "./useOverlayController-CGKumeGL.js";
9
- import D from "invariant";
10
- import { u as b } from "./useSelector-DpU7_HMO.js";
11
- import { a as T, g as N, u as R } from "./getActionGroupSlot-Do-bk4GU.js";
3
+ var B = Object.defineProperty;
4
+ var k = (o, t, e) => t in o ? B(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
5
+ var r = (o, t, e) => (k(o, typeof t != "symbol" ? t + "" : t, e), e);
6
+ import w, { createContext as M, useRef as O, useContext as b } from "react";
7
+ import { makeObservable as I, observable as E, action as D, computed as T } from "mobx";
8
+ import { u as g } from "./useOverlayController-CGKumeGL.js";
9
+ import N from "invariant";
10
+ import { u as v } from "./useSelector-DpU7_HMO.js";
11
+ import { a as R, g as V, u as $ } from "./getActionGroupSlot-Do-bk4GU.js";
12
12
  import "./propsContext-DzAKlmhS.js";
13
- import { P as V } from "./PropsContextProvider-C6Z4XGp6.js";
13
+ import { P as G } from "./PropsContextProvider-C6Z4XGp6.js";
14
14
  import "@react-aria/utils";
15
15
  import "remeda";
16
16
  import { d as u } from "./dynamic-ClpUSmEt.js";
17
- import { u as $ } from "./slotContext-DoCFkzCA.js";
18
- const m = F(void 0), G = m.Provider, g = (o) => new Promise((t) => setTimeout(t, o)), f = {
17
+ import { u as L } from "./slotContext-DoCFkzCA.js";
18
+ const C = M(void 0), U = C.Provider, x = (o) => new Promise((t) => setTimeout(t, o)), p = {
19
19
  pending: 1e3,
20
20
  succeeded: 1500,
21
21
  failed: 2e3
22
22
  };
23
- class C {
23
+ class y {
24
24
  constructor() {
25
- a(this, "showFeedback");
26
- a(this, "state", "isIdle");
27
- a(this, "setPendingTimeout");
28
- a(this, "error");
29
- a(this, "isAsync", !1);
30
- O(this, {
31
- state: M,
32
- updateState: I,
33
- isBusy: E
25
+ r(this, "showFeedback");
26
+ r(this, "state", "isIdle");
27
+ r(this, "setPendingTimeout");
28
+ r(this, "error");
29
+ r(this, "isAsync", !1);
30
+ I(this, {
31
+ state: E,
32
+ updateState: D,
33
+ isBusy: T
34
34
  });
35
35
  }
36
36
  static useNew() {
37
- return k(new C()).current;
37
+ return O(new y()).current;
38
38
  }
39
39
  updateState(t) {
40
40
  this.state = t;
41
41
  }
42
42
  useValue() {
43
- return b(() => this.state, [this]);
43
+ return v(() => this.state, [this]);
44
44
  }
45
45
  useIsBusy() {
46
- return b(() => this.isBusy, [this]);
46
+ return v(() => this.isBusy, [this]);
47
47
  }
48
48
  get isBusy() {
49
49
  return this.state !== "isIdle";
@@ -51,7 +51,7 @@ class C {
51
51
  onAsyncStart() {
52
52
  this.isAsync = !0, this.updateState("isExecuting"), this.setPendingTimeout = window.setTimeout(
53
53
  () => this.startPending(),
54
- f.pending
54
+ p.pending
55
55
  );
56
56
  }
57
57
  async onSucceeded() {
@@ -64,10 +64,10 @@ class C {
64
64
  return this.showFeedback = t, this;
65
65
  }
66
66
  async startFailedFeedback() {
67
- this.updateState("isFailed"), await g(f.failed), this.resetAfterDone();
67
+ this.updateState("isFailed"), await x(p.failed), this.resetAfterDone();
68
68
  }
69
69
  async startSucceededFeedback() {
70
- this.updateState("isSucceeded"), await g(f.succeeded), this.resetAfterDone();
70
+ this.updateState("isSucceeded"), await x(p.succeeded), this.resetAfterDone();
71
71
  }
72
72
  resetAfterDone() {
73
73
  this.updateState("isIdle"), this.isAsync = !1, this.error = void 0;
@@ -79,44 +79,44 @@ class C {
79
79
  this.updateState("isPending");
80
80
  }
81
81
  }
82
- const P = (o) => (...t) => {
82
+ const F = (o) => (...t) => {
83
83
  const e = [...o], n = e.shift();
84
84
  if (n) {
85
- const s = n(...t), i = () => e.length === 0 ? s : P(e)(...t);
86
- return s instanceof Promise ? s.then(i) : i();
85
+ const s = n(...t), a = () => e.length === 0 ? s : F(e)(...t);
86
+ return s instanceof Promise ? s.then(a) : a();
87
87
  }
88
88
  }, d = () => {
89
- }, L = (o, t = {}) => {
89
+ }, j = (o, t = {}) => {
90
90
  const {
91
91
  onSync: e = d,
92
92
  onAsync: n = d,
93
93
  then: s = d,
94
- catch: i = d,
94
+ catch: a = d,
95
95
  finally: c = d
96
96
  } = t;
97
97
  try {
98
- const r = o();
99
- return r instanceof Promise ? (n(), r.then(s).catch(i).finally(c)) : (e(), s(r), c(), r);
100
- } catch (r) {
101
- e(), i(r), c();
98
+ const i = o();
99
+ return i instanceof Promise ? (n(), i.then(s).catch(a).finally(c)) : (e(), s(i), c(), i);
100
+ } catch (i) {
101
+ e(), a(i), c();
102
102
  }
103
- }, U = () => {
103
+ }, q = () => {
104
104
  };
105
- function j(o) {
105
+ function z(o) {
106
106
  if (o.needsConfirmation)
107
107
  return o.confirmationModalController.open;
108
108
  const t = o.getOverlayController(), {
109
109
  action: e,
110
110
  toggleOverlay: n,
111
111
  closeOverlay: s,
112
- openOverlay: i
112
+ openOverlay: a
113
113
  } = o.actionProps;
114
- return e || (i && t ? t.open : s && t || n && t ? t.close : U);
114
+ return e || (a && t ? t.open : s && t || n && t ? t.close : q);
115
115
  }
116
- class v {
116
+ class P {
117
117
  constructor(t) {
118
- a(this, "actions", []);
119
- a(this, "baseAction");
118
+ r(this, "actions", []);
119
+ r(this, "baseAction");
120
120
  this.baseAction = t;
121
121
  }
122
122
  addAction(t) {
@@ -127,42 +127,42 @@ class v {
127
127
  return;
128
128
  const e = this.actions[this.actions.length - 1].actionProps.showFeedback, n = this.baseAction.state.withFeedback(
129
129
  this.baseAction.needsConfirmation ? !1 : e
130
- ), s = this.actions.map((r) => j(r)), i = P(s);
130
+ ), s = this.actions.map((i) => z(i)), a = F(s);
131
131
  let c;
132
- if (await L(() => i(...t), {
132
+ if (await j(() => a(...t), {
133
133
  onAsync: () => n.onAsyncStart(),
134
134
  then: () => n.onSucceeded(),
135
- catch: (r) => {
136
- n.onFailed(r), c = r;
135
+ catch: (i) => {
136
+ n.onFailed(i), c = i;
137
137
  }
138
138
  }), c)
139
139
  throw c;
140
140
  }
141
141
  }
142
- class q {
142
+ class H {
143
143
  constructor(t) {
144
- a(this, "action");
145
- a(this, "execute", (...t) => {
144
+ r(this, "action");
145
+ r(this, "execute", (...t) => {
146
146
  const e = this.getBatchedActions();
147
147
  (async () => {
148
148
  for (const s of e)
149
149
  await s.executeBatch(t);
150
150
  })().catch((s) => console.error(s));
151
151
  });
152
- a(this, "getBatchedActions", () => {
152
+ r(this, "getBatchedActions", () => {
153
153
  let t = this.action;
154
154
  const e = [];
155
- let n = new v(
155
+ let n = new P(
156
156
  this.action
157
157
  ), s = 0;
158
158
  for (; t; ) {
159
- const { action: i, break: c, skip: r } = t.actionProps;
159
+ const { action: a, break: c, skip: i } = t.actionProps;
160
160
  if (t.needsConfirmation) {
161
161
  n.addAction(t);
162
162
  break;
163
163
  }
164
- if (r) {
165
- s = r === !0 ? 1 : r, t = t.parentAction;
164
+ if (i) {
165
+ s = i === !0 ? 1 : i, t = t.parentAction;
166
166
  continue;
167
167
  }
168
168
  if (s > 0) {
@@ -171,7 +171,7 @@ class q {
171
171
  }
172
172
  if (c)
173
173
  break;
174
- i || (e.push(n), n = new v(this.action)), n.addAction(t), t = t.parentAction;
174
+ a || (e.push(n), n = new P(this.action)), n.addAction(t), t = t.parentAction;
175
175
  }
176
176
  return e.push(n), e;
177
177
  });
@@ -180,31 +180,31 @@ class q {
180
180
  }
181
181
  class l {
182
182
  constructor(t) {
183
- a(this, "state");
184
- a(this, "needsConfirmation");
185
- a(this, "actionProps");
186
- a(this, "parentAction");
187
- a(this, "confirmationModalController");
188
- a(this, "overlayController");
189
- a(this, "execute", (...t) => {
190
- new q(this).execute(...t);
183
+ r(this, "state");
184
+ r(this, "needsConfirmation");
185
+ r(this, "actionProps");
186
+ r(this, "parentAction");
187
+ r(this, "confirmationModalController");
188
+ r(this, "overlayController");
189
+ r(this, "execute", (...t) => {
190
+ new H(this).execute(...t);
191
191
  });
192
192
  const {
193
193
  actionProps: e,
194
194
  needsConfirmation: n,
195
195
  parentAction: s,
196
- overlayController: i,
196
+ overlayController: a,
197
197
  confirmationModalController: c,
198
- state: r
198
+ state: i
199
199
  } = t;
200
- this.actionProps = e, this.parentAction = s, this.confirmationModalController = c, this.needsConfirmation = n, this.overlayController = i, this.state = r;
200
+ this.actionProps = e, this.parentAction = s, this.confirmationModalController = c, this.needsConfirmation = n, this.overlayController = a, this.state = i;
201
201
  }
202
202
  static useNew(t, e = {}) {
203
- const n = y(m), s = w(), i = w(), c = C.useNew();
203
+ const n = b(C), s = g(), a = g(), c = y.useNew();
204
204
  return new l({
205
205
  parentAction: n,
206
206
  overlayController: s,
207
- confirmationModalController: i,
207
+ confirmationModalController: a,
208
208
  needsConfirmation: !1,
209
209
  actionProps: t,
210
210
  state: c,
@@ -212,8 +212,8 @@ class l {
212
212
  });
213
213
  }
214
214
  static use() {
215
- const t = y(m);
216
- return D(!!t, "Action context is not defined"), T.useRegisterState(t.state), t;
215
+ const t = b(C);
216
+ return N(!!t, "Action context is not defined"), R.useRegisterState(t.state), t;
217
217
  }
218
218
  static useConfirmationAction() {
219
219
  const t = l.use();
@@ -238,49 +238,50 @@ class l {
238
238
  return t(this.actionProps.openOverlay) ?? t(this.actionProps.closeOverlay) ?? t(this.actionProps.toggleOverlay);
239
239
  }
240
240
  }
241
- const z = (o) => $()[o], p = (o) => z("Modal") === "actionConfirm" ? N(o) : void 0, h = (o) => {
242
- const t = l.use(), e = t.state.useValue(), n = p(o) === "primary", s = t.confirmationModalController.useIsOpen();
241
+ const J = (o) => L()[o], A = (o) => J("Modal") === "actionConfirm" ? V(o) : void 0, f = (o) => {
242
+ const t = l.use(), e = t.state.useValue(), n = A(o) === "primary", s = t.confirmationModalController.useIsOpen();
243
243
  return t.needsConfirmation && s && !n ? "isIdle" : e;
244
- }, x = {
244
+ }, S = {
245
245
  onPress: u((o) => {
246
- const t = l.use(), e = l.useConfirmationAction(), n = p(o) === "primary";
247
- return p(o) === "abort" ? t.confirmationModalController.close : n ? e.execute : t.execute;
246
+ const t = l.use(), e = l.useConfirmationAction(), n = A(o) === "primary";
247
+ return A(o) === "abort" ? t.confirmationModalController.close : n ? e.execute : t.execute;
248
248
  }),
249
- isPending: u((o) => h(o) === "isPending"),
249
+ isPending: u((o) => f(o) === "isPending"),
250
250
  isSucceeded: u(
251
- (o) => h(o) === "isSucceeded"
251
+ (o) => f(o) === "isSucceeded"
252
252
  ),
253
- isFailed: u((o) => h(o) === "isFailed"),
253
+ isFailed: u((o) => f(o) === "isFailed"),
254
254
  "aria-disabled": u((o) => {
255
- const t = h(o), e = R().useIsBusy();
255
+ const t = f(o), e = $().useIsBusy();
256
256
  return t === "isExecuting" || e;
257
257
  })
258
- }, st = (o) => {
259
- const { children: t, ...e } = o, n = l.useNew(e), s = {
260
- Button: x,
258
+ }, rt = (o) => {
259
+ const { children: t, actionModel: e, ...n } = o, s = l.useNew(n), a = e ?? s, c = {
260
+ Button: S,
261
261
  Link: {
262
262
  onPress: u(() => l.use().execute)
263
263
  },
264
264
  Modal: {
265
265
  slot: u((i) => {
266
- const { slot: c } = i, r = l.use();
267
- return r.needsConfirmation = c === "actionConfirm", c;
266
+ const { slot: m } = i, h = l.use();
267
+ return h.needsConfirmation = m === "actionConfirm", m;
268
268
  }),
269
269
  isDismissable: u((i) => {
270
- const r = l.use().state.useValue();
271
- return r === "isExecuting" || r === "isPending" ? !1 : i.isDismissable;
270
+ const h = l.use().state.useValue();
271
+ return h === "isExecuting" || h === "isPending" ? !1 : i.isDismissable;
272
272
  }),
273
273
  controller: u(() => {
274
274
  const i = l.use();
275
275
  return i.needsConfirmation ? i.confirmationModalController : i.getOverlayController();
276
276
  }),
277
277
  ActionGroup: {
278
- Button: x
278
+ Button: S
279
279
  }
280
280
  }
281
281
  };
282
- return /* @__PURE__ */ A.createElement(G, { value: n }, /* @__PURE__ */ A.createElement(V, { props: s, mergeInParentContext: !0 }, t));
282
+ return /* @__PURE__ */ w.createElement(U, { value: a }, /* @__PURE__ */ w.createElement(G, { props: c, mergeInParentContext: !0 }, t));
283
283
  };
284
284
  export {
285
- st as A
285
+ rt as A,
286
+ l as a
286
287
  };
package/dist/Action.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client"
2
2
  /* */
3
- import { A as t } from "./Action-BGsLXvb9.js";
3
+ import { A as t } from "./Action-C4Ncwjzf.js";
4
4
  export {
5
5
  t as Action,
6
6
  t as default
@@ -15,7 +15,7 @@ import "@react-aria/utils";
15
15
  import "remeda";
16
16
  import "dot-prop";
17
17
  import { f as C } from "./flowComponent-CPKCCJEg.js";
18
- import { A as E } from "./Action-BGsLXvb9.js";
18
+ import { A as E } from "./Action-C4Ncwjzf.js";
19
19
  const B = {
20
20
  "de-DE": {
21
21
  "copyButton.copy": "Kopieren"
package/dist/OffCanvas.js CHANGED
@@ -6,7 +6,7 @@ import { B as f } from "./Button-BPAhEOTg.js";
6
6
  import "@tabler/icons-react";
7
7
  import "./Icon-D4bkU_pz.js";
8
8
  import { I as m } from "./IconClose-FTrJdf_N.js";
9
- import { A as i } from "./Action-BGsLXvb9.js";
9
+ import { A as i } from "./Action-C4Ncwjzf.js";
10
10
  import { M as p } from "./ModalOverlay-BSu4UEnW.js";
11
11
  import "./propsContext-DzAKlmhS.js";
12
12
  import { P as v } from "./PropsContextProvider-C6Z4XGp6.js";
@@ -4,15 +4,15 @@ import e from "react";
4
4
  import * as R from "react-aria-components";
5
5
  import E from "clsx";
6
6
  import "./propsContext-DzAKlmhS.js";
7
- import { P as C, m as k } from "./PropsContextProvider-C6Z4XGp6.js";
7
+ import { P as C, m as I } from "./PropsContextProvider-C6Z4XGp6.js";
8
8
  import "@react-aria/utils";
9
9
  import "remeda";
10
- import { d as x } from "./dynamic-ClpUSmEt.js";
11
- import { F as y } from "./FieldError-D_VRyiJG.js";
12
- import { C as F } from "./ColumnLayout-FMONjI17.js";
13
- import { TunnelProvider as I, TunnelExit as m } from "@mittwald/react-tunnel";
10
+ import { d as P } from "./dynamic-ClpUSmEt.js";
11
+ import { F as b } from "./FieldError-D_VRyiJG.js";
12
+ import { C as k } from "./ColumnLayout-FMONjI17.js";
13
+ import { TunnelProvider as y, TunnelExit as m } from "@mittwald/react-tunnel";
14
14
  import { s as c } from "./FormField.module-DHK6nIcD.js";
15
- import { d as P } from "./deepFindOfType-6pG0fH7S.js";
15
+ import { d as F } from "./deepFindOfType-6pG0fH7S.js";
16
16
  import { C as w } from "./ClearPropsContext-CUvsbMn8.js";
17
17
  import "@tabler/icons-react";
18
18
  import "./Icon-D4bkU_pz.js";
@@ -70,17 +70,30 @@ const T = "flow--radio-group", O = "flow--radio-group--segmented-group", $ = "fl
70
70
  tunnelId: "radios"
71
71
  }
72
72
  };
73
- o === "segmented" && (p = k(p, {
73
+ o === "segmented" && (p = I(p, {
74
74
  Radio: {
75
75
  className: a.segment,
76
76
  unstyled: !0,
77
- children: x((b) => /* @__PURE__ */ e.createElement(e.Fragment, null, b.children, /* @__PURE__ */ e.createElement(D, { className: a.checkmark })))
77
+ children: P((x) => /* @__PURE__ */ e.createElement(e.Fragment, null, x.children, /* @__PURE__ */ e.createElement(D, { className: a.checkmark })))
78
78
  }
79
79
  }));
80
- const u = !!P(t, H);
80
+ const u = !!F(t, H);
81
81
  return o === "segmented" && u && console.warn(
82
82
  "<RadioButton/> is not supported in 'segmented' variant of <RadioGroup />"
83
- ), /* @__PURE__ */ e.createElement(R.RadioGroup, { ...h, className: G, ref: d }, /* @__PURE__ */ e.createElement(I, null, /* @__PURE__ */ e.createElement(C, { props: p, dependencies: [o] }, t, o === "segmented" && /* @__PURE__ */ e.createElement("div", { className: a.segmentedGroup }, /* @__PURE__ */ e.createElement("div", { className: a.segments }, /* @__PURE__ */ e.createElement(m, { id: "radios" }))), o === "default" && u && /* @__PURE__ */ e.createElement(F, { s, m: l, l: i, className: a.radioGroup }, /* @__PURE__ */ e.createElement(m, { id: "radios" })), o === "default" && !u && /* @__PURE__ */ e.createElement("div", { className: a.radioGroup }, /* @__PURE__ */ e.createElement(m, { id: "radios" })), /* @__PURE__ */ e.createElement(m, { id: "fieldDescription" }), /* @__PURE__ */ e.createElement(m, { id: "fieldError" }))), /* @__PURE__ */ e.createElement(y, { className: c.fieldError }));
83
+ ), /* @__PURE__ */ e.createElement(R.RadioGroup, { ...h, className: G, ref: d }, /* @__PURE__ */ e.createElement(y, null, /* @__PURE__ */ e.createElement(
84
+ C,
85
+ {
86
+ props: p,
87
+ dependencies: [o],
88
+ mergeInParentContext: !0
89
+ },
90
+ t,
91
+ o === "segmented" && /* @__PURE__ */ e.createElement("div", { className: a.segmentedGroup }, /* @__PURE__ */ e.createElement("div", { className: a.segments }, /* @__PURE__ */ e.createElement(m, { id: "radios" }))),
92
+ o === "default" && u && /* @__PURE__ */ e.createElement(k, { s, m: l, l: i, className: a.radioGroup }, /* @__PURE__ */ e.createElement(m, { id: "radios" })),
93
+ o === "default" && !u && /* @__PURE__ */ e.createElement("div", { className: a.radioGroup }, /* @__PURE__ */ e.createElement(m, { id: "radios" })),
94
+ /* @__PURE__ */ e.createElement(m, { id: "fieldDescription" }),
95
+ /* @__PURE__ */ e.createElement(m, { id: "fieldError" })
96
+ )), /* @__PURE__ */ e.createElement(b, { className: c.fieldError }));
84
97
  }), J = "flow--radio-group--radio", K = "flow--radio-group--radio--icon", g = {
85
98
  radio: J,
86
99
  icon: K
package/dist/Section.js CHANGED
@@ -14,10 +14,10 @@ const u = "flow--section", h = "flow--section--header", w = "flow--section--stat
14
14
  switch: "flow--section--switch",
15
15
  statusBadge: w
16
16
  }, A = d("Section", (o) => {
17
- const { children: s, className: a, isActive: r = !0, refProp: c, ...i } = o;
17
+ const { children: s, className: r, isActive: a = !0, refProp: c, ...n } = o;
18
18
  if (!s)
19
19
  return null;
20
- const n = m(e.section, a), l = {
20
+ const i = m(e.section, r), l = {
21
21
  Heading: {
22
22
  level: 2
23
23
  },
@@ -32,7 +32,7 @@ const u = "flow--section", h = "flow--section--header", w = "flow--section--stat
32
32
  }
33
33
  }
34
34
  };
35
- return /* @__PURE__ */ t.createElement(f, { isActive: r }, /* @__PURE__ */ t.createElement("section", { ...i, className: n, ref: c }, /* @__PURE__ */ t.createElement(p, { props: l }, s)));
35
+ return /* @__PURE__ */ t.createElement(f, { isActive: a }, /* @__PURE__ */ t.createElement("section", { ...n, className: i, ref: c }, /* @__PURE__ */ t.createElement(p, { props: l, mergeInParentContext: !0 }, s)));
36
36
  });
37
37
  export {
38
38
  A as Section,
@@ -1,34 +1,37 @@
1
1
  "use client"
2
2
  /* */
3
- import r, { createContext as x, useContext as F } from "react";
4
- import { Controller as h } from "react-hook-form";
3
+ import o, { createContext as F, useContext as v, useEffect as h } from "react";
4
+ import { Controller as x, useFormState as C } from "react-hook-form";
5
5
  import "./propsContext-DzAKlmhS.js";
6
- import { P as v } from "./PropsContextProvider-C6Z4XGp6.js";
6
+ import { P as k } from "./PropsContextProvider-C6Z4XGp6.js";
7
7
  import "@react-aria/utils";
8
8
  import "remeda";
9
9
  import { d as E } from "./dynamic-ClpUSmEt.js";
10
- import { F as P } from "./FieldError-D_VRyiJG.js";
11
- const d = x({}), b = d.Provider, S = () => F(d);
12
- function g(o) {
13
- var l;
14
- const { children: n, control: i, ...t } = o, p = (l = S().form) == null ? void 0 : l.control;
15
- return /* @__PURE__ */ r.createElement(
16
- h,
10
+ import { F as g } from "./FieldError-D_VRyiJG.js";
11
+ import { a as P, A as V } from "./Action-C4Ncwjzf.js";
12
+ const b = F({}), A = b.Provider, y = () => v(b);
13
+ function I(c) {
14
+ var r;
15
+ const { children: t, control: i, ...n } = c, a = (r = y().form) == null ? void 0 : r.control;
16
+ return /* @__PURE__ */ o.createElement(
17
+ x,
17
18
  {
18
- ...t,
19
- control: i ?? p,
20
- render: (c) => {
21
- var s;
22
- const { field: u, fieldState: m } = c, e = {
23
- ...u,
24
- isRequired: !!((s = t.rules) != null && s.required),
25
- isInvalid: m.invalid,
19
+ ...n,
20
+ control: i ?? a,
21
+ render: (s) => {
22
+ var u;
23
+ const {
24
+ field: d,
25
+ fieldState: { error: l, invalid: m }
26
+ } = s, e = {
27
+ ...d,
28
+ isRequired: !!((u = n.rules) != null && u.required),
29
+ isInvalid: m,
26
30
  validationBehavior: "aria",
27
- children: E((f) => {
28
- var a;
29
- return /* @__PURE__ */ r.createElement(r.Fragment, null, f.children, /* @__PURE__ */ r.createElement(P, null, (a = m.error) == null ? void 0 : a.message));
30
- })
31
- }, C = {
31
+ children: E((p) => /* @__PURE__ */ o.createElement(o.Fragment, null, p.children, /* @__PURE__ */ o.createElement(g, null, l == null ? void 0 : l.message))),
32
+ ref: void 0,
33
+ refProp: d.ref
34
+ }, f = {
32
35
  Checkbox: e,
33
36
  CheckboxGroup: e,
34
37
  CheckboxButton: e,
@@ -40,25 +43,56 @@ function g(o) {
40
43
  Select: e,
41
44
  Slider: e
42
45
  };
43
- return /* @__PURE__ */ r.createElement(
44
- v,
46
+ return /* @__PURE__ */ o.createElement(
47
+ k,
45
48
  {
46
- props: C,
47
- dependencies: [c]
49
+ props: f,
50
+ dependencies: [s]
48
51
  },
49
- n
52
+ t
50
53
  );
51
54
  }
52
55
  }
53
56
  );
54
57
  }
55
- const A = (o) => g;
56
- function I(o) {
57
- const { form: n, children: i, ...t } = o;
58
- return /* @__PURE__ */ r.createElement(b, { value: { form: n } }, /* @__PURE__ */ r.createElement("form", { ...t }, i));
58
+ const O = (c) => I, D = (c) => {
59
+ const { isStarted: t, hasFailedWithError: i, hasSucceeded: n, children: a } = c, r = P.useNew({});
60
+ return h(() => {
61
+ n ? r.state.onSucceeded() : i ? r.state.onFailed(i) : t && r.state.onAsyncStart();
62
+ }, [t, i, n]), /* @__PURE__ */ o.createElement(V, { actionModel: r }, a);
63
+ };
64
+ function _(c) {
65
+ const { form: t, children: i, onSubmit: n, ...a } = c, { isValid: r, isSubmitted: s, isSubmitting: d, isSubmitSuccessful: l, errors: m } = C(t), e = t.control._formState;
66
+ h(() => {
67
+ s && r && t.reset(void 0, {
68
+ keepIsSubmitted: !1,
69
+ keepIsSubmitSuccessful: !1,
70
+ keepDefaultValues: !0,
71
+ keepValues: !0,
72
+ keepDirtyValues: !0,
73
+ keepIsValid: !0,
74
+ keepDirty: !0,
75
+ keepErrors: !0,
76
+ keepTouched: !0,
77
+ keepIsValidating: !0,
78
+ keepSubmitCount: !0
79
+ });
80
+ }, [s, r]);
81
+ const f = (S) => {
82
+ e.isSubmitting || e.isValidating ? S.preventDefault() : t.handleSubmit(n)(S);
83
+ }, u = s ? m : void 0, p = s && l;
84
+ return /* @__PURE__ */ o.createElement(A, { value: { form: t } }, /* @__PURE__ */ o.createElement("form", { ...a, onSubmit: f }, /* @__PURE__ */ o.createElement(
85
+ D,
86
+ {
87
+ isStarted: d,
88
+ hasFailedWithError: u,
89
+ hasSucceeded: p
90
+ },
91
+ i
92
+ )));
59
93
  }
60
94
  export {
61
- g as Controller,
62
- I as Form,
63
- A as typedController
95
+ I as Field,
96
+ _ as Form,
97
+ O as typedField
64
98
  };
@@ -0,0 +1,9 @@
1
+ import { FC, PropsWithChildren } from 'react';
2
+
3
+ interface Props extends PropsWithChildren {
4
+ isStarted?: boolean;
5
+ hasSucceeded?: boolean;
6
+ hasFailedWithError?: unknown;
7
+ }
8
+ export declare const ActionStateContext: FC<Props>;
9
+ export {};
@@ -1,9 +1,11 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import { OverlayController } from '../../lib/controller';
3
+ import { ActionModel } from './models/ActionModel';
3
4
 
4
5
  export type ActionFn = (...args: unknown[]) => unknown;
5
6
  export interface ActionProps extends PropsWithChildren {
6
7
  action?: ActionFn;
8
+ actionModel?: ActionModel;
7
9
  closeOverlay?: boolean | OverlayController;
8
10
  openOverlay?: boolean | OverlayController;
9
11
  toggleOverlay?: boolean | OverlayController;
@@ -3,6 +3,6 @@ import { ControllerProps, FieldValues, UseFormReturn } from 'react-hook-form';
3
3
 
4
4
  interface Props<T extends FieldValues> extends Omit<ControllerProps<T>, "render">, PropsWithChildren {
5
5
  }
6
- export declare function Controller<T extends FieldValues>(props: Props<T>): React.JSX.Element;
7
- export declare const typedController: <T extends FieldValues>(ignoredForm: UseFormReturn<T>) => typeof Controller<T>;
6
+ export declare function Field<T extends FieldValues>(props: Props<T>): React.JSX.Element;
7
+ export declare const typedField: <T extends FieldValues>(ignoredForm: UseFormReturn<T>) => typeof Field<T>;
8
8
  export {};
@@ -0,0 +1,4 @@
1
+ import { Field } from './Field';
2
+
3
+ export * from './Field';
4
+ export default Field;
@@ -0,0 +1,7 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+ import { Field } from '../../..';
3
+
4
+ declare const meta: Meta<typeof Field>;
5
+ export default meta;
6
+ type Story = StoryObj<typeof Field>;
7
+ export declare const Default: Story;
@@ -1,8 +1,10 @@
1
1
  import { ComponentProps, PropsWithChildren, default as React } from 'react';
2
2
  import { FieldValues, UseFormReturn } from 'react-hook-form';
3
3
 
4
- interface Props<F extends FieldValues> extends ComponentProps<"form">, PropsWithChildren {
5
- form?: UseFormReturn<F>;
4
+ export type FormOnSubmitHandler<F extends FieldValues> = Parameters<UseFormReturn<F>["handleSubmit"]>[0];
5
+ interface Props<F extends FieldValues> extends Omit<ComponentProps<"form">, "onSubmit">, PropsWithChildren {
6
+ form: UseFormReturn<F>;
7
+ onSubmit: FormOnSubmitHandler<F>;
6
8
  }
7
9
  export declare function Form<F extends FieldValues>(props: Props<F>): React.JSX.Element;
8
10
  export {};
@@ -1,2 +1,2 @@
1
- export * from './components/Controller';
1
+ export * from './components/Field';
2
2
  export * from './components/Form';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/flow-react-components",
3
- "version": "0.1.0-alpha.139",
3
+ "version": "0.1.0-alpha.140",
4
4
  "type": "module",
5
5
  "description": "A React implementation of Flow, mittwald’s design system",
6
6
  "homepage": "https://mittwald.github.io/flow",
@@ -275,7 +275,7 @@
275
275
  },
276
276
  "dependencies": {
277
277
  "@chakra-ui/live-region": "^2.1.0",
278
- "@mittwald/react-tunnel": "^0.1.0-alpha.139",
278
+ "@mittwald/react-tunnel": "^0.1.0-alpha.140",
279
279
  "@mittwald/react-use-promise": "^2.3.13",
280
280
  "@react-aria/utils": "^3.24.1",
281
281
  "@react-types/shared": "^3.23.1",
@@ -302,7 +302,7 @@
302
302
  },
303
303
  "devDependencies": {
304
304
  "@faker-js/faker": "^8.4.1",
305
- "@mittwald/flow-design-tokens": "^0.1.0-alpha.139",
305
+ "@mittwald/flow-design-tokens": "^0.1.0-alpha.140",
306
306
  "@mittwald/react-use-promise": "^2.3.13",
307
307
  "@nx/storybook": "^19.1.2",
308
308
  "@storybook/addon-a11y": "^8.1.5",
@@ -378,5 +378,5 @@
378
378
  "optional": true
379
379
  }
380
380
  },
381
- "gitHead": "7d8145a3236ade47017539c4383897c968d801d8"
381
+ "gitHead": "e617717a9569b093c1f19f0923ebf6dce8157c4b"
382
382
  }
@@ -1,4 +0,0 @@
1
- import { Controller } from './Controller';
2
-
3
- export * from './Controller';
4
- export default Controller;
@@ -1,7 +0,0 @@
1
- import { Meta, StoryObj } from '@storybook/react';
2
- import { Controller } from '../../..';
3
-
4
- declare const meta: Meta<typeof Controller>;
5
- export default meta;
6
- type Story = StoryObj<typeof Controller>;
7
- export declare const Default: Story;