@plitzi/sdk-elements 0.35.1 → 0.35.3

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 (28) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/dist/Element/hooks/useElementDataSource.mjs +18 -14
  3. package/dist/dataSource/GlobalSources.mjs +75 -61
  4. package/dist/elements/basic/Button/Button.d.ts +10 -1
  5. package/dist/elements/basic/Button/Button.mjs +7 -5
  6. package/dist/elements/basic/Button/declaration.d.ts +2 -0
  7. package/dist/elements/basic/Button/index.d.ts +2 -0
  8. package/dist/elements/declarations/index.d.ts +8 -0
  9. package/dist/elements/form/Form/Form.d.ts +9 -1
  10. package/dist/elements/form/Form/Form.mjs +79 -78
  11. package/dist/elements/form/Form/Settings.d.ts +2 -1
  12. package/dist/elements/form/Form/Settings.mjs +12 -6
  13. package/dist/elements/form/Form/declaration.d.ts +2 -0
  14. package/dist/elements/form/Form/declaration.mjs +1 -0
  15. package/dist/elements/form/Form/index.d.ts +2 -0
  16. package/dist/elements/form/FormControl/FormControl.d.ts +9 -1
  17. package/dist/elements/form/FormControl/FormControl.mjs +1 -0
  18. package/dist/elements/form/FormControl/Settings.d.ts +6 -2
  19. package/dist/elements/form/FormControl/Settings.mjs +106 -77
  20. package/dist/elements/form/FormControl/declaration.d.ts +4 -0
  21. package/dist/elements/form/FormControl/declaration.mjs +4 -0
  22. package/dist/elements/form/FormControl/helpers/validateField.d.ts +14 -0
  23. package/dist/elements/form/FormControl/helpers/validateField.mjs +13 -7
  24. package/dist/elements/form/FormControl/hocs/withFieldValue.d.ts +5 -1
  25. package/dist/elements/form/FormControl/hocs/withFieldValue.mjs +49 -39
  26. package/dist/elements/form/FormControl/index.d.ts +4 -0
  27. package/dist/index.d.ts +8 -0
  28. package/package.json +8 -8
@@ -13,28 +13,28 @@ import { produce as _ } from "immer";
13
13
  import v from "@plitzi/sdk-shared/dataSource/helpers/getSourceName";
14
14
  import y from "@plitzi/sdk-shared/dataSource/hooks/useRegisterSource";
15
15
  //#region src/elements/form/Form/Form.tsx
16
- var b = ({ ref: e, className: b = "", children: x, method: S = "get", actionUrl: C = "", managedByInteractions: w = !1, errors: T = m, values: E = m }) => {
17
- let [D, O] = l({}), k = c(/* @__PURE__ */ new Map()), A = c(!1), { id: j, definition: { label: M = "Form" }, setElementState: N } = t(), P = v(r.sourceType, j), { settings: { previewMode: F }, contexts: { InteractionsContext: I } } = u(), { interactionsManager: L } = i(I), R = a((e) => O((t) => ({
16
+ var b = ({ ref: e, className: b = "", children: x, method: S = "get", actionUrl: C = "", managedByInteractions: w = !1, noValidate: T = !1, errors: E = m, values: D = m }) => {
17
+ let [O, k] = l({}), A = c(/* @__PURE__ */ new Map()), j = c(!1), { id: M, definition: { label: N = "Form" }, setElementState: P } = t(), F = v(r.sourceType, M), { settings: { previewMode: I }, contexts: { InteractionsContext: L } } = u(), { interactionsManager: R } = i(L), z = a((e) => k((t) => ({
18
18
  ...t,
19
19
  [e.name]: e
20
- })), [O]);
21
- o(() => (A.current = !1, () => {
22
- A.current = !0;
20
+ })), [k]);
21
+ o(() => (j.current = !1, () => {
22
+ j.current = !0;
23
23
  }), []);
24
- let z = a((e) => {
25
- A.current || (O((t) => _(t, (t) => {
24
+ let B = a((e) => {
25
+ j.current || (k((t) => _(t, (t) => {
26
26
  t[e] && delete t[e];
27
- })), e && N((t) => ({
27
+ })), e && P((t) => ({
28
28
  ...t,
29
29
  values: f(t, `values.${e}`),
30
30
  errors: f(t, `errors.${e}`)
31
31
  })));
32
- }, [N]), B = a((e, t) => {
33
- k.current.set(e, t);
34
- }, []), V = a((e) => {
35
- k.current.delete(e);
36
- }, []), H = a((e, t = "") => {
37
- e && (t === null && (t = ""), N((n) => n.errors && n.errors[e] ? {
32
+ }, [P]), V = a((e, t) => {
33
+ A.current.set(e, t);
34
+ }, []), H = a((e) => {
35
+ A.current.delete(e);
36
+ }, []), U = a((e, t = "") => {
37
+ e && (t === null && (t = ""), P((n) => n.errors && n.errors[e] ? {
38
38
  ...n,
39
39
  values: {
40
40
  ...n.values,
@@ -48,8 +48,8 @@ var b = ({ ref: e, className: b = "", children: x, method: S = "get", actionUrl:
48
48
  [e]: t
49
49
  }
50
50
  }));
51
- }, [N]), U = a((e, t) => {
52
- e && N((n) => !t && !d(n, `errors.${e}`) ? n : !t && n.errors && n.errors[e] ? {
51
+ }, [P]), W = a((e, t) => {
52
+ e && P((n) => !t && !d(n, `errors.${e}`) ? n : !t && n.errors && n.errors[e] ? {
53
53
  ...n,
54
54
  errors: f(n, [`errors.${e}`])
55
55
  } : {
@@ -59,7 +59,7 @@ var b = ({ ref: e, className: b = "", children: x, method: S = "get", actionUrl:
59
59
  [e]: t
60
60
  }
61
61
  });
62
- }, [N]), W = a(() => Object.values(D).filter((e) => !!e.name).reduce((e, t) => [
62
+ }, [P]), G = a(() => Object.values(O).filter((e) => !!e.name).reduce((e, t) => [
63
63
  ...e,
64
64
  {
65
65
  path: `fields.${t.name}.id`,
@@ -73,118 +73,118 @@ var b = ({ ref: e, className: b = "", children: x, method: S = "get", actionUrl:
73
73
  path: `errors.${t.name}`,
74
74
  name: `${t.name} Error Message`
75
75
  }
76
- ], []), [D]), G = s(() => ({ runtime: { sources: {
76
+ ], []), [O]), K = s(() => ({ runtime: { sources: {
77
77
  form: {
78
- errors: T,
79
- values: E,
80
- registerField: R,
81
- unregisterField: z,
82
- registerValidator: B,
83
- unregisterValidator: V,
84
- setFieldValue: H,
85
- setFieldError: U
78
+ errors: E,
79
+ values: D,
80
+ registerField: z,
81
+ unregisterField: B,
82
+ registerValidator: V,
83
+ unregisterValidator: H,
84
+ setFieldValue: U,
85
+ setFieldError: W
86
86
  },
87
- [P]: {
88
- values: E,
89
- errors: T
87
+ [F]: {
88
+ values: D,
89
+ errors: E
90
90
  }
91
91
  } } }), [
92
- P,
93
- T,
92
+ F,
94
93
  E,
95
- R,
94
+ D,
96
95
  z,
97
96
  B,
98
97
  V,
99
98
  H,
100
- U
99
+ U,
100
+ W
101
101
  ]);
102
102
  y({
103
- id: j,
104
- source: P,
105
- name: M || `Form - ${j}`,
106
- fields: W
103
+ id: M,
104
+ source: F,
105
+ name: N || `Form - ${M}`,
106
+ fields: G
107
107
  });
108
- let K = s(() => ({ onSubmit: {
108
+ let q = s(() => ({ onSubmit: {
109
109
  action: "onSubmit",
110
110
  title: "On Form Submit",
111
111
  type: "trigger",
112
112
  params: {},
113
113
  preview: {
114
- values: Object.values(D).reduce((e, t) => ({
114
+ values: Object.values(O).reduce((e, t) => ({
115
115
  ...e,
116
116
  [t.name]: ""
117
117
  }), {}),
118
118
  actionUrl: "",
119
119
  method: ""
120
120
  }
121
- } }), [D]), q = a((e) => {
122
- let t = [...k.current].reduce((e, [t, n]) => {
123
- let r = n(E);
121
+ } }), [O]), J = a((e) => {
122
+ let t = [...A.current].reduce((e, [t, n]) => {
123
+ let r = n(D);
124
124
  return r ? {
125
125
  ...e,
126
126
  [t]: r
127
127
  } : e;
128
128
  }, {});
129
- if (N((e) => ({
129
+ if (P((e) => ({
130
130
  ...e,
131
131
  errors: t
132
132
  })), Object.keys(t).length > 0) {
133
133
  e.stopPropagation(), e.preventDefault();
134
134
  return;
135
135
  }
136
- if (!w || (e.stopPropagation(), e.preventDefault(), !F)) return;
137
- let n = Object.values(D).reduce((e, { name: t }) => ({
136
+ if (!w || (e.stopPropagation(), e.preventDefault(), !I)) return;
137
+ let n = Object.values(O).reduce((e, { name: t }) => ({
138
138
  ...e,
139
- [t]: E[t]
139
+ [t]: D[t]
140
140
  }), {});
141
- L.interactionTrigger(j, "onSubmit", {
141
+ R.interactionTrigger(M, "onSubmit", {
142
142
  values: n,
143
143
  actionUrl: C,
144
144
  method: S
145
145
  });
146
146
  }, [
147
- N,
147
+ P,
148
148
  w,
149
- F,
150
- D,
151
- L,
152
- j,
149
+ I,
150
+ O,
151
+ R,
152
+ M,
153
153
  C,
154
154
  S,
155
- E
156
- ]), J = a((e) => {
157
- w && (e instanceof Event && (e.stopPropagation(), e.preventDefault()), N((e) => ({
155
+ D
156
+ ]), Y = a((e) => {
157
+ w && (e instanceof Event && (e.stopPropagation(), e.preventDefault()), P((e) => ({
158
158
  ...e,
159
159
  values: {},
160
160
  errors: {}
161
161
  })));
162
- }, [N, w]), Y = a((e) => {
162
+ }, [P, w]), X = a((e) => {
163
163
  let { name: t, value: n } = e;
164
- H(t, n);
165
- }, [H]), X = a((e) => {
166
- let { name: t, error: n } = e;
167
164
  U(t, n);
168
- }, [U]), Z = s(() => ({
165
+ }, [U]), Z = a((e) => {
166
+ let { name: t, error: n } = e;
167
+ W(t, n);
168
+ }, [W]), Q = s(() => ({
169
169
  performReset: {
170
170
  action: "performReset",
171
- title: `Reset ${M}`,
171
+ title: `Reset ${N}`,
172
172
  type: "callback",
173
- callback: J,
173
+ callback: Y,
174
174
  params: {}
175
175
  },
176
176
  setFieldValue: {
177
177
  action: "setFieldValue",
178
- title: `Set Field Value ${M}`,
178
+ title: `Set Field Value ${N}`,
179
179
  type: "callback",
180
- callback: Y,
180
+ callback: X,
181
181
  preview: {},
182
182
  params: {
183
183
  name: {
184
184
  label: "Field Name",
185
185
  defaultValue: void 0,
186
186
  type: "select",
187
- options: Object.values(D).map((e) => ({
187
+ options: Object.values(O).map((e) => ({
188
188
  value: e.name,
189
189
  label: e.name
190
190
  }))
@@ -197,16 +197,16 @@ var b = ({ ref: e, className: b = "", children: x, method: S = "get", actionUrl:
197
197
  },
198
198
  setFieldError: {
199
199
  action: "setFieldError",
200
- title: `Set Field Error ${M}`,
200
+ title: `Set Field Error ${N}`,
201
201
  type: "callback",
202
- callback: X,
202
+ callback: Z,
203
203
  preview: {},
204
204
  params: {
205
205
  name: {
206
206
  label: "Field Name",
207
207
  defaultValue: void 0,
208
208
  type: "select",
209
- options: Object.values(D).map((e) => ({
209
+ options: Object.values(O).map((e) => ({
210
210
  value: e.name,
211
211
  label: e.name
212
212
  }))
@@ -218,26 +218,27 @@ var b = ({ ref: e, className: b = "", children: x, method: S = "get", actionUrl:
218
218
  }
219
219
  }
220
220
  }), [
221
- M,
222
- J,
221
+ N,
223
222
  Y,
224
- D,
225
- X
223
+ X,
224
+ O,
225
+ Z
226
226
  ]);
227
227
  return /* @__PURE__ */ h(n, {
228
228
  tag: "form",
229
229
  ref: e,
230
+ noValidate: T,
230
231
  method: S,
231
232
  className: g("plitzi-component__form", b),
232
- interactionTriggers: K,
233
- interactionCallbacks: Z,
234
- onSubmit: q,
235
- onReset: J,
233
+ interactionTriggers: q,
234
+ interactionCallbacks: Q,
235
+ onSubmit: J,
236
+ onReset: Y,
236
237
  action: C,
237
238
  children: /* @__PURE__ */ h(p, {
238
239
  inherit: "live",
239
- name: `Form:${j}`,
240
- value: G,
240
+ name: `Form:${M}`,
241
+ value: K,
241
242
  children: x
242
243
  })
243
244
  });
@@ -1,8 +1,9 @@
1
1
  type SettingsProps = {
2
2
  method?: 'get' | 'post';
3
3
  managedByInteractions?: boolean;
4
+ noValidate?: boolean;
4
5
  actionUrl?: string;
5
6
  onUpdate?: (key: string, value: string | boolean | number) => void;
6
7
  };
7
- declare const Settings: ({ method, managedByInteractions, actionUrl, onUpdate }: SettingsProps) => import("react").JSX.Element;
8
+ declare const Settings: ({ method, managedByInteractions, noValidate, actionUrl, onUpdate }: SettingsProps) => import("react").JSX.Element;
8
9
  export default Settings;
@@ -4,15 +4,15 @@ import r from "@plitzi/plitzi-ui/Checkbox";
4
4
  import i from "@plitzi/plitzi-ui/Input";
5
5
  import a from "@plitzi/plitzi-ui/Select";
6
6
  //#region src/elements/form/Form/Settings.tsx
7
- var o = ({ method: o = "get", managedByInteractions: s = !1, actionUrl: c = "", onUpdate: l }) => {
8
- let u = e((e) => l?.("actionUrl", e), [l]), d = e((e) => l?.("method", e), [l]), f = e((e) => l?.("managedByInteractions", e.target.checked), [l]);
7
+ var o = ({ method: o = "get", managedByInteractions: s = !1, noValidate: c = !1, actionUrl: l = "", onUpdate: u }) => {
8
+ let d = e((e) => u?.("actionUrl", e), [u]), f = e((e) => u?.("method", e), [u]), p = e((e) => u?.("managedByInteractions", e.target.checked), [u]), m = e((e) => u?.("noValidate", e.target.checked), [u]);
9
9
  return /* @__PURE__ */ n("div", {
10
10
  className: "flex h-full flex-col gap-4 py-2",
11
11
  children: [
12
12
  /* @__PURE__ */ n(a, {
13
13
  value: o,
14
14
  label: "Form Method",
15
- onChange: d,
15
+ onChange: f,
16
16
  size: "xs",
17
17
  children: [/* @__PURE__ */ t("option", {
18
18
  value: "get",
@@ -23,16 +23,22 @@ var o = ({ method: o = "get", managedByInteractions: s = !1, actionUrl: c = "",
23
23
  })]
24
24
  }),
25
25
  /* @__PURE__ */ t(i, {
26
- value: c,
27
- onChange: u,
26
+ value: l,
27
+ onChange: d,
28
28
  label: "Action URL",
29
29
  size: "xs"
30
30
  }),
31
31
  /* @__PURE__ */ t(r, {
32
32
  checked: s,
33
- onChange: f,
33
+ onChange: p,
34
34
  label: "Managed By Interactions",
35
35
  size: "xs"
36
+ }),
37
+ /* @__PURE__ */ t(r, {
38
+ checked: c,
39
+ onChange: m,
40
+ label: "Skip Browser Validation (show only the field messages)",
41
+ size: "xs"
36
42
  })
37
43
  ]
38
44
  });
@@ -10,6 +10,7 @@ declare const declaration: {
10
10
  readonly method: "get";
11
11
  readonly actionUrl: "";
12
12
  readonly managedByInteractions: false;
13
+ readonly noValidate: false;
13
14
  readonly errors: {};
14
15
  readonly values: {};
15
16
  };
@@ -57,6 +58,7 @@ declare const declaration: {
57
58
  } & import('@plitzi/sdk-shared/authoring/declare').ElementAttributesBrand<Partial<{
58
59
  values: Record<string, unknown>;
59
60
  method: "get" | "post";
61
+ noValidate: boolean;
60
62
  actionUrl: string;
61
63
  managedByInteractions: boolean;
62
64
  errors: Record<string, string>;
@@ -8,6 +8,7 @@ var t = e()({
8
8
  method: "get",
9
9
  actionUrl: "",
10
10
  managedByInteractions: !1,
11
+ noValidate: !1,
11
12
  errors: {},
12
13
  values: {}
13
14
  },
@@ -16,6 +16,7 @@ declare const Form: {
16
16
  readonly method: "get";
17
17
  readonly actionUrl: "";
18
18
  readonly managedByInteractions: false;
19
+ readonly noValidate: false;
19
20
  readonly errors: {};
20
21
  readonly values: {};
21
22
  };
@@ -57,6 +58,7 @@ declare const Form: {
57
58
  __attributes: Partial<{
58
59
  values: Record<string, unknown>;
59
60
  method: "get" | "post";
61
+ noValidate: boolean;
60
62
  actionUrl: string;
61
63
  managedByInteractions: boolean;
62
64
  errors: Record<string, string>;
@@ -2,7 +2,7 @@ import { ChangeEvent, RefObject } from 'react';
2
2
  export type FormControlProps = {
3
3
  ref: RefObject<HTMLElement>;
4
4
  className: string;
5
- subType: 'text' | 'number' | 'email' | 'password' | 'time' | 'checkbox' | 'switch' | 'select' | 'textarea' | 'hidden';
5
+ subType: 'text' | 'number' | 'email' | 'password' | 'date' | 'time' | 'checkbox' | 'switch' | 'select' | 'textarea' | 'hidden';
6
6
  name: string;
7
7
  label: string;
8
8
  placeholder: string;
@@ -16,9 +16,17 @@ export type FormControlProps = {
16
16
  /**
17
17
  * The rules a value has to meet before the form submits, checked by the form at submit time and by the control when
18
18
  * it loses focus. `0` and `''` mean no rule. See `validateField` for what each one says when it is broken.
19
+ *
20
+ * Each `…Message` is the sentence shown under the control when that rule is broken, in the site's language; empty
21
+ * falls back to an English one. `formatMessage` speaks for the shape the control's own type asks of its value — an
22
+ * address, for an `email` — so it is one attribute however many types come to have a shape.
19
23
  */
24
+ requiredMessage: string;
20
25
  minLength: number;
26
+ minLengthMessage: string;
21
27
  maxLength: number;
28
+ maxLengthMessage: string;
29
+ formatMessage: string;
22
30
  pattern: string;
23
31
  patternMessage: string;
24
32
  /** The `name` of another control in the same form this one has to repeat — a password confirmation, typically. */
@@ -105,6 +105,7 @@ var y = ({ ref: e, className: i = "", subType: y = "text", name: b = "", label:
105
105
  "number",
106
106
  "email",
107
107
  "password",
108
+ "date",
108
109
  "time"
109
110
  ].includes(y) && /* @__PURE__ */ g(s, {
110
111
  id: `${P}_${N}`,
@@ -1,5 +1,5 @@
1
1
  type SettingsProps = {
2
- subType?: 'text' | 'number' | 'time' | 'email' | 'password' | 'select' | 'checkbox' | 'textarea' | 'hidden' | 'color' | 'switch';
2
+ subType?: 'text' | 'number' | 'date' | 'time' | 'email' | 'password' | 'select' | 'checkbox' | 'textarea' | 'hidden' | 'color' | 'switch';
3
3
  name?: string;
4
4
  label?: string;
5
5
  placeholder?: string;
@@ -7,8 +7,12 @@ type SettingsProps = {
7
7
  defaultValue?: string;
8
8
  options?: string[];
9
9
  required?: boolean;
10
+ requiredMessage?: string;
10
11
  minLength?: number;
12
+ minLengthMessage?: string;
11
13
  maxLength?: number;
14
+ maxLengthMessage?: string;
15
+ formatMessage?: string;
12
16
  pattern?: string;
13
17
  patternMessage?: string;
14
18
  matches?: string;
@@ -18,5 +22,5 @@ type SettingsProps = {
18
22
  previewError?: boolean;
19
23
  onUpdate?: (key: string, value: string | boolean | number | string[]) => void;
20
24
  };
21
- declare const Settings: ({ subType, name, label, defaultValue, placeholder, autoComplete, options, required, minLength, maxLength, pattern, patternMessage, matches, matchesMessage, readOnly, disabled, previewError, onUpdate }: SettingsProps) => import("react").JSX.Element;
25
+ declare const Settings: ({ subType, name, label, defaultValue, placeholder, autoComplete, options, required, requiredMessage, minLength, minLengthMessage, maxLength, maxLengthMessage, formatMessage, pattern, patternMessage, matches, matchesMessage, readOnly, disabled, previewError, onUpdate }: SettingsProps) => import("react").JSX.Element;
22
26
  export default Settings;