@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,78 @@
|
|
|
1
|
+
const require_resource_state_error = require('../errors/resource-state-error.cjs');
|
|
2
|
+
const require_lazy_resource_error = require('../errors/lazy-resource-error.cjs');
|
|
3
|
+
let react = require("react");
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-lazy-loader.ts
|
|
6
|
+
/** A single import cache and lifecycle shared by every lazy entry point. */
|
|
7
|
+
function createLazyLoader(options) {
|
|
8
|
+
let promise;
|
|
9
|
+
let preloadPromise;
|
|
10
|
+
let status = "unresolved";
|
|
11
|
+
const components = /* @__PURE__ */ new Map();
|
|
12
|
+
let generation = 0;
|
|
13
|
+
function get() {
|
|
14
|
+
if (promise) return promise;
|
|
15
|
+
const attempt = generation;
|
|
16
|
+
status = "loading";
|
|
17
|
+
options.hooks?.onLoadStart?.();
|
|
18
|
+
promise = Promise.resolve().then(options.load).catch((cause) => {
|
|
19
|
+
if (require_lazy_resource_error.isLazyResourceError(cause)) throw cause;
|
|
20
|
+
if (process.env.NODE_ENV !== "production") console.error(`[react-layout] lazy "${options.label}" failed to load`, cause);
|
|
21
|
+
throw new require_resource_state_error.ResourceModuleLoadError(options.label, cause);
|
|
22
|
+
}).then(options.select).then((selected) => {
|
|
23
|
+
if (attempt === generation) {
|
|
24
|
+
status = "resolved";
|
|
25
|
+
options.hooks?.onLoadSuccess?.();
|
|
26
|
+
}
|
|
27
|
+
return selected;
|
|
28
|
+
}, (error) => {
|
|
29
|
+
if (attempt === generation) {
|
|
30
|
+
status = "error";
|
|
31
|
+
options.hooks?.onLoadError?.(error);
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
});
|
|
35
|
+
return promise;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
get,
|
|
39
|
+
get status() {
|
|
40
|
+
return status;
|
|
41
|
+
},
|
|
42
|
+
preload: () => preloadPromise ??= get().then(() => void 0),
|
|
43
|
+
reset() {
|
|
44
|
+
generation++;
|
|
45
|
+
promise = void 0;
|
|
46
|
+
preloadPromise = void 0;
|
|
47
|
+
components.clear();
|
|
48
|
+
status = "unresolved";
|
|
49
|
+
},
|
|
50
|
+
component(member, map) {
|
|
51
|
+
const key = map ?? member;
|
|
52
|
+
let component = components.get(key);
|
|
53
|
+
if (!component) {
|
|
54
|
+
component = (0, react.lazy)(async () => {
|
|
55
|
+
const attempt = generation;
|
|
56
|
+
const selected = await get();
|
|
57
|
+
try {
|
|
58
|
+
const candidate = map ? map(selected) : member === void 0 ? selected : selected[member];
|
|
59
|
+
if (typeof candidate !== "function") throw new require_lazy_resource_error.LazyResourceStateNotFoundError(options.label, String(member));
|
|
60
|
+
return { default: candidate };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (attempt === generation && require_lazy_resource_error.isLazyResourceError(error)) {
|
|
63
|
+
status = "error";
|
|
64
|
+
options.hooks?.onLoadError?.(error);
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
components.set(key, component);
|
|
70
|
+
}
|
|
71
|
+
return component;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
exports.createLazyLoader = createLazyLoader;
|
|
78
|
+
//# sourceMappingURL=create-lazy-loader.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-lazy-loader.cjs","names":["isLazyResourceError","ResourceModuleLoadError","LazyResourceStateNotFoundError"],"sources":["../../src/lazy/create-lazy-loader.ts"],"sourcesContent":["import { lazy, type ComponentType } from 'react';\nimport { ResourceModuleLoadError } from '../errors/resource-state-error';\nimport {\n LazyResourceStateNotFoundError,\n isLazyResourceError,\n type LazyResourceError,\n} from '../errors/lazy-resource-error';\nimport type { LazyHandle, LoadStatus } from './types';\n\nexport type LazyResourceLoadHooks = {\n onLoadStart?: () => void;\n onLoadSuccess?: () => void;\n onLoadError?: (error: LazyResourceError) => void;\n onMount?: () => (() => void) | undefined;\n};\n\nexport type LazyLoader<Selected> = LazyHandle & {\n get(): Promise<Selected>;\n reset(): void;\n component(\n member?: PropertyKey,\n map?: (selected: Selected) => ComponentType<any>,\n ): ComponentType<any>;\n};\n\n/** A single import cache and lifecycle shared by every lazy entry point. */\nexport function createLazyLoader<Module, Selected>(options: {\n load: () => Promise<Module>;\n select: (module: Module) => Selected | Promise<Selected>;\n label: string;\n hooks?: LazyResourceLoadHooks;\n}): LazyLoader<Selected> {\n let promise: Promise<Selected> | undefined;\n let preloadPromise: Promise<void> | undefined;\n let status: LoadStatus = 'unresolved';\n const components = new Map<unknown, ComponentType<any>>();\n let generation = 0;\n\n function get() {\n if (promise) return promise;\n const attempt = generation;\n status = 'loading';\n options.hooks?.onLoadStart?.();\n promise = Promise.resolve()\n .then(options.load)\n .catch((cause: unknown) => {\n if (isLazyResourceError(cause)) throw cause;\n if (process.env.NODE_ENV !== 'production') {\n console.error(\n `[react-layout] lazy \"${options.label}\" failed to load`,\n cause,\n );\n }\n throw new ResourceModuleLoadError(options.label, cause);\n })\n .then(options.select)\n .then(\n (selected) => {\n if (attempt === generation) {\n status = 'resolved';\n options.hooks?.onLoadSuccess?.();\n }\n return selected;\n },\n (error: LazyResourceError) => {\n if (attempt === generation) {\n status = 'error';\n options.hooks?.onLoadError?.(error);\n }\n throw error;\n },\n );\n return promise;\n }\n\n return {\n get,\n get status() {\n return status;\n },\n preload: () => (preloadPromise ??= get().then(() => undefined)),\n reset() {\n generation++;\n promise = undefined;\n preloadPromise = undefined;\n components.clear();\n status = 'unresolved';\n },\n component(member, map) {\n const key = map ?? member;\n let component = components.get(key);\n if (!component) {\n component = lazy(async () => {\n const attempt = generation;\n const selected = await get();\n try {\n const candidate = map\n ? map(selected)\n : member === undefined\n ? selected\n : (selected as Record<PropertyKey, unknown>)[member];\n if (typeof candidate !== 'function') {\n throw new LazyResourceStateNotFoundError(\n options.label,\n String(member),\n );\n }\n return { default: candidate as ComponentType<any> };\n } catch (error) {\n if (attempt === generation && isLazyResourceError(error)) {\n status = 'error';\n options.hooks?.onLoadError?.(error);\n }\n throw error;\n }\n });\n components.set(key, component);\n }\n return component;\n },\n };\n}\n"],"mappings":";;;;;;AA0BA,SAAgB,iBAAmC,SAK1B;CACvB,IAAI;CACJ,IAAI;CACJ,IAAI,SAAqB;CACzB,MAAM,6BAAa,IAAI,IAAiC;CACxD,IAAI,aAAa;CAEjB,SAAS,MAAM;EACb,IAAI,SAAS,OAAO;EACpB,MAAM,UAAU;EAChB,SAAS;EACT,QAAQ,OAAO,cAAc;EAC7B,UAAU,QAAQ,QAAQ,EACvB,KAAK,QAAQ,IAAI,EACjB,OAAO,UAAmB;GACzB,IAAIA,gDAAoB,KAAK,GAAG,MAAM;GACtC,IAAI,QAAQ,IAAI,aAAa,cAC3B,QAAQ,MACN,wBAAwB,QAAQ,MAAM,mBACtC,KACF;GAEF,MAAM,IAAIC,qDAAwB,QAAQ,OAAO,KAAK;EACxD,CAAC,EACA,KAAK,QAAQ,MAAM,EACnB,MACE,aAAa;GACZ,IAAI,YAAY,YAAY;IAC1B,SAAS;IACT,QAAQ,OAAO,gBAAgB;GACjC;GACA,OAAO;EACT,IACC,UAA6B;GAC5B,IAAI,YAAY,YAAY;IAC1B,SAAS;IACT,QAAQ,OAAO,cAAc,KAAK;GACpC;GACA,MAAM;EACR,CACF;EACF,OAAO;CACT;CAEA,OAAO;EACL;EACA,IAAI,SAAS;GACX,OAAO;EACT;EACA,eAAgB,mBAAmB,IAAI,EAAE,WAAW,MAAS;EAC7D,QAAQ;GACN;GACA,UAAU;GACV,iBAAiB;GACjB,WAAW,MAAM;GACjB,SAAS;EACX;EACA,UAAU,QAAQ,KAAK;GACrB,MAAM,MAAM,OAAO;GACnB,IAAI,YAAY,WAAW,IAAI,GAAG;GAClC,IAAI,CAAC,WAAW;IACd,4BAAiB,YAAY;KAC3B,MAAM,UAAU;KAChB,MAAM,WAAW,MAAM,IAAI;KAC3B,IAAI;MACF,MAAM,YAAY,MACd,IAAI,QAAQ,IACZ,WAAW,SACT,WACC,SAA0C;MACjD,IAAI,OAAO,cAAc,YACvB,MAAM,IAAIC,2DACR,QAAQ,OACR,OAAO,MAAM,CACf;MAEF,OAAO,EAAE,SAAS,UAAgC;KACpD,SAAS,OAAO;MACd,IAAI,YAAY,cAAcF,gDAAoB,KAAK,GAAG;OACxD,SAAS;OACT,QAAQ,OAAO,cAAc,KAAK;MACpC;MACA,MAAM;KACR;IACF,CAAC;IACD,WAAW,IAAI,KAAK,SAAS;GAC/B;GACA,OAAO;EACT;CACF;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LazyResourceError } from "../errors/lazy-resource-error.cjs";
|
|
2
|
+
import { LazyHandle } from "./types.cjs";
|
|
3
|
+
import { ComponentType } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-lazy-loader.d.ts
|
|
6
|
+
type LazyResourceLoadHooks = {
|
|
7
|
+
onLoadStart?: () => void;
|
|
8
|
+
onLoadSuccess?: () => void;
|
|
9
|
+
onLoadError?: (error: LazyResourceError) => void;
|
|
10
|
+
onMount?: () => (() => void) | undefined;
|
|
11
|
+
};
|
|
12
|
+
type LazyLoader<Selected> = LazyHandle & {
|
|
13
|
+
get(): Promise<Selected>;
|
|
14
|
+
reset(): void;
|
|
15
|
+
component(member?: PropertyKey, map?: (selected: Selected) => ComponentType<any>): ComponentType<any>;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { LazyLoader, LazyResourceLoadHooks };
|
|
19
|
+
//# sourceMappingURL=create-lazy-loader.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-lazy-loader.d.cts","names":[],"sources":["../../src/lazy/create-lazy-loader.ts"],"mappings":";;;;;KASY,qBAAA;EACV,WAAA;EACA,aAAA;EACA,WAAA,IAAe,KAAA,EAAO,iBAAiB;EACvC,OAAA;AAAA;AAAA,KAGU,UAAA,aAAuB,UAAA;EACjC,GAAA,IAAO,OAAA,CAAQ,QAAA;EACf,KAAA;EACA,SAAA,CACE,MAAA,GAAS,WAAA,EACT,GAAA,IAAO,QAAA,EAAU,QAAA,KAAa,aAAA,QAC7B,aAAA;AAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LazyResourceError } from "../errors/lazy-resource-error.mjs";
|
|
2
|
+
import { LazyHandle } from "./types.mjs";
|
|
3
|
+
import { ComponentType } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-lazy-loader.d.ts
|
|
6
|
+
type LazyResourceLoadHooks = {
|
|
7
|
+
onLoadStart?: () => void;
|
|
8
|
+
onLoadSuccess?: () => void;
|
|
9
|
+
onLoadError?: (error: LazyResourceError) => void;
|
|
10
|
+
onMount?: () => (() => void) | undefined;
|
|
11
|
+
};
|
|
12
|
+
type LazyLoader<Selected> = LazyHandle & {
|
|
13
|
+
get(): Promise<Selected>;
|
|
14
|
+
reset(): void;
|
|
15
|
+
component(member?: PropertyKey, map?: (selected: Selected) => ComponentType<any>): ComponentType<any>;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { LazyLoader, LazyResourceLoadHooks };
|
|
19
|
+
//# sourceMappingURL=create-lazy-loader.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-lazy-loader.d.mts","names":[],"sources":["../../src/lazy/create-lazy-loader.ts"],"mappings":";;;;;KASY,qBAAA;EACV,WAAA;EACA,aAAA;EACA,WAAA,IAAe,KAAA,EAAO,iBAAiB;EACvC,OAAA;AAAA;AAAA,KAGU,UAAA,aAAuB,UAAA;EACjC,GAAA,IAAO,OAAA,CAAQ,QAAA;EACf,KAAA;EACA,SAAA,CACE,MAAA,GAAS,WAAA,EACT,GAAA,IAAO,QAAA,EAAU,QAAA,KAAa,aAAA,QAC7B,aAAA;AAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ResourceModuleLoadError } from "../errors/resource-state-error.mjs";
|
|
2
|
+
import { LazyResourceStateNotFoundError, isLazyResourceError } from "../errors/lazy-resource-error.mjs";
|
|
3
|
+
import { lazy } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-lazy-loader.ts
|
|
6
|
+
/** A single import cache and lifecycle shared by every lazy entry point. */
|
|
7
|
+
function createLazyLoader(options) {
|
|
8
|
+
let promise;
|
|
9
|
+
let preloadPromise;
|
|
10
|
+
let status = "unresolved";
|
|
11
|
+
const components = /* @__PURE__ */ new Map();
|
|
12
|
+
let generation = 0;
|
|
13
|
+
function get() {
|
|
14
|
+
if (promise) return promise;
|
|
15
|
+
const attempt = generation;
|
|
16
|
+
status = "loading";
|
|
17
|
+
options.hooks?.onLoadStart?.();
|
|
18
|
+
promise = Promise.resolve().then(options.load).catch((cause) => {
|
|
19
|
+
if (isLazyResourceError(cause)) throw cause;
|
|
20
|
+
if (process.env.NODE_ENV !== "production") console.error(`[react-layout] lazy "${options.label}" failed to load`, cause);
|
|
21
|
+
throw new ResourceModuleLoadError(options.label, cause);
|
|
22
|
+
}).then(options.select).then((selected) => {
|
|
23
|
+
if (attempt === generation) {
|
|
24
|
+
status = "resolved";
|
|
25
|
+
options.hooks?.onLoadSuccess?.();
|
|
26
|
+
}
|
|
27
|
+
return selected;
|
|
28
|
+
}, (error) => {
|
|
29
|
+
if (attempt === generation) {
|
|
30
|
+
status = "error";
|
|
31
|
+
options.hooks?.onLoadError?.(error);
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
});
|
|
35
|
+
return promise;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
get,
|
|
39
|
+
get status() {
|
|
40
|
+
return status;
|
|
41
|
+
},
|
|
42
|
+
preload: () => preloadPromise ??= get().then(() => void 0),
|
|
43
|
+
reset() {
|
|
44
|
+
generation++;
|
|
45
|
+
promise = void 0;
|
|
46
|
+
preloadPromise = void 0;
|
|
47
|
+
components.clear();
|
|
48
|
+
status = "unresolved";
|
|
49
|
+
},
|
|
50
|
+
component(member, map) {
|
|
51
|
+
const key = map ?? member;
|
|
52
|
+
let component = components.get(key);
|
|
53
|
+
if (!component) {
|
|
54
|
+
component = lazy(async () => {
|
|
55
|
+
const attempt = generation;
|
|
56
|
+
const selected = await get();
|
|
57
|
+
try {
|
|
58
|
+
const candidate = map ? map(selected) : member === void 0 ? selected : selected[member];
|
|
59
|
+
if (typeof candidate !== "function") throw new LazyResourceStateNotFoundError(options.label, String(member));
|
|
60
|
+
return { default: candidate };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (attempt === generation && isLazyResourceError(error)) {
|
|
63
|
+
status = "error";
|
|
64
|
+
options.hooks?.onLoadError?.(error);
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
components.set(key, component);
|
|
70
|
+
}
|
|
71
|
+
return component;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { createLazyLoader };
|
|
78
|
+
//# sourceMappingURL=create-lazy-loader.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-lazy-loader.mjs","names":[],"sources":["../../src/lazy/create-lazy-loader.ts"],"sourcesContent":["import { lazy, type ComponentType } from 'react';\nimport { ResourceModuleLoadError } from '../errors/resource-state-error';\nimport {\n LazyResourceStateNotFoundError,\n isLazyResourceError,\n type LazyResourceError,\n} from '../errors/lazy-resource-error';\nimport type { LazyHandle, LoadStatus } from './types';\n\nexport type LazyResourceLoadHooks = {\n onLoadStart?: () => void;\n onLoadSuccess?: () => void;\n onLoadError?: (error: LazyResourceError) => void;\n onMount?: () => (() => void) | undefined;\n};\n\nexport type LazyLoader<Selected> = LazyHandle & {\n get(): Promise<Selected>;\n reset(): void;\n component(\n member?: PropertyKey,\n map?: (selected: Selected) => ComponentType<any>,\n ): ComponentType<any>;\n};\n\n/** A single import cache and lifecycle shared by every lazy entry point. */\nexport function createLazyLoader<Module, Selected>(options: {\n load: () => Promise<Module>;\n select: (module: Module) => Selected | Promise<Selected>;\n label: string;\n hooks?: LazyResourceLoadHooks;\n}): LazyLoader<Selected> {\n let promise: Promise<Selected> | undefined;\n let preloadPromise: Promise<void> | undefined;\n let status: LoadStatus = 'unresolved';\n const components = new Map<unknown, ComponentType<any>>();\n let generation = 0;\n\n function get() {\n if (promise) return promise;\n const attempt = generation;\n status = 'loading';\n options.hooks?.onLoadStart?.();\n promise = Promise.resolve()\n .then(options.load)\n .catch((cause: unknown) => {\n if (isLazyResourceError(cause)) throw cause;\n if (process.env.NODE_ENV !== 'production') {\n console.error(\n `[react-layout] lazy \"${options.label}\" failed to load`,\n cause,\n );\n }\n throw new ResourceModuleLoadError(options.label, cause);\n })\n .then(options.select)\n .then(\n (selected) => {\n if (attempt === generation) {\n status = 'resolved';\n options.hooks?.onLoadSuccess?.();\n }\n return selected;\n },\n (error: LazyResourceError) => {\n if (attempt === generation) {\n status = 'error';\n options.hooks?.onLoadError?.(error);\n }\n throw error;\n },\n );\n return promise;\n }\n\n return {\n get,\n get status() {\n return status;\n },\n preload: () => (preloadPromise ??= get().then(() => undefined)),\n reset() {\n generation++;\n promise = undefined;\n preloadPromise = undefined;\n components.clear();\n status = 'unresolved';\n },\n component(member, map) {\n const key = map ?? member;\n let component = components.get(key);\n if (!component) {\n component = lazy(async () => {\n const attempt = generation;\n const selected = await get();\n try {\n const candidate = map\n ? map(selected)\n : member === undefined\n ? selected\n : (selected as Record<PropertyKey, unknown>)[member];\n if (typeof candidate !== 'function') {\n throw new LazyResourceStateNotFoundError(\n options.label,\n String(member),\n );\n }\n return { default: candidate as ComponentType<any> };\n } catch (error) {\n if (attempt === generation && isLazyResourceError(error)) {\n status = 'error';\n options.hooks?.onLoadError?.(error);\n }\n throw error;\n }\n });\n components.set(key, component);\n }\n return component;\n },\n };\n}\n"],"mappings":";;;;;;AA0BA,SAAgB,iBAAmC,SAK1B;CACvB,IAAI;CACJ,IAAI;CACJ,IAAI,SAAqB;CACzB,MAAM,6BAAa,IAAI,IAAiC;CACxD,IAAI,aAAa;CAEjB,SAAS,MAAM;EACb,IAAI,SAAS,OAAO;EACpB,MAAM,UAAU;EAChB,SAAS;EACT,QAAQ,OAAO,cAAc;EAC7B,UAAU,QAAQ,QAAQ,EACvB,KAAK,QAAQ,IAAI,EACjB,OAAO,UAAmB;GACzB,IAAI,oBAAoB,KAAK,GAAG,MAAM;GACtC,IAAI,QAAQ,IAAI,aAAa,cAC3B,QAAQ,MACN,wBAAwB,QAAQ,MAAM,mBACtC,KACF;GAEF,MAAM,IAAI,wBAAwB,QAAQ,OAAO,KAAK;EACxD,CAAC,EACA,KAAK,QAAQ,MAAM,EACnB,MACE,aAAa;GACZ,IAAI,YAAY,YAAY;IAC1B,SAAS;IACT,QAAQ,OAAO,gBAAgB;GACjC;GACA,OAAO;EACT,IACC,UAA6B;GAC5B,IAAI,YAAY,YAAY;IAC1B,SAAS;IACT,QAAQ,OAAO,cAAc,KAAK;GACpC;GACA,MAAM;EACR,CACF;EACF,OAAO;CACT;CAEA,OAAO;EACL;EACA,IAAI,SAAS;GACX,OAAO;EACT;EACA,eAAgB,mBAAmB,IAAI,EAAE,WAAW,MAAS;EAC7D,QAAQ;GACN;GACA,UAAU;GACV,iBAAiB;GACjB,WAAW,MAAM;GACjB,SAAS;EACX;EACA,UAAU,QAAQ,KAAK;GACrB,MAAM,MAAM,OAAO;GACnB,IAAI,YAAY,WAAW,IAAI,GAAG;GAClC,IAAI,CAAC,WAAW;IACd,YAAY,KAAK,YAAY;KAC3B,MAAM,UAAU;KAChB,MAAM,WAAW,MAAM,IAAI;KAC3B,IAAI;MACF,MAAM,YAAY,MACd,IAAI,QAAQ,IACZ,WAAW,SACT,WACC,SAA0C;MACjD,IAAI,OAAO,cAAc,YACvB,MAAM,IAAI,+BACR,QAAQ,OACR,OAAO,MAAM,CACf;MAEF,OAAO,EAAE,SAAS,UAAgC;KACpD,SAAS,OAAO;MACd,IAAI,YAAY,cAAc,oBAAoB,KAAK,GAAG;OACxD,SAAS;OACT,QAAQ,OAAO,cAAc,KAAK;MACpC;MACA,MAAM;KACR;IACF,CAAC;IACD,WAAW,IAAI,KAAK,SAAS;GAC/B;GACA,OAAO;EACT;CACF;AACF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const require_layout_configuration_error = require('../errors/layout-configuration-error.cjs');
|
|
2
|
+
const require_define_layout = require('../create-config/define-layout.cjs');
|
|
3
|
+
let react = require("react");
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-render-state.tsx
|
|
6
|
+
function createLazyRenderStateBuilder(configuration) {
|
|
7
|
+
function createRenderState(definition) {
|
|
8
|
+
if (definition.state !== "Loading" && definition.state !== "Error") throw new require_layout_configuration_error.LayoutConfigurationError(`Unknown lazy default state "${definition.state}"`);
|
|
9
|
+
const include = Object.fromEntries(Object.entries(definition.props?.include ?? {}).map(([key, behavior]) => [key, behavior === true ? {
|
|
10
|
+
required: true,
|
|
11
|
+
suppliedVia: "component"
|
|
12
|
+
} : behavior]));
|
|
13
|
+
function RenderLazyDefault({ props, context }) {
|
|
14
|
+
if (typeof definition.render === "function") return definition.render(props, context);
|
|
15
|
+
const errorProps = props;
|
|
16
|
+
const handler = definition.render[errorProps.error.code] ?? definition.render.fallback;
|
|
17
|
+
if (!handler) throw errorProps.error;
|
|
18
|
+
return handler(props, context);
|
|
19
|
+
}
|
|
20
|
+
const layout = require_define_layout.defineResourceLayout({
|
|
21
|
+
resources: configuration.resources,
|
|
22
|
+
options: configuration.options,
|
|
23
|
+
layout: { render: {
|
|
24
|
+
default: () => null,
|
|
25
|
+
[definition.state]: {
|
|
26
|
+
composables: configuration.composables,
|
|
27
|
+
props: {
|
|
28
|
+
include,
|
|
29
|
+
custom: definition.props?.custom
|
|
30
|
+
},
|
|
31
|
+
render: (props, context) => (0, react.createElement)(RenderLazyDefault, {
|
|
32
|
+
props,
|
|
33
|
+
context
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
} }
|
|
37
|
+
});
|
|
38
|
+
const components = /* @__PURE__ */ new Map();
|
|
39
|
+
function LazyDefault(props) {
|
|
40
|
+
const resource = props.resource.split(".")[0];
|
|
41
|
+
let Component = components.get(resource);
|
|
42
|
+
if (!Component) {
|
|
43
|
+
Component = layout.createResourceLayout({
|
|
44
|
+
resource,
|
|
45
|
+
name: "LazyDefault",
|
|
46
|
+
namespace: false
|
|
47
|
+
})[definition.state];
|
|
48
|
+
components.set(resource, Component);
|
|
49
|
+
}
|
|
50
|
+
return (0, react.createElement)(Component, props);
|
|
51
|
+
}
|
|
52
|
+
return LazyDefault;
|
|
53
|
+
}
|
|
54
|
+
return createRenderState;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
exports.createLazyRenderStateBuilder = createLazyRenderStateBuilder;
|
|
59
|
+
//# sourceMappingURL=create-render-state.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-render-state.cjs","names":["LayoutConfigurationError","defineResourceLayout"],"sources":["../../src/lazy/create-render-state.tsx"],"sourcesContent":["import { createElement, type ComponentType, type ReactNode } from 'react';\nimport type { ComposableComponents } from '@jfdevelops/react-layout-composables';\nimport { LayoutConfigurationError } from '../errors';\nimport type { ResourceDefinition, ResourcePath } from '../resource';\nimport {\n type ResolvedIncludedComponentProps,\n type IncludedProps,\n type InPropsDefinition,\n type InPropsObject,\n type MergedLayoutInProps,\n} from '../props';\nimport { defineResourceLayout } from '../create-config/define-layout';\nimport type {\n LayoutComposablesDefinition,\n RenderStateContext,\n RenderStateProps,\n OptionalStateChildren,\n} from '../create-config/render-state';\nimport type { ResolveProps } from '@jfdevelops/react-layout-validator';\nimport type {\n LazyResourceErrorProps,\n LazyErrorHandlers,\n CreateLazyErrorComponent,\n} from './types';\n\nexport type LazyDefaultState = 'Loading' | 'Error';\ntype BuiltinProps<\n State extends LazyDefaultState,\n Resource,\n> = State extends 'Error'\n ? LazyResourceErrorProps<Resource>\n : { resource: Resource };\n\n/** Shorthand includes are direct props; explicit supply sources retain their contract. */\ntype LazyDefaultIncludes<Include> = {\n [Key in keyof Include]: Include[Key] extends true\n ? { required: true; suppliedVia: 'component' }\n : Include[Key];\n};\n\ntype LazyRender<State extends LazyDefaultState, Resource, Props, Context> =\n | ((\n props: Props & BuiltinProps<State, Resource>,\n context: Context,\n ) => ReactNode)\n | (State extends 'Error'\n ? LazyErrorHandlers<Resource, Props & object, Context>\n : never);\n\n/** Creates validated, composable-aware fallback components for one factory. */\nexport type CreateLazyRenderState<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n> = <\n const State extends LazyDefaultState,\n const Custom extends InPropsObject = {},\n const Include extends IncludedProps<\n MergedLayoutInProps<Resources, Options, Composables>\n > = {},\n>(definition: {\n state: State;\n props?: { include?: Include; custom?: Custom };\n render: LazyRender<State, ResourcePath<Resources>, RenderStateProps<Resources, Options, Composables, Include, Custom>, RenderStateContext<Composables, Resources, State>>;\n}) => ComponentType<\n OptionalStateChildren<\n ResolveProps<Custom> &\n ResolvedIncludedComponentProps<\n MergedLayoutInProps<Resources, Options, Composables>,\n LazyDefaultIncludes<Include>\n >\n > &\n BuiltinProps<State, ResourcePath<Resources>>\n>;\n\n/** Compatibility helper; custom props keep their existing unchecked contract. */\nexport type CreateBoundLazyErrorComponent<Resource, Context> =\n CreateLazyErrorComponent<Resource, Context>;\n\ntype RuntimeDefinition = {\n state: LazyDefaultState;\n props?: { include?: Record<string, unknown>; custom?: InPropsObject };\n render:\n | ((props: any, context: any) => ReactNode)\n | LazyErrorHandlers<string, object, any>;\n};\n\nexport function createLazyRenderStateBuilder<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n>(configuration: {\n resources: Resources;\n options: Options;\n composables?: LayoutComposablesDefinition<Resources, Composables>;\n}): CreateLazyRenderState<Resources, Options, Composables> {\n function createRenderState(definition: RuntimeDefinition) {\n if (definition.state !== 'Loading' && definition.state !== 'Error') {\n throw new LayoutConfigurationError(\n `Unknown lazy default state \"${definition.state}\"`,\n );\n }\n // Lazy defaults have no create-time configuration call. Included values are\n // supplied by their component caller unless an explicit config source is selected.\n const include = Object.fromEntries(\n Object.entries(definition.props?.include ?? {}).map(([key, behavior]) => [\n key,\n behavior === true\n ? { required: true, suppliedVia: 'component' }\n : behavior,\n ]),\n );\n function RenderLazyDefault({\n props,\n context,\n }: {\n props: any;\n context: any;\n }) {\n if (typeof definition.render === 'function') {\n return definition.render(props, context);\n }\n const errorProps = props as LazyResourceErrorProps;\n const handler =\n definition.render[errorProps.error.code] ?? definition.render.fallback;\n if (!handler) throw errorProps.error;\n return handler(props as never, context);\n }\n const layout = defineResourceLayout({\n resources: configuration.resources,\n options: configuration.options,\n layout: {\n render: {\n default: () => null,\n [definition.state]: {\n composables: configuration.composables,\n props: { include, custom: definition.props?.custom },\n render: (props: any, context: any) =>\n createElement(RenderLazyDefault, { props, context }),\n },\n },\n },\n } as never);\n const components = new Map<string, ComponentType<any>>();\n function LazyDefault(props: { resource: string }) {\n // Nested lazy paths use the factory's top-level resource definitions for\n // option resolution. The callback still receives the complete path.\n const resource = props.resource.split('.')[0]!;\n let Component = components.get(resource);\n if (!Component) {\n const Root = layout.createResourceLayout({\n resource,\n name: 'LazyDefault',\n namespace: false,\n } as never) as unknown as Record<LazyDefaultState, ComponentType<any>>;\n Component = Root[definition.state];\n components.set(resource, Component);\n }\n return createElement(Component, props);\n }\n return LazyDefault;\n }\n return createRenderState as CreateLazyRenderState<\n Resources,\n Options,\n Composables\n >;\n}\n"],"mappings":";;;;;AAuFA,SAAgB,6BAId,eAIyD;CACzD,SAAS,kBAAkB,YAA+B;EACxD,IAAI,WAAW,UAAU,aAAa,WAAW,UAAU,SACzD,MAAM,IAAIA,4DACR,+BAA+B,WAAW,MAAM,EAClD;EAIF,MAAM,UAAU,OAAO,YACrB,OAAO,QAAQ,WAAW,OAAO,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,cAAc,CACvE,KACA,aAAa,OACT;GAAE,UAAU;GAAM,aAAa;EAAY,IAC3C,QACN,CAAC,CACH;EACA,SAAS,kBAAkB,EACzB,OACA,WAIC;GACD,IAAI,OAAO,WAAW,WAAW,YAC/B,OAAO,WAAW,OAAO,OAAO,OAAO;GAEzC,MAAM,aAAa;GACnB,MAAM,UACJ,WAAW,OAAO,WAAW,MAAM,SAAS,WAAW,OAAO;GAChE,IAAI,CAAC,SAAS,MAAM,WAAW;GAC/B,OAAO,QAAQ,OAAgB,OAAO;EACxC;EACA,MAAM,SAASC,2CAAqB;GAClC,WAAW,cAAc;GACzB,SAAS,cAAc;GACvB,QAAQ,EACN,QAAQ;IACN,eAAe;KACd,WAAW,QAAQ;KAClB,aAAa,cAAc;KAC3B,OAAO;MAAE;MAAS,QAAQ,WAAW,OAAO;KAAO;KACnD,SAAS,OAAY,qCACL,mBAAmB;MAAE;MAAO;KAAQ,CAAC;IACvD;GACF,EACF;EACF,CAAU;EACV,MAAM,6BAAa,IAAI,IAAgC;EACvD,SAAS,YAAY,OAA6B;GAGhD,MAAM,WAAW,MAAM,SAAS,MAAM,GAAG,EAAE;GAC3C,IAAI,YAAY,WAAW,IAAI,QAAQ;GACvC,IAAI,CAAC,WAAW;IAMd,YALa,OAAO,qBAAqB;KACvC;KACA,MAAM;KACN,WAAW;IACb,CACe,EAAE,WAAW;IAC5B,WAAW,IAAI,UAAU,SAAS;GACpC;GACA,gCAAqB,WAAW,KAAK;EACvC;EACA,OAAO;CACT;CACA,OAAO;AAKT"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CreateLazyErrorComponent, LazyErrorHandlers, LazyResourceErrorProps } from "./types.cjs";
|
|
2
|
+
import { ResourceDefinition, ResourcePath } from "../resource.cjs";
|
|
3
|
+
import { InPropsDefinition, InPropsObject, IncludedProps, MergedLayoutInProps, ResolvedIncludedComponentProps } from "../props.cjs";
|
|
4
|
+
import { OptionalStateChildren, RenderStateContext, RenderStateProps } from "../create-config/render-state.cjs";
|
|
5
|
+
import { ComposableComponents } from "@jfdevelops/react-layout-composables";
|
|
6
|
+
import { ComponentType, ReactNode } from "react";
|
|
7
|
+
import { ResolveProps } from "@jfdevelops/react-layout-validator";
|
|
8
|
+
|
|
9
|
+
//#region src/lazy/create-render-state.d.ts
|
|
10
|
+
type LazyDefaultState = 'Loading' | 'Error';
|
|
11
|
+
type BuiltinProps<State extends LazyDefaultState, Resource> = State extends 'Error' ? LazyResourceErrorProps<Resource> : {
|
|
12
|
+
resource: Resource;
|
|
13
|
+
};
|
|
14
|
+
/** Shorthand includes are direct props; explicit supply sources retain their contract. */
|
|
15
|
+
type LazyDefaultIncludes<Include> = { [Key in keyof Include]: Include[Key] extends true ? {
|
|
16
|
+
required: true;
|
|
17
|
+
suppliedVia: 'component';
|
|
18
|
+
} : Include[Key] };
|
|
19
|
+
type LazyRender<State extends LazyDefaultState, Resource, Props, Context> = ((props: Props & BuiltinProps<State, Resource>, context: Context) => ReactNode) | (State extends 'Error' ? LazyErrorHandlers<Resource, Props & object, Context> : never);
|
|
20
|
+
/** Creates validated, composable-aware fallback components for one factory. */
|
|
21
|
+
type CreateLazyRenderState<Resources extends ReadonlyArray<ResourceDefinition>, Options extends InPropsDefinition<Resources>, Composables extends ComposableComponents> = <const State extends LazyDefaultState, const Custom extends InPropsObject = {}, const Include extends IncludedProps<MergedLayoutInProps<Resources, Options, Composables>> = {}>(definition: {
|
|
22
|
+
state: State;
|
|
23
|
+
props?: {
|
|
24
|
+
include?: Include;
|
|
25
|
+
custom?: Custom;
|
|
26
|
+
};
|
|
27
|
+
render: LazyRender<State, ResourcePath<Resources>, RenderStateProps<Resources, Options, Composables, Include, Custom>, RenderStateContext<Composables, Resources, State>>;
|
|
28
|
+
}) => ComponentType<OptionalStateChildren<ResolveProps<Custom> & ResolvedIncludedComponentProps<MergedLayoutInProps<Resources, Options, Composables>, LazyDefaultIncludes<Include>>> & BuiltinProps<State, ResourcePath<Resources>>>;
|
|
29
|
+
/** Compatibility helper; custom props keep their existing unchecked contract. */
|
|
30
|
+
type CreateBoundLazyErrorComponent<Resource, Context> = CreateLazyErrorComponent<Resource, Context>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { CreateBoundLazyErrorComponent, CreateLazyRenderState, LazyDefaultState };
|
|
33
|
+
//# sourceMappingURL=create-render-state.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-render-state.d.cts","names":[],"sources":["../../src/lazy/create-render-state.tsx"],"mappings":";;;;;;;;;KAyBY,gBAAA;AAAA,KACP,YAAA,eACW,gBAAA,cAEZ,KAAA,mBACA,sBAAA,CAAuB,QAAA;EACrB,QAAA,EAAU,QAAA;AAAA;;KAGX,mBAAA,4BACW,OAAA,GAAU,OAAA,CAAQ,GAAA;EAC1B,QAAA;EAAgB,WAAA;AAAA,IAClB,OAAA,CAAQ,GAAA;AAAA,KAGT,UAAA,eAAyB,gBAAA,gCAExB,KAAA,EAAO,KAAA,GAAQ,YAAA,CAAa,KAAA,EAAO,QAAA,GACnC,OAAA,EAAS,OAAA,KACN,SAAA,KACJ,KAAA,mBACG,iBAAA,CAAkB,QAAA,EAAU,KAAA,WAAgB,OAAA;;KAIxC,qBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,uBACd,oBAAA,yBAEA,gBAAA,uBACC,aAAA,6BACC,aAAA,CACpB,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,SAE1C,UAAA;EACA,KAAA,EAAO,KAAA;EACP,KAAA;IAAU,OAAA,GAAU,OAAA;IAAS,MAAA,GAAS,MAAA;EAAA;EACtC,MAAA,EAAQ,UAAA,CAAW,KAAA,EAAO,YAAA,CAAa,SAAA,GAAY,gBAAA,CAAiB,SAAA,EAAW,OAAA,EAAS,WAAA,EAAa,OAAA,EAAS,MAAA,GAAS,kBAAA,CAAmB,WAAA,EAAa,SAAA,EAAW,KAAA;AAAA,MAC9J,aAAA,CACJ,qBAAA,CACE,YAAA,CAAa,MAAA,IACX,8BAAA,CACE,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,GACxC,mBAAA,CAAoB,OAAA,MAGxB,YAAA,CAAa,KAAA,EAAO,YAAA,CAAa,SAAA;;KAIzB,6BAAA,sBACV,wBAAA,CAAyB,QAAA,EAAU,OAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CreateLazyErrorComponent, LazyErrorHandlers, LazyResourceErrorProps } from "./types.mjs";
|
|
2
|
+
import { ResourceDefinition, ResourcePath } from "../resource.mjs";
|
|
3
|
+
import { InPropsDefinition, InPropsObject, IncludedProps, MergedLayoutInProps, ResolvedIncludedComponentProps } from "../props.mjs";
|
|
4
|
+
import { OptionalStateChildren, RenderStateContext, RenderStateProps } from "../create-config/render-state.mjs";
|
|
5
|
+
import { ComposableComponents } from "@jfdevelops/react-layout-composables";
|
|
6
|
+
import { ComponentType, ReactNode } from "react";
|
|
7
|
+
import { ResolveProps } from "@jfdevelops/react-layout-validator";
|
|
8
|
+
|
|
9
|
+
//#region src/lazy/create-render-state.d.ts
|
|
10
|
+
type LazyDefaultState = 'Loading' | 'Error';
|
|
11
|
+
type BuiltinProps<State extends LazyDefaultState, Resource> = State extends 'Error' ? LazyResourceErrorProps<Resource> : {
|
|
12
|
+
resource: Resource;
|
|
13
|
+
};
|
|
14
|
+
/** Shorthand includes are direct props; explicit supply sources retain their contract. */
|
|
15
|
+
type LazyDefaultIncludes<Include> = { [Key in keyof Include]: Include[Key] extends true ? {
|
|
16
|
+
required: true;
|
|
17
|
+
suppliedVia: 'component';
|
|
18
|
+
} : Include[Key] };
|
|
19
|
+
type LazyRender<State extends LazyDefaultState, Resource, Props, Context> = ((props: Props & BuiltinProps<State, Resource>, context: Context) => ReactNode) | (State extends 'Error' ? LazyErrorHandlers<Resource, Props & object, Context> : never);
|
|
20
|
+
/** Creates validated, composable-aware fallback components for one factory. */
|
|
21
|
+
type CreateLazyRenderState<Resources extends ReadonlyArray<ResourceDefinition>, Options extends InPropsDefinition<Resources>, Composables extends ComposableComponents> = <const State extends LazyDefaultState, const Custom extends InPropsObject = {}, const Include extends IncludedProps<MergedLayoutInProps<Resources, Options, Composables>> = {}>(definition: {
|
|
22
|
+
state: State;
|
|
23
|
+
props?: {
|
|
24
|
+
include?: Include;
|
|
25
|
+
custom?: Custom;
|
|
26
|
+
};
|
|
27
|
+
render: LazyRender<State, ResourcePath<Resources>, RenderStateProps<Resources, Options, Composables, Include, Custom>, RenderStateContext<Composables, Resources, State>>;
|
|
28
|
+
}) => ComponentType<OptionalStateChildren<ResolveProps<Custom> & ResolvedIncludedComponentProps<MergedLayoutInProps<Resources, Options, Composables>, LazyDefaultIncludes<Include>>> & BuiltinProps<State, ResourcePath<Resources>>>;
|
|
29
|
+
/** Compatibility helper; custom props keep their existing unchecked contract. */
|
|
30
|
+
type CreateBoundLazyErrorComponent<Resource, Context> = CreateLazyErrorComponent<Resource, Context>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { CreateBoundLazyErrorComponent, CreateLazyRenderState, LazyDefaultState };
|
|
33
|
+
//# sourceMappingURL=create-render-state.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-render-state.d.mts","names":[],"sources":["../../src/lazy/create-render-state.tsx"],"mappings":";;;;;;;;;KAyBY,gBAAA;AAAA,KACP,YAAA,eACW,gBAAA,cAEZ,KAAA,mBACA,sBAAA,CAAuB,QAAA;EACrB,QAAA,EAAU,QAAA;AAAA;;KAGX,mBAAA,4BACW,OAAA,GAAU,OAAA,CAAQ,GAAA;EAC1B,QAAA;EAAgB,WAAA;AAAA,IAClB,OAAA,CAAQ,GAAA;AAAA,KAGT,UAAA,eAAyB,gBAAA,gCAExB,KAAA,EAAO,KAAA,GAAQ,YAAA,CAAa,KAAA,EAAO,QAAA,GACnC,OAAA,EAAS,OAAA,KACN,SAAA,KACJ,KAAA,mBACG,iBAAA,CAAkB,QAAA,EAAU,KAAA,WAAgB,OAAA;;KAIxC,qBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,uBACd,oBAAA,yBAEA,gBAAA,uBACC,aAAA,6BACC,aAAA,CACpB,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,SAE1C,UAAA;EACA,KAAA,EAAO,KAAA;EACP,KAAA;IAAU,OAAA,GAAU,OAAA;IAAS,MAAA,GAAS,MAAA;EAAA;EACtC,MAAA,EAAQ,UAAA,CAAW,KAAA,EAAO,YAAA,CAAa,SAAA,GAAY,gBAAA,CAAiB,SAAA,EAAW,OAAA,EAAS,WAAA,EAAa,OAAA,EAAS,MAAA,GAAS,kBAAA,CAAmB,WAAA,EAAa,SAAA,EAAW,KAAA;AAAA,MAC9J,aAAA,CACJ,qBAAA,CACE,YAAA,CAAa,MAAA,IACX,8BAAA,CACE,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,GACxC,mBAAA,CAAoB,OAAA,MAGxB,YAAA,CAAa,KAAA,EAAO,YAAA,CAAa,SAAA;;KAIzB,6BAAA,sBACV,wBAAA,CAAyB,QAAA,EAAU,OAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { LayoutConfigurationError } from "../errors/layout-configuration-error.mjs";
|
|
2
|
+
import { defineResourceLayout } from "../create-config/define-layout.mjs";
|
|
3
|
+
import { createElement } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/lazy/create-render-state.tsx
|
|
6
|
+
function createLazyRenderStateBuilder(configuration) {
|
|
7
|
+
function createRenderState(definition) {
|
|
8
|
+
if (definition.state !== "Loading" && definition.state !== "Error") throw new LayoutConfigurationError(`Unknown lazy default state "${definition.state}"`);
|
|
9
|
+
const include = Object.fromEntries(Object.entries(definition.props?.include ?? {}).map(([key, behavior]) => [key, behavior === true ? {
|
|
10
|
+
required: true,
|
|
11
|
+
suppliedVia: "component"
|
|
12
|
+
} : behavior]));
|
|
13
|
+
function RenderLazyDefault({ props, context }) {
|
|
14
|
+
if (typeof definition.render === "function") return definition.render(props, context);
|
|
15
|
+
const errorProps = props;
|
|
16
|
+
const handler = definition.render[errorProps.error.code] ?? definition.render.fallback;
|
|
17
|
+
if (!handler) throw errorProps.error;
|
|
18
|
+
return handler(props, context);
|
|
19
|
+
}
|
|
20
|
+
const layout = defineResourceLayout({
|
|
21
|
+
resources: configuration.resources,
|
|
22
|
+
options: configuration.options,
|
|
23
|
+
layout: { render: {
|
|
24
|
+
default: () => null,
|
|
25
|
+
[definition.state]: {
|
|
26
|
+
composables: configuration.composables,
|
|
27
|
+
props: {
|
|
28
|
+
include,
|
|
29
|
+
custom: definition.props?.custom
|
|
30
|
+
},
|
|
31
|
+
render: (props, context) => createElement(RenderLazyDefault, {
|
|
32
|
+
props,
|
|
33
|
+
context
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
} }
|
|
37
|
+
});
|
|
38
|
+
const components = /* @__PURE__ */ new Map();
|
|
39
|
+
function LazyDefault(props) {
|
|
40
|
+
const resource = props.resource.split(".")[0];
|
|
41
|
+
let Component = components.get(resource);
|
|
42
|
+
if (!Component) {
|
|
43
|
+
Component = layout.createResourceLayout({
|
|
44
|
+
resource,
|
|
45
|
+
name: "LazyDefault",
|
|
46
|
+
namespace: false
|
|
47
|
+
})[definition.state];
|
|
48
|
+
components.set(resource, Component);
|
|
49
|
+
}
|
|
50
|
+
return createElement(Component, props);
|
|
51
|
+
}
|
|
52
|
+
return LazyDefault;
|
|
53
|
+
}
|
|
54
|
+
return createRenderState;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { createLazyRenderStateBuilder };
|
|
59
|
+
//# sourceMappingURL=create-render-state.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-render-state.mjs","names":[],"sources":["../../src/lazy/create-render-state.tsx"],"sourcesContent":["import { createElement, type ComponentType, type ReactNode } from 'react';\nimport type { ComposableComponents } from '@jfdevelops/react-layout-composables';\nimport { LayoutConfigurationError } from '../errors';\nimport type { ResourceDefinition, ResourcePath } from '../resource';\nimport {\n type ResolvedIncludedComponentProps,\n type IncludedProps,\n type InPropsDefinition,\n type InPropsObject,\n type MergedLayoutInProps,\n} from '../props';\nimport { defineResourceLayout } from '../create-config/define-layout';\nimport type {\n LayoutComposablesDefinition,\n RenderStateContext,\n RenderStateProps,\n OptionalStateChildren,\n} from '../create-config/render-state';\nimport type { ResolveProps } from '@jfdevelops/react-layout-validator';\nimport type {\n LazyResourceErrorProps,\n LazyErrorHandlers,\n CreateLazyErrorComponent,\n} from './types';\n\nexport type LazyDefaultState = 'Loading' | 'Error';\ntype BuiltinProps<\n State extends LazyDefaultState,\n Resource,\n> = State extends 'Error'\n ? LazyResourceErrorProps<Resource>\n : { resource: Resource };\n\n/** Shorthand includes are direct props; explicit supply sources retain their contract. */\ntype LazyDefaultIncludes<Include> = {\n [Key in keyof Include]: Include[Key] extends true\n ? { required: true; suppliedVia: 'component' }\n : Include[Key];\n};\n\ntype LazyRender<State extends LazyDefaultState, Resource, Props, Context> =\n | ((\n props: Props & BuiltinProps<State, Resource>,\n context: Context,\n ) => ReactNode)\n | (State extends 'Error'\n ? LazyErrorHandlers<Resource, Props & object, Context>\n : never);\n\n/** Creates validated, composable-aware fallback components for one factory. */\nexport type CreateLazyRenderState<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n> = <\n const State extends LazyDefaultState,\n const Custom extends InPropsObject = {},\n const Include extends IncludedProps<\n MergedLayoutInProps<Resources, Options, Composables>\n > = {},\n>(definition: {\n state: State;\n props?: { include?: Include; custom?: Custom };\n render: LazyRender<State, ResourcePath<Resources>, RenderStateProps<Resources, Options, Composables, Include, Custom>, RenderStateContext<Composables, Resources, State>>;\n}) => ComponentType<\n OptionalStateChildren<\n ResolveProps<Custom> &\n ResolvedIncludedComponentProps<\n MergedLayoutInProps<Resources, Options, Composables>,\n LazyDefaultIncludes<Include>\n >\n > &\n BuiltinProps<State, ResourcePath<Resources>>\n>;\n\n/** Compatibility helper; custom props keep their existing unchecked contract. */\nexport type CreateBoundLazyErrorComponent<Resource, Context> =\n CreateLazyErrorComponent<Resource, Context>;\n\ntype RuntimeDefinition = {\n state: LazyDefaultState;\n props?: { include?: Record<string, unknown>; custom?: InPropsObject };\n render:\n | ((props: any, context: any) => ReactNode)\n | LazyErrorHandlers<string, object, any>;\n};\n\nexport function createLazyRenderStateBuilder<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n>(configuration: {\n resources: Resources;\n options: Options;\n composables?: LayoutComposablesDefinition<Resources, Composables>;\n}): CreateLazyRenderState<Resources, Options, Composables> {\n function createRenderState(definition: RuntimeDefinition) {\n if (definition.state !== 'Loading' && definition.state !== 'Error') {\n throw new LayoutConfigurationError(\n `Unknown lazy default state \"${definition.state}\"`,\n );\n }\n // Lazy defaults have no create-time configuration call. Included values are\n // supplied by their component caller unless an explicit config source is selected.\n const include = Object.fromEntries(\n Object.entries(definition.props?.include ?? {}).map(([key, behavior]) => [\n key,\n behavior === true\n ? { required: true, suppliedVia: 'component' }\n : behavior,\n ]),\n );\n function RenderLazyDefault({\n props,\n context,\n }: {\n props: any;\n context: any;\n }) {\n if (typeof definition.render === 'function') {\n return definition.render(props, context);\n }\n const errorProps = props as LazyResourceErrorProps;\n const handler =\n definition.render[errorProps.error.code] ?? definition.render.fallback;\n if (!handler) throw errorProps.error;\n return handler(props as never, context);\n }\n const layout = defineResourceLayout({\n resources: configuration.resources,\n options: configuration.options,\n layout: {\n render: {\n default: () => null,\n [definition.state]: {\n composables: configuration.composables,\n props: { include, custom: definition.props?.custom },\n render: (props: any, context: any) =>\n createElement(RenderLazyDefault, { props, context }),\n },\n },\n },\n } as never);\n const components = new Map<string, ComponentType<any>>();\n function LazyDefault(props: { resource: string }) {\n // Nested lazy paths use the factory's top-level resource definitions for\n // option resolution. The callback still receives the complete path.\n const resource = props.resource.split('.')[0]!;\n let Component = components.get(resource);\n if (!Component) {\n const Root = layout.createResourceLayout({\n resource,\n name: 'LazyDefault',\n namespace: false,\n } as never) as unknown as Record<LazyDefaultState, ComponentType<any>>;\n Component = Root[definition.state];\n components.set(resource, Component);\n }\n return createElement(Component, props);\n }\n return LazyDefault;\n }\n return createRenderState as CreateLazyRenderState<\n Resources,\n Options,\n Composables\n >;\n}\n"],"mappings":";;;;;AAuFA,SAAgB,6BAId,eAIyD;CACzD,SAAS,kBAAkB,YAA+B;EACxD,IAAI,WAAW,UAAU,aAAa,WAAW,UAAU,SACzD,MAAM,IAAI,yBACR,+BAA+B,WAAW,MAAM,EAClD;EAIF,MAAM,UAAU,OAAO,YACrB,OAAO,QAAQ,WAAW,OAAO,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,cAAc,CACvE,KACA,aAAa,OACT;GAAE,UAAU;GAAM,aAAa;EAAY,IAC3C,QACN,CAAC,CACH;EACA,SAAS,kBAAkB,EACzB,OACA,WAIC;GACD,IAAI,OAAO,WAAW,WAAW,YAC/B,OAAO,WAAW,OAAO,OAAO,OAAO;GAEzC,MAAM,aAAa;GACnB,MAAM,UACJ,WAAW,OAAO,WAAW,MAAM,SAAS,WAAW,OAAO;GAChE,IAAI,CAAC,SAAS,MAAM,WAAW;GAC/B,OAAO,QAAQ,OAAgB,OAAO;EACxC;EACA,MAAM,SAAS,qBAAqB;GAClC,WAAW,cAAc;GACzB,SAAS,cAAc;GACvB,QAAQ,EACN,QAAQ;IACN,eAAe;KACd,WAAW,QAAQ;KAClB,aAAa,cAAc;KAC3B,OAAO;MAAE;MAAS,QAAQ,WAAW,OAAO;KAAO;KACnD,SAAS,OAAY,YACnB,cAAc,mBAAmB;MAAE;MAAO;KAAQ,CAAC;IACvD;GACF,EACF;EACF,CAAU;EACV,MAAM,6BAAa,IAAI,IAAgC;EACvD,SAAS,YAAY,OAA6B;GAGhD,MAAM,WAAW,MAAM,SAAS,MAAM,GAAG,EAAE;GAC3C,IAAI,YAAY,WAAW,IAAI,QAAQ;GACvC,IAAI,CAAC,WAAW;IAMd,YALa,OAAO,qBAAqB;KACvC;KACA,MAAM;KACN,WAAW;IACb,CACe,EAAE,WAAW;IAC5B,WAAW,IAAI,UAAU,SAAS;GACpC;GACA,OAAO,cAAc,WAAW,KAAK;EACvC;EACA,OAAO;CACT;CACA,OAAO;AAKT"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
let react = require("react");
|
|
2
|
+
|
|
3
|
+
//#region src/lazy/fallback-props.ts
|
|
4
|
+
/** Scoped fallbacks receive current caller options without rebuilding their layout. */
|
|
5
|
+
const LazyFallbackPropsContext = (0, react.createContext)(void 0);
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.LazyFallbackPropsContext = LazyFallbackPropsContext;
|
|
9
|
+
//# sourceMappingURL=fallback-props.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback-props.cjs","names":[],"sources":["../../src/lazy/fallback-props.ts"],"sourcesContent":["import { createContext } from 'react';\n\n/** Scoped fallbacks receive current caller options without rebuilding their layout. */\nexport const LazyFallbackPropsContext = createContext<\n { owner?: string; props: Record<string, unknown> } | undefined\n>(undefined);\n"],"mappings":";;;;AAGA,MAAa,oDAEX,MAAS"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/lazy/fallback-props.ts
|
|
4
|
+
/** Scoped fallbacks receive current caller options without rebuilding their layout. */
|
|
5
|
+
const LazyFallbackPropsContext = createContext(void 0);
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { LazyFallbackPropsContext };
|
|
9
|
+
//# sourceMappingURL=fallback-props.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback-props.mjs","names":[],"sources":["../../src/lazy/fallback-props.ts"],"sourcesContent":["import { createContext } from 'react';\n\n/** Scoped fallbacks receive current caller options without rebuilding their layout. */\nexport const LazyFallbackPropsContext = createContext<\n { owner?: string; props: Record<string, unknown> } | undefined\n>(undefined);\n"],"mappings":";;;;AAGA,MAAa,2BAA2B,cAEtC,MAAS"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
let _jfdevelops_react_layout_devtools_core = require("@jfdevelops/react-layout-devtools-core");
|
|
2
|
+
|
|
3
|
+
//#region src/lazy/inspection.ts
|
|
4
|
+
/** Register a declaration before its import runs, retaining one node on retry. */
|
|
5
|
+
function inspectLazy(label, store = (0, _jfdevelops_react_layout_devtools_core.createInspectionStore)(), parent) {
|
|
6
|
+
const id = (0, _jfdevelops_react_layout_devtools_core.inspectionId)("lazy");
|
|
7
|
+
function update(status, error) {
|
|
8
|
+
store.node({
|
|
9
|
+
id,
|
|
10
|
+
kind: "lazy",
|
|
11
|
+
label,
|
|
12
|
+
status,
|
|
13
|
+
unresolved: status !== "resolved",
|
|
14
|
+
error: error && (0, _jfdevelops_react_layout_devtools_core.serializeInspectionError)(error)
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
update("unresolved");
|
|
18
|
+
if (parent) store.edge(parent, id, "declares");
|
|
19
|
+
return {
|
|
20
|
+
id,
|
|
21
|
+
store,
|
|
22
|
+
hooks: {
|
|
23
|
+
onLoadStart: () => update("loading"),
|
|
24
|
+
onLoadSuccess: () => update("resolved"),
|
|
25
|
+
onLoadError: (error) => update("error", error),
|
|
26
|
+
onMount: () => store.mount(id)
|
|
27
|
+
},
|
|
28
|
+
setLabel(value) {
|
|
29
|
+
label = value;
|
|
30
|
+
update("unresolved");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function withLazyHandle(target, handle) {
|
|
35
|
+
Object.defineProperties(target, {
|
|
36
|
+
preload: {
|
|
37
|
+
value: handle.preload,
|
|
38
|
+
enumerable: false
|
|
39
|
+
},
|
|
40
|
+
status: {
|
|
41
|
+
get: () => handle.status,
|
|
42
|
+
enumerable: false
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return target;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.inspectLazy = inspectLazy;
|
|
50
|
+
exports.withLazyHandle = withLazyHandle;
|
|
51
|
+
//# sourceMappingURL=inspection.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspection.cjs","names":[],"sources":["../../src/lazy/inspection.ts"],"sourcesContent":["import {\n createInspectionStore,\n inspectionId,\n serializeInspectionError,\n type InspectionStore,\n type LoadStatus,\n} from '@jfdevelops/react-layout-devtools-core';\nimport type { LazyResourceLoadHooks } from './create-lazy-loader';\nimport type { LazyResourceError } from '../errors/lazy-resource-error';\n\n/** Register a declaration before its import runs, retaining one node on retry. */\nexport function inspectLazy(\n label: string,\n store: InspectionStore = createInspectionStore(),\n parent?: string,\n) {\n const id = inspectionId('lazy');\n function update(status: LoadStatus, error?: LazyResourceError) {\n store.node({\n id,\n kind: 'lazy',\n label,\n status,\n unresolved: status !== 'resolved',\n error: error && serializeInspectionError(error),\n });\n }\n update('unresolved');\n if (parent) store.edge(parent, id, 'declares');\n const hooks: LazyResourceLoadHooks = {\n onLoadStart: () => update('loading'),\n onLoadSuccess: () => update('resolved'),\n onLoadError: (error) => update('error', error),\n onMount: () => store.mount(id),\n };\n return {\n id,\n store,\n hooks,\n setLabel(value: string) {\n label = value;\n update('unresolved');\n },\n };\n}\n\nexport function withLazyHandle<T extends object>(\n target: T,\n handle: import('./types').LazyHandle,\n): T & import('./types').LazyHandle {\n Object.defineProperties(target, {\n preload: { value: handle.preload, enumerable: false },\n status: { get: () => handle.status, enumerable: false },\n });\n return target as T & import('./types').LazyHandle;\n}\n"],"mappings":";;;;AAWA,SAAgB,YACd,OACA,0EAA+C,GAC/C,QACA;CACA,MAAM,8DAAkB,MAAM;CAC9B,SAAS,OAAO,QAAoB,OAA2B;EAC7D,MAAM,KAAK;GACT;GACA,MAAM;GACN;GACA;GACA,YAAY,WAAW;GACvB,OAAO,8EAAkC,KAAK;EAChD,CAAC;CACH;CACA,OAAO,YAAY;CACnB,IAAI,QAAQ,MAAM,KAAK,QAAQ,IAAI,UAAU;CAO7C,OAAO;EACL;EACA;EACA;GARA,mBAAmB,OAAO,SAAS;GACnC,qBAAqB,OAAO,UAAU;GACtC,cAAc,UAAU,OAAO,SAAS,KAAK;GAC7C,eAAe,MAAM,MAAM,EAAE;EAKzB;EACJ,SAAS,OAAe;GACtB,QAAQ;GACR,OAAO,YAAY;EACrB;CACF;AACF;AAEA,SAAgB,eACd,QACA,QACkC;CAClC,OAAO,iBAAiB,QAAQ;EAC9B,SAAS;GAAE,OAAO,OAAO;GAAS,YAAY;EAAM;EACpD,QAAQ;GAAE,WAAW,OAAO;GAAQ,YAAY;EAAM;CACxD,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LazyResourceLoadHooks } from "./create-lazy-loader.cjs";
|
|
2
|
+
import { InspectionStore } from "@jfdevelops/react-layout-devtools-core";
|
|
3
|
+
|
|
4
|
+
//#region src/lazy/inspection.d.ts
|
|
5
|
+
/** Register a declaration before its import runs, retaining one node on retry. */
|
|
6
|
+
declare function inspectLazy(label: string, store?: InspectionStore, parent?: string): {
|
|
7
|
+
id: string;
|
|
8
|
+
store: {
|
|
9
|
+
getSnapshot(): import("@jfdevelops/react-layout-devtools-core").GraphSnapshot;
|
|
10
|
+
subscribe(listener: () => void): () => void;
|
|
11
|
+
registerPreview(instance: import("@jfdevelops/react-layout-devtools-core").PreviewInstance, controller: import("@jfdevelops/react-layout-devtools-core").PreviewController): () => void;
|
|
12
|
+
preview(instanceId: string, state?: string): void;
|
|
13
|
+
previewError(instanceId: string, error: string): void;
|
|
14
|
+
connectPreview(): () => void;
|
|
15
|
+
node(node: Omit<import("@jfdevelops/react-layout-devtools-core").GraphNode, "active"> & {
|
|
16
|
+
active?: number;
|
|
17
|
+
}): string;
|
|
18
|
+
edge(source: string, target: string, relationship: import("@jfdevelops/react-layout-devtools-core").GraphEdge["relationship"]): void;
|
|
19
|
+
mount(...ids: string[]): () => void;
|
|
20
|
+
connect(value: object): void;
|
|
21
|
+
attach<T extends object>(value: T): T;
|
|
22
|
+
};
|
|
23
|
+
hooks: LazyResourceLoadHooks;
|
|
24
|
+
setLabel(value: string): void;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { inspectLazy };
|
|
28
|
+
//# sourceMappingURL=inspection.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspection.d.cts","names":[],"sources":["../../src/lazy/inspection.ts"],"mappings":";;;;;iBAWgB,WAAA,CACd,KAAA,UACA,KAAA,GAAO,eAAA,EACP,MAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LazyResourceLoadHooks } from "./create-lazy-loader.mjs";
|
|
2
|
+
import { InspectionStore } from "@jfdevelops/react-layout-devtools-core";
|
|
3
|
+
|
|
4
|
+
//#region src/lazy/inspection.d.ts
|
|
5
|
+
/** Register a declaration before its import runs, retaining one node on retry. */
|
|
6
|
+
declare function inspectLazy(label: string, store?: InspectionStore, parent?: string): {
|
|
7
|
+
id: string;
|
|
8
|
+
store: {
|
|
9
|
+
getSnapshot(): import("@jfdevelops/react-layout-devtools-core").GraphSnapshot;
|
|
10
|
+
subscribe(listener: () => void): () => void;
|
|
11
|
+
registerPreview(instance: import("@jfdevelops/react-layout-devtools-core").PreviewInstance, controller: import("@jfdevelops/react-layout-devtools-core").PreviewController): () => void;
|
|
12
|
+
preview(instanceId: string, state?: string): void;
|
|
13
|
+
previewError(instanceId: string, error: string): void;
|
|
14
|
+
connectPreview(): () => void;
|
|
15
|
+
node(node: Omit<import("@jfdevelops/react-layout-devtools-core").GraphNode, "active"> & {
|
|
16
|
+
active?: number;
|
|
17
|
+
}): string;
|
|
18
|
+
edge(source: string, target: string, relationship: import("@jfdevelops/react-layout-devtools-core").GraphEdge["relationship"]): void;
|
|
19
|
+
mount(...ids: string[]): () => void;
|
|
20
|
+
connect(value: object): void;
|
|
21
|
+
attach<T extends object>(value: T): T;
|
|
22
|
+
};
|
|
23
|
+
hooks: LazyResourceLoadHooks;
|
|
24
|
+
setLabel(value: string): void;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { inspectLazy };
|
|
28
|
+
//# sourceMappingURL=inspection.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspection.d.mts","names":[],"sources":["../../src/lazy/inspection.ts"],"mappings":";;;;;iBAWgB,WAAA,CACd,KAAA,UACA,KAAA,GAAO,eAAA,EACP,MAAA"}
|