@jfdevelops/react-layout 0.6.0 → 0.7.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-resource-links.cjs +3 -1
- package/dist/create-config/create-resource-links.cjs.map +1 -1
- package/dist/create-config/create-resource-links.d.cts +14 -3
- package/dist/create-config/create-resource-links.d.cts.map +1 -1
- package/dist/create-config/create-resource-links.d.mts +14 -3
- package/dist/create-config/create-resource-links.d.mts.map +1 -1
- package/dist/create-config/create-resource-links.mjs +3 -1
- package/dist/create-config/create-resource-links.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -31,7 +31,9 @@ function createResourceLinksFn(resources) {
|
|
|
31
31
|
full: createFullResourceLinkHref(givenHref, givenHash),
|
|
32
32
|
...linkConfig.hash !== void 0 && !givenHref.includes("#") ? { hash: normalizeResourceLinkHash(givenHash) } : {}
|
|
33
33
|
},
|
|
34
|
-
label: config.label
|
|
34
|
+
label: config.label,
|
|
35
|
+
resource,
|
|
36
|
+
icon: "icon" in config ? config.icon : null
|
|
35
37
|
};
|
|
36
38
|
});
|
|
37
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-resource-links.cjs","names":["createIsValidResourceFn"],"sources":["../../src/create-config/create-resource-links.ts"],"sourcesContent":["import {\n createIsValidResourceFn,\n type LayoutResourceKey,\n type ResourceDefinition,\n} from '../resource';\n\nexport type ResourceAnchorLinkFn<Resource extends string> = (\n resource: Resource,\n) => string;\n\nexport type ResourceLinkHref<Resource extends string> =\n | string\n | ResourceAnchorLinkFn<Resource>;\n\nexport interface CreateResourceLinkOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> {\n label: string;\n /**\n * The href of the link. By default, the href will be `\"/\"`. While you **don't** need to include a hash,\n * if you do, it will override the `hash` property (if provided).\n */\n href?: ResourceLinkHref<Resource>;\n /**\n * The hash of the link. By default, the hash will be the resource name. If you need to customize it, you can provide\n * a string or a function that returns a string.\n *\n * @remarks A `\"#\"` is not required. The generated href will include it automatically.\n */\n hash?: ResourceLinkHref<Resource>;\n}\n\nexport type CreateResourceLinkConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = {\n [resource in LayoutResourceKey<Resources>]?: CreateResourceLinkOptions<\n Resources,\n resource\n >;\n};\n\nexport type InferHashFromResourceLinkHref<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n> = Hash extends string\n ? Hash\n : Hash extends ResourceAnchorLinkFn<Resource>\n ? ReturnType<Hash>\n : never;\n\nexport type CreatedResourceHref = {\n /**\n * The full generated href with the `hash` if provided.\n */\n full: string;\n /**\n * The given href. This is the same value as the `href` property of the config.\n */\n given: string;\n};\n\nexport type CreatedResourceLinkBase = {\n href: CreatedResourceHref;\n label: string;\n};\nexport type CreateResourceLinkWithHash<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n> = Pick<CreatedResourceLinkBase
|
|
1
|
+
{"version":3,"file":"create-resource-links.cjs","names":["createIsValidResourceFn"],"sources":["../../src/create-config/create-resource-links.ts"],"sourcesContent":["import { ReactNode } from 'react';\nimport {\n createIsValidResourceFn,\n type LayoutResourceKey,\n type ResourceDefinition,\n} from '../resource';\n\nexport type ResourceAnchorLinkFn<Resource extends string> = (\n resource: Resource,\n) => string;\n\nexport type ResourceLinkHref<Resource extends string> =\n | string\n | ResourceAnchorLinkFn<Resource>;\n\nexport interface CreateResourceLinkOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> {\n /**\n * The label of the link. This is the text that will be displayed in the link.\n */\n label: string;\n /**\n * An optional icon to register with the link. This is a headless approach, meaning you have full control\n * over the icon's rendering.\n */\n icon?: ReactNode;\n /**\n * The href of the link. By default, the href will be `\"/\"`. While you **don't** need to include a hash,\n * if you do, it will override the `hash` property (if provided).\n */\n href?: ResourceLinkHref<Resource>;\n /**\n * The hash of the link. By default, the hash will be the resource name. If you need to customize it, you can provide\n * a string or a function that returns a string.\n *\n * @remarks A `\"#\"` is not required. The generated href will include it automatically.\n */\n hash?: ResourceLinkHref<Resource>;\n}\n\nexport type CreateResourceLinkConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = {\n [resource in LayoutResourceKey<Resources>]?: CreateResourceLinkOptions<\n Resources,\n resource\n >;\n};\n\nexport type InferHashFromResourceLinkHref<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n> = Hash extends string\n ? Hash\n : Hash extends ResourceAnchorLinkFn<Resource>\n ? ReturnType<Hash>\n : never;\n\nexport type CreatedResourceHref = {\n /**\n * The full generated href with the `hash` if provided.\n */\n full: string;\n /**\n * The given href. This is the same value as the `href` property of the config.\n */\n given: string;\n};\n\nexport type CreatedResourceLinkBase<Resource extends string> = {\n href: CreatedResourceHref;\n label: string;\n resource: Resource;\n icon: ReactNode\n};\nexport type CreateResourceLinkWithHash<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n> = Pick<CreatedResourceLinkBase<Resource>, 'label'> & {\n href: CreatedResourceHref & {\n hash: InferHashFromResourceLinkHref<Resource, Hash>;\n };\n};\n\nexport type CreatedResourceLink<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Config extends CreateResourceLinkConfig<Resources>,\n> = {\n [Resource in keyof Config]: Resource extends LayoutResourceKey<Resources>\n ? Config[Resource] extends {\n hash: infer hash extends ResourceLinkHref<Resource>;\n }\n ? CreateResourceLinkWithHash<Resource, hash>\n : CreatedResourceLinkBase<Resource>\n : never;\n}[keyof Config];\n\nexport type CreateResourceLinksFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = <const Config extends CreateResourceLinkConfig<Resources>>(\n Config: Config,\n) => Array<CreatedResourceLink<Resources, Config>>;\n\nfunction resolveResourceLinkHref<Resource extends string>(\n value: ResourceLinkHref<Resource> | undefined,\n resource: Resource,\n fallback: string,\n) {\n return typeof value === 'function' ? value(resource) : (value ?? fallback);\n}\n\nfunction normalizeResourceLinkHash(hash: string) {\n return hash.replace(/^#+/, '');\n}\n\nfunction createFullResourceLinkHref(href: string, hash: string) {\n if (href.includes('#')) {\n return href;\n }\n\n return `${href}#${normalizeResourceLinkHash(hash)}`;\n}\n\nexport function createResourceLinksFn<\n const Resources extends ReadonlyArray<ResourceDefinition>,\n>(resources: Resources): CreateResourceLinksFn<Resources> {\n const isValidResource = createIsValidResourceFn(resources);\n\n return ((config) => {\n return Object.entries(config).map(([resource, config]) => {\n if (!isValidResource(resource)) {\n throw new Error(`[createResourceLinks]: Invalid resource: ${resource}`);\n }\n\n if (!config) {\n throw new Error(\n `[createResourceLinks]: \"config\" is required for the ${resource} resource.`,\n );\n }\n\n if (typeof config !== 'object') {\n throw new Error(\n `[createResourceLinks]: \"config\" must be an object for the ${resource} resource. Received ${typeof config}`,\n );\n }\n\n if (!('label' in config)) {\n throw new Error(\n `[createResourceLinks]: \"label\" is required for the ${resource} resource.`,\n );\n }\n\n if (typeof config.label !== 'string') {\n throw new Error(\n `[createResourceLinks]: \"label\" must be a string for the ${resource} resource. Received ${typeof config.label}`,\n );\n }\n\n const linkConfig = config as CreateResourceLinkOptions<\n Resources,\n typeof resource\n >;\n\n if (\n 'href' in linkConfig &&\n linkConfig.href !== undefined &&\n typeof linkConfig.href !== 'string' &&\n typeof linkConfig.href !== 'function'\n ) {\n throw new Error(\n `[createResourceLinks]: \"href\" must be a string or function for the ${resource} resource. Received ${typeof linkConfig.href}`,\n );\n }\n\n if (\n 'hash' in linkConfig &&\n linkConfig.hash !== undefined &&\n typeof linkConfig.hash !== 'string' &&\n typeof linkConfig.hash !== 'function'\n ) {\n throw new Error(\n `[createResourceLinks]: \"hash\" must be a string or function for the ${resource} resource. Received ${typeof linkConfig.hash}`,\n );\n }\n\n const givenHref = resolveResourceLinkHref(linkConfig.href, resource, '/');\n const givenHash = resolveResourceLinkHref(\n linkConfig.hash,\n resource,\n resource,\n );\n const href = {\n given: givenHref,\n full: createFullResourceLinkHref(givenHref, givenHash),\n ...(linkConfig.hash !== undefined && !givenHref.includes('#')\n ? { hash: normalizeResourceLinkHash(givenHash) }\n : {}),\n };\n\n return {\n href,\n label: config.label,\n resource,\n icon: 'icon' in config ? config.icon : null,\n };\n });\n }) as CreateResourceLinksFn<Resources>;\n}\n"],"mappings":";;;AAyGA,SAAS,wBACP,OACA,UACA,UACA;CACA,OAAO,OAAO,UAAU,aAAa,MAAM,QAAQ,IAAK,SAAS;AACnE;AAEA,SAAS,0BAA0B,MAAc;CAC/C,OAAO,KAAK,QAAQ,OAAO,EAAE;AAC/B;AAEA,SAAS,2BAA2B,MAAc,MAAc;CAC9D,IAAI,KAAK,SAAS,GAAG,GACnB,OAAO;CAGT,OAAO,GAAG,KAAK,GAAG,0BAA0B,IAAI;AAClD;AAEA,SAAgB,sBAEd,WAAwD;CACxD,MAAM,kBAAkBA,yCAAwB,SAAS;CAEzD,SAAS,WAAW;EAClB,OAAO,OAAO,QAAQ,MAAM,EAAE,KAAK,CAAC,UAAU,YAAY;GACxD,IAAI,CAAC,gBAAgB,QAAQ,GAC3B,MAAM,IAAI,MAAM,4CAA4C,UAAU;GAGxE,IAAI,CAAC,QACH,MAAM,IAAI,MACR,uDAAuD,SAAS,WAClE;GAGF,IAAI,OAAO,WAAW,UACpB,MAAM,IAAI,MACR,6DAA6D,SAAS,sBAAsB,OAAO,QACrG;GAGF,IAAI,EAAE,WAAW,SACf,MAAM,IAAI,MACR,sDAAsD,SAAS,WACjE;GAGF,IAAI,OAAO,OAAO,UAAU,UAC1B,MAAM,IAAI,MACR,2DAA2D,SAAS,sBAAsB,OAAO,OAAO,OAC1G;GAGF,MAAM,aAAa;GAKnB,IACE,UAAU,cACV,WAAW,SAAS,UACpB,OAAO,WAAW,SAAS,YAC3B,OAAO,WAAW,SAAS,YAE3B,MAAM,IAAI,MACR,sEAAsE,SAAS,sBAAsB,OAAO,WAAW,MACzH;GAGF,IACE,UAAU,cACV,WAAW,SAAS,UACpB,OAAO,WAAW,SAAS,YAC3B,OAAO,WAAW,SAAS,YAE3B,MAAM,IAAI,MACR,sEAAsE,SAAS,sBAAsB,OAAO,WAAW,MACzH;GAGF,MAAM,YAAY,wBAAwB,WAAW,MAAM,UAAU,GAAG;GACxE,MAAM,YAAY,wBAChB,WAAW,MACX,UACA,QACF;GASA,OAAO;IACL;KARA,OAAO;KACP,MAAM,2BAA2B,WAAW,SAAS;KACrD,GAAI,WAAW,SAAS,UAAa,CAAC,UAAU,SAAS,GAAG,IACxD,EAAE,MAAM,0BAA0B,SAAS,EAAE,IAC7C,CAAC;IAIF;IACH,OAAO,OAAO;IACd;IACA,MAAM,UAAU,SAAS,OAAO,OAAO;GACzC;EACF,CAAC;CACH;AACF"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { LayoutResourceKey, ResourceDefinition } from "../resource.cjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
2
3
|
|
|
3
4
|
//#region src/create-config/create-resource-links.d.ts
|
|
4
5
|
type ResourceAnchorLinkFn<Resource extends string> = (resource: Resource) => string;
|
|
5
6
|
type ResourceLinkHref<Resource extends string> = string | ResourceAnchorLinkFn<Resource>;
|
|
6
7
|
interface CreateResourceLinkOptions<Resources extends ReadonlyArray<ResourceDefinition>, Resource extends LayoutResourceKey<Resources>> {
|
|
8
|
+
/**
|
|
9
|
+
* The label of the link. This is the text that will be displayed in the link.
|
|
10
|
+
*/
|
|
7
11
|
label: string;
|
|
12
|
+
/**
|
|
13
|
+
* An optional icon to register with the link. This is a headless approach, meaning you have full control
|
|
14
|
+
* over the icon's rendering.
|
|
15
|
+
*/
|
|
16
|
+
icon?: ReactNode;
|
|
8
17
|
/**
|
|
9
18
|
* The href of the link. By default, the href will be `"/"`. While you **don't** need to include a hash,
|
|
10
19
|
* if you do, it will override the `hash` property (if provided).
|
|
@@ -30,18 +39,20 @@ type CreatedResourceHref = {
|
|
|
30
39
|
*/
|
|
31
40
|
given: string;
|
|
32
41
|
};
|
|
33
|
-
type CreatedResourceLinkBase = {
|
|
42
|
+
type CreatedResourceLinkBase<Resource extends string> = {
|
|
34
43
|
href: CreatedResourceHref;
|
|
35
44
|
label: string;
|
|
45
|
+
resource: Resource;
|
|
46
|
+
icon: ReactNode;
|
|
36
47
|
};
|
|
37
|
-
type CreateResourceLinkWithHash<Resource extends string, Hash extends ResourceLinkHref<Resource>> = Pick<CreatedResourceLinkBase
|
|
48
|
+
type CreateResourceLinkWithHash<Resource extends string, Hash extends ResourceLinkHref<Resource>> = Pick<CreatedResourceLinkBase<Resource>, 'label'> & {
|
|
38
49
|
href: CreatedResourceHref & {
|
|
39
50
|
hash: InferHashFromResourceLinkHref<Resource, Hash>;
|
|
40
51
|
};
|
|
41
52
|
};
|
|
42
53
|
type CreatedResourceLink<Resources extends ReadonlyArray<ResourceDefinition>, Config extends CreateResourceLinkConfig<Resources>> = { [Resource in keyof Config]: Resource extends LayoutResourceKey<Resources> ? Config[Resource] extends {
|
|
43
54
|
hash: infer hash extends ResourceLinkHref<Resource>;
|
|
44
|
-
} ? CreateResourceLinkWithHash<Resource, hash> : CreatedResourceLinkBase : never }[keyof Config];
|
|
55
|
+
} ? CreateResourceLinkWithHash<Resource, hash> : CreatedResourceLinkBase<Resource> : never }[keyof Config];
|
|
45
56
|
type CreateResourceLinksFn<Resources extends ReadonlyArray<ResourceDefinition>> = <const Config extends CreateResourceLinkConfig<Resources>>(Config: Config) => Array<CreatedResourceLink<Resources, Config>>;
|
|
46
57
|
//#endregion
|
|
47
58
|
export { CreateResourceLinkConfig, CreateResourceLinkOptions, CreateResourceLinksFn, CreatedResourceHref, CreatedResourceLink, CreatedResourceLinkBase, InferHashFromResourceLinkHref, ResourceAnchorLinkFn, ResourceLinkHref };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-resource-links.d.cts","names":[],"sources":["../../src/create-config/create-resource-links.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-resource-links.d.cts","names":[],"sources":["../../src/create-config/create-resource-links.ts"],"mappings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EI,qBAAA,mBACQ,aAAA,CAAc,kBAAA,2BACR,wBAAA,CAAyB,SAAA,GACjD,MAAA,EAAQ,MAAA,KACL,KAAA,CAAM,mBAAA,CAAoB,SAAA,EAAW,MAAA"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { LayoutResourceKey, ResourceDefinition } from "../resource.mjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
2
3
|
|
|
3
4
|
//#region src/create-config/create-resource-links.d.ts
|
|
4
5
|
type ResourceAnchorLinkFn<Resource extends string> = (resource: Resource) => string;
|
|
5
6
|
type ResourceLinkHref<Resource extends string> = string | ResourceAnchorLinkFn<Resource>;
|
|
6
7
|
interface CreateResourceLinkOptions<Resources extends ReadonlyArray<ResourceDefinition>, Resource extends LayoutResourceKey<Resources>> {
|
|
8
|
+
/**
|
|
9
|
+
* The label of the link. This is the text that will be displayed in the link.
|
|
10
|
+
*/
|
|
7
11
|
label: string;
|
|
12
|
+
/**
|
|
13
|
+
* An optional icon to register with the link. This is a headless approach, meaning you have full control
|
|
14
|
+
* over the icon's rendering.
|
|
15
|
+
*/
|
|
16
|
+
icon?: ReactNode;
|
|
8
17
|
/**
|
|
9
18
|
* The href of the link. By default, the href will be `"/"`. While you **don't** need to include a hash,
|
|
10
19
|
* if you do, it will override the `hash` property (if provided).
|
|
@@ -30,18 +39,20 @@ type CreatedResourceHref = {
|
|
|
30
39
|
*/
|
|
31
40
|
given: string;
|
|
32
41
|
};
|
|
33
|
-
type CreatedResourceLinkBase = {
|
|
42
|
+
type CreatedResourceLinkBase<Resource extends string> = {
|
|
34
43
|
href: CreatedResourceHref;
|
|
35
44
|
label: string;
|
|
45
|
+
resource: Resource;
|
|
46
|
+
icon: ReactNode;
|
|
36
47
|
};
|
|
37
|
-
type CreateResourceLinkWithHash<Resource extends string, Hash extends ResourceLinkHref<Resource>> = Pick<CreatedResourceLinkBase
|
|
48
|
+
type CreateResourceLinkWithHash<Resource extends string, Hash extends ResourceLinkHref<Resource>> = Pick<CreatedResourceLinkBase<Resource>, 'label'> & {
|
|
38
49
|
href: CreatedResourceHref & {
|
|
39
50
|
hash: InferHashFromResourceLinkHref<Resource, Hash>;
|
|
40
51
|
};
|
|
41
52
|
};
|
|
42
53
|
type CreatedResourceLink<Resources extends ReadonlyArray<ResourceDefinition>, Config extends CreateResourceLinkConfig<Resources>> = { [Resource in keyof Config]: Resource extends LayoutResourceKey<Resources> ? Config[Resource] extends {
|
|
43
54
|
hash: infer hash extends ResourceLinkHref<Resource>;
|
|
44
|
-
} ? CreateResourceLinkWithHash<Resource, hash> : CreatedResourceLinkBase : never }[keyof Config];
|
|
55
|
+
} ? CreateResourceLinkWithHash<Resource, hash> : CreatedResourceLinkBase<Resource> : never }[keyof Config];
|
|
45
56
|
type CreateResourceLinksFn<Resources extends ReadonlyArray<ResourceDefinition>> = <const Config extends CreateResourceLinkConfig<Resources>>(Config: Config) => Array<CreatedResourceLink<Resources, Config>>;
|
|
46
57
|
//#endregion
|
|
47
58
|
export { CreateResourceLinkConfig, CreateResourceLinkOptions, CreateResourceLinksFn, CreatedResourceHref, CreatedResourceLink, CreatedResourceLinkBase, InferHashFromResourceLinkHref, ResourceAnchorLinkFn, ResourceLinkHref };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-resource-links.d.mts","names":[],"sources":["../../src/create-config/create-resource-links.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-resource-links.d.mts","names":[],"sources":["../../src/create-config/create-resource-links.ts"],"mappings":";;;;KAOY,oBAAA,6BACV,QAAA,EAAU,QAAQ;AAAA,KAGR,gBAAA,qCAER,oBAAoB,CAAC,QAAA;AAAA,UAER,yBAAA,mBACG,aAAA,CAAc,kBAAA,oBACf,iBAAA,CAAkB,SAAA;EAVL;;;EAe9B,KAAA;EAdU;;;AAAQ;EAmBlB,IAAA,GAAO,SAAA;EAhBmB;;;;EAqB1B,IAAA,GAAO,gBAAA,CAAiB,QAAA;EAnBD;;AAAQ;AAEjC;;;EAwBE,IAAA,GAAO,gBAAA,CAAiB,QAAA;AAAA;AAAA,KAGd,wBAAA,mBACQ,aAAA,CAAc,kBAAA,oBAEnB,iBAAA,CAAkB,SAAA,KAAc,yBAAA,CAC3C,SAAA,EACA,QAAA;AAAA,KAIQ,6BAAA,uCAEG,gBAAA,CAAiB,QAAA,KAC5B,IAAA,kBACA,IAAA,GACA,IAAA,SAAa,oBAAA,CAAqB,QAAA,IAChC,UAAA,CAAW,IAAA;AAAA,KAGL,mBAAA;EArBc;;;EAyBxB,IAAA;EAhDA;;;EAoDA,KAAK;AAAA;AAAA,KAGK,uBAAA;EACV,IAAA,EAAM,mBAAA;EACN,KAAA;EACA,QAAA,EAAU,QAAA;EACV,IAAA,EAAM,SAAA;AAAA;AAAA,KAEI,0BAAA,uCAEG,gBAAA,CAAiB,QAAA,KAC5B,IAAA,CAAK,uBAAA,CAAwB,QAAA;EAC/B,IAAA,EAAM,mBAAA;IACJ,IAAA,EAAM,6BAAA,CAA8B,QAAA,EAAU,IAAA;EAAA;AAAA;AAAA,KAItC,mBAAA,mBACQ,aAAA,CAAc,kBAAA,kBACjB,wBAAA,CAAyB,SAAA,0BAErB,MAAA,GAAS,QAAA,SAAiB,iBAAA,CAAkB,SAAA,IAC3D,MAAA,CAAO,QAAA;EACL,IAAA,qBAAyB,gBAAA,CAAiB,QAAA;AAAA,IAE1C,0BAAA,CAA2B,QAAA,EAAU,IAAA,IACrC,uBAAA,CAAwB,QAAA,kBAExB,MAAA;AAAA,KAEI,qBAAA,mBACQ,aAAA,CAAc,kBAAA,2BACR,wBAAA,CAAyB,SAAA,GACjD,MAAA,EAAQ,MAAA,KACL,KAAA,CAAM,mBAAA,CAAoB,SAAA,EAAW,MAAA"}
|
|
@@ -31,7 +31,9 @@ function createResourceLinksFn(resources) {
|
|
|
31
31
|
full: createFullResourceLinkHref(givenHref, givenHash),
|
|
32
32
|
...linkConfig.hash !== void 0 && !givenHref.includes("#") ? { hash: normalizeResourceLinkHash(givenHash) } : {}
|
|
33
33
|
},
|
|
34
|
-
label: config.label
|
|
34
|
+
label: config.label,
|
|
35
|
+
resource,
|
|
36
|
+
icon: "icon" in config ? config.icon : null
|
|
35
37
|
};
|
|
36
38
|
});
|
|
37
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-resource-links.mjs","names":[],"sources":["../../src/create-config/create-resource-links.ts"],"sourcesContent":["import {\n createIsValidResourceFn,\n type LayoutResourceKey,\n type ResourceDefinition,\n} from '../resource';\n\nexport type ResourceAnchorLinkFn<Resource extends string> = (\n resource: Resource,\n) => string;\n\nexport type ResourceLinkHref<Resource extends string> =\n | string\n | ResourceAnchorLinkFn<Resource>;\n\nexport interface CreateResourceLinkOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> {\n label: string;\n /**\n * The href of the link. By default, the href will be `\"/\"`. While you **don't** need to include a hash,\n * if you do, it will override the `hash` property (if provided).\n */\n href?: ResourceLinkHref<Resource>;\n /**\n * The hash of the link. By default, the hash will be the resource name. If you need to customize it, you can provide\n * a string or a function that returns a string.\n *\n * @remarks A `\"#\"` is not required. The generated href will include it automatically.\n */\n hash?: ResourceLinkHref<Resource>;\n}\n\nexport type CreateResourceLinkConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = {\n [resource in LayoutResourceKey<Resources>]?: CreateResourceLinkOptions<\n Resources,\n resource\n >;\n};\n\nexport type InferHashFromResourceLinkHref<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n> = Hash extends string\n ? Hash\n : Hash extends ResourceAnchorLinkFn<Resource>\n ? ReturnType<Hash>\n : never;\n\nexport type CreatedResourceHref = {\n /**\n * The full generated href with the `hash` if provided.\n */\n full: string;\n /**\n * The given href. This is the same value as the `href` property of the config.\n */\n given: string;\n};\n\nexport type CreatedResourceLinkBase = {\n href: CreatedResourceHref;\n label: string;\n};\nexport type CreateResourceLinkWithHash<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n> = Pick<CreatedResourceLinkBase
|
|
1
|
+
{"version":3,"file":"create-resource-links.mjs","names":[],"sources":["../../src/create-config/create-resource-links.ts"],"sourcesContent":["import { ReactNode } from 'react';\nimport {\n createIsValidResourceFn,\n type LayoutResourceKey,\n type ResourceDefinition,\n} from '../resource';\n\nexport type ResourceAnchorLinkFn<Resource extends string> = (\n resource: Resource,\n) => string;\n\nexport type ResourceLinkHref<Resource extends string> =\n | string\n | ResourceAnchorLinkFn<Resource>;\n\nexport interface CreateResourceLinkOptions<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> {\n /**\n * The label of the link. This is the text that will be displayed in the link.\n */\n label: string;\n /**\n * An optional icon to register with the link. This is a headless approach, meaning you have full control\n * over the icon's rendering.\n */\n icon?: ReactNode;\n /**\n * The href of the link. By default, the href will be `\"/\"`. While you **don't** need to include a hash,\n * if you do, it will override the `hash` property (if provided).\n */\n href?: ResourceLinkHref<Resource>;\n /**\n * The hash of the link. By default, the hash will be the resource name. If you need to customize it, you can provide\n * a string or a function that returns a string.\n *\n * @remarks A `\"#\"` is not required. The generated href will include it automatically.\n */\n hash?: ResourceLinkHref<Resource>;\n}\n\nexport type CreateResourceLinkConfig<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = {\n [resource in LayoutResourceKey<Resources>]?: CreateResourceLinkOptions<\n Resources,\n resource\n >;\n};\n\nexport type InferHashFromResourceLinkHref<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n> = Hash extends string\n ? Hash\n : Hash extends ResourceAnchorLinkFn<Resource>\n ? ReturnType<Hash>\n : never;\n\nexport type CreatedResourceHref = {\n /**\n * The full generated href with the `hash` if provided.\n */\n full: string;\n /**\n * The given href. This is the same value as the `href` property of the config.\n */\n given: string;\n};\n\nexport type CreatedResourceLinkBase<Resource extends string> = {\n href: CreatedResourceHref;\n label: string;\n resource: Resource;\n icon: ReactNode\n};\nexport type CreateResourceLinkWithHash<\n Resource extends string,\n Hash extends ResourceLinkHref<Resource>,\n> = Pick<CreatedResourceLinkBase<Resource>, 'label'> & {\n href: CreatedResourceHref & {\n hash: InferHashFromResourceLinkHref<Resource, Hash>;\n };\n};\n\nexport type CreatedResourceLink<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Config extends CreateResourceLinkConfig<Resources>,\n> = {\n [Resource in keyof Config]: Resource extends LayoutResourceKey<Resources>\n ? Config[Resource] extends {\n hash: infer hash extends ResourceLinkHref<Resource>;\n }\n ? CreateResourceLinkWithHash<Resource, hash>\n : CreatedResourceLinkBase<Resource>\n : never;\n}[keyof Config];\n\nexport type CreateResourceLinksFn<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = <const Config extends CreateResourceLinkConfig<Resources>>(\n Config: Config,\n) => Array<CreatedResourceLink<Resources, Config>>;\n\nfunction resolveResourceLinkHref<Resource extends string>(\n value: ResourceLinkHref<Resource> | undefined,\n resource: Resource,\n fallback: string,\n) {\n return typeof value === 'function' ? value(resource) : (value ?? fallback);\n}\n\nfunction normalizeResourceLinkHash(hash: string) {\n return hash.replace(/^#+/, '');\n}\n\nfunction createFullResourceLinkHref(href: string, hash: string) {\n if (href.includes('#')) {\n return href;\n }\n\n return `${href}#${normalizeResourceLinkHash(hash)}`;\n}\n\nexport function createResourceLinksFn<\n const Resources extends ReadonlyArray<ResourceDefinition>,\n>(resources: Resources): CreateResourceLinksFn<Resources> {\n const isValidResource = createIsValidResourceFn(resources);\n\n return ((config) => {\n return Object.entries(config).map(([resource, config]) => {\n if (!isValidResource(resource)) {\n throw new Error(`[createResourceLinks]: Invalid resource: ${resource}`);\n }\n\n if (!config) {\n throw new Error(\n `[createResourceLinks]: \"config\" is required for the ${resource} resource.`,\n );\n }\n\n if (typeof config !== 'object') {\n throw new Error(\n `[createResourceLinks]: \"config\" must be an object for the ${resource} resource. Received ${typeof config}`,\n );\n }\n\n if (!('label' in config)) {\n throw new Error(\n `[createResourceLinks]: \"label\" is required for the ${resource} resource.`,\n );\n }\n\n if (typeof config.label !== 'string') {\n throw new Error(\n `[createResourceLinks]: \"label\" must be a string for the ${resource} resource. Received ${typeof config.label}`,\n );\n }\n\n const linkConfig = config as CreateResourceLinkOptions<\n Resources,\n typeof resource\n >;\n\n if (\n 'href' in linkConfig &&\n linkConfig.href !== undefined &&\n typeof linkConfig.href !== 'string' &&\n typeof linkConfig.href !== 'function'\n ) {\n throw new Error(\n `[createResourceLinks]: \"href\" must be a string or function for the ${resource} resource. Received ${typeof linkConfig.href}`,\n );\n }\n\n if (\n 'hash' in linkConfig &&\n linkConfig.hash !== undefined &&\n typeof linkConfig.hash !== 'string' &&\n typeof linkConfig.hash !== 'function'\n ) {\n throw new Error(\n `[createResourceLinks]: \"hash\" must be a string or function for the ${resource} resource. Received ${typeof linkConfig.hash}`,\n );\n }\n\n const givenHref = resolveResourceLinkHref(linkConfig.href, resource, '/');\n const givenHash = resolveResourceLinkHref(\n linkConfig.hash,\n resource,\n resource,\n );\n const href = {\n given: givenHref,\n full: createFullResourceLinkHref(givenHref, givenHash),\n ...(linkConfig.hash !== undefined && !givenHref.includes('#')\n ? { hash: normalizeResourceLinkHash(givenHash) }\n : {}),\n };\n\n return {\n href,\n label: config.label,\n resource,\n icon: 'icon' in config ? config.icon : null,\n };\n });\n }) as CreateResourceLinksFn<Resources>;\n}\n"],"mappings":";;;AAyGA,SAAS,wBACP,OACA,UACA,UACA;CACA,OAAO,OAAO,UAAU,aAAa,MAAM,QAAQ,IAAK,SAAS;AACnE;AAEA,SAAS,0BAA0B,MAAc;CAC/C,OAAO,KAAK,QAAQ,OAAO,EAAE;AAC/B;AAEA,SAAS,2BAA2B,MAAc,MAAc;CAC9D,IAAI,KAAK,SAAS,GAAG,GACnB,OAAO;CAGT,OAAO,GAAG,KAAK,GAAG,0BAA0B,IAAI;AAClD;AAEA,SAAgB,sBAEd,WAAwD;CACxD,MAAM,kBAAkB,wBAAwB,SAAS;CAEzD,SAAS,WAAW;EAClB,OAAO,O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