@byscott-io/pagelet 0.2.0 → 0.2.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.
- package/CHANGELOG.md +24 -0
- package/README.md +1 -1
- package/dist/editor.cjs +17 -4
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.js +18 -5
- package/dist/editor.js.map +1 -1
- package/dist/index.cjs +56 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { jsx,
|
|
2
|
-
import {
|
|
3
|
-
import { useState } from 'react';
|
|
1
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { Fragment as Fragment$1, useState } from 'react';
|
|
4
3
|
|
|
5
4
|
const DOCUMENT_VERSION = 1;
|
|
6
5
|
function emptyData() {
|
|
@@ -9,7 +8,7 @@ function emptyData() {
|
|
|
9
8
|
function createDocument(data = emptyData()) {
|
|
10
9
|
return { pagelet: DOCUMENT_VERSION, data };
|
|
11
10
|
}
|
|
12
|
-
function upgradeDocument(document
|
|
11
|
+
function upgradeDocument(document) {
|
|
13
12
|
if (document == null) return createDocument();
|
|
14
13
|
if (typeof document !== "object") {
|
|
15
14
|
throw new TypeError("pagelet: a page document must be an object");
|
|
@@ -27,23 +26,64 @@ function upgradeDocument(document, palette) {
|
|
|
27
26
|
);
|
|
28
27
|
}
|
|
29
28
|
const data = { ...emptyData(), ...doc.data };
|
|
30
|
-
return createDocument(
|
|
29
|
+
return createDocument({ ...data, root: upgradeRoot(data.root) });
|
|
31
30
|
}
|
|
32
|
-
function
|
|
33
|
-
const
|
|
34
|
-
if (Object.
|
|
35
|
-
|
|
36
|
-
return Object.keys(root).some((key) => key !== "props" && key !== "readOnly");
|
|
31
|
+
function upgradeRoot(root = {}) {
|
|
32
|
+
const { props = {}, readOnly, ...legacy } = root;
|
|
33
|
+
if (Object.keys(legacy).length === 0) return root;
|
|
34
|
+
return { ...readOnly ? { readOnly } : {}, props: { ...legacy, ...props } };
|
|
37
35
|
}
|
|
38
36
|
function pageSettings(document) {
|
|
39
37
|
const props = upgradeDocument(document)?.data?.root?.props ?? {};
|
|
40
38
|
return { title: props.title || "", background: props.background ?? "site" };
|
|
41
39
|
}
|
|
42
40
|
|
|
41
|
+
const ROOT_ZONE = "root:default-zone";
|
|
42
|
+
function slotNames(component) {
|
|
43
|
+
return Object.entries(component.fields ?? {}).filter(([, field]) => field?.type === "slot").map(([name]) => name);
|
|
44
|
+
}
|
|
45
|
+
function renderItems(items, context) {
|
|
46
|
+
return (Array.isArray(items) ? items : []).map((item, index) => /* @__PURE__ */ jsx(Fragment$1, { children: renderItem(item, context) }, item?.props?.id ?? index));
|
|
47
|
+
}
|
|
48
|
+
function puckFor(areaId, context) {
|
|
49
|
+
return {
|
|
50
|
+
isEditing: false,
|
|
51
|
+
metadata: context.metadata,
|
|
52
|
+
dragRef: null,
|
|
53
|
+
renderDropZone: ({ zone }) => {
|
|
54
|
+
const compound = `${areaId}:${zone}`;
|
|
55
|
+
const items = compound === ROOT_ZONE ? context.data.content : context.data.zones?.[compound];
|
|
56
|
+
return /* @__PURE__ */ jsx(Fragment, { children: renderItems(items, context) });
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function renderItem(item, context) {
|
|
61
|
+
const component = item && context.config.components[item.type];
|
|
62
|
+
if (!component) return null;
|
|
63
|
+
const props = { ...item.props, puck: puckFor(item.props?.id, context) };
|
|
64
|
+
for (const name of slotNames(component)) {
|
|
65
|
+
const children = item.props?.[name];
|
|
66
|
+
props[name] = function Slot({ className, style }) {
|
|
67
|
+
return /* @__PURE__ */ jsx("div", { className, style, children: renderItems(children, context) });
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const Render = component.render;
|
|
71
|
+
return /* @__PURE__ */ jsx(Render, { ...props });
|
|
72
|
+
}
|
|
73
|
+
function renderPage({ config, data, metadata = {} }) {
|
|
74
|
+
const context = { config, data: data ?? {}, metadata };
|
|
75
|
+
const puck = puckFor("root", context);
|
|
76
|
+
const rootProps = data?.root?.props ?? {};
|
|
77
|
+
const content = renderItems(data?.content, context);
|
|
78
|
+
const RootRender = config.root?.render;
|
|
79
|
+
if (!RootRender) return /* @__PURE__ */ jsx(Fragment, { children: content });
|
|
80
|
+
return /* @__PURE__ */ jsx(RootRender, { ...rootProps, title: rootProps.title || "", editMode: false, id: "puck-root", puck, children: content });
|
|
81
|
+
}
|
|
82
|
+
|
|
43
83
|
function PageletPage({ document, palette, theme }) {
|
|
44
84
|
if (!palette) throw new Error("pagelet: <PageletPage> needs a palette (see createPalette)");
|
|
45
|
-
const { data } = upgradeDocument(document
|
|
46
|
-
return
|
|
85
|
+
const { data } = upgradeDocument(document);
|
|
86
|
+
return renderPage({ config: palette.config, data, metadata: { pageletTheme: theme } });
|
|
47
87
|
}
|
|
48
88
|
|
|
49
89
|
const outline = { fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" };
|
|
@@ -129,6 +169,9 @@ const defaultTheme = {
|
|
|
129
169
|
colorAccentText: "#ffffff",
|
|
130
170
|
fontBody: 'system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',
|
|
131
171
|
fontHeading: "inherit",
|
|
172
|
+
// The page's base text size. Block text is sized in em from it, so text,
|
|
173
|
+
// lists, schedules and quotes all scale together; the menu keeps its own.
|
|
174
|
+
fontSize: "1rem",
|
|
132
175
|
radius: "8px",
|
|
133
176
|
maxWidth: "1100px",
|
|
134
177
|
space: "24px"
|
|
@@ -262,7 +305,7 @@ const Hero = {
|
|
|
262
305
|
},
|
|
263
306
|
children: /* @__PURE__ */ jsxs("div", { style: { maxWidth: "760px", margin: "0 auto" }, children: [
|
|
264
307
|
/* @__PURE__ */ jsx("h1", { style: { fontFamily: tokenVar("fontHeading"), fontSize: "clamp(2rem, 5vw, 3.25rem)", margin: "0 0 0.4em", textWrap: "balance" }, children: heading }),
|
|
265
|
-
/* @__PURE__ */ jsx(Paragraphs, { text: subheading, style: { fontSize: "1.
|
|
308
|
+
/* @__PURE__ */ jsx(Paragraphs, { text: subheading, style: { fontSize: "1.15em" } }),
|
|
266
309
|
/* @__PURE__ */ jsx(ButtonLink, { label: buttonLabel, href: buttonHref, variant: "outline" })
|
|
267
310
|
] })
|
|
268
311
|
}
|
|
@@ -691,7 +734,7 @@ function resolveBackground(theme = {}, page = {}) {
|
|
|
691
734
|
function ThemeRoot({ theme, page, children }) {
|
|
692
735
|
const background = resolveBackground(theme ?? {}, page ?? {});
|
|
693
736
|
if (!background) {
|
|
694
|
-
return /* @__PURE__ */ jsx("div", { className: "pagelet", style: themeToStyle(theme), children });
|
|
737
|
+
return /* @__PURE__ */ jsx("div", { className: "pagelet", style: { ...themeToStyle(theme), fontSize: tokenVar("fontSize") }, children });
|
|
695
738
|
}
|
|
696
739
|
const radius = background.rounded ? "var(--pagelet-radius)" : 0;
|
|
697
740
|
const panel = { background: overlayColor(background.overlayColor, background.overlayOpacity), padding: "calc(var(--pagelet-space) * 2)" };
|
|
@@ -699,7 +742,7 @@ function ThemeRoot({ theme, page, children }) {
|
|
|
699
742
|
/* @__PURE__ */ jsx("img", { src: background.imageUrl, alt: "", "aria-hidden": "true", style: { gridArea: "1 / 1", width: "100%", height: "100%", objectFit: "cover", display: "block" } }),
|
|
700
743
|
/* @__PURE__ */ jsx("div", { className: "pagelet-panel", style: { gridArea: "1 / 1", ...panel }, children })
|
|
701
744
|
] }) : /* @__PURE__ */ jsx("div", { className: "pagelet-background", style: { background: `${background.image} center / cover`, borderRadius: radius, overflow: "hidden" }, children: /* @__PURE__ */ jsx("div", { className: "pagelet-panel", style: { ...panel, minHeight: "60vh" }, children }) });
|
|
702
|
-
return /* @__PURE__ */ jsx("div", { className: "pagelet", style: themeToStyle(theme), children: background.frame === "card" ? /* @__PURE__ */ jsx("div", { className: "pagelet-frame", style: { border: "1px solid rgba(0, 0, 0, 0.15)", borderRadius: radius, padding: "var(--pagelet-space)", background: "var(--pagelet-color-background)" }, children: area }) : area });
|
|
745
|
+
return /* @__PURE__ */ jsx("div", { className: "pagelet", style: { ...themeToStyle(theme), fontSize: tokenVar("fontSize") }, children: background.frame === "card" ? /* @__PURE__ */ jsx("div", { className: "pagelet-frame", style: { border: "1px solid rgba(0, 0, 0, 0.15)", borderRadius: radius, padding: "var(--pagelet-space)", background: "var(--pagelet-color-background)" }, children: area }) : area });
|
|
703
746
|
}
|
|
704
747
|
|
|
705
748
|
const pageFields = {
|