@loopr-ai/craft 0.7.5 → 0.7.6

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.
@@ -38,7 +38,7 @@ interface Validation {
38
38
  export interface ConfigField extends SelectField {
39
39
  validation?: Validation;
40
40
  customComponent?: string;
41
- submitDataKey?: string;
41
+ submitDataKey: Array<string> | string;
42
42
  preFillWithDateTime?: boolean;
43
43
  groupName?: string;
44
44
  hidden?: boolean;
@@ -1,192 +1,197 @@
1
- import { jsx as u, jsxs as j } from "react/jsx-runtime";
2
- import { useState as v, useCallback as H, useEffect as K } from "react";
3
- import S from "../../cell/Button/index.js";
4
- import { T as L } from "../../../index-03287c17.js";
5
- import f from "./Form.styles.js";
6
- import { createNestedObject as R, deepMergeObjects as z, getLocalDateTime as G } from "./Form.utils.js";
7
- import J from "./FormInput.js";
8
- import { s as Q } from "../../../styled-126c6a62.js";
9
- import { B as b } from "../../../Tooltip-b926c320.js";
10
- const U = Q("div")({
1
+ import { jsx as u, jsxs as v } from "react/jsx-runtime";
2
+ import { useState as S, useCallback as H, useEffect as L } from "react";
3
+ import j from "../../cell/Button/index.js";
4
+ import { T as R } from "../../../index-03287c17.js";
5
+ import d from "./Form.styles.js";
6
+ import { getLocalDateTime as z, createNestedObject as G, deepMergeObjects as J } from "./Form.utils.js";
7
+ import Q from "./FormInput.js";
8
+ import { s as U } from "../../../styled-126c6a62.js";
9
+ import { B as x } from "../../../Tooltip-b926c320.js";
10
+ const X = U("div")({
11
11
  marginTop: "0.75rem"
12
- }), oe = ({
13
- config: o,
12
+ }), me = ({
13
+ config: i,
14
14
  submitText: V = "Submit",
15
15
  handleSubmit: _,
16
- handleInvalidData: c,
17
- cancelText: C = "Cancel",
18
- handleCancel: E,
19
- onChange: h,
20
- formStyles: O = {},
16
+ handleInvalidData: h,
17
+ cancelText: E = "Cancel",
18
+ handleCancel: O,
19
+ onChange: f,
20
+ formStyles: C = {},
21
21
  formWrapperStyles: T = {},
22
22
  formFieldsWrapperStyles: A = {},
23
- buttonWrapperStyles: D = {},
24
- customFields: x = {}
23
+ buttonWrapperStyles: B = {},
24
+ customFields: y = {}
25
25
  }) => {
26
- const [p, y] = v({}), [B, g] = v([]);
27
- function M(e, t) {
28
- y((n) => ({
26
+ const [l, b] = S({}), [M, g] = S([]);
27
+ function N(t, e) {
28
+ b((n) => ({
29
29
  ...n,
30
- [e]: t
31
- })), h == null || h(e, t), g([]);
30
+ [t]: e
31
+ })), f == null || f(t, e), g([]);
32
32
  }
33
33
  function F() {
34
- const e = {};
35
- o == null || o.forEach((t) => {
36
- if (t.preFillWithDateTime && t.type === "text") {
37
- const n = G();
38
- e[t.name] = n;
34
+ const t = {};
35
+ i == null || i.forEach((e) => {
36
+ if (e.preFillWithDateTime && e.type === "text") {
37
+ const n = z();
38
+ t[e.name] = n;
39
39
  } else
40
- e[t.name] = t.defaultValue || "";
41
- }), y(e), g([]);
40
+ t[e.name] = e.defaultValue || "";
41
+ }), b(t), g([]);
42
42
  }
43
- function N() {
44
- const e = [];
45
- return o == null || o.forEach((t) => {
46
- const { name: n, label: r, type: a, validation: s, required: i } = t, m = p[n], l = n;
43
+ function k() {
44
+ const t = [];
45
+ return i == null || i.forEach((e) => {
46
+ const { name: n, label: r, type: p, validation: s, required: a } = e, o = l[n], m = n;
47
47
  if (s)
48
- if (a === "number") {
49
- const d = parseInt(m);
50
- s.min && d < s.min && e.push({
51
- field: l,
52
- value: m,
48
+ if (p === "number") {
49
+ const c = parseInt(o);
50
+ s.min && c < s.min && t.push({
51
+ field: m,
52
+ value: o,
53
53
  message: s.invalid_message
54
- }), s.max && d > s.max && e.push({
55
- field: l,
56
- value: m,
54
+ }), s.max && c > s.max && t.push({
55
+ field: m,
56
+ value: o,
57
57
  message: s.invalid_message
58
- }), isNaN(d) && e.push({
59
- field: l,
60
- value: m,
58
+ }), isNaN(c) && t.push({
59
+ field: m,
60
+ value: o,
61
61
  message: "Invalid number"
62
62
  });
63
63
  } else
64
- a === "text" && (s.min_length && m.length < s.min_length && e.push({
65
- field: l,
66
- value: m,
64
+ p === "text" && (s.min_length && o.length < s.min_length && t.push({
65
+ field: m,
66
+ value: o,
67
67
  message: s.invalid_message
68
- }), s.max_length && m.length > s.max_length && e.push({
69
- field: l,
70
- value: m,
68
+ }), s.max_length && o.length > s.max_length && t.push({
69
+ field: m,
70
+ value: o,
71
71
  message: s.invalid_message
72
- }), s.pattern && !new RegExp(s.pattern).test(m) && e.push({
73
- field: l,
74
- value: m,
72
+ }), s.pattern && !new RegExp(s.pattern).test(o) && t.push({
73
+ field: m,
74
+ value: o,
75
75
  message: s.invalid_message
76
76
  }));
77
- i && !m && e.push({
78
- field: l,
79
- value: m,
77
+ a && !o && t.push({
78
+ field: m,
79
+ value: o,
80
80
  message: `${r} is required`
81
81
  });
82
- }), g(e), e.length && (c == null || c(e)), !e.length;
82
+ }), g(t), t.length && (h == null || h(t)), !t.length;
83
83
  }
84
- const k = H(
85
- (e) => {
86
- let t = {};
87
- return e == null || e.forEach((n) => {
88
- const { name: r, type: a, submitDataKey: s } = n;
89
- if (s) {
90
- const i = R(
91
- s,
92
- a,
93
- p[r]
94
- );
95
- t = z(t, i);
96
- } else
97
- t[r] = a === "number" ? parseInt(p[r]) : p[r];
98
- }), t;
84
+ const D = H(
85
+ (t) => {
86
+ let e = {};
87
+ return t == null || t.forEach((n) => {
88
+ const { name: r, type: p, submitDataKey: s } = n, a = p === "number" ? parseInt(l[r]) : l[r];
89
+ function o(m) {
90
+ if (m.indexOf(".") !== -1) {
91
+ const c = G(
92
+ m,
93
+ p,
94
+ l[r]
95
+ );
96
+ e = J(e, c);
97
+ } else
98
+ e[m] = a;
99
+ }
100
+ typeof s != "string" && (s != null && s.length) ? s.forEach((m) => {
101
+ o(m);
102
+ }) : typeof s == "string" && s ? o(s) : e[r] = a;
103
+ }), e;
99
104
  },
100
- [p]
105
+ [l]
101
106
  );
102
- function I(e) {
103
- if (e.preventDefault(), N()) {
104
- const n = k(o);
107
+ function I(t) {
108
+ if (t.preventDefault(), k()) {
109
+ const n = D(i);
105
110
  _(n);
106
111
  }
107
112
  }
108
113
  function W() {
109
- F(), E();
114
+ F(), O();
110
115
  }
111
- function q(e) {
112
- const t = B.find(
113
- (r) => r.field === e.name
116
+ function q(t) {
117
+ const e = M.find(
118
+ (r) => r.field === t.name
114
119
  ), n = {
115
- ...e,
116
- value: p[e.name],
117
- handleChange: M,
118
- error: !!t,
119
- helperText: t == null ? void 0 : t.message
120
+ ...t,
121
+ value: l[t.name],
122
+ handleChange: N,
123
+ error: !!e,
124
+ helperText: e == null ? void 0 : e.message
120
125
  };
121
- if (e.hidden)
126
+ if (t.hidden)
122
127
  return null;
123
- if (e.type === "custom" && e.customComponent && x[e.customComponent]) {
124
- const { component: r, props: a } = x[e.customComponent], s = r, i = {
128
+ if (t.type === "custom" && t.customComponent && y[t.customComponent]) {
129
+ const { component: r, props: p } = y[t.customComponent], s = r, a = {
125
130
  ...n,
126
- ...a
131
+ ...p
127
132
  };
128
- if (s && i)
129
- return /* @__PURE__ */ u(s, { ...i }, e.name);
133
+ if (s && a)
134
+ return /* @__PURE__ */ u(s, { ...a }, t.name);
130
135
  } else
131
- return /* @__PURE__ */ u(J, { ...n }, e.name);
136
+ return /* @__PURE__ */ u(Q, { ...n }, t.name);
132
137
  }
133
138
  function P() {
134
- return o.reduce(
135
- (t, n) => {
139
+ return i.reduce(
140
+ (e, n) => {
136
141
  const { groupName: r } = n;
137
- if (!t.length)
138
- t.push(r ? [r, n] : [n]);
142
+ if (!e.length)
143
+ e.push(r ? [r, n] : [n]);
139
144
  else if (r) {
140
- const s = t.findIndex((i) => i[0] === r);
141
- s === -1 ? t.push([r, n]) : t[s].push(n);
145
+ const s = e.findIndex((a) => a[0] === r);
146
+ s === -1 ? e.push([r, n]) : e[s].push(n);
142
147
  } else {
143
- const s = t[t.length - 1];
144
- typeof s[0] == "string" ? t.push([n]) : s.push(n);
148
+ const s = e[e.length - 1];
149
+ typeof s[0] == "string" ? e.push([n]) : s.push(n);
145
150
  }
146
- return t;
151
+ return e;
147
152
  },
148
153
  []
149
154
  ).map(
150
- (t) => {
151
- const n = typeof t[0] == "string";
155
+ (e) => {
156
+ const n = typeof e[0] == "string";
152
157
  return /* @__PURE__ */ u(
153
- U,
158
+ X,
154
159
  {
155
- children: t.map((r) => typeof r == "string" ? /* @__PURE__ */ u(
156
- L,
160
+ children: e.map((r) => typeof r == "string" ? /* @__PURE__ */ u(
161
+ R,
157
162
  {
158
163
  type: "headingSmall",
159
- sx: f.heading,
164
+ sx: d.heading,
160
165
  children: r
161
166
  },
162
167
  r
163
168
  ) : q(r))
164
169
  },
165
- `group-${n ? t[0] : t[0].name}`
170
+ `group-${n ? e[0] : e[0].name}`
166
171
  );
167
172
  }
168
173
  );
169
174
  }
170
- K(() => {
175
+ L(() => {
171
176
  F();
172
177
  }, []);
173
178
  const $ = {
174
- ...f.alignVertical,
175
- ...O
179
+ ...d.alignVertical,
180
+ ...C
176
181
  }, w = {
177
- ...f.alignVertical,
182
+ ...d.alignVertical,
178
183
  marginTop: "1rem",
179
184
  gap: "0.5rem",
180
- ...D
185
+ ...B
181
186
  };
182
- return /* @__PURE__ */ u(b, { sx: T, children: /* @__PURE__ */ j("form", { style: $, children: [
183
- /* @__PURE__ */ u(b, { sx: A, children: Object.keys(p).length && P() }),
184
- /* @__PURE__ */ j(b, { sx: w, children: [
185
- /* @__PURE__ */ u(S, { type: "submit", onClick: I, children: V }),
186
- /* @__PURE__ */ u(S, { onClick: W, children: C })
187
+ return /* @__PURE__ */ u(x, { sx: T, children: /* @__PURE__ */ v("form", { style: $, children: [
188
+ /* @__PURE__ */ u(x, { sx: A, children: Object.keys(l).length && P() }),
189
+ /* @__PURE__ */ v(x, { sx: w, children: [
190
+ /* @__PURE__ */ u(j, { type: "submit", onClick: I, children: V }),
191
+ /* @__PURE__ */ u(j, { onClick: W, children: E })
187
192
  ] })
188
193
  ] }) });
189
194
  };
190
195
  export {
191
- oe as default
196
+ me as default
192
197
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loopr-ai/craft",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
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": {