@jfdevelops/react-layout 0.15.1 → 0.17.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/define-layout.cjs +15 -4
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +31 -5
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +31 -5
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +14 -3
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/create-config/for-resources/create-component.d.cts +284 -0
- package/dist/create-config/for-resources/create-component.d.cts.map +1 -0
- package/dist/create-config/for-resources/create-component.d.mts +284 -0
- package/dist/create-config/for-resources/create-component.d.mts.map +1 -0
- package/dist/create-config/{for-resources.cjs → for-resources/create-for-resources.cjs} +78 -39
- package/dist/create-config/for-resources/create-for-resources.cjs.map +1 -0
- package/dist/create-config/for-resources/create-for-resources.d.cts +1 -0
- package/dist/create-config/for-resources/create-for-resources.d.mts +1 -0
- package/dist/create-config/{for-resources.mjs → for-resources/create-for-resources.mjs} +77 -38
- package/dist/create-config/for-resources/create-for-resources.mjs.map +1 -0
- package/dist/create-config/for-resources/index.d.cts +1 -0
- package/dist/create-config/for-resources/index.d.mts +1 -0
- package/dist/create-config/for-resources/resource-selection.d.cts +47 -0
- package/dist/create-config/for-resources/resource-selection.d.cts.map +1 -0
- package/dist/create-config/for-resources/resource-selection.d.mts +47 -0
- package/dist/create-config/for-resources/resource-selection.d.mts.map +1 -0
- package/dist/create-config/for-resources/scoped-layout.d.cts +185 -0
- package/dist/create-config/for-resources/scoped-layout.d.cts.map +1 -0
- package/dist/create-config/for-resources/scoped-layout.d.mts +185 -0
- package/dist/create-config/for-resources/scoped-layout.d.mts.map +1 -0
- package/dist/create-config/for-resources/scoped-render.cjs +103 -0
- package/dist/create-config/for-resources/scoped-render.cjs.map +1 -0
- package/dist/create-config/for-resources/scoped-render.d.cts +18 -0
- package/dist/create-config/for-resources/scoped-render.d.cts.map +1 -0
- package/dist/create-config/for-resources/scoped-render.d.mts +18 -0
- package/dist/create-config/for-resources/scoped-render.d.mts.map +1 -0
- package/dist/create-config/for-resources/scoped-render.mjs +100 -0
- package/dist/create-config/for-resources/scoped-render.mjs.map +1 -0
- package/dist/create-config/index.d.cts +1 -1
- package/dist/create-config/index.d.mts +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/props.d.cts +22 -1
- package/dist/props.d.cts.map +1 -1
- package/dist/props.d.mts +22 -1
- package/dist/props.d.mts.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +3 -2
- package/skills/build-react-layouts/SKILL.md +132 -0
- package/skills/build-react-layouts/agents/openai.yaml +4 -0
- package/skills/build-react-layouts/references/architecture.md +184 -0
- package/skills/build-react-layouts/references/factory-patterns.md +156 -0
- package/skills/build-react-layouts/references/routing-and-navigation.md +174 -0
- package/dist/create-config/for-resources.cjs.map +0 -1
- package/dist/create-config/for-resources.d.cts +0 -358
- package/dist/create-config/for-resources.d.cts.map +0 -1
- package/dist/create-config/for-resources.d.mts +0 -358
- package/dist/create-config/for-resources.d.mts.map +0 -1
- package/dist/create-config/for-resources.mjs.map +0 -1
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
import { BaseComponent, Show } from "../utils.mjs";
|
|
2
|
-
import { LayoutResourceKey, ResourceDefinition } from "../resource.mjs";
|
|
3
|
-
import { InPropsDefinition, InPropsObject, IncludedProps, MergedLayoutInProps, ResolvedIncludedPropsAsDefined } from "../props.mjs";
|
|
4
|
-
import { CreateLayoutForResourceOptions, CreateResourceLayoutOptionsBase, CreatedLayoutForResource, SetDefaultPropForResourceFn } from "./for-resource.mjs";
|
|
5
|
-
import { LayoutIncludeProps, LayoutPropsForResource, ResourceLayoutComponent } from "./define-layout.mjs";
|
|
6
|
-
import { ComposableComponents, ComposableResourceLayout } from "@jfdevelops/react-layout-composables";
|
|
7
|
-
import { ResolveProps, ResolvedBuiltPropShape } from "@jfdevelops/react-layout-validator";
|
|
8
|
-
import { JSX, ReactNode } from "react";
|
|
9
|
-
|
|
10
|
-
//#region src/create-config/for-resources.d.ts
|
|
11
|
-
type CapitalizedResource<Resource extends string> = Resource extends Resource ? {
|
|
12
|
-
toLowerCase: () => Lowercase<Capitalize<Resource>>;
|
|
13
|
-
} & Capitalize<Resource> : never;
|
|
14
|
-
type ResourceLayoutNames<Resource extends string, CallbackName extends string = string> = { [TargetResource in Resource]?: string | ((resource: CapitalizedResource<TargetResource>) => CallbackName) };
|
|
15
|
-
type AtLeastOneResourceLayoutNameKey<Resource extends string> = { [TargetResource in Resource]: Record<TargetResource, unknown> & Partial<Record<Exclude<Resource, TargetResource>, unknown>> }[Resource];
|
|
16
|
-
type SelectedResourceLayoutNames<Resource extends string, SelectedResource extends Resource, CallbackName extends string> = { [TargetResource in Resource as TargetResource extends SelectedResource ? TargetResource : never]?: string | ((resource: CapitalizedResource<TargetResource>) => CallbackName) };
|
|
17
|
-
type ResourceLayoutSelection<Resources extends ReadonlyArray<ResourceDefinition>, CallbackName extends string = string> = { [Resource in LayoutResourceKey<Resources>]?: {
|
|
18
|
-
name?: string | ((resource: CapitalizedResource<Resource>) => CallbackName);
|
|
19
|
-
} };
|
|
20
|
-
type AtLeastOneResourceLayoutSelection<Resources extends ReadonlyArray<ResourceDefinition>, CallbackName extends string> = { [Resource in LayoutResourceKey<Resources>]: Required<Pick<ResourceLayoutSelection<Resources, CallbackName>, Resource>> & Omit<ResourceLayoutSelection<Resources, CallbackName>, Resource> }[LayoutResourceKey<Resources>];
|
|
21
|
-
type SelectedLayoutResources<Resources extends ReadonlyArray<ResourceDefinition>, Arguments extends ReadonlyArray<unknown>> = Arguments extends ReadonlyArray<LayoutResourceKey<Resources>> ? Arguments[number] : Arguments[0] extends {
|
|
22
|
-
resources: ReadonlyArray<infer Resource>;
|
|
23
|
-
} ? Resource & LayoutResourceKey<Resources> : keyof Arguments[0] & LayoutResourceKey<Resources>;
|
|
24
|
-
type ResolveResourceLayoutName<Name> = Name extends ((...args: never[]) => infer Result) ? Result & string : Name extends string ? Name : string;
|
|
25
|
-
type NormalizeCapitalizedResourceName<Name extends string, Resource extends string> = Name extends Name ? NormalizeCapitalizedResourceNameMatch<Name, Resource> extends infer Match ? [Match] extends [never] ? Name : Match : never : never;
|
|
26
|
-
type NormalizeCapitalizedResourceNameMatch<Name extends string, Resource extends string> = Resource extends Resource ? Name extends `${CapitalizedResource<Resource>}${infer Suffix}` ? `${Capitalize<Resource>}${Suffix}` : never : never;
|
|
27
|
-
type SelectedResourceLayoutName<Arguments, Resource extends string> = Arguments extends ReadonlyArray<string> ? string : Arguments extends readonly [infer Options] ? Options extends {
|
|
28
|
-
resources: ReadonlyArray<string>;
|
|
29
|
-
name?: infer Name;
|
|
30
|
-
} ? Name extends ((...args: never[]) => unknown) ? ResolveResourceLayoutName<Name> : Name extends Record<Resource, infer ResourceName> ? ResolveResourceLayoutName<ResourceName> : string : Options extends Record<Resource, infer ResourceOptions> ? ResourceOptions extends {
|
|
31
|
-
name?: infer Name;
|
|
32
|
-
} ? ResolveResourceLayoutName<Name> : string : string : string;
|
|
33
|
-
type NormalizeResourceLayoutNames<Names, CallbackName extends string> = { [Resource in keyof Names]: Names[Resource] extends ((...args: never[]) => unknown) ? (resource: CapitalizedResource<Resource & string>) => NormalizeCapitalizedResourceName<CallbackName, Resource & string> : Names[Resource] };
|
|
34
|
-
type NormalizeResourceLayoutSelection<Selection> = { [Resource in keyof Selection]: Selection[Resource] extends {
|
|
35
|
-
name: infer Name;
|
|
36
|
-
} ? {
|
|
37
|
-
name: Name extends ((...args: never[]) => unknown) ? (resource: CapitalizedResource<Resource & string>) => NormalizeCapitalizedResourceName<ResolveResourceLayoutName<Name>, Resource & string> : Name;
|
|
38
|
-
} : Selection[Resource] };
|
|
39
|
-
type SharedResourceLayoutArguments<Resources extends ReadonlyArray<ResourceDefinition>, ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>, Name extends string> = readonly [{
|
|
40
|
-
resources: ResourceKeys;
|
|
41
|
-
name: (resource: CapitalizedResource<ResourceKeys[number]>) => NormalizeCapitalizedResourceName<Name, ResourceKeys[number]>;
|
|
42
|
-
}];
|
|
43
|
-
type MappedResourceLayoutArguments<Resources extends ReadonlyArray<ResourceDefinition>, ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>, Names, CallbackName extends string> = readonly [{
|
|
44
|
-
resources: ResourceKeys;
|
|
45
|
-
name: NormalizeResourceLayoutNames<Names, CallbackName>;
|
|
46
|
-
}];
|
|
47
|
-
type SelectedResourceLayoutArguments<Selection> = readonly [NormalizeResourceLayoutSelection<Selection>];
|
|
48
|
-
type HasResourceLayoutName<Arguments, Resource extends string> = Arguments extends ReadonlyArray<string> ? false : Arguments extends readonly [infer Options] ? Options extends {
|
|
49
|
-
resources: ReadonlyArray<string>;
|
|
50
|
-
name: infer Name;
|
|
51
|
-
} ? Name extends ((...args: never[]) => unknown) ? true : Name extends Record<Resource, unknown> ? true : false : Options extends Record<Resource, infer ResourceOptions> ? 'name' extends keyof ResourceOptions ? true : false : false : false;
|
|
52
|
-
type ScopedCreateResourceLayoutOptions<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, Arguments extends ReadonlyArray<unknown>, Name extends string, Resource extends SelectedLayoutResources<Resources, Arguments>, Props extends InPropsObject> = LayoutPropsForResource<Resources, InProps, Composables> & {
|
|
53
|
-
resource: Resource;
|
|
54
|
-
props?: Props;
|
|
55
|
-
} & (HasResourceLayoutName<Arguments, Resource> extends true ? {
|
|
56
|
-
name?: Name;
|
|
57
|
-
} : {
|
|
58
|
-
name: Name;
|
|
59
|
-
});
|
|
60
|
-
type ScopedCreateResourceLayoutFnImpl<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, Arguments extends ReadonlyArray<unknown>, CustomProps extends InPropsObject> = <Resource extends SelectedLayoutResources<Resources, Arguments>, Name extends string = SelectedResourceLayoutName<Arguments, Resource>, Props extends InPropsObject = {}>(options: ScopedCreateResourceLayoutOptions<Resources, InProps, Composables, Arguments, Name, Resource, Props>) => ResourceLayoutComponent<Name, CustomProps, Composables, Resource>;
|
|
61
|
-
type ScopedCreateLayoutForResource<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, Arguments extends ReadonlyArray<unknown>, CustomProps extends InPropsObject> = <Resource extends SelectedLayoutResources<Resources, Arguments>, Name extends string = SelectedResourceLayoutName<Arguments, Resource>>(options: CreateLayoutForResourceOptions<Resources, Name, Resource>) => CreatedLayoutForResource<Resources, InProps, Composables, Name, Resource, CustomProps> & {
|
|
62
|
-
setDefaults: SetDefaultPropForResourceFn<Resources, InProps, Composables, Name, Resource, CustomProps>;
|
|
63
|
-
};
|
|
64
|
-
type ScopedCreateResourceLayoutMakeComposableFn<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, Arguments extends ReadonlyArray<unknown>> = <Resource extends SelectedLayoutResources<Resources, Arguments>, Name extends string = SelectedResourceLayoutName<Arguments, Resource>, Props extends InPropsObject = {}>(options: Omit<CreateResourceLayoutOptionsBase<Resources, Name, Resource>, 'name'> & Partial<LayoutPropsForResource<Resources, InProps, Composables>> & {
|
|
65
|
-
props?: Props;
|
|
66
|
-
} & (HasResourceLayoutName<Arguments, Resource> extends true ? {
|
|
67
|
-
name?: Name;
|
|
68
|
-
} : {
|
|
69
|
-
name: Name;
|
|
70
|
-
})) => ComposableResourceLayout<Composables, Name, any, any, any>;
|
|
71
|
-
type ScopedComponentAvailableProps<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, LayoutCustomProps extends InPropsObject> = MergedLayoutInProps<Resources, InProps, Composables> & LayoutCustomProps;
|
|
72
|
-
type ScopedResourceComponentProps<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, LayoutCustomProps extends InPropsObject, ComponentIncludeProps extends IncludedProps<ScopedComponentAvailableProps<Resources, InProps, Composables, LayoutCustomProps>>, ComponentCustomProps extends InPropsObject, Resource extends string> = Show<Omit<ResolvedIncludedPropsAsDefined<ScopedComponentAvailableProps<Resources, InProps, Composables, LayoutCustomProps>, ComponentIncludeProps> & ResolvedBuiltPropShape<ComponentCustomProps>, 'children' | 'resource'> & {
|
|
73
|
-
children?: ReactNode;
|
|
74
|
-
resource: Resource;
|
|
75
|
-
}>;
|
|
76
|
-
/**
|
|
77
|
-
* Fields reverse-inferred from each scoped component declaration. Only `props`
|
|
78
|
-
* belongs here — putting `render` in the reverse map makes TypeScript infer it
|
|
79
|
-
* as `unknown` (function types don't reverse-map cleanly). `render` is supplied
|
|
80
|
-
* by the constraint intersection instead, like the playground's `transform`.
|
|
81
|
-
*/
|
|
82
|
-
type ScopedComponentShape = {
|
|
83
|
-
props?: InPropsObject;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Homomorphic pick of reverse-mapped scoped-component fields. Paired with a
|
|
87
|
-
* mapped type over the components object, this lets each entry's inferred
|
|
88
|
-
* `props` flow into sibling render signatures.
|
|
89
|
-
*/
|
|
90
|
-
type JustScopedComponent<T> = { [Key in keyof T & keyof ScopedComponentShape]: T[Key] };
|
|
91
|
-
/**
|
|
92
|
-
* Resources with no `components` reverse-infer as `unknown`. Treat that as an
|
|
93
|
-
* empty map so sibling/context access stays closed.
|
|
94
|
-
*/
|
|
95
|
-
type NormalizeScopedComponentsMap<Components> = unknown extends Components ? {} : Components extends Record<string, unknown> ? Components : {};
|
|
96
|
-
/** Extracts the prop definitions declared on a scoped component. */
|
|
97
|
-
type ScopedComponentOwnProps<Definition> = Definition extends {
|
|
98
|
-
props: infer Props;
|
|
99
|
-
} ? Props extends InPropsObject ? Props : {} : {};
|
|
100
|
-
/**
|
|
101
|
-
* A scoped component's call signature. Components that declare no props are
|
|
102
|
-
* callable with no arguments.
|
|
103
|
-
*/
|
|
104
|
-
type ScopedComponentSignature<Props> = {} extends Props ? (props?: Props) => JSX.Element : (props: Props) => JSX.Element;
|
|
105
|
-
/**
|
|
106
|
-
* The sibling / context components for one resource, keyed by their declared
|
|
107
|
-
* names with call-site prop types.
|
|
108
|
-
*/
|
|
109
|
-
type ResolvedScopedComponentsMap<Components> = { [Name in keyof NormalizeScopedComponentsMap<Components>]: ScopedComponentSignature<Show<ResolvedBuiltPropShape<ScopedComponentOwnProps<NormalizeScopedComponentsMap<Components>[Name]>>>> };
|
|
110
|
-
type ScopedResourceComponentRenderContext<ComponentsByResource, LayoutCustomProps extends InPropsObject> = {
|
|
111
|
-
/**
|
|
112
|
-
* The resource layout for the component's current `resource`, created
|
|
113
|
-
* internally from that resource's entry options. Accepts the layout's
|
|
114
|
-
* custom props.
|
|
115
|
-
*/
|
|
116
|
-
Root: (props: Show<ResolveProps<LayoutCustomProps>>) => JSX.Element;
|
|
117
|
-
} & { [Resource in keyof ComponentsByResource as Capitalize<Resource & string>]-?: (() => JSX.Element) & ResolvedScopedComponentsMap<ComponentsByResource[Resource]> };
|
|
118
|
-
/**
|
|
119
|
-
* Reverse-mapped `resources` constraint.
|
|
120
|
-
*
|
|
121
|
-
* `ComponentsByResource` is inferred from each entry's `components` object.
|
|
122
|
-
* Mapping back over those keys types every nested `render`'s second argument
|
|
123
|
-
* with the other components for that resource — excluding the current
|
|
124
|
-
* component when typing a scoped component's own `render`.
|
|
125
|
-
*
|
|
126
|
-
* The parameter must not carry a default: TypeScript contextually types from a
|
|
127
|
-
* parameter's default when it has one, and `{}` would silently degrade every
|
|
128
|
-
* nested render to `any`.
|
|
129
|
-
*/
|
|
130
|
-
type ScopedComponentResourceEntries<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, Arguments extends ReadonlyArray<unknown>, LayoutCustomProps extends InPropsObject, ComponentIncludeProps extends IncludedProps<ScopedComponentAvailableProps<Resources, InProps, Composables, LayoutCustomProps>>, ComponentCustomProps extends InPropsObject, ComponentsByResource> = { [Resource in keyof ComponentsByResource]: LayoutPropsForResource<Resources, InProps, Composables> & {
|
|
131
|
-
/**
|
|
132
|
-
* Overrides the layout name used by `context.Root` for this resource.
|
|
133
|
-
* Defaults to the scope's configured name, then the capitalized resource.
|
|
134
|
-
*/
|
|
135
|
-
name?: string;
|
|
136
|
-
/**
|
|
137
|
-
* Components scoped to this resource. Each becomes a component on this
|
|
138
|
-
* resource's render context, on `context.<Resource>`, and on the component
|
|
139
|
-
* returned by `asHOF()`.
|
|
140
|
-
*/
|
|
141
|
-
components?: { [Name in keyof ComponentsByResource[Resource]]: JustScopedComponent<ComponentsByResource[Resource][Name]> & {
|
|
142
|
-
/** Props accepted by this component, validated at its call site. */props?: InPropsObject;
|
|
143
|
-
/**
|
|
144
|
-
* Renders this component. Receives the scoped component's props plus
|
|
145
|
-
* this component's own props, and the other components for this
|
|
146
|
-
* resource (excluding itself).
|
|
147
|
-
*/
|
|
148
|
-
render: (props: ScopedResourceComponentProps<Resources, InProps, Composables, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, Resource & string> & Show<ResolvedBuiltPropShape<ScopedComponentOwnProps<ComponentsByResource[Resource][Name]>>>, components: Omit<ResolvedScopedComponentsMap<ComponentsByResource[Resource]>, Name>) => JSX.Element;
|
|
149
|
-
} }; /** Renders this resource's content inside the shared render function. */
|
|
150
|
-
render: (props: ScopedResourceComponentProps<Resources, InProps, Composables, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, Resource & string>, components: ResolvedScopedComponentsMap<ComponentsByResource[Resource]>) => JSX.Element;
|
|
151
|
-
} } & Record<Exclude<keyof ComponentsByResource, SelectedLayoutResources<Resources, Arguments>>, never>;
|
|
152
|
-
/**
|
|
153
|
-
* Props of a resource-bound component. `resource` is supplied by the binding,
|
|
154
|
-
* so it is removed from the call site.
|
|
155
|
-
*/
|
|
156
|
-
type ScopedBoundResourceComponentProps<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, LayoutCustomProps extends InPropsObject, ComponentIncludeProps extends IncludedProps<ScopedComponentAvailableProps<Resources, InProps, Composables, LayoutCustomProps>>, ComponentCustomProps extends InPropsObject, Resource extends string> = Show<Omit<ScopedResourceComponentProps<Resources, InProps, Composables, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, Resource>, 'resource'>>;
|
|
157
|
-
type ScopedBoundResourceComponent<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, LayoutCustomProps extends InPropsObject, ComponentIncludeProps extends IncludedProps<ScopedComponentAvailableProps<Resources, InProps, Composables, LayoutCustomProps>>, ComponentCustomProps extends InPropsObject, ComponentsByResource, Resource extends string> = BaseComponent<string, ScopedBoundResourceComponentProps<Resources, InProps, Composables, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, Resource>> & ResolvedScopedComponentsMap<Resource extends keyof ComponentsByResource ? ComponentsByResource[Resource] : {}> & {
|
|
158
|
-
(props: ScopedBoundResourceComponentProps<Resources, InProps, Composables, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, Resource>): JSX.Element;
|
|
159
|
-
/**
|
|
160
|
-
* Type-only property containing the bound resource. This property is
|
|
161
|
-
* `undefined` at runtime.
|
|
162
|
-
*/
|
|
163
|
-
readonly resource: Resource;
|
|
164
|
-
};
|
|
165
|
-
type ScopedResourceComponent<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, Arguments extends ReadonlyArray<unknown>, LayoutCustomProps extends InPropsObject, ComponentIncludeProps extends IncludedProps<ScopedComponentAvailableProps<Resources, InProps, Composables, LayoutCustomProps>>, ComponentCustomProps extends InPropsObject, ComponentsByResource> = BaseComponent<string, ScopedResourceComponentProps<Resources, InProps, Composables, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, SelectedLayoutResources<Resources, Arguments>>> & {
|
|
166
|
-
/**
|
|
167
|
-
* The `resource` prop drives the generic, so it is inferred from the call
|
|
168
|
-
* site. Explicit type arguments are never needed.
|
|
169
|
-
*/
|
|
170
|
-
<const Resource extends SelectedLayoutResources<Resources, Arguments>>(props: ScopedResourceComponentProps<Resources, InProps, Composables, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, Resource>): JSX.Element;
|
|
171
|
-
/**
|
|
172
|
-
* Returns a factory that binds the component to one resource. The bound
|
|
173
|
-
* component accepts every prop except `resource`, which the binding supplies.
|
|
174
|
-
*
|
|
175
|
-
* Each resource is bound once and cached, so the returned component type is
|
|
176
|
-
* stable across renders.
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* const createDirectory = Directory.asHOF()
|
|
180
|
-
* const UsersDirectory = createDirectory('users')
|
|
181
|
-
*
|
|
182
|
-
* <UsersDirectory title='Users' />
|
|
183
|
-
*
|
|
184
|
-
* @returns A factory producing a component bound to the given resource.
|
|
185
|
-
*/
|
|
186
|
-
asHOF(): <const Resource extends SelectedLayoutResources<Resources, Arguments>>(resource: Resource) => ScopedBoundResourceComponent<Resources, InProps, Composables, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, ComponentsByResource, Resource>;
|
|
187
|
-
};
|
|
188
|
-
type ScopedCreateComponent<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, Arguments extends ReadonlyArray<unknown>, LayoutCustomProps extends InPropsObject> = <const ComponentsByResource, const ComponentIncludeProps extends IncludedProps<ScopedComponentAvailableProps<Resources, InProps, Composables, LayoutCustomProps>> = {}, ComponentCustomProps extends InPropsObject = {}>(options: {
|
|
189
|
-
props?: {
|
|
190
|
-
/** Props from the resource layout definition to expose to the component. */include?: ComponentIncludeProps; /** Additional props accepted by the component. */
|
|
191
|
-
custom?: ComponentCustomProps;
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* Per-resource content, keyed by resource. Each entry holds that resource's
|
|
195
|
-
* create-time layout options, its scoped `components`, and its `render`.
|
|
196
|
-
*/
|
|
197
|
-
resources?: ScopedComponentResourceEntries<Resources, InProps, Composables, Arguments, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, ComponentsByResource>;
|
|
198
|
-
/**
|
|
199
|
-
* Renders the scoped component. `children` and `resource` are always
|
|
200
|
-
* available. The context contains `Root`, the layout for the current
|
|
201
|
-
* resource, plus a capitalized component per defined resource.
|
|
202
|
-
*/
|
|
203
|
-
render: (props: ScopedResourceComponentProps<Resources, InProps, Composables, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, SelectedLayoutResources<Resources, Arguments>>, context: ScopedResourceComponentRenderContext<ComponentsByResource, LayoutCustomProps>) => JSX.Element;
|
|
204
|
-
}) => ScopedResourceComponent<Resources, InProps, Composables, Arguments, LayoutCustomProps, ComponentIncludeProps, ComponentCustomProps, ComponentsByResource>;
|
|
205
|
-
type ScopedCreateResourceLayoutFn<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents, Arguments extends ReadonlyArray<unknown>, CustomProps extends InPropsObject> = ScopedCreateResourceLayoutFnImpl<Resources, InProps, Composables, Arguments, CustomProps> & {
|
|
206
|
-
/**
|
|
207
|
-
* Creates a component shared by the target resources. Included layout props
|
|
208
|
-
* become component props, and `children` is always available as an optional
|
|
209
|
-
* prop in both the render callback and at the call site.
|
|
210
|
-
*
|
|
211
|
-
* Each key of `resources` holds that resource's create-time layout options
|
|
212
|
-
* alongside its `render`. The render context exposes `Root` — the layout for
|
|
213
|
-
* the current resource, built from those options — and one capitalized
|
|
214
|
-
* component per key present in `resources`.
|
|
215
|
-
*
|
|
216
|
-
* Each entry may also declare `components` — components scoped to that
|
|
217
|
-
* resource, available to the entry's own `render`, on `context.<Resource>`,
|
|
218
|
-
* and on the component returned by `asHOF()`.
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* const Directory = createDirectoryLayout.createComponent({
|
|
222
|
-
* props: { include: { title: true, actions: 'optional' } },
|
|
223
|
-
* resources: {
|
|
224
|
-
* users: {
|
|
225
|
-
* title: 'Users',
|
|
226
|
-
* components: {
|
|
227
|
-
* Toolbar: { render: ({ title }) => <nav>{title}</nav> },
|
|
228
|
-
* },
|
|
229
|
-
* render: ({ resource }, components) => (
|
|
230
|
-
* <>
|
|
231
|
-
* <components.Toolbar />
|
|
232
|
-
* <span>{resource}</span>
|
|
233
|
-
* </>
|
|
234
|
-
* ),
|
|
235
|
-
* },
|
|
236
|
-
* admins: {
|
|
237
|
-
* title: 'Admins',
|
|
238
|
-
* render: ({ resource }) => <span>{resource}</span>,
|
|
239
|
-
* },
|
|
240
|
-
* },
|
|
241
|
-
* render: ({ actions, children, resource }, context) => (
|
|
242
|
-
* <context.Root actions={actions}>
|
|
243
|
-
* {children}
|
|
244
|
-
* {resource === 'users' ? <context.Users /> : <context.Admins />}
|
|
245
|
-
* <context.Users.Toolbar />
|
|
246
|
-
* </context.Root>
|
|
247
|
-
* ),
|
|
248
|
-
* })
|
|
249
|
-
*
|
|
250
|
-
* <Directory resource='users' title='Users' />
|
|
251
|
-
*
|
|
252
|
-
* @param options The props configuration, per-resource entries, and the
|
|
253
|
-
* shared component render function.
|
|
254
|
-
* @returns A component scoped to the selected resources.
|
|
255
|
-
*/
|
|
256
|
-
createComponent: ScopedCreateComponent<Resources, InProps, Composables, Arguments, CustomProps>;
|
|
257
|
-
forResource: ScopedCreateLayoutForResource<Resources, InProps, Composables, Arguments, CustomProps>;
|
|
258
|
-
/**
|
|
259
|
-
* Type-only property containing the target resource union. This property is
|
|
260
|
-
* `undefined` at runtime and exists solely for extracting the scoped type.
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* type AccountResource = typeof createAccountLayout.resources;
|
|
264
|
-
*/
|
|
265
|
-
readonly resources: SelectedLayoutResources<Resources, Arguments>;
|
|
266
|
-
} & ([keyof Composables] extends [never] ? {} : {
|
|
267
|
-
makeComposable: ScopedCreateResourceLayoutMakeComposableFn<Resources, InProps, Composables, Arguments>;
|
|
268
|
-
});
|
|
269
|
-
type CreateResourceLayoutForResourcesFn<Resources extends ReadonlyArray<ResourceDefinition>, InProps extends InPropsDefinition<Resources>, Composables extends ComposableComponents = {}, IncludeProps extends LayoutIncludeProps<Resources, InProps, Composables> = {}, CustomProps extends InPropsObject = {}> = {
|
|
270
|
-
/**
|
|
271
|
-
* Creates a layout factory scoped to the listed resources.
|
|
272
|
-
*
|
|
273
|
-
* Layout names must be supplied when a layout is created.
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
* createResourceLayout.forResources('users', 'admins')
|
|
277
|
-
*
|
|
278
|
-
* @param resources Resources available from the returned layout factory.
|
|
279
|
-
* @returns A layout factory scoped to the selected resources.
|
|
280
|
-
*/
|
|
281
|
-
<const ResourceKeys extends readonly [LayoutResourceKey<Resources>, ...Array<LayoutResourceKey<Resources>>]>(...resources: ResourceKeys): ScopedCreateResourceLayoutFn<Resources, InProps, Composables, ResourceKeys, CustomProps>;
|
|
282
|
-
/**
|
|
283
|
-
* Creates a layout factory scoped to a resource list without default names.
|
|
284
|
-
*
|
|
285
|
-
* @example
|
|
286
|
-
* createResourceLayout.forResources({ resources: ['users', 'admins'] })
|
|
287
|
-
*
|
|
288
|
-
* @param options The resources to expose without configured default names.
|
|
289
|
-
* @returns A layout factory scoped to the selected resources.
|
|
290
|
-
*/
|
|
291
|
-
<const ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>>(options: {
|
|
292
|
-
resources: ResourceKeys;
|
|
293
|
-
name?: never;
|
|
294
|
-
}): ScopedCreateResourceLayoutFn<Resources, InProps, Composables, readonly [{
|
|
295
|
-
resources: ResourceKeys;
|
|
296
|
-
}], CustomProps>;
|
|
297
|
-
/**
|
|
298
|
-
* Creates a scoped layout factory with optional default names per resource.
|
|
299
|
-
*
|
|
300
|
-
* Each map key is limited to the resources selected in `resources`. Values
|
|
301
|
-
* can be strings or callbacks receiving that resource's capitalized name.
|
|
302
|
-
*
|
|
303
|
-
* @example
|
|
304
|
-
* createResourceLayout.forResources({
|
|
305
|
-
* resources: ['users', 'admins'],
|
|
306
|
-
* name: {
|
|
307
|
-
* users: resource => `${resource}Page`,
|
|
308
|
-
* admins: 'AdminDirectory',
|
|
309
|
-
* },
|
|
310
|
-
* })
|
|
311
|
-
*
|
|
312
|
-
* @param options The selected resources and their optional default names.
|
|
313
|
-
* @returns A layout factory scoped to the selected resources.
|
|
314
|
-
*/
|
|
315
|
-
<const ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>, const CallbackName extends string, const Names>(options: {
|
|
316
|
-
resources: ResourceKeys;
|
|
317
|
-
name: SelectedResourceLayoutNames<LayoutResourceKey<Resources>, NoInfer<ResourceKeys[number]>, CallbackName> & AtLeastOneResourceLayoutNameKey<NoInfer<ResourceKeys[number]>> & Record<string, NonNullable<ResourceLayoutNames<LayoutResourceKey<Resources>, CallbackName>[LayoutResourceKey<Resources>]>>;
|
|
318
|
-
} & {
|
|
319
|
-
name: Names & Record<Exclude<keyof Names, ResourceKeys[number]>, never>;
|
|
320
|
-
}): ScopedCreateResourceLayoutFn<Resources, InProps, Composables, MappedResourceLayoutArguments<Resources, ResourceKeys, Names, CallbackName>, CustomProps>;
|
|
321
|
-
/**
|
|
322
|
-
* Creates a scoped layout factory with one default-name callback shared by
|
|
323
|
-
* every selected resource. The callback receives a capitalized resource
|
|
324
|
-
* whose `toLowerCase()` result retains the corresponding literal type.
|
|
325
|
-
*
|
|
326
|
-
* @example
|
|
327
|
-
* createResourceLayout.forResources({
|
|
328
|
-
* resources: ['users', 'admins'],
|
|
329
|
-
* name: resource => `${resource}Page`,
|
|
330
|
-
* })
|
|
331
|
-
*
|
|
332
|
-
* @param options The selected resources and shared default-name callback.
|
|
333
|
-
* @returns A layout factory scoped to the selected resources.
|
|
334
|
-
*/
|
|
335
|
-
<const ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>, const Name extends string>(options: {
|
|
336
|
-
resources: ReadonlyArray<LayoutResourceKey<Resources>>;
|
|
337
|
-
name: (resource: CapitalizedResource<ResourceKeys[number]>) => Name;
|
|
338
|
-
} & {
|
|
339
|
-
resources: ResourceKeys;
|
|
340
|
-
}): ScopedCreateResourceLayoutFn<Resources, InProps, Composables, SharedResourceLayoutArguments<Resources, ResourceKeys, Name>, CustomProps>;
|
|
341
|
-
/**
|
|
342
|
-
* Creates a scoped layout factory from a resource-keyed configuration.
|
|
343
|
-
* Only configured resources are available from the returned factory.
|
|
344
|
-
*
|
|
345
|
-
* @example
|
|
346
|
-
* createResourceLayout.forResources({
|
|
347
|
-
* users: { name: resource => `${resource}Page` },
|
|
348
|
-
* admins: { name: 'AdminDirectory' },
|
|
349
|
-
* })
|
|
350
|
-
*
|
|
351
|
-
* @param options Resource-keyed layout defaults.
|
|
352
|
-
* @returns A layout factory scoped to the configured resources.
|
|
353
|
-
*/
|
|
354
|
-
<const CallbackName extends string, const Selection extends ResourceLayoutSelection<Resources, CallbackName>>(options: Selection & AtLeastOneResourceLayoutSelection<Resources, CallbackName> & Partial<Record<Exclude<'resources', LayoutResourceKey<Resources>>, never>> & Record<Exclude<keyof Selection, LayoutResourceKey<Resources>>, never>): ScopedCreateResourceLayoutFn<Resources, InProps, Composables, SelectedResourceLayoutArguments<Selection>, CustomProps>;
|
|
355
|
-
};
|
|
356
|
-
//#endregion
|
|
357
|
-
export { CreateResourceLayoutForResourcesFn };
|
|
358
|
-
//# sourceMappingURL=for-resources.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"for-resources.d.mts","names":[],"sources":["../../src/create-config/for-resources.ts"],"mappings":";;;;;;;;;;KAuCK,mBAAA,4BAA+C,QAAA,SAAiB,QAA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OAAA,EACA,WAAA,EACA,6BAAA,CAA8B,SAAA,EAAW,YAAA,EAAc,IAAA,GACvD,WAAA;EA9zBiB;;;;;;;;;;;;;EAAA,4DAg1BO,uBAAA,CAAwB,SAAA,EAAW,YAAA,GAE3D,OAAA,EAAS,SAAA,GACP,iCAAA,CAAkC,SAAA,EAAW,YAAA,IAC7C,OAAA,CACE,MAAA,CAAO,OAAA,cAAqB,iBAAA,CAAkB,SAAA,cAEhD,MAAA,CAAO,OAAA,OAAc,SAAA,EAAW,iBAAA,CAAkB,SAAA,aACnD,4BAAA,CACD,SAAA,EACA,OAAA,EACA,WAAA,EACA,+BAAA,CAAgC,SAAA,GAChC,WAAA;AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"for-resources.mjs","names":[],"sources":["../../src/create-config/for-resources.ts"],"sourcesContent":["import {\n createContext,\n createElement,\n type JSX,\n type ReactNode,\n useContext,\n} from 'react';\nimport type {\n ComposableComponents,\n ComposableResourceLayout,\n} from '@jfdevelops/react-layout-composables';\nimport {\n type AnyBuiltPropDefinition,\n type ResolveProps,\n type ResolvedBuiltPropShape,\n validateProps,\n} from '@jfdevelops/react-layout-validator';\nimport type {\n IncludedProps,\n InPropsDefinition,\n InPropsObject,\n MergedLayoutInProps,\n ResolvedIncludedPropsAsDefined,\n} from '../props';\nimport type { LayoutResourceKey, ResourceDefinition } from '../resource';\nimport { capitalize } from '../utils/capitalize';\nimport type { BaseComponent, Show } from '../utils';\nimport type {\n LayoutIncludeProps,\n LayoutPropsForResource,\n ResourceLayoutComponent,\n} from './define-layout';\nimport type {\n CreatedLayoutForResource,\n CreateLayoutForResourceOptions,\n CreateResourceLayoutOptionsBase,\n SetDefaultPropForResourceFn,\n} from './for-resource';\n\ntype CapitalizedResource<Resource extends string> = Resource extends Resource\n ? {\n toLowerCase: () => Lowercase<Capitalize<Resource>>;\n } & Capitalize<Resource>\n : never;\n\ntype ResourceLayoutName<\n Resource extends string,\n Name extends string = string,\n> = Name | ((resource: CapitalizedResource<Resource>) => Name);\n\ntype ResourceLayoutNames<\n Resource extends string,\n CallbackName extends string = string,\n> = {\n [TargetResource in Resource]?:\n | string\n | ((resource: CapitalizedResource<TargetResource>) => CallbackName);\n};\n\ntype AtLeastOneResourceLayoutNameKey<Resource extends string> = {\n [TargetResource in Resource]: Record<TargetResource, unknown> &\n Partial<Record<Exclude<Resource, TargetResource>, unknown>>;\n}[Resource];\n\ntype SelectedResourceLayoutNames<\n Resource extends string,\n SelectedResource extends Resource,\n CallbackName extends string,\n> = {\n [TargetResource in Resource as TargetResource extends SelectedResource\n ? TargetResource\n : never]?:\n | string\n | ((resource: CapitalizedResource<TargetResource>) => CallbackName);\n};\n\ntype ResourcesLayoutName<Resource extends string> =\n | Exclude<ResourceLayoutName<Resource>, string>\n | ResourceLayoutNames<Resource>;\n\ntype ResourceLayoutSelection<\n Resources extends ReadonlyArray<ResourceDefinition>,\n CallbackName extends string = string,\n> = {\n [Resource in LayoutResourceKey<Resources>]?: {\n name?: string | ((resource: CapitalizedResource<Resource>) => CallbackName);\n };\n};\n\ntype AtLeastOneResourceLayoutSelection<\n Resources extends ReadonlyArray<ResourceDefinition>,\n CallbackName extends string,\n> = {\n [Resource in LayoutResourceKey<Resources>]: Required<\n Pick<ResourceLayoutSelection<Resources, CallbackName>, Resource>\n > &\n Omit<ResourceLayoutSelection<Resources, CallbackName>, Resource>;\n}[LayoutResourceKey<Resources>];\n\ntype SelectedLayoutResources<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Arguments extends ReadonlyArray<unknown>,\n> =\n Arguments extends ReadonlyArray<LayoutResourceKey<Resources>>\n ? Arguments[number]\n : Arguments[0] extends {\n resources: ReadonlyArray<infer Resource>;\n }\n ? Resource & LayoutResourceKey<Resources>\n : keyof Arguments[0] & LayoutResourceKey<Resources>;\n\ntype ResolveResourceLayoutName<Name> = Name extends (\n ...args: never[]\n) => infer Result\n ? Result & string\n : Name extends string\n ? Name\n : string;\n\ntype NormalizeCapitalizedResourceName<\n Name extends string,\n Resource extends string,\n> = Name extends Name\n ? NormalizeCapitalizedResourceNameMatch<Name, Resource> extends infer Match\n ? [Match] extends [never]\n ? Name\n : Match\n : never\n : never;\n\ntype NormalizeCapitalizedResourceNameMatch<\n Name extends string,\n Resource extends string,\n> = Resource extends Resource\n ? Name extends `${CapitalizedResource<Resource>}${infer Suffix}`\n ? `${Capitalize<Resource>}${Suffix}`\n : never\n : never;\n\ntype SelectedResourceLayoutName<Arguments, Resource extends string> =\n Arguments extends ReadonlyArray<string>\n ? string\n : Arguments extends readonly [infer Options]\n ? Options extends {\n resources: ReadonlyArray<string>;\n name?: infer Name;\n }\n ? Name extends (...args: never[]) => unknown\n ? ResolveResourceLayoutName<Name>\n : Name extends Record<Resource, infer ResourceName>\n ? ResolveResourceLayoutName<ResourceName>\n : string\n : Options extends Record<Resource, infer ResourceOptions>\n ? ResourceOptions extends { name?: infer Name }\n ? ResolveResourceLayoutName<Name>\n : string\n : string\n : string;\n\ntype NormalizeResourceLayoutNames<Names, CallbackName extends string> = {\n [Resource in keyof Names]: Names[Resource] extends (\n ...args: never[]\n ) => unknown\n ? (\n resource: CapitalizedResource<Resource & string>,\n ) => NormalizeCapitalizedResourceName<CallbackName, Resource & string>\n : Names[Resource];\n};\n\ntype NormalizeResourceLayoutSelection<Selection> = {\n [Resource in keyof Selection]: Selection[Resource] extends {\n name: infer Name;\n }\n ? {\n name: Name extends (...args: never[]) => unknown\n ? (\n resource: CapitalizedResource<Resource & string>,\n ) => NormalizeCapitalizedResourceName<\n ResolveResourceLayoutName<Name>,\n Resource & string\n >\n : Name;\n }\n : Selection[Resource];\n};\n\ntype SharedResourceLayoutArguments<\n Resources extends ReadonlyArray<ResourceDefinition>,\n ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>,\n Name extends string,\n> = readonly [\n {\n resources: ResourceKeys;\n name: (\n resource: CapitalizedResource<ResourceKeys[number]>,\n ) => NormalizeCapitalizedResourceName<Name, ResourceKeys[number]>;\n },\n];\n\ntype MappedResourceLayoutArguments<\n Resources extends ReadonlyArray<ResourceDefinition>,\n ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>,\n Names,\n CallbackName extends string,\n> = readonly [\n {\n resources: ResourceKeys;\n name: NormalizeResourceLayoutNames<Names, CallbackName>;\n },\n];\n\ntype SelectedResourceLayoutArguments<Selection> = readonly [\n NormalizeResourceLayoutSelection<Selection>,\n];\n\ntype HasResourceLayoutName<Arguments, Resource extends string> =\n Arguments extends ReadonlyArray<string>\n ? false\n : Arguments extends readonly [infer Options]\n ? Options extends {\n resources: ReadonlyArray<string>;\n name: infer Name;\n }\n ? Name extends (...args: never[]) => unknown\n ? true\n : Name extends Record<Resource, unknown>\n ? true\n : false\n : Options extends Record<Resource, infer ResourceOptions>\n ? 'name' extends keyof ResourceOptions\n ? true\n : false\n : false\n : false;\n\ntype ScopedCreateResourceLayoutOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n Name extends string,\n Resource extends SelectedLayoutResources<Resources, Arguments>,\n Props extends InPropsObject,\n> = LayoutPropsForResource<Resources, InProps, Composables> & {\n resource: Resource;\n props?: Props;\n} & (HasResourceLayoutName<Arguments, Resource> extends true\n ? { name?: Name }\n : { name: Name });\n\ntype ScopedCreateResourceLayoutFnImpl<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n CustomProps extends InPropsObject,\n> = <\n Resource extends SelectedLayoutResources<Resources, Arguments>,\n Name extends string = SelectedResourceLayoutName<Arguments, Resource>,\n Props extends InPropsObject = {},\n>(\n options: ScopedCreateResourceLayoutOptions<\n Resources,\n InProps,\n Composables,\n Arguments,\n Name,\n Resource,\n Props\n >,\n) => ResourceLayoutComponent<Name, CustomProps, Composables, Resource>;\n\ntype ScopedCreateLayoutForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n CustomProps extends InPropsObject,\n> = <\n Resource extends SelectedLayoutResources<Resources, Arguments>,\n Name extends string = SelectedResourceLayoutName<Arguments, Resource>,\n>(\n options: CreateLayoutForResourceOptions<Resources, Name, Resource>,\n) => CreatedLayoutForResource<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n CustomProps\n> & {\n setDefaults: SetDefaultPropForResourceFn<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n CustomProps\n >;\n};\n\ntype ScopedCreateResourceLayoutMakeComposableFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n> = <\n Resource extends SelectedLayoutResources<Resources, Arguments>,\n Name extends string = SelectedResourceLayoutName<Arguments, Resource>,\n Props extends InPropsObject = {},\n>(\n options: Omit<\n CreateResourceLayoutOptionsBase<Resources, Name, Resource>,\n 'name'\n > &\n Partial<LayoutPropsForResource<Resources, InProps, Composables>> & {\n props?: Props;\n } & (HasResourceLayoutName<Arguments, Resource> extends true\n ? { name?: Name }\n : { name: Name }),\n) => ComposableResourceLayout<Composables, Name, any, any, any>;\n\ntype ScopedComponentAvailableProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n LayoutCustomProps extends InPropsObject,\n> = MergedLayoutInProps<Resources, InProps, Composables> & LayoutCustomProps;\n\ntype ScopedResourceComponentProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n LayoutCustomProps extends InPropsObject,\n ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n >,\n ComponentCustomProps extends InPropsObject,\n Resource extends string,\n> = Show<\n Omit<\n ResolvedIncludedPropsAsDefined<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >,\n ComponentIncludeProps\n > &\n ResolvedBuiltPropShape<ComponentCustomProps>,\n 'children' | 'resource'\n > & {\n children?: ReactNode;\n resource: Resource;\n }\n>;\n\n/**\n * Fields reverse-inferred from each scoped component declaration. Only `props`\n * belongs here — putting `render` in the reverse map makes TypeScript infer it\n * as `unknown` (function types don't reverse-map cleanly). `render` is supplied\n * by the constraint intersection instead, like the playground's `transform`.\n */\ntype ScopedComponentShape = {\n props?: InPropsObject;\n};\n\n/**\n * Homomorphic pick of reverse-mapped scoped-component fields. Paired with a\n * mapped type over the components object, this lets each entry's inferred\n * `props` flow into sibling render signatures.\n */\ntype JustScopedComponent<T> = {\n [Key in keyof T & keyof ScopedComponentShape]: T[Key];\n};\n\n/**\n * Resources with no `components` reverse-infer as `unknown`. Treat that as an\n * empty map so sibling/context access stays closed.\n */\ntype NormalizeScopedComponentsMap<Components> = unknown extends Components\n ? {}\n : Components extends Record<string, unknown>\n ? Components\n : {};\n\n/** Extracts the prop definitions declared on a scoped component. */\ntype ScopedComponentOwnProps<Definition> = Definition extends {\n props: infer Props;\n}\n ? Props extends InPropsObject\n ? Props\n : {}\n : {};\n\n/**\n * A scoped component's call signature. Components that declare no props are\n * callable with no arguments.\n */\ntype ScopedComponentSignature<Props> = {} extends Props\n ? (props?: Props) => JSX.Element\n : (props: Props) => JSX.Element;\n\n/**\n * The sibling / context components for one resource, keyed by their declared\n * names with call-site prop types.\n */\ntype ResolvedScopedComponentsMap<Components> = {\n [Name in keyof NormalizeScopedComponentsMap<Components>]: ScopedComponentSignature<\n Show<\n ResolvedBuiltPropShape<\n ScopedComponentOwnProps<NormalizeScopedComponentsMap<Components>[Name]>\n >\n >\n >;\n};\n\ntype ScopedResourceComponentRenderContext<\n ComponentsByResource,\n LayoutCustomProps extends InPropsObject,\n> = {\n /**\n * The resource layout for the component's current `resource`, created\n * internally from that resource's entry options. Accepts the layout's\n * custom props.\n */\n Root: (props: Show<ResolveProps<LayoutCustomProps>>) => JSX.Element;\n} & {\n [Resource in keyof ComponentsByResource as Capitalize<\n Resource & string\n >]-?: (() => JSX.Element) &\n ResolvedScopedComponentsMap<ComponentsByResource[Resource]>;\n};\n\n/**\n * Reverse-mapped `resources` constraint.\n *\n * `ComponentsByResource` is inferred from each entry's `components` object.\n * Mapping back over those keys types every nested `render`'s second argument\n * with the other components for that resource — excluding the current\n * component when typing a scoped component's own `render`.\n *\n * The parameter must not carry a default: TypeScript contextually types from a\n * parameter's default when it has one, and `{}` would silently degrade every\n * nested render to `any`.\n */\ntype ScopedComponentResourceEntries<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n LayoutCustomProps extends InPropsObject,\n ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n >,\n ComponentCustomProps extends InPropsObject,\n ComponentsByResource,\n> = {\n [Resource in keyof ComponentsByResource]: LayoutPropsForResource<\n Resources,\n InProps,\n Composables\n > & {\n /**\n * Overrides the layout name used by `context.Root` for this resource.\n * Defaults to the scope's configured name, then the capitalized resource.\n */\n name?: string;\n /**\n * Components scoped to this resource. Each becomes a component on this\n * resource's render context, on `context.<Resource>`, and on the component\n * returned by `asHOF()`.\n */\n components?: {\n [Name in keyof ComponentsByResource[Resource]]: JustScopedComponent<\n ComponentsByResource[Resource][Name]\n > & {\n /** Props accepted by this component, validated at its call site. */\n props?: InPropsObject;\n /**\n * Renders this component. Receives the scoped component's props plus\n * this component's own props, and the other components for this\n * resource (excluding itself).\n */\n render: (\n props: ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource & string\n > &\n Show<\n ResolvedBuiltPropShape<\n ScopedComponentOwnProps<ComponentsByResource[Resource][Name]>\n >\n >,\n components: Omit<\n ResolvedScopedComponentsMap<ComponentsByResource[Resource]>,\n Name\n >,\n ) => JSX.Element;\n };\n };\n /** Renders this resource's content inside the shared render function. */\n render: (\n props: ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource & string\n >,\n components: ResolvedScopedComponentsMap<ComponentsByResource[Resource]>,\n ) => JSX.Element;\n };\n} & Record<\n Exclude<\n keyof ComponentsByResource,\n SelectedLayoutResources<Resources, Arguments>\n >,\n never\n>;\n\n/**\n * Props of a resource-bound component. `resource` is supplied by the binding,\n * so it is removed from the call site.\n */\ntype ScopedBoundResourceComponentProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n LayoutCustomProps extends InPropsObject,\n ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n >,\n ComponentCustomProps extends InPropsObject,\n Resource extends string,\n> = Show<\n Omit<\n ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource\n >,\n 'resource'\n >\n>;\n\ntype ScopedBoundResourceComponent<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n LayoutCustomProps extends InPropsObject,\n ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n >,\n ComponentCustomProps extends InPropsObject,\n ComponentsByResource,\n Resource extends string,\n> = BaseComponent<\n string,\n ScopedBoundResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource\n >\n> &\n ResolvedScopedComponentsMap<\n Resource extends keyof ComponentsByResource\n ? ComponentsByResource[Resource]\n : {}\n > & {\n (\n props: ScopedBoundResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource\n >,\n ): JSX.Element;\n /**\n * Type-only property containing the bound resource. This property is\n * `undefined` at runtime.\n */\n readonly resource: Resource;\n };\n\ntype ScopedResourceComponent<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n LayoutCustomProps extends InPropsObject,\n ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n >,\n ComponentCustomProps extends InPropsObject,\n ComponentsByResource,\n> = BaseComponent<\n string,\n ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n SelectedLayoutResources<Resources, Arguments>\n >\n> & {\n /**\n * The `resource` prop drives the generic, so it is inferred from the call\n * site. Explicit type arguments are never needed.\n */\n <const Resource extends SelectedLayoutResources<Resources, Arguments>>(\n props: ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource\n >,\n ): JSX.Element;\n /**\n * Returns a factory that binds the component to one resource. The bound\n * component accepts every prop except `resource`, which the binding supplies.\n *\n * Each resource is bound once and cached, so the returned component type is\n * stable across renders.\n *\n * @example\n * const createDirectory = Directory.asHOF()\n * const UsersDirectory = createDirectory('users')\n *\n * <UsersDirectory title='Users' />\n *\n * @returns A factory producing a component bound to the given resource.\n */\n asHOF(): <\n const Resource extends SelectedLayoutResources<Resources, Arguments>,\n >(\n resource: Resource,\n ) => ScopedBoundResourceComponent<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n ComponentsByResource,\n Resource\n >;\n};\n\ntype ScopedCreateComponent<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n LayoutCustomProps extends InPropsObject,\n> = <\n // Declared first and deliberately without a default: TypeScript\n // contextually types from a parameter's default when one exists, so a\n // default here would type every nested render as `any`. Inferred via a\n // reverse mapped type from each entry's `components` object.\n const ComponentsByResource,\n const ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n > = {},\n ComponentCustomProps extends InPropsObject = {},\n>(options: {\n props?: {\n /** Props from the resource layout definition to expose to the component. */\n include?: ComponentIncludeProps;\n /** Additional props accepted by the component. */\n custom?: ComponentCustomProps;\n };\n /**\n * Per-resource content, keyed by resource. Each entry holds that resource's\n * create-time layout options, its scoped `components`, and its `render`.\n */\n resources?: ScopedComponentResourceEntries<\n Resources,\n InProps,\n Composables,\n Arguments,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n ComponentsByResource\n >;\n /**\n * Renders the scoped component. `children` and `resource` are always\n * available. The context contains `Root`, the layout for the current\n * resource, plus a capitalized component per defined resource.\n */\n render: (\n props: ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n SelectedLayoutResources<Resources, Arguments>\n >,\n context: ScopedResourceComponentRenderContext<\n ComponentsByResource,\n LayoutCustomProps\n >,\n ) => JSX.Element;\n}) => ScopedResourceComponent<\n Resources,\n InProps,\n Composables,\n Arguments,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n ComponentsByResource\n>;\n\ntype ScopedCreateResourceLayoutFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n CustomProps extends InPropsObject,\n> = ScopedCreateResourceLayoutFnImpl<\n Resources,\n InProps,\n Composables,\n Arguments,\n CustomProps\n> & {\n /**\n * Creates a component shared by the target resources. Included layout props\n * become component props, and `children` is always available as an optional\n * prop in both the render callback and at the call site.\n *\n * Each key of `resources` holds that resource's create-time layout options\n * alongside its `render`. The render context exposes `Root` — the layout for\n * the current resource, built from those options — and one capitalized\n * component per key present in `resources`.\n *\n * Each entry may also declare `components` — components scoped to that\n * resource, available to the entry's own `render`, on `context.<Resource>`,\n * and on the component returned by `asHOF()`.\n *\n * @example\n * const Directory = createDirectoryLayout.createComponent({\n * props: { include: { title: true, actions: 'optional' } },\n * resources: {\n * users: {\n * title: 'Users',\n * components: {\n * Toolbar: { render: ({ title }) => <nav>{title}</nav> },\n * },\n * render: ({ resource }, components) => (\n * <>\n * <components.Toolbar />\n * <span>{resource}</span>\n * </>\n * ),\n * },\n * admins: {\n * title: 'Admins',\n * render: ({ resource }) => <span>{resource}</span>,\n * },\n * },\n * render: ({ actions, children, resource }, context) => (\n * <context.Root actions={actions}>\n * {children}\n * {resource === 'users' ? <context.Users /> : <context.Admins />}\n * <context.Users.Toolbar />\n * </context.Root>\n * ),\n * })\n *\n * <Directory resource='users' title='Users' />\n *\n * @param options The props configuration, per-resource entries, and the\n * shared component render function.\n * @returns A component scoped to the selected resources.\n */\n createComponent: ScopedCreateComponent<\n Resources,\n InProps,\n Composables,\n Arguments,\n CustomProps\n >;\n forResource: ScopedCreateLayoutForResource<\n Resources,\n InProps,\n Composables,\n Arguments,\n CustomProps\n >;\n /**\n * Type-only property containing the target resource union. This property is\n * `undefined` at runtime and exists solely for extracting the scoped type.\n *\n * @example\n * type AccountResource = typeof createAccountLayout.resources;\n */\n readonly resources: SelectedLayoutResources<Resources, Arguments>;\n} & ([keyof Composables] extends [never]\n ? {}\n : {\n makeComposable: ScopedCreateResourceLayoutMakeComposableFn<\n Resources,\n InProps,\n Composables,\n Arguments\n >;\n });\n\nexport type CreateResourceLayoutForResourcesFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents = {},\n IncludeProps extends LayoutIncludeProps<Resources, InProps, Composables> = {},\n CustomProps extends InPropsObject = {},\n> = {\n /**\n * Creates a layout factory scoped to the listed resources.\n *\n * Layout names must be supplied when a layout is created.\n *\n * @example\n * createResourceLayout.forResources('users', 'admins')\n *\n * @param resources Resources available from the returned layout factory.\n * @returns A layout factory scoped to the selected resources.\n */\n <\n const ResourceKeys extends readonly [\n LayoutResourceKey<Resources>,\n ...Array<LayoutResourceKey<Resources>>,\n ],\n >(\n ...resources: ResourceKeys\n ): ScopedCreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n ResourceKeys,\n CustomProps\n >;\n\n /**\n * Creates a layout factory scoped to a resource list without default names.\n *\n * @example\n * createResourceLayout.forResources({ resources: ['users', 'admins'] })\n *\n * @param options The resources to expose without configured default names.\n * @returns A layout factory scoped to the selected resources.\n */\n <\n const ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>,\n >(options: {\n resources: ResourceKeys;\n name?: never;\n }): ScopedCreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n readonly [{ resources: ResourceKeys }],\n CustomProps\n >;\n\n /**\n * Creates a scoped layout factory with optional default names per resource.\n *\n * Each map key is limited to the resources selected in `resources`. Values\n * can be strings or callbacks receiving that resource's capitalized name.\n *\n * @example\n * createResourceLayout.forResources({\n * resources: ['users', 'admins'],\n * name: {\n * users: resource => `${resource}Page`,\n * admins: 'AdminDirectory',\n * },\n * })\n *\n * @param options The selected resources and their optional default names.\n * @returns A layout factory scoped to the selected resources.\n */\n <\n const ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>,\n const CallbackName extends string,\n const Names,\n >(\n options: {\n resources: ResourceKeys;\n name: SelectedResourceLayoutNames<\n LayoutResourceKey<Resources>,\n NoInfer<ResourceKeys[number]>,\n CallbackName\n > &\n AtLeastOneResourceLayoutNameKey<NoInfer<ResourceKeys[number]>> &\n Record<\n string,\n NonNullable<\n ResourceLayoutNames<\n LayoutResourceKey<Resources>,\n CallbackName\n >[LayoutResourceKey<Resources>]\n >\n >;\n } & {\n name: Names & Record<Exclude<keyof Names, ResourceKeys[number]>, never>;\n },\n ): ScopedCreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n MappedResourceLayoutArguments<Resources, ResourceKeys, Names, CallbackName>,\n CustomProps\n >;\n\n /**\n * Creates a scoped layout factory with one default-name callback shared by\n * every selected resource. The callback receives a capitalized resource\n * whose `toLowerCase()` result retains the corresponding literal type.\n *\n * @example\n * createResourceLayout.forResources({\n * resources: ['users', 'admins'],\n * name: resource => `${resource}Page`,\n * })\n *\n * @param options The selected resources and shared default-name callback.\n * @returns A layout factory scoped to the selected resources.\n */\n <\n const ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>,\n const Name extends string,\n >(\n options: {\n resources: ReadonlyArray<LayoutResourceKey<Resources>>;\n name: (resource: CapitalizedResource<ResourceKeys[number]>) => Name;\n } & { resources: ResourceKeys },\n ): ScopedCreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n SharedResourceLayoutArguments<Resources, ResourceKeys, Name>,\n CustomProps\n >;\n\n /**\n * Creates a scoped layout factory from a resource-keyed configuration.\n * Only configured resources are available from the returned factory.\n *\n * @example\n * createResourceLayout.forResources({\n * users: { name: resource => `${resource}Page` },\n * admins: { name: 'AdminDirectory' },\n * })\n *\n * @param options Resource-keyed layout defaults.\n * @returns A layout factory scoped to the configured resources.\n */\n <\n const CallbackName extends string,\n const Selection extends ResourceLayoutSelection<Resources, CallbackName>,\n >(\n options: Selection &\n AtLeastOneResourceLayoutSelection<Resources, CallbackName> &\n Partial<\n Record<Exclude<'resources', LayoutResourceKey<Resources>>, never>\n > &\n Record<Exclude<keyof Selection, LayoutResourceKey<Resources>>, never>,\n ): ScopedCreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n SelectedResourceLayoutArguments<Selection>,\n CustomProps\n >;\n};\n\n/**\n * Names a scoped component cannot use. Scoped components are attached to\n * function objects, so they collide with the component's own statics and with\n * non-writable `Function.prototype` properties. `__proto__` is reserved so\n * assignment cannot hit the prototype setter on a normal object.\n */\nconst reservedScopedComponentNames = new Set([\n '__proto__',\n 'apply',\n 'arguments',\n 'bind',\n 'call',\n 'caller',\n 'displayName',\n 'length',\n 'name',\n 'props',\n 'prototype',\n 'resource',\n]);\n\ntype CreateForResourcesOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = {\n createLayoutForResource: (\n defaultName: string | undefined,\n resource: LayoutResourceKey<Resources>,\n ) => unknown;\n createMakeComposableLayout?: () => (\n options: Record<string, unknown>,\n ) => unknown;\n createResourceLayout: (options: Record<string, unknown>) => unknown;\n getComponentPropDefinitions: (\n resource: LayoutResourceKey<Resources>,\n ) => Record<string, AnyBuiltPropDefinition>;\n};\n\nexport function createForResources<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n IncludeProps extends LayoutIncludeProps<Resources, InProps, Composables>,\n CustomProps extends InPropsObject,\n>({\n createLayoutForResource,\n createMakeComposableLayout,\n createResourceLayout,\n getComponentPropDefinitions,\n}: CreateForResourcesOptions<Resources>) {\n return ((...resourcesOrOptions: Array<unknown>) => {\n const firstArgument = resourcesOrOptions[0];\n let resourceOptions: Array<{\n resource: LayoutResourceKey<Resources>;\n name?:\n | string\n | ((\n resource: CapitalizedResource<LayoutResourceKey<Resources>>,\n ) => string);\n }>;\n\n if (typeof firstArgument === 'string') {\n resourceOptions = resourcesOrOptions.map((resource) => ({\n resource: resource as LayoutResourceKey<Resources>,\n }));\n } else if (\n firstArgument !== null &&\n typeof firstArgument === 'object' &&\n 'resources' in firstArgument &&\n Array.isArray(firstArgument.resources)\n ) {\n const { name, resources } = firstArgument as {\n name?: ResourcesLayoutName<LayoutResourceKey<Resources>>;\n resources: Array<LayoutResourceKey<Resources>>;\n };\n resourceOptions = resources.map((resource) => ({\n name: typeof name === 'function' ? name : name?.[resource],\n resource,\n }));\n } else {\n resourceOptions = Object.entries(firstArgument ?? {}).map(\n ([resource, options]) => ({\n ...(options as {\n name?:\n | string\n | ((\n resource: CapitalizedResource<LayoutResourceKey<Resources>>,\n ) => string);\n }),\n resource: resource as LayoutResourceKey<Resources>,\n }),\n );\n }\n\n const defaultNames = new Map(\n resourceOptions.map(({ name, resource }) => [\n resource,\n typeof name === 'function'\n ? name(\n capitalize(resource) as CapitalizedResource<\n LayoutResourceKey<Resources>\n >,\n )\n : name,\n ]),\n );\n\n function scopedCreateResourceLayout(options: Record<string, unknown>) {\n const resource = options.resource as LayoutResourceKey<Resources>;\n\n return createResourceLayout({\n ...options,\n name: options.name ?? defaultNames.get(resource),\n });\n }\n\n function scopedForResource(options: {\n name?: string;\n resource: LayoutResourceKey<Resources>;\n }) {\n return createLayoutForResource(\n options.name ?? defaultNames.get(options.resource),\n options.resource,\n );\n }\n\n type ScopedComponentRenderFn = (\n props: Record<string, unknown>,\n components: Record<string, (props?: never) => JSX.Element>,\n ) => JSX.Element;\n\n type ScopedResourceScopedComponentDefinition = {\n props?: Record<string, AnyBuiltPropDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n type ScopedComponentEntry = {\n [option: string]: unknown;\n name?: string;\n components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n function createComponent(componentOptions: {\n props?: {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n };\n resources?: Record<string, ScopedComponentEntry>;\n render: (\n props: Record<string, unknown>,\n context: Record<string, (props: never) => JSX.Element>,\n ) => JSX.Element;\n }) {\n const include = componentOptions.props?.include ?? {};\n const custom = componentOptions.props?.custom ?? {};\n const selectedResources = new Set(\n resourceOptions.map(({ resource }) => resource),\n );\n const componentPropsContext = createContext<\n Record<string, unknown> | undefined\n >(undefined);\n const definedEntries = new Map<\n LayoutResourceKey<Resources>,\n ScopedComponentEntry\n >();\n\n for (const [key, entry] of Object.entries(\n componentOptions.resources ?? {},\n )) {\n const resource = key as LayoutResourceKey<Resources>;\n\n if (!selectedResources.has(resource)) {\n throw new Error(\n `Resource \"${key}\" is not available in this scoped component`,\n );\n }\n\n definedEntries.set(resource, entry);\n }\n\n /** Resolved scoped components, per resource. */\n const resourceScopedComponents = new Map<\n LayoutResourceKey<Resources>,\n Record<string, (props?: never) => JSX.Element>\n >();\n const contextResources = new Map<string, LayoutResourceKey<Resources>>();\n const renderContext: Record<string, (props: never) => JSX.Element> =\n Object.fromEntries(\n [...definedEntries].map(([resource, entry]) => {\n const contextKey = capitalize(resource);\n\n if (contextKey === 'Root') {\n throw new Error(\n `Resource \"${resource}\" maps to the reserved render context key \"Root\"`,\n );\n }\n\n const existingResource = contextResources.get(contextKey);\n\n if (existingResource !== undefined) {\n throw new Error(\n `Resources \"${existingResource}\" and \"${resource}\" both map to render context key \"${contextKey}\"`,\n );\n }\n\n contextResources.set(contextKey, resource);\n\n /**\n * Built once per resource so every scoped component keeps a stable\n * identity, and shared by the resource render, the render context,\n * and any component bound through `asHOF()`.\n */\n const scopedComponents: Record<\n string,\n (props?: never) => JSX.Element\n > = {};\n\n for (const [name, definition] of Object.entries(\n entry.components ?? {},\n )) {\n if (reservedScopedComponentNames.has(name)) {\n throw new Error(\n `Scoped component \"${name}\" for resource \"${resource}\" uses a reserved name`,\n );\n }\n\n const ownPropDefinitions = definition.props ?? {};\n\n function ScopedComponent(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new Error(\n `Scoped component \"${name}\" must be rendered inside its scoped component`,\n );\n }\n\n const resolvedOwnProps = ownProps ?? {};\n\n validateProps(ownPropDefinitions, resolvedOwnProps);\n\n return definition.render(\n { ...componentProps, ...resolvedOwnProps, resource },\n scopedComponents,\n );\n }\n\n scopedComponents[name] = ScopedComponent as (\n props?: never,\n ) => JSX.Element;\n }\n\n resourceScopedComponents.set(resource, scopedComponents);\n\n function ResourceRender() {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new Error(\n `Render context component \"${contextKey}\" must be rendered inside its scoped component`,\n );\n }\n\n return entry.render(\n { ...componentProps, resource },\n scopedComponents,\n );\n }\n\n return [contextKey, Object.assign(ResourceRender, scopedComponents)];\n }),\n );\n\n /**\n * Layouts are created once per resource and cached. Creating one during\n * render would hand React a new component type on every pass, remounting\n * the whole subtree.\n */\n const roots = new Map<\n LayoutResourceKey<Resources>,\n (props: Record<string, unknown>) => JSX.Element\n >();\n\n function getRoot(resource: LayoutResourceKey<Resources>) {\n let root = roots.get(resource);\n\n if (root === undefined) {\n const entry = definedEntries.get(resource);\n\n if (entry === undefined) {\n // Without an entry there are no create-time layout options, so a\n // layout with required props would fail validation deep inside\n // its own render. Fail here instead, naming the fix.\n throw new Error(\n `Render context component \"Root\" requires a \"resources.${resource}\" entry to build the layout for resource \"${resource}\"`,\n );\n }\n\n const { render: _render, ...layoutOptions } = entry;\n\n root = scopedCreateResourceLayout({\n ...layoutOptions,\n name:\n layoutOptions.name ??\n defaultNames.get(resource) ??\n capitalize(resource),\n resource,\n }) as (props: Record<string, unknown>) => JSX.Element;\n roots.set(resource, root);\n }\n\n return root;\n }\n\n function Root(rootProps: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new Error(\n 'Render context component \"Root\" must be rendered inside its scoped component',\n );\n }\n\n return createElement(\n getRoot(componentProps.resource as LayoutResourceKey<Resources>),\n rootProps,\n );\n }\n\n renderContext.Root = Root;\n\n function Component(componentProps: Record<string, unknown>) {\n const componentResource =\n componentProps.resource as LayoutResourceKey<Resources>;\n\n if (!selectedResources.has(componentResource)) {\n throw new Error(\n `Resource \"${componentResource}\" is not available in this scoped component`,\n );\n }\n\n const availableDefinitions =\n getComponentPropDefinitions(componentResource);\n const definitionsToValidate: Record<string, AnyBuiltPropDefinition> =\n {};\n\n for (const [key, inclusion] of Object.entries(include)) {\n const definition = availableDefinitions[key];\n\n if (!definition) {\n continue;\n }\n\n // Keep declared keys as-is — do not capitalize JSX.Element props.\n if (inclusion === true || key in componentProps) {\n definitionsToValidate[key] = definition;\n }\n }\n\n for (const [key, definition] of Object.entries(custom)) {\n if (key === 'children' || key === 'resource') {\n continue;\n }\n\n definitionsToValidate[key] = definition;\n }\n\n validateProps(definitionsToValidate, componentProps);\n\n return createElement(\n componentPropsContext.Provider,\n { value: componentProps },\n componentOptions.render(componentProps, renderContext),\n );\n }\n\n /**\n * Bound components are created once per resource and cached. Returning a\n * fresh component from the factory would hand React a new component type\n * whenever the caller rebinds, remounting the subtree.\n */\n const boundComponents = new Map<\n LayoutResourceKey<Resources>,\n (props: Record<string, unknown>) => JSX.Element\n >();\n\n function bindResource(resource: LayoutResourceKey<Resources>) {\n if (!selectedResources.has(resource)) {\n throw new Error(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n let boundComponent = boundComponents.get(resource);\n\n if (boundComponent === undefined) {\n boundComponent = Object.assign(\n (boundProps: Record<string, unknown>) =>\n createElement(Component, { ...boundProps, resource }),\n {\n displayName: `ScopedResourceComponent(${resource})`,\n props: undefined,\n resource: undefined,\n },\n resourceScopedComponents.get(resource) ?? {},\n );\n boundComponents.set(resource, boundComponent);\n }\n\n return boundComponent;\n }\n\n function asHOF() {\n return bindResource;\n }\n\n return Object.assign(Component, {\n asHOF,\n displayName: 'ScopedResourceComponent',\n props: undefined,\n });\n }\n\n const scopedExtras: {\n createComponent: typeof createComponent;\n forResource: typeof scopedForResource;\n makeComposable?: (options: Record<string, unknown>) => unknown;\n resources: undefined;\n } = {\n createComponent,\n forResource: scopedForResource,\n resources: undefined,\n };\n\n if (createMakeComposableLayout) {\n const makeComposableLayout = createMakeComposableLayout();\n\n scopedExtras.makeComposable = (options) => {\n const resource = options.resource as LayoutResourceKey<Resources>;\n\n return makeComposableLayout({\n ...options,\n name: options.name ?? defaultNames.get(resource),\n });\n };\n }\n\n return Object.assign(scopedCreateResourceLayout, scopedExtras);\n }) as unknown as CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n}\n"],"mappings":";;;;;;;;;;;AAihCA,MAAM,+BAA+B,IAAI,IAAI;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAkBD,SAAgB,mBAMd,EACA,yBACA,4BACA,sBACA,+BACuC;CACvC,SAAS,GAAG,uBAAuC;EACjD,MAAM,gBAAgB,mBAAmB;EACzC,IAAI;EASJ,IAAI,OAAO,kBAAkB,UAC3B,kBAAkB,mBAAmB,KAAK,cAAc,EAC5C,SACZ,EAAE;OACG,IACL,kBAAkB,QAClB,OAAO,kBAAkB,YACzB,eAAe,iBACf,MAAM,QAAQ,cAAc,SAAS,GACrC;GACA,MAAM,EAAE,MAAM,cAAc;GAI5B,kBAAkB,UAAU,KAAK,cAAc;IAC7C,MAAM,OAAO,SAAS,aAAa,OAAO,OAAO;IACjD;GACF,EAAE;EACJ,OACE,kBAAkB,OAAO,QAAQ,iBAAiB,CAAC,CAAC,EAAE,KACnD,CAAC,UAAU,cAAc;GACxB,GAAI;GAOM;EACZ,EACF;EAGF,MAAM,eAAe,IAAI,IACvB,gBAAgB,KAAK,EAAE,MAAM,eAAe,CAC1C,UACA,OAAO,SAAS,aACZ,KACE,WAAW,QAAQ,CAGrB,IACA,IACN,CAAC,CACH;EAEA,SAAS,2BAA2B,SAAkC;GACpE,MAAM,WAAW,QAAQ;GAEzB,OAAO,qBAAqB;IAC1B,GAAG;IACH,MAAM,QAAQ,QAAQ,aAAa,IAAI,QAAQ;GACjD,CAAC;EACH;EAEA,SAAS,kBAAkB,SAGxB;GACD,OAAO,wBACL,QAAQ,QAAQ,aAAa,IAAI,QAAQ,QAAQ,GACjD,QAAQ,QACV;EACF;EAmBA,SAAS,gBAAgB,kBAUtB;GACD,MAAM,UAAU,iBAAiB,OAAO,WAAW,CAAC;GACpD,MAAM,SAAS,i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