@jfdevelops/react-layout 0.15.1 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-config/define-layout.cjs +15 -4
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +31 -5
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +31 -5
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +14 -3
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/create-config/for-resources/create-component.d.cts +284 -0
- package/dist/create-config/for-resources/create-component.d.cts.map +1 -0
- package/dist/create-config/for-resources/create-component.d.mts +284 -0
- package/dist/create-config/for-resources/create-component.d.mts.map +1 -0
- package/dist/create-config/{for-resources.cjs → for-resources/create-for-resources.cjs} +78 -39
- package/dist/create-config/for-resources/create-for-resources.cjs.map +1 -0
- package/dist/create-config/for-resources/create-for-resources.d.cts +1 -0
- package/dist/create-config/for-resources/create-for-resources.d.mts +1 -0
- package/dist/create-config/{for-resources.mjs → for-resources/create-for-resources.mjs} +77 -38
- package/dist/create-config/for-resources/create-for-resources.mjs.map +1 -0
- package/dist/create-config/for-resources/index.d.cts +1 -0
- package/dist/create-config/for-resources/index.d.mts +1 -0
- package/dist/create-config/for-resources/resource-selection.d.cts +47 -0
- package/dist/create-config/for-resources/resource-selection.d.cts.map +1 -0
- package/dist/create-config/for-resources/resource-selection.d.mts +47 -0
- package/dist/create-config/for-resources/resource-selection.d.mts.map +1 -0
- package/dist/create-config/for-resources/scoped-layout.d.cts +185 -0
- package/dist/create-config/for-resources/scoped-layout.d.cts.map +1 -0
- package/dist/create-config/for-resources/scoped-layout.d.mts +185 -0
- package/dist/create-config/for-resources/scoped-layout.d.mts.map +1 -0
- package/dist/create-config/for-resources/scoped-render.cjs +103 -0
- package/dist/create-config/for-resources/scoped-render.cjs.map +1 -0
- package/dist/create-config/for-resources/scoped-render.d.cts +18 -0
- package/dist/create-config/for-resources/scoped-render.d.cts.map +1 -0
- package/dist/create-config/for-resources/scoped-render.d.mts +18 -0
- package/dist/create-config/for-resources/scoped-render.d.mts.map +1 -0
- package/dist/create-config/for-resources/scoped-render.mjs +100 -0
- package/dist/create-config/for-resources/scoped-render.mjs.map +1 -0
- package/dist/create-config/index.d.cts +1 -1
- package/dist/create-config/index.d.mts +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/props.d.cts +22 -1
- package/dist/props.d.cts.map +1 -1
- package/dist/props.d.mts +22 -1
- package/dist/props.d.mts.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/create-config/for-resources.cjs.map +0 -1
- package/dist/create-config/for-resources.d.cts +0 -358
- package/dist/create-config/for-resources.d.cts.map +0 -1
- package/dist/create-config/for-resources.d.mts +0 -358
- package/dist/create-config/for-resources.d.mts.map +0 -1
- package/dist/create-config/for-resources.mjs.map +0 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createElement, isValidElement } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/create-config/for-resources/scoped-render.ts
|
|
4
|
+
/**
|
|
5
|
+
* Names a scoped component cannot use. Scoped components are attached to
|
|
6
|
+
* function objects, so they collide with the component's own statics and with
|
|
7
|
+
* non-writable `Function.prototype` properties. `__proto__` is reserved so
|
|
8
|
+
* assignment cannot hit the prototype setter on a normal object.
|
|
9
|
+
*/
|
|
10
|
+
const reservedScopedComponentNames = new Set([
|
|
11
|
+
"__proto__",
|
|
12
|
+
"apply",
|
|
13
|
+
"arguments",
|
|
14
|
+
"bind",
|
|
15
|
+
"call",
|
|
16
|
+
"caller",
|
|
17
|
+
"displayName",
|
|
18
|
+
"length",
|
|
19
|
+
"name",
|
|
20
|
+
"props",
|
|
21
|
+
"prototype",
|
|
22
|
+
"resource"
|
|
23
|
+
]);
|
|
24
|
+
/**
|
|
25
|
+
* `$$typeof` tags for object component wrappers that `createElement` accepts
|
|
26
|
+
* as `type` (forwardRef, memo, lazy).
|
|
27
|
+
*
|
|
28
|
+
* Do not treat "any object with `$$typeof`" as a component: portals also have
|
|
29
|
+
* `$$typeof` (`Symbol.for('react.portal')`) and `isValidElement(portal)` is
|
|
30
|
+
* false, so a naive check would mis-classify them.
|
|
31
|
+
*/
|
|
32
|
+
const reactForwardRefType = Symbol.for("react.forward_ref");
|
|
33
|
+
const reactMemoType = Symbol.for("react.memo");
|
|
34
|
+
const reactLazyType = Symbol.for("react.lazy");
|
|
35
|
+
/**
|
|
36
|
+
* True when `value` can be passed as the `type` argument to `createElement`.
|
|
37
|
+
*
|
|
38
|
+
* Functions always qualify. Object wrappers qualify only for the forwardRef /
|
|
39
|
+
* memo / lazy tags above — not portals or other React nodes that happen to
|
|
40
|
+
* carry `$$typeof`.
|
|
41
|
+
*/
|
|
42
|
+
function isRenderableComponentType(value) {
|
|
43
|
+
if (typeof value === "function") return true;
|
|
44
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || isValidElement(value) || !("$$typeof" in value)) return false;
|
|
45
|
+
const typeTag = value.$$typeof;
|
|
46
|
+
return typeTag === reactForwardRefType || typeTag === reactMemoType || typeTag === reactLazyType;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* If `render` returned a component type, mount it with `props`; otherwise
|
|
50
|
+
* return the node as-is (elements, portals, null, etc.).
|
|
51
|
+
*/
|
|
52
|
+
function resolveScopedRenderResult(result, props = {}) {
|
|
53
|
+
if (isRenderableComponentType(result)) return createElement(result, props);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Runtime counterpart of `ScopedComponentCompoundStaticKey` — keys that must
|
|
58
|
+
* not be treated as compound component statics on a scoped wrapper.
|
|
59
|
+
*/
|
|
60
|
+
const reservedScopedCompoundStaticKeys = new Set([
|
|
61
|
+
"apply",
|
|
62
|
+
"arguments",
|
|
63
|
+
"bind",
|
|
64
|
+
"call",
|
|
65
|
+
"caller",
|
|
66
|
+
"childContextTypes",
|
|
67
|
+
"contextTypes",
|
|
68
|
+
"defaultProps",
|
|
69
|
+
"displayName",
|
|
70
|
+
"length",
|
|
71
|
+
"name",
|
|
72
|
+
"propTypes",
|
|
73
|
+
"prototype",
|
|
74
|
+
"toLocaleString",
|
|
75
|
+
"toString",
|
|
76
|
+
"valueOf",
|
|
77
|
+
"$$typeof"
|
|
78
|
+
]);
|
|
79
|
+
/**
|
|
80
|
+
* Exposes compound statics (e.g. `DataTable.Loading`) on a scoped wrapper so
|
|
81
|
+
* runtime matches `ScopedComponentCompoundStatics`.
|
|
82
|
+
*
|
|
83
|
+
* Why a Proxy: JSX reads `components.DataTable.Loading` while building the
|
|
84
|
+
* element tree — before `DataTable` itself renders — so statics cannot be
|
|
85
|
+
* copied only after the first `render` call. Property access lazily creates a
|
|
86
|
+
* stable wrapper component that re-runs the scoped `render` under context and
|
|
87
|
+
* mounts the matching static from the returned component type.
|
|
88
|
+
*/
|
|
89
|
+
function withScopedCompoundStatics(wrapper, createCompoundStatic) {
|
|
90
|
+
return new Proxy(wrapper, { get(target, property, receiver) {
|
|
91
|
+
if (typeof property === "symbol" || reservedScopedCompoundStaticKeys.has(property) || property in target) return Reflect.get(target, property, receiver);
|
|
92
|
+
const CompoundStatic = createCompoundStatic(property);
|
|
93
|
+
target[property] = CompoundStatic;
|
|
94
|
+
return CompoundStatic;
|
|
95
|
+
} });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
export { isRenderableComponentType, reservedScopedComponentNames, resolveScopedRenderResult, withScopedCompoundStatics };
|
|
100
|
+
//# sourceMappingURL=scoped-render.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-render.mjs","names":[],"sources":["../../../src/create-config/for-resources/scoped-render.ts"],"sourcesContent":["import {\n createElement,\n isValidElement,\n type ComponentType,\n type JSX,\n type ReactNode,\n} from 'react';\n\n/**\n * Names a scoped component cannot use. Scoped components are attached to\n * function objects, so they collide with the component's own statics and with\n * non-writable `Function.prototype` properties. `__proto__` is reserved so\n * assignment cannot hit the prototype setter on a normal object.\n */\nexport const reservedScopedComponentNames = new Set([\n '__proto__',\n 'apply',\n 'arguments',\n 'bind',\n 'call',\n 'caller',\n 'displayName',\n 'length',\n 'name',\n 'props',\n 'prototype',\n 'resource',\n]);\n\n/**\n * Values a createComponent / scoped-component `render` may return.\n *\n * Alongside rendered nodes, a component type is allowed — the type constituent\n * of a React element — so factories like `createDataTable(columns)` can be\n * returned directly and mounted with the call-site props.\n *\n * At runtime, `resolveScopedRenderResult` distinguishes component types from\n * nodes (including portals). Getting that wrong mounts a portal via\n * `createElement` and blows up with an invalid-element-type error.\n */\n// Returned components declare their own props; a concrete props parameter would\n// be contravariant and reject the factories callers actually return.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above\nexport type ScopedRenderResult = ReactNode | ComponentType<any>;\n\n/**\n * `$$typeof` tags for object component wrappers that `createElement` accepts\n * as `type` (forwardRef, memo, lazy).\n *\n * Do not treat \"any object with `$$typeof`\" as a component: portals also have\n * `$$typeof` (`Symbol.for('react.portal')`) and `isValidElement(portal)` is\n * false, so a naive check would mis-classify them.\n */\nconst reactForwardRefType = Symbol.for('react.forward_ref');\nconst reactMemoType = Symbol.for('react.memo');\nconst reactLazyType = Symbol.for('react.lazy');\n\n/**\n * True when `value` can be passed as the `type` argument to `createElement`.\n *\n * Functions always qualify. Object wrappers qualify only for the forwardRef /\n * memo / lazy tags above — not portals or other React nodes that happen to\n * carry `$$typeof`.\n */\nexport function isRenderableComponentType(\n value: unknown,\n): value is ComponentType<Record<string, unknown>> {\n if (typeof value === 'function') {\n return true;\n }\n\n if (\n typeof value !== 'object' ||\n value === null ||\n Array.isArray(value) ||\n isValidElement(value) ||\n !('$$typeof' in value)\n ) {\n return false;\n }\n\n const typeTag = (value as { $$typeof: unknown }).$$typeof;\n\n return (\n typeTag === reactForwardRefType ||\n typeTag === reactMemoType ||\n typeTag === reactLazyType\n );\n}\n\n/**\n * If `render` returned a component type, mount it with `props`; otherwise\n * return the node as-is (elements, portals, null, etc.).\n */\nexport function resolveScopedRenderResult(\n result: ScopedRenderResult,\n props: Record<string, unknown> = {},\n): JSX.Element {\n if (isRenderableComponentType(result)) {\n return createElement(result, props);\n }\n\n return result as JSX.Element;\n}\n\n/**\n * Runtime counterpart of `ScopedComponentCompoundStaticKey` — keys that must\n * not be treated as compound component statics on a scoped wrapper.\n */\nconst reservedScopedCompoundStaticKeys = new Set<PropertyKey>([\n 'apply',\n 'arguments',\n 'bind',\n 'call',\n 'caller',\n 'childContextTypes',\n 'contextTypes',\n 'defaultProps',\n 'displayName',\n 'length',\n 'name',\n 'propTypes',\n 'prototype',\n 'toLocaleString',\n 'toString',\n 'valueOf',\n '$$typeof',\n]);\n\ntype ScopedComponentWrapper = ((\n props?: Record<string, unknown>,\n) => JSX.Element) &\n Record<string, unknown>;\n\n/**\n * Exposes compound statics (e.g. `DataTable.Loading`) on a scoped wrapper so\n * runtime matches `ScopedComponentCompoundStatics`.\n *\n * Why a Proxy: JSX reads `components.DataTable.Loading` while building the\n * element tree — before `DataTable` itself renders — so statics cannot be\n * copied only after the first `render` call. Property access lazily creates a\n * stable wrapper component that re-runs the scoped `render` under context and\n * mounts the matching static from the returned component type.\n */\nexport function withScopedCompoundStatics(\n wrapper: (props?: Record<string, unknown>) => JSX.Element,\n createCompoundStatic: (\n staticName: string,\n ) => (ownProps?: Record<string, unknown>) => JSX.Element,\n): ScopedComponentWrapper {\n return new Proxy(wrapper as ScopedComponentWrapper, {\n get(target, property, receiver) {\n if (\n typeof property === 'symbol' ||\n reservedScopedCompoundStaticKeys.has(property) ||\n property in target\n ) {\n return Reflect.get(target, property, receiver);\n }\n\n // Cache on the target so repeated `.Loading` access keeps one identity.\n const CompoundStatic = createCompoundStatic(property);\n target[property] = CompoundStatic;\n return CompoundStatic;\n },\n });\n}\n"],"mappings":";;;;;;;;;AAcA,MAAa,+BAA+B,IAAI,IAAI;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;AA0BD,MAAM,sBAAsB,OAAO,IAAI,mBAAmB;AAC1D,MAAM,gBAAgB,OAAO,IAAI,YAAY;AAC7C,MAAM,gBAAgB,OAAO,IAAI,YAAY;;;;;;;;AAS7C,SAAgB,0BACd,OACiD;CACjD,IAAI,OAAO,UAAU,YACnB,OAAO;CAGT,IACE,OAAO,UAAU,YACjB,UAAU,QACV,MAAM,QAAQ,KAAK,KACnB,eAAe,KAAK,KACpB,EAAE,cAAc,QAEhB,OAAO;CAGT,MAAM,UAAW,MAAgC;CAEjD,OACE,YAAY,uBACZ,YAAY,iBACZ,YAAY;AAEhB;;;;;AAMA,SAAgB,0BACd,QACA,QAAiC,CAAC,GACrB;CACb,IAAI,0BAA0B,MAAM,GAClC,OAAO,cAAc,QAAQ,KAAK;CAGpC,OAAO;AACT;;;;;AAMA,MAAM,mCAAmC,IAAI,IAAiB;CAC5D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;;AAiBD,SAAgB,0BACd,SACA,sBAGwB;CACxB,OAAO,IAAI,MAAM,SAAmC,EAClD,IAAI,QAAQ,UAAU,UAAU;EAC9B,IACE,OAAO,aAAa,YACpB,iCAAiC,IAAI,QAAQ,KAC7C,YAAY,QAEZ,OAAO,QAAQ,IAAI,QAAQ,UAAU,QAAQ;EAI/C,MAAM,iBAAiB,qBAAqB,QAAQ;EACpD,OAAO,YAAY;EACnB,OAAO;CACT,EACF,CAAC;AACH"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BaseResourceConfigComponents, ResourceConfig, ResourceConfigComponentKey, ResourceConfigComponents, ResourceConfigInput, ResourceConfigMap, SharedResourceConfigOptions, SubResourceConfig, SubResourceConfigComponentsFor } from "./types.cjs";
|
|
2
2
|
import { CreateResourceConfigFn, CreatedResourceConfig, GetComponent, GetComponentAtBound, GetComponentForResource, GetComponentForResourceOptions, GetComponentOptions, GetComponentOptionsForResource, ResourceFromGetComponentBound, SubResourceFromGetComponentBound, ValidateForResourceBound } from "./get-component.cjs";
|
|
3
3
|
import { CreateResourceLinkConfig, CreateResourceLinkGroupInput, CreateResourceLinkGroupOptions, CreateResourceLinkOptions, CreateResourceLinksFn, CreateResourceLinksWithGroups, CreateResourceLinksWithGroupsFn, CreatedResourceHref, CreatedResourceLink, CreatedResourceLinkBase, InferHashFromResourceLinkHref, ResourceAnchorLinkFn, ResourceLinkHref } from "./create-resource-links.cjs";
|
|
4
|
-
import { CreateResourceLayoutFn, CreateResourceLayoutMakeComposableOptions, defineResourceLayout } from "./define-layout.cjs";
|
|
4
|
+
import { CreateResourceLayoutFn, CreateResourceLayoutMakeComposableOptions, DefineResourceLayout, DefineResourceLayoutFn, DefineResourceLayoutForResources, DefineResourceLayoutForResourcesFactory, defineResourceLayout } from "./define-layout.cjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BaseResourceConfigComponents, ResourceConfig, ResourceConfigComponentKey, ResourceConfigComponents, ResourceConfigInput, ResourceConfigMap, SharedResourceConfigOptions, SubResourceConfig, SubResourceConfigComponentsFor } from "./types.mjs";
|
|
2
2
|
import { CreateResourceConfigFn, CreatedResourceConfig, GetComponent, GetComponentAtBound, GetComponentForResource, GetComponentForResourceOptions, GetComponentOptions, GetComponentOptionsForResource, ResourceFromGetComponentBound, SubResourceFromGetComponentBound, ValidateForResourceBound } from "./get-component.mjs";
|
|
3
3
|
import { CreateResourceLinkConfig, CreateResourceLinkGroupInput, CreateResourceLinkGroupOptions, CreateResourceLinkOptions, CreateResourceLinksFn, CreateResourceLinksWithGroups, CreateResourceLinksWithGroupsFn, CreatedResourceHref, CreatedResourceLink, CreatedResourceLinkBase, InferHashFromResourceLinkHref, ResourceAnchorLinkFn, ResourceLinkHref } from "./create-resource-links.mjs";
|
|
4
|
-
import { CreateResourceLayoutFn, CreateResourceLayoutMakeComposableOptions, defineResourceLayout } from "./define-layout.mjs";
|
|
4
|
+
import { CreateResourceLayoutFn, CreateResourceLayoutMakeComposableOptions, DefineResourceLayout, DefineResourceLayoutFn, DefineResourceLayoutForResources, DefineResourceLayoutForResourcesFactory, defineResourceLayout } from "./define-layout.mjs";
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseComponent, MergeIntersection, Show, UnionToIntersection, pick } from "./utils.cjs";
|
|
2
2
|
import { LayoutResourceKey, NormalizeResource, NormalizeResources, ResourceDefinition, ResourceEnum, ResourceLayoutComponentProps, ResourceTree, normalizeResource, normalizeResources, toResourceEnum } from "./resource.cjs";
|
|
3
|
-
import { InPropsDefinition, InPropsFunction, InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps, MergedLayoutInProps, ResolvedIncludedProps, ResolvedIncludedPropsAsDefined } from "./props.cjs";
|
|
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
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 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 };
|
|
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 };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseComponent, MergeIntersection, Show, UnionToIntersection, pick } from "./utils.mjs";
|
|
2
2
|
import { LayoutResourceKey, NormalizeResource, NormalizeResources, ResourceDefinition, ResourceEnum, ResourceLayoutComponentProps, ResourceTree, normalizeResource, normalizeResources, toResourceEnum } from "./resource.mjs";
|
|
3
|
-
import { InPropsDefinition, InPropsFunction, InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps, MergedLayoutInProps, ResolvedIncludedProps, ResolvedIncludedPropsAsDefined } from "./props.mjs";
|
|
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
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 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 };
|
|
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 };
|
package/dist/props.d.cts
CHANGED
|
@@ -4,6 +4,27 @@ import { ComposableComponents, InPropsObject, MergePresetProps } from "@jfdevelo
|
|
|
4
4
|
import { EnumWrappedProp, LiteralWrappedProp, ResolveLayoutProps, ResolveLayoutPropsAsDefined, ResolveProps } from "@jfdevelops/react-layout-validator";
|
|
5
5
|
|
|
6
6
|
//#region src/props.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Two-argument `render(props, context)` used by createComponent and scoped
|
|
9
|
+
* resource components. `Context` is sibling components (scoped) or the
|
|
10
|
+
* resource render context (top-level).
|
|
11
|
+
*/
|
|
12
|
+
type PropsContextRender<RenderProps, Context, Result = unknown> = (props: RenderProps, context: Context) => Result;
|
|
13
|
+
/**
|
|
14
|
+
* Shared `{ props?, render }` shape used by createComponent, scoped
|
|
15
|
+
* components, and anywhere else a value declares props and a two-arg render.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam Props - Declared on the entry (`props`). Often an
|
|
18
|
+
* {@link InPropsObject}, or a layout include/custom bag.
|
|
19
|
+
* @typeParam RenderProps - First argument to `render` (defaults to
|
|
20
|
+
* {@link ResolveProps}<Props> when Props is an {@link InPropsObject})
|
|
21
|
+
* @typeParam Result - `render` return type
|
|
22
|
+
* @typeParam Context - Second argument to `render`
|
|
23
|
+
*/
|
|
24
|
+
interface PropsRenderDefinition<Props = InPropsObject, RenderProps = (Props extends InPropsObject ? ResolveProps<Props> : unknown), Result = unknown, Context = unknown> {
|
|
25
|
+
props?: Props;
|
|
26
|
+
render: PropsContextRender<RenderProps, Context, Result>;
|
|
27
|
+
}
|
|
7
28
|
type InPropsOptions<Resources extends ReadonlyArray<ResourceDefinition>, Name extends string> = {
|
|
8
29
|
name: LiteralWrappedProp<Name, 'string', 'required'>;
|
|
9
30
|
resource: EnumWrappedProp<ResourceEnum<Resources>, 'string', 'required'>;
|
|
@@ -26,5 +47,5 @@ type ResolvedIncludedProps<Props extends InPropsObject, IncludeProps extends Inc
|
|
|
26
47
|
type ResolvedIncludedPropsAsDefined<Props extends InPropsObject, IncludeProps extends IncludedProps<Props>> = ResolveLayoutPropsAsDefined<Pick<Props, RequiredIncludedPropKeys<IncludeProps> & keyof Props>> & Partial<ResolveLayoutPropsAsDefined<Pick<Props, OptionalIncludedPropKeys<IncludeProps> & keyof Props>>>;
|
|
27
48
|
type LayoutRenderProps<Resources extends ReadonlyArray<ResourceDefinition>, Options extends InPropsDefinition<Resources>, Composables extends ComposableComponents = {}, IncludeProps extends IncludedProps<MergedLayoutInProps<Resources, Options, Composables>> = {}, CustomProps extends InPropsObject = {}> = Show<ResolveProps<CustomProps> & ResolvedIncludedProps<MergedLayoutInProps<Resources, Options, Composables>, IncludeProps>>;
|
|
28
49
|
//#endregion
|
|
29
|
-
export { InPropsDefinition, InPropsFunction, type InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps, MergedLayoutInProps, ResolvedIncludedProps, ResolvedIncludedPropsAsDefined };
|
|
50
|
+
export { InPropsDefinition, InPropsFunction, type InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps, MergedLayoutInProps, PropsContextRender, PropsRenderDefinition, ResolvedIncludedProps, ResolvedIncludedPropsAsDefined };
|
|
30
51
|
//# sourceMappingURL=props.d.cts.map
|
package/dist/props.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props.d.cts","names":[],"sources":["../src/props.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"props.d.cts","names":[],"sources":["../src/props.ts"],"mappings":";;;;;;AAmBA;;;;;AAAA,KAAY,kBAAA,4CAIP,KAAA,EAAO,WAAA,EAAa,OAAA,EAAS,OAAA,KAAY,MAAA;;;;;;;;;;;;UAa7B,qBAAA,SACP,aAAA,iBACM,KAAA,SAAc,aAAA,GAAgB,YAAA,CAAa,KAAA;EAIzD,KAAA,GAAQ,KAAA;EACR,MAAA,EAAQ,kBAAA,CAAmB,WAAA,EAAa,OAAA,EAAS,MAAA;AAAA;AAAA,KAGvC,cAAA,mBACQ,aAAA,CAAc,kBAAA;EA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AAA,EAAO,wBAAA,CAAyB,YAAA,UAAsB,KAAA;AAAA,KAGrD,iBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,uBACd,oBAAA,4BACC,aAAA,CACnB,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,6BAEtB,aAAA,SAClB,IAAA,CACF,YAAA,CAAa,WAAA,IACX,qBAAA,CACE,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,GACxC,YAAA"}
|
package/dist/props.d.mts
CHANGED
|
@@ -4,6 +4,27 @@ import { ComposableComponents, InPropsObject, MergePresetProps } from "@jfdevelo
|
|
|
4
4
|
import { EnumWrappedProp, LiteralWrappedProp, ResolveLayoutProps, ResolveLayoutPropsAsDefined, ResolveProps } from "@jfdevelops/react-layout-validator";
|
|
5
5
|
|
|
6
6
|
//#region src/props.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Two-argument `render(props, context)` used by createComponent and scoped
|
|
9
|
+
* resource components. `Context` is sibling components (scoped) or the
|
|
10
|
+
* resource render context (top-level).
|
|
11
|
+
*/
|
|
12
|
+
type PropsContextRender<RenderProps, Context, Result = unknown> = (props: RenderProps, context: Context) => Result;
|
|
13
|
+
/**
|
|
14
|
+
* Shared `{ props?, render }` shape used by createComponent, scoped
|
|
15
|
+
* components, and anywhere else a value declares props and a two-arg render.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam Props - Declared on the entry (`props`). Often an
|
|
18
|
+
* {@link InPropsObject}, or a layout include/custom bag.
|
|
19
|
+
* @typeParam RenderProps - First argument to `render` (defaults to
|
|
20
|
+
* {@link ResolveProps}<Props> when Props is an {@link InPropsObject})
|
|
21
|
+
* @typeParam Result - `render` return type
|
|
22
|
+
* @typeParam Context - Second argument to `render`
|
|
23
|
+
*/
|
|
24
|
+
interface PropsRenderDefinition<Props = InPropsObject, RenderProps = (Props extends InPropsObject ? ResolveProps<Props> : unknown), Result = unknown, Context = unknown> {
|
|
25
|
+
props?: Props;
|
|
26
|
+
render: PropsContextRender<RenderProps, Context, Result>;
|
|
27
|
+
}
|
|
7
28
|
type InPropsOptions<Resources extends ReadonlyArray<ResourceDefinition>, Name extends string> = {
|
|
8
29
|
name: LiteralWrappedProp<Name, 'string', 'required'>;
|
|
9
30
|
resource: EnumWrappedProp<ResourceEnum<Resources>, 'string', 'required'>;
|
|
@@ -26,5 +47,5 @@ type ResolvedIncludedProps<Props extends InPropsObject, IncludeProps extends Inc
|
|
|
26
47
|
type ResolvedIncludedPropsAsDefined<Props extends InPropsObject, IncludeProps extends IncludedProps<Props>> = ResolveLayoutPropsAsDefined<Pick<Props, RequiredIncludedPropKeys<IncludeProps> & keyof Props>> & Partial<ResolveLayoutPropsAsDefined<Pick<Props, OptionalIncludedPropKeys<IncludeProps> & keyof Props>>>;
|
|
27
48
|
type LayoutRenderProps<Resources extends ReadonlyArray<ResourceDefinition>, Options extends InPropsDefinition<Resources>, Composables extends ComposableComponents = {}, IncludeProps extends IncludedProps<MergedLayoutInProps<Resources, Options, Composables>> = {}, CustomProps extends InPropsObject = {}> = Show<ResolveProps<CustomProps> & ResolvedIncludedProps<MergedLayoutInProps<Resources, Options, Composables>, IncludeProps>>;
|
|
28
49
|
//#endregion
|
|
29
|
-
export { InPropsDefinition, InPropsFunction, type InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps, MergedLayoutInProps, ResolvedIncludedProps, ResolvedIncludedPropsAsDefined };
|
|
50
|
+
export { InPropsDefinition, InPropsFunction, type InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps, MergedLayoutInProps, PropsContextRender, PropsRenderDefinition, ResolvedIncludedProps, ResolvedIncludedPropsAsDefined };
|
|
30
51
|
//# sourceMappingURL=props.d.mts.map
|
package/dist/props.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props.d.mts","names":[],"sources":["../src/props.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"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ACI,aAAA,uBACO,aAAA,CAAc,KAAA,KACjC,kBAAA,CACF,IAAA,CAAK,KAAA,EAAO,wBAAA,CAAyB,YAAA,UAAsB,KAAA,KAE3D,OAAA,CACE,kBAAA,CACE,IAAA,CAAK,KAAA,EAAO,wBAAA,CAAyB,YAAA,UAAsB,KAAA;;;;;KAQrD,8BAAA,eACI,aAAA,uBACO,aAAA,CAAc,KAAA,KACjC,2BAAA,CACF,IAAA,CAAK,KAAA,EAAO,wBAAA,CAAyB,YAAA,UAAsB,KAAA,KAE3D,OAAA,CACE,2BAAA,CACE,IAAA,CAAK,KAAA,EAAO,wBAAA,CAAyB,YAAA,UAAsB,KAAA;AAAA,KAGrD,iBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,uBACd,oBAAA,4BACC,aAAA,CACnB,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,6BAEtB,aAAA,SAClB,IAAA,CACF,YAAA,CAAa,WAAA,IACX,qBAAA,CACE,mBAAA,CAAoB,SAAA,EAAW,OAAA,EAAS,WAAA,GACxC,YAAA"}
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["export type Show<T> = T extends (...args: infer A) => infer R\n ? (...args: A) => R\n : { [K in keyof T]: T[K] } & {};\nexport type MergeIntersection<T> = {\n [Key in keyof T]: T[Key];\n};\nexport type IsUnion<T, U = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\nexport type UnionToIntersection<Union> = (\n Union extends unknown ? (value: Union) => void : never\n) extends (value: infer Intersection) => void\n ? Intersection\n : never;\nexport type Updater<T> = T | ((prev: T) => T);\n\nexport interface BaseComponent<Name extends string, Props = {}> {\n /**\n * The name of the component. Useful for debugging and error messages.\n */\n displayName: Name;\n /**\n * A type only property to get the type of the props. At runtime,\n * this is `undefined`.\n */\n props: Props;\n}\n\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: K[]) {\n if (keys.length === 0) {\n return {} as Pick<T, K>;\n }\n\n return keys.reduce(\n (acc, key) => {\n if (key in obj) acc[key] = obj[key];\n\n return acc;\n },\n {} as Pick<T, K>,\n );\n}\n\nexport function functionalUpdate<T>(value: T, updater: Updater<T>){\n if (typeof updater === 'function') {\n return (updater as (prev: T) => T)(value);\n }\n\n return updater;\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["export type Show<T> = T extends (...args: infer A) => infer R\n ? (...args: A) => R\n : { [K in keyof T]: T[K] } & {};\nexport type MergeIntersection<T> = {\n [Key in keyof T]: T[Key];\n};\nexport type IsUnion<T, U = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\nexport type UnionToIntersection<Union> = (\n Union extends unknown ? (value: Union) => void : never\n) extends (value: infer Intersection) => void\n ? Intersection\n : never;\nexport type Updater<T> = T | ((prev: T) => T);\nexport type OptionalRecord<K extends string, V = unknown> = {\n [key in K]?: V;\n};\n\nexport interface BaseComponent<Name extends string, Props = {}> {\n /**\n * The name of the component. Useful for debugging and error messages.\n */\n displayName: Name;\n /**\n * A type only property to get the type of the props. At runtime,\n * this is `undefined`.\n */\n props: Props;\n}\n\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: K[]) {\n if (keys.length === 0) {\n return {} as Pick<T, K>;\n }\n\n return keys.reduce(\n (acc, key) => {\n if (key in obj) acc[key] = obj[key];\n\n return acc;\n },\n {} as Pick<T, K>,\n );\n}\n\nexport function functionalUpdate<T>(value: T, updater: Updater<T>){\n if (typeof updater === 'function') {\n return (updater as (prev: T) => T)(value);\n }\n\n return updater;\n}\n"],"mappings":";;AAiCA,SAAgB,KAA0C,KAAQ,MAAW;CAC3E,IAAI,KAAK,WAAW,GAClB,OAAO,CAAC;CAGV,OAAO,KAAK,QACT,KAAK,QAAQ;EACZ,IAAI,OAAO,KAAK,IAAI,OAAO,IAAI;EAE/B,OAAO;CACT,GACA,CAAC,CACH;AACF;AAEA,SAAgB,iBAAoB,OAAU,SAAoB;CAChE,IAAI,OAAO,YAAY,YACrB,OAAQ,QAA2B,KAAK;CAG1C,OAAO;AACT"}
|
package/dist/utils.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","names":[],"sources":["../src/utils.ts"],"mappings":";KAAY,IAAA,MAAU,CAAA,cAAc,IAAA,6BAC5B,IAAA,EAAM,CAAA,KAAM,CAAA,iBACF,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KACZ,iBAAA,sBACI,CAAA,GAAI,CAAA,CAAE,GAAA;AAAA,KAOV,mBAAA,WACV,KAAA,oBAAyB,KAAA,EAAO,KAAK,6BAC5B,KAAA,iCACP,YAAA;AAAA,KAEQ,OAAA,MAAa,CAAA,KAAM,IAAA,EAAM,CAAA,KAAM,CAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"utils.d.cts","names":[],"sources":["../src/utils.ts"],"mappings":";KAAY,IAAA,MAAU,CAAA,cAAc,IAAA,6BAC5B,IAAA,EAAM,CAAA,KAAM,CAAA,iBACF,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KACZ,iBAAA,sBACI,CAAA,GAAI,CAAA,CAAE,GAAA;AAAA,KAOV,mBAAA,WACV,KAAA,oBAAyB,KAAA,EAAO,KAAK,6BAC5B,KAAA,iCACP,YAAA;AAAA,KAEQ,OAAA,MAAa,CAAA,KAAM,IAAA,EAAM,CAAA,KAAM,CAAA;AAAA,UAK1B,aAAA;EArBK;;;EAyBpB,WAAA,EAAa,IAAA;EAxBP;;;;EA6BN,KAAA,EAAO,KAAK;AAAA;AAAA,iBAGE,IAAA,mCAAuC,CAAA,EAAG,GAAA,EAAK,CAAA,EAAG,IAAA,EAAM,CAAA,KAAG,IAAA,CAAA,CAAA,EAAA,CAAA"}
|
package/dist/utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.ts"],"mappings":";KAAY,IAAA,MAAU,CAAA,cAAc,IAAA,6BAC5B,IAAA,EAAM,CAAA,KAAM,CAAA,iBACF,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KACZ,iBAAA,sBACI,CAAA,GAAI,CAAA,CAAE,GAAA;AAAA,KAOV,mBAAA,WACV,KAAA,oBAAyB,KAAA,EAAO,KAAK,6BAC5B,KAAA,iCACP,YAAA;AAAA,KAEQ,OAAA,MAAa,CAAA,KAAM,IAAA,EAAM,CAAA,KAAM,CAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.ts"],"mappings":";KAAY,IAAA,MAAU,CAAA,cAAc,IAAA,6BAC5B,IAAA,EAAM,CAAA,KAAM,CAAA,iBACF,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KACZ,iBAAA,sBACI,CAAA,GAAI,CAAA,CAAE,GAAA;AAAA,KAOV,mBAAA,WACV,KAAA,oBAAyB,KAAA,EAAO,KAAK,6BAC5B,KAAA,iCACP,YAAA;AAAA,KAEQ,OAAA,MAAa,CAAA,KAAM,IAAA,EAAM,CAAA,KAAM,CAAA;AAAA,UAK1B,aAAA;EArBK;;;EAyBpB,WAAA,EAAa,IAAA;EAxBP;;;;EA6BN,KAAA,EAAO,KAAK;AAAA;AAAA,iBAGE,IAAA,mCAAuC,CAAA,EAAG,GAAA,EAAK,CAAA,EAAG,IAAA,EAAM,CAAA,KAAG,IAAA,CAAA,CAAA,EAAA,CAAA"}
|
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["export type Show<T> = T extends (...args: infer A) => infer R\n ? (...args: A) => R\n : { [K in keyof T]: T[K] } & {};\nexport type MergeIntersection<T> = {\n [Key in keyof T]: T[Key];\n};\nexport type IsUnion<T, U = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\nexport type UnionToIntersection<Union> = (\n Union extends unknown ? (value: Union) => void : never\n) extends (value: infer Intersection) => void\n ? Intersection\n : never;\nexport type Updater<T> = T | ((prev: T) => T);\n\nexport interface BaseComponent<Name extends string, Props = {}> {\n /**\n * The name of the component. Useful for debugging and error messages.\n */\n displayName: Name;\n /**\n * A type only property to get the type of the props. At runtime,\n * this is `undefined`.\n */\n props: Props;\n}\n\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: K[]) {\n if (keys.length === 0) {\n return {} as Pick<T, K>;\n }\n\n return keys.reduce(\n (acc, key) => {\n if (key in obj) acc[key] = obj[key];\n\n return acc;\n },\n {} as Pick<T, K>,\n );\n}\n\nexport function functionalUpdate<T>(value: T, updater: Updater<T>){\n if (typeof updater === 'function') {\n return (updater as (prev: T) => T)(value);\n }\n\n return updater;\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["export type Show<T> = T extends (...args: infer A) => infer R\n ? (...args: A) => R\n : { [K in keyof T]: T[K] } & {};\nexport type MergeIntersection<T> = {\n [Key in keyof T]: T[Key];\n};\nexport type IsUnion<T, U = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\nexport type UnionToIntersection<Union> = (\n Union extends unknown ? (value: Union) => void : never\n) extends (value: infer Intersection) => void\n ? Intersection\n : never;\nexport type Updater<T> = T | ((prev: T) => T);\nexport type OptionalRecord<K extends string, V = unknown> = {\n [key in K]?: V;\n};\n\nexport interface BaseComponent<Name extends string, Props = {}> {\n /**\n * The name of the component. Useful for debugging and error messages.\n */\n displayName: Name;\n /**\n * A type only property to get the type of the props. At runtime,\n * this is `undefined`.\n */\n props: Props;\n}\n\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: K[]) {\n if (keys.length === 0) {\n return {} as Pick<T, K>;\n }\n\n return keys.reduce(\n (acc, key) => {\n if (key in obj) acc[key] = obj[key];\n\n return acc;\n },\n {} as Pick<T, K>,\n );\n}\n\nexport function functionalUpdate<T>(value: T, updater: Updater<T>){\n if (typeof updater === 'function') {\n return (updater as (prev: T) => T)(value);\n }\n\n return updater;\n}\n"],"mappings":";AAiCA,SAAgB,KAA0C,KAAQ,MAAW;CAC3E,IAAI,KAAK,WAAW,GAClB,OAAO,CAAC;CAGV,OAAO,KAAK,QACT,KAAK,QAAQ;EACZ,IAAI,OAAO,KAAK,IAAI,OAAO,IAAI;EAE/B,OAAO;CACT,GACA,CAAC,CACH;AACF;AAEA,SAAgB,iBAAoB,OAAU,SAAoB;CAChE,IAAI,OAAO,YAAY,YACrB,OAAQ,QAA2B,KAAK;CAG1C,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"for-resources.cjs","names":["capitalize"],"sources":["../../src/create-config/for-resources.ts"],"sourcesContent":["import {\n createContext,\n createElement,\n type JSX,\n type ReactNode,\n useContext,\n} from 'react';\nimport type {\n ComposableComponents,\n ComposableResourceLayout,\n} from '@jfdevelops/react-layout-composables';\nimport {\n type AnyBuiltPropDefinition,\n type ResolveProps,\n type ResolvedBuiltPropShape,\n validateProps,\n} from '@jfdevelops/react-layout-validator';\nimport type {\n IncludedProps,\n InPropsDefinition,\n InPropsObject,\n MergedLayoutInProps,\n ResolvedIncludedPropsAsDefined,\n} from '../props';\nimport type { LayoutResourceKey, ResourceDefinition } from '../resource';\nimport { capitalize } from '../utils/capitalize';\nimport type { BaseComponent, Show } from '../utils';\nimport type {\n LayoutIncludeProps,\n LayoutPropsForResource,\n ResourceLayoutComponent,\n} from './define-layout';\nimport type {\n CreatedLayoutForResource,\n CreateLayoutForResourceOptions,\n CreateResourceLayoutOptionsBase,\n SetDefaultPropForResourceFn,\n} from './for-resource';\n\ntype CapitalizedResource<Resource extends string> = Resource extends Resource\n ? {\n toLowerCase: () => Lowercase<Capitalize<Resource>>;\n } & Capitalize<Resource>\n : never;\n\ntype ResourceLayoutName<\n Resource extends string,\n Name extends string = string,\n> = Name | ((resource: CapitalizedResource<Resource>) => Name);\n\ntype ResourceLayoutNames<\n Resource extends string,\n CallbackName extends string = string,\n> = {\n [TargetResource in Resource]?:\n | string\n | ((resource: CapitalizedResource<TargetResource>) => CallbackName);\n};\n\ntype AtLeastOneResourceLayoutNameKey<Resource extends string> = {\n [TargetResource in Resource]: Record<TargetResource, unknown> &\n Partial<Record<Exclude<Resource, TargetResource>, unknown>>;\n}[Resource];\n\ntype SelectedResourceLayoutNames<\n Resource extends string,\n SelectedResource extends Resource,\n CallbackName extends string,\n> = {\n [TargetResource in Resource as TargetResource extends SelectedResource\n ? TargetResource\n : never]?:\n | string\n | ((resource: CapitalizedResource<TargetResource>) => CallbackName);\n};\n\ntype ResourcesLayoutName<Resource extends string> =\n | Exclude<ResourceLayoutName<Resource>, string>\n | ResourceLayoutNames<Resource>;\n\ntype ResourceLayoutSelection<\n Resources extends ReadonlyArray<ResourceDefinition>,\n CallbackName extends string = string,\n> = {\n [Resource in LayoutResourceKey<Resources>]?: {\n name?: string | ((resource: CapitalizedResource<Resource>) => CallbackName);\n };\n};\n\ntype AtLeastOneResourceLayoutSelection<\n Resources extends ReadonlyArray<ResourceDefinition>,\n CallbackName extends string,\n> = {\n [Resource in LayoutResourceKey<Resources>]: Required<\n Pick<ResourceLayoutSelection<Resources, CallbackName>, Resource>\n > &\n Omit<ResourceLayoutSelection<Resources, CallbackName>, Resource>;\n}[LayoutResourceKey<Resources>];\n\ntype SelectedLayoutResources<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Arguments extends ReadonlyArray<unknown>,\n> =\n Arguments extends ReadonlyArray<LayoutResourceKey<Resources>>\n ? Arguments[number]\n : Arguments[0] extends {\n resources: ReadonlyArray<infer Resource>;\n }\n ? Resource & LayoutResourceKey<Resources>\n : keyof Arguments[0] & LayoutResourceKey<Resources>;\n\ntype ResolveResourceLayoutName<Name> = Name extends (\n ...args: never[]\n) => infer Result\n ? Result & string\n : Name extends string\n ? Name\n : string;\n\ntype NormalizeCapitalizedResourceName<\n Name extends string,\n Resource extends string,\n> = Name extends Name\n ? NormalizeCapitalizedResourceNameMatch<Name, Resource> extends infer Match\n ? [Match] extends [never]\n ? Name\n : Match\n : never\n : never;\n\ntype NormalizeCapitalizedResourceNameMatch<\n Name extends string,\n Resource extends string,\n> = Resource extends Resource\n ? Name extends `${CapitalizedResource<Resource>}${infer Suffix}`\n ? `${Capitalize<Resource>}${Suffix}`\n : never\n : never;\n\ntype SelectedResourceLayoutName<Arguments, Resource extends string> =\n Arguments extends ReadonlyArray<string>\n ? string\n : Arguments extends readonly [infer Options]\n ? Options extends {\n resources: ReadonlyArray<string>;\n name?: infer Name;\n }\n ? Name extends (...args: never[]) => unknown\n ? ResolveResourceLayoutName<Name>\n : Name extends Record<Resource, infer ResourceName>\n ? ResolveResourceLayoutName<ResourceName>\n : string\n : Options extends Record<Resource, infer ResourceOptions>\n ? ResourceOptions extends { name?: infer Name }\n ? ResolveResourceLayoutName<Name>\n : string\n : string\n : string;\n\ntype NormalizeResourceLayoutNames<Names, CallbackName extends string> = {\n [Resource in keyof Names]: Names[Resource] extends (\n ...args: never[]\n ) => unknown\n ? (\n resource: CapitalizedResource<Resource & string>,\n ) => NormalizeCapitalizedResourceName<CallbackName, Resource & string>\n : Names[Resource];\n};\n\ntype NormalizeResourceLayoutSelection<Selection> = {\n [Resource in keyof Selection]: Selection[Resource] extends {\n name: infer Name;\n }\n ? {\n name: Name extends (...args: never[]) => unknown\n ? (\n resource: CapitalizedResource<Resource & string>,\n ) => NormalizeCapitalizedResourceName<\n ResolveResourceLayoutName<Name>,\n Resource & string\n >\n : Name;\n }\n : Selection[Resource];\n};\n\ntype SharedResourceLayoutArguments<\n Resources extends ReadonlyArray<ResourceDefinition>,\n ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>,\n Name extends string,\n> = readonly [\n {\n resources: ResourceKeys;\n name: (\n resource: CapitalizedResource<ResourceKeys[number]>,\n ) => NormalizeCapitalizedResourceName<Name, ResourceKeys[number]>;\n },\n];\n\ntype MappedResourceLayoutArguments<\n Resources extends ReadonlyArray<ResourceDefinition>,\n ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>,\n Names,\n CallbackName extends string,\n> = readonly [\n {\n resources: ResourceKeys;\n name: NormalizeResourceLayoutNames<Names, CallbackName>;\n },\n];\n\ntype SelectedResourceLayoutArguments<Selection> = readonly [\n NormalizeResourceLayoutSelection<Selection>,\n];\n\ntype HasResourceLayoutName<Arguments, Resource extends string> =\n Arguments extends ReadonlyArray<string>\n ? false\n : Arguments extends readonly [infer Options]\n ? Options extends {\n resources: ReadonlyArray<string>;\n name: infer Name;\n }\n ? Name extends (...args: never[]) => unknown\n ? true\n : Name extends Record<Resource, unknown>\n ? true\n : false\n : Options extends Record<Resource, infer ResourceOptions>\n ? 'name' extends keyof ResourceOptions\n ? true\n : false\n : false\n : false;\n\ntype ScopedCreateResourceLayoutOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n Name extends string,\n Resource extends SelectedLayoutResources<Resources, Arguments>,\n Props extends InPropsObject,\n> = LayoutPropsForResource<Resources, InProps, Composables> & {\n resource: Resource;\n props?: Props;\n} & (HasResourceLayoutName<Arguments, Resource> extends true\n ? { name?: Name }\n : { name: Name });\n\ntype ScopedCreateResourceLayoutFnImpl<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n CustomProps extends InPropsObject,\n> = <\n Resource extends SelectedLayoutResources<Resources, Arguments>,\n Name extends string = SelectedResourceLayoutName<Arguments, Resource>,\n Props extends InPropsObject = {},\n>(\n options: ScopedCreateResourceLayoutOptions<\n Resources,\n InProps,\n Composables,\n Arguments,\n Name,\n Resource,\n Props\n >,\n) => ResourceLayoutComponent<Name, CustomProps, Composables, Resource>;\n\ntype ScopedCreateLayoutForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n CustomProps extends InPropsObject,\n> = <\n Resource extends SelectedLayoutResources<Resources, Arguments>,\n Name extends string = SelectedResourceLayoutName<Arguments, Resource>,\n>(\n options: CreateLayoutForResourceOptions<Resources, Name, Resource>,\n) => CreatedLayoutForResource<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n CustomProps\n> & {\n setDefaults: SetDefaultPropForResourceFn<\n Resources,\n InProps,\n Composables,\n Name,\n Resource,\n CustomProps\n >;\n};\n\ntype ScopedCreateResourceLayoutMakeComposableFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n> = <\n Resource extends SelectedLayoutResources<Resources, Arguments>,\n Name extends string = SelectedResourceLayoutName<Arguments, Resource>,\n Props extends InPropsObject = {},\n>(\n options: Omit<\n CreateResourceLayoutOptionsBase<Resources, Name, Resource>,\n 'name'\n > &\n Partial<LayoutPropsForResource<Resources, InProps, Composables>> & {\n props?: Props;\n } & (HasResourceLayoutName<Arguments, Resource> extends true\n ? { name?: Name }\n : { name: Name }),\n) => ComposableResourceLayout<Composables, Name, any, any, any>;\n\ntype ScopedComponentAvailableProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n LayoutCustomProps extends InPropsObject,\n> = MergedLayoutInProps<Resources, InProps, Composables> & LayoutCustomProps;\n\ntype ScopedResourceComponentProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n LayoutCustomProps extends InPropsObject,\n ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n >,\n ComponentCustomProps extends InPropsObject,\n Resource extends string,\n> = Show<\n Omit<\n ResolvedIncludedPropsAsDefined<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >,\n ComponentIncludeProps\n > &\n ResolvedBuiltPropShape<ComponentCustomProps>,\n 'children' | 'resource'\n > & {\n children?: ReactNode;\n resource: Resource;\n }\n>;\n\n/**\n * Fields reverse-inferred from each scoped component declaration. Only `props`\n * belongs here — putting `render` in the reverse map makes TypeScript infer it\n * as `unknown` (function types don't reverse-map cleanly). `render` is supplied\n * by the constraint intersection instead, like the playground's `transform`.\n */\ntype ScopedComponentShape = {\n props?: InPropsObject;\n};\n\n/**\n * Homomorphic pick of reverse-mapped scoped-component fields. Paired with a\n * mapped type over the components object, this lets each entry's inferred\n * `props` flow into sibling render signatures.\n */\ntype JustScopedComponent<T> = {\n [Key in keyof T & keyof ScopedComponentShape]: T[Key];\n};\n\n/**\n * Resources with no `components` reverse-infer as `unknown`. Treat that as an\n * empty map so sibling/context access stays closed.\n */\ntype NormalizeScopedComponentsMap<Components> = unknown extends Components\n ? {}\n : Components extends Record<string, unknown>\n ? Components\n : {};\n\n/** Extracts the prop definitions declared on a scoped component. */\ntype ScopedComponentOwnProps<Definition> = Definition extends {\n props: infer Props;\n}\n ? Props extends InPropsObject\n ? Props\n : {}\n : {};\n\n/**\n * A scoped component's call signature. Components that declare no props are\n * callable with no arguments.\n */\ntype ScopedComponentSignature<Props> = {} extends Props\n ? (props?: Props) => JSX.Element\n : (props: Props) => JSX.Element;\n\n/**\n * The sibling / context components for one resource, keyed by their declared\n * names with call-site prop types.\n */\ntype ResolvedScopedComponentsMap<Components> = {\n [Name in keyof NormalizeScopedComponentsMap<Components>]: ScopedComponentSignature<\n Show<\n ResolvedBuiltPropShape<\n ScopedComponentOwnProps<NormalizeScopedComponentsMap<Components>[Name]>\n >\n >\n >;\n};\n\ntype ScopedResourceComponentRenderContext<\n ComponentsByResource,\n LayoutCustomProps extends InPropsObject,\n> = {\n /**\n * The resource layout for the component's current `resource`, created\n * internally from that resource's entry options. Accepts the layout's\n * custom props.\n */\n Root: (props: Show<ResolveProps<LayoutCustomProps>>) => JSX.Element;\n} & {\n [Resource in keyof ComponentsByResource as Capitalize<\n Resource & string\n >]-?: (() => JSX.Element) &\n ResolvedScopedComponentsMap<ComponentsByResource[Resource]>;\n};\n\n/**\n * Reverse-mapped `resources` constraint.\n *\n * `ComponentsByResource` is inferred from each entry's `components` object.\n * Mapping back over those keys types every nested `render`'s second argument\n * with the other components for that resource — excluding the current\n * component when typing a scoped component's own `render`.\n *\n * The parameter must not carry a default: TypeScript contextually types from a\n * parameter's default when it has one, and `{}` would silently degrade every\n * nested render to `any`.\n */\ntype ScopedComponentResourceEntries<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n LayoutCustomProps extends InPropsObject,\n ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n >,\n ComponentCustomProps extends InPropsObject,\n ComponentsByResource,\n> = {\n [Resource in keyof ComponentsByResource]: LayoutPropsForResource<\n Resources,\n InProps,\n Composables\n > & {\n /**\n * Overrides the layout name used by `context.Root` for this resource.\n * Defaults to the scope's configured name, then the capitalized resource.\n */\n name?: string;\n /**\n * Components scoped to this resource. Each becomes a component on this\n * resource's render context, on `context.<Resource>`, and on the component\n * returned by `asHOF()`.\n */\n components?: {\n [Name in keyof ComponentsByResource[Resource]]: JustScopedComponent<\n ComponentsByResource[Resource][Name]\n > & {\n /** Props accepted by this component, validated at its call site. */\n props?: InPropsObject;\n /**\n * Renders this component. Receives the scoped component's props plus\n * this component's own props, and the other components for this\n * resource (excluding itself).\n */\n render: (\n props: ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource & string\n > &\n Show<\n ResolvedBuiltPropShape<\n ScopedComponentOwnProps<ComponentsByResource[Resource][Name]>\n >\n >,\n components: Omit<\n ResolvedScopedComponentsMap<ComponentsByResource[Resource]>,\n Name\n >,\n ) => JSX.Element;\n };\n };\n /** Renders this resource's content inside the shared render function. */\n render: (\n props: ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource & string\n >,\n components: ResolvedScopedComponentsMap<ComponentsByResource[Resource]>,\n ) => JSX.Element;\n };\n} & Record<\n Exclude<\n keyof ComponentsByResource,\n SelectedLayoutResources<Resources, Arguments>\n >,\n never\n>;\n\n/**\n * Props of a resource-bound component. `resource` is supplied by the binding,\n * so it is removed from the call site.\n */\ntype ScopedBoundResourceComponentProps<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n LayoutCustomProps extends InPropsObject,\n ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n >,\n ComponentCustomProps extends InPropsObject,\n Resource extends string,\n> = Show<\n Omit<\n ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource\n >,\n 'resource'\n >\n>;\n\ntype ScopedBoundResourceComponent<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n LayoutCustomProps extends InPropsObject,\n ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n >,\n ComponentCustomProps extends InPropsObject,\n ComponentsByResource,\n Resource extends string,\n> = BaseComponent<\n string,\n ScopedBoundResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource\n >\n> &\n ResolvedScopedComponentsMap<\n Resource extends keyof ComponentsByResource\n ? ComponentsByResource[Resource]\n : {}\n > & {\n (\n props: ScopedBoundResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource\n >,\n ): JSX.Element;\n /**\n * Type-only property containing the bound resource. This property is\n * `undefined` at runtime.\n */\n readonly resource: Resource;\n };\n\ntype ScopedResourceComponent<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n LayoutCustomProps extends InPropsObject,\n ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n >,\n ComponentCustomProps extends InPropsObject,\n ComponentsByResource,\n> = BaseComponent<\n string,\n ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n SelectedLayoutResources<Resources, Arguments>\n >\n> & {\n /**\n * The `resource` prop drives the generic, so it is inferred from the call\n * site. Explicit type arguments are never needed.\n */\n <const Resource extends SelectedLayoutResources<Resources, Arguments>>(\n props: ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n Resource\n >,\n ): JSX.Element;\n /**\n * Returns a factory that binds the component to one resource. The bound\n * component accepts every prop except `resource`, which the binding supplies.\n *\n * Each resource is bound once and cached, so the returned component type is\n * stable across renders.\n *\n * @example\n * const createDirectory = Directory.asHOF()\n * const UsersDirectory = createDirectory('users')\n *\n * <UsersDirectory title='Users' />\n *\n * @returns A factory producing a component bound to the given resource.\n */\n asHOF(): <\n const Resource extends SelectedLayoutResources<Resources, Arguments>,\n >(\n resource: Resource,\n ) => ScopedBoundResourceComponent<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n ComponentsByResource,\n Resource\n >;\n};\n\ntype ScopedCreateComponent<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n LayoutCustomProps extends InPropsObject,\n> = <\n // Declared first and deliberately without a default: TypeScript\n // contextually types from a parameter's default when one exists, so a\n // default here would type every nested render as `any`. Inferred via a\n // reverse mapped type from each entry's `components` object.\n const ComponentsByResource,\n const ComponentIncludeProps extends IncludedProps<\n ScopedComponentAvailableProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps\n >\n > = {},\n ComponentCustomProps extends InPropsObject = {},\n>(options: {\n props?: {\n /** Props from the resource layout definition to expose to the component. */\n include?: ComponentIncludeProps;\n /** Additional props accepted by the component. */\n custom?: ComponentCustomProps;\n };\n /**\n * Per-resource content, keyed by resource. Each entry holds that resource's\n * create-time layout options, its scoped `components`, and its `render`.\n */\n resources?: ScopedComponentResourceEntries<\n Resources,\n InProps,\n Composables,\n Arguments,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n ComponentsByResource\n >;\n /**\n * Renders the scoped component. `children` and `resource` are always\n * available. The context contains `Root`, the layout for the current\n * resource, plus a capitalized component per defined resource.\n */\n render: (\n props: ScopedResourceComponentProps<\n Resources,\n InProps,\n Composables,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n SelectedLayoutResources<Resources, Arguments>\n >,\n context: ScopedResourceComponentRenderContext<\n ComponentsByResource,\n LayoutCustomProps\n >,\n ) => JSX.Element;\n}) => ScopedResourceComponent<\n Resources,\n InProps,\n Composables,\n Arguments,\n LayoutCustomProps,\n ComponentIncludeProps,\n ComponentCustomProps,\n ComponentsByResource\n>;\n\ntype ScopedCreateResourceLayoutFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n Arguments extends ReadonlyArray<unknown>,\n CustomProps extends InPropsObject,\n> = ScopedCreateResourceLayoutFnImpl<\n Resources,\n InProps,\n Composables,\n Arguments,\n CustomProps\n> & {\n /**\n * Creates a component shared by the target resources. Included layout props\n * become component props, and `children` is always available as an optional\n * prop in both the render callback and at the call site.\n *\n * Each key of `resources` holds that resource's create-time layout options\n * alongside its `render`. The render context exposes `Root` — the layout for\n * the current resource, built from those options — and one capitalized\n * component per key present in `resources`.\n *\n * Each entry may also declare `components` — components scoped to that\n * resource, available to the entry's own `render`, on `context.<Resource>`,\n * and on the component returned by `asHOF()`.\n *\n * @example\n * const Directory = createDirectoryLayout.createComponent({\n * props: { include: { title: true, actions: 'optional' } },\n * resources: {\n * users: {\n * title: 'Users',\n * components: {\n * Toolbar: { render: ({ title }) => <nav>{title}</nav> },\n * },\n * render: ({ resource }, components) => (\n * <>\n * <components.Toolbar />\n * <span>{resource}</span>\n * </>\n * ),\n * },\n * admins: {\n * title: 'Admins',\n * render: ({ resource }) => <span>{resource}</span>,\n * },\n * },\n * render: ({ actions, children, resource }, context) => (\n * <context.Root actions={actions}>\n * {children}\n * {resource === 'users' ? <context.Users /> : <context.Admins />}\n * <context.Users.Toolbar />\n * </context.Root>\n * ),\n * })\n *\n * <Directory resource='users' title='Users' />\n *\n * @param options The props configuration, per-resource entries, and the\n * shared component render function.\n * @returns A component scoped to the selected resources.\n */\n createComponent: ScopedCreateComponent<\n Resources,\n InProps,\n Composables,\n Arguments,\n CustomProps\n >;\n forResource: ScopedCreateLayoutForResource<\n Resources,\n InProps,\n Composables,\n Arguments,\n CustomProps\n >;\n /**\n * Type-only property containing the target resource union. This property is\n * `undefined` at runtime and exists solely for extracting the scoped type.\n *\n * @example\n * type AccountResource = typeof createAccountLayout.resources;\n */\n readonly resources: SelectedLayoutResources<Resources, Arguments>;\n} & ([keyof Composables] extends [never]\n ? {}\n : {\n makeComposable: ScopedCreateResourceLayoutMakeComposableFn<\n Resources,\n InProps,\n Composables,\n Arguments\n >;\n });\n\nexport type CreateResourceLayoutForResourcesFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents = {},\n IncludeProps extends LayoutIncludeProps<Resources, InProps, Composables> = {},\n CustomProps extends InPropsObject = {},\n> = {\n /**\n * Creates a layout factory scoped to the listed resources.\n *\n * Layout names must be supplied when a layout is created.\n *\n * @example\n * createResourceLayout.forResources('users', 'admins')\n *\n * @param resources Resources available from the returned layout factory.\n * @returns A layout factory scoped to the selected resources.\n */\n <\n const ResourceKeys extends readonly [\n LayoutResourceKey<Resources>,\n ...Array<LayoutResourceKey<Resources>>,\n ],\n >(\n ...resources: ResourceKeys\n ): ScopedCreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n ResourceKeys,\n CustomProps\n >;\n\n /**\n * Creates a layout factory scoped to a resource list without default names.\n *\n * @example\n * createResourceLayout.forResources({ resources: ['users', 'admins'] })\n *\n * @param options The resources to expose without configured default names.\n * @returns A layout factory scoped to the selected resources.\n */\n <\n const ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>,\n >(options: {\n resources: ResourceKeys;\n name?: never;\n }): ScopedCreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n readonly [{ resources: ResourceKeys }],\n CustomProps\n >;\n\n /**\n * Creates a scoped layout factory with optional default names per resource.\n *\n * Each map key is limited to the resources selected in `resources`. Values\n * can be strings or callbacks receiving that resource's capitalized name.\n *\n * @example\n * createResourceLayout.forResources({\n * resources: ['users', 'admins'],\n * name: {\n * users: resource => `${resource}Page`,\n * admins: 'AdminDirectory',\n * },\n * })\n *\n * @param options The selected resources and their optional default names.\n * @returns A layout factory scoped to the selected resources.\n */\n <\n const ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>,\n const CallbackName extends string,\n const Names,\n >(\n options: {\n resources: ResourceKeys;\n name: SelectedResourceLayoutNames<\n LayoutResourceKey<Resources>,\n NoInfer<ResourceKeys[number]>,\n CallbackName\n > &\n AtLeastOneResourceLayoutNameKey<NoInfer<ResourceKeys[number]>> &\n Record<\n string,\n NonNullable<\n ResourceLayoutNames<\n LayoutResourceKey<Resources>,\n CallbackName\n >[LayoutResourceKey<Resources>]\n >\n >;\n } & {\n name: Names & Record<Exclude<keyof Names, ResourceKeys[number]>, never>;\n },\n ): ScopedCreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n MappedResourceLayoutArguments<Resources, ResourceKeys, Names, CallbackName>,\n CustomProps\n >;\n\n /**\n * Creates a scoped layout factory with one default-name callback shared by\n * every selected resource. The callback receives a capitalized resource\n * whose `toLowerCase()` result retains the corresponding literal type.\n *\n * @example\n * createResourceLayout.forResources({\n * resources: ['users', 'admins'],\n * name: resource => `${resource}Page`,\n * })\n *\n * @param options The selected resources and shared default-name callback.\n * @returns A layout factory scoped to the selected resources.\n */\n <\n const ResourceKeys extends ReadonlyArray<LayoutResourceKey<Resources>>,\n const Name extends string,\n >(\n options: {\n resources: ReadonlyArray<LayoutResourceKey<Resources>>;\n name: (resource: CapitalizedResource<ResourceKeys[number]>) => Name;\n } & { resources: ResourceKeys },\n ): ScopedCreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n SharedResourceLayoutArguments<Resources, ResourceKeys, Name>,\n CustomProps\n >;\n\n /**\n * Creates a scoped layout factory from a resource-keyed configuration.\n * Only configured resources are available from the returned factory.\n *\n * @example\n * createResourceLayout.forResources({\n * users: { name: resource => `${resource}Page` },\n * admins: { name: 'AdminDirectory' },\n * })\n *\n * @param options Resource-keyed layout defaults.\n * @returns A layout factory scoped to the configured resources.\n */\n <\n const CallbackName extends string,\n const Selection extends ResourceLayoutSelection<Resources, CallbackName>,\n >(\n options: Selection &\n AtLeastOneResourceLayoutSelection<Resources, CallbackName> &\n Partial<\n Record<Exclude<'resources', LayoutResourceKey<Resources>>, never>\n > &\n Record<Exclude<keyof Selection, LayoutResourceKey<Resources>>, never>,\n ): ScopedCreateResourceLayoutFn<\n Resources,\n InProps,\n Composables,\n SelectedResourceLayoutArguments<Selection>,\n CustomProps\n >;\n};\n\n/**\n * Names a scoped component cannot use. Scoped components are attached to\n * function objects, so they collide with the component's own statics and with\n * non-writable `Function.prototype` properties. `__proto__` is reserved so\n * assignment cannot hit the prototype setter on a normal object.\n */\nconst reservedScopedComponentNames = new Set([\n '__proto__',\n 'apply',\n 'arguments',\n 'bind',\n 'call',\n 'caller',\n 'displayName',\n 'length',\n 'name',\n 'props',\n 'prototype',\n 'resource',\n]);\n\ntype CreateForResourcesOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = {\n createLayoutForResource: (\n defaultName: string | undefined,\n resource: LayoutResourceKey<Resources>,\n ) => unknown;\n createMakeComposableLayout?: () => (\n options: Record<string, unknown>,\n ) => unknown;\n createResourceLayout: (options: Record<string, unknown>) => unknown;\n getComponentPropDefinitions: (\n resource: LayoutResourceKey<Resources>,\n ) => Record<string, AnyBuiltPropDefinition>;\n};\n\nexport function createForResources<\n Resources extends ReadonlyArray<ResourceDefinition>,\n InProps extends InPropsDefinition<Resources>,\n Composables extends ComposableComponents,\n IncludeProps extends LayoutIncludeProps<Resources, InProps, Composables>,\n CustomProps extends InPropsObject,\n>({\n createLayoutForResource,\n createMakeComposableLayout,\n createResourceLayout,\n getComponentPropDefinitions,\n}: CreateForResourcesOptions<Resources>) {\n return ((...resourcesOrOptions: Array<unknown>) => {\n const firstArgument = resourcesOrOptions[0];\n let resourceOptions: Array<{\n resource: LayoutResourceKey<Resources>;\n name?:\n | string\n | ((\n resource: CapitalizedResource<LayoutResourceKey<Resources>>,\n ) => string);\n }>;\n\n if (typeof firstArgument === 'string') {\n resourceOptions = resourcesOrOptions.map((resource) => ({\n resource: resource as LayoutResourceKey<Resources>,\n }));\n } else if (\n firstArgument !== null &&\n typeof firstArgument === 'object' &&\n 'resources' in firstArgument &&\n Array.isArray(firstArgument.resources)\n ) {\n const { name, resources } = firstArgument as {\n name?: ResourcesLayoutName<LayoutResourceKey<Resources>>;\n resources: Array<LayoutResourceKey<Resources>>;\n };\n resourceOptions = resources.map((resource) => ({\n name: typeof name === 'function' ? name : name?.[resource],\n resource,\n }));\n } else {\n resourceOptions = Object.entries(firstArgument ?? {}).map(\n ([resource, options]) => ({\n ...(options as {\n name?:\n | string\n | ((\n resource: CapitalizedResource<LayoutResourceKey<Resources>>,\n ) => string);\n }),\n resource: resource as LayoutResourceKey<Resources>,\n }),\n );\n }\n\n const defaultNames = new Map(\n resourceOptions.map(({ name, resource }) => [\n resource,\n typeof name === 'function'\n ? name(\n capitalize(resource) as CapitalizedResource<\n LayoutResourceKey<Resources>\n >,\n )\n : name,\n ]),\n );\n\n function scopedCreateResourceLayout(options: Record<string, unknown>) {\n const resource = options.resource as LayoutResourceKey<Resources>;\n\n return createResourceLayout({\n ...options,\n name: options.name ?? defaultNames.get(resource),\n });\n }\n\n function scopedForResource(options: {\n name?: string;\n resource: LayoutResourceKey<Resources>;\n }) {\n return createLayoutForResource(\n options.name ?? defaultNames.get(options.resource),\n options.resource,\n );\n }\n\n type ScopedComponentRenderFn = (\n props: Record<string, unknown>,\n components: Record<string, (props?: never) => JSX.Element>,\n ) => JSX.Element;\n\n type ScopedResourceScopedComponentDefinition = {\n props?: Record<string, AnyBuiltPropDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n type ScopedComponentEntry = {\n [option: string]: unknown;\n name?: string;\n components?: Record<string, ScopedResourceScopedComponentDefinition>;\n render: ScopedComponentRenderFn;\n };\n\n function createComponent(componentOptions: {\n props?: {\n include?: Record<string, true | 'optional'>;\n custom?: Record<string, AnyBuiltPropDefinition>;\n };\n resources?: Record<string, ScopedComponentEntry>;\n render: (\n props: Record<string, unknown>,\n context: Record<string, (props: never) => JSX.Element>,\n ) => JSX.Element;\n }) {\n const include = componentOptions.props?.include ?? {};\n const custom = componentOptions.props?.custom ?? {};\n const selectedResources = new Set(\n resourceOptions.map(({ resource }) => resource),\n );\n const componentPropsContext = createContext<\n Record<string, unknown> | undefined\n >(undefined);\n const definedEntries = new Map<\n LayoutResourceKey<Resources>,\n ScopedComponentEntry\n >();\n\n for (const [key, entry] of Object.entries(\n componentOptions.resources ?? {},\n )) {\n const resource = key as LayoutResourceKey<Resources>;\n\n if (!selectedResources.has(resource)) {\n throw new Error(\n `Resource \"${key}\" is not available in this scoped component`,\n );\n }\n\n definedEntries.set(resource, entry);\n }\n\n /** Resolved scoped components, per resource. */\n const resourceScopedComponents = new Map<\n LayoutResourceKey<Resources>,\n Record<string, (props?: never) => JSX.Element>\n >();\n const contextResources = new Map<string, LayoutResourceKey<Resources>>();\n const renderContext: Record<string, (props: never) => JSX.Element> =\n Object.fromEntries(\n [...definedEntries].map(([resource, entry]) => {\n const contextKey = capitalize(resource);\n\n if (contextKey === 'Root') {\n throw new Error(\n `Resource \"${resource}\" maps to the reserved render context key \"Root\"`,\n );\n }\n\n const existingResource = contextResources.get(contextKey);\n\n if (existingResource !== undefined) {\n throw new Error(\n `Resources \"${existingResource}\" and \"${resource}\" both map to render context key \"${contextKey}\"`,\n );\n }\n\n contextResources.set(contextKey, resource);\n\n /**\n * Built once per resource so every scoped component keeps a stable\n * identity, and shared by the resource render, the render context,\n * and any component bound through `asHOF()`.\n */\n const scopedComponents: Record<\n string,\n (props?: never) => JSX.Element\n > = {};\n\n for (const [name, definition] of Object.entries(\n entry.components ?? {},\n )) {\n if (reservedScopedComponentNames.has(name)) {\n throw new Error(\n `Scoped component \"${name}\" for resource \"${resource}\" uses a reserved name`,\n );\n }\n\n const ownPropDefinitions = definition.props ?? {};\n\n function ScopedComponent(ownProps?: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new Error(\n `Scoped component \"${name}\" must be rendered inside its scoped component`,\n );\n }\n\n const resolvedOwnProps = ownProps ?? {};\n\n validateProps(ownPropDefinitions, resolvedOwnProps);\n\n return definition.render(\n { ...componentProps, ...resolvedOwnProps, resource },\n scopedComponents,\n );\n }\n\n scopedComponents[name] = ScopedComponent as (\n props?: never,\n ) => JSX.Element;\n }\n\n resourceScopedComponents.set(resource, scopedComponents);\n\n function ResourceRender() {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new Error(\n `Render context component \"${contextKey}\" must be rendered inside its scoped component`,\n );\n }\n\n return entry.render(\n { ...componentProps, resource },\n scopedComponents,\n );\n }\n\n return [contextKey, Object.assign(ResourceRender, scopedComponents)];\n }),\n );\n\n /**\n * Layouts are created once per resource and cached. Creating one during\n * render would hand React a new component type on every pass, remounting\n * the whole subtree.\n */\n const roots = new Map<\n LayoutResourceKey<Resources>,\n (props: Record<string, unknown>) => JSX.Element\n >();\n\n function getRoot(resource: LayoutResourceKey<Resources>) {\n let root = roots.get(resource);\n\n if (root === undefined) {\n const entry = definedEntries.get(resource);\n\n if (entry === undefined) {\n // Without an entry there are no create-time layout options, so a\n // layout with required props would fail validation deep inside\n // its own render. Fail here instead, naming the fix.\n throw new Error(\n `Render context component \"Root\" requires a \"resources.${resource}\" entry to build the layout for resource \"${resource}\"`,\n );\n }\n\n const { render: _render, ...layoutOptions } = entry;\n\n root = scopedCreateResourceLayout({\n ...layoutOptions,\n name:\n layoutOptions.name ??\n defaultNames.get(resource) ??\n capitalize(resource),\n resource,\n }) as (props: Record<string, unknown>) => JSX.Element;\n roots.set(resource, root);\n }\n\n return root;\n }\n\n function Root(rootProps: Record<string, unknown>) {\n const componentProps = useContext(componentPropsContext);\n\n if (componentProps === undefined) {\n throw new Error(\n 'Render context component \"Root\" must be rendered inside its scoped component',\n );\n }\n\n return createElement(\n getRoot(componentProps.resource as LayoutResourceKey<Resources>),\n rootProps,\n );\n }\n\n renderContext.Root = Root;\n\n function Component(componentProps: Record<string, unknown>) {\n const componentResource =\n componentProps.resource as LayoutResourceKey<Resources>;\n\n if (!selectedResources.has(componentResource)) {\n throw new Error(\n `Resource \"${componentResource}\" is not available in this scoped component`,\n );\n }\n\n const availableDefinitions =\n getComponentPropDefinitions(componentResource);\n const definitionsToValidate: Record<string, AnyBuiltPropDefinition> =\n {};\n\n for (const [key, inclusion] of Object.entries(include)) {\n const definition = availableDefinitions[key];\n\n if (!definition) {\n continue;\n }\n\n // Keep declared keys as-is — do not capitalize JSX.Element props.\n if (inclusion === true || key in componentProps) {\n definitionsToValidate[key] = definition;\n }\n }\n\n for (const [key, definition] of Object.entries(custom)) {\n if (key === 'children' || key === 'resource') {\n continue;\n }\n\n definitionsToValidate[key] = definition;\n }\n\n validateProps(definitionsToValidate, componentProps);\n\n return createElement(\n componentPropsContext.Provider,\n { value: componentProps },\n componentOptions.render(componentProps, renderContext),\n );\n }\n\n /**\n * Bound components are created once per resource and cached. Returning a\n * fresh component from the factory would hand React a new component type\n * whenever the caller rebinds, remounting the subtree.\n */\n const boundComponents = new Map<\n LayoutResourceKey<Resources>,\n (props: Record<string, unknown>) => JSX.Element\n >();\n\n function bindResource(resource: LayoutResourceKey<Resources>) {\n if (!selectedResources.has(resource)) {\n throw new Error(\n `Resource \"${resource}\" is not available in this scoped component`,\n );\n }\n\n let boundComponent = boundComponents.get(resource);\n\n if (boundComponent === undefined) {\n boundComponent = Object.assign(\n (boundProps: Record<string, unknown>) =>\n createElement(Component, { ...boundProps, resource }),\n {\n displayName: `ScopedResourceComponent(${resource})`,\n props: undefined,\n resource: undefined,\n },\n resourceScopedComponents.get(resource) ?? {},\n );\n boundComponents.set(resource, boundComponent);\n }\n\n return boundComponent;\n }\n\n function asHOF() {\n return bindResource;\n }\n\n return Object.assign(Component, {\n asHOF,\n displayName: 'ScopedResourceComponent',\n props: undefined,\n });\n }\n\n const scopedExtras: {\n createComponent: typeof createComponent;\n forResource: typeof scopedForResource;\n makeComposable?: (options: Record<string, unknown>) => unknown;\n resources: undefined;\n } = {\n createComponent,\n forResource: scopedForResource,\n resources: undefined,\n };\n\n if (createMakeComposableLayout) {\n const makeComposableLayout = createMakeComposableLayout();\n\n scopedExtras.makeComposable = (options) => {\n const resource = options.resource as LayoutResourceKey<Resources>;\n\n return makeComposableLayout({\n ...options,\n name: options.name ?? defaultNames.get(resource),\n });\n };\n }\n\n return Object.assign(scopedCreateResourceLayout, scopedExtras);\n }) as unknown as CreateResourceLayoutForResourcesFn<\n Resources,\n InProps,\n Composables,\n IncludeProps,\n CustomProps\n >;\n}\n"],"mappings":";;;;;;;;;;;AAihCA,MAAM,+BAA+B,IAAI,IAAI;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAkBD,SAAgB,mBAMd,EACA,yBACA,4BACA,sBACA,+BACuC;CACvC,SAAS,GAAG,uBAAuC;EACjD,MAAM,gBAAgB,mBAAmB;EACzC,IAAI;EASJ,IAAI,OAAO,kBAAkB,UAC3B,kBAAkB,mBAAmB,KAAK,cAAc,EAC5C,SACZ,EAAE;OACG,IACL,kBAAkB,QAClB,OAAO,kBAAkB,YACzB,eAAe,iBACf,MAAM,QAAQ,cAAc,SAAS,GACrC;GACA,MAAM,EAAE,MAAM,cAAc;GAI5B,kBAAkB,UAAU,KAAK,cAAc;IAC7C,MAAM,OAAO,SAAS,aAAa,OAAO,OAAO;IACjD;GACF,EAAE;EACJ,OACE,kBAAkB,OAAO,QAAQ,iBAAiB,CAAC,CAAC,EAAE,KACnD,CAAC,UAAU,cAAc;GACxB,GAAI;GAOM;EACZ,EACF;EAGF,MAAM,eAAe,IAAI,IACvB,gBAAgB,KAAK,EAAE,MAAM,eAAe,CAC1C,UACA,OAAO,SAAS,aACZ,KACEA,8BAAW,QAAQ,CAGrB,IACA,IACN,CAAC,CACH;EAEA,SAAS,2BAA2B,SAAkC;GACpE,MAAM,WAAW,QAAQ;GAEzB,OAAO,qBAAqB;IAC1B,GAAG;IACH,MAAM,QAAQ,QAAQ,aAAa,IAAI,QAAQ;GACjD,CAAC;EACH;EAEA,SAAS,kBAAkB,SAGxB;GACD,OAAO,wBACL,QAAQ,QAAQ,aAAa,IAAI,QAAQ,QAAQ,GACjD,QAAQ,QACV;EACF;EAmBA,SAAS,gBAAgB,kBAUtB;GACD,MAAM,UAAU,iBAAiB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