resuxjs 0.4.0 → 0.5.0-beta.1
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/README.md +1 -1
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/compiler/implementation.js +11 -2
- package/dist/compiler/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/runtime/index.d.ts +10 -2
- package/dist/runtime/index.js +353 -6
- package/dist/runtime/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ import { watch, watchEffect } from "./reactivity/watch.js";
|
|
|
6
6
|
import { nextTick } from "./reactivity/scheduler.js";
|
|
7
7
|
import { ResuxViewTransition, ResuxViewTransitionOptions } from "./runtime/view-transitions/types.js";
|
|
8
8
|
import { useViewTransition } from "./runtime/view-transitions/transition.js";
|
|
9
|
-
import { AsyncDataError, AsyncDataHandlerContext, AsyncDataResource, AsyncResuxRenderer, AwaitedAsyncDataResource, ClientEnhancementContext, ClientEnhancementSetup, ClientEnhancementTrigger, ClientPluginManifestRecord, ClientRouteMiddlewareManifestRecord, ClientRuntimeSourceOptions, ComponentDefinition, ComponentStyle, DeviceInfo, ElementTemplateNode, EventHandler, EventHandlerEvent, ForDirective, HeadAttributePrimitive, HeadAttributeStyle, HeadAttributeValue, HeadAttributes, HeadEntry, HeadInput, HeadTextContentStyle, HtmlDirective, IfDirective, InterpolationTemplateNode, JsonValue, PackageAdapterContext, PackageAdapterDefinition, PageMeta, RenderAppOptions, RenderDocumentOptions, RenderHtmlContext, RenderResult, ResuxAppInjections, ResuxAppLike, ResuxAppProvides, ResuxClientBootMode, ResuxClientBootPlan, ResuxClientPackageImportRegistry, ResuxConfigInput, ResuxDeployOptions, ResuxDeployTarget, ResuxError, ResuxImageBuilder, ResuxImageCacheInput, ResuxImageConfig, ResuxImageFit, ResuxImageModifiers, ResuxImageProviderConfig, ResuxLazyPackageLoader, ResuxLazyPackageOptions, ResuxModule, ResuxModuleContext, ResuxPackageCssMap, ResuxPackageMode, ResuxPackageModeMap, ResuxPackagesConfig, ResuxPayload, ResuxPlugin, ResuxRouteMiddleware, ResuxRouter, ResuxSupportMode, RouteContext, RouteMiddlewareResult, RouteRecord, RuntimeConfig, SeoMetaInput, SeoMetaValue, SerializedAsyncData, SerializedScope, ServerMiddleware, ServerMiddlewareResult, SetupContext, TemplateAttribute, TemplateEvent, TemplateNode, TextTemplateNode, UseClientEnhancementOptions, UseResuxImageOptions, abortNavigation, clearError, createError, createServerSetupContext, defineClientEnhancement, defineClientOnlyPackage, defineComponent, defineEventHandler, defineLazyPackage, definePackageAdapter, defineResuxConfig, defineResuxModule, defineResuxPlugin, defineResuxRouteMiddleware, defineServerMiddleware, disposeClientEnhancements, evaluateExpression, eventHandler, getClientEnhancement, getClientRuntimeBootPlan, getClientRuntimeSource, getQuery, hasClientEnhancement, navigateTo, parseUserAgent, readBody, renderApp, renderAppAsync, renderClientPatches, renderDocument, renderDocumentAsync, renderTemplateNodesAsync, scanClientEnhancements, setHeader, shouldLoadClientRuntime, showError, useClientEnhancement, useClientPackage, useDevice, useError, useLazyPackage, usePackageReady, useResuxApp, useResuxImage, useRoute, useRouter, useRuntimeConfig } from "./runtime/index.js";
|
|
10
|
-
export { AsyncDataError, AsyncDataHandlerContext, AsyncDataResource, AsyncResuxRenderer, AwaitedAsyncDataResource, ClientEnhancementContext, ClientEnhancementSetup, ClientEnhancementTrigger, ClientPluginManifestRecord, ClientRouteMiddlewareManifestRecord, ClientRuntimeSourceOptions, ComponentDefinition, ComponentStyle, type ComputedRef, DeviceInfo, ElementTemplateNode, EventHandler, EventHandlerEvent, ForDirective, HeadAttributePrimitive, HeadAttributeStyle, HeadAttributeValue, HeadAttributes, HeadEntry, HeadInput, HeadTextContentStyle, HtmlDirective, IfDirective, InterpolationTemplateNode, JsonValue, type MaybeRef, type MaybeRefOrGetter, PackageAdapterContext, PackageAdapterDefinition, PageMeta, type ReactiveEffectOptions, type ReactiveEffectRunner, type Ref, RenderAppOptions, RenderDocumentOptions, RenderHtmlContext, RenderResult, ResuxAppInjections, ResuxAppLike, ResuxAppProvides, ResuxClientBootMode, ResuxClientBootPlan, ResuxClientPackageImportRegistry, ResuxConfigInput, ResuxDeployOptions, ResuxDeployTarget, ResuxError, ResuxImageBuilder, ResuxImageCacheInput, ResuxImageConfig, ResuxImageFit, ResuxImageModifiers, ResuxImageProviderConfig, ResuxLazyPackageLoader, ResuxLazyPackageOptions, ResuxModule, ResuxModuleContext, ResuxPackageCssMap, ResuxPackageMode, ResuxPackageModeMap, ResuxPackagesConfig, ResuxPayload, ResuxPlugin, ResuxRouteMiddleware, ResuxRouter, ResuxSupportMode, type ResuxViewTransition, type ResuxViewTransitionOptions, RouteContext, RouteMiddlewareResult, RouteRecord, RuntimeConfig, SeoMetaInput, SeoMetaValue, SerializedAsyncData, SerializedScope, ServerMiddleware, ServerMiddlewareResult, SetupContext, TemplateAttribute, TemplateEvent, TemplateNode, TextTemplateNode, UseClientEnhancementOptions, UseResuxImageOptions, type WatchCallback, type WatchOptions, type WatchSource, type WatchStopHandle, abortNavigation, clearError, computed, createError, createServerSetupContext, defineClientEnhancement, defineClientOnlyPackage, defineComponent, defineEventHandler, defineLazyPackage, definePackageAdapter, defineResuxConfig, defineResuxModule, defineResuxPlugin, defineResuxRouteMiddleware, defineServerMiddleware, disposeClientEnhancements, evaluateExpression, eventHandler, getClientEnhancement, getClientRuntimeBootPlan, getClientRuntimeSource, getQuery, hasClientEnhancement, isReactive, isReadonly, isRef, navigateTo, nextTick, parseUserAgent, reactive, readBody, readonly, ref, renderApp, renderAppAsync, renderClientPatches, renderDocument, renderDocumentAsync, renderTemplateNodesAsync, scanClientEnhancements, setHeader, shouldLoadClientRuntime, showError, toRef, toRefs, unref, useClientEnhancement, useClientPackage, useDevice, useError, useLazyPackage, usePackageReady, useResuxApp, useResuxImage, useRoute, useRouter, useRuntimeConfig, useViewTransition, watch, watchEffect };
|
|
9
|
+
import { AsyncDataError, AsyncDataHandlerContext, AsyncDataResource, AsyncResuxRenderer, AwaitedAsyncDataResource, ClientEnhancementContext, ClientEnhancementSetup, ClientEnhancementTrigger, ClientPluginManifestRecord, ClientRouteMiddlewareManifestRecord, ClientRuntimeSourceOptions, ComponentDefinition, ComponentEmitBinding, ComponentStyle, DeviceInfo, ElementTemplateNode, EventHandler, EventHandlerEvent, ForDirective, HeadAttributePrimitive, HeadAttributeStyle, HeadAttributeValue, HeadAttributes, HeadEntry, HeadInput, HeadTextContentStyle, HtmlDirective, IfDirective, InterpolationTemplateNode, JsonValue, PackageAdapterContext, PackageAdapterDefinition, PageMeta, RenderAppOptions, RenderDocumentOptions, RenderHtmlContext, RenderResult, ResuxAppInjections, ResuxAppLike, ResuxAppProvides, ResuxClientBootMode, ResuxClientBootPlan, ResuxClientPackageImportRegistry, ResuxConfigInput, ResuxDeployOptions, ResuxDeployTarget, ResuxError, ResuxImageBuilder, ResuxImageCacheInput, ResuxImageConfig, ResuxImageFit, ResuxImageModifiers, ResuxImageProviderConfig, ResuxLazyPackageLoader, ResuxLazyPackageOptions, ResuxModule, ResuxModuleContext, ResuxPackageCssMap, ResuxPackageMode, ResuxPackageModeMap, ResuxPackagesConfig, ResuxPayload, ResuxPlugin, ResuxRouteMiddleware, ResuxRouter, ResuxSupportMode, RouteContext, RouteMiddlewareResult, RouteRecord, RuntimeConfig, SeoMetaInput, SeoMetaValue, SerializedAsyncData, SerializedScope, ServerMiddleware, ServerMiddlewareResult, SetupContext, TemplateAttribute, TemplateEvent, TemplateNode, TextTemplateNode, UseClientEnhancementOptions, UseResuxImageOptions, abortNavigation, clearError, createError, createServerSetupContext, defineClientEnhancement, defineClientOnlyPackage, defineComponent, defineEventHandler, defineLazyPackage, definePackageAdapter, defineResuxConfig, defineResuxModule, defineResuxPlugin, defineResuxRouteMiddleware, defineServerMiddleware, disposeClientEnhancements, evaluateExpression, eventHandler, getClientEnhancement, getClientRuntimeBootPlan, getClientRuntimeSource, getQuery, hasClientEnhancement, navigateTo, parseUserAgent, readBody, renderApp, renderAppAsync, renderClientPatches, renderDocument, renderDocumentAsync, renderTemplateNodesAsync, scanClientEnhancements, setHeader, shouldLoadClientRuntime, showError, useClientEnhancement, useClientPackage, useDevice, useError, useLazyPackage, usePackageReady, useResuxApp, useResuxImage, useRoute, useRouter, useRuntimeConfig } from "./runtime/index.js";
|
|
10
|
+
export { AsyncDataError, AsyncDataHandlerContext, AsyncDataResource, AsyncResuxRenderer, AwaitedAsyncDataResource, ClientEnhancementContext, ClientEnhancementSetup, ClientEnhancementTrigger, ClientPluginManifestRecord, ClientRouteMiddlewareManifestRecord, ClientRuntimeSourceOptions, ComponentDefinition, ComponentEmitBinding, ComponentStyle, type ComputedRef, DeviceInfo, ElementTemplateNode, EventHandler, EventHandlerEvent, ForDirective, HeadAttributePrimitive, HeadAttributeStyle, HeadAttributeValue, HeadAttributes, HeadEntry, HeadInput, HeadTextContentStyle, HtmlDirective, IfDirective, InterpolationTemplateNode, JsonValue, type MaybeRef, type MaybeRefOrGetter, PackageAdapterContext, PackageAdapterDefinition, PageMeta, type ReactiveEffectOptions, type ReactiveEffectRunner, type Ref, RenderAppOptions, RenderDocumentOptions, RenderHtmlContext, RenderResult, ResuxAppInjections, ResuxAppLike, ResuxAppProvides, ResuxClientBootMode, ResuxClientBootPlan, ResuxClientPackageImportRegistry, ResuxConfigInput, ResuxDeployOptions, ResuxDeployTarget, ResuxError, ResuxImageBuilder, ResuxImageCacheInput, ResuxImageConfig, ResuxImageFit, ResuxImageModifiers, ResuxImageProviderConfig, ResuxLazyPackageLoader, ResuxLazyPackageOptions, ResuxModule, ResuxModuleContext, ResuxPackageCssMap, ResuxPackageMode, ResuxPackageModeMap, ResuxPackagesConfig, ResuxPayload, ResuxPlugin, ResuxRouteMiddleware, ResuxRouter, ResuxSupportMode, type ResuxViewTransition, type ResuxViewTransitionOptions, RouteContext, RouteMiddlewareResult, RouteRecord, RuntimeConfig, SeoMetaInput, SeoMetaValue, SerializedAsyncData, SerializedScope, ServerMiddleware, ServerMiddlewareResult, SetupContext, TemplateAttribute, TemplateEvent, TemplateNode, TextTemplateNode, UseClientEnhancementOptions, UseResuxImageOptions, type WatchCallback, type WatchOptions, type WatchSource, type WatchStopHandle, abortNavigation, clearError, computed, createError, createServerSetupContext, defineClientEnhancement, defineClientOnlyPackage, defineComponent, defineEventHandler, defineLazyPackage, definePackageAdapter, defineResuxConfig, defineResuxModule, defineResuxPlugin, defineResuxRouteMiddleware, defineServerMiddleware, disposeClientEnhancements, evaluateExpression, eventHandler, getClientEnhancement, getClientRuntimeBootPlan, getClientRuntimeSource, getQuery, hasClientEnhancement, isReactive, isReadonly, isRef, navigateTo, nextTick, parseUserAgent, reactive, readBody, readonly, ref, renderApp, renderAppAsync, renderClientPatches, renderDocument, renderDocumentAsync, renderTemplateNodesAsync, scanClientEnhancements, setHeader, shouldLoadClientRuntime, showError, toRef, toRefs, unref, useClientEnhancement, useClientPackage, useDevice, useError, useLazyPackage, usePackageReady, useResuxApp, useResuxImage, useRoute, useRouter, useRuntimeConfig, useViewTransition, watch, watchEffect };
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -502,6 +502,7 @@ export interface SerializedScope {
|
|
|
502
502
|
props?: Record<string, JsonValue>;
|
|
503
503
|
state: Record<string, JsonValue>;
|
|
504
504
|
globalStateKeys?: string[];
|
|
505
|
+
emits?: Record<string, ComponentEmitBinding>;
|
|
505
506
|
asyncData: Record<string, SerializedAsyncData>;
|
|
506
507
|
}
|
|
507
508
|
export interface SerializedAsyncData {
|
|
@@ -514,6 +515,8 @@ export interface ResuxPayload {
|
|
|
514
515
|
scopes: Record<string, SerializedScope>;
|
|
515
516
|
globalState?: Record<string, JsonValue>;
|
|
516
517
|
modules: Record<string, string>;
|
|
518
|
+
/** Component tag -> module id for components that client-rendered blocks (v-if/v-for) may need to create. */
|
|
519
|
+
componentIds?: Record<string, string>;
|
|
517
520
|
vueIslands?: Record<string, string>;
|
|
518
521
|
config?: RuntimeConfig;
|
|
519
522
|
plugins?: ClientPluginManifestRecord[];
|
|
@@ -566,9 +569,13 @@ export interface RenderDocumentOptions {
|
|
|
566
569
|
callHook(name: string, ...args: any[]): Promise<void> | void;
|
|
567
570
|
};
|
|
568
571
|
}
|
|
572
|
+
export interface ComponentEmitBinding {
|
|
573
|
+
handler: string;
|
|
574
|
+
locals?: Record<string, JsonValue>;
|
|
575
|
+
}
|
|
569
576
|
type ComponentProps = Record<string, unknown>;
|
|
570
577
|
type AsyncRenderSlot = (suppressTeleportReservations?: boolean) => Promise<string>;
|
|
571
|
-
type AsyncRenderComponent = (component: ComponentDefinition, props?: ComponentProps, renderSlot?: AsyncRenderSlot, suppressTeleportReservations?: boolean) => Promise<string>;
|
|
578
|
+
type AsyncRenderComponent = (component: ComponentDefinition, props?: ComponentProps, renderSlot?: AsyncRenderSlot, suppressTeleportReservations?: boolean, emits?: Record<string, ComponentEmitBinding>) => Promise<string>;
|
|
572
579
|
interface RenderTemplateContext {
|
|
573
580
|
scope: Record<string, unknown>;
|
|
574
581
|
scopeId: string;
|
|
@@ -671,11 +678,12 @@ export declare class AsyncResuxRenderer {
|
|
|
671
678
|
private readonly scopes;
|
|
672
679
|
private readonly globalStateRefs;
|
|
673
680
|
private readonly styleIds;
|
|
681
|
+
private readonly renderedDefinitions;
|
|
674
682
|
private readonly teleportEntries;
|
|
675
683
|
readonly headEntries: HeadEntry[];
|
|
676
684
|
readonly resuxApp: ResuxAppLike;
|
|
677
685
|
constructor(route: RouteContext, components: Record<string, ComponentDefinition>, modules: Record<string, string>, vueIslands?: Record<string, string>, layouts?: Record<string, ComponentDefinition>, pageMeta?: PageMeta, runtimeConfig?: RuntimeConfig);
|
|
678
|
-
renderComponent(definition: ComponentDefinition, renderPage?: AsyncRenderSlot, renderSlot?: AsyncRenderSlot, props?: ComponentProps, suppressTeleportReservations?: boolean): Promise<string>;
|
|
686
|
+
renderComponent(definition: ComponentDefinition, renderPage?: AsyncRenderSlot, renderSlot?: AsyncRenderSlot, props?: ComponentProps, suppressTeleportReservations?: boolean, emits?: Record<string, ComponentEmitBinding>): Promise<string>;
|
|
679
687
|
private reserveTeleport;
|
|
680
688
|
private commitTeleport;
|
|
681
689
|
createTeleports(): Record<string, string>;
|
package/dist/runtime/index.js
CHANGED
|
@@ -2214,6 +2214,64 @@ function renderTemplateNode(node, context, locals) {
|
|
|
2214
2214
|
}
|
|
2215
2215
|
return renderElement(node, context, locals);
|
|
2216
2216
|
}
|
|
2217
|
+
/**
|
|
2218
|
+
* Maps component tags used inside v-if/v-for blocks (transitively) to their module ids, so the browser
|
|
2219
|
+
* can create those components lazily when a block re-renders. Pages without such components get nothing.
|
|
2220
|
+
*/
|
|
2221
|
+
function withClientComponentIds(ids) {
|
|
2222
|
+
return ids ? { componentIds: ids } : {};
|
|
2223
|
+
}
|
|
2224
|
+
function resolveDynamicComponentNode(node, scope, locals, components) {
|
|
2225
|
+
const isAttr = node.attrs.find((attr) => attr.name === "is");
|
|
2226
|
+
if (!isAttr) throw new Error("<component> needs an `is` attribute with a registered component name.");
|
|
2227
|
+
const value = isAttr.kind === "static" ? isAttr.value : evaluateExpression(isAttr.value, scope, locals);
|
|
2228
|
+
if (typeof value !== "string" || value.length === 0) throw new Error("<component :is> needs the name of a registered component as a string. Component objects are not supported.");
|
|
2229
|
+
if (!resolveComponentDefinition(value, components)) throw new Error(`Unknown component <${value}> in <component :is>. Use the name of a registered or auto-discovered component.`);
|
|
2230
|
+
return {
|
|
2231
|
+
...node,
|
|
2232
|
+
tag: value,
|
|
2233
|
+
attrs: node.attrs.filter((attr) => attr !== isAttr)
|
|
2234
|
+
};
|
|
2235
|
+
}
|
|
2236
|
+
function collectClientBlockComponentIds(rendered, registries) {
|
|
2237
|
+
const registry = {};
|
|
2238
|
+
for (const entries of registries) for (const [name, definition] of Object.entries(entries ?? {})) if (!(name in registry)) registry[name] = definition;
|
|
2239
|
+
const result = {};
|
|
2240
|
+
const scanned = /* @__PURE__ */ new Set();
|
|
2241
|
+
const scan = (nodes, inBlock) => {
|
|
2242
|
+
for (const node of nodes) {
|
|
2243
|
+
if (node.type !== "element") continue;
|
|
2244
|
+
const blockHere = inBlock || Boolean(node.for || node.if);
|
|
2245
|
+
if (blockHere && node.tag === "component") {
|
|
2246
|
+
const isAttr = node.attrs.find((attr) => attr.name === "is");
|
|
2247
|
+
const names = isAttr?.kind === "static" ? [isAttr.value] : Object.keys(registry);
|
|
2248
|
+
for (const name of names) {
|
|
2249
|
+
if (typeof name !== "string" || Object.hasOwn(result, name)) continue;
|
|
2250
|
+
const target = resolveComponentDefinition(name, registry);
|
|
2251
|
+
if (!target?.id) continue;
|
|
2252
|
+
result[name] = target.id;
|
|
2253
|
+
if (!scanned.has(target.id)) {
|
|
2254
|
+
scanned.add(target.id);
|
|
2255
|
+
scan(target.template ?? [], true);
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
if (blockHere && isComponentTag(node.tag) && !Object.hasOwn(result, node.tag)) {
|
|
2260
|
+
const target = resolveComponentDefinition(node.tag, registry);
|
|
2261
|
+
if (target?.id) {
|
|
2262
|
+
result[node.tag] = target.id;
|
|
2263
|
+
if (!scanned.has(target.id)) {
|
|
2264
|
+
scanned.add(target.id);
|
|
2265
|
+
scan(target.template ?? [], true);
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
scan(node.children, blockHere);
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
for (const definition of rendered) scan(definition.template ?? [], false);
|
|
2273
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
2274
|
+
}
|
|
2217
2275
|
function resolveComponentDefinition(tag, components) {
|
|
2218
2276
|
if (!components) return;
|
|
2219
2277
|
if (components[tag]) return components[tag];
|
|
@@ -2360,6 +2418,7 @@ function renderTeleportBoundary(state, children, reservation) {
|
|
|
2360
2418
|
return state.disabled ? `${source}${children}${end}` : `${source}${end}`;
|
|
2361
2419
|
}
|
|
2362
2420
|
function renderElement(node, context, locals) {
|
|
2421
|
+
if (node.tag === "component") return renderElement(resolveDynamicComponentNode(node, context.scope, locals, context.components), context, locals);
|
|
2363
2422
|
if (node.tag === "ResuxPage") {
|
|
2364
2423
|
if (!context.renderPage) return "";
|
|
2365
2424
|
throw new Error("ResuxPage must be rendered by renderTemplateNodesAsync.");
|
|
@@ -2483,6 +2542,7 @@ async function renderTemplateNodeAsync(node, context, renderComponent, locals) {
|
|
|
2483
2542
|
return renderElementAsync(node, context, renderComponent, locals);
|
|
2484
2543
|
}
|
|
2485
2544
|
async function renderElementAsync(node, context, renderComponent, locals) {
|
|
2545
|
+
if (node.tag === "component") return renderElementAsync(resolveDynamicComponentNode(node, context.scope, locals, context.components), context, renderComponent, locals);
|
|
2486
2546
|
if (node.tag === "ResuxPage") return context.renderPage ? `<span data-rx-page="">${await context.renderPage(context.suppressTeleportReservations)}</span>` : "";
|
|
2487
2547
|
if (node.tag === "ResuxLayout") {
|
|
2488
2548
|
const layoutName = resolveLayoutName(node, context, locals);
|
|
@@ -2505,7 +2565,7 @@ async function renderElementAsync(node, context, renderComponent, locals) {
|
|
|
2505
2565
|
const renderResolvedComponent = (component) => {
|
|
2506
2566
|
const props = collectComponentProps(node, context.scope, locals);
|
|
2507
2567
|
const renderSlot = (suppressTeleportReservations = context.suppressTeleportReservations) => renderTemplateNodesAsync(node.children, inheritTeleportReservationSuppression(context, suppressTeleportReservations), renderComponent, locals);
|
|
2508
|
-
return renderComponent(component, props, renderSlot, context.suppressTeleportReservations);
|
|
2568
|
+
return renderComponent(component, props, renderSlot, context.suppressTeleportReservations, collectComponentEmitBindings(node, context, locals));
|
|
2509
2569
|
};
|
|
2510
2570
|
if (node.tag === "ResuxLink" || node.tag === "NuxtLink" || node.tag === "RouterLink") {
|
|
2511
2571
|
const component = resolveComponentDefinition(node.tag, context.components);
|
|
@@ -3980,6 +4040,7 @@ var AsyncResuxRenderer = class {
|
|
|
3980
4040
|
scopes = {};
|
|
3981
4041
|
globalStateRefs = Object.create(null);
|
|
3982
4042
|
styleIds = /* @__PURE__ */ new Set();
|
|
4043
|
+
renderedDefinitions = /* @__PURE__ */ new Map();
|
|
3983
4044
|
teleportEntries = [];
|
|
3984
4045
|
headEntries = [];
|
|
3985
4046
|
resuxApp;
|
|
@@ -3993,8 +4054,9 @@ var AsyncResuxRenderer = class {
|
|
|
3993
4054
|
this.runtimeConfig = runtimeConfig;
|
|
3994
4055
|
this.resuxApp = createResuxApp(route, modules, runtimeConfig);
|
|
3995
4056
|
}
|
|
3996
|
-
async renderComponent(definition, renderPage, renderSlot, props = {}, suppressTeleportReservations = false) {
|
|
4057
|
+
async renderComponent(definition, renderPage, renderSlot, props = {}, suppressTeleportReservations = false, emits) {
|
|
3997
4058
|
this.collectComponentStyles(definition);
|
|
4059
|
+
this.renderedDefinitions.set(definition.id, definition);
|
|
3998
4060
|
const scopeId = `s${this.nextScopeId++}`;
|
|
3999
4061
|
const stateRefs = Object.create(null);
|
|
4000
4062
|
const globalStateKeys = /* @__PURE__ */ new Set();
|
|
@@ -4007,7 +4069,8 @@ var AsyncResuxRenderer = class {
|
|
|
4007
4069
|
props,
|
|
4008
4070
|
stateRefs,
|
|
4009
4071
|
globalStateKeys,
|
|
4010
|
-
asyncDataRefs
|
|
4072
|
+
asyncDataRefs,
|
|
4073
|
+
...emits ? { emits } : {}
|
|
4011
4074
|
};
|
|
4012
4075
|
return withActiveResuxApp(this.resuxApp, () => renderTemplateNodesAsync(definition.template, {
|
|
4013
4076
|
scope,
|
|
@@ -4026,7 +4089,7 @@ var AsyncResuxRenderer = class {
|
|
|
4026
4089
|
renderLayout: (name, slot, suppress) => this.renderLayout(name, slot, suppress),
|
|
4027
4090
|
reserveTeleport: suppressTeleportReservations ? void 0 : (target) => this.reserveTeleport(target),
|
|
4028
4091
|
commitTeleport: suppressTeleportReservations ? void 0 : (reservation, html) => this.commitTeleport(reservation, html)
|
|
4029
|
-
}, (component, props, slot, suppress) => this.renderComponent(component, void 0, slot, props, suppress)));
|
|
4092
|
+
}, (component, props, slot, suppress, emits) => this.renderComponent(component, void 0, slot, props, suppress, emits)));
|
|
4030
4093
|
}
|
|
4031
4094
|
reserveTeleport(target) {
|
|
4032
4095
|
if (target !== "#teleports") return;
|
|
@@ -4076,6 +4139,7 @@ var AsyncResuxRenderer = class {
|
|
|
4076
4139
|
props: serializeProps(scope.props),
|
|
4077
4140
|
state: serializeRefs(scope.stateRefs),
|
|
4078
4141
|
globalStateKeys: [...scope.globalStateKeys],
|
|
4142
|
+
...scope.emits ? { emits: scope.emits } : {},
|
|
4079
4143
|
asyncData: serializeAsyncData(scope.asyncDataRefs)
|
|
4080
4144
|
};
|
|
4081
4145
|
return {
|
|
@@ -4083,6 +4147,7 @@ var AsyncResuxRenderer = class {
|
|
|
4083
4147
|
scopes,
|
|
4084
4148
|
globalState: serializeRefs(this.globalStateRefs),
|
|
4085
4149
|
modules: this.modules,
|
|
4150
|
+
...withClientComponentIds(collectClientBlockComponentIds(this.renderedDefinitions.values(), [this.components, this.layouts])),
|
|
4086
4151
|
vueIslands: this.vueIslands,
|
|
4087
4152
|
config: publicRuntimeConfig(this.runtimeConfig)
|
|
4088
4153
|
};
|
|
@@ -4935,6 +5000,26 @@ function collectComponentProps(node, scope, locals) {
|
|
|
4935
5000
|
}
|
|
4936
5001
|
return props;
|
|
4937
5002
|
}
|
|
5003
|
+
function collectComponentEmitBindings(node, context, locals) {
|
|
5004
|
+
if (node.events.length === 0) return;
|
|
5005
|
+
const bindings = {};
|
|
5006
|
+
for (const event of node.events) {
|
|
5007
|
+
const binding = { handler: `${context.scopeId}:${context.moduleId}:${event.handler}` };
|
|
5008
|
+
if (event.locals?.length) {
|
|
5009
|
+
const eventLocals = {};
|
|
5010
|
+
for (const name of event.locals) {
|
|
5011
|
+
if (!Object.hasOwn(locals, name)) continue;
|
|
5012
|
+
const value = locals[name];
|
|
5013
|
+
if (value === void 0) continue;
|
|
5014
|
+
assertJsonSerializable(value, `event local "${name}"`);
|
|
5015
|
+
eventLocals[name] = value;
|
|
5016
|
+
}
|
|
5017
|
+
binding.locals = eventLocals;
|
|
5018
|
+
}
|
|
5019
|
+
bindings[normalizePropName(event.name)] = binding;
|
|
5020
|
+
}
|
|
5021
|
+
return bindings;
|
|
5022
|
+
}
|
|
4938
5023
|
function normalizePropName(name) {
|
|
4939
5024
|
return name.replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
4940
5025
|
}
|
|
@@ -8262,6 +8347,7 @@ export function createClientComponent(definition) {
|
|
|
8262
8347
|
const asyncDataRefs = Object.create(null);
|
|
8263
8348
|
const pendingCompletions = [];
|
|
8264
8349
|
const mountedCallbacks = [];
|
|
8350
|
+
const emitQueue = [];
|
|
8265
8351
|
const props = serializedScope.props ?? {};
|
|
8266
8352
|
const setupContext = {
|
|
8267
8353
|
props,
|
|
@@ -8331,6 +8417,22 @@ export function createClientComponent(definition) {
|
|
|
8331
8417
|
defineProps() {
|
|
8332
8418
|
return props;
|
|
8333
8419
|
},
|
|
8420
|
+
defineEmits() {
|
|
8421
|
+
return (name, ...args) => {
|
|
8422
|
+
emitQueue.push({ name, args });
|
|
8423
|
+
};
|
|
8424
|
+
},
|
|
8425
|
+
emit(name, ...args) {
|
|
8426
|
+
emitQueue.push({ name, args });
|
|
8427
|
+
},
|
|
8428
|
+
defineExpose() {},
|
|
8429
|
+
defineSlots() {
|
|
8430
|
+
return {};
|
|
8431
|
+
},
|
|
8432
|
+
defineOptions() {},
|
|
8433
|
+
defineModel(name) {
|
|
8434
|
+
return ref(props[name === undefined ? "modelValue" : name]);
|
|
8435
|
+
},
|
|
8334
8436
|
useRoute() {
|
|
8335
8437
|
return route;
|
|
8336
8438
|
},
|
|
@@ -8428,9 +8530,9 @@ export function createClientComponent(definition) {
|
|
|
8428
8530
|
bindTemplateRefs(scope, definition, serializedScope.id);
|
|
8429
8531
|
serializedScope.globalStateKeys = [...globalStateKeys];
|
|
8430
8532
|
await Promise.allSettled(mountedCallbacks.map((callback) => callback()));
|
|
8431
|
-
return { scopeId: serializedScope.id, scope, props, stateRefs, globalStateKeys, asyncDataRefs, pendingCompletions };
|
|
8533
|
+
return { scopeId: serializedScope.id, scope, props, stateRefs, globalStateKeys, asyncDataRefs, pendingCompletions, emitQueue };
|
|
8432
8534
|
},
|
|
8433
|
-
async run(scopeRecord, handlerName, event, eventLocals = {}) {
|
|
8535
|
+
async run(scopeRecord, handlerName, event, eventLocals = {}, emitArgs = null) {
|
|
8434
8536
|
bindTemplateRefs(scopeRecord.scope, definition, scopeRecord.scopeId);
|
|
8435
8537
|
const handler = scopeRecord.scope[handlerName];
|
|
8436
8538
|
if (typeof handler !== "function") {
|
|
@@ -8438,6 +8540,8 @@ export function createClientComponent(definition) {
|
|
|
8438
8540
|
}
|
|
8439
8541
|
if (Object.keys(eventLocals).length > 0) {
|
|
8440
8542
|
await handler(event, eventLocals);
|
|
8543
|
+
} else if (emitArgs) {
|
|
8544
|
+
await handler(...emitArgs);
|
|
8441
8545
|
} else {
|
|
8442
8546
|
await handler(event);
|
|
8443
8547
|
}
|
|
@@ -8446,6 +8550,11 @@ export function createClientComponent(definition) {
|
|
|
8446
8550
|
render(scopeRecord) {
|
|
8447
8551
|
return renderClientPatches(definition.template, scopeRecord.scope, definition.styleScopeId, scopeRecord.scopeId, definition.id);
|
|
8448
8552
|
},
|
|
8553
|
+
renderHtml(scopeRecord) {
|
|
8554
|
+
return definition.template
|
|
8555
|
+
.map((node) => renderNode(node, scopeRecord.scope, {}, definition.styleScopeId, scopeRecord.scopeId, definition.id))
|
|
8556
|
+
.join("");
|
|
8557
|
+
},
|
|
8449
8558
|
serialize(scopeRecord) {
|
|
8450
8559
|
return {
|
|
8451
8560
|
props: serializeProps(scopeRecord.props ?? {}),
|
|
@@ -13385,6 +13494,7 @@ async function handleDelegatedEvent(eventName, event) {
|
|
|
13385
13494
|
payload.scopes[scopeId].state = serialized.state;
|
|
13386
13495
|
payload.scopes[scopeId].asyncData = serialized.asyncData;
|
|
13387
13496
|
applyPatches(scopeId, patches);
|
|
13497
|
+
await drainComponentEmits(scopeId, scopeRecord);
|
|
13388
13498
|
} catch (error) {
|
|
13389
13499
|
dispatchManagedEvent(typeof document !== "undefined" ? document : null, "resux:handler-error", {
|
|
13390
13500
|
event: eventName,
|
|
@@ -13395,6 +13505,49 @@ async function handleDelegatedEvent(eventName, event) {
|
|
|
13395
13505
|
}
|
|
13396
13506
|
}
|
|
13397
13507
|
|
|
13508
|
+
function normalizeEmitName(name) {
|
|
13509
|
+
return String(name).replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
13510
|
+
}
|
|
13511
|
+
|
|
13512
|
+
// A child's emit() only queues the call. After the child's own handler has finished and its state is
|
|
13513
|
+
// serialized, each queued emit runs the parent handler named in the payload (events written on the child tag).
|
|
13514
|
+
async function drainComponentEmits(scopeId, record) {
|
|
13515
|
+
const queue = record && record.emitQueue;
|
|
13516
|
+
if (!queue || queue.length === 0) return;
|
|
13517
|
+
const pending = queue.splice(0, queue.length);
|
|
13518
|
+
const payload = globalThis.__RESUX__;
|
|
13519
|
+
const bindings = payload && payload.scopes && payload.scopes[scopeId] ? payload.scopes[scopeId].emits : null;
|
|
13520
|
+
if (!bindings) return;
|
|
13521
|
+
for (const entry of pending) {
|
|
13522
|
+
const binding = bindings[normalizeEmitName(entry.name)];
|
|
13523
|
+
if (!binding) continue;
|
|
13524
|
+
const [parentScopeId, parentModuleId, handlerName] = String(binding.handler).split(":");
|
|
13525
|
+
if (!parentScopeId || !parentModuleId || !handlerName || !payload.scopes[parentScopeId]) continue;
|
|
13526
|
+
try {
|
|
13527
|
+
const component = await importComponent(parentModuleId, payload.modules, devImportRevision);
|
|
13528
|
+
let parentRecord = scopeCache.get(parentScopeId);
|
|
13529
|
+
if (!parentRecord) {
|
|
13530
|
+
parentRecord = await component.createScope(payload.scopes[parentScopeId], payload.route);
|
|
13531
|
+
scopeCache.set(parentScopeId, parentRecord);
|
|
13532
|
+
}
|
|
13533
|
+
const patches = await component.run(parentRecord, handlerName, entry.args[0], binding.locals || {}, entry.args);
|
|
13534
|
+
const serialized = component.serialize(parentRecord);
|
|
13535
|
+
payload.scopes[parentScopeId].props = serialized.props;
|
|
13536
|
+
payload.scopes[parentScopeId].state = serialized.state;
|
|
13537
|
+
payload.scopes[parentScopeId].asyncData = serialized.asyncData;
|
|
13538
|
+
applyPatches(parentScopeId, patches);
|
|
13539
|
+
await drainComponentEmits(parentScopeId, parentRecord);
|
|
13540
|
+
} catch (error) {
|
|
13541
|
+
dispatchManagedEvent(typeof document !== "undefined" ? document : null, "resux:handler-error", {
|
|
13542
|
+
event: "emit:" + entry.name,
|
|
13543
|
+
scopeId: parentScopeId,
|
|
13544
|
+
handler: handlerName,
|
|
13545
|
+
message: error instanceof Error ? error.message : String(error)
|
|
13546
|
+
});
|
|
13547
|
+
}
|
|
13548
|
+
}
|
|
13549
|
+
}
|
|
13550
|
+
|
|
13398
13551
|
function readEventLocals(target, eventName) {
|
|
13399
13552
|
const encoded = target.getAttribute("data-rx-locals-" + eventName);
|
|
13400
13553
|
if (!encoded) return {};
|
|
@@ -13610,6 +13763,8 @@ function renderNode(node, scope, locals, styleScopeId, scopeId, moduleId) {
|
|
|
13610
13763
|
}
|
|
13611
13764
|
if (node.for) {
|
|
13612
13765
|
const items = evaluateExpression(node.for.source, scope, locals);
|
|
13766
|
+
const previousInFor = clientRenderInFor;
|
|
13767
|
+
clientRenderInFor = true;
|
|
13613
13768
|
const rendered = Array.isArray(items)
|
|
13614
13769
|
? items.map((item, index) => {
|
|
13615
13770
|
const nextLocals = { ...locals, [node.for.value]: item };
|
|
@@ -13617,6 +13772,7 @@ function renderNode(node, scope, locals, styleScopeId, scopeId, moduleId) {
|
|
|
13617
13772
|
return renderElement({ ...node, for: undefined, if: undefined }, scope, nextLocals, styleScopeId, scopeId, moduleId);
|
|
13618
13773
|
}).join("")
|
|
13619
13774
|
: "";
|
|
13775
|
+
clientRenderInFor = previousInFor;
|
|
13620
13776
|
return '<span data-rx-block="' + scopeId + ':' + node.for.blockId + '" style="display: contents;">' + rendered + '</span>';
|
|
13621
13777
|
}
|
|
13622
13778
|
if (node.if) {
|
|
@@ -13628,6 +13784,174 @@ function renderNode(node, scope, locals, styleScopeId, scopeId, moduleId) {
|
|
|
13628
13784
|
return renderElement(node, scope, locals, styleScopeId, scopeId, moduleId);
|
|
13629
13785
|
}
|
|
13630
13786
|
|
|
13787
|
+
// Components inside client-rendered blocks (v-if / v-for). The block renderer is synchronous, so a
|
|
13788
|
+
// component becomes a placeholder first. mountClientChildren then imports the component module on demand,
|
|
13789
|
+
// creates a client-only scope (ids c1, c2, ... never clash with server ids s*), renders its template and
|
|
13790
|
+
// swaps the placeholder for the real nodes. Scopes are released when their nodes leave the document.
|
|
13791
|
+
let clientChildCounter = 0;
|
|
13792
|
+
const pendingClientChildren = new Map();
|
|
13793
|
+
const clientChildRoots = new Map();
|
|
13794
|
+
const clientChildMeta = new Map();
|
|
13795
|
+
const clientSlotContent = new Map();
|
|
13796
|
+
let clientRenderInFor = false;
|
|
13797
|
+
|
|
13798
|
+
function clientBlockComponentModuleId(tag) {
|
|
13799
|
+
const payload = globalThis.__RESUX__;
|
|
13800
|
+
const ids = payload && payload.componentIds;
|
|
13801
|
+
return ids && Object.prototype.hasOwnProperty.call(ids, tag) ? ids[tag] : "";
|
|
13802
|
+
}
|
|
13803
|
+
|
|
13804
|
+
function renderClientChildPlaceholder(node, moduleId, scope, locals, styleScopeId, scopeId, parentModuleId) {
|
|
13805
|
+
const props = {};
|
|
13806
|
+
let key = "";
|
|
13807
|
+
let hasKey = false;
|
|
13808
|
+
for (const attr of node.attrs) {
|
|
13809
|
+
const value = attr.kind === "static" ? attr.value : evaluateExpression(attr.value, scope, locals);
|
|
13810
|
+
if (attr.name === "key") {
|
|
13811
|
+
key = String(value);
|
|
13812
|
+
hasKey = true;
|
|
13813
|
+
continue;
|
|
13814
|
+
}
|
|
13815
|
+
const name = String(attr.name).replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
13816
|
+
props[name] = value;
|
|
13817
|
+
}
|
|
13818
|
+
if (clientRenderInFor && !hasKey && isClientDevMode()) {
|
|
13819
|
+
console.warn("[resux] <" + node.tag + "> inside v-for has no :key. Its state is matched by position, so reordering the list can move state to the wrong item.");
|
|
13820
|
+
}
|
|
13821
|
+
// Slot content is rendered by the parent (its scope and locals), like the server renderer does: all
|
|
13822
|
+
// children of the tag form one default slot. Named and scoped slots are not part of the server model.
|
|
13823
|
+
const slotHtml = node.children.map((child) => renderNode(child, scope, locals, styleScopeId, scopeId, parentModuleId)).join("");
|
|
13824
|
+
let emits = null;
|
|
13825
|
+
if (node.events && node.events.length > 0) {
|
|
13826
|
+
emits = {};
|
|
13827
|
+
for (const event of node.events) {
|
|
13828
|
+
const binding = { handler: scopeId + ":" + parentModuleId + ":" + event.handler };
|
|
13829
|
+
if (event.locals && event.locals.length > 0) {
|
|
13830
|
+
binding.locals = {};
|
|
13831
|
+
for (const name of event.locals) {
|
|
13832
|
+
if (Object.prototype.hasOwnProperty.call(locals, name) && locals[name] !== undefined) binding.locals[name] = locals[name];
|
|
13833
|
+
}
|
|
13834
|
+
}
|
|
13835
|
+
emits[normalizeEmitName(event.name)] = binding;
|
|
13836
|
+
}
|
|
13837
|
+
}
|
|
13838
|
+
const id = "c" + (++clientChildCounter);
|
|
13839
|
+
pendingClientChildren.set(id, { moduleId, tag: node.tag, props, key, hasKey, slotHtml, emits });
|
|
13840
|
+
return '<span data-rx-child="' + id + '" style="display: contents;"></span>';
|
|
13841
|
+
}
|
|
13842
|
+
|
|
13843
|
+
async function mountClientChildren(root) {
|
|
13844
|
+
const host = root && root.querySelectorAll ? root : document;
|
|
13845
|
+
const placeholders = Array.from(host.querySelectorAll("[data-rx-child]"));
|
|
13846
|
+
if (host !== document && host.matches && host.matches("[data-rx-child]")) placeholders.unshift(host);
|
|
13847
|
+
await Promise.all(placeholders.map((placeholder) => mountClientChild(placeholder)));
|
|
13848
|
+
}
|
|
13849
|
+
|
|
13850
|
+
async function mountClientChild(placeholder) {
|
|
13851
|
+
const id = placeholder.getAttribute("data-rx-child");
|
|
13852
|
+
const entry = pendingClientChildren.get(id);
|
|
13853
|
+
if (!entry) return;
|
|
13854
|
+
pendingClientChildren.delete(id);
|
|
13855
|
+
const payload = globalThis.__RESUX__;
|
|
13856
|
+
if (!placeholder.isConnected || !payload || !payload.modules || !payload.scopes) return;
|
|
13857
|
+
try {
|
|
13858
|
+
const component = await importComponent(entry.moduleId, payload.modules, devImportRevision);
|
|
13859
|
+
const serialized = { id, moduleId: entry.moduleId, props: serializeProps(entry.props), state: {}, globalStateKeys: [], asyncData: {} };
|
|
13860
|
+
const record = await component.createScope(serialized, payload.route);
|
|
13861
|
+
if (!placeholder.isConnected) return;
|
|
13862
|
+
clientSlotContent.set(id, entry.slotHtml);
|
|
13863
|
+
const html = component.renderHtml(record);
|
|
13864
|
+
const state = component.serialize(record);
|
|
13865
|
+
scopeCache.set(id, record);
|
|
13866
|
+
payload.scopes[id] = { ...serialized, props: state.props, state: state.state, asyncData: state.asyncData, globalStateKeys: record.globalStateKeys ? [...record.globalStateKeys] : [] };
|
|
13867
|
+
if (entry.emits) payload.scopes[id].emits = entry.emits;
|
|
13868
|
+
const template = document.createElement("template");
|
|
13869
|
+
template.innerHTML = html;
|
|
13870
|
+
const parent = placeholder.parentNode;
|
|
13871
|
+
const nodes = Array.from(template.content.childNodes);
|
|
13872
|
+
clientChildRoots.set(id, nodes);
|
|
13873
|
+
clientChildMeta.set(id, { tag: entry.tag, key: entry.hasKey ? "k:" + entry.key : "", propsJson: JSON.stringify(entry.props), slotHtml: entry.slotHtml, emitsJson: JSON.stringify(entry.emits) });
|
|
13874
|
+
placeholder.replaceWith(template.content);
|
|
13875
|
+
registerDelegatedEventsFromDom(parent && parent.nodeType === 1 ? parent : document);
|
|
13876
|
+
await Promise.all(nodes.filter((child) => child.nodeType === 1).map((child) => mountClientChildren(child)));
|
|
13877
|
+
await drainComponentEmits(id, record);
|
|
13878
|
+
} catch (error) {
|
|
13879
|
+
placeholder.replaceWith(document.createComment("resux-child-error"));
|
|
13880
|
+
dispatchManagedEvent(typeof document !== "undefined" ? document : null, "resux:handler-error", {
|
|
13881
|
+
event: "mount",
|
|
13882
|
+
scopeId: id,
|
|
13883
|
+
handler: entry.tag,
|
|
13884
|
+
message: error instanceof Error ? error.message : String(error)
|
|
13885
|
+
});
|
|
13886
|
+
}
|
|
13887
|
+
}
|
|
13888
|
+
|
|
13889
|
+
// A block patch re-renders the whole block. Client-created children inside it are held aside in a
|
|
13890
|
+
// fragment, then put back in place of their new placeholder when the key (or, unkeyed, the position
|
|
13891
|
+
// among same-tag siblings) and the props match, so their state survives unrelated updates and reorders.
|
|
13892
|
+
function holdClientChildrenOfBlock(block) {
|
|
13893
|
+
const held = [];
|
|
13894
|
+
for (const [id, nodes] of clientChildRoots) {
|
|
13895
|
+
const first = nodes[0];
|
|
13896
|
+
if (!first || !first.isConnected || !block.contains(first)) continue;
|
|
13897
|
+
const owner = first.parentNode && first.parentNode.closest ? first.parentNode.closest("[data-rx-block]") : null;
|
|
13898
|
+
if (owner !== block) continue;
|
|
13899
|
+
held.push({ id, nodes, meta: clientChildMeta.get(id) });
|
|
13900
|
+
}
|
|
13901
|
+
if (held.length === 0) return held;
|
|
13902
|
+
const holder = document.createDocumentFragment();
|
|
13903
|
+
for (const entry of held) for (const node of entry.nodes) holder.appendChild(node);
|
|
13904
|
+
held.holder = holder;
|
|
13905
|
+
return held;
|
|
13906
|
+
}
|
|
13907
|
+
|
|
13908
|
+
function restoreClientChildrenOfBlock(block, held) {
|
|
13909
|
+
if (!held || held.length === 0) return;
|
|
13910
|
+
const byKey = new Map();
|
|
13911
|
+
const unkeyedCount = new Map();
|
|
13912
|
+
for (const entry of held) {
|
|
13913
|
+
const meta = entry.meta;
|
|
13914
|
+
if (!meta) continue;
|
|
13915
|
+
let slot = meta.key;
|
|
13916
|
+
if (!slot) {
|
|
13917
|
+
const n = unkeyedCount.get(meta.tag) || 0;
|
|
13918
|
+
unkeyedCount.set(meta.tag, n + 1);
|
|
13919
|
+
slot = "i:" + meta.tag + ":" + n;
|
|
13920
|
+
}
|
|
13921
|
+
byKey.set(slot, entry);
|
|
13922
|
+
}
|
|
13923
|
+
const seen = new Map();
|
|
13924
|
+
for (const placeholder of Array.from(block.querySelectorAll("[data-rx-child]"))) {
|
|
13925
|
+
const id = placeholder.getAttribute("data-rx-child");
|
|
13926
|
+
const pending = pendingClientChildren.get(id);
|
|
13927
|
+
if (!pending) continue;
|
|
13928
|
+
let slot = pending.hasKey ? "k:" + pending.key : "";
|
|
13929
|
+
if (!slot) {
|
|
13930
|
+
const n = seen.get(pending.tag) || 0;
|
|
13931
|
+
seen.set(pending.tag, n + 1);
|
|
13932
|
+
slot = "i:" + pending.tag + ":" + n;
|
|
13933
|
+
}
|
|
13934
|
+
const old = byKey.get(slot);
|
|
13935
|
+
if (!old || old.meta.tag !== pending.tag || old.meta.propsJson !== JSON.stringify(pending.props) || old.meta.slotHtml !== pending.slotHtml || old.meta.emitsJson !== JSON.stringify(pending.emits)) continue;
|
|
13936
|
+
byKey.delete(slot);
|
|
13937
|
+
pendingClientChildren.delete(id);
|
|
13938
|
+
for (const node of old.nodes) placeholder.parentNode.insertBefore(node, placeholder);
|
|
13939
|
+
placeholder.remove();
|
|
13940
|
+
}
|
|
13941
|
+
}
|
|
13942
|
+
|
|
13943
|
+
function releaseDetachedClientChildren() {
|
|
13944
|
+
const payload = globalThis.__RESUX__;
|
|
13945
|
+
for (const [id, nodes] of Array.from(clientChildRoots)) {
|
|
13946
|
+
if (nodes.some((node) => node.isConnected)) continue;
|
|
13947
|
+
clientChildRoots.delete(id);
|
|
13948
|
+
clientChildMeta.delete(id);
|
|
13949
|
+
clientSlotContent.delete(id);
|
|
13950
|
+
scopeCache.delete(id);
|
|
13951
|
+
if (payload && payload.scopes) delete payload.scopes[id];
|
|
13952
|
+
}
|
|
13953
|
+
}
|
|
13954
|
+
|
|
13631
13955
|
const unsafeClientTransitionContainerTags = new Set(${JSON.stringify([...unsafeTransitionContainerTags])});
|
|
13632
13956
|
|
|
13633
13957
|
function normalizeClientTeleportTarget(value) {
|
|
@@ -13667,7 +13991,20 @@ function normalizeClientTransitionTag(value) {
|
|
|
13667
13991
|
}
|
|
13668
13992
|
|
|
13669
13993
|
function renderElement(node, scope, locals, styleScopeId, scopeId, moduleId) {
|
|
13994
|
+
if (node.tag === "component") {
|
|
13995
|
+
const isAttr = node.attrs.find((attr) => attr.name === "is");
|
|
13996
|
+
const name = isAttr ? (isAttr.kind === "static" ? isAttr.value : evaluateExpression(isAttr.value, scope, locals)) : "";
|
|
13997
|
+
const childModuleId = typeof name === "string" && name ? clientBlockComponentModuleId(name) : "";
|
|
13998
|
+
if (!childModuleId) {
|
|
13999
|
+
if (isClientDevMode()) console.error("[resux] <component :is> needs the name of a registered component as a string, got: " + String(name));
|
|
14000
|
+
return "<!--resux-unknown-component-->";
|
|
14001
|
+
}
|
|
14002
|
+
return renderClientChildPlaceholder({ ...node, tag: name, attrs: node.attrs.filter((attr) => attr !== isAttr) }, childModuleId, scope, locals, styleScopeId, scopeId, moduleId);
|
|
14003
|
+
}
|
|
13670
14004
|
const normalizedTag = String(node.tag || "").toLowerCase();
|
|
14005
|
+
if (normalizedTag === "slot" && clientSlotContent.size > 0 && clientSlotContent.has(scopeId)) {
|
|
14006
|
+
return clientSlotContent.get(scopeId);
|
|
14007
|
+
}
|
|
13671
14008
|
if (normalizedTag === "teleport") {
|
|
13672
14009
|
const find = (name) => node.attrs.find((attr) => attr.name === name);
|
|
13673
14010
|
const read = (attr, fallback) => attr
|
|
@@ -13745,6 +14082,12 @@ function renderElement(node, scope, locals, styleScopeId, scopeId, moduleId) {
|
|
|
13745
14082
|
if (node.tag === "ClientEnhance" || node.tag === "ResuxClientEnhance") {
|
|
13746
14083
|
return renderClientResuxClientEnhance(node, scope, locals, styleScopeId);
|
|
13747
14084
|
}
|
|
14085
|
+
if (/^[A-Z]/.test(node.tag)) {
|
|
14086
|
+
const childModuleId = clientBlockComponentModuleId(node.tag);
|
|
14087
|
+
if (childModuleId) {
|
|
14088
|
+
return renderClientChildPlaceholder(node, childModuleId, scope, locals, styleScopeId, scopeId, moduleId);
|
|
14089
|
+
}
|
|
14090
|
+
}
|
|
13748
14091
|
const tag = nativeElementTag(node);
|
|
13749
14092
|
const attrs = [];
|
|
13750
14093
|
let resolvedRef;
|
|
@@ -15868,8 +16211,10 @@ function applyPatches(scopeId, patches, options = {}) {
|
|
|
15868
16211
|
continue;
|
|
15869
16212
|
}
|
|
15870
16213
|
elements.forEach((element) => {
|
|
16214
|
+
const held = patch.type === "block" && clientChildRoots.size > 0 ? holdClientChildrenOfBlock(element) : null;
|
|
15871
16215
|
if (patch.type !== "html" && patchTransitionBlock(element, patch.value)) return;
|
|
15872
16216
|
replaceManagedRuntimeHtml(element, patch.value);
|
|
16217
|
+
if (held) restoreClientChildrenOfBlock(element, held);
|
|
15873
16218
|
void mountVueIslands(document);
|
|
15874
16219
|
needsLazyImageActivation = true;
|
|
15875
16220
|
needsDelegatedEventRegistration = true;
|
|
@@ -15893,6 +16238,8 @@ function applyPatches(scopeId, patches, options = {}) {
|
|
|
15893
16238
|
initializeManagedVideoControls();
|
|
15894
16239
|
}
|
|
15895
16240
|
if (needsDelegatedEventRegistration) registerDelegatedEventsFromDom(document);
|
|
16241
|
+
if (pendingClientChildren.size > 0) void mountClientChildren(document);
|
|
16242
|
+
if (clientChildRoots.size > 0) releaseDetachedClientChildren();
|
|
15896
16243
|
}
|
|
15897
16244
|
|
|
15898
16245
|
function evaluateExpression(expression, scope, locals) {
|