vike-solid 0.2.6 → 0.2.8
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.md +9 -0
- package/README.md +1 -1
- package/dist/+config.js +7 -0
- package/dist/+onRenderClient.js +10 -2
- package/dist/+onRenderHtml.js +27 -15
- package/dist/{usePageContext-gFteWsFt.js → PageContextProvider-OTjP33FZ.js} +13 -1
- package/dist/components/ClientOnly.d.ts +1 -2
- package/dist/components/useData.d.ts +2 -0
- package/dist/components/usePageContext.d.ts +2 -6
- package/dist/renderer/+config.d.ts +21 -4
- package/dist/useData-UNVtqljj.d.ts +13 -0
- package/dist/useData.js +3 -0
- package/dist/usePageContext.js +1 -1
- package/package.json +16 -12
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Joël Charles
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# `vike-solid`
|
|
5
5
|
|
|
6
|
-
SolidJS integration for [Vike](https://github.com/vikejs/vike)
|
|
6
|
+
SolidJS integration for [Vike](https://github.com/vikejs/vike).
|
|
7
7
|
|
|
8
8
|
> [!NOTE]
|
|
9
9
|
> For integrations with React and Vue, see the other [`vike-*` packages](https://vike.dev/vike-packages).
|
package/dist/+config.js
CHANGED
|
@@ -28,6 +28,8 @@ const toggleSsrRelatedConfig = ({
|
|
|
28
28
|
var _config = {
|
|
29
29
|
onRenderHtml: "import:vike-solid/renderer/onRenderHtml:onRenderHtml",
|
|
30
30
|
onRenderClient: "import:vike-solid/renderer/onRenderClient:onRenderClient",
|
|
31
|
+
// TODO/next-major-release: remove pageProps (i.e. tell users to use data() instead of onBeforeRender() to fetch data)
|
|
32
|
+
// TODO/next-major-release: remove support for setting title over onBeforeRender()
|
|
31
33
|
// A page can define an onBeforeRender() hook to be run on the server, which
|
|
32
34
|
// can fetch data and return it as additional page context. Typically it will
|
|
33
35
|
// return the page's root Solid component's props and additional data that can
|
|
@@ -75,6 +77,11 @@ var _config = {
|
|
|
75
77
|
config: true
|
|
76
78
|
},
|
|
77
79
|
effect: toggleSsrRelatedConfig
|
|
80
|
+
},
|
|
81
|
+
stream: {
|
|
82
|
+
env: {
|
|
83
|
+
server: true
|
|
84
|
+
}
|
|
78
85
|
}
|
|
79
86
|
}
|
|
80
87
|
};
|
package/dist/+onRenderClient.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { createComponent, Dynamic, mergeProps, memo, hydrate, render } from 'solid-js/web';
|
|
2
|
-
import { P as PageContextProvider, u as usePageContext } from './
|
|
2
|
+
import { P as PageContextProvider, u as usePageContext } from './PageContextProvider-OTjP33FZ.js';
|
|
3
3
|
import { createStore, reconcile } from 'solid-js/store';
|
|
4
4
|
import 'solid-js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Get the page's title if defined, either from the additional data fetched by
|
|
8
|
-
* the page's onBeforeRender() hook or from the config.
|
|
8
|
+
* the page's data() and onBeforeRender() hook or from the config.
|
|
9
9
|
*/
|
|
10
10
|
function getTitle(pageContext) {
|
|
11
|
+
// from data() hook
|
|
12
|
+
if (pageContext.data?.title !== undefined) {
|
|
13
|
+
return pageContext.data.title;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// TODO/next-major-release: remove support for setting title over onBeforeRender()
|
|
17
|
+
// from onBeforeRender() hook
|
|
11
18
|
if (pageContext.title !== undefined) {
|
|
12
19
|
return pageContext.title;
|
|
13
20
|
}
|
|
@@ -63,6 +70,7 @@ function Layout(props) {
|
|
|
63
70
|
}
|
|
64
71
|
function Page() {
|
|
65
72
|
const pageContext = usePageContext();
|
|
73
|
+
// TODO/next-major-release: remove pageProps (i.e. tell users to use data() instead of onBeforeRender() to fetch data)
|
|
66
74
|
return createComponent(Dynamic, mergeProps({
|
|
67
75
|
get component() {
|
|
68
76
|
return pageContext.Page;
|
package/dist/+onRenderHtml.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { createComponent, Dynamic, mergeProps, renderToString, renderToStream, generateHydrationScript } from 'solid-js/web';
|
|
2
|
-
import { version, escapeInject,
|
|
3
|
-
import { P as PageContextProvider, u as usePageContext } from './
|
|
2
|
+
import { version, escapeInject, dangerouslySkipEscape, stampPipe } from 'vike/server';
|
|
3
|
+
import { P as PageContextProvider, u as usePageContext } from './PageContextProvider-OTjP33FZ.js';
|
|
4
4
|
import 'solid-js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Get the page's title if defined, either from the additional data fetched by
|
|
8
|
-
* the page's onBeforeRender() hook or from the config.
|
|
8
|
+
* the page's data() and onBeforeRender() hook or from the config.
|
|
9
9
|
*/
|
|
10
10
|
function getTitle(pageContext) {
|
|
11
|
+
// from data() hook
|
|
12
|
+
if (pageContext.data?.title !== undefined) {
|
|
13
|
+
return pageContext.data.title;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// TODO/next-major-release: remove support for setting title over onBeforeRender()
|
|
17
|
+
// from onBeforeRender() hook
|
|
11
18
|
if (pageContext.title !== undefined) {
|
|
12
19
|
return pageContext.title;
|
|
13
20
|
}
|
|
@@ -63,6 +70,7 @@ function Layout(props) {
|
|
|
63
70
|
}
|
|
64
71
|
function Page() {
|
|
65
72
|
const pageContext = usePageContext();
|
|
73
|
+
// TODO/next-major-release: remove pageProps (i.e. tell users to use data() instead of onBeforeRender() to fetch data)
|
|
66
74
|
return createComponent(Dynamic, mergeProps({
|
|
67
75
|
get component() {
|
|
68
76
|
return pageContext.Page;
|
|
@@ -75,12 +83,15 @@ function Passthrough(props) {
|
|
|
75
83
|
|
|
76
84
|
checkVikeVersion();
|
|
77
85
|
const onRenderHtml = async pageContext => {
|
|
78
|
-
const title = getTitle(pageContext);
|
|
79
|
-
const titleTag = !title ? "" : escapeInject`<title>${title}</title>`;
|
|
80
86
|
const {
|
|
87
|
+
stream,
|
|
88
|
+
favicon,
|
|
81
89
|
description
|
|
82
90
|
} = pageContext.config;
|
|
83
|
-
const
|
|
91
|
+
const title = getTitle(pageContext);
|
|
92
|
+
const titleTag = !title ? "" : escapeInject`<title>${title}</title>`;
|
|
93
|
+
const faviconTag = !favicon ? '' : escapeInject`<link rel="icon" href="${favicon}" />`;
|
|
94
|
+
const descriptionTag = !description ? '' : escapeInject`<meta name="description" content="${description}" />`;
|
|
84
95
|
const Head = pageContext.config.Head || (() => []);
|
|
85
96
|
const headHtml = renderToString(() => createComponent(PageContextProvider, {
|
|
86
97
|
pageContext: pageContext,
|
|
@@ -88,14 +99,15 @@ const onRenderHtml = async pageContext => {
|
|
|
88
99
|
return createComponent(Head, {});
|
|
89
100
|
}
|
|
90
101
|
}));
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
let pageView = '';
|
|
103
|
+
if (!!pageContext.Page) {
|
|
104
|
+
if (!stream) {
|
|
105
|
+
pageView = dangerouslySkipEscape(renderToString(() => getPageElement(pageContext)));
|
|
106
|
+
} else {
|
|
107
|
+
pageView = renderToStream(() => getPageElement(pageContext)).pipe;
|
|
108
|
+
stampPipe(pageView, "node-stream");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
99
111
|
const lang = pageContext.config.lang || "en";
|
|
100
112
|
const documentHtml = escapeInject`<!DOCTYPE html>
|
|
101
113
|
<html lang='${lang}'>
|
|
@@ -108,7 +120,7 @@ const onRenderHtml = async pageContext => {
|
|
|
108
120
|
${dangerouslySkipEscape(generateHydrationScript())}
|
|
109
121
|
</head>
|
|
110
122
|
<body>
|
|
111
|
-
<div id="page-view">${
|
|
123
|
+
<div id="page-view">${pageView}</div>
|
|
112
124
|
</body>
|
|
113
125
|
<!-- built with https://github.com/vikejs/vike-solid -->
|
|
114
126
|
</html>`;
|
|
@@ -32,5 +32,17 @@ function usePageContext() {
|
|
|
32
32
|
if (!pageContext) throw new Error("<PageContextProvider> is needed for being able to use usePageContext()");
|
|
33
33
|
return pageContext;
|
|
34
34
|
}
|
|
35
|
+
/** Access `pageContext.data` from any SolidJS component
|
|
36
|
+
*
|
|
37
|
+
* See
|
|
38
|
+
* - https://vike.dev/data
|
|
39
|
+
* - https://vike.dev/pageContext-anywhere
|
|
40
|
+
*/
|
|
41
|
+
function useData() {
|
|
42
|
+
const {
|
|
43
|
+
data
|
|
44
|
+
} = usePageContext();
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
35
47
|
|
|
36
|
-
export { PageContextProvider as P, usePageContext as u };
|
|
48
|
+
export { PageContextProvider as P, useData as a, usePageContext as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, JSX
|
|
1
|
+
import { Component, JSX } from 'solid-js';
|
|
2
2
|
|
|
3
3
|
declare function ClientOnly<T>(props: {
|
|
4
4
|
load: () => Promise<{
|
|
@@ -6,7 +6,6 @@ declare function ClientOnly<T>(props: {
|
|
|
6
6
|
} | Component<T>>;
|
|
7
7
|
children: (Component: Component<T>) => JSX.Element;
|
|
8
8
|
fallback: JSX.Element;
|
|
9
|
-
deps?: Parameters<typeof createSignal>[1];
|
|
10
9
|
}): JSX.Element;
|
|
11
10
|
|
|
12
11
|
export { ClientOnly };
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** Access the pageContext from any SolidJS component */
|
|
4
|
-
declare function usePageContext(): PageContext;
|
|
5
|
-
|
|
6
|
-
export { usePageContext };
|
|
1
|
+
export { u as usePageContext } from '../useData-UNVtqljj.js';
|
|
2
|
+
import 'vike/types';
|
|
@@ -7,10 +7,14 @@ declare global {
|
|
|
7
7
|
namespace Vike {
|
|
8
8
|
interface PageContext {
|
|
9
9
|
Page?: Page;
|
|
10
|
-
/** Properties of the page's root Solid component. */
|
|
10
|
+
/** Properties of the page's root Solid component - e.g. set by onBeforeRender() hook */
|
|
11
11
|
pageProps?: Record<string, unknown>;
|
|
12
|
-
/** <title>${title}</title> - has precedence over the config */
|
|
12
|
+
/** <title>${title}</title> - set by onBeforeRender() hook, has precedence over the config */
|
|
13
13
|
title?: string;
|
|
14
|
+
data?: {
|
|
15
|
+
/** <title>${title}</title> - set by data() hook, has precedence over the onBeforeRender() hook */
|
|
16
|
+
title?: string;
|
|
17
|
+
};
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
}
|
|
@@ -60,14 +64,22 @@ declare const _default: {
|
|
|
60
64
|
};
|
|
61
65
|
effect: ConfigEffect;
|
|
62
66
|
};
|
|
67
|
+
stream: {
|
|
68
|
+
env: {
|
|
69
|
+
server: true;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
63
72
|
};
|
|
64
73
|
};
|
|
65
74
|
|
|
66
75
|
declare global {
|
|
67
76
|
namespace VikePackages {
|
|
68
77
|
interface ConfigVikeSolid {
|
|
78
|
+
/** The page's root Solid component */
|
|
79
|
+
Page?: Component;
|
|
69
80
|
/** Solid element renderer and appended into <head></head> */
|
|
70
81
|
Head?: Component;
|
|
82
|
+
/** A component, usually common to several pages, that wraps the root component `Page` */
|
|
71
83
|
Layout?: Component;
|
|
72
84
|
title?: string | ((pageContext: PageContext) => string);
|
|
73
85
|
description?: string;
|
|
@@ -88,8 +100,13 @@ declare global {
|
|
|
88
100
|
*
|
|
89
101
|
*/
|
|
90
102
|
ssr?: boolean;
|
|
91
|
-
/**
|
|
92
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Whether to stream the page's HTML. Requires Server-Side Rendering (`ssr: true`).
|
|
105
|
+
*
|
|
106
|
+
* @default false
|
|
107
|
+
*
|
|
108
|
+
*/
|
|
109
|
+
stream?: boolean;
|
|
93
110
|
}
|
|
94
111
|
}
|
|
95
112
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PageContext } from 'vike/types';
|
|
2
|
+
|
|
3
|
+
/** Access the pageContext from any SolidJS component */
|
|
4
|
+
declare function usePageContext(): PageContext;
|
|
5
|
+
/** Access `pageContext.data` from any SolidJS component
|
|
6
|
+
*
|
|
7
|
+
* See
|
|
8
|
+
* - https://vike.dev/data
|
|
9
|
+
* - https://vike.dev/pageContext-anywhere
|
|
10
|
+
*/
|
|
11
|
+
declare function useData<Data>(): Data;
|
|
12
|
+
|
|
13
|
+
export { useData as a, usePageContext as u };
|
package/dist/useData.js
ADDED
package/dist/usePageContext.js
CHANGED
package/package.json
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike-solid",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"vite-plugin-solid": "^2.
|
|
6
|
+
"vite-plugin-solid": "^2.8.0"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"solid-js": "^1.8.
|
|
9
|
+
"solid-js": "^1.8.7",
|
|
10
10
|
"vite": "^4.4 || ^5.0.2",
|
|
11
|
-
"vike": "^0.4.
|
|
11
|
+
"vike": "^0.4.152"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@babel/core": "^7.23.
|
|
15
|
-
"@babel/preset-env": "^7.23.
|
|
14
|
+
"@babel/core": "^7.23.7",
|
|
15
|
+
"@babel/preset-env": "^7.23.7",
|
|
16
16
|
"@babel/preset-typescript": "^7.23.3",
|
|
17
17
|
"@rollup/plugin-babel": "^6.0.4",
|
|
18
18
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
19
19
|
"@types/node": "^18.17.4",
|
|
20
20
|
"babel-preset-solid": "^1.8.6",
|
|
21
|
-
"bumpp": "^9.2.
|
|
22
|
-
"rollup": "^4.
|
|
21
|
+
"bumpp": "^9.2.1",
|
|
22
|
+
"rollup": "^4.9.2",
|
|
23
23
|
"rollup-plugin-dts": "^6.1.0",
|
|
24
|
-
"solid-js": "^1.8.
|
|
24
|
+
"solid-js": "^1.8.7",
|
|
25
25
|
"tslib": "^2.6.2",
|
|
26
|
-
"typescript": "^5.3.
|
|
27
|
-
"vite": "^5.0.
|
|
28
|
-
"vike": "^0.4.
|
|
26
|
+
"typescript": "^5.3.3",
|
|
27
|
+
"vite": "^5.0.10",
|
|
28
|
+
"vike": "^0.4.153"
|
|
29
29
|
},
|
|
30
30
|
"exports": {
|
|
31
31
|
".": "./dist/+config.js",
|
|
32
32
|
"./vite": "./dist/vite-plugin-vike-solid.js",
|
|
33
33
|
"./usePageContext": "./dist/usePageContext.js",
|
|
34
|
+
"./useData": "./dist/useData.js",
|
|
34
35
|
"./ClientOnly": "./dist/ClientOnly.js",
|
|
35
36
|
"./renderer/onRenderHtml": "./dist/+onRenderHtml.js",
|
|
36
37
|
"./renderer/onRenderClient": "./dist/+onRenderClient.js"
|
|
@@ -49,6 +50,9 @@
|
|
|
49
50
|
"usePageContext": [
|
|
50
51
|
"dist/components/usePageContext.d.ts"
|
|
51
52
|
],
|
|
53
|
+
"useData": [
|
|
54
|
+
"dist/components/useData.d.ts"
|
|
55
|
+
],
|
|
52
56
|
"ClientOnly": [
|
|
53
57
|
"dist/components/ClientOnly.d.ts"
|
|
54
58
|
]
|