@jfdevelops/react-layout 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/composable.cjs +72 -0
- package/dist/composable.cjs.map +1 -0
- package/dist/composable.d.cts +42 -0
- package/dist/composable.d.cts.map +1 -0
- package/dist/composable.d.mts +42 -0
- package/dist/composable.d.mts.map +1 -0
- package/dist/composable.mjs +70 -0
- package/dist/composable.mjs.map +1 -0
- package/dist/create-config.cjs +98 -0
- package/dist/create-config.cjs.map +1 -0
- package/dist/create-config.d.cts +67 -0
- package/dist/create-config.d.cts.map +1 -0
- package/dist/create-config.d.mts +67 -0
- package/dist/create-config.d.mts.map +1 -0
- package/dist/create-config.mjs +98 -0
- package/dist/create-config.mjs.map +1 -0
- package/dist/create-value.cjs +417 -0
- package/dist/create-value.cjs.map +1 -0
- package/dist/create-value.d.cts +348 -0
- package/dist/create-value.d.cts.map +1 -0
- package/dist/create-value.d.mts +348 -0
- package/dist/create-value.d.mts.map +1 -0
- package/dist/create-value.mjs +414 -0
- package/dist/create-value.mjs.map +1 -0
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +7 -0
- package/dist/props.d.cts +21 -0
- package/dist/props.d.cts.map +1 -0
- package/dist/props.d.mts +21 -0
- package/dist/props.d.mts.map +1 -0
- package/dist/resource.cjs +29 -0
- package/dist/resource.cjs.map +1 -0
- package/dist/resource.d.cts +47 -0
- package/dist/resource.d.cts.map +1 -0
- package/dist/resource.d.mts +47 -0
- package/dist/resource.d.mts.map +1 -0
- package/dist/resource.mjs +26 -0
- package/dist/resource.mjs.map +1 -0
- package/dist/utils.cjs +25 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +19 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +19 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +23 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { pick, resolvePropDefinitionValues } from "./utils.mjs";
|
|
2
|
+
import { makeComposable, resolveLayoutComposables } from "./composable.mjs";
|
|
3
|
+
import { createPrimitivePropBuilder, createProp, validateProps } from "./create-value.mjs";
|
|
4
|
+
import { normalizeResources, toResourceEnum } from "./resource.mjs";
|
|
5
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/create-config.tsx
|
|
8
|
+
function isBuiltPropDefinition(value) {
|
|
9
|
+
return typeof value === "function" && value !== null && "visibility" in value;
|
|
10
|
+
}
|
|
11
|
+
function isSplitLayoutInPropDefinition(value) {
|
|
12
|
+
return value !== null && typeof value === "object" && "render" in value && value.render !== void 0;
|
|
13
|
+
}
|
|
14
|
+
function splitLayoutInProps(inProps) {
|
|
15
|
+
const resolvedInProps = {};
|
|
16
|
+
const splitInProps = {};
|
|
17
|
+
for (const [key, value] of Object.entries(inProps)) {
|
|
18
|
+
if (isBuiltPropDefinition(value)) {
|
|
19
|
+
resolvedInProps[key] = value;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (isSplitLayoutInPropDefinition(value)) {
|
|
23
|
+
splitInProps[key] = value.render;
|
|
24
|
+
if (value.props && typeof value.props === "object") Object.assign(resolvedInProps, value.props);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
resolvedInProps,
|
|
29
|
+
splitInProps
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function defineResourceLayout(options) {
|
|
33
|
+
const { options: inProps, resources, layout } = options;
|
|
34
|
+
const normalizedResources = normalizeResources(resources);
|
|
35
|
+
const resourcesEnum = createPrimitivePropBuilder("string").enum(toResourceEnum(normalizedResources));
|
|
36
|
+
const definedResourceLayout = (layoutOptions) => {
|
|
37
|
+
const { name, props: instancePropDefinitions, ...layoutOptionProps } = layoutOptions;
|
|
38
|
+
const createComposableLayout = makeComposable();
|
|
39
|
+
const nameProp = createProp.string().literal(name);
|
|
40
|
+
const { resolvedInProps, splitInProps } = splitLayoutInProps({
|
|
41
|
+
...typeof inProps === "function" ? inProps({
|
|
42
|
+
resource: resourcesEnum,
|
|
43
|
+
name: nameProp
|
|
44
|
+
}) : inProps,
|
|
45
|
+
...instancePropDefinitions,
|
|
46
|
+
...layoutOptionProps
|
|
47
|
+
});
|
|
48
|
+
const { composables, render, props: layoutProps } = layout;
|
|
49
|
+
const customLayoutProps = layoutProps?.custom;
|
|
50
|
+
const includeLayoutProps = layoutProps?.include;
|
|
51
|
+
const resolvedLayoutProps = {
|
|
52
|
+
...pick(resolvedInProps, Object.keys(includeLayoutProps ?? {})),
|
|
53
|
+
...customLayoutProps
|
|
54
|
+
};
|
|
55
|
+
const layoutContext = {
|
|
56
|
+
resource: layoutOptions.resource,
|
|
57
|
+
name
|
|
58
|
+
};
|
|
59
|
+
const resolvedComposables = composables ? resolveLayoutComposables(composables, layoutContext) : void 0;
|
|
60
|
+
const mergedRenderContext = {
|
|
61
|
+
composables: resolvedComposables,
|
|
62
|
+
resource: layoutContext.resource,
|
|
63
|
+
name: layoutContext.name,
|
|
64
|
+
inProps: splitInProps
|
|
65
|
+
};
|
|
66
|
+
function Component(props) {
|
|
67
|
+
const validatedProps = validateProps(resolvedLayoutProps, props);
|
|
68
|
+
const includedPropKeys = Object.keys(includeLayoutProps ?? {});
|
|
69
|
+
const includedPropDefinitions = pick(resolvedInProps, includedPropKeys);
|
|
70
|
+
const validatedIncludedProps = validateProps(includedPropDefinitions, {
|
|
71
|
+
...resolvePropDefinitionValues(includedPropDefinitions),
|
|
72
|
+
...pick(splitInProps, includedPropKeys),
|
|
73
|
+
...pick(layoutOptionProps, includedPropKeys)
|
|
74
|
+
});
|
|
75
|
+
return /* @__PURE__ */ jsx(Fragment, { children: render({
|
|
76
|
+
...validatedProps,
|
|
77
|
+
...validatedIncludedProps
|
|
78
|
+
}, mergedRenderContext) });
|
|
79
|
+
}
|
|
80
|
+
function createComposition(compositionOptions) {
|
|
81
|
+
if (!compositionOptions.components) return {};
|
|
82
|
+
return { makeComposable: createComposableLayout(compositionOptions) };
|
|
83
|
+
}
|
|
84
|
+
return Object.assign(Component, {
|
|
85
|
+
displayName: name,
|
|
86
|
+
props: void 0,
|
|
87
|
+
...createComposition({
|
|
88
|
+
components: resolvedComposables,
|
|
89
|
+
name
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
return definedResourceLayout;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { defineResourceLayout };
|
|
98
|
+
//# sourceMappingURL=create-config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-config.mjs","names":[],"sources":["../src/create-config.tsx"],"sourcesContent":["import type { JSX } from 'react';\r\nimport {\r\n type ComposableComponents,\r\n type ComposableNameContext,\r\n type CreateLayoutComposable,\r\n MakeComposable,\r\n makeComposable,\r\n MakeComposableOptions,\r\n resolveLayoutComposables,\r\n} from './composable';\r\nimport {\r\n type AnyBuiltPropDefinition,\r\n createPrimitivePropBuilder,\r\n createProp,\r\n type ResolveLayoutProps,\r\n type ResolveProps,\r\n validateProps,\r\n} from './create-value';\r\nimport {\r\n IncludedProps,\r\n InferredInProps,\r\n InPropsDefinition,\r\n InPropsObject,\r\n LayoutRenderProps,\r\n} from './props';\r\nimport {\n normalizeResources,\n toResourceEnum,\n type LayoutResourceKey,\r\n type NormalizeResources,\r\n type ResourceDefinition,\n} from './resource';\nimport { BaseComponent, pick, resolvePropDefinitionValues, Show } from './utils';\n\r\ntype LayoutProps<\r\n Resources extends ReadonlyArray<ResourceDefinition>,\r\n Options extends InPropsDefinition<Resources>,\r\n IncludeProps extends IncludedProps<InferredInProps<Resources, Options>> = {},\r\n CustomProps extends InPropsObject = {},\r\n> = {\r\n /**\r\n * Props to include in the layout.\r\n */\r\n include?: IncludeProps;\r\n /**\r\n * Custom props that the layout will receive.\r\n */\r\n custom?: CustomProps;\r\n};\r\n\r\ntype LayoutRenderContext<\r\n Resources extends ReadonlyArray<ResourceDefinition>,\r\n Composables extends ComposableComponents,\r\n> = {\r\n composables: LayoutRenderComposables<Composables>;\r\n inProps: Record<string, unknown>;\r\n resource: LayoutResourceKey<Resources>;\r\n name: string;\r\n};\r\ntype LayoutRenderComposables<Composables extends ComposableComponents> =\r\n [keyof Composables] extends [never] ? undefined : Composables;\r\n\r\ntype SplitLayoutInPropDefinition<\r\n Props extends InPropsObject = {},\r\n Content = unknown,\r\n> = {\r\n props?: Props;\r\n render: ((props: ResolveProps<Props>) => Content) | Content;\r\n};\r\n\r\nfunction isBuiltPropDefinition(\r\n value: unknown,\r\n): value is AnyBuiltPropDefinition {\r\n return typeof value === 'function' && value !== null && 'visibility' in value;\r\n}\r\n\r\nfunction isSplitLayoutInPropDefinition(\r\n value: unknown,\r\n): value is SplitLayoutInPropDefinition {\r\n return (\r\n value !== null &&\r\n typeof value === 'object' &&\r\n 'render' in value &&\r\n (value as { render?: unknown }).render !== undefined\r\n );\r\n}\r\n\r\nfunction splitLayoutInProps(inProps: Record<string, unknown>) {\r\n const resolvedInProps: Record<string, AnyBuiltPropDefinition> = {};\r\n const splitInProps: Record<string, unknown> = {};\r\n\r\n for (const [key, value] of Object.entries(inProps)) {\r\n if (isBuiltPropDefinition(value)) {\r\n resolvedInProps[key] = value;\r\n continue;\r\n }\r\n\r\n if (isSplitLayoutInPropDefinition(value)) {\r\n splitInProps[key] = value.render;\r\n\r\n if (value.props && typeof value.props === 'object') {\r\n Object.assign(resolvedInProps, value.props);\r\n }\r\n }\r\n }\r\n\r\n return {\r\n resolvedInProps,\r\n splitInProps,\r\n };\r\n}\r\n\r\ntype CreateViewMapOptions<\r\n Resources extends ReadonlyArray<ResourceDefinition>,\r\n Options extends InPropsDefinition<Resources>,\r\n IncludeProps extends IncludedProps<InferredInProps<Resources, Options>> = {},\r\n CustomProps extends InPropsObject = {},\r\n Composables extends ComposableComponents = {},\r\n> = {\r\n /**\r\n * An array of valid resource names to support.\r\n */\r\n resources: Resources;\r\n /**\r\n * The options that are passed into the created resource layout.\r\n */\r\n options: Options;\r\n layout: {\r\n /**\r\n * The props to pass to the layout.\r\n */\r\n props?: LayoutProps<Resources, Options, IncludeProps, CustomProps>;\r\n /**\r\n * Components used to compose the layout. Invoked per layout instance with\r\n * a scoped `create` that resolves composable `name` callbacks using the\r\n * layout's `resource` and `name`.\r\n */\r\n composables?: (create: CreateLayoutComposable<LayoutResourceKey<Resources>>) => Composables;\r\n /**\r\n * The render function for the layout.\r\n */\r\n render: (\r\n props: LayoutRenderProps<Resources, Options, IncludeProps, CustomProps>,\r\n context: LayoutRenderContext<Resources, Composables>,\r\n ) => JSX.Element;\r\n };\r\n};\r\n\r\ntype ResourceLayoutComposition<\r\n Name extends string,\r\n Composables extends ComposableComponents,\r\n> = [keyof Composables] extends [never]\r\n ? {}\r\n : {\r\n makeComposable: MakeComposable<Composables, Name>;\r\n };\r\ntype ResourceLayoutComponent<\r\n Name extends string,\r\n Props extends InPropsObject = {},\r\n Composables extends ComposableComponents = {},\r\n> = ResourceLayoutComposition<Name, Composables> &\r\n BaseComponent<Name, ResolveProps<Props>> & {\r\n (props: Show<ResolveProps<Props>>): JSX.Element;\r\n };\r\n\r\ntype DefinedResourceLayoutOptions<\r\n Resources extends ReadonlyArray<ResourceDefinition>,\r\n InProps extends InPropsDefinition<Resources>,\r\n Name extends string,\r\n Resource extends LayoutResourceKey<Resources>,\r\n Props extends InPropsObject = {},\r\n> = ResolveLayoutProps<InferredInProps<Resources, InProps>> & {\r\n name: Name;\r\n resource: Resource;\r\n props?: Props;\r\n};\r\ntype DefinedResourceLayout<\r\n Resources extends ReadonlyArray<ResourceDefinition>,\r\n InProps extends InPropsDefinition<Resources>,\r\n IncludeProps extends IncludedProps<InferredInProps<Resources, InProps>> = {},\r\n CustomProps extends InPropsObject = {},\r\n Composables extends ComposableComponents = {},\r\n> = <\r\n Name extends string,\r\n Resource extends LayoutResourceKey<Resources>,\r\n Props extends InPropsObject = {},\r\n>(\r\n options: DefinedResourceLayoutOptions<\r\n Resources,\r\n InProps,\r\n Name,\r\n Resource,\r\n Props\r\n >,\r\n) => ResourceLayoutComponent<Name, CustomProps, Composables>;\r\n\r\nexport function defineResourceLayout<\r\n const Resources extends ReadonlyArray<ResourceDefinition>,\r\n InProps extends InPropsDefinition<Resources>,\r\n IncludeProps extends IncludedProps<InferredInProps<Resources, InProps>> = {},\r\n CustomProps extends InPropsObject = {},\r\n Composables extends ComposableComponents = {},\r\n>(\r\n options: CreateViewMapOptions<\r\n Resources,\r\n InProps,\r\n IncludeProps,\r\n CustomProps,\r\n Composables\r\n >,\r\n) {\r\n const { options: inProps, resources, layout } = options;\r\n const normalizedResources = normalizeResources(resources);\r\n const resourcesEnum = createPrimitivePropBuilder('string').enum(\r\n toResourceEnum(normalizedResources),\r\n );\r\n const definedResourceLayout: DefinedResourceLayout<\r\n Resources,\r\n InProps,\r\n IncludeProps,\r\n CustomProps,\r\n Composables\r\n > = (layoutOptions) => {\r\n const {\r\n name,\r\n props: instancePropDefinitions,\r\n ...layoutOptionProps\r\n } = layoutOptions;\r\n const createComposableLayout =\r\n makeComposable<\r\n LayoutRenderProps<Resources, InProps, IncludeProps, CustomProps>\r\n >();\r\n const nameProp = createProp.string().literal(name);\r\n const rawResolvedOptions =\r\n typeof inProps === 'function'\r\n ? inProps({\r\n resource: resourcesEnum,\r\n name: nameProp,\r\n })\r\n : inProps;\r\n const { resolvedInProps, splitInProps } = splitLayoutInProps({\r\n ...(rawResolvedOptions as Record<string, unknown>),\r\n ...(instancePropDefinitions as Record<string, unknown> | undefined),\r\n ...layoutOptionProps,\r\n });\r\n const { composables, render, props: layoutProps } = layout;\r\n const customLayoutProps = layoutProps?.custom;\r\n const includeLayoutProps = layoutProps?.include;\r\n const resolvedIncludedProps = pick(\r\n resolvedInProps,\r\n Object.keys(includeLayoutProps ?? {}),\r\n );\r\n const resolvedLayoutProps = {\r\n ...resolvedIncludedProps,\r\n ...customLayoutProps,\r\n };\r\n const layoutContext: ComposableNameContext<\r\n LayoutResourceKey<Resources>,\r\n typeof name\r\n > = {\r\n resource: layoutOptions.resource,\r\n name,\r\n };\r\n const resolvedComposables = composables\r\n ? resolveLayoutComposables(composables, layoutContext)\r\n : undefined;\r\n const mergedRenderContext = {\r\n composables: resolvedComposables as LayoutRenderComposables<Composables>,\r\n resource: layoutContext.resource,\r\n name: layoutContext.name,\r\n inProps: splitInProps,\r\n } as LayoutRenderContext<Resources, Composables>;\r\n\r\n function Component(props: Show<ResolveProps<CustomProps>>) {\n const validatedProps = validateProps(resolvedLayoutProps, props);\n const includedPropKeys = Object.keys(includeLayoutProps ?? {});\n const includedPropDefinitions = pick(\n resolvedInProps,\n includedPropKeys,\n ) as Record<string, unknown>;\n const includedPropValues = {\n ...resolvePropDefinitionValues(\n includedPropDefinitions,\n ),\n ...pick(\n splitInProps,\n includedPropKeys as (keyof typeof splitInProps)[],\n ),\n ...pick(\n layoutOptionProps,\n includedPropKeys as (keyof typeof layoutOptionProps)[],\n ),\n };\n const validatedIncludedProps = validateProps(\n includedPropDefinitions as Record<string, AnyBuiltPropDefinition>,\n includedPropValues,\n );\n const layoutRenderProps = {\n ...validatedProps,\n ...validatedIncludedProps,\n } as unknown as LayoutRenderProps<\n Resources,\n InProps,\n IncludeProps,\r\n CustomProps\r\n >;\r\n\r\n return <>{render(layoutRenderProps, mergedRenderContext)}</>;\r\n }\r\n\r\n function createComposition<LayoutName extends string>(\r\n compositionOptions: MakeComposableOptions<Composables, LayoutName>,\r\n ) {\r\n if (!compositionOptions.components) {\r\n return {} as ResourceLayoutComposition<LayoutName, Composables>;\r\n }\r\n\r\n return {\r\n makeComposable: createComposableLayout(compositionOptions),\r\n };\r\n }\r\n\r\n return Object.assign(Component, {\r\n displayName: name,\r\n props: undefined as unknown as ResolveProps<CustomProps>,\r\n ...createComposition({\r\n components: resolvedComposables as Composables | und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,sBAAsB;GAC1B,GAL4B,KAC5B,iBACA,OAAO,KAAK,sBAAsB,CAAC,CAAC,CAGb;GACvB,GAAG;EACL;EACA,MAAM,gBAGF;GACF,UAAU,cAAc;GACxB;EACF;EACA,MAAM,sBAAsB,cACxB,yBAAyB,aAAa,aAAa,IACnD;EACJ,MAAM,sBAAsB;GAC1B,aAAa;GACb,UAAU,cAAc;GACxB,MAAM,cAAc;GACpB,SAAS;EACX;EAEA,SAAS,UAAU,OAAwC;GACzD,MAAM,iBAAiB,cAAc,qBAAqB,KAAK;GAC/D,MAAM,mBAAmB,OAAO,KAAK,sBAAsB,CAAC,CAAC;GAC7D,MAAM,0BAA0B,KAC9B,iBACA,gBACF;GAcA,MAAM,yBAAyB,cAC7B,yBACA;IAdA,GAAG,4BACD,uBACF;IACA,GAAG,KACD,cACA,gBACF;IACA,GAAG,KACD,mBACA,gBACF;GAIiB,CACnB;GAWA,OAAO,0CAAG,OAAO;IATf,GAAG;IACH,GAAG;GAQ4B,GAAG,mBAAmB,EAAI;EAC7D;EAEA,SAAS,kBACP,oBACA;GACA,IAAI,CAAC,mBAAmB,YACtB,OAAO,CAAC;GAGV,OAAO,EACL,gBAAgB,uBAAuB,kBAAkB,EAC3D;EACF;EAEA,OAAO,OAAO,OAAO,WAAW;GAC9B,aAAa;GACb,OAAO;GACP,GAAG,kBAAkB;IACnB,YAAY;IACZ;GACF,CAAC;EACH,CAAC;CACH;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/create-value.ts
|
|
3
|
+
const primitiveTypes = {
|
|
4
|
+
string: "string",
|
|
5
|
+
number: "number",
|
|
6
|
+
boolean: "boolean",
|
|
7
|
+
object: "object",
|
|
8
|
+
array: "array",
|
|
9
|
+
date: "date",
|
|
10
|
+
regex: "regex",
|
|
11
|
+
error: "error",
|
|
12
|
+
symbol: "symbol",
|
|
13
|
+
bigint: "bigint"
|
|
14
|
+
};
|
|
15
|
+
function createInvalidPropValueMessage(type) {
|
|
16
|
+
return `"value" is not of type "${type}".`;
|
|
17
|
+
}
|
|
18
|
+
var InvalidPropValueError = class extends Error {
|
|
19
|
+
constructor(type) {
|
|
20
|
+
super(createInvalidPropValueMessage(type));
|
|
21
|
+
this.name = "InvalidPropValueError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var BaseProp = class {
|
|
25
|
+
type;
|
|
26
|
+
visibility;
|
|
27
|
+
value;
|
|
28
|
+
error;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
const { type, visibility, value } = options;
|
|
31
|
+
this.type = type;
|
|
32
|
+
this.visibility = visibility;
|
|
33
|
+
this.value = value;
|
|
34
|
+
this.error = new InvalidPropValueError(type);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var StringProp = class StringProp extends BaseProp {
|
|
38
|
+
constructor(visibility) {
|
|
39
|
+
super({
|
|
40
|
+
type: "string",
|
|
41
|
+
visibility
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
optional() {
|
|
45
|
+
return new StringProp("optional");
|
|
46
|
+
}
|
|
47
|
+
literal(value) {
|
|
48
|
+
return new LiteralProp(value, "string", this.visibility);
|
|
49
|
+
}
|
|
50
|
+
enum(values) {
|
|
51
|
+
return new EnumProp(values, "string", this.visibility);
|
|
52
|
+
}
|
|
53
|
+
validate(value) {
|
|
54
|
+
if (typeof value !== "string") throw this.error;
|
|
55
|
+
}
|
|
56
|
+
allows(value) {
|
|
57
|
+
return typeof value === "string";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var NumberProp = class NumberProp extends BaseProp {
|
|
61
|
+
constructor(visibility) {
|
|
62
|
+
super({
|
|
63
|
+
type: "number",
|
|
64
|
+
visibility
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
optional() {
|
|
68
|
+
return new NumberProp("optional");
|
|
69
|
+
}
|
|
70
|
+
literal(value) {
|
|
71
|
+
return new LiteralProp(value, "number", this.visibility);
|
|
72
|
+
}
|
|
73
|
+
enum(values) {
|
|
74
|
+
return new EnumProp(values, "number", this.visibility);
|
|
75
|
+
}
|
|
76
|
+
validate(value) {
|
|
77
|
+
if (typeof value !== "number") throw this.error;
|
|
78
|
+
}
|
|
79
|
+
allows(value) {
|
|
80
|
+
return typeof value === "number";
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var BooleanProp = class BooleanProp extends BaseProp {
|
|
84
|
+
constructor(visibility) {
|
|
85
|
+
super({
|
|
86
|
+
type: "boolean",
|
|
87
|
+
visibility
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
optional() {
|
|
91
|
+
return new BooleanProp("optional");
|
|
92
|
+
}
|
|
93
|
+
literal(value) {
|
|
94
|
+
return new LiteralProp(value, "boolean", this.visibility);
|
|
95
|
+
}
|
|
96
|
+
enum(values) {
|
|
97
|
+
return new EnumProp(values, "boolean", this.visibility);
|
|
98
|
+
}
|
|
99
|
+
validate(value) {
|
|
100
|
+
if (typeof value !== "boolean") throw this.error;
|
|
101
|
+
}
|
|
102
|
+
allows(value) {
|
|
103
|
+
return typeof value === "boolean";
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var LiteralProp = class LiteralProp extends BaseProp {
|
|
107
|
+
constructor(value, type, visibility) {
|
|
108
|
+
super({
|
|
109
|
+
type,
|
|
110
|
+
visibility,
|
|
111
|
+
value
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
optional() {
|
|
115
|
+
return new LiteralProp(this.value, this.type, "optional");
|
|
116
|
+
}
|
|
117
|
+
validate(value) {
|
|
118
|
+
if (value !== this.value) throw this.error;
|
|
119
|
+
}
|
|
120
|
+
allows(value) {
|
|
121
|
+
return value === this.value;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var EnumProp = class EnumProp extends BaseProp {
|
|
125
|
+
allowedValues;
|
|
126
|
+
constructor(values, type, visibility) {
|
|
127
|
+
super({
|
|
128
|
+
type,
|
|
129
|
+
visibility
|
|
130
|
+
});
|
|
131
|
+
this.allowedValues = values;
|
|
132
|
+
}
|
|
133
|
+
optional() {
|
|
134
|
+
return new EnumProp(this.allowedValues, this.type, "optional");
|
|
135
|
+
}
|
|
136
|
+
validate(value) {
|
|
137
|
+
if (typeof value !== primitiveTypes[this.type]) throw this.error;
|
|
138
|
+
if (!this.allowedValues.includes(value)) throw this.error;
|
|
139
|
+
}
|
|
140
|
+
allows(value) {
|
|
141
|
+
return this.allowedValues.includes(value);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var ObjectProp = class ObjectProp extends BaseProp {
|
|
145
|
+
properties;
|
|
146
|
+
constructor(properties, visibility) {
|
|
147
|
+
super({
|
|
148
|
+
type: "object",
|
|
149
|
+
visibility
|
|
150
|
+
});
|
|
151
|
+
this.properties = properties;
|
|
152
|
+
}
|
|
153
|
+
optional() {
|
|
154
|
+
return new ObjectProp(this.properties, "optional");
|
|
155
|
+
}
|
|
156
|
+
validate(value) {
|
|
157
|
+
const validatedObject = {};
|
|
158
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw this.error;
|
|
159
|
+
const objectValue = value;
|
|
160
|
+
for (const key in this.properties) {
|
|
161
|
+
const prop = this.properties[key];
|
|
162
|
+
const propertyValue = objectValue[key];
|
|
163
|
+
if (propertyValue === void 0) {
|
|
164
|
+
if (prop.visibility !== "optional") throw new TypeError(`"${key}" is required.`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
validatedObject[key] = prop(propertyValue);
|
|
168
|
+
}
|
|
169
|
+
return validatedObject;
|
|
170
|
+
}
|
|
171
|
+
allows(value) {
|
|
172
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
173
|
+
const objectValue = value;
|
|
174
|
+
for (const key in this.properties) {
|
|
175
|
+
const prop = this.properties[key];
|
|
176
|
+
const propertyValue = objectValue[key];
|
|
177
|
+
if (propertyValue === void 0) {
|
|
178
|
+
if (prop.visibility !== "optional") return false;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
prop(propertyValue);
|
|
183
|
+
} catch {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
var ComponentProp = class ComponentProp extends BaseProp {
|
|
191
|
+
constructor(type, visibility) {
|
|
192
|
+
super({
|
|
193
|
+
type,
|
|
194
|
+
visibility
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
optional() {
|
|
198
|
+
return new ComponentProp(this.type, "optional");
|
|
199
|
+
}
|
|
200
|
+
validate(value) {
|
|
201
|
+
if (this.type === "JSX.Element") {
|
|
202
|
+
if (value === null || typeof value !== "object" || !("$$typeof" in value)) throw this.error;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
allows(value) {
|
|
206
|
+
if (this.type === "JSX.Element") return value !== null && typeof value === "object" && "$$typeof" in value;
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var ComponentPropWithPropertiesProp = class ComponentPropWithPropertiesProp extends BaseProp {
|
|
211
|
+
properties;
|
|
212
|
+
constructor(type, properties, visibility) {
|
|
213
|
+
super({
|
|
214
|
+
type,
|
|
215
|
+
visibility
|
|
216
|
+
});
|
|
217
|
+
this.properties = properties;
|
|
218
|
+
}
|
|
219
|
+
optional() {
|
|
220
|
+
return new ComponentPropWithPropertiesProp(this.type, this.properties, "optional");
|
|
221
|
+
}
|
|
222
|
+
validate(value) {
|
|
223
|
+
if (this.type === "JSX.Element") {
|
|
224
|
+
if (value === null || typeof value !== "object" || !("$$typeof" in value)) throw this.error;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
allows(value) {
|
|
228
|
+
if (this.type === "JSX.Element") return value !== null && typeof value === "object" && "$$typeof" in value;
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
var UnionProp = class UnionProp extends BaseProp {
|
|
233
|
+
members;
|
|
234
|
+
constructor(members, visibility) {
|
|
235
|
+
super({
|
|
236
|
+
type: "union",
|
|
237
|
+
visibility
|
|
238
|
+
});
|
|
239
|
+
this.members = members;
|
|
240
|
+
}
|
|
241
|
+
optional() {
|
|
242
|
+
return new UnionProp(this.members, "optional");
|
|
243
|
+
}
|
|
244
|
+
validate(value) {
|
|
245
|
+
for (const member of this.members) if (member.allows(value)) return;
|
|
246
|
+
throw this.error;
|
|
247
|
+
}
|
|
248
|
+
allows(value) {
|
|
249
|
+
return this.members.some((m) => m.allows(value));
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
var RenderChildrenProp = class RenderChildrenProp extends BaseProp {
|
|
253
|
+
renderProps;
|
|
254
|
+
childrenType;
|
|
255
|
+
constructor(renderProps, childrenType, visibility) {
|
|
256
|
+
super({
|
|
257
|
+
type: "function",
|
|
258
|
+
visibility
|
|
259
|
+
});
|
|
260
|
+
this.renderProps = renderProps;
|
|
261
|
+
this.childrenType = childrenType;
|
|
262
|
+
}
|
|
263
|
+
optional() {
|
|
264
|
+
return new RenderChildrenProp(this.renderProps, this.childrenType, "optional");
|
|
265
|
+
}
|
|
266
|
+
validate(value) {
|
|
267
|
+
if (typeof value !== "function") throw this.error;
|
|
268
|
+
return value;
|
|
269
|
+
}
|
|
270
|
+
allows(value) {
|
|
271
|
+
return typeof value === "function";
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
function createConfiguredWrappedProp(prop, config) {
|
|
275
|
+
const validate = ((value) => prop.validate(value));
|
|
276
|
+
return Object.assign(validate, getPropState(prop), {
|
|
277
|
+
_baseProp: prop,
|
|
278
|
+
config
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
function getPropState(prop) {
|
|
282
|
+
const state = {
|
|
283
|
+
type: prop.type,
|
|
284
|
+
visibility: prop.visibility
|
|
285
|
+
};
|
|
286
|
+
if ("value" in prop && prop.value !== void 0) state.value = prop.value;
|
|
287
|
+
if (prop instanceof ObjectProp || prop instanceof ComponentPropWithPropertiesProp) state.properties = prop.properties;
|
|
288
|
+
if (prop instanceof UnionProp) state.members = prop.members;
|
|
289
|
+
if (prop instanceof RenderChildrenProp) {
|
|
290
|
+
state.renderProps = prop.renderProps;
|
|
291
|
+
state.childrenType = prop.childrenType;
|
|
292
|
+
}
|
|
293
|
+
return state;
|
|
294
|
+
}
|
|
295
|
+
function flattenUnionMembers(prop) {
|
|
296
|
+
return prop instanceof UnionProp ? [...prop.members] : [prop];
|
|
297
|
+
}
|
|
298
|
+
function wrapProp(prop) {
|
|
299
|
+
const validate = ((value) => prop.validate(value));
|
|
300
|
+
const chainedProps = getPropState(prop);
|
|
301
|
+
for (const methodName of [
|
|
302
|
+
"optional",
|
|
303
|
+
"literal",
|
|
304
|
+
"enum",
|
|
305
|
+
"config"
|
|
306
|
+
]) {
|
|
307
|
+
const method = prop[methodName];
|
|
308
|
+
if (typeof method === "function") {
|
|
309
|
+
if (methodName === "config") {
|
|
310
|
+
chainedProps.config = (config) => createConfiguredWrappedProp(prop, config);
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
chainedProps[methodName] = (...args) => {
|
|
314
|
+
return wrapProp(method.apply(prop, args));
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
chainedProps._baseProp = prop;
|
|
319
|
+
chainedProps.or = (other) => {
|
|
320
|
+
const otherBase = other._baseProp;
|
|
321
|
+
return wrapProp(new UnionProp([...flattenUnionMembers(prop), ...flattenUnionMembers(otherBase)], prop.visibility));
|
|
322
|
+
};
|
|
323
|
+
return Object.assign(validate, chainedProps);
|
|
324
|
+
}
|
|
325
|
+
function createPrimitiveProp(type, visibility) {
|
|
326
|
+
switch (type) {
|
|
327
|
+
case "string": return new StringProp(visibility);
|
|
328
|
+
case "number": return new NumberProp(visibility);
|
|
329
|
+
case "boolean": return new BooleanProp(visibility);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
function createWrappedProp(type, visibility) {
|
|
333
|
+
return (wrapperFor) => (value) => {
|
|
334
|
+
if (wrapperFor === "literal") return wrapProp(new LiteralProp(value, type, visibility));
|
|
335
|
+
if (wrapperFor === "enum") return wrapProp(new EnumProp(value, type, visibility));
|
|
336
|
+
throw new Error(`Invalid wrapper for: ${wrapperFor}`);
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function createPrimitivePropBuilder(type, visibility = "required") {
|
|
340
|
+
const propWrapper = createWrappedProp(type, visibility);
|
|
341
|
+
const builder = (() => wrapProp(createPrimitiveProp(type, visibility)));
|
|
342
|
+
return Object.assign(builder, {
|
|
343
|
+
literal: propWrapper("literal"),
|
|
344
|
+
enum: propWrapper("enum"),
|
|
345
|
+
config: (config) => createConfiguredWrappedProp(createPrimitiveProp(type, visibility), config),
|
|
346
|
+
...visibility === "required" ? { optional: () => createPrimitivePropBuilder(type, "optional") } : {}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function createObjectProp(properties) {
|
|
350
|
+
return wrapProp(new ObjectProp(properties, "required"));
|
|
351
|
+
}
|
|
352
|
+
function createComponentPropWithChildrenBuilder(type, visibility, childrenProp) {
|
|
353
|
+
const baseProp = new ComponentPropWithPropertiesProp(type, { children: childrenProp }, visibility);
|
|
354
|
+
const validate = ((value) => baseProp.validate(value));
|
|
355
|
+
return Object.assign(validate, {
|
|
356
|
+
_baseProp: baseProp,
|
|
357
|
+
type,
|
|
358
|
+
visibility,
|
|
359
|
+
props: (shape) => wrapProp(new ComponentPropWithPropertiesProp(type, {
|
|
360
|
+
...shape,
|
|
361
|
+
children: childrenProp
|
|
362
|
+
}, visibility)),
|
|
363
|
+
or: (other) => {
|
|
364
|
+
return wrapProp(new UnionProp([baseProp, ...flattenUnionMembers(other._baseProp)], baseProp.visibility));
|
|
365
|
+
},
|
|
366
|
+
...visibility === "required" ? { optional: () => createComponentPropWithChildrenBuilder(type, "optional", childrenProp) } : {}
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
function buildChildrenProp(childrenType, childrenVisibility, renderProps) {
|
|
370
|
+
if (renderProps !== void 0) return wrapProp(new RenderChildrenProp(renderProps, childrenType, childrenVisibility));
|
|
371
|
+
return wrapProp(new ComponentProp(childrenType, childrenVisibility));
|
|
372
|
+
}
|
|
373
|
+
function createComponentPropBuilder(type, visibility = "required") {
|
|
374
|
+
const prop = new ComponentProp(type, visibility);
|
|
375
|
+
const validate = ((value) => prop.validate(value));
|
|
376
|
+
return Object.assign(validate, {
|
|
377
|
+
type,
|
|
378
|
+
visibility,
|
|
379
|
+
_baseProp: prop,
|
|
380
|
+
props: (shape) => wrapProp(new ComponentPropWithPropertiesProp(type, shape, visibility)),
|
|
381
|
+
config: (config) => createConfiguredWrappedProp(prop, config),
|
|
382
|
+
withChildren: (options) => {
|
|
383
|
+
return createComponentPropWithChildrenBuilder(type, visibility, buildChildrenProp(options?.type ?? "ReactNode", options?.visibility ?? "optional", options?.props ?? void 0));
|
|
384
|
+
},
|
|
385
|
+
or: (other) => {
|
|
386
|
+
return wrapProp(new UnionProp([prop, ...flattenUnionMembers(other._baseProp)], prop.visibility));
|
|
387
|
+
},
|
|
388
|
+
...visibility === "required" ? { optional: () => createComponentPropBuilder(type, "optional") } : {}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
var MissingRequiredPropError = class extends Error {
|
|
392
|
+
constructor(key) {
|
|
393
|
+
super(`Property "${key}" is required but not provided.`);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
function validateProps(shape, props) {
|
|
397
|
+
for (const key in shape) {
|
|
398
|
+
const prop = shape[key];
|
|
399
|
+
if (prop.visibility === "required" && !(key in props)) throw new MissingRequiredPropError(key);
|
|
400
|
+
if (prop.visibility === "optional" && !(key in props)) continue;
|
|
401
|
+
prop(props[key]);
|
|
402
|
+
}
|
|
403
|
+
return props;
|
|
404
|
+
}
|
|
405
|
+
const createProp = {
|
|
406
|
+
string: createPrimitivePropBuilder("string"),
|
|
407
|
+
number: createPrimitivePropBuilder("number"),
|
|
408
|
+
boolean: createPrimitivePropBuilder("boolean"),
|
|
409
|
+
object: createObjectProp,
|
|
410
|
+
component: (options) => createComponentPropBuilder(options.type)
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
//#endregion
|
|
414
|
+
exports.createPrimitivePropBuilder = createPrimitivePropBuilder;
|
|
415
|
+
exports.createProp = createProp;
|
|
416
|
+
exports.validateProps = validateProps;
|
|
417
|
+
//# sourceMappingURL=create-value.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-value.cjs","names":[],"sources":["../src/create-value.ts"],"sourcesContent":["import { ReactNode, JSX } from 'react';\r\n\r\nexport type PrimitiveTypesMap = PrimitiveValueTypes & {\r\n object: object;\r\n array: unknown[];\r\n date: Date;\r\n regex: RegExp;\r\n error: Error;\r\n symbol: symbol;\r\n bigint: bigint;\r\n};\r\nexport type PrimitiveValueTypes = {\r\n string: string;\r\n number: number;\r\n boolean: boolean;\r\n};\r\n\r\nconst primitiveTypes = {\r\n string: 'string',\r\n number: 'number',\r\n boolean: 'boolean',\r\n object: 'object',\r\n array: 'array',\r\n date: 'date',\r\n regex: 'regex',\r\n error: 'error',\r\n symbol: 'symbol',\r\n bigint: 'bigint',\r\n} satisfies Record<keyof PrimitiveTypesMap, string>;\r\n\r\nfunction createInvalidPropValueMessage(type: string) {\r\n return `\"value\" is not of type \"${type}\".`;\r\n}\r\n\r\nclass InvalidPropValueError<Type extends string> extends Error {\r\n constructor(type: Type) {\r\n super(createInvalidPropValueMessage(type));\r\n\r\n this.name = 'InvalidPropValueError';\r\n }\r\n}\r\n\r\ntype PropVisibility = 'optional' | 'required';\r\ntype PrimitivePropType = keyof PrimitiveValueTypes;\r\nexport type NonEmptyReadonlyArray<Value> = readonly [Value, ...Value[]];\r\ntype PropConfig = Record<string, unknown>;\r\n\r\ntype PropType =\r\n | keyof PrimitiveTypesMap\r\n | ComponentPropType\r\n | 'union'\r\n | 'function';\r\ntype BasePropOptions<\r\n Type extends PropType,\r\n Visibility extends PropVisibility,\r\n Value = unknown,\r\n> = {\r\n type: Type;\r\n visibility: Visibility;\r\n value?: Value;\r\n};\r\n\r\nabstract class BaseProp<\r\n Type extends PropType,\r\n Visibility extends PropVisibility,\r\n Value = unknown,\r\n> {\r\n readonly type: Type;\r\n readonly visibility: Visibility;\r\n readonly value?: Value;\r\n\r\n protected error: InvalidPropValueError<Type>;\r\n\r\n constructor(options: BasePropOptions<Type, Visibility, Value>) {\r\n const { type, visibility, value } = options;\r\n\r\n this.type = type;\r\n this.visibility = visibility;\r\n this.value = value;\r\n this.error = new InvalidPropValueError(type);\r\n }\r\n\r\n abstract validate(value: unknown): void;\r\n abstract allows(value: unknown): value is Value;\r\n}\r\n\r\nexport class StringProp<Visibility extends PropVisibility> extends BaseProp<\r\n 'string',\r\n Visibility,\r\n string\r\n> {\r\n constructor(visibility: Visibility) {\r\n super({ type: 'string', visibility });\r\n }\r\n\r\n optional(this: StringProp<'required'>) {\r\n return new StringProp('optional');\r\n }\r\n\r\n literal<const Value extends string>(value: Value) {\r\n return new LiteralProp(value, 'string', this.visibility);\r\n }\r\n\r\n enum<const Values extends NonEmptyReadonlyArray<string>>(values: Values) {\r\n return new EnumProp(values, 'string', this.visibility);\r\n }\r\n\r\n validate(value: unknown) {\r\n if (typeof value !== 'string') {\r\n throw this.error;\r\n }\r\n }\r\n\r\n allows(value: unknown): value is string {\r\n return typeof value === 'string';\r\n }\r\n}\r\n\r\nclass NumberProp<Visibility extends PropVisibility> extends BaseProp<\r\n 'number',\r\n Visibility,\r\n number\r\n> {\r\n constructor(visibility: Visibility) {\r\n super({ type: 'number', visibility });\r\n }\r\n\r\n optional(this: NumberProp<'required'>) {\r\n return new NumberProp('optional');\r\n }\r\n\r\n literal<const Value extends number>(value: Value) {\r\n return new LiteralProp(value, 'number', this.visibility);\r\n }\r\n\r\n enum<const Values extends NonEmptyReadonlyArray<number>>(values: Values) {\r\n return new EnumProp(values, 'number', this.visibility);\r\n }\r\n\r\n validate(value: unknown) {\r\n if (typeof value !== 'number') {\r\n throw this.error;\r\n }\r\n }\r\n\r\n allows(value: unknown): value is number {\r\n return typeof value === 'number';\r\n }\r\n}\r\n\r\nclass BooleanProp<Visibility extends PropVisibility> extends BaseProp<\r\n 'boolean',\r\n Visibility,\r\n boolean\r\n> {\r\n constructor(visibility: Visibility) {\r\n super({ type: 'boolean', visibility });\r\n }\r\n\r\n optional(this: BooleanProp<'required'>) {\r\n return new BooleanProp('optional');\r\n }\r\n\r\n literal<const Value extends boolean>(value: Value) {\r\n return new LiteralProp(value, 'boolean', this.visibility);\r\n }\r\n\r\n enum<const Values extends NonEmptyReadonlyArray<boolean>>(values: Values) {\r\n return new EnumProp(values, 'boolean', this.visibility);\r\n }\r\n\r\n validate(value: unknown) {\r\n if (typeof value !== 'boolean') {\r\n throw this.error;\r\n }\r\n }\r\n\r\n allows(value: unknown): value is boolean {\r\n return typeof value === 'boolean';\r\n }\r\n}\r\n\r\nclass LiteralProp<\r\n const Value extends PrimitiveTypesMap[Type],\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n> extends BaseProp<Type, Visibility, Value> {\r\n declare readonly value: Value;\r\n\r\n constructor(value: Value, type: Type, visibility: Visibility) {\r\n super({ type, visibility, value });\r\n }\r\n\r\n optional(this: LiteralProp<Value, Type, 'required'>) {\r\n return new LiteralProp(this.value, this.type, 'optional');\r\n }\r\n\r\n validate(value: unknown) {\r\n if (value !== this.value) {\r\n throw this.error;\r\n }\r\n }\r\n\r\n allows(value: unknown): value is Value {\r\n return value === this.value;\r\n }\r\n}\r\n\r\nclass EnumProp<\r\n const Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>,\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n> extends BaseProp<Type, Visibility, Values[number]> {\r\n private readonly allowedValues: Values;\r\n\r\n constructor(values: Values, type: Type, visibility: Visibility) {\r\n super({ type, visibility });\r\n this.allowedValues = values;\r\n }\r\n\r\n optional(this: EnumProp<Values, Type, 'required'>) {\r\n return new EnumProp(this.allowedValues, this.type, 'optional');\r\n }\r\n\r\n validate(value: unknown) {\r\n if (typeof value !== primitiveTypes[this.type]) {\r\n throw this.error;\r\n }\r\n\r\n if (\r\n !(this.allowedValues as readonly PrimitiveTypesMap[Type][]).includes(\r\n value as PrimitiveTypesMap[Type],\r\n )\r\n ) {\r\n throw this.error;\r\n }\r\n }\r\n\r\n allows(value: unknown): value is Values[number] {\r\n // TODO alter for more complex scenarios\r\n return this.allowedValues.includes(value as never);\r\n }\r\n}\r\n\r\ntype AnyBaseProp = BaseProp<PropType, PropVisibility, unknown>;\r\n\r\ntype ExtractPropValue<Prop extends AnyBaseProp> =\r\n Prop extends BaseProp<any, any, infer V> ? V : never;\r\n\r\ntype ExtractVisibility<Prop extends AnyBaseProp> =\r\n Prop extends BaseProp<any, infer V extends PropVisibility, any>\r\n ? V\r\n : PropVisibility;\r\n\r\ntype OptionalChain<\r\n Visibility extends PropVisibility,\r\n OptionalProp extends AnyBaseProp,\r\n> = Visibility extends 'required'\r\n ? { optional(): WrappedProp<OptionalProp> }\r\n : {};\r\n\r\ntype ConfigOptions = {};\r\ntype ConfigChain<Prop extends AnyBaseProp> = {\r\n config<const Config extends PropConfig>(\r\n config: Config,\r\n ): ConfiguredWrappedProp<Prop, Config>;\r\n};\r\n\r\ntype PrimitiveWrappedPropState<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n Value,\r\n> = {\r\n type: Type;\r\n visibility: Visibility;\r\n} & ([Value] extends [never] ? {} : { value: Value });\r\n\r\ntype ObjectWrappedPropState<\r\n Shape extends BuiltPropShape,\r\n Visibility extends PropVisibility,\r\n> = {\r\n type: 'object';\r\n visibility: Visibility;\r\n properties: Shape;\r\n};\r\n\r\ntype ComponentWithPropsWrappedPropState<\r\n Type extends ComponentPropType,\r\n Shape extends BuiltPropShape,\r\n Visibility extends PropVisibility,\r\n> = {\r\n type: Type;\r\n visibility: Visibility;\r\n properties: Shape;\r\n};\r\n\r\ntype UnionWrappedPropState<\r\n Members extends readonly AnyBaseProp[],\r\n Visibility extends PropVisibility,\r\n> = {\r\n type: 'union';\r\n visibility: Visibility;\r\n members: Members;\r\n};\r\n\r\ntype RenderChildrenWrappedPropState<\r\n Shape extends BuiltPropShape,\r\n ChildrenType extends ComponentPropType,\r\n Visibility extends PropVisibility,\r\n> = {\r\n type: 'function';\r\n visibility: Visibility;\r\n renderProps: Shape;\r\n childrenType: ChildrenType;\r\n};\r\n\r\ntype StringWrappedPropState<Visibility extends PropVisibility> =\r\n PrimitiveWrappedPropState<'string', Visibility, string | undefined>;\r\ntype NumberWrappedPropState<Visibility extends PropVisibility> =\r\n PrimitiveWrappedPropState<'number', Visibility, number | undefined>;\r\ntype BooleanWrappedPropState<Visibility extends PropVisibility> =\r\n PrimitiveWrappedPropState<'boolean', Visibility, boolean | undefined>;\r\ntype LiteralWrappedPropState<\r\n Value,\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n> = PrimitiveWrappedPropState<Type, Visibility, Value>;\r\ntype EnumWrappedPropState<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n> = PrimitiveWrappedPropState<Type, Visibility, never>;\r\n\r\ntype WrappedPropState<Prop extends AnyBaseProp> =\r\n Prop extends StringProp<infer Visibility>\r\n ? StringWrappedPropState<Visibility>\r\n : Prop extends NumberProp<infer Visibility>\r\n ? NumberWrappedPropState<Visibility>\r\n : Prop extends BooleanProp<infer Visibility>\r\n ? BooleanWrappedPropState<Visibility>\r\n : Prop extends LiteralProp<infer Value, infer Type, infer Visibility>\r\n ? LiteralWrappedPropState<Value, Type, Visibility>\r\n : Prop extends EnumProp<infer _Values, infer Type, infer Visibility>\r\n ? EnumWrappedPropState<Type, Visibility>\r\n : Prop extends ObjectProp<infer Shape, infer Visibility>\r\n ? ObjectWrappedPropState<Shape, Visibility>\r\n : Prop extends ComponentPropWithPropertiesProp<\r\n infer Type,\r\n infer Shape,\r\n infer Visibility\r\n >\r\n ? ComponentWithPropsWrappedPropState<Type, Shape, Visibility>\r\n : Prop extends ComponentProp<infer Type, infer Visibility>\r\n ? { type: Type; visibility: Visibility }\r\n : Prop extends UnionProp<infer Members, infer Visibility>\r\n ? UnionWrappedPropState<Members, Visibility>\r\n : Prop extends RenderChildrenProp<\r\n infer Shape,\r\n infer ChildrenType,\r\n infer Visibility\r\n >\r\n ? RenderChildrenWrappedPropState<\r\n Shape,\r\n ChildrenType,\r\n Visibility\r\n >\r\n : never;\r\n\r\ntype ConfiguredWrappedProp<\r\n Prop extends AnyBaseProp,\r\n Config extends PropConfig,\r\n> = ((value: unknown) => ReturnType<Prop['validate']>) &\r\n WrappedPropState<Prop> & {\r\n _baseProp: Prop;\r\n config: Config;\r\n };\r\n\r\nexport type WrappedProp<Prop extends AnyBaseProp> = ((\r\n value: unknown,\r\n) => ReturnType<Prop['validate']>) &\r\n WrappedPropState<Prop> &\r\n WrappedPropChainMembers<Prop> & {\r\n _baseProp: Prop;\r\n or<Other extends AnyBaseProp>(other: {\r\n _baseProp: Other;\r\n }): WrappedProp<UnionProp<readonly [Prop, Other], ExtractVisibility<Prop>>>;\r\n };\r\n\r\nexport type LiteralWrappedProp<\r\n Value extends PrimitiveTypesMap[Type],\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n> = WrappedProp<LiteralProp<Value, Type, Visibility>>;\r\n\r\nexport type EnumWrappedProp<\r\n Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>,\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n> = WrappedProp<EnumProp<Values, Type, Visibility>>;\r\ntype WrapperFor = 'literal' | 'enum';\r\ntype GetValueForWrapper<\r\n Type extends PrimitivePropType,\r\n For extends WrapperFor,\r\n Value extends PrimitiveTypesMap[Type],\r\n> = For extends 'literal'\r\n ? Value\r\n : For extends 'enum'\r\n ? NonEmptyReadonlyArray<Value>\r\n : never;\r\ntype WrappedPropFor<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n For extends WrapperFor,\r\n Value extends PrimitiveTypesMap[Type],\r\n> = For extends 'literal'\r\n ? LiteralWrappedProp<Value, Type, Visibility>\r\n : For extends 'enum'\r\n ? EnumWrappedProp<NonEmptyReadonlyArray<Value>, Type, Visibility>\r\n : never;\r\ntype CreateWrappedProp<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n For extends WrapperFor,\r\n> = <Value extends PrimitiveTypesMap[Type]>(\r\n value: GetValueForWrapper<Type, For, Value>,\r\n) => WrappedPropFor<Type, Visibility, For, Value>;\r\n\r\ntype WrappedPropBuilder<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n Prop extends AnyBaseProp,\r\n OptionalProp extends AnyBaseProp,\r\n> = ConfigChain<Prop> &\r\n OptionalChain<Visibility, OptionalProp> & {\r\n literal: CreateWrappedProp<Type, Visibility, 'literal'>;\r\n enum: CreateWrappedProp<Type, Visibility, 'enum'>;\r\n };\r\n\r\ntype PrimitivePropTypeMap<Visibility extends PropVisibility> = {\r\n string: WrappedPropBuilder<\r\n 'string',\r\n Visibility,\r\n StringProp<Visibility>,\r\n StringProp<'optional'>\r\n >;\r\n number: WrappedPropBuilder<\r\n 'number',\r\n Visibility,\r\n NumberProp<Visibility>,\r\n NumberProp<'optional'>\r\n >;\r\n boolean: WrappedPropBuilder<\r\n 'boolean',\r\n Visibility,\r\n BooleanProp<Visibility>,\r\n BooleanProp<'optional'>\r\n >;\r\n};\r\ntype SpecialPropTypeMap = {};\r\ntype WrappedPrimitiveProp<Prop> =\r\n Prop extends BaseProp<\r\n infer type extends PrimitivePropType,\r\n infer visibility extends PropVisibility\r\n >\r\n ? PrimitivePropTypeMap<visibility>[type]\r\n : never;\r\ntype ConfigChainBuilder<\r\n Prop extends AnyBaseProp,\r\n Visibility extends PropVisibility,\r\n OptionalProp extends AnyBaseProp,\r\n> = ConfigChain<Prop> & OptionalChain<Visibility, OptionalProp>;\r\n\r\ntype WrappedSpecialProp<Prop> =\r\n Prop extends LiteralProp<infer value, infer type, infer visibility>\r\n ? ConfigChainBuilder<\r\n LiteralProp<value, type, visibility>,\r\n visibility,\r\n LiteralProp<value, type, 'optional'>\r\n >\r\n : Prop extends EnumProp<infer values, infer type, infer visibility>\r\n ? ConfigChainBuilder<\r\n EnumProp<values, type, visibility>,\r\n visibility,\r\n EnumProp<values, type, 'optional'>\r\n >\r\n : never;\r\ntype WrappedObjectProp<Prop> =\r\n Prop extends ObjectProp<infer Shape, infer Visibility>\r\n ? OptionalChain<Visibility, ObjectProp<Shape, 'optional'>>\r\n : never;\r\ntype WrappedComponentWithPropsProp<Prop> =\r\n Prop extends ComponentPropWithPropertiesProp<\r\n infer Type,\r\n infer Shape,\r\n infer Visibility\r\n >\r\n ? OptionalChain<\r\n Visibility,\r\n ComponentPropWithPropertiesProp<Type, Shape, 'optional'>\r\n >\r\n : never;\r\ntype WrappedUnionProp<Prop> =\r\n Prop extends UnionProp<infer Members, infer Visibility>\r\n ? OptionalChain<Visibility, UnionProp<Members, 'optional'>>\r\n : never;\r\ntype WrappedPropChainMembers<Prop extends AnyBaseProp> = [\r\n WrappedSpecialProp<Prop>,\r\n] extends [never]\r\n ? [WrappedObjectProp<Prop>] extends [never]\r\n ? [WrappedComponentWithPropsProp<Prop>] extends [never]\r\n ? [WrappedUnionProp<Prop>] extends [never]\r\n ? [WrappedPrimitiveProp<Prop>] extends [never]\r\n ? {}\r\n : WrappedPrimitiveProp<Prop>\r\n : WrappedUnionProp<Prop>\r\n : WrappedComponentWithPropsProp<Prop>\r\n : WrappedObjectProp<Prop>\r\n : WrappedSpecialProp<Prop>;\r\nexport interface AnyBuiltPropDefinition {\r\n (value: unknown): unknown;\r\n visibility: PropVisibility;\r\n _baseProp?: AnyBaseProp;\r\n}\r\ninterface BuiltPropShape {\r\n [key: string]: AnyBuiltPropDefinition;\r\n}\r\ntype ResolveBuiltPropValue<Definition extends AnyBuiltPropDefinition> =\r\n ReturnType<Definition>;\r\ntype ExtractDefinitionValue<D extends AnyBuiltPropDefinition> = D extends {\r\n _baseProp: infer P extends AnyBaseProp;\r\n}\r\n ? ExtractPropValue<P>\r\n : ReturnType<D>;\r\ntype ResolvedBuiltPropShape<Shape extends BuiltPropShape> = {\r\n [Key in keyof Shape as Shape[Key]['visibility'] extends 'required'\r\n ? Key\r\n : never]: ExtractDefinitionValue<Shape[Key]>;\r\n} & {\r\n [Key in keyof Shape as Shape[Key]['visibility'] extends 'required'\r\n ? never\r\n : Key]?: ExtractDefinitionValue<Shape[Key]>;\r\n};\r\n\r\n/** True when the prop's state type carries `type: 'JSX.Element'`. */\r\ntype IsJSXElementProp<D extends AnyBuiltPropDefinition> = D extends {\r\n type: 'JSX.Element';\r\n}\r\n ? true\r\n : false;\r\n\r\n/**\r\n * Returns the resolved key name for a prop: capitalizes the key when the prop\r\n * is a JSX.Element component prop (React convention for component slot props).\r\n */\r\ntype ResolvedPropKey<K extends string, D extends AnyBuiltPropDefinition> =\r\n IsJSXElementProp<D> extends true ? Capitalize<K> : K;\r\n\r\n/**\r\n * Resolves a shape of prop definitions created by the `createProp` builders\r\n * into a plain TypeScript props interface.\r\n *\r\n * - Optional props become optional keys (`prop?: Type`).\r\n * - Props whose type is `JSX.Element` have their key capitalized\r\n * (`icon` → `Icon`), following React's component-prop convention.\r\n */\r\nexport type ResolveProps<Shape extends Record<string, AnyBuiltPropDefinition>> =\r\n {\r\n [K in keyof Shape & string as Shape[K]['visibility'] extends 'required'\r\n ? ResolvedPropKey<K, Shape[K]>\r\n : never]: ExtractDefinitionValue<Shape[K]>;\r\n } & {\r\n [K in keyof Shape & string as Shape[K]['visibility'] extends 'required'\r\n ? never\r\n : ResolvedPropKey<K, Shape[K]>]?: ExtractDefinitionValue<Shape[K]>;\r\n };\r\n\r\n/**\r\n * Like `ExtractDefinitionValue` but for union members (base props).\r\n * JSX.Element component props become render functions.\r\n */\r\ntype ExtractLayoutMemberValue<P extends AnyBaseProp> = P extends {\r\n type: 'JSX.Element';\r\n properties: infer Shape extends Record<string, AnyBuiltPropDefinition>;\r\n}\r\n ? (props: ResolveProps<Shape>) => JSX.Element\r\n : P extends { type: 'JSX.Element' }\r\n ? () => JSX.Element\r\n : ExtractPropValue<P>;\r\n\r\n/**\r\n * Like `ExtractDefinitionValue` but JSX.Element component props resolve as\r\n * render functions instead of the raw `JSX.Element` value:\r\n * - No component props → `() => JSX.Element`\r\n * - With component props → `(props: ResolveProps<Shape>) => JSX.Element`\r\n * Union members are resolved individually with the same rule.\r\n */\r\ntype ExtractLayoutDefinitionValue<D extends AnyBuiltPropDefinition> =\r\n D extends {\r\n type: 'JSX.Element';\r\n properties: infer Shape extends Record<string, AnyBuiltPropDefinition>;\r\n }\r\n ? (props: ResolveProps<Shape>) => JSX.Element\r\n : D extends { type: 'JSX.Element' }\r\n ? () => JSX.Element\r\n : D extends { members: infer Members extends readonly AnyBaseProp[] }\r\n ? ExtractLayoutMemberValue<Members[number]>\r\n : ExtractDefinitionValue<D>;\r\n\r\n/**\r\n * Like `ResolveProps` but intended for the resolved options passed to the\r\n * function returned by `defineResourceLayout`. JSX.Element component props\r\n * become render functions so consumers provide a component slot rather than\r\n * a pre-rendered element:\r\n * - `createProp.component({ type: 'JSX.Element' })` → `() => JSX.Element`\r\n * - `createProp.component({ type: 'JSX.Element' }).props({ ... })` →\r\n * `(props: ResolveProps<Shape>) => JSX.Element`\r\n */\r\nexport type ResolveLayoutProps<\r\n Shape extends Record<string, AnyBuiltPropDefinition>,\r\n> = {\r\n [K in keyof Shape & string as Shape[K]['visibility'] extends 'required'\r\n ? ResolvedPropKey<K, Shape[K]>\r\n : never]: ExtractLayoutDefinitionValue<Shape[K]>;\r\n} & {\r\n [K in keyof Shape & string as Shape[K]['visibility'] extends 'required'\r\n ? never\r\n : ResolvedPropKey<K, Shape[K]>]?: ExtractLayoutDefinitionValue<Shape[K]>;\r\n};\r\n\r\nclass ObjectProp<\r\n const Shape extends BuiltPropShape,\r\n Visibility extends PropVisibility,\r\n> extends BaseProp<\r\n 'object',\r\n Visibility,\r\n {\r\n [Key in keyof Shape]: ResolveBuiltPropValue<Shape[Key]>;\r\n }\r\n> {\r\n readonly properties: Shape;\r\n\r\n constructor(properties: Shape, visibility: Visibility) {\r\n super({ type: 'object', visibility });\r\n this.properties = properties;\r\n }\r\n\r\n optional(this: ObjectProp<Shape, 'required'>) {\r\n return new ObjectProp(this.properties, 'optional');\r\n }\r\n\r\n validate(value: unknown) {\r\n const validatedObject = {} as {\r\n [Key in keyof Shape]: ResolveBuiltPropValue<Shape[Key]>;\r\n };\r\n\r\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\r\n throw this.error;\r\n }\r\n\r\n const objectValue = value as Record<string, unknown>;\r\n\r\n for (const key in this.properties) {\r\n const prop = this.properties[key];\r\n const propertyValue = objectValue[key];\r\n\r\n if (propertyValue === undefined) {\r\n if (prop.visibility !== 'optional') {\r\n throw new TypeError(`\"${key}\" is required.`);\r\n }\r\n\r\n continue;\r\n }\r\n\r\n validatedObject[key] = prop(propertyValue) as ResolveBuiltPropValue<\r\n Shape[typeof key]\r\n >;\r\n }\r\n\r\n return validatedObject;\r\n }\r\n\r\n allows(value: unknown): value is {\r\n [Key in keyof Shape]: ResolveBuiltPropValue<Shape[Key]>;\r\n } {\r\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\r\n return false;\r\n }\r\n\r\n const objectValue = value as Record<string, unknown>;\r\n\r\n for (const key in this.properties) {\r\n const prop = this.properties[key];\r\n const propertyValue = objectValue[key];\r\n\r\n if (propertyValue === undefined) {\r\n if (prop.visibility !== 'optional') {\r\n return false;\r\n }\r\n\r\n continue;\r\n }\r\n\r\n try {\r\n prop(propertyValue);\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n\r\nclass ComponentProp<\r\n Type extends ComponentPropType,\r\n Visibility extends PropVisibility,\r\n> extends BaseProp<Type, Visibility, ComponentPropTypeMap[Type]> {\r\n constructor(type: Type, visibility: Visibility) {\r\n super({ type, visibility });\r\n }\r\n\r\n optional(this: ComponentProp<Type, 'required'>) {\r\n return new ComponentProp(this.type, 'optional');\r\n }\r\n\r\n validate(value: unknown) {\r\n if (this.type === 'JSX.Element') {\r\n if (\r\n value === null ||\r\n typeof value !== 'object' ||\r\n !('$$typeof' in value)\r\n ) {\r\n throw this.error;\r\n }\r\n }\r\n }\r\n\r\n allows(value: unknown): value is ComponentPropTypeMap[Type] {\r\n if (this.type === 'JSX.Element') {\r\n return value !== null && typeof value === 'object' && '$$typeof' in value;\r\n }\r\n return true;\r\n }\r\n}\r\n\r\nclass ComponentPropWithPropertiesProp<\r\n Type extends ComponentPropType,\r\n const Shape extends BuiltPropShape,\r\n Visibility extends PropVisibility,\r\n> extends BaseProp<Type, Visibility, ComponentPropTypeMap[Type]> {\r\n readonly properties: Shape;\r\n\r\n constructor(type: Type, properties: Shape, visibility: Visibility) {\r\n super({ type, visibility });\r\n this.properties = properties;\r\n }\r\n\r\n optional(this: ComponentPropWithPropertiesProp<Type, Shape, 'required'>) {\r\n return new ComponentPropWithPropertiesProp(\r\n this.type,\r\n this.properties,\r\n 'optional',\r\n );\r\n }\r\n\r\n validate(value: unknown) {\r\n if (this.type === 'JSX.Element') {\r\n if (\r\n value === null ||\r\n typeof value !== 'object' ||\r\n !('$$typeof' in value)\r\n ) {\r\n throw this.error;\r\n }\r\n }\r\n }\r\n\r\n allows(value: unknown): value is ComponentPropTypeMap[Type] {\r\n if (this.type === 'JSX.Element') {\r\n return value !== null && typeof value === 'object' && '$$typeof' in value;\r\n }\r\n return true;\r\n }\r\n}\r\n\r\nclass UnionProp<\r\n const Members extends readonly AnyBaseProp[],\r\n Visibility extends PropVisibility,\r\n> extends BaseProp<'union', Visibility, ExtractPropValue<Members[number]>> {\r\n readonly members: Members;\r\n\r\n constructor(members: Members, visibility: Visibility) {\r\n super({ type: 'union', visibility });\r\n this.members = members;\r\n }\r\n\r\n optional(this: UnionProp<Members, 'required'>) {\r\n return new UnionProp(this.members, 'optional');\r\n }\r\n\r\n validate(value: unknown) {\r\n for (const member of this.members) {\r\n if (member.allows(value)) return;\r\n }\r\n throw this.error;\r\n }\r\n\r\n allows(value: unknown): value is ExtractPropValue<Members[number]> {\r\n return this.members.some((m) => m.allows(value));\r\n }\r\n}\r\n\r\nclass RenderChildrenProp<\r\n const Shape extends BuiltPropShape,\r\n ChildrenType extends ComponentPropType,\r\n Visibility extends PropVisibility,\r\n> extends BaseProp<\r\n 'function',\r\n Visibility,\r\n (\r\n renderProps: ResolvedBuiltPropShape<Shape>,\r\n ) => ComponentPropTypeMap[ChildrenType]\r\n> {\r\n readonly renderProps: Shape;\r\n readonly childrenType: ChildrenType;\r\n\r\n constructor(\r\n renderProps: Shape,\r\n childrenType: ChildrenType,\r\n visibility: Visibility,\r\n ) {\r\n super({ type: 'function', visibility });\r\n this.renderProps = renderProps;\r\n this.childrenType = childrenType;\r\n }\r\n\r\n optional(this: RenderChildrenProp<Shape, ChildrenType, 'required'>) {\r\n return new RenderChildrenProp(\r\n this.renderProps,\r\n this.childrenType,\r\n 'optional',\r\n );\r\n }\r\n\r\n validate(value: unknown) {\r\n if (typeof value !== 'function') {\r\n throw this.error;\r\n }\r\n return value as (\r\n renderProps: ResolvedBuiltPropShape<Shape>,\r\n ) => ComponentPropTypeMap[ChildrenType];\r\n }\r\n\r\n allows(\r\n value: unknown,\r\n ): value is (\r\n renderProps: ResolvedBuiltPropShape<Shape>,\r\n ) => ComponentPropTypeMap[ChildrenType] {\r\n return typeof value === 'function';\r\n }\r\n}\r\n\r\nexport type EnumValueDefinition<\r\n Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>,\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility = 'required',\r\n> = WrappedProp<EnumProp<Values, Type, Visibility>>;\r\nexport type ObjectValueDefinition<\r\n Shape extends BuiltPropShape,\r\n Visibility extends PropVisibility = 'required',\r\n> = WrappedProp<ObjectProp<Shape, Visibility>>;\r\n\r\ntype PrimitivePropInstanceMap<Visibility extends PropVisibility> = {\r\n string: WrappedProp<StringProp<Visibility>>;\r\n number: WrappedProp<NumberProp<Visibility>>;\r\n boolean: WrappedProp<BooleanProp<Visibility>>;\r\n};\r\n\r\ntype PrimitiveBasePropInstanceMap<Visibility extends PropVisibility> = {\r\n string: StringProp<Visibility>;\r\n number: NumberProp<Visibility>;\r\n boolean: BooleanProp<Visibility>;\r\n};\r\n\r\ntype LiteralPropBuilder<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility = 'required',\r\n> = <const Value extends PrimitiveTypesMap[Type]>(\r\n value: Value,\r\n) => LiteralWrappedProp<Value, Type, Visibility>;\r\ntype EnumPropBuilder<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility = 'required',\r\n> = <const Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>>(\r\n values: Values,\r\n) => EnumWrappedProp<Values, Type, Visibility>;\r\ntype PrimitivePropBuilder<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility = 'required',\r\n> = (() => PrimitivePropInstanceMap<Visibility>[Type]) & {\r\n literal: LiteralPropBuilder<Type, Visibility>;\r\n enum: EnumPropBuilder<Type, Visibility>;\r\n config<const Config extends PropConfig>(\r\n config: Config,\r\n ): ConfiguredWrappedProp<\r\n PrimitiveBasePropInstanceMap<Visibility>[Type],\r\n Config\r\n >;\r\n} & (Visibility extends 'required'\r\n ? {\r\n optional(): PrimitivePropBuilder<Type, 'optional'>;\r\n }\r\n : {});\r\n\r\nfunction createConfiguredWrappedProp<\r\n Prop extends AnyBaseProp,\r\n const Config extends PropConfig,\r\n>(prop: Prop, config: Config): ConfiguredWrappedProp<Prop, Config> {\r\n const validate = ((value: unknown) =>\r\n prop.validate(value)) as ConfiguredWrappedProp<Prop, Config>;\r\n\r\n return Object.assign(validate, getPropState(prop), {\r\n _baseProp: prop,\r\n config,\r\n });\r\n}\r\n\r\nfunction getPropState<Prop extends AnyBaseProp>(\r\n prop: Prop,\r\n): WrappedPropState<Prop> {\r\n const state = {\r\n type: prop.type,\r\n visibility: prop.visibility,\r\n } as Record<string, unknown>;\r\n\r\n if ('value' in prop && prop.value !== undefined) {\r\n state.value = prop.value;\r\n }\r\n\r\n if (\r\n prop instanceof ObjectProp ||\r\n prop instanceof ComponentPropWithPropertiesProp\r\n ) {\r\n state.properties = prop.properties;\r\n }\r\n\r\n if (prop instanceof UnionProp) {\r\n state.members = prop.members;\r\n }\r\n\r\n if (prop instanceof RenderChildrenProp) {\r\n state.renderProps = prop.renderProps;\r\n state.childrenType = prop.childrenType;\r\n }\r\n\r\n return state as WrappedPropState<Prop>;\r\n}\r\n\r\nfunction flattenUnionMembers(prop: AnyBaseProp): AnyBaseProp[] {\r\n return prop instanceof UnionProp\r\n ? [...(prop.members as AnyBaseProp[])]\r\n : [prop];\r\n}\r\n\r\nfunction wrapProp<Prop extends AnyBaseProp>(prop: Prop): WrappedProp<Prop> {\r\n const validate = ((value: unknown) =>\r\n prop.validate(value)) as WrappedProp<Prop>;\r\n const chainedProps = getPropState(prop) as Record<string, unknown>;\r\n const methodNames = ['optional', 'literal', 'enum', 'config'] as const;\r\n\r\n for (const methodName of methodNames) {\r\n const method = (prop as Record<string, unknown>)[methodName];\r\n\r\n if (typeof method === 'function') {\r\n if (methodName === 'config') {\r\n chainedProps.config = <const Config extends PropConfig>(\r\n config: Config,\r\n ) => createConfiguredWrappedProp(prop, config);\r\n continue;\r\n }\r\n\r\n chainedProps[methodName] = (...args: unknown[]) => {\r\n const nextProp = (\r\n method as (...methodArgs: unknown[]) => AnyBaseProp\r\n ).apply(prop, args);\r\n\r\n return wrapProp(nextProp);\r\n };\r\n }\r\n }\r\n\r\n chainedProps._baseProp = prop;\r\n chainedProps.or = (other: WrappedProp<AnyBaseProp>) => {\r\n const otherBase = (other as unknown as Record<string, unknown>)\r\n ._baseProp as AnyBaseProp;\r\n const members = [\r\n ...flattenUnionMembers(prop),\r\n ...flattenUnionMembers(otherBase),\r\n ] as never;\r\n return wrapProp(new UnionProp(members, prop.visibility));\r\n };\r\n\r\n return Object.assign(validate, chainedProps);\r\n}\r\n\r\nfunction createPrimitiveProp<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n>(\r\n type: Type,\r\n visibility: Visibility,\r\n): PrimitiveBasePropInstanceMap<Visibility>[Type] {\r\n switch (type) {\r\n case 'string':\r\n return new StringProp(\r\n visibility,\r\n ) as unknown as PrimitiveBasePropInstanceMap<Visibility>[Type];\r\n case 'number':\r\n return new NumberProp(\r\n visibility,\r\n ) as unknown as PrimitiveBasePropInstanceMap<Visibility>[Type];\r\n case 'boolean':\r\n return new BooleanProp(\r\n visibility,\r\n ) as unknown as PrimitiveBasePropInstanceMap<Visibility>[Type];\r\n }\r\n}\r\n\r\nfunction createWrappedProp<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility,\r\n>(type: Type, visibility: Visibility) {\r\n return <For extends WrapperFor>(wrapperFor: For) =>\r\n <Value extends PrimitiveTypesMap[Type]>(\r\n value: GetValueForWrapper<Type, For, Value>,\r\n ) => {\r\n if (wrapperFor === 'literal') {\r\n return wrapProp(\r\n new LiteralProp(value as never, type, visibility),\r\n ) as unknown as WrappedPropFor<Type, Visibility, For, Value>;\r\n }\r\n\r\n if (wrapperFor === 'enum') {\r\n return wrapProp(\r\n new EnumProp(value as never, type, visibility),\r\n ) as unknown as WrappedPropFor<Type, Visibility, For, Value>;\r\n }\r\n\r\n throw new Error(`Invalid wrapper for: ${wrapperFor}`);\r\n };\r\n}\r\n\r\nexport function createPrimitivePropBuilder<\r\n Type extends PrimitivePropType,\r\n Visibility extends PropVisibility = 'required',\r\n>(\r\n type: Type,\r\n visibility = 'required' as Visibility,\r\n): PrimitivePropBuilder<Type, Visibility> {\r\n const propWrapper = createWrappedProp(type, visibility);\r\n const builder = (() =>\r\n wrapProp(\r\n createPrimitiveProp(type, visibility),\r\n )) as unknown as PrimitivePropBuilder<Type, Visibility>;\r\n\r\n return Object.assign(builder, {\r\n literal: propWrapper('literal'),\r\n enum: propWrapper('enum'),\r\n config: <const Config extends PropConfig>(config: Config) =>\r\n createConfiguredWrappedProp(\r\n createPrimitiveProp(type, visibility),\r\n config,\r\n ),\r\n ...(visibility === 'required'\r\n ? { optional: () => createPrimitivePropBuilder(type, 'optional') }\r\n : {}),\r\n }) as unknown as PrimitivePropBuilder<Type, Visibility>;\r\n}\r\n\r\nfunction createObjectProp<const Shape extends BuiltPropShape>(\r\n properties: Shape,\r\n): ObjectValueDefinition<Shape, 'required'> {\r\n return wrapProp(new ObjectProp(properties, 'required'));\r\n}\r\n\r\ntype ComponentPropType = 'ReactNode' | 'JSX.Element';\r\ntype ComponentPropTypeMap = {\r\n ReactNode: ReactNode;\r\n 'JSX.Element': JSX.Element;\r\n};\r\n\r\ntype ChildrenPropFor<\r\n ChildrenType extends ComponentPropType,\r\n ChildrenVisibility extends PropVisibility,\r\n RenderProps extends BuiltPropShape | undefined,\r\n> = (RenderProps extends BuiltPropShape\r\n ? WrappedProp<\r\n RenderChildrenProp<RenderProps, ChildrenType, ChildrenVisibility>\r\n >\r\n : WrappedProp<ComponentProp<ChildrenType, ChildrenVisibility>>) &\r\n AnyBuiltPropDefinition;\r\n\r\ntype WithChildrenShape<\r\n Shape extends BuiltPropShape,\r\n ChildrenProp extends AnyBuiltPropDefinition,\r\n> = Shape & { children: ChildrenProp };\r\n\r\ntype WithChildrenOptions<\r\n ChildrenType extends ComponentPropType,\r\n ChildrenVisibility extends PropVisibility,\r\n RenderProps extends BuiltPropShape | undefined,\r\n> = {\r\n /**\r\n * The type of the children.\r\n * @default 'ReactNode'\r\n */\r\n type?: ChildrenType;\r\n /**\r\n * The visibility of the children.\r\n * @default 'optional'\r\n */\r\n visibility?: ChildrenVisibility;\r\n /**\r\n * Optional props for the children. If provided, the children\r\n * will be a function that renders the children.\r\n */\r\n props?: RenderProps;\r\n};\r\n\r\nexport type ComponentPropWithChildrenBuilder<\r\n Type extends ComponentPropType,\r\n Visibility extends PropVisibility,\r\n ChildrenProp extends AnyBuiltPropDefinition,\r\n> = ((value: unknown) => void) & {\r\n _baseProp: ComponentPropWithPropertiesProp<\r\n Type,\r\n { children: ChildrenProp },\r\n Visibility\r\n >;\r\n type: Type;\r\n visibility: Visibility;\r\n props<const Shape extends BuiltPropShape>(\r\n shape: Shape,\r\n ): WrappedProp<\r\n ComponentPropWithPropertiesProp<\r\n Type,\r\n WithChildrenShape<Shape, ChildrenProp>,\r\n Visibility\r\n >\r\n >;\r\n or<Other extends AnyBaseProp>(other: {\r\n _baseProp: Other;\r\n }): WrappedProp<\r\n UnionProp<\r\n readonly [\r\n ComponentPropWithPropertiesProp<\r\n Type,\r\n { children: ChildrenProp },\r\n Visibility\r\n >,\r\n Other,\r\n ],\r\n Visibility\r\n >\r\n >;\r\n} & (Visibility extends 'required'\r\n ? {\r\n optional(): ComponentPropWithChildrenBuilder<\r\n Type,\r\n 'optional',\r\n ChildrenProp\r\n >;\r\n }\r\n : {});\r\n\r\nexport type ComponentPropBuilder<\r\n Type extends ComponentPropType,\r\n Visibility extends PropVisibility = 'required',\r\n> = ((value: unknown) => void) & {\r\n _baseProp: ComponentProp<Type, Visibility>;\r\n type: Type;\r\n visibility: Visibility;\r\n props<const Shape extends BuiltPropShape>(\r\n shape: Shape,\r\n ): WrappedProp<ComponentPropWithPropertiesProp<Type, Shape, Visibility>>;\r\n config<const Config extends PropConfig>(\r\n config: Config,\r\n ): ConfiguredWrappedProp<ComponentProp<Type, Visibility>, Config>;\r\n /**\r\n * Allows the component to have children.\r\n * @param options The options for the children.\r\n */\r\n withChildren<\r\n ChildrenType extends ComponentPropType = 'ReactNode',\r\n ChildrenVisibility extends PropVisibility = 'optional',\r\n const RenderProps extends BuiltPropShape | undefined = undefined,\r\n >(\r\n options?: WithChildrenOptions<\r\n ChildrenType,\r\n ChildrenVisibility,\r\n RenderProps\r\n >,\r\n ): ComponentPropWithChildrenBuilder<\r\n Type,\r\n Visibility,\r\n ChildrenPropFor<ChildrenType, ChildrenVisibility, RenderProps>\r\n >;\r\n or<Other extends AnyBaseProp>(other: {\r\n _baseProp: Other;\r\n }): WrappedProp<\r\n UnionProp<readonly [ComponentProp<Type, Visibility>, Other], Visibility>\r\n >;\r\n} & (Visibility extends 'required'\r\n ? { optional(): ComponentPropBuilder<Type, 'optional'> }\r\n : {});\r\n\r\nfunction createComponentPropWithChildrenBuilder<\r\n Type extends ComponentPropType,\r\n Visibility extends PropVisibility,\r\n ChildrenProp extends AnyBuiltPropDefinition,\r\n>(\r\n type: Type,\r\n visibility: Visibility,\r\n childrenProp: ChildrenProp,\r\n): ComponentPropWithChildrenBuilder<Type, Visibility, ChildrenProp> {\r\n const baseShape = { children: childrenProp };\r\n const baseProp = new ComponentPropWithPropertiesProp(\r\n type,\r\n baseShape,\r\n visibility,\r\n );\r\n const validate = ((value: unknown) =>\r\n baseProp.validate(value)) as unknown as ComponentPropWithChildrenBuilder<\r\n Type,\r\n Visibility,\r\n ChildrenProp\r\n >;\r\n\r\n return Object.assign(validate, {\r\n _baseProp: baseProp,\r\n type,\r\n visibility,\r\n props: <const Shape extends BuiltPropShape>(shape: Shape) =>\r\n wrapProp(\r\n new ComponentPropWithPropertiesProp(\r\n type,\r\n { ...shape, children: childrenProp },\r\n visibility,\r\n ),\r\n ),\r\n or: (other: { _baseProp: AnyBaseProp }) => {\r\n const members = [\r\n baseProp,\r\n ...flattenUnionMembers(other._baseProp),\r\n ] as never;\r\n return wrapProp(new UnionProp(members, baseProp.visibility));\r\n },\r\n ...(visibility === 'required'\r\n ? {\r\n optional: () =>\r\n createComponentPropWithChildrenBuilder(\r\n type,\r\n 'optional' as const,\r\n childrenProp,\r\n ),\r\n }\r\n : {}),\r\n }) as unknown as ComponentPropWithChildrenBuilder<\r\n Type,\r\n Visibility,\r\n ChildrenProp\r\n >;\r\n}\r\n\r\nfunction buildChildrenProp<\r\n ChildrenType extends ComponentPropType,\r\n ChildrenVisibility extends PropVisibility,\r\n RenderProps extends BuiltPropShape | undefined,\r\n>(\r\n childrenType: ChildrenType,\r\n childrenVisibility: ChildrenVisibility,\r\n renderProps: RenderProps,\r\n): ChildrenPropFor<ChildrenType, ChildrenVisibility, RenderProps> {\r\n if (renderProps !== undefined) {\r\n return wrapProp(\r\n new RenderChildrenProp(renderProps, childrenType, childrenVisibility),\r\n ) as unknown as ChildrenPropFor<\r\n ChildrenType,\r\n ChildrenVisibility,\r\n RenderProps\r\n >;\r\n }\r\n return wrapProp(\r\n new ComponentProp(childrenType, childrenVisibility),\r\n ) as unknown as ChildrenPropFor<\r\n ChildrenType,\r\n ChildrenVisibility,\r\n RenderProps\r\n >;\r\n}\r\n\r\nfunction createComponentPropBuilder<\r\n Type extends ComponentPropType,\r\n Visibility extends PropVisibility = 'required',\r\n>(\r\n type: Type,\r\n visibility = 'required' as Visibility,\r\n): ComponentPropBuilder<Type, Visibility> {\r\n const prop = new ComponentProp(type, visibility);\r\n const validate = ((value: unknown) =>\r\n prop.validate(value)) as ComponentPropBuilder<Type, Visibility>;\r\n\r\n return Object.assign(validate, {\r\n type,\r\n visibility,\r\n _baseProp: prop,\r\n props: <const Shape extends BuiltPropShape>(shape: Shape) =>\r\n wrapProp(new ComponentPropWithPropertiesProp(type, shape, visibility)),\r\n config: <const Config extends PropConfig>(config: Config) =>\r\n createConfiguredWrappedProp(prop, config),\r\n withChildren: <\r\n ChildrenType extends ComponentPropType = 'ReactNode',\r\n ChildrenVisibility extends PropVisibility = 'optional',\r\n const RenderProps extends BuiltPropShape | undefined = undefined,\r\n >(\r\n options?: WithChildrenOptions<\r\n ChildrenType,\r\n ChildrenVisibility,\r\n RenderProps\r\n >,\r\n ) => {\r\n const childrenType = (options?.type ?? 'ReactNode') as ChildrenType;\r\n const childrenVisibility = (options?.visibility ??\r\n 'optional') as ChildrenVisibility;\r\n const renderProps = (options?.props ?? undefined) as RenderProps;\r\n return createComponentPropWithChildrenBuilder(\r\n type,\r\n visibility,\r\n buildChildrenProp(childrenType, childrenVisibility, renderProps),\r\n );\r\n },\r\n or: (other: { _baseProp: AnyBaseProp }) => {\r\n const members = [prop, ...flattenUnionMembers(other._baseProp)] as never;\r\n return wrapProp(new UnionProp(members, prop.visibility));\r\n },\r\n ...(visibility === 'required'\r\n ? { optional: () => createComponentPropBuilder(type, 'optional') }\r\n : {}),\r\n }) as unknown as ComponentPropBuilder<Type, Visibility>;\r\n}\r\n\r\nclass MissingRequiredPropError extends Error {\r\n constructor(key: string) {\r\n super(`Property \"${key}\" is required but not provided.`);\r\n }\r\n}\r\n\r\nexport function validateProps<T extends object>(\r\n shape: Record<string, AnyBuiltPropDefinition>,\r\n props: T,\r\n) {\r\n for (const key in shape) {\r\n const prop = shape[key];\r\n\r\n if (prop.visibility === 'required' && !(key in props)) {\r\n throw new MissingRequiredPropError(key);\r\n }\r\n\r\n if (prop.visibility === 'optional' && !(key in props)) {\r\n continue;\r\n }\r\n\r\n prop((props as Record<string, unknown>)[key]);\r\n }\r\n\r\n return props;\r\n}\r\n\r\nexport const createProp = {\r\n string: createPrimitivePropBuilder('string'),\r\n number: createPrimitivePropBuilder('number'),\r\n boolean: createPrimitivePropBuilder('boolean'),\r\n object: createObjectProp,\r\n component: <Type extends ComponentPropType>(options: { type: Type }) =>\r\n createComponentPropBuilder(options.type),\r\n};\r\n"],"mappings":";;AAiBA,MAAM,iBAAiB;CACrB,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,OAAO;CACP,MAAM;CACN,OAAO;CACP,OAAO;CACP,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,8BAA8B,MAAc;CACnD,OAAO,2BAA2B,KAAK;AACzC;AAEA,IAAM,wBAAN,cAAyD,MAAM;CAC7D,YAAY,MAAY;EACtB,MAAM,8BAA8B,IAAI,CAAC;EAEzC,KAAK,OAAO;CACd;AACF;AAsBA,IAAe,WAAf,MAIE;CACA,AAAS;CACT,AAAS;CACT,AAAS;CAET,AAAU;CAEV,Y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