@plitzi/sdk-elements 0.38.4 → 0.38.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.
- package/CHANGELOG.md +337 -0
- package/dist/Element/helpers/elementChildren.d.ts +29 -0
- package/dist/Element/helpers/elementChildren.mjs +16 -0
- package/dist/Element/hooks/useElementVisible.d.ts +11 -0
- package/dist/Element/hooks/useElementVisible.mjs +25 -0
- package/dist/Element/hooks/useRscData.d.ts +4 -0
- package/dist/Element/hooks/useRscData.mjs +23 -19
- package/dist/dataSource/GlobalSources.mjs +68 -57
- package/dist/elements/basic/Button/declaration.d.ts +1 -1
- package/dist/elements/basic/Button/declaration.mjs +1 -1
- package/dist/elements/basic/Button/index.d.ts +1 -1
- package/dist/elements/basic/Dropdown/DropdownPopup/declaration.d.ts +1 -1
- package/dist/elements/basic/Dropdown/DropdownPopup/declaration.mjs +1 -1
- package/dist/elements/basic/Dropdown/DropdownPopup/index.d.ts +1 -1
- package/dist/elements/basic/Dropdown/index.d.ts +1 -1
- package/dist/elements/basic/Markdown/Markdown.d.ts +3 -3
- package/dist/elements/basic/Markdown/Markdown.mjs +10 -6
- package/dist/elements/basic/Markdown/declaration.d.ts +1 -1
- package/dist/elements/basic/Markdown/index.d.ts +1 -1
- package/dist/elements/basic/RichText/declaration.d.ts +1 -1
- package/dist/elements/basic/RichText/declaration.mjs +1 -1
- package/dist/elements/basic/RichText/index.d.ts +1 -1
- package/dist/elements/basic/Text/Text.d.ts +6 -1
- package/dist/elements/basic/Text/Text.mjs +6 -5
- package/dist/elements/basic/Text/declaration.d.ts +1 -0
- package/dist/elements/basic/Text/index.d.ts +1 -0
- package/dist/elements/declarations/index.d.ts +49 -9
- package/dist/elements/form/Form/declaration.d.ts +1 -0
- package/dist/elements/form/Form/declaration.mjs +2 -1
- package/dist/elements/form/FormControl/declaration.d.ts +1 -0
- package/dist/elements/form/FormControl/declaration.mjs +3 -2
- package/dist/elements/internal/LayoutContainer/LayoutContainer.mjs +37 -29
- package/dist/elements/internal/LayoutContainer/mask.d.ts +11 -0
- package/dist/elements/internal/LayoutContainer/mask.mjs +14 -0
- package/dist/elements/provider/ApiContainer/ApiContainer.d.ts +9 -1
- package/dist/elements/provider/ApiContainer/ApiContainer.mjs +132 -107
- package/dist/elements/provider/ApiContainer/declaration.d.ts +38 -10
- package/dist/elements/provider/ApiContainer/declaration.mjs +7 -0
- package/dist/elements/provider/ApiContainer/hooks/useApi.d.ts +2 -0
- package/dist/elements/provider/ApiContainer/hooks/useApi.mjs +1 -0
- package/dist/elements/provider/ApiContainer/hooks/useInputRefresh.d.ts +20 -0
- package/dist/elements/provider/ApiContainer/hooks/useInputRefresh.mjs +16 -0
- package/dist/elements/provider/ApiContainer/index.d.ts +37 -1
- package/dist/elements/structure/Container/Container.d.ts +6 -1
- package/dist/elements/structure/Container/Container.mjs +6 -5
- package/dist/elements/structure/Container/declaration.d.ts +2 -1
- package/dist/elements/structure/Container/declaration.mjs +1 -1
- package/dist/elements/structure/Container/index.d.ts +2 -1
- package/dist/elements/structure/DialogContainer/declaration.d.ts +1 -1
- package/dist/elements/structure/DialogContainer/declaration.mjs +1 -1
- package/dist/elements/structure/DialogContainer/index.d.ts +1 -1
- package/dist/elements/structure/List/ListItem/declaration.d.ts +1 -1
- package/dist/elements/structure/List/ListItem/declaration.mjs +1 -1
- package/dist/elements/structure/List/ListItem/index.d.ts +1 -1
- package/dist/elements/structure/List/index.d.ts +1 -1
- package/dist/elements/structure/TabContainer/TabContainerItem/declaration.d.ts +1 -1
- package/dist/elements/structure/TabContainer/TabContainerItem/declaration.mjs +1 -1
- package/dist/elements/structure/TabContainer/TabContainerItem/index.d.ts +1 -1
- package/dist/elements/structure/TabContainer/index.d.ts +1 -1
- package/dist/index.d.ts +47 -9
- 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 {
|
|
5
|
-
import a from "
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
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
|
|
11
|
-
let { plitziElementLayout:
|
|
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 =
|
|
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
|
-
${
|
|
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",
|
|
31
|
+
e.style.setProperty("--child-clip", f);
|
|
26
32
|
}, []);
|
|
27
|
-
return
|
|
33
|
+
return o(() => {
|
|
28
34
|
let t = e?.current;
|
|
29
|
-
if (!
|
|
30
|
-
let n = null, r =
|
|
31
|
-
let e =
|
|
32
|
-
e !== n && (n &&
|
|
33
|
-
}, 50),
|
|
34
|
-
|
|
35
|
-
let
|
|
36
|
-
|
|
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(),
|
|
48
|
+
r.cancel(), a.disconnect(), s.disconnect(), t.removeEventListener("scroll", r, !0);
|
|
41
49
|
};
|
|
42
50
|
}, [
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
g,
|
|
52
|
+
_,
|
|
45
53
|
e,
|
|
46
|
-
|
|
47
|
-
]), /* @__PURE__ */
|
|
54
|
+
v
|
|
55
|
+
]), /* @__PURE__ */ l(n, {
|
|
48
56
|
ref: e,
|
|
49
|
-
tag:
|
|
50
|
-
className:
|
|
51
|
-
children:
|
|
57
|
+
tag: h,
|
|
58
|
+
className: u("plitzi-component__layout-container", f),
|
|
59
|
+
children: m
|
|
52
60
|
});
|
|
53
|
-
},
|
|
61
|
+
}, h = e(m);
|
|
54
62
|
//#endregion
|
|
55
|
-
export {
|
|
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
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import me from "
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
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
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import { QueryBuilderEvaluator as
|
|
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:
|
|
29
|
-
let { id: v, visible: y, definition: { label: b = "Api Container", runtime:
|
|
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
|
-
]),
|
|
34
|
+
]), Ve = i(() => f ? {
|
|
34
35
|
...m,
|
|
35
36
|
Authorization: `Bearer ${f}`
|
|
36
|
-
} : m, [m, f]), N =
|
|
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
|
-
|
|
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
|
-
]),
|
|
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:
|
|
52
|
+
credentials: Te,
|
|
52
53
|
mock: k ? void 0 : h,
|
|
53
|
-
customHeaders:
|
|
54
|
+
customHeaders: Ve,
|
|
54
55
|
enabled: N,
|
|
55
|
-
cache:
|
|
56
|
-
staleTime:
|
|
57
|
-
gcTime:
|
|
58
|
-
tags:
|
|
59
|
-
}),
|
|
60
|
-
|
|
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
|
-
|
|
63
|
-
|
|
63
|
+
T,
|
|
64
|
+
S,
|
|
64
65
|
h,
|
|
65
|
-
|
|
66
|
-
]),
|
|
67
|
-
...
|
|
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
|
-
}), [
|
|
70
|
-
if (!
|
|
70
|
+
}), [E]), G = r(async () => {
|
|
71
|
+
if (!x) {
|
|
71
72
|
F();
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
|
-
await
|
|
75
|
+
await W([v]);
|
|
75
76
|
}, [
|
|
76
|
-
|
|
77
|
+
x,
|
|
77
78
|
F,
|
|
78
|
-
|
|
79
|
+
W,
|
|
79
80
|
v
|
|
80
|
-
]),
|
|
81
|
+
]), K = r(async ({ input: e } = {}) => {
|
|
81
82
|
let t = ae(e);
|
|
82
|
-
t && (
|
|
83
|
-
}, [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|
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:
|
|
92
|
-
pageParam:
|
|
93
|
-
records:
|
|
94
|
-
page:
|
|
95
|
-
refresh:
|
|
96
|
-
navigate:
|
|
97
|
-
}),
|
|
98
|
-
serverMode:
|
|
99
|
-
isSuccess:
|
|
100
|
-
isError:
|
|
101
|
-
rscResolved:
|
|
102
|
-
rscPending:
|
|
103
|
-
elementData:
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
!
|
|
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
|
-
...
|
|
110
|
-
});
|
|
128
|
+
...B
|
|
129
|
+
}));
|
|
111
130
|
}, [
|
|
112
|
-
|
|
131
|
+
B,
|
|
113
132
|
v,
|
|
114
133
|
A,
|
|
115
|
-
|
|
134
|
+
V,
|
|
116
135
|
d,
|
|
117
|
-
|
|
136
|
+
X,
|
|
118
137
|
u
|
|
119
138
|
]);
|
|
120
|
-
let Q =
|
|
121
|
-
...
|
|
122
|
-
...Array.isArray(
|
|
123
|
-
isLoading:
|
|
124
|
-
isEmpty: ne(
|
|
125
|
-
hasError:
|
|
126
|
-
errorMessage:
|
|
127
|
-
isStale:
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
]),
|
|
140
|
-
|
|
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:
|
|
163
|
+
fields: Qe
|
|
145
164
|
});
|
|
146
|
-
let { writeRecord: $ } =
|
|
165
|
+
let { writeRecord: $ } = de({
|
|
147
166
|
elementId: v,
|
|
148
|
-
enabled:
|
|
149
|
-
onDone:
|
|
150
|
-
}),
|
|
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:
|
|
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:
|
|
184
|
+
callback: Ze
|
|
161
185
|
},
|
|
162
186
|
goToPage: {
|
|
163
187
|
...n.callbacks.goToPage,
|
|
164
188
|
title: `Go To Page ${b}`,
|
|
165
|
-
callback: ({ page: e }) =>
|
|
189
|
+
callback: ({ page: e }) => Xe(Number(e) || 1)
|
|
166
190
|
}
|
|
167
191
|
};
|
|
168
|
-
return
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
199
|
+
K,
|
|
200
|
+
q,
|
|
201
|
+
Ze,
|
|
202
|
+
Xe,
|
|
203
|
+
x,
|
|
179
204
|
$
|
|
180
|
-
]),
|
|
205
|
+
]), et = i(() => _ && k ? re(l, _, H) : l, [
|
|
181
206
|
l,
|
|
182
|
-
|
|
207
|
+
H,
|
|
183
208
|
_,
|
|
184
209
|
k
|
|
185
|
-
]),
|
|
210
|
+
]), tt = i(() => O ? { runtime: { sources: { [O]: Q } } } : o, [Q, O]);
|
|
186
211
|
return /* @__PURE__ */ s(te, {
|
|
187
212
|
ref: e,
|
|
188
|
-
tag: !k && !
|
|
189
|
-
className:
|
|
213
|
+
tag: !k && !Le?.length ? "div" : we,
|
|
214
|
+
className: be("plitzi-component__api-container", c),
|
|
190
215
|
interactionTriggers: n.triggers,
|
|
191
|
-
interactionCallbacks:
|
|
192
|
-
children: (!
|
|
216
|
+
interactionCallbacks: $e,
|
|
217
|
+
children: (!H || Oe || _) && /* @__PURE__ */ s(ve, {
|
|
193
218
|
inherit: "live",
|
|
194
219
|
name: `Api:${v}`,
|
|
195
|
-
value:
|
|
196
|
-
children:
|
|
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<
|
|
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
|
*
|
|
@@ -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 };
|