@jfdevelops/react-layout 1.6.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-config/create-defined-resource-layout.cjs +26 -14
- package/dist/create-config/create-defined-resource-layout.cjs.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.cts +12 -6
- package/dist/create-config/create-defined-resource-layout.d.cts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.mts +12 -6
- package/dist/create-config/create-defined-resource-layout.d.mts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.mjs +27 -15
- package/dist/create-config/create-defined-resource-layout.mjs.map +1 -1
- package/dist/create-config/define-layout.cjs +129 -58
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +9 -13
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +9 -13
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +130 -59
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/create-config/for-resources/create-component.d.cts +62 -38
- package/dist/create-config/for-resources/create-component.d.cts.map +1 -1
- package/dist/create-config/for-resources/create-component.d.mts +62 -38
- package/dist/create-config/for-resources/create-component.d.mts.map +1 -1
- package/dist/create-config/for-resources/create-for-resources.cjs +88 -12
- package/dist/create-config/for-resources/create-for-resources.cjs.map +1 -1
- package/dist/create-config/for-resources/create-for-resources.mjs +88 -12
- package/dist/create-config/for-resources/create-for-resources.mjs.map +1 -1
- package/dist/create-config/for-resources/scoped-layout.d.cts +2 -2
- package/dist/create-config/for-resources/scoped-layout.d.cts.map +1 -1
- package/dist/create-config/for-resources/scoped-layout.d.mts +2 -2
- package/dist/create-config/for-resources/scoped-layout.d.mts.map +1 -1
- package/dist/create-config/for-resources/scoped-render.cjs +39 -4
- package/dist/create-config/for-resources/scoped-render.cjs.map +1 -1
- package/dist/create-config/for-resources/scoped-render.d.cts +8 -1
- package/dist/create-config/for-resources/scoped-render.d.cts.map +1 -1
- package/dist/create-config/for-resources/scoped-render.d.mts +8 -1
- package/dist/create-config/for-resources/scoped-render.d.mts.map +1 -1
- package/dist/create-config/for-resources/scoped-render.mjs +39 -4
- package/dist/create-config/for-resources/scoped-render.mjs.map +1 -1
- package/dist/create-config/index.d.cts +3 -2
- package/dist/create-config/index.d.mts +3 -2
- package/dist/create-config/layout-name.cjs +1 -1
- package/dist/create-config/layout-name.mjs +1 -1
- package/dist/create-config/lazy-resource-layout.cjs +70 -86
- package/dist/create-config/lazy-resource-layout.cjs.map +1 -1
- package/dist/create-config/lazy-resource-layout.d.cts +9 -31
- package/dist/create-config/lazy-resource-layout.d.cts.map +1 -1
- package/dist/create-config/lazy-resource-layout.d.mts +9 -31
- package/dist/create-config/lazy-resource-layout.d.mts.map +1 -1
- package/dist/create-config/lazy-resource-layout.mjs +70 -86
- package/dist/create-config/lazy-resource-layout.mjs.map +1 -1
- package/dist/create-config/preview.cjs +1 -1
- package/dist/create-config/preview.d.cts +2 -0
- package/dist/create-config/preview.d.cts.map +1 -1
- package/dist/create-config/preview.d.mts +2 -0
- package/dist/create-config/preview.d.mts.map +1 -1
- package/dist/create-config/preview.mjs +1 -1
- package/dist/create-config/render-state-context.cjs +24 -0
- package/dist/create-config/render-state-context.cjs.map +1 -0
- package/dist/create-config/render-state-context.mjs +22 -0
- package/dist/create-config/render-state-context.mjs.map +1 -0
- package/dist/create-config/render-state.cjs +58 -18
- package/dist/create-config/render-state.cjs.map +1 -1
- package/dist/create-config/render-state.d.cts +44 -21
- package/dist/create-config/render-state.d.cts.map +1 -1
- package/dist/create-config/render-state.d.mts +44 -21
- package/dist/create-config/render-state.d.mts.map +1 -1
- package/dist/create-config/render-state.mjs +55 -18
- package/dist/create-config/render-state.mjs.map +1 -1
- package/dist/create-config/state-composable.cjs +4 -2
- package/dist/create-config/state-composable.cjs.map +1 -1
- package/dist/create-config/state-composable.d.cts.map +1 -1
- package/dist/create-config/state-composable.d.mts.map +1 -1
- package/dist/create-config/state-composable.mjs +4 -2
- package/dist/create-config/state-composable.mjs.map +1 -1
- package/dist/errors/lazy-resource-error.cjs +37 -0
- package/dist/errors/lazy-resource-error.cjs.map +1 -0
- package/dist/errors/lazy-resource-error.d.cts +26 -0
- package/dist/errors/lazy-resource-error.d.cts.map +1 -0
- package/dist/errors/lazy-resource-error.d.mts +26 -0
- package/dist/errors/lazy-resource-error.d.mts.map +1 -0
- package/dist/errors/lazy-resource-error.mjs +35 -0
- package/dist/errors/lazy-resource-error.mjs.map +1 -0
- package/dist/errors/react-layout-error.cjs +1 -1
- package/dist/errors/react-layout-error.mjs +1 -1
- package/dist/errors/resource-state-error.cjs +4 -1
- package/dist/errors/resource-state-error.cjs.map +1 -1
- package/dist/errors/resource-state-error.d.cts +1 -0
- package/dist/errors/resource-state-error.d.cts.map +1 -1
- package/dist/errors/resource-state-error.d.mts +1 -0
- package/dist/errors/resource-state-error.d.mts.map +1 -1
- package/dist/errors/resource-state-error.mjs +4 -1
- package/dist/errors/resource-state-error.mjs.map +1 -1
- package/dist/index.cjs +6 -2
- package/dist/index.d.cts +9 -5
- package/dist/index.d.mts +9 -5
- package/dist/index.mjs +4 -3
- package/dist/lazy/create-lazy-loader.cjs +78 -0
- package/dist/lazy/create-lazy-loader.cjs.map +1 -0
- package/dist/lazy/create-lazy-loader.d.cts +19 -0
- package/dist/lazy/create-lazy-loader.d.cts.map +1 -0
- package/dist/lazy/create-lazy-loader.d.mts +19 -0
- package/dist/lazy/create-lazy-loader.d.mts.map +1 -0
- package/dist/lazy/create-lazy-loader.mjs +78 -0
- package/dist/lazy/create-lazy-loader.mjs.map +1 -0
- package/dist/lazy/create-render-state.cjs +59 -0
- package/dist/lazy/create-render-state.cjs.map +1 -0
- package/dist/lazy/create-render-state.d.cts +33 -0
- package/dist/lazy/create-render-state.d.cts.map +1 -0
- package/dist/lazy/create-render-state.d.mts +33 -0
- package/dist/lazy/create-render-state.d.mts.map +1 -0
- package/dist/lazy/create-render-state.mjs +59 -0
- package/dist/lazy/create-render-state.mjs.map +1 -0
- package/dist/lazy/fallback-props.cjs +9 -0
- package/dist/lazy/fallback-props.cjs.map +1 -0
- package/dist/lazy/fallback-props.mjs +9 -0
- package/dist/lazy/fallback-props.mjs.map +1 -0
- package/dist/lazy/inspection.cjs +51 -0
- package/dist/lazy/inspection.cjs.map +1 -0
- package/dist/lazy/inspection.d.cts +28 -0
- package/dist/lazy/inspection.d.cts.map +1 -0
- package/dist/lazy/inspection.d.mts +28 -0
- package/dist/lazy/inspection.d.mts.map +1 -0
- package/dist/lazy/inspection.mjs +50 -0
- package/dist/lazy/inspection.mjs.map +1 -0
- package/dist/lazy/lazy-boundary.cjs +63 -0
- package/dist/lazy/lazy-boundary.cjs.map +1 -0
- package/dist/lazy/lazy-boundary.mjs +63 -0
- package/dist/lazy/lazy-boundary.mjs.map +1 -0
- package/dist/lazy/scoped-content.cjs +87 -0
- package/dist/lazy/scoped-content.cjs.map +1 -0
- package/dist/lazy/scoped-content.d.cts +19 -0
- package/dist/lazy/scoped-content.d.cts.map +1 -0
- package/dist/lazy/scoped-content.d.mts +19 -0
- package/dist/lazy/scoped-content.d.mts.map +1 -0
- package/dist/lazy/scoped-content.mjs +86 -0
- package/dist/lazy/scoped-content.mjs.map +1 -0
- package/dist/lazy/types.cjs +10 -0
- package/dist/lazy/types.cjs.map +1 -0
- package/dist/lazy/types.d.cts +40 -0
- package/dist/lazy/types.d.cts.map +1 -0
- package/dist/lazy/types.d.mts +40 -0
- package/dist/lazy/types.d.mts.map +1 -0
- package/dist/lazy/types.mjs +8 -0
- package/dist/lazy/types.mjs.map +1 -0
- package/dist/props.cjs +4 -2
- package/dist/props.cjs.map +1 -1
- package/dist/props.d.cts +6 -50
- package/dist/props.d.cts.map +1 -1
- package/dist/props.d.mts +6 -50
- package/dist/props.d.mts.map +1 -1
- package/dist/props.mjs +5 -2
- package/dist/props.mjs.map +1 -1
- package/dist/resource.cjs.map +1 -1
- package/dist/resource.d.cts +1 -1
- package/dist/resource.d.cts.map +1 -1
- package/dist/resource.d.mts +1 -1
- package/dist/resource.d.mts.map +1 -1
- package/dist/resource.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createInspectionStore, inspectionId, serializeInspectionError } from "@jfdevelops/react-layout-devtools-core";
|
|
2
|
+
|
|
3
|
+
//#region src/lazy/inspection.ts
|
|
4
|
+
/** Register a declaration before its import runs, retaining one node on retry. */
|
|
5
|
+
function inspectLazy(label, store = createInspectionStore(), parent) {
|
|
6
|
+
const id = inspectionId("lazy");
|
|
7
|
+
function update(status, error) {
|
|
8
|
+
store.node({
|
|
9
|
+
id,
|
|
10
|
+
kind: "lazy",
|
|
11
|
+
label,
|
|
12
|
+
status,
|
|
13
|
+
unresolved: status !== "resolved",
|
|
14
|
+
error: error && serializeInspectionError(error)
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
update("unresolved");
|
|
18
|
+
if (parent) store.edge(parent, id, "declares");
|
|
19
|
+
return {
|
|
20
|
+
id,
|
|
21
|
+
store,
|
|
22
|
+
hooks: {
|
|
23
|
+
onLoadStart: () => update("loading"),
|
|
24
|
+
onLoadSuccess: () => update("resolved"),
|
|
25
|
+
onLoadError: (error) => update("error", error),
|
|
26
|
+
onMount: () => store.mount(id)
|
|
27
|
+
},
|
|
28
|
+
setLabel(value) {
|
|
29
|
+
label = value;
|
|
30
|
+
update("unresolved");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function withLazyHandle(target, handle) {
|
|
35
|
+
Object.defineProperties(target, {
|
|
36
|
+
preload: {
|
|
37
|
+
value: handle.preload,
|
|
38
|
+
enumerable: false
|
|
39
|
+
},
|
|
40
|
+
status: {
|
|
41
|
+
get: () => handle.status,
|
|
42
|
+
enumerable: false
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return target;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { inspectLazy, withLazyHandle };
|
|
50
|
+
//# sourceMappingURL=inspection.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspection.mjs","names":[],"sources":["../../src/lazy/inspection.ts"],"sourcesContent":["import {\n createInspectionStore,\n inspectionId,\n serializeInspectionError,\n type InspectionStore,\n type LoadStatus,\n} from '@jfdevelops/react-layout-devtools-core';\nimport type { LazyResourceLoadHooks } from './create-lazy-loader';\nimport type { LazyResourceError } from '../errors/lazy-resource-error';\n\n/** Register a declaration before its import runs, retaining one node on retry. */\nexport function inspectLazy(\n label: string,\n store: InspectionStore = createInspectionStore(),\n parent?: string,\n) {\n const id = inspectionId('lazy');\n function update(status: LoadStatus, error?: LazyResourceError) {\n store.node({\n id,\n kind: 'lazy',\n label,\n status,\n unresolved: status !== 'resolved',\n error: error && serializeInspectionError(error),\n });\n }\n update('unresolved');\n if (parent) store.edge(parent, id, 'declares');\n const hooks: LazyResourceLoadHooks = {\n onLoadStart: () => update('loading'),\n onLoadSuccess: () => update('resolved'),\n onLoadError: (error) => update('error', error),\n onMount: () => store.mount(id),\n };\n return {\n id,\n store,\n hooks,\n setLabel(value: string) {\n label = value;\n update('unresolved');\n },\n };\n}\n\nexport function withLazyHandle<T extends object>(\n target: T,\n handle: import('./types').LazyHandle,\n): T & import('./types').LazyHandle {\n Object.defineProperties(target, {\n preload: { value: handle.preload, enumerable: false },\n status: { get: () => handle.status, enumerable: false },\n });\n return target as T & import('./types').LazyHandle;\n}\n"],"mappings":";;;;AAWA,SAAgB,YACd,OACA,QAAyB,sBAAsB,GAC/C,QACA;CACA,MAAM,KAAK,aAAa,MAAM;CAC9B,SAAS,OAAO,QAAoB,OAA2B;EAC7D,MAAM,KAAK;GACT;GACA,MAAM;GACN;GACA;GACA,YAAY,WAAW;GACvB,OAAO,SAAS,yBAAyB,KAAK;EAChD,CAAC;CACH;CACA,OAAO,YAAY;CACnB,IAAI,QAAQ,MAAM,KAAK,QAAQ,IAAI,UAAU;CAO7C,OAAO;EACL;EACA;EACA;GARA,mBAAmB,OAAO,SAAS;GACnC,qBAAqB,OAAO,UAAU;GACtC,cAAc,UAAU,OAAO,SAAS,KAAK;GAC7C,eAAe,MAAM,MAAM,EAAE;EAKzB;EACJ,SAAS,OAAe;GACtB,QAAQ;GACR,OAAO,YAAY;EACrB;CACF;AACF;AAEA,SAAgB,eACd,QACA,QACkC;CAClC,OAAO,iBAAiB,QAAQ;EAC9B,SAAS;GAAE,OAAO,OAAO;GAAS,YAAY;EAAM;EACpD,QAAQ;GAAE,WAAW,OAAO;GAAQ,YAAY;EAAM;CACxD,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const require_render_state_context = require('../create-config/render-state-context.cjs');
|
|
2
|
+
const require_lazy_resource_error = require('../errors/lazy-resource-error.cjs');
|
|
3
|
+
let react = require("react");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
|
|
6
|
+
//#region src/lazy/lazy-boundary.tsx
|
|
7
|
+
var LazyErrorBoundary = class extends react.Component {
|
|
8
|
+
state = {
|
|
9
|
+
failed: false,
|
|
10
|
+
error: void 0
|
|
11
|
+
};
|
|
12
|
+
static getDerivedStateFromError(error) {
|
|
13
|
+
return {
|
|
14
|
+
failed: true,
|
|
15
|
+
error
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
retry = () => {
|
|
19
|
+
this.props.onRetry();
|
|
20
|
+
this.setState({
|
|
21
|
+
failed: false,
|
|
22
|
+
error: void 0
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
render() {
|
|
26
|
+
if (!this.state.failed) return this.props.children;
|
|
27
|
+
const { ErrorComponent, resource } = this.props;
|
|
28
|
+
if (!require_lazy_resource_error.isLazyResourceError(this.state.error) || !ErrorComponent) throw this.state.error;
|
|
29
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_render_state_context.RenderStateFallback, {
|
|
30
|
+
state: "Error",
|
|
31
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, {
|
|
32
|
+
error: this.state.error,
|
|
33
|
+
retry: this.retry,
|
|
34
|
+
resource
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/** Shared loading, typed error handling and retry for all lazy components. */
|
|
40
|
+
function LazyBoundary({ loader, member, resource, fallback, ErrorComponent, componentProps, onMount, map }) {
|
|
41
|
+
const [, rerender] = (0, react.useReducer)((value) => value + 1, 0);
|
|
42
|
+
(0, react.useEffect)(() => onMount?.(), [onMount]);
|
|
43
|
+
const Current = loader.component(member, map);
|
|
44
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LazyErrorBoundary, {
|
|
45
|
+
resource,
|
|
46
|
+
ErrorComponent,
|
|
47
|
+
onRetry: () => {
|
|
48
|
+
loader.reset();
|
|
49
|
+
rerender();
|
|
50
|
+
},
|
|
51
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
|
|
52
|
+
fallback: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_render_state_context.RenderStateFallback, {
|
|
53
|
+
state: "Loading",
|
|
54
|
+
children: fallback
|
|
55
|
+
}),
|
|
56
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Current, { ...componentProps })
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.LazyBoundary = LazyBoundary;
|
|
63
|
+
//# sourceMappingURL=lazy-boundary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-boundary.cjs","names":["Component","isLazyResourceError","RenderStateFallback","Suspense"],"sources":["../../src/lazy/lazy-boundary.tsx"],"sourcesContent":["import { RenderStateFallback } from '../create-config/render-state-context';\nimport {\n Component,\n Suspense,\n useEffect,\n useReducer,\n type ReactNode,\n} from 'react';\nimport { isLazyResourceError } from '../errors/lazy-resource-error';\nimport type { LazyResourceErrorComponent } from './types';\nimport type { LazyLoader } from './create-lazy-loader';\n\ntype BoundaryProps = {\n children: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n resource: string;\n onRetry: () => void;\n};\n\nclass LazyErrorBoundary extends Component<\n BoundaryProps,\n { failed: boolean; error?: unknown }\n> {\n state = { failed: false, error: undefined as unknown };\n static getDerivedStateFromError(error: unknown) {\n return { failed: true, error };\n }\n retry = () => {\n this.props.onRetry();\n this.setState({ failed: false, error: undefined });\n };\n render() {\n if (!this.state.failed) return this.props.children;\n const { ErrorComponent, resource } = this.props;\n if (!isLazyResourceError(this.state.error) || !ErrorComponent)\n throw this.state.error;\n return (\n <RenderStateFallback state=\"Error\">\n <ErrorComponent\n error={this.state.error}\n retry={this.retry}\n resource={resource}\n />\n </RenderStateFallback>\n );\n }\n}\n\n/** Shared loading, typed error handling and retry for all lazy components. */\nexport function LazyBoundary({\n loader,\n member,\n resource,\n fallback,\n ErrorComponent,\n componentProps,\n onMount,\n map,\n}: {\n loader: LazyLoader<any>;\n member?: PropertyKey;\n map?: (selected: any) => React.ComponentType<any>;\n resource: string;\n fallback?: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n componentProps: Record<string, unknown>;\n onMount?: () => (() => void) | undefined;\n}) {\n const [, rerender] = useReducer((value) => value + 1, 0);\n useEffect(() => onMount?.(), [onMount]);\n const Current = loader.component(member, map);\n return (\n <LazyErrorBoundary\n resource={resource}\n ErrorComponent={ErrorComponent}\n onRetry={() => {\n loader.reset();\n rerender();\n }}\n >\n <Suspense fallback={\n <RenderStateFallback state=\"Loading\">{fallback}</RenderStateFallback>\n }>\n <Current {...componentProps} />\n </Suspense>\n </LazyErrorBoundary>\n );\n}\n"],"mappings":";;;;;;AAmBA,IAAM,oBAAN,cAAgCA,gBAG9B;CACA,QAAQ;EAAE,QAAQ;EAAO,OAAO;CAAqB;CACrD,OAAO,yBAAyB,OAAgB;EAC9C,OAAO;GAAE,QAAQ;GAAM;EAAM;CAC/B;CACA,cAAc;EACZ,KAAK,MAAM,QAAQ;EACnB,KAAK,SAAS;GAAE,QAAQ;GAAO,OAAO;EAAU,CAAC;CACnD;CACA,SAAS;EACP,IAAI,CAAC,KAAK,MAAM,QAAQ,OAAO,KAAK,MAAM;EAC1C,MAAM,EAAE,gBAAgB,aAAa,KAAK;EAC1C,IAAI,CAACC,gDAAoB,KAAK,MAAM,KAAK,KAAK,CAAC,gBAC7C,MAAM,KAAK,MAAM;EACnB,OACE,2CAACC,kDAAD;GAAqB,OAAM;aACzB,2CAAC,gBAAD;IACE,OAAO,KAAK,MAAM;IAClB,OAAO,KAAK;IACF;GACX;EACkB;CAEzB;AACF;;AAGA,SAAgB,aAAa,EAC3B,QACA,QACA,UACA,UACA,gBACA,gBACA,SACA,OAUC;CACD,MAAM,GAAG,mCAAwB,UAAU,QAAQ,GAAG,CAAC;CACvD,2BAAgB,UAAU,GAAG,CAAC,OAAO,CAAC;CACtC,MAAM,UAAU,OAAO,UAAU,QAAQ,GAAG;CAC5C,OACE,2CAAC,mBAAD;EACY;EACM;EAChB,eAAe;GACb,OAAO,MAAM;GACb,SAAS;EACX;YAEA,2CAACC,gBAAD;GAAU,UACR,2CAACD,kDAAD;IAAqB,OAAM;cAAW;GAA8B;aAEpE,2CAAC,SAAD,EAAS,GAAI,eAAiB;EACtB;CACO;AAEvB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { RenderStateFallback } from "../create-config/render-state-context.mjs";
|
|
2
|
+
import { isLazyResourceError } from "../errors/lazy-resource-error.mjs";
|
|
3
|
+
import { Component, Suspense, useEffect, useReducer } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/lazy/lazy-boundary.tsx
|
|
7
|
+
var LazyErrorBoundary = class extends Component {
|
|
8
|
+
state = {
|
|
9
|
+
failed: false,
|
|
10
|
+
error: void 0
|
|
11
|
+
};
|
|
12
|
+
static getDerivedStateFromError(error) {
|
|
13
|
+
return {
|
|
14
|
+
failed: true,
|
|
15
|
+
error
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
retry = () => {
|
|
19
|
+
this.props.onRetry();
|
|
20
|
+
this.setState({
|
|
21
|
+
failed: false,
|
|
22
|
+
error: void 0
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
render() {
|
|
26
|
+
if (!this.state.failed) return this.props.children;
|
|
27
|
+
const { ErrorComponent, resource } = this.props;
|
|
28
|
+
if (!isLazyResourceError(this.state.error) || !ErrorComponent) throw this.state.error;
|
|
29
|
+
return /* @__PURE__ */ jsx(RenderStateFallback, {
|
|
30
|
+
state: "Error",
|
|
31
|
+
children: /* @__PURE__ */ jsx(ErrorComponent, {
|
|
32
|
+
error: this.state.error,
|
|
33
|
+
retry: this.retry,
|
|
34
|
+
resource
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/** Shared loading, typed error handling and retry for all lazy components. */
|
|
40
|
+
function LazyBoundary({ loader, member, resource, fallback, ErrorComponent, componentProps, onMount, map }) {
|
|
41
|
+
const [, rerender] = useReducer((value) => value + 1, 0);
|
|
42
|
+
useEffect(() => onMount?.(), [onMount]);
|
|
43
|
+
const Current = loader.component(member, map);
|
|
44
|
+
return /* @__PURE__ */ jsx(LazyErrorBoundary, {
|
|
45
|
+
resource,
|
|
46
|
+
ErrorComponent,
|
|
47
|
+
onRetry: () => {
|
|
48
|
+
loader.reset();
|
|
49
|
+
rerender();
|
|
50
|
+
},
|
|
51
|
+
children: /* @__PURE__ */ jsx(Suspense, {
|
|
52
|
+
fallback: /* @__PURE__ */ jsx(RenderStateFallback, {
|
|
53
|
+
state: "Loading",
|
|
54
|
+
children: fallback
|
|
55
|
+
}),
|
|
56
|
+
children: /* @__PURE__ */ jsx(Current, { ...componentProps })
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { LazyBoundary };
|
|
63
|
+
//# sourceMappingURL=lazy-boundary.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-boundary.mjs","names":[],"sources":["../../src/lazy/lazy-boundary.tsx"],"sourcesContent":["import { RenderStateFallback } from '../create-config/render-state-context';\nimport {\n Component,\n Suspense,\n useEffect,\n useReducer,\n type ReactNode,\n} from 'react';\nimport { isLazyResourceError } from '../errors/lazy-resource-error';\nimport type { LazyResourceErrorComponent } from './types';\nimport type { LazyLoader } from './create-lazy-loader';\n\ntype BoundaryProps = {\n children: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n resource: string;\n onRetry: () => void;\n};\n\nclass LazyErrorBoundary extends Component<\n BoundaryProps,\n { failed: boolean; error?: unknown }\n> {\n state = { failed: false, error: undefined as unknown };\n static getDerivedStateFromError(error: unknown) {\n return { failed: true, error };\n }\n retry = () => {\n this.props.onRetry();\n this.setState({ failed: false, error: undefined });\n };\n render() {\n if (!this.state.failed) return this.props.children;\n const { ErrorComponent, resource } = this.props;\n if (!isLazyResourceError(this.state.error) || !ErrorComponent)\n throw this.state.error;\n return (\n <RenderStateFallback state=\"Error\">\n <ErrorComponent\n error={this.state.error}\n retry={this.retry}\n resource={resource}\n />\n </RenderStateFallback>\n );\n }\n}\n\n/** Shared loading, typed error handling and retry for all lazy components. */\nexport function LazyBoundary({\n loader,\n member,\n resource,\n fallback,\n ErrorComponent,\n componentProps,\n onMount,\n map,\n}: {\n loader: LazyLoader<any>;\n member?: PropertyKey;\n map?: (selected: any) => React.ComponentType<any>;\n resource: string;\n fallback?: ReactNode;\n ErrorComponent?: LazyResourceErrorComponent;\n componentProps: Record<string, unknown>;\n onMount?: () => (() => void) | undefined;\n}) {\n const [, rerender] = useReducer((value) => value + 1, 0);\n useEffect(() => onMount?.(), [onMount]);\n const Current = loader.component(member, map);\n return (\n <LazyErrorBoundary\n resource={resource}\n ErrorComponent={ErrorComponent}\n onRetry={() => {\n loader.reset();\n rerender();\n }}\n >\n <Suspense fallback={\n <RenderStateFallback state=\"Loading\">{fallback}</RenderStateFallback>\n }>\n <Current {...componentProps} />\n </Suspense>\n </LazyErrorBoundary>\n );\n}\n"],"mappings":";;;;;;AAmBA,IAAM,oBAAN,cAAgC,UAG9B;CACA,QAAQ;EAAE,QAAQ;EAAO,OAAO;CAAqB;CACrD,OAAO,yBAAyB,OAAgB;EAC9C,OAAO;GAAE,QAAQ;GAAM;EAAM;CAC/B;CACA,cAAc;EACZ,KAAK,MAAM,QAAQ;EACnB,KAAK,SAAS;GAAE,QAAQ;GAAO,OAAO;EAAU,CAAC;CACnD;CACA,SAAS;EACP,IAAI,CAAC,KAAK,MAAM,QAAQ,OAAO,KAAK,MAAM;EAC1C,MAAM,EAAE,gBAAgB,aAAa,KAAK;EAC1C,IAAI,CAAC,oBAAoB,KAAK,MAAM,KAAK,KAAK,CAAC,gBAC7C,MAAM,KAAK,MAAM;EACnB,OACE,oBAAC,qBAAD;GAAqB,OAAM;aACzB,oBAAC,gBAAD;IACE,OAAO,KAAK,MAAM;IAClB,OAAO,KAAK;IACF;GACX;EACkB;CAEzB;AACF;;AAGA,SAAgB,aAAa,EAC3B,QACA,QACA,UACA,UACA,gBACA,gBACA,SACA,OAUC;CACD,MAAM,GAAG,YAAY,YAAY,UAAU,QAAQ,GAAG,CAAC;CACvD,gBAAgB,UAAU,GAAG,CAAC,OAAO,CAAC;CACtC,MAAM,UAAU,OAAO,UAAU,QAAQ,GAAG;CAC5C,OACE,oBAAC,mBAAD;EACY;EACM;EAChB,eAAe;GACb,OAAO,MAAM;GACb,SAAS;EACX;YAEA,oBAAC,UAAD;GAAU,UACR,oBAAC,qBAAD;IAAqB,OAAM;cAAW;GAA8B;aAEpE,oBAAC,SAAD,EAAS,GAAI,eAAiB;EACtB;CACO;AAEvB"}
|
|
@@ -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\ntype ErrorHandlerContext<Context> = [Context] extends [never]\n ? []\n : [context: Context];\n\nexport type LazyErrorHandlers<\n Resource,\n Custom extends object = {},\n Context = never,\n> = {\n [Code in LazyResourceError['code']]?: (\n props: Custom &\n Omit<LazyResourceErrorProps<Resource>, 'error'> & {\n error: LazyResourceErrorMap[Code];\n },\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode;\n} & {\n fallback?: (\n props: Custom & LazyResourceErrorProps<Resource>,\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode;\n};\n\nexport type CreateLazyErrorComponent<Resource, Context = never> = {\n <Custom extends object = {}>(\n render: (\n props: Custom & LazyResourceErrorProps<Resource>,\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n <Custom extends object = {}>(\n handlers: LazyErrorHandlers<Resource, Custom, Context>,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n};\n\n/** Internal factory defaults propagated to layouts without publishing metadata. */\nexport const lazyDefaultsSymbol = Symbol('lazyDefaults');\n\nexport const lazyStatesSymbol = Symbol('lazyStates');\n"],"mappings":";;;AA2EA,MAAa,qBAAqB,OAAO,cAAc;AAEvD,MAAa,mBAAmB,OAAO,YAAY"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 ErrorHandlerContext<Context> = [Context] extends [never] ? [] : [context: Context];
|
|
29
|
+
type LazyErrorHandlers<Resource, Custom extends object = {}, Context = never> = { [Code in LazyResourceError['code']]?: (props: Custom & Omit<LazyResourceErrorProps<Resource>, 'error'> & {
|
|
30
|
+
error: LazyResourceErrorMap[Code];
|
|
31
|
+
}, ...context: ErrorHandlerContext<Context>) => ReactNode } & {
|
|
32
|
+
fallback?: (props: Custom & LazyResourceErrorProps<Resource>, ...context: ErrorHandlerContext<Context>) => ReactNode;
|
|
33
|
+
};
|
|
34
|
+
type CreateLazyErrorComponent<Resource, Context = never> = {
|
|
35
|
+
<Custom extends object = {}>(render: (props: Custom & LazyResourceErrorProps<Resource>, ...context: ErrorHandlerContext<Context>) => ReactNode): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
36
|
+
<Custom extends object = {}>(handlers: LazyErrorHandlers<Resource, Custom, Context>): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { CreateLazyErrorComponent, LazyErrorHandlers, LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceErrorProps, LazyResourceLoadingComponent, LazyResourceStates, type LoadStatus$1 as LoadStatus };
|
|
40
|
+
//# 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,KAGpC,mBAAA,aAAgC,OAAA,0BAEhC,OAAA,EAAS,OAAO;AAAA,KAET,iBAAA,qEAKD,iBAAA,aACP,KAAA,EAAO,MAAA,GACL,IAAA,CAAK,sBAAA,CAAuB,QAAA;EAC1B,KAAA,EAAO,oBAAA,CAAqB,IAAA;AAAA,MAE7B,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA;EAEL,QAAA,IACE,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MACpC,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA;AAAA;AAAA,KAGK,wBAAA;EAAA,6BAER,MAAA,GACE,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MACpC,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA,GACJ,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;EAAA,6BAE/C,QAAA,EAAU,iBAAA,CAAkB,QAAA,EAAU,MAAA,EAAQ,OAAA,IAC7C,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;AAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 ErrorHandlerContext<Context> = [Context] extends [never] ? [] : [context: Context];
|
|
29
|
+
type LazyErrorHandlers<Resource, Custom extends object = {}, Context = never> = { [Code in LazyResourceError['code']]?: (props: Custom & Omit<LazyResourceErrorProps<Resource>, 'error'> & {
|
|
30
|
+
error: LazyResourceErrorMap[Code];
|
|
31
|
+
}, ...context: ErrorHandlerContext<Context>) => ReactNode } & {
|
|
32
|
+
fallback?: (props: Custom & LazyResourceErrorProps<Resource>, ...context: ErrorHandlerContext<Context>) => ReactNode;
|
|
33
|
+
};
|
|
34
|
+
type CreateLazyErrorComponent<Resource, Context = never> = {
|
|
35
|
+
<Custom extends object = {}>(render: (props: Custom & LazyResourceErrorProps<Resource>, ...context: ErrorHandlerContext<Context>) => ReactNode): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
36
|
+
<Custom extends object = {}>(handlers: LazyErrorHandlers<Resource, Custom, Context>): ComponentType<Custom & LazyResourceErrorProps<Resource>>;
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { CreateLazyErrorComponent, LazyErrorHandlers, LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceErrorProps, LazyResourceLoadingComponent, LazyResourceStates, type LoadStatus$1 as LoadStatus };
|
|
40
|
+
//# 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,KAGpC,mBAAA,aAAgC,OAAA,0BAEhC,OAAA,EAAS,OAAO;AAAA,KAET,iBAAA,qEAKD,iBAAA,aACP,KAAA,EAAO,MAAA,GACL,IAAA,CAAK,sBAAA,CAAuB,QAAA;EAC1B,KAAA,EAAO,oBAAA,CAAqB,IAAA;AAAA,MAE7B,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA;EAEL,QAAA,IACE,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MACpC,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA;AAAA;AAAA,KAGK,wBAAA;EAAA,6BAER,MAAA,GACE,KAAA,EAAO,MAAA,GAAS,sBAAA,CAAuB,QAAA,MACpC,OAAA,EAAS,mBAAA,CAAoB,OAAA,MAC7B,SAAA,GACJ,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;EAAA,6BAE/C,QAAA,EAAU,iBAAA,CAAkB,QAAA,EAAU,MAAA,EAAQ,OAAA,IAC7C,aAAA,CAAc,MAAA,GAAS,sBAAA,CAAuB,QAAA;AAAA"}
|
|
@@ -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\ntype ErrorHandlerContext<Context> = [Context] extends [never]\n ? []\n : [context: Context];\n\nexport type LazyErrorHandlers<\n Resource,\n Custom extends object = {},\n Context = never,\n> = {\n [Code in LazyResourceError['code']]?: (\n props: Custom &\n Omit<LazyResourceErrorProps<Resource>, 'error'> & {\n error: LazyResourceErrorMap[Code];\n },\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode;\n} & {\n fallback?: (\n props: Custom & LazyResourceErrorProps<Resource>,\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode;\n};\n\nexport type CreateLazyErrorComponent<Resource, Context = never> = {\n <Custom extends object = {}>(\n render: (\n props: Custom & LazyResourceErrorProps<Resource>,\n ...context: ErrorHandlerContext<Context>\n ) => ReactNode,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n <Custom extends object = {}>(\n handlers: LazyErrorHandlers<Resource, Custom, Context>,\n ): ComponentType<Custom & LazyResourceErrorProps<Resource>>;\n};\n\n/** Internal factory defaults propagated to layouts without publishing metadata. */\nexport const lazyDefaultsSymbol = Symbol('lazyDefaults');\n\nexport const lazyStatesSymbol = Symbol('lazyStates');\n"],"mappings":";;AA2EA,MAAa,qBAAqB,OAAO,cAAc;AAEvD,MAAa,mBAAmB,OAAO,YAAY"}
|
package/dist/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
|
-
|
|
6
|
-
const
|
|
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",
|