@plitzi/sdk-elements 0.38.4 → 0.38.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +358 -0
  2. package/dist/Element/helpers/elementChildren.d.ts +29 -0
  3. package/dist/Element/helpers/elementChildren.mjs +16 -0
  4. package/dist/Element/hooks/useElementVisible.d.ts +11 -0
  5. package/dist/Element/hooks/useElementVisible.mjs +25 -0
  6. package/dist/Element/hooks/useRscData.d.ts +4 -0
  7. package/dist/Element/hooks/useRscData.mjs +23 -19
  8. package/dist/dataSource/GlobalSources.mjs +68 -57
  9. package/dist/elements/basic/Button/declaration.d.ts +1 -1
  10. package/dist/elements/basic/Button/declaration.mjs +1 -1
  11. package/dist/elements/basic/Button/index.d.ts +1 -1
  12. package/dist/elements/basic/Dropdown/DropdownPopup/declaration.d.ts +1 -1
  13. package/dist/elements/basic/Dropdown/DropdownPopup/declaration.mjs +1 -1
  14. package/dist/elements/basic/Dropdown/DropdownPopup/index.d.ts +1 -1
  15. package/dist/elements/basic/Dropdown/index.d.ts +1 -1
  16. package/dist/elements/basic/Markdown/Markdown.d.ts +3 -3
  17. package/dist/elements/basic/Markdown/Markdown.mjs +10 -6
  18. package/dist/elements/basic/Markdown/declaration.d.ts +1 -1
  19. package/dist/elements/basic/Markdown/index.d.ts +1 -1
  20. package/dist/elements/basic/RichText/declaration.d.ts +1 -1
  21. package/dist/elements/basic/RichText/declaration.mjs +1 -1
  22. package/dist/elements/basic/RichText/index.d.ts +1 -1
  23. package/dist/elements/basic/Text/Text.d.ts +6 -1
  24. package/dist/elements/basic/Text/Text.mjs +6 -5
  25. package/dist/elements/basic/Text/declaration.d.ts +1 -0
  26. package/dist/elements/basic/Text/index.d.ts +1 -0
  27. package/dist/elements/declarations/index.d.ts +49 -9
  28. package/dist/elements/form/Form/declaration.d.ts +1 -0
  29. package/dist/elements/form/Form/declaration.mjs +2 -1
  30. package/dist/elements/form/FormControl/declaration.d.ts +1 -0
  31. package/dist/elements/form/FormControl/declaration.mjs +3 -2
  32. package/dist/elements/internal/LayoutContainer/LayoutContainer.mjs +37 -29
  33. package/dist/elements/internal/LayoutContainer/mask.d.ts +11 -0
  34. package/dist/elements/internal/LayoutContainer/mask.mjs +14 -0
  35. package/dist/elements/provider/ApiContainer/ApiContainer.d.ts +9 -1
  36. package/dist/elements/provider/ApiContainer/ApiContainer.mjs +132 -107
  37. package/dist/elements/provider/ApiContainer/declaration.d.ts +38 -10
  38. package/dist/elements/provider/ApiContainer/declaration.mjs +7 -0
  39. package/dist/elements/provider/ApiContainer/hooks/useApi.d.ts +2 -0
  40. package/dist/elements/provider/ApiContainer/hooks/useApi.mjs +1 -0
  41. package/dist/elements/provider/ApiContainer/hooks/useInputRefresh.d.ts +20 -0
  42. package/dist/elements/provider/ApiContainer/hooks/useInputRefresh.mjs +16 -0
  43. package/dist/elements/provider/ApiContainer/index.d.ts +37 -1
  44. package/dist/elements/structure/Container/Container.d.ts +6 -1
  45. package/dist/elements/structure/Container/Container.mjs +6 -5
  46. package/dist/elements/structure/Container/declaration.d.ts +2 -1
  47. package/dist/elements/structure/Container/declaration.mjs +1 -1
  48. package/dist/elements/structure/Container/index.d.ts +2 -1
  49. package/dist/elements/structure/DialogContainer/declaration.d.ts +1 -1
  50. package/dist/elements/structure/DialogContainer/declaration.mjs +1 -1
  51. package/dist/elements/structure/DialogContainer/index.d.ts +1 -1
  52. package/dist/elements/structure/List/ListItem/declaration.d.ts +1 -1
  53. package/dist/elements/structure/List/ListItem/declaration.mjs +1 -1
  54. package/dist/elements/structure/List/ListItem/index.d.ts +1 -1
  55. package/dist/elements/structure/List/index.d.ts +1 -1
  56. package/dist/elements/structure/TabContainer/TabContainerItem/declaration.d.ts +1 -1
  57. package/dist/elements/structure/TabContainer/TabContainerItem/declaration.mjs +1 -1
  58. package/dist/elements/structure/TabContainer/TabContainerItem/index.d.ts +1 -1
  59. package/dist/elements/structure/TabContainer/index.d.ts +1 -1
  60. package/dist/index.d.ts +47 -9
  61. package/package.json +21 -9
@@ -101,7 +101,7 @@ var n = {
101
101
  definition: {
102
102
  label: "Form Control",
103
103
  type: "formControl",
104
- description: "A single labelled input (text/select/checkbox/… per its subType) inside a form; captures one field of user input.",
104
+ description: "A single labelled input (text/select/checkbox/… per its subType) inside a form; captures one field of user input. A select offers its `options`: `[{ label, value }, …]` — the text shown, and what the field takes.",
105
105
  bindings: {},
106
106
  styleSelectors: {
107
107
  base: "",
@@ -126,7 +126,8 @@ var n = {
126
126
  verified: !0,
127
127
  license: "MIT",
128
128
  website: "https://plitzi.com",
129
- backgroundColor: "#4422ee"
129
+ backgroundColor: "#4422ee",
130
+ icon: "fa-solid fa-i-cursor"
130
131
  },
131
132
  defaultStyle: {
132
133
  name: "Form Control",
@@ -1,55 +1,63 @@
1
1
  import e from "../../../Element/hocs/withElement.mjs";
2
2
  import t from "../../../Element/hooks/useElement.mjs";
3
3
  import { RootElement as n } from "../../../Element/RootElement.mjs";
4
- import { useCallback as r, useEffect as i } from "react";
5
- import a from "@plitzi/sdk-shared/hooks/usePlitziServiceContext";
6
- import { throttle as o } from "@plitzi/plitzi-ui/helpers";
7
- import { jsx as s } from "react/jsx-runtime";
8
- import c from "clsx";
4
+ import { boxOf as r, maskFrameOf as i } from "./mask.mjs";
5
+ import { useCallback as a, useEffect as o } from "react";
6
+ import s from "@plitzi/sdk-shared/hooks/usePlitziServiceContext";
7
+ import { throttle as c } from "@plitzi/plitzi-ui/helpers";
8
+ import { jsx as l } from "react/jsx-runtime";
9
+ import u from "clsx";
9
10
  //#region src/elements/internal/LayoutContainer/LayoutContainer.tsx
10
- var l = ".plitzi-component__layout-container", u = ".plitzi-component--layout-body", d = (e) => [...e.querySelectorAll(u)].find((e) => !e.querySelector(u)) ?? null, f = ({ ref: e, className: u = "", children: f, subType: p = "div" }) => {
11
- let { plitziElementLayout: m } = t(), { settings: { previewMode: h } } = a(), g = r((e, t) => {
11
+ var d = ".plitzi-component__layout-container", f = ".plitzi-component--layout-body", p = (e) => [...e.querySelectorAll(f)].find((e) => !e.querySelector(f)) ?? null, m = ({ ref: e, className: f = "", children: m, subType: h = "div" }) => {
12
+ let { plitziElementLayout: g } = t(), { settings: { previewMode: _ } } = s(), v = a((e, t) => {
12
13
  if (!e) return;
13
14
  if (!t) {
14
15
  e.style.removeProperty("--child-clip");
15
16
  return;
16
17
  }
17
- let n = e.getBoundingClientRect(), r = t.getBoundingClientRect(), i = e.offsetWidth > 0 ? n.width / e.offsetWidth : 1, a = (r.top - n.top) / i, o = (r.left - n.left) / i, s = o + r.width / i, c = a + r.height / i, l = `
18
+ let n = r(t);
19
+ if (!n) {
20
+ e.style.removeProperty("--child-clip");
21
+ return;
22
+ }
23
+ let a = i(e), o = a.getBoundingClientRect(), s = a.offsetWidth > 0 ? o.width / a.offsetWidth : 1, c = (n.top - o.top) / s - a.clientTop, l = (n.left - o.left) / s - a.clientLeft, u = l + n.width / s, d = c + n.height / s, f = `
18
24
  polygon(
19
25
  evenodd,
20
26
  /* outer rect */
21
27
  0 0, 100% 0, 100% 100%, 0% 100%, 0 0,
22
28
  /* inner rect */
23
- ${o}px ${a}px, ${s}px ${a}px, ${s}px ${c}px, ${o}px ${c}px, ${o}px ${a}px
29
+ ${l}px ${c}px, ${u}px ${c}px, ${u}px ${d}px, ${l}px ${d}px, ${l}px ${c}px
24
30
  )`;
25
- e.style.setProperty("--child-clip", l);
31
+ e.style.setProperty("--child-clip", f);
26
32
  }, []);
27
- return i(() => {
33
+ return o(() => {
28
34
  let t = e?.current;
29
- if (!m || !t || h || t.parentElement?.closest(l)) return;
30
- let n = null, r = o(() => {
31
- let e = d(t);
32
- e !== n && (n && i.unobserve(n), e && i.observe(e), n = e), g(t, e);
33
- }, 50), i = new ResizeObserver(r);
34
- i.observe(t);
35
- let a = new MutationObserver(r);
36
- return a.observe(t, {
35
+ if (!g || !t || _ || t.parentElement?.closest(d)) return;
36
+ let n = null, r = c(() => {
37
+ let e = p(t);
38
+ e !== n && (n && a.unobserve(n), e && a.observe(e), n = e), v(t, e);
39
+ }, 50), a = new ResizeObserver(r);
40
+ a.observe(t);
41
+ let o = i(t);
42
+ o !== t && a.observe(o);
43
+ let s = new MutationObserver(r);
44
+ return s.observe(t, {
37
45
  childList: !0,
38
46
  subtree: !0
39
47
  }), t.addEventListener("scroll", r, !0), r(), () => {
40
- r.cancel(), i.disconnect(), a.disconnect(), t.removeEventListener("scroll", r, !0);
48
+ r.cancel(), a.disconnect(), s.disconnect(), t.removeEventListener("scroll", r, !0);
41
49
  };
42
50
  }, [
43
- m,
44
- h,
51
+ g,
52
+ _,
45
53
  e,
46
- g
47
- ]), /* @__PURE__ */ s(n, {
54
+ v
55
+ ]), /* @__PURE__ */ l(n, {
48
56
  ref: e,
49
- tag: p,
50
- className: c("plitzi-component__layout-container", u),
51
- children: f
57
+ tag: h,
58
+ className: u("plitzi-component__layout-container", f),
59
+ children: m
52
60
  });
53
- }, p = e(f);
61
+ }, h = e(m);
54
62
  //#endregion
55
- export { f as LayoutContainer, p as default };
63
+ export { m as LayoutContainer, h as default };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The box an element draws on screen: its own — or, for one with `display: contents`, which draws none, the box around
3
+ * what it holds. A shell or a slot that only marks where something goes is written that way, and measured as itself it
4
+ * is a rect of zeros: the hole closes and the whole page is dimmed.
5
+ */
6
+ export declare const boxOf: (element: Element) => DOMRect | undefined;
7
+ /**
8
+ * The box the mask is drawn in. The mask is the layout's `::before`, placed over its containing block: the layout's own
9
+ * box — or, when the layout draws none, the nearest ancestor that positions what it holds.
10
+ */
11
+ export declare const maskFrameOf: (layout: HTMLElement) => HTMLElement;
@@ -0,0 +1,14 @@
1
+ //#region src/elements/internal/LayoutContainer/mask.ts
2
+ var e = (e) => getComputedStyle(e).display === "contents", t = (n) => {
3
+ if (!e(n)) return n.getBoundingClientRect();
4
+ let r = [...n.children].map(t).filter((e) => e !== void 0 && (e.width > 0 || e.height > 0));
5
+ if (r.length === 0) return;
6
+ let i = Math.min(...r.map((e) => e.left)), a = Math.min(...r.map((e) => e.top));
7
+ return new DOMRect(i, a, Math.max(...r.map((e) => e.right)) - i, Math.max(...r.map((e) => e.bottom)) - a);
8
+ }, n = (t) => {
9
+ if (!e(t)) return t;
10
+ for (let e = t.parentElement; e; e = e.parentElement) if (getComputedStyle(e).position !== "static") return e;
11
+ return t.ownerDocument.documentElement;
12
+ };
13
+ //#endregion
14
+ export { t as boxOf, n as maskFrameOf };
@@ -27,6 +27,14 @@ export type ApiContainerProps = {
27
27
  * route and query params, and answers whatever its output step returns.
28
28
  */
29
29
  action?: string;
30
+ /**
31
+ * What a server provider asks its action with, on top of the page's own route and query params — a search, a filter.
32
+ *
33
+ * Saved, it is what the page server resolves the first paint with. Bound — to a state the visitor changes — every
34
+ * change asks again with the new value, the way a bound `query` does for a browser provider; `reloadApi` with an
35
+ * input asks once.
36
+ */
37
+ input?: Record<string, unknown> | string;
30
38
  /** Which of the connector's read endpoints to execute. Defaults to `list`. */
31
39
  endpoint?: string;
32
40
  /** Content type / collection read through the connector. */
@@ -75,7 +83,7 @@ export type ApiContainerProps = {
75
83
  */
76
84
  refreshSeconds?: number | string;
77
85
  };
78
- declare const ApiContainer: ({ ref, className, children, query, method, accessToken, when, headers, mockData, subType, credentials, singleRecord, pagination, pageParam, renderWhileLoading, loadingSlot, cache, staleTime, gcTime, refreshSeconds, connector, action }: ApiContainerProps) => import('react').JSX.Element;
86
+ declare const ApiContainer: ({ ref, className, children, query, method, accessToken, when, headers, mockData, subType, credentials, singleRecord, pagination, pageParam, renderWhileLoading, loadingSlot, cache, staleTime, gcTime, refreshSeconds, connector, action, input }: ApiContainerProps) => import('react').JSX.Element;
79
87
  declare const _default: {
80
88
  (props: import('../../../Element/hocs/withElement').WithElementProps<ApiContainerProps>): import('react').JSX.Element;
81
89
  displayName: string;
@@ -8,36 +8,37 @@ import { childrenWhile as re } from "./helpers/loadingSlot.mjs";
8
8
  import ie from "./helpers/providerOutcome.mjs";
9
9
  import { queryInputOf as ae } from "./helpers/queryInput.mjs";
10
10
  import { serverMock as oe } from "./helpers/serverMock.mjs";
11
- import r from "./hooks/useApi.mjs";
12
- import se from "./hooks/useAutoRefresh.mjs";
13
- import ce from "./hooks/useProviderPagination.mjs";
14
- import le from "./hooks/useProviderWrite.mjs";
15
- import ue from "../../../dataSource/pathFields.mjs";
16
- import { use as de, useCallback as i, useEffect as fe, useMemo as a, useRef as pe } from "react";
17
- import me from "@plitzi/sdk-shared/hooks/usePlitziServiceContext";
18
- import { useSdkStore as he } from "@plitzi/sdk-shared/store";
19
- import { StoreProvider as ge } from "@plitzi/nexus/react";
11
+ import se from "./hooks/useApi.mjs";
12
+ import ce from "./hooks/useAutoRefresh.mjs";
13
+ import le from "./hooks/useInputRefresh.mjs";
14
+ import ue from "./hooks/useProviderPagination.mjs";
15
+ import de from "./hooks/useProviderWrite.mjs";
16
+ import fe from "../../../dataSource/pathFields.mjs";
17
+ import { use as pe, useCallback as r, useEffect as me, useMemo as i, useRef as a } from "react";
18
+ import he from "@plitzi/sdk-shared/hooks/usePlitziServiceContext";
19
+ import { useCommonStore as ge, useSdkStore as _e } from "@plitzi/sdk-shared/store";
20
+ import { StoreProvider as ve } from "@plitzi/nexus/react";
20
21
  import { emptyObject as o } from "@plitzi/sdk-shared/helpers/utils";
21
22
  import { jsx as s } from "react/jsx-runtime";
22
- import { currentRscLocation as _e } from "@plitzi/sdk-shared/server/rsc/refreshRsc";
23
- import ve from "clsx";
24
- import ye from "@plitzi/sdk-shared/dataSource/helpers/getSourceName";
25
- import be from "@plitzi/sdk-shared/dataSource/hooks/useRegisterSource";
26
- import { QueryBuilderEvaluator as xe } from "@plitzi/plitzi-ui/QueryBuilder";
23
+ import { currentRscLocation as ye } from "@plitzi/sdk-shared/server/rsc/refreshRsc";
24
+ import be from "clsx";
25
+ import xe from "@plitzi/sdk-shared/dataSource/helpers/getSourceName";
26
+ import Se from "@plitzi/sdk-shared/dataSource/hooks/useRegisterSource";
27
+ import { QueryBuilderEvaluator as Ce } from "@plitzi/plitzi-ui/QueryBuilder";
27
28
  //#region src/elements/provider/ApiContainer/ApiContainer.tsx
28
- var c = ({ ref: e, className: c = "", children: l, query: u = "", method: d = "get", accessToken: f = "", when: p = o, headers: m = o, mockData: h = "{}", subType: Se = "", credentials: Ce = "same-origin", singleRecord: g = !1, pagination: we = "none", pageParam: Te = "page", renderWhileLoading: Ee = !1, loadingSlot: _ = "", cache: De = !1, staleTime: Oe = 30, gcTime: ke = 300, refreshSeconds: Ae = 0, connector: je = "", action: Me = "" }) => {
29
- let { id: v, visible: y, definition: { label: b = "Api Container", runtime: x, items: Ne } } = t(), S = x === "server", { loaded: C, stale: w, location: T, elementData: E, refresh: D } = ee(), O = ye(n.sourceType, v), { settings: { previewMode: k }, contexts: { InteractionsContext: Pe } } = me(), { interactionsManager: A } = de(Pe), [[j, M, Fe]] = he([
29
+ var c = ({ ref: e, className: c = "", children: l, query: u = "", method: d = "get", accessToken: f = "", when: p = o, headers: m = o, mockData: h = "{}", subType: we = "", credentials: Te = "same-origin", singleRecord: g = !1, pagination: Ee = "none", pageParam: De = "page", renderWhileLoading: Oe = !1, loadingSlot: _ = "", cache: ke = !1, staleTime: Ae = 30, gcTime: je = 300, refreshSeconds: Me = 0, connector: Ne = "", action: Pe = "", input: Fe }) => {
30
+ let { id: v, visible: y, definition: { label: b = "Api Container", runtime: Ie, items: Le } } = t(), x = Ie === "server", { loaded: S, stale: C, location: w, elementData: T, refreshing: Re, refresh: E, cancel: D } = ee(), O = xe(n.sourceType, v), { settings: { previewMode: k }, contexts: { InteractionsContext: ze } } = he(), { interactionsManager: A } = pe(ze), [[j, M, Be]] = _e([
30
31
  "navigation.routeParams",
31
32
  "navigation.queryParams",
32
33
  "navigation.navigate"
33
- ]), Ie = a(() => f ? {
34
+ ]), Ve = i(() => f ? {
34
35
  ...m,
35
36
  Authorization: `Bearer ${f}`
36
- } : m, [m, f]), N = a(() => S || !y ? !1 : !!(k && u && (p === o || xe(p, {
37
+ } : m, [m, f]), N = i(() => x || !y ? !1 : !!(k && u && (p === o || Ce(p, {
37
38
  ...j,
38
39
  ...M
39
40
  })) || !k && (u || h && h !== "{}" && h !== o)), [
40
- S,
41
+ x,
41
42
  y,
42
43
  k,
43
44
  u,
@@ -45,155 +46,179 @@ var c = ({ ref: e, className: c = "", children: l, query: u = "", method: d = "g
45
46
  j,
46
47
  M,
47
48
  h
48
- ]), Le = a(() => [v], [v]), { isLoading: Re, isFetching: ze, data: P, refetch: F, isSuccess: Be, isError: Ve } = r({
49
+ ]), He = i(() => [v], [v]), { isLoading: Ue, isFetching: We, data: P, refetch: F, cancel: I, isSuccess: Ge, isError: Ke } = se({
49
50
  url: u,
50
51
  method: d,
51
- credentials: Ce,
52
+ credentials: Te,
52
53
  mock: k ? void 0 : h,
53
- customHeaders: Ie,
54
+ customHeaders: Ve,
54
55
  enabled: N,
55
- cache: De,
56
- staleTime: Oe,
57
- gcTime: ke,
58
- tags: Le
59
- }), I = S && !!T && T !== _e(), L = S && C && !I && E === null, R = S && !je && !Me, z = a(() => S ? E || (C ? o : oe(h, R)) : P ?? o, [
60
- S,
56
+ cache: ke,
57
+ staleTime: Ae,
58
+ gcTime: je,
59
+ tags: He
60
+ }), L = x && !!w && w !== ye(), R = x && S && !L && T === null, z = x && !Ne && !Pe, B = i(() => x ? T || (S ? o : oe(h, z)) : P ?? o, [
61
+ x,
61
62
  P,
62
- E,
63
- C,
63
+ T,
64
+ S,
64
65
  h,
65
- R
66
- ]), B = S ? I : ze, V = S ? I : Re, H = pe({}), U = i((e, t) => D(e, {
67
- ...H.current,
66
+ z
67
+ ]), V = x ? L || Re : We, H = x ? L : Ue, U = a({}), W = r((e, t) => E(e, {
68
+ ...U.current,
68
69
  ...t
69
- }), [D]), W = i(async () => {
70
- if (!S) {
70
+ }), [E]), G = r(async () => {
71
+ if (!x) {
71
72
  F();
72
73
  return;
73
74
  }
74
- await U([v]);
75
+ await W([v]);
75
76
  }, [
76
- S,
77
+ x,
77
78
  F,
78
- U,
79
+ W,
79
80
  v
80
- ]), G = i(async ({ input: e } = {}) => {
81
+ ]), K = r(async ({ input: e } = {}) => {
81
82
  let t = ae(e);
82
- t && (H.current = t), await W();
83
- }, [W]);
84
- se({
85
- seconds: Ae,
86
- enabled: y && (S ? C && !I : N),
87
- refresh: W
83
+ t && (U.current = t), await G();
84
+ }, [G]), q = r(() => {
85
+ if (x) {
86
+ D();
87
+ return;
88
+ }
89
+ I();
90
+ }, [
91
+ x,
92
+ D,
93
+ I
94
+ ]), [qe] = ge(`schema.flat.${v}.attributes.input`, { mode: "mount" });
95
+ le({
96
+ enabled: x && S,
97
+ input: Fe,
98
+ savedInput: qe,
99
+ performQuery: K
100
+ }), ce({
101
+ seconds: Me,
102
+ enabled: y && (x ? S && !L : N),
103
+ refresh: G
88
104
  });
89
- let K = z, He = a(() => Array.isArray(K.records) ? K.records : [], [K.records]), { records: q, isLoadingMore: J, goToPage: Y, loadMore: X } = ce({
105
+ let J = B, Je = i(() => Array.isArray(J.records) ? J.records : [], [J.records]), { records: Y, isLoadingMore: Ye, goToPage: Xe, loadMore: Ze } = ue({
90
106
  elementId: v,
91
- mode: we,
92
- pageParam: Te,
93
- records: He,
94
- page: K.pageInfo?.page ?? 1,
95
- refresh: U,
96
- navigate: Fe
97
- }), Z = ie({
98
- serverMode: S,
99
- isSuccess: Be,
100
- isError: Ve,
101
- rscResolved: C,
102
- rscPending: I,
103
- elementData: E
104
- });
105
- fe(() => {
106
- !B && v && Z && A.interactionTrigger(v, Z === "success" ? "onApiSuccess" : "onApiError", {
107
+ mode: Ee,
108
+ pageParam: De,
109
+ records: Je,
110
+ page: J.pageInfo?.page ?? 1,
111
+ refresh: W,
112
+ navigate: Be
113
+ }), X = ie({
114
+ serverMode: x,
115
+ isSuccess: Ge,
116
+ isError: Ke,
117
+ rscResolved: S,
118
+ rscPending: L,
119
+ elementData: T
120
+ }), Z = a(void 0);
121
+ me(() => {
122
+ !V && v && X && (Z.current?.data !== B || Z.current.outcome !== X) && (Z.current = {
123
+ data: B,
124
+ outcome: X
125
+ }, A.interactionTrigger(v, X === "success" ? "onApiSuccess" : "onApiError", {
107
126
  url: u,
108
127
  method: d,
109
- ...z
110
- });
128
+ ...B
129
+ }));
111
130
  }, [
112
- z,
131
+ B,
113
132
  v,
114
133
  A,
115
- B,
134
+ V,
116
135
  d,
117
- Z,
136
+ X,
118
137
  u
119
138
  ]);
120
- let Q = a(() => ({
121
- ...z,
122
- ...Array.isArray(K.records) ? { records: q } : o,
123
- isLoading: B || J,
124
- isEmpty: ne(K, q, g),
125
- hasError: L,
126
- errorMessage: L ? "The data provider could not be reached" : "",
127
- isStale: S && w
139
+ let Q = i(() => ({
140
+ ...B,
141
+ ...Array.isArray(J.records) ? { records: Y } : o,
142
+ isLoading: V || Ye,
143
+ isEmpty: ne(J, Y, g),
144
+ hasError: R,
145
+ errorMessage: R ? "The data provider could not be reached" : "",
146
+ isStale: x && C
128
147
  }), [
129
- z,
130
- K.records,
131
- K.record,
132
- q,
133
148
  B,
134
- J,
149
+ J.records,
150
+ J.record,
151
+ Y,
152
+ V,
153
+ Ye,
135
154
  g,
136
- L,
137
- S,
138
- w
139
- ]), Ue = i(() => ue(Q), [Q]);
140
- be({
155
+ R,
156
+ x,
157
+ C
158
+ ]), Qe = r(() => fe(Q), [Q]);
159
+ Se({
141
160
  id: v,
142
161
  source: O,
143
162
  name: b || `API - ${v}`,
144
- fields: Ue
163
+ fields: Qe
145
164
  });
146
- let { writeRecord: $ } = le({
165
+ let { writeRecord: $ } = de({
147
166
  elementId: v,
148
- enabled: S,
149
- onDone: W
150
- }), We = a(() => {
167
+ enabled: x,
168
+ onDone: G
169
+ }), $e = i(() => {
151
170
  let e = {
152
171
  performQuery: {
153
172
  ...n.callbacks.performQuery,
154
173
  title: `Perform Query ${b}`,
155
- callback: G
174
+ callback: K
175
+ },
176
+ cancelQuery: {
177
+ ...n.callbacks.cancelQuery,
178
+ title: `Cancel Query ${b}`,
179
+ callback: q
156
180
  },
157
181
  loadMore: {
158
182
  ...n.callbacks.loadMore,
159
183
  title: `Load More ${b}`,
160
- callback: X
184
+ callback: Ze
161
185
  },
162
186
  goToPage: {
163
187
  ...n.callbacks.goToPage,
164
188
  title: `Go To Page ${b}`,
165
- callback: ({ page: e }) => Y(Number(e) || 1)
189
+ callback: ({ page: e }) => Xe(Number(e) || 1)
166
190
  }
167
191
  };
168
- return S && (e.writeRecord = {
192
+ return x && (e.writeRecord = {
169
193
  ...n.callbacks.writeRecord,
170
194
  title: `Write Record ${b}`,
171
195
  callback: $
172
196
  }), e;
173
197
  }, [
174
198
  b,
175
- G,
176
- X,
177
- Y,
178
- S,
199
+ K,
200
+ q,
201
+ Ze,
202
+ Xe,
203
+ x,
179
204
  $
180
- ]), Ge = a(() => _ && k ? re(l, _, V) : l, [
205
+ ]), et = i(() => _ && k ? re(l, _, H) : l, [
181
206
  l,
182
- V,
207
+ H,
183
208
  _,
184
209
  k
185
- ]), Ke = a(() => O ? { runtime: { sources: { [O]: Q } } } : o, [Q, O]);
210
+ ]), tt = i(() => O ? { runtime: { sources: { [O]: Q } } } : o, [Q, O]);
186
211
  return /* @__PURE__ */ s(te, {
187
212
  ref: e,
188
- tag: !k && !Ne?.length ? "div" : Se,
189
- className: ve("plitzi-component__api-container", c),
213
+ tag: !k && !Le?.length ? "div" : we,
214
+ className: be("plitzi-component__api-container", c),
190
215
  interactionTriggers: n.triggers,
191
- interactionCallbacks: We,
192
- children: (!V || Ee || _) && /* @__PURE__ */ s(ge, {
216
+ interactionCallbacks: $e,
217
+ children: (!H || Oe || _) && /* @__PURE__ */ s(ve, {
193
218
  inherit: "live",
194
219
  name: `Api:${v}`,
195
- value: Ke,
196
- children: Ge
220
+ value: tt,
221
+ children: et
197
222
  })
198
223
  });
199
224
  }, l = e(c);
@@ -1,15 +1,7 @@
1
1
  import { ApiContainerProps } from './ApiContainer';
2
2
  import { AuthorableAttributes } from '@plitzi/sdk-shared/authoring/declare';
3
3
  /** What this element can be authored with — its component's own props, minus what the runtime supplies. */
4
- export type ApiContainerAttributes = AuthorableAttributes<ApiContainerProps> & {
5
- /**
6
- * What this element asks of the action it names, on top of the page's own route and query params.
7
- *
8
- * Not a component prop, and it never will be: the action runs on the server, so this is read there and the
9
- * element only ever sees what came back.
10
- */
11
- input?: Record<string, unknown>;
12
- };
4
+ export type ApiContainerAttributes = AuthorableAttributes<ApiContainerProps>;
13
5
  declare const declaration: {
14
6
  readonly type: "apiContainer";
15
7
  readonly attributeValues: {
@@ -60,6 +52,13 @@ declare const declaration: {
60
52
  };
61
53
  };
62
54
  };
55
+ readonly cancelQuery: {
56
+ readonly action: "cancelQuery";
57
+ readonly title: "Cancel Query";
58
+ readonly type: "callback";
59
+ readonly preview: {};
60
+ readonly params: {};
61
+ };
63
62
  readonly loadMore: {
64
63
  readonly action: "loadMore";
65
64
  readonly title: "Load More";
@@ -164,5 +163,34 @@ declare const declaration: {
164
163
  };
165
164
  readonly settings: {};
166
165
  };
167
- } & import('@plitzi/sdk-shared/authoring/declare').ElementAttributesBrand<ApiContainerAttributes>;
166
+ } & import('@plitzi/sdk-shared/authoring/declare').ElementAttributesBrand<Partial<{
167
+ when?: import('@plitzi/sdk-shared').RuleGroup | undefined;
168
+ action?: string | undefined;
169
+ cache?: boolean | undefined;
170
+ endpoint?: string | undefined;
171
+ input?: (Record<string, unknown> | string) | undefined;
172
+ method?: "get" | "post" | "put" | "delete" | "patch" | undefined;
173
+ resource?: string | undefined;
174
+ headers?: Record<string, string> | undefined;
175
+ subType?: "div" | "header" | "footer" | "nav" | "main" | "section" | "article" | "aside" | "address" | "figure" | "" | undefined;
176
+ query?: string | undefined;
177
+ accessToken?: string | undefined;
178
+ mockData?: (Record<string, unknown> | string) | undefined;
179
+ credentials?: RequestCredentials | undefined;
180
+ connector?: string | undefined;
181
+ limit?: string | undefined;
182
+ singleRecord?: boolean | undefined;
183
+ filters?: {
184
+ field: string;
185
+ operator: string;
186
+ value: string;
187
+ }[] | undefined;
188
+ pagination?: import('./hooks/useProviderPagination').ProviderPagination | undefined;
189
+ pageParam?: string | undefined;
190
+ renderWhileLoading?: boolean | undefined;
191
+ loadingSlot?: string | undefined;
192
+ staleTime?: number | string | undefined;
193
+ gcTime?: number | string | undefined;
194
+ refreshSeconds?: number | string | undefined;
195
+ }>>;
168
196
  export default declaration;
@@ -74,6 +74,13 @@ var n = e()({
74
74
  description: "Values handed to a server-driven provider with its request, beside the page’s own route and query params — a search, a filter. Kept for the pages it loads after (`loadMore`, `goToPage`) until the next query."
75
75
  } }
76
76
  },
77
+ cancelQuery: {
78
+ action: "cancelQuery",
79
+ title: "Cancel Query",
80
+ type: "callback",
81
+ preview: {},
82
+ params: {}
83
+ },
77
84
  loadMore: {
78
85
  action: "loadMore",
79
86
  title: "Load More",
@@ -39,6 +39,8 @@ declare const useApi: ({ url, method, mock, customHeaders, enabled, credentials,
39
39
  isFetching: boolean;
40
40
  data: ApiResponse | undefined;
41
41
  refetch: () => void;
42
+ /** Stops the request in flight; the last answer stays on screen. */
43
+ cancel: () => void;
42
44
  /**
43
45
  * Whether THIS question has been answered — not whether an answer is on screen.
44
46
  *
@@ -94,6 +94,7 @@ var l = 30, u = 300, d = (e) => !!e && e !== "{}" && e !== i, f = (e) => {
94
94
  isFetching: A,
95
95
  data: k,
96
96
  refetch: D.refetch,
97
+ cancel: D.cancel,
97
98
  isSuccess: !w && !A && !!k && k.status < 400,
98
99
  isError: !w && !A && !!k && k.status >= 400
99
100
  };
@@ -0,0 +1,20 @@
1
+ export type UseInputRefreshProps = {
2
+ /** A server provider whose payload has arrived: there is a question to ask again. */
3
+ enabled: boolean;
4
+ /** The input as it resolves now — bound to state, it changes as the visitor does. */
5
+ input: unknown;
6
+ /** The input the element was saved with: what the page server resolved the first paint with. */
7
+ savedInput: unknown;
8
+ performQuery: (options: {
9
+ input?: unknown;
10
+ }) => Promise<void>;
11
+ };
12
+ /**
13
+ * A bound `input` asks again when what it says changes.
14
+ *
15
+ * The first paint was resolved by the page server with the input the element was SAVED with — bindings to the
16
+ * visitor's state are not the server's to read — so that is what the first value is compared against: a binding that
17
+ * already says something else (a state kept from the last visit) asks at once.
18
+ */
19
+ declare const useInputRefresh: ({ enabled, input, savedInput, performQuery }: UseInputRefreshProps) => void;
20
+ export default useInputRefresh;
@@ -0,0 +1,16 @@
1
+ import { queryInputOf as e } from "../helpers/queryInput.mjs";
2
+ import { useEffect as t, useRef as n } from "react";
3
+ //#region src/elements/provider/ApiContainer/hooks/useInputRefresh.ts
4
+ var r = ({ enabled: r, input: i, savedInput: a, performQuery: o }) => {
5
+ let s = JSON.stringify(e(i) ?? {}), c = n(JSON.stringify(e(a) ?? {}));
6
+ t(() => {
7
+ r && s !== c.current && (c.current = s, o({ input: i }));
8
+ }, [
9
+ r,
10
+ s,
11
+ i,
12
+ o
13
+ ]);
14
+ };
15
+ //#endregion
16
+ export { r as default };