@plitzi/sdk-elements 0.36.0 → 0.36.2

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 (38) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/Element/ElementParentContext.d.ts +13 -0
  3. package/dist/Element/ElementParentContext.mjs +6 -0
  4. package/dist/Element/LayoutBody.d.ts +21 -0
  5. package/dist/Element/LayoutBody.mjs +24 -0
  6. package/dist/Element/hocs/withElement.mjs +104 -87
  7. package/dist/Element/hooks/useElementInternal.mjs +24 -24
  8. package/dist/Element/hooks/useInternalItems.mjs +42 -39
  9. package/dist/Element/hooks/useLayoutChain.d.ts +10 -0
  10. package/dist/Element/hooks/useLayoutChain.mjs +20 -0
  11. package/dist/Element/hooks/useRootElementInteractions.mjs +45 -44
  12. package/dist/dataSource/GlobalSources.mjs +60 -59
  13. package/dist/dataSource/pathFields.d.ts +7 -0
  14. package/dist/dataSource/pathFields.mjs +8 -0
  15. package/dist/elements/advanced/Reference/Reference.mjs +93 -89
  16. package/dist/elements/advanced/Reference/declaration.d.ts +1 -1
  17. package/dist/elements/advanced/Reference/index.d.ts +1 -1
  18. package/dist/elements/declarations/index.d.ts +3 -1
  19. package/dist/elements/internal/LayoutContainer/LayoutContainer.d.ts +6 -0
  20. package/dist/elements/internal/LayoutContainer/LayoutContainer.mjs +31 -23
  21. package/dist/elements/internal/LayoutContainer/Settings.d.ts +4 -1
  22. package/dist/elements/internal/LayoutContainer/Settings.mjs +78 -64
  23. package/dist/elements/internal/LayoutContainer/declaration.d.ts +2 -0
  24. package/dist/elements/internal/LayoutContainer/index.d.ts +2 -0
  25. package/dist/elements/internal/LayoutPicker/LayoutPicker.d.ts +10 -0
  26. package/dist/elements/internal/LayoutPicker/LayoutPicker.mjs +35 -0
  27. package/dist/elements/internal/LayoutPicker/index.d.ts +3 -0
  28. package/dist/elements/internal/LayoutPicker/index.mjs +5 -0
  29. package/dist/elements/internal/Page/Page.mjs +49 -48
  30. package/dist/elements/internal/Page/Settings.mjs +101 -119
  31. package/dist/elements/provider/ApiContainer/ApiContainer.mjs +58 -66
  32. package/dist/elements/provider/ApiContainer/declaration.mjs +1 -1
  33. package/dist/elements/provider/ApiContainer/hooks/useApi.d.ts +8 -0
  34. package/dist/elements/provider/ApiContainer/hooks/useApi.mjs +52 -48
  35. package/dist/elements/structure/DialogContainer/DialogContainer.mjs +17 -25
  36. package/dist/elements/structure/ModalContainer/ModalContainer.mjs +15 -23
  37. package/dist/index.d.ts +3 -1
  38. package/package.json +38 -10
@@ -7,41 +7,49 @@ import { throttle as o } from "@plitzi/plitzi-ui/helpers";
7
7
  import { jsx as s } from "react/jsx-runtime";
8
8
  import c from "clsx";
9
9
  //#region src/elements/internal/LayoutContainer/LayoutContainer.tsx
10
- var l = ({ ref: e, className: l = "", children: u, subType: d = "div" }) => {
11
- let { plitziElementLayout: f } = t(), { settings: { previewMode: p } } = a(), m = r((e, t) => {
12
- if (!e || !t) return;
13
- let n = t.getBoundingClientRect(), r = n.top - 0, i = n.left - 0, a = i + n.width + 0, o = r + n.height + 0, s = `
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) => {
12
+ if (!e) return;
13
+ if (!t) {
14
+ e.style.removeProperty("--child-clip");
15
+ return;
16
+ }
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 = `
14
18
  polygon(
15
19
  evenodd,
16
20
  /* outer rect */
17
21
  0 0, 100% 0, 100% 100%, 0% 100%, 0 0,
18
22
  /* inner rect */
19
- ${i}px ${r}px, ${a}px ${r}px, ${a}px ${o}px, ${i}px ${o}px, ${i}px ${r}px
23
+ ${o}px ${a}px, ${s}px ${a}px, ${s}px ${c}px, ${o}px ${c}px, ${o}px ${a}px
20
24
  )`;
21
- e.style.setProperty("--child-clip", s);
25
+ e.style.setProperty("--child-clip", l);
22
26
  }, []);
23
27
  return i(() => {
24
- if (!f || !e?.current || p) return;
25
- let t = o(() => {
26
- let t = e.current, n = t.querySelector(".plitzi-component--layout-body");
27
- m(t, n);
28
- }, 150), n = new ResizeObserver(t);
29
- n.observe(e.current);
30
- let r = e.current.querySelector(".plitzi-component--layout-body");
31
- return r && n.observe(r), () => {
32
- t.cancel(), n.disconnect();
28
+ 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, {
37
+ childList: !0,
38
+ subtree: !0
39
+ }), t.addEventListener("scroll", r, !0), r(), () => {
40
+ r.cancel(), i.disconnect(), a.disconnect(), t.removeEventListener("scroll", r, !0);
33
41
  };
34
42
  }, [
35
- f,
36
- p,
43
+ m,
44
+ h,
37
45
  e,
38
- m
46
+ g
39
47
  ]), /* @__PURE__ */ s(n, {
40
48
  ref: e,
41
- tag: d,
42
- className: c("plitzi-component__layout-container", l),
43
- children: u
49
+ tag: p,
50
+ className: c("plitzi-component__layout-container", u),
51
+ children: f
44
52
  });
45
- }, u = e(l);
53
+ }, p = e(f);
46
54
  //#endregion
47
- export { l as LayoutContainer, u as default };
55
+ export { f as LayoutContainer, p as default };
@@ -1,7 +1,10 @@
1
1
  type SettingsProps = {
2
+ id?: string;
3
+ layout?: string;
4
+ layoutContainer?: string;
2
5
  subType?: 'div' | 'header' | 'footer' | 'nav' | 'main' | 'section' | 'article' | 'aside' | 'address' | 'figure';
3
6
  folder?: string;
4
7
  onUpdate?: (key: string, value: string | boolean | number) => void;
5
8
  };
6
- declare const Settings: ({ subType, folder, onUpdate }: SettingsProps) => import("react").JSX.Element;
9
+ declare const Settings: ({ id, layout, layoutContainer, subType, folder, onUpdate }: SettingsProps) => import("react").JSX.Element;
7
10
  export default Settings;
@@ -1,73 +1,87 @@
1
- import { useCallback as e, useMemo as t } from "react";
2
- import { useCommonStore as n } from "@plitzi/sdk-shared/store";
3
- import { jsx as r, jsxs as i } from "react/jsx-runtime";
4
- import a from "@plitzi/plitzi-ui/Select";
5
- import o from "@plitzi/plitzi-ui/Select2";
1
+ import e from "../LayoutPicker/index.mjs";
2
+ import { useCallback as t, useMemo as n } from "react";
3
+ import { useCommonStore as r } from "@plitzi/sdk-shared/store";
4
+ import { jsx as i, jsxs as a } from "react/jsx-runtime";
5
+ import o from "@plitzi/plitzi-ui/Select";
6
+ import s from "@plitzi/plitzi-ui/Select2";
6
7
  //#region src/elements/internal/LayoutContainer/Settings.tsx
7
- var s = ({ subType: s = "div", folder: c = "", onUpdate: l }) => {
8
- let [u] = n("schema.pageFolders"), d = e((e) => l?.("subType", e), [l]), f = e((e) => l?.("folder", e?.value ?? ""), [l]), p = t(() => [{
8
+ var c = ({ id: c, layout: l = "", layoutContainer: u = "", subType: d = "div", folder: f = "", onUpdate: p }) => {
9
+ let [m] = r("schema.pageFolders"), h = t((e) => p?.("subType", e), [p]), g = t((e) => p?.("folder", e?.value ?? ""), [p]), _ = n(() => [{
9
10
  value: "",
10
11
  label: "None"
11
- }, ...u.map(({ id: e, name: t }) => ({
12
+ }, ...m.map(({ id: e, name: t }) => ({
12
13
  value: e,
13
14
  label: t
14
- }))], [u]);
15
- return /* @__PURE__ */ i("div", {
15
+ }))], [m]);
16
+ return /* @__PURE__ */ a("div", {
16
17
  className: "flex flex-col gap-4 py-2",
17
- children: [/* @__PURE__ */ i(a, {
18
- value: s,
19
- label: "Container Tag",
20
- onChange: d,
21
- children: [
22
- /* @__PURE__ */ r("option", {
23
- value: "div",
24
- children: "Div"
25
- }),
26
- /* @__PURE__ */ r("option", {
27
- value: "header",
28
- children: "Header"
29
- }),
30
- /* @__PURE__ */ r("option", {
31
- value: "footer",
32
- children: "Footer"
33
- }),
34
- /* @__PURE__ */ r("option", {
35
- value: "nav",
36
- children: "Nav"
37
- }),
38
- /* @__PURE__ */ r("option", {
39
- value: "main",
40
- children: "Main"
41
- }),
42
- /* @__PURE__ */ r("option", {
43
- value: "section",
44
- children: "Section"
45
- }),
46
- /* @__PURE__ */ r("option", {
47
- value: "article",
48
- children: "Article"
49
- }),
50
- /* @__PURE__ */ r("option", {
51
- value: "aside",
52
- children: "Aside"
53
- }),
54
- /* @__PURE__ */ r("option", {
55
- value: "address",
56
- children: "Address"
57
- }),
58
- /* @__PURE__ */ r("option", {
59
- value: "figure",
60
- children: "Figure"
61
- })
62
- ]
63
- }), /* @__PURE__ */ r(o, {
64
- label: "Folder",
65
- value: c,
66
- options: p,
67
- placeholder: "None",
68
- onChange: f
69
- })]
18
+ children: [
19
+ /* @__PURE__ */ a(o, {
20
+ value: d,
21
+ label: "Container Tag",
22
+ onChange: h,
23
+ children: [
24
+ /* @__PURE__ */ i("option", {
25
+ value: "div",
26
+ children: "Div"
27
+ }),
28
+ /* @__PURE__ */ i("option", {
29
+ value: "header",
30
+ children: "Header"
31
+ }),
32
+ /* @__PURE__ */ i("option", {
33
+ value: "footer",
34
+ children: "Footer"
35
+ }),
36
+ /* @__PURE__ */ i("option", {
37
+ value: "nav",
38
+ children: "Nav"
39
+ }),
40
+ /* @__PURE__ */ i("option", {
41
+ value: "main",
42
+ children: "Main"
43
+ }),
44
+ /* @__PURE__ */ i("option", {
45
+ value: "section",
46
+ children: "Section"
47
+ }),
48
+ /* @__PURE__ */ i("option", {
49
+ value: "article",
50
+ children: "Article"
51
+ }),
52
+ /* @__PURE__ */ i("option", {
53
+ value: "aside",
54
+ children: "Aside"
55
+ }),
56
+ /* @__PURE__ */ i("option", {
57
+ value: "address",
58
+ children: "Address"
59
+ }),
60
+ /* @__PURE__ */ i("option", {
61
+ value: "figure",
62
+ children: "Figure"
63
+ })
64
+ ]
65
+ }),
66
+ /* @__PURE__ */ i(s, {
67
+ label: "Folder",
68
+ value: f,
69
+ options: _,
70
+ placeholder: "None",
71
+ onChange: g
72
+ }),
73
+ /* @__PURE__ */ i(e, {
74
+ layout: l,
75
+ layoutContainer: u,
76
+ ownLayoutId: c,
77
+ onUpdate: p
78
+ }),
79
+ /* @__PURE__ */ i("span", {
80
+ className: "text-xs text-gray-500 dark:text-zinc-400",
81
+ children: "A layout can sit inside another one: pages using this layout are shown inside it, and it inside the one picked here — the outer shell stays mounted while moving between pages that share it."
82
+ })
83
+ ]
70
84
  });
71
85
  };
72
86
  //#endregion
73
- export { s as default };
87
+ export { c as default };
@@ -52,6 +52,8 @@ declare const declaration: {
52
52
  readonly settings: {};
53
53
  };
54
54
  } & import('@plitzi/sdk-shared/authoring/declare').ElementAttributesBrand<Partial<{
55
+ layout?: string | undefined;
55
56
  subType?: "div" | "header" | "footer" | "nav" | "main" | "section" | "article" | "aside" | "address" | "figure" | undefined;
57
+ layoutContainer?: string | undefined;
56
58
  }>>;
57
59
  export default declaration;
@@ -51,6 +51,8 @@ declare const LayoutContainer: {
51
51
  readonly settings: {};
52
52
  };
53
53
  } & import('@plitzi/sdk-shared/authoring/declare').ElementAttributesBrand<Partial<{
54
+ layout?: string | undefined;
54
55
  subType?: "div" | "header" | "footer" | "nav" | "main" | "section" | "article" | "aside" | "address" | "figure" | undefined;
56
+ layoutContainer?: string | undefined;
55
57
  }>>;
56
58
  export default LayoutContainer;
@@ -0,0 +1,10 @@
1
+ export type LayoutPickerProps = {
2
+ layout?: string;
3
+ layoutContainer?: string;
4
+ /** The layout being edited, when it is one: it cannot sit in itself, nor in a shell that already sits in it. */
5
+ ownLayoutId?: string;
6
+ onUpdate?: (key: string, value: string) => void;
7
+ };
8
+ /** Which shell something is rendered inside, and the container in that shell its content goes into. */
9
+ declare const LayoutPicker: ({ layout, layoutContainer, ownLayoutId, onUpdate }: LayoutPickerProps) => import("react").JSX.Element;
10
+ export default LayoutPicker;
@@ -0,0 +1,35 @@
1
+ import { useCallback as e, useMemo as t } from "react";
2
+ import { useCommonStore as n } from "@plitzi/sdk-shared/store";
3
+ import { get as r } from "@plitzi/plitzi-ui/helpers";
4
+ import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
5
+ import { resolveLayoutChain as s } from "@plitzi/sdk-shared/schema/layoutChain";
6
+ import c from "@plitzi/plitzi-ui/Select";
7
+ //#region src/elements/internal/LayoutPicker/LayoutPicker.tsx
8
+ var l = ({ layout: l = "", layoutContainer: u = "", ownLayoutId: d, onUpdate: f }) => {
9
+ let [p] = n("schema.flat"), m = t(() => Object.values(p).filter((e) => r(e, "definition.type", "") === "layoutContainer" && (!d || !s((e) => p[e], e.id, "").some((e) => e.layout === d))), [p, d]), h = t(() => l ? Object.values(p).filter((e) => r(e, "definition.type", "") === "container" && r(e, "definition.rootId", "") === l) : [], [p, l]), g = e((e) => {
10
+ f?.("layout", e), f?.("layoutContainer", "");
11
+ }, [f]), _ = e((e) => f?.("layoutContainer", e), [f]);
12
+ return /* @__PURE__ */ o(i, { children: [/* @__PURE__ */ a(c, {
13
+ value: l,
14
+ placeholder: "None",
15
+ label: "Layout",
16
+ onChange: g,
17
+ size: "xs",
18
+ children: m.map(({ id: e, definition: { label: t } }) => /* @__PURE__ */ a("option", {
19
+ value: e,
20
+ children: t
21
+ }, e))
22
+ }), l && /* @__PURE__ */ a(c, {
23
+ value: u,
24
+ placeholder: "None",
25
+ label: "Layout Container Body",
26
+ onChange: _,
27
+ size: "xs",
28
+ children: h.map(({ id: e, definition: { label: t } }) => /* @__PURE__ */ a("option", {
29
+ value: e,
30
+ children: t
31
+ }, e))
32
+ })] });
33
+ };
34
+ //#endregion
35
+ export { l as default };
@@ -0,0 +1,3 @@
1
+ import { default as LayoutPicker } from './LayoutPicker';
2
+ export * from './LayoutPicker';
3
+ export default LayoutPicker;
@@ -0,0 +1,5 @@
1
+ import e from "./LayoutPicker.mjs";
2
+ //#region src/elements/internal/LayoutPicker/index.ts
3
+ var t = e;
4
+ //#endregion
5
+ export { t as default };
@@ -1,31 +1,36 @@
1
- import e from "../../../Element/hocs/withElement.mjs";
2
- import t from "../../../Element/hooks/useElement.mjs";
3
- import { RootElement as n } from "../../../Element/RootElement.mjs";
4
- import r from "../LayoutContainer/index.mjs";
5
- import { use as i, useEffect as a, useMemo as o } from "react";
6
- import s from "@plitzi/sdk-shared/hooks/usePlitziServiceContext";
7
- import { useSdkStore as c } from "@plitzi/sdk-shared/store";
8
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
9
- import d from "clsx";
10
- import { Helmet as f } from "@dr.pogodin/react-helmet";
1
+ import e from "../../../Element/LayoutBody.mjs";
2
+ import t from "../../../Element/hocs/withElement.mjs";
3
+ import n from "../../../Element/hooks/useElement.mjs";
4
+ import { RootElement as r } from "../../../Element/RootElement.mjs";
5
+ import i from "../LayoutContainer/index.mjs";
6
+ import a from "../../../Element/hooks/useLayoutChain.mjs";
7
+ import { use as o, useEffect as s, useMemo as c } from "react";
8
+ import l from "@plitzi/sdk-shared/hooks/usePlitziServiceContext";
9
+ import { useSdkStore as u } from "@plitzi/sdk-shared/store";
10
+ import { jsx as d, jsxs as f } from "react/jsx-runtime";
11
+ import p from "clsx";
12
+ import { Helmet as m } from "@dr.pogodin/react-helmet";
11
13
  //#region src/elements/internal/Page/Page.tsx
12
- var p = ({ ref: e, seoEnabled: p = !1, seoPageTitle: m = "Title", seoPageDescription: h = "Description", className: g = "", layout: _ = "", layoutContainer: v = "", children: y }) => {
13
- let { id: b } = t(), { settings: { previewMode: x }, contexts: { InteractionsContext: S } } = s(), { interactionsManager: C } = i(S), [[w, T]] = c(["navigation.routeParams", "navigation.queryParams"]), E = o(() => ({
14
- id: _,
15
- rootId: b,
16
- plitziElementLayout: {
17
- bodyChildren: y,
18
- containerId: v || _,
19
- referenceId: b,
20
- rootId: v || _,
21
- type: "layout"
22
- }
23
- }), [
24
- v,
25
- _,
26
- b,
27
- y
28
- ]), D = o(() => ({ onPageLoad: {
14
+ var h = (e) => e.map((e) => ({
15
+ ...e,
16
+ plitziElementLayout: {
17
+ containerId: e.slot,
18
+ rootId: e.slot,
19
+ type: "layout"
20
+ }
21
+ })), g = (t, n, r) => t.reduce((t, { layout: r, slot: a, plitziElementLayout: o }) => /* @__PURE__ */ d(e, {
22
+ body: t,
23
+ children: /* @__PURE__ */ d(i, { internalProps: {
24
+ id: r,
25
+ rootId: n,
26
+ plitziElementLayout: o
27
+ } })
28
+ }, a), r), _ = ({ ref: e, seoEnabled: t = !1, seoPageTitle: i = "Title", seoPageDescription: _ = "Description", className: v = "", layout: y = "", layoutContainer: b = "", children: x }) => {
29
+ let { id: S } = n(), { settings: { previewMode: C }, contexts: { InteractionsContext: w } } = l(), { interactionsManager: T } = o(w), [[E, D]] = u(["navigation.routeParams", "navigation.queryParams"]), O = a(y, b), k = c(() => h(O), [O]), A = c(() => g(k, S, x), [
30
+ k,
31
+ S,
32
+ x
33
+ ]), j = c(() => ({ onPageLoad: {
29
34
  action: "onPageLoad",
30
35
  title: "On Page Load",
31
36
  type: "trigger",
@@ -36,35 +41,31 @@ var p = ({ ref: e, seoEnabled: p = !1, seoPageTitle: m = "Title", seoPageDescrip
36
41
  queryParams: ""
37
42
  }
38
43
  } }), []);
39
- return a(() => {
44
+ return s(() => {
40
45
  let e = !1;
41
46
  return queueMicrotask(() => {
42
- e || C.interactionTrigger(b, "onPageLoad", {
43
- pageId: b,
44
- routeParams: w,
45
- queryParams: T
47
+ e || T.interactionTrigger(S, "onPageLoad", {
48
+ pageId: S,
49
+ routeParams: E,
50
+ queryParams: D
46
51
  });
47
52
  }), () => {
48
53
  e = !0;
49
54
  };
50
55
  }, [
51
- b,
52
- C,
56
+ S,
53
57
  T,
54
- w
55
- ]), /* @__PURE__ */ u(n, {
58
+ D,
59
+ E
60
+ ]), /* @__PURE__ */ f(r, {
56
61
  ref: e,
57
- className: d("plitzi-component__page", g),
58
- interactionTriggers: D,
59
- children: [
60
- p && x && /* @__PURE__ */ u(f, { children: [!!m && /* @__PURE__ */ l("title", { children: m }), !!h && /* @__PURE__ */ l("meta", {
61
- name: "description",
62
- content: h
63
- })] }),
64
- _ && /* @__PURE__ */ l(r, { internalProps: E }, v || _),
65
- !_ && y
66
- ]
62
+ className: p("plitzi-component__page", v),
63
+ interactionTriggers: j,
64
+ children: [t && C && /* @__PURE__ */ f(m, { children: [!!i && /* @__PURE__ */ d("title", { children: i }), !!_ && /* @__PURE__ */ d("meta", {
65
+ name: "description",
66
+ content: _
67
+ })] }), A]
67
68
  });
68
- }, m = e(p);
69
+ }, v = t(_);
69
70
  //#endregion
70
- export { p as Page, m as default };
71
+ export { _ as Page, v as default };