@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.
Files changed (137) 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 +1 -1
  34. package/dist/create-config/layout-name.mjs +1 -1
  35. package/dist/create-config/lazy-resource-layout.cjs +70 -86
  36. package/dist/create-config/lazy-resource-layout.cjs.map +1 -1
  37. package/dist/create-config/lazy-resource-layout.d.cts +9 -31
  38. package/dist/create-config/lazy-resource-layout.d.cts.map +1 -1
  39. package/dist/create-config/lazy-resource-layout.d.mts +9 -31
  40. package/dist/create-config/lazy-resource-layout.d.mts.map +1 -1
  41. package/dist/create-config/lazy-resource-layout.mjs +70 -86
  42. package/dist/create-config/lazy-resource-layout.mjs.map +1 -1
  43. package/dist/create-config/preview.cjs +1 -1
  44. package/dist/create-config/preview.d.cts +2 -0
  45. package/dist/create-config/preview.d.cts.map +1 -1
  46. package/dist/create-config/preview.d.mts +2 -0
  47. package/dist/create-config/preview.d.mts.map +1 -1
  48. package/dist/create-config/preview.mjs +1 -1
  49. package/dist/create-config/render-state.cjs +57 -18
  50. package/dist/create-config/render-state.cjs.map +1 -1
  51. package/dist/create-config/render-state.d.cts +18 -6
  52. package/dist/create-config/render-state.d.cts.map +1 -1
  53. package/dist/create-config/render-state.d.mts +18 -6
  54. package/dist/create-config/render-state.d.mts.map +1 -1
  55. package/dist/create-config/render-state.mjs +54 -18
  56. package/dist/create-config/render-state.mjs.map +1 -1
  57. package/dist/errors/lazy-resource-error.cjs +37 -0
  58. package/dist/errors/lazy-resource-error.cjs.map +1 -0
  59. package/dist/errors/lazy-resource-error.d.cts +26 -0
  60. package/dist/errors/lazy-resource-error.d.cts.map +1 -0
  61. package/dist/errors/lazy-resource-error.d.mts +26 -0
  62. package/dist/errors/lazy-resource-error.d.mts.map +1 -0
  63. package/dist/errors/lazy-resource-error.mjs +35 -0
  64. package/dist/errors/lazy-resource-error.mjs.map +1 -0
  65. package/dist/errors/react-layout-error.cjs +1 -1
  66. package/dist/errors/react-layout-error.mjs +1 -1
  67. package/dist/errors/resource-state-error.cjs +4 -1
  68. package/dist/errors/resource-state-error.cjs.map +1 -1
  69. package/dist/errors/resource-state-error.d.cts +1 -0
  70. package/dist/errors/resource-state-error.d.cts.map +1 -1
  71. package/dist/errors/resource-state-error.d.mts +1 -0
  72. package/dist/errors/resource-state-error.d.mts.map +1 -1
  73. package/dist/errors/resource-state-error.mjs +4 -1
  74. package/dist/errors/resource-state-error.mjs.map +1 -1
  75. package/dist/index.cjs +6 -2
  76. package/dist/index.d.cts +7 -4
  77. package/dist/index.d.mts +7 -4
  78. package/dist/index.mjs +4 -3
  79. package/dist/lazy/create-error-component.cjs +17 -0
  80. package/dist/lazy/create-error-component.cjs.map +1 -0
  81. package/dist/lazy/create-error-component.mjs +16 -0
  82. package/dist/lazy/create-error-component.mjs.map +1 -0
  83. package/dist/lazy/create-lazy-loader.cjs +78 -0
  84. package/dist/lazy/create-lazy-loader.cjs.map +1 -0
  85. package/dist/lazy/create-lazy-loader.d.cts +19 -0
  86. package/dist/lazy/create-lazy-loader.d.cts.map +1 -0
  87. package/dist/lazy/create-lazy-loader.d.mts +19 -0
  88. package/dist/lazy/create-lazy-loader.d.mts.map +1 -0
  89. package/dist/lazy/create-lazy-loader.mjs +78 -0
  90. package/dist/lazy/create-lazy-loader.mjs.map +1 -0
  91. package/dist/lazy/fallback-props.cjs +9 -0
  92. package/dist/lazy/fallback-props.cjs.map +1 -0
  93. package/dist/lazy/fallback-props.mjs +9 -0
  94. package/dist/lazy/fallback-props.mjs.map +1 -0
  95. package/dist/lazy/inspection.cjs +51 -0
  96. package/dist/lazy/inspection.cjs.map +1 -0
  97. package/dist/lazy/inspection.d.cts +28 -0
  98. package/dist/lazy/inspection.d.cts.map +1 -0
  99. package/dist/lazy/inspection.d.mts +28 -0
  100. package/dist/lazy/inspection.d.mts.map +1 -0
  101. package/dist/lazy/inspection.mjs +50 -0
  102. package/dist/lazy/inspection.mjs.map +1 -0
  103. package/dist/lazy/lazy-boundary.cjs +55 -0
  104. package/dist/lazy/lazy-boundary.cjs.map +1 -0
  105. package/dist/lazy/lazy-boundary.mjs +55 -0
  106. package/dist/lazy/lazy-boundary.mjs.map +1 -0
  107. package/dist/lazy/scoped-content.cjs +87 -0
  108. package/dist/lazy/scoped-content.cjs.map +1 -0
  109. package/dist/lazy/scoped-content.d.cts +19 -0
  110. package/dist/lazy/scoped-content.d.cts.map +1 -0
  111. package/dist/lazy/scoped-content.d.mts +19 -0
  112. package/dist/lazy/scoped-content.d.mts.map +1 -0
  113. package/dist/lazy/scoped-content.mjs +86 -0
  114. package/dist/lazy/scoped-content.mjs.map +1 -0
  115. package/dist/lazy/types.cjs +10 -0
  116. package/dist/lazy/types.cjs.map +1 -0
  117. package/dist/lazy/types.d.cts +39 -0
  118. package/dist/lazy/types.d.cts.map +1 -0
  119. package/dist/lazy/types.d.mts +39 -0
  120. package/dist/lazy/types.d.mts.map +1 -0
  121. package/dist/lazy/types.mjs +8 -0
  122. package/dist/lazy/types.mjs.map +1 -0
  123. package/dist/props.cjs +4 -2
  124. package/dist/props.cjs.map +1 -1
  125. package/dist/props.d.cts +6 -50
  126. package/dist/props.d.cts.map +1 -1
  127. package/dist/props.d.mts +6 -50
  128. package/dist/props.d.mts.map +1 -1
  129. package/dist/props.mjs +5 -2
  130. package/dist/props.mjs.map +1 -1
  131. package/dist/resource.cjs.map +1 -1
  132. package/dist/resource.d.cts +1 -1
  133. package/dist/resource.d.cts.map +1 -1
  134. package/dist/resource.d.mts +1 -1
  135. package/dist/resource.d.mts.map +1 -1
  136. package/dist/resource.mjs.map +1 -1
  137. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy-boundary.cjs","names":["Component","isLazyResourceError","Suspense"],"sources":["../../src/lazy/lazy-boundary.tsx"],"sourcesContent":["import {\n Component,\n Suspense,\n useEffect,\n useReducer,\n type ReactNode,\n} from 'react';\nimport { isLazyResourceError } from '../errors/lazy-resource-error';\nimport type { LazyResourceErrorComponent } from './types';\nimport type { LazyLoader } from './create-lazy-loader';\n\ntype BoundaryProps = {\n children: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n resource: string;\n onRetry: () => void;\n};\n\nclass LazyErrorBoundary extends Component<\n BoundaryProps,\n { failed: boolean; error?: unknown }\n> {\n state = { failed: false, error: undefined as unknown };\n static getDerivedStateFromError(error: unknown) {\n return { failed: true, error };\n }\n retry = () => {\n this.props.onRetry();\n this.setState({ failed: false, error: undefined });\n };\n render() {\n if (!this.state.failed) return this.props.children;\n const { ErrorComponent, resource } = this.props;\n if (!isLazyResourceError(this.state.error) || !ErrorComponent)\n throw this.state.error;\n return (\n <ErrorComponent\n error={this.state.error}\n retry={this.retry}\n resource={resource}\n />\n );\n }\n}\n\n/** Shared loading, typed error handling and retry for all lazy components. */\nexport function LazyBoundary({\n loader,\n member,\n resource,\n fallback,\n ErrorComponent,\n componentProps,\n onMount,\n map,\n}: {\n loader: LazyLoader<any>;\n member?: PropertyKey;\n map?: (selected: any) => React.ComponentType<any>;\n resource: string;\n fallback?: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n componentProps: Record<string, unknown>;\n onMount?: () => (() => void) | undefined;\n}) {\n const [, rerender] = useReducer((value) => value + 1, 0);\n useEffect(() => onMount?.(), [onMount]);\n const Current = loader.component(member, map);\n return (\n <LazyErrorBoundary\n resource={resource}\n ErrorComponent={ErrorComponent}\n onRetry={() => {\n loader.reset();\n rerender();\n }}\n >\n <Suspense fallback={fallback}>\n <Current {...componentProps} />\n </Suspense>\n </LazyErrorBoundary>\n );\n}\n"],"mappings":";;;;;AAkBA,IAAM,oBAAN,cAAgCA,gBAG9B;CACA,QAAQ;EAAE,QAAQ;EAAO,OAAO;CAAqB;CACrD,OAAO,yBAAyB,OAAgB;EAC9C,OAAO;GAAE,QAAQ;GAAM;EAAM;CAC/B;CACA,cAAc;EACZ,KAAK,MAAM,QAAQ;EACnB,KAAK,SAAS;GAAE,QAAQ;GAAO,OAAO;EAAU,CAAC;CACnD;CACA,SAAS;EACP,IAAI,CAAC,KAAK,MAAM,QAAQ,OAAO,KAAK,MAAM;EAC1C,MAAM,EAAE,gBAAgB,aAAa,KAAK;EAC1C,IAAI,CAACC,gDAAoB,KAAK,MAAM,KAAK,KAAK,CAAC,gBAC7C,MAAM,KAAK,MAAM;EACnB,OACE,2CAAC,gBAAD;GACE,OAAO,KAAK,MAAM;GAClB,OAAO,KAAK;GACF;EACX;CAEL;AACF;;AAGA,SAAgB,aAAa,EAC3B,QACA,QACA,UACA,UACA,gBACA,gBACA,SACA,OAUC;CACD,MAAM,GAAG,mCAAwB,UAAU,QAAQ,GAAG,CAAC;CACvD,2BAAgB,UAAU,GAAG,CAAC,OAAO,CAAC;CAEtC,OACE,2CAAC,mBAAD;EACY;EACM;EAChB,eAAe;GACb,OAAO,MAAM;GACb,SAAS;EACX;YAEA,2CAACC,gBAAD;GAAoB;aAClB,2CAXU,OAAO,UAAU,QAAQ,GAW5B,GAAP,EAAS,GAAI,eAAiB;EACtB;CACO;AAEvB"}
@@ -0,0 +1,55 @@
1
+ import { isLazyResourceError } from "../errors/lazy-resource-error.mjs";
2
+ import { Component, Suspense, useEffect, useReducer } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+
5
+ //#region src/lazy/lazy-boundary.tsx
6
+ var LazyErrorBoundary = class extends 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 (!isLazyResourceError(this.state.error) || !ErrorComponent) throw this.state.error;
28
+ return /* @__PURE__ */ 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] = useReducer((value) => value + 1, 0);
38
+ useEffect(() => onMount?.(), [onMount]);
39
+ return /* @__PURE__ */ jsx(LazyErrorBoundary, {
40
+ resource,
41
+ ErrorComponent,
42
+ onRetry: () => {
43
+ loader.reset();
44
+ rerender();
45
+ },
46
+ children: /* @__PURE__ */ jsx(Suspense, {
47
+ fallback,
48
+ children: /* @__PURE__ */ jsx(loader.component(member, map), { ...componentProps })
49
+ })
50
+ });
51
+ }
52
+
53
+ //#endregion
54
+ export { LazyBoundary };
55
+ //# sourceMappingURL=lazy-boundary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy-boundary.mjs","names":[],"sources":["../../src/lazy/lazy-boundary.tsx"],"sourcesContent":["import {\n Component,\n Suspense,\n useEffect,\n useReducer,\n type ReactNode,\n} from 'react';\nimport { isLazyResourceError } from '../errors/lazy-resource-error';\nimport type { LazyResourceErrorComponent } from './types';\nimport type { LazyLoader } from './create-lazy-loader';\n\ntype BoundaryProps = {\n children: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n resource: string;\n onRetry: () => void;\n};\n\nclass LazyErrorBoundary extends Component<\n BoundaryProps,\n { failed: boolean; error?: unknown }\n> {\n state = { failed: false, error: undefined as unknown };\n static getDerivedStateFromError(error: unknown) {\n return { failed: true, error };\n }\n retry = () => {\n this.props.onRetry();\n this.setState({ failed: false, error: undefined });\n };\n render() {\n if (!this.state.failed) return this.props.children;\n const { ErrorComponent, resource } = this.props;\n if (!isLazyResourceError(this.state.error) || !ErrorComponent)\n throw this.state.error;\n return (\n <ErrorComponent\n error={this.state.error}\n retry={this.retry}\n resource={resource}\n />\n );\n }\n}\n\n/** Shared loading, typed error handling and retry for all lazy components. */\nexport function LazyBoundary({\n loader,\n member,\n resource,\n fallback,\n ErrorComponent,\n componentProps,\n onMount,\n map,\n}: {\n loader: LazyLoader<any>;\n member?: PropertyKey;\n map?: (selected: any) => React.ComponentType<any>;\n resource: string;\n fallback?: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n componentProps: Record<string, unknown>;\n onMount?: () => (() => void) | undefined;\n}) {\n const [, rerender] = useReducer((value) => value + 1, 0);\n useEffect(() => onMount?.(), [onMount]);\n const Current = loader.component(member, map);\n return (\n <LazyErrorBoundary\n resource={resource}\n ErrorComponent={ErrorComponent}\n onRetry={() => {\n loader.reset();\n rerender();\n }}\n >\n <Suspense fallback={fallback}>\n <Current {...componentProps} />\n </Suspense>\n </LazyErrorBoundary>\n );\n}\n"],"mappings":";;;;;AAkBA,IAAM,oBAAN,cAAgC,UAG9B;CACA,QAAQ;EAAE,QAAQ;EAAO,OAAO;CAAqB;CACrD,OAAO,yBAAyB,OAAgB;EAC9C,OAAO;GAAE,QAAQ;GAAM;EAAM;CAC/B;CACA,cAAc;EACZ,KAAK,MAAM,QAAQ;EACnB,KAAK,SAAS;GAAE,QAAQ;GAAO,OAAO;EAAU,CAAC;CACnD;CACA,SAAS;EACP,IAAI,CAAC,KAAK,MAAM,QAAQ,OAAO,KAAK,MAAM;EAC1C,MAAM,EAAE,gBAAgB,aAAa,KAAK;EAC1C,IAAI,CAAC,oBAAoB,KAAK,MAAM,KAAK,KAAK,CAAC,gBAC7C,MAAM,KAAK,MAAM;EACnB,OACE,oBAAC,gBAAD;GACE,OAAO,KAAK,MAAM;GAClB,OAAO,KAAK;GACF;EACX;CAEL;AACF;;AAGA,SAAgB,aAAa,EAC3B,QACA,QACA,UACA,UACA,gBACA,gBACA,SACA,OAUC;CACD,MAAM,GAAG,YAAY,YAAY,UAAU,QAAQ,GAAG,CAAC;CACvD,gBAAgB,UAAU,GAAG,CAAC,OAAO,CAAC;CAEtC,OACE,oBAAC,mBAAD;EACY;EACM;EAChB,eAAe;GACb,OAAO,MAAM;GACb,SAAS;EACX;YAEA,oBAAC,UAAD;GAAoB;aAClB,oBAXU,OAAO,UAAU,QAAQ,GAW5B,GAAP,EAAS,GAAI,eAAiB;EACtB;CACO;AAEvB"}
@@ -0,0 +1,87 @@
1
+ const require_lazy_resource_error = require('../errors/lazy-resource-error.cjs');
2
+ const require_lazy_boundary = require('./lazy-boundary.cjs');
3
+ const require_fallback_props = require('./fallback-props.cjs');
4
+ const require_create_lazy_loader = require('./create-lazy-loader.cjs');
5
+ const require_inspection = require('./inspection.cjs');
6
+ const require_render_state = require('../create-config/render-state.cjs');
7
+ const require_scoped_render = require('../create-config/for-resources/scoped-render.cjs');
8
+ let react = require("react");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ let _jfdevelops_react_layout_devtools_core = require("@jfdevelops/react-layout-devtools-core");
11
+
12
+ //#region src/lazy/scoped-content.tsx
13
+ const scopedLazySymbol = Symbol("scopedLazy");
14
+ /** Content is imported only when rendered or preloaded, never during shell creation. */
15
+ function createScopedLazyContent(input, resource, label, environment) {
16
+ const options = typeof input.lazy === "function" ? { load: input.lazy } : input.lazy;
17
+ const componentId = environment?.store.node({
18
+ id: (0, _jfdevelops_react_layout_devtools_core.inspectionId)("component"),
19
+ kind: "component",
20
+ label,
21
+ details: { resource }
22
+ });
23
+ if (componentId && environment) environment.store.edge(environment.parent, componentId, "declares");
24
+ const inspection = require_inspection.inspectLazy(label, environment?.store, componentId);
25
+ if (componentId) inspection.hooks.onMount = () => inspection.store.mount(componentId, inspection.id);
26
+ const loader = require_create_lazy_loader.createLazyLoader({
27
+ load: options.load,
28
+ label,
29
+ hooks: inspection.hooks,
30
+ async select(module) {
31
+ const candidates = Object.values(module).filter((value) => require_scoped_render.isRenderableComponentType(value) || typeof value === "object" && value !== null && require_render_state.definedRenderStateSymbol in value);
32
+ if (candidates.length !== 1) throw new require_lazy_resource_error.LazyResourceModuleShapeError(label, candidates.length);
33
+ const selected = candidates[0];
34
+ const render = typeof selected === "object" && selected !== null && require_render_state.definedRenderStateSymbol in selected ? (await require_render_state.findDefinedRenderState({ State: selected }, label)).render : selected;
35
+ function Loaded({ callProps, context }) {
36
+ if (typeof render !== "function" || render.prototype?.isReactComponent) return (0, react.createElement)(render, callProps);
37
+ return require_scoped_render.resolveScopedRenderResult(render(callProps, context), callProps);
38
+ }
39
+ return Loaded;
40
+ }
41
+ });
42
+ const Content = require_inspection.withLazyHandle(function LazyScopedContent({ callProps, context }) {
43
+ const defaults = environment?.defaults() ?? {};
44
+ const currentProps = (0, react.useRef)(callProps);
45
+ currentProps.current = callProps;
46
+ const fallbackStates = (0, react.useRef)();
47
+ fallbackStates.current ??= environment?.states?.(resource, callProps) ?? {};
48
+ const nearest = fallbackStates.current;
49
+ const errorComponent = (0, react.useRef)();
50
+ const NearestError = nearest.Error;
51
+ if (NearestError && !errorComponent.current) errorComponent.current = function ScopedFallbackError(props) {
52
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_fallback_props.LazyFallbackPropsContext.Provider, {
53
+ value: {
54
+ owner: nearest.owner,
55
+ props: currentProps.current
56
+ },
57
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NearestError, { ...props })
58
+ });
59
+ };
60
+ const Loading = nearest.Loading ?? defaults.Loading;
61
+ const fallback = input.fallback !== void 0 ? input.fallback : options.fallback;
62
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_lazy_boundary.LazyBoundary, {
63
+ loader,
64
+ resource,
65
+ componentProps: {
66
+ callProps,
67
+ context
68
+ },
69
+ ErrorComponent: errorComponent.current ?? defaults.Error,
70
+ onMount: inspection.hooks.onMount,
71
+ fallback: fallback !== void 0 ? fallback : Loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_fallback_props.LazyFallbackPropsContext.Provider, {
72
+ value: {
73
+ owner: nearest.owner,
74
+ props: callProps
75
+ },
76
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Loading, { resource })
77
+ }) : null
78
+ });
79
+ }, loader);
80
+ inspection.store.attach(Content);
81
+ return Content;
82
+ }
83
+
84
+ //#endregion
85
+ exports.createScopedLazyContent = createScopedLazyContent;
86
+ exports.scopedLazySymbol = scopedLazySymbol;
87
+ //# sourceMappingURL=scoped-content.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoped-content.cjs","names":["inspectLazy","createLazyLoader","isRenderableComponentType","definedRenderStateSymbol","LazyResourceModuleShapeError","findDefinedRenderState","resolveScopedRenderResult","withLazyHandle","LazyFallbackPropsContext","LazyBoundary"],"sources":["../../src/lazy/scoped-content.tsx"],"sourcesContent":["import { LazyFallbackPropsContext } from './fallback-props';\nimport { createElement, useRef, type ComponentType } from 'react';\nimport type { LazyOptions, LazyResourceStates } from './types';\nimport { createLazyLoader } from './create-lazy-loader';\nimport { LazyBoundary } from './lazy-boundary';\nimport { inspectLazy, withLazyHandle } from './inspection';\nimport { LazyResourceModuleShapeError } from '../errors/lazy-resource-error';\nimport {\n definedRenderStateSymbol,\n findDefinedRenderState,\n} from '../create-config/render-state';\nimport {\n isRenderableComponentType,\n resolveScopedRenderResult,\n type ScopedRenderResult,\n} from '../create-config/for-resources/scoped-render';\nimport {\n inspectionId,\n type InspectionStore,\n} from '@jfdevelops/react-layout-devtools-core';\n\nexport type ScopedComponentRenderFn<\n Props = Record<string, unknown>,\n Context = Record<string, ComponentType<any>>,\n> = (props: Props, context: Context) => ScopedRenderResult;\n\nexport type ScopedLazyContent<Render> =\n | { render: Render; lazy?: never; fallback?: never }\n | {\n render?: never;\n lazy: LazyOptions['load'] | LazyOptions;\n fallback?: React.ReactNode;\n };\n\nexport type LazyEnvironment = {\n store: InspectionStore;\n parent: string;\n defaults: () => LazyResourceStates;\n states?: (\n resource: string,\n props: Record<string, unknown>,\n ) => LazyResourceStates & { owner?: string };\n};\n\nexport const scopedLazySymbol = Symbol('scopedLazy');\n\n/** Content is imported only when rendered or preloaded, never during shell creation. */\nexport function createScopedLazyContent(\n input: {\n lazy: LazyOptions['load'] | LazyOptions;\n fallback?: React.ReactNode;\n },\n resource: string,\n label: string,\n environment?: LazyEnvironment,\n) {\n const options =\n typeof input.lazy === 'function' ? { load: input.lazy } : input.lazy;\n const componentId = environment?.store.node({\n id: inspectionId('component'),\n kind: 'component',\n label,\n details: { resource },\n });\n if (componentId && environment) {\n environment.store.edge(environment.parent, componentId, 'declares');\n }\n const inspection = inspectLazy(label, environment?.store, componentId);\n if (componentId) {\n inspection.hooks.onMount = () =>\n inspection.store.mount(componentId, inspection.id);\n }\n const loader = createLazyLoader({\n load: options.load,\n label,\n hooks: inspection.hooks,\n async select(module) {\n const candidates = Object.values(module).filter(\n (value) =>\n isRenderableComponentType(value) ||\n (typeof value === 'object' &&\n value !== null &&\n definedRenderStateSymbol in value),\n );\n if (candidates.length !== 1)\n throw new LazyResourceModuleShapeError(label, candidates.length);\n const selected = candidates[0];\n const render =\n typeof selected === 'object' &&\n selected !== null &&\n definedRenderStateSymbol in selected\n ? (await findDefinedRenderState({ State: selected }, label)).render\n : (selected as ScopedComponentRenderFn);\n // The render callback runs as a React component so hooks remain legal.\n function Loaded({\n callProps,\n context,\n }: {\n callProps: Record<string, unknown>;\n context: Record<string, ComponentType<any>>;\n }) {\n if (\n typeof render !== 'function' ||\n (render as unknown as { prototype?: { isReactComponent?: unknown } })\n .prototype?.isReactComponent\n )\n return createElement(render as ComponentType<any>, callProps);\n return resolveScopedRenderResult(render(callProps, context), callProps);\n }\n return Loaded;\n },\n });\n const Content = withLazyHandle(function LazyScopedContent({\n callProps,\n context,\n }: {\n callProps: Record<string, unknown>;\n context: Record<string, ComponentType<any>>;\n }) {\n const defaults = environment?.defaults() ?? {};\n const currentProps = useRef(callProps);\n currentProps.current = callProps;\n const fallbackStates = useRef<LazyResourceStates & { owner?: string }>();\n fallbackStates.current ??= environment?.states?.(resource, callProps) ?? {};\n const nearest = fallbackStates.current;\n const errorComponent = useRef<LazyResourceStates['Error']>();\n const NearestError = nearest.Error;\n if (NearestError && !errorComponent.current) {\n errorComponent.current = function ScopedFallbackError(props) {\n return (\n <LazyFallbackPropsContext.Provider\n value={{ owner: nearest.owner, props: currentProps.current }}\n >\n <NearestError {...props} />\n </LazyFallbackPropsContext.Provider>\n );\n };\n }\n const Loading = nearest.Loading ?? defaults.Loading;\n const fallback =\n input.fallback !== undefined ? input.fallback : options.fallback;\n return (\n <LazyBoundary\n loader={loader}\n resource={resource}\n componentProps={{ callProps, context }}\n ErrorComponent={errorComponent.current ?? defaults.Error}\n onMount={inspection.hooks.onMount}\n fallback={\n fallback !== undefined ? (\n fallback\n ) : Loading ? (\n <LazyFallbackPropsContext.Provider\n value={{ owner: nearest.owner, props: callProps }}\n >\n <Loading resource={resource} />\n </LazyFallbackPropsContext.Provider>\n ) : null\n }\n />\n );\n }, loader);\n inspection.store.attach(Content);\n return Content;\n}\n"],"mappings":";;;;;;;;;;;;AA4CA,MAAa,mBAAmB,OAAO,YAAY;;AAGnD,SAAgB,wBACd,OAIA,UACA,OACA,aACA;CACA,MAAM,UACJ,OAAO,MAAM,SAAS,aAAa,EAAE,MAAM,MAAM,KAAK,IAAI,MAAM;CAClE,MAAM,cAAc,aAAa,MAAM,KAAK;EAC1C,6DAAiB,WAAW;EAC5B,MAAM;EACN;EACA,SAAS,EAAE,SAAS;CACtB,CAAC;CACD,IAAI,eAAe,aACjB,YAAY,MAAM,KAAK,YAAY,QAAQ,aAAa,UAAU;CAEpE,MAAM,aAAaA,+BAAY,OAAO,aAAa,OAAO,WAAW;CACrE,IAAI,aACF,WAAW,MAAM,gBACf,WAAW,MAAM,MAAM,aAAa,WAAW,EAAE;CAErD,MAAM,SAASC,4CAAiB;EAC9B,MAAM,QAAQ;EACd;EACA,OAAO,WAAW;EAClB,MAAM,OAAO,QAAQ;GACnB,MAAM,aAAa,OAAO,OAAO,MAAM,EAAE,QACtC,UACCC,gDAA0B,KAAK,KAC9B,OAAO,UAAU,YAChB,UAAU,QACVC,iDAA4B,KAClC;GACA,IAAI,WAAW,WAAW,GACxB,MAAM,IAAIC,yDAA6B,OAAO,WAAW,MAAM;GACjE,MAAM,WAAW,WAAW;GAC5B,MAAM,SACJ,OAAO,aAAa,YACpB,aAAa,QACbD,iDAA4B,YACvB,MAAME,4CAAuB,EAAE,OAAO,SAAS,GAAG,KAAK,GAAG,SAC1D;GAEP,SAAS,OAAO,EACd,WACA,WAIC;IACD,IACE,OAAO,WAAW,cACjB,OACE,WAAW,kBAEd,gCAAqB,QAA8B,SAAS;IAC9D,OAAOC,gDAA0B,OAAO,WAAW,OAAO,GAAG,SAAS;GACxE;GACA,OAAO;EACT;CACF,CAAC;CACD,MAAM,UAAUC,kCAAe,SAAS,kBAAkB,EACxD,WACA,WAIC;EACD,MAAM,WAAW,aAAa,SAAS,KAAK,CAAC;EAC7C,MAAM,iCAAsB,SAAS;EACrC,aAAa,UAAU;EACvB,MAAM,mCAAiE;EACvE,eAAe,YAAY,aAAa,SAAS,UAAU,SAAS,KAAK,CAAC;EAC1E,MAAM,UAAU,eAAe;EAC/B,MAAM,mCAAqD;EAC3D,MAAM,eAAe,QAAQ;EAC7B,IAAI,gBAAgB,CAAC,eAAe,SAClC,eAAe,UAAU,SAAS,oBAAoB,OAAO;GAC3D,OACE,2CAACC,gDAAyB,UAA1B;IACE,OAAO;KAAE,OAAO,QAAQ;KAAO,OAAO,aAAa;IAAQ;cAE3D,2CAAC,cAAD,EAAc,GAAI,MAAQ;GACO;EAEvC;EAEF,MAAM,UAAU,QAAQ,WAAW,SAAS;EAC5C,MAAM,WACJ,MAAM,aAAa,SAAY,MAAM,WAAW,QAAQ;EAC1D,OACE,2CAACC,oCAAD;GACU;GACE;GACV,gBAAgB;IAAE;IAAW;GAAQ;GACrC,gBAAgB,eAAe,WAAW,SAAS;GACnD,SAAS,WAAW,MAAM;GAC1B,UACE,aAAa,SACX,WACE,UACF,2CAACD,gDAAyB,UAA1B;IACE,OAAO;KAAE,OAAO,QAAQ;KAAO,OAAO;IAAU;cAEhD,2CAAC,SAAD,EAAmB,SAAW;GACG,KACjC;EAEP;CAEL,GAAG,MAAM;CACT,WAAW,MAAM,OAAO,OAAO;CAC/B,OAAO;AACT"}
@@ -0,0 +1,19 @@
1
+ import { LazyOptions } from "./types.cjs";
2
+ import { ScopedRenderResult } from "../create-config/for-resources/scoped-render.cjs";
3
+ import { ComponentType } from "react";
4
+ import { InspectionStore } from "@jfdevelops/react-layout-devtools-core";
5
+
6
+ //#region src/lazy/scoped-content.d.ts
7
+ type ScopedComponentRenderFn<Props = Record<string, unknown>, Context = Record<string, ComponentType<any>>> = (props: Props, context: Context) => ScopedRenderResult;
8
+ type ScopedLazyContent<Render> = {
9
+ render: Render;
10
+ lazy?: never;
11
+ fallback?: never;
12
+ } | {
13
+ render?: never;
14
+ lazy: LazyOptions['load'] | LazyOptions;
15
+ fallback?: React.ReactNode;
16
+ };
17
+ //#endregion
18
+ export { ScopedComponentRenderFn, ScopedLazyContent };
19
+ //# sourceMappingURL=scoped-content.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoped-content.d.cts","names":[],"sources":["../../src/lazy/scoped-content.tsx"],"mappings":";;;;;;KAqBY,uBAAA,SACF,MAAA,6BACE,MAAA,SAAe,aAAA,WACtB,KAAA,EAAO,KAAA,EAAO,OAAA,EAAS,OAAA,KAAY,kBAAA;AAAA,KAE5B,iBAAA;EACN,MAAA,EAAQ,MAAA;EAAQ,IAAA;EAAc,QAAA;AAAA;EAE9B,MAAA;EACA,IAAA,EAAM,WAAA,WAAsB,WAAA;EAC5B,QAAA,GAAW,KAAA,CAAM,SAAA;AAAA"}
@@ -0,0 +1,19 @@
1
+ import { LazyOptions } from "./types.mjs";
2
+ import { ScopedRenderResult } from "../create-config/for-resources/scoped-render.mjs";
3
+ import { ComponentType } from "react";
4
+ import { InspectionStore } from "@jfdevelops/react-layout-devtools-core";
5
+
6
+ //#region src/lazy/scoped-content.d.ts
7
+ type ScopedComponentRenderFn<Props = Record<string, unknown>, Context = Record<string, ComponentType<any>>> = (props: Props, context: Context) => ScopedRenderResult;
8
+ type ScopedLazyContent<Render> = {
9
+ render: Render;
10
+ lazy?: never;
11
+ fallback?: never;
12
+ } | {
13
+ render?: never;
14
+ lazy: LazyOptions['load'] | LazyOptions;
15
+ fallback?: React.ReactNode;
16
+ };
17
+ //#endregion
18
+ export { ScopedComponentRenderFn, ScopedLazyContent };
19
+ //# sourceMappingURL=scoped-content.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoped-content.d.mts","names":[],"sources":["../../src/lazy/scoped-content.tsx"],"mappings":";;;;;;KAqBY,uBAAA,SACF,MAAA,6BACE,MAAA,SAAe,aAAA,WACtB,KAAA,EAAO,KAAA,EAAO,OAAA,EAAS,OAAA,KAAY,kBAAA;AAAA,KAE5B,iBAAA;EACN,MAAA,EAAQ,MAAA;EAAQ,IAAA;EAAc,QAAA;AAAA;EAE9B,MAAA;EACA,IAAA,EAAM,WAAA,WAAsB,WAAA;EAC5B,QAAA,GAAW,KAAA,CAAM,SAAA;AAAA"}
@@ -0,0 +1,86 @@
1
+ import { LazyResourceModuleShapeError } from "../errors/lazy-resource-error.mjs";
2
+ import { LazyBoundary } from "./lazy-boundary.mjs";
3
+ import { LazyFallbackPropsContext } from "./fallback-props.mjs";
4
+ import { createLazyLoader } from "./create-lazy-loader.mjs";
5
+ import { inspectLazy, withLazyHandle } from "./inspection.mjs";
6
+ import { definedRenderStateSymbol, findDefinedRenderState } from "../create-config/render-state.mjs";
7
+ import { isRenderableComponentType, resolveScopedRenderResult } from "../create-config/for-resources/scoped-render.mjs";
8
+ import { createElement, useRef } from "react";
9
+ import { jsx } from "react/jsx-runtime";
10
+ import { inspectionId } from "@jfdevelops/react-layout-devtools-core";
11
+
12
+ //#region src/lazy/scoped-content.tsx
13
+ const scopedLazySymbol = Symbol("scopedLazy");
14
+ /** Content is imported only when rendered or preloaded, never during shell creation. */
15
+ function createScopedLazyContent(input, resource, label, environment) {
16
+ const options = typeof input.lazy === "function" ? { load: input.lazy } : input.lazy;
17
+ const componentId = environment?.store.node({
18
+ id: inspectionId("component"),
19
+ kind: "component",
20
+ label,
21
+ details: { resource }
22
+ });
23
+ if (componentId && environment) environment.store.edge(environment.parent, componentId, "declares");
24
+ const inspection = inspectLazy(label, environment?.store, componentId);
25
+ if (componentId) inspection.hooks.onMount = () => inspection.store.mount(componentId, inspection.id);
26
+ const loader = createLazyLoader({
27
+ load: options.load,
28
+ label,
29
+ hooks: inspection.hooks,
30
+ async select(module) {
31
+ const candidates = Object.values(module).filter((value) => isRenderableComponentType(value) || typeof value === "object" && value !== null && definedRenderStateSymbol in value);
32
+ if (candidates.length !== 1) throw new LazyResourceModuleShapeError(label, candidates.length);
33
+ const selected = candidates[0];
34
+ const render = typeof selected === "object" && selected !== null && definedRenderStateSymbol in selected ? (await findDefinedRenderState({ State: selected }, label)).render : selected;
35
+ function Loaded({ callProps, context }) {
36
+ if (typeof render !== "function" || render.prototype?.isReactComponent) return createElement(render, callProps);
37
+ return resolveScopedRenderResult(render(callProps, context), callProps);
38
+ }
39
+ return Loaded;
40
+ }
41
+ });
42
+ const Content = withLazyHandle(function LazyScopedContent({ callProps, context }) {
43
+ const defaults = environment?.defaults() ?? {};
44
+ const currentProps = useRef(callProps);
45
+ currentProps.current = callProps;
46
+ const fallbackStates = useRef();
47
+ fallbackStates.current ??= environment?.states?.(resource, callProps) ?? {};
48
+ const nearest = fallbackStates.current;
49
+ const errorComponent = useRef();
50
+ const NearestError = nearest.Error;
51
+ if (NearestError && !errorComponent.current) errorComponent.current = function ScopedFallbackError(props) {
52
+ return /* @__PURE__ */ jsx(LazyFallbackPropsContext.Provider, {
53
+ value: {
54
+ owner: nearest.owner,
55
+ props: currentProps.current
56
+ },
57
+ children: /* @__PURE__ */ jsx(NearestError, { ...props })
58
+ });
59
+ };
60
+ const Loading = nearest.Loading ?? defaults.Loading;
61
+ const fallback = input.fallback !== void 0 ? input.fallback : options.fallback;
62
+ return /* @__PURE__ */ jsx(LazyBoundary, {
63
+ loader,
64
+ resource,
65
+ componentProps: {
66
+ callProps,
67
+ context
68
+ },
69
+ ErrorComponent: errorComponent.current ?? defaults.Error,
70
+ onMount: inspection.hooks.onMount,
71
+ fallback: fallback !== void 0 ? fallback : Loading ? /* @__PURE__ */ jsx(LazyFallbackPropsContext.Provider, {
72
+ value: {
73
+ owner: nearest.owner,
74
+ props: callProps
75
+ },
76
+ children: /* @__PURE__ */ jsx(Loading, { resource })
77
+ }) : null
78
+ });
79
+ }, loader);
80
+ inspection.store.attach(Content);
81
+ return Content;
82
+ }
83
+
84
+ //#endregion
85
+ export { createScopedLazyContent, scopedLazySymbol };
86
+ //# sourceMappingURL=scoped-content.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoped-content.mjs","names":[],"sources":["../../src/lazy/scoped-content.tsx"],"sourcesContent":["import { LazyFallbackPropsContext } from './fallback-props';\nimport { createElement, useRef, type ComponentType } from 'react';\nimport type { LazyOptions, LazyResourceStates } from './types';\nimport { createLazyLoader } from './create-lazy-loader';\nimport { LazyBoundary } from './lazy-boundary';\nimport { inspectLazy, withLazyHandle } from './inspection';\nimport { LazyResourceModuleShapeError } from '../errors/lazy-resource-error';\nimport {\n definedRenderStateSymbol,\n findDefinedRenderState,\n} from '../create-config/render-state';\nimport {\n isRenderableComponentType,\n resolveScopedRenderResult,\n type ScopedRenderResult,\n} from '../create-config/for-resources/scoped-render';\nimport {\n inspectionId,\n type InspectionStore,\n} from '@jfdevelops/react-layout-devtools-core';\n\nexport type ScopedComponentRenderFn<\n Props = Record<string, unknown>,\n Context = Record<string, ComponentType<any>>,\n> = (props: Props, context: Context) => ScopedRenderResult;\n\nexport type ScopedLazyContent<Render> =\n | { render: Render; lazy?: never; fallback?: never }\n | {\n render?: never;\n lazy: LazyOptions['load'] | LazyOptions;\n fallback?: React.ReactNode;\n };\n\nexport type LazyEnvironment = {\n store: InspectionStore;\n parent: string;\n defaults: () => LazyResourceStates;\n states?: (\n resource: string,\n props: Record<string, unknown>,\n ) => LazyResourceStates & { owner?: string };\n};\n\nexport const scopedLazySymbol = Symbol('scopedLazy');\n\n/** Content is imported only when rendered or preloaded, never during shell creation. */\nexport function createScopedLazyContent(\n input: {\n lazy: LazyOptions['load'] | LazyOptions;\n fallback?: React.ReactNode;\n },\n resource: string,\n label: string,\n environment?: LazyEnvironment,\n) {\n const options =\n typeof input.lazy === 'function' ? { load: input.lazy } : input.lazy;\n const componentId = environment?.store.node({\n id: inspectionId('component'),\n kind: 'component',\n label,\n details: { resource },\n });\n if (componentId && environment) {\n environment.store.edge(environment.parent, componentId, 'declares');\n }\n const inspection = inspectLazy(label, environment?.store, componentId);\n if (componentId) {\n inspection.hooks.onMount = () =>\n inspection.store.mount(componentId, inspection.id);\n }\n const loader = createLazyLoader({\n load: options.load,\n label,\n hooks: inspection.hooks,\n async select(module) {\n const candidates = Object.values(module).filter(\n (value) =>\n isRenderableComponentType(value) ||\n (typeof value === 'object' &&\n value !== null &&\n definedRenderStateSymbol in value),\n );\n if (candidates.length !== 1)\n throw new LazyResourceModuleShapeError(label, candidates.length);\n const selected = candidates[0];\n const render =\n typeof selected === 'object' &&\n selected !== null &&\n definedRenderStateSymbol in selected\n ? (await findDefinedRenderState({ State: selected }, label)).render\n : (selected as ScopedComponentRenderFn);\n // The render callback runs as a React component so hooks remain legal.\n function Loaded({\n callProps,\n context,\n }: {\n callProps: Record<string, unknown>;\n context: Record<string, ComponentType<any>>;\n }) {\n if (\n typeof render !== 'function' ||\n (render as unknown as { prototype?: { isReactComponent?: unknown } })\n .prototype?.isReactComponent\n )\n return createElement(render as ComponentType<any>, callProps);\n return resolveScopedRenderResult(render(callProps, context), callProps);\n }\n return Loaded;\n },\n });\n const Content = withLazyHandle(function LazyScopedContent({\n callProps,\n context,\n }: {\n callProps: Record<string, unknown>;\n context: Record<string, ComponentType<any>>;\n }) {\n const defaults = environment?.defaults() ?? {};\n const currentProps = useRef(callProps);\n currentProps.current = callProps;\n const fallbackStates = useRef<LazyResourceStates & { owner?: string }>();\n fallbackStates.current ??= environment?.states?.(resource, callProps) ?? {};\n const nearest = fallbackStates.current;\n const errorComponent = useRef<LazyResourceStates['Error']>();\n const NearestError = nearest.Error;\n if (NearestError && !errorComponent.current) {\n errorComponent.current = function ScopedFallbackError(props) {\n return (\n <LazyFallbackPropsContext.Provider\n value={{ owner: nearest.owner, props: currentProps.current }}\n >\n <NearestError {...props} />\n </LazyFallbackPropsContext.Provider>\n );\n };\n }\n const Loading = nearest.Loading ?? defaults.Loading;\n const fallback =\n input.fallback !== undefined ? input.fallback : options.fallback;\n return (\n <LazyBoundary\n loader={loader}\n resource={resource}\n componentProps={{ callProps, context }}\n ErrorComponent={errorComponent.current ?? defaults.Error}\n onMount={inspection.hooks.onMount}\n fallback={\n fallback !== undefined ? (\n fallback\n ) : Loading ? (\n <LazyFallbackPropsContext.Provider\n value={{ owner: nearest.owner, props: callProps }}\n >\n <Loading resource={resource} />\n </LazyFallbackPropsContext.Provider>\n ) : null\n }\n />\n );\n }, loader);\n inspection.store.attach(Content);\n return Content;\n}\n"],"mappings":";;;;;;;;;;;;AA4CA,MAAa,mBAAmB,OAAO,YAAY;;AAGnD,SAAgB,wBACd,OAIA,UACA,OACA,aACA;CACA,MAAM,UACJ,OAAO,MAAM,SAAS,aAAa,EAAE,MAAM,MAAM,KAAK,IAAI,MAAM;CAClE,MAAM,cAAc,aAAa,MAAM,KAAK;EAC1C,IAAI,aAAa,WAAW;EAC5B,MAAM;EACN;EACA,SAAS,EAAE,SAAS;CACtB,CAAC;CACD,IAAI,eAAe,aACjB,YAAY,MAAM,KAAK,YAAY,QAAQ,aAAa,UAAU;CAEpE,MAAM,aAAa,YAAY,OAAO,aAAa,OAAO,WAAW;CACrE,IAAI,aACF,WAAW,MAAM,gBACf,WAAW,MAAM,MAAM,aAAa,WAAW,EAAE;CAErD,MAAM,SAAS,iBAAiB;EAC9B,MAAM,QAAQ;EACd;EACA,OAAO,WAAW;EAClB,MAAM,OAAO,QAAQ;GACnB,MAAM,aAAa,OAAO,OAAO,MAAM,EAAE,QACtC,UACC,0BAA0B,KAAK,KAC9B,OAAO,UAAU,YAChB,UAAU,QACV,4BAA4B,KAClC;GACA,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,6BAA6B,OAAO,WAAW,MAAM;GACjE,MAAM,WAAW,WAAW;GAC5B,MAAM,SACJ,OAAO,aAAa,YACpB,aAAa,QACb,4BAA4B,YACvB,MAAM,uBAAuB,EAAE,OAAO,SAAS,GAAG,KAAK,GAAG,SAC1D;GAEP,SAAS,OAAO,EACd,WACA,WAIC;IACD,IACE,OAAO,WAAW,cACjB,OACE,WAAW,kBAEd,OAAO,cAAc,QAA8B,SAAS;IAC9D,OAAO,0BAA0B,OAAO,WAAW,OAAO,GAAG,SAAS;GACxE;GACA,OAAO;EACT;CACF,CAAC;CACD,MAAM,UAAU,eAAe,SAAS,kBAAkB,EACxD,WACA,WAIC;EACD,MAAM,WAAW,aAAa,SAAS,KAAK,CAAC;EAC7C,MAAM,eAAe,OAAO,SAAS;EACrC,aAAa,UAAU;EACvB,MAAM,iBAAiB,OAAgD;EACvE,eAAe,YAAY,aAAa,SAAS,UAAU,SAAS,KAAK,CAAC;EAC1E,MAAM,UAAU,eAAe;EAC/B,MAAM,iBAAiB,OAAoC;EAC3D,MAAM,eAAe,QAAQ;EAC7B,IAAI,gBAAgB,CAAC,eAAe,SAClC,eAAe,UAAU,SAAS,oBAAoB,OAAO;GAC3D,OACE,oBAAC,yBAAyB,UAA1B;IACE,OAAO;KAAE,OAAO,QAAQ;KAAO,OAAO,aAAa;IAAQ;cAE3D,oBAAC,cAAD,EAAc,GAAI,MAAQ;GACO;EAEvC;EAEF,MAAM,UAAU,QAAQ,WAAW,SAAS;EAC5C,MAAM,WACJ,MAAM,aAAa,SAAY,MAAM,WAAW,QAAQ;EAC1D,OACE,oBAAC,cAAD;GACU;GACE;GACV,gBAAgB;IAAE;IAAW;GAAQ;GACrC,gBAAgB,eAAe,WAAW,SAAS;GACnD,SAAS,WAAW,MAAM;GAC1B,UACE,aAAa,SACX,WACE,UACF,oBAAC,yBAAyB,UAA1B;IACE,OAAO;KAAE,OAAO,QAAQ;KAAO,OAAO;IAAU;cAEhD,oBAAC,SAAD,EAAmB,SAAW;GACG,KACjC;EAEP;CAEL,GAAG,MAAM;CACT,WAAW,MAAM,OAAO,OAAO;CAC/B,OAAO;AACT"}
@@ -0,0 +1,10 @@
1
+
2
+ //#region src/lazy/types.ts
3
+ /** Internal factory defaults propagated to layouts without publishing metadata. */
4
+ const lazyDefaultsSymbol = Symbol("lazyDefaults");
5
+ const lazyStatesSymbol = Symbol("lazyStates");
6
+
7
+ //#endregion
8
+ exports.lazyDefaultsSymbol = lazyDefaultsSymbol;
9
+ exports.lazyStatesSymbol = lazyStatesSymbol;
10
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","names":[],"sources":["../../src/lazy/types.ts"],"sourcesContent":["import type { ComponentType, ReactNode } from 'react';\nimport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\nimport type {\n LazyResourceError,\n LazyResourceErrorMap,\n} from '../errors/lazy-resource-error';\n\nexport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\n\n/** Options shared by lazy layouts, render states, and scoped content. */\nexport type LazyOptions<\n Module extends Record<string, unknown> = Record<string, unknown>,\n> = {\n load: () => Promise<Module>;\n fallback?: ReactNode;\n};\n\nexport type LazyHandle = {\n preload(): Promise<void>;\n readonly status: LoadStatus;\n};\n\nexport type LazyResourceErrorProps<Resource = string> = {\n error: LazyResourceError;\n retry: () => void;\n resource: Resource;\n};\n\nexport type LazyResourceErrorComponent<Resource = string> = ComponentType<\n LazyResourceErrorProps<Resource>\n>;\nexport type LazyResourceLoadingComponent<Resource = string> = ComponentType<{\n resource: Resource;\n}>;\nexport type LazyResourceStates<Resource = string> = {\n Error?: LazyResourceErrorComponent<Resource>;\n Loading?: LazyResourceLoadingComponent<Resource>;\n};\n\nexport type LazyErrorHandlers<Resource, Custom extends object = {}> = {\n [Code in LazyResourceError['code']]?: (\n props: Custom &\n Omit<LazyResourceErrorProps<Resource>, 'error'> & {\n error: LazyResourceErrorMap[Code];\n },\n ) => ReactNode;\n} & {\n fallback?: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode;\n};\n\nexport type CreateLazyErrorComponent<Resource> = {\n <Custom extends object = {}>(\n render: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n <Custom extends object = {}>(\n handlers: LazyErrorHandlers<Resource, Custom>,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n};\n\n/** Internal factory defaults propagated to layouts without publishing metadata. */\nexport const lazyDefaultsSymbol = Symbol('lazyDefaults');\n\nexport const lazyStatesSymbol = Symbol('lazyStates');\n"],"mappings":";;;AA4DA,MAAa,qBAAqB,OAAO,cAAc;AAEvD,MAAa,mBAAmB,OAAO,YAAY"}
@@ -0,0 +1,39 @@
1
+ import { LazyResourceError, LazyResourceErrorMap } from "../errors/lazy-resource-error.cjs";
2
+ import { ComponentType, ReactNode } from "react";
3
+ import { LoadStatus, LoadStatus as LoadStatus$1 } from "@jfdevelops/react-layout-devtools-core";
4
+
5
+ //#region src/lazy/types.d.ts
6
+ /** Options shared by lazy layouts, render states, and scoped content. */
7
+ type LazyOptions<Module extends Record<string, unknown> = Record<string, unknown>> = {
8
+ load: () => Promise<Module>;
9
+ fallback?: ReactNode;
10
+ };
11
+ type LazyHandle = {
12
+ preload(): Promise<void>;
13
+ readonly status: LoadStatus;
14
+ };
15
+ type LazyResourceErrorProps<Resource = string> = {
16
+ error: LazyResourceError;
17
+ retry: () => void;
18
+ resource: Resource;
19
+ };
20
+ type LazyResourceErrorComponent<Resource = string> = ComponentType<LazyResourceErrorProps<Resource>>;
21
+ type LazyResourceLoadingComponent<Resource = string> = ComponentType<{
22
+ resource: Resource;
23
+ }>;
24
+ type LazyResourceStates<Resource = string> = {
25
+ Error?: LazyResourceErrorComponent<Resource>;
26
+ Loading?: LazyResourceLoadingComponent<Resource>;
27
+ };
28
+ type LazyErrorHandlers<Resource, Custom extends object = {}> = { [Code in LazyResourceError['code']]?: (props: Custom & Omit<LazyResourceErrorProps<Resource>, 'error'> & {
29
+ error: LazyResourceErrorMap[Code];
30
+ }) => ReactNode } & {
31
+ fallback?: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode;
32
+ };
33
+ type CreateLazyErrorComponent<Resource> = {
34
+ <Custom extends object = {}>(render: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
35
+ <Custom extends object = {}>(handlers: LazyErrorHandlers<Resource, Custom>): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
36
+ };
37
+ //#endregion
38
+ export { CreateLazyErrorComponent, LazyErrorHandlers, LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceErrorProps, LazyResourceLoadingComponent, LazyResourceStates, type LoadStatus$1 as LoadStatus };
39
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/lazy/types.ts"],"mappings":";;;;;;KAUY,WAAA,gBACK,MAAA,oBAA0B,MAAA;EAEzC,IAAA,QAAY,OAAA,CAAQ,MAAA;EACpB,QAAA,GAAW,SAAA;AAAA;AAAA,KAGD,UAAA;EACV,OAAA,IAAW,OAAA;EAAA,SACF,MAAA,EAAQ,UAAU;AAAA;AAAA,KAGjB,sBAAA;EACV,KAAA,EAAO,iBAAA;EACP,KAAA;EACA,QAAA,EAAU,QAAQ;AAAA;AAAA,KAGR,0BAAA,sBAAgD,aAAA,CAC1D,sBAAA,CAAuB,QAAA;AAAA,KAEb,4BAAA,sBAAkD,aAAa;EACzE,QAAA,EAAU,QAAA;AAAA;AAAA,KAEA,kBAAA;EACV,KAAA,GAAQ,0BAAA,CAA2B,QAAA;EACnC,OAAA,GAAU,4BAAA,CAA6B,QAAA;AAAA;AAAA,KAG7B,iBAAA,oDACD,iBAAA,aACP,KAAA,EAAO,MAAA,GACL,IAAA,CAAK,sBAAA,CAAuB,QAAA;EAC1B,KAAA,EAAO,oBAAA,CAAqB,IAAA;AAAA,MAE7B,SAAA;EAEL,QAAA,IAAY,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MAAc,SAAA;AAAA;AAAA,KAGvD,wBAAA;EAAA,6BAER,MAAA,GAAS,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MAAc,SAAA,GAC7D,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;EAAA,6BAE/C,QAAA,EAAU,iBAAA,CAAkB,QAAA,EAAU,MAAA,IACrC,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;AAAA"}
@@ -0,0 +1,39 @@
1
+ import { LazyResourceError, LazyResourceErrorMap } from "../errors/lazy-resource-error.mjs";
2
+ import { ComponentType, ReactNode } from "react";
3
+ import { LoadStatus, LoadStatus as LoadStatus$1 } from "@jfdevelops/react-layout-devtools-core";
4
+
5
+ //#region src/lazy/types.d.ts
6
+ /** Options shared by lazy layouts, render states, and scoped content. */
7
+ type LazyOptions<Module extends Record<string, unknown> = Record<string, unknown>> = {
8
+ load: () => Promise<Module>;
9
+ fallback?: ReactNode;
10
+ };
11
+ type LazyHandle = {
12
+ preload(): Promise<void>;
13
+ readonly status: LoadStatus;
14
+ };
15
+ type LazyResourceErrorProps<Resource = string> = {
16
+ error: LazyResourceError;
17
+ retry: () => void;
18
+ resource: Resource;
19
+ };
20
+ type LazyResourceErrorComponent<Resource = string> = ComponentType<LazyResourceErrorProps<Resource>>;
21
+ type LazyResourceLoadingComponent<Resource = string> = ComponentType<{
22
+ resource: Resource;
23
+ }>;
24
+ type LazyResourceStates<Resource = string> = {
25
+ Error?: LazyResourceErrorComponent<Resource>;
26
+ Loading?: LazyResourceLoadingComponent<Resource>;
27
+ };
28
+ type LazyErrorHandlers<Resource, Custom extends object = {}> = { [Code in LazyResourceError['code']]?: (props: Custom & Omit<LazyResourceErrorProps<Resource>, 'error'> & {
29
+ error: LazyResourceErrorMap[Code];
30
+ }) => ReactNode } & {
31
+ fallback?: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode;
32
+ };
33
+ type CreateLazyErrorComponent<Resource> = {
34
+ <Custom extends object = {}>(render: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
35
+ <Custom extends object = {}>(handlers: LazyErrorHandlers<Resource, Custom>): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
36
+ };
37
+ //#endregion
38
+ export { CreateLazyErrorComponent, LazyErrorHandlers, LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceErrorProps, LazyResourceLoadingComponent, LazyResourceStates, type LoadStatus$1 as LoadStatus };
39
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/lazy/types.ts"],"mappings":";;;;;;KAUY,WAAA,gBACK,MAAA,oBAA0B,MAAA;EAEzC,IAAA,QAAY,OAAA,CAAQ,MAAA;EACpB,QAAA,GAAW,SAAA;AAAA;AAAA,KAGD,UAAA;EACV,OAAA,IAAW,OAAA;EAAA,SACF,MAAA,EAAQ,UAAU;AAAA;AAAA,KAGjB,sBAAA;EACV,KAAA,EAAO,iBAAA;EACP,KAAA;EACA,QAAA,EAAU,QAAQ;AAAA;AAAA,KAGR,0BAAA,sBAAgD,aAAA,CAC1D,sBAAA,CAAuB,QAAA;AAAA,KAEb,4BAAA,sBAAkD,aAAa;EACzE,QAAA,EAAU,QAAA;AAAA;AAAA,KAEA,kBAAA;EACV,KAAA,GAAQ,0BAAA,CAA2B,QAAA;EACnC,OAAA,GAAU,4BAAA,CAA6B,QAAA;AAAA;AAAA,KAG7B,iBAAA,oDACD,iBAAA,aACP,KAAA,EAAO,MAAA,GACL,IAAA,CAAK,sBAAA,CAAuB,QAAA;EAC1B,KAAA,EAAO,oBAAA,CAAqB,IAAA;AAAA,MAE7B,SAAA;EAEL,QAAA,IAAY,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MAAc,SAAA;AAAA;AAAA,KAGvD,wBAAA;EAAA,6BAER,MAAA,GAAS,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MAAc,SAAA,GAC7D,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;EAAA,6BAE/C,QAAA,EAAU,iBAAA,CAAkB,QAAA,EAAU,MAAA,IACrC,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;AAAA"}
@@ -0,0 +1,8 @@
1
+ //#region src/lazy/types.ts
2
+ /** Internal factory defaults propagated to layouts without publishing metadata. */
3
+ const lazyDefaultsSymbol = Symbol("lazyDefaults");
4
+ const lazyStatesSymbol = Symbol("lazyStates");
5
+
6
+ //#endregion
7
+ export { lazyDefaultsSymbol, lazyStatesSymbol };
8
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","names":[],"sources":["../../src/lazy/types.ts"],"sourcesContent":["import type { ComponentType, ReactNode } from 'react';\nimport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\nimport type {\n LazyResourceError,\n LazyResourceErrorMap,\n} from '../errors/lazy-resource-error';\n\nexport type { LoadStatus } from '@jfdevelops/react-layout-devtools-core';\n\n/** Options shared by lazy layouts, render states, and scoped content. */\nexport type LazyOptions<\n Module extends Record<string, unknown> = Record<string, unknown>,\n> = {\n load: () => Promise<Module>;\n fallback?: ReactNode;\n};\n\nexport type LazyHandle = {\n preload(): Promise<void>;\n readonly status: LoadStatus;\n};\n\nexport type LazyResourceErrorProps<Resource = string> = {\n error: LazyResourceError;\n retry: () => void;\n resource: Resource;\n};\n\nexport type LazyResourceErrorComponent<Resource = string> = ComponentType<\n LazyResourceErrorProps<Resource>\n>;\nexport type LazyResourceLoadingComponent<Resource = string> = ComponentType<{\n resource: Resource;\n}>;\nexport type LazyResourceStates<Resource = string> = {\n Error?: LazyResourceErrorComponent<Resource>;\n Loading?: LazyResourceLoadingComponent<Resource>;\n};\n\nexport type LazyErrorHandlers<Resource, Custom extends object = {}> = {\n [Code in LazyResourceError['code']]?: (\n props: Custom &\n Omit<LazyResourceErrorProps<Resource>, 'error'> & {\n error: LazyResourceErrorMap[Code];\n },\n ) => ReactNode;\n} & {\n fallback?: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode;\n};\n\nexport type CreateLazyErrorComponent<Resource> = {\n <Custom extends object = {}>(\n render: (props: Custom & LazyResourceErrorProps<Resource>) => ReactNode,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n <Custom extends object = {}>(\n handlers: LazyErrorHandlers<Resource, Custom>,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n};\n\n/** Internal factory defaults propagated to layouts without publishing metadata. */\nexport const lazyDefaultsSymbol = Symbol('lazyDefaults');\n\nexport const lazyStatesSymbol = Symbol('lazyStates');\n"],"mappings":";;AA4DA,MAAa,qBAAqB,OAAO,cAAc;AAEvD,MAAa,mBAAmB,OAAO,YAAY"}
package/dist/props.cjs CHANGED
@@ -1,9 +1,11 @@
1
+ const require_layout_configuration_error = require('./errors/layout-configuration-error.cjs');
1
2
 
2
3
  //#region src/props.ts
3
4
  function getIncludedPropBehavior(value) {
4
5
  if (value === null || typeof value !== "object") return null;
5
- const required = "required" in value && typeof value.required === "boolean" ? value.required : "visibility" in value ? value.visibility === "required" : void 0;
6
- const suppliedVia = "suppliedVia" in value ? value.suppliedVia : "passthrough" in value ? value.passthrough : void 0;
6
+ if ("visibility" in value || "passthrough" in value) throw new require_layout_configuration_error.LayoutConfigurationError("Include properties visibility and passthrough were removed; use required and suppliedVia.");
7
+ const required = "required" in value && typeof value.required === "boolean" ? value.required : void 0;
8
+ const suppliedVia = "suppliedVia" in value ? value.suppliedVia : void 0;
7
9
  if (required === void 0 || suppliedVia !== "component" && suppliedVia !== "config") return null;
8
10
  return {
9
11
  visibility: required ? "required" : "optional",
@@ -1 +1 @@
1
- {"version":3,"file":"props.cjs","names":[],"sources":["../src/props.ts"],"sourcesContent":["import type {\n ComposableComponents,\n MergePresetProps,\n} from '@jfdevelops/react-layout-composables';\nimport type { InPropsObject } from '@jfdevelops/react-layout-composables';\nimport {\n EnumWrappedProp,\n LiteralWrappedProp,\n ResolveLayoutProps,\n ResolveLayoutPropsAsDefined,\n ResolveProps,\n} from '@jfdevelops/react-layout-validator';\nimport { ResourceDefinition, ResourceEnum } from './resource';\nimport { Show } from './utils';\n\nexport type { InPropsObject };\n\n/**\n * Two-argument `render(props, context)` used by createComponent and scoped\n * resource components. `Context` is sibling components (scoped) or the\n * resource render context (top-level).\n */\nexport type PropsContextRender<RenderProps, Context, Result = unknown> = (\n props: RenderProps,\n context: Context\n) => Result;\n\n/**\n * Shared `{ props?, render }` shape used by createComponent, scoped\n * components, and anywhere else a value declares props and a two-arg render.\n *\n * @typeParam Props - Declared on the entry (`props`). Often an\n * {@link InPropsObject}, or a layout include/custom bag.\n * @typeParam RenderProps - First argument to `render` (defaults to\n * {@link ResolveProps}<Props> when Props is an {@link InPropsObject})\n * @typeParam Result - `render` return type\n * @typeParam Context - Second argument to `render`\n */\nexport interface PropsRenderDefinition<\n Props = InPropsObject,\n RenderProps = Props extends InPropsObject ? ResolveProps<Props> : unknown,\n Result = unknown,\n Context = unknown\n> {\n props?: Props;\n render: PropsContextRender<RenderProps, Context, Result>;\n}\n\nexport type InPropsOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Name extends string\n> = {\n name: LiteralWrappedProp<Name, 'string', 'required'>;\n resource: EnumWrappedProp<ResourceEnum<Resources>, 'string', 'required'>;\n};\nexport type InPropsFunction<\n Resources extends ReadonlyArray<ResourceDefinition>\n> = <Name extends string>(\n props: Show<InPropsOptions<Resources, Name>>\n) => InPropsObject;\nexport type InPropsDefinition<\n Resources extends ReadonlyArray<ResourceDefinition>\n> = InPropsObject | InPropsFunction<Resources>;\nexport type InferredInProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>\n> = Options extends InPropsFunction<Resources> ? ReturnType<Options> : Options;\nexport type MergedLayoutInProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents\n> = InferredInProps<Resources, Options> extends InPropsObject\n ? InferredInProps<Resources, Options> & MergePresetProps<Composables>\n : never;\nexport type RequiredVariant = true | 'required';\n/**\n * @typeParam RequiredVariant How the required props are selected. In application code,\n * it will always be `true`, but internally we need to support `'required'` as well.\n */\ntype PropsType<Variant extends RequiredVariant = true> = Variant | 'optional';\ntype InternalPropsType = PropsType<'required'>;\ntype IncludedPropSource = 'component' | 'config';\ntype IncludedPropRequirement =\n | {\n /**\n * Whether the prop must be supplied. When both names are present,\n * `required` takes precedence over the deprecated `visibility` setting.\n */\n required: boolean;\n }\n | {\n /**\n * Whether the prop must be supplied (`'required'`) or may be omitted\n * (`'optional'`). The `required` setting takes precedence when both are present.\n *\n * @deprecated Use `required: true` instead of `visibility: 'required'`, or\n * `required: false` instead of `visibility: 'optional'`.\n * This property will be removed in the next major version.\n */\n visibility: 'optional' | 'required';\n };\ntype IncludedPropSupply =\n | {\n /**\n * Where the prop is supplied: at component render time (`'component'`)\n * or through layout creation options (`'config'`). Optional component props\n * also accept configuration-time defaults. This setting takes precedence\n * over the deprecated `passthrough` setting.\n */\n suppliedVia: IncludedPropSource;\n }\n | {\n /**\n * Where the prop is supplied: at component render time (`'component'`)\n * or through layout creation options (`'config'`). Optional component props\n * also accept configuration-time defaults. The `suppliedVia` setting takes\n * precedence when both names are present.\n *\n * @deprecated Use `suppliedVia: 'component'` instead of\n * `passthrough: 'component'`, or `suppliedVia: 'config'` instead of\n * `passthrough: 'config'`. This property will be removed in the next major version.\n */\n passthrough: IncludedPropSource;\n };\n\n/**\n * Controls where an included layout prop is supplied and whether it is required there.\n */\nexport type IncludedPropBehavior = IncludedPropRequirement & IncludedPropSupply;\n\ntype IncludedPropType = PropsType | IncludedPropBehavior;\n/**\n * A map of props to include in the layout.\n */\nexport type IncludedProps<T extends object> = {\n [K in keyof T & string]?: IncludedPropType;\n};\n\ntype PropsKeys<Props extends InPropsObject, T> = T & keyof Props;\nexport type IncludedPropVisibility<Value> = Value extends { required: boolean }\n ? Value['required'] extends true\n ? 'required'\n : 'optional'\n : Value extends { visibility: 'required' | 'optional' }\n ? Value['visibility']\n : Value extends true | 'required'\n ? 'required'\n : Value extends 'optional'\n ? 'optional'\n : never;\nexport type IncludedPropSupplySource<Value> = Value extends {\n suppliedVia: IncludedPropSource;\n}\n ? Value['suppliedVia']\n : Value extends { passthrough: IncludedPropSource }\n ? Value['passthrough']\n : never;\n/**\n * Canonical shape used internally for either spelling of an include behavior.\n */\nexport type NormalizedIncludedPropBehavior<Value> = Value extends\n | { required: boolean }\n | { suppliedVia: IncludedPropSource }\n ? {\n visibility: IncludedPropVisibility<Value>;\n passthrough: IncludedPropSupplySource<Value>;\n }\n : Value;\n\nexport type IncludedPropPassthrough<Value> = Value extends\n | { required: boolean }\n | { suppliedVia: IncludedPropSource }\n ? IncludedPropSupplySource<Value> extends 'component'\n ? IncludedPropVisibility<Value> extends 'optional'\n ? 'component' | 'config'\n : 'component'\n : IncludedPropSupplySource<Value>\n : Value extends {\n visibility: 'required' | 'optional';\n passthrough: IncludedPropSource;\n }\n ? Value['passthrough'] extends 'component'\n ? Value['visibility'] extends 'optional'\n ? 'component' | 'config'\n : 'component'\n : Value['passthrough']\n : Value extends true | 'required'\n ? 'config'\n : Value extends 'optional'\n ? 'component' | 'config'\n : never;\n\ntype GetPropsKey<\n IncludeProps extends object,\n Visibility extends InternalPropsType,\n Passthrough extends IncludedPropSource | 'render' = 'render'\n> = {\n [Key in keyof IncludeProps]: IncludedPropVisibility<\n IncludeProps[Key]\n > extends Visibility\n ? Passthrough extends 'render'\n ? Key\n : Passthrough extends IncludedPropPassthrough<IncludeProps[Key]>\n ? Key\n : never\n : never;\n}[keyof IncludeProps];\ntype SelectedIncludedProps<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>,\n Visibility extends InternalPropsType,\n Passthrough extends IncludedPropSource | 'render' = 'render'\n> = Pick<\n Props,\n PropsKeys<Props, GetPropsKey<IncludeProps, Visibility, Passthrough>>\n>;\n\ntype OptionalPropDefinition<Definition> = Definition extends {\n optional(): infer OptionalDefinition;\n}\n ? OptionalDefinition\n : Definition;\n\n/** Raw validator definitions accepted by a generated component call. */\nexport type IncludedComponentPropDefinitions<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>\n> = SelectedIncludedProps<Props, IncludeProps, 'required', 'component'> & {\n [Key in keyof SelectedIncludedProps<\n Props,\n IncludeProps,\n 'optional',\n 'component'\n >]: OptionalPropDefinition<\n SelectedIncludedProps<Props, IncludeProps, 'optional', 'component'>[Key]\n >;\n};\n\nexport type ResolvedIncludedProps<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>\n> = ResolveLayoutProps<SelectedIncludedProps<Props, IncludeProps, 'required'>> &\n Partial<\n ResolveLayoutProps<SelectedIncludedProps<Props, IncludeProps, 'optional'>>\n >;\n\nexport type ResolvedIncludedConfigProps<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>\n> = ResolveLayoutProps<\n SelectedIncludedProps<Props, IncludeProps, 'required', 'config'>\n> &\n Partial<\n ResolveLayoutProps<\n SelectedIncludedProps<Props, IncludeProps, 'optional', 'config'>\n >\n >;\n\nexport type ResolvedIncludedComponentProps<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>\n> = ResolveLayoutProps<\n SelectedIncludedProps<Props, IncludeProps, 'required', 'component'>\n> &\n Partial<\n ResolveLayoutProps<\n SelectedIncludedProps<Props, IncludeProps, 'optional', 'component'>\n >\n >;\n\n/**\n * Like {@link ResolvedIncludedProps}, but keeps included prop keys exactly as\n * declared (no `JSX.Element` capitalization).\n */\nexport type ResolvedIncludedPropsAsDefined<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>\n> = ResolveLayoutPropsAsDefined<\n SelectedIncludedProps<Props, IncludeProps, 'required'>\n> &\n Partial<\n ResolveLayoutPropsAsDefined<\n SelectedIncludedProps<Props, IncludeProps, 'optional'>\n >\n >;\nexport type LayoutRenderProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents = {},\n IncludeProps extends IncludedProps<\n MergedLayoutInProps<Resources, Options, Composables>\n > = {},\n CustomProps extends InPropsObject = {}\n> = Show<\n ResolveProps<CustomProps> &\n ResolvedIncludedProps<\n MergedLayoutInProps<Resources, Options, Composables>,\n IncludeProps\n >\n>;\n\nexport function getIncludedPropBehavior(value: unknown): {\n visibility: 'required' | 'optional';\n passthrough: 'component' | 'config';\n} | null {\n if (value === null || typeof value !== 'object') {\n return null;\n }\n\n const required =\n 'required' in value && typeof value.required === 'boolean'\n ? value.required\n : 'visibility' in value\n ? value.visibility === 'required'\n : undefined;\n const suppliedVia =\n 'suppliedVia' in value\n ? value.suppliedVia\n : 'passthrough' in value\n ? value.passthrough\n : undefined;\n\n if (\n required === undefined ||\n (suppliedVia !== 'component' && suppliedVia !== 'config')\n ) {\n return null;\n }\n\n return {\n visibility: required ? 'required' : 'optional',\n passthrough: suppliedVia,\n };\n}\n"],"mappings":";;AA6SA,SAAgB,wBAAwB,OAG/B;CACP,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO;CAGT,MAAM,WACJ,cAAc,SAAS,OAAO,MAAM,aAAa,YAC7C,MAAM,WACN,gBAAgB,QAChB,MAAM,eAAe,aACrB;CACN,MAAM,cACJ,iBAAiB,QACb,MAAM,cACN,iBAAiB,QACjB,MAAM,cACN;CAEN,IACE,aAAa,UACZ,gBAAgB,eAAe,gBAAgB,UAEhD,OAAO;CAGT,OAAO;EACL,YAAY,WAAW,aAAa;EACpC,aAAa;CACf;AACF"}
1
+ {"version":3,"file":"props.cjs","names":["LayoutConfigurationError"],"sources":["../src/props.ts"],"sourcesContent":["import { LayoutConfigurationError } from './errors';\nimport type {\n ComposableComponents,\n MergePresetProps,\n} from '@jfdevelops/react-layout-composables';\nimport type { InPropsObject } from '@jfdevelops/react-layout-composables';\nimport {\n EnumWrappedProp,\n LiteralWrappedProp,\n ResolveLayoutProps,\n ResolveLayoutPropsAsDefined,\n ResolveProps,\n} from '@jfdevelops/react-layout-validator';\nimport { ResourceDefinition, ResourceEnum } from './resource';\nimport { Show } from './utils';\n\nexport type { InPropsObject };\n\n/**\n * Two-argument `render(props, context)` used by createComponent and scoped\n * resource components. `Context` is sibling components (scoped) or the\n * resource render context (top-level).\n */\nexport type PropsContextRender<RenderProps, Context, Result = unknown> = (\n props: RenderProps,\n context: Context,\n) => Result;\n\n/**\n * Shared `{ props?, render }` shape used by createComponent, scoped\n * components, and anywhere else a value declares props and a two-arg render.\n *\n * @typeParam Props - Declared on the entry (`props`). Often an\n * {@link InPropsObject}, or a layout include/custom bag.\n * @typeParam RenderProps - First argument to `render` (defaults to\n * {@link ResolveProps}<Props> when Props is an {@link InPropsObject})\n * @typeParam Result - `render` return type\n * @typeParam Context - Second argument to `render`\n */\nexport interface PropsRenderDefinition<\n Props = InPropsObject,\n RenderProps = Props extends InPropsObject ? ResolveProps<Props> : unknown,\n Result = unknown,\n Context = unknown,\n> {\n props?: Props;\n render: PropsContextRender<RenderProps, Context, Result>;\n}\n\nexport type InPropsOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Name extends string,\n> = {\n name: LiteralWrappedProp<Name, 'string', 'required'>;\n resource: EnumWrappedProp<ResourceEnum<Resources>, 'string', 'required'>;\n};\nexport type InPropsFunction<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = <Name extends string>(\n props: Show<InPropsOptions<Resources, Name>>,\n) => InPropsObject;\nexport type InPropsDefinition<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = InPropsObject | InPropsFunction<Resources>;\nexport type InferredInProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n> = Options extends InPropsFunction<Resources> ? ReturnType<Options> : Options;\nexport type MergedLayoutInProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n> =\n InferredInProps<Resources, Options> extends InPropsObject\n ? InferredInProps<Resources, Options> & MergePresetProps<Composables>\n : never;\nexport type RequiredVariant = true | 'required';\n/**\n * @typeParam RequiredVariant How the required props are selected. In application code,\n * it will always be `true`, but internally we need to support `'required'` as well.\n */\ntype PropsType<Variant extends RequiredVariant = true> = Variant | 'optional';\ntype InternalPropsType = PropsType<'required'>;\ntype IncludedPropSource = 'component' | 'config';\n/** Controls whether an included prop is required and where it is supplied. */\nexport type IncludedPropBehavior = {\n required: boolean;\n suppliedVia: IncludedPropSource;\n};\n\ntype IncludedPropType = PropsType | IncludedPropBehavior;\n/**\n * A map of props to include in the layout.\n */\nexport type IncludedProps<T extends object> = {\n [K in keyof T & string]?: IncludedPropType;\n};\n\ntype PropsKeys<Props extends InPropsObject, T> = T & keyof Props;\nexport type IncludedPropVisibility<Value> = Value extends { required: boolean }\n ? Value['required'] extends true\n ? 'required'\n : 'optional'\n : Value extends true | 'required'\n ? 'required'\n : Value extends 'optional'\n ? 'optional'\n : never;\nexport type IncludedPropSupplySource<Value> = Value extends {\n suppliedVia: IncludedPropSource;\n}\n ? Value['suppliedVia']\n : never;\n/**\n * Internal representation of the supported include behavior.\n */\nexport type NormalizedIncludedPropBehavior<Value> = Value extends\n | { required: boolean }\n | { suppliedVia: IncludedPropSource }\n ? {\n visibility: IncludedPropVisibility<Value>;\n passthrough: IncludedPropSupplySource<Value>;\n }\n : Value;\n\nexport type IncludedPropPassthrough<Value> = Value extends\n | { required: boolean }\n | { suppliedVia: IncludedPropSource }\n ? IncludedPropSupplySource<Value> extends 'component'\n ? IncludedPropVisibility<Value> extends 'optional'\n ? 'component' | 'config'\n : 'component'\n : IncludedPropSupplySource<Value>\n : Value extends true | 'required'\n ? 'config'\n : Value extends 'optional'\n ? 'component' | 'config'\n : never;\n\ntype GetPropsKey<\n IncludeProps extends object,\n Visibility extends InternalPropsType,\n Passthrough extends IncludedPropSource | 'render' = 'render',\n> = {\n [Key in keyof IncludeProps]: IncludedPropVisibility<\n IncludeProps[Key]\n > extends Visibility\n ? Passthrough extends 'render'\n ? Key\n : Passthrough extends IncludedPropPassthrough<IncludeProps[Key]>\n ? Key\n : never\n : never;\n}[keyof IncludeProps];\ntype SelectedIncludedProps<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>,\n Visibility extends InternalPropsType,\n Passthrough extends IncludedPropSource | 'render' = 'render',\n> = Pick<\n Props,\n PropsKeys<Props, GetPropsKey<IncludeProps, Visibility, Passthrough>>\n>;\n\ntype OptionalPropDefinition<Definition> = Definition extends {\n optional(): infer OptionalDefinition;\n}\n ? OptionalDefinition\n : Definition;\n\n/** Raw validator definitions accepted by a generated component call. */\nexport type IncludedComponentPropDefinitions<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>,\n> = SelectedIncludedProps<Props, IncludeProps, 'required', 'component'> & {\n [Key in keyof SelectedIncludedProps<\n Props,\n IncludeProps,\n 'optional',\n 'component'\n >]: OptionalPropDefinition<\n SelectedIncludedProps<Props, IncludeProps, 'optional', 'component'>[Key]\n >;\n};\n\nexport type ResolvedIncludedProps<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>,\n> = ResolveLayoutProps<SelectedIncludedProps<Props, IncludeProps, 'required'>> &\n Partial<\n ResolveLayoutProps<SelectedIncludedProps<Props, IncludeProps, 'optional'>>\n >;\n\nexport type ResolvedIncludedConfigProps<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>,\n> = ResolveLayoutProps<\n SelectedIncludedProps<Props, IncludeProps, 'required', 'config'>\n> &\n Partial<\n ResolveLayoutProps<\n SelectedIncludedProps<Props, IncludeProps, 'optional', 'config'>\n >\n >;\n\nexport type ResolvedIncludedComponentProps<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>,\n> = ResolveLayoutProps<\n SelectedIncludedProps<Props, IncludeProps, 'required', 'component'>\n> &\n Partial<\n ResolveLayoutProps<\n SelectedIncludedProps<Props, IncludeProps, 'optional', 'component'>\n >\n >;\n\n/**\n * Like {@link ResolvedIncludedProps}, but keeps included prop keys exactly as\n * declared (no `JSX.Element` capitalization).\n */\nexport type ResolvedIncludedPropsAsDefined<\n Props extends InPropsObject,\n IncludeProps extends IncludedProps<Props>,\n> = ResolveLayoutPropsAsDefined<\n SelectedIncludedProps<Props, IncludeProps, 'required'>\n> &\n Partial<\n ResolveLayoutPropsAsDefined<\n SelectedIncludedProps<Props, IncludeProps, 'optional'>\n >\n >;\nexport type LayoutRenderProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents = {},\n IncludeProps extends IncludedProps<\n MergedLayoutInProps<Resources, Options, Composables>\n > = {},\n CustomProps extends InPropsObject = {},\n> = Show<\n ResolveProps<CustomProps> &\n ResolvedIncludedProps<\n MergedLayoutInProps<Resources, Options, Composables>,\n IncludeProps\n >\n>;\n\nexport function getIncludedPropBehavior(value: unknown): {\n visibility: 'required' | 'optional';\n passthrough: 'component' | 'config';\n} | null {\n if (value === null || typeof value !== 'object') {\n return null;\n }\n\n if ('visibility' in value || 'passthrough' in value) {\n throw new LayoutConfigurationError(\n 'Include properties visibility and passthrough were removed; use required and suppliedVia.',\n );\n }\n\n const required =\n 'required' in value && typeof value.required === 'boolean'\n ? value.required\n : undefined;\n const suppliedVia = 'suppliedVia' in value ? value.suppliedVia : undefined;\n\n if (\n required === undefined ||\n (suppliedVia !== 'component' && suppliedVia !== 'config')\n ) {\n return null;\n }\n\n return {\n visibility: required ? 'required' : 'optional',\n passthrough: suppliedVia,\n };\n}\n"],"mappings":";;;AAwPA,SAAgB,wBAAwB,OAG/B;CACP,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO;CAGT,IAAI,gBAAgB,SAAS,iBAAiB,OAC5C,MAAM,IAAIA,4DACR,2FACF;CAGF,MAAM,WACJ,cAAc,SAAS,OAAO,MAAM,aAAa,YAC7C,MAAM,WACN;CACN,MAAM,cAAc,iBAAiB,QAAQ,MAAM,cAAc;CAEjE,IACE,aAAa,UACZ,gBAAgB,eAAe,gBAAgB,UAEhD,OAAO;CAGT,OAAO;EACL,YAAY,WAAW,aAAa;EACpC,aAAa;CACf;AACF"}
package/dist/props.d.cts CHANGED
@@ -41,48 +41,11 @@ type RequiredVariant = true | 'required';
41
41
  type PropsType<Variant extends RequiredVariant = true> = Variant | 'optional';
42
42
  type InternalPropsType = PropsType<'required'>;
43
43
  type IncludedPropSource = 'component' | 'config';
44
- type IncludedPropRequirement = {
45
- /**
46
- * Whether the prop must be supplied. When both names are present,
47
- * `required` takes precedence over the deprecated `visibility` setting.
48
- */
44
+ /** Controls whether an included prop is required and where it is supplied. */
45
+ type IncludedPropBehavior = {
49
46
  required: boolean;
50
- } | {
51
- /**
52
- * Whether the prop must be supplied (`'required'`) or may be omitted
53
- * (`'optional'`). The `required` setting takes precedence when both are present.
54
- *
55
- * @deprecated Use `required: true` instead of `visibility: 'required'`, or
56
- * `required: false` instead of `visibility: 'optional'`.
57
- * This property will be removed in the next major version.
58
- */
59
- visibility: 'optional' | 'required';
60
- };
61
- type IncludedPropSupply = {
62
- /**
63
- * Where the prop is supplied: at component render time (`'component'`)
64
- * or through layout creation options (`'config'`). Optional component props
65
- * also accept configuration-time defaults. This setting takes precedence
66
- * over the deprecated `passthrough` setting.
67
- */
68
47
  suppliedVia: IncludedPropSource;
69
- } | {
70
- /**
71
- * Where the prop is supplied: at component render time (`'component'`)
72
- * or through layout creation options (`'config'`). Optional component props
73
- * also accept configuration-time defaults. The `suppliedVia` setting takes
74
- * precedence when both names are present.
75
- *
76
- * @deprecated Use `suppliedVia: 'component'` instead of
77
- * `passthrough: 'component'`, or `suppliedVia: 'config'` instead of
78
- * `passthrough: 'config'`. This property will be removed in the next major version.
79
- */
80
- passthrough: IncludedPropSource;
81
48
  };
82
- /**
83
- * Controls where an included layout prop is supplied and whether it is required there.
84
- */
85
- type IncludedPropBehavior = IncludedPropRequirement & IncludedPropSupply;
86
49
  type IncludedPropType = PropsType | IncludedPropBehavior;
87
50
  /**
88
51
  * A map of props to include in the layout.
@@ -91,16 +54,12 @@ type IncludedProps<T extends object> = { [K in keyof T & string]?: IncludedPropT
91
54
  type PropsKeys<Props extends InPropsObject, T> = T & keyof Props;
92
55
  type IncludedPropVisibility<Value> = Value extends {
93
56
  required: boolean;
94
- } ? Value['required'] extends true ? 'required' : 'optional' : Value extends {
95
- visibility: 'required' | 'optional';
96
- } ? Value['visibility'] : Value extends true | 'required' ? 'required' : Value extends 'optional' ? 'optional' : never;
57
+ } ? Value['required'] extends true ? 'required' : 'optional' : Value extends true | 'required' ? 'required' : Value extends 'optional' ? 'optional' : never;
97
58
  type IncludedPropSupplySource<Value> = Value extends {
98
59
  suppliedVia: IncludedPropSource;
99
- } ? Value['suppliedVia'] : Value extends {
100
- passthrough: IncludedPropSource;
101
- } ? Value['passthrough'] : never;
60
+ } ? Value['suppliedVia'] : never;
102
61
  /**
103
- * Canonical shape used internally for either spelling of an include behavior.
62
+ * Internal representation of the supported include behavior.
104
63
  */
105
64
  type NormalizedIncludedPropBehavior<Value> = Value extends {
106
65
  required: boolean;
@@ -114,10 +73,7 @@ type IncludedPropPassthrough<Value> = Value extends {
114
73
  required: boolean;
115
74
  } | {
116
75
  suppliedVia: IncludedPropSource;
117
- } ? IncludedPropSupplySource<Value> extends 'component' ? IncludedPropVisibility<Value> extends 'optional' ? 'component' | 'config' : 'component' : IncludedPropSupplySource<Value> : Value extends {
118
- visibility: 'required' | 'optional';
119
- passthrough: IncludedPropSource;
120
- } ? Value['passthrough'] extends 'component' ? Value['visibility'] extends 'optional' ? 'component' | 'config' : 'component' : Value['passthrough'] : Value extends true | 'required' ? 'config' : Value extends 'optional' ? 'component' | 'config' : never;
76
+ } ? IncludedPropSupplySource<Value> extends 'component' ? IncludedPropVisibility<Value> extends 'optional' ? 'component' | 'config' : 'component' : IncludedPropSupplySource<Value> : Value extends true | 'required' ? 'config' : Value extends 'optional' ? 'component' | 'config' : never;
121
77
  type GetPropsKey<IncludeProps extends object, Visibility extends InternalPropsType, Passthrough extends IncludedPropSource | 'render' = 'render'> = { [Key in keyof IncludeProps]: IncludedPropVisibility<IncludeProps[Key]> extends Visibility ? Passthrough extends 'render' ? Key : Passthrough extends IncludedPropPassthrough<IncludeProps[Key]> ? Key : never : never }[keyof IncludeProps];
122
78
  type SelectedIncludedProps<Props extends InPropsObject, IncludeProps extends IncludedProps<Props>, Visibility extends InternalPropsType, Passthrough extends IncludedPropSource | 'render' = 'render'> = Pick<Props, PropsKeys<Props, GetPropsKey<IncludeProps, Visibility, Passthrough>>>;
123
79
  type OptionalPropDefinition<Definition> = Definition extends {