@oakjs/react-renderer 0.0.0-stage → 4.0.0-alpha.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.
Files changed (43) hide show
  1. package/README.md +137 -2
  2. package/dist/index.cjs +460 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.js +438 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/oak-renderer.css +5 -0
  7. package/dist/oak-renderer.css.map +1 -0
  8. package/dist/server.cjs +331 -0
  9. package/dist/server.cjs.map +1 -0
  10. package/dist/server.js +312 -0
  11. package/dist/server.js.map +1 -0
  12. package/dist/types/components/Button/index.d.ts +7 -0
  13. package/dist/types/components/Button/index.d.ts.map +1 -0
  14. package/dist/types/components/Clickable/index.d.ts +7 -0
  15. package/dist/types/components/Clickable/index.d.ts.map +1 -0
  16. package/dist/types/components/Col/index.d.ts +8 -0
  17. package/dist/types/components/Col/index.d.ts.map +1 -0
  18. package/dist/types/components/EmptySpace/index.d.ts +7 -0
  19. package/dist/types/components/EmptySpace/index.d.ts.map +1 -0
  20. package/dist/types/components/Foldable/index.d.ts +7 -0
  21. package/dist/types/components/Foldable/index.d.ts.map +1 -0
  22. package/dist/types/components/HTMLContent.d.ts +14 -0
  23. package/dist/types/components/HTMLContent.d.ts.map +1 -0
  24. package/dist/types/components/Image/index.d.ts +7 -0
  25. package/dist/types/components/Image/index.d.ts.map +1 -0
  26. package/dist/types/components/Row/index.d.ts +7 -0
  27. package/dist/types/components/Row/index.d.ts.map +1 -0
  28. package/dist/types/components/Text/index.d.ts +7 -0
  29. package/dist/types/components/Text/index.d.ts.map +1 -0
  30. package/dist/types/components/Title/index.d.ts +7 -0
  31. package/dist/types/components/Title/index.d.ts.map +1 -0
  32. package/dist/types/components/index.d.ts +17 -0
  33. package/dist/types/components/index.d.ts.map +1 -0
  34. package/dist/types/index.d.ts +4 -0
  35. package/dist/types/index.d.ts.map +1 -0
  36. package/dist/types/server.d.ts +30 -0
  37. package/dist/types/server.d.ts.map +1 -0
  38. package/dist/types/types.d.ts +81 -0
  39. package/dist/types/types.d.ts.map +1 -0
  40. package/dist/types/utils.d.ts +62 -0
  41. package/dist/types/utils.d.ts.map +1 -0
  42. package/lib/tailwind.css +49 -0
  43. package/package.json +65 -4
package/README.md CHANGED
@@ -1,3 +1,138 @@
1
- # Temporary Holding Version
1
+ # @oakjs/react-renderer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React renderers for oak's base components (row, col, title, text, image,
4
+ button, empty space, foldable, clickable).
5
+
6
+ Renderers output the final page markup: they are used by
7
+ [`@oakjs/ash`](../ash) to display content inside the builder canvas exactly
8
+ like it will be displayed on the page, and can be used to render the content
9
+ on your website.
10
+
11
+ This package only contains the component renderers (and the helpers they
12
+ rely on). Walking the content tree is up to you:
13
+
14
+ ```tsx
15
+ import {
16
+ type RendererComponentProps,
17
+ baseComponents,
18
+ getElementAttributes,
19
+ } from '@oakjs/react-renderer';
20
+ import '@oakjs/react-renderer/styles.css';
21
+
22
+ const components = baseComponents();
23
+
24
+ const Element = ({ element }) => {
25
+ const Component = components[element.type];
26
+
27
+ if (!Component) {
28
+ return null;
29
+ }
30
+
31
+ return (
32
+ <Component
33
+ element={element}
34
+ attributes={getElementAttributes(element, Component)}
35
+ renderContainer={key => (element[key] || []).map(child => (
36
+ <Element key={child.id} element={child} />
37
+ ))}
38
+ />
39
+ );
40
+ };
41
+
42
+ export const Page = ({ content }) => (
43
+ // Responsive settings use container queries
44
+ <div className="oak:@container">
45
+ { content.map(e => <Element key={e.id} element={e} />) }
46
+ </div>
47
+ );
48
+ ```
49
+
50
+ ## React Server Components
51
+
52
+ The main entrypoint (`@oakjs/react-renderer`) is marked with
53
+ `'use client'`, as some renderers are interactive (button, foldable,
54
+ clickable).
55
+
56
+ `@oakjs/react-renderer/server` exports the renderers that can be rendered on
57
+ the server (row, col, empty space, title, text, image, `HTMLContent`) and
58
+ every helper, without the `'use client'` directive:
59
+
60
+ ```tsx
61
+ // page.tsx (server component)
62
+ import {
63
+ getElementAttributes,
64
+ serverComponents,
65
+ } from '@oakjs/react-renderer/server';
66
+
67
+ const components = serverComponents();
68
+ ```
69
+
70
+ Interactive renderers have to be rendered from a client component. As
71
+ `renderContainer` is a function, it can't be passed from a server component
72
+ to a client one: render the children on the server and give them to your
73
+ client component as nodes:
74
+
75
+ ```tsx
76
+ // ClientElement.tsx
77
+ 'use client';
78
+
79
+ import { baseComponents, getElementAttributes } from '@oakjs/react-renderer';
80
+
81
+ const components = baseComponents();
82
+
83
+ export const ClientElement = ({ element, containers }) => {
84
+ const Component = components[element.type];
85
+
86
+ return (
87
+ <Component
88
+ element={element}
89
+ attributes={getElementAttributes(element, Component)}
90
+ renderContainer={key => containers[key]}
91
+ />
92
+ );
93
+ };
94
+ ```
95
+
96
+ ## Component props
97
+
98
+ | Prop | Description |
99
+ | --- | --- |
100
+ | `element` | The element to render |
101
+ | `attributes` | Attributes to spread on the root DOM node (className, style, data attributes...) |
102
+ | `renderContainer(key)` | Renders the children stored in `element[key]` |
103
+ | `editing` | `true` when rendered inside a builder |
104
+ | `dark` | `true` when the content is displayed in dark mode |
105
+ | `sanitizeHTML(html)` | Optional sanitizer for raw html content |
106
+ | `onEvent(event, element)` | Called when an element with an `event` action is clicked |
107
+
108
+ ## Hidden children
109
+
110
+ Components hiding some of their children (like the foldable, collapsed by
111
+ default) keep them in the DOM with the `hidden` attribute, and display them
112
+ when a `REVEAL_EVENT` (`oak:reveal`) DOM event bubbles from one of them.
113
+ Builders use it to show hidden elements when they're selected.
114
+
115
+ ## Dark mode
116
+
117
+ Elements can declare dark styles (`styles.dark.*`, `settings.dark.className`
118
+ and `styles.dark.hover`/`active`). Your website knows when it displays dark
119
+ mode: pass `{ dark: true }` to the helpers and the `dark` prop to the
120
+ components:
121
+
122
+ ```tsx
123
+ <Component
124
+ element={element}
125
+ attributes={getElementAttributes(element, Component, { dark })}
126
+ dark={dark}
127
+ renderContainer={...}
128
+ />
129
+ ```
130
+
131
+ `getElementStatesCSS(element, { dark })` returns the hover & active css
132
+ rules, including dark ones.
133
+
134
+ ## Styles
135
+
136
+ Renderers use tailwind classes prefixed with `oak:`. Either import the
137
+ precompiled `@oakjs/react-renderer/styles.css`, or add
138
+ `@oakjs/react-renderer/tailwind.css` to your own tailwind (v4) build.
package/dist/index.cjs ADDED
@@ -0,0 +1,460 @@
1
+ 'use client';
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ let react = require("react");
4
+ let _junipero_core = require("@junipero/core");
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+ // lib/utils.ts
7
+ const BREAKPOINTS = [
8
+ "xs",
9
+ "sm",
10
+ "md",
11
+ "lg",
12
+ "xl"
13
+ ];
14
+ /**
15
+ * Container widths (in px) at which each breakpoint starts.
16
+ * Responsive rules use container queries (not media queries) so that the
17
+ * content adapts to its container width: this allows builders to preview
18
+ * any screen size without resizing the window.
19
+ */
20
+ const BREAKPOINT_WIDTHS = {
21
+ xs: 0,
22
+ sm: 576,
23
+ md: 768,
24
+ lg: 992,
25
+ xl: 1200
26
+ };
27
+ const HIDDEN_CLASSES = {
28
+ xs: "oak:@max-[575.98px]:hidden",
29
+ sm: "oak:@min-[576px]:@max-[767.98px]:hidden",
30
+ md: "oak:@min-[768px]:@max-[991.98px]:hidden",
31
+ lg: "oak:@min-[992px]:@max-[1199.98px]:hidden",
32
+ xl: "oak:@min-[1200px]:hidden"
33
+ };
34
+ const COL_VARIANTS = {
35
+ xs: "oak:",
36
+ sm: "oak:@min-[576px]:",
37
+ md: "oak:@min-[768px]:",
38
+ lg: "oak:@min-[992px]:",
39
+ xl: "oak:@min-[1200px]:"
40
+ };
41
+ const COL_VALUES = [
42
+ "fluid",
43
+ "auto",
44
+ "hide",
45
+ ...Array.from({ length: 12 }, (_, i) => i + 1)
46
+ ];
47
+ const isNumeric = (value) => typeof value === "number" || typeof value === "string" && /^-?\d+(\.\d+)?$/.test(value.trim());
48
+ /**
49
+ * Appends `px` to unitless numeric values, and returns undefined for empty
50
+ * values so they are omitted from the style object.
51
+ */
52
+ const toCSSUnit = (value) => {
53
+ if (value === void 0 || value === null || value === "") return;
54
+ if (isNumeric(value)) return Number(value) === 0 ? "0" : `${value}px`.replace(/\s/g, "");
55
+ return String(value);
56
+ };
57
+ const SIDES = [
58
+ "Top",
59
+ "Right",
60
+ "Bottom",
61
+ "Left"
62
+ ];
63
+ const CORNERS = [
64
+ "TopLeft",
65
+ "TopRight",
66
+ "BottomRight",
67
+ "BottomLeft"
68
+ ];
69
+ const assignIfDefined = (target, key, value) => {
70
+ if (value !== void 0 && value !== null && value !== "") target[key] = value;
71
+ };
72
+ /**
73
+ * Converts oak's element styling settings (`element.styles`) into a react
74
+ * style object.
75
+ */
76
+ const getElementStyle = (styles) => {
77
+ if (!styles || typeof styles !== "object") return {};
78
+ const style = {};
79
+ SIDES.forEach((side) => {
80
+ assignIfDefined(style, `padding${side}`, toCSSUnit(styles[`padding${side}`]));
81
+ assignIfDefined(style, `margin${side}`, toCSSUnit(styles[`margin${side}`]));
82
+ const borderWidth = toCSSUnit(styles[`border${side}`]);
83
+ if (borderWidth) {
84
+ style[`border${side}Width`] = borderWidth;
85
+ style[`border${side}Style`] = styles[`border${side}Style`] || "solid";
86
+ } else assignIfDefined(style, `border${side}Style`, styles[`border${side}Style`]);
87
+ assignIfDefined(style, `border${side}Color`, styles[`border${side}Color`]);
88
+ });
89
+ CORNERS.forEach((corner) => {
90
+ assignIfDefined(style, `border${corner}Radius`, toCSSUnit(styles[`border${corner}Radius`]));
91
+ });
92
+ assignIfDefined(style, "backgroundColor", styles.backgroundColor);
93
+ const backgroundImage = typeof styles.backgroundImage === "string" ? styles.backgroundImage : styles.backgroundImage?.url;
94
+ if (backgroundImage) {
95
+ style.backgroundImage = `url("${String(backgroundImage).replace(/"/g, "\\\"")}")`;
96
+ style.backgroundSize = styles.backgroundSize && styles.backgroundSize !== "default" ? styles.backgroundSize : void 0;
97
+ assignIfDefined(style, "backgroundPosition", styles.backgroundPosition);
98
+ assignIfDefined(style, "backgroundRepeat", styles.backgroundRepeat);
99
+ }
100
+ if ([
101
+ styles.boxShadowX,
102
+ styles.boxShadowY,
103
+ styles.boxShadowBlur,
104
+ styles.boxShadowSpread
105
+ ].some((v) => v !== void 0 && v !== null && v !== "")) style.boxShadow = [
106
+ toCSSUnit(styles.boxShadowX) || "0",
107
+ toCSSUnit(styles.boxShadowY) || "0",
108
+ toCSSUnit(styles.boxShadowBlur) || "0",
109
+ toCSSUnit(styles.boxShadowSpread) || "0",
110
+ styles.boxShadowColor || "rgba(0, 0, 0, 0.25)"
111
+ ].join(" ");
112
+ Object.keys(style).forEach((k) => style[k] === void 0 && delete style[k]);
113
+ return style;
114
+ };
115
+ const toKebabCase = (str) => str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
116
+ const escapeAttribute = (value) => String(value).replace(/["\\]/g, "\\$&");
117
+ /**
118
+ * Generates the css rules for interactive states (hover, active) that cannot
119
+ * be expressed through inline styles.
120
+ */
121
+ const getElementStatesCSS = (element, { dark = false } = {}) => {
122
+ const rules = [];
123
+ ["hover", "active"].forEach((state) => {
124
+ const style = {
125
+ ...getElementStyle(element.styles?.[state]),
126
+ ...dark && getElementStyle(element.styles?.dark?.[state])
127
+ };
128
+ const declarations = Object.entries(style).map(([k, v]) => `${toKebabCase(k)}:${v} !important`).join(";");
129
+ if (declarations) rules.push(`[data-oak-id="${escapeAttribute(String(element.id))}"]:${state}{${declarations}}`);
130
+ });
131
+ return rules.join("");
132
+ };
133
+ /**
134
+ * Returns classes hiding the element on the breakpoints where it was set as
135
+ * hidden (`element.responsive[breakpoint] === 'hide'`).
136
+ */
137
+ const getVisibilityClasses = (element) => (0, _junipero_core.classNames)(BREAKPOINTS.filter((bp) => element.responsive?.[bp] === "hide").map((bp) => HIDDEN_CLASSES[bp]));
138
+ /**
139
+ * Returns the size classes of a column, for every breakpoint.
140
+ * The base size (`element.size`) is used for every breakpoint that doesn't
141
+ * declare a specific size in `element.responsive`.
142
+ */
143
+ const getColClasses = (element) => {
144
+ const base = COL_VALUES.includes(element.size) ? element.size : "fluid";
145
+ const classes = [];
146
+ let previous = null;
147
+ BREAKPOINTS.forEach((bp) => {
148
+ const value = COL_VALUES.includes(element.responsive?.[bp]) ? element.responsive[bp] : base;
149
+ if (value !== previous) {
150
+ classes.push(`${COL_VARIANTS[bp]}colsize-${value}`);
151
+ previous = value;
152
+ }
153
+ });
154
+ return (0, _junipero_core.classNames)(classes);
155
+ };
156
+ /**
157
+ * Merges additional attributes into the attributes given by the renderer,
158
+ * concatenating classNames & merging styles.
159
+ */
160
+ const mergeAttributes = (attributes, ...others) => others.reduce((res, other) => {
161
+ if (!other) return res;
162
+ return {
163
+ ...res,
164
+ ...other,
165
+ className: (0, _junipero_core.classNames)(res.className, other.className) || void 0,
166
+ style: {
167
+ ...other.style,
168
+ ...res.style
169
+ }
170
+ };
171
+ }, { ...attributes });
172
+ /**
173
+ * DOM event dispatched (bubbling) by builders on an element that is hidden
174
+ * by one of its ancestors (e.g. inside a collapsed foldable) and needs to be
175
+ * displayed. Components hiding their children should listen to it on their
176
+ * root node and display the section containing `event.target`.
177
+ */
178
+ const REVEAL_EVENT = "oak:reveal";
179
+ /**
180
+ * Attributes to put on the DOM node that directly wraps a list of child
181
+ * elements. Builders rely on them to know where elements can be dropped.
182
+ */
183
+ const containerAttributes = (key) => ({ "data-oak-container": key });
184
+ /**
185
+ * Computes the attributes every rendered element should receive (see
186
+ * `RendererComponentProps.attributes`): data attributes, className (custom
187
+ * class & responsive visibility), style (from styling settings), dir & role.
188
+ */
189
+ const getElementAttributes = (element, component, { dark = false } = {}) => {
190
+ const style = {
191
+ ...getElementStyle(element?.styles),
192
+ ...dark && getElementStyle(element?.styles?.dark)
193
+ };
194
+ return {
195
+ "data-oak-id": element?.id !== void 0 ? String(element.id) : void 0,
196
+ "data-oak-type": element?.type,
197
+ className: (0, _junipero_core.classNames)(element?.settings?.className, dark && element?.settings?.dark?.className, !component?.oakHandlesResponsive && getVisibilityClasses(element)) || void 0,
198
+ ...element?.settings?.dir && { dir: element.settings.dir },
199
+ ...element?.settings?.role && { role: element.settings.role },
200
+ ...Object.keys(style).length > 0 && { style }
201
+ };
202
+ };
203
+ // lib/components/HTMLContent.tsx
204
+ /**
205
+ * Renders a raw html string (usually coming from a rich text field), using
206
+ * the given sanitizer if any.
207
+ */
208
+ const HTMLContent = ({ tag: Tag = "div", html, sanitizeHTML, ...rest }) => {
209
+ const content = (0, react.useMemo)(() => sanitizeHTML ? sanitizeHTML(html || "") : html || "", [html, sanitizeHTML]);
210
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Tag, {
211
+ ...rest,
212
+ dangerouslySetInnerHTML: { __html: content }
213
+ });
214
+ };
215
+ HTMLContent.displayName = "HTMLContent";
216
+ // lib/components/Button/index.tsx
217
+ const Button = ({ element, attributes, sanitizeHTML, onEvent, dark }) => {
218
+ const [hovered, setHovered] = (0, react.useState)(false);
219
+ const [active, setActive] = (0, react.useState)(false);
220
+ const isLink = (element.action || "link") === "link";
221
+ const settings = dark ? {
222
+ ...element.settings,
223
+ ...element.settings?.dark
224
+ } : element.settings;
225
+ const hasStateClasses = settings?.hoverClassName || settings?.activeClassName;
226
+ const onClick = (e) => {
227
+ if (isLink) return;
228
+ e.preventDefault();
229
+ onEvent?.(element.event, element);
230
+ };
231
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HTMLContent, {
232
+ ...mergeAttributes(attributes, { className: (0, _junipero_core.classNames)("oak:inline-flex oak:items-center oak:justify-center", "oak:cursor-pointer oak:no-underline", (element.settings?.buttonType || "button") === "button" ? (0, _junipero_core.classNames)("oak:px-5 oak:py-2 oak:rounded oak:border-0", dark ? "oak:bg-white oak:text-[#1A1A1A]" : "oak:bg-[#1A1A1A] oak:text-white") : "oak:underline oak:bg-transparent oak:border-0 oak:p-0", hovered && settings?.hoverClassName, active && settings?.activeClassName) }),
233
+ tag: isLink ? "a" : "button",
234
+ ...isLink ? {
235
+ href: element.url || void 0,
236
+ target: element.target || void 0,
237
+ rel: element.target === "_blank" ? "noopener noreferrer" : void 0
238
+ } : { type: "button" },
239
+ ...hasStateClasses && {
240
+ onMouseEnter: () => setHovered(true),
241
+ onMouseLeave: () => {
242
+ setHovered(false);
243
+ setActive(false);
244
+ },
245
+ onMouseDown: () => setActive(true),
246
+ onMouseUp: () => setActive(false)
247
+ },
248
+ onClick,
249
+ html: element.content,
250
+ sanitizeHTML
251
+ });
252
+ };
253
+ Button.displayName = "ButtonRenderer";
254
+ // lib/components/Clickable/index.tsx
255
+ const Clickable = ({ element, attributes, renderContainer, onEvent }) => {
256
+ const isLink = (element.action || "link") === "link";
257
+ const children = renderContainer("content");
258
+ const attrs = {
259
+ ...mergeAttributes(attributes, {
260
+ className: "oak:block oak:cursor-pointer oak:no-underline",
261
+ style: { color: "inherit" }
262
+ }),
263
+ ...containerAttributes("content")
264
+ };
265
+ if (isLink) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
266
+ ...attrs,
267
+ href: element.url || void 0,
268
+ target: element.target || void 0,
269
+ rel: element.target === "_blank" ? "noopener noreferrer" : void 0,
270
+ children
271
+ });
272
+ const onClick = (e) => {
273
+ e.preventDefault();
274
+ onEvent?.(element.event, element);
275
+ };
276
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
277
+ role: "button",
278
+ tabIndex: 0,
279
+ ...attrs,
280
+ onClick,
281
+ children
282
+ });
283
+ };
284
+ Clickable.displayName = "ClickableRenderer";
285
+ // lib/components/Col/index.tsx
286
+ const Col = ({ element, attributes, renderContainer }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
287
+ ...mergeAttributes(attributes, { className: getColClasses(element) }),
288
+ ...containerAttributes("content"),
289
+ children: renderContainer("content")
290
+ });
291
+ Col.displayName = "ColRenderer";
292
+ Col.oakHandlesResponsive = true;
293
+ // lib/components/EmptySpace/index.tsx
294
+ const EmptySpace = ({ element, attributes }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...mergeAttributes(attributes, { style: { height: toCSSUnit(element.settings?.height) || "32px" } }) });
295
+ EmptySpace.displayName = "EmptySpaceRenderer";
296
+ // lib/components/Foldable/index.tsx
297
+ /**
298
+ * Collapsed by default: displays the "see more" label, and its content (+ the
299
+ * "see less" label) once clicked. Every section is always rendered (inactive
300
+ * ones are `hidden`), so that hidden elements can be revealed (see
301
+ * `REVEAL_EVENT`).
302
+ */
303
+ const Foldable = ({ element, attributes, renderContainer }) => {
304
+ const innerRef = (0, react.useRef)(null);
305
+ const seeMoreRef = (0, react.useRef)(null);
306
+ const [opened, setOpened] = (0, react.useState)(false);
307
+ const position = element.settings?.seeMorePosition || "after";
308
+ (0, react.useEffect)(() => {
309
+ const el = innerRef.current;
310
+ const onReveal = (e) => {
311
+ setOpened(!seeMoreRef.current?.contains(e.target));
312
+ };
313
+ el?.addEventListener(REVEAL_EVENT, onReveal);
314
+ return () => el?.removeEventListener(REVEAL_EVENT, onReveal);
315
+ }, []);
316
+ const toggle = () => setOpened((o) => !o);
317
+ const onKeyDown = (e) => {
318
+ if (e.key === "Enter" || e.key === " ") {
319
+ e.preventDefault();
320
+ toggle();
321
+ }
322
+ };
323
+ const toggles = ["seeMore", "seeLess"].map((key) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
324
+ ref: key === "seeMore" ? seeMoreRef : void 0,
325
+ role: "button",
326
+ tabIndex: 0,
327
+ "aria-expanded": opened,
328
+ hidden: key === "seeMore" ? opened : !opened,
329
+ className: "oak:cursor-pointer",
330
+ onClick: toggle,
331
+ onKeyDown,
332
+ ...containerAttributes(key),
333
+ children: renderContainer(key)
334
+ }, key));
335
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
336
+ ref: innerRef,
337
+ ...attributes,
338
+ children: [
339
+ position === "before" && toggles,
340
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
341
+ hidden: !opened,
342
+ ...containerAttributes("content"),
343
+ children: renderContainer("content")
344
+ }),
345
+ position !== "before" && toggles
346
+ ]
347
+ });
348
+ };
349
+ Foldable.displayName = "FoldableRenderer";
350
+ // lib/components/Image/index.tsx
351
+ const Image = ({ element, attributes, editing, dark }) => {
352
+ const size = element.settings?.size || "auto";
353
+ const imageStyle = size === "custom" ? {
354
+ width: toCSSUnit(element.settings?.width),
355
+ height: toCSSUnit(element.settings?.height),
356
+ maxWidth: "100%"
357
+ } : size === "full" ? { maxWidth: "none" } : {
358
+ maxWidth: "100%",
359
+ height: "auto"
360
+ };
361
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
362
+ ...mergeAttributes(attributes, { style: { textAlign: element.settings?.textAlign || "left" } }),
363
+ children: element.url ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
364
+ className: "oak:inline-block oak:align-middle",
365
+ src: element.url,
366
+ alt: element.settings?.alt || "",
367
+ title: element.settings?.description || void 0,
368
+ style: imageStyle,
369
+ draggable: editing ? false : void 0
370
+ }) : editing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
371
+ className: "oak:inline-flex oak:items-center oak:justify-center oak:w-full oak:h-32 oak:text-sm " + (dark ? "oak:bg-[#262626] oak:text-[#9097A3]" : "oak:bg-[#F3F3F3] oak:text-[#6B778C]"),
372
+ children: "No image"
373
+ }) : null
374
+ });
375
+ };
376
+ Image.displayName = "ImageRenderer";
377
+ // lib/components/Row/index.tsx
378
+ const Row = ({ element, attributes, renderContainer }) => {
379
+ const gap = toCSSUnit(element.settings?.gap);
380
+ const direction = element.settings?.flexDirection || "row";
381
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
382
+ ...mergeAttributes(attributes, {
383
+ className: "oak:flex oak:flex-wrap oak:w-full",
384
+ style: {
385
+ flexDirection: direction,
386
+ justifyContent: element.settings?.justifyContent,
387
+ alignItems: element.settings?.alignItems || (/column/.test(direction) ? "stretch" : "flex-start"),
388
+ ...gap && {
389
+ gap,
390
+ ["--oak-col-gap"]: gap
391
+ }
392
+ }
393
+ }),
394
+ ...containerAttributes("cols"),
395
+ children: renderContainer("cols")
396
+ });
397
+ };
398
+ Row.displayName = "RowRenderer";
399
+ // lib/components/Text/index.tsx
400
+ const Text = ({ element, attributes, sanitizeHTML }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HTMLContent, {
401
+ ...attributes,
402
+ html: element.content,
403
+ sanitizeHTML
404
+ });
405
+ Text.displayName = "TextRenderer";
406
+ // lib/components/Title/index.tsx
407
+ const HEADINGS = [
408
+ "h1",
409
+ "h2",
410
+ "h3",
411
+ "h4",
412
+ "h5",
413
+ "h6"
414
+ ];
415
+ const Title = ({ element, attributes, sanitizeHTML }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HTMLContent, {
416
+ ...attributes,
417
+ tag: HEADINGS.includes(element.headingLevel) ? element.headingLevel : "h1",
418
+ html: element.content,
419
+ sanitizeHTML
420
+ });
421
+ Title.displayName = "TitleRenderer";
422
+ // lib/components/index.ts
423
+ /**
424
+ * Renderers for oak's base components, keyed by component id
425
+ */
426
+ const baseComponents = () => ({
427
+ row: Row,
428
+ col: Col,
429
+ "empty-space": EmptySpace,
430
+ title: Title,
431
+ text: Text,
432
+ image: Image,
433
+ button: Button,
434
+ foldable: Foldable,
435
+ clickable: Clickable
436
+ });
437
+ exports.BREAKPOINTS = BREAKPOINTS;
438
+ exports.BREAKPOINT_WIDTHS = BREAKPOINT_WIDTHS;
439
+ exports.Button = Button;
440
+ exports.Clickable = Clickable;
441
+ exports.Col = Col;
442
+ exports.EmptySpace = EmptySpace;
443
+ exports.Foldable = Foldable;
444
+ exports.HTMLContent = HTMLContent;
445
+ exports.Image = Image;
446
+ exports.REVEAL_EVENT = REVEAL_EVENT;
447
+ exports.Row = Row;
448
+ exports.Text = Text;
449
+ exports.Title = Title;
450
+ exports.baseComponents = baseComponents;
451
+ exports.containerAttributes = containerAttributes;
452
+ exports.getColClasses = getColClasses;
453
+ exports.getElementAttributes = getElementAttributes;
454
+ exports.getElementStatesCSS = getElementStatesCSS;
455
+ exports.getElementStyle = getElementStyle;
456
+ exports.getVisibilityClasses = getVisibilityClasses;
457
+ exports.mergeAttributes = mergeAttributes;
458
+ exports.toCSSUnit = toCSSUnit;
459
+
460
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["classNames","useMemo","useState","classNames","useRef","useState"],"sources":["../lib/utils.ts","../lib/components/HTMLContent.tsx","../lib/components/Button/index.tsx","../lib/components/Clickable/index.tsx","../lib/components/Col/index.tsx","../lib/components/EmptySpace/index.tsx","../lib/components/Foldable/index.tsx","../lib/components/Image/index.tsx","../lib/components/Row/index.tsx","../lib/components/Text/index.tsx","../lib/components/Title/index.tsx","../lib/components/index.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\nimport { classNames } from '@junipero/core';\n\nimport type {\n Breakpoint,\n ElementObject,\n ElementAttributes,\n ElementRenderOptions,\n ElementStyles,\n RendererComponent,\n} from './types';\n\nexport const BREAKPOINTS: Breakpoint[] = ['xs', 'sm', 'md', 'lg', 'xl'];\n\n/**\n * Container widths (in px) at which each breakpoint starts.\n * Responsive rules use container queries (not media queries) so that the\n * content adapts to its container width: this allows builders to preview\n * any screen size without resizing the window.\n */\nexport const BREAKPOINT_WIDTHS: Record<Breakpoint, number> = {\n xs: 0,\n sm: 576,\n md: 768,\n lg: 992,\n xl: 1200,\n};\n\n// Class names must be written in full so that tailwind can find them\nconst HIDDEN_CLASSES: Record<Breakpoint, string> = {\n xs: 'oak:@max-[575.98px]:hidden',\n sm: 'oak:@min-[576px]:@max-[767.98px]:hidden',\n md: 'oak:@min-[768px]:@max-[991.98px]:hidden',\n lg: 'oak:@min-[992px]:@max-[1199.98px]:hidden',\n xl: 'oak:@min-[1200px]:hidden',\n};\n\n// Generated through @source inline() in tailwind.css\nconst COL_VARIANTS: Record<Breakpoint, string> = {\n xs: 'oak:',\n sm: 'oak:@min-[576px]:',\n md: 'oak:@min-[768px]:',\n lg: 'oak:@min-[992px]:',\n xl: 'oak:@min-[1200px]:',\n};\n\nconst COL_VALUES = [\n 'fluid', 'auto', 'hide', ...Array.from({ length: 12 }, (_, i) => i + 1),\n];\n\nconst isNumeric = (value: unknown) =>\n typeof value === 'number' ||\n (typeof value === 'string' && /^-?\\d+(\\.\\d+)?$/.test(value.trim()));\n\n/**\n * Appends `px` to unitless numeric values, and returns undefined for empty\n * values so they are omitted from the style object.\n */\nexport const toCSSUnit = (value: unknown): string | undefined => {\n if (value === undefined || value === null || value === '') {\n return undefined;\n }\n\n if (isNumeric(value)) {\n return Number(value) === 0 ? '0' : `${value}px`.replace(/\\s/g, '');\n }\n\n return String(value);\n};\n\nconst SIDES = ['Top', 'Right', 'Bottom', 'Left'] as const;\nconst CORNERS = ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft'] as const;\n\nconst assignIfDefined = (\n target: Record<string, any>,\n key: string,\n value: unknown,\n) => {\n if (value !== undefined && value !== null && value !== '') {\n target[key] = value;\n }\n};\n\n/**\n * Converts oak's element styling settings (`element.styles`) into a react\n * style object.\n */\nexport const getElementStyle = (styles?: ElementStyles): CSSProperties => {\n if (!styles || typeof styles !== 'object') {\n return {};\n }\n\n const style: Record<string, any> = {};\n\n SIDES.forEach(side => {\n assignIfDefined(style, `padding${side}`, toCSSUnit(styles[`padding${side}`]));\n assignIfDefined(style, `margin${side}`, toCSSUnit(styles[`margin${side}`]));\n\n const borderWidth = toCSSUnit(styles[`border${side}`]);\n\n if (borderWidth) {\n style[`border${side}Width`] = borderWidth;\n // A border width without style would be invisible\n style[`border${side}Style`] = styles[`border${side}Style`] || 'solid';\n } else {\n assignIfDefined(style, `border${side}Style`, styles[`border${side}Style`]);\n }\n\n assignIfDefined(style, `border${side}Color`, styles[`border${side}Color`]);\n });\n\n CORNERS.forEach(corner => {\n assignIfDefined(\n style,\n `border${corner}Radius`,\n toCSSUnit(styles[`border${corner}Radius`]),\n );\n });\n\n assignIfDefined(style, 'backgroundColor', styles.backgroundColor);\n\n const backgroundImage = typeof styles.backgroundImage === 'string'\n ? styles.backgroundImage\n : styles.backgroundImage?.url;\n\n if (backgroundImage) {\n style.backgroundImage = `url(\"${String(backgroundImage)\n .replace(/\"/g, '\\\\\"')}\")`;\n style.backgroundSize = styles.backgroundSize &&\n styles.backgroundSize !== 'default' ? styles.backgroundSize : undefined;\n assignIfDefined(style, 'backgroundPosition', styles.backgroundPosition);\n assignIfDefined(style, 'backgroundRepeat', styles.backgroundRepeat);\n }\n\n if (\n [\n styles.boxShadowX, styles.boxShadowY,\n styles.boxShadowBlur, styles.boxShadowSpread,\n ].some(v => v !== undefined && v !== null && v !== '')\n ) {\n style.boxShadow = [\n toCSSUnit(styles.boxShadowX) || '0',\n toCSSUnit(styles.boxShadowY) || '0',\n toCSSUnit(styles.boxShadowBlur) || '0',\n toCSSUnit(styles.boxShadowSpread) || '0',\n styles.boxShadowColor || 'rgba(0, 0, 0, 0.25)',\n ].join(' ');\n }\n\n Object.keys(style).forEach(k => style[k] === undefined && delete style[k]);\n\n return style;\n};\n\nconst toKebabCase = (str: string) =>\n str.replace(/[A-Z]/g, m => '-' + m.toLowerCase());\n\nconst escapeAttribute = (value: string) =>\n String(value).replace(/[\"\\\\]/g, '\\\\$&');\n\n/**\n * Generates the css rules for interactive states (hover, active) that cannot\n * be expressed through inline styles.\n */\nexport const getElementStatesCSS = (\n element: ElementObject,\n { dark = false }: ElementRenderOptions = {},\n): string => {\n const rules: string[] = [];\n\n (['hover', 'active'] as const).forEach(state => {\n const style = {\n ...getElementStyle(element.styles?.[state]),\n ...dark && getElementStyle(element.styles?.dark?.[state]),\n };\n const declarations = Object.entries(style)\n .map(([k, v]) => `${toKebabCase(k)}:${v} !important`)\n .join(';');\n\n if (declarations) {\n rules.push(\n `[data-oak-id=\"${escapeAttribute(String(element.id))}\"]:${state}` +\n `{${declarations}}`\n );\n }\n });\n\n return rules.join('');\n};\n\n/**\n * Returns classes hiding the element on the breakpoints where it was set as\n * hidden (`element.responsive[breakpoint] === 'hide'`).\n */\nexport const getVisibilityClasses = (element: ElementObject): string =>\n classNames(\n BREAKPOINTS\n .filter(bp => element.responsive?.[bp] === 'hide')\n .map(bp => HIDDEN_CLASSES[bp])\n );\n\n/**\n * Returns the size classes of a column, for every breakpoint.\n * The base size (`element.size`) is used for every breakpoint that doesn't\n * declare a specific size in `element.responsive`.\n */\nexport const getColClasses = (element: ElementObject): string => {\n const base = COL_VALUES.includes(element.size) ? element.size : 'fluid';\n const classes: string[] = [];\n let previous: string | number = null;\n\n BREAKPOINTS.forEach(bp => {\n const value = COL_VALUES.includes(element.responsive?.[bp])\n ? element.responsive[bp]\n : base;\n\n if (value !== previous) {\n classes.push(`${COL_VARIANTS[bp]}colsize-${value}`);\n previous = value;\n }\n });\n\n return classNames(classes);\n};\n\n/**\n * Merges additional attributes into the attributes given by the renderer,\n * concatenating classNames & merging styles.\n */\nexport const mergeAttributes = (\n attributes: ElementAttributes,\n ...others: (ElementAttributes | null | undefined | false)[]\n): ElementAttributes =>\n others.reduce<ElementAttributes>((res, other) => {\n if (!other) {\n return res;\n }\n\n return {\n ...res,\n ...other,\n className: classNames(res.className, other.className) || undefined,\n style: { ...other.style, ...res.style },\n };\n }, { ...attributes });\n\n/**\n * DOM event dispatched (bubbling) by builders on an element that is hidden\n * by one of its ancestors (e.g. inside a collapsed foldable) and needs to be\n * displayed. Components hiding their children should listen to it on their\n * root node and display the section containing `event.target`.\n */\nexport const REVEAL_EVENT = 'oak:reveal';\n\n/**\n * Attributes to put on the DOM node that directly wraps a list of child\n * elements. Builders rely on them to know where elements can be dropped.\n */\nexport const containerAttributes = (key: string) => ({\n 'data-oak-container': key,\n});\n\n/**\n * Computes the attributes every rendered element should receive (see\n * `RendererComponentProps.attributes`): data attributes, className (custom\n * class & responsive visibility), style (from styling settings), dir & role.\n */\nexport const getElementAttributes = (\n element: ElementObject,\n component?: RendererComponent,\n { dark = false }: ElementRenderOptions = {},\n): ElementAttributes => {\n const style = {\n ...getElementStyle(element?.styles),\n ...dark && getElementStyle(element?.styles?.dark),\n };\n\n return {\n 'data-oak-id': element?.id !== undefined ? String(element.id) : undefined,\n 'data-oak-type': element?.type,\n className: classNames(\n element?.settings?.className,\n dark && element?.settings?.dark?.className,\n !component?.oakHandlesResponsive && getVisibilityClasses(element),\n ) || undefined,\n ...element?.settings?.dir && { dir: element.settings.dir },\n ...element?.settings?.role && { role: element.settings.role },\n ...Object.keys(style).length > 0 && { style },\n };\n};\n","import { type ElementType, type HTMLAttributes, useMemo } from 'react';\n\nimport type { SanitizeHTMLCallback } from '../types';\n\nexport declare interface HTMLContentProps extends HTMLAttributes<HTMLElement> {\n tag?: ElementType;\n html: string;\n sanitizeHTML?: SanitizeHTMLCallback;\n [key: string]: any;\n}\n\n/**\n * Renders a raw html string (usually coming from a rich text field), using\n * the given sanitizer if any.\n */\nconst HTMLContent = ({\n tag: Tag = 'div',\n html,\n sanitizeHTML,\n ...rest\n}: HTMLContentProps) => {\n const content = useMemo(() => (\n sanitizeHTML ? sanitizeHTML(html || '') : html || ''\n ), [html, sanitizeHTML]);\n\n return <Tag { ...rest } dangerouslySetInnerHTML={{ __html: content }} />;\n};\n\nHTMLContent.displayName = 'HTMLContent';\n\nexport default HTMLContent;\n","import { type MouseEvent, useState } from 'react';\nimport { classNames } from '@junipero/core';\n\nimport type { RendererComponentProps } from '../../types';\nimport { mergeAttributes } from '../../utils';\nimport HTMLContent from '../HTMLContent';\n\nconst Button = ({\n element,\n attributes,\n sanitizeHTML,\n onEvent,\n dark,\n}: RendererComponentProps) => {\n const [hovered, setHovered] = useState(false);\n const [active, setActive] = useState(false);\n const isLink = (element.action || 'link') === 'link';\n const settings = dark\n ? { ...element.settings, ...element.settings?.dark }\n : element.settings;\n const hasStateClasses = settings?.hoverClassName ||\n settings?.activeClassName;\n\n const onClick = (e: MouseEvent<HTMLElement>) => {\n if (isLink) {\n return;\n }\n\n e.preventDefault();\n onEvent?.(element.event, element);\n };\n\n return (\n <HTMLContent\n { ...mergeAttributes(attributes, {\n className: classNames(\n 'oak:inline-flex oak:items-center oak:justify-center',\n 'oak:cursor-pointer oak:no-underline',\n (element.settings?.buttonType || 'button') === 'button'\n ? classNames(\n 'oak:px-5 oak:py-2 oak:rounded oak:border-0',\n dark\n ? 'oak:bg-white oak:text-[#1A1A1A]'\n : 'oak:bg-[#1A1A1A] oak:text-white',\n )\n : 'oak:underline oak:bg-transparent oak:border-0 oak:p-0',\n hovered && settings?.hoverClassName,\n active && settings?.activeClassName,\n ),\n }) }\n tag={isLink ? 'a' : 'button'}\n { ...isLink ? {\n href: element.url || undefined,\n target: element.target || undefined,\n rel: element.target === '_blank' ? 'noopener noreferrer' : undefined,\n } : { type: 'button' } }\n { ...hasStateClasses && {\n onMouseEnter: () => setHovered(true),\n onMouseLeave: () => { setHovered(false); setActive(false); },\n onMouseDown: () => setActive(true),\n onMouseUp: () => setActive(false),\n } }\n onClick={onClick}\n html={element.content as string}\n sanitizeHTML={sanitizeHTML}\n />\n );\n};\n\nButton.displayName = 'ButtonRenderer';\n\nexport default Button;\n","import type { MouseEvent } from 'react';\n\nimport type { RendererComponentProps } from '../../types';\nimport { containerAttributes, mergeAttributes } from '../../utils';\n\nconst Clickable = ({\n element,\n attributes,\n renderContainer,\n onEvent,\n}: RendererComponentProps) => {\n const isLink = (element.action || 'link') === 'link';\n const children = renderContainer('content');\n const attrs = {\n ...mergeAttributes(attributes, {\n className: 'oak:block oak:cursor-pointer oak:no-underline',\n style: { color: 'inherit' },\n }),\n ...containerAttributes('content'),\n };\n\n if (isLink) {\n return (\n <a\n { ...attrs }\n href={element.url || undefined}\n target={element.target || undefined}\n rel={element.target === '_blank' ? 'noopener noreferrer' : undefined}\n >\n { children }\n </a>\n );\n }\n\n const onClick = (e: MouseEvent<HTMLDivElement>) => {\n e.preventDefault();\n onEvent?.(element.event, element);\n };\n\n return (\n <div role=\"button\" tabIndex={0} { ...attrs } onClick={onClick}>\n { children }\n </div>\n );\n};\n\nClickable.displayName = 'ClickableRenderer';\n\nexport default Clickable;\n","import type { RendererComponentProps } from '../../types';\nimport {\n containerAttributes,\n getColClasses,\n mergeAttributes,\n} from '../../utils';\n\nconst Col = ({ element, attributes, renderContainer }: RendererComponentProps) => (\n <div\n { ...mergeAttributes(attributes, {\n className: getColClasses(element),\n }) }\n { ...containerAttributes('content') }\n >\n { renderContainer('content') }\n </div>\n);\n\nCol.displayName = 'ColRenderer';\nCol.oakHandlesResponsive = true;\n\nexport default Col;\n","import type { RendererComponentProps } from '../../types';\nimport { mergeAttributes, toCSSUnit } from '../../utils';\n\nconst EmptySpace = ({ element, attributes }: RendererComponentProps) => (\n <div\n { ...mergeAttributes(attributes, {\n style: { height: toCSSUnit(element.settings?.height) || '32px' },\n }) }\n />\n);\n\nEmptySpace.displayName = 'EmptySpaceRenderer';\n\nexport default EmptySpace;\n","import { type KeyboardEvent, useEffect, useRef, useState } from 'react';\n\nimport type { RendererComponentProps } from '../../types';\nimport { REVEAL_EVENT, containerAttributes } from '../../utils';\n\n/**\n * Collapsed by default: displays the \"see more\" label, and its content (+ the\n * \"see less\" label) once clicked. Every section is always rendered (inactive\n * ones are `hidden`), so that hidden elements can be revealed (see\n * `REVEAL_EVENT`).\n */\nconst Foldable = ({\n element,\n attributes,\n renderContainer,\n}: RendererComponentProps) => {\n const innerRef = useRef<HTMLDivElement>(null);\n const seeMoreRef = useRef<HTMLDivElement>(null);\n const [opened, setOpened] = useState(false);\n const position = element.settings?.seeMorePosition || 'after';\n\n // Open (or close) to display a hidden descendant asking to be revealed\n useEffect(() => {\n const el = innerRef.current;\n\n const onReveal = (e: Event) => {\n setOpened(!seeMoreRef.current?.contains(e.target as Node));\n };\n\n el?.addEventListener(REVEAL_EVENT, onReveal);\n\n return () => el?.removeEventListener(REVEAL_EVENT, onReveal);\n }, []);\n\n const toggle = () => setOpened(o => !o);\n\n const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n toggle();\n }\n };\n\n const toggles = (['seeMore', 'seeLess'] as const).map(key => (\n <div\n key={key}\n ref={key === 'seeMore' ? seeMoreRef : undefined}\n role=\"button\"\n tabIndex={0}\n aria-expanded={opened}\n hidden={key === 'seeMore' ? opened : !opened}\n className=\"oak:cursor-pointer\"\n onClick={toggle}\n onKeyDown={onKeyDown}\n { ...containerAttributes(key) }\n >\n { renderContainer(key) }\n </div>\n ));\n\n return (\n <div ref={innerRef} { ...attributes }>\n { position === 'before' && toggles }\n <div hidden={!opened} { ...containerAttributes('content') }>\n { renderContainer('content') }\n </div>\n { position !== 'before' && toggles }\n </div>\n );\n};\n\nFoldable.displayName = 'FoldableRenderer';\n\nexport default Foldable;\n","import type { CSSProperties } from 'react';\n\nimport type { RendererComponentProps } from '../../types';\nimport { mergeAttributes, toCSSUnit } from '../../utils';\n\nconst Image = ({\n element,\n attributes,\n editing,\n dark,\n}: RendererComponentProps) => {\n const size = element.settings?.size || 'auto';\n const imageStyle: CSSProperties = size === 'custom'\n ? {\n width: toCSSUnit(element.settings?.width),\n height: toCSSUnit(element.settings?.height),\n maxWidth: '100%',\n }\n : size === 'full'\n ? { maxWidth: 'none' }\n : { maxWidth: '100%', height: 'auto' };\n\n return (\n <div\n { ...mergeAttributes(attributes, {\n style: { textAlign: element.settings?.textAlign || 'left' },\n }) }\n >\n { element.url ? (\n <img\n className=\"oak:inline-block oak:align-middle\"\n src={element.url}\n alt={element.settings?.alt || ''}\n title={element.settings?.description || undefined}\n style={imageStyle}\n draggable={editing ? false : undefined}\n />\n ) : editing ? (\n <div\n className={\n 'oak:inline-flex oak:items-center oak:justify-center ' +\n 'oak:w-full oak:h-32 oak:text-sm ' +\n (dark\n ? 'oak:bg-[#262626] oak:text-[#9097A3]'\n : 'oak:bg-[#F3F3F3] oak:text-[#6B778C]')\n }\n >\n No image\n </div>\n ) : null }\n </div>\n );\n};\n\nImage.displayName = 'ImageRenderer';\n\nexport default Image;\n","import type { RendererComponentProps } from '../../types';\nimport { containerAttributes, mergeAttributes, toCSSUnit } from '../../utils';\n\nconst Row = ({ element, attributes, renderContainer }: RendererComponentProps) => {\n const gap = toCSSUnit(element.settings?.gap);\n const direction = element.settings?.flexDirection || 'row';\n\n return (\n <div\n { ...mergeAttributes(attributes, {\n className: 'oak:flex oak:flex-wrap oak:w-full',\n style: {\n flexDirection: direction,\n justifyContent: element.settings?.justifyContent,\n alignItems: element.settings?.alignItems ||\n (/column/.test(direction) ? 'stretch' : 'flex-start'),\n ...gap && {\n gap,\n ['--oak-col-gap' as string]: gap,\n },\n },\n }) }\n { ...containerAttributes('cols') }\n >\n { renderContainer('cols') }\n </div>\n );\n};\n\nRow.displayName = 'RowRenderer';\n\nexport default Row;\n","import type { RendererComponentProps } from '../../types';\nimport HTMLContent from '../HTMLContent';\n\nconst Text = ({ element, attributes, sanitizeHTML }: RendererComponentProps) => (\n <HTMLContent\n { ...attributes }\n html={element.content as string}\n sanitizeHTML={sanitizeHTML}\n />\n);\n\nText.displayName = 'TextRenderer';\n\nexport default Text;\n","import type { RendererComponentProps } from '../../types';\nimport HTMLContent from '../HTMLContent';\n\nconst HEADINGS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];\n\nconst Title = ({ element, attributes, sanitizeHTML }: RendererComponentProps) => (\n <HTMLContent\n { ...attributes }\n tag={HEADINGS.includes(element.headingLevel) ? element.headingLevel : 'h1'}\n html={element.content as string}\n sanitizeHTML={sanitizeHTML}\n />\n);\n\nTitle.displayName = 'TitleRenderer';\n\nexport default Title;\n","import type { RendererComponentsMap } from '../types';\nimport Button from './Button';\nimport Clickable from './Clickable';\nimport Col from './Col';\nimport EmptySpace from './EmptySpace';\nimport Foldable from './Foldable';\nimport Image from './Image';\nimport Row from './Row';\nimport Text from './Text';\nimport Title from './Title';\n\nexport {\n Button,\n Clickable,\n Col,\n EmptySpace,\n Foldable,\n Image,\n Row,\n Text,\n Title,\n};\n\nexport { default as HTMLContent, type HTMLContentProps } from './HTMLContent';\n\n/**\n * Renderers for oak's base components, keyed by component id\n */\nexport const baseComponents = (): RendererComponentsMap => ({\n row: Row,\n col: Col,\n 'empty-space': EmptySpace,\n title: Title,\n text: Text,\n image: Image,\n button: Button,\n foldable: Foldable,\n clickable: Clickable,\n});\n"],"mappings":";;;;;;AAYA,MAAa,cAA4B;CAAC;CAAM;CAAM;CAAM;CAAM;AAAI;;;;;;;AAQtE,MAAa,oBAAgD;CAC3D,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAGA,MAAM,iBAA6C;CACjD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAGA,MAAM,eAA2C;CAC/C,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,MAAM,aAAa;CACjB;CAAS;CAAQ;CAAQ,GAAG,MAAM,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,MAAM,IAAI,CAAC;AACxE;AAEA,MAAM,aAAa,UACjB,OAAO,UAAU,YAChB,OAAO,UAAU,YAAY,kBAAkB,KAAK,MAAM,KAAK,CAAC;;;;;AAMnE,MAAa,aAAa,UAAuC;CAC/D,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,IACrD;CAGF,IAAI,UAAU,KAAK,GACjB,OAAO,OAAO,KAAK,MAAM,IAAI,MAAM,GAAG,MAAM,IAAI,QAAQ,OAAO,EAAE;CAGnE,OAAO,OAAO,KAAK;AACrB;AAEA,MAAM,QAAQ;CAAC;CAAO;CAAS;CAAU;AAAM;AAC/C,MAAM,UAAU;CAAC;CAAW;CAAY;CAAe;AAAY;AAEnE,MAAM,mBACJ,QACA,KACA,UACG;CACH,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,IACrD,OAAO,OAAO;AAElB;;;;;AAMA,MAAa,mBAAmB,WAA0C;CACxE,IAAI,CAAC,U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