@techrox/page-studio-renderer 1.0.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.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/index.cjs +52 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 techrox
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @techrox/page-studio-renderer
|
|
2
|
+
|
|
3
|
+
Server-safe renderer for `@techrox/page-studio` Puck output.
|
|
4
|
+
|
|
5
|
+
Use this on public pages to display whatever your admin saved in the editor. Renders to clean HTML in SSR, so search engines + users see the content immediately — no hydration flash.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @techrox/page-studio-renderer @techrox/page-studio-blocks
|
|
9
|
+
pnpm add @puckeditor/core # peer
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
Next.js App Router (server component):
|
|
15
|
+
|
|
16
|
+
```jsx
|
|
17
|
+
import { PageStudioRender } from '@techrox/page-studio-renderer';
|
|
18
|
+
import { fetchPage } from '@/lib/cms';
|
|
19
|
+
|
|
20
|
+
export default async function HomePage() {
|
|
21
|
+
const data = await fetchPage('page.home'); // your CMS read
|
|
22
|
+
return (
|
|
23
|
+
<PageStudioRender
|
|
24
|
+
data={data}
|
|
25
|
+
studio={{ /* same shape as the editor */ }}
|
|
26
|
+
fallback={<StaticDefault />}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
If `data` is empty or missing, `fallback` is rendered instead — so the public site can always ship a sensible default when the CMS has no override yet.
|
|
33
|
+
|
|
34
|
+
## Props
|
|
35
|
+
|
|
36
|
+
| Prop | Type | Notes |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| `data` | `PuckData \| null` | The JSON your editor saved. Empty `content` arrays render the fallback. |
|
|
39
|
+
| `config` | `PuckConfig` | Optional override; default uses `createPuckConfig()`. |
|
|
40
|
+
| `fallback` | `ReactNode` | Rendered when `data` is missing/empty. Defaults to `null`. |
|
|
41
|
+
| `studio` | `StudioValue` | Forwarded to `<PageStudioProvider>` — same shape as the editor's `studio` prop. |
|
|
42
|
+
|
|
43
|
+
The renderer **must** see the same `studio` value as the editor so blocks see consistent service catalogues, Link components, and site metadata across edit + view.
|
|
44
|
+
|
|
45
|
+
## What this package wraps
|
|
46
|
+
|
|
47
|
+
`<Render>` from `@puckeditor/core`, plus `<PageStudioProvider>` from `@techrox/page-studio-blocks`. That's it.
|
|
48
|
+
|
|
49
|
+
You could write the same five lines yourself; this package exists so server-only consumers don't have to add the editor as an indirect dependency.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.js
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
PageStudioProvider: () => import_page_studio_blocks2.PageStudioProvider,
|
|
23
|
+
PageStudioRender: () => PageStudioRender
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/PageStudioRender.jsx
|
|
28
|
+
var import_core = require("@puckeditor/core");
|
|
29
|
+
var import_page_studio_blocks = require("@techrox/page-studio-blocks");
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
function PageStudioRender({
|
|
32
|
+
data,
|
|
33
|
+
config,
|
|
34
|
+
fallback = null,
|
|
35
|
+
studio
|
|
36
|
+
}) {
|
|
37
|
+
if (!data || !Array.isArray(data.content) || data.content.length === 0) {
|
|
38
|
+
return fallback;
|
|
39
|
+
}
|
|
40
|
+
const resolved = config || (0, import_page_studio_blocks.createPuckConfig)();
|
|
41
|
+
const populated = (0, import_page_studio_blocks.applyConfigDefaults)(data, resolved);
|
|
42
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_page_studio_blocks.PageStudioProvider, { value: studio, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Render, { config: resolved, data: populated }) });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/index.js
|
|
46
|
+
var import_page_studio_blocks2 = require("@techrox/page-studio-blocks");
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
PageStudioProvider,
|
|
50
|
+
PageStudioRender
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.js","../src/PageStudioRender.jsx"],"sourcesContent":["export { PageStudioRender } from './PageStudioRender.jsx';\n// Re-exported for convenience so renderer-only consumers don't need to add\n// the blocks package as a direct import to wrap their tree with context.\nexport { PageStudioProvider } from '@techrox/page-studio-blocks';\n","// Server-safe renderer for Puck output. Designed to be dropped into a\n// Next.js/Remix/Astro server component so the block HTML lands in the SSR\n// response — no client-side render flash.\n//\n// `data` is the Puck JSON saved by the editor (typically stored on the\n// page row in your CMS). If `data` is missing or empty we render the\n// `fallback` so the host can still ship a static page when the CMS has\n// no override yet.\n\nimport { Render } from '@puckeditor/core';\nimport {\n applyConfigDefaults,\n createPuckConfig,\n PageStudioProvider,\n} from '@techrox/page-studio-blocks';\n\nexport function PageStudioRender({\n data,\n config,\n fallback = null,\n studio,\n}) {\n if (!data || !Array.isArray(data.content) || data.content.length === 0) {\n return fallback;\n }\n const resolved = config || createPuckConfig();\n const populated = applyConfigDefaults(data, resolved);\n // Blocks read site/services/Link/etc. from StudioContext at render time.\n // Wrapping here means the renderer works the same whether the host is\n // server-rendered or hydrating on the client.\n return (\n <PageStudioProvider value={studio}>\n <Render config={resolved} data={populated} />\n </PageStudioProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSA,kBAAuB;AACvB,gCAIO;AAkBD;AAhBC,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AACF,GAAG;AACD,MAAI,CAAC,QAAQ,CAAC,MAAM,QAAQ,KAAK,OAAO,KAAK,KAAK,QAAQ,WAAW,GAAG;AACtE,WAAO;AAAA,EACT;AACA,QAAM,WAAW,cAAU,4CAAiB;AAC5C,QAAM,gBAAY,+CAAoB,MAAM,QAAQ;AAIpD,SACE,4CAAC,gDAAmB,OAAO,QACzB,sDAAC,sBAAO,QAAQ,UAAU,MAAM,WAAW,GAC7C;AAEJ;;;ADhCA,IAAAA,6BAAmC;","names":["import_page_studio_blocks"]}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/PageStudioRender.jsx
|
|
2
|
+
import { Render } from "@puckeditor/core";
|
|
3
|
+
import {
|
|
4
|
+
applyConfigDefaults,
|
|
5
|
+
createPuckConfig,
|
|
6
|
+
PageStudioProvider
|
|
7
|
+
} from "@techrox/page-studio-blocks";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
function PageStudioRender({
|
|
10
|
+
data,
|
|
11
|
+
config,
|
|
12
|
+
fallback = null,
|
|
13
|
+
studio
|
|
14
|
+
}) {
|
|
15
|
+
if (!data || !Array.isArray(data.content) || data.content.length === 0) {
|
|
16
|
+
return fallback;
|
|
17
|
+
}
|
|
18
|
+
const resolved = config || createPuckConfig();
|
|
19
|
+
const populated = applyConfigDefaults(data, resolved);
|
|
20
|
+
return /* @__PURE__ */ jsx(PageStudioProvider, { value: studio, children: /* @__PURE__ */ jsx(Render, { config: resolved, data: populated }) });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/index.js
|
|
24
|
+
import { PageStudioProvider as PageStudioProvider2 } from "@techrox/page-studio-blocks";
|
|
25
|
+
export {
|
|
26
|
+
PageStudioProvider2 as PageStudioProvider,
|
|
27
|
+
PageStudioRender
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/PageStudioRender.jsx","../src/index.js"],"sourcesContent":["// Server-safe renderer for Puck output. Designed to be dropped into a\n// Next.js/Remix/Astro server component so the block HTML lands in the SSR\n// response — no client-side render flash.\n//\n// `data` is the Puck JSON saved by the editor (typically stored on the\n// page row in your CMS). If `data` is missing or empty we render the\n// `fallback` so the host can still ship a static page when the CMS has\n// no override yet.\n\nimport { Render } from '@puckeditor/core';\nimport {\n applyConfigDefaults,\n createPuckConfig,\n PageStudioProvider,\n} from '@techrox/page-studio-blocks';\n\nexport function PageStudioRender({\n data,\n config,\n fallback = null,\n studio,\n}) {\n if (!data || !Array.isArray(data.content) || data.content.length === 0) {\n return fallback;\n }\n const resolved = config || createPuckConfig();\n const populated = applyConfigDefaults(data, resolved);\n // Blocks read site/services/Link/etc. from StudioContext at render time.\n // Wrapping here means the renderer works the same whether the host is\n // server-rendered or hydrating on the client.\n return (\n <PageStudioProvider value={studio}>\n <Render config={resolved} data={populated} />\n </PageStudioProvider>\n );\n}\n","export { PageStudioRender } from './PageStudioRender.jsx';\n// Re-exported for convenience so renderer-only consumers don't need to add\n// the blocks package as a direct import to wrap their tree with context.\nexport { PageStudioProvider } from '@techrox/page-studio-blocks';\n"],"mappings":";AASA,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAkBD;AAhBC,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AACF,GAAG;AACD,MAAI,CAAC,QAAQ,CAAC,MAAM,QAAQ,KAAK,OAAO,KAAK,KAAK,QAAQ,WAAW,GAAG;AACtE,WAAO;AAAA,EACT;AACA,QAAM,WAAW,UAAU,iBAAiB;AAC5C,QAAM,YAAY,oBAAoB,MAAM,QAAQ;AAIpD,SACE,oBAAC,sBAAmB,OAAO,QACzB,8BAAC,UAAO,QAAQ,UAAU,MAAM,WAAW,GAC7C;AAEJ;;;AChCA,SAAS,sBAAAA,2BAA0B;","names":["PageStudioProvider"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@techrox/page-studio-renderer",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SSR-safe React renderer for displaying saved Puck JSON from @techrox/page-studio on a public page. Small footprint, no editor dependencies.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "techrox",
|
|
7
|
+
"homepage": "https://github.com/techrox/page-studio#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/techrox/page-studio.git",
|
|
11
|
+
"directory": "packages/renderer"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/techrox/page-studio/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@puckeditor/core": ">=0.21",
|
|
32
|
+
"react": ">=18",
|
|
33
|
+
"react-dom": ">=18",
|
|
34
|
+
"@techrox/page-studio-blocks": "1.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@puckeditor/core": "^0.21.2",
|
|
38
|
+
"react": "^18.3.1",
|
|
39
|
+
"react-dom": "^18.3.1",
|
|
40
|
+
"@techrox/page-studio-blocks": "1.0.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"renderer",
|
|
47
|
+
"ssr",
|
|
48
|
+
"page-renderer",
|
|
49
|
+
"puck",
|
|
50
|
+
"puckeditor",
|
|
51
|
+
"cms",
|
|
52
|
+
"react",
|
|
53
|
+
"headless",
|
|
54
|
+
"page-studio"
|
|
55
|
+
],
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=18"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup",
|
|
61
|
+
"dev": "tsup --watch",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"test:watch": "vitest"
|
|
64
|
+
}
|
|
65
|
+
}
|