@jfdevelops/react-layout 0.17.0 → 0.17.1

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.
@@ -75,10 +75,14 @@ function defineResourceLayoutImpl(options) {
75
75
  name,
76
76
  capitalize: require_capitalize.capitalize
77
77
  };
78
+ const validationContext = {
79
+ layoutName: name,
80
+ resource: layoutContext.resource
81
+ };
78
82
  const resolvedComposables = composables ? (0, _jfdevelops_react_layout_composables.resolveLayoutComposables)(composables, layoutContext) : void 0;
79
83
  const mergedResolvedInProps = { ...resolvedInProps };
80
84
  for (const { props: presetPropDefinitions } of (0, _jfdevelops_react_layout_composables.collectComposablePresetEntries)(resolvedComposables)) Object.assign(mergedResolvedInProps, presetPropDefinitions);
81
- const composablePresetProps = (0, _jfdevelops_react_layout_composables.resolveComposablePresetProps)(resolvedComposables, layoutOptionProps);
85
+ const composablePresetProps = (0, _jfdevelops_react_layout_composables.resolveComposablePresetProps)(resolvedComposables, layoutOptionProps, validationContext);
82
86
  const mergedRenderContext = {
83
87
  composables: resolvedComposables,
84
88
  resource: layoutContext.resource,
@@ -86,7 +90,7 @@ function defineResourceLayoutImpl(options) {
86
90
  inProps: splitInProps
87
91
  };
88
92
  function Component(props) {
89
- const validatedProps = (0, _jfdevelops_react_layout_validator.validateProps)(resolvedLayoutProps, props);
93
+ const validatedProps = (0, _jfdevelops_react_layout_validator.validateProps)(resolvedLayoutProps, props, { ...validationContext });
90
94
  const includedPropKeys = Object.keys(includeLayoutProps ?? {});
91
95
  const includedPropDefinitions = require_utils.pick(mergedResolvedInProps, includedPropKeys);
92
96
  const includedPropValues = { ...(0, _jfdevelops_react_layout_validator.resolvePropDefinitionValues)(includedPropDefinitions) };
@@ -102,7 +106,7 @@ function defineResourceLayoutImpl(options) {
102
106
  const validatedIncludedProps = (0, _jfdevelops_react_layout_validator.validateProps)({
103
107
  ...requiredIncludedPropDefinitions,
104
108
  ...optionalIncludedPropDefinitions
105
- }, includedPropValues);
109
+ }, includedPropValues, validationContext);
106
110
  const layoutRenderIncludedProps = Object.fromEntries(includedPropKeys.flatMap((key) => {
107
111
  if (!(key in validatedIncludedProps)) return [];
108
112
  return [[toLayoutRenderPropKey(key, mergedResolvedInProps[key]), validatedIncludedProps[key]]];
@@ -1 +1 @@
1
- {"version":3,"file":"define-layout.cjs","names":["capitalize","functionalUpdate","normalizeResources","toResourceEnum","createProp","pick","LayoutComposablePresetProvider","createForResource","createForResources","createResourceLinksFn"],"sources":["../../src/create-config/define-layout.tsx"],"sourcesContent":["import type { JSX } from 'react';\nimport {\n type ComposableComponents,\n type ComposableNameContext,\n type ComposableResourceLayout,\n type CreateLayoutComposable,\n collectComposablePresetEntries,\n LayoutComposablePresetProvider,\n MakeComposable,\n makeComposable,\n MakeComposableOptions,\n RequiredPresetLayoutProps,\n resolveComposablePresetProps,\n resolveLayoutComposables,\n} from '@jfdevelops/react-layout-composables';\nimport {\n type AnyBuiltPropDefinition,\n createPrimitivePropBuilder,\n createProp,\n type ResolveLayoutProps,\n type ResolveProps,\n resolvePropDefinitionValues,\n validateProps,\n} from '@jfdevelops/react-layout-validator';\nimport {\n IncludedProps,\n InferredInProps,\n InPropsDefinition,\n InPropsObject,\n LayoutRenderProps,\n MergedLayoutInProps,\n} from '../props';\nimport {\n normalizeResources,\n toResourceEnum,\n type LayoutResourceKey,\n type ResourceDefinition,\n} from '../resource';\nimport { BaseComponent, functionalUpdate, pick, Show, Updater } from '../utils';\nimport { capitalize } from '../utils/capitalize';\nimport {\n type CreateResourceConfigFn,\n createResourceConfig,\n} from './get-component';\nimport {\n createResourceLinksFn,\n type CreateResourceLinksFn,\n} from './create-resource-links';\nimport {\n createForResource,\n type CreateLayoutForResource,\n type CreateResourceLayoutOptions,\n type CreateResourceLayoutOptionsBase,\n} from './for-resource';\nimport {\n createForResources,\n type CreateResourceLayoutForResourcesFn,\n} from './for-resources';\n\nexport type LayoutIncludeProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n> = IncludedProps<MergedLayoutInProps<Resources, Options, Composables>>;\n\nexport type LayoutProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n IncludeProps extends LayoutIncludeProps<Resources, Options, Composables> = {},\n CustomProps extends InPropsObject = {},\n> = {\n /**\n * Props to include in the layout.\n */\n include?: LayoutIncludeProps<Resources, Options, Composables> & IncludeProps;\n /**\n * Custom props that the layout will receive.\n */\n custom?: CustomProps;\n};\n\ntype LayoutRenderContext<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Composables extends ComposableComponents,\n> = {\n composables: LayoutRenderComposables<Composables>;\n inProps: Record<string, unknown>;\n resource: LayoutResourceKey<Resources>;\n name: string;\n};\ntype LayoutRenderComposables<Composables extends ComposableComponents> = [\n keyof Composables,\n] extends [never]\n ? undefined\n : Composables;\n\ntype SplitLayoutInPropDefinition<\n Props extends InPropsObject = {},\n Content = unknown,\n> = {\n props?: Props;\n render: ((props: ResolveProps<Props>) => Content) | Content;\n};\n\nfunction isBuiltPropDefinition(\n value: unknown,\n): value is AnyBuiltPropDefinition {\n return typeof value === 'function' && value !== null && 'visibility' in value;\n}\n\nfunction isSplitLayoutInPropDefinition(\n value: unknown,\n): value is SplitLayoutInPropDefinition {\n return (\n value !== null &&\n typeof value === 'object' &&\n 'render' in value &&\n (value as { render?: unknown }).render !== undefined\n );\n}\n\nfunction isJSXElementDefinition(\n definition: unknown,\n): definition is AnyBuiltPropDefinition & { type: 'JSX.Element' } {\n return (\n isBuiltPropDefinition(definition) &&\n 'type' in definition &&\n definition.type === 'JSX.Element'\n );\n}\n\nfunction toLayoutRenderPropKey(includeKey: string, definition: unknown) {\n return isJSXElementDefinition(definition)\n ? capitalize(includeKey)\n : includeKey;\n}\n\nfunction readLayoutOptionValue(\n includeKey: string,\n definition: unknown,\n sources: Record<string, unknown>,\n) {\n const layoutOptionKeys = isJSXElementDefinition(definition)\n ? [capitalize(includeKey), includeKey]\n : [includeKey, capitalize(includeKey)];\n\n for (const key of layoutOptionKeys) {\n if (key in sources) {\n return sources[key];\n }\n }\n\n return undefined;\n}\n\nfunction splitLayoutInProps(inProps: Record<string, unknown>) {\n const resolvedInProps: Record<string, AnyBuiltPropDefinition> = {};\n const splitInProps: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(inProps)) {\n if (isBuiltPropDefinition(value)) {\n resolvedInProps[key] = value;\n continue;\n }\n\n if (isSplitLayoutInPropDefinition(value)) {\n splitInProps[key] = value.render;\n\n if (value.props && typeof value.props === 'object') {\n Object.assign(resolvedInProps, value.props);\n }\n }\n }\n\n return {\n resolvedInProps,\n splitInProps,\n };\n}\n\nfunction resolveLayoutOptionDefaults(\n defaults: Record<string, unknown>,\n options: Record<string, unknown>,\n) {\n const resolved = { ...options };\n\n for (const [key, defaultValue] of Object.entries(defaults)) {\n if (key in options) {\n if (typeof defaultValue === 'function') {\n resolved[key] = options[key];\n } else {\n resolved[key] = functionalUpdate(\n defaultValue,\n options[key] as Updater<unknown>,\n );\n }\n }\n }\n\n return resolved;\n}\n\ntype CreateViewMapOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n IncludeProps extends LayoutIncludeProps<Resources, Options, Composables> = {},\n CustomProps extends InPropsObject = {},\n> = {\n /**\n * An array of valid resource names to support.\n */\n resources: Resources;\n /**\n * The options that are passed into the created resource layout.\n */\n options?: Options;\n layout: {\n /**\n * The props to pass to the layout.\n */\n props?: LayoutProps<\n Resources,\n Options,\n Composables,\n IncludeProps,\n CustomProps\n >;\n /**\n * Components used to compose the layout. Invoked per layout instance with\n * a scoped `create` that resolves composable `name` callbacks using the\n * layout's `resource` and `name`.\n */\n composables?: (\n create: CreateLayoutComposable<LayoutResourceKey<Resources>>,\n ) => Composables;\n /**\n * The render function for the layout.\n */\n render: (\n props: LayoutRenderProps<\n Resources,\n Options,\n Composables,\n IncludeProps,\n CustomProps\n >,\n context: LayoutRenderContext<Resources, Composables>,\n ) => JSX.Element;\n };\n};\n\ntype ResourceLayoutComposition<\n Name extends string,\n Composables extends ComposableComponents,\n> = [keyof Composables] extends [never]\n ? {}\n : {\n makeComposable: MakeComposable<Composables, Name>;\n };\nexport type ResourceLayoutComponent<\n Name extends string,\n Props extends InPropsObject = {},\n Composables extends ComposableComponents = {},\n Resource extends string = string,\n> = ResourceLayoutComposition<Name, Composables> &\n BaseComponent<Name, ResolveProps<Props>> & {\n (props: Show<ResolveProps<Props>>): JSX.Element;\n /**\n * A type-only property containing the resource associated with this\n * component. This property is `undefined` at runtime.\n */\n readonly resource: Resource;\n };\n\nexport type LayoutPropsForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents = {},\n> = ResolveLayoutProps<InferredInProps<Resources, InProps>> &\n RequiredPresetLayoutProps<Composables>;\n\ntype CreateResourceLayoutFnImpl<\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 Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n>(\n options: CreateResourceLayoutOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n) => ResourceLayoutComponent<Name, CustomProps, Composables, Resource>;\n\nexport type CreateResourceLayoutMakeComposableOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n> = CreateResourceLayoutOptionsBase<Resources, Name, Resource, Props> &\n Partial<LayoutPropsForResource<Resources, InProps, Composables>>;\n\ntype CreateResourceLayoutMakeComposableFn<\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 Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n>(\n options: CreateResourceLayoutMakeComposableOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n) => ComposableResourceLayout<Composables, Name, any, any, any>;\n\ntype CreateResourceLayoutFnBase<\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> = CreateResourceLayoutFnImpl<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> & {\n /**\n * A function to create a resource layout for a specific resource.\n */\n forResource: CreateLayoutForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n /**\n * Creates resource layout factories for multiple defined resources.\n */\n forResources: CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n};\n\ntype CreateResourceLayoutMakeComposableMember<\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> = [keyof Composables] extends [never]\n ? {}\n : {\n makeComposable: CreateResourceLayoutMakeComposableFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n };\n\nexport type CreateResourceLayoutFn<\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> = CreateResourceLayoutFnBase<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> &\n CreateResourceLayoutMakeComposableMember<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\ntype DefinedResourceLayout<\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 createResourceConfig: CreateResourceConfigFn<Resources>;\n createResourceLayout: CreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n createResourceLinks: CreateResourceLinksFn<Resources>;\n};\n\n\nfunction defineResourceLayoutImpl<\n const Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n Resources,\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n>(\n options: CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n): DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> {\n const { options: inProps = {} as InProps, resources, layout } = options;\n const normalizedResources = normalizeResources(resources);\n const resourcesEnum = createPrimitivePropBuilder('string').enum(\n toResourceEnum(normalizedResources),\n );\n const definedResourceLayout = (<\n Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n >(\n layoutOptions: CreateResourceLayoutOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n ) => {\n const {\n name,\n props: instancePropDefinitions,\n ...layoutOptionProps\n } = layoutOptions;\n const createComposableLayout =\n makeComposable<\n LayoutRenderProps<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >\n >();\n const nameProp = createProp.string().literal(name);\n const rawResolvedOptions =\n typeof inProps === 'function'\n ? inProps({\n resource: resourcesEnum,\n name: nameProp,\n })\n : inProps;\n const { resolvedInProps, splitInProps } = splitLayoutInProps({\n ...(rawResolvedOptions as Record<string, unknown>),\n ...(instancePropDefinitions as Record<string, unknown> | undefined),\n ...layoutOptionProps,\n });\n const { composables, render, props: layoutProps } = layout;\n const customLayoutProps = layoutProps?.custom;\n const includeLayoutProps = layoutProps?.include;\n const resolvedLayoutProps = {\n ...customLayoutProps,\n };\n const layoutContext: ComposableNameContext<\n LayoutResourceKey<Resources>,\n typeof name\n > = {\n resource: layoutOptions.resource,\n name,\n capitalize,\n };\n const resolvedComposables = composables\n ? resolveLayoutComposables(composables, layoutContext)\n : undefined;\n const mergedResolvedInProps = { ...resolvedInProps };\n\n for (const {\n props: presetPropDefinitions,\n } of collectComposablePresetEntries(resolvedComposables)) {\n Object.assign(mergedResolvedInProps, presetPropDefinitions);\n }\n\n const composablePresetProps = resolveComposablePresetProps(\n resolvedComposables,\n layoutOptionProps as Record<string, unknown>,\n );\n const mergedRenderContext = {\n composables: resolvedComposables as LayoutRenderComposables<Composables>,\n resource: layoutContext.resource,\n name: layoutContext.name,\n inProps: splitInProps,\n } as LayoutRenderContext<Resources, Composables>;\n\n function Component(props: Show<ResolveProps<CustomProps>>) {\n const validatedProps = validateProps(resolvedLayoutProps, props);\n const includedPropKeys = Object.keys(includeLayoutProps ?? {});\n const includedPropDefinitions = pick(\n mergedResolvedInProps,\n includedPropKeys,\n ) as Record<string, unknown>;\n const includedPropValues = {\n ...resolvePropDefinitionValues(includedPropDefinitions),\n } as Record<string, unknown>;\n\n for (const key of includedPropKeys) {\n const definition = mergedResolvedInProps[key];\n const layoutOptionValue = readLayoutOptionValue(\n key,\n definition,\n layoutOptionProps,\n );\n const splitValue = key in splitInProps ? splitInProps[key] : undefined;\n const value = layoutOptionValue ?? splitValue;\n\n if (value !== undefined) {\n includedPropValues[key] = value;\n }\n }\n\n const requiredIncludedPropDefinitions = Object.fromEntries(\n Object.entries(includedPropDefinitions).filter(\n ([key]) => includeLayoutProps?.[key] === true,\n ),\n );\n const optionalIncludedPropDefinitions = Object.fromEntries(\n Object.entries(includedPropDefinitions).filter(\n ([key]) =>\n includeLayoutProps?.[key] === 'optional' &&\n includedPropValues[key] !== undefined,\n ),\n );\n const validatedIncludedProps = validateProps(\n {\n ...requiredIncludedPropDefinitions,\n ...optionalIncludedPropDefinitions,\n } as Record<string, AnyBuiltPropDefinition>,\n includedPropValues,\n );\n const layoutRenderIncludedProps = Object.fromEntries(\n includedPropKeys.flatMap((key) => {\n if (!(key in validatedIncludedProps)) {\n return [];\n }\n\n return [\n [\n toLayoutRenderPropKey(key, mergedResolvedInProps[key]),\n validatedIncludedProps[\n key as keyof typeof validatedIncludedProps\n ],\n ],\n ];\n }),\n );\n const layoutRenderProps = {\n ...validatedProps,\n ...layoutRenderIncludedProps,\n } as unknown as LayoutRenderProps<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\n return (\n <LayoutComposablePresetProvider value={composablePresetProps}>\n {render(layoutRenderProps, mergedRenderContext)}\n </LayoutComposablePresetProvider>\n );\n }\n\n function createComposition<\n LayoutName extends string,\n const Defined extends MakeComposableOptions<Composables, LayoutName>,\n >(compositionOptions: Defined) {\n if (!compositionOptions.components) {\n return {} as ResourceLayoutComposition<LayoutName, Composables>;\n }\n\n return {\n makeComposable: createComposableLayout(\n compositionOptions,\n ) as MakeComposable<Composables, LayoutName>,\n };\n }\n\n return Object.assign(Component, {\n displayName: name,\n props: undefined as unknown as ResolveProps<CustomProps>,\n resource: undefined as unknown as Resource,\n ...createComposition({\n components: resolvedComposables as Composables | undefined,\n name,\n }),\n });\n }) as CreateResourceLayoutFnImpl<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n const createTopLevelMakeComposable = () => {\n return (options: Record<string, unknown>) => {\n const layout = definedResourceLayout(options as never);\n\n if (\n !('makeComposable' in layout) ||\n typeof layout.makeComposable !== 'function'\n ) {\n throw new Error(\n 'makeComposable requires composables to be defined in the layout',\n );\n }\n\n return layout.makeComposable();\n };\n };\n\n function getComponentPropDefinitions(resource: LayoutResourceKey<Resources>) {\n const componentName = 'ScopedResourceComponent';\n const rawResolvedOptions =\n typeof inProps === 'function'\n ? inProps({\n resource: resourcesEnum,\n name: createProp.string().literal(componentName),\n })\n : inProps;\n const { resolvedInProps } = splitLayoutInProps(\n rawResolvedOptions as Record<string, unknown>,\n );\n const resolvedComposables = layout.composables\n ? resolveLayoutComposables(layout.composables, {\n resource,\n name: componentName,\n capitalize,\n })\n : undefined;\n\n for (const {\n props: presetPropDefinitions,\n } of collectComposablePresetEntries(resolvedComposables)) {\n Object.assign(resolvedInProps, presetPropDefinitions);\n }\n\n return {\n ...resolvedInProps,\n ...layout.props?.custom,\n };\n }\n\n const { createLayoutForResourceBuilder, forResource } = createForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >({\n createResourceLayout: definedResourceLayout as never,\n resolveLayoutOptionDefaults,\n });\n const forResources = createForResources<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >({\n createLayoutForResource: createLayoutForResourceBuilder,\n ...(layout.composables\n ? { createMakeComposableLayout: createTopLevelMakeComposable }\n : {}),\n createResourceLayout: definedResourceLayout as never,\n getComponentPropDefinitions,\n });\n\n const createResourceLayoutExtras: {\n forResource: CreateLayoutForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n forResources: CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n makeComposable?: ReturnType<typeof createTopLevelMakeComposable>;\n } = {\n forResource,\n forResources,\n };\n\n if (layout.composables) {\n createResourceLayoutExtras.makeComposable = createTopLevelMakeComposable();\n }\n\n const createResourceLayout = Object.assign(\n definedResourceLayout,\n createResourceLayoutExtras,\n ) as CreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\n const createResourceLinks = createResourceLinksFn(resources);\n\n return {\n createResourceConfig,\n createResourceLayout,\n createResourceLinks,\n } as DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n}\n\ntype DefineResourceLayoutForResourcesOptions<\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 ExtraResources extends ReadonlyArray<ResourceDefinition> = [],\n> = Omit<\n CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n 'resources'\n> & {\n /**\n * Additional resources to merge with those bound by\n * {@link defineResourceLayout.forResources}.\n */\n resources?: ExtraResources;\n};\n\ntype NonEmptyResourceDefinitions = readonly [\n ResourceDefinition,\n ...ResourceDefinition[],\n];\n\n/**\n * Factory returned by {@link DefineResourceLayout.forResources}.\n */\nexport type DefineResourceLayoutForResourcesFactory<\n BaseResources extends NonEmptyResourceDefinitions,\n> = <\n const ExtraResources extends ReadonlyArray<ResourceDefinition> = [],\n InProps extends InPropsDefinition<[...BaseResources, ...ExtraResources]> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n>(\n options: DefineResourceLayoutForResourcesOptions<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables,\n IncludeProps,\n CustomProps,\n ExtraResources\n >,\n) => DefinedResourceLayout<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n>;\n\n/**\n * Binds one or more resources, then accepts the remaining\n * {@link defineResourceLayout} options (with optional extra `resources`).\n */\nexport type DefineResourceLayoutForResources = <\n const Resources extends NonEmptyResourceDefinitions,\n>(\n ...resources: Resources\n) => DefineResourceLayoutForResourcesFactory<Resources>;\n\n/**\n * Creates a resource layout definition for a set of resources.\n */\nexport type DefineResourceLayoutFn = {\n <\n const Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n Resources,\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n >(\n options: CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n ): DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n};\n\nexport type DefineResourceLayout = DefineResourceLayoutFn & {\n forResources: DefineResourceLayoutForResources;\n};\n\nfunction defineResourceLayoutForResources<\n const Resources extends NonEmptyResourceDefinitions,\n>(\n ...baseResources: Resources\n): DefineResourceLayoutForResourcesFactory<Resources> {\n return ((options) => {\n const { resources: extraResources, ...rest } = options;\n const resources = extraResources\n ? [...baseResources, ...extraResources]\n : [...baseResources];\n\n return defineResourceLayoutImpl({\n ...rest,\n resources,\n } as never);\n }) as DefineResourceLayoutForResourcesFactory<Resources>;\n}\n\nexport const defineResourceLayout: DefineResourceLayout = Object.assign(\n defineResourceLayoutImpl as DefineResourceLayoutFn,\n {\n forResources: defineResourceLayoutForResources,\n },\n);\n"],"mappings":";;;;;;;;;;;;AAyGA,SAAS,sBACP,OACiC;CACjC,OAAO,OAAO,UAAU,cAAc,UAAU,QAAQ,gBAAgB;AAC1E;AAEA,SAAS,8BACP,OACsC;CACtC,OACE,UAAU,QACV,OAAO,UAAU,YACjB,YAAY,SACX,MAA+B,WAAW;AAE/C;AAEA,SAAS,uBACP,YACgE;CAChE,OACE,sBAAsB,UAAU,KAChC,UAAU,cACV,WAAW,SAAS;AAExB;AAEA,SAAS,sBAAsB,YAAoB,YAAqB;CACtE,OAAO,uBAAuB,UAAU,IACpCA,8BAAW,UAAU,IACrB;AACN;AAEA,SAAS,sBACP,YACA,YACA,SACA;CACA,MAAM,mBAAmB,uBAAuB,UAAU,IACtD,CAACA,8BAAW,UAAU,GAAG,UAAU,IACnC,CAAC,YAAYA,8BAAW,UAAU,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A6B,IAC3D,CAAC;GACL,sBAAsB;GACtB;EACF,CAoBa;CACb;CAEA,IAAI,OAAO,aACT,2BAA2B,iBAAiB,6BAA6B;CAgB3E,OAAO;EACL;EACA,sBAf2B,OAAO,OAClC,uBACA,0BAamB;EACnB,qBAL0BC,oDAAsB,SAK9B;CACpB;AAOF;AA4GA,SAAS,iCAGP,GAAG,eACiD;CACpD,SAAS,YAAY;EACnB,MAAM,EAAE,WAAW,gBAAgB,GAAG,SAAS;EAC/C,MAAM,YAAY,iBACd,CAAC,GAAG,eAAe,GAAG,cAAc,IACpC,CAAC,GAAG,aAAa;EAErB,OAAO,yBAAyB;GAC9B,GAAG;GACH;EACF,CAAU;CACZ;AACF;AAEA,MAAa,uBAA6C,OAAO,OAC/D,0BACA,EACE,cAAc,iCAChB,CACF"}
1
+ {"version":3,"file":"define-layout.cjs","names":["capitalize","functionalUpdate","normalizeResources","toResourceEnum","createProp","pick","LayoutComposablePresetProvider","createForResource","createForResources","createResourceLinksFn"],"sources":["../../src/create-config/define-layout.tsx"],"sourcesContent":["import type { JSX } from 'react';\nimport {\n type ComposableComponents,\n type ComposableNameContext,\n type ComposableResourceLayout,\n type CreateLayoutComposable,\n collectComposablePresetEntries,\n LayoutComposablePresetProvider,\n MakeComposable,\n makeComposable,\n MakeComposableOptions,\n RequiredPresetLayoutProps,\n resolveComposablePresetProps,\n resolveLayoutComposables,\n} from '@jfdevelops/react-layout-composables';\nimport {\n type AnyBuiltPropDefinition,\n createPrimitivePropBuilder,\n createProp,\n type ResolveLayoutProps,\n type ResolveProps,\n resolvePropDefinitionValues,\n validateProps,\n} from '@jfdevelops/react-layout-validator';\nimport {\n IncludedProps,\n InferredInProps,\n InPropsDefinition,\n InPropsObject,\n LayoutRenderProps,\n MergedLayoutInProps,\n} from '../props';\nimport {\n normalizeResources,\n toResourceEnum,\n type LayoutResourceKey,\n type ResourceDefinition,\n} from '../resource';\nimport { BaseComponent, functionalUpdate, pick, Show, Updater } from '../utils';\nimport { capitalize } from '../utils/capitalize';\nimport {\n type CreateResourceConfigFn,\n createResourceConfig,\n} from './get-component';\nimport {\n createResourceLinksFn,\n type CreateResourceLinksFn,\n} from './create-resource-links';\nimport {\n createForResource,\n type CreateLayoutForResource,\n type CreateResourceLayoutOptions,\n type CreateResourceLayoutOptionsBase,\n} from './for-resource';\nimport {\n createForResources,\n type CreateResourceLayoutForResourcesFn,\n} from './for-resources';\n\nexport type LayoutIncludeProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n> = IncludedProps<MergedLayoutInProps<Resources, Options, Composables>>;\n\nexport type LayoutProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n IncludeProps extends LayoutIncludeProps<Resources, Options, Composables> = {},\n CustomProps extends InPropsObject = {},\n> = {\n /**\n * Props to include in the layout.\n */\n include?: LayoutIncludeProps<Resources, Options, Composables> & IncludeProps;\n /**\n * Custom props that the layout will receive.\n */\n custom?: CustomProps;\n};\n\ntype LayoutRenderContext<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Composables extends ComposableComponents,\n> = {\n composables: LayoutRenderComposables<Composables>;\n inProps: Record<string, unknown>;\n resource: LayoutResourceKey<Resources>;\n name: string;\n};\ntype LayoutRenderComposables<Composables extends ComposableComponents> = [\n keyof Composables,\n] extends [never]\n ? undefined\n : Composables;\n\ntype SplitLayoutInPropDefinition<\n Props extends InPropsObject = {},\n Content = unknown,\n> = {\n props?: Props;\n render: ((props: ResolveProps<Props>) => Content) | Content;\n};\n\nfunction isBuiltPropDefinition(\n value: unknown,\n): value is AnyBuiltPropDefinition {\n return typeof value === 'function' && value !== null && 'visibility' in value;\n}\n\nfunction isSplitLayoutInPropDefinition(\n value: unknown,\n): value is SplitLayoutInPropDefinition {\n return (\n value !== null &&\n typeof value === 'object' &&\n 'render' in value &&\n (value as { render?: unknown }).render !== undefined\n );\n}\n\nfunction isJSXElementDefinition(\n definition: unknown,\n): definition is AnyBuiltPropDefinition & { type: 'JSX.Element' } {\n return (\n isBuiltPropDefinition(definition) &&\n 'type' in definition &&\n definition.type === 'JSX.Element'\n );\n}\n\nfunction toLayoutRenderPropKey(includeKey: string, definition: unknown) {\n return isJSXElementDefinition(definition)\n ? capitalize(includeKey)\n : includeKey;\n}\n\nfunction readLayoutOptionValue(\n includeKey: string,\n definition: unknown,\n sources: Record<string, unknown>,\n) {\n const layoutOptionKeys = isJSXElementDefinition(definition)\n ? [capitalize(includeKey), includeKey]\n : [includeKey, capitalize(includeKey)];\n\n for (const key of layoutOptionKeys) {\n if (key in sources) {\n return sources[key];\n }\n }\n\n return undefined;\n}\n\nfunction splitLayoutInProps(inProps: Record<string, unknown>) {\n const resolvedInProps: Record<string, AnyBuiltPropDefinition> = {};\n const splitInProps: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(inProps)) {\n if (isBuiltPropDefinition(value)) {\n resolvedInProps[key] = value;\n continue;\n }\n\n if (isSplitLayoutInPropDefinition(value)) {\n splitInProps[key] = value.render;\n\n if (value.props && typeof value.props === 'object') {\n Object.assign(resolvedInProps, value.props);\n }\n }\n }\n\n return {\n resolvedInProps,\n splitInProps,\n };\n}\n\nfunction resolveLayoutOptionDefaults(\n defaults: Record<string, unknown>,\n options: Record<string, unknown>,\n) {\n const resolved = { ...options };\n\n for (const [key, defaultValue] of Object.entries(defaults)) {\n if (key in options) {\n if (typeof defaultValue === 'function') {\n resolved[key] = options[key];\n } else {\n resolved[key] = functionalUpdate(\n defaultValue,\n options[key] as Updater<unknown>,\n );\n }\n }\n }\n\n return resolved;\n}\n\ntype CreateViewMapOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n IncludeProps extends LayoutIncludeProps<Resources, Options, Composables> = {},\n CustomProps extends InPropsObject = {},\n> = {\n /**\n * An array of valid resource names to support.\n */\n resources: Resources;\n /**\n * The options that are passed into the created resource layout.\n */\n options?: Options;\n layout: {\n /**\n * The props to pass to the layout.\n */\n props?: LayoutProps<\n Resources,\n Options,\n Composables,\n IncludeProps,\n CustomProps\n >;\n /**\n * Components used to compose the layout. Invoked per layout instance with\n * a scoped `create` that resolves composable `name` callbacks using the\n * layout's `resource` and `name`.\n */\n composables?: (\n create: CreateLayoutComposable<LayoutResourceKey<Resources>>,\n ) => Composables;\n /**\n * The render function for the layout.\n */\n render: (\n props: LayoutRenderProps<\n Resources,\n Options,\n Composables,\n IncludeProps,\n CustomProps\n >,\n context: LayoutRenderContext<Resources, Composables>,\n ) => JSX.Element;\n };\n};\n\ntype ResourceLayoutComposition<\n Name extends string,\n Composables extends ComposableComponents,\n> = [keyof Composables] extends [never]\n ? {}\n : {\n makeComposable: MakeComposable<Composables, Name>;\n };\nexport type ResourceLayoutComponent<\n Name extends string,\n Props extends InPropsObject = {},\n Composables extends ComposableComponents = {},\n Resource extends string = string,\n> = ResourceLayoutComposition<Name, Composables> &\n BaseComponent<Name, ResolveProps<Props>> & {\n (props: Show<ResolveProps<Props>>): JSX.Element;\n /**\n * A type-only property containing the resource associated with this\n * component. This property is `undefined` at runtime.\n */\n readonly resource: Resource;\n };\n\nexport type LayoutPropsForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents = {},\n> = ResolveLayoutProps<InferredInProps<Resources, InProps>> &\n RequiredPresetLayoutProps<Composables>;\n\ntype CreateResourceLayoutFnImpl<\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 Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n>(\n options: CreateResourceLayoutOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n) => ResourceLayoutComponent<Name, CustomProps, Composables, Resource>;\n\nexport type CreateResourceLayoutMakeComposableOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n> = CreateResourceLayoutOptionsBase<Resources, Name, Resource, Props> &\n Partial<LayoutPropsForResource<Resources, InProps, Composables>>;\n\ntype CreateResourceLayoutMakeComposableFn<\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 Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n>(\n options: CreateResourceLayoutMakeComposableOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n) => ComposableResourceLayout<Composables, Name, any, any, any>;\n\ntype CreateResourceLayoutFnBase<\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> = CreateResourceLayoutFnImpl<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> & {\n /**\n * A function to create a resource layout for a specific resource.\n */\n forResource: CreateLayoutForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n /**\n * Creates resource layout factories for multiple defined resources.\n */\n forResources: CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n};\n\ntype CreateResourceLayoutMakeComposableMember<\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> = [keyof Composables] extends [never]\n ? {}\n : {\n makeComposable: CreateResourceLayoutMakeComposableFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n };\n\nexport type CreateResourceLayoutFn<\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> = CreateResourceLayoutFnBase<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> &\n CreateResourceLayoutMakeComposableMember<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\ntype DefinedResourceLayout<\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 createResourceConfig: CreateResourceConfigFn<Resources>;\n createResourceLayout: CreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n createResourceLinks: CreateResourceLinksFn<Resources>;\n};\n\n\nfunction defineResourceLayoutImpl<\n const Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n Resources,\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n>(\n options: CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n): DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> {\n const { options: inProps = {} as InProps, resources, layout } = options;\n const normalizedResources = normalizeResources(resources);\n const resourcesEnum = createPrimitivePropBuilder('string').enum(\n toResourceEnum(normalizedResources),\n );\n const definedResourceLayout = (<\n Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n >(\n layoutOptions: CreateResourceLayoutOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n ) => {\n const {\n name,\n props: instancePropDefinitions,\n ...layoutOptionProps\n } = layoutOptions;\n const createComposableLayout =\n makeComposable<\n LayoutRenderProps<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >\n >();\n const nameProp = createProp.string().literal(name);\n const rawResolvedOptions =\n typeof inProps === 'function'\n ? inProps({\n resource: resourcesEnum,\n name: nameProp,\n })\n : inProps;\n const { resolvedInProps, splitInProps } = splitLayoutInProps({\n ...(rawResolvedOptions as Record<string, unknown>),\n ...(instancePropDefinitions as Record<string, unknown> | undefined),\n ...layoutOptionProps,\n });\n const { composables, render, props: layoutProps } = layout;\n const customLayoutProps = layoutProps?.custom;\n const includeLayoutProps = layoutProps?.include;\n const resolvedLayoutProps = {\n ...customLayoutProps,\n };\n const layoutContext: ComposableNameContext<\n LayoutResourceKey<Resources>,\n typeof name\n > = {\n resource: layoutOptions.resource,\n name,\n capitalize,\n };\n const validationContext = {\n layoutName: name,\n resource: layoutContext.resource,\n };\n const resolvedComposables = composables\n ? resolveLayoutComposables(composables, layoutContext)\n : undefined;\n const mergedResolvedInProps = { ...resolvedInProps };\n\n for (const {\n props: presetPropDefinitions,\n } of collectComposablePresetEntries(resolvedComposables)) {\n Object.assign(mergedResolvedInProps, presetPropDefinitions);\n }\n\n const composablePresetProps = resolveComposablePresetProps(\n resolvedComposables,\n layoutOptionProps as Record<string, unknown>,\n validationContext,\n );\n const mergedRenderContext = {\n composables: resolvedComposables as LayoutRenderComposables<Composables>,\n resource: layoutContext.resource,\n name: layoutContext.name,\n inProps: splitInProps,\n } as LayoutRenderContext<Resources, Composables>;\n\n function Component(props: Show<ResolveProps<CustomProps>>) {\n const validatedProps = validateProps(resolvedLayoutProps, props, {\n ...validationContext,\n });\n const includedPropKeys = Object.keys(includeLayoutProps ?? {});\n const includedPropDefinitions = pick(\n mergedResolvedInProps,\n includedPropKeys,\n ) as Record<string, unknown>;\n const includedPropValues = {\n ...resolvePropDefinitionValues(includedPropDefinitions),\n } as Record<string, unknown>;\n\n for (const key of includedPropKeys) {\n const definition = mergedResolvedInProps[key];\n const layoutOptionValue = readLayoutOptionValue(\n key,\n definition,\n layoutOptionProps,\n );\n const splitValue = key in splitInProps ? splitInProps[key] : undefined;\n const value = layoutOptionValue ?? splitValue;\n\n if (value !== undefined) {\n includedPropValues[key] = value;\n }\n }\n\n const requiredIncludedPropDefinitions = Object.fromEntries(\n Object.entries(includedPropDefinitions).filter(\n ([key]) => includeLayoutProps?.[key] === true,\n ),\n );\n const optionalIncludedPropDefinitions = Object.fromEntries(\n Object.entries(includedPropDefinitions).filter(\n ([key]) =>\n includeLayoutProps?.[key] === 'optional' &&\n includedPropValues[key] !== undefined,\n ),\n );\n const validatedIncludedProps = validateProps(\n {\n ...requiredIncludedPropDefinitions,\n ...optionalIncludedPropDefinitions,\n } as Record<string, AnyBuiltPropDefinition>,\n includedPropValues,\n validationContext,\n );\n const layoutRenderIncludedProps = Object.fromEntries(\n includedPropKeys.flatMap((key) => {\n if (!(key in validatedIncludedProps)) {\n return [];\n }\n\n return [\n [\n toLayoutRenderPropKey(key, mergedResolvedInProps[key]),\n validatedIncludedProps[\n key as keyof typeof validatedIncludedProps\n ],\n ],\n ];\n }),\n );\n const layoutRenderProps = {\n ...validatedProps,\n ...layoutRenderIncludedProps,\n } as unknown as LayoutRenderProps<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\n return (\n <LayoutComposablePresetProvider value={composablePresetProps}>\n {render(layoutRenderProps, mergedRenderContext)}\n </LayoutComposablePresetProvider>\n );\n }\n\n function createComposition<\n LayoutName extends string,\n const Defined extends MakeComposableOptions<Composables, LayoutName>,\n >(compositionOptions: Defined) {\n if (!compositionOptions.components) {\n return {} as ResourceLayoutComposition<LayoutName, Composables>;\n }\n\n return {\n makeComposable: createComposableLayout(\n compositionOptions,\n ) as MakeComposable<Composables, LayoutName>,\n };\n }\n\n return Object.assign(Component, {\n displayName: name,\n props: undefined as unknown as ResolveProps<CustomProps>,\n resource: undefined as unknown as Resource,\n ...createComposition({\n components: resolvedComposables as Composables | undefined,\n name,\n }),\n });\n }) as CreateResourceLayoutFnImpl<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n const createTopLevelMakeComposable = () => {\n return (options: Record<string, unknown>) => {\n const layout = definedResourceLayout(options as never);\n\n if (\n !('makeComposable' in layout) ||\n typeof layout.makeComposable !== 'function'\n ) {\n throw new Error(\n 'makeComposable requires composables to be defined in the layout',\n );\n }\n\n return layout.makeComposable();\n };\n };\n\n function getComponentPropDefinitions(resource: LayoutResourceKey<Resources>) {\n const componentName = 'ScopedResourceComponent';\n const rawResolvedOptions =\n typeof inProps === 'function'\n ? inProps({\n resource: resourcesEnum,\n name: createProp.string().literal(componentName),\n })\n : inProps;\n const { resolvedInProps } = splitLayoutInProps(\n rawResolvedOptions as Record<string, unknown>,\n );\n const resolvedComposables = layout.composables\n ? resolveLayoutComposables(layout.composables, {\n resource,\n name: componentName,\n capitalize,\n })\n : undefined;\n\n for (const {\n props: presetPropDefinitions,\n } of collectComposablePresetEntries(resolvedComposables)) {\n Object.assign(resolvedInProps, presetPropDefinitions);\n }\n\n return {\n ...resolvedInProps,\n ...layout.props?.custom,\n };\n }\n\n const { createLayoutForResourceBuilder, forResource } = createForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >({\n createResourceLayout: definedResourceLayout as never,\n resolveLayoutOptionDefaults,\n });\n const forResources = createForResources<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >({\n createLayoutForResource: createLayoutForResourceBuilder,\n ...(layout.composables\n ? { createMakeComposableLayout: createTopLevelMakeComposable }\n : {}),\n createResourceLayout: definedResourceLayout as never,\n getComponentPropDefinitions,\n });\n\n const createResourceLayoutExtras: {\n forResource: CreateLayoutForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n forResources: CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n makeComposable?: ReturnType<typeof createTopLevelMakeComposable>;\n } = {\n forResource,\n forResources,\n };\n\n if (layout.composables) {\n createResourceLayoutExtras.makeComposable = createTopLevelMakeComposable();\n }\n\n const createResourceLayout = Object.assign(\n definedResourceLayout,\n createResourceLayoutExtras,\n ) as CreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\n const createResourceLinks = createResourceLinksFn(resources);\n\n return {\n createResourceConfig,\n createResourceLayout,\n createResourceLinks,\n } as DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n}\n\ntype DefineResourceLayoutForResourcesOptions<\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 ExtraResources extends ReadonlyArray<ResourceDefinition> = [],\n> = Omit<\n CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n 'resources'\n> & {\n /**\n * Additional resources to merge with those bound by\n * {@link defineResourceLayout.forResources}.\n */\n resources?: ExtraResources;\n};\n\ntype NonEmptyResourceDefinitions = readonly [\n ResourceDefinition,\n ...ResourceDefinition[],\n];\n\n/**\n * Factory returned by {@link DefineResourceLayout.forResources}.\n */\nexport type DefineResourceLayoutForResourcesFactory<\n BaseResources extends NonEmptyResourceDefinitions,\n> = <\n const ExtraResources extends ReadonlyArray<ResourceDefinition> = [],\n InProps extends InPropsDefinition<[...BaseResources, ...ExtraResources]> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n>(\n options: DefineResourceLayoutForResourcesOptions<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables,\n IncludeProps,\n CustomProps,\n ExtraResources\n >,\n) => DefinedResourceLayout<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n>;\n\n/**\n * Binds one or more resources, then accepts the remaining\n * {@link defineResourceLayout} options (with optional extra `resources`).\n */\nexport type DefineResourceLayoutForResources = <\n const Resources extends NonEmptyResourceDefinitions,\n>(\n ...resources: Resources\n) => DefineResourceLayoutForResourcesFactory<Resources>;\n\n/**\n * Creates a resource layout definition for a set of resources.\n */\nexport type DefineResourceLayoutFn = {\n <\n const Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n Resources,\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n >(\n options: CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n ): DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n};\n\nexport type DefineResourceLayout = DefineResourceLayoutFn & {\n forResources: DefineResourceLayoutForResources;\n};\n\nfunction defineResourceLayoutForResources<\n const Resources extends NonEmptyResourceDefinitions,\n>(\n ...baseResources: Resources\n): DefineResourceLayoutForResourcesFactory<Resources> {\n return ((options) => {\n const { resources: extraResources, ...rest } = options;\n const resources = extraResources\n ? [...baseResources, ...extraResources]\n : [...baseResources];\n\n return defineResourceLayoutImpl({\n ...rest,\n resources,\n } as never);\n }) as DefineResourceLayoutForResourcesFactory<Resources>;\n}\n\nexport const defineResourceLayout: DefineResourceLayout = Object.assign(\n defineResourceLayoutImpl as DefineResourceLayoutFn,\n {\n forResources: defineResourceLayoutForResources,\n },\n);\n"],"mappings":";;;;;;;;;;;;AAyGA,SAAS,sBACP,OACiC;CACjC,OAAO,OAAO,UAAU,cAAc,UAAU,QAAQ,gBAAgB;AAC1E;AAEA,SAAS,8BACP,OAC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;GACN,UAAU;GACV,MAAMF,8CAAW,OAAO,EAAE,QAAQ,aAAa;EACjD,CAAC,IACD,OAGN;EACA,MAAM,sBAAsB,OAAO,iFACN,OAAO,aAAa;GAC3C;GACA,MAAM;GACN;EACF,CAAC,IACD;EAEJ,KAAK,MAAM,EACT,OAAO,oGAC2B,mBAAmB,GACrD,OAAO,OAAO,iBAAiB,qBAAqB;EAGtD,OAAO;GACL,GAAG;GACH,GAAG,OAAO,OAAO;EACnB;CACF;CAEA,MAAM,EAAE,gCAAgC,gBAAgBG,uCAMtD;EACA,sBAAsB;EACtB;CACF,CAAC;CAgBD,MAAM,6BAgBF;EACF;EACA,cAjCmBC,gDAMnB;GACA,yBAAyB;GACzB,GAAI,OAAO,cACP,EAAE,4BAA4B,6BAA6B,IAC3D,CAAC;GACL,sBAAsB;GACtB;EACF,CAoBa;CACb;CAEA,IAAI,OAAO,aACT,2BAA2B,iBAAiB,6BAA6B;CAgB3E,OAAO;EACL;EACA,sBAf2B,OAAO,OAClC,uBACA,0BAamB;EACnB,qBAL0BC,oDAAsB,SAK9B;CACpB;AAOF;AA4GA,SAAS,iCAGP,GAAG,eACiD;CACpD,SAAS,YAAY;EACnB,MAAM,EAAE,WAAW,gBAAgB,GAAG,SAAS;EAC/C,MAAM,YAAY,iBACd,CAAC,GAAG,eAAe,GAAG,cAAc,IACpC,CAAC,GAAG,aAAa;EAErB,OAAO,yBAAyB;GAC9B,GAAG;GACH;EACF,CAAU;CACZ;AACF;AAEA,MAAa,uBAA6C,OAAO,OAC/D,0BACA,EACE,cAAc,iCAChB,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"define-layout.d.cts","names":[],"sources":["../../src/create-config/define-layout.tsx"],"mappings":";;;;;;;;;;;;KA2DY,kBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,uBACd,oBAAA,IAClB,aAAA,CAAc,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA;AAAA,KAE9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CAAA,uBACY,2BAAA,kCAEO,aAAA,CAAc,kBAAA,wBAC3B,iBAAA,KAAsB,aAAA,KAAkB,cAAA,6BACpC,oBAAA,kCACO,kBAAA,KACrB,aAAA,KAAkB,cAAA,GACtB,OAAA,EACA,WAAA,4BAEkB,aAAA,OAEpB,OAAA,EAAS,uCAAA,KACH,aAAA,KAAkB,cAAA,GACtB,OAAA,EACA,WAAA,EACA,YAAA,EACA,WAAA,EACA,cAAA,MAEC,qBAAA,KACC,aAAA,KAAkB,cAAA,GACtB,OAAA,EACA,WAAA,EACA,YAAA,EACA,WAAA;;;;AApuBI;KA2uBM,gCAAA,4BACc,2BAAA,KAErB,SAAA,EAAW,SAAA,KACX,uCAAA,CAAwC,SAAA;;;;KAKjC,sBAAA;EAAA,yBAEgB,aAAA,CAAc,kBAAA,mBACtB,iBAAA,CAAkB,SAAA,4BACd,oBAAA,kCACO,kBAAA,CACzB,SAAA,EACA,OAAA,EACA,WAAA,4BAEkB,aAAA,OAEpB,OAAA,EAAS,oBAAA,CACP,SAAA,EACA,OAAA,EACA,WAAA,EACA,YAAA,EACA,WAAA,IAED,qBAAA,CACD,SAAA,EACA,OAAA,EACA,WAAA,EACA,YAAA,EACA,WAAA;AAAA;AAAA,KAIQ,oBAAA,GAAuB,sBAAA;EACjC,YAAA,EAAc,gCAAgC;AAAA;AAAA,cAqBnC,oBAAA,EAAsB,oBAKlC"}
1
+ {"version":3,"file":"define-layout.d.mts","names":[],"sources":["../../src/create-config/define-layout.tsx"],"mappings":";;;;;;;;;;;;KA2DY,kBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,uBACd,oBAAA,IAClB,aAAA,CAAc,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA;AAAA,KAE9C,WAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,uBACd,oBAAA,uBACC,kBAAA,CAAmB,SAAA,EAAW,OAAA,EAAS,WAAA,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}
@@ -75,10 +75,14 @@ function defineResourceLayoutImpl(options) {
75
75
  name,
76
76
  capitalize
77
77
  };
78
+ const validationContext = {
79
+ layoutName: name,
80
+ resource: layoutContext.resource
81
+ };
78
82
  const resolvedComposables = composables ? resolveLayoutComposables(composables, layoutContext) : void 0;
79
83
  const mergedResolvedInProps = { ...resolvedInProps };
80
84
  for (const { props: presetPropDefinitions } of collectComposablePresetEntries(resolvedComposables)) Object.assign(mergedResolvedInProps, presetPropDefinitions);
81
- const composablePresetProps = resolveComposablePresetProps(resolvedComposables, layoutOptionProps);
85
+ const composablePresetProps = resolveComposablePresetProps(resolvedComposables, layoutOptionProps, validationContext);
82
86
  const mergedRenderContext = {
83
87
  composables: resolvedComposables,
84
88
  resource: layoutContext.resource,
@@ -86,7 +90,7 @@ function defineResourceLayoutImpl(options) {
86
90
  inProps: splitInProps
87
91
  };
88
92
  function Component(props) {
89
- const validatedProps = validateProps(resolvedLayoutProps, props);
93
+ const validatedProps = validateProps(resolvedLayoutProps, props, { ...validationContext });
90
94
  const includedPropKeys = Object.keys(includeLayoutProps ?? {});
91
95
  const includedPropDefinitions = pick(mergedResolvedInProps, includedPropKeys);
92
96
  const includedPropValues = { ...resolvePropDefinitionValues(includedPropDefinitions) };
@@ -102,7 +106,7 @@ function defineResourceLayoutImpl(options) {
102
106
  const validatedIncludedProps = validateProps({
103
107
  ...requiredIncludedPropDefinitions,
104
108
  ...optionalIncludedPropDefinitions
105
- }, includedPropValues);
109
+ }, includedPropValues, validationContext);
106
110
  const layoutRenderIncludedProps = Object.fromEntries(includedPropKeys.flatMap((key) => {
107
111
  if (!(key in validatedIncludedProps)) return [];
108
112
  return [[toLayoutRenderPropKey(key, mergedResolvedInProps[key]), validatedIncludedProps[key]]];
@@ -1 +1 @@
1
- {"version":3,"file":"define-layout.mjs","names":[],"sources":["../../src/create-config/define-layout.tsx"],"sourcesContent":["import type { JSX } from 'react';\nimport {\n type ComposableComponents,\n type ComposableNameContext,\n type ComposableResourceLayout,\n type CreateLayoutComposable,\n collectComposablePresetEntries,\n LayoutComposablePresetProvider,\n MakeComposable,\n makeComposable,\n MakeComposableOptions,\n RequiredPresetLayoutProps,\n resolveComposablePresetProps,\n resolveLayoutComposables,\n} from '@jfdevelops/react-layout-composables';\nimport {\n type AnyBuiltPropDefinition,\n createPrimitivePropBuilder,\n createProp,\n type ResolveLayoutProps,\n type ResolveProps,\n resolvePropDefinitionValues,\n validateProps,\n} from '@jfdevelops/react-layout-validator';\nimport {\n IncludedProps,\n InferredInProps,\n InPropsDefinition,\n InPropsObject,\n LayoutRenderProps,\n MergedLayoutInProps,\n} from '../props';\nimport {\n normalizeResources,\n toResourceEnum,\n type LayoutResourceKey,\n type ResourceDefinition,\n} from '../resource';\nimport { BaseComponent, functionalUpdate, pick, Show, Updater } from '../utils';\nimport { capitalize } from '../utils/capitalize';\nimport {\n type CreateResourceConfigFn,\n createResourceConfig,\n} from './get-component';\nimport {\n createResourceLinksFn,\n type CreateResourceLinksFn,\n} from './create-resource-links';\nimport {\n createForResource,\n type CreateLayoutForResource,\n type CreateResourceLayoutOptions,\n type CreateResourceLayoutOptionsBase,\n} from './for-resource';\nimport {\n createForResources,\n type CreateResourceLayoutForResourcesFn,\n} from './for-resources';\n\nexport type LayoutIncludeProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n> = IncludedProps<MergedLayoutInProps<Resources, Options, Composables>>;\n\nexport type LayoutProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n IncludeProps extends LayoutIncludeProps<Resources, Options, Composables> = {},\n CustomProps extends InPropsObject = {},\n> = {\n /**\n * Props to include in the layout.\n */\n include?: LayoutIncludeProps<Resources, Options, Composables> & IncludeProps;\n /**\n * Custom props that the layout will receive.\n */\n custom?: CustomProps;\n};\n\ntype LayoutRenderContext<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Composables extends ComposableComponents,\n> = {\n composables: LayoutRenderComposables<Composables>;\n inProps: Record<string, unknown>;\n resource: LayoutResourceKey<Resources>;\n name: string;\n};\ntype LayoutRenderComposables<Composables extends ComposableComponents> = [\n keyof Composables,\n] extends [never]\n ? undefined\n : Composables;\n\ntype SplitLayoutInPropDefinition<\n Props extends InPropsObject = {},\n Content = unknown,\n> = {\n props?: Props;\n render: ((props: ResolveProps<Props>) => Content) | Content;\n};\n\nfunction isBuiltPropDefinition(\n value: unknown,\n): value is AnyBuiltPropDefinition {\n return typeof value === 'function' && value !== null && 'visibility' in value;\n}\n\nfunction isSplitLayoutInPropDefinition(\n value: unknown,\n): value is SplitLayoutInPropDefinition {\n return (\n value !== null &&\n typeof value === 'object' &&\n 'render' in value &&\n (value as { render?: unknown }).render !== undefined\n );\n}\n\nfunction isJSXElementDefinition(\n definition: unknown,\n): definition is AnyBuiltPropDefinition & { type: 'JSX.Element' } {\n return (\n isBuiltPropDefinition(definition) &&\n 'type' in definition &&\n definition.type === 'JSX.Element'\n );\n}\n\nfunction toLayoutRenderPropKey(includeKey: string, definition: unknown) {\n return isJSXElementDefinition(definition)\n ? capitalize(includeKey)\n : includeKey;\n}\n\nfunction readLayoutOptionValue(\n includeKey: string,\n definition: unknown,\n sources: Record<string, unknown>,\n) {\n const layoutOptionKeys = isJSXElementDefinition(definition)\n ? [capitalize(includeKey), includeKey]\n : [includeKey, capitalize(includeKey)];\n\n for (const key of layoutOptionKeys) {\n if (key in sources) {\n return sources[key];\n }\n }\n\n return undefined;\n}\n\nfunction splitLayoutInProps(inProps: Record<string, unknown>) {\n const resolvedInProps: Record<string, AnyBuiltPropDefinition> = {};\n const splitInProps: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(inProps)) {\n if (isBuiltPropDefinition(value)) {\n resolvedInProps[key] = value;\n continue;\n }\n\n if (isSplitLayoutInPropDefinition(value)) {\n splitInProps[key] = value.render;\n\n if (value.props && typeof value.props === 'object') {\n Object.assign(resolvedInProps, value.props);\n }\n }\n }\n\n return {\n resolvedInProps,\n splitInProps,\n };\n}\n\nfunction resolveLayoutOptionDefaults(\n defaults: Record<string, unknown>,\n options: Record<string, unknown>,\n) {\n const resolved = { ...options };\n\n for (const [key, defaultValue] of Object.entries(defaults)) {\n if (key in options) {\n if (typeof defaultValue === 'function') {\n resolved[key] = options[key];\n } else {\n resolved[key] = functionalUpdate(\n defaultValue,\n options[key] as Updater<unknown>,\n );\n }\n }\n }\n\n return resolved;\n}\n\ntype CreateViewMapOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n IncludeProps extends LayoutIncludeProps<Resources, Options, Composables> = {},\n CustomProps extends InPropsObject = {},\n> = {\n /**\n * An array of valid resource names to support.\n */\n resources: Resources;\n /**\n * The options that are passed into the created resource layout.\n */\n options?: Options;\n layout: {\n /**\n * The props to pass to the layout.\n */\n props?: LayoutProps<\n Resources,\n Options,\n Composables,\n IncludeProps,\n CustomProps\n >;\n /**\n * Components used to compose the layout. Invoked per layout instance with\n * a scoped `create` that resolves composable `name` callbacks using the\n * layout's `resource` and `name`.\n */\n composables?: (\n create: CreateLayoutComposable<LayoutResourceKey<Resources>>,\n ) => Composables;\n /**\n * The render function for the layout.\n */\n render: (\n props: LayoutRenderProps<\n Resources,\n Options,\n Composables,\n IncludeProps,\n CustomProps\n >,\n context: LayoutRenderContext<Resources, Composables>,\n ) => JSX.Element;\n };\n};\n\ntype ResourceLayoutComposition<\n Name extends string,\n Composables extends ComposableComponents,\n> = [keyof Composables] extends [never]\n ? {}\n : {\n makeComposable: MakeComposable<Composables, Name>;\n };\nexport type ResourceLayoutComponent<\n Name extends string,\n Props extends InPropsObject = {},\n Composables extends ComposableComponents = {},\n Resource extends string = string,\n> = ResourceLayoutComposition<Name, Composables> &\n BaseComponent<Name, ResolveProps<Props>> & {\n (props: Show<ResolveProps<Props>>): JSX.Element;\n /**\n * A type-only property containing the resource associated with this\n * component. This property is `undefined` at runtime.\n */\n readonly resource: Resource;\n };\n\nexport type LayoutPropsForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents = {},\n> = ResolveLayoutProps<InferredInProps<Resources, InProps>> &\n RequiredPresetLayoutProps<Composables>;\n\ntype CreateResourceLayoutFnImpl<\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 Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n>(\n options: CreateResourceLayoutOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n) => ResourceLayoutComponent<Name, CustomProps, Composables, Resource>;\n\nexport type CreateResourceLayoutMakeComposableOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n> = CreateResourceLayoutOptionsBase<Resources, Name, Resource, Props> &\n Partial<LayoutPropsForResource<Resources, InProps, Composables>>;\n\ntype CreateResourceLayoutMakeComposableFn<\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 Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n>(\n options: CreateResourceLayoutMakeComposableOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n) => ComposableResourceLayout<Composables, Name, any, any, any>;\n\ntype CreateResourceLayoutFnBase<\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> = CreateResourceLayoutFnImpl<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> & {\n /**\n * A function to create a resource layout for a specific resource.\n */\n forResource: CreateLayoutForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n /**\n * Creates resource layout factories for multiple defined resources.\n */\n forResources: CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n};\n\ntype CreateResourceLayoutMakeComposableMember<\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> = [keyof Composables] extends [never]\n ? {}\n : {\n makeComposable: CreateResourceLayoutMakeComposableFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n };\n\nexport type CreateResourceLayoutFn<\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> = CreateResourceLayoutFnBase<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> &\n CreateResourceLayoutMakeComposableMember<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\ntype DefinedResourceLayout<\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 createResourceConfig: CreateResourceConfigFn<Resources>;\n createResourceLayout: CreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n createResourceLinks: CreateResourceLinksFn<Resources>;\n};\n\n\nfunction defineResourceLayoutImpl<\n const Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n Resources,\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n>(\n options: CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n): DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> {\n const { options: inProps = {} as InProps, resources, layout } = options;\n const normalizedResources = normalizeResources(resources);\n const resourcesEnum = createPrimitivePropBuilder('string').enum(\n toResourceEnum(normalizedResources),\n );\n const definedResourceLayout = (<\n Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n >(\n layoutOptions: CreateResourceLayoutOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n ) => {\n const {\n name,\n props: instancePropDefinitions,\n ...layoutOptionProps\n } = layoutOptions;\n const createComposableLayout =\n makeComposable<\n LayoutRenderProps<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >\n >();\n const nameProp = createProp.string().literal(name);\n const rawResolvedOptions =\n typeof inProps === 'function'\n ? inProps({\n resource: resourcesEnum,\n name: nameProp,\n })\n : inProps;\n const { resolvedInProps, splitInProps } = splitLayoutInProps({\n ...(rawResolvedOptions as Record<string, unknown>),\n ...(instancePropDefinitions as Record<string, unknown> | undefined),\n ...layoutOptionProps,\n });\n const { composables, render, props: layoutProps } = layout;\n const customLayoutProps = layoutProps?.custom;\n const includeLayoutProps = layoutProps?.include;\n const resolvedLayoutProps = {\n ...customLayoutProps,\n };\n const layoutContext: ComposableNameContext<\n LayoutResourceKey<Resources>,\n typeof name\n > = {\n resource: layoutOptions.resource,\n name,\n capitalize,\n };\n const resolvedComposables = composables\n ? resolveLayoutComposables(composables, layoutContext)\n : undefined;\n const mergedResolvedInProps = { ...resolvedInProps };\n\n for (const {\n props: presetPropDefinitions,\n } of collectComposablePresetEntries(resolvedComposables)) {\n Object.assign(mergedResolvedInProps, presetPropDefinitions);\n }\n\n const composablePresetProps = resolveComposablePresetProps(\n resolvedComposables,\n layoutOptionProps as Record<string, unknown>,\n );\n const mergedRenderContext = {\n composables: resolvedComposables as LayoutRenderComposables<Composables>,\n resource: layoutContext.resource,\n name: layoutContext.name,\n inProps: splitInProps,\n } as LayoutRenderContext<Resources, Composables>;\n\n function Component(props: Show<ResolveProps<CustomProps>>) {\n const validatedProps = validateProps(resolvedLayoutProps, props);\n const includedPropKeys = Object.keys(includeLayoutProps ?? {});\n const includedPropDefinitions = pick(\n mergedResolvedInProps,\n includedPropKeys,\n ) as Record<string, unknown>;\n const includedPropValues = {\n ...resolvePropDefinitionValues(includedPropDefinitions),\n } as Record<string, unknown>;\n\n for (const key of includedPropKeys) {\n const definition = mergedResolvedInProps[key];\n const layoutOptionValue = readLayoutOptionValue(\n key,\n definition,\n layoutOptionProps,\n );\n const splitValue = key in splitInProps ? splitInProps[key] : undefined;\n const value = layoutOptionValue ?? splitValue;\n\n if (value !== undefined) {\n includedPropValues[key] = value;\n }\n }\n\n const requiredIncludedPropDefinitions = Object.fromEntries(\n Object.entries(includedPropDefinitions).filter(\n ([key]) => includeLayoutProps?.[key] === true,\n ),\n );\n const optionalIncludedPropDefinitions = Object.fromEntries(\n Object.entries(includedPropDefinitions).filter(\n ([key]) =>\n includeLayoutProps?.[key] === 'optional' &&\n includedPropValues[key] !== undefined,\n ),\n );\n const validatedIncludedProps = validateProps(\n {\n ...requiredIncludedPropDefinitions,\n ...optionalIncludedPropDefinitions,\n } as Record<string, AnyBuiltPropDefinition>,\n includedPropValues,\n );\n const layoutRenderIncludedProps = Object.fromEntries(\n includedPropKeys.flatMap((key) => {\n if (!(key in validatedIncludedProps)) {\n return [];\n }\n\n return [\n [\n toLayoutRenderPropKey(key, mergedResolvedInProps[key]),\n validatedIncludedProps[\n key as keyof typeof validatedIncludedProps\n ],\n ],\n ];\n }),\n );\n const layoutRenderProps = {\n ...validatedProps,\n ...layoutRenderIncludedProps,\n } as unknown as LayoutRenderProps<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\n return (\n <LayoutComposablePresetProvider value={composablePresetProps}>\n {render(layoutRenderProps, mergedRenderContext)}\n </LayoutComposablePresetProvider>\n );\n }\n\n function createComposition<\n LayoutName extends string,\n const Defined extends MakeComposableOptions<Composables, LayoutName>,\n >(compositionOptions: Defined) {\n if (!compositionOptions.components) {\n return {} as ResourceLayoutComposition<LayoutName, Composables>;\n }\n\n return {\n makeComposable: createComposableLayout(\n compositionOptions,\n ) as MakeComposable<Composables, LayoutName>,\n };\n }\n\n return Object.assign(Component, {\n displayName: name,\n props: undefined as unknown as ResolveProps<CustomProps>,\n resource: undefined as unknown as Resource,\n ...createComposition({\n components: resolvedComposables as Composables | undefined,\n name,\n }),\n });\n }) as CreateResourceLayoutFnImpl<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n const createTopLevelMakeComposable = () => {\n return (options: Record<string, unknown>) => {\n const layout = definedResourceLayout(options as never);\n\n if (\n !('makeComposable' in layout) ||\n typeof layout.makeComposable !== 'function'\n ) {\n throw new Error(\n 'makeComposable requires composables to be defined in the layout',\n );\n }\n\n return layout.makeComposable();\n };\n };\n\n function getComponentPropDefinitions(resource: LayoutResourceKey<Resources>) {\n const componentName = 'ScopedResourceComponent';\n const rawResolvedOptions =\n typeof inProps === 'function'\n ? inProps({\n resource: resourcesEnum,\n name: createProp.string().literal(componentName),\n })\n : inProps;\n const { resolvedInProps } = splitLayoutInProps(\n rawResolvedOptions as Record<string, unknown>,\n );\n const resolvedComposables = layout.composables\n ? resolveLayoutComposables(layout.composables, {\n resource,\n name: componentName,\n capitalize,\n })\n : undefined;\n\n for (const {\n props: presetPropDefinitions,\n } of collectComposablePresetEntries(resolvedComposables)) {\n Object.assign(resolvedInProps, presetPropDefinitions);\n }\n\n return {\n ...resolvedInProps,\n ...layout.props?.custom,\n };\n }\n\n const { createLayoutForResourceBuilder, forResource } = createForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >({\n createResourceLayout: definedResourceLayout as never,\n resolveLayoutOptionDefaults,\n });\n const forResources = createForResources<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >({\n createLayoutForResource: createLayoutForResourceBuilder,\n ...(layout.composables\n ? { createMakeComposableLayout: createTopLevelMakeComposable }\n : {}),\n createResourceLayout: definedResourceLayout as never,\n getComponentPropDefinitions,\n });\n\n const createResourceLayoutExtras: {\n forResource: CreateLayoutForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n forResources: CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n makeComposable?: ReturnType<typeof createTopLevelMakeComposable>;\n } = {\n forResource,\n forResources,\n };\n\n if (layout.composables) {\n createResourceLayoutExtras.makeComposable = createTopLevelMakeComposable();\n }\n\n const createResourceLayout = Object.assign(\n definedResourceLayout,\n createResourceLayoutExtras,\n ) as CreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\n const createResourceLinks = createResourceLinksFn(resources);\n\n return {\n createResourceConfig,\n createResourceLayout,\n createResourceLinks,\n } as DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n}\n\ntype DefineResourceLayoutForResourcesOptions<\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 ExtraResources extends ReadonlyArray<ResourceDefinition> = [],\n> = Omit<\n CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n 'resources'\n> & {\n /**\n * Additional resources to merge with those bound by\n * {@link defineResourceLayout.forResources}.\n */\n resources?: ExtraResources;\n};\n\ntype NonEmptyResourceDefinitions = readonly [\n ResourceDefinition,\n ...ResourceDefinition[],\n];\n\n/**\n * Factory returned by {@link DefineResourceLayout.forResources}.\n */\nexport type DefineResourceLayoutForResourcesFactory<\n BaseResources extends NonEmptyResourceDefinitions,\n> = <\n const ExtraResources extends ReadonlyArray<ResourceDefinition> = [],\n InProps extends InPropsDefinition<[...BaseResources, ...ExtraResources]> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n>(\n options: DefineResourceLayoutForResourcesOptions<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables,\n IncludeProps,\n CustomProps,\n ExtraResources\n >,\n) => DefinedResourceLayout<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n>;\n\n/**\n * Binds one or more resources, then accepts the remaining\n * {@link defineResourceLayout} options (with optional extra `resources`).\n */\nexport type DefineResourceLayoutForResources = <\n const Resources extends NonEmptyResourceDefinitions,\n>(\n ...resources: Resources\n) => DefineResourceLayoutForResourcesFactory<Resources>;\n\n/**\n * Creates a resource layout definition for a set of resources.\n */\nexport type DefineResourceLayoutFn = {\n <\n const Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n Resources,\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n >(\n options: CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n ): DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n};\n\nexport type DefineResourceLayout = DefineResourceLayoutFn & {\n forResources: DefineResourceLayoutForResources;\n};\n\nfunction defineResourceLayoutForResources<\n const Resources extends NonEmptyResourceDefinitions,\n>(\n ...baseResources: Resources\n): DefineResourceLayoutForResourcesFactory<Resources> {\n return ((options) => {\n const { resources: extraResources, ...rest } = options;\n const resources = extraResources\n ? [...baseResources, ...extraResources]\n : [...baseResources];\n\n return defineResourceLayoutImpl({\n ...rest,\n resources,\n } as never);\n }) as DefineResourceLayoutForResourcesFactory<Resources>;\n}\n\nexport const defineResourceLayout: DefineResourceLayout = Object.assign(\n defineResourceLayoutImpl as DefineResourceLayoutFn,\n {\n forResources: defineResourceLayoutForResources,\n },\n);\n"],"mappings":";;;;;;;;;;;;AAyGA,SAAS,sBACP,OACiC;CACjC,OAAO,OAAO,UAAU,cAAc,UAAU,QAAQ,gBAAgB;AAC1E;AAEA,SAAS,8BACP,OACsC;CACtC,OACE,UAAU,QACV,OAAO,UAAU,YACjB,YAAY,SACX,MAA+B,WAAW;AAE/C;AAEA,SAAS,uBACP,YACgE;CAChE,OACE,sBAAsB,UAAU,KAChC,UAAU,cACV,WAAW,SAAS;AAExB;AAEA,SAAS,sBAAsB,YAAoB,YAAqB;CACtE,OAAO,uBAAuB,UAAU,IACpC,WAAW,UAAU,IACrB;AACN;AAEA,SAAS,sBACP,YACA,YACA,SACA;CACA,MAAM,mBAAmB,uBAAuB,UAAU,IACtD,CAAC,WAAW,UAAU,GAAG,UAAU,IACnC,CAAC,YAAY,WAAW,UAAU,CAAC;CAEvC,KAAK,MAAM,OAAO,kBAChB,IAAI,OAAO,SACT,OAAO,QAAQ;AAKrB;AAEA,SAAS,mBAAmB,SAAkC;CAC5D,MAAM,kBAA0D,CAAC;CACjE,MAAM,eAAwC,CAAC;CAE/C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,GAAG;EAClD,IAAI,sBAAsB,KAAK,GAAG;GAChC,gBAAgB,OAAO;GACvB;EACF;EAEA,IAAI,8BAA8B,KAAK,GAAG;GACxC,aAAa,OAAO,MAAM;GAE1B,IAAI,MAAM,SAAS,OAAO,MAAM,UAAU,UACxC,OAAO,OAAO,iBAAiB,MAAM,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,IACpC,CAAC,GAAG,aAAa;EAErB,OAAO,yBAAyB;GAC9B,GAAG;GACH;EACF,CAAU;CACZ;AACF;AAEA,MAAa,uBAA6C,OAAO,OAC/D,0BACA,EACE,cAAc,iCAChB,CACF"}
1
+ {"version":3,"file":"define-layout.mjs","names":[],"sources":["../../src/create-config/define-layout.tsx"],"sourcesContent":["import type { JSX } from 'react';\nimport {\n type ComposableComponents,\n type ComposableNameContext,\n type ComposableResourceLayout,\n type CreateLayoutComposable,\n collectComposablePresetEntries,\n LayoutComposablePresetProvider,\n MakeComposable,\n makeComposable,\n MakeComposableOptions,\n RequiredPresetLayoutProps,\n resolveComposablePresetProps,\n resolveLayoutComposables,\n} from '@jfdevelops/react-layout-composables';\nimport {\n type AnyBuiltPropDefinition,\n createPrimitivePropBuilder,\n createProp,\n type ResolveLayoutProps,\n type ResolveProps,\n resolvePropDefinitionValues,\n validateProps,\n} from '@jfdevelops/react-layout-validator';\nimport {\n IncludedProps,\n InferredInProps,\n InPropsDefinition,\n InPropsObject,\n LayoutRenderProps,\n MergedLayoutInProps,\n} from '../props';\nimport {\n normalizeResources,\n toResourceEnum,\n type LayoutResourceKey,\n type ResourceDefinition,\n} from '../resource';\nimport { BaseComponent, functionalUpdate, pick, Show, Updater } from '../utils';\nimport { capitalize } from '../utils/capitalize';\nimport {\n type CreateResourceConfigFn,\n createResourceConfig,\n} from './get-component';\nimport {\n createResourceLinksFn,\n type CreateResourceLinksFn,\n} from './create-resource-links';\nimport {\n createForResource,\n type CreateLayoutForResource,\n type CreateResourceLayoutOptions,\n type CreateResourceLayoutOptionsBase,\n} from './for-resource';\nimport {\n createForResources,\n type CreateResourceLayoutForResourcesFn,\n} from './for-resources';\n\nexport type LayoutIncludeProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n> = IncludedProps<MergedLayoutInProps<Resources, Options, Composables>>;\n\nexport type LayoutProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n IncludeProps extends LayoutIncludeProps<Resources, Options, Composables> = {},\n CustomProps extends InPropsObject = {},\n> = {\n /**\n * Props to include in the layout.\n */\n include?: LayoutIncludeProps<Resources, Options, Composables> & IncludeProps;\n /**\n * Custom props that the layout will receive.\n */\n custom?: CustomProps;\n};\n\ntype LayoutRenderContext<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Composables extends ComposableComponents,\n> = {\n composables: LayoutRenderComposables<Composables>;\n inProps: Record<string, unknown>;\n resource: LayoutResourceKey<Resources>;\n name: string;\n};\ntype LayoutRenderComposables<Composables extends ComposableComponents> = [\n keyof Composables,\n] extends [never]\n ? undefined\n : Composables;\n\ntype SplitLayoutInPropDefinition<\n Props extends InPropsObject = {},\n Content = unknown,\n> = {\n props?: Props;\n render: ((props: ResolveProps<Props>) => Content) | Content;\n};\n\nfunction isBuiltPropDefinition(\n value: unknown,\n): value is AnyBuiltPropDefinition {\n return typeof value === 'function' && value !== null && 'visibility' in value;\n}\n\nfunction isSplitLayoutInPropDefinition(\n value: unknown,\n): value is SplitLayoutInPropDefinition {\n return (\n value !== null &&\n typeof value === 'object' &&\n 'render' in value &&\n (value as { render?: unknown }).render !== undefined\n );\n}\n\nfunction isJSXElementDefinition(\n definition: unknown,\n): definition is AnyBuiltPropDefinition & { type: 'JSX.Element' } {\n return (\n isBuiltPropDefinition(definition) &&\n 'type' in definition &&\n definition.type === 'JSX.Element'\n );\n}\n\nfunction toLayoutRenderPropKey(includeKey: string, definition: unknown) {\n return isJSXElementDefinition(definition)\n ? capitalize(includeKey)\n : includeKey;\n}\n\nfunction readLayoutOptionValue(\n includeKey: string,\n definition: unknown,\n sources: Record<string, unknown>,\n) {\n const layoutOptionKeys = isJSXElementDefinition(definition)\n ? [capitalize(includeKey), includeKey]\n : [includeKey, capitalize(includeKey)];\n\n for (const key of layoutOptionKeys) {\n if (key in sources) {\n return sources[key];\n }\n }\n\n return undefined;\n}\n\nfunction splitLayoutInProps(inProps: Record<string, unknown>) {\n const resolvedInProps: Record<string, AnyBuiltPropDefinition> = {};\n const splitInProps: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(inProps)) {\n if (isBuiltPropDefinition(value)) {\n resolvedInProps[key] = value;\n continue;\n }\n\n if (isSplitLayoutInPropDefinition(value)) {\n splitInProps[key] = value.render;\n\n if (value.props && typeof value.props === 'object') {\n Object.assign(resolvedInProps, value.props);\n }\n }\n }\n\n return {\n resolvedInProps,\n splitInProps,\n };\n}\n\nfunction resolveLayoutOptionDefaults(\n defaults: Record<string, unknown>,\n options: Record<string, unknown>,\n) {\n const resolved = { ...options };\n\n for (const [key, defaultValue] of Object.entries(defaults)) {\n if (key in options) {\n if (typeof defaultValue === 'function') {\n resolved[key] = options[key];\n } else {\n resolved[key] = functionalUpdate(\n defaultValue,\n options[key] as Updater<unknown>,\n );\n }\n }\n }\n\n return resolved;\n}\n\ntype CreateViewMapOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Options extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n IncludeProps extends LayoutIncludeProps<Resources, Options, Composables> = {},\n CustomProps extends InPropsObject = {},\n> = {\n /**\n * An array of valid resource names to support.\n */\n resources: Resources;\n /**\n * The options that are passed into the created resource layout.\n */\n options?: Options;\n layout: {\n /**\n * The props to pass to the layout.\n */\n props?: LayoutProps<\n Resources,\n Options,\n Composables,\n IncludeProps,\n CustomProps\n >;\n /**\n * Components used to compose the layout. Invoked per layout instance with\n * a scoped `create` that resolves composable `name` callbacks using the\n * layout's `resource` and `name`.\n */\n composables?: (\n create: CreateLayoutComposable<LayoutResourceKey<Resources>>,\n ) => Composables;\n /**\n * The render function for the layout.\n */\n render: (\n props: LayoutRenderProps<\n Resources,\n Options,\n Composables,\n IncludeProps,\n CustomProps\n >,\n context: LayoutRenderContext<Resources, Composables>,\n ) => JSX.Element;\n };\n};\n\ntype ResourceLayoutComposition<\n Name extends string,\n Composables extends ComposableComponents,\n> = [keyof Composables] extends [never]\n ? {}\n : {\n makeComposable: MakeComposable<Composables, Name>;\n };\nexport type ResourceLayoutComponent<\n Name extends string,\n Props extends InPropsObject = {},\n Composables extends ComposableComponents = {},\n Resource extends string = string,\n> = ResourceLayoutComposition<Name, Composables> &\n BaseComponent<Name, ResolveProps<Props>> & {\n (props: Show<ResolveProps<Props>>): JSX.Element;\n /**\n * A type-only property containing the resource associated with this\n * component. This property is `undefined` at runtime.\n */\n readonly resource: Resource;\n };\n\nexport type LayoutPropsForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents = {},\n> = ResolveLayoutProps<InferredInProps<Resources, InProps>> &\n RequiredPresetLayoutProps<Composables>;\n\ntype CreateResourceLayoutFnImpl<\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 Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n>(\n options: CreateResourceLayoutOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n) => ResourceLayoutComponent<Name, CustomProps, Composables, Resource>;\n\nexport type CreateResourceLayoutMakeComposableOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n> = CreateResourceLayoutOptionsBase<Resources, Name, Resource, Props> &\n Partial<LayoutPropsForResource<Resources, InProps, Composables>>;\n\ntype CreateResourceLayoutMakeComposableFn<\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 Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n>(\n options: CreateResourceLayoutMakeComposableOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n) => ComposableResourceLayout<Composables, Name, any, any, any>;\n\ntype CreateResourceLayoutFnBase<\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> = CreateResourceLayoutFnImpl<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> & {\n /**\n * A function to create a resource layout for a specific resource.\n */\n forResource: CreateLayoutForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n /**\n * Creates resource layout factories for multiple defined resources.\n */\n forResources: CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n};\n\ntype CreateResourceLayoutMakeComposableMember<\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> = [keyof Composables] extends [never]\n ? {}\n : {\n makeComposable: CreateResourceLayoutMakeComposableFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n };\n\nexport type CreateResourceLayoutFn<\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> = CreateResourceLayoutFnBase<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> &\n CreateResourceLayoutMakeComposableMember<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\ntype DefinedResourceLayout<\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 createResourceConfig: CreateResourceConfigFn<Resources>;\n createResourceLayout: CreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n createResourceLinks: CreateResourceLinksFn<Resources>;\n};\n\n\nfunction defineResourceLayoutImpl<\n const Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n Resources,\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n>(\n options: CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n): DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n> {\n const { options: inProps = {} as InProps, resources, layout } = options;\n const normalizedResources = normalizeResources(resources);\n const resourcesEnum = createPrimitivePropBuilder('string').enum(\n toResourceEnum(normalizedResources),\n );\n const definedResourceLayout = (<\n Name extends string,\n Resource extends LayoutResourceKey<Resources>,\n Props extends InPropsObject = {},\n >(\n layoutOptions: CreateResourceLayoutOptions<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n Props\n >,\n ) => {\n const {\n name,\n props: instancePropDefinitions,\n ...layoutOptionProps\n } = layoutOptions;\n const createComposableLayout =\n makeComposable<\n LayoutRenderProps<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >\n >();\n const nameProp = createProp.string().literal(name);\n const rawResolvedOptions =\n typeof inProps === 'function'\n ? inProps({\n resource: resourcesEnum,\n name: nameProp,\n })\n : inProps;\n const { resolvedInProps, splitInProps } = splitLayoutInProps({\n ...(rawResolvedOptions as Record<string, unknown>),\n ...(instancePropDefinitions as Record<string, unknown> | undefined),\n ...layoutOptionProps,\n });\n const { composables, render, props: layoutProps } = layout;\n const customLayoutProps = layoutProps?.custom;\n const includeLayoutProps = layoutProps?.include;\n const resolvedLayoutProps = {\n ...customLayoutProps,\n };\n const layoutContext: ComposableNameContext<\n LayoutResourceKey<Resources>,\n typeof name\n > = {\n resource: layoutOptions.resource,\n name,\n capitalize,\n };\n const validationContext = {\n layoutName: name,\n resource: layoutContext.resource,\n };\n const resolvedComposables = composables\n ? resolveLayoutComposables(composables, layoutContext)\n : undefined;\n const mergedResolvedInProps = { ...resolvedInProps };\n\n for (const {\n props: presetPropDefinitions,\n } of collectComposablePresetEntries(resolvedComposables)) {\n Object.assign(mergedResolvedInProps, presetPropDefinitions);\n }\n\n const composablePresetProps = resolveComposablePresetProps(\n resolvedComposables,\n layoutOptionProps as Record<string, unknown>,\n validationContext,\n );\n const mergedRenderContext = {\n composables: resolvedComposables as LayoutRenderComposables<Composables>,\n resource: layoutContext.resource,\n name: layoutContext.name,\n inProps: splitInProps,\n } as LayoutRenderContext<Resources, Composables>;\n\n function Component(props: Show<ResolveProps<CustomProps>>) {\n const validatedProps = validateProps(resolvedLayoutProps, props, {\n ...validationContext,\n });\n const includedPropKeys = Object.keys(includeLayoutProps ?? {});\n const includedPropDefinitions = pick(\n mergedResolvedInProps,\n includedPropKeys,\n ) as Record<string, unknown>;\n const includedPropValues = {\n ...resolvePropDefinitionValues(includedPropDefinitions),\n } as Record<string, unknown>;\n\n for (const key of includedPropKeys) {\n const definition = mergedResolvedInProps[key];\n const layoutOptionValue = readLayoutOptionValue(\n key,\n definition,\n layoutOptionProps,\n );\n const splitValue = key in splitInProps ? splitInProps[key] : undefined;\n const value = layoutOptionValue ?? splitValue;\n\n if (value !== undefined) {\n includedPropValues[key] = value;\n }\n }\n\n const requiredIncludedPropDefinitions = Object.fromEntries(\n Object.entries(includedPropDefinitions).filter(\n ([key]) => includeLayoutProps?.[key] === true,\n ),\n );\n const optionalIncludedPropDefinitions = Object.fromEntries(\n Object.entries(includedPropDefinitions).filter(\n ([key]) =>\n includeLayoutProps?.[key] === 'optional' &&\n includedPropValues[key] !== undefined,\n ),\n );\n const validatedIncludedProps = validateProps(\n {\n ...requiredIncludedPropDefinitions,\n ...optionalIncludedPropDefinitions,\n } as Record<string, AnyBuiltPropDefinition>,\n includedPropValues,\n validationContext,\n );\n const layoutRenderIncludedProps = Object.fromEntries(\n includedPropKeys.flatMap((key) => {\n if (!(key in validatedIncludedProps)) {\n return [];\n }\n\n return [\n [\n toLayoutRenderPropKey(key, mergedResolvedInProps[key]),\n validatedIncludedProps[\n key as keyof typeof validatedIncludedProps\n ],\n ],\n ];\n }),\n );\n const layoutRenderProps = {\n ...validatedProps,\n ...layoutRenderIncludedProps,\n } as unknown as LayoutRenderProps<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\n return (\n <LayoutComposablePresetProvider value={composablePresetProps}>\n {render(layoutRenderProps, mergedRenderContext)}\n </LayoutComposablePresetProvider>\n );\n }\n\n function createComposition<\n LayoutName extends string,\n const Defined extends MakeComposableOptions<Composables, LayoutName>,\n >(compositionOptions: Defined) {\n if (!compositionOptions.components) {\n return {} as ResourceLayoutComposition<LayoutName, Composables>;\n }\n\n return {\n makeComposable: createComposableLayout(\n compositionOptions,\n ) as MakeComposable<Composables, LayoutName>,\n };\n }\n\n return Object.assign(Component, {\n displayName: name,\n props: undefined as unknown as ResolveProps<CustomProps>,\n resource: undefined as unknown as Resource,\n ...createComposition({\n components: resolvedComposables as Composables | undefined,\n name,\n }),\n });\n }) as CreateResourceLayoutFnImpl<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n const createTopLevelMakeComposable = () => {\n return (options: Record<string, unknown>) => {\n const layout = definedResourceLayout(options as never);\n\n if (\n !('makeComposable' in layout) ||\n typeof layout.makeComposable !== 'function'\n ) {\n throw new Error(\n 'makeComposable requires composables to be defined in the layout',\n );\n }\n\n return layout.makeComposable();\n };\n };\n\n function getComponentPropDefinitions(resource: LayoutResourceKey<Resources>) {\n const componentName = 'ScopedResourceComponent';\n const rawResolvedOptions =\n typeof inProps === 'function'\n ? inProps({\n resource: resourcesEnum,\n name: createProp.string().literal(componentName),\n })\n : inProps;\n const { resolvedInProps } = splitLayoutInProps(\n rawResolvedOptions as Record<string, unknown>,\n );\n const resolvedComposables = layout.composables\n ? resolveLayoutComposables(layout.composables, {\n resource,\n name: componentName,\n capitalize,\n })\n : undefined;\n\n for (const {\n props: presetPropDefinitions,\n } of collectComposablePresetEntries(resolvedComposables)) {\n Object.assign(resolvedInProps, presetPropDefinitions);\n }\n\n return {\n ...resolvedInProps,\n ...layout.props?.custom,\n };\n }\n\n const { createLayoutForResourceBuilder, forResource } = createForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >({\n createResourceLayout: definedResourceLayout as never,\n resolveLayoutOptionDefaults,\n });\n const forResources = createForResources<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >({\n createLayoutForResource: createLayoutForResourceBuilder,\n ...(layout.composables\n ? { createMakeComposableLayout: createTopLevelMakeComposable }\n : {}),\n createResourceLayout: definedResourceLayout as never,\n getComponentPropDefinitions,\n });\n\n const createResourceLayoutExtras: {\n forResource: CreateLayoutForResource<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n forResources: CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n makeComposable?: ReturnType<typeof createTopLevelMakeComposable>;\n } = {\n forResource,\n forResources,\n };\n\n if (layout.composables) {\n createResourceLayoutExtras.makeComposable = createTopLevelMakeComposable();\n }\n\n const createResourceLayout = Object.assign(\n definedResourceLayout,\n createResourceLayoutExtras,\n ) as CreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n\n const createResourceLinks = createResourceLinksFn(resources);\n\n return {\n createResourceConfig,\n createResourceLayout,\n createResourceLinks,\n } as DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n}\n\ntype DefineResourceLayoutForResourcesOptions<\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 ExtraResources extends ReadonlyArray<ResourceDefinition> = [],\n> = Omit<\n CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n 'resources'\n> & {\n /**\n * Additional resources to merge with those bound by\n * {@link defineResourceLayout.forResources}.\n */\n resources?: ExtraResources;\n};\n\ntype NonEmptyResourceDefinitions = readonly [\n ResourceDefinition,\n ...ResourceDefinition[],\n];\n\n/**\n * Factory returned by {@link DefineResourceLayout.forResources}.\n */\nexport type DefineResourceLayoutForResourcesFactory<\n BaseResources extends NonEmptyResourceDefinitions,\n> = <\n const ExtraResources extends ReadonlyArray<ResourceDefinition> = [],\n InProps extends InPropsDefinition<[...BaseResources, ...ExtraResources]> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n>(\n options: DefineResourceLayoutForResourcesOptions<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables,\n IncludeProps,\n CustomProps,\n ExtraResources\n >,\n) => DefinedResourceLayout<\n [...BaseResources, ...ExtraResources],\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n>;\n\n/**\n * Binds one or more resources, then accepts the remaining\n * {@link defineResourceLayout} options (with optional extra `resources`).\n */\nexport type DefineResourceLayoutForResources = <\n const Resources extends NonEmptyResourceDefinitions,\n>(\n ...resources: Resources\n) => DefineResourceLayoutForResourcesFactory<Resources>;\n\n/**\n * Creates a resource layout definition for a set of resources.\n */\nexport type DefineResourceLayoutFn = {\n <\n const Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources> = {},\n Composables extends ComposableComponents = {},\n const IncludeProps extends LayoutIncludeProps<\n Resources,\n InProps,\n Composables\n > = {},\n CustomProps extends InPropsObject = {},\n >(\n options: CreateViewMapOptions<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >,\n ): DefinedResourceLayout<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n};\n\nexport type DefineResourceLayout = DefineResourceLayoutFn & {\n forResources: DefineResourceLayoutForResources;\n};\n\nfunction defineResourceLayoutForResources<\n const Resources extends NonEmptyResourceDefinitions,\n>(\n ...baseResources: Resources\n): DefineResourceLayoutForResourcesFactory<Resources> {\n return ((options) => {\n const { resources: extraResources, ...rest } = options;\n const resources = extraResources\n ? [...baseResources, ...extraResources]\n : [...baseResources];\n\n return defineResourceLayoutImpl({\n ...rest,\n resources,\n } as never);\n }) as DefineResourceLayoutForResourcesFactory<Resources>;\n}\n\nexport const defineResourceLayout: DefineResourceLayout = Object.assign(\n defineResourceLayoutImpl as DefineResourceLayoutFn,\n {\n forResources: defineResourceLayoutForResources,\n },\n);\n"],"mappings":";;;;;;;;;;;;AAyGA,SAAS,sBACP,OACiC;CACjC,OAAO,OAAO,UAAU,cAAc,UAAU,QAAQ,gBAAgB;AAC1E;AAEA,SAAS,8BACP,OACsC;CACtC,OACE,UAAU,QACV,OAAO,UAAU,YACjB,YAAY,SACX,MAA+B,WAAW;AAE/C;AAEA,SAAS,uBACP,YACgE;CAChE,OACE,sBAAsB,UAAU,KAChC,UAAU,cACV,WAAW,SAAS;AAExB;AAEA,SAAS,sBAAsB,YAAoB,YAAqB;CACtE,OAAO,uBAAuB,UAAU,IACpC,WAAW,UAAU,IACrB;AACN;AAEA,SAAS,sBACP,YACA,YACA,SACA;CACA,MAAM,mBAAmB,uBAAuB,UAAU,IACtD,CAAC,WAAW,UAAU,GAAG,UAAU,IACnC,CAAC,YAAY,WAAW,UAAU,CAAC;CAEvC,KAAK,MAAM,OAAO,kBAChB,IAAI,OAAO,SACT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AgBD,MAAM,6BAgBF;EACF;EACA,cAjCmB,mBAMnB;GACA,yBAAyB;GACzB,GAAI,OAAO,cACP,EAAE,4BAA4B,6BAA6B,IAC3D,CAAC;GACL,sBAAsB;GACtB;EACF,CAoBa;CACb;CAEA,IAAI,OAAO,aACT,2BAA2B,iBAAiB,6BAA6B;CAgB3E,OAAO;EACL;EACA,sBAf2B,OAAO,OAClC,uBACA,0BAamB;EACnB,qBAL0B,sBAAsB,SAK9B;CACpB;AAOF;AA4GA,SAAS,iCAGP,GAAG,eACiD;CACpD,SAAS,YAAY;EACnB,MAAM,EAAE,WAAW,gBAAgB,GAAG,SAAS;EAC/C,MAAM,YAAY,iBACd,CAAC,GAAG,eAAe,GAAG,cAAc,IACpC,CAAC,GAAG,aAAa;EAErB,OAAO,yBAAyB;GAC9B,GAAG;GACH;EACF,CAAU;CACZ;AACF;AAEA,MAAa,uBAA6C,OAAO,OAC/D,0BACA,EACE,cAAc,iCAChB,CACF"}
@@ -66,7 +66,10 @@ function createForResources({ createLayoutForResource, createMakeComposableLayou
66
66
  if (componentProps === void 0) throw new Error(`Scoped component "${name}" must be rendered inside its scoped component`);
67
67
  const resolvedOwnProps = ownProps ?? {};
68
68
  cachedOwnProps = resolvedOwnProps;
69
- (0, _jfdevelops_react_layout_validator.validateProps)(ownPropDefinitions, resolvedOwnProps);
69
+ (0, _jfdevelops_react_layout_validator.validateProps)(ownPropDefinitions, resolvedOwnProps, {
70
+ layoutName: entry.name ?? defaultNames.get(resource) ?? require_capitalize.capitalize(resource),
71
+ resource
72
+ });
70
73
  const result = definition.render({
71
74
  ...componentProps,
72
75
  ...resolvedOwnProps,
@@ -152,7 +155,10 @@ function createForResources({ createLayoutForResource, createMakeComposableLayou
152
155
  if (key === "children" || key === "resource") continue;
153
156
  definitionsToValidate[key] = definition;
154
157
  }
155
- (0, _jfdevelops_react_layout_validator.validateProps)(definitionsToValidate, componentProps);
158
+ (0, _jfdevelops_react_layout_validator.validateProps)(definitionsToValidate, componentProps, {
159
+ layoutName: definedEntries.get(componentResource)?.name ?? defaultNames.get(componentResource) ?? require_capitalize.capitalize(componentResource),
160
+ resource: componentResource
161
+ });
156
162
  return (0, react.createElement)(componentPropsContext.Provider, { value: componentProps }, require_scoped_render.resolveScopedRenderResult(componentOptions.render(componentProps, renderContext), componentProps));
157
163
  }
158
164
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"create-for-resources.cjs","names":["capitalize","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 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 components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n function createComponent(componentOptions: {\n props?: {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n };\n resources?: Record<string, ScopedComponentEntry>;\n render: (\n props: Record<string, unknown>,\n context: Record<string, (props: never) => JSX.Element>,\n ) => ScopedRenderResult;\n }) {\n const include = componentOptions.props?.include ?? {};\n const custom = componentOptions.props?.custom ?? {};\n const selectedResources = new Set(\n resourceOptions.map(({ resource }) => resource),\n );\n const componentPropsContext = createContext<\n Record<string, unknown> | undefined\n >(undefined);\n const definedEntries = new Map<\n LayoutResourceKey<Resources>,\n ScopedComponentEntry\n >();\n\n for (const [key, entry] of Object.entries(\n componentOptions.resources ?? {},\n )) {\n const resource = key as LayoutResourceKey<Resources>;\n\n if (!selectedResources.has(resource)) {\n throw new Error(\n `Resource \"${key}\" is not available in this scoped component`,\n );\n }\n\n definedEntries.set(resource, entry);\n }\n\n /** Resolved scoped components, per resource. */\n const resourceScopedComponents = new Map<\n LayoutResourceKey<Resources>,\n Record<string, (props?: never) => JSX.Element>\n >();\n const contextResources = new Map<string, LayoutResourceKey<Resources>>();\n const renderContext: Record<string, (props: never) => JSX.Element> =\n Object.fromEntries(\n [...definedEntries].map(([resource, entry]) => {\n const contextKey = capitalize(resource);\n\n if (contextKey === 'Root') {\n throw new Error(\n `Resource \"${resource}\" maps to the reserved render context key \"Root\"`,\n );\n }\n\n const existingResource = contextResources.get(contextKey);\n\n if (existingResource !== undefined) {\n throw new Error(\n `Resources \"${existingResource}\" and \"${resource}\" both map to render context key \"${contextKey}\"`,\n );\n }\n\n contextResources.set(contextKey, resource);\n\n /**\n * Built once per resource so every scoped component keeps a stable\n * identity, and shared by the resource render, the render context,\n * and any component bound through `asHOF()`.\n */\n const scopedComponents: Record<\n string,\n (props?: never) => JSX.Element\n > = {};\n\n for (const [name, definition] of Object.entries(\n entry.components ?? {},\n )) {\n if (reservedScopedComponentNames.has(name)) {\n throw new Error(\n `Scoped component \"${name}\" for resource \"${resource}\" uses a reserved name`,\n );\n }\n\n const ownPropDefinitions = definition.props ?? {};\n // 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 Error(\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\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 Error(\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 Error(\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 Error(\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 Error(\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 Error(\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 Error(\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\n for (const key of Object.keys(availableDefinitions)) {\n if (key in componentProps) {\n layoutOptions[key] = componentProps[key];\n }\n\n const capitalized = capitalize(key);\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 return createElement(root, 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 Error(\n `Resource \"${componentResource}\" is not available in this scoped component`,\n );\n }\n\n const availableDefinitions =\n getComponentPropDefinitions(componentResource);\n const definitionsToValidate: Record<string, AnyBuiltPropDefinition> =\n {};\n\n for (const [key, inclusion] of Object.entries(include)) {\n const definition = availableDefinitions[key];\n\n if (!definition) {\n continue;\n }\n\n // Keep declared keys as-is — do not capitalize JSX.Element props.\n if (inclusion === true || key in componentProps) {\n definitionsToValidate[key] = definition;\n }\n }\n\n for (const [key, definition] of Object.entries(custom)) {\n if (key === 'children' || key === 'resource') {\n continue;\n }\n\n definitionsToValidate[key] = definition;\n }\n\n validateProps(definitionsToValidate, componentProps);\n\n // 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: componentProps },\n resolveScopedRenderResult(\n componentOptions.render(componentProps, renderContext),\n componentProps,\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 Error(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n let boundComponent = boundComponents.get(resource);\n\n if (boundComponent === undefined) {\n boundComponent = Object.assign(\n (boundProps: Record<string, unknown>) =>\n createElement(Component, { ...boundProps, resource }),\n {\n displayName: `ScopedResourceComponent(${resource})`,\n props: undefined,\n resource: undefined,\n },\n resourceScopedComponents.get(resource) ?? {},\n );\n boundComponents.set(resource, boundComponent);\n }\n\n return boundComponent;\n }\n\n function asHOF() {\n return bindResource;\n }\n\n return Object.assign(Component, {\n asHOF,\n displayName: 'ScopedResourceComponent',\n props: undefined,\n });\n }\n\n type CreateComponentPropsBag = {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n };\n\n const createResourceComponentExtras = new WeakMap<\n object,\n CreateComponentPropsBag\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\n return { include, custom };\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 const fromEntries = mergeCreateComponentProps(\n ...Object.values(componentOptions.resources ?? {}).map(\n (entry) => createResourceComponentExtras.get(entry),\n ),\n );\n\n return createComponent({\n ...componentOptions,\n props: mergeCreateComponentProps(\n baseProps,\n fromEntries,\n componentOptions.props,\n ),\n });\n }\n\n createWithProps.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 Error(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n if (props !== undefined) {\n createResourceComponentExtras.set(entry, props);\n }\n\n return entry;\n };\n\n return createWithProps;\n }\n\n Object.assign(createComponent, {\n setProps: createComponentSetProps,\n });\n\n const scopedExtras: {\n createComponent: typeof createComponent;\n forResource: typeof scopedForResource;\n makeComposable?: (options: Record<string, unknown>) => unknown;\n resources: undefined;\n } = {\n createComponent,\n forResource: scopedForResource,\n resources: undefined,\n };\n\n if (createMakeComposableLayout) {\n const makeComposableLayout = createMakeComposableLayout();\n\n scopedExtras.makeComposable = (options) => {\n const resource = options.resource as LayoutResourceKey<Resources>;\n\n return makeComposableLayout({\n ...options,\n name: options.name ?? defaultNames.get(resource),\n });\n };\n }\n\n return Object.assign(scopedCreateResourceLayout, scopedExtras);\n }) as unknown as CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n}\n"],"mappings":";;;;;;AA6CA,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;GAO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GAAG,MACsB;GACzB,MAAM,UAA6C,CAAC;GACpD,MAAM,SAAiD,CAAC;GAExD,KAAK,MAAM,OAAO,MAAM;IACtB,OAAO,OAAO,SAAS,KAAK,OAAO;IACnC,OAAO,OAAO,QAAQ,KAAK,MAAM;GACnC;GAEA,OAAO;IAAE;IAAS;GAAO;EAC3B;EAEA,SAAS,wBAAwB,WAAoC;GACnE,SAAS,gBAAgB,kBAOtB;IACD,MAAM,cAAc,0BAClB,GAAG,OAAO,OAAO,iBAAiB,aAAa,CAAC,CAAC,EAAE,KAChD,UAAU,8BAA8B,IAAI,KAAK,CACpD,CACF;IAEA,OAAO,gBAAgB;KACrB,GAAG;KACH,OAAO,0BACL,WACA,aACA,iBAAiB,KACnB;IACF,CAAC;GACH;GAEA,gBAAgB,4BAA4B,YAMtC;IACJ,MAAM,EAAE,UAAU,OAAO,GAAG,UAAU;IAEtC,IACE,CAAC,gBAAgB,MACd,mBAAmB,eAAe,aAAa,QAClD,GAEA,MAAM,IAAI,MACR,aAAa,SAAS,4CACxB;IAGF,IAAI,UAAU,QACZ,8BAA8B,IAAI,OAAO,KAAK;IAGhD,OAAO;GACT;GAEA,OAAO;EACT;EAEA,OAAO,OAAO,iBAAiB,EAC7B,UAAU,wBACZ,CAAC;EAED,MAAM,eAKF;GACF;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.cjs","names":["capitalize","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 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 components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n function createComponent(componentOptions: {\n props?: {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n };\n resources?: Record<string, ScopedComponentEntry>;\n render: (\n props: Record<string, unknown>,\n context: Record<string, (props: never) => JSX.Element>,\n ) => ScopedRenderResult;\n }) {\n const include = componentOptions.props?.include ?? {};\n const custom = componentOptions.props?.custom ?? {};\n const selectedResources = new Set(\n resourceOptions.map(({ resource }) => resource),\n );\n const componentPropsContext = createContext<\n Record<string, unknown> | undefined\n >(undefined);\n const definedEntries = new Map<\n LayoutResourceKey<Resources>,\n ScopedComponentEntry\n >();\n\n for (const [key, entry] of Object.entries(\n componentOptions.resources ?? {},\n )) {\n const resource = key as LayoutResourceKey<Resources>;\n\n if (!selectedResources.has(resource)) {\n throw new Error(\n `Resource \"${key}\" is not available in this scoped component`,\n );\n }\n\n definedEntries.set(resource, entry);\n }\n\n /** Resolved scoped components, per resource. */\n const resourceScopedComponents = new Map<\n LayoutResourceKey<Resources>,\n Record<string, (props?: never) => JSX.Element>\n >();\n const contextResources = new Map<string, LayoutResourceKey<Resources>>();\n const renderContext: Record<string, (props: never) => JSX.Element> =\n Object.fromEntries(\n [...definedEntries].map(([resource, entry]) => {\n const contextKey = capitalize(resource);\n\n if (contextKey === 'Root') {\n throw new Error(\n `Resource \"${resource}\" maps to the reserved render context key \"Root\"`,\n );\n }\n\n const existingResource = contextResources.get(contextKey);\n\n if (existingResource !== undefined) {\n throw new Error(\n `Resources \"${existingResource}\" and \"${resource}\" both map to render context key \"${contextKey}\"`,\n );\n }\n\n contextResources.set(contextKey, resource);\n\n /**\n * Built once per resource so every scoped component keeps a stable\n * identity, and shared by the resource render, the render context,\n * and any component bound through `asHOF()`.\n */\n const scopedComponents: Record<\n string,\n (props?: never) => JSX.Element\n > = {};\n\n for (const [name, definition] of Object.entries(\n entry.components ?? {},\n )) {\n if (reservedScopedComponentNames.has(name)) {\n throw new Error(\n `Scoped component \"${name}\" for resource \"${resource}\" uses a reserved name`,\n );\n }\n\n const ownPropDefinitions = definition.props ?? {};\n // 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 Error(\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 Error(\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 Error(\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 Error(\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 Error(\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 Error(\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 Error(\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\n for (const key of Object.keys(availableDefinitions)) {\n if (key in componentProps) {\n layoutOptions[key] = componentProps[key];\n }\n\n const capitalized = capitalize(key);\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 return createElement(root, 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 Error(\n `Resource \"${componentResource}\" is not available in this scoped component`,\n );\n }\n\n const availableDefinitions =\n getComponentPropDefinitions(componentResource);\n const definitionsToValidate: Record<string, AnyBuiltPropDefinition> =\n {};\n\n for (const [key, inclusion] of Object.entries(include)) {\n const definition = availableDefinitions[key];\n\n if (!definition) {\n continue;\n }\n\n // Keep declared keys as-is — do not capitalize JSX.Element props.\n if (inclusion === true || key in componentProps) {\n definitionsToValidate[key] = definition;\n }\n }\n\n for (const [key, definition] of Object.entries(custom)) {\n if (key === 'children' || key === 'resource') {\n continue;\n }\n\n definitionsToValidate[key] = definition;\n }\n\n validateProps(definitionsToValidate, componentProps, {\n 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: componentProps },\n resolveScopedRenderResult(\n componentOptions.render(componentProps, renderContext),\n componentProps,\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 Error(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n let boundComponent = boundComponents.get(resource);\n\n if (boundComponent === undefined) {\n boundComponent = Object.assign(\n (boundProps: Record<string, unknown>) =>\n createElement(Component, { ...boundProps, resource }),\n {\n displayName: `ScopedResourceComponent(${resource})`,\n props: undefined,\n resource: undefined,\n },\n resourceScopedComponents.get(resource) ?? {},\n );\n boundComponents.set(resource, boundComponent);\n }\n\n return boundComponent;\n }\n\n function asHOF() {\n return bindResource;\n }\n\n return Object.assign(Component, {\n asHOF,\n displayName: 'ScopedResourceComponent',\n props: undefined,\n });\n }\n\n type CreateComponentPropsBag = {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n };\n\n const createResourceComponentExtras = new WeakMap<\n object,\n CreateComponentPropsBag\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\n return { include, custom };\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 const fromEntries = mergeCreateComponentProps(\n ...Object.values(componentOptions.resources ?? {}).map(\n (entry) => createResourceComponentExtras.get(entry),\n ),\n );\n\n return createComponent({\n ...componentOptions,\n props: mergeCreateComponentProps(\n baseProps,\n fromEntries,\n componentOptions.props,\n ),\n });\n }\n\n createWithProps.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 Error(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n if (props !== undefined) {\n createResourceComponentExtras.set(entry, props);\n }\n\n return entry;\n };\n\n return createWithProps;\n }\n\n Object.assign(createComponent, {\n setProps: createComponentSetProps,\n });\n\n const scopedExtras: {\n createComponent: typeof createComponent;\n forResource: typeof scopedForResource;\n makeComposable?: (options: Record<string, unknown>) => unknown;\n resources: undefined;\n } = {\n createComponent,\n forResource: scopedForResource,\n resources: undefined,\n };\n\n if (createMakeComposableLayout) {\n const makeComposableLayout = createMakeComposableLayout();\n\n scopedExtras.makeComposable = (options) => {\n const resource = options.resource as LayoutResourceKey<Resources>;\n\n return makeComposableLayout({\n ...options,\n name: options.name ?? defaultNames.get(resource),\n });\n };\n }\n\n return Object.assign(scopedCreateResourceLayout, scopedExtras);\n }) as unknown as CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n}\n"],"mappings":";;;;;;AA6CA,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;IA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D,MAAM,SAAiD,CAAC;GAExD,KAAK,MAAM,OAAO,MAAM;IACtB,OAAO,OAAO,SAAS,KAAK,OAAO;IACnC,OAAO,OAAO,QAAQ,KAAK,MAAM;GACnC;GAEA,OAAO;IAAE;IAAS;GAAO;EAC3B;EAEA,SAAS,wBAAwB,WAAoC;GACnE,SAAS,gBAAgB,kBAOtB;IACD,MAAM,cAAc,0BAClB,GAAG,OAAO,OAAO,iBAAiB,aAAa,CAAC,CAAC,EAAE,KAChD,UAAU,8BAA8B,IAAI,KAAK,CACpD,CACF;IAEA,OAAO,gBAAgB;KACrB,GAAG;KACH,OAAO,0BACL,WACA,aACA,iBAAiB,KACnB;IACF,CAAC;GACH;GAEA,gBAAgB,4BAA4B,YAMtC;IACJ,MAAM,EAAE,UAAU,OAAO,GAAG,UAAU;IAEtC,IACE,CAAC,gBAAgB,MACd,mBAAmB,eAAe,aAAa,QAClD,GAEA,MAAM,IAAI,MACR,aAAa,SAAS,4CACxB;IAGF,IAAI,UAAU,QACZ,8BAA8B,IAAI,OAAO,KAAK;IAGhD,OAAO;GACT;GAEA,OAAO;EACT;EAEA,OAAO,OAAO,iBAAiB,EAC7B,UAAU,wBACZ,CAAC;EAED,MAAM,eAKF;GACF;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"}
@@ -66,7 +66,10 @@ function createForResources({ createLayoutForResource, createMakeComposableLayou
66
66
  if (componentProps === void 0) throw new Error(`Scoped component "${name}" must be rendered inside its scoped component`);
67
67
  const resolvedOwnProps = ownProps ?? {};
68
68
  cachedOwnProps = resolvedOwnProps;
69
- validateProps(ownPropDefinitions, resolvedOwnProps);
69
+ validateProps(ownPropDefinitions, resolvedOwnProps, {
70
+ layoutName: entry.name ?? defaultNames.get(resource) ?? capitalize(resource),
71
+ resource
72
+ });
70
73
  const result = definition.render({
71
74
  ...componentProps,
72
75
  ...resolvedOwnProps,
@@ -152,7 +155,10 @@ function createForResources({ createLayoutForResource, createMakeComposableLayou
152
155
  if (key === "children" || key === "resource") continue;
153
156
  definitionsToValidate[key] = definition;
154
157
  }
155
- validateProps(definitionsToValidate, componentProps);
158
+ validateProps(definitionsToValidate, componentProps, {
159
+ layoutName: definedEntries.get(componentResource)?.name ?? defaultNames.get(componentResource) ?? capitalize(componentResource),
160
+ resource: componentResource
161
+ });
156
162
  return createElement(componentPropsContext.Provider, { value: componentProps }, resolveScopedRenderResult(componentOptions.render(componentProps, renderContext), componentProps));
157
163
  }
158
164
  /**
@@ -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 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 components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n function createComponent(componentOptions: {\n props?: {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n };\n resources?: Record<string, ScopedComponentEntry>;\n render: (\n props: Record<string, unknown>,\n context: Record<string, (props: never) => JSX.Element>,\n ) => ScopedRenderResult;\n }) {\n const include = componentOptions.props?.include ?? {};\n const custom = componentOptions.props?.custom ?? {};\n const selectedResources = new Set(\n resourceOptions.map(({ resource }) => resource),\n );\n const componentPropsContext = createContext<\n Record<string, unknown> | undefined\n >(undefined);\n const definedEntries = new Map<\n LayoutResourceKey<Resources>,\n ScopedComponentEntry\n >();\n\n for (const [key, entry] of Object.entries(\n componentOptions.resources ?? {},\n )) {\n const resource = key as LayoutResourceKey<Resources>;\n\n if (!selectedResources.has(resource)) {\n throw new Error(\n `Resource \"${key}\" is not available in this scoped component`,\n );\n }\n\n definedEntries.set(resource, entry);\n }\n\n /** Resolved scoped components, per resource. */\n const resourceScopedComponents = new Map<\n LayoutResourceKey<Resources>,\n Record<string, (props?: never) => JSX.Element>\n >();\n const contextResources = new Map<string, LayoutResourceKey<Resources>>();\n const renderContext: Record<string, (props: never) => JSX.Element> =\n Object.fromEntries(\n [...definedEntries].map(([resource, entry]) => {\n const contextKey = capitalize(resource);\n\n if (contextKey === 'Root') {\n throw new Error(\n `Resource \"${resource}\" maps to the reserved render context key \"Root\"`,\n );\n }\n\n const existingResource = contextResources.get(contextKey);\n\n if (existingResource !== undefined) {\n throw new Error(\n `Resources \"${existingResource}\" and \"${resource}\" both map to render context key \"${contextKey}\"`,\n );\n }\n\n contextResources.set(contextKey, resource);\n\n /**\n * Built once per resource so every scoped component keeps a stable\n * identity, and shared by the resource render, the render context,\n * and any component bound through `asHOF()`.\n */\n const scopedComponents: Record<\n string,\n (props?: never) => JSX.Element\n > = {};\n\n for (const [name, definition] of Object.entries(\n entry.components ?? {},\n )) {\n if (reservedScopedComponentNames.has(name)) {\n throw new Error(\n `Scoped component \"${name}\" for resource \"${resource}\" uses a reserved name`,\n );\n }\n\n const ownPropDefinitions = definition.props ?? {};\n // 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 Error(\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\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 Error(\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 Error(\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 Error(\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 Error(\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 Error(\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 Error(\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\n for (const key of Object.keys(availableDefinitions)) {\n if (key in componentProps) {\n layoutOptions[key] = componentProps[key];\n }\n\n const capitalized = capitalize(key);\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 return createElement(root, 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 Error(\n `Resource \"${componentResource}\" is not available in this scoped component`,\n );\n }\n\n const availableDefinitions =\n getComponentPropDefinitions(componentResource);\n const definitionsToValidate: Record<string, AnyBuiltPropDefinition> =\n {};\n\n for (const [key, inclusion] of Object.entries(include)) {\n const definition = availableDefinitions[key];\n\n if (!definition) {\n continue;\n }\n\n // Keep declared keys as-is — do not capitalize JSX.Element props.\n if (inclusion === true || key in componentProps) {\n definitionsToValidate[key] = definition;\n }\n }\n\n for (const [key, definition] of Object.entries(custom)) {\n if (key === 'children' || key === 'resource') {\n continue;\n }\n\n definitionsToValidate[key] = definition;\n }\n\n validateProps(definitionsToValidate, componentProps);\n\n // 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: componentProps },\n resolveScopedRenderResult(\n componentOptions.render(componentProps, renderContext),\n componentProps,\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 Error(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n let boundComponent = boundComponents.get(resource);\n\n if (boundComponent === undefined) {\n boundComponent = Object.assign(\n (boundProps: Record<string, unknown>) =>\n createElement(Component, { ...boundProps, resource }),\n {\n displayName: `ScopedResourceComponent(${resource})`,\n props: undefined,\n resource: undefined,\n },\n resourceScopedComponents.get(resource) ?? {},\n );\n boundComponents.set(resource, boundComponent);\n }\n\n return boundComponent;\n }\n\n function asHOF() {\n return bindResource;\n }\n\n return Object.assign(Component, {\n asHOF,\n displayName: 'ScopedResourceComponent',\n props: undefined,\n });\n }\n\n type CreateComponentPropsBag = {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n };\n\n const createResourceComponentExtras = new WeakMap<\n object,\n CreateComponentPropsBag\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\n return { include, custom };\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 const fromEntries = mergeCreateComponentProps(\n ...Object.values(componentOptions.resources ?? {}).map(\n (entry) => createResourceComponentExtras.get(entry),\n ),\n );\n\n return createComponent({\n ...componentOptions,\n props: mergeCreateComponentProps(\n baseProps,\n fromEntries,\n componentOptions.props,\n ),\n });\n }\n\n createWithProps.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 Error(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n if (props !== undefined) {\n createResourceComponentExtras.set(entry, props);\n }\n\n return entry;\n };\n\n return createWithProps;\n }\n\n Object.assign(createComponent, {\n setProps: createComponentSetProps,\n });\n\n const scopedExtras: {\n createComponent: typeof createComponent;\n forResource: typeof scopedForResource;\n makeComposable?: (options: Record<string, unknown>) => unknown;\n resources: undefined;\n } = {\n createComponent,\n forResource: scopedForResource,\n resources: undefined,\n };\n\n if (createMakeComposableLayout) {\n const makeComposableLayout = createMakeComposableLayout();\n\n scopedExtras.makeComposable = (options) => {\n const resource = options.resource as LayoutResourceKey<Resources>;\n\n return makeComposableLayout({\n ...options,\n name: options.name ?? defaultNames.get(resource),\n });\n };\n }\n\n return Object.assign(scopedCreateResourceLayout, scopedExtras);\n }) as unknown as CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n}\n"],"mappings":";;;;;;AA6CA,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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BAAqB;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 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 components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n function createComponent(componentOptions: {\n props?: {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n };\n resources?: Record<string, ScopedComponentEntry>;\n render: (\n props: Record<string, unknown>,\n context: Record<string, (props: never) => JSX.Element>,\n ) => ScopedRenderResult;\n }) {\n const include = componentOptions.props?.include ?? {};\n const custom = componentOptions.props?.custom ?? {};\n const selectedResources = new Set(\n resourceOptions.map(({ resource }) => resource),\n );\n const componentPropsContext = createContext<\n Record<string, unknown> | undefined\n >(undefined);\n const definedEntries = new Map<\n LayoutResourceKey<Resources>,\n ScopedComponentEntry\n >();\n\n for (const [key, entry] of Object.entries(\n componentOptions.resources ?? {},\n )) {\n const resource = key as LayoutResourceKey<Resources>;\n\n if (!selectedResources.has(resource)) {\n throw new Error(\n `Resource \"${key}\" is not available in this scoped component`,\n );\n }\n\n definedEntries.set(resource, entry);\n }\n\n /** Resolved scoped components, per resource. */\n const resourceScopedComponents = new Map<\n LayoutResourceKey<Resources>,\n Record<string, (props?: never) => JSX.Element>\n >();\n const contextResources = new Map<string, LayoutResourceKey<Resources>>();\n const renderContext: Record<string, (props: never) => JSX.Element> =\n Object.fromEntries(\n [...definedEntries].map(([resource, entry]) => {\n const contextKey = capitalize(resource);\n\n if (contextKey === 'Root') {\n throw new Error(\n `Resource \"${resource}\" maps to the reserved render context key \"Root\"`,\n );\n }\n\n const existingResource = contextResources.get(contextKey);\n\n if (existingResource !== undefined) {\n throw new Error(\n `Resources \"${existingResource}\" and \"${resource}\" both map to render context key \"${contextKey}\"`,\n );\n }\n\n contextResources.set(contextKey, resource);\n\n /**\n * Built once per resource so every scoped component keeps a stable\n * identity, and shared by the resource render, the render context,\n * and any component bound through `asHOF()`.\n */\n const scopedComponents: Record<\n string,\n (props?: never) => JSX.Element\n > = {};\n\n for (const [name, definition] of Object.entries(\n entry.components ?? {},\n )) {\n if (reservedScopedComponentNames.has(name)) {\n throw new Error(\n `Scoped component \"${name}\" for resource \"${resource}\" uses a reserved name`,\n );\n }\n\n const ownPropDefinitions = definition.props ?? {};\n // 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 Error(\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 Error(\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 Error(\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 Error(\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 Error(\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 Error(\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 Error(\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\n for (const key of Object.keys(availableDefinitions)) {\n if (key in componentProps) {\n layoutOptions[key] = componentProps[key];\n }\n\n const capitalized = capitalize(key);\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 return createElement(root, 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 Error(\n `Resource \"${componentResource}\" is not available in this scoped component`,\n );\n }\n\n const availableDefinitions =\n getComponentPropDefinitions(componentResource);\n const definitionsToValidate: Record<string, AnyBuiltPropDefinition> =\n {};\n\n for (const [key, inclusion] of Object.entries(include)) {\n const definition = availableDefinitions[key];\n\n if (!definition) {\n continue;\n }\n\n // Keep declared keys as-is — do not capitalize JSX.Element props.\n if (inclusion === true || key in componentProps) {\n definitionsToValidate[key] = definition;\n }\n }\n\n for (const [key, definition] of Object.entries(custom)) {\n if (key === 'children' || key === 'resource') {\n continue;\n }\n\n definitionsToValidate[key] = definition;\n }\n\n validateProps(definitionsToValidate, componentProps, {\n 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: componentProps },\n resolveScopedRenderResult(\n componentOptions.render(componentProps, renderContext),\n componentProps,\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 Error(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n let boundComponent = boundComponents.get(resource);\n\n if (boundComponent === undefined) {\n boundComponent = Object.assign(\n (boundProps: Record<string, unknown>) =>\n createElement(Component, { ...boundProps, resource }),\n {\n displayName: `ScopedResourceComponent(${resource})`,\n props: undefined,\n resource: undefined,\n },\n resourceScopedComponents.get(resource) ?? {},\n );\n boundComponents.set(resource, boundComponent);\n }\n\n return boundComponent;\n }\n\n function asHOF() {\n return bindResource;\n }\n\n return Object.assign(Component, {\n asHOF,\n displayName: 'ScopedResourceComponent',\n props: undefined,\n });\n }\n\n type CreateComponentPropsBag = {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n };\n\n const createResourceComponentExtras = new WeakMap<\n object,\n CreateComponentPropsBag\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\n return { include, custom };\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 const fromEntries = mergeCreateComponentProps(\n ...Object.values(componentOptions.resources ?? {}).map(\n (entry) => createResourceComponentExtras.get(entry),\n ),\n );\n\n return createComponent({\n ...componentOptions,\n props: mergeCreateComponentProps(\n baseProps,\n fromEntries,\n componentOptions.props,\n ),\n });\n }\n\n createWithProps.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 Error(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n if (props !== undefined) {\n createResourceComponentExtras.set(entry, props);\n }\n\n return entry;\n };\n\n return createWithProps;\n }\n\n Object.assign(createComponent, {\n setProps: createComponentSetProps,\n });\n\n const scopedExtras: {\n createComponent: typeof createComponent;\n forResource: typeof scopedForResource;\n makeComposable?: (options: Record<string, unknown>) => unknown;\n resources: undefined;\n } = {\n createComponent,\n forResource: scopedForResource,\n resources: undefined,\n };\n\n if (createMakeComposableLayout) {\n const makeComposableLayout = createMakeComposableLayout();\n\n scopedExtras.makeComposable = (options) => {\n const resource = options.resource as LayoutResourceKey<Resources>;\n\n return makeComposableLayout({\n ...options,\n name: options.name ?? defaultNames.get(resource),\n });\n };\n }\n\n return Object.assign(scopedCreateResourceLayout, scopedExtras);\n }) as unknown as CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n}\n"],"mappings":";;;;;;AA6CA,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,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GACH;EACF;EAEA,OAAO,OAAO,OAAO,4BAA4B,YAAY;CAC/D;AAOF"}
package/dist/index.cjs CHANGED
@@ -11,6 +11,12 @@ Object.defineProperty(exports, 'LayoutComposablePresetProvider', {
11
11
  return _jfdevelops_react_layout_composables.LayoutComposablePresetProvider;
12
12
  }
13
13
  });
14
+ Object.defineProperty(exports, 'PropError', {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _jfdevelops_react_layout_validator.PropError;
18
+ }
19
+ });
14
20
  Object.defineProperty(exports, 'collectComposablePresetEntries', {
15
21
  enumerable: true,
16
22
  get: function () {
package/dist/index.d.cts CHANGED
@@ -3,5 +3,5 @@ import { LayoutResourceKey, NormalizeResource, NormalizeResources, ResourceDefin
3
3
  import { InPropsDefinition, InPropsFunction, InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps, MergedLayoutInProps, PropsContextRender, PropsRenderDefinition, ResolvedIncludedProps, ResolvedIncludedPropsAsDefined } from "./props.cjs";
4
4
  import { defineResourceLayout } from "./create-config/define-layout.cjs";
5
5
  import { AnyComposableComponent, ComposableComponent, ComposableComponentCallable, ComposableComponents, ComposableNameContext, ComposablePresetComponent, ComposablePresetComponentCallProps, ComposablePresetMeta, ComposablePresetProps, ComposableResourceLayout, CreateLayoutComposable, DefinedComposableComponentRecord, LayoutComposablePresetProvider, LayoutComposablesFactory, MakeComposable, MakeComposableOptions, MergePresetProps, PresetPropsFromComposable, RequiredPresetLayoutProps, RequiredPresetRenderProps, ResolveLayoutComposables, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, defineComposableComponent, makeComposable, resolveComposablePresetProps, resolveLayoutComposables } from "@jfdevelops/react-layout-composables";
6
- import { AnyBuiltPropDefinition, ExtractDefinitionValue, ResolveLayoutProps, ResolveLayoutPropsAsDefined, ResolveProps, ResolvedBuiltPropShape, createPrimitivePropBuilder, createProp, isPropDefinitionShape, resolvePropDefinitionValues, validateProps } from "@jfdevelops/react-layout-validator";
7
- export { type AnyBuiltPropDefinition, type AnyComposableComponent, type BaseComponent, type ComposableComponent, type ComposableComponentCallable, type ComposableComponents, type ComposableNameContext, type ComposablePresetComponent, type ComposablePresetComponentCallProps, type ComposablePresetMeta, type ComposablePresetProps, type ComposableResourceLayout, type CreateLayoutComposable, type DefinedComposableComponentRecord, type ExtractDefinitionValue, type InPropsDefinition, type InPropsFunction, type InPropsObject, type InPropsOptions, type IncludedProps, type InferredInProps, LayoutComposablePresetProvider, type LayoutComposablesFactory, type LayoutRenderProps, type LayoutResourceKey, type MakeComposable, type MakeComposableOptions, type MergeIntersection, type MergePresetProps, type MergedLayoutInProps, type NormalizeResource, type NormalizeResources, type PresetPropsFromComposable, type PropsContextRender, type PropsRenderDefinition, type RequiredPresetLayoutProps, type RequiredPresetRenderProps, type ResolveLayoutComposables, type ResolveLayoutProps, type ResolveLayoutPropsAsDefined, type ResolveProps, type ResolvedBuiltPropShape, type ResolvedIncludedProps, type ResolvedIncludedPropsAsDefined, type ResourceDefinition, type ResourceEnum, type ResourceLayoutComponentProps, type ResourceTree, type Show, type UnionToIntersection, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, createPrimitivePropBuilder, createProp, defineComposableComponent, defineResourceLayout, isPropDefinitionShape, makeComposable, normalizeResource, normalizeResources, pick, resolveComposablePresetProps, resolveLayoutComposables, resolvePropDefinitionValues, toResourceEnum, validateProps };
6
+ import { AnyBuiltPropDefinition, ExtractDefinitionValue, PropError, PropErrorOptions, ResolveLayoutProps, ResolveLayoutPropsAsDefined, ResolveProps, ResolvedBuiltPropShape, createPrimitivePropBuilder, createProp, isPropDefinitionShape, resolvePropDefinitionValues, validateProps } from "@jfdevelops/react-layout-validator";
7
+ export { type AnyBuiltPropDefinition, type AnyComposableComponent, type BaseComponent, type ComposableComponent, type ComposableComponentCallable, type ComposableComponents, type ComposableNameContext, type ComposablePresetComponent, type ComposablePresetComponentCallProps, type ComposablePresetMeta, type ComposablePresetProps, type ComposableResourceLayout, type CreateLayoutComposable, type DefinedComposableComponentRecord, type ExtractDefinitionValue, type InPropsDefinition, type InPropsFunction, type InPropsObject, type InPropsOptions, type IncludedProps, type InferredInProps, LayoutComposablePresetProvider, type LayoutComposablesFactory, type LayoutRenderProps, type LayoutResourceKey, type MakeComposable, type MakeComposableOptions, type MergeIntersection, type MergePresetProps, type MergedLayoutInProps, type NormalizeResource, type NormalizeResources, type PresetPropsFromComposable, PropError, type PropErrorOptions, type PropsContextRender, type PropsRenderDefinition, type RequiredPresetLayoutProps, type RequiredPresetRenderProps, type ResolveLayoutComposables, type ResolveLayoutProps, type ResolveLayoutPropsAsDefined, type ResolveProps, type ResolvedBuiltPropShape, type ResolvedIncludedProps, type ResolvedIncludedPropsAsDefined, type ResourceDefinition, type ResourceEnum, type ResourceLayoutComponentProps, type ResourceTree, type Show, type UnionToIntersection, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, createPrimitivePropBuilder, createProp, defineComposableComponent, defineResourceLayout, isPropDefinitionShape, makeComposable, normalizeResource, normalizeResources, pick, resolveComposablePresetProps, resolveLayoutComposables, resolvePropDefinitionValues, toResourceEnum, validateProps };
package/dist/index.d.mts CHANGED
@@ -3,5 +3,5 @@ import { LayoutResourceKey, NormalizeResource, NormalizeResources, ResourceDefin
3
3
  import { InPropsDefinition, InPropsFunction, InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps, MergedLayoutInProps, PropsContextRender, PropsRenderDefinition, ResolvedIncludedProps, ResolvedIncludedPropsAsDefined } from "./props.mjs";
4
4
  import { defineResourceLayout } from "./create-config/define-layout.mjs";
5
5
  import { AnyComposableComponent, ComposableComponent, ComposableComponentCallable, ComposableComponents, ComposableNameContext, ComposablePresetComponent, ComposablePresetComponentCallProps, ComposablePresetMeta, ComposablePresetProps, ComposableResourceLayout, CreateLayoutComposable, DefinedComposableComponentRecord, LayoutComposablePresetProvider, LayoutComposablesFactory, MakeComposable, MakeComposableOptions, MergePresetProps, PresetPropsFromComposable, RequiredPresetLayoutProps, RequiredPresetRenderProps, ResolveLayoutComposables, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, defineComposableComponent, makeComposable, resolveComposablePresetProps, resolveLayoutComposables } from "@jfdevelops/react-layout-composables";
6
- import { AnyBuiltPropDefinition, ExtractDefinitionValue, ResolveLayoutProps, ResolveLayoutPropsAsDefined, ResolveProps, ResolvedBuiltPropShape, createPrimitivePropBuilder, createProp, isPropDefinitionShape, resolvePropDefinitionValues, validateProps } from "@jfdevelops/react-layout-validator";
7
- export { type AnyBuiltPropDefinition, type AnyComposableComponent, type BaseComponent, type ComposableComponent, type ComposableComponentCallable, type ComposableComponents, type ComposableNameContext, type ComposablePresetComponent, type ComposablePresetComponentCallProps, type ComposablePresetMeta, type ComposablePresetProps, type ComposableResourceLayout, type CreateLayoutComposable, type DefinedComposableComponentRecord, type ExtractDefinitionValue, type InPropsDefinition, type InPropsFunction, type InPropsObject, type InPropsOptions, type IncludedProps, type InferredInProps, LayoutComposablePresetProvider, type LayoutComposablesFactory, type LayoutRenderProps, type LayoutResourceKey, type MakeComposable, type MakeComposableOptions, type MergeIntersection, type MergePresetProps, type MergedLayoutInProps, type NormalizeResource, type NormalizeResources, type PresetPropsFromComposable, type PropsContextRender, type PropsRenderDefinition, type RequiredPresetLayoutProps, type RequiredPresetRenderProps, type ResolveLayoutComposables, type ResolveLayoutProps, type ResolveLayoutPropsAsDefined, type ResolveProps, type ResolvedBuiltPropShape, type ResolvedIncludedProps, type ResolvedIncludedPropsAsDefined, type ResourceDefinition, type ResourceEnum, type ResourceLayoutComponentProps, type ResourceTree, type Show, type UnionToIntersection, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, createPrimitivePropBuilder, createProp, defineComposableComponent, defineResourceLayout, isPropDefinitionShape, makeComposable, normalizeResource, normalizeResources, pick, resolveComposablePresetProps, resolveLayoutComposables, resolvePropDefinitionValues, toResourceEnum, validateProps };
6
+ import { AnyBuiltPropDefinition, ExtractDefinitionValue, PropError, PropErrorOptions, ResolveLayoutProps, ResolveLayoutPropsAsDefined, ResolveProps, ResolvedBuiltPropShape, createPrimitivePropBuilder, createProp, isPropDefinitionShape, resolvePropDefinitionValues, validateProps } from "@jfdevelops/react-layout-validator";
7
+ export { type AnyBuiltPropDefinition, type AnyComposableComponent, type BaseComponent, type ComposableComponent, type ComposableComponentCallable, type ComposableComponents, type ComposableNameContext, type ComposablePresetComponent, type ComposablePresetComponentCallProps, type ComposablePresetMeta, type ComposablePresetProps, type ComposableResourceLayout, type CreateLayoutComposable, type DefinedComposableComponentRecord, type ExtractDefinitionValue, type InPropsDefinition, type InPropsFunction, type InPropsObject, type InPropsOptions, type IncludedProps, type InferredInProps, LayoutComposablePresetProvider, type LayoutComposablesFactory, type LayoutRenderProps, type LayoutResourceKey, type MakeComposable, type MakeComposableOptions, type MergeIntersection, type MergePresetProps, type MergedLayoutInProps, type NormalizeResource, type NormalizeResources, type PresetPropsFromComposable, PropError, type PropErrorOptions, type PropsContextRender, type PropsRenderDefinition, type RequiredPresetLayoutProps, type RequiredPresetRenderProps, type ResolveLayoutComposables, type ResolveLayoutProps, type ResolveLayoutPropsAsDefined, type ResolveProps, type ResolvedBuiltPropShape, type ResolvedIncludedProps, type ResolvedIncludedPropsAsDefined, type ResourceDefinition, type ResourceEnum, type ResourceLayoutComponentProps, type ResourceTree, type Show, type UnionToIntersection, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, createPrimitivePropBuilder, createProp, defineComposableComponent, defineResourceLayout, isPropDefinitionShape, makeComposable, normalizeResource, normalizeResources, pick, resolveComposablePresetProps, resolveLayoutComposables, resolvePropDefinitionValues, toResourceEnum, validateProps };
package/dist/index.mjs CHANGED
@@ -2,6 +2,6 @@ import { normalizeResource, normalizeResources, toResourceEnum } from "./resourc
2
2
  import { pick } from "./utils.mjs";
3
3
  import { defineResourceLayout } from "./create-config/define-layout.mjs";
4
4
  import { LayoutComposablePresetProvider, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, defineComposableComponent, makeComposable, resolveComposablePresetProps, resolveLayoutComposables } from "@jfdevelops/react-layout-composables";
5
- import { createPrimitivePropBuilder, createProp, isPropDefinitionShape, resolvePropDefinitionValues, validateProps } from "@jfdevelops/react-layout-validator";
5
+ import { PropError, createPrimitivePropBuilder, createProp, isPropDefinitionShape, resolvePropDefinitionValues, validateProps } from "@jfdevelops/react-layout-validator";
6
6
 
7
- export { LayoutComposablePresetProvider, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, createPrimitivePropBuilder, createProp, defineComposableComponent, defineResourceLayout, isPropDefinitionShape, makeComposable, normalizeResource, normalizeResources, pick, resolveComposablePresetProps, resolveLayoutComposables, resolvePropDefinitionValues, toResourceEnum, validateProps };
7
+ export { LayoutComposablePresetProvider, PropError, collectComposablePresetEntries, createComposableComponent, createLayoutComposableFactory, createPrimitivePropBuilder, createProp, defineComposableComponent, defineResourceLayout, isPropDefinitionShape, makeComposable, normalizeResource, normalizeResources, pick, resolveComposablePresetProps, resolveLayoutComposables, resolvePropDefinitionValues, toResourceEnum, validateProps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jfdevelops/react-layout",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "A React library for creating layout components.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,8 +27,8 @@
27
27
  "node": "^20.19.0 || >=22.12.0"
28
28
  },
29
29
  "dependencies": {
30
- "@jfdevelops/react-layout-composables": "0.2.3",
31
- "@jfdevelops/react-layout-validator": "0.2.3"
30
+ "@jfdevelops/react-layout-composables": "0.2.4",
31
+ "@jfdevelops/react-layout-validator": "0.2.4"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": ">=18",