@ox-content/islands 3.1.3 → 3.1.5
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/html-host.cjs +8 -0
- package/dist/html-host.d.cts +88 -0
- package/dist/html-host.d.mts +88 -0
- package/dist/html-host.mjs +2 -0
- package/dist/html-host2.cjs +259 -0
- package/dist/html-host2.d.cts +2 -0
- package/dist/html-host2.d.mts +2 -0
- package/dist/html-host2.mjs +226 -0
- package/dist/html-host2.mjs.map +1 -0
- package/dist/index.cjs +15 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/runtime.cjs +5 -0
- package/dist/runtime.d.cts +95 -0
- package/dist/runtime.d.cts.map +1 -0
- package/dist/runtime.d.mts +2 -84
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime2.cjs +359 -0
- package/dist/runtime2.mjs +45 -19
- package/dist/runtime2.mjs.map +1 -1
- package/dist/types.d.cts +86 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +86 -0
- package/dist/types.d.mts.map +1 -0
- package/package.json +28 -6
- package/dist/runtime2.d.mts +0 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_html_host = require("./html-host2.cjs");
|
|
3
|
+
exports.HtmlHostClientHydrationError = require_html_host.HtmlHostClientHydrationError;
|
|
4
|
+
exports.createHtmlHostClientError = require_html_host.createHtmlHostClientError;
|
|
5
|
+
exports.createHtmlHostLazyHydrate = require_html_host.createHtmlHostLazyHydrate;
|
|
6
|
+
exports.initHtmlHost = require_html_host.initHtmlHost;
|
|
7
|
+
exports.readHtmlHostSlot = require_html_host.readHtmlHostSlot;
|
|
8
|
+
exports.reportHtmlHostClientError = require_html_host.reportHtmlHostClientError;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { n as HydrateFunction, r as InitIslandsOptions } from "./types.cjs";
|
|
2
|
+
//#region src/html-host-errors.d.ts
|
|
3
|
+
type HtmlHostClientDiagnosticCode = "missing-island-name" | "missing-module-id" | "unknown-module" | "module-load-failed" | "runtime-load-failed" | "missing-export" | "render-failed";
|
|
4
|
+
interface HtmlHostClientError {
|
|
5
|
+
code: HtmlHostClientDiagnosticCode;
|
|
6
|
+
message: string;
|
|
7
|
+
element: HTMLElement;
|
|
8
|
+
props: Record<string, unknown>;
|
|
9
|
+
componentName?: string;
|
|
10
|
+
moduleId?: string;
|
|
11
|
+
exportName?: string;
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
}
|
|
14
|
+
declare class HtmlHostClientHydrationError extends Error {
|
|
15
|
+
readonly diagnostic: HtmlHostClientError;
|
|
16
|
+
constructor(diagnostic: HtmlHostClientError);
|
|
17
|
+
}
|
|
18
|
+
interface HtmlHostClientErrorContext {
|
|
19
|
+
componentName?: string;
|
|
20
|
+
moduleId?: string;
|
|
21
|
+
exportName?: string;
|
|
22
|
+
cause?: unknown;
|
|
23
|
+
frameworkName?: string;
|
|
24
|
+
}
|
|
25
|
+
declare function reportHtmlHostClientError(input: {
|
|
26
|
+
onError?: (error: HtmlHostClientError) => void;
|
|
27
|
+
}, error: HtmlHostClientError, eventName?: string): void;
|
|
28
|
+
declare function createHtmlHostClientError(code: HtmlHostClientDiagnosticCode, element: HTMLElement, props: Record<string, unknown>, context?: HtmlHostClientErrorContext): HtmlHostClientError;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/html-host.d.ts
|
|
31
|
+
type HtmlHostClientComponentValue = unknown;
|
|
32
|
+
type HtmlHostClientModuleValue = unknown;
|
|
33
|
+
type HtmlHostClientModuleLoader<TModule = HtmlHostClientModuleValue> = () => TModule | PromiseLike<TModule>;
|
|
34
|
+
type HtmlHostClientModules<TModule = HtmlHostClientModuleValue> = Readonly<Record<string, HtmlHostClientModuleLoader<TModule>>> | ReadonlyMap<string, HtmlHostClientModuleLoader<TModule>>;
|
|
35
|
+
interface HtmlHostClientContext<TRuntime = undefined> {
|
|
36
|
+
component: unknown;
|
|
37
|
+
componentName: string;
|
|
38
|
+
element: HTMLElement;
|
|
39
|
+
exportName: string;
|
|
40
|
+
moduleExports: unknown;
|
|
41
|
+
moduleId: string;
|
|
42
|
+
props: Record<string, unknown>;
|
|
43
|
+
runtime: TRuntime | undefined;
|
|
44
|
+
slotHtml: string | undefined;
|
|
45
|
+
}
|
|
46
|
+
type HtmlHostClientRenderer<TRuntime = undefined> = (context: HtmlHostClientContext<TRuntime>) => void | (() => void) | PromiseLike<void | (() => void)>;
|
|
47
|
+
type HtmlHostClientRuntimeLoader<TRuntime = undefined> = () => TRuntime | PromiseLike<TRuntime>;
|
|
48
|
+
type HtmlHostModuleIdResolver = (element: HTMLElement, context: {
|
|
49
|
+
componentName: string;
|
|
50
|
+
props: Record<string, unknown>;
|
|
51
|
+
}) => string | undefined;
|
|
52
|
+
type HtmlHostExportNameResolver = (element: HTMLElement, context: {
|
|
53
|
+
componentName: string;
|
|
54
|
+
moduleId: string;
|
|
55
|
+
props: Record<string, unknown>;
|
|
56
|
+
}) => string | undefined;
|
|
57
|
+
interface HtmlHostClientAdapter<TRuntime = undefined> {
|
|
58
|
+
frameworkName?: string;
|
|
59
|
+
eventName?: string;
|
|
60
|
+
render: HtmlHostClientRenderer<TRuntime>;
|
|
61
|
+
loadRuntime?: HtmlHostClientRuntimeLoader<TRuntime>;
|
|
62
|
+
preserveElementContents?: boolean;
|
|
63
|
+
}
|
|
64
|
+
interface CreateHtmlHostLazyHydrateInput<TRuntime = undefined> {
|
|
65
|
+
modules: HtmlHostClientModules;
|
|
66
|
+
adapter?: HtmlHostClientAdapter<TRuntime>;
|
|
67
|
+
render?: HtmlHostClientRenderer<TRuntime>;
|
|
68
|
+
loadRuntime?: HtmlHostClientRuntimeLoader<TRuntime>;
|
|
69
|
+
preserveElementContents?: boolean;
|
|
70
|
+
resolveModuleId?: HtmlHostModuleIdResolver;
|
|
71
|
+
resolveExportName?: HtmlHostExportNameResolver;
|
|
72
|
+
onError?: (error: HtmlHostClientError) => void;
|
|
73
|
+
frameworkName?: string;
|
|
74
|
+
eventName?: string;
|
|
75
|
+
}
|
|
76
|
+
type HtmlHostHydrationHandle = (() => void) & PromiseLike<void>;
|
|
77
|
+
type HtmlHostLazyHydrateFunction = (element: HTMLElement, props: Record<string, unknown>) => HtmlHostHydrationHandle;
|
|
78
|
+
type HtmlHostInitIslands<TController = unknown> = (hydrate: HydrateFunction, options?: InitIslandsOptions) => TController;
|
|
79
|
+
type InitHtmlHostInput<TRuntime = undefined> = CreateHtmlHostLazyHydrateInput<TRuntime> & {
|
|
80
|
+
initIslands: HtmlHostInitIslands;
|
|
81
|
+
options?: InitIslandsOptions;
|
|
82
|
+
};
|
|
83
|
+
declare function initHtmlHost<TRuntime = undefined>(input: InitHtmlHostInput<TRuntime>): ReturnType<InitHtmlHostInput<TRuntime>["initIslands"]>;
|
|
84
|
+
declare function createHtmlHostLazyHydrate<TRuntime = undefined>(input: CreateHtmlHostLazyHydrateInput<TRuntime>): HtmlHostLazyHydrateFunction;
|
|
85
|
+
declare function readHtmlHostSlot(element: Pick<HTMLElement, "dataset" | "innerHTML">): string | undefined;
|
|
86
|
+
//#endregion
|
|
87
|
+
export { HtmlHostClientHydrationError, createHtmlHostClientError, createHtmlHostLazyHydrate, initHtmlHost, readHtmlHostSlot, reportHtmlHostClientError };
|
|
88
|
+
export type { CreateHtmlHostLazyHydrateInput, HtmlHostClientAdapter, HtmlHostClientComponentValue, HtmlHostClientContext, HtmlHostClientDiagnosticCode, HtmlHostClientError, HtmlHostClientModuleLoader, HtmlHostClientModules, HtmlHostClientModuleValue, HtmlHostClientRenderer, HtmlHostClientRuntimeLoader, HtmlHostExportNameResolver, HtmlHostHydrationHandle, HtmlHostInitIslands, HtmlHostLazyHydrateFunction, HtmlHostModuleIdResolver, InitHtmlHostInput };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { n as HydrateFunction, r as InitIslandsOptions } from "./types.mjs";
|
|
2
|
+
//#region src/html-host-errors.d.ts
|
|
3
|
+
type HtmlHostClientDiagnosticCode = "missing-island-name" | "missing-module-id" | "unknown-module" | "module-load-failed" | "runtime-load-failed" | "missing-export" | "render-failed";
|
|
4
|
+
interface HtmlHostClientError {
|
|
5
|
+
code: HtmlHostClientDiagnosticCode;
|
|
6
|
+
message: string;
|
|
7
|
+
element: HTMLElement;
|
|
8
|
+
props: Record<string, unknown>;
|
|
9
|
+
componentName?: string;
|
|
10
|
+
moduleId?: string;
|
|
11
|
+
exportName?: string;
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
}
|
|
14
|
+
declare class HtmlHostClientHydrationError extends Error {
|
|
15
|
+
readonly diagnostic: HtmlHostClientError;
|
|
16
|
+
constructor(diagnostic: HtmlHostClientError);
|
|
17
|
+
}
|
|
18
|
+
interface HtmlHostClientErrorContext {
|
|
19
|
+
componentName?: string;
|
|
20
|
+
moduleId?: string;
|
|
21
|
+
exportName?: string;
|
|
22
|
+
cause?: unknown;
|
|
23
|
+
frameworkName?: string;
|
|
24
|
+
}
|
|
25
|
+
declare function reportHtmlHostClientError(input: {
|
|
26
|
+
onError?: (error: HtmlHostClientError) => void;
|
|
27
|
+
}, error: HtmlHostClientError, eventName?: string): void;
|
|
28
|
+
declare function createHtmlHostClientError(code: HtmlHostClientDiagnosticCode, element: HTMLElement, props: Record<string, unknown>, context?: HtmlHostClientErrorContext): HtmlHostClientError;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/html-host.d.ts
|
|
31
|
+
type HtmlHostClientComponentValue = unknown;
|
|
32
|
+
type HtmlHostClientModuleValue = unknown;
|
|
33
|
+
type HtmlHostClientModuleLoader<TModule = HtmlHostClientModuleValue> = () => TModule | PromiseLike<TModule>;
|
|
34
|
+
type HtmlHostClientModules<TModule = HtmlHostClientModuleValue> = Readonly<Record<string, HtmlHostClientModuleLoader<TModule>>> | ReadonlyMap<string, HtmlHostClientModuleLoader<TModule>>;
|
|
35
|
+
interface HtmlHostClientContext<TRuntime = undefined> {
|
|
36
|
+
component: unknown;
|
|
37
|
+
componentName: string;
|
|
38
|
+
element: HTMLElement;
|
|
39
|
+
exportName: string;
|
|
40
|
+
moduleExports: unknown;
|
|
41
|
+
moduleId: string;
|
|
42
|
+
props: Record<string, unknown>;
|
|
43
|
+
runtime: TRuntime | undefined;
|
|
44
|
+
slotHtml: string | undefined;
|
|
45
|
+
}
|
|
46
|
+
type HtmlHostClientRenderer<TRuntime = undefined> = (context: HtmlHostClientContext<TRuntime>) => void | (() => void) | PromiseLike<void | (() => void)>;
|
|
47
|
+
type HtmlHostClientRuntimeLoader<TRuntime = undefined> = () => TRuntime | PromiseLike<TRuntime>;
|
|
48
|
+
type HtmlHostModuleIdResolver = (element: HTMLElement, context: {
|
|
49
|
+
componentName: string;
|
|
50
|
+
props: Record<string, unknown>;
|
|
51
|
+
}) => string | undefined;
|
|
52
|
+
type HtmlHostExportNameResolver = (element: HTMLElement, context: {
|
|
53
|
+
componentName: string;
|
|
54
|
+
moduleId: string;
|
|
55
|
+
props: Record<string, unknown>;
|
|
56
|
+
}) => string | undefined;
|
|
57
|
+
interface HtmlHostClientAdapter<TRuntime = undefined> {
|
|
58
|
+
frameworkName?: string;
|
|
59
|
+
eventName?: string;
|
|
60
|
+
render: HtmlHostClientRenderer<TRuntime>;
|
|
61
|
+
loadRuntime?: HtmlHostClientRuntimeLoader<TRuntime>;
|
|
62
|
+
preserveElementContents?: boolean;
|
|
63
|
+
}
|
|
64
|
+
interface CreateHtmlHostLazyHydrateInput<TRuntime = undefined> {
|
|
65
|
+
modules: HtmlHostClientModules;
|
|
66
|
+
adapter?: HtmlHostClientAdapter<TRuntime>;
|
|
67
|
+
render?: HtmlHostClientRenderer<TRuntime>;
|
|
68
|
+
loadRuntime?: HtmlHostClientRuntimeLoader<TRuntime>;
|
|
69
|
+
preserveElementContents?: boolean;
|
|
70
|
+
resolveModuleId?: HtmlHostModuleIdResolver;
|
|
71
|
+
resolveExportName?: HtmlHostExportNameResolver;
|
|
72
|
+
onError?: (error: HtmlHostClientError) => void;
|
|
73
|
+
frameworkName?: string;
|
|
74
|
+
eventName?: string;
|
|
75
|
+
}
|
|
76
|
+
type HtmlHostHydrationHandle = (() => void) & PromiseLike<void>;
|
|
77
|
+
type HtmlHostLazyHydrateFunction = (element: HTMLElement, props: Record<string, unknown>) => HtmlHostHydrationHandle;
|
|
78
|
+
type HtmlHostInitIslands<TController = unknown> = (hydrate: HydrateFunction, options?: InitIslandsOptions) => TController;
|
|
79
|
+
type InitHtmlHostInput<TRuntime = undefined> = CreateHtmlHostLazyHydrateInput<TRuntime> & {
|
|
80
|
+
initIslands: HtmlHostInitIslands;
|
|
81
|
+
options?: InitIslandsOptions;
|
|
82
|
+
};
|
|
83
|
+
declare function initHtmlHost<TRuntime = undefined>(input: InitHtmlHostInput<TRuntime>): ReturnType<InitHtmlHostInput<TRuntime>["initIslands"]>;
|
|
84
|
+
declare function createHtmlHostLazyHydrate<TRuntime = undefined>(input: CreateHtmlHostLazyHydrateInput<TRuntime>): HtmlHostLazyHydrateFunction;
|
|
85
|
+
declare function readHtmlHostSlot(element: Pick<HTMLElement, "dataset" | "innerHTML">): string | undefined;
|
|
86
|
+
//#endregion
|
|
87
|
+
export { HtmlHostClientHydrationError, createHtmlHostClientError, createHtmlHostLazyHydrate, initHtmlHost, readHtmlHostSlot, reportHtmlHostClientError };
|
|
88
|
+
export type { CreateHtmlHostLazyHydrateInput, HtmlHostClientAdapter, HtmlHostClientComponentValue, HtmlHostClientContext, HtmlHostClientDiagnosticCode, HtmlHostClientError, HtmlHostClientModuleLoader, HtmlHostClientModules, HtmlHostClientModuleValue, HtmlHostClientRenderer, HtmlHostClientRuntimeLoader, HtmlHostExportNameResolver, HtmlHostHydrationHandle, HtmlHostInitIslands, HtmlHostLazyHydrateFunction, HtmlHostModuleIdResolver, InitHtmlHostInput };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as createHtmlHostClientError, i as HtmlHostClientHydrationError, n as initHtmlHost, o as reportHtmlHostClientError, r as readHtmlHostSlot, t as createHtmlHostLazyHydrate } from "./html-host2.mjs";
|
|
2
|
+
export { HtmlHostClientHydrationError, createHtmlHostClientError, createHtmlHostLazyHydrate, initHtmlHost, readHtmlHostSlot, reportHtmlHostClientError };
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
//#region src/html-host-errors.ts
|
|
2
|
+
var HtmlHostClientHydrationError = class extends Error {
|
|
3
|
+
diagnostic;
|
|
4
|
+
constructor(diagnostic) {
|
|
5
|
+
super(diagnostic.message);
|
|
6
|
+
this.name = "HtmlHostClientHydrationError";
|
|
7
|
+
this.diagnostic = diagnostic;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function reportHtmlHostClientError(input, error, eventName = "ox-content-html-host:error") {
|
|
11
|
+
error.element.classList?.add("ox-island-error");
|
|
12
|
+
error.element.dataset.oxError = error.message;
|
|
13
|
+
input.onError?.(error);
|
|
14
|
+
if (typeof CustomEvent === "function" && typeof error.element.dispatchEvent === "function") error.element.dispatchEvent(new CustomEvent(eventName, { detail: error }));
|
|
15
|
+
}
|
|
16
|
+
function createHtmlHostClientError(code, element, props, context = {}) {
|
|
17
|
+
return {
|
|
18
|
+
code,
|
|
19
|
+
element,
|
|
20
|
+
props,
|
|
21
|
+
componentName: context.componentName,
|
|
22
|
+
moduleId: context.moduleId,
|
|
23
|
+
exportName: context.exportName,
|
|
24
|
+
cause: context.cause,
|
|
25
|
+
message: clientErrorMessage(code, context)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function once(cleanup) {
|
|
29
|
+
let called = false;
|
|
30
|
+
return () => {
|
|
31
|
+
if (called) return;
|
|
32
|
+
called = true;
|
|
33
|
+
cleanup();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function clientErrorMessage(code, context) {
|
|
37
|
+
const framework = context.frameworkName?.trim() || "HTML host";
|
|
38
|
+
const island = `${framework} island`;
|
|
39
|
+
const component = context.componentName ? `${island} "${context.componentName}"` : island;
|
|
40
|
+
const reason = causeMessage(context.cause);
|
|
41
|
+
switch (code) {
|
|
42
|
+
case "missing-island-name": return `${island} element is missing data-ox-island.`;
|
|
43
|
+
case "missing-module-id": return `${component} is missing data-ox-module.`;
|
|
44
|
+
case "unknown-module": return `${component} references unknown module "${context.moduleId ?? ""}".`;
|
|
45
|
+
case "module-load-failed": return `${component} module "${context.moduleId ?? ""}" failed to load: ${reason}`;
|
|
46
|
+
case "runtime-load-failed": return `${framework} runtime failed to load: ${reason}`;
|
|
47
|
+
case "missing-export": return `${component} module "${context.moduleId ?? ""}" is missing export "${context.exportName ?? "default"}".`;
|
|
48
|
+
case "render-failed": return `${component} failed to render: ${reason}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function causeMessage(cause) {
|
|
52
|
+
if (cause == null) return "";
|
|
53
|
+
if (cause instanceof Error) return cause.message;
|
|
54
|
+
if (typeof cause === "string") return cause;
|
|
55
|
+
if (typeof cause === "number" || typeof cause === "boolean") return cause.toString();
|
|
56
|
+
try {
|
|
57
|
+
return JSON.stringify(cause);
|
|
58
|
+
} catch {
|
|
59
|
+
return Object.prototype.toString.call(cause);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/html-host.ts
|
|
64
|
+
const ISLAND_JSON_SCRIPT = /^\s*<script type="application\/json">[\s\S]*?<\/script>/;
|
|
65
|
+
function initHtmlHost(input) {
|
|
66
|
+
return input.initIslands(createHtmlHostLazyHydrate(input), input.options);
|
|
67
|
+
}
|
|
68
|
+
function createHtmlHostLazyHydrate(input) {
|
|
69
|
+
const render = resolveRenderer(input);
|
|
70
|
+
const loadRuntime = input.loadRuntime ?? input.adapter?.loadRuntime;
|
|
71
|
+
const preserveElementContents = input.preserveElementContents ?? input.adapter?.preserveElementContents ?? false;
|
|
72
|
+
const frameworkName = input.frameworkName ?? input.adapter?.frameworkName ?? "HTML host";
|
|
73
|
+
const eventName = input.eventName ?? input.adapter?.eventName ?? "ox-content-html-host:error";
|
|
74
|
+
const moduleCache = /* @__PURE__ */ new Map();
|
|
75
|
+
let runtimeCache;
|
|
76
|
+
return (element, props) => {
|
|
77
|
+
let disposed = false;
|
|
78
|
+
let disposeMounted;
|
|
79
|
+
const dispose = (() => {
|
|
80
|
+
if (disposed) return;
|
|
81
|
+
disposed = true;
|
|
82
|
+
disposeMounted?.();
|
|
83
|
+
disposeMounted = void 0;
|
|
84
|
+
});
|
|
85
|
+
const ready = (async () => {
|
|
86
|
+
const componentName = element.dataset.oxIsland;
|
|
87
|
+
if (!componentName) fail(input, eventName, frameworkName, "missing-island-name", element, props);
|
|
88
|
+
const moduleId = input.resolveModuleId?.(element, {
|
|
89
|
+
componentName,
|
|
90
|
+
props
|
|
91
|
+
}) ?? element.dataset.oxModule;
|
|
92
|
+
if (!moduleId) fail(input, eventName, frameworkName, "missing-module-id", element, props, { componentName });
|
|
93
|
+
if (!moduleLoader(input.modules, moduleId)) fail(input, eventName, frameworkName, "unknown-module", element, props, {
|
|
94
|
+
componentName,
|
|
95
|
+
moduleId
|
|
96
|
+
});
|
|
97
|
+
const exportName = input.resolveExportName?.(element, {
|
|
98
|
+
componentName,
|
|
99
|
+
moduleId,
|
|
100
|
+
props
|
|
101
|
+
}) ?? element.dataset.oxExport ?? "default";
|
|
102
|
+
const slotHtml = readHtmlHostSlot(element);
|
|
103
|
+
let moduleExports;
|
|
104
|
+
let runtime;
|
|
105
|
+
try {
|
|
106
|
+
moduleExports = await loadClientModule(input.modules, moduleId, moduleCache);
|
|
107
|
+
} catch (cause) {
|
|
108
|
+
if (!disposed) fail(input, eventName, frameworkName, "module-load-failed", element, props, {
|
|
109
|
+
componentName,
|
|
110
|
+
moduleId,
|
|
111
|
+
exportName,
|
|
112
|
+
cause
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (disposed) return;
|
|
117
|
+
try {
|
|
118
|
+
runtime = await loadHtmlHostRuntime(loadRuntime, () => runtimeCache, (pending) => {
|
|
119
|
+
runtimeCache = pending;
|
|
120
|
+
});
|
|
121
|
+
} catch (cause) {
|
|
122
|
+
if (!disposed) fail(input, eventName, frameworkName, "runtime-load-failed", element, props, {
|
|
123
|
+
componentName,
|
|
124
|
+
moduleId,
|
|
125
|
+
exportName,
|
|
126
|
+
cause
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (disposed) return;
|
|
131
|
+
const component = exportedValue(moduleExports, exportName);
|
|
132
|
+
if (component == null) fail(input, eventName, frameworkName, "missing-export", element, props, {
|
|
133
|
+
componentName,
|
|
134
|
+
moduleId,
|
|
135
|
+
exportName,
|
|
136
|
+
cause: /* @__PURE__ */ new Error(`Export "${exportName}" was not found.`)
|
|
137
|
+
});
|
|
138
|
+
if (!preserveElementContents) element.innerHTML = "";
|
|
139
|
+
try {
|
|
140
|
+
const cleanup = await render({
|
|
141
|
+
component,
|
|
142
|
+
componentName,
|
|
143
|
+
element,
|
|
144
|
+
exportName,
|
|
145
|
+
moduleExports,
|
|
146
|
+
moduleId,
|
|
147
|
+
props,
|
|
148
|
+
runtime,
|
|
149
|
+
slotHtml
|
|
150
|
+
});
|
|
151
|
+
disposeMounted = cleanup ? once(cleanup) : void 0;
|
|
152
|
+
if (disposed) {
|
|
153
|
+
disposeMounted?.();
|
|
154
|
+
disposeMounted = void 0;
|
|
155
|
+
}
|
|
156
|
+
} catch (cause) {
|
|
157
|
+
if (!disposed) fail(input, eventName, frameworkName, "render-failed", element, props, {
|
|
158
|
+
componentName,
|
|
159
|
+
moduleId,
|
|
160
|
+
exportName,
|
|
161
|
+
cause
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
})();
|
|
165
|
+
ready.catch(() => void 0);
|
|
166
|
+
Object.defineProperty(dispose, "then", { value: ready.then.bind(ready) });
|
|
167
|
+
return dispose;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function readHtmlHostSlot(element) {
|
|
171
|
+
const fromAttr = element.dataset.oxContent;
|
|
172
|
+
if (fromAttr) return fromAttr;
|
|
173
|
+
if (element.dataset.oxSsr === "true") return void 0;
|
|
174
|
+
return element.innerHTML.replace(ISLAND_JSON_SCRIPT, "") || void 0;
|
|
175
|
+
}
|
|
176
|
+
async function loadClientModule(modules, moduleId, cache) {
|
|
177
|
+
const cached = cache.get(moduleId);
|
|
178
|
+
if (cached) return cached;
|
|
179
|
+
const loader = moduleLoader(modules, moduleId);
|
|
180
|
+
if (!loader) throw new Error(`Unknown module "${moduleId}".`);
|
|
181
|
+
const pending = Promise.resolve().then(loader).catch((cause) => {
|
|
182
|
+
cache.delete(moduleId);
|
|
183
|
+
throw cause;
|
|
184
|
+
});
|
|
185
|
+
cache.set(moduleId, pending);
|
|
186
|
+
return pending;
|
|
187
|
+
}
|
|
188
|
+
async function loadHtmlHostRuntime(load, getCached, setCached) {
|
|
189
|
+
if (!load) return void 0;
|
|
190
|
+
const cached = getCached();
|
|
191
|
+
if (cached) return cached;
|
|
192
|
+
const pending = Promise.resolve().then(load).catch((cause) => {
|
|
193
|
+
setCached(void 0);
|
|
194
|
+
throw cause;
|
|
195
|
+
});
|
|
196
|
+
setCached(pending);
|
|
197
|
+
return pending;
|
|
198
|
+
}
|
|
199
|
+
function fail(input, eventName, frameworkName, code, element, props, context = {}) {
|
|
200
|
+
const error = createHtmlHostClientError(code, element, props, {
|
|
201
|
+
...context,
|
|
202
|
+
frameworkName
|
|
203
|
+
});
|
|
204
|
+
reportHtmlHostClientError(input, error, eventName);
|
|
205
|
+
throw new HtmlHostClientHydrationError(error);
|
|
206
|
+
}
|
|
207
|
+
function resolveRenderer(input) {
|
|
208
|
+
const render = input.render ?? input.adapter?.render;
|
|
209
|
+
if (render) return render;
|
|
210
|
+
throw new Error("initHtmlHost requires either render or adapter.render.");
|
|
211
|
+
}
|
|
212
|
+
function moduleLoader(modules, moduleId) {
|
|
213
|
+
return isReadonlyMap(modules) ? modules.get(moduleId) : modules[moduleId];
|
|
214
|
+
}
|
|
215
|
+
function isReadonlyMap(value) {
|
|
216
|
+
return typeof value.get === "function";
|
|
217
|
+
}
|
|
218
|
+
function exportedValue(moduleExports, exportName) {
|
|
219
|
+
if (exportName === "default" && typeof moduleExports === "function") return moduleExports;
|
|
220
|
+
if (!moduleExports || typeof moduleExports !== "object") return;
|
|
221
|
+
return moduleExports[exportName];
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
Object.defineProperty(exports, "HtmlHostClientHydrationError", {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
get: function() {
|
|
227
|
+
return HtmlHostClientHydrationError;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
Object.defineProperty(exports, "createHtmlHostClientError", {
|
|
231
|
+
enumerable: true,
|
|
232
|
+
get: function() {
|
|
233
|
+
return createHtmlHostClientError;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(exports, "createHtmlHostLazyHydrate", {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
get: function() {
|
|
239
|
+
return createHtmlHostLazyHydrate;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
Object.defineProperty(exports, "initHtmlHost", {
|
|
243
|
+
enumerable: true,
|
|
244
|
+
get: function() {
|
|
245
|
+
return initHtmlHost;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
Object.defineProperty(exports, "readHtmlHostSlot", {
|
|
249
|
+
enumerable: true,
|
|
250
|
+
get: function() {
|
|
251
|
+
return readHtmlHostSlot;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
Object.defineProperty(exports, "reportHtmlHostClientError", {
|
|
255
|
+
enumerable: true,
|
|
256
|
+
get: function() {
|
|
257
|
+
return reportHtmlHostClientError;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as reportHtmlHostClientError, S as createHtmlHostClientError, _ as initHtmlHost, a as HtmlHostClientModuleLoader, b as HtmlHostClientError, c as HtmlHostClientRenderer, d as HtmlHostHydrationHandle, f as HtmlHostInitIslands, g as createHtmlHostLazyHydrate, h as InitHtmlHostInput, i as HtmlHostClientContext, l as HtmlHostClientRuntimeLoader, m as HtmlHostModuleIdResolver, n as HtmlHostClientAdapter, o as HtmlHostClientModuleValue, p as HtmlHostLazyHydrateFunction, r as HtmlHostClientComponentValue, s as HtmlHostClientModules, t as CreateHtmlHostLazyHydrateInput, u as HtmlHostExportNameResolver, v as readHtmlHostSlot, x as HtmlHostClientHydrationError, y as HtmlHostClientDiagnosticCode } from "./html-host.cjs";
|
|
2
|
+
export { CreateHtmlHostLazyHydrateInput, HtmlHostClientAdapter, HtmlHostClientComponentValue, HtmlHostClientContext, type HtmlHostClientDiagnosticCode, type HtmlHostClientError, HtmlHostClientHydrationError, HtmlHostClientModuleLoader, HtmlHostClientModuleValue, HtmlHostClientModules, HtmlHostClientRenderer, HtmlHostClientRuntimeLoader, HtmlHostExportNameResolver, HtmlHostHydrationHandle, HtmlHostInitIslands, HtmlHostLazyHydrateFunction, HtmlHostModuleIdResolver, InitHtmlHostInput, createHtmlHostClientError, createHtmlHostLazyHydrate, initHtmlHost, readHtmlHostSlot, reportHtmlHostClientError };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as reportHtmlHostClientError, S as createHtmlHostClientError, _ as initHtmlHost, a as HtmlHostClientModuleLoader, b as HtmlHostClientError, c as HtmlHostClientRenderer, d as HtmlHostHydrationHandle, f as HtmlHostInitIslands, g as createHtmlHostLazyHydrate, h as InitHtmlHostInput, i as HtmlHostClientContext, l as HtmlHostClientRuntimeLoader, m as HtmlHostModuleIdResolver, n as HtmlHostClientAdapter, o as HtmlHostClientModuleValue, p as HtmlHostLazyHydrateFunction, r as HtmlHostClientComponentValue, s as HtmlHostClientModules, t as CreateHtmlHostLazyHydrateInput, u as HtmlHostExportNameResolver, v as readHtmlHostSlot, x as HtmlHostClientHydrationError, y as HtmlHostClientDiagnosticCode } from "./html-host.mjs";
|
|
2
|
+
export { CreateHtmlHostLazyHydrateInput, HtmlHostClientAdapter, HtmlHostClientComponentValue, HtmlHostClientContext, type HtmlHostClientDiagnosticCode, type HtmlHostClientError, HtmlHostClientHydrationError, HtmlHostClientModuleLoader, HtmlHostClientModuleValue, HtmlHostClientModules, HtmlHostClientRenderer, HtmlHostClientRuntimeLoader, HtmlHostExportNameResolver, HtmlHostHydrationHandle, HtmlHostInitIslands, HtmlHostLazyHydrateFunction, HtmlHostModuleIdResolver, InitHtmlHostInput, createHtmlHostClientError, createHtmlHostLazyHydrate, initHtmlHost, readHtmlHostSlot, reportHtmlHostClientError };
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
//#region src/html-host-errors.ts
|
|
2
|
+
var HtmlHostClientHydrationError = class extends Error {
|
|
3
|
+
diagnostic;
|
|
4
|
+
constructor(diagnostic) {
|
|
5
|
+
super(diagnostic.message);
|
|
6
|
+
this.name = "HtmlHostClientHydrationError";
|
|
7
|
+
this.diagnostic = diagnostic;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function reportHtmlHostClientError(input, error, eventName = "ox-content-html-host:error") {
|
|
11
|
+
error.element.classList?.add("ox-island-error");
|
|
12
|
+
error.element.dataset.oxError = error.message;
|
|
13
|
+
input.onError?.(error);
|
|
14
|
+
if (typeof CustomEvent === "function" && typeof error.element.dispatchEvent === "function") error.element.dispatchEvent(new CustomEvent(eventName, { detail: error }));
|
|
15
|
+
}
|
|
16
|
+
function createHtmlHostClientError(code, element, props, context = {}) {
|
|
17
|
+
return {
|
|
18
|
+
code,
|
|
19
|
+
element,
|
|
20
|
+
props,
|
|
21
|
+
componentName: context.componentName,
|
|
22
|
+
moduleId: context.moduleId,
|
|
23
|
+
exportName: context.exportName,
|
|
24
|
+
cause: context.cause,
|
|
25
|
+
message: clientErrorMessage(code, context)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function once(cleanup) {
|
|
29
|
+
let called = false;
|
|
30
|
+
return () => {
|
|
31
|
+
if (called) return;
|
|
32
|
+
called = true;
|
|
33
|
+
cleanup();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function clientErrorMessage(code, context) {
|
|
37
|
+
const framework = context.frameworkName?.trim() || "HTML host";
|
|
38
|
+
const island = `${framework} island`;
|
|
39
|
+
const component = context.componentName ? `${island} "${context.componentName}"` : island;
|
|
40
|
+
const reason = causeMessage(context.cause);
|
|
41
|
+
switch (code) {
|
|
42
|
+
case "missing-island-name": return `${island} element is missing data-ox-island.`;
|
|
43
|
+
case "missing-module-id": return `${component} is missing data-ox-module.`;
|
|
44
|
+
case "unknown-module": return `${component} references unknown module "${context.moduleId ?? ""}".`;
|
|
45
|
+
case "module-load-failed": return `${component} module "${context.moduleId ?? ""}" failed to load: ${reason}`;
|
|
46
|
+
case "runtime-load-failed": return `${framework} runtime failed to load: ${reason}`;
|
|
47
|
+
case "missing-export": return `${component} module "${context.moduleId ?? ""}" is missing export "${context.exportName ?? "default"}".`;
|
|
48
|
+
case "render-failed": return `${component} failed to render: ${reason}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function causeMessage(cause) {
|
|
52
|
+
if (cause == null) return "";
|
|
53
|
+
if (cause instanceof Error) return cause.message;
|
|
54
|
+
if (typeof cause === "string") return cause;
|
|
55
|
+
if (typeof cause === "number" || typeof cause === "boolean") return cause.toString();
|
|
56
|
+
try {
|
|
57
|
+
return JSON.stringify(cause);
|
|
58
|
+
} catch {
|
|
59
|
+
return Object.prototype.toString.call(cause);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/html-host.ts
|
|
64
|
+
const ISLAND_JSON_SCRIPT = /^\s*<script type="application\/json">[\s\S]*?<\/script>/;
|
|
65
|
+
function initHtmlHost(input) {
|
|
66
|
+
return input.initIslands(createHtmlHostLazyHydrate(input), input.options);
|
|
67
|
+
}
|
|
68
|
+
function createHtmlHostLazyHydrate(input) {
|
|
69
|
+
const render = resolveRenderer(input);
|
|
70
|
+
const loadRuntime = input.loadRuntime ?? input.adapter?.loadRuntime;
|
|
71
|
+
const preserveElementContents = input.preserveElementContents ?? input.adapter?.preserveElementContents ?? false;
|
|
72
|
+
const frameworkName = input.frameworkName ?? input.adapter?.frameworkName ?? "HTML host";
|
|
73
|
+
const eventName = input.eventName ?? input.adapter?.eventName ?? "ox-content-html-host:error";
|
|
74
|
+
const moduleCache = /* @__PURE__ */ new Map();
|
|
75
|
+
let runtimeCache;
|
|
76
|
+
return (element, props) => {
|
|
77
|
+
let disposed = false;
|
|
78
|
+
let disposeMounted;
|
|
79
|
+
const dispose = (() => {
|
|
80
|
+
if (disposed) return;
|
|
81
|
+
disposed = true;
|
|
82
|
+
disposeMounted?.();
|
|
83
|
+
disposeMounted = void 0;
|
|
84
|
+
});
|
|
85
|
+
const ready = (async () => {
|
|
86
|
+
const componentName = element.dataset.oxIsland;
|
|
87
|
+
if (!componentName) fail(input, eventName, frameworkName, "missing-island-name", element, props);
|
|
88
|
+
const moduleId = input.resolveModuleId?.(element, {
|
|
89
|
+
componentName,
|
|
90
|
+
props
|
|
91
|
+
}) ?? element.dataset.oxModule;
|
|
92
|
+
if (!moduleId) fail(input, eventName, frameworkName, "missing-module-id", element, props, { componentName });
|
|
93
|
+
if (!moduleLoader(input.modules, moduleId)) fail(input, eventName, frameworkName, "unknown-module", element, props, {
|
|
94
|
+
componentName,
|
|
95
|
+
moduleId
|
|
96
|
+
});
|
|
97
|
+
const exportName = input.resolveExportName?.(element, {
|
|
98
|
+
componentName,
|
|
99
|
+
moduleId,
|
|
100
|
+
props
|
|
101
|
+
}) ?? element.dataset.oxExport ?? "default";
|
|
102
|
+
const slotHtml = readHtmlHostSlot(element);
|
|
103
|
+
let moduleExports;
|
|
104
|
+
let runtime;
|
|
105
|
+
try {
|
|
106
|
+
moduleExports = await loadClientModule(input.modules, moduleId, moduleCache);
|
|
107
|
+
} catch (cause) {
|
|
108
|
+
if (!disposed) fail(input, eventName, frameworkName, "module-load-failed", element, props, {
|
|
109
|
+
componentName,
|
|
110
|
+
moduleId,
|
|
111
|
+
exportName,
|
|
112
|
+
cause
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (disposed) return;
|
|
117
|
+
try {
|
|
118
|
+
runtime = await loadHtmlHostRuntime(loadRuntime, () => runtimeCache, (pending) => {
|
|
119
|
+
runtimeCache = pending;
|
|
120
|
+
});
|
|
121
|
+
} catch (cause) {
|
|
122
|
+
if (!disposed) fail(input, eventName, frameworkName, "runtime-load-failed", element, props, {
|
|
123
|
+
componentName,
|
|
124
|
+
moduleId,
|
|
125
|
+
exportName,
|
|
126
|
+
cause
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (disposed) return;
|
|
131
|
+
const component = exportedValue(moduleExports, exportName);
|
|
132
|
+
if (component == null) fail(input, eventName, frameworkName, "missing-export", element, props, {
|
|
133
|
+
componentName,
|
|
134
|
+
moduleId,
|
|
135
|
+
exportName,
|
|
136
|
+
cause: /* @__PURE__ */ new Error(`Export "${exportName}" was not found.`)
|
|
137
|
+
});
|
|
138
|
+
if (!preserveElementContents) element.innerHTML = "";
|
|
139
|
+
try {
|
|
140
|
+
const cleanup = await render({
|
|
141
|
+
component,
|
|
142
|
+
componentName,
|
|
143
|
+
element,
|
|
144
|
+
exportName,
|
|
145
|
+
moduleExports,
|
|
146
|
+
moduleId,
|
|
147
|
+
props,
|
|
148
|
+
runtime,
|
|
149
|
+
slotHtml
|
|
150
|
+
});
|
|
151
|
+
disposeMounted = cleanup ? once(cleanup) : void 0;
|
|
152
|
+
if (disposed) {
|
|
153
|
+
disposeMounted?.();
|
|
154
|
+
disposeMounted = void 0;
|
|
155
|
+
}
|
|
156
|
+
} catch (cause) {
|
|
157
|
+
if (!disposed) fail(input, eventName, frameworkName, "render-failed", element, props, {
|
|
158
|
+
componentName,
|
|
159
|
+
moduleId,
|
|
160
|
+
exportName,
|
|
161
|
+
cause
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
})();
|
|
165
|
+
ready.catch(() => void 0);
|
|
166
|
+
Object.defineProperty(dispose, "then", { value: ready.then.bind(ready) });
|
|
167
|
+
return dispose;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function readHtmlHostSlot(element) {
|
|
171
|
+
const fromAttr = element.dataset.oxContent;
|
|
172
|
+
if (fromAttr) return fromAttr;
|
|
173
|
+
if (element.dataset.oxSsr === "true") return void 0;
|
|
174
|
+
return element.innerHTML.replace(ISLAND_JSON_SCRIPT, "") || void 0;
|
|
175
|
+
}
|
|
176
|
+
async function loadClientModule(modules, moduleId, cache) {
|
|
177
|
+
const cached = cache.get(moduleId);
|
|
178
|
+
if (cached) return cached;
|
|
179
|
+
const loader = moduleLoader(modules, moduleId);
|
|
180
|
+
if (!loader) throw new Error(`Unknown module "${moduleId}".`);
|
|
181
|
+
const pending = Promise.resolve().then(loader).catch((cause) => {
|
|
182
|
+
cache.delete(moduleId);
|
|
183
|
+
throw cause;
|
|
184
|
+
});
|
|
185
|
+
cache.set(moduleId, pending);
|
|
186
|
+
return pending;
|
|
187
|
+
}
|
|
188
|
+
async function loadHtmlHostRuntime(load, getCached, setCached) {
|
|
189
|
+
if (!load) return void 0;
|
|
190
|
+
const cached = getCached();
|
|
191
|
+
if (cached) return cached;
|
|
192
|
+
const pending = Promise.resolve().then(load).catch((cause) => {
|
|
193
|
+
setCached(void 0);
|
|
194
|
+
throw cause;
|
|
195
|
+
});
|
|
196
|
+
setCached(pending);
|
|
197
|
+
return pending;
|
|
198
|
+
}
|
|
199
|
+
function fail(input, eventName, frameworkName, code, element, props, context = {}) {
|
|
200
|
+
const error = createHtmlHostClientError(code, element, props, {
|
|
201
|
+
...context,
|
|
202
|
+
frameworkName
|
|
203
|
+
});
|
|
204
|
+
reportHtmlHostClientError(input, error, eventName);
|
|
205
|
+
throw new HtmlHostClientHydrationError(error);
|
|
206
|
+
}
|
|
207
|
+
function resolveRenderer(input) {
|
|
208
|
+
const render = input.render ?? input.adapter?.render;
|
|
209
|
+
if (render) return render;
|
|
210
|
+
throw new Error("initHtmlHost requires either render or adapter.render.");
|
|
211
|
+
}
|
|
212
|
+
function moduleLoader(modules, moduleId) {
|
|
213
|
+
return isReadonlyMap(modules) ? modules.get(moduleId) : modules[moduleId];
|
|
214
|
+
}
|
|
215
|
+
function isReadonlyMap(value) {
|
|
216
|
+
return typeof value.get === "function";
|
|
217
|
+
}
|
|
218
|
+
function exportedValue(moduleExports, exportName) {
|
|
219
|
+
if (exportName === "default" && typeof moduleExports === "function") return moduleExports;
|
|
220
|
+
if (!moduleExports || typeof moduleExports !== "object") return;
|
|
221
|
+
return moduleExports[exportName];
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
export { createHtmlHostClientError as a, HtmlHostClientHydrationError as i, initHtmlHost as n, reportHtmlHostClientError as o, readHtmlHostSlot as r, createHtmlHostLazyHydrate as t };
|
|
225
|
+
|
|
226
|
+
//# sourceMappingURL=html-host2.mjs.map
|