@levo-so/studio 0.1.104 → 0.1.106

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,4 +1,4 @@
1
- import { m as e } from "./widgets-eu5zXTf-.js";
1
+ import { m as e } from "./widgets-NzmPF3Ji.js";
2
2
  //#region ../../libraries/react-collection/dist/utils.js
3
3
  var t = (t) => Object.entries(e).find(([e, n]) => Object.keys(n).includes(t))?.[0];
4
4
  //#endregion
@@ -0,0 +1,215 @@
1
+ import e from "react";
2
+ import { FieldInterfaces as t, FieldInterfacesList as n, defaultByKinds as r, formatsByInterface as i, interfaceKinds as a } from "@levo-so/core";
3
+ import { Snowflake as o } from "@theinternetfolks/snowflake";
4
+ import { isPossiblePhoneNumber as s } from "react-phone-number-input";
5
+ import * as c from "yup";
6
+ //#region ../../libraries/react-collection/dist/constants/fileUploadPresets.js
7
+ var l = [
8
+ "pdf",
9
+ "xls",
10
+ "xlsx",
11
+ "doc",
12
+ "docx",
13
+ "csv"
14
+ ], u = [
15
+ "svg",
16
+ "png",
17
+ "jpg",
18
+ "jpeg",
19
+ "webp",
20
+ "gif",
21
+ "avif"
22
+ ], d = ["mpeg", "mp4"], f = [
23
+ "mp3",
24
+ "ogg",
25
+ "oga"
26
+ ], p = {
27
+ audio: {
28
+ "audio/mpeg": [".mp3"],
29
+ "audio/ogg": [".oga"]
30
+ },
31
+ document: {
32
+ "application/pdf": [".pdf"],
33
+ "application/msword": [".doc"],
34
+ "application/vnd.ms-excel": [".xls"],
35
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [".xlsx"],
36
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [".docx"],
37
+ "text/csv": [".csv"]
38
+ },
39
+ image: {
40
+ "image/jpeg": [".jpeg", ".jpg"],
41
+ "image/png": [".png"],
42
+ "image/gif": [".gif"],
43
+ "image/svg+xml": [".svg"],
44
+ "image/webp": [".webp"],
45
+ "image/avif": [".avif"]
46
+ },
47
+ video: {
48
+ "video/mp4": [".mp4"],
49
+ "video/mpeg": [".mpeg"]
50
+ }
51
+ }, m = {
52
+ audio: f,
53
+ document: l,
54
+ image: u,
55
+ video: d
56
+ };
57
+ [
58
+ ...m.audio,
59
+ ...m.document,
60
+ ...m.image,
61
+ ...m.video
62
+ ], {
63
+ ...p.audio,
64
+ ...p.document,
65
+ ...p.image,
66
+ ...p.video
67
+ };
68
+ //#endregion
69
+ //#region ../../libraries/react-collection/dist/utils/formHelpers.js
70
+ var h = (e) => {
71
+ let t = [];
72
+ for (let n of Object.keys(e)) for (let r of e?.[n] || []) t.push({
73
+ message: r,
74
+ name: n
75
+ });
76
+ return t;
77
+ }, g = (e) => e ? s(e) : !1, _ = (e, t) => {
78
+ let n = [];
79
+ for (let [r, i] of Object.entries(t)) {
80
+ let t = e?.[r], a = c.string();
81
+ for (let e of i) if (typeof e == "string") switch (e) {
82
+ case "required":
83
+ a = a.required(`The ${r} field is required`);
84
+ break;
85
+ case "email":
86
+ a = a.email("The email address is not valid");
87
+ break;
88
+ case "phone_number":
89
+ a = a.test("phone", "The phone number has incorrect format", (e) => e ? g(e) : !0);
90
+ break;
91
+ case "url":
92
+ a = a.url("The URL is not valid");
93
+ break;
94
+ case "data_uri":
95
+ a = a.test("data_uri", "The field does not have a valid file", (e) => typeof e == "string" ? e.startsWith("data:") && e.includes(",") : !1);
96
+ break;
97
+ }
98
+ else if (typeof e == "object" && e) {
99
+ let t = e;
100
+ "max" in e && t.max?.[0] && (a = a.max(Number(t.max[0]))), "min" in e && t.min?.[0] && (a = a.min(Number(t.min[0])));
101
+ }
102
+ try {
103
+ a.validateSync(t);
104
+ } catch (e) {
105
+ e instanceof c.ValidationError && n.push({
106
+ message: e.message,
107
+ name: r
108
+ });
109
+ }
110
+ }
111
+ return n.length > 0 ? {
112
+ status: !1,
113
+ errors: n
114
+ } : { status: !0 };
115
+ }, v = (e, n) => {
116
+ let r = {};
117
+ for (let n of e.sections) for (let e of n.fields) {
118
+ let n = [];
119
+ switch (e.required && n.push("required"), e.max !== void 0 && e.max !== null && n.push({ max: [e.max] }), e.min !== void 0 && e.min !== null && n.push({ min: [e.min] }), e.field_interface) {
120
+ case t.EmailWidget:
121
+ n.push("email");
122
+ break;
123
+ case t.PhoneWidget:
124
+ n.push("phone_number");
125
+ break;
126
+ case t.URLWidget:
127
+ n.push("url");
128
+ break;
129
+ default: break;
130
+ }
131
+ r[e.key] = n;
132
+ }
133
+ let { errors: i } = _(n, r), a = {};
134
+ return i && i.map((e) => {
135
+ a[e.name] = e.message;
136
+ }), a;
137
+ }, y = (e) => {
138
+ let n = {};
139
+ for (let i of e) {
140
+ if (i.kind === "collection") {
141
+ let e = i.options?.current_have_many_connected, t = i.options?.connected_have_many_current;
142
+ e && t ? n[i.key] = r.collection.m2m : n[i.key] = r.collection.m2o;
143
+ } else n[i.key] = r?.[i?.kind];
144
+ i?.field_interface === t.RecordWidget && i?.fields?.length && (n[i.key] = y(i.fields));
145
+ }
146
+ return n;
147
+ }, b = (e) => {
148
+ if (!e?.sections) return {};
149
+ let t = {};
150
+ for (let n of e.sections) n?.fields && n?.fields?.length > 0 && (t = {
151
+ ...t,
152
+ ...y(n.fields)
153
+ });
154
+ return t;
155
+ }, x = (e) => e === void 0 ? null : e, S = (e, t) => {
156
+ if (!e?.sections) return {};
157
+ let n = {};
158
+ for (let r of e.sections) {
159
+ let e = y(r.fields ?? []);
160
+ for (let i of r.fields) {
161
+ let r = x(t?.[i?.key]);
162
+ Array.isArray(r) && r?.length > 0 && Array.isArray(i?.values) && i?.values?.length > 0 && !i?.options?.custom_input && (r = r?.filter((e) => i?.values?.includes(e))), n[i.key] = r ?? x(i?.default_value) ?? e[i.key];
163
+ }
164
+ }
165
+ return n;
166
+ }, C = (e, s) => {
167
+ let c = { ...e }, l = null;
168
+ if ((c.field_interface === t.ArrayWidget && s !== t.ArrayWidget || c.field_interface === t.RecordWidget && s !== t.RecordWidget) && (c.fields = []), (s !== t.MultiDropdownWidget || s !== t.DropdownWidget || s !== t.RadioWidget || s !== t.CheckboxWidget) && c.field_interface !== t.MultiDropdownWidget && c.field_interface !== t.DropdownWidget && c.field_interface !== t.RadioWidget && c.field_interface !== t.CheckboxWidget && c.values?.length !== 0 && (c.values = []), (s === t.MultiDropdownWidget && c.field_interface !== t.MultiDropdownWidget || s === t.DropdownWidget && c.field_interface !== t.DropdownWidget || s === t.RadioWidget && c.field_interface !== t.RadioWidget || s === t.CheckboxWidget && c.field_interface !== t.CheckboxWidget) && (c.values = [""], l = `${c.id}-option-0`), [t.RecordWidget, t.ArrayWidget].includes(s) && (l = `field-${o.generate()}`, c.kind = s === t.RecordWidget ? "record" : "group", c.fields = [...c?.fields || [], {
169
+ id: l,
170
+ key: "title",
171
+ label: "Title",
172
+ helper_text: "",
173
+ kind: "string",
174
+ field_interface: t.TextWidget,
175
+ default_value: "",
176
+ options: {},
177
+ fields: [],
178
+ hidden: !1,
179
+ readonly: !1,
180
+ required: !1,
181
+ unique: !1,
182
+ min: null,
183
+ max: null,
184
+ formats: i[s] || [],
185
+ values: [],
186
+ editable: !0
187
+ }]), c.kind = a[s] || "string", !c.default_value) if (c.kind === "collection") {
188
+ let e = c.options?.current_have_many_connected, t = c.options?.connected_have_many_current;
189
+ e && t ? c.default_value = r.collection.m2m : c.default_value = r.collection.m2o;
190
+ } else c.default_value = r[c.kind] || null;
191
+ return s !== t.CollectionWidget && n.includes(s) && (c.field_interface = s), {
192
+ field: c,
193
+ fieldFocused: l
194
+ };
195
+ }, w = (e, t) => {
196
+ let n = {};
197
+ if (t) for (let r of t?.sections ?? []) for (let t of r?.fields) if (t.field_interface === "CollectionWidget") {
198
+ let r = e?.[t?.key];
199
+ r && typeof r == "object" && (Array.isArray(r) ? n[t?.key] = r?.filter((e) => e) : n[t?.key] = r._id);
200
+ } else n[t?.key] = e?.[t?.key];
201
+ return n;
202
+ }, T = (e) => e.every((e) => {
203
+ let { field_interface: t = "", key: n = "", hidden: r } = e;
204
+ return !t || !n || r;
205
+ }), E = (e, t) => {
206
+ if (Array.isArray(e) && e.length > 0) {
207
+ let n = 0;
208
+ for (let r of e) n += 1, r?.param && t && t(r?.param, {
209
+ type: "server_error",
210
+ message: r?.message
211
+ }, { shouldFocus: n === 0 });
212
+ }
213
+ }, D = (t) => e.memo(t);
214
+ //#endregion
215
+ export { v as a, S as c, b as d, T as f, h as i, g as l, p as m, E as n, y as o, m as p, w as r, C as s, D as t, x as u };
@@ -1,230 +0,0 @@
1
- import { n as e } from "./theme.cssm-BXDp-ojp.js";
2
- import t from "react";
3
- import { FieldInterfaces as n, FieldInterfacesList as r, defaultByKinds as i, formatsByInterface as a, interfaceKinds as o } from "@levo-so/core";
4
- import { Snowflake as s } from "@theinternetfolks/snowflake";
5
- import { isPossiblePhoneNumber as c } from "react-phone-number-input";
6
- import * as l from "yup";
7
- //#region ../../libraries/react-collection/dist/theme/collectionThemeVars.cssm.js
8
- var u = {
9
- form: {
10
- maxWidth: "var(--_1092q7b0)",
11
- gap: "var(--_1092q7b1)",
12
- borderRadius: "var(--_1092q7b2)",
13
- labelFontSize: "var(--_1092q7b3)",
14
- helpFontSize: "var(--_1092q7b4)"
15
- },
16
- input: {
17
- fontSize: "var(--_1092q7b5)",
18
- height: "var(--_1092q7b6)",
19
- borderRadius: "var(--_1092q7b7)"
20
- },
21
- checkbox: { labelFontSize: "var(--_1092q7b8)" }
22
- }, d = e(u), f = [
23
- "pdf",
24
- "xls",
25
- "xlsx",
26
- "doc",
27
- "docx",
28
- "csv"
29
- ], p = [
30
- "svg",
31
- "png",
32
- "jpg",
33
- "jpeg",
34
- "webp",
35
- "gif",
36
- "avif"
37
- ], m = ["mpeg", "mp4"], h = [
38
- "mp3",
39
- "ogg",
40
- "oga"
41
- ], g = {
42
- audio: {
43
- "audio/mpeg": [".mp3"],
44
- "audio/ogg": [".oga"]
45
- },
46
- document: {
47
- "application/pdf": [".pdf"],
48
- "application/msword": [".doc"],
49
- "application/vnd.ms-excel": [".xls"],
50
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [".xlsx"],
51
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [".docx"],
52
- "text/csv": [".csv"]
53
- },
54
- image: {
55
- "image/jpeg": [".jpeg", ".jpg"],
56
- "image/png": [".png"],
57
- "image/gif": [".gif"],
58
- "image/svg+xml": [".svg"],
59
- "image/webp": [".webp"],
60
- "image/avif": [".avif"]
61
- },
62
- video: {
63
- "video/mp4": [".mp4"],
64
- "video/mpeg": [".mpeg"]
65
- }
66
- }, _ = {
67
- audio: h,
68
- document: f,
69
- image: p,
70
- video: m
71
- };
72
- [
73
- ..._.audio,
74
- ..._.document,
75
- ..._.image,
76
- ..._.video
77
- ], {
78
- ...g.audio,
79
- ...g.document,
80
- ...g.image,
81
- ...g.video
82
- };
83
- //#endregion
84
- //#region ../../libraries/react-collection/dist/utils/formHelpers.js
85
- var v = (e) => {
86
- let t = [];
87
- for (let n of Object.keys(e)) for (let r of e?.[n] || []) t.push({
88
- message: r,
89
- name: n
90
- });
91
- return t;
92
- }, y = (e) => e ? c(e) : !1, b = (e, t) => {
93
- let n = [];
94
- for (let [r, i] of Object.entries(t)) {
95
- let t = e?.[r], a = l.string();
96
- for (let e of i) if (typeof e == "string") switch (e) {
97
- case "required":
98
- a = a.required(`The ${r} field is required`);
99
- break;
100
- case "email":
101
- a = a.email("The email address is not valid");
102
- break;
103
- case "phone_number":
104
- a = a.test("phone", "The phone number has incorrect format", (e) => e ? y(e) : !0);
105
- break;
106
- case "url":
107
- a = a.url("The URL is not valid");
108
- break;
109
- case "data_uri":
110
- a = a.test("data_uri", "The field does not have a valid file", (e) => typeof e == "string" ? e.startsWith("data:") && e.includes(",") : !1);
111
- break;
112
- }
113
- else if (typeof e == "object" && e) {
114
- let t = e;
115
- "max" in e && t.max?.[0] && (a = a.max(Number(t.max[0]))), "min" in e && t.min?.[0] && (a = a.min(Number(t.min[0])));
116
- }
117
- try {
118
- a.validateSync(t);
119
- } catch (e) {
120
- e instanceof l.ValidationError && n.push({
121
- message: e.message,
122
- name: r
123
- });
124
- }
125
- }
126
- return n.length > 0 ? {
127
- status: !1,
128
- errors: n
129
- } : { status: !0 };
130
- }, x = (e, t) => {
131
- let r = {};
132
- for (let t of e.sections) for (let e of t.fields) {
133
- let t = [];
134
- switch (e.required && t.push("required"), e.max !== void 0 && e.max !== null && t.push({ max: [e.max] }), e.min !== void 0 && e.min !== null && t.push({ min: [e.min] }), e.field_interface) {
135
- case n.EmailWidget:
136
- t.push("email");
137
- break;
138
- case n.PhoneWidget:
139
- t.push("phone_number");
140
- break;
141
- case n.URLWidget:
142
- t.push("url");
143
- break;
144
- default: break;
145
- }
146
- r[e.key] = t;
147
- }
148
- let { errors: i } = b(t, r), a = {};
149
- return i && i.map((e) => {
150
- a[e.name] = e.message;
151
- }), a;
152
- }, S = (e) => {
153
- let t = {};
154
- for (let r of e) {
155
- if (r.kind === "collection") {
156
- let e = r.options?.current_have_many_connected, n = r.options?.connected_have_many_current;
157
- e && n ? t[r.key] = i.collection.m2m : t[r.key] = i.collection.m2o;
158
- } else t[r.key] = i?.[r?.kind];
159
- r?.field_interface === n.RecordWidget && r?.fields?.length && (t[r.key] = S(r.fields));
160
- }
161
- return t;
162
- }, C = (e) => {
163
- if (!e?.sections) return {};
164
- let t = {};
165
- for (let n of e.sections) n?.fields && n?.fields?.length > 0 && (t = {
166
- ...t,
167
- ...S(n.fields)
168
- });
169
- return t;
170
- }, w = (e) => e === void 0 ? null : e, T = (e, t) => {
171
- if (!e?.sections) return {};
172
- let n = {};
173
- for (let r of e.sections) {
174
- let e = S(r.fields ?? []);
175
- for (let i of r.fields) {
176
- let r = w(t?.[i?.key]);
177
- Array.isArray(r) && r?.length > 0 && Array.isArray(i?.values) && i?.values?.length > 0 && !i?.options?.custom_input && (r = r?.filter((e) => i?.values?.includes(e))), n[i.key] = r ?? w(i?.default_value) ?? e[i.key];
178
- }
179
- }
180
- return n;
181
- }, E = (e, t) => {
182
- let c = { ...e }, l = null;
183
- if ((c.field_interface === n.ArrayWidget && t !== n.ArrayWidget || c.field_interface === n.RecordWidget && t !== n.RecordWidget) && (c.fields = []), (t !== n.MultiDropdownWidget || t !== n.DropdownWidget || t !== n.RadioWidget || t !== n.CheckboxWidget) && c.field_interface !== n.MultiDropdownWidget && c.field_interface !== n.DropdownWidget && c.field_interface !== n.RadioWidget && c.field_interface !== n.CheckboxWidget && c.values?.length !== 0 && (c.values = []), (t === n.MultiDropdownWidget && c.field_interface !== n.MultiDropdownWidget || t === n.DropdownWidget && c.field_interface !== n.DropdownWidget || t === n.RadioWidget && c.field_interface !== n.RadioWidget || t === n.CheckboxWidget && c.field_interface !== n.CheckboxWidget) && (c.values = [""], l = `${c.id}-option-0`), [n.RecordWidget, n.ArrayWidget].includes(t) && (l = `field-${s.generate()}`, c.kind = t === n.RecordWidget ? "record" : "group", c.fields = [...c?.fields || [], {
184
- id: l,
185
- key: "title",
186
- label: "Title",
187
- helper_text: "",
188
- kind: "string",
189
- field_interface: n.TextWidget,
190
- default_value: "",
191
- options: {},
192
- fields: [],
193
- hidden: !1,
194
- readonly: !1,
195
- required: !1,
196
- unique: !1,
197
- min: null,
198
- max: null,
199
- formats: a[t] || [],
200
- values: [],
201
- editable: !0
202
- }]), c.kind = o[t] || "string", !c.default_value) if (c.kind === "collection") {
203
- let e = c.options?.current_have_many_connected, t = c.options?.connected_have_many_current;
204
- e && t ? c.default_value = i.collection.m2m : c.default_value = i.collection.m2o;
205
- } else c.default_value = i[c.kind] || null;
206
- return t !== n.CollectionWidget && r.includes(t) && (c.field_interface = t), {
207
- field: c,
208
- fieldFocused: l
209
- };
210
- }, D = (e, t) => {
211
- let n = {};
212
- if (t) for (let r of t?.sections ?? []) for (let t of r?.fields) if (t.field_interface === "CollectionWidget") {
213
- let r = e?.[t?.key];
214
- r && typeof r == "object" && (Array.isArray(r) ? n[t?.key] = r?.filter((e) => e) : n[t?.key] = r._id);
215
- } else n[t?.key] = e?.[t?.key];
216
- return n;
217
- }, O = (e) => e.every((e) => {
218
- let { field_interface: t = "", key: n = "", hidden: r } = e;
219
- return !t || !n || r;
220
- }), k = (e, t) => {
221
- if (Array.isArray(e) && e.length > 0) {
222
- let n = 0;
223
- for (let r of e) n += 1, r?.param && t && t(r?.param, {
224
- type: "server_error",
225
- message: r?.message
226
- }, { shouldFocus: n === 0 });
227
- }
228
- }, A = (e) => t.memo(e);
229
- //#endregion
230
- export { x as a, T as c, C as d, O as f, u as g, d as h, v as i, y as l, g as m, k as n, S as o, _ as p, D as r, E as s, A as t, w as u };
File without changes
File without changes