@jfdevelops/react-layout 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-config/create-defined-resource-layout.cjs +28 -0
- package/dist/create-config/create-defined-resource-layout.cjs.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.cts +6 -10
- package/dist/create-config/create-defined-resource-layout.d.cts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.mts +6 -10
- package/dist/create-config/create-defined-resource-layout.d.mts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.mjs +28 -0
- package/dist/create-config/create-defined-resource-layout.mjs.map +1 -1
- package/dist/create-config/define-layout.cjs +1 -1
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +10 -22
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +10 -22
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +1 -1
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/create-config/for-resource.cjs.map +1 -1
- package/dist/create-config/for-resource.d.cts +10 -7
- package/dist/create-config/for-resource.d.cts.map +1 -1
- package/dist/create-config/for-resource.d.mts +10 -7
- package/dist/create-config/for-resource.d.mts.map +1 -1
- package/dist/create-config/for-resource.mjs.map +1 -1
- package/dist/create-config/for-resources/resource-selection.d.cts +4 -2
- package/dist/create-config/for-resources/resource-selection.d.cts.map +1 -1
- package/dist/create-config/for-resources/resource-selection.d.mts +4 -2
- package/dist/create-config/for-resources/resource-selection.d.mts.map +1 -1
- package/dist/create-config/for-resources/scoped-layout.d.cts +16 -24
- package/dist/create-config/for-resources/scoped-layout.d.cts.map +1 -1
- package/dist/create-config/for-resources/scoped-layout.d.mts +16 -24
- package/dist/create-config/for-resources/scoped-layout.d.mts.map +1 -1
- package/dist/create-config/layout-name.cjs +170 -8
- package/dist/create-config/layout-name.cjs.map +1 -1
- package/dist/create-config/layout-name.d.cts +219 -23
- package/dist/create-config/layout-name.d.cts.map +1 -1
- package/dist/create-config/layout-name.d.mts +219 -23
- package/dist/create-config/layout-name.d.mts.map +1 -1
- package/dist/create-config/layout-name.mjs +171 -8
- package/dist/create-config/layout-name.mjs.map +1 -1
- package/dist/errors/invalid-part-type.cjs +21 -0
- package/dist/errors/invalid-part-type.cjs.map +1 -0
- package/dist/errors/invalid-part-type.d.cts +110 -0
- package/dist/errors/invalid-part-type.d.cts.map +1 -0
- package/dist/errors/invalid-part-type.d.mts +110 -0
- package/dist/errors/invalid-part-type.d.mts.map +1 -0
- package/dist/errors/invalid-part-type.mjs +21 -0
- package/dist/errors/invalid-part-type.mjs.map +1 -0
- package/dist/errors/invalid-part.cjs +23 -0
- package/dist/errors/invalid-part.cjs.map +1 -0
- package/dist/errors/invalid-part.d.cts +107 -0
- package/dist/errors/invalid-part.d.cts.map +1 -0
- package/dist/errors/invalid-part.d.mts +107 -0
- package/dist/errors/invalid-part.d.mts.map +1 -0
- package/dist/errors/invalid-part.mjs +23 -0
- package/dist/errors/invalid-part.mjs.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +4 -2
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +3 -1
- package/package.json +3 -3
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { capitalize } from "../utils/capitalize.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/create-config/layout-name.d.ts
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Each slot has a distinct type identity, so ordinary text cannot become a slot.
|
|
6
|
+
*/
|
|
7
|
+
declare const layoutNamePlaceholder: unique symbol;
|
|
8
|
+
type NamePlaceholder<Key extends string, Value extends string | number = string> = Value & {
|
|
9
|
+
readonly [layoutNamePlaceholder]: Key;
|
|
8
10
|
};
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
capitalize: <T extends string>(value: T) => T extends ResourceToken ? CapitalizedToken : Capitalize<T>;
|
|
11
|
+
type PatternNameContext = Omit<LayoutNameContext<NamePlaceholder<'resource'>>, 'capitalize'> & {
|
|
12
|
+
capitalize: <T extends string>(value: T) => T extends NamePlaceholder<'resource'> ? NamePlaceholder<'capitalizedResource'> : Capitalize<T>;
|
|
12
13
|
};
|
|
13
|
-
type PrefixToken = '__layout_prefix__';
|
|
14
|
-
type BeforeToken = '__layout_before_suffix__';
|
|
15
|
-
type AppendToken = '__layout_append__';
|
|
16
14
|
interface LayoutNameContext<Resource extends string = string, State extends string = string> {
|
|
17
15
|
resource: Resource;
|
|
18
16
|
states: readonly State[];
|
|
@@ -23,15 +21,47 @@ interface LayoutNameParts {
|
|
|
23
21
|
beforeSuffix?: string;
|
|
24
22
|
append?: string;
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Value kinds accepted by a declared naming part.
|
|
26
|
+
*/
|
|
27
|
+
type LayoutNamePartType = 'string' | 'number';
|
|
28
|
+
/**
|
|
29
|
+
* Declares each naming part and the value kind accepted at call sites.
|
|
30
|
+
*/
|
|
31
|
+
type LayoutNamePartDefinitions = Readonly<Record<string, LayoutNamePartType>>;
|
|
32
|
+
/**
|
|
33
|
+
* Defines the naming pattern and strict-checking policy. Strict defaults to true.
|
|
34
|
+
*/
|
|
35
|
+
interface LayoutNameOptions<Definitions extends LayoutNamePartDefinitions, Pattern extends string, Strict extends boolean = true> {
|
|
36
|
+
/**
|
|
37
|
+
* Combines the naming context and part placeholders into a name.
|
|
38
|
+
*/
|
|
39
|
+
pattern: NamingPattern<Definitions, Pattern, Strict>;
|
|
40
|
+
/**
|
|
41
|
+
* Set to false to skip part type checking and runtime validation.
|
|
42
|
+
*/
|
|
43
|
+
strict?: Strict;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Part values are intentionally unchecked when strict is false.
|
|
47
|
+
*/
|
|
48
|
+
type UncheckedNamingParts<Definitions extends LayoutNamePartDefinitions> = { [Key in keyof Definitions]?: any } & Record<string, any>;
|
|
49
|
+
type PartValue<Type extends LayoutNamePartType> = Type extends 'number' ? number : string;
|
|
50
|
+
/**
|
|
51
|
+
* Optional values for declared naming parts. Omitted slots render as empty text.
|
|
52
|
+
*/
|
|
53
|
+
type LayoutNamePartValues<Definitions extends LayoutNamePartDefinitions> = { [Key in keyof Definitions]?: PartValue<Definitions[Key]> };
|
|
54
|
+
type PatternParts<Definitions extends LayoutNamePartDefinitions> = { [Key in keyof Definitions & string]: NamePlaceholder<`part:${Key}`, PartValue<Definitions[Key]> | ''> };
|
|
55
|
+
type PartText<Value> = Value extends string | number ? `${Value}` : '';
|
|
56
|
+
type Part<Parts, Key extends keyof Parts> = PartText<Parts[Key]>;
|
|
57
|
+
type ResourcePlaceholderValues<Resource extends string> = {
|
|
58
|
+
resource: Resource;
|
|
59
|
+
capitalizedResource: Capitalize<Resource>;
|
|
30
60
|
};
|
|
31
|
-
type
|
|
32
|
-
type
|
|
33
|
-
type
|
|
34
|
-
type ResolveNamePattern<Pattern extends string, Resource extends string, Parts = {}> =
|
|
61
|
+
type PlaceholderValues<Resource extends string, Parts> = ResourcePlaceholderValues<Resource> & { [Key in keyof Parts & string as `part:${Key}`]: ResolvePattern<Part<Parts, Key>, ResourcePlaceholderValues<Resource>> };
|
|
62
|
+
type MatchPlaceholder<Pattern extends string, Values> = { [Key in keyof Values & string]: Pattern extends NamePlaceholder<Key> | `${NamePlaceholder<Key>}` | `${NamePlaceholder<Key, number>}` ? [Extract<Values[Key], string>, ''] : Pattern extends `${NamePlaceholder<Key>}${infer Rest}` ? [Extract<Values[Key], string>, Rest] : Pattern extends `${NamePlaceholder<Key, number>}${infer Rest}` ? [Extract<Values[Key], string>, Rest] : never }[keyof Values & string];
|
|
63
|
+
type ResolvePattern<Pattern extends string, Values, Result extends string = ''> = [MatchPlaceholder<Pattern, Values>] extends [never] ? Pattern extends `${infer First}${infer Rest}` ? ResolvePattern<Rest, Values, `${Result}${First}`> : `${Result}${Pattern}` : MatchPlaceholder<Pattern, Values> extends [infer Value extends string, infer Rest extends string] ? ResolvePattern<Rest, Values, `${Result}${Value}`> : never;
|
|
64
|
+
type ResolveNamePattern<Pattern extends string, Resource extends string, Parts = {}> = ResolvePattern<Pattern, PlaceholderValues<Resource, Parts>>;
|
|
35
65
|
declare const layoutNamePattern: unique symbol;
|
|
36
66
|
interface LayoutNameResolver<Pattern extends string = string, Parts = {}> {
|
|
37
67
|
(context: LayoutNameContext): string;
|
|
@@ -40,10 +70,176 @@ interface LayoutNameResolver<Pattern extends string = string, Parts = {}> {
|
|
|
40
70
|
parts: Parts;
|
|
41
71
|
};
|
|
42
72
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Computes a layout name from its resource and available render states.
|
|
75
|
+
*/
|
|
76
|
+
type LayoutNameCallback<Resource extends string = string, States extends string = string, Name extends string = string> = (context: LayoutNameContext<Resource, States>) => Name;
|
|
77
|
+
type LayoutNameInput<Resource extends string = string, States extends string = string, Name extends string = string> = Name | LayoutNameCallback<Resource, States, Name>;
|
|
78
|
+
type ResolvedLayoutName<Naming, Resource extends string> = [Naming] extends [undefined] ? `${Capitalize<Resource>}Layout` : Naming extends LayoutNameResolver<infer Pattern, infer Parts> ? ResolveNamePattern<Pattern, Resource, Parts> : Naming extends ((...args: any[]) => infer Result) ? Extract<Result, string> : Naming extends string ? Naming : `${Capitalize<Resource>}Layout`;
|
|
79
|
+
type NamingPartsInput<Definitions extends LayoutNamePartDefinitions, Parts extends LayoutNamePartValues<Definitions>> = { [Key in keyof (LayoutNamePartValues<Definitions> & Parts)]: Key extends keyof Definitions ? (LayoutNamePartValues<Definitions> & Parts)[Key] : never };
|
|
80
|
+
type NamingPartsCallback<Definitions extends LayoutNamePartDefinitions, Parts extends LayoutNamePartValues<Definitions>> = (context: PatternNameContext) => NamingPartsInput<Definitions, Parts>;
|
|
81
|
+
type ResolvedParts<Definitions extends LayoutNamePartDefinitions, Parts> = { [Key in keyof Definitions]: Key extends keyof Parts ? Parts[Key] : '' };
|
|
82
|
+
type NamingPattern<Definitions extends LayoutNamePartDefinitions, Pattern extends string, Strict extends boolean = true> = (context: PatternNameContext, parts: [Strict] extends [false] ? UncheckedNamingParts<Definitions> : PatternParts<Definitions>) => Pattern;
|
|
83
|
+
type NamingDefinition<Definitions extends LayoutNamePartDefinitions, Pattern extends string, Strict extends boolean> = NamingPattern<Definitions, Pattern, Strict> | LayoutNameOptions<Definitions, Pattern, Strict>;
|
|
84
|
+
/**
|
|
85
|
+
* Supplies optional part values while preserving their literal types in names.
|
|
86
|
+
*/
|
|
87
|
+
interface CheckedLayoutNameFactory<Definitions extends LayoutNamePartDefinitions, Pattern extends string> {
|
|
88
|
+
/**
|
|
89
|
+
* Supplies values for declared parts without coercing their types.
|
|
90
|
+
* Fixed values are checked immediately; callback results are checked when
|
|
91
|
+
* the layout name is resolved for a resource.
|
|
92
|
+
*
|
|
93
|
+
* @throws {InvalidPartError} A supplied part has not been declared.
|
|
94
|
+
* @throws {InvalidPartTypeError} A supplied value has the wrong kind.
|
|
95
|
+
*/
|
|
96
|
+
<const Parts extends LayoutNamePartValues<Definitions> = {}>(parts?: NamingPartsInput<Definitions, Parts> | NamingPartsCallback<Definitions, Parts>): LayoutNameResolver<Pattern, ResolvedParts<Definitions, Parts>>;
|
|
97
|
+
}
|
|
98
|
+
interface UncheckedLayoutNameFactory<Definitions extends LayoutNamePartDefinitions> {
|
|
99
|
+
(parts?: UncheckedNamingParts<Definitions> | ((context: PatternNameContext) => UncheckedNamingParts<Definitions>)): LayoutNameResolver<string>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Supplies optional naming parts. Strict conventions preserve literal names;
|
|
103
|
+
* unchecked conventions accept arbitrary keys and values and return string names.
|
|
104
|
+
*/
|
|
105
|
+
type LayoutNameFactory<Definitions extends LayoutNamePartDefinitions, Pattern extends string, Strict extends boolean = true> = [Strict] extends [false] ? UncheckedLayoutNameFactory<Definitions> : CheckedLayoutNameFactory<Definitions, Pattern>;
|
|
106
|
+
interface DefinedLayoutNameParts<Definitions extends LayoutNamePartDefinitions> {
|
|
107
|
+
/**
|
|
108
|
+
* Defines the naming pattern and optional strict-checking policy.
|
|
109
|
+
* Strict defaults to true; false accepts unchecked part keys and values.
|
|
110
|
+
*/
|
|
111
|
+
namingFn<const Pattern extends string, const Strict extends boolean = true>(definition: NamingDefinition<Definitions, Pattern, Strict>): LayoutNameFactory<Definitions, Pattern, Strict>;
|
|
112
|
+
}
|
|
113
|
+
declare const defaultPartDefinitions: {
|
|
114
|
+
prefix: "string";
|
|
115
|
+
beforeSuffix: "string";
|
|
116
|
+
append: "string";
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Defines a reusable layout naming convention that preserves resource-specific
|
|
120
|
+
* literal names in TypeScript. Define the pattern once, then supply optional
|
|
121
|
+
* part values wherever the convention is used.
|
|
122
|
+
*
|
|
123
|
+
* Omit `name` entirely when the generated name, such as `UsersLayout`, is enough.
|
|
124
|
+
* Use this helper when several layouts share a naming rule or need variations
|
|
125
|
+
* while retaining exact component `displayName` types.
|
|
126
|
+
*
|
|
127
|
+
* Choose the form that matches the values your convention needs:
|
|
128
|
+
*
|
|
129
|
+
* - `defineLayoutName(pattern)` provides the string parts `prefix`,
|
|
130
|
+
* `beforeSuffix`, and `append` for common naming variations.
|
|
131
|
+
* - `defineLayoutName.defineParts(...names).namingFn(pattern)` provides custom
|
|
132
|
+
* string parts when domain-specific names make the pattern clearer.
|
|
133
|
+
* - `defineLayoutName.defineParts(schema).namingFn(pattern)` declares each
|
|
134
|
+
* part as `'string'` or `'number'` when supplied values need different types.
|
|
135
|
+
*
|
|
136
|
+
* The pattern controls where parts appear; their names do not impose an order.
|
|
137
|
+
* Part values are optional and omitted values render as empty text. Supply an
|
|
138
|
+
* object for fixed values, or a callback when values depend on the resource.
|
|
139
|
+
* Numeric placeholders can also be empty text inside the pattern. Narrow them
|
|
140
|
+
* with `typeof value === 'number'` before using number-only methods.
|
|
141
|
+
* Supplied keys and value kinds are also validated at runtime. Unknown parts
|
|
142
|
+
* throw InvalidPartError; incorrect value kinds throw InvalidPartTypeError.
|
|
143
|
+
* Each returned naming resolver can be passed to a factory, definition, or
|
|
144
|
+
* component creation call through its `name` option.
|
|
145
|
+
*
|
|
146
|
+
* Strict checking defaults to true. Use `{ pattern, strict: false }` here or
|
|
147
|
+
* in namingFn to accept unchecked part keys and values in both TypeScript
|
|
148
|
+
* and runtime calls. Unchecked conventions return string names.
|
|
149
|
+
*
|
|
150
|
+
* @param definition - A pattern callback, or an object containing the pattern
|
|
151
|
+
* and optional strict-checking policy.
|
|
152
|
+
* @returns A function accepting optional part values or a context callback.
|
|
153
|
+
* Calling it with no arguments leaves every declared part empty.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* Use the default string parts for a shared convention with occasional variants.
|
|
157
|
+
* ```tsx
|
|
158
|
+
* const layoutName = defineLayoutName(({ resource, capitalize }, parts) =>
|
|
159
|
+
* `${parts.prefix}${capitalize(resource)}${parts.beforeSuffix}Layout${parts.append}`,
|
|
160
|
+
* );
|
|
161
|
+
* const factory = createDefinedResourceLayout({
|
|
162
|
+
* resources: ['users'],
|
|
163
|
+
* name: layoutName(),
|
|
164
|
+
* });
|
|
165
|
+
* const { createResourceLayout } = factory.defineResourceLayout({
|
|
166
|
+
* render: () => <div />,
|
|
167
|
+
* });
|
|
168
|
+
* const Users = createResourceLayout({ resource: 'users' });
|
|
169
|
+
* // Users.displayName is typed as 'UsersLayout'.
|
|
170
|
+
* const AdminUsers = createResourceLayout({
|
|
171
|
+
* resource: 'users',
|
|
172
|
+
* name: layoutName({ prefix: 'Admin', beforeSuffix: 'Detail' }),
|
|
173
|
+
* });
|
|
174
|
+
* // AdminUsers.displayName is typed as 'AdminUsersDetailLayout'.
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* Declare custom string parts when their names describe your application's
|
|
179
|
+
* conventions more clearly than prefix, beforeSuffix, and append.
|
|
180
|
+
* ```ts
|
|
181
|
+
* const pageName = defineLayoutName
|
|
182
|
+
* .defineParts('section', 'variant')
|
|
183
|
+
* .namingFn(({ resource, capitalize }, parts) =>
|
|
184
|
+
* `${parts.section}${capitalize(resource)}${parts.variant}Page`,
|
|
185
|
+
* );
|
|
186
|
+
* const adminPage = pageName({ section: 'Admin', variant: 'Detail' });
|
|
187
|
+
* // Used for 'users', this produces 'AdminUsersDetailPage'.
|
|
188
|
+
* const resourcePage = pageName(({ resource }) => ({
|
|
189
|
+
* section: resource === 'users' ? 'Admin' : 'Public',
|
|
190
|
+
* }));
|
|
191
|
+
* // Used for 'users', this produces 'AdminUsersPage'.
|
|
192
|
+
* // Other resources receive the 'Public' section instead.
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* Use a schema when a part should accept a number instead of a string.
|
|
197
|
+
* Supplied keys are suggested by the editor and checked against the schema.
|
|
198
|
+
* ```ts
|
|
199
|
+
* const versionedName = defineLayoutName
|
|
200
|
+
* .defineParts({ section: 'string', version: 'number' })
|
|
201
|
+
* .namingFn(({ resource, capitalize }, parts) =>
|
|
202
|
+
* `${parts.section}${capitalize(resource)}V${parts.version}`,
|
|
203
|
+
* );
|
|
204
|
+
* const adminV2 = versionedName({ section: 'Admin', version: 2 });
|
|
205
|
+
* // Used for 'users', this produces 'AdminUsersV2'.
|
|
206
|
+
* // versionedName({ version: '2' }) is rejected: version must be a number.
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* Guard optional numeric values before formatting them with number methods.
|
|
211
|
+
* Plain interpolation, as above, already handles empty values.
|
|
212
|
+
* ```ts
|
|
213
|
+
* const formattedName = defineLayoutName
|
|
214
|
+
* .defineParts({ version: 'number' })
|
|
215
|
+
* .namingFn(({ resource, capitalize }, parts) => {
|
|
216
|
+
* const version = typeof parts.version === 'number'
|
|
217
|
+
* ? parts.version.toFixed(0)
|
|
218
|
+
* : '';
|
|
219
|
+
* return `${capitalize(resource)}V${version}`;
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* Opt out of part checking when a convention intentionally accepts external
|
|
225
|
+
* keys and mixed value types. The resulting displayName is typed as string.
|
|
226
|
+
* ```ts
|
|
227
|
+
* const externalName = defineLayoutName
|
|
228
|
+
* .defineParts({ version: 'number' })
|
|
229
|
+
* .namingFn({
|
|
230
|
+
* pattern: ({ resource }, parts) => `${resource}${parts.version}${parts.extra}`,
|
|
231
|
+
* strict: false,
|
|
232
|
+
* });
|
|
233
|
+
* const legacy = externalName({ version: 'legacy', extra: true });
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare function defineLayoutName<const Pattern extends string, const Strict extends boolean = true>(definition: NamingDefinition<typeof defaultPartDefinitions, Pattern, Strict>): LayoutNameFactory<typeof defaultPartDefinitions, Pattern, Strict>;
|
|
237
|
+
declare namespace defineLayoutName {
|
|
238
|
+
var defineParts: {
|
|
239
|
+
<const Keys extends readonly string[]>(...keys: Keys): DefinedLayoutNameParts<{ [Key in Keys[number]]: "string" }>;
|
|
240
|
+
<const Definitions extends LayoutNamePartDefinitions>(definitions: Definitions): DefinedLayoutNameParts<Definitions>;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
47
243
|
//#endregion
|
|
48
|
-
export { LayoutNameContext, LayoutNameInput, LayoutNameParts, LayoutNameResolver, ResolvedLayoutName, defineLayoutName };
|
|
244
|
+
export { LayoutNameCallback, LayoutNameContext, LayoutNameFactory, LayoutNameInput, LayoutNameOptions, LayoutNamePartDefinitions, LayoutNamePartType, LayoutNamePartValues, LayoutNameParts, LayoutNameResolver, ResolvedLayoutName, defineLayoutName };
|
|
49
245
|
//# sourceMappingURL=layout-name.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout-name.d.cts","names":[],"sources":["../../src/create-config/layout-name.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"layout-name.d.cts","names":[],"sources":["../../src/create-config/layout-name.ts"],"mappings":";;;;;AAAiD;cASnC,qBAAA;AAAA,KACT,eAAA,+DAGD,KAAA;EAAA,UACQ,qBAAA,GAAwB,GAAA;AAAA;AAAA,KAE/B,kBAAA,GAAqB,IAAA,CACxB,iBAAA,CAAkB,eAAA;EAGlB,UAAA,qBACE,KAAA,EAAO,CAAA,KACJ,CAAA,SAAU,eAAA,eACX,eAAA,0BACA,UAAA,CAAW,CAAA;AAAA;AAAA,UAEA,iBAAA;EAIf,QAAA,EAAU,QAAA;EACV,MAAA,WAAiB,KAAA;EACjB,UAAA,SAAmB,UAAA;AAAA;AAAA,UAEJ,eAAA;EACf,MAAA;EACA,YAAA;EACA,MAAA;AAAA;;AAvBqC;AAAA;KA4B3B,kBAAA;;;;KAKA,yBAAA,GAA4B,QAAA,CACtC,MAAA,SAAe,kBAAA;;;;UAMA,iBAAA,qBACK,yBAAA;EA/BL;;;EAsCf,OAAA,EAAS,aAAA,CAAc,WAAA,EAAa,OAAA,EAAS,MAAA;EA9CrB;;;EAkDxB,MAAA,GAAS,MAAA;AAAA;;;;KAMN,oBAAA,qBAAyC,yBAAA,oBAE5B,WAAA,YACZ,MAAA;AAAA,KAED,SAAA,cAAuB,kBAAA,IAAsB,IAAI;;AArDpC;AAElB;KA0DY,oBAAA,qBACU,yBAAA,oBAEN,WAAA,IAAe,SAAA,CAAU,WAAA,CAAY,GAAA;AAAA,KAGhD,YAAA,qBAAiC,yBAAA,oBACtB,WAAA,YAAuB,eAAA,SAC3B,GAAA,IACR,SAAA,CAAU,WAAA,CAAY,GAAA;AAAA,KAGrB,QAAA,UAAkB,KAAA,8BAAmC,KAAK;AAAA,KAC1D,IAAA,0BAA8B,KAAA,IAAS,QAAA,CAAS,KAAA,CAAM,GAAA;AAAA,KACtD,yBA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,WAAA,MAEnB,OAAA,EAAS,kBAAA,KACN,oBAAA,CAAqB,WAAA,KAC7B,kBAAA;AAAA;;;AAvLY;AAChB;KA6LW,iBAAA,qBACU,yBAAA,4DAGjB,MAAA,oBACD,0BAAA,CAA2B,WAAA,IAC3B,wBAAA,CAAyB,WAAA,EAAa,OAAA;AAAA,UAEhC,sBAAA,qBACY,yBAAA;EAjMwB;;;;EAuM5C,QAAA,oEAIE,UAAA,EAAY,gBAAA,CAAiB,WAAA,EAAa,OAAA,EAAS,MAAA,IAClD,iBAAA,CAAkB,WAAA,EAAa,OAAA,EAAS,MAAA;AAAA;AAAA,cAGvC,sBAAA;;;;;AA5MM;AAAA;;;;;;;;AAE0C;AAOtD;;;;;;;;;;;;;;;;;;AAGwD;AACtD;;;;;;;;;;;;;;;;;;;;;;AAK2B;AAAA;;;;;;;;AAGkC;AAAA;;;;;;;;;;;;;;;;AACD;AAAA;;;;;;;;;;;;;;;AAGpB;AAAA;;;;;;;;;;;;;;;;;;;;;;;;AAzB9B,iBA+aI,gBAAA,oEAId,UAAA,EAAY,gBAAA,QACH,sBAAA,EACP,OAAA,EACA,MAAA,IAED,iBAAA,QAAyB,sBAAA,EAAwB,OAAA,EAAS,MAAA;AAAA,kBAT7C,gBAAA;EAAA;8CAiByC,IAAA,EAC9C,IAAA,GACR,sBAAA,WAAiC,IAAA;IAAA,2BAKW,yBAAA,EAAyB,WAAA,EACzD,WAAA,GACZ,sBAAA,CAAuB,WAAA;EAAA;AAAA"}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { capitalize } from "../utils/capitalize.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/create-config/layout-name.d.ts
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Each slot has a distinct type identity, so ordinary text cannot become a slot.
|
|
6
|
+
*/
|
|
7
|
+
declare const layoutNamePlaceholder: unique symbol;
|
|
8
|
+
type NamePlaceholder<Key extends string, Value extends string | number = string> = Value & {
|
|
9
|
+
readonly [layoutNamePlaceholder]: Key;
|
|
8
10
|
};
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
capitalize: <T extends string>(value: T) => T extends ResourceToken ? CapitalizedToken : Capitalize<T>;
|
|
11
|
+
type PatternNameContext = Omit<LayoutNameContext<NamePlaceholder<'resource'>>, 'capitalize'> & {
|
|
12
|
+
capitalize: <T extends string>(value: T) => T extends NamePlaceholder<'resource'> ? NamePlaceholder<'capitalizedResource'> : Capitalize<T>;
|
|
12
13
|
};
|
|
13
|
-
type PrefixToken = '__layout_prefix__';
|
|
14
|
-
type BeforeToken = '__layout_before_suffix__';
|
|
15
|
-
type AppendToken = '__layout_append__';
|
|
16
14
|
interface LayoutNameContext<Resource extends string = string, State extends string = string> {
|
|
17
15
|
resource: Resource;
|
|
18
16
|
states: readonly State[];
|
|
@@ -23,15 +21,47 @@ interface LayoutNameParts {
|
|
|
23
21
|
beforeSuffix?: string;
|
|
24
22
|
append?: string;
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Value kinds accepted by a declared naming part.
|
|
26
|
+
*/
|
|
27
|
+
type LayoutNamePartType = 'string' | 'number';
|
|
28
|
+
/**
|
|
29
|
+
* Declares each naming part and the value kind accepted at call sites.
|
|
30
|
+
*/
|
|
31
|
+
type LayoutNamePartDefinitions = Readonly<Record<string, LayoutNamePartType>>;
|
|
32
|
+
/**
|
|
33
|
+
* Defines the naming pattern and strict-checking policy. Strict defaults to true.
|
|
34
|
+
*/
|
|
35
|
+
interface LayoutNameOptions<Definitions extends LayoutNamePartDefinitions, Pattern extends string, Strict extends boolean = true> {
|
|
36
|
+
/**
|
|
37
|
+
* Combines the naming context and part placeholders into a name.
|
|
38
|
+
*/
|
|
39
|
+
pattern: NamingPattern<Definitions, Pattern, Strict>;
|
|
40
|
+
/**
|
|
41
|
+
* Set to false to skip part type checking and runtime validation.
|
|
42
|
+
*/
|
|
43
|
+
strict?: Strict;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Part values are intentionally unchecked when strict is false.
|
|
47
|
+
*/
|
|
48
|
+
type UncheckedNamingParts<Definitions extends LayoutNamePartDefinitions> = { [Key in keyof Definitions]?: any } & Record<string, any>;
|
|
49
|
+
type PartValue<Type extends LayoutNamePartType> = Type extends 'number' ? number : string;
|
|
50
|
+
/**
|
|
51
|
+
* Optional values for declared naming parts. Omitted slots render as empty text.
|
|
52
|
+
*/
|
|
53
|
+
type LayoutNamePartValues<Definitions extends LayoutNamePartDefinitions> = { [Key in keyof Definitions]?: PartValue<Definitions[Key]> };
|
|
54
|
+
type PatternParts<Definitions extends LayoutNamePartDefinitions> = { [Key in keyof Definitions & string]: NamePlaceholder<`part:${Key}`, PartValue<Definitions[Key]> | ''> };
|
|
55
|
+
type PartText<Value> = Value extends string | number ? `${Value}` : '';
|
|
56
|
+
type Part<Parts, Key extends keyof Parts> = PartText<Parts[Key]>;
|
|
57
|
+
type ResourcePlaceholderValues<Resource extends string> = {
|
|
58
|
+
resource: Resource;
|
|
59
|
+
capitalizedResource: Capitalize<Resource>;
|
|
30
60
|
};
|
|
31
|
-
type
|
|
32
|
-
type
|
|
33
|
-
type
|
|
34
|
-
type ResolveNamePattern<Pattern extends string, Resource extends string, Parts = {}> =
|
|
61
|
+
type PlaceholderValues<Resource extends string, Parts> = ResourcePlaceholderValues<Resource> & { [Key in keyof Parts & string as `part:${Key}`]: ResolvePattern<Part<Parts, Key>, ResourcePlaceholderValues<Resource>> };
|
|
62
|
+
type MatchPlaceholder<Pattern extends string, Values> = { [Key in keyof Values & string]: Pattern extends NamePlaceholder<Key> | `${NamePlaceholder<Key>}` | `${NamePlaceholder<Key, number>}` ? [Extract<Values[Key], string>, ''] : Pattern extends `${NamePlaceholder<Key>}${infer Rest}` ? [Extract<Values[Key], string>, Rest] : Pattern extends `${NamePlaceholder<Key, number>}${infer Rest}` ? [Extract<Values[Key], string>, Rest] : never }[keyof Values & string];
|
|
63
|
+
type ResolvePattern<Pattern extends string, Values, Result extends string = ''> = [MatchPlaceholder<Pattern, Values>] extends [never] ? Pattern extends `${infer First}${infer Rest}` ? ResolvePattern<Rest, Values, `${Result}${First}`> : `${Result}${Pattern}` : MatchPlaceholder<Pattern, Values> extends [infer Value extends string, infer Rest extends string] ? ResolvePattern<Rest, Values, `${Result}${Value}`> : never;
|
|
64
|
+
type ResolveNamePattern<Pattern extends string, Resource extends string, Parts = {}> = ResolvePattern<Pattern, PlaceholderValues<Resource, Parts>>;
|
|
35
65
|
declare const layoutNamePattern: unique symbol;
|
|
36
66
|
interface LayoutNameResolver<Pattern extends string = string, Parts = {}> {
|
|
37
67
|
(context: LayoutNameContext): string;
|
|
@@ -40,10 +70,176 @@ interface LayoutNameResolver<Pattern extends string = string, Parts = {}> {
|
|
|
40
70
|
parts: Parts;
|
|
41
71
|
};
|
|
42
72
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Computes a layout name from its resource and available render states.
|
|
75
|
+
*/
|
|
76
|
+
type LayoutNameCallback<Resource extends string = string, States extends string = string, Name extends string = string> = (context: LayoutNameContext<Resource, States>) => Name;
|
|
77
|
+
type LayoutNameInput<Resource extends string = string, States extends string = string, Name extends string = string> = Name | LayoutNameCallback<Resource, States, Name>;
|
|
78
|
+
type ResolvedLayoutName<Naming, Resource extends string> = [Naming] extends [undefined] ? `${Capitalize<Resource>}Layout` : Naming extends LayoutNameResolver<infer Pattern, infer Parts> ? ResolveNamePattern<Pattern, Resource, Parts> : Naming extends ((...args: any[]) => infer Result) ? Extract<Result, string> : Naming extends string ? Naming : `${Capitalize<Resource>}Layout`;
|
|
79
|
+
type NamingPartsInput<Definitions extends LayoutNamePartDefinitions, Parts extends LayoutNamePartValues<Definitions>> = { [Key in keyof (LayoutNamePartValues<Definitions> & Parts)]: Key extends keyof Definitions ? (LayoutNamePartValues<Definitions> & Parts)[Key] : never };
|
|
80
|
+
type NamingPartsCallback<Definitions extends LayoutNamePartDefinitions, Parts extends LayoutNamePartValues<Definitions>> = (context: PatternNameContext) => NamingPartsInput<Definitions, Parts>;
|
|
81
|
+
type ResolvedParts<Definitions extends LayoutNamePartDefinitions, Parts> = { [Key in keyof Definitions]: Key extends keyof Parts ? Parts[Key] : '' };
|
|
82
|
+
type NamingPattern<Definitions extends LayoutNamePartDefinitions, Pattern extends string, Strict extends boolean = true> = (context: PatternNameContext, parts: [Strict] extends [false] ? UncheckedNamingParts<Definitions> : PatternParts<Definitions>) => Pattern;
|
|
83
|
+
type NamingDefinition<Definitions extends LayoutNamePartDefinitions, Pattern extends string, Strict extends boolean> = NamingPattern<Definitions, Pattern, Strict> | LayoutNameOptions<Definitions, Pattern, Strict>;
|
|
84
|
+
/**
|
|
85
|
+
* Supplies optional part values while preserving their literal types in names.
|
|
86
|
+
*/
|
|
87
|
+
interface CheckedLayoutNameFactory<Definitions extends LayoutNamePartDefinitions, Pattern extends string> {
|
|
88
|
+
/**
|
|
89
|
+
* Supplies values for declared parts without coercing their types.
|
|
90
|
+
* Fixed values are checked immediately; callback results are checked when
|
|
91
|
+
* the layout name is resolved for a resource.
|
|
92
|
+
*
|
|
93
|
+
* @throws {InvalidPartError} A supplied part has not been declared.
|
|
94
|
+
* @throws {InvalidPartTypeError} A supplied value has the wrong kind.
|
|
95
|
+
*/
|
|
96
|
+
<const Parts extends LayoutNamePartValues<Definitions> = {}>(parts?: NamingPartsInput<Definitions, Parts> | NamingPartsCallback<Definitions, Parts>): LayoutNameResolver<Pattern, ResolvedParts<Definitions, Parts>>;
|
|
97
|
+
}
|
|
98
|
+
interface UncheckedLayoutNameFactory<Definitions extends LayoutNamePartDefinitions> {
|
|
99
|
+
(parts?: UncheckedNamingParts<Definitions> | ((context: PatternNameContext) => UncheckedNamingParts<Definitions>)): LayoutNameResolver<string>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Supplies optional naming parts. Strict conventions preserve literal names;
|
|
103
|
+
* unchecked conventions accept arbitrary keys and values and return string names.
|
|
104
|
+
*/
|
|
105
|
+
type LayoutNameFactory<Definitions extends LayoutNamePartDefinitions, Pattern extends string, Strict extends boolean = true> = [Strict] extends [false] ? UncheckedLayoutNameFactory<Definitions> : CheckedLayoutNameFactory<Definitions, Pattern>;
|
|
106
|
+
interface DefinedLayoutNameParts<Definitions extends LayoutNamePartDefinitions> {
|
|
107
|
+
/**
|
|
108
|
+
* Defines the naming pattern and optional strict-checking policy.
|
|
109
|
+
* Strict defaults to true; false accepts unchecked part keys and values.
|
|
110
|
+
*/
|
|
111
|
+
namingFn<const Pattern extends string, const Strict extends boolean = true>(definition: NamingDefinition<Definitions, Pattern, Strict>): LayoutNameFactory<Definitions, Pattern, Strict>;
|
|
112
|
+
}
|
|
113
|
+
declare const defaultPartDefinitions: {
|
|
114
|
+
prefix: "string";
|
|
115
|
+
beforeSuffix: "string";
|
|
116
|
+
append: "string";
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Defines a reusable layout naming convention that preserves resource-specific
|
|
120
|
+
* literal names in TypeScript. Define the pattern once, then supply optional
|
|
121
|
+
* part values wherever the convention is used.
|
|
122
|
+
*
|
|
123
|
+
* Omit `name` entirely when the generated name, such as `UsersLayout`, is enough.
|
|
124
|
+
* Use this helper when several layouts share a naming rule or need variations
|
|
125
|
+
* while retaining exact component `displayName` types.
|
|
126
|
+
*
|
|
127
|
+
* Choose the form that matches the values your convention needs:
|
|
128
|
+
*
|
|
129
|
+
* - `defineLayoutName(pattern)` provides the string parts `prefix`,
|
|
130
|
+
* `beforeSuffix`, and `append` for common naming variations.
|
|
131
|
+
* - `defineLayoutName.defineParts(...names).namingFn(pattern)` provides custom
|
|
132
|
+
* string parts when domain-specific names make the pattern clearer.
|
|
133
|
+
* - `defineLayoutName.defineParts(schema).namingFn(pattern)` declares each
|
|
134
|
+
* part as `'string'` or `'number'` when supplied values need different types.
|
|
135
|
+
*
|
|
136
|
+
* The pattern controls where parts appear; their names do not impose an order.
|
|
137
|
+
* Part values are optional and omitted values render as empty text. Supply an
|
|
138
|
+
* object for fixed values, or a callback when values depend on the resource.
|
|
139
|
+
* Numeric placeholders can also be empty text inside the pattern. Narrow them
|
|
140
|
+
* with `typeof value === 'number'` before using number-only methods.
|
|
141
|
+
* Supplied keys and value kinds are also validated at runtime. Unknown parts
|
|
142
|
+
* throw InvalidPartError; incorrect value kinds throw InvalidPartTypeError.
|
|
143
|
+
* Each returned naming resolver can be passed to a factory, definition, or
|
|
144
|
+
* component creation call through its `name` option.
|
|
145
|
+
*
|
|
146
|
+
* Strict checking defaults to true. Use `{ pattern, strict: false }` here or
|
|
147
|
+
* in namingFn to accept unchecked part keys and values in both TypeScript
|
|
148
|
+
* and runtime calls. Unchecked conventions return string names.
|
|
149
|
+
*
|
|
150
|
+
* @param definition - A pattern callback, or an object containing the pattern
|
|
151
|
+
* and optional strict-checking policy.
|
|
152
|
+
* @returns A function accepting optional part values or a context callback.
|
|
153
|
+
* Calling it with no arguments leaves every declared part empty.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* Use the default string parts for a shared convention with occasional variants.
|
|
157
|
+
* ```tsx
|
|
158
|
+
* const layoutName = defineLayoutName(({ resource, capitalize }, parts) =>
|
|
159
|
+
* `${parts.prefix}${capitalize(resource)}${parts.beforeSuffix}Layout${parts.append}`,
|
|
160
|
+
* );
|
|
161
|
+
* const factory = createDefinedResourceLayout({
|
|
162
|
+
* resources: ['users'],
|
|
163
|
+
* name: layoutName(),
|
|
164
|
+
* });
|
|
165
|
+
* const { createResourceLayout } = factory.defineResourceLayout({
|
|
166
|
+
* render: () => <div />,
|
|
167
|
+
* });
|
|
168
|
+
* const Users = createResourceLayout({ resource: 'users' });
|
|
169
|
+
* // Users.displayName is typed as 'UsersLayout'.
|
|
170
|
+
* const AdminUsers = createResourceLayout({
|
|
171
|
+
* resource: 'users',
|
|
172
|
+
* name: layoutName({ prefix: 'Admin', beforeSuffix: 'Detail' }),
|
|
173
|
+
* });
|
|
174
|
+
* // AdminUsers.displayName is typed as 'AdminUsersDetailLayout'.
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* Declare custom string parts when their names describe your application's
|
|
179
|
+
* conventions more clearly than prefix, beforeSuffix, and append.
|
|
180
|
+
* ```ts
|
|
181
|
+
* const pageName = defineLayoutName
|
|
182
|
+
* .defineParts('section', 'variant')
|
|
183
|
+
* .namingFn(({ resource, capitalize }, parts) =>
|
|
184
|
+
* `${parts.section}${capitalize(resource)}${parts.variant}Page`,
|
|
185
|
+
* );
|
|
186
|
+
* const adminPage = pageName({ section: 'Admin', variant: 'Detail' });
|
|
187
|
+
* // Used for 'users', this produces 'AdminUsersDetailPage'.
|
|
188
|
+
* const resourcePage = pageName(({ resource }) => ({
|
|
189
|
+
* section: resource === 'users' ? 'Admin' : 'Public',
|
|
190
|
+
* }));
|
|
191
|
+
* // Used for 'users', this produces 'AdminUsersPage'.
|
|
192
|
+
* // Other resources receive the 'Public' section instead.
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* Use a schema when a part should accept a number instead of a string.
|
|
197
|
+
* Supplied keys are suggested by the editor and checked against the schema.
|
|
198
|
+
* ```ts
|
|
199
|
+
* const versionedName = defineLayoutName
|
|
200
|
+
* .defineParts({ section: 'string', version: 'number' })
|
|
201
|
+
* .namingFn(({ resource, capitalize }, parts) =>
|
|
202
|
+
* `${parts.section}${capitalize(resource)}V${parts.version}`,
|
|
203
|
+
* );
|
|
204
|
+
* const adminV2 = versionedName({ section: 'Admin', version: 2 });
|
|
205
|
+
* // Used for 'users', this produces 'AdminUsersV2'.
|
|
206
|
+
* // versionedName({ version: '2' }) is rejected: version must be a number.
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* Guard optional numeric values before formatting them with number methods.
|
|
211
|
+
* Plain interpolation, as above, already handles empty values.
|
|
212
|
+
* ```ts
|
|
213
|
+
* const formattedName = defineLayoutName
|
|
214
|
+
* .defineParts({ version: 'number' })
|
|
215
|
+
* .namingFn(({ resource, capitalize }, parts) => {
|
|
216
|
+
* const version = typeof parts.version === 'number'
|
|
217
|
+
* ? parts.version.toFixed(0)
|
|
218
|
+
* : '';
|
|
219
|
+
* return `${capitalize(resource)}V${version}`;
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* Opt out of part checking when a convention intentionally accepts external
|
|
225
|
+
* keys and mixed value types. The resulting displayName is typed as string.
|
|
226
|
+
* ```ts
|
|
227
|
+
* const externalName = defineLayoutName
|
|
228
|
+
* .defineParts({ version: 'number' })
|
|
229
|
+
* .namingFn({
|
|
230
|
+
* pattern: ({ resource }, parts) => `${resource}${parts.version}${parts.extra}`,
|
|
231
|
+
* strict: false,
|
|
232
|
+
* });
|
|
233
|
+
* const legacy = externalName({ version: 'legacy', extra: true });
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare function defineLayoutName<const Pattern extends string, const Strict extends boolean = true>(definition: NamingDefinition<typeof defaultPartDefinitions, Pattern, Strict>): LayoutNameFactory<typeof defaultPartDefinitions, Pattern, Strict>;
|
|
237
|
+
declare namespace defineLayoutName {
|
|
238
|
+
var defineParts: {
|
|
239
|
+
<const Keys extends readonly string[]>(...keys: Keys): DefinedLayoutNameParts<{ [Key in Keys[number]]: "string" }>;
|
|
240
|
+
<const Definitions extends LayoutNamePartDefinitions>(definitions: Definitions): DefinedLayoutNameParts<Definitions>;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
47
243
|
//#endregion
|
|
48
|
-
export { LayoutNameContext, LayoutNameInput, LayoutNameParts, LayoutNameResolver, ResolvedLayoutName, defineLayoutName };
|
|
244
|
+
export { LayoutNameCallback, LayoutNameContext, LayoutNameFactory, LayoutNameInput, LayoutNameOptions, LayoutNamePartDefinitions, LayoutNamePartType, LayoutNamePartValues, LayoutNameParts, LayoutNameResolver, ResolvedLayoutName, defineLayoutName };
|
|
49
245
|
//# sourceMappingURL=layout-name.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout-name.d.mts","names":[],"sources":["../../src/create-config/layout-name.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"layout-name.d.mts","names":[],"sources":["../../src/create-config/layout-name.ts"],"mappings":";;;;;AAAiD;cASnC,qBAAA;AAAA,KACT,eAAA,+DAGD,KAAA;EAAA,UACQ,qBAAA,GAAwB,GAAA;AAAA;AAAA,KAE/B,kBAAA,GAAqB,IAAA,CACxB,iBAAA,CAAkB,eAAA;EAGlB,UAAA,qBACE,KAAA,EAAO,CAAA,KACJ,CAAA,SAAU,eAAA,eACX,eAAA,0BACA,UAAA,CAAW,CAAA;AAAA;AAAA,UAEA,iBAAA;EAIf,QAAA,EAAU,QAAA;EACV,MAAA,WAAiB,KAAA;EACjB,UAAA,SAAmB,UAAA;AAAA;AAAA,UAEJ,eAAA;EACf,MAAA;EACA,YAAA;EACA,MAAA;AAAA;;AAvBqC;AAAA;KA4B3B,kBAAA;;;;KAKA,yBAAA,GAA4B,QAAA,CACtC,MAAA,SAAe,kBAAA;;;;UAMA,iBAAA,qBACK,yBAAA;EA/BL;;;EAsCf,OAAA,EAAS,aAAA,CAAc,WAAA,EAAa,OAAA,EAAS,MAAA;EA9CrB;;;EAkDxB,MAAA,GAAS,MAAA;AAAA;;;;KAMN,oBAAA,qBAAyC,yBAAA,oBAE5B,WAAA,YACZ,MAAA;AAAA,KAED,SAAA,cAAuB,kBAAA,IAAsB,IAAI;;AArDpC;AAElB;KA0DY,oBAAA,qBACU,yBAAA,oBAEN,WAAA,IAAe,SAAA,CAAU,WAAA,CAAY,GAAA;AAAA,KAGhD,YAAA,qBAAiC,yBAAA,oBACtB,WAAA,YAAuB,eAAA,SAC3B,GAAA,IACR,SAAA,CAAU,WAAA,C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