@jfdevelops/react-layout 0.24.3 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-config/create-defined-resource-layout.cjs +67 -0
- package/dist/create-config/create-defined-resource-layout.cjs.map +1 -0
- package/dist/create-config/create-defined-resource-layout.d.cts +68 -0
- package/dist/create-config/create-defined-resource-layout.d.cts.map +1 -0
- package/dist/create-config/create-defined-resource-layout.d.mts +68 -0
- package/dist/create-config/create-defined-resource-layout.d.mts.map +1 -0
- package/dist/create-config/create-defined-resource-layout.mjs +67 -0
- package/dist/create-config/create-defined-resource-layout.mjs.map +1 -0
- package/dist/create-config/create-resource-links.cjs.map +1 -1
- package/dist/create-config/create-resource-links.d.cts +1 -1
- package/dist/create-config/create-resource-links.d.cts.map +1 -1
- package/dist/create-config/create-resource-links.d.mts +1 -1
- package/dist/create-config/create-resource-links.d.mts.map +1 -1
- package/dist/create-config/create-resource-links.mjs.map +1 -1
- package/dist/create-config/define-layout.cjs +187 -8
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +152 -21
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +152 -21
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +189 -10
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/create-config/for-resources/create-for-resources.cjs +7 -0
- package/dist/create-config/for-resources/create-for-resources.cjs.map +1 -1
- package/dist/create-config/for-resources/create-for-resources.mjs +7 -0
- package/dist/create-config/for-resources/create-for-resources.mjs.map +1 -1
- package/dist/create-config/index.d.cts +4 -1
- package/dist/create-config/index.d.mts +4 -1
- package/dist/create-config/lazy-resource-layout.cjs +111 -0
- package/dist/create-config/lazy-resource-layout.cjs.map +1 -0
- package/dist/create-config/lazy-resource-layout.d.cts +51 -0
- package/dist/create-config/lazy-resource-layout.d.cts.map +1 -0
- package/dist/create-config/lazy-resource-layout.d.mts +51 -0
- package/dist/create-config/lazy-resource-layout.d.mts.map +1 -0
- package/dist/create-config/lazy-resource-layout.mjs +111 -0
- package/dist/create-config/lazy-resource-layout.mjs.map +1 -0
- package/dist/create-config/render-state.cjs +75 -0
- package/dist/create-config/render-state.cjs.map +1 -0
- package/dist/create-config/render-state.d.cts +120 -0
- package/dist/create-config/render-state.d.cts.map +1 -0
- package/dist/create-config/render-state.d.mts +120 -0
- package/dist/create-config/render-state.d.mts.map +1 -0
- package/dist/create-config/render-state.mjs +68 -0
- package/dist/create-config/render-state.mjs.map +1 -0
- package/dist/errors/resource-state-error.cjs +29 -0
- package/dist/errors/resource-state-error.cjs.map +1 -0
- package/dist/errors/resource-state-error.d.cts +19 -0
- package/dist/errors/resource-state-error.d.cts.map +1 -0
- package/dist/errors/resource-state-error.d.mts +19 -0
- package/dist/errors/resource-state-error.d.mts.map +1 -0
- package/dist/errors/resource-state-error.mjs +27 -0
- package/dist/errors/resource-state-error.mjs.map +1 -0
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +8 -4
- package/dist/index.d.mts +8 -4
- package/dist/index.mjs +3 -1
- package/dist/props.d.cts +6 -1
- package/dist/props.d.cts.map +1 -1
- package/dist/props.d.mts +6 -1
- package/dist/props.d.mts.map +1 -1
- package/dist/resource.cjs.map +1 -1
- package/dist/resource.d.cts +7 -1
- package/dist/resource.d.cts.map +1 -1
- package/dist/resource.d.mts +7 -1
- package/dist/resource.d.mts.map +1 -1
- package/dist/resource.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-resource-links.d.mts","names":[],"sources":["../../src/create-config/create-resource-links.ts"],"mappings":";;;;;;KAaY,oBAAA,6BACV,QAAA,EAAU,QAAQ;AAAA,KAGR,gBAAA,qCAER,oBAAoB,CAAC,QAAA;AAAA,KAEb,0BAAA,mBACQ,aAAA,CAAc,kBAAA,KAC9B,iBAAA,CAAkB,SAAA;AAAA,KAE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;;;;;AACyD;AAG7D;;EAyVE,YAAA,iCACkC,iBAAA,CAAkB,SAAA,IAAa,QAAA,EAE/D,QAAA,EAAU,iBAAA,GACT,uBAAA,CACD,SAAA,EACA,QAAA,EACA,iBAAA,EACA,SAAA,EACA,QAAA;AAAA;AAAA,KAIQ,qCAAA,mBACQ,aAAA,CAAc,kBAAA,oBACf,0BAAA,CAA2B,SAAA,IAAa,0BAAA,CAA2B,SAAA,eACxE,YAAA,CAAa,6BAAA,CAA8B,SAAA,eAC5C,YAAA,CAAa,6BAAA,CAA8B,SAAA,MACpD,KAAA,CACF,+BAAA,CAAgC,SAAA,EAAW,SAAA,EAAW,QAAA;EAzWxC,iEA4Wd,YAAA,iCACkC,iBAAA,CAAkB,SAAA,IAAa,QAAA,EAE/D,QAAA,EAAU,iBAAA,GACT,+BAAA,CACD,SAAA,EACA,QAAA,EACA,iBAAA,EACA,SAAA,EACA,QAAA;AAAA;AAAA,KAIQ,uBAAA,mBACQ,aAAA,CAAc,kBAAA,kFAGpB,YAAA,CAAa,6BAAA,CAA8B,SAAA,eAC5C,YAAA,CAAa,6BAAA,CAA8B,SAAA,MACpD,iBAAA,mBACA,iBAAA,SAA0B,gBAAA,GACxB,6BAAA,CAA8B,SAAA,EAAW,SAAA,EAAW,QAAA;AAAA,KAI9C,+BAAA,mBACQ,aAAA,CAAc,kBAAA,kFAGpB,YAAA,CAAa,6BAAA,CAA8B,SAAA,eAC5C,YAAA,CAAa,6BAAA,CAA8B,SAAA,MACpD,iBAAA,mBACA,iBAAA,SAA0B,gBAAA,GACxB,+BAAA,CAAgC,SAAA,EAAW,SAAA,EAAW,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-resource-links.mjs","names":[],"sources":["../../src/create-config/create-resource-links.ts"],"sourcesContent":["import type { ElementType, ReactNode } from 'react';\nimport type { NonEmptyReadonlyArray } from '@jfdevelops/react-layout-validator';\nimport {\n createIsValidResourceFn,\n type LayoutResourceKey,\n type ResourceDefinition,\n} from '../resource';\nimport { LayoutConfigurationError } from '../errors';\nimport type {\n LayoutRenderResourcesAccessor,\n ResourceSelection,\n} from './define-layout';\n\nexport type ResourceAnchorLinkFn<Resource extends string> = (\n resource: Resource,\n) => string;\n\nexport type ResourceLinkHref<Resource extends string> =\n | string\n | ResourceAnchorLinkFn<Resource>;\n\nexport type ResourceLinkConfigResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = LayoutResourceKey<Resources> | (string & {});\n\nexport type ResourceIconFn<Resource = any> = (resource: Resource) => ReactNode;\n\nexport type ResourceIcon<Resource = any> = ReactNode | ResourceIconFn<Resource>;\n\ndeclare const resourceIconInputMarker: unique symbol;\ndeclare const resourceIconComponentInputMarker: unique symbol;\n\ntype ResourceIconInputMarker<Value> = {\n readonly [resourceIconInputMarker]: Value;\n};\n\ntype ResourceIconComponentInputMarker<Icon extends ElementType> = {\n readonly [resourceIconComponentInputMarker]: Icon;\n};\n\nexport type ResolveResourceIconInput<Definition> =\n Definition extends ResourceIconComponentInputMarker<infer Icon>\n ? Icon\n : Definition extends ResourceIconInputMarker<infer Value>\n ? Value\n : Definition extends ReadonlyArray<unknown>\n ? { [Index in keyof Definition]: ResolveResourceIconInput<Definition[Index]> }\n : Definition extends object\n ? { [Key in keyof Definition]: ResolveResourceIconInput<Definition[Key]> }\n : Definition;\n\nexport interface DefineResourceIconInputHelpers<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n resource(): ResourceIconInputMarker<LayoutResourceKey<Resources>>;\n icon<Icon extends ElementType = ElementType>(): ResourceIconComponentInputMarker<Icon>;\n}\n\nexport interface DefineResourceIconInputResult<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Definition,\n> {\n render(\n render: (options: {\n resource: LayoutRenderResourcesAccessor<Resources>;\n input: ResolveResourceIconInput<Definition>;\n }) => ReactNode,\n ): (\n input: ResolveResourceIconInput<Definition>,\n ) => ResourceIconFn<LayoutRenderResourcesAccessor<Resources>>;\n}\n\nexport interface DefineResourceIconFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n <Icon extends ElementType = ElementType>(\n render: (options: {\n resource: LayoutRenderResourcesAccessor<Resources>;\n Icon: Icon;\n }) => ReactNode,\n ): (Icon: Icon) => ResourceIconFn<LayoutRenderResourcesAccessor<Resources>>;\n input<Definition>(\n defineInput: (\n helpers: DefineResourceIconInputHelpers<Resources>,\n ) => Definition,\n ): DefineResourceIconInputResult<Resources, Definition>;\n}\nexport interface CreateResourceLinkOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources>,\n Icon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> {\n /**\n * The label of the link. This is the text that will be displayed in the link.\n */\n label: string;\n /**\n * An optional icon to render when the link is active.\n */\n activeIcon?: ReactNode;\n /**\n * An optional icon to register with the link. This is a headless approach, meaning you have full control\n * over the icon's rendering.\n */\n icon?: Icon;\n /**\n * The href of the link. By default, the href will be `\"/\"`. While you **don't** need to include a hash,\n * if you do, it will override the `hash` property (if provided).\n */\n href?: ResourceLinkHref<Resource>;\n /**\n * The hash of the link. By default, the hash will be the resource name. If you need to customize it, you can provide\n * a string or a function that returns a string.\n *\n * @remarks A `\"#\"` is not required. The generated href will include it automatically.\n */\n hash?: ResourceLinkHref<Resource>;\n}\n\nexport type CreateResourceLinkConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources> = ResourceLinkConfigResource<Resources>,\n Icon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = {\n [Key in Resource]?: CreateResourceLinkOptions<\n Resources,\n Key,\n Icon\n >;\n};\n\nexport type InferHashFromResourceLinkHref<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n> = Hash extends string\n ? Hash\n : Hash extends ResourceAnchorLinkFn<Resource>\n ? ReturnType<Hash>\n : never;\n\nexport type CreatedResourceHref = {\n /**\n * The full generated href with the `hash` if provided.\n */\n full: string;\n /**\n * The given href. This is the same value as the `href` property of the config.\n */\n given: string;\n};\n\nexport type CreatedResourceLinkBase<\n Resource extends string,\n Icon = ResourceIcon,\n> = {\n activeIcon?: ReactNode;\n href: CreatedResourceHref;\n label: string;\n resource: Resource;\n icon: Icon | null;\n};\nexport type CreateResourceLinkWithHash<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n Icon = ResourceIcon,\n> = Omit<CreatedResourceLinkBase<Resource, Icon>, 'href'> & {\n href: CreatedResourceHref & {\n hash: InferHashFromResourceLinkHref<Resource, Hash>;\n };\n};\n\nexport type CreatedResourceLink<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Config,\n Icon = ResourceIcon,\n> = {\n [Resource in keyof Config]-?: Resource extends ResourceLinkConfigResource<Resources>\n ? Config[Resource] extends {\n hash: infer hash extends ResourceLinkHref<Resource>;\n }\n ? CreateResourceLinkWithHash<Resource, hash, Icon>\n : CreatedResourceLinkBase<Resource, Icon>\n : never;\n}[keyof Config];\n\ntype ResourceLinkConfigIcon<Config> = {\n [Resource in keyof Config]-?: 'icon' extends keyof NonNullable<\n Config[Resource]\n >\n ? NonNullable<Config[Resource]> extends { icon?: infer Icon }\n ? Icon\n : never\n : never;\n}[keyof Config];\n\nexport interface CreateResourceLinksFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n <\n const Resource extends ResourceLinkConfigResource<Resources>,\n const Config extends object,\n >(\n config: CreateResourceLinkConfig<Resources, Resource> & Config,\n ): Array<\n CreatedResourceLink<\n Resources,\n Config,\n ResourceLinkConfigIcon<Config>\n >\n >;\n createResourceMap: CreateResourceMapFn<Resources>;\n defineIcon: DefineResourceIconFn<Resources>;\n withGroups: CreateResourceLinksWithGroupsFn<Resources>;\n}\n\nexport interface CreateResourceLinkGroupOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Links extends object =\n CreateResourceLinkConfig<Resources>,\n Icon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> {\n /**\n * An optional, caller-provided identity for the group. Provide this when you\n * combine groups from more than one `withGroups()` call into one list (e.g.\n * a module-owned nav section alongside a feature-owned one) — without it,\n * the id is derived from the group's `label` and its link resources, which\n * is enough to keep groups from a single call apart but can't distinguish\n * two independently-defined groups that happen to look identical.\n */\n id?: string;\n /**\n * The label of the group. This is the text that will be displayed for the group.\n */\n label?: string;\n /**\n * An optional icon to render when the group is active.\n */\n activeIcon?: ReactNode;\n /**\n * An optional icon to register with the group. This is a headless approach, meaning you have full control\n * over the icon's rendering.\n */\n icon?: Icon;\n /**\n * The resource links in this group.\n */\n links: Links;\n}\n\nexport type CreateResourceLinkGroupInput<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources> = ResourceLinkConfigResource<Resources>,\n Icon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = CreateResourceLinkGroupOptions<\n Resources,\n CreateResourceLinkConfig<Resources, Resource, Icon>,\n Icon\n>;\n\ntype ResourceLinkGroupResource<Groups extends ReadonlyArray<unknown>> =\n Groups[number] extends infer Group\n ? Group extends { links: infer Links }\n ? Extract<keyof Links, string>\n : never\n : never;\n\ntype ResourceLinkGroupIcon<Groups extends ReadonlyArray<unknown>> =\n Groups[number] extends infer Group\n ? 'icon' extends keyof Group\n ? Group extends { icon?: infer Icon }\n ? Icon\n : never\n : never\n : never;\n\ntype ResourceLinkGroupLinkIcon<Groups extends ReadonlyArray<unknown>> =\n Groups[number] extends infer Group\n ? Group extends { links: infer Links }\n ? ResourceLinkConfigIcon<Links>\n : never\n : never;\n\nexport type AnyCreatedResourceLink<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Icon = ResourceIcon,\n> = {\n [Resource in LayoutResourceKey<Resources>]:\n | CreatedResourceLinkBase<Resource, Icon>\n | CreateResourceLinkWithHash<Resource, string, Icon>;\n}[LayoutResourceKey<Resources>];\n\nexport type CreateResourceLinksWithGroups<\n Resources extends ReadonlyArray<ResourceDefinition>,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = {\n activeIcon?: ReactNode;\n id: string;\n label: string | null;\n icon: GroupIcon | null;\n links: Array<AnyCreatedResourceLink<Resources, LinkIcon>>;\n};\n\ntype ResolveResourceIcon<Icon> = Icon extends (...args: any[]) => infer Result\n ? Result\n : Icon;\n\nexport type ResolvedResourceLinksWithGroups<\n Resources extends ReadonlyArray<ResourceDefinition>,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = Omit<\n CreateResourceLinksWithGroups<Resources, GroupIcon, LinkIcon>,\n 'icon' | 'links'\n> & {\n icon: ResolveResourceIcon<GroupIcon> | null;\n links: Array<\n Omit<AnyCreatedResourceLink<Resources, LinkIcon>, 'icon'> & {\n icon: ResolveResourceIcon<LinkIcon> | null;\n }\n >;\n};\n\nexport type CreateResourceMap<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Value,\n> = Partial<Record<LayoutResourceKey<Resources>, Value>>;\n\nexport type ValidateResource<\n Resource extends string,\n Map extends object,\n> = Resource extends Extract<keyof Map, string> ? Resource : never;\n\nexport type CreatedResourceMap<Map extends object> = Map & {\n isValidResource(value: unknown): value is Extract<keyof Map, string>;\n get<const Resource extends string>(\n resource: ValidateResource<Resource, Map>,\n ): Map[typeof resource];\n};\n\nexport interface CreateResourceMapFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n /**\n * Creates a resource map for this layout.\n *\n * @param map Values keyed by this layout's resources. An unknown resource,\n * or a key that collides with a map helper, is rejected.\n */\n <const Map extends CreateResourceMap<Resources, unknown>>(\n map: Map,\n ): CreatedResourceMap<Map>;\n}\n\nexport interface CreateResourceLinksWithGroupsFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n /**\n * Groups resource links into sections.\n *\n * @param groups The sections to create. At least one is required. The link\n * keys in those sections are the resources `findResource` can resolve.\n */\n <\n const Resource extends ResourceLinkConfigResource<Resources>,\n const Groups extends ReadonlyArray<unknown>,\n >(\n groups: NonEmptyReadonlyArray<\n CreateResourceLinkGroupInput<Resources, Resource>\n > &\n Groups,\n ): CreateResourceLinksWithGroupsResult<\n Resources,\n ResourceLinkGroupResource<Groups>,\n ResourceLinkGroupIcon<Groups>,\n ResourceLinkGroupLinkIcon<Groups>\n >;\n}\n\nexport type CreateResourceLinksWithGroupsResult<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources> = ResourceLinkConfigResource<Resources>,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = Array<CreateResourceLinksWithGroups<Resources, GroupIcon, LinkIcon>> & {\n /**\n * Resolves each group's icon and its link icons for the active resource.\n *\n * Functional icons receive the resources accessor for `resource`. Read the\n * groups value directly when you do not need to resolve icons.\n *\n * @param resource The active resource key.\n */\n (\n resource: LayoutResourceKey<Resources>,\n ): ResolvedResourceLinksWithGroupsResult<\n Resources,\n Resource,\n GroupIcon,\n LinkIcon\n >;\n /**\n * Creates a resource map for this layout. Same helper as\n * `createResourceLinks.createResourceMap`.\n *\n * @param map Values keyed by this layout's resources. An unknown resource,\n * or a key that collides with a map helper, is rejected.\n */\n createResourceMap: CreateResourceMapFn<Resources>;\n /**\n * Returns the group whose links include `resource`.\n *\n * The result is `undefined` when that resource was not configured in any\n * group. A resource outside this layout is rejected by the type.\n *\n * @param resource The resource whose group should be returned.\n */\n findResource<\n const RequestedResource extends LayoutResourceKey<Resources> | Resource,\n >(\n resource: RequestedResource,\n ): FindResourceGroupResult<\n Resources,\n Resource,\n RequestedResource,\n GroupIcon,\n LinkIcon\n >;\n};\n\nexport type ResolvedResourceLinksWithGroupsResult<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources> = ResourceLinkConfigResource<Resources>,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = Array<\n ResolvedResourceLinksWithGroups<Resources, GroupIcon, LinkIcon>\n> & {\n /** Returns the resolved group whose links include `resource`. */\n findResource<\n const RequestedResource extends LayoutResourceKey<Resources> | Resource,\n >(\n resource: RequestedResource,\n ): FindResolvedResourceGroupResult<\n Resources,\n Resource,\n RequestedResource,\n GroupIcon,\n LinkIcon\n >;\n};\n\nexport type FindResourceGroupResult<\n Resources extends ReadonlyArray<ResourceDefinition>,\n IncludedResource extends string,\n RequestedResource extends string,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = RequestedResource extends unknown\n ? RequestedResource extends IncludedResource\n ? CreateResourceLinksWithGroups<Resources, GroupIcon, LinkIcon>\n : undefined\n : never;\n\nexport type FindResolvedResourceGroupResult<\n Resources extends ReadonlyArray<ResourceDefinition>,\n IncludedResource extends string,\n RequestedResource extends string,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = RequestedResource extends unknown\n ? RequestedResource extends IncludedResource\n ? ResolvedResourceLinksWithGroups<Resources, GroupIcon, LinkIcon>\n : undefined\n : never;\n\nfunction resolveResourceLinkHref<Resource extends string>(\n value: ResourceLinkHref<Resource> | undefined,\n resource: Resource,\n fallback: string,\n) {\n return typeof value === 'function' ? value(resource) : (value ?? fallback);\n}\n\nfunction normalizeResourceLinkHash(hash: string) {\n return hash.replace(/^#+/, '');\n}\n\nfunction createFullResourceLinkHref(href: string, hash: string) {\n if (href.includes('#')) {\n return href;\n }\n\n return `${href}#${normalizeResourceLinkHash(hash)}`;\n}\n\nfunction createResourceLinksFromConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources>,\n>(config: CreateResourceLinkConfig<Resources, Resource>) {\n return Object.entries(config).map(([resource, config]) => {\n if (!config) {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"config\" is required for the ${resource} resource.`,\n );\n }\n\n if (typeof config !== 'object') {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"config\" must be an object for the ${resource} resource. Received ${typeof config}`,\n );\n }\n\n if (!('label' in config)) {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"label\" is required for the ${resource} resource.`,\n );\n }\n\n if (typeof config.label !== 'string') {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"label\" must be a string for the ${resource} resource. Received ${typeof config.label}`,\n );\n }\n\n const linkConfig = config as CreateResourceLinkOptions<\n Resources,\n typeof resource,\n ResourceIcon<LayoutRenderResourcesAccessor<Resources>>\n >;\n\n if (\n 'href' in linkConfig &&\n linkConfig.href !== undefined &&\n typeof linkConfig.href !== 'string' &&\n typeof linkConfig.href !== 'function'\n ) {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"href\" must be a string or function for the ${resource} resource. Received ${typeof linkConfig.href}`,\n );\n }\n\n if (\n 'hash' in linkConfig &&\n linkConfig.hash !== undefined &&\n typeof linkConfig.hash !== 'string' &&\n typeof linkConfig.hash !== 'function'\n ) {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"hash\" must be a string or function for the ${resource} resource. Received ${typeof linkConfig.hash}`,\n );\n }\n\n const givenHref = resolveResourceLinkHref(linkConfig.href, resource, '/');\n const givenHash = resolveResourceLinkHref(\n linkConfig.hash,\n resource,\n resource,\n );\n const href = {\n given: givenHref,\n full: createFullResourceLinkHref(givenHref, givenHash),\n ...(linkConfig.hash !== undefined && !givenHref.includes('#')\n ? { hash: normalizeResourceLinkHash(givenHash) }\n : {}),\n };\n\n return {\n ...(linkConfig.activeIcon !== undefined\n ? { activeIcon: linkConfig.activeIcon }\n : {}),\n href,\n label: config.label,\n resource,\n icon: 'icon' in config ? config.icon : null,\n };\n });\n}\n\n/**\n * Deterministic, not random: a random id (the previous implementation used\n * `crypto.randomUUID()` / `Math.random()`) would make `withGroups()` unsafe to\n * call from module scope — some runtimes (e.g. Cloudflare Workers) disallow\n * generating random values outside a request handler, and config arrays like\n * this are routinely defined as top-level constants.\n *\n * Falls back to the group's own shape — its `label` and its link resource\n * keys — rather than just the array index, so groups from *separate*\n * `withGroups()` calls that get concatenated into one list (a module-owned nav\n * section next to a feature-owned one, say) don't collide just because they're\n * both first in their own call. Two groups that are genuinely identical in\n * shape will still collide; pass an explicit `id` on the group to rule that\n * out entirely.\n */\nfunction createResourceLinkGroupId(\n group: { id?: unknown; label?: unknown; links: object },\n index: number,\n) {\n if (typeof group.id === 'string' && group.id.length > 0) {\n return group.id;\n }\n\n const label = typeof group.label === 'string' ? group.label : '';\n const linkKeys = Object.keys(group.links).join(',');\n return `group-${index}-${label}-${linkKeys}`;\n}\n\nfunction readResourceValue(resource: ResourceDefinition) {\n return typeof resource === 'string' ? resource : resource.value;\n}\n\nfunction createResourceSelection(\n definitions: ReadonlyArray<ResourceDefinition>,\n): ResourceSelection<ReadonlyArray<ResourceDefinition>> {\n const selection = (() => definitions) as ResourceSelection<\n ReadonlyArray<ResourceDefinition>\n >;\n\n selection.isResource = createIsValidResourceFn(definitions);\n\n return selection;\n}\n\nfunction createRenderResourcesAccessor<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(resources: Resources, current: LayoutResourceKey<Resources>) {\n const accessor = Object.assign(() => resources, {\n current,\n }) as LayoutRenderResourcesAccessor<Resources>;\n\n accessor.isResource = createIsValidResourceFn(resources);\n accessor.omit = ((...keys: string[]) =>\n createResourceSelection(\n resources.filter((resource) => !keys.includes(readResourceValue(resource))),\n )) as LayoutRenderResourcesAccessor<Resources>['omit'];\n accessor.pick = ((...keys: string[]) =>\n createResourceSelection(\n resources.filter((resource) => keys.includes(readResourceValue(resource))),\n )) as LayoutRenderResourcesAccessor<Resources>['pick'];\n\n return accessor;\n}\n\nfunction createResourceMapFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(resources: Resources): CreateResourceMapFn<Resources> {\n const helperNames = new Set(['get', 'isValidResource']);\n const resourceKeys = new Set(\n resources.map((resource) =>\n typeof resource === 'string' ? resource : resource.value,\n ),\n );\n\n return function createResourceMap<\n const Map extends CreateResourceMap<Resources, unknown>,\n >(map: Map) {\n const configuredResources = Object.keys(map);\n\n for (const resource of configuredResources) {\n if (!resourceKeys.has(resource)) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.createResourceMap]: unknown resource \"${resource}\".`,\n );\n }\n\n if (helperNames.has(resource)) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.createResourceMap]: resource \"${resource}\" conflicts with a map helper.`,\n );\n }\n }\n\n const configuredResourceKeys = new Set(configuredResources);\n const resourceValues = new Map(\n configuredResources.map((resource) => [\n resource,\n (map as Record<string, unknown>)[resource],\n ]),\n );\n\n Object.defineProperties(map, {\n get: {\n value(resource: string) {\n return resourceValues.get(resource);\n },\n },\n isValidResource: {\n value(value: unknown): value is Extract<keyof Map, string> {\n return (\n typeof value === 'string' && configuredResourceKeys.has(value)\n );\n },\n },\n });\n\n return map as CreatedResourceMap<Map>;\n };\n}\n\nfunction createResourceLinksWithGroups<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources>,\n const Groups extends ReadonlyArray<unknown>,\n>(\n resources: Resources,\n createResourceMap: CreateResourceMapFn<Resources>,\n groups: ReadonlyArray<CreateResourceLinkGroupInput<Resources, Resource>> &\n Groups,\n): CreateResourceLinksWithGroupsResult<\n Resources,\n ResourceLinkGroupResource<Groups>,\n ResourceLinkGroupIcon<Groups>,\n ResourceLinkGroupLinkIcon<Groups>\n> {\n if (!Array.isArray(groups)) {\n throw new LayoutConfigurationError(\n '[createResourceLinks.withGroups]: \"groups\" must be an array.',\n );\n }\n\n if (groups.length === 0) {\n throw new LayoutConfigurationError(\n '[createResourceLinks.withGroups]: \"groups\" must include at least one group.',\n );\n }\n\n const createdGroups = groups.map((group, index) => {\n if (!group) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: group at index ${index} is required.`,\n );\n }\n\n if (typeof group !== 'object') {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: group at index ${index} must be an object. Received ${typeof group}`,\n );\n }\n\n if (\n 'label' in group &&\n group.label !== undefined &&\n typeof group.label !== 'string'\n ) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: \"label\" must be a string for group at index ${index}. Received ${typeof group.label}`,\n );\n }\n\n if ('id' in group && group.id !== undefined && typeof group.id !== 'string') {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: \"id\" must be a string for group at index ${index}. Received ${typeof group.id}`,\n );\n }\n\n if (!('links' in group)) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: \"links\" is required for group at index ${index}.`,\n );\n }\n\n if (\n typeof group.links !== 'object' ||\n group.links === null ||\n Array.isArray(group.links)\n ) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: \"links\" must be an object for group at index ${index}. Received ${Array.isArray(group.links) ? 'array' : typeof group.links}`,\n );\n }\n\n return {\n ...(group.activeIcon !== undefined\n ? { activeIcon: group.activeIcon }\n : {}),\n id: createResourceLinkGroupId(group, index),\n label: 'label' in group ? (group.label ?? null) : null,\n icon: 'icon' in group ? group.icon : null,\n links: createResourceLinksFromConfig(group.links),\n };\n }) as Array<CreateResourceLinksWithGroups<Resources>>;\n\n function resolveGroups(resource?: LayoutResourceKey<Resources>) {\n if (resource === undefined) {\n throw new LayoutConfigurationError(\n '[createResourceLinks.withGroups]: \"resource\" is required.',\n );\n }\n\n const currentResources = createRenderResourcesAccessor(resources, resource);\n\n const resolvedGroups = createdGroups.map((group) => ({\n ...group,\n icon:\n typeof group.icon === 'function'\n ? group.icon(currentResources)\n : group.icon,\n links: group.links.map((link) => ({\n ...link,\n icon:\n typeof link.icon === 'function'\n ? link.icon(currentResources)\n : link.icon,\n })),\n }));\n\n Object.defineProperty(resolvedGroups, 'findResource', {\n value(requestedResource: ResourceLinkConfigResource<Resources>) {\n return resolvedGroups.find((group) =>\n group.links.some((link) => link.resource === requestedResource),\n );\n },\n });\n\n return resolvedGroups as ResolvedResourceLinksWithGroupsResult<\n Resources,\n ResourceLinkGroupResource<Groups>,\n ResourceLinkGroupIcon<Groups>,\n ResourceLinkGroupLinkIcon<Groups>\n >;\n }\n\n const callableGroups = new Proxy(resolveGroups, {\n get(target, property, receiver) {\n if (property === 'createResourceMap') {\n return createResourceMap;\n }\n\n if (property === Symbol.iterator) {\n return createdGroups[Symbol.iterator].bind(createdGroups);\n }\n\n if (property === 'toJSON') {\n return () => createdGroups;\n }\n\n if (property in createdGroups) {\n const value = Reflect.get(createdGroups, property);\n return typeof value === 'function' ? value.bind(createdGroups) : value;\n }\n\n return Reflect.get(target, property, receiver);\n },\n getOwnPropertyDescriptor(target, property) {\n return (\n Reflect.getOwnPropertyDescriptor(createdGroups, property) ??\n Reflect.getOwnPropertyDescriptor(target, property)\n );\n },\n getPrototypeOf() {\n return Array.prototype;\n },\n ownKeys(target) {\n return [\n ...new Set([\n ...Reflect.ownKeys(target),\n ...Reflect.ownKeys(createdGroups),\n ]),\n ];\n },\n set(target, property, value, receiver) {\n if (property in createdGroups || /^\\d+$/.test(String(property))) {\n return Reflect.set(createdGroups, property, value);\n }\n\n return Reflect.set(target, property, value, receiver);\n },\n });\n Object.defineProperty(createdGroups, 'findResource', {\n value(resource: ResourceLinkConfigResource<Resources>) {\n return createdGroups.find((group) =>\n group.links.some((link) => link.resource === resource),\n );\n },\n });\n\n return callableGroups as CreateResourceLinksWithGroupsResult<\n Resources,\n ResourceLinkGroupResource<Groups>,\n ResourceLinkGroupIcon<Groups>,\n ResourceLinkGroupLinkIcon<Groups>\n >;\n}\n\nfunction createDefineIcon<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(): DefineResourceIconFn<Resources> {\n function defineIcon<Icon extends ElementType = ElementType>(\n render: (options: {\n resource: LayoutRenderResourcesAccessor<Resources>;\n Icon: Icon;\n }) => ReactNode,\n ) {\n return function createIcon(Icon: Icon) {\n return function renderIcon(\n resource: LayoutRenderResourcesAccessor<Resources>,\n ) {\n return render({ resource, Icon });\n };\n };\n }\n\n defineIcon.input = function defineIconInput<Definition>(\n defineInput: (\n helpers: DefineResourceIconInputHelpers<Resources>,\n ) => Definition,\n ): DefineResourceIconInputResult<Resources, Definition> {\n const resourceMarker = {} as ResourceIconInputMarker<never>;\n const componentMarker = {} as ResourceIconComponentInputMarker<ElementType>;\n\n defineInput({\n resource() {\n return resourceMarker;\n },\n icon<Icon extends ElementType = ElementType>() {\n return componentMarker as ResourceIconComponentInputMarker<Icon>;\n },\n });\n\n return {\n render(\n render: (options: {\n resource: LayoutRenderResourcesAccessor<Resources>;\n input: ResolveResourceIconInput<Definition>;\n }) => ReactNode,\n ) {\n return function createIcon(\n input: ResolveResourceIconInput<Definition>,\n ) {\n return function renderIcon(\n resource: LayoutRenderResourcesAccessor<Resources>,\n ) {\n return render({ resource, input });\n };\n };\n },\n };\n };\n\n return defineIcon;\n}\n\nexport function createResourceLinksFn<\n const Resources extends ReadonlyArray<ResourceDefinition>,\n>(_resources: Resources): CreateResourceLinksFn<Resources> {\n const createResourceMap = createResourceMapFn(_resources);\n const defineIcon = createDefineIcon<Resources>();\n\n function createResourceLinks<\n const Resource extends ResourceLinkConfigResource<Resources>,\n const Config extends object,\n >(config: CreateResourceLinkConfig<Resources, Resource> & Config) {\n return createResourceLinksFromConfig(config);\n }\n\n function withGroups<\n const Resource extends ResourceLinkConfigResource<Resources>,\n const Groups extends ReadonlyArray<unknown>,\n >(\n groups: NonEmptyReadonlyArray<\n CreateResourceLinkGroupInput<Resources, Resource>\n > &\n Groups,\n ) {\n return createResourceLinksWithGroups(_resources, createResourceMap, groups);\n }\n\n return Object.assign(createResourceLinks, {\n createResourceMap,\n defineIcon,\n withGroups,\n }) as CreateResourceLinksFn<Resources>;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O;AACT;AAEA,SAAgB,sBAEd,YAAyD;CACzD,MAAM,oBAAoB,oBAAoB,UAAU;CACxD,MAAM,aAAa,iBAA4B;CAE/C,SAAS,oBAGP,QAAgE;EAChE,OAAO,8BAA8B,MAAM;CAC7C;CAEA,SAAS,WAIP,QAIA;EACA,OAAO,8BAA8B,YAAY,mBAAmB,MAAM;CAC5E;CAEA,OAAO,OAAO,OAAO,qBAAqB;EACxC;EACA;EACA;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"create-resource-links.mjs","names":[],"sources":["../../src/create-config/create-resource-links.ts"],"sourcesContent":["import type { ElementType, ReactNode } from 'react';\nimport type { NonEmptyReadonlyArray } from '@jfdevelops/react-layout-validator';\nimport {\n createIsValidResourceFn,\n type LayoutResourceKey,\n type ResourceDefinition,\n} from '../resource';\nimport { LayoutConfigurationError } from '../errors';\nimport type {\n LayoutRenderResourcesAccessor,\n ResourceSelection,\n} from './define-layout';\n\nexport type ResourceAnchorLinkFn<Resource extends string> = (\n resource: Resource,\n) => string;\n\nexport type ResourceLinkHref<Resource extends string> =\n | string\n | ResourceAnchorLinkFn<Resource>;\n\nexport type ResourceLinkConfigResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = LayoutResourceKey<Resources> | (string & {});\n\nexport type ResourceIconFn<Resource = any> = (resource: Resource) => ReactNode;\n\nexport type ResourceIcon<Resource = any> = ReactNode | ResourceIconFn<Resource>;\n\ndeclare const resourceIconInputMarker: unique symbol;\ndeclare const resourceIconComponentInputMarker: unique symbol;\n\ntype ResourceIconInputMarker<Value> = {\n readonly [resourceIconInputMarker]: Value;\n};\n\ntype ResourceIconComponentInputMarker<Icon extends ElementType> = {\n readonly [resourceIconComponentInputMarker]: Icon;\n};\n\nexport type ResolveResourceIconInput<Definition> =\n Definition extends ResourceIconComponentInputMarker<infer Icon>\n ? Icon\n : Definition extends ResourceIconInputMarker<infer Value>\n ? Value\n : Definition extends ReadonlyArray<unknown>\n ? { [Index in keyof Definition]: ResolveResourceIconInput<Definition[Index]> }\n : Definition extends object\n ? { [Key in keyof Definition]: ResolveResourceIconInput<Definition[Key]> }\n : Definition;\n\nexport interface DefineResourceIconInputHelpers<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n resource(): ResourceIconInputMarker<LayoutResourceKey<Resources>>;\n icon<Icon extends ElementType = ElementType>(): ResourceIconComponentInputMarker<Icon>;\n}\n\nexport interface DefineResourceIconInputResult<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Definition,\n> {\n render(\n render: (options: {\n resource: LayoutRenderResourcesAccessor<Resources>;\n input: ResolveResourceIconInput<Definition>;\n }) => ReactNode,\n ): (\n input: ResolveResourceIconInput<Definition>,\n ) => ResourceIconFn<LayoutRenderResourcesAccessor<Resources>>;\n}\n\nexport interface DefineResourceIconFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n <Icon extends ElementType = ElementType>(\n render: (options: {\n resource: LayoutRenderResourcesAccessor<Resources>;\n Icon: Icon;\n }) => ReactNode,\n ): (Icon: Icon) => ResourceIconFn<LayoutRenderResourcesAccessor<Resources>>;\n input<Definition>(\n defineInput: (\n helpers: DefineResourceIconInputHelpers<Resources>,\n ) => Definition,\n ): DefineResourceIconInputResult<Resources, Definition>;\n}\nexport interface CreateResourceLinkOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources>,\n Icon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> {\n /**\n * The label of the link. This is the text that will be displayed in the link.\n */\n label: string;\n /**\n * An optional icon to render when the link is active.\n */\n activeIcon?: ReactNode;\n /**\n * An optional icon to register with the link. This is a headless approach, meaning you have full control\n * over the icon's rendering.\n */\n icon?: Icon;\n /**\n * The href of the link. By default, the href will be `\"/\"`. While you **don't** need to include a hash,\n * if you do, it will override the `hash` property (if provided).\n */\n href?: ResourceLinkHref<Resource>;\n /**\n * The hash of the link. By default, the hash will be the resource name. If you need to customize it, you can provide\n * a string or a function that returns a string.\n *\n * @remarks A `\"#\"` is not required. The generated href will include it automatically.\n */\n hash?: ResourceLinkHref<Resource>;\n}\n\nexport type CreateResourceLinkConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources> = ResourceLinkConfigResource<Resources>,\n Icon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = {\n [Key in Resource]?: CreateResourceLinkOptions<\n Resources,\n Key,\n Icon\n >;\n};\n\nexport type InferHashFromResourceLinkHref<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n> = Hash extends string\n ? Hash\n : Hash extends ResourceAnchorLinkFn<Resource>\n ? ReturnType<Hash>\n : never;\n\nexport type CreatedResourceHref = {\n /**\n * The full generated href with the `hash` if provided.\n */\n full: string;\n /**\n * The given href. This is the same value as the `href` property of the config.\n */\n given: string;\n};\n\nexport type CreatedResourceLinkBase<\n Resource extends string,\n Icon = ResourceIcon,\n> = {\n activeIcon?: ReactNode;\n href: CreatedResourceHref;\n label: string;\n resource: Resource;\n icon: Icon | null;\n};\nexport type CreateResourceLinkWithHash<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n Icon = ResourceIcon,\n> = Omit<CreatedResourceLinkBase<Resource, Icon>, 'href'> & {\n href: CreatedResourceHref & {\n hash: InferHashFromResourceLinkHref<Resource, Hash>;\n };\n};\n\nexport type CreatedResourceLink<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Config,\n Icon = ResourceIcon,\n> = {\n [Resource in keyof Config]-?: Resource extends ResourceLinkConfigResource<Resources>\n ? Config[Resource] extends {\n hash: infer hash extends ResourceLinkHref<Resource>;\n }\n ? CreateResourceLinkWithHash<Resource, hash, Icon>\n : CreatedResourceLinkBase<Resource, Icon>\n : never;\n}[keyof Config];\n\ntype ResourceLinkConfigIcon<Config> = {\n [Resource in keyof Config]-?: 'icon' extends keyof NonNullable<\n Config[Resource]\n >\n ? NonNullable<Config[Resource]> extends { icon?: infer Icon }\n ? Icon\n : never\n : never;\n}[keyof Config];\n\nexport interface CreateResourceLinksFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n <\n const Resource extends ResourceLinkConfigResource<Resources>,\n const Config extends object,\n >(\n config: CreateResourceLinkConfig<Resources, Resource> & Config,\n ): Array<\n CreatedResourceLink<\n Resources,\n Config,\n ResourceLinkConfigIcon<Config>\n >\n >;\n createResourceMap: CreateResourceMapFn<Resources>;\n defineIcon: DefineResourceIconFn<Resources>;\n withGroups: CreateResourceLinksWithGroupsFn<Resources>;\n}\n\nexport interface CreateResourceLinkGroupOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Links extends object =\n CreateResourceLinkConfig<Resources>,\n Icon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> {\n /**\n * An optional, caller-provided identity for the group. Provide this when you\n * combine groups from more than one `withGroups()` call into one list (e.g.\n * a module-owned nav section alongside a feature-owned one) — without it,\n * the id is derived from the group's `label` and its link resources, which\n * is enough to keep groups from a single call apart but can't distinguish\n * two independently-defined groups that happen to look identical.\n */\n id?: string;\n /**\n * The label of the group. This is the text that will be displayed for the group.\n */\n label?: string;\n /**\n * An optional icon to render when the group is active.\n */\n activeIcon?: ReactNode;\n /**\n * An optional icon to register with the group. This is a headless approach, meaning you have full control\n * over the icon's rendering.\n */\n icon?: Icon;\n /**\n * The resource links in this group.\n */\n links: Links;\n}\n\nexport type CreateResourceLinkGroupInput<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources> = ResourceLinkConfigResource<Resources>,\n Icon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = CreateResourceLinkGroupOptions<\n Resources,\n CreateResourceLinkConfig<Resources, Resource, Icon>,\n Icon\n>;\n\ntype ResourceLinkGroupResource<Groups extends ReadonlyArray<unknown>> =\n Groups[number] extends infer Group\n ? Group extends { links: infer Links }\n ? Extract<keyof Links, string>\n : never\n : never;\n\ntype ResourceLinkGroupIcon<Groups extends ReadonlyArray<unknown>> =\n Groups[number] extends infer Group\n ? 'icon' extends keyof Group\n ? Group extends { icon?: infer Icon }\n ? Icon\n : never\n : never\n : never;\n\ntype ResourceLinkGroupLinkIcon<Groups extends ReadonlyArray<unknown>> =\n Groups[number] extends infer Group\n ? Group extends { links: infer Links }\n ? ResourceLinkConfigIcon<Links>\n : never\n : never;\n\nexport type AnyCreatedResourceLink<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Icon = ResourceIcon,\n> = {\n [Resource in LayoutResourceKey<Resources>]:\n | CreatedResourceLinkBase<Resource, Icon>\n | CreateResourceLinkWithHash<Resource, string, Icon>;\n}[LayoutResourceKey<Resources>];\n\nexport type CreateResourceLinksWithGroups<\n Resources extends ReadonlyArray<ResourceDefinition>,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = {\n activeIcon?: ReactNode;\n id: string;\n label: string | null;\n icon: GroupIcon | null;\n links: Array<AnyCreatedResourceLink<Resources, LinkIcon>>;\n};\n\ntype ResolveResourceIcon<Icon> = Icon extends (...args: any[]) => infer Result\n ? Result\n : Icon;\n\nexport type ResolvedResourceLinksWithGroups<\n Resources extends ReadonlyArray<ResourceDefinition>,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = Omit<\n CreateResourceLinksWithGroups<Resources, GroupIcon, LinkIcon>,\n 'icon' | 'links'\n> & {\n icon: ResolveResourceIcon<GroupIcon> | null;\n links: Array<\n Omit<AnyCreatedResourceLink<Resources, LinkIcon>, 'icon'> & {\n icon: ResolveResourceIcon<LinkIcon> | null;\n }\n >;\n};\n\nexport type CreateResourceMap<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Value,\n> = Partial<Record<LayoutResourceKey<Resources>, Value>>;\n\nexport type ValidateResource<\n Resource extends string,\n Map extends object,\n> = Resource extends Extract<keyof Map, string> ? Resource : never;\n\nexport type CreatedResourceMap<Map extends object> = Map & {\n isValidResource(value: unknown): value is Extract<keyof Map, string>;\n get<const Resource extends string>(\n resource: ValidateResource<Resource, Map>,\n ): Map[typeof resource];\n};\n\nexport interface CreateResourceMapFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n /**\n * Creates a resource map for this layout.\n *\n * @param map Values keyed by this layout's resources. An unknown resource,\n * or a key that collides with a map helper, is rejected.\n */\n <const Map extends CreateResourceMap<Resources, unknown>>(\n map: Map,\n ): CreatedResourceMap<Map>;\n}\n\nexport interface CreateResourceLinksWithGroupsFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> {\n /**\n * Groups resource links into sections.\n *\n * @param groups The sections to create. At least one is required. The link\n * keys in those sections are the resources `findResource` can resolve.\n */\n <\n const Resource extends ResourceLinkConfigResource<Resources>,\n const Groups extends ReadonlyArray<unknown>,\n >(\n groups: NonEmptyReadonlyArray<\n CreateResourceLinkGroupInput<Resources, Resource>\n > &\n Groups,\n ): CreateResourceLinksWithGroupsResult<\n Resources,\n ResourceLinkGroupResource<Groups>,\n ResourceLinkGroupIcon<Groups>,\n ResourceLinkGroupLinkIcon<Groups>\n >;\n}\n\nexport type CreateResourceLinksWithGroupsResult<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources> = ResourceLinkConfigResource<Resources>,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = Array<CreateResourceLinksWithGroups<Resources, GroupIcon, LinkIcon>> & {\n /**\n * Resolves each group's icon and its link icons for the active resource.\n *\n * Functional icons receive the resources accessor for `resource`. Read the\n * groups value directly when you do not need to resolve icons.\n *\n * @param resource The active resource key.\n */\n <TargetResource extends LayoutResourceKey<Resources>>(\n resource: TargetResource,\n ): ResolvedResourceLinksWithGroupsResult<\n Resources,\n TargetResource,\n GroupIcon,\n LinkIcon\n >;\n /**\n * Creates a resource map for this layout. Same helper as\n * `createResourceLinks.createResourceMap`.\n *\n * @param map Values keyed by this layout's resources. An unknown resource,\n * or a key that collides with a map helper, is rejected.\n */\n createResourceMap: CreateResourceMapFn<Resources>;\n /**\n * Returns the group whose links include `resource`.\n *\n * The result is `undefined` when that resource was not configured in any\n * group. A resource outside this layout is rejected by the type.\n *\n * @param resource The resource whose group should be returned.\n */\n findResource<\n const RequestedResource extends LayoutResourceKey<Resources> | Resource,\n >(\n resource: RequestedResource,\n ): FindResourceGroupResult<\n Resources,\n Resource,\n RequestedResource,\n GroupIcon,\n LinkIcon\n >;\n};\n\nexport type ResolvedResourceLinksWithGroupsResult<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources> = ResourceLinkConfigResource<Resources>,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = Array<\n ResolvedResourceLinksWithGroups<Resources, GroupIcon, LinkIcon>\n> & {\n /** Returns the resolved group whose links include `resource`. */\n findResource<\n const RequestedResource extends LayoutResourceKey<Resources> | Resource,\n >(\n resource: RequestedResource,\n ): FindResolvedResourceGroupResult<\n Resources,\n Resource,\n RequestedResource,\n GroupIcon,\n LinkIcon\n >;\n};\n\nexport type FindResourceGroupResult<\n Resources extends ReadonlyArray<ResourceDefinition>,\n IncludedResource extends string,\n RequestedResource extends string,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = RequestedResource extends unknown\n ? RequestedResource extends IncludedResource\n ? CreateResourceLinksWithGroups<Resources, GroupIcon, LinkIcon>\n : undefined\n : never;\n\nexport type FindResolvedResourceGroupResult<\n Resources extends ReadonlyArray<ResourceDefinition>,\n IncludedResource extends string,\n RequestedResource extends string,\n GroupIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n LinkIcon = ResourceIcon<LayoutRenderResourcesAccessor<Resources>>,\n> = RequestedResource extends unknown\n ? RequestedResource extends IncludedResource\n ? ResolvedResourceLinksWithGroups<Resources, GroupIcon, LinkIcon>\n : undefined\n : never;\n\nfunction resolveResourceLinkHref<Resource extends string>(\n value: ResourceLinkHref<Resource> | undefined,\n resource: Resource,\n fallback: string,\n) {\n return typeof value === 'function' ? value(resource) : (value ?? fallback);\n}\n\nfunction normalizeResourceLinkHash(hash: string) {\n return hash.replace(/^#+/, '');\n}\n\nfunction createFullResourceLinkHref(href: string, hash: string) {\n if (href.includes('#')) {\n return href;\n }\n\n return `${href}#${normalizeResourceLinkHash(hash)}`;\n}\n\nfunction createResourceLinksFromConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources>,\n>(config: CreateResourceLinkConfig<Resources, Resource>) {\n return Object.entries(config).map(([resource, config]) => {\n if (!config) {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"config\" is required for the ${resource} resource.`,\n );\n }\n\n if (typeof config !== 'object') {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"config\" must be an object for the ${resource} resource. Received ${typeof config}`,\n );\n }\n\n if (!('label' in config)) {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"label\" is required for the ${resource} resource.`,\n );\n }\n\n if (typeof config.label !== 'string') {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"label\" must be a string for the ${resource} resource. Received ${typeof config.label}`,\n );\n }\n\n const linkConfig = config as CreateResourceLinkOptions<\n Resources,\n typeof resource,\n ResourceIcon<LayoutRenderResourcesAccessor<Resources>>\n >;\n\n if (\n 'href' in linkConfig &&\n linkConfig.href !== undefined &&\n typeof linkConfig.href !== 'string' &&\n typeof linkConfig.href !== 'function'\n ) {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"href\" must be a string or function for the ${resource} resource. Received ${typeof linkConfig.href}`,\n );\n }\n\n if (\n 'hash' in linkConfig &&\n linkConfig.hash !== undefined &&\n typeof linkConfig.hash !== 'string' &&\n typeof linkConfig.hash !== 'function'\n ) {\n throw new LayoutConfigurationError(\n `[createResourceLinks]: \"hash\" must be a string or function for the ${resource} resource. Received ${typeof linkConfig.hash}`,\n );\n }\n\n const givenHref = resolveResourceLinkHref(linkConfig.href, resource, '/');\n const givenHash = resolveResourceLinkHref(\n linkConfig.hash,\n resource,\n resource,\n );\n const href = {\n given: givenHref,\n full: createFullResourceLinkHref(givenHref, givenHash),\n ...(linkConfig.hash !== undefined && !givenHref.includes('#')\n ? { hash: normalizeResourceLinkHash(givenHash) }\n : {}),\n };\n\n return {\n ...(linkConfig.activeIcon !== undefined\n ? { activeIcon: linkConfig.activeIcon }\n : {}),\n href,\n label: config.label,\n resource,\n icon: 'icon' in config ? config.icon : null,\n };\n });\n}\n\n/**\n * Deterministic, not random: a random id (the previous implementation used\n * `crypto.randomUUID()` / `Math.random()`) would make `withGroups()` unsafe to\n * call from module scope — some runtimes (e.g. Cloudflare Workers) disallow\n * generating random values outside a request handler, and config arrays like\n * this are routinely defined as top-level constants.\n *\n * Falls back to the group's own shape — its `label` and its link resource\n * keys — rather than just the array index, so groups from *separate*\n * `withGroups()` calls that get concatenated into one list (a module-owned nav\n * section next to a feature-owned one, say) don't collide just because they're\n * both first in their own call. Two groups that are genuinely identical in\n * shape will still collide; pass an explicit `id` on the group to rule that\n * out entirely.\n */\nfunction createResourceLinkGroupId(\n group: { id?: unknown; label?: unknown; links: object },\n index: number,\n) {\n if (typeof group.id === 'string' && group.id.length > 0) {\n return group.id;\n }\n\n const label = typeof group.label === 'string' ? group.label : '';\n const linkKeys = Object.keys(group.links).join(',');\n return `group-${index}-${label}-${linkKeys}`;\n}\n\nfunction readResourceValue(resource: ResourceDefinition) {\n return typeof resource === 'string' ? resource : resource.value;\n}\n\nfunction createResourceSelection(\n definitions: ReadonlyArray<ResourceDefinition>,\n): ResourceSelection<ReadonlyArray<ResourceDefinition>> {\n const selection = (() => definitions) as ResourceSelection<\n ReadonlyArray<ResourceDefinition>\n >;\n\n selection.isResource = createIsValidResourceFn(definitions);\n\n return selection;\n}\n\nfunction createRenderResourcesAccessor<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(resources: Resources, current: LayoutResourceKey<Resources>) {\n const accessor = Object.assign(() => resources, {\n current,\n }) as LayoutRenderResourcesAccessor<Resources>;\n\n accessor.isResource = createIsValidResourceFn(resources);\n accessor.omit = ((...keys: string[]) =>\n createResourceSelection(\n resources.filter((resource) => !keys.includes(readResourceValue(resource))),\n )) as LayoutRenderResourcesAccessor<Resources>['omit'];\n accessor.pick = ((...keys: string[]) =>\n createResourceSelection(\n resources.filter((resource) => keys.includes(readResourceValue(resource))),\n )) as LayoutRenderResourcesAccessor<Resources>['pick'];\n\n return accessor;\n}\n\nfunction createResourceMapFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(resources: Resources): CreateResourceMapFn<Resources> {\n const helperNames = new Set(['get', 'isValidResource']);\n const resourceKeys = new Set(\n resources.map((resource) =>\n typeof resource === 'string' ? resource : resource.value,\n ),\n );\n\n return function createResourceMap<\n const Map extends CreateResourceMap<Resources, unknown>,\n >(map: Map) {\n const configuredResources = Object.keys(map);\n\n for (const resource of configuredResources) {\n if (!resourceKeys.has(resource)) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.createResourceMap]: unknown resource \"${resource}\".`,\n );\n }\n\n if (helperNames.has(resource)) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.createResourceMap]: resource \"${resource}\" conflicts with a map helper.`,\n );\n }\n }\n\n const configuredResourceKeys = new Set(configuredResources);\n const resourceValues = new Map(\n configuredResources.map((resource) => [\n resource,\n (map as Record<string, unknown>)[resource],\n ]),\n );\n\n Object.defineProperties(map, {\n get: {\n value(resource: string) {\n return resourceValues.get(resource);\n },\n },\n isValidResource: {\n value(value: unknown): value is Extract<keyof Map, string> {\n return (\n typeof value === 'string' && configuredResourceKeys.has(value)\n );\n },\n },\n });\n\n return map as CreatedResourceMap<Map>;\n };\n}\n\nfunction createResourceLinksWithGroups<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends ResourceLinkConfigResource<Resources>,\n const Groups extends ReadonlyArray<unknown>,\n>(\n resources: Resources,\n createResourceMap: CreateResourceMapFn<Resources>,\n groups: ReadonlyArray<CreateResourceLinkGroupInput<Resources, Resource>> &\n Groups,\n): CreateResourceLinksWithGroupsResult<\n Resources,\n ResourceLinkGroupResource<Groups>,\n ResourceLinkGroupIcon<Groups>,\n ResourceLinkGroupLinkIcon<Groups>\n> {\n if (!Array.isArray(groups)) {\n throw new LayoutConfigurationError(\n '[createResourceLinks.withGroups]: \"groups\" must be an array.',\n );\n }\n\n if (groups.length === 0) {\n throw new LayoutConfigurationError(\n '[createResourceLinks.withGroups]: \"groups\" must include at least one group.',\n );\n }\n\n const createdGroups = groups.map((group, index) => {\n if (!group) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: group at index ${index} is required.`,\n );\n }\n\n if (typeof group !== 'object') {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: group at index ${index} must be an object. Received ${typeof group}`,\n );\n }\n\n if (\n 'label' in group &&\n group.label !== undefined &&\n typeof group.label !== 'string'\n ) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: \"label\" must be a string for group at index ${index}. Received ${typeof group.label}`,\n );\n }\n\n if ('id' in group && group.id !== undefined && typeof group.id !== 'string') {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: \"id\" must be a string for group at index ${index}. Received ${typeof group.id}`,\n );\n }\n\n if (!('links' in group)) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: \"links\" is required for group at index ${index}.`,\n );\n }\n\n if (\n typeof group.links !== 'object' ||\n group.links === null ||\n Array.isArray(group.links)\n ) {\n throw new LayoutConfigurationError(\n `[createResourceLinks.withGroups]: \"links\" must be an object for group at index ${index}. Received ${Array.isArray(group.links) ? 'array' : typeof group.links}`,\n );\n }\n\n return {\n ...(group.activeIcon !== undefined\n ? { activeIcon: group.activeIcon }\n : {}),\n id: createResourceLinkGroupId(group, index),\n label: 'label' in group ? (group.label ?? null) : null,\n icon: 'icon' in group ? group.icon : null,\n links: createResourceLinksFromConfig(group.links),\n };\n }) as Array<CreateResourceLinksWithGroups<Resources>>;\n\n function resolveGroups(resource?: LayoutResourceKey<Resources>) {\n if (resource === undefined) {\n throw new LayoutConfigurationError(\n '[createResourceLinks.withGroups]: \"resource\" is required.',\n );\n }\n\n const currentResources = createRenderResourcesAccessor(resources, resource);\n\n const resolvedGroups = createdGroups.map((group) => ({\n ...group,\n icon:\n typeof group.icon === 'function'\n ? group.icon(currentResources)\n : group.icon,\n links: group.links.map((link) => ({\n ...link,\n icon:\n typeof link.icon === 'function'\n ? link.icon(currentResources)\n : link.icon,\n })),\n }));\n\n Object.defineProperty(resolvedGroups, 'findResource', {\n value(requestedResource: ResourceLinkConfigResource<Resources>) {\n return resolvedGroups.find((group) =>\n group.links.some((link) => link.resource === requestedResource),\n );\n },\n });\n\n return resolvedGroups as ResolvedResourceLinksWithGroupsResult<\n Resources,\n ResourceLinkGroupResource<Groups>,\n ResourceLinkGroupIcon<Groups>,\n ResourceLinkGroupLinkIcon<Groups>\n >;\n }\n\n const callableGroups = new Proxy(resolveGroups, {\n get(target, property, receiver) {\n if (property === 'createResourceMap') {\n return createResourceMap;\n }\n\n if (property === Symbol.iterator) {\n return createdGroups[Symbol.iterator].bind(createdGroups);\n }\n\n if (property === 'toJSON') {\n return () => createdGroups;\n }\n\n if (property in createdGroups) {\n const value = Reflect.get(createdGroups, property);\n return typeof value === 'function' ? value.bind(createdGroups) : value;\n }\n\n return Reflect.get(target, property, receiver);\n },\n getOwnPropertyDescriptor(target, property) {\n return (\n Reflect.getOwnPropertyDescriptor(createdGroups, property) ??\n Reflect.getOwnPropertyDescriptor(target, property)\n );\n },\n getPrototypeOf() {\n return Array.prototype;\n },\n ownKeys(target) {\n return [\n ...new Set([\n ...Reflect.ownKeys(target),\n ...Reflect.ownKeys(createdGroups),\n ]),\n ];\n },\n set(target, property, value, receiver) {\n if (property in createdGroups || /^\\d+$/.test(String(property))) {\n return Reflect.set(createdGroups, property, value);\n }\n\n return Reflect.set(target, property, value, receiver);\n },\n });\n Object.defineProperty(createdGroups, 'findResource', {\n value(resource: ResourceLinkConfigResource<Resources>) {\n return createdGroups.find((group) =>\n group.links.some((link) => link.resource === resource),\n );\n },\n });\n\n return callableGroups as CreateResourceLinksWithGroupsResult<\n Resources,\n ResourceLinkGroupResource<Groups>,\n ResourceLinkGroupIcon<Groups>,\n ResourceLinkGroupLinkIcon<Groups>\n >;\n}\n\nfunction createDefineIcon<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(): DefineResourceIconFn<Resources> {\n function defineIcon<Icon extends ElementType = ElementType>(\n render: (options: {\n resource: LayoutRenderResourcesAccessor<Resources>;\n Icon: Icon;\n }) => ReactNode,\n ) {\n return function createIcon(Icon: Icon) {\n return function renderIcon(\n resource: LayoutRenderResourcesAccessor<Resources>,\n ) {\n return render({ resource, Icon });\n };\n };\n }\n\n defineIcon.input = function defineIconInput<Definition>(\n defineInput: (\n helpers: DefineResourceIconInputHelpers<Resources>,\n ) => Definition,\n ): DefineResourceIconInputResult<Resources, Definition> {\n const resourceMarker = {} as ResourceIconInputMarker<never>;\n const componentMarker = {} as ResourceIconComponentInputMarker<ElementType>;\n\n defineInput({\n resource() {\n return resourceMarker;\n },\n icon<Icon extends ElementType = ElementType>() {\n return componentMarker as ResourceIconComponentInputMarker<Icon>;\n },\n });\n\n return {\n render(\n render: (options: {\n resource: LayoutRenderResourcesAccessor<Resources>;\n input: ResolveResourceIconInput<Definition>;\n }) => ReactNode,\n ) {\n return function createIcon(\n input: ResolveResourceIconInput<Definition>,\n ) {\n return function renderIcon(\n resource: LayoutRenderResourcesAccessor<Resources>,\n ) {\n return render({ resource, input });\n };\n };\n },\n };\n };\n\n return defineIcon;\n}\n\nexport function createResourceLinksFn<\n const Resources extends ReadonlyArray<ResourceDefinition>,\n>(_resources: Resources): CreateResourceLinksFn<Resources> {\n const createResourceMap = createResourceMapFn(_resources);\n const defineIcon = createDefineIcon<Resources>();\n\n function createResourceLinks<\n const Resource extends ResourceLinkConfigResource<Resources>,\n const Config extends object,\n >(config: CreateResourceLinkConfig<Resources, Resource> & Config) {\n return createResourceLinksFromConfig(config);\n }\n\n function withGroups<\n const Resource extends ResourceLinkConfigResource<Resources>,\n const Groups extends ReadonlyArray<unknown>,\n >(\n groups: NonEmptyReadonlyArray<\n CreateResourceLinkGroupInput<Resources, Resource>\n > &\n Groups,\n ) {\n return createResourceLinksWithGroups(_resources, createResourceMap, groups);\n }\n\n return Object.assign(createResourceLinks, {\n createResourceMap,\n defineIcon,\n withGroups,\n }) as CreateResourceLinksFn<Resources>;\n}\n"],"mappings":";;;;AA4dA,SAAS,wBACP,OACA,UACA,UACA;CACA,OAAO,OAAO,UAAU,aAAa,MAAM,QAAQ,IAAK,SAAS;AACnE;AAEA,SAAS,0BAA0B,MAAc;CAC/C,OAAO,KAAK,QAAQ,OAAO,EAAE;AAC/B;AAEA,SAAS,2BAA2B,MAAc,MAAc;CAC9D,IAAI,KAAK,SAAS,GAAG,GACnB,OAAO;CAGT,OAAO,GAAG,KAAK,GAAG,0BAA0B,IAAI;AAClD;AAEA,SAAS,8BAGP,QAAuD;CACvD,OAAO,OAAO,QAAQ,MAAM,EAAE,KAAK,CAAC,UAAU,YAAY;EACxD,IAAI,CAAC,QACH,MAAM,IAAI,yBACR,uDAAuD,SAAS,WAClE;EAGF,IAAI,OAAO,WAAW,UACpB,MAAM,IAAI,yBACR,6DAA6D,SAAS,sBAAsB,OAAO,QACrG;EAGF,IAAI,EAAE,WAAW,SACf,MAAM,IAAI,yBACR,sDAAsD,SAAS,WACjE;EAGF,IAAI,OAAO,OAAO,UAAU,UAC1B,MAAM,IAAI,yBACR,2DAA2D,SAAS,sBAAsB,OAAO,OAAO,OAC1G;EAGF,MAAM,aAA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AAC;CAED,OAAO;AAMT;AAEA,SAAS,mBAE4B;CACnC,SAAS,WACP,QAIA;EACA,OAAO,SAAS,WAAW,MAAY;GACrC,OAAO,SAAS,WACd,UACA;IACA,OAAO,OAAO;KAAE;KAAU;IAAK,CAAC;GAClC;EACF;CACF;CAEA,WAAW,QAAQ,SAAS,gBAC1B,aAGsD;EACtD,MAAM,iBAAiB,CAAC;EACxB,MAAM,kBAAkB,CAAC;EAEzB,YAAY;GACV,WAAW;IACT,OAAO;GACT;GACA,OAA+C;IAC7C,OAAO;GACT;EACF,CAAC;EAED,OAAO,EACL,OACE,QAIA;GACA,OAAO,SAAS,WACd,OACA;IACA,OAAO,SAAS,WACd,UACA;KACA,OAAO,OAAO;MAAE;MAAU;KAAM,CAAC;IACnC;GACF;EACF,EACF;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,sBAEd,YAAyD;CACzD,MAAM,oBAAoB,oBAAoB,UAAU;CACxD,MAAM,aAAa,iBAA4B;CAE/C,SAAS,oBAGP,QAAgE;EAChE,OAAO,8BAA8B,MAAM;CAC7C;CAEA,SAAS,WAIP,QAIA;EACA,OAAO,8BAA8B,YAAY,mBAAmB,MAAM;CAC5E;CAEA,OAAO,OAAO,OAAO,qBAAqB;EACxC;EACA;EACA;CACF,CAAC;AACH"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_invalid_config = require('../errors/invalid-config.cjs');
|
|
2
2
|
const require_missing_resource_provider = require('../errors/missing-resource-provider.cjs');
|
|
3
3
|
const require_layout_configuration_error = require('../errors/layout-configuration-error.cjs');
|
|
4
|
+
const require_resource_state_error = require('../errors/resource-state-error.cjs');
|
|
4
5
|
const require_resource = require('../resource.cjs');
|
|
5
6
|
const require_utils = require('../utils.cjs');
|
|
6
7
|
const require_capitalize = require('../utils/capitalize.cjs');
|
|
@@ -10,12 +11,31 @@ const require_create_resource_links = require('./create-resource-links.cjs');
|
|
|
10
11
|
const require_for_resource = require('./for-resource.cjs');
|
|
11
12
|
const require_create_for_resources = require('./for-resources/create-for-resources.cjs');
|
|
12
13
|
const require_shell_context = require('./shell-context.cjs');
|
|
14
|
+
const require_render_state = require('./render-state.cjs');
|
|
13
15
|
let _jfdevelops_react_layout_composables = require("@jfdevelops/react-layout-composables");
|
|
14
16
|
let react = require("react");
|
|
15
17
|
let _jfdevelops_react_layout_validator = require("@jfdevelops/react-layout-validator");
|
|
16
18
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
17
19
|
|
|
18
20
|
//#region src/create-config/define-layout.tsx
|
|
21
|
+
const RenderStateRetryContext = (0, react.createContext)(void 0);
|
|
22
|
+
var RenderStateBoundary = class extends react.Component {
|
|
23
|
+
state = {};
|
|
24
|
+
static getDerivedStateFromError(error) {
|
|
25
|
+
return { error };
|
|
26
|
+
}
|
|
27
|
+
retry = () => {
|
|
28
|
+
this.props.onRetry?.();
|
|
29
|
+
this.setState({ error: void 0 });
|
|
30
|
+
};
|
|
31
|
+
render() {
|
|
32
|
+
if (this.state.error !== void 0) return this.props.fallback(this.state.error, this.retry);
|
|
33
|
+
return this.props.children;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
function toResourceStateError(resource, state, error) {
|
|
37
|
+
return error instanceof require_resource_state_error.ResourceModuleLoadError || error instanceof require_resource_state_error.ResourceRenderError ? error : new require_resource_state_error.ResourceRenderError(resource, state, error);
|
|
38
|
+
}
|
|
19
39
|
function createResourceSelection(definitions) {
|
|
20
40
|
const selection = (() => definitions);
|
|
21
41
|
selection.isResource = require_resource.createIsValidResourceFn(definitions);
|
|
@@ -88,6 +108,15 @@ function resolveLayoutOptionDefaults(defaults, options) {
|
|
|
88
108
|
else resolved[key] = require_utils.functionalUpdate(defaultValue, options[key]);
|
|
89
109
|
return resolved;
|
|
90
110
|
}
|
|
111
|
+
function getSynchronousRenderStateDefinition(input, fallbackProps) {
|
|
112
|
+
if (require_render_state.isLazyRenderState(input)) return;
|
|
113
|
+
if (require_render_state.isDeferredRenderState(input)) return input[require_render_state.deferredRenderStateSymbol];
|
|
114
|
+
if (typeof input === "function") return {
|
|
115
|
+
props: fallbackProps,
|
|
116
|
+
render: input
|
|
117
|
+
};
|
|
118
|
+
return typeof input === "object" && input !== null ? input : void 0;
|
|
119
|
+
}
|
|
91
120
|
function readResourceSlug(resource) {
|
|
92
121
|
return typeof resource === "string" ? resource : resource.value;
|
|
93
122
|
}
|
|
@@ -129,7 +158,15 @@ function defineResourceLayoutImpl(options) {
|
|
|
129
158
|
...instancePropDefinitions,
|
|
130
159
|
...layoutOptionProps
|
|
131
160
|
});
|
|
132
|
-
const { composables,
|
|
161
|
+
const { composables, props: legacyLayoutProps } = layout;
|
|
162
|
+
const renderStates = typeof layout.render === "function" ? { default: layout.render } : layout.render;
|
|
163
|
+
const defaultRenderInput = renderStates.default;
|
|
164
|
+
const createdDefaultState = require_render_state.isDeferredRenderState(defaultRenderInput) || require_render_state.isLazyRenderState(defaultRenderInput);
|
|
165
|
+
const defaultRenderDefinition = getSynchronousRenderStateDefinition(defaultRenderInput, legacyLayoutProps) ?? { render: () => null };
|
|
166
|
+
if (typeof defaultRenderDefinition !== "object" || defaultRenderDefinition === null || !("render" in defaultRenderDefinition) || typeof defaultRenderDefinition.render !== "function") throw new require_layout_configuration_error.LayoutConfigurationError("The \"default\" render state must define a render function");
|
|
167
|
+
const defaultState = defaultRenderDefinition;
|
|
168
|
+
const render = defaultState.render;
|
|
169
|
+
const layoutProps = defaultState.props ?? legacyLayoutProps;
|
|
133
170
|
const customLayoutProps = layoutProps?.custom;
|
|
134
171
|
const includeLayoutProps = layoutProps?.include;
|
|
135
172
|
const layoutOptionValues = layoutOptionProps;
|
|
@@ -143,7 +180,11 @@ function defineResourceLayoutImpl(options) {
|
|
|
143
180
|
layoutName: name,
|
|
144
181
|
resource: layoutContext.resource
|
|
145
182
|
};
|
|
146
|
-
const
|
|
183
|
+
const defaultComposables = defaultState.composables ? (create) => ({
|
|
184
|
+
...composables?.(create) ?? {},
|
|
185
|
+
...defaultState.composables?.(create)
|
|
186
|
+
}) : composables;
|
|
187
|
+
const resolvedComposables = defaultComposables ? (0, _jfdevelops_react_layout_composables.resolveLayoutComposables)(defaultComposables, layoutContext) : void 0;
|
|
147
188
|
const mergedResolvedInProps = { ...resolvedInProps };
|
|
148
189
|
for (const { props: presetPropDefinitions } of (0, _jfdevelops_react_layout_composables.collectComposablePresetEntries)(resolvedComposables)) Object.assign(mergedResolvedInProps, presetPropDefinitions);
|
|
149
190
|
const composablePresetProps = Object.fromEntries((0, _jfdevelops_react_layout_composables.collectComposablePresetEntries)(resolvedComposables).map(({ key, props: presetPropDefinitions }) => {
|
|
@@ -160,6 +201,12 @@ function defineResourceLayoutImpl(options) {
|
|
|
160
201
|
name: layoutContext.name,
|
|
161
202
|
inProps: splitInProps
|
|
162
203
|
};
|
|
204
|
+
const stateComponents = {};
|
|
205
|
+
let CreatedDefaultStateComponent;
|
|
206
|
+
function RenderDefaultState({ renderProps }) {
|
|
207
|
+
if (CreatedDefaultStateComponent) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CreatedDefaultStateComponent, { ...renderProps });
|
|
208
|
+
return render(renderProps, mergedRenderContext);
|
|
209
|
+
}
|
|
163
210
|
function Component(props) {
|
|
164
211
|
const publishResource = require_shell_context.useResourceLayoutShellPublisher();
|
|
165
212
|
(0, react.useLayoutEffect)(() => {
|
|
@@ -193,26 +240,153 @@ function defineResourceLayoutImpl(options) {
|
|
|
193
240
|
...validatedProps,
|
|
194
241
|
...layoutRenderIncludedProps
|
|
195
242
|
};
|
|
196
|
-
|
|
243
|
+
const rendered = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResourceProvider, {
|
|
197
244
|
resource: layoutContext.resource,
|
|
198
245
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_jfdevelops_react_layout_composables.LayoutComposablePresetProvider, {
|
|
199
246
|
value: composablePresetProps,
|
|
200
|
-
children:
|
|
247
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderDefaultState, { renderProps: layoutRenderProps })
|
|
201
248
|
})
|
|
202
249
|
});
|
|
250
|
+
const ErrorComponent = stateComponents.Error;
|
|
251
|
+
return ErrorComponent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderStateBoundary, {
|
|
252
|
+
fallback: (error, retry) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderStateRetryContext.Provider, {
|
|
253
|
+
value: retry,
|
|
254
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, {
|
|
255
|
+
error: toResourceStateError(String(layoutContext.resource), "default", error),
|
|
256
|
+
retry
|
|
257
|
+
})
|
|
258
|
+
}),
|
|
259
|
+
children: rendered
|
|
260
|
+
}) : rendered;
|
|
203
261
|
}
|
|
204
262
|
function createComposition(compositionOptions) {
|
|
205
263
|
if (!compositionOptions.components) return {};
|
|
206
264
|
return { makeComposable: createComposableLayout(compositionOptions) };
|
|
207
265
|
}
|
|
208
|
-
|
|
266
|
+
function createStateComponent(stateName, input) {
|
|
267
|
+
if (require_render_state.isLazyRenderState(input)) {
|
|
268
|
+
const loadState = input[require_render_state.lazyRenderStateSymbol];
|
|
269
|
+
function createLazyState() {
|
|
270
|
+
return (0, react.lazy)(async () => {
|
|
271
|
+
const stateDefinition = require_render_state.findDefinedRenderState(await loadState().catch((error) => {
|
|
272
|
+
throw new require_resource_state_error.ResourceModuleLoadError(String(layoutContext.resource), error);
|
|
273
|
+
}));
|
|
274
|
+
if (stateDefinition.state !== void 0 && stateDefinition.state !== stateName) throw new require_layout_configuration_error.LayoutConfigurationError(`Lazy render state "${stateDefinition.state}" cannot be used as "${stateName}"`);
|
|
275
|
+
return { default: createLoadedStateComponent(stateName, stateDefinition) };
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
function LazyStateComponent(props) {
|
|
279
|
+
const [, rerender] = (0, react.useReducer)((version) => version + 1, 0);
|
|
280
|
+
const LazyState = (0, react.useRef)(createLazyState());
|
|
281
|
+
const CurrentLazyState = LazyState.current;
|
|
282
|
+
const LoadingComponent = stateName === "Loading" ? void 0 : stateComponents.Loading;
|
|
283
|
+
const ErrorComponent = stateName === "Error" ? void 0 : stateComponents.Error;
|
|
284
|
+
function retry() {
|
|
285
|
+
LazyState.current = createLazyState();
|
|
286
|
+
rerender();
|
|
287
|
+
}
|
|
288
|
+
const rendered = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
|
|
289
|
+
fallback: LoadingComponent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingComponent, {}) : null,
|
|
290
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CurrentLazyState, { ...props })
|
|
291
|
+
});
|
|
292
|
+
return ErrorComponent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderStateBoundary, {
|
|
293
|
+
fallback: (error, reset) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderStateRetryContext.Provider, {
|
|
294
|
+
value: reset,
|
|
295
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, {
|
|
296
|
+
error: toResourceStateError(String(layoutContext.resource), stateName, error),
|
|
297
|
+
retry: reset
|
|
298
|
+
})
|
|
299
|
+
}),
|
|
300
|
+
onRetry: retry,
|
|
301
|
+
children: rendered
|
|
302
|
+
}) : rendered;
|
|
303
|
+
}
|
|
304
|
+
return LazyStateComponent;
|
|
305
|
+
}
|
|
306
|
+
const definition = require_render_state.isDeferredRenderState(input) ? input[require_render_state.deferredRenderStateSymbol] : typeof input === "function" ? { render: input } : input;
|
|
307
|
+
if (typeof definition !== "object" || definition === null || !("render" in definition) || typeof definition.render !== "function") throw new require_layout_configuration_error.LayoutConfigurationError(`Render state "${stateName}" must define a render function`);
|
|
308
|
+
const StateComponent = createLoadedStateComponent(stateName, definition);
|
|
309
|
+
if (!require_render_state.isDeferredRenderState(input)) return StateComponent;
|
|
310
|
+
const DeferredState = (0, react.lazy)(() => Promise.resolve({ default: StateComponent }));
|
|
311
|
+
function DeferredStateComponent(props) {
|
|
312
|
+
const LoadingComponent = stateName === "Loading" ? void 0 : stateComponents.Loading;
|
|
313
|
+
const ErrorComponent = stateName === "Error" ? void 0 : stateComponents.Error;
|
|
314
|
+
const rendered = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
|
|
315
|
+
fallback: LoadingComponent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingComponent, {}) : null,
|
|
316
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DeferredState, { ...props })
|
|
317
|
+
});
|
|
318
|
+
return ErrorComponent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderStateBoundary, {
|
|
319
|
+
fallback: (error, retry) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderStateRetryContext.Provider, {
|
|
320
|
+
value: retry,
|
|
321
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorComponent, {
|
|
322
|
+
error: toResourceStateError(String(layoutContext.resource), stateName, error),
|
|
323
|
+
retry
|
|
324
|
+
})
|
|
325
|
+
}),
|
|
326
|
+
children: rendered
|
|
327
|
+
}) : rendered;
|
|
328
|
+
}
|
|
329
|
+
return DeferredStateComponent;
|
|
330
|
+
}
|
|
331
|
+
function createLoadedStateComponent(stateName, definition) {
|
|
332
|
+
const stateComposables = definition.composables ? (create) => ({
|
|
333
|
+
...composables?.(create) ?? {},
|
|
334
|
+
...definition.composables?.(create)
|
|
335
|
+
}) : composables;
|
|
336
|
+
const stateRender = stateName === "Error" ? (props, context) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderStateRetryContext.Consumer, { children: (retry) => definition.render(props, {
|
|
337
|
+
...context,
|
|
338
|
+
retry
|
|
339
|
+
}) }) : definition.render;
|
|
340
|
+
const StateComponent = defineResourceLayoutImpl({
|
|
341
|
+
resources,
|
|
342
|
+
options: inProps,
|
|
343
|
+
layout: {
|
|
344
|
+
composables: stateComposables,
|
|
345
|
+
props: definition.props,
|
|
346
|
+
render: stateRender
|
|
347
|
+
}
|
|
348
|
+
}).createResourceLayout(layoutOptions);
|
|
349
|
+
StateComponent.displayName = `${name}.${stateName}`;
|
|
350
|
+
return StateComponent;
|
|
351
|
+
}
|
|
352
|
+
if (createdDefaultState) CreatedDefaultStateComponent = createStateComponent("default", defaultRenderInput);
|
|
353
|
+
for (const [stateName, input] of Object.entries(renderStates)) {
|
|
354
|
+
if (stateName === "default") continue;
|
|
355
|
+
if ([
|
|
356
|
+
"__proto__",
|
|
357
|
+
"apply",
|
|
358
|
+
"arguments",
|
|
359
|
+
"bind",
|
|
360
|
+
"call",
|
|
361
|
+
"caller",
|
|
362
|
+
"displayName",
|
|
363
|
+
"length",
|
|
364
|
+
"makeComposable",
|
|
365
|
+
"name",
|
|
366
|
+
"props",
|
|
367
|
+
"prototype",
|
|
368
|
+
"resource"
|
|
369
|
+
].includes(stateName)) throw new require_layout_configuration_error.LayoutConfigurationError(`Render state name "${stateName}" is reserved`);
|
|
370
|
+
stateComponents[stateName] = createStateComponent(stateName, input);
|
|
371
|
+
}
|
|
372
|
+
const includedComponentDefinitions = Object.fromEntries(Object.keys(includeLayoutProps ?? {}).flatMap((key) => {
|
|
373
|
+
if (!allowsComponentPassthrough(includeLayoutProps?.[key]) || !(key in mergedResolvedInProps)) return [];
|
|
374
|
+
const definition = mergedResolvedInProps[key];
|
|
375
|
+
return [[key, isIncludedPropRequired(includeLayoutProps?.[key]) ? definition : definition.optional?.() ?? definition]];
|
|
376
|
+
}));
|
|
377
|
+
return (0, _jfdevelops_react_layout_validator.attachComponentPropDefinitions)(Object.assign(Component, {
|
|
209
378
|
displayName: name,
|
|
210
379
|
props: void 0,
|
|
211
380
|
resource: void 0,
|
|
212
381
|
...createComposition({
|
|
213
382
|
components: resolvedComposables,
|
|
214
383
|
name
|
|
215
|
-
})
|
|
384
|
+
}),
|
|
385
|
+
...stateComponents,
|
|
386
|
+
[require_render_state.definedResourceLayoutComponentSymbol]: true
|
|
387
|
+
}), {
|
|
388
|
+
...customLayoutProps,
|
|
389
|
+
...includedComponentDefinitions
|
|
216
390
|
});
|
|
217
391
|
});
|
|
218
392
|
const createTopLevelMakeComposable = () => {
|
|
@@ -228,7 +402,12 @@ function defineResourceLayoutImpl(options) {
|
|
|
228
402
|
resource: resourcesEnum,
|
|
229
403
|
name: _jfdevelops_react_layout_validator.createProp.string().literal(componentName)
|
|
230
404
|
}) : inProps);
|
|
231
|
-
const
|
|
405
|
+
const defaultState = getSynchronousRenderStateDefinition((typeof layout.render === "function" ? { default: layout.render } : layout.render).default, layout.props);
|
|
406
|
+
const defaultComposables = defaultState?.composables ? (create) => ({
|
|
407
|
+
...layout.composables?.(create) ?? {},
|
|
408
|
+
...defaultState.composables?.(create)
|
|
409
|
+
}) : layout.composables;
|
|
410
|
+
const resolvedComposables = defaultComposables ? (0, _jfdevelops_react_layout_composables.resolveLayoutComposables)(defaultComposables, {
|
|
232
411
|
resource,
|
|
233
412
|
name: componentName,
|
|
234
413
|
capitalize: require_capitalize.capitalize
|
|
@@ -236,7 +415,7 @@ function defineResourceLayoutImpl(options) {
|
|
|
236
415
|
for (const { props: presetPropDefinitions } of (0, _jfdevelops_react_layout_composables.collectComposablePresetEntries)(resolvedComposables)) Object.assign(resolvedInProps, presetPropDefinitions);
|
|
237
416
|
return {
|
|
238
417
|
...resolvedInProps,
|
|
239
|
-
...layout.props?.custom
|
|
418
|
+
...(defaultState?.props ?? layout.props)?.custom
|
|
240
419
|
};
|
|
241
420
|
}
|
|
242
421
|
const { createLayoutForResourceBuilder, forResource } = require_for_resource.createForResource({
|