@jfdevelops/react-layout 0.24.3 → 1.0.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 (77) hide show
  1. package/dist/create-config/create-defined-resource-layout.cjs +72 -0
  2. package/dist/create-config/create-defined-resource-layout.cjs.map +1 -0
  3. package/dist/create-config/create-defined-resource-layout.d.cts +88 -0
  4. package/dist/create-config/create-defined-resource-layout.d.cts.map +1 -0
  5. package/dist/create-config/create-defined-resource-layout.d.mts +88 -0
  6. package/dist/create-config/create-defined-resource-layout.d.mts.map +1 -0
  7. package/dist/create-config/create-defined-resource-layout.mjs +72 -0
  8. package/dist/create-config/create-defined-resource-layout.mjs.map +1 -0
  9. package/dist/create-config/create-resource-links.cjs.map +1 -1
  10. package/dist/create-config/create-resource-links.d.cts +1 -1
  11. package/dist/create-config/create-resource-links.d.cts.map +1 -1
  12. package/dist/create-config/create-resource-links.d.mts +1 -1
  13. package/dist/create-config/create-resource-links.d.mts.map +1 -1
  14. package/dist/create-config/create-resource-links.mjs.map +1 -1
  15. package/dist/create-config/define-layout.cjs +199 -9
  16. package/dist/create-config/define-layout.cjs.map +1 -1
  17. package/dist/create-config/define-layout.d.cts +172 -29
  18. package/dist/create-config/define-layout.d.cts.map +1 -1
  19. package/dist/create-config/define-layout.d.mts +172 -29
  20. package/dist/create-config/define-layout.d.mts.map +1 -1
  21. package/dist/create-config/define-layout.mjs +202 -13
  22. package/dist/create-config/define-layout.mjs.map +1 -1
  23. package/dist/create-config/for-resources/create-for-resources.cjs +7 -0
  24. package/dist/create-config/for-resources/create-for-resources.cjs.map +1 -1
  25. package/dist/create-config/for-resources/create-for-resources.mjs +7 -0
  26. package/dist/create-config/for-resources/create-for-resources.mjs.map +1 -1
  27. package/dist/create-config/get-component.cjs +22 -1
  28. package/dist/create-config/get-component.cjs.map +1 -1
  29. package/dist/create-config/get-component.d.cts +25 -3
  30. package/dist/create-config/get-component.d.cts.map +1 -1
  31. package/dist/create-config/get-component.d.mts +25 -3
  32. package/dist/create-config/get-component.d.mts.map +1 -1
  33. package/dist/create-config/get-component.mjs +22 -1
  34. package/dist/create-config/get-component.mjs.map +1 -1
  35. package/dist/create-config/index.d.cts +5 -2
  36. package/dist/create-config/index.d.mts +5 -2
  37. package/dist/create-config/lazy-resource-layout.cjs +111 -0
  38. package/dist/create-config/lazy-resource-layout.cjs.map +1 -0
  39. package/dist/create-config/lazy-resource-layout.d.cts +51 -0
  40. package/dist/create-config/lazy-resource-layout.d.cts.map +1 -0
  41. package/dist/create-config/lazy-resource-layout.d.mts +51 -0
  42. package/dist/create-config/lazy-resource-layout.d.mts.map +1 -0
  43. package/dist/create-config/lazy-resource-layout.mjs +111 -0
  44. package/dist/create-config/lazy-resource-layout.mjs.map +1 -0
  45. package/dist/create-config/render-state.cjs +62 -0
  46. package/dist/create-config/render-state.cjs.map +1 -0
  47. package/dist/create-config/render-state.d.cts +121 -0
  48. package/dist/create-config/render-state.d.cts.map +1 -0
  49. package/dist/create-config/render-state.d.mts +121 -0
  50. package/dist/create-config/render-state.d.mts.map +1 -0
  51. package/dist/create-config/render-state.mjs +55 -0
  52. package/dist/create-config/render-state.mjs.map +1 -0
  53. package/dist/errors/resource-state-error.cjs +29 -0
  54. package/dist/errors/resource-state-error.cjs.map +1 -0
  55. package/dist/errors/resource-state-error.d.cts +19 -0
  56. package/dist/errors/resource-state-error.d.cts.map +1 -0
  57. package/dist/errors/resource-state-error.d.mts +19 -0
  58. package/dist/errors/resource-state-error.d.mts.map +1 -0
  59. package/dist/errors/resource-state-error.mjs +27 -0
  60. package/dist/errors/resource-state-error.mjs.map +1 -0
  61. package/dist/index.cjs +6 -0
  62. package/dist/index.d.cts +9 -5
  63. package/dist/index.d.mts +9 -5
  64. package/dist/index.mjs +4 -2
  65. package/dist/props.d.cts +6 -1
  66. package/dist/props.d.cts.map +1 -1
  67. package/dist/props.d.mts +6 -1
  68. package/dist/props.d.mts.map +1 -1
  69. package/dist/resource.cjs +17 -0
  70. package/dist/resource.cjs.map +1 -1
  71. package/dist/resource.d.cts +33 -1
  72. package/dist/resource.d.cts.map +1 -1
  73. package/dist/resource.d.mts +33 -1
  74. package/dist/resource.d.mts.map +1 -1
  75. package/dist/resource.mjs +17 -1
  76. package/dist/resource.mjs.map +1 -1
  77. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"create-for-resources.cjs","names":["capitalize","LayoutConfigurationError","reservedScopedComponentNames","isRenderableComponentType","resolveScopedRenderResult","withScopedCompoundStatics"],"sources":["../../../src/create-config/for-resources/create-for-resources.ts"],"sourcesContent":["import {\n createContext,\n createElement,\n type ComponentType,\n type JSX,\n useContext,\n} from 'react';\nimport type { ComposableComponents } from '@jfdevelops/react-layout-composables';\nimport {\n type AnyBuiltPropDefinition,\n validateProps,\n} from '@jfdevelops/react-layout-validator';\nimport type { InPropsDefinition, InPropsObject } from '../../props';\nimport type { LayoutResourceKey, ResourceDefinition } from '../../resource';\nimport { capitalize } from '../../utils/capitalize';\nimport { LayoutConfigurationError } from '../../errors';\nimport type { LayoutIncludeProps } from '../define-layout';\nimport type {\n CapitalizedResource,\n ResourcesLayoutName,\n} from './resource-selection';\nimport type { CreateResourceLayoutForResourcesFn } from './scoped-layout';\nimport {\n isRenderableComponentType,\n reservedScopedComponentNames,\n resolveScopedRenderResult,\n type ScopedRenderResult,\n withScopedCompoundStatics,\n} from './scoped-render';\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 ) => ScopedRenderResult;\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 props?: CreateComponentPropsBag;\n components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n type CreateComponentPropsBag = {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n defined?: Record<string, unknown>;\n };\n\n function mergeCreateComponentProps(\n ...bags: Array<CreateComponentPropsBag | undefined>\n ): CreateComponentPropsBag {\n const include: Record<string, true | 'optional'> = {};\n const custom: Record<string, AnyBuiltPropDefinition> = {};\n\n for (const bag of bags) {\n Object.assign(include, bag?.include);\n Object.assign(custom, bag?.custom);\n\n for (const key of Object.keys(bag?.defined ?? {})) {\n include[key] = true;\n }\n }\n\n return { include, custom };\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 ) => ScopedRenderResult;\n }) {\n const mergedProps = mergeCreateComponentProps(\n componentOptions.props,\n ...Object.values(componentOptions.resources ?? {}).map(\n (entry) => entry.props,\n ),\n );\n const include = mergedProps.include ?? {};\n const custom = mergedProps.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 LayoutConfigurationError(\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 LayoutConfigurationError(\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 LayoutConfigurationError(\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 LayoutConfigurationError(\n `Scoped component \"${name}\" for resource \"${resource}\" uses a reserved name`,\n );\n }\n\n const ownPropDefinitions = definition.props ?? {};\n // Last call-site own-props / returned component for this scoped\n // entry. Compound statics re-run `render` with these so\n // `<DataTable variant=\"b\" />` then `<DataTable.Loading />` sees \"b\".\n let cachedOwnProps: Record<string, unknown> = {};\n let cachedReturnedComponent:\n | ComponentType<Record<string, unknown>>\n | undefined;\n\n function ScopedComponent(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" must be rendered inside its scoped component`,\n );\n }\n\n const resolvedOwnProps = ownProps ?? {};\n cachedOwnProps = resolvedOwnProps;\n\n validateProps(ownPropDefinitions, resolvedOwnProps, {\n layoutName:\n entry.name ??\n defaultNames.get(resource) ??\n capitalize(resource),\n resource,\n });\n\n // Mount a returned component type with call-site props; pass\n // nodes (elements, portals, null) through unchanged.\n const result = definition.render(\n { ...componentProps, ...resolvedOwnProps, resource },\n scopedComponents,\n );\n\n if (isRenderableComponentType(result)) {\n cachedReturnedComponent = result as ComponentType<\n Record<string, unknown>\n >;\n }\n\n return resolveScopedRenderResult(result, resolvedOwnProps);\n }\n\n // Types expose compound statics from the returned component\n // (`DataTable.Loading`); attach matching runtime wrappers.\n scopedComponents[name] = withScopedCompoundStatics(\n ScopedComponent,\n (staticName) => {\n function CompoundStatic(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}.${staticName}\" must be rendered inside its scoped component`,\n );\n }\n\n // Prefer the component from the last parent call (same\n // closure as that call's own-props). Fall back to re-running\n // render with cached parent props when needed.\n let result: unknown = cachedReturnedComponent;\n\n if (!isRenderableComponentType(result)) {\n result = definition.render(\n {\n ...componentProps,\n ...cachedOwnProps,\n resource,\n },\n scopedComponents,\n );\n }\n\n if (!isRenderableComponentType(result)) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" must return a component type to use static \"${staticName}\"`,\n );\n }\n\n const staticComponent = (\n result as ComponentType<Record<string, unknown>> &\n Record<string, unknown>\n )[staticName];\n\n if (!isRenderableComponentType(staticComponent)) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" has no component static \"${staticName}\"`,\n );\n }\n\n // Loading's props — those mount the static itself.\n return createElement(staticComponent, ownProps ?? {});\n }\n\n CompoundStatic.displayName = `${name}.${staticName}`;\n return CompoundStatic;\n },\n ) as (props?: never) => JSX.Element;\n }\n\n resourceScopedComponents.set(resource, scopedComponents);\n\n function ResourceRender(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Render context component \"${contextKey}\" must be rendered inside its scoped component`,\n );\n }\n\n // Call-site props on `context.Users({ title, heading })` merge into\n // the resource render props and mount a returned component type.\n const callProps = { ...componentProps, ...ownProps, resource };\n return resolveScopedRenderResult(\n entry.render(callProps, scopedComponents),\n ownProps,\n );\n }\n\n return [\n contextKey,\n Object.assign(ResourceRender, scopedComponents),\n ];\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 Root(rootProps: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n 'Render context component \"Root\" must be rendered inside its scoped component',\n );\n }\n\n const resource =\n componentProps.resource as 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 throw new LayoutConfigurationError(\n `Render context component \"Root\" requires a \"resources.${resource}\" entry to build the layout for resource \"${resource}\"`,\n );\n }\n\n // Layout option values come from the outer component call site\n // (`<Directory title=\"…\" />`), not from the resource entry.\n const availableDefinitions =\n getComponentPropDefinitions(resource);\n const layoutOptions: Record<string, unknown> = {};\n const defined = entry.props?.defined ?? {};\n\n for (const key of Object.keys(availableDefinitions)) {\n if (key in defined) {\n layoutOptions[key] = defined[key];\n }\n\n const capitalized = capitalize(key);\n if (capitalized in defined) {\n layoutOptions[capitalized] = defined[capitalized];\n }\n\n if (key in componentProps) {\n layoutOptions[key] = componentProps[key];\n }\n\n if (capitalized in componentProps) {\n layoutOptions[capitalized] = componentProps[capitalized];\n }\n }\n\n root = scopedCreateResourceLayout({\n ...layoutOptions,\n name:\n entry.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 const entry = definedEntries.get(resource);\n const definedCustom: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(\n entry?.props?.defined ?? {},\n )) {\n if (key in custom) {\n definedCustom[key] = value;\n }\n }\n\n return createElement(root, { ...definedCustom, ...rootProps });\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 LayoutConfigurationError(\n `Resource \"${componentResource}\" is not available in this scoped component`,\n );\n }\n\n const defined =\n definedEntries.get(componentResource)?.props?.defined ?? {};\n const resolvedComponentProps = { ...defined, ...componentProps };\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 resolvedComponentProps) {\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, resolvedComponentProps, {\n layoutName:\n definedEntries.get(componentResource)?.name ??\n defaultNames.get(componentResource) ??\n capitalize(componentResource),\n resource: componentResource,\n });\n\n // Top-level render may return a component type; mount it with the full\n // component props (include/custom + inferred return-type props).\n return createElement(\n componentPropsContext.Provider,\n { value: resolvedComponentProps },\n resolveScopedRenderResult(\n componentOptions.render(resolvedComponentProps, renderContext),\n resolvedComponentProps,\n ),\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 LayoutConfigurationError(\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 function createComponentSetProps(baseProps: CreateComponentPropsBag) {\n function createWithProps(componentOptions: {\n props?: CreateComponentPropsBag;\n resources?: Record<string, ScopedComponentEntry>;\n render: (\n props: Record<string, unknown>,\n context: Record<string, (props: never) => JSX.Element>,\n ) => ScopedRenderResult;\n }) {\n return createComponent({\n ...componentOptions,\n props: mergeCreateComponentProps(baseProps, componentOptions.props),\n });\n }\n\n createWithProps.createResourceComponents = createResourceComponents;\n\n return createWithProps;\n }\n\n function createResourceComponents(options: {\n resource: LayoutResourceKey<Resources>;\n props?: CreateComponentPropsBag;\n name?: string;\n components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n }) {\n const { resource, props, ...entry } = options;\n\n if (\n !resourceOptions.some(\n (resourceOption) => resourceOption.resource === resource,\n )\n ) {\n throw new LayoutConfigurationError(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n return { ...entry, props: props ?? {} };\n }\n\n Object.assign(createComponent, {\n setProps: createComponentSetProps,\n });\n\n const scopedExtras: {\n createComponent: typeof createComponent;\n createResourceComponents: typeof createResourceComponents;\n forResource: typeof scopedForResource;\n makeComposable?: (options: Record<string, unknown>) => unknown;\n resources: undefined;\n } = {\n createComponent,\n createResourceComponents,\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":";;;;;;;AA8CA,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,KACEA,8BAAW,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;EA0BA,SAAS,0BACP,GAAG,MACsB;GACzB,MAAM,UAA6C,CAAC;GACpD,MAAM,SAAiD,CAAC;GAExD,KAAK,MAAM,OAAO,MAAM;IACtB,OAA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AO,OAAO,4BAA4B,YAAY;CAC/D;AAOF"}
1
+ {"version":3,"file":"create-for-resources.cjs","names":["capitalize","LayoutConfigurationError","reservedScopedComponentNames","isRenderableComponentType","resolveScopedRenderResult","withScopedCompoundStatics"],"sources":["../../../src/create-config/for-resources/create-for-resources.ts"],"sourcesContent":["import {\n createContext,\n createElement,\n type ComponentType,\n type JSX,\n useContext,\n} from 'react';\nimport type { ComposableComponents } from '@jfdevelops/react-layout-composables';\nimport {\n type AnyBuiltPropDefinition,\n validateProps,\n} from '@jfdevelops/react-layout-validator';\nimport type { InPropsDefinition, InPropsObject } from '../../props';\nimport type { LayoutResourceKey, ResourceDefinition } from '../../resource';\nimport { capitalize } from '../../utils/capitalize';\nimport { LayoutConfigurationError } from '../../errors';\nimport type { LayoutIncludeProps } from '../define-layout';\nimport type {\n CapitalizedResource,\n ResourcesLayoutName,\n} from './resource-selection';\nimport type { CreateResourceLayoutForResourcesFn } from './scoped-layout';\nimport {\n isRenderableComponentType,\n reservedScopedComponentNames,\n resolveScopedRenderResult,\n type ScopedRenderResult,\n withScopedCompoundStatics,\n} from './scoped-render';\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 ) => ScopedRenderResult;\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 props?: CreateComponentPropsBag;\n components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n type CreateComponentPropsBag = {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n defined?: Record<string, unknown>;\n };\n\n function mergeCreateComponentProps(\n ...bags: Array<CreateComponentPropsBag | undefined>\n ): CreateComponentPropsBag {\n const include: Record<string, true | 'optional'> = {};\n const custom: Record<string, AnyBuiltPropDefinition> = {};\n\n for (const bag of bags) {\n Object.assign(include, bag?.include);\n Object.assign(custom, bag?.custom);\n\n for (const key of Object.keys(bag?.defined ?? {})) {\n include[key] = true;\n }\n }\n\n return { include, custom };\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 ) => ScopedRenderResult;\n }) {\n const mergedProps = mergeCreateComponentProps(\n componentOptions.props,\n ...Object.values(componentOptions.resources ?? {}).map(\n (entry) => entry.props,\n ),\n );\n const include = mergedProps.include ?? {};\n const custom = mergedProps.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 LayoutConfigurationError(\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 LayoutConfigurationError(\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 LayoutConfigurationError(\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 LayoutConfigurationError(\n `Scoped component \"${name}\" for resource \"${resource}\" uses a reserved name`,\n );\n }\n\n const ownPropDefinitions = definition.props ?? {};\n // Last call-site own-props / returned component for this scoped\n // entry. Compound statics re-run `render` with these so\n // `<DataTable variant=\"b\" />` then `<DataTable.Loading />` sees \"b\".\n let cachedOwnProps: Record<string, unknown> = {};\n let cachedReturnedComponent:\n | ComponentType<Record<string, unknown>>\n | undefined;\n\n function ScopedComponent(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" must be rendered inside its scoped component`,\n );\n }\n\n const resolvedOwnProps = ownProps ?? {};\n cachedOwnProps = resolvedOwnProps;\n\n validateProps(ownPropDefinitions, resolvedOwnProps, {\n layoutName:\n entry.name ??\n defaultNames.get(resource) ??\n capitalize(resource),\n resource,\n });\n\n // Mount a returned component type with call-site props; pass\n // nodes (elements, portals, null) through unchanged.\n const result = definition.render(\n { ...componentProps, ...resolvedOwnProps, resource },\n scopedComponents,\n );\n\n if (isRenderableComponentType(result)) {\n cachedReturnedComponent = result as ComponentType<\n Record<string, unknown>\n >;\n }\n\n return resolveScopedRenderResult(result, resolvedOwnProps);\n }\n\n // Types expose compound statics from the returned component\n // (`DataTable.Loading`); attach matching runtime wrappers.\n scopedComponents[name] = withScopedCompoundStatics(\n ScopedComponent,\n (staticName) => {\n function CompoundStatic(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}.${staticName}\" must be rendered inside its scoped component`,\n );\n }\n\n // Prefer the component from the last parent call (same\n // closure as that call's own-props). Fall back to re-running\n // render with cached parent props when needed.\n let result: unknown = cachedReturnedComponent;\n\n if (!isRenderableComponentType(result)) {\n result = definition.render(\n {\n ...componentProps,\n ...cachedOwnProps,\n resource,\n },\n scopedComponents,\n );\n }\n\n if (!isRenderableComponentType(result)) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" must return a component type to use static \"${staticName}\"`,\n );\n }\n\n const staticComponent = (\n result as ComponentType<Record<string, unknown>> &\n Record<string, unknown>\n )[staticName];\n\n if (!isRenderableComponentType(staticComponent)) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" has no component static \"${staticName}\"`,\n );\n }\n\n // Loading's props — those mount the static itself.\n return createElement(staticComponent, ownProps ?? {});\n }\n\n CompoundStatic.displayName = `${name}.${staticName}`;\n return CompoundStatic;\n },\n ) as (props?: never) => JSX.Element;\n }\n\n resourceScopedComponents.set(resource, scopedComponents);\n\n function ResourceRender(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Render context component \"${contextKey}\" must be rendered inside its scoped component`,\n );\n }\n\n // Call-site props on `context.Users({ title, heading })` merge into\n // the resource render props and mount a returned component type.\n const callProps = { ...componentProps, ...ownProps, resource };\n return resolveScopedRenderResult(\n entry.render(callProps, scopedComponents),\n ownProps,\n );\n }\n\n return [\n contextKey,\n Object.assign(ResourceRender, scopedComponents),\n ];\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 Root(rootProps: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n 'Render context component \"Root\" must be rendered inside its scoped component',\n );\n }\n\n const resource =\n componentProps.resource as 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 throw new LayoutConfigurationError(\n `Render context component \"Root\" requires a \"resources.${resource}\" entry to build the layout for resource \"${resource}\"`,\n );\n }\n\n // Layout option values come from the outer component call site\n // (`<Directory title=\"…\" />`), not from the resource entry.\n const availableDefinitions =\n getComponentPropDefinitions(resource);\n const layoutOptions: Record<string, unknown> = {};\n const defined = entry.props?.defined ?? {};\n\n for (const key of Object.keys(availableDefinitions)) {\n if (key in defined) {\n layoutOptions[key] = defined[key];\n }\n\n const capitalized = capitalize(key);\n if (capitalized in defined) {\n layoutOptions[capitalized] = defined[capitalized];\n }\n\n if (key in componentProps) {\n layoutOptions[key] = componentProps[key];\n }\n\n if (capitalized in componentProps) {\n layoutOptions[capitalized] = componentProps[capitalized];\n }\n }\n\n root = scopedCreateResourceLayout({\n ...layoutOptions,\n name:\n entry.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 const entry = definedEntries.get(resource);\n const definedCustom: Record<string, unknown> = {};\n const forwardedRootProps: Record<string, unknown> = {};\n\n for (const key of Object.keys(getComponentPropDefinitions(resource))) {\n if (key in componentProps) {\n forwardedRootProps[key] = componentProps[key];\n }\n\n const capitalized = capitalize(key);\n if (capitalized in componentProps) {\n forwardedRootProps[capitalized] = componentProps[capitalized];\n }\n }\n\n for (const [key, value] of Object.entries(\n entry?.props?.defined ?? {},\n )) {\n if (key in custom) {\n definedCustom[key] = value;\n }\n }\n\n return createElement(root, {\n ...forwardedRootProps,\n ...definedCustom,\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 LayoutConfigurationError(\n `Resource \"${componentResource}\" is not available in this scoped component`,\n );\n }\n\n const defined =\n definedEntries.get(componentResource)?.props?.defined ?? {};\n const resolvedComponentProps = { ...defined, ...componentProps };\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 resolvedComponentProps) {\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, resolvedComponentProps, {\n layoutName:\n definedEntries.get(componentResource)?.name ??\n defaultNames.get(componentResource) ??\n capitalize(componentResource),\n resource: componentResource,\n });\n\n // Top-level render may return a component type; mount it with the full\n // component props (include/custom + inferred return-type props).\n return createElement(\n componentPropsContext.Provider,\n { value: resolvedComponentProps },\n resolveScopedRenderResult(\n componentOptions.render(resolvedComponentProps, renderContext),\n resolvedComponentProps,\n ),\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 LayoutConfigurationError(\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 function createComponentSetProps(baseProps: CreateComponentPropsBag) {\n function createWithProps(componentOptions: {\n props?: CreateComponentPropsBag;\n resources?: Record<string, ScopedComponentEntry>;\n render: (\n props: Record<string, unknown>,\n context: Record<string, (props: never) => JSX.Element>,\n ) => ScopedRenderResult;\n }) {\n return createComponent({\n ...componentOptions,\n props: mergeCreateComponentProps(baseProps, componentOptions.props),\n });\n }\n\n createWithProps.createResourceComponents = createResourceComponents;\n\n return createWithProps;\n }\n\n function createResourceComponents(options: {\n resource: LayoutResourceKey<Resources>;\n props?: CreateComponentPropsBag;\n name?: string;\n components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n }) {\n const { resource, props, ...entry } = options;\n\n if (\n !resourceOptions.some(\n (resourceOption) => resourceOption.resource === resource,\n )\n ) {\n throw new LayoutConfigurationError(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n return { ...entry, props: props ?? {} };\n }\n\n Object.assign(createComponent, {\n setProps: createComponentSetProps,\n });\n\n const scopedExtras: {\n createComponent: typeof createComponent;\n createResourceComponents: typeof createResourceComponents;\n forResource: typeof scopedForResource;\n makeComposable?: (options: Record<string, unknown>) => unknown;\n resources: undefined;\n } = {\n createComponent,\n createResourceComponents,\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":";;;;;;;AA8CA,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,KACEA,8BAAW,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;EA0BA,SAAS,0BACP,GAAG,MACsB;GACzB,MAAM,UAA6C,CAAC;GACpD,MAAM,SAAiD,CAAC;GAExD,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AMF;GACF;GACA;GACA,aAAa;GACb,WAAW;EACb;EAEA,IAAI,4BAA4B;GAC9B,MAAM,uBAAuB,2BAA2B;GAExD,aAAa,kBAAkB,YAAY;IACzC,MAAM,WAAW,QAAQ;IAEzB,OAAO,qBAAqB;KAC1B,GAAG;KACH,MAAM,QAAQ,QAAQ,aAAa,IAAI,QAAQ;IACjD,CAAC;GACH;EACF;EAEA,OAAO,OAAO,OAAO,4BAA4B,YAAY;CAC/D;AAOF"}
@@ -158,8 +158,15 @@ function createForResources({ createLayoutForResource, createMakeComposableLayou
158
158
  }
159
159
  const entry = definedEntries.get(resource);
160
160
  const definedCustom = {};
161
+ const forwardedRootProps = {};
162
+ for (const key of Object.keys(getComponentPropDefinitions(resource))) {
163
+ if (key in componentProps) forwardedRootProps[key] = componentProps[key];
164
+ const capitalized = capitalize(key);
165
+ if (capitalized in componentProps) forwardedRootProps[capitalized] = componentProps[capitalized];
166
+ }
161
167
  for (const [key, value] of Object.entries(entry?.props?.defined ?? {})) if (key in custom) definedCustom[key] = value;
162
168
  return createElement(root, {
169
+ ...forwardedRootProps,
163
170
  ...definedCustom,
164
171
  ...rootProps
165
172
  });
@@ -1 +1 @@
1
- {"version":3,"file":"create-for-resources.mjs","names":[],"sources":["../../../src/create-config/for-resources/create-for-resources.ts"],"sourcesContent":["import {\n createContext,\n createElement,\n type ComponentType,\n type JSX,\n useContext,\n} from 'react';\nimport type { ComposableComponents } from '@jfdevelops/react-layout-composables';\nimport {\n type AnyBuiltPropDefinition,\n validateProps,\n} from '@jfdevelops/react-layout-validator';\nimport type { InPropsDefinition, InPropsObject } from '../../props';\nimport type { LayoutResourceKey, ResourceDefinition } from '../../resource';\nimport { capitalize } from '../../utils/capitalize';\nimport { LayoutConfigurationError } from '../../errors';\nimport type { LayoutIncludeProps } from '../define-layout';\nimport type {\n CapitalizedResource,\n ResourcesLayoutName,\n} from './resource-selection';\nimport type { CreateResourceLayoutForResourcesFn } from './scoped-layout';\nimport {\n isRenderableComponentType,\n reservedScopedComponentNames,\n resolveScopedRenderResult,\n type ScopedRenderResult,\n withScopedCompoundStatics,\n} from './scoped-render';\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 ) => ScopedRenderResult;\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 props?: CreateComponentPropsBag;\n components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n type CreateComponentPropsBag = {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n defined?: Record<string, unknown>;\n };\n\n function mergeCreateComponentProps(\n ...bags: Array<CreateComponentPropsBag | undefined>\n ): CreateComponentPropsBag {\n const include: Record<string, true | 'optional'> = {};\n const custom: Record<string, AnyBuiltPropDefinition> = {};\n\n for (const bag of bags) {\n Object.assign(include, bag?.include);\n Object.assign(custom, bag?.custom);\n\n for (const key of Object.keys(bag?.defined ?? {})) {\n include[key] = true;\n }\n }\n\n return { include, custom };\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 ) => ScopedRenderResult;\n }) {\n const mergedProps = mergeCreateComponentProps(\n componentOptions.props,\n ...Object.values(componentOptions.resources ?? {}).map(\n (entry) => entry.props,\n ),\n );\n const include = mergedProps.include ?? {};\n const custom = mergedProps.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 LayoutConfigurationError(\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 LayoutConfigurationError(\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 LayoutConfigurationError(\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 LayoutConfigurationError(\n `Scoped component \"${name}\" for resource \"${resource}\" uses a reserved name`,\n );\n }\n\n const ownPropDefinitions = definition.props ?? {};\n // Last call-site own-props / returned component for this scoped\n // entry. Compound statics re-run `render` with these so\n // `<DataTable variant=\"b\" />` then `<DataTable.Loading />` sees \"b\".\n let cachedOwnProps: Record<string, unknown> = {};\n let cachedReturnedComponent:\n | ComponentType<Record<string, unknown>>\n | undefined;\n\n function ScopedComponent(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" must be rendered inside its scoped component`,\n );\n }\n\n const resolvedOwnProps = ownProps ?? {};\n cachedOwnProps = resolvedOwnProps;\n\n validateProps(ownPropDefinitions, resolvedOwnProps, {\n layoutName:\n entry.name ??\n defaultNames.get(resource) ??\n capitalize(resource),\n resource,\n });\n\n // Mount a returned component type with call-site props; pass\n // nodes (elements, portals, null) through unchanged.\n const result = definition.render(\n { ...componentProps, ...resolvedOwnProps, resource },\n scopedComponents,\n );\n\n if (isRenderableComponentType(result)) {\n cachedReturnedComponent = result as ComponentType<\n Record<string, unknown>\n >;\n }\n\n return resolveScopedRenderResult(result, resolvedOwnProps);\n }\n\n // Types expose compound statics from the returned component\n // (`DataTable.Loading`); attach matching runtime wrappers.\n scopedComponents[name] = withScopedCompoundStatics(\n ScopedComponent,\n (staticName) => {\n function CompoundStatic(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}.${staticName}\" must be rendered inside its scoped component`,\n );\n }\n\n // Prefer the component from the last parent call (same\n // closure as that call's own-props). Fall back to re-running\n // render with cached parent props when needed.\n let result: unknown = cachedReturnedComponent;\n\n if (!isRenderableComponentType(result)) {\n result = definition.render(\n {\n ...componentProps,\n ...cachedOwnProps,\n resource,\n },\n scopedComponents,\n );\n }\n\n if (!isRenderableComponentType(result)) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" must return a component type to use static \"${staticName}\"`,\n );\n }\n\n const staticComponent = (\n result as ComponentType<Record<string, unknown>> &\n Record<string, unknown>\n )[staticName];\n\n if (!isRenderableComponentType(staticComponent)) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" has no component static \"${staticName}\"`,\n );\n }\n\n // Loading's props — those mount the static itself.\n return createElement(staticComponent, ownProps ?? {});\n }\n\n CompoundStatic.displayName = `${name}.${staticName}`;\n return CompoundStatic;\n },\n ) as (props?: never) => JSX.Element;\n }\n\n resourceScopedComponents.set(resource, scopedComponents);\n\n function ResourceRender(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Render context component \"${contextKey}\" must be rendered inside its scoped component`,\n );\n }\n\n // Call-site props on `context.Users({ title, heading })` merge into\n // the resource render props and mount a returned component type.\n const callProps = { ...componentProps, ...ownProps, resource };\n return resolveScopedRenderResult(\n entry.render(callProps, scopedComponents),\n ownProps,\n );\n }\n\n return [\n contextKey,\n Object.assign(ResourceRender, scopedComponents),\n ];\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 Root(rootProps: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n 'Render context component \"Root\" must be rendered inside its scoped component',\n );\n }\n\n const resource =\n componentProps.resource as 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 throw new LayoutConfigurationError(\n `Render context component \"Root\" requires a \"resources.${resource}\" entry to build the layout for resource \"${resource}\"`,\n );\n }\n\n // Layout option values come from the outer component call site\n // (`<Directory title=\"…\" />`), not from the resource entry.\n const availableDefinitions =\n getComponentPropDefinitions(resource);\n const layoutOptions: Record<string, unknown> = {};\n const defined = entry.props?.defined ?? {};\n\n for (const key of Object.keys(availableDefinitions)) {\n if (key in defined) {\n layoutOptions[key] = defined[key];\n }\n\n const capitalized = capitalize(key);\n if (capitalized in defined) {\n layoutOptions[capitalized] = defined[capitalized];\n }\n\n if (key in componentProps) {\n layoutOptions[key] = componentProps[key];\n }\n\n if (capitalized in componentProps) {\n layoutOptions[capitalized] = componentProps[capitalized];\n }\n }\n\n root = scopedCreateResourceLayout({\n ...layoutOptions,\n name:\n entry.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 const entry = definedEntries.get(resource);\n const definedCustom: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(\n entry?.props?.defined ?? {},\n )) {\n if (key in custom) {\n definedCustom[key] = value;\n }\n }\n\n return createElement(root, { ...definedCustom, ...rootProps });\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 LayoutConfigurationError(\n `Resource \"${componentResource}\" is not available in this scoped component`,\n );\n }\n\n const defined =\n definedEntries.get(componentResource)?.props?.defined ?? {};\n const resolvedComponentProps = { ...defined, ...componentProps };\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 resolvedComponentProps) {\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, resolvedComponentProps, {\n layoutName:\n definedEntries.get(componentResource)?.name ??\n defaultNames.get(componentResource) ??\n capitalize(componentResource),\n resource: componentResource,\n });\n\n // Top-level render may return a component type; mount it with the full\n // component props (include/custom + inferred return-type props).\n return createElement(\n componentPropsContext.Provider,\n { value: resolvedComponentProps },\n resolveScopedRenderResult(\n componentOptions.render(resolvedComponentProps, renderContext),\n resolvedComponentProps,\n ),\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 LayoutConfigurationError(\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 function createComponentSetProps(baseProps: CreateComponentPropsBag) {\n function createWithProps(componentOptions: {\n props?: CreateComponentPropsBag;\n resources?: Record<string, ScopedComponentEntry>;\n render: (\n props: Record<string, unknown>,\n context: Record<string, (props: never) => JSX.Element>,\n ) => ScopedRenderResult;\n }) {\n return createComponent({\n ...componentOptions,\n props: mergeCreateComponentProps(baseProps, componentOptions.props),\n });\n }\n\n createWithProps.createResourceComponents = createResourceComponents;\n\n return createWithProps;\n }\n\n function createResourceComponents(options: {\n resource: LayoutResourceKey<Resources>;\n props?: CreateComponentPropsBag;\n name?: string;\n components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n }) {\n const { resource, props, ...entry } = options;\n\n if (\n !resourceOptions.some(\n (resourceOption) => resourceOption.resource === resource,\n )\n ) {\n throw new LayoutConfigurationError(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n return { ...entry, props: props ?? {} };\n }\n\n Object.assign(createComponent, {\n setProps: createComponentSetProps,\n });\n\n const scopedExtras: {\n createComponent: typeof createComponent;\n createResourceComponents: typeof createResourceComponents;\n forResource: typeof scopedForResource;\n makeComposable?: (options: Record<string, unknown>) => unknown;\n resources: undefined;\n } = {\n createComponent,\n createResourceComponents,\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":";;;;;;;AA8CA,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,OAA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AmB,eAAe,aAAa,QAClD,GAEA,MAAM,IAAI,yBACR,aAAa,SAAS,4CACxB;GAGF,OAAO;IAAE,GAAG;IAAO,OAAO,SAAS,CAAC;GAAE;EACxC;EAEA,OAAO,OAAO,iBAAiB,EAC7B,UAAU,wBACZ,CAAC;EAED,MAAM,eAMF;GACF;GACA;GACA,aAAa;GACb,WAAW;EACb;EAEA,IAAI,4BAA4B;GAC9B,MAAM,uBAAuB,2BAA2B;GAExD,aAAa,kBAAkB,YAAY;IACzC,MAAM,WAAW,QAAQ;IAEzB,OAAO,qBAAqB;KAC1B,GAAG;KACH,MAAM,QAAQ,QAAQ,aAAa,IAAI,QAAQ;IACjD,CAAC;GACH;EACF;EAEA,OAAO,OAAO,OAAO,4BAA4B,YAAY;CAC/D;AAOF"}
1
+ {"version":3,"file":"create-for-resources.mjs","names":[],"sources":["../../../src/create-config/for-resources/create-for-resources.ts"],"sourcesContent":["import {\n createContext,\n createElement,\n type ComponentType,\n type JSX,\n useContext,\n} from 'react';\nimport type { ComposableComponents } from '@jfdevelops/react-layout-composables';\nimport {\n type AnyBuiltPropDefinition,\n validateProps,\n} from '@jfdevelops/react-layout-validator';\nimport type { InPropsDefinition, InPropsObject } from '../../props';\nimport type { LayoutResourceKey, ResourceDefinition } from '../../resource';\nimport { capitalize } from '../../utils/capitalize';\nimport { LayoutConfigurationError } from '../../errors';\nimport type { LayoutIncludeProps } from '../define-layout';\nimport type {\n CapitalizedResource,\n ResourcesLayoutName,\n} from './resource-selection';\nimport type { CreateResourceLayoutForResourcesFn } from './scoped-layout';\nimport {\n isRenderableComponentType,\n reservedScopedComponentNames,\n resolveScopedRenderResult,\n type ScopedRenderResult,\n withScopedCompoundStatics,\n} from './scoped-render';\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 ) => ScopedRenderResult;\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 props?: CreateComponentPropsBag;\n components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n type CreateComponentPropsBag = {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n defined?: Record<string, unknown>;\n };\n\n function mergeCreateComponentProps(\n ...bags: Array<CreateComponentPropsBag | undefined>\n ): CreateComponentPropsBag {\n const include: Record<string, true | 'optional'> = {};\n const custom: Record<string, AnyBuiltPropDefinition> = {};\n\n for (const bag of bags) {\n Object.assign(include, bag?.include);\n Object.assign(custom, bag?.custom);\n\n for (const key of Object.keys(bag?.defined ?? {})) {\n include[key] = true;\n }\n }\n\n return { include, custom };\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 ) => ScopedRenderResult;\n }) {\n const mergedProps = mergeCreateComponentProps(\n componentOptions.props,\n ...Object.values(componentOptions.resources ?? {}).map(\n (entry) => entry.props,\n ),\n );\n const include = mergedProps.include ?? {};\n const custom = mergedProps.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 LayoutConfigurationError(\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 LayoutConfigurationError(\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 LayoutConfigurationError(\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 LayoutConfigurationError(\n `Scoped component \"${name}\" for resource \"${resource}\" uses a reserved name`,\n );\n }\n\n const ownPropDefinitions = definition.props ?? {};\n // Last call-site own-props / returned component for this scoped\n // entry. Compound statics re-run `render` with these so\n // `<DataTable variant=\"b\" />` then `<DataTable.Loading />` sees \"b\".\n let cachedOwnProps: Record<string, unknown> = {};\n let cachedReturnedComponent:\n | ComponentType<Record<string, unknown>>\n | undefined;\n\n function ScopedComponent(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" must be rendered inside its scoped component`,\n );\n }\n\n const resolvedOwnProps = ownProps ?? {};\n cachedOwnProps = resolvedOwnProps;\n\n validateProps(ownPropDefinitions, resolvedOwnProps, {\n layoutName:\n entry.name ??\n defaultNames.get(resource) ??\n capitalize(resource),\n resource,\n });\n\n // Mount a returned component type with call-site props; pass\n // nodes (elements, portals, null) through unchanged.\n const result = definition.render(\n { ...componentProps, ...resolvedOwnProps, resource },\n scopedComponents,\n );\n\n if (isRenderableComponentType(result)) {\n cachedReturnedComponent = result as ComponentType<\n Record<string, unknown>\n >;\n }\n\n return resolveScopedRenderResult(result, resolvedOwnProps);\n }\n\n // Types expose compound statics from the returned component\n // (`DataTable.Loading`); attach matching runtime wrappers.\n scopedComponents[name] = withScopedCompoundStatics(\n ScopedComponent,\n (staticName) => {\n function CompoundStatic(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}.${staticName}\" must be rendered inside its scoped component`,\n );\n }\n\n // Prefer the component from the last parent call (same\n // closure as that call's own-props). Fall back to re-running\n // render with cached parent props when needed.\n let result: unknown = cachedReturnedComponent;\n\n if (!isRenderableComponentType(result)) {\n result = definition.render(\n {\n ...componentProps,\n ...cachedOwnProps,\n resource,\n },\n scopedComponents,\n );\n }\n\n if (!isRenderableComponentType(result)) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" must return a component type to use static \"${staticName}\"`,\n );\n }\n\n const staticComponent = (\n result as ComponentType<Record<string, unknown>> &\n Record<string, unknown>\n )[staticName];\n\n if (!isRenderableComponentType(staticComponent)) {\n throw new LayoutConfigurationError(\n `Scoped component \"${name}\" has no component static \"${staticName}\"`,\n );\n }\n\n // Loading's props — those mount the static itself.\n return createElement(staticComponent, ownProps ?? {});\n }\n\n CompoundStatic.displayName = `${name}.${staticName}`;\n return CompoundStatic;\n },\n ) as (props?: never) => JSX.Element;\n }\n\n resourceScopedComponents.set(resource, scopedComponents);\n\n function ResourceRender(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n `Render context component \"${contextKey}\" must be rendered inside its scoped component`,\n );\n }\n\n // Call-site props on `context.Users({ title, heading })` merge into\n // the resource render props and mount a returned component type.\n const callProps = { ...componentProps, ...ownProps, resource };\n return resolveScopedRenderResult(\n entry.render(callProps, scopedComponents),\n ownProps,\n );\n }\n\n return [\n contextKey,\n Object.assign(ResourceRender, scopedComponents),\n ];\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 Root(rootProps: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new LayoutConfigurationError(\n 'Render context component \"Root\" must be rendered inside its scoped component',\n );\n }\n\n const resource =\n componentProps.resource as 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 throw new LayoutConfigurationError(\n `Render context component \"Root\" requires a \"resources.${resource}\" entry to build the layout for resource \"${resource}\"`,\n );\n }\n\n // Layout option values come from the outer component call site\n // (`<Directory title=\"…\" />`), not from the resource entry.\n const availableDefinitions =\n getComponentPropDefinitions(resource);\n const layoutOptions: Record<string, unknown> = {};\n const defined = entry.props?.defined ?? {};\n\n for (const key of Object.keys(availableDefinitions)) {\n if (key in defined) {\n layoutOptions[key] = defined[key];\n }\n\n const capitalized = capitalize(key);\n if (capitalized in defined) {\n layoutOptions[capitalized] = defined[capitalized];\n }\n\n if (key in componentProps) {\n layoutOptions[key] = componentProps[key];\n }\n\n if (capitalized in componentProps) {\n layoutOptions[capitalized] = componentProps[capitalized];\n }\n }\n\n root = scopedCreateResourceLayout({\n ...layoutOptions,\n name:\n entry.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 const entry = definedEntries.get(resource);\n const definedCustom: Record<string, unknown> = {};\n const forwardedRootProps: Record<string, unknown> = {};\n\n for (const key of Object.keys(getComponentPropDefinitions(resource))) {\n if (key in componentProps) {\n forwardedRootProps[key] = componentProps[key];\n }\n\n const capitalized = capitalize(key);\n if (capitalized in componentProps) {\n forwardedRootProps[capitalized] = componentProps[capitalized];\n }\n }\n\n for (const [key, value] of Object.entries(\n entry?.props?.defined ?? {},\n )) {\n if (key in custom) {\n definedCustom[key] = value;\n }\n }\n\n return createElement(root, {\n ...forwardedRootProps,\n ...definedCustom,\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 LayoutConfigurationError(\n `Resource \"${componentResource}\" is not available in this scoped component`,\n );\n }\n\n const defined =\n definedEntries.get(componentResource)?.props?.defined ?? {};\n const resolvedComponentProps = { ...defined, ...componentProps };\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 resolvedComponentProps) {\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, resolvedComponentProps, {\n layoutName:\n definedEntries.get(componentResource)?.name ??\n defaultNames.get(componentResource) ??\n capitalize(componentResource),\n resource: componentResource,\n });\n\n // Top-level render may return a component type; mount it with the full\n // component props (include/custom + inferred return-type props).\n return createElement(\n componentPropsContext.Provider,\n { value: resolvedComponentProps },\n resolveScopedRenderResult(\n componentOptions.render(resolvedComponentProps, renderContext),\n resolvedComponentProps,\n ),\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 LayoutConfigurationError(\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 function createComponentSetProps(baseProps: CreateComponentPropsBag) {\n function createWithProps(componentOptions: {\n props?: CreateComponentPropsBag;\n resources?: Record<string, ScopedComponentEntry>;\n render: (\n props: Record<string, unknown>,\n context: Record<string, (props: never) => JSX.Element>,\n ) => ScopedRenderResult;\n }) {\n return createComponent({\n ...componentOptions,\n props: mergeCreateComponentProps(baseProps, componentOptions.props),\n });\n }\n\n createWithProps.createResourceComponents = createResourceComponents;\n\n return createWithProps;\n }\n\n function createResourceComponents(options: {\n resource: LayoutResourceKey<Resources>;\n props?: CreateComponentPropsBag;\n name?: string;\n components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n }) {\n const { resource, props, ...entry } = options;\n\n if (\n !resourceOptions.some(\n (resourceOption) => resourceOption.resource === resource,\n )\n ) {\n throw new LayoutConfigurationError(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n return { ...entry, props: props ?? {} };\n }\n\n Object.assign(createComponent, {\n setProps: createComponentSetProps,\n });\n\n const scopedExtras: {\n createComponent: typeof createComponent;\n createResourceComponents: typeof createResourceComponents;\n forResource: typeof scopedForResource;\n makeComposable?: (options: Record<string, unknown>) => unknown;\n resources: undefined;\n } = {\n createComponent,\n createResourceComponents,\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":";;;;;;;AA8CA,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,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0BAA0B,WAAW,iBAAiB,KAAK;IACpE,CAAC;GACH;GAEA,gBAAgB,2BAA2B;GAE3C,OAAO;EACT;EAEA,SAAS,yBAAyB,SAM/B;GACD,MAAM,EAAE,UAAU,OAAO,GAAG,UAAU;GAEtC,IACE,CAAC,gBAAgB,MACd,mBAAmB,eAAe,aAAa,QAClD,GAEA,MAAM,IAAI,yBACR,aAAa,SAAS,4CACxB;GAGF,OAAO;IAAE,GAAG;IAAO,OAAO,SAAS,CAAC;GAAE;EACxC;EAEA,OAAO,OAAO,iBAAiB,EAC7B,UAAU,wBACZ,CAAC;EAED,MAAM,eAMF;GACF;GACA;GACA,aAAa;GACb,WAAW;EACb;EAEA,IAAI,4BAA4B;GAC9B,MAAM,uBAAuB,2BAA2B;GAExD,aAAa,kBAAkB,YAAY;IACzC,MAAM,WAAW,QAAQ;IAEzB,OAAO,qBAAqB;KAC1B,GAAG;KACH,MAAM,QAAQ,QAAQ,aAAa,IAAI,QAAQ;IACjD,CAAC;GACH;EACF;EAEA,OAAO,OAAO,OAAO,4BAA4B,YAAY;CAC/D;AAOF"}
@@ -80,7 +80,7 @@ function createGetComponent(config) {
80
80
  };
81
81
  return Object.assign(getComponent, { forResource });
82
82
  }
83
- function createResourceConfig(config) {
83
+ function createResourceConfigImpl(config) {
84
84
  const configRecord = config;
85
85
  if (require_introspect.collectConfigResources(configRecord).length === 0) throw new require_invalid_config.InvalidConfigError({
86
86
  reason: "A resource config must configure at least one resource",
@@ -95,6 +95,27 @@ function createResourceConfig(config) {
95
95
  subResources: require_introspect.collectAllSubResourceKeys(configRecord)
96
96
  };
97
97
  }
98
+ function createResourceConfigForResource(resource, config) {
99
+ return { [resource]: config };
100
+ }
101
+ /**
102
+ * Creates a validated resource configuration. Use `.forResource()` to build
103
+ * independently declared, type-safe fragments that can be spread into the
104
+ * complete configuration object.
105
+ *
106
+ * @param config - Resource entries to validate and expose through lookup helpers.
107
+ * @returns The original config plus typed component and path lookup helpers.
108
+ *
109
+ * @example
110
+ * ```tsx
111
+ * const users = createResourceConfig.forResource('users', {
112
+ * component: <Users />,
113
+ * });
114
+ *
115
+ * const config = createResourceConfig({ ...users });
116
+ * ```
117
+ */
118
+ const createResourceConfig = Object.assign(createResourceConfigImpl, { forResource: createResourceConfigForResource });
98
119
 
99
120
  //#endregion
100
121
  exports.createResourceConfig = createResourceConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"get-component.cjs","names":["InvalidSubResourceError","readSubResourceKeys","InvalidComponentError","readComponentKeys","InvalidResourceError","collectConfigResources","InvalidPathError","InvalidConfigError","createGetComponentForPath","createForPaths","createIsSubResourceKey","collectAllSubResourceKeys"],"sources":["../../src/create-config/get-component.ts"],"sourcesContent":["import type { JSX } from 'react';\nimport {\n InvalidComponentError,\n InvalidConfigError,\n InvalidPathError,\n InvalidResourceError,\n InvalidSubResourceError,\n} from '../errors';\nimport type {\n LayoutResourceKey,\n ResourceDefinition,\n ResourceDefinitionForKey,\n SubResourceDefinitionsFor,\n SubResourceParamForResource,\n} from '../resource';\nimport {\n createForPaths,\n createGetComponentForPath,\n type CreateGetComponentForPath,\n type ForPaths,\n} from './for-paths';\nimport {\n createIsSubResourceKey,\n type IsSubResourceKey,\n} from './is-sub-resource-key';\nimport {\n readComponentKeys,\n readSubResourceKeys,\n} from './component-keys';\nimport {\n collectAllSubResourceKeys,\n collectConfigResources,\n} from './paths';\nimport type {\n ConfigSubResourceKeys,\n ParameterizedResourcePath,\n} from './paths';\nimport type {\n BaseResourceConfigComponents,\n ResourceConfigComponentKey,\n ResourceConfigComponents,\n ResourceConfigEntry,\n ResourceConfigMap,\n ResourceConfigInput,\n SharedResourceConfigOptions,\n} from './types';\n\ntype ResourceHasLayoutSubResources<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> = [SubResourceDefinitionsFor<Resources, Resource>] extends [readonly []]\n ? false\n : true;\n\ntype SubResourceOptionForGenerics<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n SubResource extends\n | SubResourceParamForResource<Resources, Resource>\n | undefined,\n> = [SubResource] extends [undefined]\n ? ResourceHasLayoutSubResources<Resources, Resource> extends true\n ? {\n subResource?: SubResourceParamForResource<Resources, Resource>;\n }\n : {}\n : ResourceHasLayoutSubResources<Resources, Resource> extends true\n ? { subResource?: SubResource }\n : {};\n\n/** Options for one layout resource passed to {@link GetComponent}. */\nexport type GetComponentOptionsForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n SubResource extends\n | SubResourceParamForResource<Resources, Resource>\n | undefined = undefined,\n> = SubResourceOptionForGenerics<Resources, Resource, SubResource> & {\n resource: Resource;\n /**\n * The component to get.\n *\n * @default 'component'\n */\n component?: ResourceConfigComponentKey;\n};\n\n/** Union of valid `getComponent` option shapes for each declared layout resource. */\nexport type GetComponentOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> =\n LayoutResourceKey<Resources> extends infer Resource\n ? Resource extends LayoutResourceKey<Resources>\n ? GetComponentOptionsForResource<Resources, Resource>\n : never\n : never;\n\ntype ComponentSlotPathKey = keyof BaseResourceConfigComponents;\n\n/** `detail.errorComponent`, `new.component`, … — component slots inside a shared branch. */\ntype SharedBranchPath = {\n [Branch in keyof SharedResourceConfigOptions]: `${Branch}.${ComponentSlotPathKey}`;\n}[keyof SharedResourceConfigOptions];\n\ntype NestedSubResourceDefinitions<Def extends ResourceDefinition> = Def extends {\n subResources: infer Nested extends ReadonlyArray<ResourceDefinition>;\n}\n ? Nested\n : readonly [];\n\ntype SubResourceEntryPaths<\n SubDefs extends ReadonlyArray<ResourceDefinition>,\n DepthAcc extends readonly unknown[],\n> =\n LayoutResourceKey<SubDefs> extends infer Key extends string\n ? Key extends LayoutResourceKey<SubDefs>\n ?\n | Key\n | `${Key}.${ResourceConfigEntryPath<\n NestedSubResourceDefinitions<\n ResourceDefinitionForKey<SubDefs, Key>\n >,\n readonly [...DepthAcc, unknown]\n >}`\n : never\n : never;\n\n/** Dot-separated keys below one config node: component slots and nested sub-resources. */\ntype ResourceConfigEntryPath<\n SubDefs extends ReadonlyArray<ResourceDefinition>,\n DepthAcc extends readonly unknown[] = readonly [],\n> =\n | ComponentSlotPathKey\n | SharedBranchPath\n | ([SubDefs] extends [readonly []]\n ? never\n : DepthAcc['length'] extends 6\n ? never\n : SubResourceEntryPaths<SubDefs, DepthAcc>);\n\n/**\n * Deep config paths accepted by {@link GetComponent}, e.g.\n * `'templates.deleted.expired.errorComponent'`. Sub-resource segments come from the\n * layout tree, so only declared sub-resources are allowed at each depth.\n */\nexport type ResourceConfigPath<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> =\n LayoutResourceKey<Resources> extends infer Resource extends string\n ? Resource extends LayoutResourceKey<Resources>\n ?\n | Resource\n | `${Resource}.${ResourceConfigEntryPath<\n SubResourceDefinitionsFor<Resources, Resource>\n >}`\n : never\n : never;\n\n/** `subResource` bound by {@link GetComponentForResource}. */\nexport type SubResourceFromGetComponentBound<Bound> = Bound extends {\n subResource: infer SubResource;\n}\n ? SubResource\n : undefined;\n\n/** Options for {@link GetComponentForResource} — binds `resource` and optional `subResource`. */\nexport type GetComponentForResourceOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n SubResource extends\n | SubResourceParamForResource<Resources, Resource>\n | undefined = undefined,\n> = {\n resource: Resource;\n} & SubResourceOptionForGenerics<Resources, Resource, SubResource>;\n\n/** Valid bind shapes for {@link GetComponentForResource}. */\nexport type GetComponentForResourceBound<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> =\n LayoutResourceKey<Resources> extends infer Resource\n ? Resource extends LayoutResourceKey<Resources>\n ? GetComponentForResourceOptions<Resources, Resource>\n : never\n : never;\n\ntype GetComponentForResourceOptionsForBound<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Bound extends { resource: LayoutResourceKey<Resources> },\n> = GetComponentForResourceOptions<\n Resources,\n Bound['resource'],\n SubResourceFromGetComponentBound<Bound>\n>;\n\n/**\n * Rejects bind objects with keys (e.g. `subResource`) that are invalid for the\n * given `resource`. Union assignability alone is too permissive for excess keys.\n */\nexport type ValidateForResourceBound<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Bound extends { resource: LayoutResourceKey<Resources> },\n> = Bound extends GetComponentForResourceOptionsForBound<Resources, Bound>\n ? keyof Bound extends keyof GetComponentForResourceOptionsForBound<\n Resources,\n Bound\n >\n ? Bound\n : never\n : never;\n\n/** `resource` inferred from a {@link GetComponentForResource} bind argument. */\nexport type ResourceFromGetComponentBound<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Bound,\n> = Bound extends {\n resource: infer Resource extends LayoutResourceKey<Resources>;\n}\n ? Resource\n : never;\n\n/** Reusable getter returned by {@link GetComponentForResource} (only `component` remains). */\nexport type GetComponentAtBound<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n SubResource extends\n | SubResourceParamForResource<Resources, Resource>\n | undefined = undefined,\n> = (\n options?: Pick<\n GetComponentOptionsForResource<Resources, Resource, SubResource>,\n 'component'\n >,\n) => JSX.Element;\n\nexport type GetComponentForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = <\n const Bound extends {\n resource: LayoutResourceKey<Resources>;\n },\n>(\n bound: ValidateForResourceBound<Resources, Bound>,\n) => GetComponentAtBound<\n Resources,\n ResourceFromGetComponentBound<Resources, Bound>,\n SubResourceFromGetComponentBound<Bound>\n>;\n\nexport interface GetComponent<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n /** Looks up a component by resource / optional sub-resource / optional component slot. */\n <const Options extends GetComponentOptions<Resources>>(\n options: Options,\n ): JSX.Element;\n /**\n * Looks up a component by a deep config path.\n * A path ending on a branch (e.g. `'templates.deleted.expired'`) returns that branch's\n * `component`; a path ending on a slot returns that slot.\n */\n <const Path extends ResourceConfigPath<Resources>>(path: Path): JSX.Element;\n forResource: GetComponentForResource<Resources>;\n}\n\nexport interface CreatedResourceConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Config extends ResourceConfigMap<Resources> = ResourceConfigMap<Resources>,\n> {\n config: Config;\n getComponent: GetComponent<Resources>;\n /**\n * Creates a reusable getter bound to one path. Variables the path leaves open become\n * the getter's arguments.\n *\n * @example\n * ```ts\n * const getDetail = createGetComponent('$resource.detail.$component');\n *\n * getDetail({ resource: 'templates', component: 'errorComponent' });\n * ```\n */\n createGetComponent: CreateGetComponentForPath<\n Resources,\n Config,\n ParameterizedResourcePath<Resources>\n >;\n /**\n * Builds a component for one or more paths. Declare which params the component takes,\n * then render it.\n *\n * @example\n * ```ts\n * const ResourceDetail = forPaths('$resource.detail.$component')\n * .addPathParams()\n * .render(({ params, getComponentForPath }) =>\n * getComponentForPath('$resource.detail.$component')(params),\n * );\n * ```\n */\n forPaths: ForPaths<\n Resources,\n Config,\n ParameterizedResourcePath<Resources>\n >;\n /** Narrows an unknown value to a sub-resource key configured for a path or resource. */\n isSubResourceKey: IsSubResourceKey<\n Resources,\n Config,\n ParameterizedResourcePath<Resources>\n >;\n /** Every sub-resource key configured in this config, at any depth. */\n subResources: ReadonlyArray<ConfigSubResourceKeys<Resources, Config>>;\n}\n\ntype ComponentTypesFromEntry<Entry> = Entry extends JSX.Element\n ? never\n : Entry extends object\n ?\n | Extract<keyof Entry, ResourceConfigComponentKey>\n | {\n [Key in keyof Entry]: NonNullable<Entry[Key]> extends JSX.Element\n ? never\n : ComponentTypesFromEntry<NonNullable<Entry[Key]>>;\n }[keyof Entry]\n : never;\n\n/**\n * Component selector keys actually defined anywhere in a created resource config.\n *\n * @example\n * ```ts\n * ComponentTypes<typeof resourceConfig>\n * // ^? may resolve to:`'component' | 'errorComponent' | 'detail'`.\n * ```\n */\nexport type ComponentTypes<Created> = Created extends {\n config: infer Config extends object;\n}\n ? {\n [Resource in keyof Config]: ComponentTypesFromEntry<\n NonNullable<Config[Resource]>\n >;\n }[keyof Config]\n : never;\n\nexport type CreateResourceConfigFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = <const Config extends ResourceConfigMap<Resources>>(\n config: ResourceConfigInput<Resources, Config>,\n) => CreatedResourceConfig<Resources, Config>;\n\ntype SubResourceParam =\n | string\n | {\n value: string;\n subResource: SubResourceParam;\n };\n\nfunction isResourceConfigEntry(value: unknown): value is ResourceConfigEntry {\n return typeof value === 'object' && value !== null;\n}\n\nfunction resolveResourceConfigEntry(\n entry: ResourceConfigEntry,\n subResource: SubResourceParam,\n): ResourceConfigEntry {\n const key = typeof subResource === 'string' ? subResource : subResource.value;\n const next = entry[key];\n\n if (!isResourceConfigEntry(next)) {\n throw new InvalidSubResourceError({\n subResource: key,\n validSubResources: readSubResourceKeys(entry),\n });\n }\n\n if (typeof subResource === 'string') {\n return next;\n }\n\n return resolveResourceConfigEntry(next, subResource.subResource);\n}\n\nfunction readResourceConfigComponent(\n entry: ResourceConfigComponents,\n componentKey: ResourceConfigComponentKey,\n): JSX.Element {\n if (componentKey === 'new' || componentKey === 'detail') {\n const branch = entry[componentKey];\n\n if (!branch?.component) {\n throw new InvalidComponentError({\n component: `${componentKey}.component`,\n validComponents: readComponentKeys(entry),\n });\n }\n\n return branch.component;\n }\n\n const value = entry[componentKey];\n\n if (!value) {\n throw new InvalidComponentError({\n component: componentKey,\n validComponents: readComponentKeys(entry),\n });\n }\n\n return value;\n}\n\nfunction getComponentFromOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(\n config: ResourceConfigMap<Resources>,\n options: GetComponentOptions<Resources>,\n): JSX.Element {\n const { resource, component: componentKey = 'component' } = options;\n const resourceEntry = config[resource];\n\n if (!resourceEntry) {\n throw new InvalidResourceError({\n resource,\n validResources: collectConfigResources(config as Record<string, unknown>),\n });\n }\n\n let entry = resourceEntry as ResourceConfigEntry;\n\n if ('subResource' in options && options.subResource !== undefined) {\n entry = resolveResourceConfigEntry(entry, options.subResource);\n }\n\n return readResourceConfigComponent(entry, componentKey);\n}\n\nfunction getComponentFromPath<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(config: ResourceConfigMap<Resources>, path: string): JSX.Element {\n let cursor: unknown = config;\n\n for (const segment of path.split('.')) {\n if (!isResourceConfigEntry(cursor)) {\n throw new InvalidPathError({\n path,\n reason: `\"${segment}\" cannot be read because the value before it is not a config branch`,\n });\n }\n\n const next: unknown = (cursor as Record<string, unknown>)[segment];\n\n if (next === undefined || next === null) {\n throw new InvalidPathError({\n path,\n reason: `\"${segment}\" is not configured`,\n });\n }\n\n cursor = next;\n }\n\n if (isResourceConfigEntry(cursor) && 'component' in cursor) {\n return readResourceConfigComponent(cursor, 'component');\n }\n\n return cursor as JSX.Element;\n}\n\nexport function createGetComponent<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(config: ResourceConfigMap<Resources>): GetComponent<Resources> {\n function getComponent(options: GetComponentOptions<Resources>): JSX.Element;\n function getComponent(path: ResourceConfigPath<Resources>): JSX.Element;\n function getComponent(\n options: GetComponentOptions<Resources> | ResourceConfigPath<Resources>,\n ): JSX.Element {\n if (typeof options === 'string') {\n return getComponentFromPath(config, options);\n }\n\n return getComponentFromOptions(config, options);\n }\n\n const forResource: GetComponentForResource<Resources> = (bound) => {\n return (options) =>\n getComponentFromOptions(config, {\n ...bound,\n ...options,\n } as unknown as GetComponentOptions<Resources>);\n };\n\n return Object.assign(getComponent, { forResource });\n}\n\nexport function createResourceConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n const Config extends ResourceConfigMap<Resources>,\n>(\n config: ResourceConfigInput<Resources, Config>,\n): CreatedResourceConfig<Resources, Config> {\n const configRecord = config as Record<string, unknown>;\n\n if (collectConfigResources(configRecord).length === 0) {\n throw new InvalidConfigError({\n reason: 'A resource config must configure at least one resource',\n config,\n });\n }\n\n type Created = CreatedResourceConfig<Resources, Config>;\n\n return {\n config,\n getComponent: createGetComponent(config),\n createGetComponent: ((path: string) =>\n createGetComponentForPath(\n configRecord,\n path,\n )) as unknown as Created['createGetComponent'],\n forPaths: createForPaths(configRecord) as unknown as Created['forPaths'],\n isSubResourceKey: createIsSubResourceKey(\n configRecord,\n ) as unknown as Created['isSubResourceKey'],\n subResources: collectAllSubResourceKeys(\n configRecord,\n ) as unknown as Created['subResources'],\n };\n}\n"],"mappings":";;;;;;;;;;;;AAuWA,SAAS,sBAAsB,OAA8C;CAC3E,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAEA,SAAS,2BACP,OACA,aACqB;CACrB,MAAM,MAAM,OAAO,gBAAgB,WAAW,cAAc,YAAY;CACxE,MAAM,OAAO,MAAM;CAEnB,IAAI,CAAC,sBAAsB,IAAI,GAC7B,MAAM,IAAIA,qDAAwB;EAChC,aAAa;EACb,mBAAmBC,2CAAoB,KAAK;CAC9C,CAAC;CAGH,IAAI,OAAO,gBAAgB,UACzB,OAAO;CAGT,OAAO,2BAA2B,MAAM,YAAY,WAAW;AACjE;AAEA,SAAS,4BACP,OACA,cACa;CACb,IAAI,iBAAiB,SAAS,iBAAiB,UAAU;EACvD,MAAM,SAAS,MAAM;EAErB,IAAI,CAAC,QAAQ,WACX,MAAM,IAAIC,gDAAsB;GAC9B,WAAW,GAAG,aAAa;GAC3B,iBAAiBC,yCAAkB,KAAK;EAC1C,CAAC;EAGH,OAAO,OAAO;CAChB;CAEA,MAAM,QAAQ,MAAM;CAEpB,IAAI,CAAC,OACH,MAAM,IAAID,gDAAsB;EAC9B,WAAW;EACX,iBAAiBC,yCAAkB,KAAK;CAC1C,CAAC;CAGH,OAAO;AACT;AAEA,SAAS,wBAGP,QACA,SACa;CACb,MAAM,EAAE,UAAU,WAAW,eAAe,gBAAgB;CAC5D,MAAM,gBAAgB,OAAO;CAE7B,IAAI,CAAC,eACH,MAAM,IAAIC,8CAAqB;EAC7B;EACA,gBAAgBC,0CAAuB,MAAiC;CAC1E,CAAC;CAGH,IAAI,QAAQ;CAEZ,IAAI,iBAAiB,WAAW,QAAQ,gBAAgB,QACtD,QAAQ,2BAA2B,OAAO,QAAQ,WAAW;CAG/D,OAAO,4BAA4B,OAAO,YAAY;AACxD;AAEA,SAAS,qBAEP,QAAsC,MAA2B;CACjE,IAAI,SAAkB;CAEtB,KAAK,MAAM,WAAW,KAAK,MAAM,GAAG,GAAG;EACrC,IAAI,CAAC,sBAAsB,MAAM,GAC/B,MAAM,IAAIC,sCAAiB;GACzB;GACA,QAAQ,IAAI,QAAQ;EACtB,CAAC;EAGH,MAAM,OAAiB,OAAmC;EAE1D,IAAI,SAAS,UAAa,SAAS,MACjC,MAAM,IAAIA,sCAAiB;GACzB;GACA,QAAQ,IAAI,QAAQ;EACtB,CAAC;EAGH,SAAS;CACX;CAEA,IAAI,sBAAsB,MAAM,KAAK,eAAe,QAClD,OAAO,4BAA4B,QAAQ,WAAW;CAGxD,OAAO;AACT;AAEA,SAAgB,mBAEd,QAA+D;CAG/D,SAAS,aACP,SACa;EACb,IAAI,OAAO,YAAY,UACrB,OAAO,qBAAqB,QAAQ,OAAO;EAG7C,OAAO,wBAAwB,QAAQ,OAAO;CAChD;CAEA,MAAM,eAAmD,UAAU;EACjE,QAAQ,YACN,wBAAwB,QAAQ;GAC9B,GAAG;GACH,GAAG;EACL,CAA8C;CAClD;CAEA,OAAO,OAAO,OAAO,cAAc,EAAE,YAAY,CAAC;AACpD;AAEA,SAAgB,qBAId,QAC0C;CAC1C,MAAM,eAAe;CAErB,IAAID,0CAAuB,YAAY,EAAE,WAAW,GAClD,MAAM,IAAIE,0CAAmB;EAC3B,QAAQ;EACR;CACF,CAAC;CAKH,OAAO;EACL;EACA,cAAc,mBAAmB,MAAM;EACvC,sBAAsB,SACpBC,yDACE,cACA,IACF;EACF,UAAUC,+BAAe,YAAY;EACrC,kBAAkBC,mDAChB,YACF;EACA,cAAcC,6CACZ,YACF;CACF;AACF"}
1
+ {"version":3,"file":"get-component.cjs","names":["InvalidSubResourceError","readSubResourceKeys","InvalidComponentError","readComponentKeys","InvalidResourceError","collectConfigResources","InvalidPathError","InvalidConfigError","createGetComponentForPath","createForPaths","createIsSubResourceKey","collectAllSubResourceKeys"],"sources":["../../src/create-config/get-component.ts"],"sourcesContent":["import type { JSX } from 'react';\nimport {\n InvalidComponentError,\n InvalidConfigError,\n InvalidPathError,\n InvalidResourceError,\n InvalidSubResourceError,\n} from '../errors';\nimport type {\n LayoutResourceKey,\n ResourceDefinition,\n ResourceDefinitionForKey,\n SubResourceDefinitionsFor,\n SubResourceParamForResource,\n} from '../resource';\nimport {\n createForPaths,\n createGetComponentForPath,\n type CreateGetComponentForPath,\n type ForPaths,\n} from './for-paths';\nimport {\n createIsSubResourceKey,\n type IsSubResourceKey,\n} from './is-sub-resource-key';\nimport {\n readComponentKeys,\n readSubResourceKeys,\n} from './component-keys';\nimport {\n collectAllSubResourceKeys,\n collectConfigResources,\n} from './paths';\nimport type {\n ConfigSubResourceKeys,\n ParameterizedResourcePath,\n} from './paths';\nimport type {\n BaseResourceConfigComponents,\n ResourceConfig,\n ResourceConfigComponentKey,\n ResourceConfigComponents,\n ResourceConfigEntry,\n ResourceConfigMap,\n ResourceConfigInput,\n SharedResourceConfigOptions,\n} from './types';\n\ntype ResourceHasLayoutSubResources<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> = [SubResourceDefinitionsFor<Resources, Resource>] extends [readonly []]\n ? false\n : true;\n\ntype SubResourceOptionForGenerics<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n SubResource extends\n | SubResourceParamForResource<Resources, Resource>\n | undefined,\n> = [SubResource] extends [undefined]\n ? ResourceHasLayoutSubResources<Resources, Resource> extends true\n ? {\n subResource?: SubResourceParamForResource<Resources, Resource>;\n }\n : {}\n : ResourceHasLayoutSubResources<Resources, Resource> extends true\n ? { subResource?: SubResource }\n : {};\n\n/** Options for one layout resource passed to {@link GetComponent}. */\nexport type GetComponentOptionsForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n SubResource extends\n | SubResourceParamForResource<Resources, Resource>\n | undefined = undefined,\n> = SubResourceOptionForGenerics<Resources, Resource, SubResource> & {\n resource: Resource;\n /**\n * The component to get.\n *\n * @default 'component'\n */\n component?: ResourceConfigComponentKey;\n};\n\n/** Union of valid `getComponent` option shapes for each declared layout resource. */\nexport type GetComponentOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> =\n LayoutResourceKey<Resources> extends infer Resource\n ? Resource extends LayoutResourceKey<Resources>\n ? GetComponentOptionsForResource<Resources, Resource>\n : never\n : never;\n\ntype ComponentSlotPathKey = keyof BaseResourceConfigComponents;\n\n/** `detail.errorComponent`, `new.component`, … — component slots inside a shared branch. */\ntype SharedBranchPath = {\n [Branch in keyof SharedResourceConfigOptions]: `${Branch}.${ComponentSlotPathKey}`;\n}[keyof SharedResourceConfigOptions];\n\ntype NestedSubResourceDefinitions<Def extends ResourceDefinition> = Def extends {\n subResources: infer Nested extends ReadonlyArray<ResourceDefinition>;\n}\n ? Nested\n : readonly [];\n\ntype SubResourceEntryPaths<\n SubDefs extends ReadonlyArray<ResourceDefinition>,\n DepthAcc extends readonly unknown[],\n> =\n LayoutResourceKey<SubDefs> extends infer Key extends string\n ? Key extends LayoutResourceKey<SubDefs>\n ?\n | Key\n | `${Key}.${ResourceConfigEntryPath<\n NestedSubResourceDefinitions<\n ResourceDefinitionForKey<SubDefs, Key>\n >,\n readonly [...DepthAcc, unknown]\n >}`\n : never\n : never;\n\n/** Dot-separated keys below one config node: component slots and nested sub-resources. */\ntype ResourceConfigEntryPath<\n SubDefs extends ReadonlyArray<ResourceDefinition>,\n DepthAcc extends readonly unknown[] = readonly [],\n> =\n | ComponentSlotPathKey\n | SharedBranchPath\n | ([SubDefs] extends [readonly []]\n ? never\n : DepthAcc['length'] extends 6\n ? never\n : SubResourceEntryPaths<SubDefs, DepthAcc>);\n\n/**\n * Deep config paths accepted by {@link GetComponent}, e.g.\n * `'templates.deleted.expired.errorComponent'`. Sub-resource segments come from the\n * layout tree, so only declared sub-resources are allowed at each depth.\n */\nexport type ResourceConfigPath<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> =\n LayoutResourceKey<Resources> extends infer Resource extends string\n ? Resource extends LayoutResourceKey<Resources>\n ?\n | Resource\n | `${Resource}.${ResourceConfigEntryPath<\n SubResourceDefinitionsFor<Resources, Resource>\n >}`\n : never\n : never;\n\n/** `subResource` bound by {@link GetComponentForResource}. */\nexport type SubResourceFromGetComponentBound<Bound> = Bound extends {\n subResource: infer SubResource;\n}\n ? SubResource\n : undefined;\n\n/** Options for {@link GetComponentForResource} — binds `resource` and optional `subResource`. */\nexport type GetComponentForResourceOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n SubResource extends\n | SubResourceParamForResource<Resources, Resource>\n | undefined = undefined,\n> = {\n resource: Resource;\n} & SubResourceOptionForGenerics<Resources, Resource, SubResource>;\n\n/** Valid bind shapes for {@link GetComponentForResource}. */\nexport type GetComponentForResourceBound<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> =\n LayoutResourceKey<Resources> extends infer Resource\n ? Resource extends LayoutResourceKey<Resources>\n ? GetComponentForResourceOptions<Resources, Resource>\n : never\n : never;\n\ntype GetComponentForResourceOptionsForBound<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Bound extends { resource: LayoutResourceKey<Resources> },\n> = GetComponentForResourceOptions<\n Resources,\n Bound['resource'],\n SubResourceFromGetComponentBound<Bound>\n>;\n\n/**\n * Rejects bind objects with keys (e.g. `subResource`) that are invalid for the\n * given `resource`. Union assignability alone is too permissive for excess keys.\n */\nexport type ValidateForResourceBound<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Bound extends { resource: LayoutResourceKey<Resources> },\n> = Bound extends GetComponentForResourceOptionsForBound<Resources, Bound>\n ? keyof Bound extends keyof GetComponentForResourceOptionsForBound<\n Resources,\n Bound\n >\n ? Bound\n : never\n : never;\n\n/** `resource` inferred from a {@link GetComponentForResource} bind argument. */\nexport type ResourceFromGetComponentBound<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Bound,\n> = Bound extends {\n resource: infer Resource extends LayoutResourceKey<Resources>;\n}\n ? Resource\n : never;\n\n/** Reusable getter returned by {@link GetComponentForResource} (only `component` remains). */\nexport type GetComponentAtBound<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n SubResource extends\n | SubResourceParamForResource<Resources, Resource>\n | undefined = undefined,\n> = (\n options?: Pick<\n GetComponentOptionsForResource<Resources, Resource, SubResource>,\n 'component'\n >,\n) => JSX.Element;\n\nexport type GetComponentForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = <\n const Bound extends {\n resource: LayoutResourceKey<Resources>;\n },\n>(\n bound: ValidateForResourceBound<Resources, Bound>,\n) => GetComponentAtBound<\n Resources,\n ResourceFromGetComponentBound<Resources, Bound>,\n SubResourceFromGetComponentBound<Bound>\n>;\n\nexport interface GetComponent<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n /** Looks up a component by resource / optional sub-resource / optional component slot. */\n <const Options extends GetComponentOptions<Resources>>(\n options: Options,\n ): JSX.Element;\n /**\n * Looks up a component by a deep config path.\n * A path ending on a branch (e.g. `'templates.deleted.expired'`) returns that branch's\n * `component`; a path ending on a slot returns that slot.\n */\n <const Path extends ResourceConfigPath<Resources>>(path: Path): JSX.Element;\n forResource: GetComponentForResource<Resources>;\n}\n\nexport interface CreatedResourceConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Config extends ResourceConfigMap<Resources> = ResourceConfigMap<Resources>,\n> {\n config: Config;\n getComponent: GetComponent<Resources>;\n /**\n * Creates a reusable getter bound to one path. Variables the path leaves open become\n * the getter's arguments.\n *\n * @example\n * ```ts\n * const getDetail = createGetComponent('$resource.detail.$component');\n *\n * getDetail({ resource: 'templates', component: 'errorComponent' });\n * ```\n */\n createGetComponent: CreateGetComponentForPath<\n Resources,\n Config,\n ParameterizedResourcePath<Resources>\n >;\n /**\n * Builds a component for one or more paths. Declare which params the component takes,\n * then render it.\n *\n * @example\n * ```ts\n * const ResourceDetail = forPaths('$resource.detail.$component')\n * .addPathParams()\n * .render(({ params, getComponentForPath }) =>\n * getComponentForPath('$resource.detail.$component')(params),\n * );\n * ```\n */\n forPaths: ForPaths<\n Resources,\n Config,\n ParameterizedResourcePath<Resources>\n >;\n /** Narrows an unknown value to a sub-resource key configured for a path or resource. */\n isSubResourceKey: IsSubResourceKey<\n Resources,\n Config,\n ParameterizedResourcePath<Resources>\n >;\n /** Every sub-resource key configured in this config, at any depth. */\n subResources: ReadonlyArray<ConfigSubResourceKeys<Resources, Config>>;\n}\n\ntype ComponentTypesFromEntry<Entry> = Entry extends JSX.Element\n ? never\n : Entry extends object\n ?\n | Extract<keyof Entry, ResourceConfigComponentKey>\n | {\n [Key in keyof Entry]: NonNullable<Entry[Key]> extends JSX.Element\n ? never\n : ComponentTypesFromEntry<NonNullable<Entry[Key]>>;\n }[keyof Entry]\n : never;\n\n/**\n * Component selector keys actually defined anywhere in a created resource config.\n *\n * @example\n * ```ts\n * ComponentTypes<typeof resourceConfig>\n * // ^? may resolve to:`'component' | 'errorComponent' | 'detail'`.\n * ```\n */\nexport type ComponentTypes<Created> = Created extends {\n config: infer Config extends object;\n}\n ? {\n [Resource in keyof Config]: ComponentTypesFromEntry<\n NonNullable<Config[Resource]>\n >;\n }[keyof Config]\n : never;\n\n/**\n * One resource entry keyed for direct spreading into a resource config.\n * Preserves the precise component slots and sub-resource branches in `Config`.\n */\nexport type ResourceConfigFragment<\n Resource extends string,\n Config,\n> = { [Key in Resource]: Config };\n\n/**\n * Creates one keyed config fragment for spreading into a resource config.\n *\n * @param resource - A top-level resource supported by the layout definition.\n * @param config - Components and declared sub-resource branches for that resource.\n */\nexport type CreateResourceConfigForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = <\n const Resource extends LayoutResourceKey<Resources>,\n const Config extends ResourceConfig<Resources>[Resource],\n>(\n resource: Resource,\n config: Config,\n) => ResourceConfigFragment<Resource, Config>;\n\n/** Creates a validated resource config and exposes helpers for config fragments. */\nexport type CreateResourceConfigFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = {\n /**\n * Validates and indexes a complete configuration assembled from one or more\n * resource entries.\n *\n * @param config - At least one resource entry supported by the layout.\n */\n <const Config extends ResourceConfigMap<Resources>>(\n config: ResourceConfigInput<Resources, Config>,\n ): CreatedResourceConfig<Resources, Config>;\n /** Creates a typed fragment that can be spread into the complete config. */\n forResource: CreateResourceConfigForResource<Resources>;\n};\n\ntype SubResourceParam =\n | string\n | {\n value: string;\n subResource: SubResourceParam;\n };\n\nfunction isResourceConfigEntry(value: unknown): value is ResourceConfigEntry {\n return typeof value === 'object' && value !== null;\n}\n\nfunction resolveResourceConfigEntry(\n entry: ResourceConfigEntry,\n subResource: SubResourceParam,\n): ResourceConfigEntry {\n const key = typeof subResource === 'string' ? subResource : subResource.value;\n const next = entry[key];\n\n if (!isResourceConfigEntry(next)) {\n throw new InvalidSubResourceError({\n subResource: key,\n validSubResources: readSubResourceKeys(entry),\n });\n }\n\n if (typeof subResource === 'string') {\n return next;\n }\n\n return resolveResourceConfigEntry(next, subResource.subResource);\n}\n\nfunction readResourceConfigComponent(\n entry: ResourceConfigComponents,\n componentKey: ResourceConfigComponentKey,\n): JSX.Element {\n if (componentKey === 'new' || componentKey === 'detail') {\n const branch = entry[componentKey];\n\n if (!branch?.component) {\n throw new InvalidComponentError({\n component: `${componentKey}.component`,\n validComponents: readComponentKeys(entry),\n });\n }\n\n return branch.component;\n }\n\n const value = entry[componentKey];\n\n if (!value) {\n throw new InvalidComponentError({\n component: componentKey,\n validComponents: readComponentKeys(entry),\n });\n }\n\n return value;\n}\n\nfunction getComponentFromOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(\n config: ResourceConfigMap<Resources>,\n options: GetComponentOptions<Resources>,\n): JSX.Element {\n const { resource, component: componentKey = 'component' } = options;\n const resourceEntry = config[resource];\n\n if (!resourceEntry) {\n throw new InvalidResourceError({\n resource,\n validResources: collectConfigResources(config as Record<string, unknown>),\n });\n }\n\n let entry = resourceEntry as ResourceConfigEntry;\n\n if ('subResource' in options && options.subResource !== undefined) {\n entry = resolveResourceConfigEntry(entry, options.subResource);\n }\n\n return readResourceConfigComponent(entry, componentKey);\n}\n\nfunction getComponentFromPath<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(config: ResourceConfigMap<Resources>, path: string): JSX.Element {\n let cursor: unknown = config;\n\n for (const segment of path.split('.')) {\n if (!isResourceConfigEntry(cursor)) {\n throw new InvalidPathError({\n path,\n reason: `\"${segment}\" cannot be read because the value before it is not a config branch`,\n });\n }\n\n const next: unknown = (cursor as Record<string, unknown>)[segment];\n\n if (next === undefined || next === null) {\n throw new InvalidPathError({\n path,\n reason: `\"${segment}\" is not configured`,\n });\n }\n\n cursor = next;\n }\n\n if (isResourceConfigEntry(cursor) && 'component' in cursor) {\n return readResourceConfigComponent(cursor, 'component');\n }\n\n return cursor as JSX.Element;\n}\n\nexport function createGetComponent<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(config: ResourceConfigMap<Resources>): GetComponent<Resources> {\n function getComponent(options: GetComponentOptions<Resources>): JSX.Element;\n function getComponent(path: ResourceConfigPath<Resources>): JSX.Element;\n function getComponent(\n options: GetComponentOptions<Resources> | ResourceConfigPath<Resources>,\n ): JSX.Element {\n if (typeof options === 'string') {\n return getComponentFromPath(config, options);\n }\n\n return getComponentFromOptions(config, options);\n }\n\n const forResource: GetComponentForResource<Resources> = (bound) => {\n return (options) =>\n getComponentFromOptions(config, {\n ...bound,\n ...options,\n } as unknown as GetComponentOptions<Resources>);\n };\n\n return Object.assign(getComponent, { forResource });\n}\n\nfunction createResourceConfigImpl<\n Resources extends ReadonlyArray<ResourceDefinition>,\n const Config extends ResourceConfigMap<Resources>,\n>(\n config: ResourceConfigInput<Resources, Config>,\n): CreatedResourceConfig<Resources, Config> {\n const configRecord = config as Record<string, unknown>;\n\n if (collectConfigResources(configRecord).length === 0) {\n throw new InvalidConfigError({\n reason: 'A resource config must configure at least one resource',\n config,\n });\n }\n\n type Created = CreatedResourceConfig<Resources, Config>;\n\n return {\n config,\n getComponent: createGetComponent(config),\n createGetComponent: ((path: string) =>\n createGetComponentForPath(\n configRecord,\n path,\n )) as unknown as Created['createGetComponent'],\n forPaths: createForPaths(configRecord) as unknown as Created['forPaths'],\n isSubResourceKey: createIsSubResourceKey(\n configRecord,\n ) as unknown as Created['isSubResourceKey'],\n subResources: collectAllSubResourceKeys(\n configRecord,\n ) as unknown as Created['subResources'],\n };\n}\n\nfunction createResourceConfigForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n const Resource extends LayoutResourceKey<Resources>,\n const Config extends ResourceConfig<Resources>[Resource],\n>(\n resource: Resource,\n config: Config,\n): ResourceConfigFragment<Resource, Config> {\n return { [resource]: config } as ResourceConfigFragment<Resource, Config>;\n}\n\n/**\n * Creates a validated resource configuration. Use `.forResource()` to build\n * independently declared, type-safe fragments that can be spread into the\n * complete configuration object.\n *\n * @param config - Resource entries to validate and expose through lookup helpers.\n * @returns The original config plus typed component and path lookup helpers.\n *\n * @example\n * ```tsx\n * const users = createResourceConfig.forResource('users', {\n * component: <Users />,\n * });\n *\n * const config = createResourceConfig({ ...users });\n * ```\n */\nexport const createResourceConfig = Object.assign(createResourceConfigImpl, {\n forResource: createResourceConfigForResource,\n});\n"],"mappings":";;;;;;;;;;;;AA4YA,SAAS,sBAAsB,OAA8C;CAC3E,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAEA,SAAS,2BACP,OACA,aACqB;CACrB,MAAM,MAAM,OAAO,gBAAgB,WAAW,cAAc,YAAY;CACxE,MAAM,OAAO,MAAM;CAEnB,IAAI,CAAC,sBAAsB,IAAI,GAC7B,MAAM,IAAIA,qDAAwB;EAChC,aAAa;EACb,mBAAmBC,2CAAoB,KAAK;CAC9C,CAAC;CAGH,IAAI,OAAO,gBAAgB,UACzB,OAAO;CAG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G/D,SAAS,aACP,SACa;EACb,IAAI,OAAO,YAAY,UACrB,OAAO,qBAAqB,QAAQ,OAAO;EAG7C,OAAO,wBAAwB,QAAQ,OAAO;CAChD;CAEA,MAAM,eAAmD,UAAU;EACjE,QAAQ,YACN,wBAAwB,QAAQ;GAC9B,GAAG;GACH,GAAG;EACL,CAA8C;CAClD;CAEA,OAAO,OAAO,OAAO,cAAc,EAAE,YAAY,CAAC;AACpD;AAEA,SAAS,yBAIP,QAC0C;CAC1C,MAAM,eAAe;CAErB,IAAID,0CAAuB,YAAY,EAAE,WAAW,GAClD,MAAM,IAAIE,0CAAmB;EAC3B,QAAQ;EACR;CACF,CAAC;CAKH,OAAO;EACL;EACA,cAAc,mBAAmB,MAAM;EACvC,sBAAsB,SACpBC,yDACE,cACA,IACF;EACF,UAAUC,+BAAe,YAAY;EACrC,kBAAkBC,mDAChB,YACF;EACA,cAAcC,6CACZ,YACF;CACF;AACF;AAEA,SAAS,gCAKP,UACA,QAC0C;CAC1C,OAAO,GAAG,WAAW,OAAO;AAC9B;;;;;;;;;;;;;;;;;;AAmBA,MAAa,uBAAuB,OAAO,OAAO,0BAA0B,EAC1E,aAAa,gCACf,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { LayoutResourceKey, ResourceDefinition, ResourceDefinitionForKey, SubResourceDefinitionsFor, SubResourceParamForResource } from "../resource.cjs";
2
- import { BaseResourceConfigComponents, ResourceConfigComponentKey, ResourceConfigInput, ResourceConfigMap, SharedResourceConfigOptions } from "./types.cjs";
2
+ import { BaseResourceConfigComponents, ResourceConfig, ResourceConfigComponentKey, ResourceConfigInput, ResourceConfigMap, SharedResourceConfigOptions } from "./types.cjs";
3
3
  import { ConfigSubResourceKeys, ParameterizedResourcePath } from "./paths/types.cjs";
4
4
  import { CreateGetComponentForPath } from "./for-paths/get-component-for-path.cjs";
5
5
  import { ForPaths } from "./for-paths/builder.cjs";
@@ -125,7 +125,29 @@ type ComponentTypesFromEntry<Entry> = Entry extends JSX.Element ? never : Entry
125
125
  type ComponentTypes<Created> = Created extends {
126
126
  config: infer Config extends object;
127
127
  } ? { [Resource in keyof Config]: ComponentTypesFromEntry<NonNullable<Config[Resource]>> }[keyof Config] : never;
128
- type CreateResourceConfigFn<Resources extends ReadonlyArray<ResourceDefinition>> = <const Config extends ResourceConfigMap<Resources>>(config: ResourceConfigInput<Resources, Config>) => CreatedResourceConfig<Resources, Config>;
128
+ /**
129
+ * One resource entry keyed for direct spreading into a resource config.
130
+ * Preserves the precise component slots and sub-resource branches in `Config`.
131
+ */
132
+ type ResourceConfigFragment<Resource extends string, Config> = { [Key in Resource]: Config };
133
+ /**
134
+ * Creates one keyed config fragment for spreading into a resource config.
135
+ *
136
+ * @param resource - A top-level resource supported by the layout definition.
137
+ * @param config - Components and declared sub-resource branches for that resource.
138
+ */
139
+ type CreateResourceConfigForResource<Resources extends ReadonlyArray<ResourceDefinition>> = <const Resource extends LayoutResourceKey<Resources>, const Config extends ResourceConfig<Resources>[Resource]>(resource: Resource, config: Config) => ResourceConfigFragment<Resource, Config>;
140
+ /** Creates a validated resource config and exposes helpers for config fragments. */
141
+ type CreateResourceConfigFn<Resources extends ReadonlyArray<ResourceDefinition>> = {
142
+ /**
143
+ * Validates and indexes a complete configuration assembled from one or more
144
+ * resource entries.
145
+ *
146
+ * @param config - At least one resource entry supported by the layout.
147
+ */
148
+ <const Config extends ResourceConfigMap<Resources>>(config: ResourceConfigInput<Resources, Config>): CreatedResourceConfig<Resources, Config>; /** Creates a typed fragment that can be spread into the complete config. */
149
+ forResource: CreateResourceConfigForResource<Resources>;
150
+ };
129
151
  //#endregion
130
- export { ComponentTypes, CreateResourceConfigFn, CreatedResourceConfig, GetComponent, GetComponentAtBound, GetComponentForResource, GetComponentForResourceOptions, GetComponentOptions, GetComponentOptionsForResource, ResourceConfigPath, ResourceFromGetComponentBound, SubResourceFromGetComponentBound, ValidateForResourceBound };
152
+ export { ComponentTypes, CreateResourceConfigFn, CreateResourceConfigForResource, CreatedResourceConfig, GetComponent, GetComponentAtBound, GetComponentForResource, GetComponentForResourceOptions, GetComponentOptions, GetComponentOptionsForResource, ResourceConfigFragment, ResourceConfigPath, ResourceFromGetComponentBound, SubResourceFromGetComponentBound, ValidateForResourceBound };
131
153
  //# sourceMappingURL=get-component.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-component.d.cts","names":[],"sources":["../../src/create-config/get-component.ts"],"mappings":";;;;;;;;;KA+CK,6BAAA,mBACe,aAAA,CAAc,kBAAA,oBACf,iBAAA,CAAkB,SAAA,MAChC,yBAAA,CAA0B,SAAA,EAAW,QAAA;AAAA,KAIrC,4BAAA,mBACe,aAAA,CAAc,kBAAA,oBACf,iBAAA,CAAkB,SAAA,uBAE/B,2BAAA,CAA4B,SAAA,EAAW,QAAA,kBAExC,WAAA,wBACD,6BAAA,CAA8B,SAAA,EAAW,QAAA;EAErC,WAAA,GAAc,2BAAA,CAA4B,SAAA,EAAW,QAAA;AAAA,SAGzD,6BAAA,CAA8B,SAAA,EAAW,QAAA;EACrC,WAAA,GAAc,WAAA;AAAA;;KAIV,8BAAA,mBACQ,aAAA,CAAc,kBAAA,oBACf,iBAAA,CAAkB,SAAA,uBAE/B,2BAAA,CAA4B,SAAA,EAAW,QAAA,6BAEzC,4BAAA,CAA6B,SAAA,EAAW,QAAA,EAAU,WAAA;EACpD,QAAA,EAAU,QAAA;EA9BQ;;;;;EAoClB,SAAA,GAAY,0BAAA;AAAA;;KAIF,mBAAA,mBACQ,aAAA,CAAc,kBAAA,KAEhC,iBAAA,CAAkB,SAAA,2BACd,QAAA,SAAiB,iBAAA,CAAkB,SAAA,IACjC,8BAAA,CAA+B,SAAA,EAAW,QAAA;AAAA,KAI7C,oBAAA,SAA6B,4BAA4B;;KAGzD,gBAAA,sBACc,2BAAA,MAAiC,MAAA,IAAU,oBAAA,WACtD,2BAAA;AAAA,KAEH,4BAAA,aAAyC,kBAAA,IAAsB,GAAA;EAClE,YAAA,uBAAmC,aAAA,CAAc,kB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C,MAAA,EAAQ,mBAAA,CAAoB,SAAA,EAAW,MAAA,IACtC,qBAAA,CAAsB,SAAA,EAAW,MAAA;EAEpC,WAAA,EAAa,+BAAA,CAAgC,SAAA;AAAA"}
@@ -1,5 +1,5 @@
1
1
  import { LayoutResourceKey, ResourceDefinition, ResourceDefinitionForKey, SubResourceDefinitionsFor, SubResourceParamForResource } from "../resource.mjs";
2
- import { BaseResourceConfigComponents, ResourceConfigComponentKey, ResourceConfigInput, ResourceConfigMap, SharedResourceConfigOptions } from "./types.mjs";
2
+ import { BaseResourceConfigComponents, ResourceConfig, ResourceConfigComponentKey, ResourceConfigInput, ResourceConfigMap, SharedResourceConfigOptions } from "./types.mjs";
3
3
  import { ConfigSubResourceKeys, ParameterizedResourcePath } from "./paths/types.mjs";
4
4
  import { CreateGetComponentForPath } from "./for-paths/get-component-for-path.mjs";
5
5
  import { ForPaths } from "./for-paths/builder.mjs";
@@ -125,7 +125,29 @@ type ComponentTypesFromEntry<Entry> = Entry extends JSX.Element ? never : Entry
125
125
  type ComponentTypes<Created> = Created extends {
126
126
  config: infer Config extends object;
127
127
  } ? { [Resource in keyof Config]: ComponentTypesFromEntry<NonNullable<Config[Resource]>> }[keyof Config] : never;
128
- type CreateResourceConfigFn<Resources extends ReadonlyArray<ResourceDefinition>> = <const Config extends ResourceConfigMap<Resources>>(config: ResourceConfigInput<Resources, Config>) => CreatedResourceConfig<Resources, Config>;
128
+ /**
129
+ * One resource entry keyed for direct spreading into a resource config.
130
+ * Preserves the precise component slots and sub-resource branches in `Config`.
131
+ */
132
+ type ResourceConfigFragment<Resource extends string, Config> = { [Key in Resource]: Config };
133
+ /**
134
+ * Creates one keyed config fragment for spreading into a resource config.
135
+ *
136
+ * @param resource - A top-level resource supported by the layout definition.
137
+ * @param config - Components and declared sub-resource branches for that resource.
138
+ */
139
+ type CreateResourceConfigForResource<Resources extends ReadonlyArray<ResourceDefinition>> = <const Resource extends LayoutResourceKey<Resources>, const Config extends ResourceConfig<Resources>[Resource]>(resource: Resource, config: Config) => ResourceConfigFragment<Resource, Config>;
140
+ /** Creates a validated resource config and exposes helpers for config fragments. */
141
+ type CreateResourceConfigFn<Resources extends ReadonlyArray<ResourceDefinition>> = {
142
+ /**
143
+ * Validates and indexes a complete configuration assembled from one or more
144
+ * resource entries.
145
+ *
146
+ * @param config - At least one resource entry supported by the layout.
147
+ */
148
+ <const Config extends ResourceConfigMap<Resources>>(config: ResourceConfigInput<Resources, Config>): CreatedResourceConfig<Resources, Config>; /** Creates a typed fragment that can be spread into the complete config. */
149
+ forResource: CreateResourceConfigForResource<Resources>;
150
+ };
129
151
  //#endregion
130
- export { ComponentTypes, CreateResourceConfigFn, CreatedResourceConfig, GetComponent, GetComponentAtBound, GetComponentForResource, GetComponentForResourceOptions, GetComponentOptions, GetComponentOptionsForResource, ResourceConfigPath, ResourceFromGetComponentBound, SubResourceFromGetComponentBound, ValidateForResourceBound };
152
+ export { ComponentTypes, CreateResourceConfigFn, CreateResourceConfigForResource, CreatedResourceConfig, GetComponent, GetComponentAtBound, GetComponentForResource, GetComponentForResourceOptions, GetComponentOptions, GetComponentOptionsForResource, ResourceConfigFragment, ResourceConfigPath, ResourceFromGetComponentBound, SubResourceFromGetComponentBound, ValidateForResourceBound };
131
153
  //# sourceMappingURL=get-component.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-component.d.mts","names":[],"sources":["../../src/create-config/get-component.ts"],"mappings":";;;;;;;;;KA+CK,6BAAA,mBACe,aAAA,CAAc,kBAAA,oBACf,iBAAA,CAAkB,SAAA,MAChC,yBAAA,CAA0B,SAAA,EAAW,QAAA;AAAA,KAIrC,4BAAA,mBACe,aAAA,CAAc,kBAAA,oBACf,iBAAA,CAAkB,SAAA,uBAE/B,2BAAA,CAA4B,SAAA,EAAW,QAAA,kBAExC,WAAA,wBACD,6BAAA,CAA8B,SAAA,EAAW,QAAA;EAErC,WAAA,GAAc,2BAAA,CAA4B,SAAA,EAAW,QAAA;AAAA,SAGzD,6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