jaguar-form 1.0.4 → 1.0.5

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.
Files changed (49) hide show
  1. package/README.md +15 -2
  2. package/dist/Select-DiEHlcyU.js +376 -0
  3. package/dist/{TreeSelect-CkPtMg-g.js → TreeSelect-1jpd43zZ.js} +7 -8
  4. package/dist/{compound-D4_6P0d_.js → compound-BhkceJal.js} +11 -10
  5. package/dist/compound.js +1 -1
  6. package/dist/core.js +1 -1
  7. package/dist/date-time.js +1 -1
  8. package/dist/form-CnRp3fRw.js +457 -0
  9. package/dist/form.js +3 -3
  10. package/dist/{icons-BI3fdIey.js → icons-D79FYcGF.js} +1 -1
  11. package/dist/{image-upload-VtUlQgzJ.js → image-upload-BstB2jRd.js} +13 -9
  12. package/dist/image-upload.js +1 -1
  13. package/dist/index.js +14 -14
  14. package/dist/input.js +1 -1
  15. package/dist/inputs-Ch4x2nwn.js +615 -0
  16. package/dist/locale/load.js +7 -3
  17. package/dist/{pickers-C9QTR2XN.js → pickers-D-ymAf_p.js} +29 -30
  18. package/dist/select.js +1 -1
  19. package/dist/selection-9NP9MXSn.js +190 -0
  20. package/dist/{slider-CNwkLMmo.js → slider-C2T2wII7.js} +1 -1
  21. package/dist/slider.js +1 -1
  22. package/dist/{store-DOn9K-EA.js → store-BvcQ7xcl.js} +47 -29
  23. package/dist/style.css +1 -1
  24. package/dist/tree-select.js +1 -1
  25. package/dist/types/components/extended-inputs.d.ts +30 -0
  26. package/dist/types/components/image-upload/ManagedImageUpload.d.ts +10 -3
  27. package/dist/types/components/image-upload/upload.d.ts +1 -1
  28. package/dist/types/components/inputs.d.ts +24 -1
  29. package/dist/types/components/select/types.d.ts +4 -1
  30. package/dist/types/components/select/useRemoteOptions.d.ts +11 -0
  31. package/dist/types/components/select.d.ts +1 -0
  32. package/dist/types/entries/input.d.ts +5 -2
  33. package/dist/types/entries/select.d.ts +1 -0
  34. package/dist/types/form/adapter.d.ts +1 -0
  35. package/dist/types/form/index.d.ts +32 -1
  36. package/dist/types/form/store.d.ts +9 -0
  37. package/dist/types/locale/load.d.ts +2 -1
  38. package/dist/types/primitives/Popup.d.ts +1 -0
  39. package/dist/types/utils/decimal.d.ts +4 -0
  40. package/dist/types/utils/remote-options.d.ts +23 -0
  41. package/dist/useControllable-Dhp7tTjy.js +97 -0
  42. package/dist/{useSelection-C0OEFZUE.js → useSelection-BUBndjzo.js} +2 -3
  43. package/package.json +1 -1
  44. package/dist/Control-B36bu6zQ.js +0 -47
  45. package/dist/Select-BG2H-YnK.js +0 -252
  46. package/dist/form-DTI0Sqsy.js +0 -413
  47. package/dist/inputs-BOP8Ryne.js +0 -403
  48. package/dist/selection-CIEa1uce.js +0 -146
  49. package/dist/useControllable-Zax42z2F.js +0 -87
@@ -1,413 +0,0 @@
1
- import { c as e, s as t, t as n } from "./compound-D4_6P0d_.js";
2
- import { a as r } from "./useControllable-Zax42z2F.js";
3
- import { r as i } from "./locale-yHkdw2xz.js";
4
- import { n as a, t as o } from "./slider-CNwkLMmo.js";
5
- import { i as s, t as c } from "./image-upload-VtUlQgzJ.js";
6
- import { cloneElement as l, createContext as u, isValidElement as d, useCallback as f, useContext as p, useEffect as m, useId as h, useMemo as g, useRef as _, useState as v, useSyncExternalStore as y } from "react";
7
- import { d as b, n as x, t as S } from "./store-DOn9K-EA.js";
8
- import { a as C, c as w, d as T, f as E, l as D, n as O, o as k, r as A, s as j, t as M, u as N } from "./inputs-BOP8Ryne.js";
9
- import { n as P, t as F } from "./Select-BG2H-YnK.js";
10
- import { t as I } from "./TreeSelect-CkPtMg-g.js";
11
- import { a as L, c as R, i as z, l as B, n as ee, o as te, r as ne, s as re, t as ie, u as ae } from "./pickers-C9QTR2XN.js";
12
- import { jsx as V, jsxs as H } from "react/jsx-runtime";
13
- // src/form/index.tsx
14
- var U = u(null);
15
- function W(e = {}) {
16
- let [t] = v(() => {
17
- let t = e.fields ?? [], n = {
18
- ...Object.fromEntries(t.map((e) => [e.name, Q(e)])),
19
- ...e.defaultValues
20
- }, r = Object.fromEntries(t.filter((e) => e.transform).map((e) => [e.name, e.transform]));
21
- return S(n, {
22
- nested: e.nested,
23
- initialValues: e.initialValues,
24
- adapter: {
25
- ...e.adapter,
26
- fields: {
27
- ...r,
28
- ...e.adapter?.fields
29
- }
30
- }
31
- });
32
- });
33
- return t;
34
- }
35
- function G({ form: e, children: t }) {
36
- return /* @__PURE__ */ V(U.Provider, {
37
- value: e,
38
- children: t
39
- });
40
- }
41
- function K() {
42
- let e = p(U);
43
- if (!e) throw Error("FormProvider is required");
44
- return e;
45
- }
46
- function q(e) {
47
- let t = K(), n = f((n) => t.subscribe(e, n), [t, e]), r = f(() => t.getFieldState(e), [t, e]), i = y(n, r, r);
48
- return {
49
- ...i,
50
- value: i.value,
51
- setValue: (n) => t.setValue(e, n),
52
- onBlur: () => t.blur(e)
53
- };
54
- }
55
- function J(e) {
56
- let t = K(), n = f((n) => t.subscribe(e, n), [t, e]), r = f(() => t.getValue(e), [t, e]);
57
- return y(n, r, r);
58
- }
59
- function oe(e) {
60
- let t = K(), n = J(e), r = h(), i = _(0), a = _([]), o = (e) => ({
61
- key: `${r}-${++i.current}`,
62
- value: e
63
- }), s = (e) => {
64
- let t = [...a.current];
65
- return e.map((e) => {
66
- let n = t.findIndex((t) => x(t.value, e));
67
- return n < 0 ? o(e) : {
68
- ...t.splice(n, 1)[0],
69
- value: e
70
- };
71
- });
72
- }, c = g(() => s(Array.isArray(n) ? n : []), [n]);
73
- m(() => {
74
- a.current = c;
75
- }, [c]);
76
- let l = (n) => {
77
- let r = t.getValue(e), i = s(Array.isArray(r) ? r : []), c = n.type === "insert" ? {
78
- ...n,
79
- value: o(n.value)
80
- } : n.type === "update" ? {
81
- ...n,
82
- value: {
83
- key: i[n.index]?.key ?? "",
84
- value: n.value
85
- }
86
- } : n, l = b(i, c);
87
- return a.current = l, t.editFieldArray(e, n);
88
- };
89
- return {
90
- fields: c,
91
- append: (n) => {
92
- let r = t.getValue(e);
93
- return l({
94
- type: "insert",
95
- index: Array.isArray(r) ? r.length : 0,
96
- value: n
97
- });
98
- },
99
- prepend: (e) => l({
100
- type: "insert",
101
- index: 0,
102
- value: e
103
- }),
104
- insert: (e, t) => l({
105
- type: "insert",
106
- index: e,
107
- value: t
108
- }),
109
- remove: (e) => l({
110
- type: "remove",
111
- index: e
112
- }),
113
- move: (e, t) => l({
114
- type: "move",
115
- from: e,
116
- to: t
117
- }),
118
- update: (e, t) => l({
119
- type: "update",
120
- index: e,
121
- value: t
122
- }),
123
- replace: (n) => t.setValue(e, n)
124
- };
125
- }
126
- function se(e = (e) => e) {
127
- let t = K(), n = _(null), r = f(() => {
128
- let r = e(t.getFormSummary());
129
- return n.current && x(n.current.value, r) ? n.current.value : (n.current = { value: r }, r);
130
- }, [t, e]);
131
- return y(t.subscribeAll, r, r);
132
- }
133
- function ce() {
134
- let e = K();
135
- return y(e.subscribeAll, e.getVersion, e.getVersion), {
136
- values: e.getValues(),
137
- changedValues: e.getChangedValues()
138
- };
139
- }
140
- var le = (e) => e, ue = {
141
- compound: n,
142
- imageUpload: c,
143
- input: C,
144
- number: k,
145
- password: j,
146
- textarea: E,
147
- switch: T,
148
- checkbox: O,
149
- radio: w,
150
- checkboxGroup: A,
151
- select: P,
152
- multiSelect: F,
153
- treeSelect: I,
154
- date: ie,
155
- dateRange: ee,
156
- time: re,
157
- timeRange: R,
158
- dateTime: ne,
159
- dateTimeRange: z,
160
- month: L,
161
- year: B,
162
- monthRange: te,
163
- yearRange: ae,
164
- search: D,
165
- segmented: N,
166
- slider: a,
167
- rangeSlider: o
168
- };
169
- function Y({ label: e, description: t, error: n, required: r, id: i, children: a, span: o = 1 }) {
170
- return /* @__PURE__ */ H("div", {
171
- className: "rfe-field",
172
- style: { gridColumn: `span ${o}` },
173
- children: [e && /* @__PURE__ */ H("label", {
174
- htmlFor: i,
175
- className: "rfe-field-label",
176
- children: [r && /* @__PURE__ */ V("span", {
177
- className: "rfe-required",
178
- "aria-hidden": "true",
179
- children: "* "
180
- }), e]
181
- }), /* @__PURE__ */ H("div", {
182
- className: "rfe-field-content",
183
- children: [a, n ? /* @__PURE__ */ V("div", {
184
- id: i ? `${i}-help` : void 0,
185
- role: "alert",
186
- className: "rfe-error",
187
- children: n
188
- }) : t && /* @__PURE__ */ V("div", {
189
- id: i ? `${i}-help` : void 0,
190
- className: "rfe-description",
191
- children: t
192
- })]
193
- })]
194
- });
195
- }
196
- var X = (e, t) => typeof e.visible == "function" ? e.visible(t) : e.visible !== !1, Z = (e) => e.type === "compound" && Array.isArray(e.componentProps?.fields) ? e.componentProps.fields : void 0, Q = (e) => e.defaultValue === void 0 ? Z(e) ? t(Z(e)) : void 0 : e.defaultValue;
197
- function de(t) {
198
- return [
199
- ...t.required && !t.rules?.some((e) => e.required) ? [{ required: !0 }] : [],
200
- ...t.rules ?? [],
201
- ...Z(t) ? [e(Z(t))] : [],
202
- ...t.type === "imageUpload" && t.componentProps?.mode === "upload" ? [s] : []
203
- ];
204
- }
205
- function fe({ field: e, components: t, fields: n, validateOn: a }) {
206
- let o = K(), s = q(e.name), c = r(), l = h(), u = e.dependsOn, d = g(() => ({
207
- rules: de(e),
208
- debounce: e.debounce,
209
- dependsOn: u,
210
- validateOn: e.validateOn ?? a,
211
- defaultValue: Q(e),
212
- visible: (t) => X(e, t)
213
- }), [
214
- e,
215
- u,
216
- a
217
- ]);
218
- m(() => o.registerField(e.name, { ...d }), [o, e.name]), m(() => o.updateField(e.name, d), [
219
- o,
220
- e.name,
221
- d
222
- ]);
223
- let p = f((t) => {
224
- if (!u) return typeof e.visible == "function" || typeof e.disabled == "function" ? o.subscribeAll(t) : () => {};
225
- let n = u.map((e) => o.subscribe(e, t));
226
- return () => n.forEach((e) => e());
227
- }, [
228
- o,
229
- u,
230
- e.visible,
231
- e.disabled
232
- ]);
233
- y(p, o.getVersion, o.getVersion);
234
- let _ = typeof e.visible == "function" || typeof e.disabled == "function" ? o.getValues() : $;
235
- if (!X(e, _)) return null;
236
- let v = t[e.type] ?? ue[e.type], b = {
237
- ...e.componentProps,
238
- id: l,
239
- name: e.name,
240
- value: s.value ?? ([
241
- "input",
242
- "password",
243
- "textarea",
244
- "search"
245
- ].includes(e.type) ? "" : e.type === "switch" || e.type === "checkbox" ? !1 : e.type === "imageUpload" || e.type === "multiSelect" || e.type === "checkboxGroup" || e.type === "treeSelect" && e.componentProps?.multiple ? [] : e.type === "slider" ? 0 : e.type === "rangeSlider" ? [0, 100] : null),
246
- onChange: (t) => {
247
- o.setValue(e.name, t);
248
- },
249
- onBlur: () => {
250
- o.blur(e.name);
251
- },
252
- status: s.error ? "error" : "default",
253
- "aria-invalid": !!s.error,
254
- disabled: typeof e.disabled == "function" ? e.disabled(_) : e.disabled ?? e.componentProps?.disabled,
255
- "aria-describedby": s.error || e.description ? `${l}-help` : void 0
256
- };
257
- return /* @__PURE__ */ H(Y, {
258
- label: e.label,
259
- required: e.required,
260
- description: e.description,
261
- error: i(s.issue, s.error, c),
262
- id: l,
263
- span: e.span,
264
- children: [e.render ? e.render(b) : v ? /* @__PURE__ */ V(v, { ...b }) : /* @__PURE__ */ V("div", {
265
- className: "rfe-error",
266
- children: c.t("unknownField", { type: e.type })
267
- }), s.validating && /* @__PURE__ */ V("small", {
268
- role: "status",
269
- className: "rfe-description",
270
- children: c.t("validating")
271
- })]
272
- });
273
- }
274
- var pe = u("blur"), me = [], $ = {}, he = {};
275
- function ge({ nested: e, initialValues: t, adapter: n, submitHiddenFields: i = !1, validateOn: a = "blur", form: o, fields: s = me, defaultValues: c = $, components: l = he, children: u, columns: d = 1, layout: f = "vertical", onSubmit: p, onError: m, submitText: h, resetText: g, showActions: y = !0 }) {
276
- let b = r(), x = W(o ? {} : {
277
- fields: s,
278
- defaultValues: c,
279
- initialValues: t,
280
- adapter: n,
281
- nested: e
282
- }), S = o ?? x, [C, w] = v(!1), [T, E] = v(""), D = _(!1), O = _(null);
283
- return /* @__PURE__ */ V(G, {
284
- form: S,
285
- children: /* @__PURE__ */ V(pe.Provider, {
286
- value: a,
287
- children: /* @__PURE__ */ H("form", {
288
- ref: O,
289
- className: "rfe-form",
290
- "data-layout": f,
291
- noValidate: !0,
292
- onSubmit: async (e) => {
293
- if (e.preventDefault(), !D.current) {
294
- D.current = !0, w(!0), E("");
295
- try {
296
- let e = S.getDataVersion(), t = await S.validate();
297
- if (S.getDataVersion() !== e || !t) {
298
- requestAnimationFrame(() => O.current?.querySelector("input[aria-invalid=\"true\"],button[aria-invalid=\"true\"],textarea[aria-invalid=\"true\"],[tabindex][aria-invalid=\"true\"]")?.focus());
299
- return;
300
- }
301
- await p?.(S.getSubmitValues(i));
302
- } catch (e) {
303
- E(e instanceof Error ? e.message : b.t("submitFailed")), m?.(e);
304
- } finally {
305
- D.current = !1, w(!1);
306
- }
307
- }
308
- },
309
- children: [
310
- /* @__PURE__ */ H("div", {
311
- className: "rfe-form-grid",
312
- style: { gridTemplateColumns: `repeat(${Math.max(1, d)},minmax(0,1fr))` },
313
- children: [s.map((e) => /* @__PURE__ */ V(fe, {
314
- field: e,
315
- components: l,
316
- fields: s,
317
- validateOn: a
318
- }, e.name)), u]
319
- }),
320
- T && /* @__PURE__ */ V("div", {
321
- role: "alert",
322
- className: "rfe-error",
323
- children: T
324
- }),
325
- y && /* @__PURE__ */ H("div", {
326
- className: "rfe-form-actions",
327
- children: [/* @__PURE__ */ V(M, {
328
- variant: "secondary",
329
- disabled: C,
330
- onClick: () => {
331
- S.reset(), E("");
332
- },
333
- children: g ?? b.t("reset")
334
- }), /* @__PURE__ */ V(M, {
335
- type: "submit",
336
- loading: C,
337
- children: h ?? b.t("save")
338
- })]
339
- })
340
- ]
341
- })
342
- })
343
- });
344
- }
345
- function _e({ children: a, name: o, label: u, description: _, required: v, rules: b, defaultValue: x, dependsOn: S, debounce: C, validateOn: w, span: T, disabled: E, visible: D, componentProps: O }) {
346
- let k = K(), A = p(pe), j = w ?? A, M = q(o), N = r(), P = h(), F = d(a) && a.type === n ? a.props.fields : void 0, I = d(a) && a.type === c && a.props.mode === "upload", L = g(() => ({
347
- rules: [
348
- ...v && !b?.some((e) => e.required) ? [{ required: !0 }] : [],
349
- ...b ?? [],
350
- ...I ? [s] : [],
351
- ...F ? [e(F)] : []
352
- ],
353
- defaultValue: x ?? (F ? t(F) : void 0),
354
- dependsOn: S,
355
- debounce: C,
356
- validateOn: j,
357
- visible: (e) => typeof D == "function" ? D(e) : D !== !1
358
- }), [
359
- v,
360
- b,
361
- x,
362
- S,
363
- C,
364
- j,
365
- D,
366
- I,
367
- F
368
- ]);
369
- m(() => k.registerField(o, { ...L }), [k, o]), m(() => k.updateField(o, L), [
370
- k,
371
- o,
372
- L
373
- ]);
374
- let R = f((e) => typeof D == "function" || typeof E == "function" ? k.subscribeAll(e) : () => {}, [
375
- k,
376
- D,
377
- E
378
- ]);
379
- y(R, k.getVersion, k.getVersion);
380
- let z = typeof D == "function" || typeof E == "function" ? k.getValues() : $;
381
- if (!L.visible(z)) return null;
382
- let B = {
383
- ...O,
384
- id: P,
385
- name: o,
386
- value: M.value,
387
- onChange: (e) => {
388
- k.setValue(o, e);
389
- },
390
- onBlur: () => {
391
- k.blur(o);
392
- },
393
- disabled: typeof E == "function" ? E(z) : E,
394
- status: M.error ? "error" : "default",
395
- "aria-invalid": !!M.error,
396
- "aria-describedby": M.error || _ ? `${P}-help` : void 0
397
- };
398
- return /* @__PURE__ */ H(Y, {
399
- id: P,
400
- label: u,
401
- required: v,
402
- description: _,
403
- error: i(M.issue, M.error, N),
404
- span: T,
405
- children: [typeof a == "function" ? a(B) : d(a) ? l(a, B) : a, M.validating && /* @__PURE__ */ V("small", {
406
- role: "status",
407
- className: "rfe-description",
408
- children: N.t("validating")
409
- })]
410
- });
411
- }
412
- var ve = Object.assign(ge, { Field: _e }), ye = (e) => e;
413
- export { le as a, W as c, se as d, J as f, ye as i, K as l, Y as n, q as o, G as r, oe as s, ve as t, ce as u };