@plitzi/sdk-elements 0.39.3 → 0.39.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 (58) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/Element/PluginRemote.mjs +7 -3
  3. package/dist/Element/hooks/useElementState.d.ts +1 -1
  4. package/dist/Element/hooks/useRootElementInteractions.mjs +21 -18
  5. package/dist/components/ElementAdvancedEditor.mjs +4 -4
  6. package/dist/components/MarkdownDocument/MarkdownDocument.mjs +37 -36
  7. package/dist/components/MarkdownDocument/helpers/rehypeTableLabels.d.ts +7 -0
  8. package/dist/components/MarkdownDocument/helpers/rehypeTableLabels.mjs +19 -0
  9. package/dist/components/SettingsSection/SettingsSection.d.ts +19 -0
  10. package/dist/components/SettingsSection/SettingsSection.mjs +37 -0
  11. package/dist/components/SettingsSection/index.d.ts +2 -0
  12. package/dist/components/SettingsSection/index.mjs +1 -0
  13. package/dist/elements/advanced/BlockJsx/declaration.d.ts +1 -1
  14. package/dist/elements/advanced/BlockJsx/declaration.mjs +1 -1
  15. package/dist/elements/advanced/BlockJsx/index.d.ts +1 -1
  16. package/dist/elements/basic/Link/Link.mjs +68 -63
  17. package/dist/elements/basic/Link/Settings.mjs +1 -1
  18. package/dist/elements/basic/Link/usePrefetchInView.d.ts +3 -0
  19. package/dist/elements/basic/Link/usePrefetchInView.mjs +29 -0
  20. package/dist/elements/basic/RichText/Settings.mjs +1 -1
  21. package/dist/elements/declarations/index.d.ts +8 -3
  22. package/dist/elements/form/Form/Form.mjs +1 -1
  23. package/dist/elements/form/FormControl/FormControl.d.ts +7 -1
  24. package/dist/elements/form/FormControl/FormControl.mjs +78 -77
  25. package/dist/elements/form/FormControl/Settings.d.ts +2 -1
  26. package/dist/elements/form/FormControl/Settings.mjs +1 -1
  27. package/dist/elements/form/FormControl/declaration.d.ts +1 -0
  28. package/dist/elements/form/FormControl/declaration.mjs +55 -51
  29. package/dist/elements/form/FormControl/helpers/autofill.d.ts +13 -0
  30. package/dist/elements/form/FormControl/helpers/autofill.mjs +18 -0
  31. package/dist/elements/form/FormControl/index.d.ts +2 -0
  32. package/dist/elements/form/FormControl/inputs/Input.d.ts +2 -1
  33. package/dist/elements/form/FormControl/inputs/Input.mjs +2 -2
  34. package/dist/elements/internal/LayoutContainer/Settings.mjs +1 -1
  35. package/dist/elements/internal/Page/Settings.mjs +323 -285
  36. package/dist/elements/internal/Page/settingsSummary.d.ts +26 -0
  37. package/dist/elements/internal/Page/settingsSummary.mjs +22 -0
  38. package/dist/elements/media/Chart/Chart.mjs +1 -1
  39. package/dist/elements/media/Image/Settings.mjs +2 -2
  40. package/dist/elements/media/Video/Settings.mjs +2 -2
  41. package/dist/elements/provider/ApiContainer/Settings.mjs +6 -6
  42. package/dist/elements/provider/ApiContainer/components/FiltersInput/FiltersInput.mjs +1 -1
  43. package/dist/elements/provider/ApiContainer/hooks/useApi.mjs +20 -19
  44. package/dist/elements/provider/ApiContainer/hooks/useProviderWrite.mjs +20 -19
  45. package/dist/elements/structure/Pagination/Settings.mjs +1 -1
  46. package/dist/elements/structure/TabContainer/TabContainer.mjs +15 -11
  47. package/dist/elements/structure/TabContainer/TabContainerItem/Settings.d.ts +6 -1
  48. package/dist/elements/structure/TabContainer/TabContainerItem/Settings.mjs +24 -3
  49. package/dist/elements/structure/TabContainer/TabContainerItem/TabContainerItem.d.ts +7 -1
  50. package/dist/elements/structure/TabContainer/TabContainerItem/TabContainerItem.mjs +66 -38
  51. package/dist/elements/structure/TabContainer/TabContainerItem/declaration.d.ts +6 -2
  52. package/dist/elements/structure/TabContainer/TabContainerItem/declaration.mjs +1 -1
  53. package/dist/elements/structure/TabContainer/TabContainerItem/index.d.ts +6 -2
  54. package/dist/elements/structure/TabContainer/TabContainerItem/openTabFromHash.d.ts +10 -0
  55. package/dist/elements/structure/TabContainer/TabContainerItem/openTabFromHash.mjs +18 -0
  56. package/dist/elements/structure/TabContainer/index.d.ts +6 -2
  57. package/dist/index.d.ts +8 -3
  58. package/package.json +12 -12
@@ -0,0 +1,26 @@
1
+ import { DocumentScroll } from './declaration';
2
+ /**
3
+ * What each section of a page's settings says on its header, and the one line of help under its fields — of the state
4
+ * it is in, never of every state it could be in: a page's form wrote a notice under each field, and grew longer than
5
+ * the panel showed.
6
+ */
7
+ export type AccessSettings = {
8
+ accessLevel: 'public' | 'authenticated' | '';
9
+ permissions: string[];
10
+ unauthorizedBehaviour: '' | 'redirect' | 'notFound';
11
+ /** The page a refused visitor is sent to, by name, when one is chosen. */
12
+ redirectName: string;
13
+ };
14
+ /** Who a page is for, and what anybody else gets: `Signed-in visitors · 404 to others`. */
15
+ export declare const accessSummary: ({ accessLevel, permissions, unauthorizedBehaviour, redirectName }: AccessSettings) => string;
16
+ /** Whether a page is kept from anybody: what its section's header draws in the accent. */
17
+ export declare const isRestricted: ({ accessLevel, permissions }: Pick<AccessSettings, "accessLevel" | "permissions">) => boolean;
18
+ /** The one line under the access fields, of the state they are in. */
19
+ export declare const accessHelp: ({ accessLevel, permissions, unauthorizedBehaviour }: AccessSettings) => string;
20
+ /** How the page scrolls, in a word, and what that means. */
21
+ export declare const scrollOf: (documentScroll: DocumentScroll | "") => {
22
+ label: string;
23
+ help: string;
24
+ };
25
+ /** What the search and sharing section holds: off, or the title a search result shows. */
26
+ export declare const seoSummary: (seoEnabled: boolean, title: string) => string;
@@ -0,0 +1,22 @@
1
+ // src/elements/internal/Page/settingsSummary.ts
2
+ var e = ({ accessLevel: e, permissions: t, unauthorizedBehaviour: n, redirectName: r }) => {
3
+ let i = t.length > 0 ? `Needs ${t.join(", ")}` : e === "authenticated" ? "Signed-in visitors" : e === "public" ? "Signed-out visitors only" : "Anyone";
4
+ return i === "Anyone" ? i : `${i}${n === "notFound" ? " · 404 to others" : n === "redirect" ? ` · others to ${r || "a page"}` : ""}`;
5
+ }, t = ({ accessLevel: e, permissions: t }) => e !== "" || t.length > 0, n = ({ accessLevel: e, permissions: n, unauthorizedBehaviour: r }) => t({
6
+ accessLevel: e,
7
+ permissions: n
8
+ }) ? e === "public" && n.length === 0 ? "Only visitors who are not signed in can open this page." : `${n.length > 0 ? "Only signed-in visitors holding every one of these permissions see this page." : "Only signed-in visitors see this page."}${r === "notFound" ? " Anybody else gets the space’s 404, and nothing of it — not its name nor its path: for a back-office, whose refusal would tell a prober something is there." : r === "redirect" ? " Anybody else is sent to the redirect page." : " Anybody else is answered 401 or 403, and the server never sends them its content."}` : "Anyone on the internet can open this page.", r = {
9
+ "": {
10
+ label: "Scrolls",
11
+ help: "The page scrolls as any page does."
12
+ },
13
+ noBounce: {
14
+ label: "No bounce",
15
+ help: "The page scrolls, but a finger pulled past either end no longer bounces it or reloads it."
16
+ },
17
+ locked: {
18
+ label: "Locked",
19
+ help: "The page holds still: only the parts set to scroll on their own (overflow auto) move. For a screen that fills the window — a dashboard, a board."
20
+ }
21
+ }, i = (e) => r[e], a = (e, t) => e ? t || "On" : "Off";
22
+ export { n as accessHelp, e as accessSummary, t as isRestricted, i as scrollOf, a as seoSummary };
@@ -466,7 +466,7 @@ var oe = 600, se = [
466
466
  display: "inline-block",
467
467
  width: "12px",
468
468
  height: "2px",
469
- borderRadius: "1px",
469
+ borderRadius: "999px",
470
470
  flexShrink: 0
471
471
  }, ve = {
472
472
  display: "inline-block",
@@ -19,9 +19,9 @@ var l = ({ src: l = "", alt: u = "", decorative: d = !1, variables: f, fetchPrio
19
19
  onChange: b.text("src"),
20
20
  size: "xs"
21
21
  }), y && /* @__PURE__ */ a("div", {
22
- className: "relative mt-2 flex items-center justify-center rounded-sm border border-gray-300 p-2",
22
+ className: "border-ui-line-strong relative mt-2 flex items-center justify-center rounded-sm border p-2",
23
23
  children: [/* @__PURE__ */ i("div", {
24
- className: "absolute top-2 left-2 rounded-tl rounded-br border border-gray-300 bg-white p-1 text-xs",
24
+ className: "border-ui-line-strong bg-ui-panel absolute top-2 left-2 rounded-tl rounded-br border p-1 text-xs",
25
25
  children: "Preview"
26
26
  }), /* @__PURE__ */ i("img", {
27
27
  src: y,
@@ -15,9 +15,9 @@ var a = ({ src: a = "", autoPlay: o = !1, playsInline: s = !1, loop: c = !1, mut
15
15
  label: "Url",
16
16
  onChange: d.text("src")
17
17
  }), a && /* @__PURE__ */ n("div", {
18
- className: "relative mt-2 flex items-center justify-center rounded-sm border border-gray-300 p-2",
18
+ className: "border-ui-line-strong relative mt-2 flex items-center justify-center rounded-sm border p-2",
19
19
  children: [/* @__PURE__ */ t("div", {
20
- className: "absolute top-2 left-2 rounded-tl rounded-br border border-gray-300 bg-white p-1 text-xs",
20
+ className: "border-ui-line-strong bg-ui-panel absolute top-2 left-2 rounded-tl rounded-br border p-1 text-xs",
21
21
  children: "Preview"
22
22
  }), /* @__PURE__ */ t("video", {
23
23
  className: "h-full w-full rounded-sm",
@@ -56,7 +56,7 @@ var _ = [], v = ({ query: v = "", method: y = "get", accessToken: b = "", header
56
56
  ]
57
57
  }),
58
58
  /* @__PURE__ */ u("span", {
59
- className: "text-xs text-gray-500 dark:text-zinc-400",
59
+ className: "text-ui-fg-subtle text-xs",
60
60
  children: [
61
61
  G === "connector" && "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.",
62
62
  G === "action" && "A flow runs on the server and hands the page whatever its output step returns — for the read a connector cannot express: two calls joined, a computed field, a shape that depends on who is looking. It is fed this page’s route and query params.",
@@ -64,7 +64,7 @@ var _ = [], v = ({ query: v = "", method: y = "get", accessToken: b = "", header
64
64
  ]
65
65
  }),
66
66
  G === "action" && /* @__PURE__ */ u(c, { children: [B?.length === 0 && /* @__PURE__ */ l("div", {
67
- className: "rounded-sm border border-gray-300 p-2 text-xs text-gray-500 dark:border-zinc-600 dark:text-zinc-400",
67
+ className: "border-ui-line-strong text-ui-fg-subtle rounded-sm border p-2 text-xs",
68
68
  children: "No actions yet. Add one in the Actions panel and give it a “While a page renders” trigger — that is the way in this element uses."
69
69
  }), /* @__PURE__ */ u(p, {
70
70
  value: T,
@@ -85,7 +85,7 @@ var _ = [], v = ({ query: v = "", method: y = "get", accessToken: b = "", header
85
85
  }),
86
86
  G === "connector" && /* @__PURE__ */ u(c, { children: [
87
87
  X.length === 0 && /* @__PURE__ */ l("div", {
88
- className: "rounded-sm border border-gray-300 p-2 text-xs text-gray-500 dark:border-zinc-600 dark:text-zinc-400",
88
+ className: "border-ui-line-strong text-ui-fg-subtle rounded-sm border p-2 text-xs",
89
89
  children: "No connectors yet. Add one in the Connectors panel — it holds the API endpoints, and the credential stays on the server."
90
90
  }),
91
91
  /* @__PURE__ */ u(p, {
@@ -170,7 +170,7 @@ var _ = [], v = ({ query: v = "", method: y = "get", accessToken: b = "", header
170
170
  /* @__PURE__ */ u("div", {
171
171
  className: "flex flex-col",
172
172
  children: [/* @__PURE__ */ l("label", { children: "Query" }), /* @__PURE__ */ l(d, {
173
- className: "min-h-6.5 basis-auto rounded-sm border border-gray-300 px-1 text-xs",
173
+ className: "border-ui-line-strong min-h-6.5 basis-auto rounded-sm border px-1 text-xs",
174
174
  value: v,
175
175
  theme: L,
176
176
  mode: "text",
@@ -242,7 +242,7 @@ var _ = [], v = ({ query: v = "", method: y = "get", accessToken: b = "", header
242
242
  size: "xs"
243
243
  }),
244
244
  /* @__PURE__ */ l("div", {
245
- className: "rounded-sm border border-gray-300 p-2 text-xs text-gray-500 dark:border-zinc-600 dark:text-zinc-400",
245
+ className: "border-ui-line-strong text-ui-fg-subtle rounded-sm border p-2 text-xs",
246
246
  children: "A completed server action refreshes every cached request, in case it changed what they read. On its step, “Refresh cached requests” can name only the containers it affects, or none for an action that only reads. A webhook step can do the same."
247
247
  })
248
248
  ] }),
@@ -344,7 +344,7 @@ var _ = [], v = ({ query: v = "", method: y = "get", accessToken: b = "", header
344
344
  })
345
345
  ]
346
346
  }),
347
- /* @__PURE__ */ l("div", { className: "my-2 h-px w-full border border-gray-300 bg-gray-300" }),
347
+ /* @__PURE__ */ l("div", { className: "border-ui-line-strong bg-ui-line-strong my-2 h-px w-full border" }),
348
348
  /* @__PURE__ */ u("div", {
349
349
  className: "flex min-h-50 grow flex-col",
350
350
  children: [/* @__PURE__ */ l("label", { children: "Mock Data (Build Mode)" }), /* @__PURE__ */ l(d, {
@@ -65,7 +65,7 @@ var o = {
65
65
  children: "Add Filter"
66
66
  }),
67
67
  c.length === 0 && /* @__PURE__ */ t("span", {
68
- className: "text-xs text-gray-500",
68
+ className: "text-ui-fg-subtle text-xs",
69
69
  children: "Select a connector to see the operators it supports."
70
70
  })
71
71
  ]
@@ -3,8 +3,9 @@ import { emptyObject as r } from "@plitzi/sdk-shared/helpers";
3
3
  import { hasValidToken as i } from "@plitzi/sdk-shared/helpers/twigWrapper";
4
4
  import { requestKey as a, useQuery as o } from "@plitzi/sdk-shared/queries";
5
5
  import { authFailureFromResponse as s, reportAuthFailure as c } from "@plitzi/sdk-shared/auth";
6
+ import { csrfFetch as l } from "@plitzi/sdk-shared/csrf";
6
7
  // src/elements/provider/ApiContainer/hooks/useApi.ts
7
- var l = 30, u = 300, d = (e) => !!e && e !== "{}" && e !== r, f = (e) => {
8
+ var u = 30, d = 300, f = (e) => !!e && e !== "{}" && e !== r, p = (e) => {
8
9
  if (typeof e != "string") return {
9
10
  status: 200,
10
11
  data: e
@@ -20,28 +21,28 @@ var l = 30, u = 300, d = (e) => !!e && e !== "{}" && e !== r, f = (e) => {
20
21
  data: e.message
21
22
  };
22
23
  }
23
- }, p = async (e, t, n, r, i, a = !1) => {
24
+ }, m = async (e, t, n, r, i, a = !1) => {
24
25
  if (!e) return {
25
26
  status: 400,
26
27
  data: "URL is required"
27
28
  };
28
29
  let o = new Headers(r);
29
30
  o.has("Accept") || o.set("Accept", "application/json");
30
- let l = {
31
+ let u = {
31
32
  method: t,
32
33
  credentials: n,
33
34
  headers: o,
34
35
  signal: i
35
36
  };
36
- t !== "get" && (l.body = "{}", o.has("Content-Type") || o.set("Content-Type", "application/json"));
37
+ t !== "get" && (u.body = "{}", o.has("Content-Type") || o.set("Content-Type", "application/json"));
37
38
  try {
38
- let o = await fetch(e, l), u = await o.json(), d = s(o.status, u);
39
- return d && await c({
40
- reason: d,
39
+ let o = await l(e, u), d = await o.json(), f = s(o.status, d);
40
+ return f && await c({
41
+ reason: f,
41
42
  url: e
42
- }) && !a && !i.aborted ? await p(e, t, n, r, i, !0) : {
43
+ }) && !a && !i.aborted ? await m(e, t, n, r, i, !0) : {
43
44
  status: o.status,
44
- data: u
45
+ data: d
45
46
  };
46
47
  } catch (e) {
47
48
  if (i.aborted) throw e;
@@ -50,11 +51,11 @@ var l = 30, u = 300, d = (e) => !!e && e !== "{}" && e !== r, f = (e) => {
50
51
  data: e.message
51
52
  };
52
53
  }
53
- }, m = (e) => e.status < 400, h = (e, t) => {
54
+ }, h = (e) => e.status < 400, g = (e, t) => {
54
55
  let n = typeof e == "number" ? e : Number(e);
55
56
  return (Number.isFinite(n) && n >= 0 ? n : t) * 1e3;
56
- }, g = ({ url: s = "", method: c = "get", mock: l, customHeaders: u = r, enabled: g = !0, credentials: _ = "same-origin", cache: v = !1, staleTime: y = 30, gcTime: b = 300, tags: x }) => {
57
- let S = d(l), C = t(), w = !S && (!s || i(s)), T = n(() => {
57
+ }, _ = ({ url: s = "", method: c = "get", mock: l, customHeaders: u = r, enabled: d = !0, credentials: _ = "same-origin", cache: v = !1, staleTime: y = 30, gcTime: b = 300, tags: x }) => {
58
+ let S = f(l), C = t(), w = !S && (!s || i(s)), T = n(() => {
58
59
  if (S || w) return;
59
60
  let e = a({
60
61
  method: c,
@@ -72,7 +73,7 @@ var l = 30, u = 300, d = (e) => !!e && e !== "{}" && e !== r, f = (e) => {
72
73
  u,
73
74
  v,
74
75
  C
75
- ]), E = e((e) => p(s, c, _, u, e), [
76
+ ]), E = e((e) => m(s, c, _, u, e), [
76
77
  s,
77
78
  c,
78
79
  _,
@@ -84,11 +85,11 @@ var l = 30, u = 300, d = (e) => !!e && e !== "{}" && e !== r, f = (e) => {
84
85
  tags: x
85
86
  },
86
87
  fetcher: E,
87
- enabled: g,
88
- staleTime: v ? h(y, 30) : 0,
89
- gcTime: v ? h(b, 300) : 0,
90
- isCacheable: m
91
- }), O = n(() => S ? f(l) : void 0, [S, l]), k = g && O ? O : D.data, A = !O && D.isFetching;
88
+ enabled: d,
89
+ staleTime: v ? g(y, 30) : 0,
90
+ gcTime: v ? g(b, 300) : 0,
91
+ isCacheable: h
92
+ }), O = n(() => S ? p(l) : void 0, [S, l]), k = d && O ? O : D.data, A = !O && D.isFetching;
92
93
  return {
93
94
  isLoading: A && k === void 0,
94
95
  isFetching: A,
@@ -99,4 +100,4 @@ var l = 30, u = 300, d = (e) => !!e && e !== "{}" && e !== r, f = (e) => {
99
100
  isError: !w && !A && !!k && k.status >= 400
100
101
  };
101
102
  };
102
- export { u as DEFAULT_GC_TIME, l as DEFAULT_STALE_TIME, g as default };
103
+ export { d as DEFAULT_GC_TIME, u as DEFAULT_STALE_TIME, _ as default };
@@ -2,38 +2,39 @@ import { useCallback as e } from "react";
2
2
  import { useCommonStore as t } from "@plitzi/sdk-shared/store";
3
3
  import { invalidateQueries as n } from "@plitzi/sdk-shared/queries";
4
4
  import { authFailureFromResponse as r, reportAuthFailure as i } from "@plitzi/sdk-shared/auth";
5
+ import { csrfFetch as a } from "@plitzi/sdk-shared/csrf";
5
6
  // src/elements/provider/ApiContainer/hooks/useProviderWrite.ts
6
- var a = ({ elementId: a, enabled: o, onDone: s }) => {
7
- let [c] = t("actions.endpoint");
7
+ var o = ({ elementId: o, enabled: s, onDone: c }) => {
8
+ let [l] = t("actions.endpoint");
8
9
  return { writeRecord: e(async (e = {}) => {
9
- let { action: t, recordId: l, ...u } = e;
10
- if (!o || typeof t != "string" || !t) return;
11
- if (!c) throw Error(`Write "${t}" was not sent: this page is served without a server that takes its writes`);
12
- let d = await fetch(c, {
10
+ let { action: t, recordId: u, ...d } = e;
11
+ if (!s || typeof t != "string" || !t) return;
12
+ if (!l) throw Error(`Write "${t}" was not sent: this page is served without a server that takes its writes`);
13
+ let f = await a(l, {
13
14
  method: "POST",
14
15
  headers: { "Content-Type": "application/json" },
15
16
  credentials: "include",
16
17
  body: JSON.stringify({
17
- elementId: a,
18
+ elementId: o,
18
19
  action: t,
19
- recordId: l,
20
- values: u
20
+ recordId: u,
21
+ values: d
21
22
  })
22
23
  });
23
- if (!d.ok) {
24
- let e = r(d.status, await d.json().catch(() => void 0));
24
+ if (!f.ok) {
25
+ let e = r(f.status, await f.json().catch(() => void 0));
25
26
  throw e && i({
26
27
  reason: e,
27
- url: c
28
- }), Error(`Write failed with status ${d.status}`);
28
+ url: l
29
+ }), Error(`Write failed with status ${f.status}`);
29
30
  }
30
- let f = await d.json();
31
- return n(), await s?.(), f.record;
31
+ let p = await f.json();
32
+ return n(), await c?.(), p.record;
32
33
  }, [
33
- c,
34
- a,
34
+ l,
35
35
  o,
36
- s
36
+ s,
37
+ c
37
38
  ]) };
38
39
  };
39
- export { a as default };
40
+ export { o as default };
@@ -75,7 +75,7 @@ var o = ({ mode: o = "pages", target: s = "url", pageParam: c = "page", windowSi
75
75
  size: "xs"
76
76
  }),
77
77
  /* @__PURE__ */ r("span", {
78
- className: "text-xs text-gray-500",
78
+ className: "text-ui-fg-subtle text-xs",
79
79
  children: [
80
80
  "Bind ",
81
81
  /* @__PURE__ */ n("strong", { children: "pageInfo" }),
@@ -6,19 +6,23 @@ import { useMemo as i, useState as a } from "react";
6
6
  import { jsx as o } from "react/jsx-runtime";
7
7
  import s from "clsx";
8
8
  // src/elements/structure/TabContainer/TabContainer.tsx
9
- var c = ({ ref: t, className: c = "", children: l }) => {
10
- let { id: u, rootId: d } = n(), [f, p] = a(0), m = `${d}_${u}`, h = i(() => ({
11
- baseId: m,
12
- tabSelected: f,
13
- onSelect: p
14
- }), [m, f]);
9
+ var c = (e) => {
10
+ if (typeof document > "u") return 0;
11
+ let t = document.querySelector(`[id^="${CSS.escape(`${e}_tab_`)}"][aria-selected="true"]`), n = t ? Number(t.id.slice(`${e}_tab_`.length)) : 0;
12
+ return Number.isInteger(n) && n >= 0 ? n : 0;
13
+ }, l = ({ ref: t, className: l = "", children: u }) => {
14
+ let { id: d, rootId: f } = n(), p = `${f}_${d}`, [m, h] = a(() => c(p)), g = i(() => ({
15
+ baseId: p,
16
+ tabSelected: m,
17
+ onSelect: h
18
+ }), [p, m]);
15
19
  return /* @__PURE__ */ o(r, {
16
20
  ref: t,
17
- className: s("plitzi-component__tab-container", c),
21
+ className: s("plitzi-component__tab-container", l),
18
22
  children: /* @__PURE__ */ o(e, {
19
- value: h,
20
- children: l
23
+ value: g,
24
+ children: u
21
25
  })
22
26
  });
23
- }, l = t(c);
24
- export { c as TabContainer, l as default };
27
+ }, u = t(l);
28
+ export { l as TabContainer, u as default };
@@ -1,2 +1,7 @@
1
- declare const Settings: () => import('react').JSX.Element;
1
+ type SettingsProps = {
2
+ hash?: string;
3
+ onUpdate?: (key: string, value: string | boolean | number) => void;
4
+ };
5
+ /** A tab's settings: the address hash that opens it (`#domains`), which choosing it writes. */
6
+ declare const Settings: ({ hash, onUpdate }: SettingsProps) => import('react').JSX.Element;
2
7
  export default Settings;
@@ -1,4 +1,25 @@
1
- import { jsx as e } from "react/jsx-runtime";
1
+ import e from "../../../useSettingsUpdate.mjs";
2
+ import { jsx as t, jsxs as n } from "react/jsx-runtime";
3
+ import r from "@plitzi/plitzi-ui/Input";
2
4
  // src/elements/structure/TabContainer/TabContainerItem/Settings.tsx
3
- var t = () => /* @__PURE__ */ e("div", { className: "flex flex-col gap-4 py-2" });
4
- export { t as default };
5
+ var i = ({ hash: i = "", onUpdate: a }) => {
6
+ let o = e(a);
7
+ return /* @__PURE__ */ n("div", {
8
+ className: "flex flex-col gap-4 py-2",
9
+ children: [/* @__PURE__ */ t(r, {
10
+ value: i,
11
+ label: "Address hash",
12
+ placeholder: "domains",
13
+ onChange: o.text("hash"),
14
+ size: "xs"
15
+ }), /* @__PURE__ */ n("span", {
16
+ className: "text-ui-fg-subtle text-xs",
17
+ children: [
18
+ "A link to the page ending in #",
19
+ i || "domains",
20
+ " opens on this tab, and choosing the tab writes it in the address. Set it on the header’s tab."
21
+ ]
22
+ })]
23
+ });
24
+ };
25
+ export { i as default };
@@ -3,6 +3,12 @@ export type TabContainerItemProps = {
3
3
  ref: RefObject<HTMLElement>;
4
4
  className: string;
5
5
  children: ReactNode;
6
+ /**
7
+ * The address's hash that opens this tab — `domains` for `#domains`: a link to the page with it opens on this tab,
8
+ * and choosing the tab writes it in the address (replacing it, so Back leaves the page rather than the tab). Only a tab
9
+ * of the header reads it.
10
+ */
11
+ hash?: string;
6
12
  baseId?: string;
7
13
  tabSelected?: number;
8
14
  /** The item's position among its siblings — not the HTML attribute, which the tabs set themselves. */
@@ -12,7 +18,7 @@ export type TabContainerItemProps = {
12
18
  isHeader?: boolean;
13
19
  onSelect?: Dispatch<SetStateAction<number>>;
14
20
  };
15
- declare const TabContainerItem: ({ className, children, ref, baseId, tabSelected, tabIndex: position, tabCount, isHeader, onSelect }: TabContainerItemProps) => import('react').JSX.Element;
21
+ declare const TabContainerItem: ({ className, children, ref, baseId, tabSelected, tabIndex: position, tabCount, isHeader, onSelect, hash }: TabContainerItemProps) => import('react').JSX.Element;
16
22
  declare const _default: import('react').FC<import('../../../..').WithElementProps<TabContainerItemProps>>;
17
23
  export default _default;
18
24
  export { TabContainerItem };
@@ -1,10 +1,12 @@
1
- import e from "../../../../Element/hocs/withElement.mjs";
2
- import { RootElement as t } from "../../../../Element/RootElement.mjs";
3
- import { useCallback as n } from "react";
4
- import { jsx as r } from "react/jsx-runtime";
5
- import i from "clsx";
1
+ import { openTabFromHash as e } from "./openTabFromHash.mjs";
2
+ import t from "../../../../Element/hocs/withElement.mjs";
3
+ import { RootElement as n } from "../../../../Element/RootElement.mjs";
4
+ import { useCallback as r, useEffect as i, useLayoutEffect as a, useRef as o } from "react";
5
+ import { usePrePaint as s } from "@plitzi/sdk-shared/hooks";
6
+ import { jsx as c } from "react/jsx-runtime";
7
+ import l from "clsx";
6
8
  // src/elements/structure/TabContainer/TabContainerItem/TabContainerItem.tsx
7
- var a = (e, t, n) => {
9
+ var u = (e, t, n) => {
8
10
  switch (e) {
9
11
  case "ArrowRight":
10
12
  case "ArrowDown": return (t + 1) % n;
@@ -14,46 +16,72 @@ var a = (e, t, n) => {
14
16
  case "End": return n - 1;
15
17
  default: return;
16
18
  }
17
- }, o = ({ className: e = "", children: o, ref: s, baseId: c = "", tabSelected: l, tabIndex: u = 0, tabCount: d = 0, isHeader: f, onSelect: p }) => {
18
- let m = l === u, h = `${c}_tab_${u}`, g = `${c}_panel_${u}`, _ = n(() => {
19
- f && !m && p?.(u);
19
+ }, d = ({ className: t = "", children: d, ref: f, baseId: p = "", tabSelected: m, tabIndex: h = 0, tabCount: g = 0, isHeader: _, onSelect: v, hash: y = "" }) => {
20
+ let b = m === h, x = y.replace(/^#/, "").trim(), S = !!(_ && x);
21
+ s("tab-hash", e, S), a(() => {
22
+ if (!S || typeof window > "u") return;
23
+ let e = () => {
24
+ decodeURIComponent(window.location.hash.slice(1)) === x && v?.(h);
25
+ };
26
+ return e(), window.addEventListener("hashchange", e), () => window.removeEventListener("hashchange", e);
20
27
  }, [
21
- f,
22
- m,
23
- u,
24
- p
25
- ]), v = n((e) => {
28
+ S,
29
+ x,
30
+ v,
31
+ h
32
+ ]);
33
+ let C = o(void 0);
34
+ i(() => {
35
+ let e = C.current;
36
+ if (C.current = b, S && b && e === !1 && typeof window < "u" && decodeURIComponent(window.location.hash.slice(1)) !== x) {
37
+ let { pathname: e, search: t } = window.location;
38
+ window.history.replaceState(window.history.state, "", `${e}${t}#${encodeURIComponent(x)}`);
39
+ }
40
+ }, [
41
+ S,
42
+ x,
43
+ b
44
+ ]);
45
+ let w = `${p}_tab_${h}`, T = `${p}_panel_${h}`, E = r(() => {
46
+ _ && !b && v?.(h);
47
+ }, [
48
+ _,
49
+ b,
50
+ h,
51
+ v
52
+ ]), D = r((e) => {
26
53
  if (e.key === "Enter" || e.key === " ") {
27
- e.preventDefault(), p?.(u);
54
+ e.preventDefault(), v?.(h);
28
55
  return;
29
56
  }
30
- let t = a(e.key, u, d);
31
- t !== void 0 && d !== 0 && (e.preventDefault(), p?.(t), e.currentTarget.ownerDocument.getElementById(`${c}_tab_${t}`)?.focus());
57
+ let t = u(e.key, h, g);
58
+ t !== void 0 && g !== 0 && (e.preventDefault(), v?.(t), e.currentTarget.ownerDocument.getElementById(`${p}_tab_${t}`)?.focus());
32
59
  }, [
33
- c,
34
- u,
35
- d,
36
- p
37
- ]), y = f ? {
38
- id: h,
60
+ p,
61
+ h,
62
+ g,
63
+ v
64
+ ]), O = _ ? {
65
+ id: w,
39
66
  role: "tab",
40
- "aria-selected": m,
41
- "aria-controls": g,
42
- tabIndex: m ? 0 : -1,
43
- onKeyDown: v
67
+ "aria-selected": b,
68
+ "aria-controls": T,
69
+ tabIndex: b ? 0 : -1,
70
+ onKeyDown: D,
71
+ ...S ? { "data-tab-hash": x } : {}
44
72
  } : {
45
- id: g,
73
+ id: T,
46
74
  role: "tabpanel",
47
- "aria-labelledby": h,
75
+ "aria-labelledby": w,
48
76
  tabIndex: 0,
49
- hidden: !m
77
+ hidden: !b
50
78
  };
51
- return /* @__PURE__ */ r(t, {
52
- ref: s,
53
- onClick: _,
54
- className: i("plitzi-component__tab-container-item", e, { active: m }),
55
- ...c ? y : {},
56
- children: o
79
+ return /* @__PURE__ */ c(n, {
80
+ ref: f,
81
+ onClick: E,
82
+ className: l("plitzi-component__tab-container-item", t, { active: b }),
83
+ ...p ? O : {},
84
+ children: d
57
85
  });
58
- }, s = e(o);
59
- export { o as TabContainerItem, s as default };
86
+ }, f = t(d);
87
+ export { d as TabContainerItem, f as default };
@@ -11,7 +11,9 @@ declare const declaration: import('@plitzi/sdk-shared/authoring').DeclaredElemen
11
11
  readonly tabindex: "roving: 0 on the open tab, -1 on the rest — the arrow keys move between them";
12
12
  };
13
13
  readonly content: {
14
- readonly attributes: {};
14
+ readonly attributes: {
15
+ readonly hash: "";
16
+ };
15
17
  readonly definition: {
16
18
  readonly label: "Tab Container Item";
17
19
  readonly description: "One selectable tab (trigger + panel) inside a tabContainer.";
@@ -33,5 +35,7 @@ declare const declaration: import('@plitzi/sdk-shared/authoring').DeclaredElemen
33
35
  readonly subTypes: {};
34
36
  };
35
37
  };
36
- }, unknown>;
38
+ }, Partial<{
39
+ hash?: string | undefined;
40
+ }>>;
37
41
  export default declaration;
@@ -9,7 +9,7 @@ var t = e()({
9
9
  tabindex: "roving: 0 on the open tab, -1 on the rest — the arrow keys move between them"
10
10
  },
11
11
  content: {
12
- attributes: {},
12
+ attributes: { hash: "" },
13
13
  definition: {
14
14
  label: "Tab Container Item",
15
15
  description: "One selectable tab (trigger + panel) inside a tabContainer.",
@@ -7,7 +7,9 @@ declare const TabContainerItem: import('react').FC<import('../../../..').WithEle
7
7
  readonly tabindex: "roving: 0 on the open tab, -1 on the rest — the arrow keys move between them";
8
8
  };
9
9
  readonly content: {
10
- readonly attributes: {};
10
+ readonly attributes: {
11
+ readonly hash: "";
12
+ };
11
13
  readonly definition: {
12
14
  readonly label: "Tab Container Item";
13
15
  readonly description: "One selectable tab (trigger + panel) inside a tabContainer.";
@@ -31,5 +33,7 @@ declare const TabContainerItem: import('react').FC<import('../../../..').WithEle
31
33
  };
32
34
  } & {
33
35
  content: import('@plitzi/sdk-shared/authoring').ElementContentDefaults;
34
- } & import('@plitzi/sdk-shared/authoring').ElementAttributesBrand<unknown>;
36
+ } & import('@plitzi/sdk-shared/authoring').ElementAttributesBrand<Partial<{
37
+ hash?: string | undefined;
38
+ }>>;
35
39
  export default TabContainerItem;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The tab the address names (`#domains`, a tab's `hash`), opened as the page is parsed — run by the page before it
3
+ * paints (`usePrePaint`), because the server never sees the hash and draws a page's tabs on their first. It sets the
4
+ * tabs' attributes and their panels' as the tabs would draw them, and the container hydrates on the tab the document
5
+ * shows (`TabContainer`'s first state), so React finds what it would have drawn.
6
+ *
7
+ * Its source is what the page runs: it reads the document and the window alone, closes over nothing and declares no
8
+ * function inside it.
9
+ */
10
+ export declare const openTabFromHash: () => void;
@@ -0,0 +1,18 @@
1
+ // src/elements/structure/TabContainer/TabContainerItem/openTabFromHash.ts
2
+ var e = () => {
3
+ let e = "";
4
+ try {
5
+ e = decodeURIComponent(window.location.hash.slice(1));
6
+ } catch {
7
+ return;
8
+ }
9
+ if (e) {
10
+ for (let t of document.querySelectorAll("[role=\"tab\"][data-tab-hash]")) if (t.getAttribute("data-tab-hash") === e && t.getAttribute("aria-selected") !== "true" && t.parentElement) for (let e of t.parentElement.querySelectorAll(":scope > [role=\"tab\"]")) {
11
+ let n = e === t;
12
+ e.setAttribute("aria-selected", String(n)), e.setAttribute("tabindex", n ? "0" : "-1"), e.classList.toggle("active", n);
13
+ let r = document.getElementById(e.getAttribute("aria-controls") ?? "");
14
+ r && (r.hidden = !n, r.classList.toggle("active", n));
15
+ }
16
+ }
17
+ };
18
+ export { e as openTabFromHash };