@storylite/renderer-preact 1.1.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/dist/client.d.mts +7 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +21 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +57 -0
- package/dist/index.mjs.map +1 -0
- package/dist/static.d.mts +7 -0
- package/dist/static.d.mts.map +1 -0
- package/dist/static.mjs +22 -0
- package/dist/static.mjs.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Javi Aguilar
|
|
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.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MountedStory, StoryArgs, StoryContext, StoryLiteStory } from "@storylite/contracts";
|
|
2
|
+
|
|
3
|
+
//#region src/client.d.ts
|
|
4
|
+
declare function renderStory(story: StoryLiteStory, args: StoryArgs, context: StoryContext): MountedStory;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { renderStory };
|
|
7
|
+
//# sourceMappingURL=client.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;iBAIgB,WAAA,CACd,KAAA,EAAO,cAAA,EACP,IAAA,EAAM,SAAA,EACN,OAAA,EAAS,YAAA,GACR,YAAA"}
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { h, render } from "preact";
|
|
2
|
+
//#region src/client.ts
|
|
3
|
+
function renderStory(story, args, context) {
|
|
4
|
+
const mountPoint = context.document.createElement("div");
|
|
5
|
+
mountPoint.className = "sl-preact-root";
|
|
6
|
+
context.canvas.replaceChildren(mountPoint);
|
|
7
|
+
render(resolveOutput(story, args, context), mountPoint);
|
|
8
|
+
return { cleanup: () => {
|
|
9
|
+
render(null, mountPoint);
|
|
10
|
+
context.canvas.replaceChildren();
|
|
11
|
+
} };
|
|
12
|
+
}
|
|
13
|
+
function resolveOutput(story, args, context) {
|
|
14
|
+
if (story.render) return story.render(args, context);
|
|
15
|
+
if (typeof story.component !== "function") throw new Error(`Preact story "${story.name}" must provide a component or render function.`);
|
|
16
|
+
return h(story.component, args);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { renderStory };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { MountedStory, StoryArgs, StoryContext, StoryLiteStory } from '@storylite/contracts'\nimport type { ComponentChild, ComponentType } from 'preact'\nimport { h, render } from 'preact'\n\nexport function renderStory(\n story: StoryLiteStory,\n args: StoryArgs,\n context: StoryContext,\n): MountedStory {\n const mountPoint = context.document.createElement('div')\n mountPoint.className = 'sl-preact-root'\n context.canvas.replaceChildren(mountPoint)\n\n render(resolveOutput(story, args, context), mountPoint)\n\n return {\n cleanup: () => {\n render(null, mountPoint)\n context.canvas.replaceChildren()\n },\n }\n}\n\nfunction resolveOutput(\n story: StoryLiteStory,\n args: StoryArgs,\n context: StoryContext,\n): ComponentChild {\n if (story.render) {\n return story.render(args, context) as ComponentChild\n }\n\n if (typeof story.component !== 'function') {\n throw new Error(`Preact story \"${story.name}\" must provide a component or render function.`)\n }\n\n return h(story.component as ComponentType<Record<string, unknown>>, args)\n}\n"],"mappings":";;AAIA,SAAgB,YACd,OACA,MACA,SACc;CACd,MAAM,aAAa,QAAQ,SAAS,cAAc,KAAK;CACvD,WAAW,YAAY;CACvB,QAAQ,OAAO,gBAAgB,UAAU;CAEzC,OAAO,cAAc,OAAO,MAAM,OAAO,GAAG,UAAU;CAEtD,OAAO,EACL,eAAe;EACb,OAAO,MAAM,UAAU;EACvB,QAAQ,OAAO,gBAAgB;CACjC,EACF;AACF;AAEA,SAAS,cACP,OACA,MACA,SACgB;CAChB,IAAI,MAAM,QACR,OAAO,MAAM,OAAO,MAAM,OAAO;CAGnC,IAAI,OAAO,MAAM,cAAc,YAC7B,MAAM,IAAI,MAAM,iBAAiB,MAAM,KAAK,+CAA+C;CAG7F,OAAO,EAAE,MAAM,WAAqD,IAAI;AAC1E"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";iBAIwB,cAAA,CAAA,kCAAc,wBAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { defineRenderer } from "@storylite/contracts";
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
function preactRenderer() {
|
|
6
|
+
return defineRenderer({
|
|
7
|
+
name: "preact",
|
|
8
|
+
client: "@storylite/renderer-preact/client",
|
|
9
|
+
static: "@storylite/renderer-preact/static",
|
|
10
|
+
vitePlugins: async (context) => {
|
|
11
|
+
const { default: preact } = await import("@preact/preset-vite");
|
|
12
|
+
return [context.target === "manager" && context.command === "serve" ? preactProjectRuntimePlugin(context.projectRoot) : null, preact()].filter(Boolean);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function preactProjectRuntimePlugin(projectRoot) {
|
|
17
|
+
const preactPackageRoot = dirname(createRequire(`${projectRoot}/package.json`).resolve("preact/package.json"));
|
|
18
|
+
return {
|
|
19
|
+
name: "storylite-preact-project-runtime",
|
|
20
|
+
config() {
|
|
21
|
+
return { resolve: { alias: [
|
|
22
|
+
{
|
|
23
|
+
find: /^preact$/,
|
|
24
|
+
replacement: `${preactPackageRoot}/dist/preact.module.js`
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
find: /^preact\/jsx-runtime$/,
|
|
28
|
+
replacement: `${preactPackageRoot}/jsx-runtime/dist/jsxRuntime.module.js`
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
find: /^preact\/jsx-dev-runtime$/,
|
|
32
|
+
replacement: `${preactPackageRoot}/jsx-runtime/dist/jsxRuntime.module.js`
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
find: /^preact\/debug$/,
|
|
36
|
+
replacement: `${preactPackageRoot}/debug/dist/debug.module.js`
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
find: /^preact\/devtools$/,
|
|
40
|
+
replacement: `${preactPackageRoot}/devtools/dist/devtools.module.js`
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
find: /^preact\/hooks$/,
|
|
44
|
+
replacement: `${preactPackageRoot}/hooks/dist/hooks.module.js`
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
find: /^preact\/compat$/,
|
|
48
|
+
replacement: `${preactPackageRoot}/compat/dist/compat.module.js`
|
|
49
|
+
}
|
|
50
|
+
] } };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { preactRenderer as default };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { dirname } from 'node:path'\nimport { createRequire } from 'node:module'\nimport { defineRenderer } from '@storylite/contracts'\n\nexport default function preactRenderer() {\n return defineRenderer({\n name: 'preact',\n client: '@storylite/renderer-preact/client',\n static: '@storylite/renderer-preact/static',\n vitePlugins: async (context) => {\n const { default: preact } = await import('@preact/preset-vite')\n const needsProjectRuntime = context.target === 'manager' && context.command === 'serve'\n\n return [\n needsProjectRuntime ? preactProjectRuntimePlugin(context.projectRoot) : null,\n preact(),\n ].filter(Boolean)\n },\n })\n}\n\nfunction preactProjectRuntimePlugin(projectRoot: string) {\n const requireFromProject = createRequire(`${projectRoot}/package.json`)\n const preactPackageRoot = dirname(requireFromProject.resolve('preact/package.json'))\n\n return {\n name: 'storylite-preact-project-runtime',\n config() {\n return {\n resolve: {\n alias: [\n { find: /^preact$/, replacement: `${preactPackageRoot}/dist/preact.module.js` },\n {\n find: /^preact\\/jsx-runtime$/,\n replacement: `${preactPackageRoot}/jsx-runtime/dist/jsxRuntime.module.js`,\n },\n {\n find: /^preact\\/jsx-dev-runtime$/,\n replacement: `${preactPackageRoot}/jsx-runtime/dist/jsxRuntime.module.js`,\n },\n {\n find: /^preact\\/debug$/,\n replacement: `${preactPackageRoot}/debug/dist/debug.module.js`,\n },\n {\n find: /^preact\\/devtools$/,\n replacement: `${preactPackageRoot}/devtools/dist/devtools.module.js`,\n },\n {\n find: /^preact\\/hooks$/,\n replacement: `${preactPackageRoot}/hooks/dist/hooks.module.js`,\n },\n {\n find: /^preact\\/compat$/,\n replacement: `${preactPackageRoot}/compat/dist/compat.module.js`,\n },\n ],\n },\n }\n },\n }\n}\n"],"mappings":";;;;AAIA,SAAwB,iBAAiB;CACvC,OAAO,eAAe;EACpB,MAAM;EACN,QAAQ;EACR,QAAQ;EACR,aAAa,OAAO,YAAY;GAC9B,MAAM,EAAE,SAAS,WAAW,MAAM,OAAO;GAGzC,OAAO,CAFqB,QAAQ,WAAW,aAAa,QAAQ,YAAY,UAGxD,2BAA2B,QAAQ,WAAW,IAAI,MACxE,OAAO,CACT,EAAE,OAAO,OAAO;EAClB;CACF,CAAC;AACH;AAEA,SAAS,2BAA2B,aAAqB;CAEvD,MAAM,oBAAoB,QADC,cAAc,GAAG,YAAY,cACL,EAAE,QAAQ,qBAAqB,CAAC;CAEnF,OAAO;EACL,MAAM;EACN,SAAS;GACP,OAAO,EACL,SAAS,EACP,OAAO;IACL;KAAE,MAAM;KAAY,aAAa,GAAG,kBAAkB;IAAwB;IAC9E;KACE,MAAM;KACN,aAAa,GAAG,kBAAkB;IACpC;IACA;KACE,MAAM;KACN,aAAa,GAAG,kBAAkB;IACpC;IACA;KACE,MAAM;KACN,aAAa,GAAG,kBAAkB;IACpC;IACA;KACE,MAAM;KACN,aAAa,GAAG,kBAAkB;IACpC;IACA;KACE,MAAM;KACN,aAAa,GAAG,kBAAkB;IACpC;IACA;KACE,MAAM;KACN,aAAa,GAAG,kBAAkB;IACpC;GACF,EACF,EACF;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StoryLiteStaticRenderResult, StoryLiteStory } from "@storylite/contracts";
|
|
2
|
+
|
|
3
|
+
//#region src/static.d.ts
|
|
4
|
+
declare function renderStory(story: StoryLiteStory): StoryLiteStaticRenderResult;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { renderStory };
|
|
7
|
+
//# sourceMappingURL=static.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static.d.mts","names":[],"sources":["../src/static.ts"],"mappings":";;;iBASgB,WAAA,CAAY,KAAA,EAAO,cAAA,GAAiB,2BAA2B"}
|
package/dist/static.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { h } from "preact";
|
|
2
|
+
import renderToString from "preact-render-to-string";
|
|
3
|
+
//#region src/static.ts
|
|
4
|
+
function renderStory(story) {
|
|
5
|
+
return { html: renderToString(resolveOutput(story)) };
|
|
6
|
+
}
|
|
7
|
+
function resolveOutput(story) {
|
|
8
|
+
if (story.render) return story.render(story.args, {
|
|
9
|
+
id: story.id,
|
|
10
|
+
title: story.title,
|
|
11
|
+
name: story.name,
|
|
12
|
+
canvas: null,
|
|
13
|
+
document: null,
|
|
14
|
+
window: null
|
|
15
|
+
});
|
|
16
|
+
if (typeof story.component !== "function") throw new Error(`Preact story "${story.name}" must provide a component or render function.`);
|
|
17
|
+
return h(story.component, story.args);
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { renderStory };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=static.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static.mjs","names":[],"sources":["../src/static.ts"],"sourcesContent":["import type {\n StoryContext,\n StoryLiteStaticRenderResult,\n StoryLiteStory,\n} from '@storylite/contracts'\nimport type { ComponentType, VNode } from 'preact'\nimport { h } from 'preact'\nimport renderToString from 'preact-render-to-string'\n\nexport function renderStory(story: StoryLiteStory): StoryLiteStaticRenderResult {\n return { html: renderToString(resolveOutput(story)) }\n}\n\nfunction resolveOutput(story: StoryLiteStory): VNode {\n if (story.render) {\n return story.render(story.args, {\n id: story.id,\n title: story.title,\n name: story.name,\n canvas: null,\n document: null,\n window: null,\n } as unknown as StoryContext) as VNode\n }\n\n if (typeof story.component !== 'function') {\n throw new Error(`Preact story \"${story.name}\" must provide a component or render function.`)\n }\n\n return h(story.component as ComponentType<Record<string, unknown>>, story.args)\n}\n"],"mappings":";;;AASA,SAAgB,YAAY,OAAoD;CAC9E,OAAO,EAAE,MAAM,eAAe,cAAc,KAAK,CAAC,EAAE;AACtD;AAEA,SAAS,cAAc,OAA8B;CACnD,IAAI,MAAM,QACR,OAAO,MAAM,OAAO,MAAM,MAAM;EAC9B,IAAI,MAAM;EACV,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,QAAQ;EACR,UAAU;EACV,QAAQ;CACV,CAA4B;CAG9B,IAAI,OAAO,MAAM,cAAc,YAC7B,MAAM,IAAI,MAAM,iBAAiB,MAAM,KAAK,+CAA+C;CAG7F,OAAO,EAAE,MAAM,WAAqD,MAAM,IAAI;AAChF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@storylite/renderer-preact",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Preact renderer for StoryLite",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"main": "./dist/index.mjs",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.mts",
|
|
16
|
+
"import": "./dist/index.mjs",
|
|
17
|
+
"default": "./dist/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"./client": {
|
|
20
|
+
"types": "./dist/client.d.mts",
|
|
21
|
+
"import": "./dist/client.mjs",
|
|
22
|
+
"default": "./dist/client.mjs"
|
|
23
|
+
},
|
|
24
|
+
"./static": {
|
|
25
|
+
"types": "./dist/static.d.mts",
|
|
26
|
+
"import": "./dist/static.mjs",
|
|
27
|
+
"default": "./dist/static.mjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@storylite/contracts": "1.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@preact/preset-vite": "^2.10.5",
|
|
38
|
+
"@types/node": "^25.9.1",
|
|
39
|
+
"preact": "^10.29.2",
|
|
40
|
+
"preact-render-to-string": "^6.7.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@preact/preset-vite": "^2.10.5",
|
|
44
|
+
"preact": "^10.29.2",
|
|
45
|
+
"preact-render-to-string": "^6.7.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsdown",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"publint": "publint"
|
|
51
|
+
}
|
|
52
|
+
}
|