@jfdevelops/react-layout 1.6.0 → 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.
Files changed (143) hide show
  1. package/dist/create-config/create-defined-resource-layout.cjs +18 -14
  2. package/dist/create-config/create-defined-resource-layout.cjs.map +1 -1
  3. package/dist/create-config/create-defined-resource-layout.d.cts +9 -5
  4. package/dist/create-config/create-defined-resource-layout.d.cts.map +1 -1
  5. package/dist/create-config/create-defined-resource-layout.d.mts +9 -5
  6. package/dist/create-config/create-defined-resource-layout.d.mts.map +1 -1
  7. package/dist/create-config/create-defined-resource-layout.mjs +19 -15
  8. package/dist/create-config/create-defined-resource-layout.mjs.map +1 -1
  9. package/dist/create-config/define-layout.cjs +66 -39
  10. package/dist/create-config/define-layout.cjs.map +1 -1
  11. package/dist/create-config/define-layout.d.cts +0 -5
  12. package/dist/create-config/define-layout.d.cts.map +1 -1
  13. package/dist/create-config/define-layout.d.mts +0 -5
  14. package/dist/create-config/define-layout.d.mts.map +1 -1
  15. package/dist/create-config/define-layout.mjs +67 -40
  16. package/dist/create-config/define-layout.mjs.map +1 -1
  17. package/dist/create-config/for-resources/create-component.d.cts +39 -21
  18. package/dist/create-config/for-resources/create-component.d.cts.map +1 -1
  19. package/dist/create-config/for-resources/create-component.d.mts +39 -21
  20. package/dist/create-config/for-resources/create-component.d.mts.map +1 -1
  21. package/dist/create-config/for-resources/create-for-resources.cjs +62 -7
  22. package/dist/create-config/for-resources/create-for-resources.cjs.map +1 -1
  23. package/dist/create-config/for-resources/create-for-resources.mjs +62 -7
  24. package/dist/create-config/for-resources/create-for-resources.mjs.map +1 -1
  25. package/dist/create-config/for-resources/scoped-render.cjs +1 -0
  26. package/dist/create-config/for-resources/scoped-render.cjs.map +1 -1
  27. package/dist/create-config/for-resources/scoped-render.d.cts.map +1 -1
  28. package/dist/create-config/for-resources/scoped-render.d.mts.map +1 -1
  29. package/dist/create-config/for-resources/scoped-render.mjs +1 -0
  30. package/dist/create-config/for-resources/scoped-render.mjs.map +1 -1
  31. package/dist/create-config/index.d.cts +2 -1
  32. package/dist/create-config/index.d.mts +2 -1
  33. package/dist/create-config/layout-name.cjs +36 -28
  34. package/dist/create-config/layout-name.cjs.map +1 -1
  35. package/dist/create-config/layout-name.d.cts +34 -28
  36. package/dist/create-config/layout-name.d.cts.map +1 -1
  37. package/dist/create-config/layout-name.d.mts +34 -28
  38. package/dist/create-config/layout-name.d.mts.map +1 -1
  39. package/dist/create-config/layout-name.mjs +36 -28
  40. package/dist/create-config/layout-name.mjs.map +1 -1
  41. package/dist/create-config/lazy-resource-layout.cjs +70 -86
  42. package/dist/create-config/lazy-resource-layout.cjs.map +1 -1
  43. package/dist/create-config/lazy-resource-layout.d.cts +9 -31
  44. package/dist/create-config/lazy-resource-layout.d.cts.map +1 -1
  45. package/dist/create-config/lazy-resource-layout.d.mts +9 -31
  46. package/dist/create-config/lazy-resource-layout.d.mts.map +1 -1
  47. package/dist/create-config/lazy-resource-layout.mjs +70 -86
  48. package/dist/create-config/lazy-resource-layout.mjs.map +1 -1
  49. package/dist/create-config/preview.cjs +1 -1
  50. package/dist/create-config/preview.d.cts +2 -0
  51. package/dist/create-config/preview.d.cts.map +1 -1
  52. package/dist/create-config/preview.d.mts +2 -0
  53. package/dist/create-config/preview.d.mts.map +1 -1
  54. package/dist/create-config/preview.mjs +1 -1
  55. package/dist/create-config/render-state.cjs +57 -18
  56. package/dist/create-config/render-state.cjs.map +1 -1
  57. package/dist/create-config/render-state.d.cts +18 -6
  58. package/dist/create-config/render-state.d.cts.map +1 -1
  59. package/dist/create-config/render-state.d.mts +18 -6
  60. package/dist/create-config/render-state.d.mts.map +1 -1
  61. package/dist/create-config/render-state.mjs +54 -18
  62. package/dist/create-config/render-state.mjs.map +1 -1
  63. package/dist/errors/lazy-resource-error.cjs +37 -0
  64. package/dist/errors/lazy-resource-error.cjs.map +1 -0
  65. package/dist/errors/lazy-resource-error.d.cts +26 -0
  66. package/dist/errors/lazy-resource-error.d.cts.map +1 -0
  67. package/dist/errors/lazy-resource-error.d.mts +26 -0
  68. package/dist/errors/lazy-resource-error.d.mts.map +1 -0
  69. package/dist/errors/lazy-resource-error.mjs +35 -0
  70. package/dist/errors/lazy-resource-error.mjs.map +1 -0
  71. package/dist/errors/react-layout-error.cjs +1 -1
  72. package/dist/errors/react-layout-error.mjs +1 -1
  73. package/dist/errors/resource-state-error.cjs +4 -1
  74. package/dist/errors/resource-state-error.cjs.map +1 -1
  75. package/dist/errors/resource-state-error.d.cts +1 -0
  76. package/dist/errors/resource-state-error.d.cts.map +1 -1
  77. package/dist/errors/resource-state-error.d.mts +1 -0
  78. package/dist/errors/resource-state-error.d.mts.map +1 -1
  79. package/dist/errors/resource-state-error.mjs +4 -1
  80. package/dist/errors/resource-state-error.mjs.map +1 -1
  81. package/dist/index.cjs +6 -2
  82. package/dist/index.d.cts +7 -4
  83. package/dist/index.d.mts +7 -4
  84. package/dist/index.mjs +4 -3
  85. package/dist/lazy/create-error-component.cjs +17 -0
  86. package/dist/lazy/create-error-component.cjs.map +1 -0
  87. package/dist/lazy/create-error-component.mjs +16 -0
  88. package/dist/lazy/create-error-component.mjs.map +1 -0
  89. package/dist/lazy/create-lazy-loader.cjs +78 -0
  90. package/dist/lazy/create-lazy-loader.cjs.map +1 -0
  91. package/dist/lazy/create-lazy-loader.d.cts +19 -0
  92. package/dist/lazy/create-lazy-loader.d.cts.map +1 -0
  93. package/dist/lazy/create-lazy-loader.d.mts +19 -0
  94. package/dist/lazy/create-lazy-loader.d.mts.map +1 -0
  95. package/dist/lazy/create-lazy-loader.mjs +78 -0
  96. package/dist/lazy/create-lazy-loader.mjs.map +1 -0
  97. package/dist/lazy/fallback-props.cjs +9 -0
  98. package/dist/lazy/fallback-props.cjs.map +1 -0
  99. package/dist/lazy/fallback-props.mjs +9 -0
  100. package/dist/lazy/fallback-props.mjs.map +1 -0
  101. package/dist/lazy/inspection.cjs +51 -0
  102. package/dist/lazy/inspection.cjs.map +1 -0
  103. package/dist/lazy/inspection.d.cts +28 -0
  104. package/dist/lazy/inspection.d.cts.map +1 -0
  105. package/dist/lazy/inspection.d.mts +28 -0
  106. package/dist/lazy/inspection.d.mts.map +1 -0
  107. package/dist/lazy/inspection.mjs +50 -0
  108. package/dist/lazy/inspection.mjs.map +1 -0
  109. package/dist/lazy/lazy-boundary.cjs +55 -0
  110. package/dist/lazy/lazy-boundary.cjs.map +1 -0
  111. package/dist/lazy/lazy-boundary.mjs +55 -0
  112. package/dist/lazy/lazy-boundary.mjs.map +1 -0
  113. package/dist/lazy/scoped-content.cjs +87 -0
  114. package/dist/lazy/scoped-content.cjs.map +1 -0
  115. package/dist/lazy/scoped-content.d.cts +19 -0
  116. package/dist/lazy/scoped-content.d.cts.map +1 -0
  117. package/dist/lazy/scoped-content.d.mts +19 -0
  118. package/dist/lazy/scoped-content.d.mts.map +1 -0
  119. package/dist/lazy/scoped-content.mjs +86 -0
  120. package/dist/lazy/scoped-content.mjs.map +1 -0
  121. package/dist/lazy/types.cjs +10 -0
  122. package/dist/lazy/types.cjs.map +1 -0
  123. package/dist/lazy/types.d.cts +39 -0
  124. package/dist/lazy/types.d.cts.map +1 -0
  125. package/dist/lazy/types.d.mts +39 -0
  126. package/dist/lazy/types.d.mts.map +1 -0
  127. package/dist/lazy/types.mjs +8 -0
  128. package/dist/lazy/types.mjs.map +1 -0
  129. package/dist/props.cjs +4 -2
  130. package/dist/props.cjs.map +1 -1
  131. package/dist/props.d.cts +6 -50
  132. package/dist/props.d.cts.map +1 -1
  133. package/dist/props.d.mts +6 -50
  134. package/dist/props.d.mts.map +1 -1
  135. package/dist/props.mjs +5 -2
  136. package/dist/props.mjs.map +1 -1
  137. package/dist/resource.cjs.map +1 -1
  138. package/dist/resource.d.cts +1 -1
  139. package/dist/resource.d.cts.map +1 -1
  140. package/dist/resource.d.mts +1 -1
  141. package/dist/resource.d.mts.map +1 -1
  142. package/dist/resource.mjs.map +1 -1
  143. package/package.json +2 -2
@@ -1,109 +1,93 @@
1
- const require_layout_configuration_error = require('../errors/layout-configuration-error.cjs');
2
- const require_resource_state_error = require('../errors/resource-state-error.cjs');
1
+ const require_lazy_resource_error = require('../errors/lazy-resource-error.cjs');
2
+ const require_lazy_boundary = require('../lazy/lazy-boundary.cjs');
3
+ const require_create_lazy_loader = require('../lazy/create-lazy-loader.cjs');
3
4
  const require_render_state = require('./render-state.cjs');
4
- let react = require("react");
5
5
  let react_jsx_runtime = require("react/jsx-runtime");
6
6
  let _jfdevelops_react_layout_validator = require("@jfdevelops/react-layout-validator");
7
7
 
8
8
  //#region src/create-config/lazy-resource-layout.tsx
9
- var LazyResourceErrorBoundary = class extends react.Component {
10
- state = {};
11
- static getDerivedStateFromError(error) {
12
- return { error };
13
- }
14
- retry = () => {
15
- this.props.onRetry();
16
- this.setState({ error: void 0 });
17
- };
18
- render() {
19
- if (this.state.error !== void 0) {
20
- const { ErrorComponent } = this.props;
21
- if (!ErrorComponent) throw this.state.error;
22
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, {
23
- error: this.state.error,
24
- retry: this.retry
25
- });
26
- }
27
- return this.props.children;
28
- }
29
- };
30
- function findDefinedLayoutComponent(module) {
9
+ function findDefinedLayoutComponent(module, resource) {
31
10
  const components = Object.values(module).map((value) => typeof value === "object" && value !== null && "Root" in value ? value.Root : value).filter((value) => typeof value === "function" && require_render_state.definedResourceLayoutComponentSymbol in value);
32
- if (components.length !== 1) throw new require_layout_configuration_error.LayoutConfigurationError(`A lazy resource module must export exactly one created resource layout component; received ${components.length}`);
11
+ if (components.length !== 1) throw new require_lazy_resource_error.LazyResourceModuleShapeError(resource, components.length);
33
12
  return components[0];
34
13
  }
35
- /**
36
- * Creates a cached lazy proxy for a resource component and all of its compound
37
- * state components. This is normally called through
38
- * `defineResourceLayout.lazy(...)`, which supplies shared defaults.
39
- */
40
- function createLazyResourceLayout(options, defaults) {
41
- const runtimeOptions = options;
42
- let loadedComponentPromise;
43
- const stateComponents = /* @__PURE__ */ new Map();
44
- const resolvedStates = {
14
+ /** Cached resource component and its compound states, backed by the shared loader. */
15
+ function createLazyResourceLayout(options, defaults, hooks = {}) {
16
+ const runtime = options;
17
+ const resource = runtime.resource;
18
+ const states = {
45
19
  ...defaults,
46
- ...runtimeOptions.states
20
+ ...runtime.states
47
21
  };
48
- function loadComponent() {
49
- loadedComponentPromise ??= runtimeOptions.load().then(findDefinedLayoutComponent).catch((error) => {
50
- throw new require_resource_state_error.ResourceModuleLoadError(runtimeOptions.resource, error);
51
- });
52
- return loadedComponentPromise;
53
- }
54
- function resetLoad() {
55
- loadedComponentPromise = void 0;
56
- stateComponents.clear();
57
- }
58
- function createMemberComponent(member) {
59
- function createLazyComponent() {
60
- return (0, react.lazy)(async () => {
61
- const component = await loadComponent();
62
- const selected = member === void 0 ? component : component[member];
63
- if (typeof selected !== "function") throw new require_layout_configuration_error.LayoutConfigurationError(`Lazy resource "${runtimeOptions.resource}" does not define state "${String(member)}"`);
64
- return { default: selected };
65
- });
66
- }
22
+ const loader = require_create_lazy_loader.createLazyLoader({
23
+ load: runtime.load,
24
+ select: (module) => findDefinedLayoutComponent(module, resource),
25
+ label: resource,
26
+ hooks
27
+ });
28
+ const members = /* @__PURE__ */ new Map();
29
+ function createMember(member) {
67
30
  function LazyMember(props) {
68
- const [, rerender] = (0, react.useReducer)((version) => version + 1, 0);
69
- const LazyComponent = (0, react.useRef)(createLazyComponent());
70
- const LoadingComponent = resolvedStates.Loading;
71
- const CurrentLazyComponent = LazyComponent.current;
72
- function retry() {
73
- resetLoad();
74
- LazyComponent.current = createLazyComponent();
75
- rerender();
76
- }
77
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LazyResourceErrorBoundary, {
78
- ErrorComponent: resolvedStates.Error,
79
- onRetry: retry,
80
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
81
- fallback: LoadingComponent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingComponent, {}) : null,
82
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CurrentLazyComponent, { ...props })
83
- })
31
+ const Loading = states.Loading;
32
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_lazy_boundary.LazyBoundary, {
33
+ loader,
34
+ member,
35
+ resource,
36
+ componentProps: props,
37
+ ErrorComponent: states.Error,
38
+ onMount: hooks.onMount,
39
+ fallback: runtime.fallback !== void 0 ? runtime.fallback : Loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Loading, { resource }) : null
84
40
  });
85
41
  }
86
- const resourceName = runtimeOptions.resource;
87
- LazyMember.displayName = member === void 0 ? `LazyResource(${resourceName})` : `LazyResource(${resourceName}).${String(member)}`;
42
+ LazyMember.displayName = `LazyResource(${resource})${member ? `.${member}` : ""}`;
43
+ Object.defineProperties(LazyMember, {
44
+ preload: { value: loader.preload },
45
+ status: { get: () => loader.status }
46
+ });
88
47
  return LazyMember;
89
48
  }
90
- const Component = createMemberComponent();
91
- const unsupportedStatics = new Set([
49
+ const Component = createMember();
50
+ const reservedStatics = new Set([
92
51
  "makeComposable",
93
52
  "props",
94
53
  "resource",
95
54
  _jfdevelops_react_layout_validator.componentPropDefinitionsSymbol,
96
- require_render_state.definedResourceLayoutComponentSymbol
55
+ require_render_state.definedResourceLayoutComponentSymbol,
56
+ "contextTypes",
57
+ "childContextTypes",
58
+ "contextType",
59
+ "propTypes",
60
+ "defaultProps",
61
+ "getDerivedStateFromProps",
62
+ "getDerivedStateFromError",
63
+ "getDefaultProps",
64
+ "$$typeof",
65
+ "_payload",
66
+ "_init",
67
+ "render",
68
+ "compare",
69
+ "type",
70
+ "then",
71
+ "catch",
72
+ "finally",
73
+ "toJSON",
74
+ "asymmetricMatch",
75
+ "__esModule",
76
+ "default"
97
77
  ]);
98
- return new Proxy(Component, { get(target, property, receiver) {
99
- if (Reflect.has(target, property)) return Reflect.get(target, property, receiver);
100
- if (typeof property !== "string" || unsupportedStatics.has(property)) return;
101
- const existing = stateComponents.get(property);
102
- if (existing) return existing;
103
- const stateComponent = createMemberComponent(property);
104
- stateComponents.set(property, stateComponent);
105
- return stateComponent;
106
- } });
78
+ return new Proxy(Component, {
79
+ get(target, property, receiver) {
80
+ if (Reflect.has(target, property)) return Reflect.get(target, property, receiver);
81
+ if (typeof property !== "string" || reservedStatics.has(property) || !/^[A-Z]/.test(property)) return void 0;
82
+ let component = members.get(property);
83
+ if (!component) {
84
+ component = createMember(property);
85
+ members.set(property, component);
86
+ }
87
+ return component;
88
+ },
89
+ has: (target, property) => Reflect.has(target, property)
90
+ });
107
91
  }
108
92
 
109
93
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"lazy-resource-layout.cjs","names":["Component","definedResourceLayoutComponentSymbol","LayoutConfigurationError","ResourceModuleLoadError","Suspense","componentPropDefinitionsSymbol"],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"sourcesContent":["import {\n Component,\n type ComponentProps,\n type ComponentType,\n type JSX,\n lazy,\n Suspense,\n useReducer,\n useRef,\n} from 'react';\nimport {\n LayoutConfigurationError,\n ResourceModuleLoadError,\n} from '../errors';\nimport { componentPropDefinitionsSymbol } from '@jfdevelops/react-layout-validator';\nimport type { ResourcePath, ResourceDefinition } from '../resource';\nimport { definedResourceLayoutComponentSymbol } from './render-state';\n\ntype DefinedLayoutComponent = ComponentType<any> & {\n readonly [definedResourceLayoutComponentSymbol]: true;\n};\n\ntype UnwrapDefinedLayout<Export> = Export extends DefinedLayoutComponent\n ? Export\n : Export extends { Root: infer Root extends DefinedLayoutComponent }\n ? Root\n : never;\n\ntype DefinedLayoutFromModule<Module> = UnwrapDefinedLayout<Module[keyof Module]>;\n\ntype LazyUnsupportedStatic =\n | 'makeComposable'\n | 'props'\n | 'resource'\n | typeof componentPropDefinitionsSymbol\n | typeof definedResourceLayoutComponentSymbol;\n\n/**\n * Public surface available before a lazy module resolves. Component metadata\n * and composition factories are intentionally omitted because they cannot be\n * read synchronously without loading the module.\n */\nexport type LazyResourceLayoutComponent<Module> = ComponentType<\n ComponentProps<DefinedLayoutFromModule<Module>>\n> &\n Pick<\n DefinedLayoutFromModule<Module>,\n Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>\n >;\n\n/** Component rendered while a resource module or one of its states is loading. */\nexport type LazyResourceLoadingComponent = ComponentType;\n/**\n * Component rendered when a resource module cannot be loaded. Calling\n * `retry` discards React's rejected lazy cache entry and imports it again.\n */\nexport type LazyResourceErrorComponent = ComponentType<{\n error: unknown;\n retry: () => void;\n}>;\n\n/** Loading and module-error UI used around a lazy resource component. */\nexport type LazyResourceStates = {\n Error?: LazyResourceErrorComponent;\n Loading?: LazyResourceLoadingComponent;\n};\n\n/**\n * Configuration for a lazy resource component. `resource` is checked against\n * the bound resource paths, including dot-delimited subresources, and `load`\n * must resolve to a module with exactly one created resource component.\n */\nexport type LazyResourceLayoutOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n> = {\n load: () => Promise<Module>;\n resource: ResourcePath<Resources>;\n states?: LazyResourceStates;\n};\n\ntype BoundaryProps = {\n children: JSX.Element;\n ErrorComponent?: LazyResourceErrorComponent;\n onRetry: () => void;\n};\n\ntype BoundaryState = {\n error?: unknown;\n};\n\nclass LazyResourceErrorBoundary extends Component<\n BoundaryProps,\n BoundaryState\n> {\n state: BoundaryState = {};\n\n static getDerivedStateFromError(error: unknown): BoundaryState {\n return { error };\n }\n\n retry = () => {\n this.props.onRetry();\n this.setState({ error: undefined });\n };\n\n render() {\n if (this.state.error !== undefined) {\n const { ErrorComponent } = this.props;\n\n if (!ErrorComponent) {\n throw this.state.error;\n }\n\n return <ErrorComponent error={this.state.error} retry={this.retry} />;\n }\n\n return this.props.children;\n }\n}\n\nfunction findDefinedLayoutComponent(module: Record<string, unknown>) {\n const components = Object.values(module)\n .map((value) =>\n typeof value === 'object' && value !== null && 'Root' in value\n ? value.Root\n : value,\n )\n .filter(\n (value): value is DefinedLayoutComponent =>\n typeof value === 'function' &&\n definedResourceLayoutComponentSymbol in value,\n );\n\n if (components.length !== 1) {\n throw new LayoutConfigurationError(\n `A lazy resource module must export exactly one created resource layout component; received ${components.length}`,\n );\n }\n\n return components[0];\n}\n\n/**\n * Creates a cached lazy proxy for a resource component and all of its compound\n * state components. This is normally called through\n * `defineResourceLayout.lazy(...)`, which supplies shared defaults.\n */\nexport function createLazyResourceLayout<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n>(\n options: LazyResourceLayoutOptions<Resources, Module>,\n defaults: LazyResourceStates,\n): LazyResourceLayoutComponent<Module> {\n const runtimeOptions = options as {\n load: () => Promise<Record<string, unknown>>;\n resource: string;\n states?: LazyResourceStates;\n };\n let loadedComponentPromise: Promise<DefinedLayoutComponent> | undefined;\n const stateComponents = new Map<PropertyKey, ComponentType<any>>();\n const resolvedStates = { ...defaults, ...runtimeOptions.states };\n\n function loadComponent() {\n loadedComponentPromise ??= runtimeOptions\n .load()\n .then(findDefinedLayoutComponent)\n .catch((error: unknown) => {\n throw new ResourceModuleLoadError(runtimeOptions.resource, error);\n });\n\n return loadedComponentPromise;\n }\n\n function resetLoad() {\n loadedComponentPromise = undefined;\n stateComponents.clear();\n }\n\n function createMemberComponent(member?: PropertyKey) {\n function createLazyComponent() {\n return lazy(async () => {\n const component = await loadComponent();\n const selected =\n member === undefined\n ? component\n : (component as unknown as Record<PropertyKey, unknown>)[member];\n\n if (typeof selected !== 'function') {\n throw new LayoutConfigurationError(\n `Lazy resource \"${runtimeOptions.resource}\" does not define state \"${String(member)}\"`,\n );\n }\n\n return { default: selected as ComponentType<any> };\n });\n }\n\n function LazyMember(props: Record<string, unknown>) {\n const [, rerender] = useReducer((version) => version + 1, 0);\n const LazyComponent = useRef(createLazyComponent());\n const LoadingComponent = resolvedStates.Loading;\n const CurrentLazyComponent = LazyComponent.current;\n\n function retry() {\n resetLoad();\n LazyComponent.current = createLazyComponent();\n rerender();\n }\n\n return (\n <LazyResourceErrorBoundary\n ErrorComponent={resolvedStates.Error}\n onRetry={retry}\n >\n <Suspense\n fallback={LoadingComponent ? <LoadingComponent /> : null}\n >\n <CurrentLazyComponent {...props} />\n </Suspense>\n </LazyResourceErrorBoundary>\n );\n }\n\n const resourceName = runtimeOptions.resource;\n LazyMember.displayName =\n member === undefined\n ? `LazyResource(${resourceName})`\n : `LazyResource(${resourceName}).${String(member)}`;\n\n return LazyMember;\n }\n\n const Component = createMemberComponent();\n const unsupportedStatics = new Set<PropertyKey>([\n 'makeComposable',\n 'props',\n 'resource',\n componentPropDefinitionsSymbol,\n definedResourceLayoutComponentSymbol,\n ]);\n\n return new Proxy(Component, {\n get(target, property, receiver) {\n if (Reflect.has(target, property)) {\n return Reflect.get(target, property, receiver);\n }\n\n if (typeof property !== 'string' || unsupportedStatics.has(property)) {\n return undefined;\n }\n\n const existing = stateComponents.get(property);\n\n if (existing) {\n return existing;\n }\n\n const stateComponent = createMemberComponent(property);\n stateComponents.set(property, stateComponent);\n\n return stateComponent;\n },\n }) as unknown as LazyResourceLayoutComponent<Module>;\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"lazy-resource-layout.cjs","names":["definedResourceLayoutComponentSymbol","LazyResourceModuleShapeError","createLazyLoader","LazyBoundary","componentPropDefinitionsSymbol"],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"sourcesContent":["import { type ComponentProps, type ComponentType } from 'react';\nimport { LazyResourceModuleShapeError } from '../errors/lazy-resource-error';\nimport { componentPropDefinitionsSymbol } from '@jfdevelops/react-layout-validator';\nimport type { ResourcePath, ResourceDefinition } from '../resource';\nimport { definedResourceLayoutComponentSymbol } from './render-state';\nimport {\n createLazyLoader,\n type LazyResourceLoadHooks,\n} from '../lazy/create-lazy-loader';\nimport { LazyBoundary } from '../lazy/lazy-boundary';\nimport type {\n LazyHandle,\n LazyOptions,\n LazyResourceStates,\n} from '../lazy/types';\nexport type {\n LazyResourceErrorComponent,\n LazyResourceLoadingComponent,\n LazyResourceStates,\n} from '../lazy/types';\nexport type { LazyResourceLoadHooks } from '../lazy/create-lazy-loader';\n\ntype DefinedLayoutComponent = ComponentType<any> & {\n readonly [definedResourceLayoutComponentSymbol]: true;\n};\n\ntype UnwrapDefinedLayout<Export> = Export extends DefinedLayoutComponent\n ? Export\n : Export extends { Root: infer Root extends DefinedLayoutComponent }\n ? Root\n : never;\n\ntype DefinedLayoutFromModule<Module> = UnwrapDefinedLayout<\n Module[keyof Module]\n>;\n\ntype LazyUnsupportedStatic =\n | 'makeComposable'\n | 'props'\n | 'resource'\n | typeof componentPropDefinitionsSymbol\n | typeof definedResourceLayoutComponentSymbol;\n\n/**\n * Public surface available before a lazy module resolves. Component metadata\n * and composition factories are intentionally omitted because they cannot be\n * read synchronously without loading the module.\n */\nexport type LazyResourceLayoutComponent<Module> = ComponentType<\n ComponentProps<DefinedLayoutFromModule<Module>>\n> &\n LazyHandle &\n Pick<\n DefinedLayoutFromModule<Module>,\n Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>\n >;\n\n/** Lazy resource options, sharing import and fallback semantics with lazy states. */\nexport type LazyResourceLayoutOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n> = LazyOptions<Module> & {\n resource: ResourcePath<Resources>;\n states?: LazyResourceStates<ResourcePath<Resources>>;\n};\n\nfunction findDefinedLayoutComponent(\n module: Record<string, unknown>,\n resource: string,\n) {\n const components = Object.values(module)\n .map((value) =>\n typeof value === 'object' && value !== null && 'Root' in value\n ? value.Root\n : value,\n )\n .filter(\n (value): value is DefinedLayoutComponent =>\n typeof value === 'function' &&\n definedResourceLayoutComponentSymbol in value,\n );\n if (components.length !== 1)\n throw new LazyResourceModuleShapeError(resource, components.length);\n return components[0];\n}\n\n/** Cached resource component and its compound states, backed by the shared loader. */\nexport function createLazyResourceLayout<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n>(\n options: LazyResourceLayoutOptions<Resources, Module>,\n defaults: LazyResourceStates<any>,\n hooks: LazyResourceLoadHooks = {},\n): LazyResourceLayoutComponent<Module> {\n const runtime = options as unknown as LazyOptions<Module> & {\n resource: string;\n states?: LazyResourceStates;\n };\n const resource = runtime.resource;\n const states = { ...defaults, ...runtime.states } as LazyResourceStates;\n const loader = createLazyLoader({\n load: runtime.load,\n select: (module) => findDefinedLayoutComponent(module, resource),\n label: resource,\n hooks,\n });\n const members = new Map<string, ComponentType<any>>();\n function createMember(member?: string) {\n function LazyMember(props: Record<string, unknown>) {\n const Loading = states.Loading;\n return (\n <LazyBoundary\n loader={loader}\n member={member}\n resource={resource}\n componentProps={props}\n ErrorComponent={states.Error}\n onMount={hooks.onMount}\n fallback={\n runtime.fallback !== undefined ? (\n runtime.fallback\n ) : Loading ? (\n <Loading resource={resource} />\n ) : null\n }\n />\n );\n }\n LazyMember.displayName = `LazyResource(${resource})${member ? `.${member}` : ''}`;\n Object.defineProperties(LazyMember, {\n preload: { value: loader.preload },\n status: { get: () => loader.status },\n });\n return LazyMember;\n }\n const Component = createMember();\n const reservedStatics = new Set<PropertyKey>([\n 'makeComposable',\n 'props',\n 'resource',\n componentPropDefinitionsSymbol,\n definedResourceLayoutComponentSymbol,\n 'contextTypes',\n 'childContextTypes',\n 'contextType',\n 'propTypes',\n 'defaultProps',\n 'getDerivedStateFromProps',\n 'getDerivedStateFromError',\n 'getDefaultProps',\n '$$typeof',\n '_payload',\n '_init',\n 'render',\n 'compare',\n 'type',\n 'then',\n 'catch',\n 'finally',\n 'toJSON',\n 'asymmetricMatch',\n '__esModule',\n 'default',\n ]);\n return new Proxy(Component, {\n get(target, property, receiver) {\n if (Reflect.has(target, property))\n return Reflect.get(target, property, receiver);\n if (\n typeof property !== 'string' ||\n reservedStatics.has(property) ||\n !/^[A-Z]/.test(property)\n )\n return undefined;\n let component = members.get(property);\n if (!component) {\n component = createMember(property);\n members.set(property, component);\n }\n return component;\n },\n has: (target, property) => Reflect.has(target, property),\n }) as unknown as LazyResourceLayoutComponent<Module>;\n}\n"],"mappings":";;;;;;;;AAkEA,SAAS,2BACP,QACA,UACA;CACA,MAAM,aAAa,OAAO,OAAO,MAAM,EACpC,KAAK,UACJ,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,QACrD,MAAM,OACN,KACN,EACC,QACE,UACC,OAAO,UAAU,cACjBA,6DAAwC,KAC5C;CACF,IAAI,WAAW,WAAW,GACxB,MAAM,IAAIC,yDAA6B,UAAU,WAAW,MAAM;CACpE,OAAO,WAAW;AACpB;;AAGA,SAAgB,yBAId,SACA,UACA,QAA+B,CAAC,GACK;CACrC,MAAM,UAAU;CAIhB,MAAM,WAAW,QAAQ;CACzB,MAAM,SAAS;EAAE,GAAG;EAAU,GAAG,QAAQ;CAAO;CAChD,MAAM,SAASC,4CAAiB;EAC9B,MAAM,QAAQ;EACd,SAAS,WAAW,2BAA2B,QAAQ,QAAQ;EAC/D,OAAO;EACP;CACF,CAAC;CACD,MAAM,0BAAU,IAAI,IAAgC;CACpD,SAAS,aAAa,QAAiB;EACrC,SAAS,WAAW,OAAgC;GAClD,MAAM,UAAU,OAAO;GACvB,OACE,2CAACC,oCAAD;IACU;IACA;IACE;IACV,gBAAgB;IAChB,gBAAgB,OAAO;IACvB,SAAS,MAAM;IACf,UACE,QAAQ,aAAa,SACnB,QAAQ,WACN,UACF,2CAAC,SAAD,EAAmB,SAAW,KAC5B;GAEP;EAEL;EACA,WAAW,cAAc,gBAAgB,SAAS,GAAG,SAAS,IAAI,WAAW;EAC7E,OAAO,iBAAiB,YAAY;GAClC,SAAS,EAAE,OAAO,OAAO,QAAQ;GACjC,QAAQ,EAAE,WAAW,OAAO,OAAO;EACrC,CAAC;EACD,OAAO;CACT;CACA,MAAM,YAAY,aAAa;CAC/B,MAAM,kBAAkB,IAAI,IAAiB;EAC3C;EACA;EACA;EACAC;EACAJ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OAAO,IAAI,MAAM,WAAW;EAC1B,IAAI,QAAQ,UAAU,UAAU;GAC9B,IAAI,QAAQ,IAAI,QAAQ,QAAQ,GAC9B,OAAO,QAAQ,IAAI,QAAQ,UAAU,QAAQ;GAC/C,IACE,OAAO,aAAa,YACpB,gBAAgB,IAAI,QAAQ,KAC5B,CAAC,SAAS,KAAK,QAAQ,GAEvB,OAAO;GACT,IAAI,YAAY,QAAQ,IAAI,QAAQ;GACpC,IAAI,CAAC,WAAW;IACd,YAAY,aAAa,QAAQ;IACjC,QAAQ,IAAI,UAAU,SAAS;GACjC;GACA,OAAO;EACT;EACA,MAAM,QAAQ,aAAa,QAAQ,IAAI,QAAQ,QAAQ;CACzD,CAAC;AACH"}
@@ -1,3 +1,5 @@
1
+ import { LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceLoadingComponent, LazyResourceStates } from "../lazy/types.cjs";
2
+ import { LazyResourceLoadHooks } from "../lazy/create-lazy-loader.cjs";
1
3
  import { ResourceDefinition, ResourcePath } from "../resource.cjs";
2
4
  import { definedResourceLayoutComponentSymbol } from "./render-state.cjs";
3
5
  import { ComponentProps, ComponentType } from "react";
@@ -17,38 +19,14 @@ type LazyUnsupportedStatic = 'makeComposable' | 'props' | 'resource' | typeof co
17
19
  * and composition factories are intentionally omitted because they cannot be
18
20
  * read synchronously without loading the module.
19
21
  */
20
- type LazyResourceLayoutComponent<Module> = ComponentType<ComponentProps<DefinedLayoutFromModule<Module>>> & Pick<DefinedLayoutFromModule<Module>, Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>>;
21
- /** Component rendered while a resource module or one of its states is loading. */
22
- type LazyResourceLoadingComponent = ComponentType;
23
- /**
24
- * Component rendered when a resource module cannot be loaded. Calling
25
- * `retry` discards React's rejected lazy cache entry and imports it again.
26
- */
27
- type LazyResourceErrorComponent = ComponentType<{
28
- error: unknown;
29
- retry: () => void;
30
- }>;
31
- /** Loading and module-error UI used around a lazy resource component. */
32
- type LazyResourceStates = {
33
- Error?: LazyResourceErrorComponent;
34
- Loading?: LazyResourceLoadingComponent;
35
- };
36
- /**
37
- * Configuration for a lazy resource component. `resource` is checked against
38
- * the bound resource paths, including dot-delimited subresources, and `load`
39
- * must resolve to a module with exactly one created resource component.
40
- */
41
- type LazyResourceLayoutOptions<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>> = {
42
- load: () => Promise<Module>;
22
+ type LazyResourceLayoutComponent<Module> = ComponentType<ComponentProps<DefinedLayoutFromModule<Module>>> & LazyHandle & Pick<DefinedLayoutFromModule<Module>, Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>>;
23
+ /** Lazy resource options, sharing import and fallback semantics with lazy states. */
24
+ type LazyResourceLayoutOptions<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>> = LazyOptions<Module> & {
43
25
  resource: ResourcePath<Resources>;
44
- states?: LazyResourceStates;
26
+ states?: LazyResourceStates<ResourcePath<Resources>>;
45
27
  };
46
- /**
47
- * Creates a cached lazy proxy for a resource component and all of its compound
48
- * state components. This is normally called through
49
- * `defineResourceLayout.lazy(...)`, which supplies shared defaults.
50
- */
51
- declare function createLazyResourceLayout<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>>(options: LazyResourceLayoutOptions<Resources, Module>, defaults: LazyResourceStates): LazyResourceLayoutComponent<Module>;
28
+ /** Cached resource component and its compound states, backed by the shared loader. */
29
+ declare function createLazyResourceLayout<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>>(options: LazyResourceLayoutOptions<Resources, Module>, defaults: LazyResourceStates<any>, hooks?: LazyResourceLoadHooks): LazyResourceLayoutComponent<Module>;
52
30
  //#endregion
53
- export { LazyResourceErrorComponent, LazyResourceLayoutComponent, LazyResourceLayoutOptions, LazyResourceLoadingComponent, LazyResourceStates, createLazyResourceLayout };
31
+ export { LazyResourceLayoutComponent, LazyResourceLayoutOptions, createLazyResourceLayout };
54
32
  //# sourceMappingURL=lazy-resource-layout.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lazy-resource-layout.d.cts","names":[],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"mappings":";;;;;;KAkBK,sBAAA,GAAyB,aAAA;EAAA,UAClB,oCAAoC;AAAA;AAAA,KAG3C,mBAAA,WAA8B,MAAA,SAAe,sBAAA,GAC9C,MAAA,GACA,MAAA;EAAiB,IAAA,qBAAyB,sBAAA;AAAA,IACxC,IAAA;AAAA,KAGD,uBAAA,WAAkC,mBAAA,CAAoB,MAAA,OAAa,MAAA;AAAA,KAEnE,qBAAA,oDAIM,8BAAA,UACA,oCAAoC;;;;;;KAOnC,2BAAA,WAAsC,aAAA,CAChD,cAAA,CAAe,uBAAA,CAAwB,MAAA,MAEvC,IAAA,CACE,uBAAA,CAAwB,MAAA,GACxB,OAAA,OAAc,uBAAA,CAAwB,MAAA,GAAS,qBAAA;;KAIvC,4BAAA,GAA+B,aAAa;;;;;KAK5C,0BAAA,GAA6B,aAAa;EACpD,KAAA;EACA,KAAA;AAAA;;KAIU,kBAAA;EACV,KAAA,GAAQ,0BAAA;EACR,OAAA,GAAU,4BAA4B;AAAA;;;;;;KAQ5B,yBAAA,mBACQ,aAAA,CAAc,kBAAA,kBACjB,MAAA;EAEf,IAAA,QAAY,OAAA,CAAQ,MAAA;EACpB,QAAA,EAAU,YAAA,CAAa,SAAA;EACvB,MAAA,GAAS,kBAAA;AAAA;;;AAlDmE;AAAA;;iBAwH9D,wBAAA,mBACI,aAAA,CAAc,kBAAA,kBACjB,MAAA,mBAEf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,MAAA,GAC9C,QAAA,EAAU,kBAAA,GACT,2BAAA,CAA4B,MAAA"}
1
+ {"version":3,"file":"lazy-resource-layout.d.cts","names":[],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"mappings":";;;;;;;;KAsBK,sBAAA,GAAyB,aAAA;EAAA,UAClB,oCAAoC;AAAA;AAAA,KAG3C,mBAAA,WAA8B,MAAA,SAAe,sBAAA,GAC9C,MAAA,GACA,MAAA;EAAiB,IAAA,qBAAyB,sBAAA;AAAA,IACxC,IAAA;AAAA,KAGD,uBAAA,WAAkC,mBAAA,CACrC,MAAA,OAAa,MAAA;AAAA,KAGV,qBAAA,oDAIM,8BAAA,UACA,oCAAoC;;;;;;KAOnC,2BAAA,WAAsC,aAAA,CAChD,cAAA,CAAe,uBAAA,CAAwB,MAAA,MAEvC,UAAA,GACA,IAAA,CACE,uBAAA,CAAwB,MAAA,GACxB,OAAA,OAAc,uBAAA,CAAwB,MAAA,GAAS,qBAAA;;KAIvC,yBAAA,mBACQ,aAAA,CAAc,kBAAA,kBACjB,MAAA,qBACb,WAAA,CAAY,MAAA;EACd,QAAA,EAAU,YAAA,CAAa,SAAA;EACvB,MAAA,GAAS,kBAAA,CAAmB,YAAA,CAAa,SAAA;AAAA;;iBAwB3B,wBAAA,mBACI,aAAA,CAAc,kBAAA,kBACjB,MAAA,mBAEf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,MAAA,GAC9C,QAAA,EAAU,kBAAA,OACV,KAAA,GAAO,qBAAA,GACN,2BAAA,CAA4B,MAAA"}
@@ -1,3 +1,5 @@
1
+ import { LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceLoadingComponent, LazyResourceStates } from "../lazy/types.mjs";
2
+ import { LazyResourceLoadHooks } from "../lazy/create-lazy-loader.mjs";
1
3
  import { ResourceDefinition, ResourcePath } from "../resource.mjs";
2
4
  import { definedResourceLayoutComponentSymbol } from "./render-state.mjs";
3
5
  import { ComponentProps, ComponentType } from "react";
@@ -17,38 +19,14 @@ type LazyUnsupportedStatic = 'makeComposable' | 'props' | 'resource' | typeof co
17
19
  * and composition factories are intentionally omitted because they cannot be
18
20
  * read synchronously without loading the module.
19
21
  */
20
- type LazyResourceLayoutComponent<Module> = ComponentType<ComponentProps<DefinedLayoutFromModule<Module>>> & Pick<DefinedLayoutFromModule<Module>, Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>>;
21
- /** Component rendered while a resource module or one of its states is loading. */
22
- type LazyResourceLoadingComponent = ComponentType;
23
- /**
24
- * Component rendered when a resource module cannot be loaded. Calling
25
- * `retry` discards React's rejected lazy cache entry and imports it again.
26
- */
27
- type LazyResourceErrorComponent = ComponentType<{
28
- error: unknown;
29
- retry: () => void;
30
- }>;
31
- /** Loading and module-error UI used around a lazy resource component. */
32
- type LazyResourceStates = {
33
- Error?: LazyResourceErrorComponent;
34
- Loading?: LazyResourceLoadingComponent;
35
- };
36
- /**
37
- * Configuration for a lazy resource component. `resource` is checked against
38
- * the bound resource paths, including dot-delimited subresources, and `load`
39
- * must resolve to a module with exactly one created resource component.
40
- */
41
- type LazyResourceLayoutOptions<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>> = {
42
- load: () => Promise<Module>;
22
+ type LazyResourceLayoutComponent<Module> = ComponentType<ComponentProps<DefinedLayoutFromModule<Module>>> & LazyHandle & Pick<DefinedLayoutFromModule<Module>, Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>>;
23
+ /** Lazy resource options, sharing import and fallback semantics with lazy states. */
24
+ type LazyResourceLayoutOptions<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>> = LazyOptions<Module> & {
43
25
  resource: ResourcePath<Resources>;
44
- states?: LazyResourceStates;
26
+ states?: LazyResourceStates<ResourcePath<Resources>>;
45
27
  };
46
- /**
47
- * Creates a cached lazy proxy for a resource component and all of its compound
48
- * state components. This is normally called through
49
- * `defineResourceLayout.lazy(...)`, which supplies shared defaults.
50
- */
51
- declare function createLazyResourceLayout<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>>(options: LazyResourceLayoutOptions<Resources, Module>, defaults: LazyResourceStates): LazyResourceLayoutComponent<Module>;
28
+ /** Cached resource component and its compound states, backed by the shared loader. */
29
+ declare function createLazyResourceLayout<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>>(options: LazyResourceLayoutOptions<Resources, Module>, defaults: LazyResourceStates<any>, hooks?: LazyResourceLoadHooks): LazyResourceLayoutComponent<Module>;
52
30
  //#endregion
53
- export { LazyResourceErrorComponent, LazyResourceLayoutComponent, LazyResourceLayoutOptions, LazyResourceLoadingComponent, LazyResourceStates, createLazyResourceLayout };
31
+ export { LazyResourceLayoutComponent, LazyResourceLayoutOptions, createLazyResourceLayout };
54
32
  //# sourceMappingURL=lazy-resource-layout.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lazy-resource-layout.d.mts","names":[],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"mappings":";;;;;;KAkBK,sBAAA,GAAyB,aAAA;EAAA,UAClB,oCAAoC;AAAA;AAAA,KAG3C,mBAAA,WAA8B,MAAA,SAAe,sBAAA,GAC9C,MAAA,GACA,MAAA;EAAiB,IAAA,qBAAyB,sBAAA;AAAA,IACxC,IAAA;AAAA,KAGD,uBAAA,WAAkC,mBAAA,CAAoB,MAAA,OAAa,MAAA;AAAA,KAEnE,qBAAA,oDAIM,8BAAA,UACA,oCAAoC;;;;;;KAOnC,2BAAA,WAAsC,aAAA,CAChD,cAAA,CAAe,uBAAA,CAAwB,MAAA,MAEvC,IAAA,CACE,uBAAA,CAAwB,MAAA,GACxB,OAAA,OAAc,uBAAA,CAAwB,MAAA,GAAS,qBAAA;;KAIvC,4BAAA,GAA+B,aAAa;;;;;KAK5C,0BAAA,GAA6B,aAAa;EACpD,KAAA;EACA,KAAA;AAAA;;KAIU,kBAAA;EACV,KAAA,GAAQ,0BAAA;EACR,OAAA,GAAU,4BAA4B;AAAA;;;;;;KAQ5B,yBAAA,mBACQ,aAAA,CAAc,kBAAA,kBACjB,MAAA;EAEf,IAAA,QAAY,OAAA,CAAQ,MAAA;EACpB,QAAA,EAAU,YAAA,CAAa,SAAA;EACvB,MAAA,GAAS,kBAAA;AAAA;;;AAlDmE;AAAA;;iBAwH9D,wBAAA,mBACI,aAAA,CAAc,kBAAA,kBACjB,MAAA,mBAEf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,MAAA,GAC9C,QAAA,EAAU,kBAAA,GACT,2BAAA,CAA4B,MAAA"}
1
+ {"version":3,"file":"lazy-resource-layout.d.mts","names":[],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"mappings":";;;;;;;;KAsBK,sBAAA,GAAyB,aAAA;EAAA,UAClB,oCAAoC;AAAA;AAAA,KAG3C,mBAAA,WAA8B,MAAA,SAAe,sBAAA,GAC9C,MAAA,GACA,MAAA;EAAiB,IAAA,qBAAyB,sBAAA;AAAA,IACxC,IAAA;AAAA,KAGD,uBAAA,WAAkC,mBAAA,CACrC,MAAA,OAAa,MAAA;AAAA,KAGV,qBAAA,oDAIM,8BAAA,UACA,oCAAoC;;;;;;KAOnC,2BAAA,WAAsC,aAAA,CAChD,cAAA,CAAe,uBAAA,CAAwB,MAAA,MAEvC,UAAA,GACA,IAAA,CACE,uBAAA,CAAwB,MAAA,GACxB,OAAA,OAAc,uBAAA,CAAwB,MAAA,GAAS,qBAAA;;KAIvC,yBAAA,mBACQ,aAAA,CAAc,kBAAA,kBACjB,MAAA,qBACb,WAAA,CAAY,MAAA;EACd,QAAA,EAAU,YAAA,CAAa,SAAA;EACvB,MAAA,GAAS,kBAAA,CAAmB,YAAA,CAAa,SAAA;AAAA;;iBAwB3B,wBAAA,mBACI,aAAA,CAAc,kBAAA,kBACjB,MAAA,mBAEf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,MAAA,GAC9C,QAAA,EAAU,kBAAA,OACV,KAAA,GAAO,qBAAA,GACN,2BAAA,CAA4B,MAAA"}
@@ -1,109 +1,93 @@
1
- import { LayoutConfigurationError } from "../errors/layout-configuration-error.mjs";
2
- import { ResourceModuleLoadError } from "../errors/resource-state-error.mjs";
1
+ import { LazyResourceModuleShapeError } from "../errors/lazy-resource-error.mjs";
2
+ import { LazyBoundary } from "../lazy/lazy-boundary.mjs";
3
+ import { createLazyLoader } from "../lazy/create-lazy-loader.mjs";
3
4
  import { definedResourceLayoutComponentSymbol } from "./render-state.mjs";
4
- import { Component, Suspense, lazy, useReducer, useRef } from "react";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import { componentPropDefinitionsSymbol } from "@jfdevelops/react-layout-validator";
7
7
 
8
8
  //#region src/create-config/lazy-resource-layout.tsx
9
- var LazyResourceErrorBoundary = class extends Component {
10
- state = {};
11
- static getDerivedStateFromError(error) {
12
- return { error };
13
- }
14
- retry = () => {
15
- this.props.onRetry();
16
- this.setState({ error: void 0 });
17
- };
18
- render() {
19
- if (this.state.error !== void 0) {
20
- const { ErrorComponent } = this.props;
21
- if (!ErrorComponent) throw this.state.error;
22
- return /* @__PURE__ */ jsx(ErrorComponent, {
23
- error: this.state.error,
24
- retry: this.retry
25
- });
26
- }
27
- return this.props.children;
28
- }
29
- };
30
- function findDefinedLayoutComponent(module) {
9
+ function findDefinedLayoutComponent(module, resource) {
31
10
  const components = Object.values(module).map((value) => typeof value === "object" && value !== null && "Root" in value ? value.Root : value).filter((value) => typeof value === "function" && definedResourceLayoutComponentSymbol in value);
32
- if (components.length !== 1) throw new LayoutConfigurationError(`A lazy resource module must export exactly one created resource layout component; received ${components.length}`);
11
+ if (components.length !== 1) throw new LazyResourceModuleShapeError(resource, components.length);
33
12
  return components[0];
34
13
  }
35
- /**
36
- * Creates a cached lazy proxy for a resource component and all of its compound
37
- * state components. This is normally called through
38
- * `defineResourceLayout.lazy(...)`, which supplies shared defaults.
39
- */
40
- function createLazyResourceLayout(options, defaults) {
41
- const runtimeOptions = options;
42
- let loadedComponentPromise;
43
- const stateComponents = /* @__PURE__ */ new Map();
44
- const resolvedStates = {
14
+ /** Cached resource component and its compound states, backed by the shared loader. */
15
+ function createLazyResourceLayout(options, defaults, hooks = {}) {
16
+ const runtime = options;
17
+ const resource = runtime.resource;
18
+ const states = {
45
19
  ...defaults,
46
- ...runtimeOptions.states
20
+ ...runtime.states
47
21
  };
48
- function loadComponent() {
49
- loadedComponentPromise ??= runtimeOptions.load().then(findDefinedLayoutComponent).catch((error) => {
50
- throw new ResourceModuleLoadError(runtimeOptions.resource, error);
51
- });
52
- return loadedComponentPromise;
53
- }
54
- function resetLoad() {
55
- loadedComponentPromise = void 0;
56
- stateComponents.clear();
57
- }
58
- function createMemberComponent(member) {
59
- function createLazyComponent() {
60
- return lazy(async () => {
61
- const component = await loadComponent();
62
- const selected = member === void 0 ? component : component[member];
63
- if (typeof selected !== "function") throw new LayoutConfigurationError(`Lazy resource "${runtimeOptions.resource}" does not define state "${String(member)}"`);
64
- return { default: selected };
65
- });
66
- }
22
+ const loader = createLazyLoader({
23
+ load: runtime.load,
24
+ select: (module) => findDefinedLayoutComponent(module, resource),
25
+ label: resource,
26
+ hooks
27
+ });
28
+ const members = /* @__PURE__ */ new Map();
29
+ function createMember(member) {
67
30
  function LazyMember(props) {
68
- const [, rerender] = useReducer((version) => version + 1, 0);
69
- const LazyComponent = useRef(createLazyComponent());
70
- const LoadingComponent = resolvedStates.Loading;
71
- const CurrentLazyComponent = LazyComponent.current;
72
- function retry() {
73
- resetLoad();
74
- LazyComponent.current = createLazyComponent();
75
- rerender();
76
- }
77
- return /* @__PURE__ */ jsx(LazyResourceErrorBoundary, {
78
- ErrorComponent: resolvedStates.Error,
79
- onRetry: retry,
80
- children: /* @__PURE__ */ jsx(Suspense, {
81
- fallback: LoadingComponent ? /* @__PURE__ */ jsx(LoadingComponent, {}) : null,
82
- children: /* @__PURE__ */ jsx(CurrentLazyComponent, { ...props })
83
- })
31
+ const Loading = states.Loading;
32
+ return /* @__PURE__ */ jsx(LazyBoundary, {
33
+ loader,
34
+ member,
35
+ resource,
36
+ componentProps: props,
37
+ ErrorComponent: states.Error,
38
+ onMount: hooks.onMount,
39
+ fallback: runtime.fallback !== void 0 ? runtime.fallback : Loading ? /* @__PURE__ */ jsx(Loading, { resource }) : null
84
40
  });
85
41
  }
86
- const resourceName = runtimeOptions.resource;
87
- LazyMember.displayName = member === void 0 ? `LazyResource(${resourceName})` : `LazyResource(${resourceName}).${String(member)}`;
42
+ LazyMember.displayName = `LazyResource(${resource})${member ? `.${member}` : ""}`;
43
+ Object.defineProperties(LazyMember, {
44
+ preload: { value: loader.preload },
45
+ status: { get: () => loader.status }
46
+ });
88
47
  return LazyMember;
89
48
  }
90
- const Component = createMemberComponent();
91
- const unsupportedStatics = new Set([
49
+ const Component = createMember();
50
+ const reservedStatics = new Set([
92
51
  "makeComposable",
93
52
  "props",
94
53
  "resource",
95
54
  componentPropDefinitionsSymbol,
96
- definedResourceLayoutComponentSymbol
55
+ definedResourceLayoutComponentSymbol,
56
+ "contextTypes",
57
+ "childContextTypes",
58
+ "contextType",
59
+ "propTypes",
60
+ "defaultProps",
61
+ "getDerivedStateFromProps",
62
+ "getDerivedStateFromError",
63
+ "getDefaultProps",
64
+ "$$typeof",
65
+ "_payload",
66
+ "_init",
67
+ "render",
68
+ "compare",
69
+ "type",
70
+ "then",
71
+ "catch",
72
+ "finally",
73
+ "toJSON",
74
+ "asymmetricMatch",
75
+ "__esModule",
76
+ "default"
97
77
  ]);
98
- return new Proxy(Component, { get(target, property, receiver) {
99
- if (Reflect.has(target, property)) return Reflect.get(target, property, receiver);
100
- if (typeof property !== "string" || unsupportedStatics.has(property)) return;
101
- const existing = stateComponents.get(property);
102
- if (existing) return existing;
103
- const stateComponent = createMemberComponent(property);
104
- stateComponents.set(property, stateComponent);
105
- return stateComponent;
106
- } });
78
+ return new Proxy(Component, {
79
+ get(target, property, receiver) {
80
+ if (Reflect.has(target, property)) return Reflect.get(target, property, receiver);
81
+ if (typeof property !== "string" || reservedStatics.has(property) || !/^[A-Z]/.test(property)) return void 0;
82
+ let component = members.get(property);
83
+ if (!component) {
84
+ component = createMember(property);
85
+ members.set(property, component);
86
+ }
87
+ return component;
88
+ },
89
+ has: (target, property) => Reflect.has(target, property)
90
+ });
107
91
  }
108
92
 
109
93
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"lazy-resource-layout.mjs","names":[],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"sourcesContent":["import {\n Component,\n type ComponentProps,\n type ComponentType,\n type JSX,\n lazy,\n Suspense,\n useReducer,\n useRef,\n} from 'react';\nimport {\n LayoutConfigurationError,\n ResourceModuleLoadError,\n} from '../errors';\nimport { componentPropDefinitionsSymbol } from '@jfdevelops/react-layout-validator';\nimport type { ResourcePath, ResourceDefinition } from '../resource';\nimport { definedResourceLayoutComponentSymbol } from './render-state';\n\ntype DefinedLayoutComponent = ComponentType<any> & {\n readonly [definedResourceLayoutComponentSymbol]: true;\n};\n\ntype UnwrapDefinedLayout<Export> = Export extends DefinedLayoutComponent\n ? Export\n : Export extends { Root: infer Root extends DefinedLayoutComponent }\n ? Root\n : never;\n\ntype DefinedLayoutFromModule<Module> = UnwrapDefinedLayout<Module[keyof Module]>;\n\ntype LazyUnsupportedStatic =\n | 'makeComposable'\n | 'props'\n | 'resource'\n | typeof componentPropDefinitionsSymbol\n | typeof definedResourceLayoutComponentSymbol;\n\n/**\n * Public surface available before a lazy module resolves. Component metadata\n * and composition factories are intentionally omitted because they cannot be\n * read synchronously without loading the module.\n */\nexport type LazyResourceLayoutComponent<Module> = ComponentType<\n ComponentProps<DefinedLayoutFromModule<Module>>\n> &\n Pick<\n DefinedLayoutFromModule<Module>,\n Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>\n >;\n\n/** Component rendered while a resource module or one of its states is loading. */\nexport type LazyResourceLoadingComponent = ComponentType;\n/**\n * Component rendered when a resource module cannot be loaded. Calling\n * `retry` discards React's rejected lazy cache entry and imports it again.\n */\nexport type LazyResourceErrorComponent = ComponentType<{\n error: unknown;\n retry: () => void;\n}>;\n\n/** Loading and module-error UI used around a lazy resource component. */\nexport type LazyResourceStates = {\n Error?: LazyResourceErrorComponent;\n Loading?: LazyResourceLoadingComponent;\n};\n\n/**\n * Configuration for a lazy resource component. `resource` is checked against\n * the bound resource paths, including dot-delimited subresources, and `load`\n * must resolve to a module with exactly one created resource component.\n */\nexport type LazyResourceLayoutOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n> = {\n load: () => Promise<Module>;\n resource: ResourcePath<Resources>;\n states?: LazyResourceStates;\n};\n\ntype BoundaryProps = {\n children: JSX.Element;\n ErrorComponent?: LazyResourceErrorComponent;\n onRetry: () => void;\n};\n\ntype BoundaryState = {\n error?: unknown;\n};\n\nclass LazyResourceErrorBoundary extends Component<\n BoundaryProps,\n BoundaryState\n> {\n state: BoundaryState = {};\n\n static getDerivedStateFromError(error: unknown): BoundaryState {\n return { error };\n }\n\n retry = () => {\n this.props.onRetry();\n this.setState({ error: undefined });\n };\n\n render() {\n if (this.state.error !== undefined) {\n const { ErrorComponent } = this.props;\n\n if (!ErrorComponent) {\n throw this.state.error;\n }\n\n return <ErrorComponent error={this.state.error} retry={this.retry} />;\n }\n\n return this.props.children;\n }\n}\n\nfunction findDefinedLayoutComponent(module: Record<string, unknown>) {\n const components = Object.values(module)\n .map((value) =>\n typeof value === 'object' && value !== null && 'Root' in value\n ? value.Root\n : value,\n )\n .filter(\n (value): value is DefinedLayoutComponent =>\n typeof value === 'function' &&\n definedResourceLayoutComponentSymbol in value,\n );\n\n if (components.length !== 1) {\n throw new LayoutConfigurationError(\n `A lazy resource module must export exactly one created resource layout component; received ${components.length}`,\n );\n }\n\n return components[0];\n}\n\n/**\n * Creates a cached lazy proxy for a resource component and all of its compound\n * state components. This is normally called through\n * `defineResourceLayout.lazy(...)`, which supplies shared defaults.\n */\nexport function createLazyResourceLayout<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n>(\n options: LazyResourceLayoutOptions<Resources, Module>,\n defaults: LazyResourceStates,\n): LazyResourceLayoutComponent<Module> {\n const runtimeOptions = options as {\n load: () => Promise<Record<string, unknown>>;\n resource: string;\n states?: LazyResourceStates;\n };\n let loadedComponentPromise: Promise<DefinedLayoutComponent> | undefined;\n const stateComponents = new Map<PropertyKey, ComponentType<any>>();\n const resolvedStates = { ...defaults, ...runtimeOptions.states };\n\n function loadComponent() {\n loadedComponentPromise ??= runtimeOptions\n .load()\n .then(findDefinedLayoutComponent)\n .catch((error: unknown) => {\n throw new ResourceModuleLoadError(runtimeOptions.resource, error);\n });\n\n return loadedComponentPromise;\n }\n\n function resetLoad() {\n loadedComponentPromise = undefined;\n stateComponents.clear();\n }\n\n function createMemberComponent(member?: PropertyKey) {\n function createLazyComponent() {\n return lazy(async () => {\n const component = await loadComponent();\n const selected =\n member === undefined\n ? component\n : (component as unknown as Record<PropertyKey, unknown>)[member];\n\n if (typeof selected !== 'function') {\n throw new LayoutConfigurationError(\n `Lazy resource \"${runtimeOptions.resource}\" does not define state \"${String(member)}\"`,\n );\n }\n\n return { default: selected as ComponentType<any> };\n });\n }\n\n function LazyMember(props: Record<string, unknown>) {\n const [, rerender] = useReducer((version) => version + 1, 0);\n const LazyComponent = useRef(createLazyComponent());\n const LoadingComponent = resolvedStates.Loading;\n const CurrentLazyComponent = LazyComponent.current;\n\n function retry() {\n resetLoad();\n LazyComponent.current = createLazyComponent();\n rerender();\n }\n\n return (\n <LazyResourceErrorBoundary\n ErrorComponent={resolvedStates.Error}\n onRetry={retry}\n >\n <Suspense\n fallback={LoadingComponent ? <LoadingComponent /> : null}\n >\n <CurrentLazyComponent {...props} />\n </Suspense>\n </LazyResourceErrorBoundary>\n );\n }\n\n const resourceName = runtimeOptions.resource;\n LazyMember.displayName =\n member === undefined\n ? `LazyResource(${resourceName})`\n : `LazyResource(${resourceName}).${String(member)}`;\n\n return LazyMember;\n }\n\n const Component = createMemberComponent();\n const unsupportedStatics = new Set<PropertyKey>([\n 'makeComposable',\n 'props',\n 'resource',\n componentPropDefinitionsSymbol,\n definedResourceLayoutComponentSymbol,\n ]);\n\n return new Proxy(Component, {\n get(target, property, receiver) {\n if (Reflect.has(target, property)) {\n return Reflect.get(target, property, receiver);\n }\n\n if (typeof property !== 'string' || unsupportedStatics.has(property)) {\n return undefined;\n }\n\n const existing = stateComponents.get(property);\n\n if (existing) {\n return existing;\n }\n\n const stateComponent = createMemberComponent(property);\n stateComponents.set(property, stateComponent);\n\n return stateComponent;\n },\n }) as unknown as LazyResourceLayoutComponent<Module>;\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"lazy-resource-layout.mjs","names":[],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"sourcesContent":["import { type ComponentProps, type ComponentType } from 'react';\nimport { LazyResourceModuleShapeError } from '../errors/lazy-resource-error';\nimport { componentPropDefinitionsSymbol } from '@jfdevelops/react-layout-validator';\nimport type { ResourcePath, ResourceDefinition } from '../resource';\nimport { definedResourceLayoutComponentSymbol } from './render-state';\nimport {\n createLazyLoader,\n type LazyResourceLoadHooks,\n} from '../lazy/create-lazy-loader';\nimport { LazyBoundary } from '../lazy/lazy-boundary';\nimport type {\n LazyHandle,\n LazyOptions,\n LazyResourceStates,\n} from '../lazy/types';\nexport type {\n LazyResourceErrorComponent,\n LazyResourceLoadingComponent,\n LazyResourceStates,\n} from '../lazy/types';\nexport type { LazyResourceLoadHooks } from '../lazy/create-lazy-loader';\n\ntype DefinedLayoutComponent = ComponentType<any> & {\n readonly [definedResourceLayoutComponentSymbol]: true;\n};\n\ntype UnwrapDefinedLayout<Export> = Export extends DefinedLayoutComponent\n ? Export\n : Export extends { Root: infer Root extends DefinedLayoutComponent }\n ? Root\n : never;\n\ntype DefinedLayoutFromModule<Module> = UnwrapDefinedLayout<\n Module[keyof Module]\n>;\n\ntype LazyUnsupportedStatic =\n | 'makeComposable'\n | 'props'\n | 'resource'\n | typeof componentPropDefinitionsSymbol\n | typeof definedResourceLayoutComponentSymbol;\n\n/**\n * Public surface available before a lazy module resolves. Component metadata\n * and composition factories are intentionally omitted because they cannot be\n * read synchronously without loading the module.\n */\nexport type LazyResourceLayoutComponent<Module> = ComponentType<\n ComponentProps<DefinedLayoutFromModule<Module>>\n> &\n LazyHandle &\n Pick<\n DefinedLayoutFromModule<Module>,\n Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>\n >;\n\n/** Lazy resource options, sharing import and fallback semantics with lazy states. */\nexport type LazyResourceLayoutOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n> = LazyOptions<Module> & {\n resource: ResourcePath<Resources>;\n states?: LazyResourceStates<ResourcePath<Resources>>;\n};\n\nfunction findDefinedLayoutComponent(\n module: Record<string, unknown>,\n resource: string,\n) {\n const components = Object.values(module)\n .map((value) =>\n typeof value === 'object' && value !== null && 'Root' in value\n ? value.Root\n : value,\n )\n .filter(\n (value): value is DefinedLayoutComponent =>\n typeof value === 'function' &&\n definedResourceLayoutComponentSymbol in value,\n );\n if (components.length !== 1)\n throw new LazyResourceModuleShapeError(resource, components.length);\n return components[0];\n}\n\n/** Cached resource component and its compound states, backed by the shared loader. */\nexport function createLazyResourceLayout<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n>(\n options: LazyResourceLayoutOptions<Resources, Module>,\n defaults: LazyResourceStates<any>,\n hooks: LazyResourceLoadHooks = {},\n): LazyResourceLayoutComponent<Module> {\n const runtime = options as unknown as LazyOptions<Module> & {\n resource: string;\n states?: LazyResourceStates;\n };\n const resource = runtime.resource;\n const states = { ...defaults, ...runtime.states } as LazyResourceStates;\n const loader = createLazyLoader({\n load: runtime.load,\n select: (module) => findDefinedLayoutComponent(module, resource),\n label: resource,\n hooks,\n });\n const members = new Map<string, ComponentType<any>>();\n function createMember(member?: string) {\n function LazyMember(props: Record<string, unknown>) {\n const Loading = states.Loading;\n return (\n <LazyBoundary\n loader={loader}\n member={member}\n resource={resource}\n componentProps={props}\n ErrorComponent={states.Error}\n onMount={hooks.onMount}\n fallback={\n runtime.fallback !== undefined ? (\n runtime.fallback\n ) : Loading ? (\n <Loading resource={resource} />\n ) : null\n }\n />\n );\n }\n LazyMember.displayName = `LazyResource(${resource})${member ? `.${member}` : ''}`;\n Object.defineProperties(LazyMember, {\n preload: { value: loader.preload },\n status: { get: () => loader.status },\n });\n return LazyMember;\n }\n const Component = createMember();\n const reservedStatics = new Set<PropertyKey>([\n 'makeComposable',\n 'props',\n 'resource',\n componentPropDefinitionsSymbol,\n definedResourceLayoutComponentSymbol,\n 'contextTypes',\n 'childContextTypes',\n 'contextType',\n 'propTypes',\n 'defaultProps',\n 'getDerivedStateFromProps',\n 'getDerivedStateFromError',\n 'getDefaultProps',\n '$$typeof',\n '_payload',\n '_init',\n 'render',\n 'compare',\n 'type',\n 'then',\n 'catch',\n 'finally',\n 'toJSON',\n 'asymmetricMatch',\n '__esModule',\n 'default',\n ]);\n return new Proxy(Component, {\n get(target, property, receiver) {\n if (Reflect.has(target, property))\n return Reflect.get(target, property, receiver);\n if (\n typeof property !== 'string' ||\n reservedStatics.has(property) ||\n !/^[A-Z]/.test(property)\n )\n return undefined;\n let component = members.get(property);\n if (!component) {\n component = createMember(property);\n members.set(property, component);\n }\n return component;\n },\n has: (target, property) => Reflect.has(target, property),\n }) as unknown as LazyResourceLayoutComponent<Module>;\n}\n"],"mappings":";;;;;;;;AAkEA,SAAS,2BACP,QACA,UACA;CACA,MAAM,aAAa,OAAO,OAAO,MAAM,EACpC,KAAK,UACJ,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,QACrD,MAAM,OACN,KACN,EACC,QACE,UACC,OAAO,UAAU,cACjB,wCAAwC,KAC5C;CACF,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,6BAA6B,UAAU,WAAW,MAAM;CACpE,OAAO,WAAW;AACpB;;AAGA,SAAgB,yBAId,SACA,UACA,QAA+B,CAAC,GACK;CACrC,MAAM,UAAU;CAIhB,MAAM,WAAW,QAAQ;CACzB,MAAM,SAAS;EAAE,GAAG;EAAU,GAAG,QAAQ;CAAO;CAChD,MAAM,SAAS,iBAAiB;EAC9B,MAAM,QAAQ;EACd,SAAS,WAAW,2BAA2B,QAAQ,QAAQ;EAC/D,OAAO;EACP;CACF,CAAC;CACD,MAAM,0BAAU,IAAI,IAAgC;CACpD,SAAS,aAAa,QAAiB;EACrC,SAAS,WAAW,OAAgC;GAClD,MAAM,UAAU,OAAO;GACvB,OACE,oBAAC,cAAD;IACU;IACA;IACE;IACV,gBAAgB;IAChB,gBAAgB,OAAO;IACvB,SAAS,MAAM;IACf,UACE,QAAQ,aAAa,SACnB,QAAQ,WACN,UACF,oBAAC,SAAD,EAAmB,SAAW,KAC5B;GAEP;EAEL;EACA,WAAW,cAAc,gBAAgB,SAAS,GAAG,SAAS,IAAI,WAAW;EAC7E,OAAO,iBAAiB,YAAY;GAClC,SAAS,EAAE,OAAO,OAAO,QAAQ;GACjC,QAAQ,EAAE,WAAW,OAAO,OAAO;EACrC,CAAC;EACD,OAAO;CACT;CACA,MAAM,YAAY,aAAa;CAC/B,MAAM,kBAAkB,IAAI,IAAiB;EAC3C;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OAAO,IAAI,MAAM,WAAW;EAC1B,IAAI,QAAQ,UAAU,UAAU;GAC9B,IAAI,QAAQ,IAAI,QAAQ,QAAQ,GAC9B,OAAO,QAAQ,IAAI,QAAQ,UAAU,QAAQ;GAC/C,IACE,OAAO,aAAa,YACpB,gBAAgB,IAAI,QAAQ,KAC5B,CAAC,SAAS,KAAK,QAAQ,GAEvB,OAAO;GACT,IAAI,YAAY,QAAQ,IAAI,QAAQ;GACpC,IAAI,CAAC,WAAW;IACd,YAAY,aAAa,QAAQ;IACjC,QAAQ,IAAI,UAAU,SAAS;GACjC;GACA,OAAO;EACT;EACA,MAAM,QAAQ,aAAa,QAAQ,IAAI,QAAQ,QAAQ;CACzD,CAAC;AACH"}
@@ -1,6 +1,6 @@
1
1
  let react = require("react");
2
- let _jfdevelops_react_layout_devtools_core = require("@jfdevelops/react-layout-devtools-core");
3
2
  let react_jsx_runtime = require("react/jsx-runtime");
3
+ let _jfdevelops_react_layout_devtools_core = require("@jfdevelops/react-layout-devtools-core");
4
4
 
5
5
  //#region src/create-config/preview.tsx
6
6
  /** Typed, partial props used only while an opted-in development preview is forced. */
@@ -1,4 +1,6 @@
1
1
  import { ComponentType } from "react";
2
+ import { InspectionStore } from "@jfdevelops/react-layout-devtools-core";
3
+
2
4
  //#region src/create-config/preview.d.ts
3
5
  type PropsOf<T> = T extends ((props: infer P, ...rest: never[]) => unknown) ? Partial<P> : never;
4
6
  type LayoutPreviewProps<T> = { [K in keyof T as K extends 'Root' | 'makeComposable' ? never : T[K] extends ((...args: never[]) => unknown) ? K : never]?: PropsOf<T[K]> } & {
@@ -1 +1 @@
1
- {"version":3,"file":"preview.d.cts","names":[],"sources":["../../src/create-config/preview.tsx"],"mappings":";;KAcK,OAAA,MAAa,CAAA,WAAW,KAAA,cAAmB,IAAA,yBAC5C,OAAA,CAAQ,CAAA;AAAA,KAGA,kBAAA,oBACE,CAAA,IAAK,CAAA,6CAEb,CAAA,CAAE,CAAA,eAAe,IAAA,yBACjB,CAAA,YACS,OAAA,CAAQ,CAAA,CAAE,CAAA;EACnB,OAAA,GAAU,OAAA,CAAQ,CAAA;IAAY,IAAA;EAAA,IAAkB,CAAA,GAAI,CAAA;AAAA;;iBAG1C,mBAAA,mBACd,MAAA,EAAQ,CAAA,EACR,QAAA,EAAU,kBAAA,CAAmB,CAAA,IAC5B,CAAA"}
1
+ {"version":3,"file":"preview.d.cts","names":[],"sources":["../../src/create-config/preview.tsx"],"mappings":";;;;KAcK,OAAA,MAAa,CAAA,WAAW,KAAA,cAAmB,IAAA,yBAC5C,OAAA,CAAQ,CAAA;AAAA,KAGA,kBAAA,oBACE,CAAA,IAAK,CAAA,6CAEb,CAAA,CAAE,CAAA,eAAe,IAAA,yBACjB,CAAA,YACS,OAAA,CAAQ,CAAA,CAAE,CAAA;EACnB,OAAA,GAAU,OAAA,CAAQ,CAAA;IAAY,IAAA;EAAA,IAAkB,CAAA,GAAI,CAAA;AAAA;;iBAG1C,mBAAA,mBACd,MAAA,EAAQ,CAAA,EACR,QAAA,EAAU,kBAAA,CAAmB,CAAA,IAC5B,CAAA"}
@@ -1,4 +1,6 @@
1
1
  import { ComponentType } from "react";
2
+ import { InspectionStore } from "@jfdevelops/react-layout-devtools-core";
3
+
2
4
  //#region src/create-config/preview.d.ts
3
5
  type PropsOf<T> = T extends ((props: infer P, ...rest: never[]) => unknown) ? Partial<P> : never;
4
6
  type LayoutPreviewProps<T> = { [K in keyof T as K extends 'Root' | 'makeComposable' ? never : T[K] extends ((...args: never[]) => unknown) ? K : never]?: PropsOf<T[K]> } & {
@@ -1 +1 @@
1
- {"version":3,"file":"preview.d.mts","names":[],"sources":["../../src/create-config/preview.tsx"],"mappings":";;KAcK,OAAA,MAAa,CAAA,WAAW,KAAA,cAAmB,IAAA,yBAC5C,OAAA,CAAQ,CAAA;AAAA,KAGA,kBAAA,oBACE,CAAA,IAAK,CAAA,6CAEb,CAAA,CAAE,CAAA,eAAe,IAAA,yBACjB,CAAA,YACS,OAAA,CAAQ,CAAA,CAAE,CAAA;EACnB,OAAA,GAAU,OAAA,CAAQ,CAAA;IAAY,IAAA;EAAA,IAAkB,CAAA,GAAI,CAAA;AAAA;;iBAG1C,mBAAA,mBACd,MAAA,EAAQ,CAAA,EACR,QAAA,EAAU,kBAAA,CAAmB,CAAA,IAC5B,CAAA"}
1
+ {"version":3,"file":"preview.d.mts","names":[],"sources":["../../src/create-config/preview.tsx"],"mappings":";;;;KAcK,OAAA,MAAa,CAAA,WAAW,KAAA,cAAmB,IAAA,yBAC5C,OAAA,CAAQ,CAAA;AAAA,KAGA,kBAAA,oBACE,CAAA,IAAK,CAAA,6CAEb,CAAA,CAAE,CAAA,eAAe,IAAA,yBACjB,CAAA,YACS,OAAA,CAAQ,CAAA,CAAE,CAAA;EACnB,OAAA,GAAU,OAAA,CAAQ,CAAA;IAAY,IAAA;EAAA,IAAkB,CAAA,GAAI,CAAA;AAAA;;iBAG1C,mBAAA,mBACd,MAAA,EAAQ,CAAA,EACR,QAAA,EAAU,kBAAA,CAAmB,CAAA,IAC5B,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { Component, createElement, useLayoutEffect, useState } from "react";
2
- import { inspectionId, layoutPreviewFixtures } from "@jfdevelops/react-layout-devtools-core";
3
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { inspectionId, layoutPreviewFixtures } from "@jfdevelops/react-layout-devtools-core";
4
4
 
5
5
  //#region src/create-config/preview.tsx
6
6
  /** Typed, partial props used only while an opted-in development preview is forced. */