@jfdevelops/react-layout 2.1.0 → 2.3.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 +6 -3
- package/dist/create-config/create-defined-resource-layout.cjs.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.cts +16 -13
- package/dist/create-config/create-defined-resource-layout.d.cts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.mts +16 -13
- package/dist/create-config/create-defined-resource-layout.d.mts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.mjs +6 -3
- package/dist/create-config/create-defined-resource-layout.mjs.map +1 -1
- package/dist/create-config/create-resource-links.cjs.map +1 -1
- package/dist/create-config/create-resource-links.d.cts +3 -1
- package/dist/create-config/create-resource-links.d.cts.map +1 -1
- package/dist/create-config/create-resource-links.d.mts +3 -1
- package/dist/create-config/create-resource-links.d.mts.map +1 -1
- package/dist/create-config/create-resource-links.mjs.map +1 -1
- package/dist/create-config/create-reusable.cjs +49 -0
- package/dist/create-config/create-reusable.cjs.map +1 -0
- package/dist/create-config/create-reusable.d.cts +41 -0
- package/dist/create-config/create-reusable.d.cts.map +1 -0
- package/dist/create-config/create-reusable.d.mts +41 -0
- package/dist/create-config/create-reusable.d.mts.map +1 -0
- package/dist/create-config/create-reusable.mjs +49 -0
- package/dist/create-config/create-reusable.mjs.map +1 -0
- package/dist/create-config/define-layout.cjs +19 -12
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +43 -42
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +43 -42
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +22 -15
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/create-config/for-paths/builder.cjs +1 -0
- package/dist/create-config/for-paths/builder.cjs.map +1 -1
- package/dist/create-config/for-paths/builder.d.cts +5 -3
- package/dist/create-config/for-paths/builder.d.cts.map +1 -1
- package/dist/create-config/for-paths/builder.d.mts +5 -3
- package/dist/create-config/for-paths/builder.d.mts.map +1 -1
- package/dist/create-config/for-paths/builder.mjs +1 -0
- package/dist/create-config/for-paths/builder.mjs.map +1 -1
- package/dist/create-config/for-resource.cjs.map +1 -1
- package/dist/create-config/for-resource.d.cts +7 -6
- package/dist/create-config/for-resource.d.cts.map +1 -1
- package/dist/create-config/for-resource.d.mts +7 -6
- package/dist/create-config/for-resource.d.mts.map +1 -1
- package/dist/create-config/for-resource.mjs.map +1 -1
- package/dist/create-config/for-resources/create-component.d.cts +34 -33
- package/dist/create-config/for-resources/create-component.d.cts.map +1 -1
- package/dist/create-config/for-resources/create-component.d.mts +34 -33
- package/dist/create-config/for-resources/create-component.d.mts.map +1 -1
- package/dist/create-config/for-resources/create-for-resources.cjs +7 -6
- package/dist/create-config/for-resources/create-for-resources.cjs.map +1 -1
- package/dist/create-config/for-resources/create-for-resources.d.cts +2 -1
- package/dist/create-config/for-resources/create-for-resources.d.mts +2 -1
- package/dist/create-config/for-resources/create-for-resources.mjs +7 -6
- package/dist/create-config/for-resources/create-for-resources.mjs.map +1 -1
- package/dist/create-config/for-resources/scoped-layout.d.cts +5 -4
- package/dist/create-config/for-resources/scoped-layout.d.cts.map +1 -1
- package/dist/create-config/for-resources/scoped-layout.d.mts +5 -4
- package/dist/create-config/for-resources/scoped-layout.d.mts.map +1 -1
- package/dist/create-config/index.d.cts +1 -0
- package/dist/create-config/index.d.mts +1 -0
- package/dist/create-config/inspection.cjs +23 -1
- package/dist/create-config/inspection.cjs.map +1 -1
- package/dist/create-config/inspection.mjs +24 -3
- package/dist/create-config/inspection.mjs.map +1 -1
- package/dist/create-config/layout-name.cjs +1 -1
- package/dist/create-config/layout-name.mjs +1 -1
- package/dist/create-config/lazy-resource-layout.cjs +5 -5
- package/dist/create-config/lazy-resource-layout.cjs.map +1 -1
- package/dist/create-config/lazy-resource-layout.d.cts +2 -2
- package/dist/create-config/lazy-resource-layout.d.cts.map +1 -1
- package/dist/create-config/lazy-resource-layout.d.mts +2 -2
- package/dist/create-config/lazy-resource-layout.d.mts.map +1 -1
- package/dist/create-config/lazy-resource-layout.mjs +5 -5
- package/dist/create-config/lazy-resource-layout.mjs.map +1 -1
- package/dist/create-config/render-state.cjs +3 -2
- package/dist/create-config/render-state.cjs.map +1 -1
- package/dist/create-config/render-state.d.cts +27 -25
- package/dist/create-config/render-state.d.cts.map +1 -1
- package/dist/create-config/render-state.d.mts +27 -25
- package/dist/create-config/render-state.d.mts.map +1 -1
- package/dist/create-config/render-state.mjs +3 -2
- package/dist/create-config/render-state.mjs.map +1 -1
- package/dist/create-config/state-composable.cjs +1 -1
- package/dist/create-config/state-composable.mjs +1 -1
- package/dist/custom-props.cjs +15 -0
- package/dist/custom-props.cjs.map +1 -0
- package/dist/custom-props.d.cts +17 -0
- package/dist/custom-props.d.cts.map +1 -0
- package/dist/custom-props.d.mts +17 -0
- package/dist/custom-props.d.mts.map +1 -0
- package/dist/custom-props.mjs +15 -0
- package/dist/custom-props.mjs.map +1 -0
- package/dist/errors/react-layout-error.cjs +1 -1
- package/dist/errors/react-layout-error.mjs +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +3 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +3 -3
- package/dist/lazy/create-lazy-loader.cjs +30 -9
- package/dist/lazy/create-lazy-loader.cjs.map +1 -1
- package/dist/lazy/create-lazy-loader.mjs +31 -10
- package/dist/lazy/create-lazy-loader.mjs.map +1 -1
- package/dist/lazy/create-render-state.cjs.map +1 -1
- package/dist/lazy/create-render-state.d.cts +5 -5
- package/dist/lazy/create-render-state.d.cts.map +1 -1
- package/dist/lazy/create-render-state.d.mts +5 -5
- package/dist/lazy/create-render-state.d.mts.map +1 -1
- package/dist/lazy/create-render-state.mjs.map +1 -1
- package/dist/lazy/lazy-boundary.cjs +1 -1
- package/dist/lazy/lazy-boundary.mjs +1 -1
- package/dist/lazy/types.cjs.map +1 -1
- package/dist/lazy/types.d.cts +5 -4
- package/dist/lazy/types.d.cts.map +1 -1
- package/dist/lazy/types.d.mts +5 -4
- package/dist/lazy/types.d.mts.map +1 -1
- package/dist/lazy/types.mjs.map +1 -1
- package/dist/props.cjs.map +1 -1
- package/dist/props.d.cts +4 -3
- package/dist/props.d.cts.map +1 -1
- package/dist/props.d.mts +4 -3
- package/dist/props.d.mts.map +1 -1
- package/dist/props.mjs.map +1 -1
- package/dist/resource.d.cts +1 -1
- package/dist/resource.d.mts +1 -1
- package/package.json +5 -5
|
@@ -10,6 +10,7 @@ import { IsSubResourceKey, IsSubResourceKeyOptions, IsSubResourceKeyResult } fro
|
|
|
10
10
|
import { ComponentTypes, CreateResourceConfigFn, CreateResourceConfigForResource, CreatedResourceConfig, GetComponent, GetComponentAtBound, GetComponentForResource, GetComponentForResourceOptions, GetComponentOptions, GetComponentOptionsForResource, ResourceConfigFragment, ResourceConfigPath, ResourceFromGetComponentBound, SubResourceFromGetComponentBound, ValidateForResourceBound } from "./get-component.cjs";
|
|
11
11
|
import { CreateResourceLinkConfig, CreateResourceLinkGroupInput, CreateResourceLinkGroupOptions, CreateResourceLinkOptions, CreateResourceLinksFn, CreateResourceLinksWithGroups, CreateResourceLinksWithGroupsFn, CreateResourceLinksWithGroupsResult, CreateResourceMap, CreateResourceMapFn, CreatedResourceHref, CreatedResourceLink, CreatedResourceLinkBase, CreatedResourceMap, DefineResourceIconFn, DefineResourceIconInputHelpers, DefineResourceIconInputResult, FindResolvedResourceGroupResult, FindResourceGroupResult, InferHashFromResourceLinkHref, ResolveResourceIconInput, ResolvedResourceLinksWithGroups, ResolvedResourceLinksWithGroupsResult, ResourceAnchorLinkFn, ResourceIcon, ResourceIconFn, ResourceLinkHref, ValidateResource } from "./create-resource-links.cjs";
|
|
12
12
|
import { ContextualInlineRenderState, ContextualInlineRenderStates, CreateResourceLayoutFn, CreateResourceLayoutMakeComposableOptions, CreateResourceLayoutWithLayoutOptions, CreateViewMapBuiltInRenderStatesOptions, CreateViewMapFunctionRenderOptions, CreateViewMapInlineRenderStatesOptions, CreateViewMapOptions, CreateViewMapRenderStatesOptions, DefineResourceLayout, DefineResourceLayoutFn, DefineResourceLayoutForResources, DefineResourceLayoutForResourcesFactory, DefineResourceLayoutWithLayoutFn, DefineResourcesFn, DefinedResourceLayout, DefinedResourceLayoutWithShell, LayoutDefinition, LayoutIncludeProps, LayoutRenderResourcesAccessor, LayoutResourcesAccessor, ResourceLayoutProvider, ResourceLayoutProviderProps, ResourceLayoutShellComponent, ResourceLayoutShellProps, ResourceSelection, ShellLayoutDefinition, ShellRenderContext, TypedBuiltInRenderStates, TypedInlineRenderState, defineResourceLayout } from "./define-layout.cjs";
|
|
13
|
+
import { CreateReusable, ReusableInclude, ReusableOptionSelection, ReusableProps } from "./create-reusable.cjs";
|
|
13
14
|
import { LazyResourceLayoutComponent, LazyResourceLayoutOptions } from "./lazy-resource-layout.cjs";
|
|
14
15
|
import { BoundDefineResourceLayout, CreateDefinedResourceLayoutOptions, CreateDefinedResourceLayoutResult, DefineLazyDefaults, DefinedResourceLayoutInput, NonEmptyResources, createDefinedResourceLayout } from "./create-defined-resource-layout.cjs";
|
|
15
16
|
import { ResourceLayoutShellPublisher } from "./shell-context.cjs";
|
|
@@ -10,6 +10,7 @@ import { IsSubResourceKey, IsSubResourceKeyOptions, IsSubResourceKeyResult } fro
|
|
|
10
10
|
import { ComponentTypes, CreateResourceConfigFn, CreateResourceConfigForResource, CreatedResourceConfig, GetComponent, GetComponentAtBound, GetComponentForResource, GetComponentForResourceOptions, GetComponentOptions, GetComponentOptionsForResource, ResourceConfigFragment, ResourceConfigPath, ResourceFromGetComponentBound, SubResourceFromGetComponentBound, ValidateForResourceBound } from "./get-component.mjs";
|
|
11
11
|
import { CreateResourceLinkConfig, CreateResourceLinkGroupInput, CreateResourceLinkGroupOptions, CreateResourceLinkOptions, CreateResourceLinksFn, CreateResourceLinksWithGroups, CreateResourceLinksWithGroupsFn, CreateResourceLinksWithGroupsResult, CreateResourceMap, CreateResourceMapFn, CreatedResourceHref, CreatedResourceLink, CreatedResourceLinkBase, CreatedResourceMap, DefineResourceIconFn, DefineResourceIconInputHelpers, DefineResourceIconInputResult, FindResolvedResourceGroupResult, FindResourceGroupResult, InferHashFromResourceLinkHref, ResolveResourceIconInput, ResolvedResourceLinksWithGroups, ResolvedResourceLinksWithGroupsResult, ResourceAnchorLinkFn, ResourceIcon, ResourceIconFn, ResourceLinkHref, ValidateResource } from "./create-resource-links.mjs";
|
|
12
12
|
import { ContextualInlineRenderState, ContextualInlineRenderStates, CreateResourceLayoutFn, CreateResourceLayoutMakeComposableOptions, CreateResourceLayoutWithLayoutOptions, CreateViewMapBuiltInRenderStatesOptions, CreateViewMapFunctionRenderOptions, CreateViewMapInlineRenderStatesOptions, CreateViewMapOptions, CreateViewMapRenderStatesOptions, DefineResourceLayout, DefineResourceLayoutFn, DefineResourceLayoutForResources, DefineResourceLayoutForResourcesFactory, DefineResourceLayoutWithLayoutFn, DefineResourcesFn, DefinedResourceLayout, DefinedResourceLayoutWithShell, LayoutDefinition, LayoutIncludeProps, LayoutRenderResourcesAccessor, LayoutResourcesAccessor, ResourceLayoutProvider, ResourceLayoutProviderProps, ResourceLayoutShellComponent, ResourceLayoutShellProps, ResourceSelection, ShellLayoutDefinition, ShellRenderContext, TypedBuiltInRenderStates, TypedInlineRenderState, defineResourceLayout } from "./define-layout.mjs";
|
|
13
|
+
import { CreateReusable, ReusableInclude, ReusableOptionSelection, ReusableProps } from "./create-reusable.mjs";
|
|
13
14
|
import { LazyResourceLayoutComponent, LazyResourceLayoutOptions } from "./lazy-resource-layout.mjs";
|
|
14
15
|
import { BoundDefineResourceLayout, CreateDefinedResourceLayoutOptions, CreateDefinedResourceLayoutResult, DefineLazyDefaults, DefinedResourceLayoutInput, NonEmptyResources, createDefinedResourceLayout } from "./create-defined-resource-layout.mjs";
|
|
15
16
|
import { ResourceLayoutShellPublisher } from "./shell-context.mjs";
|
|
@@ -34,15 +34,36 @@ function inspectDefinition(resources, source) {
|
|
|
34
34
|
resourceIds
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
const inspectedComposables = /* @__PURE__ */ new WeakSet();
|
|
38
|
+
/** Mark existing roots only; never add wrappers or forward props to user components. */
|
|
39
|
+
function markInspectionRoots(children, owners) {
|
|
40
|
+
if (process.env.NODE_ENV === "production") return children;
|
|
41
|
+
if (Array.isArray(children)) return children.map((child) => markInspectionRoots(child, owners));
|
|
42
|
+
if (!(0, react.isValidElement)(children)) return children;
|
|
43
|
+
if (children.type === react.Fragment) return (0, react.cloneElement)(children, { children: markInspectionRoots(children.props.children, owners) });
|
|
44
|
+
if (typeof children.type !== "string" && (typeof children.type !== "object" || !inspectedComposables.has(children.type))) return children;
|
|
45
|
+
let previous = [];
|
|
46
|
+
try {
|
|
47
|
+
const parsed = JSON.parse(children.props["data-rl-owners"] ?? "[]");
|
|
48
|
+
if (Array.isArray(parsed)) previous = parsed.filter((id) => typeof id === "string");
|
|
49
|
+
} catch {}
|
|
50
|
+
return (0, react.cloneElement)(children, { "data-rl-owners": JSON.stringify([...new Set([...previous, ...owners])]) });
|
|
51
|
+
}
|
|
37
52
|
/** Preserve composable metadata while measuring committed React instances, not declarations. */
|
|
38
53
|
function trackComposable(component, store, id) {
|
|
39
54
|
const Tracked = (0, react.forwardRef)(function InspectedComposable(props, ref) {
|
|
40
55
|
(0, react.useLayoutEffect)(() => store.mount(id), [store, id]);
|
|
41
|
-
|
|
56
|
+
const inspectedProps = process.env.NODE_ENV === "production" ? props : {
|
|
42
57
|
...props,
|
|
58
|
+
"data-rl-node": id,
|
|
59
|
+
"data-rl-composable": component.displayName ?? "Composable"
|
|
60
|
+
};
|
|
61
|
+
return (0, react.createElement)(component, ref == null ? inspectedProps : {
|
|
62
|
+
...inspectedProps,
|
|
43
63
|
ref
|
|
44
64
|
});
|
|
45
65
|
});
|
|
66
|
+
inspectedComposables.add(Tracked);
|
|
46
67
|
for (const key of Reflect.ownKeys(component)) {
|
|
47
68
|
if (typeof key === "string" && [
|
|
48
69
|
"name",
|
|
@@ -63,5 +84,6 @@ function trackComposable(component, store, id) {
|
|
|
63
84
|
|
|
64
85
|
//#endregion
|
|
65
86
|
exports.inspectDefinition = inspectDefinition;
|
|
87
|
+
exports.markInspectionRoots = markInspectionRoots;
|
|
66
88
|
exports.trackComposable = trackComposable;
|
|
67
89
|
//# sourceMappingURL=inspection.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspection.cjs","names":[],"sources":["../../src/create-config/inspection.ts"],"sourcesContent":["import {\n createElement,\n forwardRef,\n useLayoutEffect,\n type ComponentType,\n} from 'react';\nimport {\n createInspectionStore,\n inspectionId,\n type InspectionStore,\n type SourceLocation,\n} from '@jfdevelops/react-layout-devtools-core';\nimport type { ResourceDefinition } from '../resource';\n\nexport function inspectDefinition(\n resources: readonly ResourceDefinition[],\n source?: SourceLocation\n) {\n const store = createInspectionStore();\n const definition = store.node({\n id: inspectionId('definition'),\n kind: 'definition',\n label: 'Layout definition',\n source,\n });\n const resourceIds = new Map<string, string>();\n\n function visit(\n items: readonly ResourceDefinition[],\n parent: string,\n prefix = ''\n ) {\n for (const item of items) {\n const slug = typeof item === 'string' ? item : item.value;\n const path = prefix ? `${prefix}.${slug}` : slug;\n const id = store.node({\n id: inspectionId('resource'),\n kind: 'resource',\n label: path,\n source,\n details: { path },\n });\n\n resourceIds.set(path, id);\n\n store.edge(parent, id, 'contains');\n\n if (typeof item !== 'string') visit(item.subResources, id, path);\n }\n }\n\n visit(resources, definition);\n\n return { store, definition, resourceIds };\n}\n\nexport interface ActiveInspection {\n store: InspectionStore;\n layout: string;\n resource?: string;\n state: string;\n}\n\n/** Preserve composable metadata while measuring committed React instances, not declarations. */\nexport function trackComposable<T extends object>(\n component: T,\n store: InspectionStore,\n id: string\n): T {\n const Tracked = forwardRef<unknown, Record<string, unknown>>(\n function InspectedComposable(props, ref) {\n useLayoutEffect(() => store.mount(id), [store, id]);\n\n return createElement(\n component as ComponentType<Record<string, unknown>>,\n ref == null ?
|
|
1
|
+
{"version":3,"file":"inspection.cjs","names":["Fragment"],"sources":["../../src/create-config/inspection.ts"],"sourcesContent":["import {\n createElement,\n cloneElement,\n Fragment,\n isValidElement,\n type ReactNode,\n forwardRef,\n useLayoutEffect,\n type ComponentType,\n} from 'react';\nimport {\n createInspectionStore,\n inspectionId,\n type InspectionStore,\n type SourceLocation,\n} from '@jfdevelops/react-layout-devtools-core';\nimport type { ResourceDefinition } from '../resource';\n\nexport function inspectDefinition(\n resources: readonly ResourceDefinition[],\n source?: SourceLocation\n) {\n const store = createInspectionStore();\n const definition = store.node({\n id: inspectionId('definition'),\n kind: 'definition',\n label: 'Layout definition',\n source,\n });\n const resourceIds = new Map<string, string>();\n\n function visit(\n items: readonly ResourceDefinition[],\n parent: string,\n prefix = ''\n ) {\n for (const item of items) {\n const slug = typeof item === 'string' ? item : item.value;\n const path = prefix ? `${prefix}.${slug}` : slug;\n const id = store.node({\n id: inspectionId('resource'),\n kind: 'resource',\n label: path,\n source,\n details: { path },\n });\n\n resourceIds.set(path, id);\n\n store.edge(parent, id, 'contains');\n\n if (typeof item !== 'string') visit(item.subResources, id, path);\n }\n }\n\n visit(resources, definition);\n\n return { store, definition, resourceIds };\n}\n\nexport interface ActiveInspection {\n store: InspectionStore;\n layout: string;\n resource?: string;\n state: string;\n}\n\nconst inspectedComposables = new WeakSet<object>();\n\n/** Mark existing roots only; never add wrappers or forward props to user components. */\nexport function markInspectionRoots(\n children: ReactNode,\n owners: readonly string[]\n): ReactNode {\n if (process.env.NODE_ENV === 'production') return children;\n if (Array.isArray(children))\n return children.map((child) => markInspectionRoots(child, owners));\n if (\n !isValidElement<{ children?: ReactNode; 'data-rl-owners'?: string }>(\n children\n )\n )\n return children;\n if (children.type === Fragment) {\n return cloneElement(children, {\n children: markInspectionRoots(children.props.children, owners),\n });\n }\n if (\n typeof children.type !== 'string' &&\n (typeof children.type !== 'object' ||\n !inspectedComposables.has(children.type))\n )\n return children;\n let previous: string[] = [];\n try {\n const parsed: unknown = JSON.parse(\n children.props['data-rl-owners'] ?? '[]'\n );\n if (Array.isArray(parsed))\n previous = parsed.filter((id): id is string => typeof id === 'string');\n } catch {}\n return cloneElement(children, {\n 'data-rl-owners': JSON.stringify([...new Set([...previous, ...owners])]),\n });\n}\n\n/** Preserve composable metadata while measuring committed React instances, not declarations. */\nexport function trackComposable<T extends object>(\n component: T,\n store: InspectionStore,\n id: string\n): T {\n const Tracked = forwardRef<unknown, Record<string, unknown>>(\n function InspectedComposable(props, ref) {\n useLayoutEffect(() => store.mount(id), [store, id]);\n\n const inspectedProps =\n process.env.NODE_ENV === 'production'\n ? props\n : {\n ...props,\n 'data-rl-node': id,\n 'data-rl-composable':\n (component as { displayName?: string }).displayName ??\n 'Composable',\n };\n return createElement(\n component as ComponentType<Record<string, unknown>>,\n ref == null ? inspectedProps : { ...inspectedProps, ref }\n );\n }\n );\n\n inspectedComposables.add(Tracked);\n\n for (const key of Reflect.ownKeys(component)) {\n if (\n typeof key === 'string' &&\n [\n 'name',\n 'length',\n 'prototype',\n 'caller',\n 'arguments',\n '$$typeof',\n 'render',\n 'compare',\n 'type',\n ].includes(key)\n )\n continue;\n\n const descriptor = Object.getOwnPropertyDescriptor(component, key);\n\n if (descriptor) Object.defineProperty(Tracked, key, descriptor);\n }\n\n return Tracked as unknown as T;\n}\n"],"mappings":";;;;AAkBA,SAAgB,kBACd,WACA,QACA;CACA,MAAM,0EAA8B;CACpC,MAAM,aAAa,MAAM,KAAK;EAC5B,6DAAiB,YAAY;EAC7B,MAAM;EACN,OAAO;EACP;CACF,CAAC;CACD,MAAM,8BAAc,IAAI,IAAoB;CAE5C,SAAS,MACP,OACA,QACA,SAAS,IACT;EACA,KAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,KAAK;GACpD,MAAM,OAAO,SAAS,GAAG,OAAO,GAAG,SAAS;G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EAElD,MAAM,iBACJ,QAAQ,IAAI,aAAa,eACrB,QACA;GACE,GAAG;GACH,gBAAgB;GAChB,sBACG,UAAuC,eACxC;EACJ;EACN,gCACE,WACA,OAAO,OAAO,iBAAiB;GAAE,GAAG;GAAgB;EAAI,CAC1D;CACF,CACF;CAEA,qBAAqB,IAAI,OAAO;CAEhC,KAAK,MAAM,OAAO,QAAQ,QAAQ,SAAS,GAAG;EAC5C,IACE,OAAO,QAAQ,YACf;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,EAAE,SAAS,GAAG,GAEd;EAEF,MAAM,aAAa,OAAO,yBAAyB,WAAW,GAAG;EAEjE,IAAI,YAAY,OAAO,eAAe,SAAS,KAAK,UAAU;CAChE;CAEA,OAAO;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createElement, forwardRef, useLayoutEffect } from "react";
|
|
1
|
+
import { Fragment, cloneElement, createElement, forwardRef, isValidElement, useLayoutEffect } from "react";
|
|
2
2
|
import { createInspectionStore, inspectionId } from "@jfdevelops/react-layout-devtools-core";
|
|
3
3
|
|
|
4
4
|
//#region src/create-config/inspection.ts
|
|
@@ -34,15 +34,36 @@ function inspectDefinition(resources, source) {
|
|
|
34
34
|
resourceIds
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
const inspectedComposables = /* @__PURE__ */ new WeakSet();
|
|
38
|
+
/** Mark existing roots only; never add wrappers or forward props to user components. */
|
|
39
|
+
function markInspectionRoots(children, owners) {
|
|
40
|
+
if (process.env.NODE_ENV === "production") return children;
|
|
41
|
+
if (Array.isArray(children)) return children.map((child) => markInspectionRoots(child, owners));
|
|
42
|
+
if (!isValidElement(children)) return children;
|
|
43
|
+
if (children.type === Fragment) return cloneElement(children, { children: markInspectionRoots(children.props.children, owners) });
|
|
44
|
+
if (typeof children.type !== "string" && (typeof children.type !== "object" || !inspectedComposables.has(children.type))) return children;
|
|
45
|
+
let previous = [];
|
|
46
|
+
try {
|
|
47
|
+
const parsed = JSON.parse(children.props["data-rl-owners"] ?? "[]");
|
|
48
|
+
if (Array.isArray(parsed)) previous = parsed.filter((id) => typeof id === "string");
|
|
49
|
+
} catch {}
|
|
50
|
+
return cloneElement(children, { "data-rl-owners": JSON.stringify([...new Set([...previous, ...owners])]) });
|
|
51
|
+
}
|
|
37
52
|
/** Preserve composable metadata while measuring committed React instances, not declarations. */
|
|
38
53
|
function trackComposable(component, store, id) {
|
|
39
54
|
const Tracked = forwardRef(function InspectedComposable(props, ref) {
|
|
40
55
|
useLayoutEffect(() => store.mount(id), [store, id]);
|
|
41
|
-
|
|
56
|
+
const inspectedProps = process.env.NODE_ENV === "production" ? props : {
|
|
42
57
|
...props,
|
|
58
|
+
"data-rl-node": id,
|
|
59
|
+
"data-rl-composable": component.displayName ?? "Composable"
|
|
60
|
+
};
|
|
61
|
+
return createElement(component, ref == null ? inspectedProps : {
|
|
62
|
+
...inspectedProps,
|
|
43
63
|
ref
|
|
44
64
|
});
|
|
45
65
|
});
|
|
66
|
+
inspectedComposables.add(Tracked);
|
|
46
67
|
for (const key of Reflect.ownKeys(component)) {
|
|
47
68
|
if (typeof key === "string" && [
|
|
48
69
|
"name",
|
|
@@ -62,5 +83,5 @@ function trackComposable(component, store, id) {
|
|
|
62
83
|
}
|
|
63
84
|
|
|
64
85
|
//#endregion
|
|
65
|
-
export { inspectDefinition, trackComposable };
|
|
86
|
+
export { inspectDefinition, markInspectionRoots, trackComposable };
|
|
66
87
|
//# sourceMappingURL=inspection.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspection.mjs","names":[],"sources":["../../src/create-config/inspection.ts"],"sourcesContent":["import {\n createElement,\n forwardRef,\n useLayoutEffect,\n type ComponentType,\n} from 'react';\nimport {\n createInspectionStore,\n inspectionId,\n type InspectionStore,\n type SourceLocation,\n} from '@jfdevelops/react-layout-devtools-core';\nimport type { ResourceDefinition } from '../resource';\n\nexport function inspectDefinition(\n resources: readonly ResourceDefinition[],\n source?: SourceLocation\n) {\n const store = createInspectionStore();\n const definition = store.node({\n id: inspectionId('definition'),\n kind: 'definition',\n label: 'Layout definition',\n source,\n });\n const resourceIds = new Map<string, string>();\n\n function visit(\n items: readonly ResourceDefinition[],\n parent: string,\n prefix = ''\n ) {\n for (const item of items) {\n const slug = typeof item === 'string' ? item : item.value;\n const path = prefix ? `${prefix}.${slug}` : slug;\n const id = store.node({\n id: inspectionId('resource'),\n kind: 'resource',\n label: path,\n source,\n details: { path },\n });\n\n resourceIds.set(path, id);\n\n store.edge(parent, id, 'contains');\n\n if (typeof item !== 'string') visit(item.subResources, id, path);\n }\n }\n\n visit(resources, definition);\n\n return { store, definition, resourceIds };\n}\n\nexport interface ActiveInspection {\n store: InspectionStore;\n layout: string;\n resource?: string;\n state: string;\n}\n\n/** Preserve composable metadata while measuring committed React instances, not declarations. */\nexport function trackComposable<T extends object>(\n component: T,\n store: InspectionStore,\n id: string\n): T {\n const Tracked = forwardRef<unknown, Record<string, unknown>>(\n function InspectedComposable(props, ref) {\n useLayoutEffect(() => store.mount(id), [store, id]);\n\n return createElement(\n component as ComponentType<Record<string, unknown>>,\n ref == null ?
|
|
1
|
+
{"version":3,"file":"inspection.mjs","names":[],"sources":["../../src/create-config/inspection.ts"],"sourcesContent":["import {\n createElement,\n cloneElement,\n Fragment,\n isValidElement,\n type ReactNode,\n forwardRef,\n useLayoutEffect,\n type ComponentType,\n} from 'react';\nimport {\n createInspectionStore,\n inspectionId,\n type InspectionStore,\n type SourceLocation,\n} from '@jfdevelops/react-layout-devtools-core';\nimport type { ResourceDefinition } from '../resource';\n\nexport function inspectDefinition(\n resources: readonly ResourceDefinition[],\n source?: SourceLocation\n) {\n const store = createInspectionStore();\n const definition = store.node({\n id: inspectionId('definition'),\n kind: 'definition',\n label: 'Layout definition',\n source,\n });\n const resourceIds = new Map<string, string>();\n\n function visit(\n items: readonly ResourceDefinition[],\n parent: string,\n prefix = ''\n ) {\n for (const item of items) {\n const slug = typeof item === 'string' ? item : item.value;\n const path = prefix ? `${prefix}.${slug}` : slug;\n const id = store.node({\n id: inspectionId('resource'),\n kind: 'resource',\n label: path,\n source,\n details: { path },\n });\n\n resourceIds.set(path, id);\n\n store.edge(parent, id, 'contains');\n\n if (typeof item !== 'string') visit(item.subResources, id, path);\n }\n }\n\n visit(resources, definition);\n\n return { store, definition, resourceIds };\n}\n\nexport interface ActiveInspection {\n store: InspectionStore;\n layout: string;\n resource?: string;\n state: string;\n}\n\nconst inspectedComposables = new WeakSet<object>();\n\n/** Mark existing roots only; never add wrappers or forward props to user components. */\nexport function markInspectionRoots(\n children: ReactNode,\n owners: readonly string[]\n): ReactNode {\n if (process.env.NODE_ENV === 'production') return children;\n if (Array.isArray(children))\n return children.map((child) => markInspectionRoots(child, owners));\n if (\n !isValidElement<{ children?: ReactNode; 'data-rl-owners'?: string }>(\n children\n )\n )\n return children;\n if (children.type === Fragment) {\n return cloneElement(children, {\n children: markInspectionRoots(children.props.children, owners),\n });\n }\n if (\n typeof children.type !== 'string' &&\n (typeof children.type !== 'object' ||\n !inspectedComposables.has(children.type))\n )\n return children;\n let previous: string[] = [];\n try {\n const parsed: unknown = JSON.parse(\n children.props['data-rl-owners'] ?? '[]'\n );\n if (Array.isArray(parsed))\n previous = parsed.filter((id): id is string => typeof id === 'string');\n } catch {}\n return cloneElement(children, {\n 'data-rl-owners': JSON.stringify([...new Set([...previous, ...owners])]),\n });\n}\n\n/** Preserve composable metadata while measuring committed React instances, not declarations. */\nexport function trackComposable<T extends object>(\n component: T,\n store: InspectionStore,\n id: string\n): T {\n const Tracked = forwardRef<unknown, Record<string, unknown>>(\n function InspectedComposable(props, ref) {\n useLayoutEffect(() => store.mount(id), [store, id]);\n\n const inspectedProps =\n process.env.NODE_ENV === 'production'\n ? props\n : {\n ...props,\n 'data-rl-node': id,\n 'data-rl-composable':\n (component as { displayName?: string }).displayName ??\n 'Composable',\n };\n return createElement(\n component as ComponentType<Record<string, unknown>>,\n ref == null ? inspectedProps : { ...inspectedProps, ref }\n );\n }\n );\n\n inspectedComposables.add(Tracked);\n\n for (const key of Reflect.ownKeys(component)) {\n if (\n typeof key === 'string' &&\n [\n 'name',\n 'length',\n 'prototype',\n 'caller',\n 'arguments',\n '$$typeof',\n 'render',\n 'compare',\n 'type',\n ].includes(key)\n )\n continue;\n\n const descriptor = Object.getOwnPropertyDescriptor(component, key);\n\n if (descriptor) Object.defineProperty(Tracked, key, descriptor);\n }\n\n return Tracked as unknown as T;\n}\n"],"mappings":";;;;AAkBA,SAAgB,kBACd,WACA,QACA;CACA,MAAM,QAAQ,sBAAsB;CACpC,MAAM,aAAa,MAAM,KAAK;EAC5B,IAAI,aAAa,YAAY;EAC7B,MAAM;EACN,OAAO;EACP;CACF,CAAC;CACD,MAAM,8BAAc,IAAI,IAAoB;CAE5C,SAAS,MACP,OACA,QACA,SAAS,IACT;EACA,KAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,KAAK;GACpD,MAAM,OAAO,SAAS,GAAG,OAAO,GAAG,SAAS;GAC5C,MAAM,KAAK,MAAM,KAAK;IACpB,IAAI,aAAa,UAAU;IAC3B,MAAM;IACN,OAAO;IACP;IACA,SAAS,EAAE,KAAK;GAClB,CAAC;GAED,YAAY,IAAI,MAAM,EAAE;GAExB,MAAM,KAAK,QAAQ,IAAI,UAAU;GAEjC,IAAI,OAAO,SAAS,UAAU,MAAM,KAAK,cAAc,IAAI,IAAI;EACjE;CACF;CAEA,MAAM,WAAW,UAAU;CAE3B,OAAO;EAAE;EAAO;EAAY;CAAY;AAC1C;AASA,MAAM,uCAAuB,IAAI,QAAgB;;AAGjD,SAAgB,oBACd,UACA,QACW;CACX,IAAI,QAAQ,IAAI,aAAa,cAAc,OAAO;CAClD,IAAI,MAAM,QAAQ,QAAQ,GACxB,OAAO,SAAS,KAAK,UAAU,oBAAoB,OAAO,MAAM,CAAC;CACnE,IACE,CAAC,eACC,QACF,GAEA,OAAO;CACT,IAA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out-configuration-error.cjs');
|
|
2
1
|
const require_invalid_part = require('../errors/invalid-part.cjs');
|
|
3
2
|
const require_invalid_part_type = require('../errors/invalid-part-type.cjs');
|
|
3
|
+
const require_layout_configuration_error = require('../errors/layout-configuration-error.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/create-config/layout-name.ts
|
|
6
6
|
const layoutNamePattern = Symbol("layoutNamePattern");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LayoutConfigurationError } from "../errors/layout-configuration-error.mjs";
|
|
2
1
|
import { InvalidPartError } from "../errors/invalid-part.mjs";
|
|
3
2
|
import { InvalidPartTypeError } from "../errors/invalid-part-type.mjs";
|
|
3
|
+
import { LayoutConfigurationError } from "../errors/layout-configuration-error.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/create-config/layout-name.ts
|
|
6
6
|
const layoutNamePattern = Symbol("layoutNamePattern");
|
|
@@ -2,8 +2,8 @@ const require_lazy_resource_error = require('../errors/lazy-resource-error.cjs')
|
|
|
2
2
|
const require_lazy_boundary = require('../lazy/lazy-boundary.cjs');
|
|
3
3
|
const require_create_lazy_loader = require('../lazy/create-lazy-loader.cjs');
|
|
4
4
|
const require_render_state = require('./render-state.cjs');
|
|
5
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
5
|
let _jfdevelops_react_layout_validator = require("@jfdevelops/react-layout-validator");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
7
|
|
|
8
8
|
//#region src/create-config/lazy-resource-layout.tsx
|
|
9
9
|
function findDefinedLayoutComponent(module, resource) {
|
|
@@ -15,10 +15,6 @@ function findDefinedLayoutComponent(module, resource) {
|
|
|
15
15
|
function createLazyResourceLayout(options, defaults, hooks = {}) {
|
|
16
16
|
const runtime = options;
|
|
17
17
|
const resource = runtime.resource;
|
|
18
|
-
const states = {
|
|
19
|
-
...defaults,
|
|
20
|
-
...runtime.states
|
|
21
|
-
};
|
|
22
18
|
const loader = require_create_lazy_loader.createLazyLoader({
|
|
23
19
|
load: runtime.load,
|
|
24
20
|
select: (module) => findDefinedLayoutComponent(module, resource),
|
|
@@ -28,6 +24,10 @@ function createLazyResourceLayout(options, defaults, hooks = {}) {
|
|
|
28
24
|
const members = /* @__PURE__ */ new Map();
|
|
29
25
|
function createMember(member) {
|
|
30
26
|
function LazyMember(props) {
|
|
27
|
+
const states = {
|
|
28
|
+
...typeof defaults === "function" ? defaults() : defaults,
|
|
29
|
+
...runtime.states
|
|
30
|
+
};
|
|
31
31
|
const Loading = states.Loading;
|
|
32
32
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_lazy_boundary.LazyBoundary, {
|
|
33
33
|
loader,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-resource-layout.cjs","names":["definedResourceLayoutComponentSymbol","LazyResourceModuleShapeError","createLazyLoader","LazyBoundary","componentPropDefinitionsSymbol"],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"sourcesContent":["import { type ComponentProps, type ComponentType } from 'react';\nimport { LazyResourceModuleShapeError } from '../errors/lazy-resource-error';\nimport { componentPropDefinitionsSymbol } from '@jfdevelops/react-layout-validator';\nimport type { ResourcePath, ResourceDefinition } from '../resource';\nimport { definedResourceLayoutComponentSymbol } from './render-state';\nimport {\n createLazyLoader,\n type LazyResourceLoadHooks,\n} from '../lazy/create-lazy-loader';\nimport { LazyBoundary } from '../lazy/lazy-boundary';\nimport type {\n LazyHandle,\n LazyOptions,\n LazyResourceStates,\n} from '../lazy/types';\nexport type {\n LazyResourceErrorComponent,\n LazyResourceLoadingComponent,\n LazyResourceStates,\n} from '../lazy/types';\nexport type { LazyResourceLoadHooks } from '../lazy/create-lazy-loader';\n\ntype DefinedLayoutComponent = ComponentType<any> & {\n readonly [definedResourceLayoutComponentSymbol]: true;\n};\n\ntype UnwrapDefinedLayout<Export> = Export extends DefinedLayoutComponent\n ? Export\n : Export extends { Root: infer Root extends DefinedLayoutComponent }\n ? Root\n : never;\n\ntype DefinedLayoutFromModule<Module> = UnwrapDefinedLayout<\n Module[keyof Module]\n>;\n\ntype LazyUnsupportedStatic =\n | 'makeComposable'\n | 'props'\n | 'resource'\n | typeof componentPropDefinitionsSymbol\n | typeof definedResourceLayoutComponentSymbol;\n\n/**\n * Public surface available before a lazy module resolves. Component metadata\n * and composition factories are intentionally omitted because they cannot be\n * read synchronously without loading the module.\n */\nexport type LazyResourceLayoutComponent<Module> = ComponentType<\n ComponentProps<DefinedLayoutFromModule<Module>>\n> &\n LazyHandle &\n Pick<\n DefinedLayoutFromModule<Module>,\n Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>\n >;\n\n/** Lazy resource options, sharing import and fallback semantics with lazy states. */\nexport type LazyResourceLayoutOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n> = LazyOptions<Module> & {\n resource: ResourcePath<Resources>;\n states?: LazyResourceStates<ResourcePath<Resources>>;\n};\n\nfunction findDefinedLayoutComponent(\n module: Record<string, unknown>,\n resource: string,\n) {\n const components = Object.values(module)\n .map((value) =>\n typeof value === 'object' && value !== null && 'Root' in value\n ? value.Root\n : value,\n )\n .filter(\n (value): value is DefinedLayoutComponent =>\n typeof value === 'function' &&\n definedResourceLayoutComponentSymbol in value,\n );\n if (components.length !== 1)\n throw new LazyResourceModuleShapeError(resource, components.length);\n return components[0];\n}\n\n/** Cached resource component and its compound states, backed by the shared loader. */\nexport function createLazyResourceLayout<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n>(\n options: LazyResourceLayoutOptions<Resources, Module>,\n defaults: LazyResourceStates<any
|
|
1
|
+
{"version":3,"file":"lazy-resource-layout.cjs","names":["definedResourceLayoutComponentSymbol","LazyResourceModuleShapeError","createLazyLoader","LazyBoundary","componentPropDefinitionsSymbol"],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"sourcesContent":["import { type ComponentProps, type ComponentType } from 'react';\nimport { LazyResourceModuleShapeError } from '../errors/lazy-resource-error';\nimport { componentPropDefinitionsSymbol } from '@jfdevelops/react-layout-validator';\nimport type { ResourcePath, ResourceDefinition } from '../resource';\nimport { definedResourceLayoutComponentSymbol } from './render-state';\nimport {\n createLazyLoader,\n type LazyResourceLoadHooks,\n} from '../lazy/create-lazy-loader';\nimport { LazyBoundary } from '../lazy/lazy-boundary';\nimport type {\n LazyHandle,\n LazyOptions,\n LazyResourceStates,\n} from '../lazy/types';\nexport type {\n LazyResourceErrorComponent,\n LazyResourceLoadingComponent,\n LazyResourceStates,\n} from '../lazy/types';\nexport type { LazyResourceLoadHooks } from '../lazy/create-lazy-loader';\n\ntype DefinedLayoutComponent = ComponentType<any> & {\n readonly [definedResourceLayoutComponentSymbol]: true;\n};\n\ntype UnwrapDefinedLayout<Export> = Export extends DefinedLayoutComponent\n ? Export\n : Export extends { Root: infer Root extends DefinedLayoutComponent }\n ? Root\n : never;\n\ntype DefinedLayoutFromModule<Module> = UnwrapDefinedLayout<\n Module[keyof Module]\n>;\n\ntype LazyUnsupportedStatic =\n | 'makeComposable'\n | 'props'\n | 'resource'\n | typeof componentPropDefinitionsSymbol\n | typeof definedResourceLayoutComponentSymbol;\n\n/**\n * Public surface available before a lazy module resolves. Component metadata\n * and composition factories are intentionally omitted because they cannot be\n * read synchronously without loading the module.\n */\nexport type LazyResourceLayoutComponent<Module> = ComponentType<\n ComponentProps<DefinedLayoutFromModule<Module>>\n> &\n LazyHandle &\n Pick<\n DefinedLayoutFromModule<Module>,\n Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>\n >;\n\n/** Lazy resource options, sharing import and fallback semantics with lazy states. */\nexport type LazyResourceLayoutOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n> = LazyOptions<Module> & {\n resource: ResourcePath<Resources>;\n states?: LazyResourceStates<ResourcePath<Resources>>;\n};\n\nfunction findDefinedLayoutComponent(\n module: Record<string, unknown>,\n resource: string,\n) {\n const components = Object.values(module)\n .map((value) =>\n typeof value === 'object' && value !== null && 'Root' in value\n ? value.Root\n : value,\n )\n .filter(\n (value): value is DefinedLayoutComponent =>\n typeof value === 'function' &&\n definedResourceLayoutComponentSymbol in value,\n );\n if (components.length !== 1)\n throw new LazyResourceModuleShapeError(resource, components.length);\n return components[0];\n}\n\n/** Cached resource component and its compound states, backed by the shared loader. */\nexport function createLazyResourceLayout<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n>(\n options: LazyResourceLayoutOptions<Resources, Module>,\n defaults: LazyResourceStates<any> | (() => LazyResourceStates<any>),\n hooks: LazyResourceLoadHooks = {},\n): LazyResourceLayoutComponent<Module> {\n const runtime = options as unknown as LazyOptions<Module> & {\n resource: string;\n states?: LazyResourceStates;\n };\n const resource = runtime.resource;\n const loader = createLazyLoader({\n load: runtime.load,\n select: (module) => findDefinedLayoutComponent(module, resource),\n label: resource,\n hooks,\n });\n const members = new Map<string, ComponentType<any>>();\n function createMember(member?: string) {\n function LazyMember(props: Record<string, unknown>) {\n const states = { ...(typeof defaults === 'function' ? defaults() : defaults), ...runtime.states } as LazyResourceStates;\n const Loading = states.Loading;\n return (\n <LazyBoundary\n loader={loader}\n member={member}\n resource={resource}\n componentProps={props}\n ErrorComponent={states.Error}\n onMount={hooks.onMount}\n fallback={\n runtime.fallback !== undefined ? (\n runtime.fallback\n ) : Loading ? (\n <Loading resource={resource} />\n ) : null\n }\n />\n );\n }\n LazyMember.displayName = `LazyResource(${resource})${member ? `.${member}` : ''}`;\n Object.defineProperties(LazyMember, {\n preload: { value: loader.preload },\n status: { get: () => loader.status },\n });\n return LazyMember;\n }\n const Component = createMember();\n const reservedStatics = new Set<PropertyKey>([\n 'makeComposable',\n 'props',\n 'resource',\n componentPropDefinitionsSymbol,\n definedResourceLayoutComponentSymbol,\n 'contextTypes',\n 'childContextTypes',\n 'contextType',\n 'propTypes',\n 'defaultProps',\n 'getDerivedStateFromProps',\n 'getDerivedStateFromError',\n 'getDefaultProps',\n '$$typeof',\n '_payload',\n '_init',\n 'render',\n 'compare',\n 'type',\n 'then',\n 'catch',\n 'finally',\n 'toJSON',\n 'asymmetricMatch',\n '__esModule',\n 'default',\n ]);\n return new Proxy(Component, {\n get(target, property, receiver) {\n if (Reflect.has(target, property))\n return Reflect.get(target, property, receiver);\n if (\n typeof property !== 'string' ||\n reservedStatics.has(property) ||\n !/^[A-Z]/.test(property)\n )\n return undefined;\n let component = members.get(property);\n if (!component) {\n component = createMember(property);\n members.set(property, component);\n }\n return component;\n },\n has: (target, property) => Reflect.has(target, property),\n }) as unknown as LazyResourceLayoutComponent<Module>;\n}\n"],"mappings":";;;;;;;;AAkEA,SAAS,2BACP,QACA,UACA;CACA,MAAM,aAAa,OAAO,OAAO,MAAM,EACpC,KAAK,UACJ,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,QACrD,MAAM,OACN,KACN,EACC,QACE,UACC,OAAO,UAAU,cACjBA,6DAAwC,KAC5C;CACF,IAAI,WAAW,WAAW,GACxB,MAAM,IAAIC,yDAA6B,UAAU,WAAW,MAAM;CACpE,OAAO,WAAW;AACpB;;AAGA,SAAgB,yBAId,SACA,UACA,QAA+B,CAAC,GACK;CACrC,MAAM,UAAU;CAIhB,MAAM,WAAW,QAAQ;CACzB,MAAM,SAASC,4CAAiB;EAC9B,MAAM,QAAQ;EACd,SAAS,WAAW,2BAA2B,QAAQ,QAAQ;EAC/D,OAAO;EACP;CACF,CAAC;CACD,MAAM,0BAAU,IAAI,IAAgC;CACpD,SAAS,aAAa,QAAiB;EACrC,SAAS,WAAW,OAAgC;GAClD,MAAM,SAAS;IAAE,GAAI,OAAO,aAAa,aAAa,SAAS,IAAI;IAAW,GAAG,QAAQ;GAAO;GAChG,MAAM,UAAU,OAAO;GACvB,OACE,2CAACC,oCAAD;IACU;IACA;IACE;IACV,gBAAgB;IAChB,gBAAgB,OAAO;IACvB,SAAS,MAAM;IACf,UACE,QAAQ,aAAa,SACnB,QAAQ,WACN,UACF,2CAAC,SAAD,EAAmB,SAAW,KAC5B;GAEP;EAEL;EACA,WAAW,cAAc,gBAAgB,SAAS,GAAG,SAAS,IAAI,WAAW;EAC7E,OAAO,iBAAiB,YAAY;GAClC,SAAS,EAAE,OAAO,OAAO,QAAQ;GACjC,QAAQ,EAAE,WAAW,OAAO,OAAO;EACrC,CAAC;EACD,OAAO;CACT;CACA,MAAM,YAAY,aAAa;CAC/B,MAAM,kBAAkB,IAAI,IAAiB;EAC3C;EACA;EACA;EACAC;EACAJ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OAAO,IAAI,MAAM,WAAW;EAC1B,IAAI,QAAQ,UAAU,UAAU;GAC9B,IAAI,QAAQ,IAAI,QAAQ,QAAQ,GAC9B,OAAO,QAAQ,IAAI,QAAQ,UAAU,QAAQ;GAC/C,IACE,OAAO,aAAa,YACpB,gBAAgB,IAAI,QAAQ,KAC5B,CAAC,SAAS,KAAK,QAAQ,GAEvB,OAAO;GACT,IAAI,YAAY,QAAQ,IAAI,QAAQ;GACpC,IAAI,CAAC,WAAW;IACd,YAAY,aAAa,QAAQ;IACjC,QAAQ,IAAI,UAAU,SAAS;GACjC;GACA,OAAO;EACT;EACA,MAAM,QAAQ,aAAa,QAAQ,IAAI,QAAQ,QAAQ;CACzD,CAAC;AACH"}
|
|
@@ -2,8 +2,8 @@ import { LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceLoadin
|
|
|
2
2
|
import { LazyResourceLoadHooks } from "../lazy/create-lazy-loader.cjs";
|
|
3
3
|
import { ResourceDefinition, ResourcePath } from "../resource.cjs";
|
|
4
4
|
import { definedResourceLayoutComponentSymbol } from "./render-state.cjs";
|
|
5
|
-
import { ComponentProps, ComponentType } from "react";
|
|
6
5
|
import { componentPropDefinitionsSymbol } from "@jfdevelops/react-layout-validator";
|
|
6
|
+
import { ComponentProps, ComponentType } from "react";
|
|
7
7
|
|
|
8
8
|
//#region src/create-config/lazy-resource-layout.d.ts
|
|
9
9
|
type DefinedLayoutComponent = ComponentType<any> & {
|
|
@@ -26,7 +26,7 @@ type LazyResourceLayoutOptions<Resources extends ReadonlyArray<ResourceDefinitio
|
|
|
26
26
|
states?: LazyResourceStates<ResourcePath<Resources>>;
|
|
27
27
|
};
|
|
28
28
|
/** Cached resource component and its compound states, backed by the shared loader. */
|
|
29
|
-
declare function createLazyResourceLayout<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>>(options: LazyResourceLayoutOptions<Resources, Module>, defaults: LazyResourceStates<any
|
|
29
|
+
declare function createLazyResourceLayout<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>>(options: LazyResourceLayoutOptions<Resources, Module>, defaults: LazyResourceStates<any> | (() => LazyResourceStates<any>), hooks?: LazyResourceLoadHooks): LazyResourceLayoutComponent<Module>;
|
|
30
30
|
//#endregion
|
|
31
31
|
export { LazyResourceLayoutComponent, LazyResourceLayoutOptions, createLazyResourceLayout };
|
|
32
32
|
//# sourceMappingURL=lazy-resource-layout.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-resource-layout.d.cts","names":[],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"mappings":";;;;;;;;KAsBK,sBAAA,GAAyB,aAAA;EAAA,UAClB,oCAAoC;AAAA;AAAA,KAG3C,mBAAA,WAA8B,MAAA,SAAe,sBAAA,GAC9C,MAAA,GACA,MAAA;EAAiB,IAAA,qBAAyB,sBAAA;AAAA,IACxC,IAAA;AAAA,KAGD,uBAAA,WAAkC,mBAAA,CACrC,MAAA,OAAa,MAAA;AAAA,KAGV,qBAAA,oDAIM,8BAAA,UACA,oCAAoC;;;;;;KAOnC,2BAAA,WAAsC,aAAA,CAChD,cAAA,CAAe,uBAAA,CAAwB,MAAA,MAEvC,UAAA,GACA,IAAA,CACE,uBAAA,CAAwB,MAAA,GACx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A,GAAO,qBAAA,GACN,2BAAA,CAA4B,MAAA"}
|
|
@@ -2,8 +2,8 @@ import { LazyHandle, LazyOptions, LazyResourceErrorComponent, LazyResourceLoadin
|
|
|
2
2
|
import { LazyResourceLoadHooks } from "../lazy/create-lazy-loader.mjs";
|
|
3
3
|
import { ResourceDefinition, ResourcePath } from "../resource.mjs";
|
|
4
4
|
import { definedResourceLayoutComponentSymbol } from "./render-state.mjs";
|
|
5
|
-
import { ComponentProps, ComponentType } from "react";
|
|
6
5
|
import { componentPropDefinitionsSymbol } from "@jfdevelops/react-layout-validator";
|
|
6
|
+
import { ComponentProps, ComponentType } from "react";
|
|
7
7
|
|
|
8
8
|
//#region src/create-config/lazy-resource-layout.d.ts
|
|
9
9
|
type DefinedLayoutComponent = ComponentType<any> & {
|
|
@@ -26,7 +26,7 @@ type LazyResourceLayoutOptions<Resources extends ReadonlyArray<ResourceDefinitio
|
|
|
26
26
|
states?: LazyResourceStates<ResourcePath<Resources>>;
|
|
27
27
|
};
|
|
28
28
|
/** Cached resource component and its compound states, backed by the shared loader. */
|
|
29
|
-
declare function createLazyResourceLayout<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>>(options: LazyResourceLayoutOptions<Resources, Module>, defaults: LazyResourceStates<any
|
|
29
|
+
declare function createLazyResourceLayout<Resources extends ReadonlyArray<ResourceDefinition>, Module extends Record<string, unknown>>(options: LazyResourceLayoutOptions<Resources, Module>, defaults: LazyResourceStates<any> | (() => LazyResourceStates<any>), hooks?: LazyResourceLoadHooks): LazyResourceLayoutComponent<Module>;
|
|
30
30
|
//#endregion
|
|
31
31
|
export { LazyResourceLayoutComponent, LazyResourceLayoutOptions, createLazyResourceLayout };
|
|
32
32
|
//# sourceMappingURL=lazy-resource-layout.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-resource-layout.d.mts","names":[],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"mappings":";;;;;;;;KAsBK,sBAAA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MAAA,GACxB,OAAA,OAAc,uBAAA,CAAwB,MAAA,GAAS,qBAAA;;KAIvC,yBAAA,mBACQ,aAAA,CAAc,kBAAA,kBACjB,MAAA,qBACb,WAAA,CAAY,MAAA;EACd,QAAA,EAAU,YAAA,CAAa,SAAA;EACvB,MAAA,GAAS,kBAAA,CAAmB,YAAA,CAAa,SAAA;AAAA;;iBAwB3B,wBAAA,mBACI,aAAA,CAAc,kBAAA,kBACjB,MAAA,mBAEf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,MAAA,GAC9C,QAAA,EAAU,kBAAA,eAAiC,kBAAA,QAC3C,KAAA,GAAO,qBAAA,GACN,2BAAA,CAA4B,MAAA"}
|
|
@@ -2,8 +2,8 @@ import { LazyResourceModuleShapeError } from "../errors/lazy-resource-error.mjs"
|
|
|
2
2
|
import { LazyBoundary } from "../lazy/lazy-boundary.mjs";
|
|
3
3
|
import { createLazyLoader } from "../lazy/create-lazy-loader.mjs";
|
|
4
4
|
import { definedResourceLayoutComponentSymbol } from "./render-state.mjs";
|
|
5
|
-
import { jsx } from "react/jsx-runtime";
|
|
6
5
|
import { componentPropDefinitionsSymbol } from "@jfdevelops/react-layout-validator";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
|
|
8
8
|
//#region src/create-config/lazy-resource-layout.tsx
|
|
9
9
|
function findDefinedLayoutComponent(module, resource) {
|
|
@@ -15,10 +15,6 @@ function findDefinedLayoutComponent(module, resource) {
|
|
|
15
15
|
function createLazyResourceLayout(options, defaults, hooks = {}) {
|
|
16
16
|
const runtime = options;
|
|
17
17
|
const resource = runtime.resource;
|
|
18
|
-
const states = {
|
|
19
|
-
...defaults,
|
|
20
|
-
...runtime.states
|
|
21
|
-
};
|
|
22
18
|
const loader = createLazyLoader({
|
|
23
19
|
load: runtime.load,
|
|
24
20
|
select: (module) => findDefinedLayoutComponent(module, resource),
|
|
@@ -28,6 +24,10 @@ function createLazyResourceLayout(options, defaults, hooks = {}) {
|
|
|
28
24
|
const members = /* @__PURE__ */ new Map();
|
|
29
25
|
function createMember(member) {
|
|
30
26
|
function LazyMember(props) {
|
|
27
|
+
const states = {
|
|
28
|
+
...typeof defaults === "function" ? defaults() : defaults,
|
|
29
|
+
...runtime.states
|
|
30
|
+
};
|
|
31
31
|
const Loading = states.Loading;
|
|
32
32
|
return /* @__PURE__ */ jsx(LazyBoundary, {
|
|
33
33
|
loader,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-resource-layout.mjs","names":[],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"sourcesContent":["import { type ComponentProps, type ComponentType } from 'react';\nimport { LazyResourceModuleShapeError } from '../errors/lazy-resource-error';\nimport { componentPropDefinitionsSymbol } from '@jfdevelops/react-layout-validator';\nimport type { ResourcePath, ResourceDefinition } from '../resource';\nimport { definedResourceLayoutComponentSymbol } from './render-state';\nimport {\n createLazyLoader,\n type LazyResourceLoadHooks,\n} from '../lazy/create-lazy-loader';\nimport { LazyBoundary } from '../lazy/lazy-boundary';\nimport type {\n LazyHandle,\n LazyOptions,\n LazyResourceStates,\n} from '../lazy/types';\nexport type {\n LazyResourceErrorComponent,\n LazyResourceLoadingComponent,\n LazyResourceStates,\n} from '../lazy/types';\nexport type { LazyResourceLoadHooks } from '../lazy/create-lazy-loader';\n\ntype DefinedLayoutComponent = ComponentType<any> & {\n readonly [definedResourceLayoutComponentSymbol]: true;\n};\n\ntype UnwrapDefinedLayout<Export> = Export extends DefinedLayoutComponent\n ? Export\n : Export extends { Root: infer Root extends DefinedLayoutComponent }\n ? Root\n : never;\n\ntype DefinedLayoutFromModule<Module> = UnwrapDefinedLayout<\n Module[keyof Module]\n>;\n\ntype LazyUnsupportedStatic =\n | 'makeComposable'\n | 'props'\n | 'resource'\n | typeof componentPropDefinitionsSymbol\n | typeof definedResourceLayoutComponentSymbol;\n\n/**\n * Public surface available before a lazy module resolves. Component metadata\n * and composition factories are intentionally omitted because they cannot be\n * read synchronously without loading the module.\n */\nexport type LazyResourceLayoutComponent<Module> = ComponentType<\n ComponentProps<DefinedLayoutFromModule<Module>>\n> &\n LazyHandle &\n Pick<\n DefinedLayoutFromModule<Module>,\n Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>\n >;\n\n/** Lazy resource options, sharing import and fallback semantics with lazy states. */\nexport type LazyResourceLayoutOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n> = LazyOptions<Module> & {\n resource: ResourcePath<Resources>;\n states?: LazyResourceStates<ResourcePath<Resources>>;\n};\n\nfunction findDefinedLayoutComponent(\n module: Record<string, unknown>,\n resource: string,\n) {\n const components = Object.values(module)\n .map((value) =>\n typeof value === 'object' && value !== null && 'Root' in value\n ? value.Root\n : value,\n )\n .filter(\n (value): value is DefinedLayoutComponent =>\n typeof value === 'function' &&\n definedResourceLayoutComponentSymbol in value,\n );\n if (components.length !== 1)\n throw new LazyResourceModuleShapeError(resource, components.length);\n return components[0];\n}\n\n/** Cached resource component and its compound states, backed by the shared loader. */\nexport function createLazyResourceLayout<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n>(\n options: LazyResourceLayoutOptions<Resources, Module>,\n defaults: LazyResourceStates<any
|
|
1
|
+
{"version":3,"file":"lazy-resource-layout.mjs","names":[],"sources":["../../src/create-config/lazy-resource-layout.tsx"],"sourcesContent":["import { type ComponentProps, type ComponentType } from 'react';\nimport { LazyResourceModuleShapeError } from '../errors/lazy-resource-error';\nimport { componentPropDefinitionsSymbol } from '@jfdevelops/react-layout-validator';\nimport type { ResourcePath, ResourceDefinition } from '../resource';\nimport { definedResourceLayoutComponentSymbol } from './render-state';\nimport {\n createLazyLoader,\n type LazyResourceLoadHooks,\n} from '../lazy/create-lazy-loader';\nimport { LazyBoundary } from '../lazy/lazy-boundary';\nimport type {\n LazyHandle,\n LazyOptions,\n LazyResourceStates,\n} from '../lazy/types';\nexport type {\n LazyResourceErrorComponent,\n LazyResourceLoadingComponent,\n LazyResourceStates,\n} from '../lazy/types';\nexport type { LazyResourceLoadHooks } from '../lazy/create-lazy-loader';\n\ntype DefinedLayoutComponent = ComponentType<any> & {\n readonly [definedResourceLayoutComponentSymbol]: true;\n};\n\ntype UnwrapDefinedLayout<Export> = Export extends DefinedLayoutComponent\n ? Export\n : Export extends { Root: infer Root extends DefinedLayoutComponent }\n ? Root\n : never;\n\ntype DefinedLayoutFromModule<Module> = UnwrapDefinedLayout<\n Module[keyof Module]\n>;\n\ntype LazyUnsupportedStatic =\n | 'makeComposable'\n | 'props'\n | 'resource'\n | typeof componentPropDefinitionsSymbol\n | typeof definedResourceLayoutComponentSymbol;\n\n/**\n * Public surface available before a lazy module resolves. Component metadata\n * and composition factories are intentionally omitted because they cannot be\n * read synchronously without loading the module.\n */\nexport type LazyResourceLayoutComponent<Module> = ComponentType<\n ComponentProps<DefinedLayoutFromModule<Module>>\n> &\n LazyHandle &\n Pick<\n DefinedLayoutFromModule<Module>,\n Exclude<keyof DefinedLayoutFromModule<Module>, LazyUnsupportedStatic>\n >;\n\n/** Lazy resource options, sharing import and fallback semantics with lazy states. */\nexport type LazyResourceLayoutOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n> = LazyOptions<Module> & {\n resource: ResourcePath<Resources>;\n states?: LazyResourceStates<ResourcePath<Resources>>;\n};\n\nfunction findDefinedLayoutComponent(\n module: Record<string, unknown>,\n resource: string,\n) {\n const components = Object.values(module)\n .map((value) =>\n typeof value === 'object' && value !== null && 'Root' in value\n ? value.Root\n : value,\n )\n .filter(\n (value): value is DefinedLayoutComponent =>\n typeof value === 'function' &&\n definedResourceLayoutComponentSymbol in value,\n );\n if (components.length !== 1)\n throw new LazyResourceModuleShapeError(resource, components.length);\n return components[0];\n}\n\n/** Cached resource component and its compound states, backed by the shared loader. */\nexport function createLazyResourceLayout<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Module extends Record<string, unknown>,\n>(\n options: LazyResourceLayoutOptions<Resources, Module>,\n defaults: LazyResourceStates<any> | (() => LazyResourceStates<any>),\n hooks: LazyResourceLoadHooks = {},\n): LazyResourceLayoutComponent<Module> {\n const runtime = options as unknown as LazyOptions<Module> & {\n resource: string;\n states?: LazyResourceStates;\n };\n const resource = runtime.resource;\n const loader = createLazyLoader({\n load: runtime.load,\n select: (module) => findDefinedLayoutComponent(module, resource),\n label: resource,\n hooks,\n });\n const members = new Map<string, ComponentType<any>>();\n function createMember(member?: string) {\n function LazyMember(props: Record<string, unknown>) {\n const states = { ...(typeof defaults === 'function' ? defaults() : defaults), ...runtime.states } as LazyResourceStates;\n const Loading = states.Loading;\n return (\n <LazyBoundary\n loader={loader}\n member={member}\n resource={resource}\n componentProps={props}\n ErrorComponent={states.Error}\n onMount={hooks.onMount}\n fallback={\n runtime.fallback !== undefined ? (\n runtime.fallback\n ) : Loading ? (\n <Loading resource={resource} />\n ) : null\n }\n />\n );\n }\n LazyMember.displayName = `LazyResource(${resource})${member ? `.${member}` : ''}`;\n Object.defineProperties(LazyMember, {\n preload: { value: loader.preload },\n status: { get: () => loader.status },\n });\n return LazyMember;\n }\n const Component = createMember();\n const reservedStatics = new Set<PropertyKey>([\n 'makeComposable',\n 'props',\n 'resource',\n componentPropDefinitionsSymbol,\n definedResourceLayoutComponentSymbol,\n 'contextTypes',\n 'childContextTypes',\n 'contextType',\n 'propTypes',\n 'defaultProps',\n 'getDerivedStateFromProps',\n 'getDerivedStateFromError',\n 'getDefaultProps',\n '$$typeof',\n '_payload',\n '_init',\n 'render',\n 'compare',\n 'type',\n 'then',\n 'catch',\n 'finally',\n 'toJSON',\n 'asymmetricMatch',\n '__esModule',\n 'default',\n ]);\n return new Proxy(Component, {\n get(target, property, receiver) {\n if (Reflect.has(target, property))\n return Reflect.get(target, property, receiver);\n if (\n typeof property !== 'string' ||\n reservedStatics.has(property) ||\n !/^[A-Z]/.test(property)\n )\n return undefined;\n let component = members.get(property);\n if (!component) {\n component = createMember(property);\n members.set(property, component);\n }\n return component;\n },\n has: (target, property) => Reflect.has(target, property),\n }) as unknown as LazyResourceLayoutComponent<Module>;\n}\n"],"mappings":";;;;;;;;AAkEA,SAAS,2BACP,QACA,UACA;CACA,MAAM,aAAa,OAAO,OAAO,MAAM,EACpC,KAAK,UACJ,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,QACrD,MAAM,OACN,KACN,EACC,QACE,UACC,OAAO,UAAU,cACjB,wCAAwC,KAC5C;CACF,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,6BAA6B,UAAU,WAAW,MAAM;CACpE,OAAO,WAAW;AACpB;;AAGA,SAAgB,yBAId,SACA,UACA,QAA+B,CAAC,GACK;CACrC,MAAM,UAAU;CAIhB,MAAM,WAAW,QAAQ;CACzB,MAAM,SAAS,iBAAiB;EAC9B,MAAM,QAAQ;EACd,SAAS,WAAW,2BAA2B,QAAQ,QAAQ;EAC/D,OAAO;EACP;CACF,CAAC;CACD,MAAM,0BAAU,IAAI,IAAgC;CACpD,SAAS,aAAa,QAAiB;EACrC,SAAS,WAAW,OAAgC;GAClD,MAAM,SAAS;IAAE,GAAI,OAAO,aAAa,aAAa,SAAS,IAAI;IAAW,GAAG,QAAQ;GAAO;GAChG,MAAM,UAAU,OAAO;GACvB,OACE,oBAAC,cAAD;IACU;IACA;IACE;IACV,gBAAgB;IAChB,gBAAgB,OAAO;IACvB,SAAS,MAAM;IACf,UACE,QAAQ,aAAa,SACnB,QAAQ,WACN,UACF,oBAAC,SAAD,EAAmB,SAAW,KAC5B;GAEP;EAEL;EACA,WAAW,cAAc,gBAAgB,SAAS,GAAG,SAAS,IAAI,WAAW;EAC7E,OAAO,iBAAiB,YAAY;GAClC,SAAS,EAAE,OAAO,OAAO,QAAQ;GACjC,QAAQ,EAAE,WAAW,OAAO,OAAO;EACrC,CAAC;EACD,OAAO;CACT;CACA,MAAM,YAAY,aAAa;CAC/B,MAAM,kBAAkB,IAAI,IAAiB;EAC3C;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OAAO,IAAI,MAAM,WAAW;EAC1B,IAAI,QAAQ,UAAU,UAAU;GAC9B,IAAI,QAAQ,IAAI,QAAQ,QAAQ,GAC9B,OAAO,QAAQ,IAAI,QAAQ,UAAU,QAAQ;GAC/C,IACE,OAAO,aAAa,YACpB,gBAAgB,IAAI,QAAQ,KAC5B,CAAC,SAAS,KAAK,QAAQ,GAEvB,OAAO;GACT,IAAI,YAAY,QAAQ,IAAI,QAAQ;GACpC,IAAI,CAAC,WAAW;IACd,YAAY,aAAa,QAAQ;IACjC,QAAQ,IAAI,UAAU,SAAS;GACjC;GACA,OAAO;EACT;EACA,MAAM,QAAQ,aAAa,QAAQ,IAAI,QAAQ,QAAQ;CACzD,CAAC;AACH"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_layout_configuration_error = require('../errors/layout-configuration-error.cjs');
|
|
2
2
|
const require_lazy_resource_error = require('../errors/lazy-resource-error.cjs');
|
|
3
|
+
const require_custom_props = require('../custom-props.cjs');
|
|
3
4
|
const require_state_composable = require('./state-composable.cjs');
|
|
4
5
|
const require_props = require('../props.cjs');
|
|
5
6
|
const require_create_lazy_loader = require('../lazy/create-lazy-loader.cjs');
|
|
@@ -71,7 +72,7 @@ function createRenderStateBuilder(_arguments, environment) {
|
|
|
71
72
|
const includes = input.props?.include ?? Object.fromEntries(Object.entries({
|
|
72
73
|
...source.props?.include,
|
|
73
74
|
...Object.fromEntries(Object.entries(source.props?.custom ?? {}).map(([key, prop]) => [key, {
|
|
74
|
-
required: prop.visibility !== "optional",
|
|
75
|
+
required: typeof prop === "string" ? prop === "required" : prop.visibility !== "optional",
|
|
75
76
|
suppliedVia: "component"
|
|
76
77
|
}]))
|
|
77
78
|
}).filter(([key]) => !(key in custom)));
|
|
@@ -86,7 +87,7 @@ function createRenderStateBuilder(_arguments, environment) {
|
|
|
86
87
|
const inherited = source.composables?.(create, states) ?? {};
|
|
87
88
|
const local = input.composables?.(create, states) ?? {};
|
|
88
89
|
if (Object.prototype.hasOwnProperty.call(local, "Ref")) throw new require_layout_configuration_error.LayoutConfigurationError("Composable name \"Ref\" is reserved by fromState");
|
|
89
|
-
const schemas = Object.assign({}, ...(0, _jfdevelops_react_layout_composables.collectComposablePresetEntries)(inherited).map(({ props }) => props), source.props?.custom);
|
|
90
|
+
const schemas = Object.assign({}, ...(0, _jfdevelops_react_layout_composables.collectComposablePresetEntries)(inherited).map(({ props }) => props), require_custom_props.normalizeCustomProps(source.props?.custom ?? {}));
|
|
90
91
|
const selected = Object.fromEntries(Object.entries(schemas).filter(([key]) => key in includes));
|
|
91
92
|
const referenceSource = {
|
|
92
93
|
...source,
|