@jfdevelops/react-layout 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-config/create-defined-resource-layout.cjs +10 -2
- package/dist/create-config/create-defined-resource-layout.cjs.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.cts +7 -5
- package/dist/create-config/create-defined-resource-layout.d.cts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.mts +7 -5
- package/dist/create-config/create-defined-resource-layout.d.mts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.mjs +10 -2
- package/dist/create-config/create-defined-resource-layout.mjs.map +1 -1
- package/dist/create-config/define-layout.cjs +63 -19
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +9 -8
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +9 -8
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +63 -19
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/create-config/for-resources/create-component.d.cts +30 -24
- package/dist/create-config/for-resources/create-component.d.cts.map +1 -1
- package/dist/create-config/for-resources/create-component.d.mts +30 -24
- package/dist/create-config/for-resources/create-component.d.mts.map +1 -1
- package/dist/create-config/for-resources/create-for-resources.cjs +27 -6
- package/dist/create-config/for-resources/create-for-resources.cjs.map +1 -1
- package/dist/create-config/for-resources/create-for-resources.mjs +27 -6
- package/dist/create-config/for-resources/create-for-resources.mjs.map +1 -1
- package/dist/create-config/for-resources/scoped-layout.d.cts +2 -2
- package/dist/create-config/for-resources/scoped-layout.d.cts.map +1 -1
- package/dist/create-config/for-resources/scoped-layout.d.mts +2 -2
- package/dist/create-config/for-resources/scoped-layout.d.mts.map +1 -1
- package/dist/create-config/for-resources/scoped-render.cjs +38 -4
- package/dist/create-config/for-resources/scoped-render.cjs.map +1 -1
- package/dist/create-config/for-resources/scoped-render.d.cts +8 -1
- package/dist/create-config/for-resources/scoped-render.d.cts.map +1 -1
- package/dist/create-config/for-resources/scoped-render.d.mts +8 -1
- package/dist/create-config/for-resources/scoped-render.d.mts.map +1 -1
- package/dist/create-config/for-resources/scoped-render.mjs +38 -4
- package/dist/create-config/for-resources/scoped-render.mjs.map +1 -1
- package/dist/create-config/index.d.cts +1 -1
- package/dist/create-config/index.d.mts +1 -1
- package/dist/create-config/render-state-context.cjs +24 -0
- package/dist/create-config/render-state-context.cjs.map +1 -0
- package/dist/create-config/render-state-context.mjs +22 -0
- package/dist/create-config/render-state-context.mjs.map +1 -0
- package/dist/create-config/render-state.cjs +1 -0
- package/dist/create-config/render-state.cjs.map +1 -1
- package/dist/create-config/render-state.d.cts +26 -15
- package/dist/create-config/render-state.d.cts.map +1 -1
- package/dist/create-config/render-state.d.mts +26 -15
- package/dist/create-config/render-state.d.mts.map +1 -1
- package/dist/create-config/render-state.mjs +1 -0
- package/dist/create-config/render-state.mjs.map +1 -1
- package/dist/create-config/state-composable.cjs +4 -2
- package/dist/create-config/state-composable.cjs.map +1 -1
- package/dist/create-config/state-composable.d.cts.map +1 -1
- package/dist/create-config/state-composable.d.mts.map +1 -1
- package/dist/create-config/state-composable.mjs +4 -2
- package/dist/create-config/state-composable.mjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/lazy/create-render-state.cjs +59 -0
- package/dist/lazy/create-render-state.cjs.map +1 -0
- package/dist/lazy/create-render-state.d.cts +33 -0
- package/dist/lazy/create-render-state.d.cts.map +1 -0
- package/dist/lazy/create-render-state.d.mts +33 -0
- package/dist/lazy/create-render-state.d.mts.map +1 -0
- package/dist/lazy/create-render-state.mjs +59 -0
- package/dist/lazy/create-render-state.mjs.map +1 -0
- package/dist/lazy/lazy-boundary.cjs +14 -6
- package/dist/lazy/lazy-boundary.cjs.map +1 -1
- package/dist/lazy/lazy-boundary.mjs +14 -6
- package/dist/lazy/lazy-boundary.mjs.map +1 -1
- package/dist/lazy/types.cjs.map +1 -1
- package/dist/lazy/types.d.cts +7 -6
- package/dist/lazy/types.d.cts.map +1 -1
- package/dist/lazy/types.d.mts +7 -6
- package/dist/lazy/types.d.mts.map +1 -1
- package/dist/lazy/types.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/lazy/create-error-component.cjs +0 -17
- package/dist/lazy/create-error-component.cjs.map +0 -1
- package/dist/lazy/create-error-component.mjs +0 -16
- package/dist/lazy/create-error-component.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-render-state.cjs","names":["LayoutConfigurationError","defineResourceLayout"],"sources":["../../src/lazy/create-render-state.tsx"],"sourcesContent":["import { createElement, type ComponentType, type ReactNode } from 'react';\nimport type { ComposableComponents } from '@jfdevelops/react-layout-composables';\nimport { LayoutConfigurationError } from '../errors';\nimport type { ResourceDefinition, ResourcePath } from '../resource';\nimport {\n type ResolvedIncludedComponentProps,\n type IncludedProps,\n type InPropsDefinition,\n type InPropsObject,\n type MergedLayoutInProps,\n} from '../props';\nimport { defineResourceLayout } from '../create-config/define-layout';\nimport type {\n LayoutComposablesDefinition,\n RenderStateContext,\n RenderStateProps,\n OptionalStateChildren,\n} from '../create-config/render-state';\nimport type { ResolveProps } from '@jfdevelops/react-layout-validator';\nimport type {\n LazyResourceErrorProps,\n LazyErrorHandlers,\n CreateLazyErrorComponent,\n} from './types';\n\nexport type LazyDefaultState = 'Loading' | 'Error';\ntype BuiltinProps<\n State extends LazyDefaultState,\n Resource,\n> = State extends 'Error'\n ? LazyResourceErrorProps<Resource>\n : { resource: Resource };\n\n/** Shorthand includes are direct props; explicit supply sources retain their contract. */\ntype LazyDefaultIncludes<Include> = {\n [Key in keyof Include]: Include[Key] extends true\n ? { required: true; suppliedVia: 'component' }\n : Include[Key];\n};\n\ntype LazyRender<State extends LazyDefaultState, Resource, Props, Context> =\n | ((\n props: Props & BuiltinProps<State, Resource>,\n context: Context,\n ) => ReactNode)\n | (State extends 'Error'\n ? LazyErrorHandlers<Resource, Props & object, Context>\n : never);\n\n/** Creates validated, composable-aware fallback components for one factory. */\nexport type CreateLazyRenderState<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n> = <\n const State extends LazyDefaultState,\n const Custom extends InPropsObject = {},\n const Include extends IncludedProps<\n MergedLayoutInProps<Resources, Options, Composables>\n > = {},\n>(definition: {\n state: State;\n props?: { include?: Include; custom?: Custom };\n render: LazyRender<State, ResourcePath<Resources>, RenderStateProps<Resources, Options, Composables, Include, Custom>, RenderStateContext<Composables, Resources, State>>;\n}) => ComponentType<\n OptionalStateChildren<\n ResolveProps<Custom> &\n ResolvedIncludedComponentProps<\n MergedLayoutInProps<Resources, Options, Composables>,\n LazyDefaultIncludes<Include>\n >\n > &\n BuiltinProps<State, ResourcePath<Resources>>\n>;\n\n/** Compatibility helper; custom props keep their existing unchecked contract. */\nexport type CreateBoundLazyErrorComponent<Resource, Context> =\n CreateLazyErrorComponent<Resource, Context>;\n\ntype RuntimeDefinition = {\n state: LazyDefaultState;\n props?: { include?: Record<string, unknown>; custom?: InPropsObject };\n render:\n | ((props: any, context: any) => ReactNode)\n | LazyErrorHandlers<string, object, any>;\n};\n\nexport function createLazyRenderStateBuilder<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n>(configuration: {\n resources: Resources;\n options: Options;\n composables?: LayoutComposablesDefinition<Resources, Composables>;\n}): CreateLazyRenderState<Resources, Options, Composables> {\n function createRenderState(definition: RuntimeDefinition) {\n if (definition.state !== 'Loading' && definition.state !== 'Error') {\n throw new LayoutConfigurationError(\n `Unknown lazy default state \"${definition.state}\"`,\n );\n }\n // Lazy defaults have no create-time configuration call. Included values are\n // supplied by their component caller unless an explicit config source is selected.\n const include = Object.fromEntries(\n Object.entries(definition.props?.include ?? {}).map(([key, behavior]) => [\n key,\n behavior === true\n ? { required: true, suppliedVia: 'component' }\n : behavior,\n ]),\n );\n function RenderLazyDefault({\n props,\n context,\n }: {\n props: any;\n context: any;\n }) {\n if (typeof definition.render === 'function') {\n return definition.render(props, context);\n }\n const errorProps = props as LazyResourceErrorProps;\n const handler =\n definition.render[errorProps.error.code] ?? definition.render.fallback;\n if (!handler) throw errorProps.error;\n return handler(props as never, context);\n }\n const layout = defineResourceLayout({\n resources: configuration.resources,\n options: configuration.options,\n layout: {\n render: {\n default: () => null,\n [definition.state]: {\n composables: configuration.composables,\n props: { include, custom: definition.props?.custom },\n render: (props: any, context: any) =>\n createElement(RenderLazyDefault, { props, context }),\n },\n },\n },\n } as never);\n const components = new Map<string, ComponentType<any>>();\n function LazyDefault(props: { resource: string }) {\n // Nested lazy paths use the factory's top-level resource definitions for\n // option resolution. The callback still receives the complete path.\n const resource = props.resource.split('.')[0]!;\n let Component = components.get(resource);\n if (!Component) {\n const Root = layout.createResourceLayout({\n resource,\n name: 'LazyDefault',\n namespace: false,\n } as never) as unknown as Record<LazyDefaultState, ComponentType<any>>;\n Component = Root[definition.state];\n components.set(resource, Component);\n }\n return createElement(Component, props);\n }\n return LazyDefault;\n }\n return createRenderState as CreateLazyRenderState<\n Resources,\n Options,\n Composables\n >;\n}\n"],"mappings":";;;;;AAuFA,SAAgB,6BAId,eAIyD;CACzD,SAAS,kBAAkB,YAA+B;EACxD,IAAI,WAAW,UAAU,aAAa,WAAW,UAAU,SACzD,MAAM,IAAIA,4DACR,+BAA+B,WAAW,MAAM,EAClD;EAIF,MAAM,UAAU,OAAO,YACrB,OAAO,QAAQ,WAAW,OAAO,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,cAAc,CACvE,KACA,aAAa,OACT;GAAE,UAAU;GAAM,aAAa;EAAY,IAC3C,QACN,CAAC,CACH;EACA,SAAS,kBAAkB,EACzB,OACA,WAIC;GACD,IAAI,OAAO,WAAW,WAAW,YAC/B,OAAO,WAAW,OAAO,OAAO,OAAO;GAEzC,MAAM,aAAa;GACnB,MAAM,UACJ,WAAW,OAAO,WAAW,MAAM,SAAS,WAAW,OAAO;GAChE,IAAI,CAAC,SAAS,MAAM,WAAW;GAC/B,OAAO,QAAQ,OAAgB,OAAO;EACxC;EACA,MAAM,SAASC,2CAAqB;GAClC,WAAW,cAAc;GACzB,SAAS,cAAc;GACvB,QAAQ,EACN,QAAQ;IACN,eAAe;KACd,WAAW,QAAQ;KAClB,aAAa,cAAc;KAC3B,OAAO;MAAE;MAAS,QAAQ,WAAW,OAAO;KAAO;KACnD,SAAS,OAAY,qCACL,mBAAmB;MAAE;MAAO;KAAQ,CAAC;IACvD;GACF,EACF;EACF,CAAU;EACV,MAAM,6BAAa,IAAI,IAAgC;EACvD,SAAS,YAAY,OAA6B;GAGhD,MAAM,WAAW,MAAM,SAAS,MAAM,GAAG,EAAE;GAC3C,IAAI,YAAY,WAAW,IAAI,QAAQ;GACvC,IAAI,CAAC,WAAW;IAMd,YALa,OAAO,qBAAqB;KACvC;KACA,MAAM;KACN,WAAW;IACb,CACe,EAAE,WAAW;IAC5B,WAAW,IAAI,UAAU,SAAS;GACpC;GACA,gCAAqB,WAAW,KAAK;EACvC;EACA,OAAO;CACT;CACA,OAAO;AAKT"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CreateLazyErrorComponent, LazyErrorHandlers, LazyResourceErrorProps } from "./types.cjs";
|
|
2
|
+
import { ResourceDefinition, ResourcePath } from "../resource.cjs";
|
|
3
|
+
import { InPropsDefinition, InPropsObject, IncludedProps, MergedLayoutInProps, ResolvedIncludedComponentProps } from "../props.cjs";
|
|
4
|
+
import { OptionalStateChildren, RenderStateContext, RenderStateProps } from "../create-config/render-state.cjs";
|
|
5
|
+
import { ComposableComponents } from "@jfdevelops/react-layout-composables";
|
|
6
|
+
import { ComponentType, ReactNode } from "react";
|
|
7
|
+
import { ResolveProps } from "@jfdevelops/react-layout-validator";
|
|
8
|
+
|
|
9
|
+
//#region src/lazy/create-render-state.d.ts
|
|
10
|
+
type LazyDefaultState = 'Loading' | 'Error';
|
|
11
|
+
type BuiltinProps<State extends LazyDefaultState, Resource> = State extends 'Error' ? LazyResourceErrorProps<Resource> : {
|
|
12
|
+
resource: Resource;
|
|
13
|
+
};
|
|
14
|
+
/** Shorthand includes are direct props; explicit supply sources retain their contract. */
|
|
15
|
+
type LazyDefaultIncludes<Include> = { [Key in keyof Include]: Include[Key] extends true ? {
|
|
16
|
+
required: true;
|
|
17
|
+
suppliedVia: 'component';
|
|
18
|
+
} : Include[Key] };
|
|
19
|
+
type LazyRender<State extends LazyDefaultState, Resource, Props, Context> = ((props: Props & BuiltinProps<State, Resource>, context: Context) => ReactNode) | (State extends 'Error' ? LazyErrorHandlers<Resource, Props & object, Context> : never);
|
|
20
|
+
/** Creates validated, composable-aware fallback components for one factory. */
|
|
21
|
+
type CreateLazyRenderState<Resources extends ReadonlyArray<ResourceDefinition>, Options extends InPropsDefinition<Resources>, Composables extends ComposableComponents> = <const State extends LazyDefaultState, const Custom extends InPropsObject = {}, const Include extends IncludedProps<MergedLayoutInProps<Resources, Options, Composables>> = {}>(definition: {
|
|
22
|
+
state: State;
|
|
23
|
+
props?: {
|
|
24
|
+
include?: Include;
|
|
25
|
+
custom?: Custom;
|
|
26
|
+
};
|
|
27
|
+
render: LazyRender<State, ResourcePath<Resources>, RenderStateProps<Resources, Options, Composables, Include, Custom>, RenderStateContext<Composables, Resources, State>>;
|
|
28
|
+
}) => ComponentType<OptionalStateChildren<ResolveProps<Custom> & ResolvedIncludedComponentProps<MergedLayoutInProps<Resources, Options, Composables>, LazyDefaultIncludes<Include>>> & BuiltinProps<State, ResourcePath<Resources>>>;
|
|
29
|
+
/** Compatibility helper; custom props keep their existing unchecked contract. */
|
|
30
|
+
type CreateBoundLazyErrorComponent<Resource, Context> = CreateLazyErrorComponent<Resource, Context>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { CreateBoundLazyErrorComponent, CreateLazyRenderState, LazyDefaultState };
|
|
33
|
+
//# sourceMappingURL=create-render-state.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-render-state.d.cts","names":[],"sources":["../../src/lazy/create-render-state.tsx"],"mappings":";;;;;;;;;KAyBY,gBAAA;AAAA,KACP,YAAA,eACW,gBAAA,cAEZ,KAAA,mBACA,sBAAA,CAAuB,QAAA;EACrB,QAAA,EAAU,QAAA;AAAA;;KAGX,mBAAA,4BACW,OAAA,GAAU,OAAA,CAAQ,GAAA;EAC1B,QAAA;EAAgB,WAAA;AAAA,IAClB,OAAA,CAAQ,GAAA;AAAA,KAGT,UAAA,eAAyB,gBAAA,gCAExB,KAAA,EAAO,KAAA,GAAQ,YAAA,CAAa,KAAA,EAAO,QAAA,GACnC,OAAA,EAAS,OAAA,KACN,SAAA,KACJ,KAAA,mBACG,iBAAA,CAAkB,QAAA,EAAU,KAAA,WAAgB,OAAA;;KAIxC,qBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,uBACd,oBAAA,yBAEA,gBAAA,uBACC,aAAA,6BACC,aAAA,CACpB,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,SAE1C,UAAA;EACA,KAAA,EAAO,KAAA;EACP,KAAA;IAAU,OAAA,GAAU,OAAA;IAAS,MAAA,GAAS,MAAA;EAAA;EACtC,MAAA,EAAQ,UAAA,CAAW,KAAA,EAAO,YAAA,CAAa,SAAA,GAAY,gBAAA,CAAiB,SAAA,EAAW,OAAA,EAAS,WAAA,EAAa,OAAA,EAAS,MAAA,GAAS,kBAAA,CAAmB,WAAA,EAAa,SAAA,EAAW,KAAA;AAAA,MAC9J,aAAA,CACJ,qBAAA,CACE,YAAA,CAAa,MAAA,IACX,8BAAA,CACE,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,GACxC,mBAAA,CAAoB,OAAA,MAGxB,YAAA,CAAa,KAAA,EAAO,YAAA,CAAa,SAAA;;KAIzB,6BAAA,sBACV,wBAAA,CAAyB,QAAA,EAAU,OAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CreateLazyErrorComponent, LazyErrorHandlers, LazyResourceErrorProps } from "./types.mjs";
|
|
2
|
+
import { ResourceDefinition, ResourcePath } from "../resource.mjs";
|
|
3
|
+
import { InPropsDefinition, InPropsObject, IncludedProps, MergedLayoutInProps, ResolvedIncludedComponentProps } from "../props.mjs";
|
|
4
|
+
import { OptionalStateChildren, RenderStateContext, RenderStateProps } from "../create-config/render-state.mjs";
|
|
5
|
+
import { ComposableComponents } from "@jfdevelops/react-layout-composables";
|
|
6
|
+
import { ComponentType, ReactNode } from "react";
|
|
7
|
+
import { ResolveProps } from "@jfdevelops/react-layout-validator";
|
|
8
|
+
|
|
9
|
+
//#region src/lazy/create-render-state.d.ts
|
|
10
|
+
type LazyDefaultState = 'Loading' | 'Error';
|
|
11
|
+
type BuiltinProps<State extends LazyDefaultState, Resource> = State extends 'Error' ? LazyResourceErrorProps<Resource> : {
|
|
12
|
+
resource: Resource;
|
|
13
|
+
};
|
|
14
|
+
/** Shorthand includes are direct props; explicit supply sources retain their contract. */
|
|
15
|
+
type LazyDefaultIncludes<Include> = { [Key in keyof Include]: Include[Key] extends true ? {
|
|
16
|
+
required: true;
|
|
17
|
+
suppliedVia: 'component';
|
|
18
|
+
} : Include[Key] };
|
|
19
|
+
type LazyRender<State extends LazyDefaultState, Resource, Props, Context> = ((props: Props & BuiltinProps<State, Resource>, context: Context) => ReactNode) | (State extends 'Error' ? LazyErrorHandlers<Resource, Props & object, Context> : never);
|
|
20
|
+
/** Creates validated, composable-aware fallback components for one factory. */
|
|
21
|
+
type CreateLazyRenderState<Resources extends ReadonlyArray<ResourceDefinition>, Options extends InPropsDefinition<Resources>, Composables extends ComposableComponents> = <const State extends LazyDefaultState, const Custom extends InPropsObject = {}, const Include extends IncludedProps<MergedLayoutInProps<Resources, Options, Composables>> = {}>(definition: {
|
|
22
|
+
state: State;
|
|
23
|
+
props?: {
|
|
24
|
+
include?: Include;
|
|
25
|
+
custom?: Custom;
|
|
26
|
+
};
|
|
27
|
+
render: LazyRender<State, ResourcePath<Resources>, RenderStateProps<Resources, Options, Composables, Include, Custom>, RenderStateContext<Composables, Resources, State>>;
|
|
28
|
+
}) => ComponentType<OptionalStateChildren<ResolveProps<Custom> & ResolvedIncludedComponentProps<MergedLayoutInProps<Resources, Options, Composables>, LazyDefaultIncludes<Include>>> & BuiltinProps<State, ResourcePath<Resources>>>;
|
|
29
|
+
/** Compatibility helper; custom props keep their existing unchecked contract. */
|
|
30
|
+
type CreateBoundLazyErrorComponent<Resource, Context> = CreateLazyErrorComponent<Resource, Context>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { CreateBoundLazyErrorComponent, CreateLazyRenderState, LazyDefaultState };
|
|
33
|
+
//# sourceMappingURL=create-render-state.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-render-state.d.mts","names":[],"sources":["../../src/lazy/create-render-state.tsx"],"mappings":";;;;;;;;;KAyBY,gBAAA;AAAA,KACP,YAAA,eACW,gBAAA,cAEZ,KAAA,mBACA,sBAAA,CAAuB,QAAA;EACrB,QAAA,EAAU,QAAA;AAAA;;KAGX,mBAAA,4BACW,OAAA,GAAU,OAAA,CAAQ,GAAA;EAC1B,QAAA;EAAgB,WAAA;AAAA,IAClB,OAAA,CAAQ,GAAA;AAAA,KAGT,UAAA,eAAyB,gBAAA,gCAExB,KAAA,EAAO,KAAA,GAAQ,YAAA,CAAa,KAAA,EAAO,QAAA,GACnC,OAAA,EAAS,OAAA,KACN,SAAA,KACJ,KAAA,mBACG,iBAAA,CAAkB,QAAA,EAAU,KAAA,WAAgB,OAAA;;KAIxC,qBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,uBACd,oBAAA,yBAEA,gBAAA,uBACC,aAAA,6BACC,aAAA,CACpB,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,SAE1C,UAAA;EACA,KAAA,EAAO,KAAA;EACP,KAAA;IAAU,OAAA,GAAU,OAAA;IAAS,MAAA,GAAS,MAAA;EAAA;EACtC,MAAA,EAAQ,UAAA,CAAW,KAAA,EAAO,YAAA,CAAa,SAAA,GAAY,gBAAA,CAAiB,SAAA,EAAW,OAAA,EAAS,WAAA,EAAa,OAAA,EAAS,MAAA,GAAS,kBAAA,CAAmB,WAAA,EAAa,SAAA,EAAW,KAAA;AAAA,MAC9J,aAAA,CACJ,qBAAA,CACE,YAAA,CAAa,MAAA,IACX,8BAAA,CACE,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,GACxC,mBAAA,CAAoB,OAAA,MAGxB,YAAA,CAAa,KAAA,EAAO,YAAA,CAAa,SAAA;;KAIzB,6BAAA,sBACV,wBAAA,CAAyB,QAAA,EAAU,OAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { LayoutConfigurationError } from "../errors/layout-configuration-error.mjs";
|
|
2
|
+
import { defineResourceLayout } from "../create-config/define-layout.mjs";
|
|
3
|
+
import { createElement } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-render-state.tsx
|
|
6
|
+
function createLazyRenderStateBuilder(configuration) {
|
|
7
|
+
function createRenderState(definition) {
|
|
8
|
+
if (definition.state !== "Loading" && definition.state !== "Error") throw new LayoutConfigurationError(`Unknown lazy default state "${definition.state}"`);
|
|
9
|
+
const include = Object.fromEntries(Object.entries(definition.props?.include ?? {}).map(([key, behavior]) => [key, behavior === true ? {
|
|
10
|
+
required: true,
|
|
11
|
+
suppliedVia: "component"
|
|
12
|
+
} : behavior]));
|
|
13
|
+
function RenderLazyDefault({ props, context }) {
|
|
14
|
+
if (typeof definition.render === "function") return definition.render(props, context);
|
|
15
|
+
const errorProps = props;
|
|
16
|
+
const handler = definition.render[errorProps.error.code] ?? definition.render.fallback;
|
|
17
|
+
if (!handler) throw errorProps.error;
|
|
18
|
+
return handler(props, context);
|
|
19
|
+
}
|
|
20
|
+
const layout = defineResourceLayout({
|
|
21
|
+
resources: configuration.resources,
|
|
22
|
+
options: configuration.options,
|
|
23
|
+
layout: { render: {
|
|
24
|
+
default: () => null,
|
|
25
|
+
[definition.state]: {
|
|
26
|
+
composables: configuration.composables,
|
|
27
|
+
props: {
|
|
28
|
+
include,
|
|
29
|
+
custom: definition.props?.custom
|
|
30
|
+
},
|
|
31
|
+
render: (props, context) => createElement(RenderLazyDefault, {
|
|
32
|
+
props,
|
|
33
|
+
context
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
} }
|
|
37
|
+
});
|
|
38
|
+
const components = /* @__PURE__ */ new Map();
|
|
39
|
+
function LazyDefault(props) {
|
|
40
|
+
const resource = props.resource.split(".")[0];
|
|
41
|
+
let Component = components.get(resource);
|
|
42
|
+
if (!Component) {
|
|
43
|
+
Component = layout.createResourceLayout({
|
|
44
|
+
resource,
|
|
45
|
+
name: "LazyDefault",
|
|
46
|
+
namespace: false
|
|
47
|
+
})[definition.state];
|
|
48
|
+
components.set(resource, Component);
|
|
49
|
+
}
|
|
50
|
+
return createElement(Component, props);
|
|
51
|
+
}
|
|
52
|
+
return LazyDefault;
|
|
53
|
+
}
|
|
54
|
+
return createRenderState;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { createLazyRenderStateBuilder };
|
|
59
|
+
//# sourceMappingURL=create-render-state.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-render-state.mjs","names":[],"sources":["../../src/lazy/create-render-state.tsx"],"sourcesContent":["import { createElement, type ComponentType, type ReactNode } from 'react';\nimport type { ComposableComponents } from '@jfdevelops/react-layout-composables';\nimport { LayoutConfigurationError } from '../errors';\nimport type { ResourceDefinition, ResourcePath } from '../resource';\nimport {\n type ResolvedIncludedComponentProps,\n type IncludedProps,\n type InPropsDefinition,\n type InPropsObject,\n type MergedLayoutInProps,\n} from '../props';\nimport { defineResourceLayout } from '../create-config/define-layout';\nimport type {\n LayoutComposablesDefinition,\n RenderStateContext,\n RenderStateProps,\n OptionalStateChildren,\n} from '../create-config/render-state';\nimport type { ResolveProps } from '@jfdevelops/react-layout-validator';\nimport type {\n LazyResourceErrorProps,\n LazyErrorHandlers,\n CreateLazyErrorComponent,\n} from './types';\n\nexport type LazyDefaultState = 'Loading' | 'Error';\ntype BuiltinProps<\n State extends LazyDefaultState,\n Resource,\n> = State extends 'Error'\n ? LazyResourceErrorProps<Resource>\n : { resource: Resource };\n\n/** Shorthand includes are direct props; explicit supply sources retain their contract. */\ntype LazyDefaultIncludes<Include> = {\n [Key in keyof Include]: Include[Key] extends true\n ? { required: true; suppliedVia: 'component' }\n : Include[Key];\n};\n\ntype LazyRender<State extends LazyDefaultState, Resource, Props, Context> =\n | ((\n props: Props & BuiltinProps<State, Resource>,\n context: Context,\n ) => ReactNode)\n | (State extends 'Error'\n ? LazyErrorHandlers<Resource, Props & object, Context>\n : never);\n\n/** Creates validated, composable-aware fallback components for one factory. */\nexport type CreateLazyRenderState<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n> = <\n const State extends LazyDefaultState,\n const Custom extends InPropsObject = {},\n const Include extends IncludedProps<\n MergedLayoutInProps<Resources, Options, Composables>\n > = {},\n>(definition: {\n state: State;\n props?: { include?: Include; custom?: Custom };\n render: LazyRender<State, ResourcePath<Resources>, RenderStateProps<Resources, Options, Composables, Include, Custom>, RenderStateContext<Composables, Resources, State>>;\n}) => ComponentType<\n OptionalStateChildren<\n ResolveProps<Custom> &\n ResolvedIncludedComponentProps<\n MergedLayoutInProps<Resources, Options, Composables>,\n LazyDefaultIncludes<Include>\n >\n > &\n BuiltinProps<State, ResourcePath<Resources>>\n>;\n\n/** Compatibility helper; custom props keep their existing unchecked contract. */\nexport type CreateBoundLazyErrorComponent<Resource, Context> =\n CreateLazyErrorComponent<Resource, Context>;\n\ntype RuntimeDefinition = {\n state: LazyDefaultState;\n props?: { include?: Record<string, unknown>; custom?: InPropsObject };\n render:\n | ((props: any, context: any) => ReactNode)\n | LazyErrorHandlers<string, object, any>;\n};\n\nexport function createLazyRenderStateBuilder<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n>(configuration: {\n resources: Resources;\n options: Options;\n composables?: LayoutComposablesDefinition<Resources, Composables>;\n}): CreateLazyRenderState<Resources, Options, Composables> {\n function createRenderState(definition: RuntimeDefinition) {\n if (definition.state !== 'Loading' && definition.state !== 'Error') {\n throw new LayoutConfigurationError(\n `Unknown lazy default state \"${definition.state}\"`,\n );\n }\n // Lazy defaults have no create-time configuration call. Included values are\n // supplied by their component caller unless an explicit config source is selected.\n const include = Object.fromEntries(\n Object.entries(definition.props?.include ?? {}).map(([key, behavior]) => [\n key,\n behavior === true\n ? { required: true, suppliedVia: 'component' }\n : behavior,\n ]),\n );\n function RenderLazyDefault({\n props,\n context,\n }: {\n props: any;\n context: any;\n }) {\n if (typeof definition.render === 'function') {\n return definition.render(props, context);\n }\n const errorProps = props as LazyResourceErrorProps;\n const handler =\n definition.render[errorProps.error.code] ?? definition.render.fallback;\n if (!handler) throw errorProps.error;\n return handler(props as never, context);\n }\n const layout = defineResourceLayout({\n resources: configuration.resources,\n options: configuration.options,\n layout: {\n render: {\n default: () => null,\n [definition.state]: {\n composables: configuration.composables,\n props: { include, custom: definition.props?.custom },\n render: (props: any, context: any) =>\n createElement(RenderLazyDefault, { props, context }),\n },\n },\n },\n } as never);\n const components = new Map<string, ComponentType<any>>();\n function LazyDefault(props: { resource: string }) {\n // Nested lazy paths use the factory's top-level resource definitions for\n // option resolution. The callback still receives the complete path.\n const resource = props.resource.split('.')[0]!;\n let Component = components.get(resource);\n if (!Component) {\n const Root = layout.createResourceLayout({\n resource,\n name: 'LazyDefault',\n namespace: false,\n } as never) as unknown as Record<LazyDefaultState, ComponentType<any>>;\n Component = Root[definition.state];\n components.set(resource, Component);\n }\n return createElement(Component, props);\n }\n return LazyDefault;\n }\n return createRenderState as CreateLazyRenderState<\n Resources,\n Options,\n Composables\n >;\n}\n"],"mappings":";;;;;AAuFA,SAAgB,6BAId,eAIyD;CACzD,SAAS,kBAAkB,YAA+B;EACxD,IAAI,WAAW,UAAU,aAAa,WAAW,UAAU,SACzD,MAAM,IAAI,yBACR,+BAA+B,WAAW,MAAM,EAClD;EAIF,MAAM,UAAU,OAAO,YACrB,OAAO,QAAQ,WAAW,OAAO,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,cAAc,CACvE,KACA,aAAa,OACT;GAAE,UAAU;GAAM,aAAa;EAAY,IAC3C,QACN,CAAC,CACH;EACA,SAAS,kBAAkB,EACzB,OACA,WAIC;GACD,IAAI,OAAO,WAAW,WAAW,YAC/B,OAAO,WAAW,OAAO,OAAO,OAAO;GAEzC,MAAM,aAAa;GACnB,MAAM,UACJ,WAAW,OAAO,WAAW,MAAM,SAAS,WAAW,OAAO;GAChE,IAAI,CAAC,SAAS,MAAM,WAAW;GAC/B,OAAO,QAAQ,OAAgB,OAAO;EACxC;EACA,MAAM,SAAS,qBAAqB;GAClC,WAAW,cAAc;GACzB,SAAS,cAAc;GACvB,QAAQ,EACN,QAAQ;IACN,eAAe;KACd,WAAW,QAAQ;KAClB,aAAa,cAAc;KAC3B,OAAO;MAAE;MAAS,QAAQ,WAAW,OAAO;KAAO;KACnD,SAAS,OAAY,YACnB,cAAc,mBAAmB;MAAE;MAAO;KAAQ,CAAC;IACvD;GACF,EACF;EACF,CAAU;EACV,MAAM,6BAAa,IAAI,IAAgC;EACvD,SAAS,YAAY,OAA6B;GAGhD,MAAM,WAAW,MAAM,SAAS,MAAM,GAAG,EAAE;GAC3C,IAAI,YAAY,WAAW,IAAI,QAAQ;GACvC,IAAI,CAAC,WAAW;IAMd,YALa,OAAO,qBAAqB;KACvC;KACA,MAAM;KACN,WAAW;IACb,CACe,EAAE,WAAW;IAC5B,WAAW,IAAI,UAAU,SAAS;GACpC;GACA,OAAO,cAAc,WAAW,KAAK;EACvC;EACA,OAAO;CACT;CACA,OAAO;AAKT"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_render_state_context = require('../create-config/render-state-context.cjs');
|
|
1
2
|
const require_lazy_resource_error = require('../errors/lazy-resource-error.cjs');
|
|
2
3
|
let react = require("react");
|
|
3
4
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -25,10 +26,13 @@ var LazyErrorBoundary = class extends react.Component {
|
|
|
25
26
|
if (!this.state.failed) return this.props.children;
|
|
26
27
|
const { ErrorComponent, resource } = this.props;
|
|
27
28
|
if (!require_lazy_resource_error.isLazyResourceError(this.state.error) || !ErrorComponent) throw this.state.error;
|
|
28
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_render_state_context.RenderStateFallback, {
|
|
30
|
+
state: "Error",
|
|
31
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, {
|
|
32
|
+
error: this.state.error,
|
|
33
|
+
retry: this.retry,
|
|
34
|
+
resource
|
|
35
|
+
})
|
|
32
36
|
});
|
|
33
37
|
}
|
|
34
38
|
};
|
|
@@ -36,6 +40,7 @@ var LazyErrorBoundary = class extends react.Component {
|
|
|
36
40
|
function LazyBoundary({ loader, member, resource, fallback, ErrorComponent, componentProps, onMount, map }) {
|
|
37
41
|
const [, rerender] = (0, react.useReducer)((value) => value + 1, 0);
|
|
38
42
|
(0, react.useEffect)(() => onMount?.(), [onMount]);
|
|
43
|
+
const Current = loader.component(member, map);
|
|
39
44
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LazyErrorBoundary, {
|
|
40
45
|
resource,
|
|
41
46
|
ErrorComponent,
|
|
@@ -44,8 +49,11 @@ function LazyBoundary({ loader, member, resource, fallback, ErrorComponent, comp
|
|
|
44
49
|
rerender();
|
|
45
50
|
},
|
|
46
51
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
|
|
47
|
-
fallback,
|
|
48
|
-
|
|
52
|
+
fallback: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_render_state_context.RenderStateFallback, {
|
|
53
|
+
state: "Loading",
|
|
54
|
+
children: fallback
|
|
55
|
+
}),
|
|
56
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Current, { ...componentProps })
|
|
49
57
|
})
|
|
50
58
|
});
|
|
51
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-boundary.cjs","names":["Component","isLazyResourceError","Suspense"],"sources":["../../src/lazy/lazy-boundary.tsx"],"sourcesContent":["import {\n Component,\n Suspense,\n useEffect,\n useReducer,\n type ReactNode,\n} from 'react';\nimport { isLazyResourceError } from '../errors/lazy-resource-error';\nimport type { LazyResourceErrorComponent } from './types';\nimport type { LazyLoader } from './create-lazy-loader';\n\ntype BoundaryProps = {\n children: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n resource: string;\n onRetry: () => void;\n};\n\nclass LazyErrorBoundary extends Component<\n BoundaryProps,\n { failed: boolean; error?: unknown }\n> {\n state = { failed: false, error: undefined as unknown };\n static getDerivedStateFromError(error: unknown) {\n return { failed: true, error };\n }\n retry = () => {\n this.props.onRetry();\n this.setState({ failed: false, error: undefined });\n };\n render() {\n if (!this.state.failed) return this.props.children;\n const { ErrorComponent, resource } = this.props;\n if (!isLazyResourceError(this.state.error) || !ErrorComponent)\n throw this.state.error;\n return (\n <ErrorComponent\n
|
|
1
|
+
{"version":3,"file":"lazy-boundary.cjs","names":["Component","isLazyResourceError","RenderStateFallback","Suspense"],"sources":["../../src/lazy/lazy-boundary.tsx"],"sourcesContent":["import { RenderStateFallback } from '../create-config/render-state-context';\nimport {\n Component,\n Suspense,\n useEffect,\n useReducer,\n type ReactNode,\n} from 'react';\nimport { isLazyResourceError } from '../errors/lazy-resource-error';\nimport type { LazyResourceErrorComponent } from './types';\nimport type { LazyLoader } from './create-lazy-loader';\n\ntype BoundaryProps = {\n children: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n resource: string;\n onRetry: () => void;\n};\n\nclass LazyErrorBoundary extends Component<\n BoundaryProps,\n { failed: boolean; error?: unknown }\n> {\n state = { failed: false, error: undefined as unknown };\n static getDerivedStateFromError(error: unknown) {\n return { failed: true, error };\n }\n retry = () => {\n this.props.onRetry();\n this.setState({ failed: false, error: undefined });\n };\n render() {\n if (!this.state.failed) return this.props.children;\n const { ErrorComponent, resource } = this.props;\n if (!isLazyResourceError(this.state.error) || !ErrorComponent)\n throw this.state.error;\n return (\n <RenderStateFallback state=\"Error\">\n <ErrorComponent\n error={this.state.error}\n retry={this.retry}\n resource={resource}\n />\n </RenderStateFallback>\n );\n }\n}\n\n/** Shared loading, typed error handling and retry for all lazy components. */\nexport function LazyBoundary({\n loader,\n member,\n resource,\n fallback,\n ErrorComponent,\n componentProps,\n onMount,\n map,\n}: {\n loader: LazyLoader<any>;\n member?: PropertyKey;\n map?: (selected: any) => React.ComponentType<any>;\n resource: string;\n fallback?: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n componentProps: Record<string, unknown>;\n onMount?: () => (() => void) | undefined;\n}) {\n const [, rerender] = useReducer((value) => value + 1, 0);\n useEffect(() => onMount?.(), [onMount]);\n const Current = loader.component(member, map);\n return (\n <LazyErrorBoundary\n resource={resource}\n ErrorComponent={ErrorComponent}\n onRetry={() => {\n loader.reset();\n rerender();\n }}\n >\n <Suspense fallback={\n <RenderStateFallback state=\"Loading\">{fallback}</RenderStateFallback>\n }>\n <Current {...componentProps} />\n </Suspense>\n </LazyErrorBoundary>\n );\n}\n"],"mappings":";;;;;;AAmBA,IAAM,oBAAN,cAAgCA,gBAG9B;CACA,QAAQ;EAAE,QAAQ;EAAO,OAAO;CAAqB;CACrD,OAAO,yBAAyB,OAAgB;EAC9C,OAAO;GAAE,QAAQ;GAAM;EAAM;CAC/B;CACA,cAAc;EACZ,KAAK,MAAM,QAAQ;EACnB,KAAK,SAAS;GAAE,QAAQ;GAAO,OAAO;EAAU,CAAC;CACnD;CACA,SAAS;EACP,IAAI,CAAC,KAAK,MAAM,QAAQ,OAAO,KAAK,MAAM;EAC1C,MAAM,EAAE,gBAAgB,aAAa,KAAK;EAC1C,IAAI,CAACC,gDAAoB,KAAK,MAAM,KAAK,KAAK,CAAC,gBAC7C,MAAM,KAAK,MAAM;EACnB,OACE,2CAACC,kDAAD;GAAqB,OAAM;aACzB,2CAAC,gBAAD;IACE,OAAO,KAAK,MAAM;IAClB,OAAO,KAAK;IACF;GACX;EACkB;CAEzB;AACF;;AAGA,SAAgB,aAAa,EAC3B,QACA,QACA,UACA,UACA,gBACA,gBACA,SACA,OAUC;CACD,MAAM,GAAG,mCAAwB,UAAU,QAAQ,GAAG,CAAC;CACvD,2BAAgB,UAAU,GAAG,CAAC,OAAO,CAAC;CACtC,MAAM,UAAU,OAAO,UAAU,QAAQ,GAAG;CAC5C,OACE,2CAAC,mBAAD;EACY;EACM;EAChB,eAAe;GACb,OAAO,MAAM;GACb,SAAS;EACX;YAEA,2CAACC,gBAAD;GAAU,UACR,2CAACD,kDAAD;IAAqB,OAAM;cAAW;GAA8B;aAEpE,2CAAC,SAAD,EAAS,GAAI,eAAiB;EACtB;CACO;AAEvB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RenderStateFallback } from "../create-config/render-state-context.mjs";
|
|
1
2
|
import { isLazyResourceError } from "../errors/lazy-resource-error.mjs";
|
|
2
3
|
import { Component, Suspense, useEffect, useReducer } from "react";
|
|
3
4
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -25,10 +26,13 @@ var LazyErrorBoundary = class extends Component {
|
|
|
25
26
|
if (!this.state.failed) return this.props.children;
|
|
26
27
|
const { ErrorComponent, resource } = this.props;
|
|
27
28
|
if (!isLazyResourceError(this.state.error) || !ErrorComponent) throw this.state.error;
|
|
28
|
-
return /* @__PURE__ */ jsx(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
return /* @__PURE__ */ jsx(RenderStateFallback, {
|
|
30
|
+
state: "Error",
|
|
31
|
+
children: /* @__PURE__ */ jsx(ErrorComponent, {
|
|
32
|
+
error: this.state.error,
|
|
33
|
+
retry: this.retry,
|
|
34
|
+
resource
|
|
35
|
+
})
|
|
32
36
|
});
|
|
33
37
|
}
|
|
34
38
|
};
|
|
@@ -36,6 +40,7 @@ var LazyErrorBoundary = class extends Component {
|
|
|
36
40
|
function LazyBoundary({ loader, member, resource, fallback, ErrorComponent, componentProps, onMount, map }) {
|
|
37
41
|
const [, rerender] = useReducer((value) => value + 1, 0);
|
|
38
42
|
useEffect(() => onMount?.(), [onMount]);
|
|
43
|
+
const Current = loader.component(member, map);
|
|
39
44
|
return /* @__PURE__ */ jsx(LazyErrorBoundary, {
|
|
40
45
|
resource,
|
|
41
46
|
ErrorComponent,
|
|
@@ -44,8 +49,11 @@ function LazyBoundary({ loader, member, resource, fallback, ErrorComponent, comp
|
|
|
44
49
|
rerender();
|
|
45
50
|
},
|
|
46
51
|
children: /* @__PURE__ */ jsx(Suspense, {
|
|
47
|
-
fallback,
|
|
48
|
-
|
|
52
|
+
fallback: /* @__PURE__ */ jsx(RenderStateFallback, {
|
|
53
|
+
state: "Loading",
|
|
54
|
+
children: fallback
|
|
55
|
+
}),
|
|
56
|
+
children: /* @__PURE__ */ jsx(Current, { ...componentProps })
|
|
49
57
|
})
|
|
50
58
|
});
|
|
51
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-boundary.mjs","names":[],"sources":["../../src/lazy/lazy-boundary.tsx"],"sourcesContent":["import {\n Component,\n Suspense,\n useEffect,\n useReducer,\n type ReactNode,\n} from 'react';\nimport { isLazyResourceError } from '../errors/lazy-resource-error';\nimport type { LazyResourceErrorComponent } from './types';\nimport type { LazyLoader } from './create-lazy-loader';\n\ntype BoundaryProps = {\n children: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n resource: string;\n onRetry: () => void;\n};\n\nclass LazyErrorBoundary extends Component<\n BoundaryProps,\n { failed: boolean; error?: unknown }\n> {\n state = { failed: false, error: undefined as unknown };\n static getDerivedStateFromError(error: unknown) {\n return { failed: true, error };\n }\n retry = () => {\n this.props.onRetry();\n this.setState({ failed: false, error: undefined });\n };\n render() {\n if (!this.state.failed) return this.props.children;\n const { ErrorComponent, resource } = this.props;\n if (!isLazyResourceError(this.state.error) || !ErrorComponent)\n throw this.state.error;\n return (\n <ErrorComponent\n
|
|
1
|
+
{"version":3,"file":"lazy-boundary.mjs","names":[],"sources":["../../src/lazy/lazy-boundary.tsx"],"sourcesContent":["import { RenderStateFallback } from '../create-config/render-state-context';\nimport {\n Component,\n Suspense,\n useEffect,\n useReducer,\n type ReactNode,\n} from 'react';\nimport { isLazyResourceError } from '../errors/lazy-resource-error';\nimport type { LazyResourceErrorComponent } from './types';\nimport type { LazyLoader } from './create-lazy-loader';\n\ntype BoundaryProps = {\n children: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n resource: string;\n onRetry: () => void;\n};\n\nclass LazyErrorBoundary extends Component<\n BoundaryProps,\n { failed: boolean; error?: unknown }\n> {\n state = { failed: false, error: undefined as unknown };\n static getDerivedStateFromError(error: unknown) {\n return { failed: true, error };\n }\n retry = () => {\n this.props.onRetry();\n this.setState({ failed: false, error: undefined });\n };\n render() {\n if (!this.state.failed) return this.props.children;\n const { ErrorComponent, resource } = this.props;\n if (!isLazyResourceError(this.state.error) || !ErrorComponent)\n throw this.state.error;\n return (\n <RenderStateFallback state=\"Error\">\n <ErrorComponent\n error={this.state.error}\n retry={this.retry}\n resource={resource}\n />\n </RenderStateFallback>\n );\n }\n}\n\n/** Shared loading, typed error handling and retry for all lazy components. */\nexport function LazyBoundary({\n loader,\n member,\n resource,\n fallback,\n ErrorComponent,\n componentProps,\n onMount,\n map,\n}: {\n loader: LazyLoader<any>;\n member?: PropertyKey;\n map?: (selected: any) => React.ComponentType<any>;\n resource: string;\n fallback?: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n componentProps: Record<string, unknown>;\n onMount?: () => (() => void) | undefined;\n}) {\n const [, rerender] = useReducer((value) => value + 1, 0);\n useEffect(() => onMount?.(), [onMount]);\n const Current = loader.component(member, map);\n return (\n <LazyErrorBoundary\n resource={resource}\n ErrorComponent={ErrorComponent}\n onRetry={() => {\n loader.reset();\n rerender();\n }}\n >\n <Suspense fallback={\n <RenderStateFallback state=\"Loading\">{fallback}</RenderStateFallback>\n }>\n <Current {...componentProps} />\n </Suspense>\n </LazyErrorBoundary>\n );\n}\n"],"mappings":";;;;;;AAmBA,IAAM,oBAAN,cAAgC,UAG9B;CACA,QAAQ;EAAE,QAAQ;EAAO,OAAO;CAAqB;CACrD,OAAO,yBAAyB,OAAgB;EAC9C,OAAO;GAAE,QAAQ;GAAM;EAAM;CAC/B;CACA,cAAc;EACZ,KAAK,MAAM,QAAQ;EACnB,KAAK,SAAS;GAAE,QAAQ;GAAO,OAAO;EAAU,CAAC;CACnD;CACA,SAAS;EACP,IAAI,CAAC,KAAK,MAAM,QAAQ,OAAO,KAAK,MAAM;EAC1C,MAAM,EAAE,gBAAgB,aAAa,KAAK;EAC1C,IAAI,CAAC,oBAAoB,KAAK,MAAM,KAAK,KAAK,CAAC,gBAC7C,MAAM,KAAK,MAAM;EACnB,OACE,oBAAC,qBAAD;GAAqB,OAAM;aACzB,oBAAC,gBAAD;IACE,OAAO,KAAK,MAAM;IAClB,OAAO,KAAK;IACF;GACX;EACkB;CAEzB;AACF;;AAGA,SAAgB,aAAa,EAC3B,QACA,QACA,UACA,UACA,gBACA,gBACA,SACA,OAUC;CACD,MAAM,GAAG,YAAY,YAAY,UAAU,QAAQ,GAAG,CAAC;CACvD,gBAAgB,UAAU,GAAG,CAAC,OAAO,CAAC;CACtC,MAAM,UAAU,OAAO,UAAU,QAAQ,GAAG;CAC5C,OACE,oBAAC,mBAAD;EACY;EACM;EAChB,eAAe;GACb,OAAO,MAAM;GACb,SAAS;EACX;YAEA,oBAAC,UAAD;GAAU,UACR,oBAAC,qBAAD;IAAqB,OAAM;cAAW;GAA8B;aAEpE,oBAAC,SAAD,EAAS,GAAI,eAAiB;EACtB;CACO;AAEvB"}
|
package/dist/lazy/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","names":[],"sources":["../../src/lazy/types.ts"],"sourcesContent":["import type { ComponentType, ReactNode } from 'react';\nimport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\nimport type {\n LazyResourceError,\n LazyResourceErrorMap,\n} from '../errors/lazy-resource-error';\n\nexport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\n\n/** Options shared by lazy layouts, render states, and scoped content. */\nexport type LazyOptions<\n Module extends Record<string, unknown> = Record<string, unknown>,\n> = {\n load: () => Promise<Module>;\n fallback?: ReactNode;\n};\n\nexport type LazyHandle = {\n preload(): Promise<void>;\n readonly status: LoadStatus;\n};\n\nexport type LazyResourceErrorProps<Resource = string> = {\n error: LazyResourceError;\n retry: () => void;\n resource: Resource;\n};\n\nexport type LazyResourceErrorComponent<Resource = string> = ComponentType<\n LazyResourceErrorProps<Resource>\n>;\nexport type LazyResourceLoadingComponent<Resource = string> = ComponentType<{\n resource: Resource;\n}>;\nexport type LazyResourceStates<Resource = string> = {\n Error?: LazyResourceErrorComponent<Resource>;\n Loading?: LazyResourceLoadingComponent<Resource>;\n};\n\nexport type LazyErrorHandlers
|
|
1
|
+
{"version":3,"file":"types.cjs","names":[],"sources":["../../src/lazy/types.ts"],"sourcesContent":["import type { ComponentType, ReactNode } from 'react';\nimport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\nimport type {\n LazyResourceError,\n LazyResourceErrorMap,\n} from '../errors/lazy-resource-error';\n\nexport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\n\n/** Options shared by lazy layouts, render states, and scoped content. */\nexport type LazyOptions<\n Module extends Record<string, unknown> = Record<string, unknown>,\n> = {\n load: () => Promise<Module>;\n fallback?: ReactNode;\n};\n\nexport type LazyHandle = {\n preload(): Promise<void>;\n readonly status: LoadStatus;\n};\n\nexport type LazyResourceErrorProps<Resource = string> = {\n error: LazyResourceError;\n retry: () => void;\n resource: Resource;\n};\n\nexport type LazyResourceErrorComponent<Resource = string> = ComponentType<\n LazyResourceErrorProps<Resource>\n>;\nexport type LazyResourceLoadingComponent<Resource = string> = ComponentType<{\n resource: Resource;\n}>;\nexport type LazyResourceStates<Resource = string> = {\n Error?: LazyResourceErrorComponent<Resource>;\n Loading?: LazyResourceLoadingComponent<Resource>;\n};\n\ntype ErrorHandlerContext<Context> = [Context] extends [never]\n ? []\n : [context: Context];\n\nexport type LazyErrorHandlers<\n Resource,\n Custom extends object = {},\n Context = never,\n> = {\n [Code in LazyResourceError['code']]?: (\n props: Custom &\n Omit<LazyResourceErrorProps<Resource>, 'error'> & {\n error: LazyResourceErrorMap[Code];\n },\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode;\n} & {\n fallback?: (\n props: Custom & LazyResourceErrorProps<Resource>,\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode;\n};\n\nexport type CreateLazyErrorComponent<Resource, Context = never> = {\n <Custom extends object = {}>(\n render: (\n props: Custom & LazyResourceErrorProps<Resource>,\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n <Custom extends object = {}>(\n handlers: LazyErrorHandlers<Resource, Custom, Context>,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n};\n\n/** Internal factory defaults propagated to layouts without publishing metadata. */\nexport const lazyDefaultsSymbol = Symbol('lazyDefaults');\n\nexport const lazyStatesSymbol = Symbol('lazyStates');\n"],"mappings":";;;AA2EA,MAAa,qBAAqB,OAAO,cAAc;AAEvD,MAAa,mBAAmB,OAAO,YAAY"}
|
package/dist/lazy/types.d.cts
CHANGED
|
@@ -25,14 +25,15 @@ type LazyResourceStates<Resource = string> = {
|
|
|
25
25
|
Error?: LazyResourceErrorComponent<Resource>;
|
|
26
26
|
Loading?: LazyResourceLoadingComponent<Resource>;
|
|
27
27
|
};
|
|
28
|
-
type
|
|
28
|
+
type ErrorHandlerContext<Context> = [Context] extends [never] ? [] : [context: Context];
|
|
29
|
+
type LazyErrorHandlers<Resource, Custom extends object = {}, Context = never> = { [Code in LazyResourceError['code']]?: (props: Custom & Omit<LazyResourceErrorProps<Resource>, 'error'> & {
|
|
29
30
|
error: LazyResourceErrorMap[Code];
|
|
30
|
-
}) => ReactNode } & {
|
|
31
|
-
fallback?: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode;
|
|
31
|
+
}, ...context: ErrorHandlerContext<Context>) => ReactNode } & {
|
|
32
|
+
fallback?: (props: Custom & LazyResourceErrorProps<Resource>, ...context: ErrorHandlerContext<Context>) => ReactNode;
|
|
32
33
|
};
|
|
33
|
-
type CreateLazyErrorComponent<Resource> = {
|
|
34
|
-
<Custom extends object = {}>(render: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
35
|
-
<Custom extends object = {}>(handlers: LazyErrorHandlers<Resource, Custom>): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
34
|
+
type CreateLazyErrorComponent<Resource, Context = never> = {
|
|
35
|
+
<Custom extends object = {}>(render: (props: Custom & LazyResourceErrorProps<Resource>, ...context: ErrorHandlerContext<Context>) => ReactNode): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
36
|
+
<Custom extends object = {}>(handlers: LazyErrorHandlers<Resource, Custom, Context>): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
36
37
|
};
|
|
37
38
|
//#endregion
|
|
38
39
|
export { CreateLazyErrorComponent, LazyErrorHandlers, LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceErrorProps, LazyResourceLoadingComponent, LazyResourceStates, type LoadStatus$1 as LoadStatus };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/lazy/types.ts"],"mappings":";;;;;;KAUY,WAAA,gBACK,MAAA,oBAA0B,MAAA;EAEzC,IAAA,QAAY,OAAA,CAAQ,MAAA;EACpB,QAAA,GAAW,SAAA;AAAA;AAAA,KAGD,UAAA;EACV,OAAA,IAAW,OAAA;EAAA,SACF,MAAA,EAAQ,UAAU;AAAA;AAAA,KAGjB,sBAAA;EACV,KAAA,EAAO,iBAAA;EACP,KAAA;EACA,QAAA,EAAU,QAAQ;AAAA;AAAA,KAGR,0BAAA,sBAAgD,aAAA,CAC1D,sBAAA,CAAuB,QAAA;AAAA,KAEb,4BAAA,sBAAkD,aAAa;EACzE,QAAA,EAAU,QAAA;AAAA;AAAA,KAEA,kBAAA;EACV,KAAA,GAAQ,0BAAA,CAA2B,QAAA;EACnC,OAAA,GAAU,4BAAA,CAA6B,QAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/lazy/types.ts"],"mappings":";;;;;;KAUY,WAAA,gBACK,MAAA,oBAA0B,MAAA;EAEzC,IAAA,QAAY,OAAA,CAAQ,MAAA;EACpB,QAAA,GAAW,SAAA;AAAA;AAAA,KAGD,UAAA;EACV,OAAA,IAAW,OAAA;EAAA,SACF,MAAA,EAAQ,UAAU;AAAA;AAAA,KAGjB,sBAAA;EACV,KAAA,EAAO,iBAAA;EACP,KAAA;EACA,QAAA,EAAU,QAAQ;AAAA;AAAA,KAGR,0BAAA,sBAAgD,aAAA,CAC1D,sBAAA,CAAuB,QAAA;AAAA,KAEb,4BAAA,sBAAkD,aAAa;EACzE,QAAA,EAAU,QAAA;AAAA;AAAA,KAEA,kBAAA;EACV,KAAA,GAAQ,0BAAA,CAA2B,QAAA;EACnC,OAAA,GAAU,4BAAA,CAA6B,QAAA;AAAA;AAAA,KAGpC,mBAAA,aAAgC,OAAA,0BAEhC,OAAA,EAAS,OAAO;AAAA,KAET,iBAAA,qEAKD,iBAAA,aACP,KAAA,EAAO,MAAA,GACL,IAAA,CAAK,sBAAA,CAAuB,QAAA;EAC1B,KAAA,EAAO,oBAAA,CAAqB,IAAA;AAAA,MAE7B,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA;EAEL,QAAA,IACE,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MACpC,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA;AAAA;AAAA,KAGK,wBAAA;EAAA,6BAER,MAAA,GACE,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MACpC,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA,GACJ,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;EAAA,6BAE/C,QAAA,EAAU,iBAAA,CAAkB,QAAA,EAAU,MAAA,EAAQ,OAAA,IAC7C,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;AAAA"}
|
package/dist/lazy/types.d.mts
CHANGED
|
@@ -25,14 +25,15 @@ type LazyResourceStates<Resource = string> = {
|
|
|
25
25
|
Error?: LazyResourceErrorComponent<Resource>;
|
|
26
26
|
Loading?: LazyResourceLoadingComponent<Resource>;
|
|
27
27
|
};
|
|
28
|
-
type
|
|
28
|
+
type ErrorHandlerContext<Context> = [Context] extends [never] ? [] : [context: Context];
|
|
29
|
+
type LazyErrorHandlers<Resource, Custom extends object = {}, Context = never> = { [Code in LazyResourceError['code']]?: (props: Custom & Omit<LazyResourceErrorProps<Resource>, 'error'> & {
|
|
29
30
|
error: LazyResourceErrorMap[Code];
|
|
30
|
-
}) => ReactNode } & {
|
|
31
|
-
fallback?: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode;
|
|
31
|
+
}, ...context: ErrorHandlerContext<Context>) => ReactNode } & {
|
|
32
|
+
fallback?: (props: Custom & LazyResourceErrorProps<Resource>, ...context: ErrorHandlerContext<Context>) => ReactNode;
|
|
32
33
|
};
|
|
33
|
-
type CreateLazyErrorComponent<Resource> = {
|
|
34
|
-
<Custom extends object = {}>(render: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
35
|
-
<Custom extends object = {}>(handlers: LazyErrorHandlers<Resource, Custom>): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
34
|
+
type CreateLazyErrorComponent<Resource, Context = never> = {
|
|
35
|
+
<Custom extends object = {}>(render: (props: Custom & LazyResourceErrorProps<Resource>, ...context: ErrorHandlerContext<Context>) => ReactNode): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
36
|
+
<Custom extends object = {}>(handlers: LazyErrorHandlers<Resource, Custom, Context>): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
36
37
|
};
|
|
37
38
|
//#endregion
|
|
38
39
|
export { CreateLazyErrorComponent, LazyErrorHandlers, LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceErrorProps, LazyResourceLoadingComponent, LazyResourceStates, type LoadStatus$1 as LoadStatus };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/lazy/types.ts"],"mappings":";;;;;;KAUY,WAAA,gBACK,MAAA,oBAA0B,MAAA;EAEzC,IAAA,QAAY,OAAA,CAAQ,MAAA;EACpB,QAAA,GAAW,SAAA;AAAA;AAAA,KAGD,UAAA;EACV,OAAA,IAAW,OAAA;EAAA,SACF,MAAA,EAAQ,UAAU;AAAA;AAAA,KAGjB,sBAAA;EACV,KAAA,EAAO,iBAAA;EACP,KAAA;EACA,QAAA,EAAU,QAAQ;AAAA;AAAA,KAGR,0BAAA,sBAAgD,aAAA,CAC1D,sBAAA,CAAuB,QAAA;AAAA,KAEb,4BAAA,sBAAkD,aAAa;EACzE,QAAA,EAAU,QAAA;AAAA;AAAA,KAEA,kBAAA;EACV,KAAA,GAAQ,0BAAA,CAA2B,QAAA;EACnC,OAAA,GAAU,4BAAA,CAA6B,QAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/lazy/types.ts"],"mappings":";;;;;;KAUY,WAAA,gBACK,MAAA,oBAA0B,MAAA;EAEzC,IAAA,QAAY,OAAA,CAAQ,MAAA;EACpB,QAAA,GAAW,SAAA;AAAA;AAAA,KAGD,UAAA;EACV,OAAA,IAAW,OAAA;EAAA,SACF,MAAA,EAAQ,UAAU;AAAA;AAAA,KAGjB,sBAAA;EACV,KAAA,EAAO,iBAAA;EACP,KAAA;EACA,QAAA,EAAU,QAAQ;AAAA;AAAA,KAGR,0BAAA,sBAAgD,aAAA,CAC1D,sBAAA,CAAuB,QAAA;AAAA,KAEb,4BAAA,sBAAkD,aAAa;EACzE,QAAA,EAAU,QAAA;AAAA;AAAA,KAEA,kBAAA;EACV,KAAA,GAAQ,0BAAA,CAA2B,QAAA;EACnC,OAAA,GAAU,4BAAA,CAA6B,QAAA;AAAA;AAAA,KAGpC,mBAAA,aAAgC,OAAA,0BAEhC,OAAA,EAAS,OAAO;AAAA,KAET,iBAAA,qEAKD,iBAAA,aACP,KAAA,EAAO,MAAA,GACL,IAAA,CAAK,sBAAA,CAAuB,QAAA;EAC1B,KAAA,EAAO,oBAAA,CAAqB,IAAA;AAAA,MAE7B,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA;EAEL,QAAA,IACE,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MACpC,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA;AAAA;AAAA,KAGK,wBAAA;EAAA,6BAER,MAAA,GACE,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MACpC,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA,GACJ,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;EAAA,6BAE/C,QAAA,EAAU,iBAAA,CAAkB,QAAA,EAAU,MAAA,EAAQ,OAAA,IAC7C,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;AAAA"}
|
package/dist/lazy/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/lazy/types.ts"],"sourcesContent":["import type { ComponentType, ReactNode } from 'react';\nimport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\nimport type {\n LazyResourceError,\n LazyResourceErrorMap,\n} from '../errors/lazy-resource-error';\n\nexport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\n\n/** Options shared by lazy layouts, render states, and scoped content. */\nexport type LazyOptions<\n Module extends Record<string, unknown> = Record<string, unknown>,\n> = {\n load: () => Promise<Module>;\n fallback?: ReactNode;\n};\n\nexport type LazyHandle = {\n preload(): Promise<void>;\n readonly status: LoadStatus;\n};\n\nexport type LazyResourceErrorProps<Resource = string> = {\n error: LazyResourceError;\n retry: () => void;\n resource: Resource;\n};\n\nexport type LazyResourceErrorComponent<Resource = string> = ComponentType<\n LazyResourceErrorProps<Resource>\n>;\nexport type LazyResourceLoadingComponent<Resource = string> = ComponentType<{\n resource: Resource;\n}>;\nexport type LazyResourceStates<Resource = string> = {\n Error?: LazyResourceErrorComponent<Resource>;\n Loading?: LazyResourceLoadingComponent<Resource>;\n};\n\nexport type LazyErrorHandlers
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/lazy/types.ts"],"sourcesContent":["import type { ComponentType, ReactNode } from 'react';\nimport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\nimport type {\n LazyResourceError,\n LazyResourceErrorMap,\n} from '../errors/lazy-resource-error';\n\nexport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\n\n/** Options shared by lazy layouts, render states, and scoped content. */\nexport type LazyOptions<\n Module extends Record<string, unknown> = Record<string, unknown>,\n> = {\n load: () => Promise<Module>;\n fallback?: ReactNode;\n};\n\nexport type LazyHandle = {\n preload(): Promise<void>;\n readonly status: LoadStatus;\n};\n\nexport type LazyResourceErrorProps<Resource = string> = {\n error: LazyResourceError;\n retry: () => void;\n resource: Resource;\n};\n\nexport type LazyResourceErrorComponent<Resource = string> = ComponentType<\n LazyResourceErrorProps<Resource>\n>;\nexport type LazyResourceLoadingComponent<Resource = string> = ComponentType<{\n resource: Resource;\n}>;\nexport type LazyResourceStates<Resource = string> = {\n Error?: LazyResourceErrorComponent<Resource>;\n Loading?: LazyResourceLoadingComponent<Resource>;\n};\n\ntype ErrorHandlerContext<Context> = [Context] extends [never]\n ? []\n : [context: Context];\n\nexport type LazyErrorHandlers<\n Resource,\n Custom extends object = {},\n Context = never,\n> = {\n [Code in LazyResourceError['code']]?: (\n props: Custom &\n Omit<LazyResourceErrorProps<Resource>, 'error'> & {\n error: LazyResourceErrorMap[Code];\n },\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode;\n} & {\n fallback?: (\n props: Custom & LazyResourceErrorProps<Resource>,\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode;\n};\n\nexport type CreateLazyErrorComponent<Resource, Context = never> = {\n <Custom extends object = {}>(\n render: (\n props: Custom & LazyResourceErrorProps<Resource>,\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n <Custom extends object = {}>(\n handlers: LazyErrorHandlers<Resource, Custom, Context>,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n};\n\n/** Internal factory defaults propagated to layouts without publishing metadata. */\nexport const lazyDefaultsSymbol = Symbol('lazyDefaults');\n\nexport const lazyStatesSymbol = Symbol('lazyStates');\n"],"mappings":";;AA2EA,MAAa,qBAAqB,OAAO,cAAc;AAEvD,MAAa,mBAAmB,OAAO,YAAY"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jfdevelops/react-layout",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A React library for creating layout components.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@jfdevelops/create-error": "0.2.0",
|
|
31
31
|
"arktype": "2.2.8",
|
|
32
32
|
"@jfdevelops/react-layout-composables": "0.3.1",
|
|
33
|
-
"@jfdevelops/react-layout-
|
|
34
|
-
"@jfdevelops/react-layout-
|
|
33
|
+
"@jfdevelops/react-layout-devtools-core": "0.3.0",
|
|
34
|
+
"@jfdevelops/react-layout-validator": "0.3.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": ">=18",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/lazy/create-error-component.tsx
|
|
3
|
-
/** Function inputs retain their identity; handler maps dispatch by error code. */
|
|
4
|
-
const createLazyErrorComponent = (input) => {
|
|
5
|
-
if (typeof input === "function") return input;
|
|
6
|
-
const handlers = input;
|
|
7
|
-
function LazyResourceErrorByCode(props) {
|
|
8
|
-
const handler = handlers[props.error.code] ?? handlers.fallback;
|
|
9
|
-
if (!handler) throw props.error;
|
|
10
|
-
return handler(props);
|
|
11
|
-
}
|
|
12
|
-
return LazyResourceErrorByCode;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
exports.createLazyErrorComponent = createLazyErrorComponent;
|
|
17
|
-
//# sourceMappingURL=create-error-component.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-error-component.cjs","names":[],"sources":["../../src/lazy/create-error-component.tsx"],"sourcesContent":["import type {\n CreateLazyErrorComponent,\n LazyErrorHandlers,\n LazyResourceErrorProps,\n} from './types';\n\n/** Function inputs retain their identity; handler maps dispatch by error code. */\nexport const createLazyErrorComponent: CreateLazyErrorComponent<string> = (\n input:\n | ((props: LazyResourceErrorProps) => React.ReactNode)\n | LazyErrorHandlers<string>,\n) => {\n if (typeof input === 'function') return input;\n const handlers = input;\n function LazyResourceErrorByCode(props: LazyResourceErrorProps) {\n const handler = handlers[props.error.code] ?? handlers.fallback;\n if (!handler) throw props.error;\n return handler(props as never);\n }\n return LazyResourceErrorByCode;\n};\n"],"mappings":";;;AAOA,MAAa,4BACX,UAGG;CACH,IAAI,OAAO,UAAU,YAAY,OAAO;CACxC,MAAM,WAAW;CACjB,SAAS,wBAAwB,OAA+B;EAC9D,MAAM,UAAU,SAAS,MAAM,MAAM,SAAS,SAAS;EACvD,IAAI,CAAC,SAAS,MAAM,MAAM;EAC1B,OAAO,QAAQ,KAAc;CAC/B;CACA,OAAO;AACT"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//#region src/lazy/create-error-component.tsx
|
|
2
|
-
/** Function inputs retain their identity; handler maps dispatch by error code. */
|
|
3
|
-
const createLazyErrorComponent = (input) => {
|
|
4
|
-
if (typeof input === "function") return input;
|
|
5
|
-
const handlers = input;
|
|
6
|
-
function LazyResourceErrorByCode(props) {
|
|
7
|
-
const handler = handlers[props.error.code] ?? handlers.fallback;
|
|
8
|
-
if (!handler) throw props.error;
|
|
9
|
-
return handler(props);
|
|
10
|
-
}
|
|
11
|
-
return LazyResourceErrorByCode;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
export { createLazyErrorComponent };
|
|
16
|
-
//# sourceMappingURL=create-error-component.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-error-component.mjs","names":[],"sources":["../../src/lazy/create-error-component.tsx"],"sourcesContent":["import type {\n CreateLazyErrorComponent,\n LazyErrorHandlers,\n LazyResourceErrorProps,\n} from './types';\n\n/** Function inputs retain their identity; handler maps dispatch by error code. */\nexport const createLazyErrorComponent: CreateLazyErrorComponent<string> = (\n input:\n | ((props: LazyResourceErrorProps) => React.ReactNode)\n | LazyErrorHandlers<string>,\n) => {\n if (typeof input === 'function') return input;\n const handlers = input;\n function LazyResourceErrorByCode(props: LazyResourceErrorProps) {\n const handler = handlers[props.error.code] ?? handlers.fallback;\n if (!handler) throw props.error;\n return handler(props as never);\n }\n return LazyResourceErrorByCode;\n};\n"],"mappings":";;AAOA,MAAa,4BACX,UAGG;CACH,IAAI,OAAO,UAAU,YAAY,OAAO;CACxC,MAAM,WAAW;CACjB,SAAS,wBAAwB,OAA+B;EAC9D,MAAM,UAAU,SAAS,MAAM,MAAM,SAAS,SAAS;EACvD,IAAI,CAAC,SAAS,MAAM,MAAM;EAC1B,OAAO,QAAQ,KAAc;CAC/B;CACA,OAAO;AACT"}
|