@jfdevelops/react-layout 1.6.1 → 2.0.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 +18 -14
- package/dist/create-config/create-defined-resource-layout.cjs.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.cts +9 -5
- package/dist/create-config/create-defined-resource-layout.d.cts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.mts +9 -5
- package/dist/create-config/create-defined-resource-layout.d.mts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.mjs +19 -15
- package/dist/create-config/create-defined-resource-layout.mjs.map +1 -1
- package/dist/create-config/define-layout.cjs +66 -39
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +0 -5
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +0 -5
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +67 -40
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/create-config/for-resources/create-component.d.cts +39 -21
- package/dist/create-config/for-resources/create-component.d.cts.map +1 -1
- package/dist/create-config/for-resources/create-component.d.mts +39 -21
- package/dist/create-config/for-resources/create-component.d.mts.map +1 -1
- package/dist/create-config/for-resources/create-for-resources.cjs +62 -7
- package/dist/create-config/for-resources/create-for-resources.cjs.map +1 -1
- package/dist/create-config/for-resources/create-for-resources.mjs +62 -7
- package/dist/create-config/for-resources/create-for-resources.mjs.map +1 -1
- package/dist/create-config/for-resources/scoped-render.cjs +1 -0
- package/dist/create-config/for-resources/scoped-render.cjs.map +1 -1
- package/dist/create-config/for-resources/scoped-render.d.cts.map +1 -1
- package/dist/create-config/for-resources/scoped-render.d.mts.map +1 -1
- package/dist/create-config/for-resources/scoped-render.mjs +1 -0
- package/dist/create-config/for-resources/scoped-render.mjs.map +1 -1
- package/dist/create-config/index.d.cts +2 -1
- package/dist/create-config/index.d.mts +2 -1
- package/dist/create-config/layout-name.cjs +1 -1
- package/dist/create-config/layout-name.mjs +1 -1
- package/dist/create-config/lazy-resource-layout.cjs +70 -86
- package/dist/create-config/lazy-resource-layout.cjs.map +1 -1
- package/dist/create-config/lazy-resource-layout.d.cts +9 -31
- package/dist/create-config/lazy-resource-layout.d.cts.map +1 -1
- package/dist/create-config/lazy-resource-layout.d.mts +9 -31
- package/dist/create-config/lazy-resource-layout.d.mts.map +1 -1
- package/dist/create-config/lazy-resource-layout.mjs +70 -86
- package/dist/create-config/lazy-resource-layout.mjs.map +1 -1
- package/dist/create-config/preview.cjs +1 -1
- package/dist/create-config/preview.d.cts +2 -0
- package/dist/create-config/preview.d.cts.map +1 -1
- package/dist/create-config/preview.d.mts +2 -0
- package/dist/create-config/preview.d.mts.map +1 -1
- package/dist/create-config/preview.mjs +1 -1
- package/dist/create-config/render-state.cjs +57 -18
- package/dist/create-config/render-state.cjs.map +1 -1
- package/dist/create-config/render-state.d.cts +18 -6
- package/dist/create-config/render-state.d.cts.map +1 -1
- package/dist/create-config/render-state.d.mts +18 -6
- package/dist/create-config/render-state.d.mts.map +1 -1
- package/dist/create-config/render-state.mjs +54 -18
- package/dist/create-config/render-state.mjs.map +1 -1
- package/dist/errors/lazy-resource-error.cjs +37 -0
- package/dist/errors/lazy-resource-error.cjs.map +1 -0
- package/dist/errors/lazy-resource-error.d.cts +26 -0
- package/dist/errors/lazy-resource-error.d.cts.map +1 -0
- package/dist/errors/lazy-resource-error.d.mts +26 -0
- package/dist/errors/lazy-resource-error.d.mts.map +1 -0
- package/dist/errors/lazy-resource-error.mjs +35 -0
- package/dist/errors/lazy-resource-error.mjs.map +1 -0
- package/dist/errors/react-layout-error.cjs +1 -1
- package/dist/errors/react-layout-error.mjs +1 -1
- package/dist/errors/resource-state-error.cjs +4 -1
- package/dist/errors/resource-state-error.cjs.map +1 -1
- package/dist/errors/resource-state-error.d.cts +1 -0
- package/dist/errors/resource-state-error.d.cts.map +1 -1
- package/dist/errors/resource-state-error.d.mts +1 -0
- package/dist/errors/resource-state-error.d.mts.map +1 -1
- package/dist/errors/resource-state-error.mjs +4 -1
- package/dist/errors/resource-state-error.mjs.map +1 -1
- package/dist/index.cjs +6 -2
- package/dist/index.d.cts +7 -4
- package/dist/index.d.mts +7 -4
- package/dist/index.mjs +4 -3
- package/dist/lazy/create-error-component.cjs +17 -0
- package/dist/lazy/create-error-component.cjs.map +1 -0
- package/dist/lazy/create-error-component.mjs +16 -0
- package/dist/lazy/create-error-component.mjs.map +1 -0
- package/dist/lazy/create-lazy-loader.cjs +78 -0
- package/dist/lazy/create-lazy-loader.cjs.map +1 -0
- package/dist/lazy/create-lazy-loader.d.cts +19 -0
- package/dist/lazy/create-lazy-loader.d.cts.map +1 -0
- package/dist/lazy/create-lazy-loader.d.mts +19 -0
- package/dist/lazy/create-lazy-loader.d.mts.map +1 -0
- package/dist/lazy/create-lazy-loader.mjs +78 -0
- package/dist/lazy/create-lazy-loader.mjs.map +1 -0
- package/dist/lazy/fallback-props.cjs +9 -0
- package/dist/lazy/fallback-props.cjs.map +1 -0
- package/dist/lazy/fallback-props.mjs +9 -0
- package/dist/lazy/fallback-props.mjs.map +1 -0
- package/dist/lazy/inspection.cjs +51 -0
- package/dist/lazy/inspection.cjs.map +1 -0
- package/dist/lazy/inspection.d.cts +28 -0
- package/dist/lazy/inspection.d.cts.map +1 -0
- package/dist/lazy/inspection.d.mts +28 -0
- package/dist/lazy/inspection.d.mts.map +1 -0
- package/dist/lazy/inspection.mjs +50 -0
- package/dist/lazy/inspection.mjs.map +1 -0
- package/dist/lazy/lazy-boundary.cjs +55 -0
- package/dist/lazy/lazy-boundary.cjs.map +1 -0
- package/dist/lazy/lazy-boundary.mjs +55 -0
- package/dist/lazy/lazy-boundary.mjs.map +1 -0
- package/dist/lazy/scoped-content.cjs +87 -0
- package/dist/lazy/scoped-content.cjs.map +1 -0
- package/dist/lazy/scoped-content.d.cts +19 -0
- package/dist/lazy/scoped-content.d.cts.map +1 -0
- package/dist/lazy/scoped-content.d.mts +19 -0
- package/dist/lazy/scoped-content.d.mts.map +1 -0
- package/dist/lazy/scoped-content.mjs +86 -0
- package/dist/lazy/scoped-content.mjs.map +1 -0
- package/dist/lazy/types.cjs +10 -0
- package/dist/lazy/types.cjs.map +1 -0
- package/dist/lazy/types.d.cts +39 -0
- package/dist/lazy/types.d.cts.map +1 -0
- package/dist/lazy/types.d.mts +39 -0
- package/dist/lazy/types.d.mts.map +1 -0
- package/dist/lazy/types.mjs +8 -0
- package/dist/lazy/types.mjs.map +1 -0
- package/dist/props.cjs +4 -2
- package/dist/props.cjs.map +1 -1
- package/dist/props.d.cts +6 -50
- package/dist/props.d.cts.map +1 -1
- package/dist/props.d.mts +6 -50
- package/dist/props.d.mts.map +1 -1
- package/dist/props.mjs +5 -2
- package/dist/props.mjs.map +1 -1
- package/dist/resource.cjs.map +1 -1
- package/dist/resource.d.cts +1 -1
- package/dist/resource.d.cts.map +1 -1
- package/dist/resource.d.mts +1 -1
- package/dist/resource.d.mts.map +1 -1
- package/dist/resource.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { LayoutConfigurationError, LayoutConfigurationErrorContext } from "./errors/layout-configuration-error.mjs";
|
|
2
|
+
import { ResourceModuleLoadError, ResourceRenderError, ResourceStateError } from "./errors/resource-state-error.mjs";
|
|
3
|
+
import { LazyResourceError, LazyResourceErrorMap, LazyResourceModuleShapeError, LazyResourceStateNotFoundError, isLazyResourceError } from "./errors/lazy-resource-error.mjs";
|
|
4
|
+
import { CreateLazyErrorComponent, LazyErrorHandlers, LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceErrorProps, LazyResourceLoadingComponent, LazyResourceStates, LoadStatus } from "./lazy/types.mjs";
|
|
1
5
|
import { BaseComponent, MergeIntersection, Show, UnionToIntersection, pick } from "./utils.mjs";
|
|
2
6
|
import { LayoutResourceKey, NormalizeResource, NormalizeResources, NormalizedResourceDefinition, NormalizedResourceDefinitions, ResourceDefinition, ResourceDefinitionValue, ResourceEnum, ResourceLayoutComponentProps, ResourcePath, ResourceTree, normalizeResource, normalizeResourceDefinitions, normalizeResources, toResourceEnum } from "./resource.mjs";
|
|
3
7
|
import { InPropsDefinition, InPropsFunction, InPropsObject, InPropsOptions, IncludedComponentPropDefinitions, IncludedPropBehavior, IncludedProps, InferredInProps, LayoutRenderProps, MergedLayoutInProps, PropsContextRender, PropsRenderDefinition, ResolvedIncludedComponentProps, ResolvedIncludedConfigProps, ResolvedIncludedProps, ResolvedIncludedPropsAsDefined } from "./props.mjs";
|
|
@@ -10,8 +14,9 @@ import { ForPaths, ForPathsRenderContext, RenderedPathComponent, RenderedPathCom
|
|
|
10
14
|
import { IsSubResourceKey } from "./create-config/is-sub-resource-key.mjs";
|
|
11
15
|
import { ComponentTypes, CreateResourceConfigFn, CreateResourceConfigForResource, CreatedResourceConfig, ResourceConfigFragment } from "./create-config/get-component.mjs";
|
|
12
16
|
import { CreateResourceMap, CreateResourceMapFn } from "./create-config/create-resource-links.mjs";
|
|
17
|
+
import { ScopedComponentRenderFn } from "./lazy/scoped-content.mjs";
|
|
13
18
|
import { ContextualInlineRenderState, ContextualInlineRenderStates, CreateResourceLayoutWithLayoutOptions, CreateViewMapBuiltInRenderStatesOptions, CreateViewMapFunctionRenderOptions, CreateViewMapInlineRenderStatesOptions, CreateViewMapRenderStatesOptions, DefineResourceLayoutWithLayoutFn, DefineResourcesFn, DefinedResourceLayoutWithShell, LayoutRenderResourcesAccessor, LayoutResourcesAccessor, ResourceLayoutProvider, ResourceLayoutProviderProps, ResourceLayoutShellComponent, ResourceLayoutShellProps, ResourceSelection, ShellLayoutDefinition, ShellRenderContext, TypedBuiltInRenderStates, TypedInlineRenderState, defineResourceLayout } from "./create-config/define-layout.mjs";
|
|
14
|
-
import {
|
|
19
|
+
import { LazyResourceLayoutComponent, LazyResourceLayoutOptions } from "./create-config/lazy-resource-layout.mjs";
|
|
15
20
|
import { BoundDefineResourceLayout, CreateDefinedResourceLayoutOptions, CreateDefinedResourceLayoutResult, DefineLazyDefaults, DefinedResourceLayoutInput, NonEmptyResources, createDefinedResourceLayout } from "./create-config/create-defined-resource-layout.mjs";
|
|
16
21
|
import { ResourceLayoutShellPublisher } from "./create-config/shell-context.mjs";
|
|
17
22
|
import { LayoutPreviewProps, defineLayoutPreview } from "./create-config/preview.mjs";
|
|
@@ -25,8 +30,6 @@ import { InvalidPartContext, InvalidPartError } from "./errors/invalid-part.mjs"
|
|
|
25
30
|
import { InvalidPartTypeContext, InvalidPartTypeError } from "./errors/invalid-part-type.mjs";
|
|
26
31
|
import { MissingPathVariableContext, MissingPathVariableError } from "./errors/missing-path-variable.mjs";
|
|
27
32
|
import { MissingResourceProviderError } from "./errors/missing-resource-provider.mjs";
|
|
28
|
-
import { LayoutConfigurationError, LayoutConfigurationErrorContext } from "./errors/layout-configuration-error.mjs";
|
|
29
|
-
import { ResourceModuleLoadError, ResourceRenderError, ResourceStateError } from "./errors/resource-state-error.mjs";
|
|
30
33
|
import { AnyComposableComponent, ComposableComponent, ComposableComponentCallable, ComposableComponents, ComposableNameContext, ComposablePresetComponent, ComposablePresetComponentCallProps, ComposablePresetMeta, ComposablePresetProps, ComposableResourceLayout, CreateLayoutComposable, DefinedComposableComponentRecord, LayoutComposablePresetProvider, LayoutComposablesFactory, MakeComposable, MakeComposableOptions, MergePresetProps, PresetPropsFromComposable, RequiredPresetLayoutProps, RequiredPresetRenderProps, ResolveLayoutComposables, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, defineComposableComponent, makeComposable, resolveComposablePresetProps, resolveLayoutComposables } from "@jfdevelops/react-layout-composables";
|
|
31
34
|
import { AnyBuiltPropDefinition, ExtractDefinitionValue, PropError, PropErrorOptions, ResolveLayoutProps, ResolveLayoutPropsAsDefined, ResolveProps, ResolvedBuiltPropShape, createPrimitivePropBuilder, createProp, isPropDefinitionShape, resolvePropDefinitionValues, validateProps } from "@jfdevelops/react-layout-validator";
|
|
32
|
-
export { type AnyBuiltPropDefinition, type AnyComposableComponent, type AnyRenderStateDefinition, type AsStateComposable, type BaseComponent, type BoundDefineResourceLayout, type ComponentTypes, type ComposableComponent, type ComposableComponentCallable, type ComposableComponents, type ComposableNameContext, type ComposablePresetComponent, type ComposablePresetComponentCallProps, type ComposablePresetMeta, type ComposablePresetProps, type ComposableResourceLayout, type ContextualInlineRenderState, type ContextualInlineRenderStates, type CreateDefinedResourceLayoutOptions, type CreateDefinedResourceLayoutResult, type CreateGetComponentForPath, type CreateLayoutBuildingBlocks, type CreateLayoutBuildingBlocksArguments, type CreateLayoutBuildingBlocksResult, type CreateLayoutComposable, type CreateRenderState, type CreateRenderStateBuilderArguments, type CreateRenderStateBuilderResult, type CreateRenderStateFromState, type CreateResourceConfigFn, type CreateResourceConfigForResource, type CreateResourceLayoutWithLayoutOptions, type CreateResourceMap, type CreateResourceMapFn, type CreateViewMapBuiltInRenderStatesOptions, type CreateViewMapFunctionRenderOptions, type CreateViewMapInlineRenderStatesOptions, type CreateViewMapRenderStatesOptions, type CreatedResourceConfig, type DeferredRenderState, type DefineLayoutComposables, type DefineLazyDefaults, type DefineResourceLayoutWithLayoutFn, type DefineResourcesFn, type DefinedComposableComponentRecord, type DefinedResourceLayoutInput, type DefinedResourceLayoutWithShell, type ExtractDefinitionValue, type ForPaths, type ForPathsRenderContext, type GetComponentForPath, type InPropsDefinition, type InPropsFunction, type InPropsObject, type InPropsOptions, type IncludedComponentPropDefinitions, type IncludedPropBehavior, type IncludedProps, type InferredInProps, type InvalidComponentContext, InvalidComponentError, type InvalidConfigContext, InvalidConfigError, type InvalidPartContext, InvalidPartError, type InvalidPartTypeContext, InvalidPartTypeError, type InvalidPathContext, InvalidPathError, type InvalidResourceContext, InvalidResourceError, type InvalidSubResourceContext, InvalidSubResourceError, type IsSubResourceKey, LayoutComposablePresetProvider, type LayoutComposablesDefinition, type LayoutComposablesFactory, LayoutConfigurationError, type LayoutConfigurationErrorContext, type LayoutNameCallback, type LayoutNameContext, type LayoutNameFactory, type LayoutNameInput, type LayoutNameOptions, type LayoutNamePartDefinitions, type LayoutNamePartType, type LayoutNamePartValues, type LayoutNameParts, type LayoutNameResolver, type LayoutPreviewProps, type LayoutRenderProps, type LayoutRenderResourcesAccessor, type LayoutResourceKey, type LayoutResourcesAccessor, type LazyRenderState, type LazyResourceErrorComponent, type LazyResourceLayoutComponent, type LazyResourceLayoutOptions, type LazyResourceLoadingComponent, type LazyResourceStates, type MakeComposable, type MakeComposableOptions, type MergeIntersection, type MergePresetProps, type MergedLayoutInProps, type MissingPathVariableContext, MissingPathVariableError, MissingResourceProviderError, type NonEmptyResources, type NormalizeResource, type NormalizeResources, type NormalizedResourceDefinition, type NormalizedResourceDefinitions, type ParameterizedResourcePath, type PathVariables, type PresetPropsFromComposable, PropError, type PropErrorOptions, type PropsContextRender, type PropsRenderDefinition, ReactLayoutError, type RenderStateCallProps, type RenderStateCallback, type RenderStateComposablesDefinition, type RenderStateContext, type RenderStateFragment, type RenderStateName, type RenderStateOverloads, type RenderStateProps, type RenderStateReferences, type RenderedPathComponent, type RenderedPathComponentHOF, type RequiredPresetLayoutProps, type RequiredPresetRenderProps, type ResolveLayoutComposables, type ResolveLayoutProps, type ResolveLayoutPropsAsDefined, type ResolveProps, type ResolvedBuiltPropShape, type ResolvedIncludedComponentProps, type ResolvedIncludedConfigProps, type ResolvedIncludedProps, type ResolvedIncludedPropsAsDefined, type ResolvedLayoutName, type ResolvedPathValue, type ResourceConfigFragment, type ResourceDefinition, type ResourceDefinitionValue, type ResourceEnum, type ResourceLayoutComponentProps, type ResourceLayoutProvider, type ResourceLayoutProviderProps, type ResourceLayoutShellComponent, type ResourceLayoutShellProps, type ResourceLayoutShellPublisher, ResourceModuleLoadError, type ResourcePath, ResourceRenderError, type ResourceSelection, type ResourceStateError, type ResourceTree, type ShellLayoutDefinition, type ShellRenderContext, type Show, type StateComposable, type StateComposableOptions, type TargetPathBuilder, type TypedBuiltInRenderStates, type TypedInlineRenderState, type TypedRenderStateCallback, type UnionToIntersection, collectComposablePresetEntries, createComposableComponent, createDefinedResourceLayout, createLayoutComposableFactory, createPrimitivePropBuilder, createProp, defineComposableComponent, defineLayoutName, defineLayoutPreview, defineResourceLayout, isPropDefinitionShape, makeComposable, normalizeResource, normalizeResourceDefinitions, normalizeResources, pick, resolveComposablePresetProps, resolveLayoutComposables, resolvePropDefinitionValues, toResourceEnum, validateProps };
|
|
35
|
+
export { type AnyBuiltPropDefinition, type AnyComposableComponent, type AnyRenderStateDefinition, type AsStateComposable, type BaseComponent, type BoundDefineResourceLayout, type ComponentTypes, type ComposableComponent, type ComposableComponentCallable, type ComposableComponents, type ComposableNameContext, type ComposablePresetComponent, type ComposablePresetComponentCallProps, type ComposablePresetMeta, type ComposablePresetProps, type ComposableResourceLayout, type ContextualInlineRenderState, type ContextualInlineRenderStates, type CreateDefinedResourceLayoutOptions, type CreateDefinedResourceLayoutResult, type CreateGetComponentForPath, type CreateLayoutBuildingBlocks, type CreateLayoutBuildingBlocksArguments, type CreateLayoutBuildingBlocksResult, type CreateLayoutComposable, type CreateLazyErrorComponent, type CreateRenderState, type CreateRenderStateBuilderArguments, type CreateRenderStateBuilderResult, type CreateRenderStateFromState, type CreateResourceConfigFn, type CreateResourceConfigForResource, type CreateResourceLayoutWithLayoutOptions, type CreateResourceMap, type CreateResourceMapFn, type CreateViewMapBuiltInRenderStatesOptions, type CreateViewMapFunctionRenderOptions, type CreateViewMapInlineRenderStatesOptions, type CreateViewMapRenderStatesOptions, type CreatedResourceConfig, type DeferredRenderState, type DefineLayoutComposables, type DefineLazyDefaults, type DefineResourceLayoutWithLayoutFn, type DefineResourcesFn, type DefinedComposableComponentRecord, type DefinedResourceLayoutInput, type DefinedResourceLayoutWithShell, type ExtractDefinitionValue, type ForPaths, type ForPathsRenderContext, type GetComponentForPath, type InPropsDefinition, type InPropsFunction, type InPropsObject, type InPropsOptions, type IncludedComponentPropDefinitions, type IncludedPropBehavior, type IncludedProps, type InferredInProps, type InvalidComponentContext, InvalidComponentError, type InvalidConfigContext, InvalidConfigError, type InvalidPartContext, InvalidPartError, type InvalidPartTypeContext, InvalidPartTypeError, type InvalidPathContext, InvalidPathError, type InvalidResourceContext, InvalidResourceError, type InvalidSubResourceContext, InvalidSubResourceError, type IsSubResourceKey, LayoutComposablePresetProvider, type LayoutComposablesDefinition, type LayoutComposablesFactory, LayoutConfigurationError, type LayoutConfigurationErrorContext, type LayoutNameCallback, type LayoutNameContext, type LayoutNameFactory, type LayoutNameInput, type LayoutNameOptions, type LayoutNamePartDefinitions, type LayoutNamePartType, type LayoutNamePartValues, type LayoutNameParts, type LayoutNameResolver, type LayoutPreviewProps, type LayoutRenderProps, type LayoutRenderResourcesAccessor, type LayoutResourceKey, type LayoutResourcesAccessor, type LazyErrorHandlers, type LazyHandle, type LazyOptions, type LazyRenderState, type LazyResourceError, type LazyResourceErrorComponent, type LazyResourceErrorMap, type LazyResourceErrorProps, type LazyResourceLayoutComponent, type LazyResourceLayoutOptions, type LazyResourceLoadingComponent, LazyResourceModuleShapeError, LazyResourceStateNotFoundError, type LazyResourceStates, type LoadStatus, type MakeComposable, type MakeComposableOptions, type MergeIntersection, type MergePresetProps, type MergedLayoutInProps, type MissingPathVariableContext, MissingPathVariableError, MissingResourceProviderError, type NonEmptyResources, type NormalizeResource, type NormalizeResources, type NormalizedResourceDefinition, type NormalizedResourceDefinitions, type ParameterizedResourcePath, type PathVariables, type PresetPropsFromComposable, PropError, type PropErrorOptions, type PropsContextRender, type PropsRenderDefinition, ReactLayoutError, type RenderStateCallProps, type RenderStateCallback, type RenderStateComposablesDefinition, type RenderStateContext, type RenderStateFragment, type RenderStateName, type RenderStateOverloads, type RenderStateProps, type RenderStateReferences, type RenderedPathComponent, type RenderedPathComponentHOF, type RequiredPresetLayoutProps, type RequiredPresetRenderProps, type ResolveLayoutComposables, type ResolveLayoutProps, type ResolveLayoutPropsAsDefined, type ResolveProps, type ResolvedBuiltPropShape, type ResolvedIncludedComponentProps, type ResolvedIncludedConfigProps, type ResolvedIncludedProps, type ResolvedIncludedPropsAsDefined, type ResolvedLayoutName, type ResolvedPathValue, type ResourceConfigFragment, type ResourceDefinition, type ResourceDefinitionValue, type ResourceEnum, type ResourceLayoutComponentProps, type ResourceLayoutProvider, type ResourceLayoutProviderProps, type ResourceLayoutShellComponent, type ResourceLayoutShellProps, type ResourceLayoutShellPublisher, ResourceModuleLoadError, type ResourcePath, ResourceRenderError, type ResourceSelection, type ResourceStateError, type ResourceTree, type ScopedComponentRenderFn, type ShellLayoutDefinition, type ShellRenderContext, type Show, type StateComposable, type StateComposableOptions, type TargetPathBuilder, type TypedBuiltInRenderStates, type TypedInlineRenderState, type TypedRenderStateCallback, type UnionToIntersection, collectComposablePresetEntries, createComposableComponent, createDefinedResourceLayout, createLayoutComposableFactory, createPrimitivePropBuilder, createProp, defineComposableComponent, defineLayoutName, defineLayoutPreview, defineResourceLayout, isLazyResourceError, isPropDefinitionShape, makeComposable, normalizeResource, normalizeResourceDefinitions, normalizeResources, pick, resolveComposablePresetProps, resolveLayoutComposables, resolvePropDefinitionValues, toResourceEnum, validateProps };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { ReactLayoutError } from "./errors/react-layout-error.mjs";
|
|
2
|
+
import { LayoutConfigurationError } from "./errors/layout-configuration-error.mjs";
|
|
3
|
+
import { ResourceModuleLoadError, ResourceRenderError } from "./errors/resource-state-error.mjs";
|
|
4
|
+
import { LazyResourceModuleShapeError, LazyResourceStateNotFoundError, isLazyResourceError } from "./errors/lazy-resource-error.mjs";
|
|
2
5
|
import { InvalidConfigError } from "./errors/invalid-config.mjs";
|
|
3
6
|
import { InvalidPathError } from "./errors/invalid-path.mjs";
|
|
4
7
|
import { InvalidResourceError } from "./errors/invalid-resource.mjs";
|
|
@@ -8,8 +11,6 @@ import { InvalidPartError } from "./errors/invalid-part.mjs";
|
|
|
8
11
|
import { InvalidPartTypeError } from "./errors/invalid-part-type.mjs";
|
|
9
12
|
import { MissingPathVariableError } from "./errors/missing-path-variable.mjs";
|
|
10
13
|
import { MissingResourceProviderError } from "./errors/missing-resource-provider.mjs";
|
|
11
|
-
import { LayoutConfigurationError } from "./errors/layout-configuration-error.mjs";
|
|
12
|
-
import { ResourceModuleLoadError, ResourceRenderError } from "./errors/resource-state-error.mjs";
|
|
13
14
|
import { defineLayoutPreview } from "./create-config/preview.mjs";
|
|
14
15
|
import { normalizeResource, normalizeResourceDefinitions, normalizeResources, toResourceEnum } from "./resource.mjs";
|
|
15
16
|
import { pick } from "./utils.mjs";
|
|
@@ -19,4 +20,4 @@ import { defineLayoutName } from "./create-config/layout-name.mjs";
|
|
|
19
20
|
import { LayoutComposablePresetProvider, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, defineComposableComponent, makeComposable, resolveComposablePresetProps, resolveLayoutComposables } from "@jfdevelops/react-layout-composables";
|
|
20
21
|
import { PropError, createPrimitivePropBuilder, createProp, isPropDefinitionShape, resolvePropDefinitionValues, validateProps } from "@jfdevelops/react-layout-validator";
|
|
21
22
|
|
|
22
|
-
export { InvalidComponentError, InvalidConfigError, InvalidPartError, InvalidPartTypeError, InvalidPathError, InvalidResourceError, InvalidSubResourceError, LayoutComposablePresetProvider, LayoutConfigurationError, MissingPathVariableError, MissingResourceProviderError, PropError, ReactLayoutError, ResourceModuleLoadError, ResourceRenderError, collectComposablePresetEntries, createComposableComponent, createDefinedResourceLayout, createLayoutComposableFactory, createPrimitivePropBuilder, createProp, defineComposableComponent, defineLayoutName, defineLayoutPreview, defineResourceLayout, isPropDefinitionShape, makeComposable, normalizeResource, normalizeResourceDefinitions, normalizeResources, pick, resolveComposablePresetProps, resolveLayoutComposables, resolvePropDefinitionValues, toResourceEnum, validateProps };
|
|
23
|
+
export { InvalidComponentError, InvalidConfigError, InvalidPartError, InvalidPartTypeError, InvalidPathError, InvalidResourceError, InvalidSubResourceError, LayoutComposablePresetProvider, LayoutConfigurationError, LazyResourceModuleShapeError, LazyResourceStateNotFoundError, MissingPathVariableError, MissingResourceProviderError, PropError, ReactLayoutError, ResourceModuleLoadError, ResourceRenderError, collectComposablePresetEntries, createComposableComponent, createDefinedResourceLayout, createLayoutComposableFactory, createPrimitivePropBuilder, createProp, defineComposableComponent, defineLayoutName, defineLayoutPreview, defineResourceLayout, isLazyResourceError, isPropDefinitionShape, makeComposable, normalizeResource, normalizeResourceDefinitions, normalizeResources, pick, resolveComposablePresetProps, resolveLayoutComposables, resolvePropDefinitionValues, toResourceEnum, validateProps };
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const require_resource_state_error = require('../errors/resource-state-error.cjs');
|
|
2
|
+
const require_lazy_resource_error = require('../errors/lazy-resource-error.cjs');
|
|
3
|
+
let react = require("react");
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-lazy-loader.ts
|
|
6
|
+
/** A single import cache and lifecycle shared by every lazy entry point. */
|
|
7
|
+
function createLazyLoader(options) {
|
|
8
|
+
let promise;
|
|
9
|
+
let preloadPromise;
|
|
10
|
+
let status = "unresolved";
|
|
11
|
+
const components = /* @__PURE__ */ new Map();
|
|
12
|
+
let generation = 0;
|
|
13
|
+
function get() {
|
|
14
|
+
if (promise) return promise;
|
|
15
|
+
const attempt = generation;
|
|
16
|
+
status = "loading";
|
|
17
|
+
options.hooks?.onLoadStart?.();
|
|
18
|
+
promise = Promise.resolve().then(options.load).catch((cause) => {
|
|
19
|
+
if (require_lazy_resource_error.isLazyResourceError(cause)) throw cause;
|
|
20
|
+
if (process.env.NODE_ENV !== "production") console.error(`[react-layout] lazy "${options.label}" failed to load`, cause);
|
|
21
|
+
throw new require_resource_state_error.ResourceModuleLoadError(options.label, cause);
|
|
22
|
+
}).then(options.select).then((selected) => {
|
|
23
|
+
if (attempt === generation) {
|
|
24
|
+
status = "resolved";
|
|
25
|
+
options.hooks?.onLoadSuccess?.();
|
|
26
|
+
}
|
|
27
|
+
return selected;
|
|
28
|
+
}, (error) => {
|
|
29
|
+
if (attempt === generation) {
|
|
30
|
+
status = "error";
|
|
31
|
+
options.hooks?.onLoadError?.(error);
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
});
|
|
35
|
+
return promise;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
get,
|
|
39
|
+
get status() {
|
|
40
|
+
return status;
|
|
41
|
+
},
|
|
42
|
+
preload: () => preloadPromise ??= get().then(() => void 0),
|
|
43
|
+
reset() {
|
|
44
|
+
generation++;
|
|
45
|
+
promise = void 0;
|
|
46
|
+
preloadPromise = void 0;
|
|
47
|
+
components.clear();
|
|
48
|
+
status = "unresolved";
|
|
49
|
+
},
|
|
50
|
+
component(member, map) {
|
|
51
|
+
const key = map ?? member;
|
|
52
|
+
let component = components.get(key);
|
|
53
|
+
if (!component) {
|
|
54
|
+
component = (0, react.lazy)(async () => {
|
|
55
|
+
const attempt = generation;
|
|
56
|
+
const selected = await get();
|
|
57
|
+
try {
|
|
58
|
+
const candidate = map ? map(selected) : member === void 0 ? selected : selected[member];
|
|
59
|
+
if (typeof candidate !== "function") throw new require_lazy_resource_error.LazyResourceStateNotFoundError(options.label, String(member));
|
|
60
|
+
return { default: candidate };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (attempt === generation && require_lazy_resource_error.isLazyResourceError(error)) {
|
|
63
|
+
status = "error";
|
|
64
|
+
options.hooks?.onLoadError?.(error);
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
components.set(key, component);
|
|
70
|
+
}
|
|
71
|
+
return component;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
exports.createLazyLoader = createLazyLoader;
|
|
78
|
+
//# sourceMappingURL=create-lazy-loader.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-lazy-loader.cjs","names":["isLazyResourceError","ResourceModuleLoadError","LazyResourceStateNotFoundError"],"sources":["../../src/lazy/create-lazy-loader.ts"],"sourcesContent":["import { lazy, type ComponentType } from 'react';\nimport { ResourceModuleLoadError } from '../errors/resource-state-error';\nimport {\n LazyResourceStateNotFoundError,\n isLazyResourceError,\n type LazyResourceError,\n} from '../errors/lazy-resource-error';\nimport type { LazyHandle, LoadStatus } from './types';\n\nexport type LazyResourceLoadHooks = {\n onLoadStart?: () => void;\n onLoadSuccess?: () => void;\n onLoadError?: (error: LazyResourceError) => void;\n onMount?: () => (() => void) | undefined;\n};\n\nexport type LazyLoader<Selected> = LazyHandle & {\n get(): Promise<Selected>;\n reset(): void;\n component(\n member?: PropertyKey,\n map?: (selected: Selected) => ComponentType<any>,\n ): ComponentType<any>;\n};\n\n/** A single import cache and lifecycle shared by every lazy entry point. */\nexport function createLazyLoader<Module, Selected>(options: {\n load: () => Promise<Module>;\n select: (module: Module) => Selected | Promise<Selected>;\n label: string;\n hooks?: LazyResourceLoadHooks;\n}): LazyLoader<Selected> {\n let promise: Promise<Selected> | undefined;\n let preloadPromise: Promise<void> | undefined;\n let status: LoadStatus = 'unresolved';\n const components = new Map<unknown, ComponentType<any>>();\n let generation = 0;\n\n function get() {\n if (promise) return promise;\n const attempt = generation;\n status = 'loading';\n options.hooks?.onLoadStart?.();\n promise = Promise.resolve()\n .then(options.load)\n .catch((cause: unknown) => {\n if (isLazyResourceError(cause)) throw cause;\n if (process.env.NODE_ENV !== 'production') {\n console.error(\n `[react-layout] lazy \"${options.label}\" failed to load`,\n cause,\n );\n }\n throw new ResourceModuleLoadError(options.label, cause);\n })\n .then(options.select)\n .then(\n (selected) => {\n if (attempt === generation) {\n status = 'resolved';\n options.hooks?.onLoadSuccess?.();\n }\n return selected;\n },\n (error: LazyResourceError) => {\n if (attempt === generation) {\n status = 'error';\n options.hooks?.onLoadError?.(error);\n }\n throw error;\n },\n );\n return promise;\n }\n\n return {\n get,\n get status() {\n return status;\n },\n preload: () => (preloadPromise ??= get().then(() => undefined)),\n reset() {\n generation++;\n promise = undefined;\n preloadPromise = undefined;\n components.clear();\n status = 'unresolved';\n },\n component(member, map) {\n const key = map ?? member;\n let component = components.get(key);\n if (!component) {\n component = lazy(async () => {\n const attempt = generation;\n const selected = await get();\n try {\n const candidate = map\n ? map(selected)\n : member === undefined\n ? selected\n : (selected as Record<PropertyKey, unknown>)[member];\n if (typeof candidate !== 'function') {\n throw new LazyResourceStateNotFoundError(\n options.label,\n String(member),\n );\n }\n return { default: candidate as ComponentType<any> };\n } catch (error) {\n if (attempt === generation && isLazyResourceError(error)) {\n status = 'error';\n options.hooks?.onLoadError?.(error);\n }\n throw error;\n }\n });\n components.set(key, component);\n }\n return component;\n },\n };\n}\n"],"mappings":";;;;;;AA0BA,SAAgB,iBAAmC,SAK1B;CACvB,IAAI;CACJ,IAAI;CACJ,IAAI,SAAqB;CACzB,MAAM,6BAAa,IAAI,IAAiC;CACxD,IAAI,aAAa;CAEjB,SAAS,MAAM;EACb,IAAI,SAAS,OAAO;EACpB,MAAM,UAAU;EAChB,SAAS;EACT,QAAQ,OAAO,cAAc;EAC7B,UAAU,QAAQ,QAAQ,EACvB,KAAK,QAAQ,IAAI,EACjB,OAAO,UAAmB;GACzB,IAAIA,gDAAoB,KAAK,GAAG,MAAM;GACtC,IAAI,QAAQ,IAAI,aAAa,cAC3B,QAAQ,MACN,wBAAwB,QAAQ,MAAM,mBACtC,KACF;GAEF,MAAM,IAAIC,qDAAwB,QAAQ,OAAO,KAAK;EACxD,CAAC,EACA,KAAK,QAAQ,MAAM,EACnB,MACE,aAAa;GACZ,IAAI,YAAY,YAAY;IAC1B,SAAS;IACT,QAAQ,OAAO,gBAAgB;GACjC;GACA,OAAO;EACT,IACC,UAA6B;GAC5B,IAAI,YAAY,YAAY;IAC1B,SAAS;IACT,QAAQ,OAAO,cAAc,KAAK;GACpC;GACA,MAAM;EACR,CACF;EACF,OAAO;CACT;CAEA,OAAO;EACL;EACA,IAAI,SAAS;GACX,OAAO;EACT;EACA,eAAgB,mBAAmB,IAAI,EAAE,WAAW,MAAS;EAC7D,QAAQ;GACN;GACA,UAAU;GACV,iBAAiB;GACjB,WAAW,MAAM;GACjB,SAAS;EACX;EACA,UAAU,QAAQ,KAAK;GACrB,MAAM,MAAM,OAAO;GACnB,IAAI,YAAY,WAAW,IAAI,GAAG;GAClC,IAAI,CAAC,WAAW;IACd,4BAAiB,YAAY;KAC3B,MAAM,UAAU;KAChB,MAAM,WAAW,MAAM,IAAI;KAC3B,IAAI;MACF,MAAM,YAAY,MACd,IAAI,QAAQ,IACZ,WAAW,SACT,WACC,SAA0C;MACjD,IAAI,OAAO,cAAc,YACvB,MAAM,IAAIC,2DACR,QAAQ,OACR,OAAO,MAAM,CACf;MAEF,OAAO,EAAE,SAAS,UAAgC;KACpD,SAAS,OAAO;MACd,IAAI,YAAY,cAAcF,gDAAoB,KAAK,GAAG;OACxD,SAAS;OACT,QAAQ,OAAO,cAAc,KAAK;MACpC;MACA,MAAM;KACR;IACF,CAAC;IACD,WAAW,IAAI,KAAK,SAAS;GAC/B;GACA,OAAO;EACT;CACF;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LazyResourceError } from "../errors/lazy-resource-error.cjs";
|
|
2
|
+
import { LazyHandle } from "./types.cjs";
|
|
3
|
+
import { ComponentType } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-lazy-loader.d.ts
|
|
6
|
+
type LazyResourceLoadHooks = {
|
|
7
|
+
onLoadStart?: () => void;
|
|
8
|
+
onLoadSuccess?: () => void;
|
|
9
|
+
onLoadError?: (error: LazyResourceError) => void;
|
|
10
|
+
onMount?: () => (() => void) | undefined;
|
|
11
|
+
};
|
|
12
|
+
type LazyLoader<Selected> = LazyHandle & {
|
|
13
|
+
get(): Promise<Selected>;
|
|
14
|
+
reset(): void;
|
|
15
|
+
component(member?: PropertyKey, map?: (selected: Selected) => ComponentType<any>): ComponentType<any>;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { LazyLoader, LazyResourceLoadHooks };
|
|
19
|
+
//# sourceMappingURL=create-lazy-loader.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-lazy-loader.d.cts","names":[],"sources":["../../src/lazy/create-lazy-loader.ts"],"mappings":";;;;;KASY,qBAAA;EACV,WAAA;EACA,aAAA;EACA,WAAA,IAAe,KAAA,EAAO,iBAAiB;EACvC,OAAA;AAAA;AAAA,KAGU,UAAA,aAAuB,UAAA;EACjC,GAAA,IAAO,OAAA,CAAQ,QAAA;EACf,KAAA;EACA,SAAA,CACE,MAAA,GAAS,WAAA,EACT,GAAA,IAAO,QAAA,EAAU,QAAA,KAAa,aAAA,QAC7B,aAAA;AAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LazyResourceError } from "../errors/lazy-resource-error.mjs";
|
|
2
|
+
import { LazyHandle } from "./types.mjs";
|
|
3
|
+
import { ComponentType } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-lazy-loader.d.ts
|
|
6
|
+
type LazyResourceLoadHooks = {
|
|
7
|
+
onLoadStart?: () => void;
|
|
8
|
+
onLoadSuccess?: () => void;
|
|
9
|
+
onLoadError?: (error: LazyResourceError) => void;
|
|
10
|
+
onMount?: () => (() => void) | undefined;
|
|
11
|
+
};
|
|
12
|
+
type LazyLoader<Selected> = LazyHandle & {
|
|
13
|
+
get(): Promise<Selected>;
|
|
14
|
+
reset(): void;
|
|
15
|
+
component(member?: PropertyKey, map?: (selected: Selected) => ComponentType<any>): ComponentType<any>;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { LazyLoader, LazyResourceLoadHooks };
|
|
19
|
+
//# sourceMappingURL=create-lazy-loader.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-lazy-loader.d.mts","names":[],"sources":["../../src/lazy/create-lazy-loader.ts"],"mappings":";;;;;KASY,qBAAA;EACV,WAAA;EACA,aAAA;EACA,WAAA,IAAe,KAAA,EAAO,iBAAiB;EACvC,OAAA;AAAA;AAAA,KAGU,UAAA,aAAuB,UAAA;EACjC,GAAA,IAAO,OAAA,CAAQ,QAAA;EACf,KAAA;EACA,SAAA,CACE,MAAA,GAAS,WAAA,EACT,GAAA,IAAO,QAAA,EAAU,QAAA,KAAa,aAAA,QAC7B,aAAA;AAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ResourceModuleLoadError } from "../errors/resource-state-error.mjs";
|
|
2
|
+
import { LazyResourceStateNotFoundError, isLazyResourceError } from "../errors/lazy-resource-error.mjs";
|
|
3
|
+
import { lazy } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-lazy-loader.ts
|
|
6
|
+
/** A single import cache and lifecycle shared by every lazy entry point. */
|
|
7
|
+
function createLazyLoader(options) {
|
|
8
|
+
let promise;
|
|
9
|
+
let preloadPromise;
|
|
10
|
+
let status = "unresolved";
|
|
11
|
+
const components = /* @__PURE__ */ new Map();
|
|
12
|
+
let generation = 0;
|
|
13
|
+
function get() {
|
|
14
|
+
if (promise) return promise;
|
|
15
|
+
const attempt = generation;
|
|
16
|
+
status = "loading";
|
|
17
|
+
options.hooks?.onLoadStart?.();
|
|
18
|
+
promise = Promise.resolve().then(options.load).catch((cause) => {
|
|
19
|
+
if (isLazyResourceError(cause)) throw cause;
|
|
20
|
+
if (process.env.NODE_ENV !== "production") console.error(`[react-layout] lazy "${options.label}" failed to load`, cause);
|
|
21
|
+
throw new ResourceModuleLoadError(options.label, cause);
|
|
22
|
+
}).then(options.select).then((selected) => {
|
|
23
|
+
if (attempt === generation) {
|
|
24
|
+
status = "resolved";
|
|
25
|
+
options.hooks?.onLoadSuccess?.();
|
|
26
|
+
}
|
|
27
|
+
return selected;
|
|
28
|
+
}, (error) => {
|
|
29
|
+
if (attempt === generation) {
|
|
30
|
+
status = "error";
|
|
31
|
+
options.hooks?.onLoadError?.(error);
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
});
|
|
35
|
+
return promise;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
get,
|
|
39
|
+
get status() {
|
|
40
|
+
return status;
|
|
41
|
+
},
|
|
42
|
+
preload: () => preloadPromise ??= get().then(() => void 0),
|
|
43
|
+
reset() {
|
|
44
|
+
generation++;
|
|
45
|
+
promise = void 0;
|
|
46
|
+
preloadPromise = void 0;
|
|
47
|
+
components.clear();
|
|
48
|
+
status = "unresolved";
|
|
49
|
+
},
|
|
50
|
+
component(member, map) {
|
|
51
|
+
const key = map ?? member;
|
|
52
|
+
let component = components.get(key);
|
|
53
|
+
if (!component) {
|
|
54
|
+
component = lazy(async () => {
|
|
55
|
+
const attempt = generation;
|
|
56
|
+
const selected = await get();
|
|
57
|
+
try {
|
|
58
|
+
const candidate = map ? map(selected) : member === void 0 ? selected : selected[member];
|
|
59
|
+
if (typeof candidate !== "function") throw new LazyResourceStateNotFoundError(options.label, String(member));
|
|
60
|
+
return { default: candidate };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (attempt === generation && isLazyResourceError(error)) {
|
|
63
|
+
status = "error";
|
|
64
|
+
options.hooks?.onLoadError?.(error);
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
components.set(key, component);
|
|
70
|
+
}
|
|
71
|
+
return component;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { createLazyLoader };
|
|
78
|
+
//# sourceMappingURL=create-lazy-loader.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-lazy-loader.mjs","names":[],"sources":["../../src/lazy/create-lazy-loader.ts"],"sourcesContent":["import { lazy, type ComponentType } from 'react';\nimport { ResourceModuleLoadError } from '../errors/resource-state-error';\nimport {\n LazyResourceStateNotFoundError,\n isLazyResourceError,\n type LazyResourceError,\n} from '../errors/lazy-resource-error';\nimport type { LazyHandle, LoadStatus } from './types';\n\nexport type LazyResourceLoadHooks = {\n onLoadStart?: () => void;\n onLoadSuccess?: () => void;\n onLoadError?: (error: LazyResourceError) => void;\n onMount?: () => (() => void) | undefined;\n};\n\nexport type LazyLoader<Selected> = LazyHandle & {\n get(): Promise<Selected>;\n reset(): void;\n component(\n member?: PropertyKey,\n map?: (selected: Selected) => ComponentType<any>,\n ): ComponentType<any>;\n};\n\n/** A single import cache and lifecycle shared by every lazy entry point. */\nexport function createLazyLoader<Module, Selected>(options: {\n load: () => Promise<Module>;\n select: (module: Module) => Selected | Promise<Selected>;\n label: string;\n hooks?: LazyResourceLoadHooks;\n}): LazyLoader<Selected> {\n let promise: Promise<Selected> | undefined;\n let preloadPromise: Promise<void> | undefined;\n let status: LoadStatus = 'unresolved';\n const components = new Map<unknown, ComponentType<any>>();\n let generation = 0;\n\n function get() {\n if (promise) return promise;\n const attempt = generation;\n status = 'loading';\n options.hooks?.onLoadStart?.();\n promise = Promise.resolve()\n .then(options.load)\n .catch((cause: unknown) => {\n if (isLazyResourceError(cause)) throw cause;\n if (process.env.NODE_ENV !== 'production') {\n console.error(\n `[react-layout] lazy \"${options.label}\" failed to load`,\n cause,\n );\n }\n throw new ResourceModuleLoadError(options.label, cause);\n })\n .then(options.select)\n .then(\n (selected) => {\n if (attempt === generation) {\n status = 'resolved';\n options.hooks?.onLoadSuccess?.();\n }\n return selected;\n },\n (error: LazyResourceError) => {\n if (attempt === generation) {\n status = 'error';\n options.hooks?.onLoadError?.(error);\n }\n throw error;\n },\n );\n return promise;\n }\n\n return {\n get,\n get status() {\n return status;\n },\n preload: () => (preloadPromise ??= get().then(() => undefined)),\n reset() {\n generation++;\n promise = undefined;\n preloadPromise = undefined;\n components.clear();\n status = 'unresolved';\n },\n component(member, map) {\n const key = map ?? member;\n let component = components.get(key);\n if (!component) {\n component = lazy(async () => {\n const attempt = generation;\n const selected = await get();\n try {\n const candidate = map\n ? map(selected)\n : member === undefined\n ? selected\n : (selected as Record<PropertyKey, unknown>)[member];\n if (typeof candidate !== 'function') {\n throw new LazyResourceStateNotFoundError(\n options.label,\n String(member),\n );\n }\n return { default: candidate as ComponentType<any> };\n } catch (error) {\n if (attempt === generation && isLazyResourceError(error)) {\n status = 'error';\n options.hooks?.onLoadError?.(error);\n }\n throw error;\n }\n });\n components.set(key, component);\n }\n return component;\n },\n };\n}\n"],"mappings":";;;;;;AA0BA,SAAgB,iBAAmC,SAK1B;CACvB,IAAI;CACJ,IAAI;CACJ,IAAI,SAAqB;CACzB,MAAM,6BAAa,IAAI,IAAiC;CACxD,IAAI,aAAa;CAEjB,SAAS,MAAM;EACb,IAAI,SAAS,OAAO;EACpB,MAAM,UAAU;EAChB,SAAS;EACT,QAAQ,OAAO,cAAc;EAC7B,UAAU,QAAQ,QAAQ,EACvB,KAAK,QAAQ,IAAI,EACjB,OAAO,UAAmB;GACzB,IAAI,oBAAoB,KAAK,GAAG,MAAM;GACtC,IAAI,QAAQ,IAAI,aAAa,cAC3B,QAAQ,MACN,wBAAwB,QAAQ,MAAM,mBACtC,KACF;GAEF,MAAM,IAAI,wBAAwB,QAAQ,OAAO,KAAK;EACxD,CAAC,EACA,KAAK,QAAQ,MAAM,EACnB,MACE,aAAa;GACZ,IAAI,YAAY,YAAY;IAC1B,SAAS;IACT,QAAQ,OAAO,gBAAgB;GACjC;GACA,OAAO;EACT,IACC,UAA6B;GAC5B,IAAI,YAAY,YAAY;IAC1B,SAAS;IACT,QAAQ,OAAO,cAAc,KAAK;GACpC;GACA,MAAM;EACR,CACF;EACF,OAAO;CACT;CAEA,OAAO;EACL;EACA,IAAI,SAAS;GACX,OAAO;EACT;EACA,eAAgB,mBAAmB,IAAI,EAAE,WAAW,MAAS;EAC7D,QAAQ;GACN;GACA,UAAU;GACV,iBAAiB;GACjB,WAAW,MAAM;GACjB,SAAS;EACX;EACA,UAAU,QAAQ,KAAK;GACrB,MAAM,MAAM,OAAO;GACnB,IAAI,YAAY,WAAW,IAAI,GAAG;GAClC,IAAI,CAAC,WAAW;IACd,YAAY,KAAK,YAAY;KAC3B,MAAM,UAAU;KAChB,MAAM,WAAW,MAAM,IAAI;KAC3B,IAAI;MACF,MAAM,YAAY,MACd,IAAI,QAAQ,IACZ,WAAW,SACT,WACC,SAA0C;MACjD,IAAI,OAAO,cAAc,YACvB,MAAM,IAAI,+BACR,QAAQ,OACR,OAAO,MAAM,CACf;MAEF,OAAO,EAAE,SAAS,UAAgC;KACpD,SAAS,OAAO;MACd,IAAI,YAAY,cAAc,oBAAoB,KAAK,GAAG;OACxD,SAAS;OACT,QAAQ,OAAO,cAAc,KAAK;MACpC;MACA,MAAM;KACR;IACF,CAAC;IACD,WAAW,IAAI,KAAK,SAAS;GAC/B;GACA,OAAO;EACT;CACF;AACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
let react = require("react");
|
|
2
|
+
|
|
3
|
+
//#region src/lazy/fallback-props.ts
|
|
4
|
+
/** Scoped fallbacks receive current caller options without rebuilding their layout. */
|
|
5
|
+
const LazyFallbackPropsContext = (0, react.createContext)(void 0);
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.LazyFallbackPropsContext = LazyFallbackPropsContext;
|
|
9
|
+
//# sourceMappingURL=fallback-props.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback-props.cjs","names":[],"sources":["../../src/lazy/fallback-props.ts"],"sourcesContent":["import { createContext } from 'react';\n\n/** Scoped fallbacks receive current caller options without rebuilding their layout. */\nexport const LazyFallbackPropsContext = createContext<\n { owner?: string; props: Record<string, unknown> } | undefined\n>(undefined);\n"],"mappings":";;;;AAGA,MAAa,oDAEX,MAAS"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/lazy/fallback-props.ts
|
|
4
|
+
/** Scoped fallbacks receive current caller options without rebuilding their layout. */
|
|
5
|
+
const LazyFallbackPropsContext = createContext(void 0);
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { LazyFallbackPropsContext };
|
|
9
|
+
//# sourceMappingURL=fallback-props.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback-props.mjs","names":[],"sources":["../../src/lazy/fallback-props.ts"],"sourcesContent":["import { createContext } from 'react';\n\n/** Scoped fallbacks receive current caller options without rebuilding their layout. */\nexport const LazyFallbackPropsContext = createContext<\n { owner?: string; props: Record<string, unknown> } | undefined\n>(undefined);\n"],"mappings":";;;;AAGA,MAAa,2BAA2B,cAEtC,MAAS"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
let _jfdevelops_react_layout_devtools_core = require("@jfdevelops/react-layout-devtools-core");
|
|
2
|
+
|
|
3
|
+
//#region src/lazy/inspection.ts
|
|
4
|
+
/** Register a declaration before its import runs, retaining one node on retry. */
|
|
5
|
+
function inspectLazy(label, store = (0, _jfdevelops_react_layout_devtools_core.createInspectionStore)(), parent) {
|
|
6
|
+
const id = (0, _jfdevelops_react_layout_devtools_core.inspectionId)("lazy");
|
|
7
|
+
function update(status, error) {
|
|
8
|
+
store.node({
|
|
9
|
+
id,
|
|
10
|
+
kind: "lazy",
|
|
11
|
+
label,
|
|
12
|
+
status,
|
|
13
|
+
unresolved: status !== "resolved",
|
|
14
|
+
error: error && (0, _jfdevelops_react_layout_devtools_core.serializeInspectionError)(error)
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
update("unresolved");
|
|
18
|
+
if (parent) store.edge(parent, id, "declares");
|
|
19
|
+
return {
|
|
20
|
+
id,
|
|
21
|
+
store,
|
|
22
|
+
hooks: {
|
|
23
|
+
onLoadStart: () => update("loading"),
|
|
24
|
+
onLoadSuccess: () => update("resolved"),
|
|
25
|
+
onLoadError: (error) => update("error", error),
|
|
26
|
+
onMount: () => store.mount(id)
|
|
27
|
+
},
|
|
28
|
+
setLabel(value) {
|
|
29
|
+
label = value;
|
|
30
|
+
update("unresolved");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function withLazyHandle(target, handle) {
|
|
35
|
+
Object.defineProperties(target, {
|
|
36
|
+
preload: {
|
|
37
|
+
value: handle.preload,
|
|
38
|
+
enumerable: false
|
|
39
|
+
},
|
|
40
|
+
status: {
|
|
41
|
+
get: () => handle.status,
|
|
42
|
+
enumerable: false
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return target;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.inspectLazy = inspectLazy;
|
|
50
|
+
exports.withLazyHandle = withLazyHandle;
|
|
51
|
+
//# sourceMappingURL=inspection.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspection.cjs","names":[],"sources":["../../src/lazy/inspection.ts"],"sourcesContent":["import {\n createInspectionStore,\n inspectionId,\n serializeInspectionError,\n type InspectionStore,\n type LoadStatus,\n} from '@jfdevelops/react-layout-devtools-core';\nimport type { LazyResourceLoadHooks } from './create-lazy-loader';\nimport type { LazyResourceError } from '../errors/lazy-resource-error';\n\n/** Register a declaration before its import runs, retaining one node on retry. */\nexport function inspectLazy(\n label: string,\n store: InspectionStore = createInspectionStore(),\n parent?: string,\n) {\n const id = inspectionId('lazy');\n function update(status: LoadStatus, error?: LazyResourceError) {\n store.node({\n id,\n kind: 'lazy',\n label,\n status,\n unresolved: status !== 'resolved',\n error: error && serializeInspectionError(error),\n });\n }\n update('unresolved');\n if (parent) store.edge(parent, id, 'declares');\n const hooks: LazyResourceLoadHooks = {\n onLoadStart: () => update('loading'),\n onLoadSuccess: () => update('resolved'),\n onLoadError: (error) => update('error', error),\n onMount: () => store.mount(id),\n };\n return {\n id,\n store,\n hooks,\n setLabel(value: string) {\n label = value;\n update('unresolved');\n },\n };\n}\n\nexport function withLazyHandle<T extends object>(\n target: T,\n handle: import('./types').LazyHandle,\n): T & import('./types').LazyHandle {\n Object.defineProperties(target, {\n preload: { value: handle.preload, enumerable: false },\n status: { get: () => handle.status, enumerable: false },\n });\n return target as T & import('./types').LazyHandle;\n}\n"],"mappings":";;;;AAWA,SAAgB,YACd,OACA,0EAA+C,GAC/C,QACA;CACA,MAAM,8DAAkB,MAAM;CAC9B,SAAS,OAAO,QAAoB,OAA2B;EAC7D,MAAM,KAAK;GACT;GACA,MAAM;GACN;GACA;GACA,YAAY,WAAW;GACvB,OAAO,8EAAkC,KAAK;EAChD,CAAC;CACH;CACA,OAAO,YAAY;CACnB,IAAI,QAAQ,MAAM,KAAK,QAAQ,IAAI,UAAU;CAO7C,OAAO;EACL;EACA;EACA;GARA,mBAAmB,OAAO,SAAS;GACnC,qBAAqB,OAAO,UAAU;GACtC,cAAc,UAAU,OAAO,SAAS,KAAK;GAC7C,eAAe,MAAM,MAAM,EAAE;EAKzB;EACJ,SAAS,OAAe;GACtB,QAAQ;GACR,OAAO,YAAY;EACrB;CACF;AACF;AAEA,SAAgB,eACd,QACA,QACkC;CAClC,OAAO,iBAAiB,QAAQ;EAC9B,SAAS;GAAE,OAAO,OAAO;GAAS,YAAY;EAAM;EACpD,QAAQ;GAAE,WAAW,OAAO;GAAQ,YAAY;EAAM;CACxD,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LazyResourceLoadHooks } from "./create-lazy-loader.cjs";
|
|
2
|
+
import { InspectionStore } from "@jfdevelops/react-layout-devtools-core";
|
|
3
|
+
|
|
4
|
+
//#region src/lazy/inspection.d.ts
|
|
5
|
+
/** Register a declaration before its import runs, retaining one node on retry. */
|
|
6
|
+
declare function inspectLazy(label: string, store?: InspectionStore, parent?: string): {
|
|
7
|
+
id: string;
|
|
8
|
+
store: {
|
|
9
|
+
getSnapshot(): import("@jfdevelops/react-layout-devtools-core").GraphSnapshot;
|
|
10
|
+
subscribe(listener: () => void): () => void;
|
|
11
|
+
registerPreview(instance: import("@jfdevelops/react-layout-devtools-core").PreviewInstance, controller: import("@jfdevelops/react-layout-devtools-core").PreviewController): () => void;
|
|
12
|
+
preview(instanceId: string, state?: string): void;
|
|
13
|
+
previewError(instanceId: string, error: string): void;
|
|
14
|
+
connectPreview(): () => void;
|
|
15
|
+
node(node: Omit<import("@jfdevelops/react-layout-devtools-core").GraphNode, "active"> & {
|
|
16
|
+
active?: number;
|
|
17
|
+
}): string;
|
|
18
|
+
edge(source: string, target: string, relationship: import("@jfdevelops/react-layout-devtools-core").GraphEdge["relationship"]): void;
|
|
19
|
+
mount(...ids: string[]): () => void;
|
|
20
|
+
connect(value: object): void;
|
|
21
|
+
attach<T extends object>(value: T): T;
|
|
22
|
+
};
|
|
23
|
+
hooks: LazyResourceLoadHooks;
|
|
24
|
+
setLabel(value: string): void;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { inspectLazy };
|
|
28
|
+
//# sourceMappingURL=inspection.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspection.d.cts","names":[],"sources":["../../src/lazy/inspection.ts"],"mappings":";;;;;iBAWgB,WAAA,CACd,KAAA,UACA,KAAA,GAAO,eAAA,EACP,MAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LazyResourceLoadHooks } from "./create-lazy-loader.mjs";
|
|
2
|
+
import { InspectionStore } from "@jfdevelops/react-layout-devtools-core";
|
|
3
|
+
|
|
4
|
+
//#region src/lazy/inspection.d.ts
|
|
5
|
+
/** Register a declaration before its import runs, retaining one node on retry. */
|
|
6
|
+
declare function inspectLazy(label: string, store?: InspectionStore, parent?: string): {
|
|
7
|
+
id: string;
|
|
8
|
+
store: {
|
|
9
|
+
getSnapshot(): import("@jfdevelops/react-layout-devtools-core").GraphSnapshot;
|
|
10
|
+
subscribe(listener: () => void): () => void;
|
|
11
|
+
registerPreview(instance: import("@jfdevelops/react-layout-devtools-core").PreviewInstance, controller: import("@jfdevelops/react-layout-devtools-core").PreviewController): () => void;
|
|
12
|
+
preview(instanceId: string, state?: string): void;
|
|
13
|
+
previewError(instanceId: string, error: string): void;
|
|
14
|
+
connectPreview(): () => void;
|
|
15
|
+
node(node: Omit<import("@jfdevelops/react-layout-devtools-core").GraphNode, "active"> & {
|
|
16
|
+
active?: number;
|
|
17
|
+
}): string;
|
|
18
|
+
edge(source: string, target: string, relationship: import("@jfdevelops/react-layout-devtools-core").GraphEdge["relationship"]): void;
|
|
19
|
+
mount(...ids: string[]): () => void;
|
|
20
|
+
connect(value: object): void;
|
|
21
|
+
attach<T extends object>(value: T): T;
|
|
22
|
+
};
|
|
23
|
+
hooks: LazyResourceLoadHooks;
|
|
24
|
+
setLabel(value: string): void;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { inspectLazy };
|
|
28
|
+
//# sourceMappingURL=inspection.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspection.d.mts","names":[],"sources":["../../src/lazy/inspection.ts"],"mappings":";;;;;iBAWgB,WAAA,CACd,KAAA,UACA,KAAA,GAAO,eAAA,EACP,MAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createInspectionStore, inspectionId, serializeInspectionError } from "@jfdevelops/react-layout-devtools-core";
|
|
2
|
+
|
|
3
|
+
//#region src/lazy/inspection.ts
|
|
4
|
+
/** Register a declaration before its import runs, retaining one node on retry. */
|
|
5
|
+
function inspectLazy(label, store = createInspectionStore(), parent) {
|
|
6
|
+
const id = inspectionId("lazy");
|
|
7
|
+
function update(status, error) {
|
|
8
|
+
store.node({
|
|
9
|
+
id,
|
|
10
|
+
kind: "lazy",
|
|
11
|
+
label,
|
|
12
|
+
status,
|
|
13
|
+
unresolved: status !== "resolved",
|
|
14
|
+
error: error && serializeInspectionError(error)
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
update("unresolved");
|
|
18
|
+
if (parent) store.edge(parent, id, "declares");
|
|
19
|
+
return {
|
|
20
|
+
id,
|
|
21
|
+
store,
|
|
22
|
+
hooks: {
|
|
23
|
+
onLoadStart: () => update("loading"),
|
|
24
|
+
onLoadSuccess: () => update("resolved"),
|
|
25
|
+
onLoadError: (error) => update("error", error),
|
|
26
|
+
onMount: () => store.mount(id)
|
|
27
|
+
},
|
|
28
|
+
setLabel(value) {
|
|
29
|
+
label = value;
|
|
30
|
+
update("unresolved");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function withLazyHandle(target, handle) {
|
|
35
|
+
Object.defineProperties(target, {
|
|
36
|
+
preload: {
|
|
37
|
+
value: handle.preload,
|
|
38
|
+
enumerable: false
|
|
39
|
+
},
|
|
40
|
+
status: {
|
|
41
|
+
get: () => handle.status,
|
|
42
|
+
enumerable: false
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return target;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { inspectLazy, withLazyHandle };
|
|
50
|
+
//# sourceMappingURL=inspection.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspection.mjs","names":[],"sources":["../../src/lazy/inspection.ts"],"sourcesContent":["import {\n createInspectionStore,\n inspectionId,\n serializeInspectionError,\n type InspectionStore,\n type LoadStatus,\n} from '@jfdevelops/react-layout-devtools-core';\nimport type { LazyResourceLoadHooks } from './create-lazy-loader';\nimport type { LazyResourceError } from '../errors/lazy-resource-error';\n\n/** Register a declaration before its import runs, retaining one node on retry. */\nexport function inspectLazy(\n label: string,\n store: InspectionStore = createInspectionStore(),\n parent?: string,\n) {\n const id = inspectionId('lazy');\n function update(status: LoadStatus, error?: LazyResourceError) {\n store.node({\n id,\n kind: 'lazy',\n label,\n status,\n unresolved: status !== 'resolved',\n error: error && serializeInspectionError(error),\n });\n }\n update('unresolved');\n if (parent) store.edge(parent, id, 'declares');\n const hooks: LazyResourceLoadHooks = {\n onLoadStart: () => update('loading'),\n onLoadSuccess: () => update('resolved'),\n onLoadError: (error) => update('error', error),\n onMount: () => store.mount(id),\n };\n return {\n id,\n store,\n hooks,\n setLabel(value: string) {\n label = value;\n update('unresolved');\n },\n };\n}\n\nexport function withLazyHandle<T extends object>(\n target: T,\n handle: import('./types').LazyHandle,\n): T & import('./types').LazyHandle {\n Object.defineProperties(target, {\n preload: { value: handle.preload, enumerable: false },\n status: { get: () => handle.status, enumerable: false },\n });\n return target as T & import('./types').LazyHandle;\n}\n"],"mappings":";;;;AAWA,SAAgB,YACd,OACA,QAAyB,sBAAsB,GAC/C,QACA;CACA,MAAM,KAAK,aAAa,MAAM;CAC9B,SAAS,OAAO,QAAoB,OAA2B;EAC7D,MAAM,KAAK;GACT;GACA,MAAM;GACN;GACA;GACA,YAAY,WAAW;GACvB,OAAO,SAAS,yBAAyB,KAAK;EAChD,CAAC;CACH;CACA,OAAO,YAAY;CACnB,IAAI,QAAQ,MAAM,KAAK,QAAQ,IAAI,UAAU;CAO7C,OAAO;EACL;EACA;EACA;GARA,mBAAmB,OAAO,SAAS;GACnC,qBAAqB,OAAO,UAAU;GACtC,cAAc,UAAU,OAAO,SAAS,KAAK;GAC7C,eAAe,MAAM,MAAM,EAAE;EAKzB;EACJ,SAAS,OAAe;GACtB,QAAQ;GACR,OAAO,YAAY;EACrB;CACF;AACF;AAEA,SAAgB,eACd,QACA,QACkC;CAClC,OAAO,iBAAiB,QAAQ;EAC9B,SAAS;GAAE,OAAO,OAAO;GAAS,YAAY;EAAM;EACpD,QAAQ;GAAE,WAAW,OAAO;GAAQ,YAAY;EAAM;CACxD,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const require_lazy_resource_error = require('../errors/lazy-resource-error.cjs');
|
|
2
|
+
let react = require("react");
|
|
3
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/lazy-boundary.tsx
|
|
6
|
+
var LazyErrorBoundary = class extends react.Component {
|
|
7
|
+
state = {
|
|
8
|
+
failed: false,
|
|
9
|
+
error: void 0
|
|
10
|
+
};
|
|
11
|
+
static getDerivedStateFromError(error) {
|
|
12
|
+
return {
|
|
13
|
+
failed: true,
|
|
14
|
+
error
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
retry = () => {
|
|
18
|
+
this.props.onRetry();
|
|
19
|
+
this.setState({
|
|
20
|
+
failed: false,
|
|
21
|
+
error: void 0
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
render() {
|
|
25
|
+
if (!this.state.failed) return this.props.children;
|
|
26
|
+
const { ErrorComponent, resource } = this.props;
|
|
27
|
+
if (!require_lazy_resource_error.isLazyResourceError(this.state.error) || !ErrorComponent) throw this.state.error;
|
|
28
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, {
|
|
29
|
+
error: this.state.error,
|
|
30
|
+
retry: this.retry,
|
|
31
|
+
resource
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/** Shared loading, typed error handling and retry for all lazy components. */
|
|
36
|
+
function LazyBoundary({ loader, member, resource, fallback, ErrorComponent, componentProps, onMount, map }) {
|
|
37
|
+
const [, rerender] = (0, react.useReducer)((value) => value + 1, 0);
|
|
38
|
+
(0, react.useEffect)(() => onMount?.(), [onMount]);
|
|
39
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LazyErrorBoundary, {
|
|
40
|
+
resource,
|
|
41
|
+
ErrorComponent,
|
|
42
|
+
onRetry: () => {
|
|
43
|
+
loader.reset();
|
|
44
|
+
rerender();
|
|
45
|
+
},
|
|
46
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
|
|
47
|
+
fallback,
|
|
48
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(loader.component(member, map), { ...componentProps })
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
exports.LazyBoundary = LazyBoundary;
|
|
55
|
+
//# sourceMappingURL=lazy-boundary.cjs.map
|