@hyperspan/plugin-preact 1.0.0-alpha.0 → 1.0.0-alpha.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/package.json +2 -2
- package/src/index.ts +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperspan/plugin-preact",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "Hyperspan Plugin for Preact",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"typescript": "^5.0.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@hyperspan/html": "0.
|
|
31
|
+
"@hyperspan/html": "^1.0.0-alpha",
|
|
32
32
|
"@hyperspan/framework": "^1.0.0-alpha"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { assetHash } from '@hyperspan/framework/utils';
|
|
|
3
3
|
import { IS_PROD } from '@hyperspan/framework/server';
|
|
4
4
|
import { join, resolve } from 'node:path';
|
|
5
5
|
import type { Hyperspan as HS } from '@hyperspan/framework';
|
|
6
|
+
import { html } from '@hyperspan/html';
|
|
6
7
|
|
|
7
8
|
// External ESM = https://esm.sh/preact@10.26.4/compat
|
|
8
9
|
const PREACT_ISLAND_CACHE = new Map<string, string>();
|
|
@@ -154,3 +155,21 @@ ${componentName}.__HS_ISLAND = {
|
|
|
154
155
|
});
|
|
155
156
|
};
|
|
156
157
|
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Render a Preact island component
|
|
162
|
+
*/
|
|
163
|
+
export function renderPreactIsland(Component: any, props: any = {}, options = {
|
|
164
|
+
ssr: true,
|
|
165
|
+
loading: undefined,
|
|
166
|
+
}) {
|
|
167
|
+
// Render island with its own logic
|
|
168
|
+
if (Component.__HS_ISLAND?.render) {
|
|
169
|
+
return html.raw(Component.__HS_ISLAND.render(props, options));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
throw new Error(
|
|
173
|
+
`Module ${Component.name} was not loaded with an island plugin! Did you forget to install an island plugin and add it to the 'islandPlugins' option in your hyperspan.config.ts file?`
|
|
174
|
+
);
|
|
175
|
+
}
|