@zikojs/astro 0.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/package.json +35 -0
- package/src/client.d.ts +1 -0
- package/src/client.js +19 -0
- package/src/index.d.ts +9 -0
- package/src/index.js +36 -0
- package/src/server.js +26 -0
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zikojs/astro",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Use Zikojs components within Astro",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"astro-integration",
|
|
7
|
+
"astro-component",
|
|
8
|
+
"renderer",
|
|
9
|
+
"zikojs",
|
|
10
|
+
"ziko"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "zakaria elalaoui",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "index.js",
|
|
16
|
+
"exports":{
|
|
17
|
+
".":"./src/index.js",
|
|
18
|
+
"./client": "./client.js",
|
|
19
|
+
"./server": "./server.js"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"ziko": "^1.8.0"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/zikojs/integrations.git",
|
|
33
|
+
"directory": "packages/astro"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (wrapper: HTMLElement): (Component: any, props: Record<string, any>, { default: children, ...slotted }: Record<string, any>, { client }: Record<string, string>) => void;
|
package/src/client.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// import { isAsync } from "ziko-server/utils"
|
|
2
|
+
export default function (wrapper) {
|
|
3
|
+
return (Component, props, { default: children, ...slotted }, {client}) => {
|
|
4
|
+
// if (!wrapper.hasAttribute("ssr")){
|
|
5
|
+
// console.log("ssr")
|
|
6
|
+
// return
|
|
7
|
+
// }
|
|
8
|
+
wrapper.setAttribute("data-engine","zikojs")
|
|
9
|
+
const properties = props ?? {};
|
|
10
|
+
switch(client){
|
|
11
|
+
case "only" : Component(properties).mount(wrapper); break;
|
|
12
|
+
default : {
|
|
13
|
+
wrapper.innerHTML = ""
|
|
14
|
+
console.log(`Client Hydration : ${Component}`)
|
|
15
|
+
Component(properties).mount(wrapper); break;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const astroZikojs = (options = {}) => {
|
|
2
|
+
const noExternal = options.noExternal || []
|
|
3
|
+
|
|
4
|
+
return {
|
|
5
|
+
name: "astro-zikojs",
|
|
6
|
+
|
|
7
|
+
hooks: {
|
|
8
|
+
"astro:config:setup": async ({ addRenderer, updateConfig, config }) => {
|
|
9
|
+
|
|
10
|
+
// 1. Register renderer
|
|
11
|
+
addRenderer({
|
|
12
|
+
name: "astro-zikojs",
|
|
13
|
+
serverEntrypoint: "@zikojs/astro/server",
|
|
14
|
+
clientEntrypoint: "@zikojs/astro/client",
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// 2. Merge noExternal
|
|
18
|
+
const existing = config.vite?.ssr?.noExternal || []
|
|
19
|
+
|
|
20
|
+
if (noExternal.length) {
|
|
21
|
+
updateConfig({
|
|
22
|
+
vite: {
|
|
23
|
+
ssr: {
|
|
24
|
+
noExternal: [
|
|
25
|
+
...new Set([...existing, ...noExternal])
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default astroZikojs
|
package/src/server.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { renderToString } from "ziko-server/server-only-utils"
|
|
2
|
+
import { isAsync } from "ziko-server/utils"
|
|
3
|
+
function check(Component, attributes) {
|
|
4
|
+
if (typeof Component !== "function") return false;
|
|
5
|
+
return true
|
|
6
|
+
}
|
|
7
|
+
async function renderToStaticMarkup(Component, props, { default: children, ...slotted }, metadata) {
|
|
8
|
+
const UI = isAsync(Component) ? await Component(props) : Component(props)
|
|
9
|
+
const html = renderToString(UI)
|
|
10
|
+
console.log({metadata})
|
|
11
|
+
return {
|
|
12
|
+
html,
|
|
13
|
+
// hydration: {
|
|
14
|
+
// ...metadata,
|
|
15
|
+
// directive: "astro-zikojs",
|
|
16
|
+
// // componentExport: "default",
|
|
17
|
+
// // componentUrl: metadata.filePath,
|
|
18
|
+
// },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
name : "astro-zikojs",
|
|
24
|
+
check,
|
|
25
|
+
renderToStaticMarkup
|
|
26
|
+
}
|