@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.
Files changed (60) hide show
  1. package/dist/create-config/define-layout.cjs +15 -4
  2. package/dist/create-config/define-layout.cjs.map +1 -1
  3. package/dist/create-config/define-layout.d.cts +31 -5
  4. package/dist/create-config/define-layout.d.cts.map +1 -1
  5. package/dist/create-config/define-layout.d.mts +31 -5
  6. package/dist/create-config/define-layout.d.mts.map +1 -1
  7. package/dist/create-config/define-layout.mjs +14 -3
  8. package/dist/create-config/define-layout.mjs.map +1 -1
  9. package/dist/create-config/for-resources/create-component.d.cts +284 -0
  10. package/dist/create-config/for-resources/create-component.d.cts.map +1 -0
  11. package/dist/create-config/for-resources/create-component.d.mts +284 -0
  12. package/dist/create-config/for-resources/create-component.d.mts.map +1 -0
  13. package/dist/create-config/{for-resources.cjs → for-resources/create-for-resources.cjs} +78 -39
  14. package/dist/create-config/for-resources/create-for-resources.cjs.map +1 -0
  15. package/dist/create-config/for-resources/create-for-resources.d.cts +1 -0
  16. package/dist/create-config/for-resources/create-for-resources.d.mts +1 -0
  17. package/dist/create-config/{for-resources.mjs → for-resources/create-for-resources.mjs} +77 -38
  18. package/dist/create-config/for-resources/create-for-resources.mjs.map +1 -0
  19. package/dist/create-config/for-resources/index.d.cts +1 -0
  20. package/dist/create-config/for-resources/index.d.mts +1 -0
  21. package/dist/create-config/for-resources/resource-selection.d.cts +47 -0
  22. package/dist/create-config/for-resources/resource-selection.d.cts.map +1 -0
  23. package/dist/create-config/for-resources/resource-selection.d.mts +47 -0
  24. package/dist/create-config/for-resources/resource-selection.d.mts.map +1 -0
  25. package/dist/create-config/for-resources/scoped-layout.d.cts +185 -0
  26. package/dist/create-config/for-resources/scoped-layout.d.cts.map +1 -0
  27. package/dist/create-config/for-resources/scoped-layout.d.mts +185 -0
  28. package/dist/create-config/for-resources/scoped-layout.d.mts.map +1 -0
  29. package/dist/create-config/for-resources/scoped-render.cjs +103 -0
  30. package/dist/create-config/for-resources/scoped-render.cjs.map +1 -0
  31. package/dist/create-config/for-resources/scoped-render.d.cts +18 -0
  32. package/dist/create-config/for-resources/scoped-render.d.cts.map +1 -0
  33. package/dist/create-config/for-resources/scoped-render.d.mts +18 -0
  34. package/dist/create-config/for-resources/scoped-render.d.mts.map +1 -0
  35. package/dist/create-config/for-resources/scoped-render.mjs +100 -0
  36. package/dist/create-config/for-resources/scoped-render.mjs.map +1 -0
  37. package/dist/create-config/index.d.cts +1 -1
  38. package/dist/create-config/index.d.mts +1 -1
  39. package/dist/index.d.cts +2 -2
  40. package/dist/index.d.mts +2 -2
  41. package/dist/props.d.cts +22 -1
  42. package/dist/props.d.cts.map +1 -1
  43. package/dist/props.d.mts +22 -1
  44. package/dist/props.d.mts.map +1 -1
  45. package/dist/utils.cjs.map +1 -1
  46. package/dist/utils.d.cts.map +1 -1
  47. package/dist/utils.d.mts.map +1 -1
  48. package/dist/utils.mjs.map +1 -1
  49. package/package.json +3 -2
  50. package/skills/build-react-layouts/SKILL.md +132 -0
  51. package/skills/build-react-layouts/agents/openai.yaml +4 -0
  52. package/skills/build-react-layouts/references/architecture.md +184 -0
  53. package/skills/build-react-layouts/references/factory-patterns.md +156 -0
  54. package/skills/build-react-layouts/references/routing-and-navigation.md +174 -0
  55. package/dist/create-config/for-resources.cjs.map +0 -1
  56. package/dist/create-config/for-resources.d.cts +0 -358
  57. package/dist/create-config/for-resources.d.cts.map +0 -1
  58. package/dist/create-config/for-resources.d.mts +0 -358
  59. package/dist/create-config/for-resources.d.mts.map +0 -1
  60. package/dist/create-config/for-resources.mjs.map +0 -1
@@ -0,0 +1,156 @@
1
+ # Factory Patterns
2
+
3
+ ## Contents
4
+
5
+ - Direct creation
6
+ - Resource-scoped factories
7
+ - Composable detail pages
8
+ - Multi-resource subsets
9
+ - Higher-order multi-resource components
10
+ - Selection guide
11
+
12
+ ## Create one page directly
13
+
14
+ Use direct creation for one isolated page:
15
+
16
+ ```tsx
17
+ export const WaitlistPage = createResourceLayout({
18
+ resource: 'waitlist',
19
+ name: 'WaitlistPage',
20
+ segments: {
21
+ title: 'Waitlist',
22
+ },
23
+ });
24
+ ```
25
+
26
+ Provide an explicit `name` when the surrounding factory does not establish one.
27
+
28
+ ## Scope a factory to one resource
29
+
30
+ Use `forResource` when multiple page definitions share one resource:
31
+
32
+ ```tsx
33
+ const createLocationsPage = createResourceLayout.forResource({
34
+ resource: 'locations',
35
+ });
36
+
37
+ export const LocationsPage = createLocationsPage({
38
+ segments: {
39
+ title: 'Locations',
40
+ },
41
+ });
42
+ ```
43
+
44
+ Keep the scoped factory private unless several modules genuinely need it.
45
+
46
+ ## Make a generated page composable
47
+
48
+ Use `makeComposable` when a page needs to retain the resource layout contract
49
+ while allowing consumers to address or rearrange semantic regions:
50
+
51
+ ```tsx
52
+ export const LocationsDetailPage = LocationsPage.makeComposable({
53
+ name: 'LocationsDetailPage',
54
+ });
55
+ ```
56
+
57
+ Prefer this over copying the parent layout or manually reproducing its header
58
+ and content structure. Do not call `makeComposable` when consumers only need to
59
+ pass `children` or other declared custom props.
60
+
61
+ ## Narrow a factory to several resources
62
+
63
+ Use `forResources` when a shared implementation applies to a known subset:
64
+
65
+ ```tsx
66
+ const createCalendarPane =
67
+ resourcePaneLayout.createResourceLayout.forResources('create', 'detail');
68
+
69
+ export const createCalendarDetailPane = createCalendarPane.forResource({
70
+ resource: 'detail',
71
+ });
72
+
73
+ export const createCalendarCreatePane = createCalendarPane.forResource({
74
+ resource: 'create',
75
+ });
76
+ ```
77
+
78
+ Narrow the resource set before creating the final resource-specific factory.
79
+
80
+ ## Create a higher-order multi-resource component
81
+
82
+ Use the advanced component factory when several resources share behavior but
83
+ need distinct render implementations:
84
+
85
+ ```tsx
86
+ const createCalendarPage = createResourceLayout
87
+ .forResources('appointments', 'availability')
88
+ .createComponent({
89
+ resources: {
90
+ appointments: {
91
+ segments: {
92
+ title: 'Appointments',
93
+ },
94
+ render: function AppointmentsRender() {
95
+ return <AppointmentsView />;
96
+ },
97
+ },
98
+ availability: {
99
+ segments: {
100
+ title: 'Availability',
101
+ },
102
+ render: function AvailabilityRender() {
103
+ return <AvailabilityView />;
104
+ },
105
+ },
106
+ },
107
+ render: function Render({ resource, children }, context) {
108
+ return (
109
+ <context.Root>
110
+ {children ??
111
+ (resource === 'appointments' ? (
112
+ <context.Appointments />
113
+ ) : (
114
+ <context.Availability />
115
+ ))}
116
+ </context.Root>
117
+ );
118
+ },
119
+ })
120
+ .asHOF();
121
+
122
+ export const AppointmentsPage = createCalendarPage('appointments');
123
+ export const AvailabilityPage = createCalendarPage('availability');
124
+ ```
125
+
126
+ Use this pattern only when the resources share meaningful behavior, controls,
127
+ or state transitions. The outer renderer should own behavior shared by the
128
+ resource subset. Each resource renderer should own resource-specific data and
129
+ content.
130
+
131
+ Attach closely related states when that creates a useful page namespace:
132
+
133
+ ```tsx
134
+ export const AppointmentsPage = Object.assign(
135
+ createCalendarPage('appointments'),
136
+ {
137
+ Loading: AppointmentsLoading,
138
+ Error: AppointmentsError,
139
+ NotFound: AppointmentsNotFound,
140
+ },
141
+ );
142
+ ```
143
+
144
+ Use this for components that are semantically part of the generated page
145
+ surface. Avoid turning the page component into an unrelated utility namespace.
146
+
147
+ ## Choose the narrowest factory
148
+
149
+ - For one page, call `createResourceLayout`.
150
+ - For several pages belonging to one resource, use `forResource`.
151
+ - For several resources with the same configuration shape, use `forResources`.
152
+ - When consumers need semantic subcomponents, use `makeComposable`.
153
+ - When several resources share an outer behavior but need distinct
154
+ implementations, use `createComponent(...).asHOF()`.
155
+ - When the surface has a different structural contract, create another
156
+ `defineResourceLayout`.
@@ -0,0 +1,174 @@
1
+ # Routing and Navigation
2
+
3
+ ## Contents
4
+
5
+ - Grouped resource links
6
+ - Resource configuration
7
+ - Route dispatch
8
+ - Runtime route validation
9
+ - Async route states
10
+ - Separation of concerns
11
+
12
+ ## Generate grouped resource links
13
+
14
+ Generate navigation from the layout's resource vocabulary:
15
+
16
+ ```tsx
17
+ const navigation = createResourceLinks.withGroups([
18
+ {
19
+ links: {
20
+ dashboard: {
21
+ label: 'Dashboard',
22
+ icon: <DashboardIcon />,
23
+ href: '/admin',
24
+ },
25
+ appointments: {
26
+ label: 'Appointments',
27
+ icon: <AppointmentsIcon />,
28
+ },
29
+ },
30
+ },
31
+ {
32
+ label: 'Configuration',
33
+ links: {
34
+ settings: {
35
+ label: 'Settings',
36
+ icon: <SettingsIcon />,
37
+ },
38
+ },
39
+ },
40
+ ]);
41
+ ```
42
+
43
+ Use groups to express information architecture. Let normal resources use the
44
+ shared resource route. Provide `href` only for special destinations whose route
45
+ does not follow the general pattern.
46
+
47
+ Render links using the generated `resource` value instead of reconstructing it
48
+ from labels.
49
+
50
+ ## Create the resource configuration
51
+
52
+ Create a typed configuration that maps each routeable resource to its normal
53
+ and asynchronous states:
54
+
55
+ ```tsx
56
+ export const resourcePageConfig = createResourceConfig({
57
+ appointments: {
58
+ component: <AppointmentsPage />,
59
+ pendingComponent: (
60
+ <AppointmentsPage>
61
+ <AppointmentsPage.Loading />
62
+ </AppointmentsPage>
63
+ ),
64
+ errorComponent: (
65
+ <AppointmentsPage>
66
+ <AppointmentsPage.Error />
67
+ </AppointmentsPage>
68
+ ),
69
+ notFoundComponent: (
70
+ <AppointmentsPage>
71
+ <AppointmentsPage.NotFound />
72
+ </AppointmentsPage>
73
+ ),
74
+ },
75
+ locations: {
76
+ component: <Locations />,
77
+ pendingComponent: <LocationsLoading />,
78
+ errorComponent: <LocationsError />,
79
+ notFoundComponent: <LocationsNotFound />,
80
+ detail: {
81
+ component: <LocationDetail />,
82
+ pendingComponent: <LocationDetailLoading />,
83
+ errorComponent: <LocationDetailError />,
84
+ notFoundComponent: <LocationDetailNotFound />,
85
+ },
86
+ },
87
+ });
88
+ ```
89
+
90
+ Keep this mapping declarative. Keep data fetching and mutation logic inside the
91
+ corresponding feature components or router loaders.
92
+
93
+ ## Dispatch route components generically
94
+
95
+ Use one generic route adapter to select the configured component:
96
+
97
+ ```tsx
98
+ type ResourceComponentKey =
99
+ | 'component'
100
+ | 'pendingComponent'
101
+ | 'errorComponent'
102
+ | 'notFoundComponent';
103
+
104
+ function getResourceComponent(component: ResourceComponentKey) {
105
+ const resource = Route.useParams({
106
+ select: ({ resource }) => resource,
107
+ });
108
+
109
+ return resourcePageConfig.getComponent.forResource({
110
+ resource,
111
+ })({
112
+ component,
113
+ });
114
+ }
115
+
116
+ function RouteComponent() {
117
+ return getResourceComponent('component');
118
+ }
119
+
120
+ function PendingComponent() {
121
+ return getResourceComponent('pendingComponent');
122
+ }
123
+ ```
124
+
125
+ Use the same mechanism for error and not-found states. Do not create resource
126
+ condition chains in the generic route component when the information belongs
127
+ in `createResourceConfig`.
128
+
129
+ ## Validate route parameters at runtime
130
+
131
+ The layout provides compile-time resource constraints. The router must still
132
+ validate untrusted URL parameters at runtime.
133
+
134
+ Parse or validate the route parameter before passing it to generated resource
135
+ helpers. Reject invalid resources through the router's normal not-found
136
+ mechanism. Keep routing validation in the router layer instead of embedding it
137
+ in the shared layout renderer.
138
+
139
+ ## Preserve the layout during async states
140
+
141
+ Wrap pending, error, and not-found content in the same generated page shell
142
+ when the shell should remain visible during those states.
143
+
144
+ Use a separate route-state surface when a detail view cannot render its normal
145
+ page structure without loaded data. Keep the mapping explicit so one resource's
146
+ state cannot appear inside another resource's layout.
147
+
148
+ ## Keep ownership clear
149
+
150
+ Let the layout layer own:
151
+
152
+ - Valid resource vocabulary
153
+ - Shared application structure
154
+ - Page configuration contracts
155
+ - Semantic composition points
156
+ - Navigation metadata
157
+ - Resource-to-component dispatch
158
+
159
+ Let the router own:
160
+
161
+ - URL parsing
162
+ - Search parameter validation
163
+ - Redirects
164
+ - Loaders
165
+ - Route lifecycle selection
166
+ - Runtime not-found behavior
167
+
168
+ Let feature components own:
169
+
170
+ - Queries and mutations
171
+ - Feature-level loading details
172
+ - Tables and calendars
173
+ - Forms
174
+ - Resource-specific interactions
@@ -1 +0,0 @@
1
- {"version":3,"file":"for-resources.cjs","names":["capitalize"],"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,k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