@plitzi/sdk-elements 0.32.25 → 0.33.1

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 (59) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/Element/ElementContext.d.ts +7 -0
  3. package/dist/Element/helpers/isVisible.d.ts +1 -0
  4. package/dist/Element/helpers/isVisible.mjs +4 -0
  5. package/dist/Element/hocs/withElement.mjs +86 -78
  6. package/dist/Element/hooks/useInternalClassName.mjs +21 -20
  7. package/dist/Element/hooks/useInternalItems.mjs +1 -1
  8. package/dist/Element/hooks/useRscData.d.ts +4 -3
  9. package/dist/Element/hooks/useRscData.mjs +15 -10
  10. package/dist/dataSource/GlobalSources.d.ts +1 -2
  11. package/dist/dataSource/GlobalSources.mjs +46 -62
  12. package/dist/elements/advanced/BlockJsx/BlockJsx.mjs +1 -1
  13. package/dist/elements/basic/Link/Link.mjs +47 -41
  14. package/dist/elements/basic/RichText/RichText.d.ts +20 -0
  15. package/dist/elements/basic/RichText/RichText.mjs +30 -0
  16. package/dist/elements/basic/RichText/Settings.d.ts +7 -0
  17. package/dist/elements/basic/RichText/Settings.mjs +51 -0
  18. package/dist/elements/{provider/CollectionContainer → basic/RichText}/index.d.ts +6 -7
  19. package/dist/elements/{provider/CollectionContainer → basic/RichText}/index.mjs +12 -13
  20. package/dist/elements/basic/RichText/sanitizeHtml.d.ts +21 -0
  21. package/dist/elements/basic/RichText/sanitizeHtml.mjs +8 -0
  22. package/dist/elements/form/FormControl/index.mjs +1 -1
  23. package/dist/elements/index.d.ts +5 -3
  24. package/dist/elements/index.mjs +30 -28
  25. package/dist/elements/internal/Page/Page.mjs +28 -26
  26. package/dist/elements/provider/ApiContainer/ApiContainer.d.ts +28 -1
  27. package/dist/elements/provider/ApiContainer/ApiContainer.mjs +201 -86
  28. package/dist/elements/provider/ApiContainer/Settings.d.ts +15 -3
  29. package/dist/elements/provider/ApiContainer/Settings.mjs +209 -92
  30. package/dist/elements/provider/ApiContainer/components/FiltersInput/FiltersInput.d.ts +22 -0
  31. package/dist/elements/provider/ApiContainer/components/FiltersInput/FiltersInput.mjs +75 -0
  32. package/dist/elements/provider/ApiContainer/components/FiltersInput/index.d.ts +3 -0
  33. package/dist/elements/provider/ApiContainer/components/FiltersInput/index.mjs +5 -0
  34. package/dist/elements/provider/ApiContainer/hooks/useProviderPagination.d.ts +31 -0
  35. package/dist/elements/provider/ApiContainer/hooks/useProviderPagination.mjs +51 -0
  36. package/dist/elements/provider/ApiContainer/hooks/useProviderWrite.d.ts +26 -0
  37. package/dist/elements/provider/ApiContainer/hooks/useProviderWrite.mjs +27 -0
  38. package/dist/elements/provider/ApiContainer/index.d.ts +8 -0
  39. package/dist/elements/provider/ApiContainer/index.mjs +9 -1
  40. package/dist/elements/settings.mjs +32 -30
  41. package/dist/elements/structure/Pagination/Pagination.d.ts +41 -0
  42. package/dist/elements/structure/Pagination/Pagination.mjs +83 -0
  43. package/dist/elements/structure/Pagination/Settings.d.ts +12 -0
  44. package/dist/elements/structure/Pagination/Settings.mjs +85 -0
  45. package/dist/elements/structure/Pagination/buildPageWindow.d.ts +9 -0
  46. package/dist/elements/structure/Pagination/buildPageWindow.mjs +8 -0
  47. package/dist/elements/structure/Pagination/index.d.ts +67 -0
  48. package/dist/elements/structure/Pagination/index.mjs +59 -0
  49. package/dist/index.d.ts +130 -57
  50. package/dist/index.mjs +32 -30
  51. package/package.json +76 -32
  52. package/dist/elements/internal/Page/helpers/UserHelper.d.ts +0 -4
  53. package/dist/elements/provider/CollectionContainer/CollectionContainer.d.ts +0 -18
  54. package/dist/elements/provider/CollectionContainer/CollectionContainer.mjs +0 -69
  55. package/dist/elements/provider/CollectionContainer/CollectionContainer.stories-pending.d.ts +0 -1
  56. package/dist/elements/provider/CollectionContainer/Settings.d.ts +0 -10
  57. package/dist/elements/provider/CollectionContainer/Settings.mjs +0 -74
  58. package/dist/elements/provider/CollectionContainer/hooks/useCollectionContext.d.ts +0 -19
  59. package/dist/elements/provider/CollectionContainer/hooks/useCollectionContext.mjs +0 -71
@@ -1,84 +1,145 @@
1
1
  import e from "../../../Element/hooks/useElement.mjs";
2
- import { RootElement as t } from "../../../Element/RootElement.mjs";
3
- import n from "./hooks/useApi.mjs";
4
- import r from "../../../Element/hocs/withElement.mjs";
5
- import { use as i, useCallback as a, useEffect as o, useMemo as s } from "react";
6
- import c from "@plitzi/sdk-shared/hooks/usePlitziServiceContext";
7
- import { get as l } from "@plitzi/plitzi-ui/helpers";
8
- import { processTwig as u } from "@plitzi/sdk-shared/helpers/twigWrapper";
9
- import { StoreProvider as d } from "@plitzi/nexus/react";
10
- import { emptyObject as f, getPathsFromObeject as p } from "@plitzi/sdk-shared/helpers/utils";
11
- import { jsx as m } from "react/jsx-runtime";
12
- import h from "clsx";
13
- import g from "@plitzi/sdk-shared/dataSource/helpers/getSourceName";
14
- import _ from "@plitzi/sdk-shared/dataSource/hooks/useRegisterSource";
15
- import { QueryBuilderEvaluator as v } from "@plitzi/plitzi-ui/QueryBuilder";
2
+ import t from "../../../Element/hooks/useRscData.mjs";
3
+ import { RootElement as n } from "../../../Element/RootElement.mjs";
4
+ import ee from "./hooks/useApi.mjs";
5
+ import te from "./hooks/useProviderPagination.mjs";
6
+ import r from "./hooks/useProviderWrite.mjs";
7
+ import i from "../../../Element/hocs/withElement.mjs";
8
+ import { use as ne, useCallback as a, useEffect as re, useMemo as o } from "react";
9
+ import s from "@plitzi/sdk-shared/hooks/usePlitziServiceContext";
10
+ import { useSdkStore as ie } from "@plitzi/sdk-shared/store";
11
+ import { get as ae } from "@plitzi/plitzi-ui/helpers";
12
+ import { processTwig as oe } from "@plitzi/sdk-shared/helpers/twigWrapper";
13
+ import { StoreProvider as se } from "@plitzi/nexus/react";
14
+ import { emptyObject as c, getPathsFromObeject as ce } from "@plitzi/sdk-shared/helpers/utils";
15
+ import { jsx as l } from "react/jsx-runtime";
16
+ import le from "clsx";
17
+ import ue from "@plitzi/sdk-shared/dataSource/helpers/getSourceName";
18
+ import u from "@plitzi/sdk-shared/dataSource/hooks/useRegisterSource";
19
+ import { QueryBuilderEvaluator as d } from "@plitzi/plitzi-ui/QueryBuilder";
16
20
  //#region src/elements/provider/ApiContainer/ApiContainer.tsx
17
- var y = ({ ref: r, className: y = "", children: b, query: x = "", method: S = "get", accessToken: C = "", when: w = f, headers: T = f, mockData: E = "{}", subType: D = "div", credentials: O = "same-origin" }) => {
18
- let { id: k, idRef: A, definition: { label: j = "Api Container" } } = e(), M = g("apiContainer", { idRef: A }), { settings: { previewMode: N, debugMode: P }, contexts: { NavigationContext: F, InteractionsContext: I } } = c(), { interactionsManager: L } = i(I), { routeParams: R, queryParams: z } = i(F), B = s(() => {
19
- if (!x) return "";
21
+ var f = ({ ref: i, className: f = "", children: p, query: m = "", method: h = "get", accessToken: g = "", when: _ = c, headers: v = c, mockData: y = "{}", subType: de = "div", credentials: fe = "same-origin", singleRecord: b = !1, pagination: x = "none", pageParam: pe = "page", renderWhileLoading: me = !1 }) => {
22
+ let { id: S, idRef: C, visible: w, definition: { label: T = "Api Container", runtime: he } } = e(), E = he === "server", { loaded: D, elementData: O, refresh: k } = t(), A = ue("apiContainer", { idRef: C }), { settings: { previewMode: j, debugMode: M }, contexts: { InteractionsContext: N } } = s(), { interactionsManager: P } = ne(N), [[F, I, L]] = ie([
23
+ "navigation.routeParams",
24
+ "navigation.queryParams",
25
+ "navigation.navigate"
26
+ ]), R = o(() => {
27
+ if (!m) return "";
20
28
  try {
21
29
  let e = {
22
- ...z,
23
- ...R
30
+ ...I,
31
+ ...F
24
32
  };
25
- P && [...x.matchAll(/{{([ ]+|)(?<token>[a-zA-Z0-9-_:*/]+)([ ]+|)}}/gim)].forEach(({ groups: t }) => {
33
+ M && [...m.matchAll(/{{([ ]+|)(?<token>[a-zA-Z0-9-_:*/]+)([ ]+|)}}/gim)].forEach(({ groups: t }) => {
26
34
  let n = t?.token.trim();
27
- (!n || !l(e, n)) && console.log(`Token ${n} is required`);
35
+ (!n || !ae(e, n)) && console.log(`Token ${n} is required`);
28
36
  });
29
- let t = u(x, e, !0);
30
- return typeof t == "string" ? t : x;
37
+ let t = oe(m, e, !0);
38
+ return typeof t == "string" ? t : m;
31
39
  } catch (e) {
32
40
  console.error(e.message);
33
41
  }
34
42
  return "";
35
43
  }, [
36
- x,
37
- z,
38
- R,
39
- P
40
- ]), V = s(() => C ? {
41
- ...T,
42
- Authorization: `Bearer ${C}`
43
- } : T, [T, C]), H = s(() => !!(N && B && (w === f || v(w, {
44
- ...R,
45
- ...z
46
- })) || !N && (B || E && E !== "{}" && E !== f)), [
47
- N,
48
- B,
44
+ m,
45
+ I,
46
+ F,
47
+ M
48
+ ]), ge = o(() => g ? {
49
+ ...v,
50
+ Authorization: `Bearer ${g}`
51
+ } : v, [v, g]), _e = o(() => E || !w ? !1 : !!(j && R && (_ === c || d(_, {
52
+ ...F,
53
+ ...I
54
+ })) || !j && (R || y && y !== "{}" && y !== c)), [
55
+ E,
49
56
  w,
57
+ j,
50
58
  R,
59
+ _,
60
+ F,
61
+ I,
62
+ y
63
+ ]), { isLoading: ve, data: z, refetch: B, isSuccess: V, isError: H } = ee({
64
+ url: R,
65
+ method: h,
66
+ credentials: fe,
67
+ mock: j ? void 0 : y,
68
+ customHeaders: ge,
69
+ enabled: _e
70
+ }), U = E && D && O === null, W = o(() => {
71
+ if (!E) return z ?? c;
72
+ if (O) return O;
73
+ if (D) return c;
74
+ if (typeof y != "string") return y;
75
+ try {
76
+ return JSON.parse(y || "{}");
77
+ } catch {
78
+ return c;
79
+ }
80
+ }, [
81
+ E,
51
82
  z,
52
- E
53
- ]), { isLoading: U, data: W, refetch: G, isSuccess: K, isError: q } = n({
54
- url: B,
55
- method: S,
56
- credentials: O,
57
- mock: N ? void 0 : E,
58
- customHeaders: V,
59
- enabled: H
83
+ O,
84
+ D,
85
+ y
86
+ ]), G = !E && ve, K = a(async () => {
87
+ if (!E) {
88
+ B();
89
+ return;
90
+ }
91
+ await k([S]);
92
+ }, [
93
+ E,
94
+ B,
95
+ k,
96
+ S
97
+ ]), q = W, ye = o(() => Array.isArray(q.records) ? q.records : [], [q.records]), { records: J, isLoadingMore: Y, goToPage: X, loadMore: Z } = te({
98
+ elementId: S,
99
+ mode: x,
100
+ pageParam: pe,
101
+ records: ye,
102
+ page: q.pageInfo?.page ?? 1,
103
+ refresh: k,
104
+ navigate: L
60
105
  });
61
- o(() => {
62
- U || !A || (K ? L.interactionTrigger(A, "onApiSuccess", {
63
- url: B,
64
- method: S,
106
+ re(() => {
107
+ G || !C || (V ? P.interactionTrigger(C, "onApiSuccess", {
108
+ url: R,
109
+ method: h,
65
110
  ...W
66
- }) : q && L.interactionTrigger(A, "onApiError", {
67
- url: B,
68
- method: S,
111
+ }) : H && P.interactionTrigger(C, "onApiError", {
112
+ url: R,
113
+ method: h,
69
114
  ...W
70
115
  }));
71
116
  }, [
72
117
  W,
73
- A,
74
- L,
75
- q,
76
- U,
77
- K,
78
- S,
79
- B
118
+ C,
119
+ P,
120
+ H,
121
+ G,
122
+ V,
123
+ h,
124
+ R
80
125
  ]);
81
- let J = a(() => p(W).reduce((e, t) => {
126
+ let Q = o(() => ({
127
+ ...W,
128
+ ...Array.isArray(q.records) ? { records: J } : c,
129
+ isLoading: G || Y,
130
+ isEmpty: b ? q.record === void 0 : J.length === 0,
131
+ hasError: U,
132
+ errorMessage: U ? "The data provider could not be reached" : ""
133
+ }), [
134
+ W,
135
+ q.records,
136
+ q.record,
137
+ J,
138
+ G,
139
+ Y,
140
+ b,
141
+ U
142
+ ]), be = a(() => ce(Q).reduce((e, t) => {
82
143
  let n = t.split(".");
83
144
  return n.length > 1 ? [...e, {
84
145
  path: t,
@@ -87,21 +148,75 @@ var y = ({ ref: r, className: y = "", children: b, query: x = "", method: S = "g
87
148
  path: t,
88
149
  name: n[n.length - 1]
89
150
  }];
90
- }, []), [W]);
91
- _({
92
- id: k,
93
- source: M,
94
- name: j || `API - ${k}`,
95
- fields: J
151
+ }, []), [Q]);
152
+ u({
153
+ id: S,
154
+ source: A,
155
+ name: T || `API - ${S}`,
156
+ fields: be
96
157
  });
97
- let Y = s(() => ({ performQuery: {
98
- action: "performQuery",
99
- title: `Perform Query ${j}`,
100
- type: "callback",
101
- callback: G,
102
- preview: {},
103
- params: {}
104
- } }), [j, G]), X = s(() => ({
158
+ let { writeRecord: $ } = r({
159
+ elementId: S,
160
+ enabled: E,
161
+ onDone: K
162
+ }), xe = o(() => {
163
+ let e = {
164
+ performQuery: {
165
+ action: "performQuery",
166
+ title: `Perform Query ${T}`,
167
+ type: "callback",
168
+ callback: K,
169
+ preview: {},
170
+ params: {}
171
+ },
172
+ loadMore: {
173
+ action: "loadMore",
174
+ title: `Load More ${T}`,
175
+ type: "callback",
176
+ callback: Z,
177
+ preview: {},
178
+ params: {}
179
+ },
180
+ goToPage: {
181
+ action: "goToPage",
182
+ title: `Go To Page ${T}`,
183
+ type: "callback",
184
+ callback: ({ page: e }) => X(Number(e) || 1),
185
+ preview: {},
186
+ params: { page: {
187
+ label: "Page",
188
+ defaultValue: "1",
189
+ type: "text"
190
+ } }
191
+ }
192
+ };
193
+ return E && (e.writeRecord = {
194
+ action: "writeRecord",
195
+ title: `Write Record ${T}`,
196
+ type: "callback",
197
+ callback: $,
198
+ preview: { action: "create" },
199
+ params: {
200
+ action: {
201
+ label: "Endpoint",
202
+ defaultValue: "create",
203
+ type: "text"
204
+ },
205
+ recordId: {
206
+ label: "Record Id",
207
+ defaultValue: "",
208
+ type: "text"
209
+ }
210
+ }
211
+ }), e;
212
+ }, [
213
+ T,
214
+ K,
215
+ Z,
216
+ X,
217
+ E,
218
+ $
219
+ ]), Se = o(() => ({
105
220
  onApiError: {
106
221
  action: "onApiError",
107
222
  title: "On Api Error",
@@ -126,20 +241,20 @@ var y = ({ ref: r, className: y = "", children: b, query: x = "", method: S = "g
126
241
  data: ""
127
242
  }
128
243
  }
129
- }), []), Z = s(() => M ? { runtime: { sources: { [M]: W } } } : f, [W, M]);
130
- return /* @__PURE__ */ m(t, {
131
- ref: r,
132
- tag: D,
133
- className: h("plitzi-component__api-container", y),
134
- interactionTriggers: X,
135
- interactionCallbacks: Y,
136
- children: /* @__PURE__ */ m(d, {
244
+ }), []), Ce = o(() => A ? { runtime: { sources: { [A]: Q } } } : c, [Q, A]);
245
+ return /* @__PURE__ */ l(n, {
246
+ ref: i,
247
+ tag: de,
248
+ className: le("plitzi-component__api-container", f),
249
+ interactionTriggers: Se,
250
+ interactionCallbacks: xe,
251
+ children: /* @__PURE__ */ l(se, {
137
252
  inherit: "live",
138
- name: `Api:${k}`,
139
- value: Z,
140
- children: !U && b
253
+ name: `Api:${S}`,
254
+ value: Ce,
255
+ children: (!G || me) && p
141
256
  })
142
257
  });
143
- }, b = r(y);
258
+ }, p = i(f);
144
259
  //#endregion
145
- export { y as ApiContainer, b as default };
260
+ export { f as ApiContainer, p as default };
@@ -1,14 +1,26 @@
1
+ import { ConnectorFilterValue } from './components/FiltersInput';
1
2
  import { RuleGroup } from '@plitzi/plitzi-ui/QueryBuilder';
3
+ import { ElementRuntime } from '@plitzi/sdk-shared';
2
4
  type SettingsProps = {
3
5
  query?: string;
4
6
  method?: 'get' | 'post';
5
7
  accessToken?: string;
6
- when?: RuleGroup;
7
8
  headers?: object;
9
+ when?: RuleGroup;
8
10
  subType?: 'div' | 'header' | 'footer' | 'nav' | 'main' | 'section' | 'article' | 'aside' | 'address' | 'figure';
9
11
  mockData?: string;
10
12
  credentials?: RequestCredentials;
11
- onUpdate?: (key: string, value: string | boolean | number | object) => void;
13
+ runtime?: ElementRuntime;
14
+ connector?: string;
15
+ endpoint?: string;
16
+ resource?: string;
17
+ limit?: string;
18
+ singleRecord?: boolean;
19
+ filters?: ConnectorFilterValue[];
20
+ pagination?: 'none' | 'url' | 'append';
21
+ pageParam?: string;
22
+ renderWhileLoading?: boolean;
23
+ onUpdate?: (key: string, value: string | boolean | number | object, isDefinition?: boolean) => void;
12
24
  };
13
- declare const Settings: ({ query, method, accessToken, when, headers, subType, mockData, credentials, onUpdate }: SettingsProps) => import("react").JSX.Element;
25
+ declare const Settings: ({ query, method, accessToken, headers, when, subType, mockData, credentials, runtime, connector, endpoint, resource, limit, singleRecord, filters, pagination, pageParam, renderWhileLoading, onUpdate }: SettingsProps) => import("react").JSX.Element;
14
26
  export default Settings;