@loopr-ai/craft 0.8.1 → 0.8.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.
@@ -1,31 +1,32 @@
1
1
  import { jsx as C, jsxs as F } from "react/jsx-runtime";
2
- import { getColorToHex as v } from "../../../global/colors.js";
3
- import { g as U, c as e, a as t, e as b, _ as D, P as a } from "../../../createTheme-759a022d.js";
4
- import * as p from "react";
5
- import { g as H, s as y, r as A, e as q, a as J, c as R, b as K } from "../../../styled-78608e1f.js";
6
- import { B as Q } from "../../../ButtonBase-08b16b61.js";
7
- function X(o) {
8
- return U("MuiButton", o);
2
+ import * as u from "react";
3
+ import { forwardRef as U } from "react";
4
+ import { getColorToHex as b } from "../../../global/colors.js";
5
+ import { g as D, c as s, a as t, e as g, _ as H, P as a } from "../../../createTheme-759a022d.js";
6
+ import { g as A, s as y, r as q, e as J, a as K, c as R, b as Q } from "../../../styled-78608e1f.js";
7
+ import { B as X } from "../../../ButtonBase-08b16b61.js";
8
+ function Y(o) {
9
+ return D("MuiButton", o);
9
10
  }
10
- const Y = H("MuiButton", ["root", "text", "textInherit", "textPrimary", "textSecondary", "textSuccess", "textError", "textInfo", "textWarning", "outlined", "outlinedInherit", "outlinedPrimary", "outlinedSecondary", "outlinedSuccess", "outlinedError", "outlinedInfo", "outlinedWarning", "contained", "containedInherit", "containedPrimary", "containedSecondary", "containedSuccess", "containedError", "containedInfo", "containedWarning", "disableElevation", "focusVisible", "disabled", "colorInherit", "textSizeSmall", "textSizeMedium", "textSizeLarge", "outlinedSizeSmall", "outlinedSizeMedium", "outlinedSizeLarge", "containedSizeSmall", "containedSizeMedium", "containedSizeLarge", "sizeMedium", "sizeSmall", "sizeLarge", "fullWidth", "startIcon", "endIcon", "iconSizeSmall", "iconSizeMedium", "iconSizeLarge"]), g = Y, k = /* @__PURE__ */ p.createContext({});
11
+ const Z = A("MuiButton", ["root", "text", "textInherit", "textPrimary", "textSecondary", "textSuccess", "textError", "textInfo", "textWarning", "outlined", "outlinedInherit", "outlinedPrimary", "outlinedSecondary", "outlinedSuccess", "outlinedError", "outlinedInfo", "outlinedWarning", "contained", "containedInherit", "containedPrimary", "containedSecondary", "containedSuccess", "containedError", "containedInfo", "containedWarning", "disableElevation", "focusVisible", "disabled", "colorInherit", "textSizeSmall", "textSizeMedium", "textSizeLarge", "outlinedSizeSmall", "outlinedSizeMedium", "outlinedSizeLarge", "containedSizeSmall", "containedSizeMedium", "containedSizeLarge", "sizeMedium", "sizeSmall", "sizeLarge", "fullWidth", "startIcon", "endIcon", "iconSizeSmall", "iconSizeMedium", "iconSizeLarge"]), x = Z, k = /* @__PURE__ */ u.createContext({});
11
12
  process.env.NODE_ENV !== "production" && (k.displayName = "ButtonGroupContext");
12
- const Z = k, N = /* @__PURE__ */ p.createContext(void 0);
13
+ const w = k, N = /* @__PURE__ */ u.createContext(void 0);
13
14
  process.env.NODE_ENV !== "production" && (N.displayName = "ButtonGroupButtonContext");
14
- const w = N, oo = ["children", "color", "component", "className", "disabled", "disableElevation", "disableFocusRipple", "endIcon", "focusVisibleClassName", "fullWidth", "size", "startIcon", "type", "variant"], no = (o) => {
15
+ const oo = N, no = ["children", "color", "component", "className", "disabled", "disableElevation", "disableFocusRipple", "endIcon", "focusVisibleClassName", "fullWidth", "size", "startIcon", "type", "variant"], ao = (o) => {
15
16
  const {
16
17
  color: n,
17
18
  disableElevation: i,
18
- fullWidth: l,
19
+ fullWidth: e,
19
20
  size: r,
20
- variant: c,
21
- classes: s
22
- } = o, x = {
23
- root: ["root", c, `${c}${e(n)}`, `size${e(r)}`, `${c}Size${e(r)}`, n === "inherit" && "colorInherit", i && "disableElevation", l && "fullWidth"],
21
+ variant: l,
22
+ classes: c
23
+ } = o, d = {
24
+ root: ["root", l, `${l}${s(n)}`, `size${s(r)}`, `${l}Size${s(r)}`, n === "inherit" && "colorInherit", i && "disableElevation", e && "fullWidth"],
24
25
  label: ["label"],
25
- startIcon: ["startIcon", `iconSize${e(r)}`],
26
- endIcon: ["endIcon", `iconSize${e(r)}`]
27
- }, f = K(x, X, s);
28
- return t({}, s, f);
26
+ startIcon: ["startIcon", `iconSize${s(r)}`],
27
+ endIcon: ["endIcon", `iconSize${s(r)}`]
28
+ }, f = Q(d, Y, c);
29
+ return t({}, c, f);
29
30
  }, E = (o) => t({}, o.size === "small" && {
30
31
  "& > *:nth-of-type(1)": {
31
32
  fontSize: 18
@@ -38,22 +39,22 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
38
39
  "& > *:nth-of-type(1)": {
39
40
  fontSize: 22
40
41
  }
41
- }), ao = y(Q, {
42
- shouldForwardProp: (o) => A(o) || o === "classes",
42
+ }), io = y(X, {
43
+ shouldForwardProp: (o) => q(o) || o === "classes",
43
44
  name: "MuiButton",
44
45
  slot: "Root",
45
46
  overridesResolver: (o, n) => {
46
47
  const {
47
48
  ownerState: i
48
49
  } = o;
49
- return [n.root, n[i.variant], n[`${i.variant}${e(i.color)}`], n[`size${e(i.size)}`], n[`${i.variant}Size${e(i.size)}`], i.color === "inherit" && n.colorInherit, i.disableElevation && n.disableElevation, i.fullWidth && n.fullWidth];
50
+ return [n.root, n[i.variant], n[`${i.variant}${s(i.color)}`], n[`size${s(i.size)}`], n[`${i.variant}Size${s(i.size)}`], i.color === "inherit" && n.colorInherit, i.disableElevation && n.disableElevation, i.fullWidth && n.fullWidth];
50
51
  }
51
52
  })(({
52
53
  theme: o,
53
54
  ownerState: n
54
55
  }) => {
55
- var i, l;
56
- const r = o.palette.mode === "light" ? o.palette.grey[300] : o.palette.grey[800], c = o.palette.mode === "light" ? o.palette.grey.A100 : o.palette.grey[700];
56
+ var i, e;
57
+ const r = o.palette.mode === "light" ? o.palette.grey[300] : o.palette.grey[800], l = o.palette.mode === "light" ? o.palette.grey.A100 : o.palette.grey[700];
57
58
  return t({}, o.typography.button, {
58
59
  minWidth: 64,
59
60
  padding: "6px 16px",
@@ -63,26 +64,26 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
63
64
  }),
64
65
  "&:hover": t({
65
66
  textDecoration: "none",
66
- backgroundColor: o.vars ? `rgba(${o.vars.palette.text.primaryChannel} / ${o.vars.palette.action.hoverOpacity})` : b(o.palette.text.primary, o.palette.action.hoverOpacity),
67
+ backgroundColor: o.vars ? `rgba(${o.vars.palette.text.primaryChannel} / ${o.vars.palette.action.hoverOpacity})` : g(o.palette.text.primary, o.palette.action.hoverOpacity),
67
68
  // Reset on touch devices, it doesn't add specificity
68
69
  "@media (hover: none)": {
69
70
  backgroundColor: "transparent"
70
71
  }
71
72
  }, n.variant === "text" && n.color !== "inherit" && {
72
- backgroundColor: o.vars ? `rgba(${o.vars.palette[n.color].mainChannel} / ${o.vars.palette.action.hoverOpacity})` : b(o.palette[n.color].main, o.palette.action.hoverOpacity),
73
+ backgroundColor: o.vars ? `rgba(${o.vars.palette[n.color].mainChannel} / ${o.vars.palette.action.hoverOpacity})` : g(o.palette[n.color].main, o.palette.action.hoverOpacity),
73
74
  // Reset on touch devices, it doesn't add specificity
74
75
  "@media (hover: none)": {
75
76
  backgroundColor: "transparent"
76
77
  }
77
78
  }, n.variant === "outlined" && n.color !== "inherit" && {
78
79
  border: `1px solid ${(o.vars || o).palette[n.color].main}`,
79
- backgroundColor: o.vars ? `rgba(${o.vars.palette[n.color].mainChannel} / ${o.vars.palette.action.hoverOpacity})` : b(o.palette[n.color].main, o.palette.action.hoverOpacity),
80
+ backgroundColor: o.vars ? `rgba(${o.vars.palette[n.color].mainChannel} / ${o.vars.palette.action.hoverOpacity})` : g(o.palette[n.color].main, o.palette.action.hoverOpacity),
80
81
  // Reset on touch devices, it doesn't add specificity
81
82
  "@media (hover: none)": {
82
83
  backgroundColor: "transparent"
83
84
  }
84
85
  }, n.variant === "contained" && {
85
- backgroundColor: o.vars ? o.vars.palette.Button.inheritContainedHoverBg : c,
86
+ backgroundColor: o.vars ? o.vars.palette.Button.inheritContainedHoverBg : l,
86
87
  boxShadow: (o.vars || o).shadows[4],
87
88
  // Reset on touch devices, it doesn't add specificity
88
89
  "@media (hover: none)": {
@@ -99,10 +100,10 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
99
100
  "&:active": t({}, n.variant === "contained" && {
100
101
  boxShadow: (o.vars || o).shadows[8]
101
102
  }),
102
- [`&.${g.focusVisible}`]: t({}, n.variant === "contained" && {
103
+ [`&.${x.focusVisible}`]: t({}, n.variant === "contained" && {
103
104
  boxShadow: (o.vars || o).shadows[6]
104
105
  }),
105
- [`&.${g.disabled}`]: t({
106
+ [`&.${x.disabled}`]: t({
106
107
  color: (o.vars || o).palette.action.disabled
107
108
  }, n.variant === "outlined" && {
108
109
  border: `1px solid ${(o.vars || o).palette.action.disabledBackground}`
@@ -120,12 +121,12 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
120
121
  border: "1px solid currentColor"
121
122
  }, n.variant === "outlined" && n.color !== "inherit" && {
122
123
  color: (o.vars || o).palette[n.color].main,
123
- border: o.vars ? `1px solid rgba(${o.vars.palette[n.color].mainChannel} / 0.5)` : `1px solid ${b(o.palette[n.color].main, 0.5)}`
124
+ border: o.vars ? `1px solid rgba(${o.vars.palette[n.color].mainChannel} / 0.5)` : `1px solid ${g(o.palette[n.color].main, 0.5)}`
124
125
  }, n.variant === "contained" && {
125
126
  color: o.vars ? (
126
127
  // this is safe because grey does not change between default light/dark mode
127
128
  o.vars.palette.text.primary
128
- ) : (i = (l = o.palette).getContrastText) == null ? void 0 : i.call(l, o.palette.grey[300]),
129
+ ) : (i = (e = o.palette).getContrastText) == null ? void 0 : i.call(e, o.palette.grey[300]),
129
130
  backgroundColor: o.vars ? o.vars.palette.Button.inheritContainedBg : r,
130
131
  boxShadow: (o.vars || o).shadows[2]
131
132
  }, n.variant === "contained" && n.color !== "inherit" && {
@@ -162,23 +163,23 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
162
163
  "&:hover": {
163
164
  boxShadow: "none"
164
165
  },
165
- [`&.${g.focusVisible}`]: {
166
+ [`&.${x.focusVisible}`]: {
166
167
  boxShadow: "none"
167
168
  },
168
169
  "&:active": {
169
170
  boxShadow: "none"
170
171
  },
171
- [`&.${g.disabled}`]: {
172
+ [`&.${x.disabled}`]: {
172
173
  boxShadow: "none"
173
174
  }
174
- }), io = y("span", {
175
+ }), ro = y("span", {
175
176
  name: "MuiButton",
176
177
  slot: "StartIcon",
177
178
  overridesResolver: (o, n) => {
178
179
  const {
179
180
  ownerState: i
180
181
  } = o;
181
- return [n.startIcon, n[`iconSize${e(i.size)}`]];
182
+ return [n.startIcon, n[`iconSize${s(i.size)}`]];
182
183
  }
183
184
  })(({
184
185
  ownerState: o
@@ -188,14 +189,14 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
188
189
  marginLeft: -4
189
190
  }, o.size === "small" && {
190
191
  marginLeft: -2
191
- }, E(o))), ro = y("span", {
192
+ }, E(o))), to = y("span", {
192
193
  name: "MuiButton",
193
194
  slot: "EndIcon",
194
195
  overridesResolver: (o, n) => {
195
196
  const {
196
197
  ownerState: i
197
198
  } = o;
198
- return [n.endIcon, n[`iconSize${e(i.size)}`]];
199
+ return [n.endIcon, n[`iconSize${s(i.size)}`]];
199
200
  }
200
201
  })(({
201
202
  ownerState: o
@@ -205,12 +206,12 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
205
206
  marginLeft: 8
206
207
  }, o.size === "small" && {
207
208
  marginRight: -2
208
- }, E(o))), O = /* @__PURE__ */ p.forwardRef(function(n, i) {
209
- const l = p.useContext(Z), r = p.useContext(w), c = q(l, n), s = J({
210
- props: c,
209
+ }, E(o))), O = /* @__PURE__ */ u.forwardRef(function(n, i) {
210
+ const e = u.useContext(w), r = u.useContext(oo), l = J(e, n), c = K({
211
+ props: l,
211
212
  name: "MuiButton"
212
213
  }), {
213
- children: x,
214
+ children: d,
214
215
  color: f = "primary",
215
216
  component: z = "button",
216
217
  className: T,
@@ -224,7 +225,7 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
224
225
  startIcon: $,
225
226
  type: h,
226
227
  variant: V = "text"
227
- } = s, L = D(s, oo), u = t({}, s, {
228
+ } = c, L = H(c, no), v = t({}, c, {
228
229
  color: f,
229
230
  component: z,
230
231
  disabled: m,
@@ -234,27 +235,27 @@ const w = N, oo = ["children", "color", "component", "className", "disabled", "d
234
235
  size: S,
235
236
  type: h,
236
237
  variant: V
237
- }), d = no(u), _ = $ && /* @__PURE__ */ C(io, {
238
- className: d.startIcon,
239
- ownerState: u,
238
+ }), p = ao(v), _ = $ && /* @__PURE__ */ C(ro, {
239
+ className: p.startIcon,
240
+ ownerState: v,
240
241
  children: $
241
- }), G = I && /* @__PURE__ */ C(ro, {
242
- className: d.endIcon,
243
- ownerState: u,
242
+ }), G = I && /* @__PURE__ */ C(to, {
243
+ className: p.endIcon,
244
+ ownerState: v,
244
245
  children: I
245
246
  }), j = r || "";
246
- return /* @__PURE__ */ F(ao, t({
247
- ownerState: u,
248
- className: R(l.className, d.root, T, j),
247
+ return /* @__PURE__ */ F(io, t({
248
+ ownerState: v,
249
+ className: R(e.className, p.root, T, j),
249
250
  component: z,
250
251
  disabled: m,
251
252
  focusRipple: !B,
252
- focusVisibleClassName: R(d.focusVisible, W),
253
+ focusVisibleClassName: R(p.focusVisible, W),
253
254
  ref: i,
254
255
  type: h
255
256
  }, L, {
256
- classes: d,
257
- children: [_, x, G]
257
+ classes: p,
258
+ children: [_, d, G]
258
259
  }));
259
260
  });
260
261
  process.env.NODE_ENV !== "production" && (O.propTypes = {
@@ -351,35 +352,47 @@ process.env.NODE_ENV !== "production" && (O.propTypes = {
351
352
  */
352
353
  variant: a.oneOfType([a.oneOf(["contained", "outlined", "text"]), a.string])
353
354
  });
354
- const to = O, uo = ({
355
- variant: o = "contained",
356
- disabled: n = !1,
357
- look: i = "normal",
358
- children: l,
359
- sx: r,
360
- ...c
361
- }) => {
362
- let s = {};
363
- return i === "modified" ? (n === !1 && (s = {
364
- border: "0rem",
365
- backgroundColor: v("modify"),
366
- color: v("primary"),
367
- "&:hover": {
368
- border: "0.0625rem solid",
369
- borderColor: v("primary"),
370
- backgroundColor: v("modify")
371
- }
372
- }), o = "outlined") : o === "contained" && n === !0 && (s = {
373
- "&.Mui-disabled": {
374
- backgroundColor: "#C4C4C4",
375
- color: "#000000",
376
- boxShadow: "none"
377
- }
378
- }), r = {
379
- ...s,
380
- ...r
381
- }, /* @__PURE__ */ C(to, { variant: o, disabled: n, sx: r, ...c, children: l });
382
- };
355
+ const so = O, bo = U(
356
+ ({
357
+ variant: o = "contained",
358
+ disabled: n = !1,
359
+ look: i = "normal",
360
+ children: e,
361
+ sx: r,
362
+ ...l
363
+ }, c) => {
364
+ let d = {};
365
+ return i === "modified" ? (n === !1 && (d = {
366
+ border: "0rem",
367
+ backgroundColor: b("modify"),
368
+ color: b("primary"),
369
+ "&:hover": {
370
+ border: "0.0625rem solid",
371
+ borderColor: b("primary"),
372
+ backgroundColor: b("modify")
373
+ }
374
+ }), o = "outlined") : o === "contained" && n === !0 && (d = {
375
+ "&.Mui-disabled": {
376
+ backgroundColor: "#C4C4C4",
377
+ color: "#000000",
378
+ boxShadow: "none"
379
+ }
380
+ }), r = {
381
+ ...d,
382
+ ...r
383
+ }, /* @__PURE__ */ C(
384
+ so,
385
+ {
386
+ ref: c,
387
+ variant: o,
388
+ disabled: n,
389
+ sx: r,
390
+ ...l,
391
+ children: e
392
+ }
393
+ );
394
+ }
395
+ );
383
396
  export {
384
- uo as default
397
+ bo as default
385
398
  };
@@ -62,4 +62,8 @@ export interface InvalidData {
62
62
  field: string;
63
63
  value: string;
64
64
  }
65
+ export interface FormRefs {
66
+ submitButtonRef: React.RefObject<HTMLButtonElement>;
67
+ cancelButtonRef: React.RefObject<HTMLButtonElement>;
68
+ }
65
69
  export {};
@@ -20,15 +20,20 @@ interface FormProps {
20
20
  }
21
21
  /**
22
22
  * Form component
23
- * @param config - Array of ConfigField objects
23
+ * @param config - Array of form fields
24
24
  * @param submitText - Text for submit button
25
25
  * @param handleSubmit - Function to handle form submission
26
- * @param handleInvalidData - Function to handle invalid form data
26
+ * @param handleInvalidData - Function to handle invalid data
27
27
  * @param cancelText - Text for cancel button
28
28
  * @param handleCancel - Function to handle form cancel
29
29
  * @param onChange - Function to handle form field change
30
- * @param customFields - Custom form fields
31
- * @param style - Form style
30
+ * @param customFields - Object containing custom fields
31
+ * @param formWrapperStyles - Styles for form wrapper
32
+ * @param formFieldsWrapperStyles - Styles for form fields wrapper
33
+ * @param formStyles - Styles for form
34
+ * @param buttonWrapperStyles - Styles for button wrapper
35
+ * @param preFillValues - Object containing pre-fill values
36
+ * @param formAdornments - Object containing form adornments
32
37
  */
33
38
  declare const Form: CraftFC<FormProps>;
34
39
  export default Form;
@@ -1,205 +1,228 @@
1
- import { jsx as u, jsxs as j } from "react/jsx-runtime";
2
- import { useState as v, useCallback as E, useEffect as z } from "react";
3
- import O from "../../cell/Button/index.js";
4
- import { T as G } from "../../../index-c9c32237.js";
5
- import y from "./Form.styles.js";
6
- import { getLocalDateTime as J, createNestedObject as Q, deepMergeObjects as U } from "./Form.utils.js";
7
- import X from "./FormInput.js";
8
- import { s as Y } from "../../../styled-78608e1f.js";
9
- import { B as b } from "../../../Tooltip-e797a425.js";
10
- const Z = Y("div")({
1
+ import { jsx as l, jsxs as E } from "react/jsx-runtime";
2
+ import { forwardRef as X, useState as O, useRef as _, useCallback as V, useEffect as Y, useImperativeHandle as Z } from "react";
3
+ import A from "../../cell/Button/index.js";
4
+ import { T as K } from "../../../index-c9c32237.js";
5
+ import d from "./Form.styles.js";
6
+ import { getLocalDateTime as C, createNestedObject as ee, deepMergeObjects as te } from "./Form.utils.js";
7
+ import se from "./FormInput.js";
8
+ import { s as re } from "../../../styled-78608e1f.js";
9
+ import { B as v } from "../../../Tooltip-e797a425.js";
10
+ const ne = re("div")({
11
11
  marginTop: "0.75rem"
12
- }), ie = ({
13
- config: i,
14
- submitText: _ = "Submit",
15
- handleSubmit: V,
16
- handleInvalidData: h,
17
- cancelText: A = "Cancel",
18
- handleCancel: g,
19
- onChange: f,
20
- formStyles: T = {},
21
- formWrapperStyles: B = {},
22
- formFieldsWrapperStyles: k = {},
23
- buttonWrapperStyles: M = {},
24
- customFields: F = {},
25
- preFillValues: S = {},
26
- formAdornments: N = {}
27
- }) => {
28
- const [l, x] = v({}), [C, d] = v([]);
29
- function D(t, e) {
30
- x((n) => ({
31
- ...n,
32
- [t]: e
33
- })), f == null || f(t, e), d([]);
34
- }
35
- const I = E(() => {
36
- const t = {};
37
- i == null || i.forEach((e) => {
38
- if (e.preFillWithDateTime && e.type === "text") {
39
- const n = J();
40
- t[e.name] = n;
41
- } else
42
- t[e.name] = e.defaultValue || S[e.name] || "";
43
- }), x(t), d([]);
44
- }, [S]);
45
- function W() {
46
- const t = [];
47
- return i == null || i.forEach((e) => {
48
- const { name: n, label: r, type: p, validation: s, required: a } = e, o = l[n], m = n;
49
- if (s)
50
- if (p === "number") {
51
- const c = parseInt(o);
52
- s.min && c < s.min && t.push({
53
- field: m,
54
- value: o,
55
- message: s.invalid_message
56
- }), s.max && c > s.max && t.push({
57
- field: m,
58
- value: o,
59
- message: s.invalid_message
60
- }), isNaN(c) && t.push({
61
- field: m,
62
- value: o,
63
- message: "Invalid number"
64
- });
12
+ }), he = X(
13
+ ({
14
+ config: i,
15
+ submitText: B = "Submit",
16
+ handleSubmit: T,
17
+ handleInvalidData: h,
18
+ cancelText: R = "Cancel",
19
+ handleCancel: g,
20
+ onChange: a,
21
+ formStyles: k = {},
22
+ formWrapperStyles: I = {},
23
+ formFieldsWrapperStyles: M = {},
24
+ buttonWrapperStyles: N = {},
25
+ customFields: F = {},
26
+ preFillValues: x = {},
27
+ formAdornments: w = {}
28
+ }, D) => {
29
+ const [c, b] = O({}), [W, y] = O([]), S = _(null), j = _(null);
30
+ function q(t, e) {
31
+ b((r) => ({
32
+ ...r,
33
+ [t]: e
34
+ })), a == null || a(t, e), y([]);
35
+ }
36
+ const H = V(() => {
37
+ const t = {};
38
+ i == null || i.forEach((e) => {
39
+ if (e.preFillWithDateTime && e.type === "text") {
40
+ const r = C();
41
+ t[e.name] = r, a == null || a(e.name, r);
65
42
  } else
66
- p === "text" && (s.min_length && o.length < s.min_length && t.push({
67
- field: m,
68
- value: o,
69
- message: s.invalid_message
70
- }), s.max_length && o.length > s.max_length && t.push({
71
- field: m,
72
- value: o,
73
- message: s.invalid_message
74
- }), s.pattern && !new RegExp(s.pattern).test(o) && t.push({
75
- field: m,
76
- value: o,
77
- message: s.invalid_message
78
- }));
79
- a && !o && t.push({
80
- field: m,
81
- value: o,
82
- message: `${r} is required`
83
- });
84
- }), d(t), t.length && (h == null || h(t)), !t.length;
85
- }
86
- const q = E(
87
- (t) => {
88
- let e = {};
89
- return t == null || t.forEach((n) => {
90
- const { name: r, type: p, submitDataKey: s } = n, a = p === "number" ? parseInt(l[r]) : l[r];
91
- function o(m) {
92
- if (m.indexOf(".") !== -1) {
93
- const c = Q(
94
- m,
95
- p,
96
- l[r]
97
- );
98
- e = U(e, c);
43
+ t[e.name] = e.defaultValue || x[e.name] || "", a == null || a(
44
+ e.name,
45
+ e.defaultValue || x[e.name] || ""
46
+ );
47
+ }), b(t), y([]);
48
+ }, [x]);
49
+ function P() {
50
+ const t = [];
51
+ return i == null || i.forEach((e) => {
52
+ const { name: r, label: n, type: p, validation: s, required: u } = e, m = c[r], o = r;
53
+ if (s)
54
+ if (p === "number") {
55
+ const f = parseInt(m);
56
+ s.min && f < s.min && t.push({
57
+ field: o,
58
+ value: m,
59
+ message: s.invalid_message
60
+ }), s.max && f > s.max && t.push({
61
+ field: o,
62
+ value: m,
63
+ message: s.invalid_message
64
+ }), isNaN(f) && t.push({
65
+ field: o,
66
+ value: m,
67
+ message: "Invalid number"
68
+ });
99
69
  } else
100
- e[m] = a;
101
- }
102
- typeof s != "string" && (s != null && s.length) ? s.forEach((m) => {
103
- o(m);
104
- }) : typeof s == "string" && s ? o(s) : e[r] = a;
105
- }), e;
106
- },
107
- [l]
108
- );
109
- function w(t) {
110
- if (t.preventDefault(), W()) {
111
- const n = q(i);
112
- V(n);
70
+ p === "text" && (s.min_length && m.length < s.min_length && t.push({
71
+ field: o,
72
+ value: m,
73
+ message: s.invalid_message
74
+ }), s.max_length && m.length > s.max_length && t.push({
75
+ field: o,
76
+ value: m,
77
+ message: s.invalid_message
78
+ }), s.pattern && !new RegExp(s.pattern).test(m) && t.push({
79
+ field: o,
80
+ value: m,
81
+ message: s.invalid_message
82
+ }));
83
+ u && !m && t.push({
84
+ field: o,
85
+ value: m,
86
+ message: `${n} is required`
87
+ });
88
+ }), y(t), t.length && (h == null || h(t)), !t.length;
113
89
  }
114
- }
115
- function P() {
116
- x((t) => {
117
- const e = { ...t };
118
- return Object.keys(e).forEach((n) => {
119
- e[n] = "";
120
- }), e;
121
- }), g == null || g();
122
- }
123
- function $(t) {
124
- const e = C.find(
125
- (r) => r.field === t.name
126
- ), n = {
127
- ...t,
128
- value: l[t.name],
129
- handleChange: D,
130
- error: !!e,
131
- helperText: e == null ? void 0 : e.message,
132
- inputAdornments: N[t.name] || {}
133
- };
134
- if (t.hidden)
135
- return null;
136
- if (t.type === "custom" && t.customComponent && F[t.customComponent]) {
137
- const { component: r, props: p } = F[t.customComponent], s = r, a = {
138
- ...n,
139
- ...p
90
+ const $ = V(
91
+ (t) => {
92
+ let e = {};
93
+ return t == null || t.forEach((r) => {
94
+ const { name: n, type: p, submitDataKey: s } = r, u = p === "number" ? parseInt(c[n]) : c[n];
95
+ function m(o) {
96
+ if (o.indexOf(".") !== -1) {
97
+ const f = ee(
98
+ o,
99
+ p,
100
+ c[n]
101
+ );
102
+ e = te(
103
+ e,
104
+ f
105
+ );
106
+ } else
107
+ e[o] = u;
108
+ }
109
+ typeof s != "string" && (s != null && s.length) ? s.forEach((o) => {
110
+ m(o);
111
+ }) : typeof s == "string" && s ? m(s) : e[n] = u;
112
+ }), e;
113
+ },
114
+ [c]
115
+ );
116
+ function L(t) {
117
+ if (t.preventDefault(), P()) {
118
+ const r = $(i);
119
+ T(r);
120
+ }
121
+ }
122
+ function z() {
123
+ b((t) => {
124
+ const e = { ...t };
125
+ return Object.keys(e).forEach((r) => {
126
+ e[r] = "";
127
+ }), e;
128
+ }), g == null || g();
129
+ }
130
+ function G(t) {
131
+ const e = W.find(
132
+ (n) => n.field === t.name
133
+ ), r = {
134
+ ...t,
135
+ value: c[t.name],
136
+ handleChange: q,
137
+ error: !!e,
138
+ helperText: e == null ? void 0 : e.message,
139
+ inputAdornments: w[t.name] || {}
140
140
  };
141
- if (s && a)
142
- return /* @__PURE__ */ u(s, { ...a }, t.name);
143
- } else
144
- return /* @__PURE__ */ u(X, { ...n }, t.name);
145
- }
146
- function H() {
147
- return i.reduce(
148
- (e, n) => {
149
- const { groupName: r } = n;
150
- if (!e.length)
151
- e.push(r ? [r, n] : [n]);
152
- else if (r) {
153
- const s = e.findIndex((a) => a[0] === r);
154
- s === -1 ? e.push([r, n]) : e[s].push(n);
155
- } else {
156
- const s = e[e.length - 1];
157
- typeof s[0] == "string" ? e.push([n]) : s.push(n);
141
+ if (t.hidden)
142
+ return null;
143
+ if (t.type === "custom" && t.customComponent && F[t.customComponent]) {
144
+ const { component: n, props: p } = F[t.customComponent], s = n, u = {
145
+ ...r,
146
+ ...p
147
+ };
148
+ if (s && u)
149
+ return /* @__PURE__ */ l(s, { ...u }, t.name);
150
+ } else
151
+ return /* @__PURE__ */ l(se, { ...r }, t.name);
152
+ }
153
+ function J() {
154
+ return i.reduce(
155
+ (e, r) => {
156
+ const { groupName: n } = r;
157
+ if (!e.length)
158
+ e.push(n ? [n, r] : [r]);
159
+ else if (n) {
160
+ const s = e.findIndex((u) => u[0] === n);
161
+ s === -1 ? e.push([n, r]) : e[s].push(r);
162
+ } else {
163
+ const s = e[e.length - 1];
164
+ typeof s[0] == "string" ? e.push([r]) : s.push(r);
165
+ }
166
+ return e;
167
+ },
168
+ []
169
+ ).map(
170
+ (e) => {
171
+ const r = typeof e[0] == "string";
172
+ return /* @__PURE__ */ l(
173
+ ne,
174
+ {
175
+ children: e.map((n) => typeof n == "string" ? /* @__PURE__ */ l(
176
+ K,
177
+ {
178
+ type: "headingSmall",
179
+ sx: d.heading,
180
+ children: n
181
+ },
182
+ n
183
+ ) : G(n))
184
+ },
185
+ `group-${r ? e[0] : e[0].name}`
186
+ );
158
187
  }
159
- return e;
160
- },
188
+ );
189
+ }
190
+ Y(() => {
191
+ H();
192
+ }, []);
193
+ const Q = {
194
+ ...d.alignVertical,
195
+ ...k
196
+ }, U = {
197
+ ...d.alignVertical,
198
+ marginTop: "1rem",
199
+ gap: "0.5rem",
200
+ ...N
201
+ };
202
+ return Z(
203
+ D,
204
+ () => ({
205
+ submitButtonRef: S,
206
+ cancelButtonRef: j
207
+ }),
161
208
  []
162
- ).map(
163
- (e) => {
164
- const n = typeof e[0] == "string";
165
- return /* @__PURE__ */ u(
166
- Z,
209
+ ), /* @__PURE__ */ l(v, { sx: I, children: /* @__PURE__ */ E("form", { style: Q, children: [
210
+ /* @__PURE__ */ l(v, { sx: M, children: Object.keys(c).length && J() }),
211
+ /* @__PURE__ */ E(v, { sx: U, children: [
212
+ /* @__PURE__ */ l(
213
+ A,
167
214
  {
168
- children: e.map((r) => typeof r == "string" ? /* @__PURE__ */ u(
169
- G,
170
- {
171
- type: "headingSmall",
172
- sx: y.heading,
173
- children: r
174
- },
175
- r
176
- ) : $(r))
177
- },
178
- `group-${n ? e[0] : e[0].name}`
179
- );
180
- }
181
- );
215
+ ref: S,
216
+ type: "submit",
217
+ onClick: L,
218
+ children: B
219
+ }
220
+ ),
221
+ /* @__PURE__ */ l(A, { ref: j, onClick: z, children: R })
222
+ ] })
223
+ ] }) });
182
224
  }
183
- z(() => {
184
- I();
185
- }, []);
186
- const L = {
187
- ...y.alignVertical,
188
- ...T
189
- }, R = {
190
- ...y.alignVertical,
191
- marginTop: "1rem",
192
- gap: "0.5rem",
193
- ...M
194
- };
195
- return /* @__PURE__ */ u(b, { sx: B, children: /* @__PURE__ */ j("form", { style: L, children: [
196
- /* @__PURE__ */ u(b, { sx: k, children: Object.keys(l).length && H() }),
197
- /* @__PURE__ */ j(b, { sx: R, children: [
198
- /* @__PURE__ */ u(O, { type: "submit", onClick: w, children: _ }),
199
- /* @__PURE__ */ u(O, { onClick: P, children: A })
200
- ] })
201
- ] }) });
202
- };
225
+ );
203
226
  export {
204
- ie as default
227
+ he as default
205
228
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loopr-ai/craft",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Component library based out of Material UI customized to support Loopr AI products",
5
5
  "homepage": "https://loopr.ai",
6
6
  "author": {