@ilha/astro 0.2.1 → 0.2.2
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/dist/client.js +1 -14
- package/dist/plain-Dy-BNLLq.js +24 -0
- package/dist/plain.d.ts +8 -0
- package/dist/server.js +4 -28
- package/package.json +5 -5
package/dist/client.js
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as wrapPlainAsIsland } from "./plain-Dy-BNLLq.js";
|
|
2
2
|
|
|
3
3
|
//#region src/client.ts
|
|
4
|
-
const RAW = Symbol.for("ilha.raw");
|
|
5
4
|
function isMountable(Component) {
|
|
6
5
|
return !!Component && typeof Component.mount === "function";
|
|
7
6
|
}
|
|
8
|
-
function isRawHtml(value) {
|
|
9
|
-
return !!(value && typeof value === "object" && RAW in value);
|
|
10
|
-
}
|
|
11
|
-
function wrapPlainAsIsland(Component, merged) {
|
|
12
|
-
return ilha(() => {
|
|
13
|
-
const result = Component(merged);
|
|
14
|
-
if (result == null) return raw("");
|
|
15
|
-
if (typeof result === "string") return raw(result);
|
|
16
|
-
if (isRawHtml(result)) return raw(result.value);
|
|
17
|
-
return raw("");
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
7
|
var client_default = (element) => async (Component, props, slotted, _metadata) => {
|
|
21
8
|
if (!element.hasAttribute("ssr")) {
|
|
22
9
|
if (isMountable(Component)) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ilha, raw } from "ilha";
|
|
2
|
+
|
|
3
|
+
//#region src/plain.ts
|
|
4
|
+
const ISLAND = Symbol.for("ilha.island");
|
|
5
|
+
const RAW = Symbol.for("ilha.raw");
|
|
6
|
+
function isIsland(Component) {
|
|
7
|
+
return typeof Component === "function" && ISLAND in Component;
|
|
8
|
+
}
|
|
9
|
+
function isRawHtml(value) {
|
|
10
|
+
return !!(value && typeof value === "object" && RAW in value);
|
|
11
|
+
}
|
|
12
|
+
function resultToHtml(result) {
|
|
13
|
+
if (typeof result === "string") return result;
|
|
14
|
+
if (isRawHtml(result)) return result.value;
|
|
15
|
+
}
|
|
16
|
+
function wrapPlainAsIsland(Component, merged) {
|
|
17
|
+
return ilha(() => {
|
|
18
|
+
const html = resultToHtml(Component(merged));
|
|
19
|
+
return html === void 0 ? raw("") : raw(html);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { wrapPlainAsIsland as i, isRawHtml as n, resultToHtml as r, isIsland as t };
|
package/dist/plain.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Island } from "ilha";
|
|
2
|
+
export type PlainComponent = (props: Record<string, unknown>) => unknown;
|
|
3
|
+
export declare function isIsland(Component: unknown): Component is Island;
|
|
4
|
+
export declare function isRawHtml(value: unknown): value is {
|
|
5
|
+
value: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function resultToHtml(result: unknown): string | undefined;
|
|
8
|
+
export declare function wrapPlainAsIsland(Component: PlainComponent, merged: Record<string, unknown>): Island<unknown>;
|
package/dist/server.js
CHANGED
|
@@ -1,40 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as wrapPlainAsIsland, n as isRawHtml, r as resultToHtml, t as isIsland } from "./plain-Dy-BNLLq.js";
|
|
2
|
+
import { raw } from "ilha";
|
|
2
3
|
|
|
3
4
|
//#region src/server.ts
|
|
4
|
-
const ISLAND = Symbol.for("ilha.island");
|
|
5
|
-
const RAW = Symbol.for("ilha.raw");
|
|
6
5
|
let componentFilter;
|
|
7
6
|
function getComponentFilter() {
|
|
8
7
|
return componentFilter ??= import("virtual:@ilha/astro/options").then(({ default: filter }) => filter).catch(() => () => true);
|
|
9
8
|
}
|
|
10
|
-
function isIsland(Component) {
|
|
11
|
-
return typeof Component === "function" && ISLAND in Component;
|
|
12
|
-
}
|
|
13
|
-
function isRawHtml(value) {
|
|
14
|
-
return !!(value && typeof value === "object" && RAW in value);
|
|
15
|
-
}
|
|
16
|
-
function resultToHtml(result) {
|
|
17
|
-
if (typeof result === "string") return result;
|
|
18
|
-
if (isRawHtml(result)) return result.value;
|
|
19
|
-
}
|
|
20
9
|
/** True when plain SSR emitted nested island slot hosts that need a parent mount ctx. */
|
|
21
10
|
function hasNestedIslandSlots(html) {
|
|
22
11
|
return html.includes("data-ilha-slot");
|
|
23
12
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Wrap a plain function so its render runs under an island render ctx.
|
|
26
|
-
* Nested islands then get unique `data-ilha-slot` ids and can be mounted
|
|
27
|
-
* when the shell hydrates on the client.
|
|
28
|
-
*/
|
|
29
|
-
function wrapPlainAsIsland(Component, merged) {
|
|
30
|
-
return ilha(() => {
|
|
31
|
-
const result = Component(merged);
|
|
32
|
-
if (result == null) return raw("");
|
|
33
|
-
if (typeof result === "string") return raw(result);
|
|
34
|
-
if (isRawHtml(result)) return raw(result.value);
|
|
35
|
-
return raw("");
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
13
|
function toRawHtml(value) {
|
|
39
14
|
return raw(String(value));
|
|
40
15
|
}
|
|
@@ -65,7 +40,8 @@ async function mergePlainProps(props, slots) {
|
|
|
65
40
|
}
|
|
66
41
|
async function renderPlainComponent(Component, props, slots, metadata) {
|
|
67
42
|
const merged = await mergePlainProps(props, slots);
|
|
68
|
-
const
|
|
43
|
+
const result = Component(merged);
|
|
44
|
+
const html = resultToHtml(result);
|
|
69
45
|
if (html === void 0) return void 0;
|
|
70
46
|
if (!hasNestedIslandSlots(html)) return html;
|
|
71
47
|
return wrapPlainAsIsland(Component, merged).hydratable({}, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ilha/astro",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Astro integration for Ilha islands",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro-component",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"test": "bun test"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"astro": "^7.2.
|
|
56
|
-
"ilha": "
|
|
55
|
+
"astro": "^7.2.9",
|
|
56
|
+
"ilha": "0.13.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"astro": "^7.2.
|
|
60
|
-
"ilha": "
|
|
59
|
+
"astro": "^7.2.9",
|
|
60
|
+
"ilha": "^0.13.0"
|
|
61
61
|
}
|
|
62
62
|
}
|