@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
@@ -0,0 +1,81 @@
1
+ import type { ComponentType, HTMLAttributes, ReactNode } from 'react';
2
+ /**
3
+ * An element of oak's content. Structurally identical to `@oakjs/core`'s
4
+ * ElementObject, redeclared so that the renderer doesn't depend on core.
5
+ */
6
+ export declare interface ElementObject {
7
+ id?: string | number;
8
+ type?: string;
9
+ content?: string | ((content: string) => any) | ElementObject[];
10
+ [key: string]: any;
11
+ }
12
+ export declare type ElementAttributes = HTMLAttributes<HTMLElement> & {
13
+ 'data-oak-id'?: string;
14
+ 'data-oak-type'?: string;
15
+ [key: `data-${string}`]: string | undefined;
16
+ };
17
+ export declare type SanitizeHTMLCallback = (html: string) => string;
18
+ export declare type RendererEventCallback = (event: string, element: ElementObject) => void;
19
+ export declare interface RendererComponentProps {
20
+ /**
21
+ * The element to render
22
+ */
23
+ element: ElementObject;
24
+ /**
25
+ * Attributes that MUST be spread on the root DOM node of the rendered
26
+ * component. They contain the computed className & style (from the
27
+ * element's settings) and data attributes used by builders to identify the
28
+ * element in the DOM.
29
+ */
30
+ attributes: ElementAttributes;
31
+ /**
32
+ * Renders the child elements stored in `element[containerKey]`.
33
+ * Container components (row, col, foldable, ...) use it to render their
34
+ * children without knowing how the content tree is walked.
35
+ */
36
+ renderContainer: (containerKey: string) => ReactNode;
37
+ /**
38
+ * Nesting depth of the element (0 = root)
39
+ */
40
+ depth?: number;
41
+ /**
42
+ * Editing mode is enabled when the content is rendered inside a builder.
43
+ * Components may slightly adapt their output in this mode (e.g. show every
44
+ * section of a foldable, or display a placeholder for an empty image), but
45
+ * should otherwise render exactly like they would on the final page.
46
+ */
47
+ editing?: boolean;
48
+ /**
49
+ * Whether the content is displayed in dark mode. Dark styles
50
+ * (`element.styles.dark`) are already merged into `attributes`, but
51
+ * components may need it to adapt their default appearance.
52
+ */
53
+ dark?: boolean;
54
+ /**
55
+ * Used to sanitize raw html content (titles, texts, buttons)
56
+ */
57
+ sanitizeHTML?: SanitizeHTMLCallback;
58
+ /**
59
+ * Called when an element with an `event` action is clicked
60
+ */
61
+ onEvent?: RendererEventCallback;
62
+ }
63
+ export declare type RendererComponent = ComponentType<RendererComponentProps> & {
64
+ /**
65
+ * Set to true if the component computes its own responsive classes
66
+ * (e.g. columns), so that the default visibility classes are not applied
67
+ * by whatever walks the content tree (see `getElementAttributes`).
68
+ */
69
+ oakHandlesResponsive?: boolean;
70
+ };
71
+ export declare type RendererComponentsMap = Record<string, RendererComponent>;
72
+ export declare type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
73
+ export declare type ElementStyles = Record<string, any>;
74
+ export declare interface ElementRenderOptions {
75
+ /**
76
+ * Use the element's dark styles (`styles.dark`, `settings.dark.className`)
77
+ * on top of its default styles
78
+ */
79
+ dark?: boolean;
80
+ }
81
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtE;;;GAGG;AACH,MAAM,CAAC,OAAO,WAAW,aAAa;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,GAAG,CAAC,GAAG,aAAa,EAAE,CAAC;IAChE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,CAAC,OAAO,MAAM,iBAAiB,GAAG,cAAc,CAAC,WAAW,CAAC,GAAG;IACpE,aAAa,CAAC,EAA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,OAAO,WAAW,oBAAoB;IAC3C;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB"}
@@ -0,0 +1,62 @@
1
+ import type { CSSProperties } from 'react';
2
+ import type { Breakpoint, ElementObject, ElementAttributes, ElementRenderOptions, ElementStyles, RendererComponent } from './types';
3
+ export declare const BREAKPOINTS: Breakpoint[];
4
+ /**
5
+ * Container widths (in px) at which each breakpoint starts.
6
+ * Responsive rules use container queries (not media queries) so that the
7
+ * content adapts to its container width: this allows builders to preview
8
+ * any screen size without resizing the window.
9
+ */
10
+ export declare const BREAKPOINT_WIDTHS: Record<Breakpoint, number>;
11
+ /**
12
+ * Appends `px` to unitless numeric values, and returns undefined for empty
13
+ * values so they are omitted from the style object.
14
+ */
15
+ export declare const toCSSUnit: (value: unknown) => string | undefined;
16
+ /**
17
+ * Converts oak's element styling settings (`element.styles`) into a react
18
+ * style object.
19
+ */
20
+ export declare const getElementStyle: (styles?: ElementStyles) => CSSProperties;
21
+ /**
22
+ * Generates the css rules for interactive states (hover, active) that cannot
23
+ * be expressed through inline styles.
24
+ */
25
+ export declare const getElementStatesCSS: (element: ElementObject, { dark }?: ElementRenderOptions) => string;
26
+ /**
27
+ * Returns classes hiding the element on the breakpoints where it was set as
28
+ * hidden (`element.responsive[breakpoint] === 'hide'`).
29
+ */
30
+ export declare const getVisibilityClasses: (element: ElementObject) => string;
31
+ /**
32
+ * Returns the size classes of a column, for every breakpoint.
33
+ * The base size (`element.size`) is used for every breakpoint that doesn't
34
+ * declare a specific size in `element.responsive`.
35
+ */
36
+ export declare const getColClasses: (element: ElementObject) => string;
37
+ /**
38
+ * Merges additional attributes into the attributes given by the renderer,
39
+ * concatenating classNames & merging styles.
40
+ */
41
+ export declare const mergeAttributes: (attributes: ElementAttributes, ...others: (ElementAttributes | null | undefined | false)[]) => ElementAttributes;
42
+ /**
43
+ * DOM event dispatched (bubbling) by builders on an element that is hidden
44
+ * by one of its ancestors (e.g. inside a collapsed foldable) and needs to be
45
+ * displayed. Components hiding their children should listen to it on their
46
+ * root node and display the section containing `event.target`.
47
+ */
48
+ export declare const REVEAL_EVENT = "oak:reveal";
49
+ /**
50
+ * Attributes to put on the DOM node that directly wraps a list of child
51
+ * elements. Builders rely on them to know where elements can be dropped.
52
+ */
53
+ export declare const containerAttributes: (key: string) => {
54
+ 'data-oak-container': string;
55
+ };
56
+ /**
57
+ * Computes the attributes every rendered element should receive (see
58
+ * `RendererComponentProps.attributes`): data attributes, className (custom
59
+ * class & responsive visibility), style (from styling settings), dir & role.
60
+ */
61
+ export declare const getElementAttributes: (element: ElementObject, component?: RendererComponent, { dark }?: ElementRenderOptions) => ElementAttributes;
62
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAG3C,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,WAAW,EAAE,UAAU,EAAmC,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAMxD,CAAC;AA4BF;;;GAGG;AACH,eAAO,MAAM,SAAS,UAAW,OAAO,KAAG,MAAM,GAAG,SAUnD,CAAC;AAeF;;;GAGG;AACH,eAAO,MAAM,eAAe,YAAa,aAAa,KAAG,aAiExD,CAAC;AAQF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,YACrB,aAAa,aACJ,oBAAoB,KACrC,MAqBF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,YAAa,aAAa,KAAG,MAK3D,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,aAAa,YAAa,aAAa,KAAG,MAiBtD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,eACd,iBAAiB,aAClB,CAAC,iBAAiB,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,EAAE,KAC1D,iBAYoB,CAAC;AAExB;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAe,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QAAS,MAAM;IAC7C,oBAAoB;CACpB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,YACtB,aAAa,cACV,iBAAiB,aACX,oBAAoB,KACrC,iBAkBF,CAAC"}
@@ -0,0 +1,49 @@
1
+ /*
2
+ * Tailwind preset for @oakjs/react-renderer.
3
+ * Import it after tailwind's theme & utilities (with the `oak` prefix) to
4
+ * generate every class used by the renderer:
5
+ *
6
+ * @import "tailwindcss/theme.css" prefix(oak);
7
+ * @import "tailwindcss/utilities.css" prefix(oak) source(none);
8
+ * @import "@oakjs/react-renderer/tailwind.css";
9
+ */
10
+
11
+ @source "./";
12
+
13
+ /* Responsive settings use container queries: the content root needs it */
14
+ @source inline("oak:@container");
15
+
16
+ /* Columns sizes, for every breakpoint (see BREAKPOINT_WIDTHS in utils.ts) */
17
+ @source inline("oak:{,@min-[576px]:,@min-[768px]:,@min-[992px]:,@min-[1200px]:}colsize-{1,2,3,4,5,6,7,8,9,10,11,12,fluid,auto,hide}");
18
+
19
+ /*
20
+ * A column of N/12 takes N/12 of the row minus its share of the gaps, so
21
+ * that 12 columns of 1/12 (with 11 gaps) fit exactly on a single line.
22
+ */
23
+ @utility colsize-* {
24
+ display: flex;
25
+ flex-direction: column;
26
+ min-width: 0;
27
+ flex: 0 0 calc(100% * --value(integer) / 12 - var(--oak-col-gap, 0px) * (12 - --value(integer)) / 12);
28
+ max-width: calc(100% * --value(integer) / 12 - var(--oak-col-gap, 0px) * (12 - --value(integer)) / 12);
29
+ }
30
+
31
+ @utility colsize-fluid {
32
+ display: flex;
33
+ flex-direction: column;
34
+ min-width: 0;
35
+ flex: 1 1 0%;
36
+ max-width: 100%;
37
+ }
38
+
39
+ @utility colsize-auto {
40
+ display: flex;
41
+ flex-direction: column;
42
+ min-width: 0;
43
+ flex: 0 0 auto;
44
+ max-width: 100%;
45
+ }
46
+
47
+ @utility colsize-hide {
48
+ display: none;
49
+ }
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@oakjs/react-renderer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.0.0-alpha.0",
4
+ "description": "🌳 React renderer for oak page builder content",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/types/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/p3ol/oak.git",
12
+ "directory": "packages/react-renderer"
13
+ },
14
+ "author": "Ugo Stephant <ugo@poool.fr>",
15
+ "contributors": [
16
+ "Maxime Da Silva <maximed@poool.fr>"
17
+ ],
18
+ "license": "MIT",
19
+ "sideEffects": [
20
+ "*.css"
21
+ ],
22
+ "engines": {
23
+ "node": ">= 20"
24
+ },
25
+ "peerDependencies": {
26
+ "react": "^18.0.0 || ^19.0.0"
27
+ },
28
+ "dependencies": {
29
+ "@junipero/core": "3.14.1"
30
+ },
31
+ "scripts": {
32
+ "clean": "rm -rf ./dist || true",
33
+ "build": "yarn clean && yarn build:code && yarn build:dts && yarn build:css",
34
+ "build:code": "yarn run -T tsdown",
35
+ "build:dts": "yarn run -T tsc --project ./tsconfig.build.json",
36
+ "build:css": "node --import=tsx ../../scripts/build-css.ts ./lib/index.css ./dist/oak-renderer.css"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "exports": {
42
+ ".": {
43
+ "types": "./dist/types/index.d.ts",
44
+ "import": "./dist/index.js",
45
+ "require": "./dist/index.cjs"
46
+ },
47
+ "./server": {
48
+ "types": "./dist/types/server.d.ts",
49
+ "import": "./dist/server.js",
50
+ "require": "./dist/server.cjs"
51
+ },
52
+ "./styles.css": "./dist/oak-renderer.css",
53
+ "./tailwind.css": "./lib/tailwind.css"
54
+ },
55
+ "files": [
56
+ "dist",
57
+ "lib/tailwind.css"
58
+ ],
59
+ "targets": [
60
+ "chrome109",
61
+ "edge138",
62
+ "firefox140",
63
+ "safari18",
64
+ "opera80",
65
+ "node20"
66
+ ]
67
+ }