@plitzi/sdk-elements 0.32.25 → 0.33.0
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 +17 -0
- package/dist/Element/ElementContext.d.ts +7 -0
- package/dist/Element/helpers/isVisible.d.ts +1 -0
- package/dist/Element/helpers/isVisible.mjs +4 -0
- package/dist/Element/hocs/withElement.mjs +86 -78
- package/dist/Element/hooks/useInternalClassName.mjs +21 -20
- package/dist/Element/hooks/useInternalItems.mjs +1 -1
- package/dist/Element/hooks/useRscData.d.ts +4 -3
- package/dist/Element/hooks/useRscData.mjs +15 -10
- package/dist/dataSource/GlobalSources.d.ts +1 -2
- package/dist/dataSource/GlobalSources.mjs +46 -62
- package/dist/elements/advanced/BlockJsx/BlockJsx.mjs +1 -1
- package/dist/elements/basic/Link/Link.mjs +47 -41
- package/dist/elements/basic/RichText/RichText.d.ts +20 -0
- package/dist/elements/basic/RichText/RichText.mjs +30 -0
- package/dist/elements/basic/RichText/Settings.d.ts +7 -0
- package/dist/elements/basic/RichText/Settings.mjs +51 -0
- package/dist/elements/{provider/CollectionContainer → basic/RichText}/index.d.ts +6 -7
- package/dist/elements/{provider/CollectionContainer → basic/RichText}/index.mjs +12 -13
- package/dist/elements/basic/RichText/sanitizeHtml.d.ts +21 -0
- package/dist/elements/basic/RichText/sanitizeHtml.mjs +8 -0
- package/dist/elements/form/FormControl/index.mjs +1 -1
- package/dist/elements/index.d.ts +5 -3
- package/dist/elements/index.mjs +30 -28
- package/dist/elements/internal/Page/Page.mjs +28 -26
- package/dist/elements/provider/ApiContainer/ApiContainer.d.ts +28 -1
- package/dist/elements/provider/ApiContainer/ApiContainer.mjs +201 -86
- package/dist/elements/provider/ApiContainer/Settings.d.ts +15 -3
- package/dist/elements/provider/ApiContainer/Settings.mjs +209 -92
- package/dist/elements/provider/ApiContainer/components/FiltersInput/FiltersInput.d.ts +22 -0
- package/dist/elements/provider/ApiContainer/components/FiltersInput/FiltersInput.mjs +75 -0
- package/dist/elements/provider/ApiContainer/components/FiltersInput/index.d.ts +3 -0
- package/dist/elements/provider/ApiContainer/components/FiltersInput/index.mjs +5 -0
- package/dist/elements/provider/ApiContainer/hooks/useProviderPagination.d.ts +31 -0
- package/dist/elements/provider/ApiContainer/hooks/useProviderPagination.mjs +51 -0
- package/dist/elements/provider/ApiContainer/hooks/useProviderWrite.d.ts +26 -0
- package/dist/elements/provider/ApiContainer/hooks/useProviderWrite.mjs +27 -0
- package/dist/elements/provider/ApiContainer/index.d.ts +8 -0
- package/dist/elements/provider/ApiContainer/index.mjs +9 -1
- package/dist/elements/settings.mjs +32 -30
- package/dist/elements/structure/Pagination/Pagination.d.ts +41 -0
- package/dist/elements/structure/Pagination/Pagination.mjs +83 -0
- package/dist/elements/structure/Pagination/Settings.d.ts +12 -0
- package/dist/elements/structure/Pagination/Settings.mjs +85 -0
- package/dist/elements/structure/Pagination/buildPageWindow.d.ts +9 -0
- package/dist/elements/structure/Pagination/buildPageWindow.mjs +8 -0
- package/dist/elements/structure/Pagination/index.d.ts +67 -0
- package/dist/elements/structure/Pagination/index.mjs +59 -0
- package/dist/index.d.ts +130 -57
- package/dist/index.mjs +32 -30
- package/package.json +76 -32
- package/dist/elements/internal/Page/helpers/UserHelper.d.ts +0 -4
- package/dist/elements/provider/CollectionContainer/CollectionContainer.d.ts +0 -18
- package/dist/elements/provider/CollectionContainer/CollectionContainer.mjs +0 -69
- package/dist/elements/provider/CollectionContainer/CollectionContainer.stories-pending.d.ts +0 -1
- package/dist/elements/provider/CollectionContainer/Settings.d.ts +0 -10
- package/dist/elements/provider/CollectionContainer/Settings.mjs +0 -74
- package/dist/elements/provider/CollectionContainer/hooks/useCollectionContext.d.ts +0 -19
- package/dist/elements/provider/CollectionContainer/hooks/useCollectionContext.mjs +0 -71
|
@@ -1,166 +1,283 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import u from "
|
|
7
|
-
import d from "@plitzi/plitzi-ui/
|
|
8
|
-
import
|
|
1
|
+
import e from "./components/FiltersInput/index.mjs";
|
|
2
|
+
import { use as t, useCallback as n, useMemo as r, useState as i } from "react";
|
|
3
|
+
import { useBuilderStore as a, useSdkStore as o } from "@plitzi/sdk-shared/store";
|
|
4
|
+
import { get as s } from "@plitzi/plitzi-ui/helpers";
|
|
5
|
+
import { emptyObject as ee } from "@plitzi/sdk-shared/helpers/utils";
|
|
6
|
+
import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
7
|
+
import d from "@plitzi/plitzi-ui/QueryBuilder";
|
|
8
|
+
import f from "@plitzi/plitzi-ui/CodeMirror";
|
|
9
|
+
import { ThemeContext as te } from "@plitzi/sdk-shared/theme/ThemeProvider";
|
|
9
10
|
import p from "@plitzi/plitzi-ui/Input";
|
|
10
11
|
import m from "@plitzi/plitzi-ui/Select";
|
|
11
12
|
import h from "@plitzi/plitzi-ui/KVInput";
|
|
12
13
|
import g from "@plitzi/plitzi-ui/Switch";
|
|
13
|
-
import _ from "@plitzi/sdk-navigation/NavigationContext";
|
|
14
14
|
//#region src/elements/provider/ApiContainer/Settings.tsx
|
|
15
|
-
var v = ({ query: v = "", method: y = "get", accessToken: b = "",
|
|
16
|
-
let { theme:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
var _ = [], v = ({ query: v = "", method: y = "get", accessToken: b = "", headers: x = ee, when: S, subType: C = "div", mockData: ne = "{}", credentials: w = "same-origin", runtime: T = "client", connector: E = "", endpoint: re = "", resource: ie = "", limit: D = "10", singleRecord: O = !1, filters: k = _, pagination: A = "none", pageParam: j = "page", renderWhileLoading: M = !1, onUpdate: N }) => {
|
|
16
|
+
let { theme: P } = t(te), [F] = a("pageDefinitions"), [I] = a("connectors"), [L] = a("hasServerRendering"), [R, z] = i(!1), B = T === "server", [[V, H, U]] = o([
|
|
17
|
+
"navigation.routeParams",
|
|
18
|
+
"navigation.queryParams",
|
|
19
|
+
"navigation.currentPageId"
|
|
20
|
+
]), W = n((e) => (t) => N?.(e, t), [N]), G = n((e) => N?.("query", e), [N]), K = n((e) => N?.("when", e), [N]), q = n((e) => N?.("mockData", e), [N]), J = n((e) => z(e.target.checked), []), Y = n((e, t) => N?.("headers", t), [N]), ae = n((e) => N?.("runtime", e, !0), [N]), oe = n((e) => N?.("singleRecord", e.target.checked), [N]), se = n((e) => N?.("renderWhileLoading", e.target.checked), [N]), ce = n((e) => N?.("filters", e), [N]), X = r(() => Object.values(I), [I]), Z = r(() => X.find((e) => e.identifier === E)?.manifest, [X, E]), le = r(() => Object.keys(Z?.operators ?? {}), [Z]), Q = r(() => Object.keys(Z?.endpoints.read ?? {}), [Z]), $ = r(() => [...s(F, `${U}.attributes.slug`, "").matchAll(/:[a-z0-9_-]+/gim)].map((e) => e[0].slice(1)), [F, U]), ue = r(() => [
|
|
21
|
+
...Object.keys(V),
|
|
22
|
+
...Object.keys(H),
|
|
23
|
+
...$
|
|
20
24
|
].map((e) => ({
|
|
21
25
|
type: "token",
|
|
22
26
|
value: e
|
|
23
27
|
})), [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
V,
|
|
29
|
+
H,
|
|
30
|
+
$
|
|
27
31
|
]);
|
|
28
|
-
return /* @__PURE__ */
|
|
32
|
+
return /* @__PURE__ */ u("div", {
|
|
29
33
|
className: "flex grow flex-col gap-4 py-2",
|
|
30
34
|
children: [
|
|
31
|
-
/* @__PURE__ */
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
value: v,
|
|
36
|
-
theme: D === "dark" ? "dark" : "light",
|
|
37
|
-
mode: "text",
|
|
38
|
-
autoComplete: V,
|
|
39
|
-
lineWrapping: !0,
|
|
40
|
-
multiline: !1,
|
|
41
|
-
onChange: F
|
|
42
|
-
})]
|
|
43
|
-
}),
|
|
44
|
-
/* @__PURE__ */ l(m, {
|
|
45
|
-
value: y,
|
|
46
|
-
label: "Method",
|
|
47
|
-
onChange: P("method"),
|
|
35
|
+
/* @__PURE__ */ u(m, {
|
|
36
|
+
value: T,
|
|
37
|
+
label: "Data Source",
|
|
38
|
+
onChange: ae,
|
|
48
39
|
size: "xs",
|
|
49
|
-
children: [/* @__PURE__ */
|
|
50
|
-
value: "
|
|
51
|
-
children: "
|
|
52
|
-
}), /* @__PURE__ */
|
|
53
|
-
value: "
|
|
54
|
-
children: "
|
|
40
|
+
children: [/* @__PURE__ */ l("option", {
|
|
41
|
+
value: "client",
|
|
42
|
+
children: "Browser request"
|
|
43
|
+
}), /* @__PURE__ */ l("option", {
|
|
44
|
+
value: "server",
|
|
45
|
+
children: "Connector (server-side)"
|
|
55
46
|
})]
|
|
56
47
|
}),
|
|
57
|
-
/* @__PURE__ */
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
onChange: P("accessToken"),
|
|
61
|
-
size: "xs"
|
|
48
|
+
/* @__PURE__ */ l("span", {
|
|
49
|
+
className: "text-xs text-gray-500 dark:text-zinc-400",
|
|
50
|
+
children: B ? "The server calls the API and hands the page its records. The endpoint and the credential never reach the browser, and the content is in the HTML search engines see." : "The browser calls the URL directly. Anything it needs to authenticate with is visible to the visitor, and the content is not in the initial HTML."
|
|
62
51
|
}),
|
|
63
|
-
/* @__PURE__ */
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
52
|
+
B && /* @__PURE__ */ u(c, { children: [
|
|
53
|
+
!L && /* @__PURE__ */ l("div", {
|
|
54
|
+
className: "rounded-sm border border-yellow-300 bg-yellow-50 p-2 text-xs text-yellow-800 dark:border-yellow-700 dark:bg-yellow-950 dark:text-yellow-200",
|
|
55
|
+
children: "This space has no server-rendered deployment. Connectors resolve here in the builder, but a published page would have no server to resolve them — publish with a Plitzi SSR credential, or read the API from the browser instead."
|
|
56
|
+
}),
|
|
57
|
+
X.length === 0 && /* @__PURE__ */ l("div", {
|
|
58
|
+
className: "rounded-sm border border-gray-300 p-2 text-xs text-gray-500 dark:border-zinc-600 dark:text-zinc-400",
|
|
59
|
+
children: "No connectors yet. Add one in the Connectors panel — it holds the API endpoints, and the credential stays on the server."
|
|
60
|
+
}),
|
|
61
|
+
/* @__PURE__ */ u(m, {
|
|
62
|
+
value: E,
|
|
63
|
+
label: "Connector",
|
|
64
|
+
onChange: W("connector"),
|
|
65
|
+
size: "xs",
|
|
66
|
+
children: [/* @__PURE__ */ l("option", {
|
|
67
|
+
value: "",
|
|
68
|
+
children: "Select a connector…"
|
|
69
|
+
}), X.map((e) => /* @__PURE__ */ l("option", {
|
|
70
|
+
value: e.identifier,
|
|
71
|
+
children: e.name
|
|
72
|
+
}, e.identifier))]
|
|
73
|
+
}),
|
|
74
|
+
Q.length > 1 && /* @__PURE__ */ l(m, {
|
|
75
|
+
value: re,
|
|
76
|
+
label: "Endpoint",
|
|
77
|
+
onChange: W("endpoint"),
|
|
78
|
+
size: "xs",
|
|
79
|
+
children: Q.map((e) => /* @__PURE__ */ l("option", {
|
|
80
|
+
value: e,
|
|
81
|
+
children: e
|
|
82
|
+
}, e))
|
|
83
|
+
}),
|
|
84
|
+
/* @__PURE__ */ l(p, {
|
|
85
|
+
value: ie,
|
|
86
|
+
label: "Resource",
|
|
87
|
+
placeholder: "posts",
|
|
88
|
+
title: "The collection read through the connector — what {{resource}} becomes in the endpoint path.",
|
|
89
|
+
onChange: W("resource"),
|
|
90
|
+
size: "xs"
|
|
91
|
+
}),
|
|
92
|
+
/* @__PURE__ */ l(e, {
|
|
93
|
+
value: k,
|
|
94
|
+
operators: le,
|
|
95
|
+
onChange: ce
|
|
96
|
+
}),
|
|
97
|
+
/* @__PURE__ */ l(g, {
|
|
98
|
+
checked: O,
|
|
99
|
+
size: "sm",
|
|
100
|
+
label: "Single record (detail page)",
|
|
101
|
+
onChange: oe
|
|
102
|
+
}),
|
|
103
|
+
!O && /* @__PURE__ */ u(c, { children: [
|
|
104
|
+
/* @__PURE__ */ l(p, {
|
|
105
|
+
value: D,
|
|
106
|
+
label: "Records per page",
|
|
107
|
+
onChange: W("limit"),
|
|
108
|
+
size: "xs"
|
|
72
109
|
}),
|
|
73
|
-
/* @__PURE__ */
|
|
74
|
-
value:
|
|
75
|
-
|
|
110
|
+
/* @__PURE__ */ u(m, {
|
|
111
|
+
value: A,
|
|
112
|
+
label: "Pagination",
|
|
113
|
+
onChange: W("pagination"),
|
|
114
|
+
size: "xs",
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ l("option", {
|
|
117
|
+
value: "none",
|
|
118
|
+
children: "None"
|
|
119
|
+
}),
|
|
120
|
+
/* @__PURE__ */ l("option", {
|
|
121
|
+
value: "url",
|
|
122
|
+
children: "URL (indexable)"
|
|
123
|
+
}),
|
|
124
|
+
/* @__PURE__ */ l("option", {
|
|
125
|
+
value: "append",
|
|
126
|
+
children: "Load more"
|
|
127
|
+
})
|
|
128
|
+
]
|
|
76
129
|
}),
|
|
77
|
-
/* @__PURE__ */
|
|
78
|
-
value:
|
|
79
|
-
|
|
130
|
+
A !== "none" && /* @__PURE__ */ l(p, {
|
|
131
|
+
value: j,
|
|
132
|
+
label: "Page parameter",
|
|
133
|
+
title: "Query-string key this list pages on. Give each list its own so they page independently.",
|
|
134
|
+
onChange: W("pageParam"),
|
|
135
|
+
size: "xs"
|
|
80
136
|
})
|
|
81
|
-
]
|
|
82
|
-
}),
|
|
83
|
-
/* @__PURE__ */ c
|
|
84
|
-
|
|
137
|
+
] })
|
|
138
|
+
] }),
|
|
139
|
+
!B && /* @__PURE__ */ u(c, { children: [
|
|
140
|
+
/* @__PURE__ */ u("div", {
|
|
141
|
+
className: "flex flex-col",
|
|
142
|
+
children: [/* @__PURE__ */ l("label", { children: "Query" }), /* @__PURE__ */ l(f, {
|
|
143
|
+
className: "font-rubik min-h-6.5 basis-auto rounded-sm border border-gray-300 px-1 text-xs",
|
|
144
|
+
value: v,
|
|
145
|
+
theme: P === "dark" ? "dark" : "light",
|
|
146
|
+
mode: "text",
|
|
147
|
+
autoComplete: ue,
|
|
148
|
+
lineWrapping: !0,
|
|
149
|
+
multiline: !1,
|
|
150
|
+
onChange: G
|
|
151
|
+
})]
|
|
152
|
+
}),
|
|
153
|
+
/* @__PURE__ */ u(m, {
|
|
154
|
+
value: y,
|
|
155
|
+
label: "Method",
|
|
156
|
+
onChange: W("method"),
|
|
157
|
+
size: "xs",
|
|
158
|
+
children: [/* @__PURE__ */ l("option", {
|
|
159
|
+
value: "get",
|
|
160
|
+
children: "Get"
|
|
161
|
+
}), /* @__PURE__ */ l("option", {
|
|
162
|
+
value: "post",
|
|
163
|
+
children: "Post"
|
|
164
|
+
})]
|
|
165
|
+
}),
|
|
166
|
+
/* @__PURE__ */ l(p, {
|
|
167
|
+
value: b,
|
|
168
|
+
label: "Access Token",
|
|
169
|
+
title: "Bind this to the signed-in visitor's token. A value typed here is saved in the page and served to\n every visitor — put anything secret behind a connector instead.",
|
|
170
|
+
onChange: W("accessToken"),
|
|
171
|
+
size: "xs"
|
|
172
|
+
}),
|
|
173
|
+
/* @__PURE__ */ u(m, {
|
|
174
|
+
value: w,
|
|
175
|
+
label: "Include Credentials",
|
|
176
|
+
onChange: W("credentials"),
|
|
177
|
+
size: "xs",
|
|
178
|
+
children: [
|
|
179
|
+
/* @__PURE__ */ l("option", {
|
|
180
|
+
value: "include",
|
|
181
|
+
children: "Include"
|
|
182
|
+
}),
|
|
183
|
+
/* @__PURE__ */ l("option", {
|
|
184
|
+
value: "omit",
|
|
185
|
+
children: "Omit"
|
|
186
|
+
}),
|
|
187
|
+
/* @__PURE__ */ l("option", {
|
|
188
|
+
value: "same-origin",
|
|
189
|
+
children: "Same Origin"
|
|
190
|
+
})
|
|
191
|
+
]
|
|
192
|
+
}),
|
|
193
|
+
/* @__PURE__ */ l(g, {
|
|
194
|
+
checked: M,
|
|
195
|
+
size: "sm",
|
|
196
|
+
label: "Render children while loading",
|
|
197
|
+
onChange: se
|
|
198
|
+
})
|
|
199
|
+
] }),
|
|
200
|
+
/* @__PURE__ */ l(g, {
|
|
201
|
+
checked: R,
|
|
85
202
|
size: "sm",
|
|
86
203
|
label: "Advanced Settings",
|
|
87
|
-
onChange:
|
|
204
|
+
onChange: J
|
|
88
205
|
}),
|
|
89
|
-
|
|
90
|
-
/* @__PURE__ */
|
|
91
|
-
value: Object.entries(
|
|
206
|
+
R && /* @__PURE__ */ u(c, { children: [
|
|
207
|
+
/* @__PURE__ */ l(h, {
|
|
208
|
+
value: Object.entries(x),
|
|
92
209
|
label: "Headers",
|
|
93
|
-
onChange:
|
|
210
|
+
onChange: Y,
|
|
94
211
|
size: "xs"
|
|
95
212
|
}),
|
|
96
|
-
/* @__PURE__ */
|
|
213
|
+
/* @__PURE__ */ u("div", {
|
|
97
214
|
className: "flex flex-col",
|
|
98
|
-
children: [/* @__PURE__ */
|
|
215
|
+
children: [/* @__PURE__ */ l("label", { children: "When to perform query request" }), /* @__PURE__ */ l(d, {
|
|
99
216
|
direction: "vertical",
|
|
100
217
|
className: "w-full",
|
|
101
218
|
size: "xs",
|
|
102
|
-
query:
|
|
103
|
-
onChange:
|
|
219
|
+
query: S,
|
|
220
|
+
onChange: K,
|
|
104
221
|
showBranches: !0
|
|
105
222
|
})]
|
|
106
223
|
}),
|
|
107
|
-
/* @__PURE__ */
|
|
224
|
+
/* @__PURE__ */ u(m, {
|
|
108
225
|
value: C,
|
|
109
226
|
label: "Container Tag",
|
|
110
|
-
onChange:
|
|
227
|
+
onChange: W("subType"),
|
|
111
228
|
size: "xs",
|
|
112
229
|
children: [
|
|
113
|
-
/* @__PURE__ */
|
|
230
|
+
/* @__PURE__ */ l("option", {
|
|
114
231
|
value: "div",
|
|
115
232
|
children: "Div"
|
|
116
233
|
}),
|
|
117
|
-
/* @__PURE__ */
|
|
234
|
+
/* @__PURE__ */ l("option", {
|
|
118
235
|
value: "header",
|
|
119
236
|
children: "Header"
|
|
120
237
|
}),
|
|
121
|
-
/* @__PURE__ */
|
|
238
|
+
/* @__PURE__ */ l("option", {
|
|
122
239
|
value: "footer",
|
|
123
240
|
children: "Footer"
|
|
124
241
|
}),
|
|
125
|
-
/* @__PURE__ */
|
|
242
|
+
/* @__PURE__ */ l("option", {
|
|
126
243
|
value: "nav",
|
|
127
244
|
children: "Nav"
|
|
128
245
|
}),
|
|
129
|
-
/* @__PURE__ */
|
|
246
|
+
/* @__PURE__ */ l("option", {
|
|
130
247
|
value: "main",
|
|
131
248
|
children: "Main"
|
|
132
249
|
}),
|
|
133
|
-
/* @__PURE__ */
|
|
250
|
+
/* @__PURE__ */ l("option", {
|
|
134
251
|
value: "section",
|
|
135
252
|
children: "Section"
|
|
136
253
|
}),
|
|
137
|
-
/* @__PURE__ */
|
|
254
|
+
/* @__PURE__ */ l("option", {
|
|
138
255
|
value: "article",
|
|
139
256
|
children: "Article"
|
|
140
257
|
}),
|
|
141
|
-
/* @__PURE__ */
|
|
258
|
+
/* @__PURE__ */ l("option", {
|
|
142
259
|
value: "aside",
|
|
143
260
|
children: "Aside"
|
|
144
261
|
}),
|
|
145
|
-
/* @__PURE__ */
|
|
262
|
+
/* @__PURE__ */ l("option", {
|
|
146
263
|
value: "address",
|
|
147
264
|
children: "Address"
|
|
148
265
|
}),
|
|
149
|
-
/* @__PURE__ */
|
|
266
|
+
/* @__PURE__ */ l("option", {
|
|
150
267
|
value: "figure",
|
|
151
268
|
children: "Figure"
|
|
152
269
|
})
|
|
153
270
|
]
|
|
154
271
|
}),
|
|
155
|
-
/* @__PURE__ */
|
|
156
|
-
/* @__PURE__ */
|
|
272
|
+
/* @__PURE__ */ l("div", { className: "my-2 h-px w-full border border-gray-300 bg-gray-300" }),
|
|
273
|
+
/* @__PURE__ */ u("div", {
|
|
157
274
|
className: "flex min-h-50 grow flex-col",
|
|
158
|
-
children: [/* @__PURE__ */
|
|
159
|
-
value:
|
|
160
|
-
theme:
|
|
275
|
+
children: [/* @__PURE__ */ l("label", { children: "Mock Data (Build Mode)" }), /* @__PURE__ */ l(f, {
|
|
276
|
+
value: ne,
|
|
277
|
+
theme: P === "dark" ? "dark" : "light",
|
|
161
278
|
mode: "json",
|
|
162
279
|
lineWrapping: !0,
|
|
163
|
-
onChange:
|
|
280
|
+
onChange: q
|
|
164
281
|
})]
|
|
165
282
|
})
|
|
166
283
|
] })
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type ConnectorFilterValue = {
|
|
2
|
+
field: string;
|
|
3
|
+
operator: string;
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
6
|
+
export type FiltersInputProps = {
|
|
7
|
+
value: ConnectorFilterValue[];
|
|
8
|
+
/** Operator names the selected connector declares. An empty list means no connector is selected yet. */
|
|
9
|
+
operators: string[];
|
|
10
|
+
onChange: (filters: ConnectorFilterValue[]) => void;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Field / operator / value rows applied to the connector query.
|
|
14
|
+
*
|
|
15
|
+
* Deliberately not the `QueryBuilder` used for `when`: that produces nested groups and OR, and a connector manifest
|
|
16
|
+
* executes a flat AND list of query parameters. Offering the richer editor would let an author build a query the
|
|
17
|
+
* provider silently cannot run. These rows express exactly what the manifest can express.
|
|
18
|
+
*
|
|
19
|
+
* Values are templates resolved on the server, so `{{routeParams.slug}}` is what makes a page a detail page.
|
|
20
|
+
*/
|
|
21
|
+
declare const FiltersInput: ({ value, operators, onChange }: FiltersInputProps) => import("react").JSX.Element;
|
|
22
|
+
export default FiltersInput;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useCallback as e } from "react";
|
|
2
|
+
import { jsx as t, jsxs as n } from "react/jsx-runtime";
|
|
3
|
+
import r from "@plitzi/plitzi-ui/Button";
|
|
4
|
+
import i from "@plitzi/plitzi-ui/Input";
|
|
5
|
+
import a from "@plitzi/plitzi-ui/Select";
|
|
6
|
+
//#region src/elements/provider/ApiContainer/components/FiltersInput/FiltersInput.tsx
|
|
7
|
+
var o = {
|
|
8
|
+
field: "",
|
|
9
|
+
operator: "",
|
|
10
|
+
value: ""
|
|
11
|
+
}, s = ({ value: s, operators: c, onChange: l }) => {
|
|
12
|
+
let u = e((e, t) => (n) => l(s.map((r, i) => i === e ? {
|
|
13
|
+
...r,
|
|
14
|
+
[t]: n
|
|
15
|
+
} : r)), [s, l]), d = e((e) => () => l(s.filter((t, n) => n !== e)), [s, l]), f = e(() => l([...s, {
|
|
16
|
+
...o,
|
|
17
|
+
operator: c[0] ?? ""
|
|
18
|
+
}]), [
|
|
19
|
+
s,
|
|
20
|
+
c,
|
|
21
|
+
l
|
|
22
|
+
]);
|
|
23
|
+
return /* @__PURE__ */ n("div", {
|
|
24
|
+
className: "flex flex-col gap-2",
|
|
25
|
+
children: [
|
|
26
|
+
/* @__PURE__ */ t("label", { children: "Filters" }),
|
|
27
|
+
s.map((e, o) => /* @__PURE__ */ n("div", {
|
|
28
|
+
className: "flex items-end gap-1",
|
|
29
|
+
children: [
|
|
30
|
+
/* @__PURE__ */ t(i, {
|
|
31
|
+
className: "grow",
|
|
32
|
+
value: e.field,
|
|
33
|
+
placeholder: "field",
|
|
34
|
+
onChange: u(o, "field"),
|
|
35
|
+
size: "xs"
|
|
36
|
+
}),
|
|
37
|
+
/* @__PURE__ */ t(a, {
|
|
38
|
+
value: e.operator,
|
|
39
|
+
onChange: u(o, "operator"),
|
|
40
|
+
size: "xs",
|
|
41
|
+
children: c.map((e) => /* @__PURE__ */ t("option", {
|
|
42
|
+
value: e,
|
|
43
|
+
children: e
|
|
44
|
+
}, e))
|
|
45
|
+
}),
|
|
46
|
+
/* @__PURE__ */ t(i, {
|
|
47
|
+
className: "grow",
|
|
48
|
+
value: e.value,
|
|
49
|
+
placeholder: "{{routeParams.slug}}",
|
|
50
|
+
onChange: u(o, "value"),
|
|
51
|
+
size: "xs"
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ t(r, {
|
|
54
|
+
size: "xs",
|
|
55
|
+
onClick: d(o),
|
|
56
|
+
title: "Remove filter",
|
|
57
|
+
children: /* @__PURE__ */ t(r.Icon, { icon: "fa-solid fa-trash" })
|
|
58
|
+
})
|
|
59
|
+
]
|
|
60
|
+
}, o)),
|
|
61
|
+
/* @__PURE__ */ t(r, {
|
|
62
|
+
size: "xs",
|
|
63
|
+
onClick: f,
|
|
64
|
+
disabled: c.length === 0,
|
|
65
|
+
children: "Add Filter"
|
|
66
|
+
}),
|
|
67
|
+
c.length === 0 && /* @__PURE__ */ t("span", {
|
|
68
|
+
className: "text-xs text-gray-500",
|
|
69
|
+
children: "Select a connector to see the operators it supports."
|
|
70
|
+
})
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
export { s as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type ProviderPagination = 'none' | 'url' | 'append';
|
|
2
|
+
export type UseProviderPaginationProps = {
|
|
3
|
+
elementId: string;
|
|
4
|
+
mode: ProviderPagination;
|
|
5
|
+
/** Query-string key this provider pages on. Distinct per element so two lists on one page move independently. */
|
|
6
|
+
pageParam: string;
|
|
7
|
+
/** Records in the currently resolved window. */
|
|
8
|
+
records: unknown[];
|
|
9
|
+
/** Page the resolved window belongs to, as reported by the server. */
|
|
10
|
+
page: number;
|
|
11
|
+
refresh?: (ids?: string[], params?: Record<string, string>) => Promise<void>;
|
|
12
|
+
navigate?: (url: string, isExternal?: boolean) => void;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Drives a provider's window, in the two shapes a content site needs.
|
|
16
|
+
*
|
|
17
|
+
* **URL** paging writes the page into the address bar and lets the server resolve it, so the window is indexable,
|
|
18
|
+
* shareable and survives the back button. **Append** keeps the accumulated records in the browser and asks the
|
|
19
|
+
* server only for the next slice — the "load more" shape, which is deliberately not the default because it is
|
|
20
|
+
* none of those things.
|
|
21
|
+
*
|
|
22
|
+
* Accumulation is keyed on the page the *server* reports, not on a local counter: a full refresh returns page one
|
|
23
|
+
* and resets the list, which is what makes navigating away and back behave.
|
|
24
|
+
*/
|
|
25
|
+
declare const useProviderPagination: ({ elementId, mode, pageParam, records, page, refresh, navigate }: UseProviderPaginationProps) => {
|
|
26
|
+
records: unknown[];
|
|
27
|
+
isLoadingMore: boolean;
|
|
28
|
+
goToPage: (target: number) => Promise<void>;
|
|
29
|
+
loadMore: () => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
export default useProviderPagination;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useCallback as e, useEffect as t, useRef as n, useState as r } from "react";
|
|
2
|
+
//#region src/elements/provider/ApiContainer/hooks/useProviderPagination.ts
|
|
3
|
+
var i = (e, t) => {
|
|
4
|
+
if (typeof window > "u") return "";
|
|
5
|
+
let n = new URL(window.location.href);
|
|
6
|
+
return t <= 1 ? n.searchParams.delete(e) : n.searchParams.set(e, String(t)), `${n.pathname}${n.search}`;
|
|
7
|
+
}, a = ({ elementId: a, mode: o, pageParam: s, records: c, page: l, refresh: u, navigate: d }) => {
|
|
8
|
+
let [f, p] = r(c), [m, h] = r(!1), g = n(0);
|
|
9
|
+
t(() => {
|
|
10
|
+
if (o === "append") {
|
|
11
|
+
if (l <= 1) {
|
|
12
|
+
g.current = 1, p(c);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
g.current !== l && (g.current = l, p((e) => [...e, ...c]));
|
|
16
|
+
}
|
|
17
|
+
}, [
|
|
18
|
+
o,
|
|
19
|
+
l,
|
|
20
|
+
c
|
|
21
|
+
]);
|
|
22
|
+
let _ = e(async (e) => {
|
|
23
|
+
let t = Math.max(e, 1);
|
|
24
|
+
if (o === "url") {
|
|
25
|
+
d?.(i(s, t));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (u) {
|
|
29
|
+
h(!0);
|
|
30
|
+
try {
|
|
31
|
+
await u([a], { [s]: String(t) });
|
|
32
|
+
} finally {
|
|
33
|
+
h(!1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, [
|
|
37
|
+
o,
|
|
38
|
+
d,
|
|
39
|
+
s,
|
|
40
|
+
u,
|
|
41
|
+
a
|
|
42
|
+
]), v = e(() => _(l + 1), [_, l]);
|
|
43
|
+
return {
|
|
44
|
+
records: o === "append" ? f : c,
|
|
45
|
+
isLoadingMore: m,
|
|
46
|
+
goToPage: _,
|
|
47
|
+
loadMore: v
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { a as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Values a write callback receives from the interaction step, minus the keys the endpoint reads itself. */
|
|
2
|
+
type WriteParams = Record<string, unknown> & {
|
|
3
|
+
action?: unknown;
|
|
4
|
+
recordId?: string;
|
|
5
|
+
};
|
|
6
|
+
export type UseProviderWriteProps = {
|
|
7
|
+
elementId: string;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
actionPath?: string;
|
|
10
|
+
onDone?: () => Promise<void> | void;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Write callbacks for a server-driven provider.
|
|
14
|
+
*
|
|
15
|
+
* The browser posts an **element id and an action name** — never a URL, a connector or a credential. The server
|
|
16
|
+
* resolves the target from the published schema and refuses anything the connector has not declared, so a form can
|
|
17
|
+
* only ever reach the backend its own page is already wired to.
|
|
18
|
+
*
|
|
19
|
+
* There is one callback rather than one per CRUD verb because a connector's write endpoints are named by whoever
|
|
20
|
+
* wrote the manifest: `escalate` and `sendInvoice` are as legitimate as `create`, and three fixed verbs would only
|
|
21
|
+
* be able to reach a connector that happened to use them.
|
|
22
|
+
*/
|
|
23
|
+
declare const useProviderWrite: ({ elementId, enabled, actionPath, onDone }: UseProviderWriteProps) => {
|
|
24
|
+
writeRecord: (params?: WriteParams) => Promise<unknown>;
|
|
25
|
+
};
|
|
26
|
+
export default useProviderWrite;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCallback as e } from "react";
|
|
2
|
+
//#region src/elements/provider/ApiContainer/hooks/useProviderWrite.ts
|
|
3
|
+
var t = ({ elementId: t, enabled: n, actionPath: r = "/_action", onDone: i }) => ({ writeRecord: e(async (e = {}) => {
|
|
4
|
+
let { action: a, recordId: o, ...s } = e;
|
|
5
|
+
if (!n || typeof a != "string" || !a) return;
|
|
6
|
+
let c = await fetch(r, {
|
|
7
|
+
method: "POST",
|
|
8
|
+
headers: { "Content-Type": "application/json" },
|
|
9
|
+
credentials: "same-origin",
|
|
10
|
+
body: JSON.stringify({
|
|
11
|
+
elementId: t,
|
|
12
|
+
action: a,
|
|
13
|
+
recordId: o,
|
|
14
|
+
values: s
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
if (!c.ok) throw Error(`Write failed with status ${c.status}`);
|
|
18
|
+
let l = await c.json();
|
|
19
|
+
return await i?.(), l.record;
|
|
20
|
+
}, [
|
|
21
|
+
r,
|
|
22
|
+
t,
|
|
23
|
+
n,
|
|
24
|
+
i
|
|
25
|
+
]) });
|
|
26
|
+
//#endregion
|
|
27
|
+
export { t as default };
|
|
@@ -11,6 +11,14 @@ declare const ApiContainer: {
|
|
|
11
11
|
mockData: string;
|
|
12
12
|
subType: string;
|
|
13
13
|
credentials: string;
|
|
14
|
+
connector: string;
|
|
15
|
+
resource: string;
|
|
16
|
+
limit: string;
|
|
17
|
+
singleRecord: boolean;
|
|
18
|
+
filters: never[];
|
|
19
|
+
pagination: string;
|
|
20
|
+
pageParam: string;
|
|
21
|
+
renderWhileLoading: boolean;
|
|
14
22
|
};
|
|
15
23
|
definition: {
|
|
16
24
|
label: string;
|
|
@@ -9,7 +9,15 @@ var t = Object.assign(e, {
|
|
|
9
9
|
accessToken: "",
|
|
10
10
|
mockData: "{}",
|
|
11
11
|
subType: "div",
|
|
12
|
-
credentials: "same-origin"
|
|
12
|
+
credentials: "same-origin",
|
|
13
|
+
connector: "",
|
|
14
|
+
resource: "",
|
|
15
|
+
limit: "10",
|
|
16
|
+
singleRecord: !1,
|
|
17
|
+
filters: [],
|
|
18
|
+
pagination: "none",
|
|
19
|
+
pageParam: "page",
|
|
20
|
+
renderWhileLoading: !1
|
|
13
21
|
},
|
|
14
22
|
definition: {
|
|
15
23
|
label: "Api Container",
|