@zayne-labs/ui-react 0.10.5 → 0.10.7
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/css/animation.css +47 -0
- package/css/theme.css +10 -4
- package/dist/esm/{await-fjas2Q-C.js → await-Da5w2vIc.js} +14 -15
- package/dist/esm/await-Da5w2vIc.js.map +1 -0
- package/dist/esm/{card-TD60Xux0.js → card-DDLJVCwL.js} +10 -10
- package/dist/esm/card-DDLJVCwL.js.map +1 -0
- package/dist/esm/{carousel-YXXtZ85s.js → carousel-B051PAAX.js} +20 -23
- package/dist/esm/carousel-B051PAAX.js.map +1 -0
- package/dist/esm/{chunk-Cl8Af3a2.js → chunk-CTAAG5j7.js} +3 -1
- package/dist/esm/{cn-_FbtIrlZ.js → cn-s-D7vHW1.js} +1 -1
- package/dist/esm/{cn-_FbtIrlZ.js.map → cn-s-D7vHW1.js.map} +1 -1
- package/dist/esm/common/await/index.d.ts +4 -0
- package/dist/esm/common/await/index.js +8 -0
- package/dist/esm/common/client-gate/index.d.ts +33 -0
- package/dist/esm/common/client-gate/index.js +35 -0
- package/dist/esm/common/client-gate/index.js.map +1 -0
- package/dist/esm/{components/common → common}/error-boundary/index.d.ts +1 -1
- package/dist/esm/{components/common → common}/error-boundary/index.js +1 -1
- package/dist/esm/common/for/index.d.ts +2 -0
- package/dist/esm/common/for/index.js +3 -0
- package/dist/esm/common/index.d.ts +9 -0
- package/dist/esm/common/index.js +11 -0
- package/dist/esm/common/presence/index.d.ts +22 -0
- package/dist/esm/common/presence/index.js +6 -0
- package/dist/esm/{components/common → common}/show/index.d.ts +1 -1
- package/dist/esm/{components/common → common}/show/index.js +1 -2
- package/dist/esm/{components/common → common}/slot/index.d.ts +1 -1
- package/dist/esm/common/slot/index.js +3 -0
- package/dist/esm/common/suspense-with-boundary/index.d.ts +3 -0
- package/dist/esm/common/suspense-with-boundary/index.js +4 -0
- package/dist/esm/{components/common → common}/switch/index.d.ts +1 -1
- package/dist/esm/{components/common → common}/switch/index.js +1 -2
- package/dist/esm/common/teleport/index.d.ts +2 -0
- package/dist/esm/common/teleport/index.js +3 -0
- package/dist/esm/{drag-scroll-De6-soln.js → drag-scroll-Bb1SG4On.js} +9 -12
- package/dist/esm/{drag-scroll-De6-soln.js.map → drag-scroll-Bb1SG4On.js.map} +1 -1
- package/dist/esm/drop-zone-C9VpKJAD.js +1013 -0
- package/dist/esm/drop-zone-C9VpKJAD.js.map +1 -0
- package/dist/esm/{error-boundary-xM9An3gz.js → error-boundary-y9Samt_s.js} +1 -1
- package/dist/esm/error-boundary-y9Samt_s.js.map +1 -0
- package/dist/esm/{for-DGs2XZ21.js → for-DK5rEY_m.js} +5 -7
- package/dist/esm/for-DK5rEY_m.js.map +1 -0
- package/dist/esm/{form-BHfmbX32.js → form-DyGy9LnA.js} +61 -73
- package/dist/esm/form-DyGy9LnA.js.map +1 -0
- package/dist/esm/{index-Y_2u8pWF.d.ts → index-ATxxr1XS.d.ts} +5 -4
- package/dist/esm/{index-Cbg54Lt4.d.ts → index-B4YvRWlE.d.ts} +21 -20
- package/dist/esm/{index-lKxE9WPi.d.ts → index-BAywimP3.d.ts} +4 -2
- package/dist/esm/index-BT0UvcRp.d.ts +23 -0
- package/dist/esm/index-BWD8WVO-.d.ts +340 -0
- package/dist/esm/{index-DVr1tbxh.d.ts → index-BsGxDKlt.d.ts} +10 -9
- package/dist/esm/{index-BYhH4Fm0.d.ts → index-C1GPFYKG.d.ts} +1 -1
- package/dist/esm/{index-D6o1oxQd.d.ts → index-C889t8UO.d.ts} +13 -16
- package/dist/esm/{index-CWKQ5V4B.d.ts → index-CZjeBSoQ.d.ts} +1 -1
- package/dist/esm/{index-DJjxpXUk.d.ts → index-CffEFE66.d.ts} +1 -1
- package/dist/esm/{index-BBJzo-WC.d.ts → index-CuJVxLEc.d.ts} +4 -3
- package/dist/esm/{index-BeDmH7lX.d.ts → index-DVBtz0VB.d.ts} +10 -9
- package/dist/esm/{index-DqutTJQB.d.ts → index-Dpt8KDv1.d.ts} +13 -12
- package/dist/esm/presence-CL5_GHQH.js +156 -0
- package/dist/esm/presence-CL5_GHQH.js.map +1 -0
- package/dist/esm/{show-BabiXbf7.js → show-N1ZXBhoA.js} +18 -9
- package/dist/esm/show-N1ZXBhoA.js.map +1 -0
- package/dist/esm/{slot-D1062oA5.js → slot-WVWfOlr3.js} +5 -6
- package/dist/esm/{slot-D1062oA5.js.map → slot-WVWfOlr3.js.map} +1 -1
- package/dist/esm/{suspense-with-boundary-CEVORL8K.js → suspense-with-boundary-D-1NYDV4.js} +2 -2
- package/dist/esm/suspense-with-boundary-D-1NYDV4.js.map +1 -0
- package/dist/esm/{switch-CCMD01Rs.js → switch-Ch22z21e.js} +7 -11
- package/dist/esm/switch-Ch22z21e.js.map +1 -0
- package/dist/esm/{teleport-DfuYOzsj.js → teleport-C8TzRm4M.js} +1 -1
- package/dist/esm/teleport-C8TzRm4M.js.map +1 -0
- package/dist/esm/{components/ui → ui}/card/index.d.ts +1 -1
- package/dist/esm/{components/ui → ui}/card/index.js +3 -3
- package/dist/esm/ui/carousel/index.d.ts +2 -0
- package/dist/esm/ui/carousel/index.js +16 -0
- package/dist/esm/ui/drag-scroll/index.d.ts +2 -0
- package/dist/esm/ui/drag-scroll/index.js +4 -0
- package/dist/esm/ui/drop-zone/index.d.ts +2 -0
- package/dist/esm/ui/drop-zone/index.js +17 -0
- package/dist/esm/{components/ui → ui}/form/index.d.ts +1 -1
- package/dist/esm/{components/ui → ui}/form/index.js +4 -5
- package/dist/esm/ui/index.d.ts +6 -0
- package/dist/esm/ui/index.js +18 -0
- package/dist/style.css +415 -25
- package/package.json +20 -17
- package/dist/esm/await-fjas2Q-C.js.map +0 -1
- package/dist/esm/card-TD60Xux0.js.map +0 -1
- package/dist/esm/carousel-YXXtZ85s.js.map +0 -1
- package/dist/esm/components/common/await/index.d.ts +0 -5
- package/dist/esm/components/common/await/index.js +0 -10
- package/dist/esm/components/common/for/index.d.ts +0 -2
- package/dist/esm/components/common/for/index.js +0 -3
- package/dist/esm/components/common/index.d.ts +0 -10
- package/dist/esm/components/common/index.js +0 -13
- package/dist/esm/components/common/slot/index.js +0 -3
- package/dist/esm/components/common/suspense-with-boundary/index.d.ts +0 -3
- package/dist/esm/components/common/suspense-with-boundary/index.js +0 -4
- package/dist/esm/components/common/teleport/index.d.ts +0 -2
- package/dist/esm/components/common/teleport/index.js +0 -3
- package/dist/esm/components/ui/carousel/index.d.ts +0 -2
- package/dist/esm/components/ui/carousel/index.js +0 -18
- package/dist/esm/components/ui/drag-scroll/index.d.ts +0 -2
- package/dist/esm/components/ui/drag-scroll/index.js +0 -4
- package/dist/esm/components/ui/drop-zone/index.d.ts +0 -2
- package/dist/esm/components/ui/drop-zone/index.js +0 -18
- package/dist/esm/components/ui/index.d.ts +0 -6
- package/dist/esm/components/ui/index.js +0 -19
- package/dist/esm/drop-zone-BPfSu99L.js +0 -381
- package/dist/esm/drop-zone-BPfSu99L.js.map +0 -1
- package/dist/esm/error-boundary-xM9An3gz.js.map +0 -1
- package/dist/esm/for-DGs2XZ21.js.map +0 -1
- package/dist/esm/form-BHfmbX32.js.map +0 -1
- package/dist/esm/getSlot-Cf5ON6lE.js +0 -85
- package/dist/esm/getSlot-Cf5ON6lE.js.map +0 -1
- package/dist/esm/index-B-NUFudm.d.ts +0 -183
- package/dist/esm/index-BNrCAe9Y.d.ts +0 -142
- package/dist/esm/index-CnvH74ea.d.ts +0 -20
- package/dist/esm/lib/utils/index.d.ts +0 -2
- package/dist/esm/lib/utils/index.js +0 -4
- package/dist/esm/show-BabiXbf7.js.map +0 -1
- package/dist/esm/suspense-with-boundary-CEVORL8K.js.map +0 -1
- package/dist/esm/switch-CCMD01Rs.js.map +0 -1
- package/dist/esm/teleport-DfuYOzsj.js.map +0 -1
- package/dist/esm/utils-ChjmDoRe.js +0 -89
- package/dist/esm/utils-ChjmDoRe.js.map +0 -1
- /package/dist/esm/{common-BYWy8Q78.js → common-PS3X58Pj.js} +0 -0
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { AssertionError, isArray, isFunction } from "@zayne-labs/toolkit-type-helpers";
|
|
2
|
-
import { Fragment, isValidElement } from "react";
|
|
3
|
-
import { toArray } from "@zayne-labs/toolkit-core";
|
|
4
|
-
|
|
5
|
-
//#region src/lib/utils/getSlot/getSlot.ts
|
|
6
|
-
const isWithSlotSymbol = (component) => {
|
|
7
|
-
return "slotSymbol" in component && Boolean(component.slotSymbol);
|
|
8
|
-
};
|
|
9
|
-
const isWithSlotReference = (component) => {
|
|
10
|
-
return "slotReference" in component && Boolean(component.slotReference);
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* @description Checks if a react child (within the children array) matches the provided SlotComponent using multiple matching strategies:
|
|
14
|
-
* 1. Matches by slot symbol property
|
|
15
|
-
* 2. Matches by component name
|
|
16
|
-
*/
|
|
17
|
-
const matchesSlotComponent = (child, SlotComponent) => {
|
|
18
|
-
if (!isValidElement(child) || !isFunction(child.type)) return false;
|
|
19
|
-
const resolvedChildType = isWithSlotReference(child.type) ? child.type.slotReference : child.type;
|
|
20
|
-
const hasMatchingSlotSymbol = isWithSlotSymbol(resolvedChildType) && isWithSlotSymbol(SlotComponent) && resolvedChildType.slotSymbol === SlotComponent.slotSymbol;
|
|
21
|
-
if (hasMatchingSlotSymbol) return true;
|
|
22
|
-
if (child.type.name === SlotComponent.name) return true;
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* @description Checks if a react child (within the children array) matches any of the provided SlotComponents.
|
|
27
|
-
*/
|
|
28
|
-
const matchesAnySlotComponent = (child, SlotComponents) => {
|
|
29
|
-
const matchesSlot = SlotComponents.some((SlotComponent) => matchesSlotComponent(child, SlotComponent));
|
|
30
|
-
return matchesSlot;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* @description Counts how many times a given slot component appears in an array of children
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
const calculateSlotOccurrences = (childrenArray, SlotComponent) => {
|
|
37
|
-
let count = 0;
|
|
38
|
-
for (const child of childrenArray) {
|
|
39
|
-
if (!matchesSlotComponent(child, SlotComponent)) continue;
|
|
40
|
-
count += 1;
|
|
41
|
-
}
|
|
42
|
-
return count;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* @description Retrieves a single slot element from a collection of React children that matches the provided SlotComponent component.
|
|
46
|
-
*
|
|
47
|
-
* @throws { AssertionError } when throwOnMultipleSlotMatch is true and multiple slots are found
|
|
48
|
-
*/
|
|
49
|
-
const getSingleSlot = (children, SlotComponent, options = {}) => {
|
|
50
|
-
const { errorMessage = "Only one instance of the SlotComponent is allowed", throwOnMultipleSlotMatch = false } = options;
|
|
51
|
-
const actualChildren = isValidElement(children) && children.type === Fragment ? children.props.children : children;
|
|
52
|
-
const childrenArray = toArray(actualChildren);
|
|
53
|
-
const shouldThrow = throwOnMultipleSlotMatch && calculateSlotOccurrences(childrenArray, SlotComponent) > 1;
|
|
54
|
-
if (shouldThrow) throw new AssertionError(errorMessage);
|
|
55
|
-
const slotElement = childrenArray.find((child) => matchesSlotComponent(child, SlotComponent));
|
|
56
|
-
return slotElement;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* @description The same as getSingleSlot, but for multiple slot components
|
|
60
|
-
*/
|
|
61
|
-
const getMultipleSlots = (children, SlotComponents, options) => {
|
|
62
|
-
const { errorMessage, throwOnMultipleSlotMatch } = options ?? {};
|
|
63
|
-
const slots = SlotComponents.map((SlotComponent, index) => getSingleSlot(children, SlotComponent, {
|
|
64
|
-
errorMessage: isArray(errorMessage) ? errorMessage[index] : errorMessage,
|
|
65
|
-
throwOnMultipleSlotMatch: isArray(throwOnMultipleSlotMatch) ? throwOnMultipleSlotMatch[index] : throwOnMultipleSlotMatch
|
|
66
|
-
}));
|
|
67
|
-
const regularChildren = getRegularChildren(children, SlotComponents);
|
|
68
|
-
return {
|
|
69
|
-
regularChildren,
|
|
70
|
-
slots
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* @description Returns all children that are not slot elements (i.e., don't match any of the provided slot components)
|
|
75
|
-
*/
|
|
76
|
-
const getRegularChildren = (children, SlotComponentOrComponents) => {
|
|
77
|
-
const actualChildren = isValidElement(children) && children.type === Fragment ? children.props.children : children;
|
|
78
|
-
const childrenArray = toArray(actualChildren);
|
|
79
|
-
const regularChildren = childrenArray.filter((child) => !matchesAnySlotComponent(child, toArray(SlotComponentOrComponents)));
|
|
80
|
-
return regularChildren;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
export { getMultipleSlots, getRegularChildren, getSingleSlot, matchesAnySlotComponent, matchesSlotComponent };
|
|
85
|
-
//# sourceMappingURL=getSlot-Cf5ON6lE.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSlot-Cf5ON6lE.js","names":["ReactFragment"],"sources":["../../src/lib/utils/getSlot/getSlot.ts"],"sourcesContent":["import { toArray } from \"@zayne-labs/toolkit-core\";\nimport type { InferProps } from \"@zayne-labs/toolkit-react/utils\";\nimport {\n\ttype AnyFunction,\n\tAssertionError,\n\ttype Prettify,\n\ttype UnknownObject,\n\tisArray,\n\tisFunction,\n} from \"@zayne-labs/toolkit-type-helpers\";\nimport { Fragment as ReactFragment, isValidElement } from \"react\";\n\nexport type FunctionalComponent<TProps extends UnknownObject = never> = React.FunctionComponent<TProps>;\n\nconst isWithSlotSymbol = <TFunction extends AnyFunction>(\n\tcomponent: TFunction\n): component is Record<\"slotSymbol\", unknown> & TFunction => {\n\treturn \"slotSymbol\" in component && Boolean(component.slotSymbol);\n};\n\nconst isWithSlotReference = <TFunction extends AnyFunction>(\n\tcomponent: TFunction\n): component is Record<\"slotReference\", unknown> & TFunction => {\n\treturn \"slotReference\" in component && Boolean(component.slotReference);\n};\n/**\n * @description Checks if a react child (within the children array) matches the provided SlotComponent using multiple matching strategies:\n * 1. Matches by slot symbol property\n * 2. Matches by component name\n */\n\nexport const matchesSlotComponent = (child: React.ReactNode, SlotComponent: FunctionalComponent) => {\n\tif (!isValidElement(child) || !isFunction(child.type)) {\n\t\treturn false;\n\t}\n\n\tconst resolvedChildType = isWithSlotReference(child.type)\n\t\t? (child.type.slotReference as FunctionalComponent)\n\t\t: child.type;\n\n\tconst hasMatchingSlotSymbol =\n\t\tisWithSlotSymbol(resolvedChildType)\n\t\t&& isWithSlotSymbol(SlotComponent)\n\t\t&& resolvedChildType.slotSymbol === SlotComponent.slotSymbol;\n\n\tif (hasMatchingSlotSymbol) {\n\t\treturn true;\n\t}\n\n\tif (child.type.name === SlotComponent.name) {\n\t\treturn true;\n\t}\n\n\treturn false;\n};\n\n/**\n * @description Checks if a react child (within the children array) matches any of the provided SlotComponents.\n */\nexport const matchesAnySlotComponent = (child: React.ReactNode, SlotComponents: FunctionalComponent[]) => {\n\tconst matchesSlot = SlotComponents.some((SlotComponent) => matchesSlotComponent(child, SlotComponent));\n\n\treturn matchesSlot;\n};\n\ntype SlotOptions = {\n\t/**\n\t * @description The error message to throw when multiple slots are found for a given slot component\n\t */\n\terrorMessage?: string;\n\t/**\n\t * @description When true, an AssertionError will be thrown if multiple slots are found for a given slot component\n\t */\n\tthrowOnMultipleSlotMatch?: boolean;\n};\n\n/**\n * @description Counts how many times a given slot component appears in an array of children\n * @internal\n */\nconst calculateSlotOccurrences = (\n\tchildrenArray: React.ReactNode[],\n\tSlotComponent: FunctionalComponent\n) => {\n\tlet count = 0;\n\n\tfor (const child of childrenArray) {\n\t\tif (!matchesSlotComponent(child, SlotComponent)) continue;\n\n\t\tcount += 1;\n\t}\n\n\treturn count;\n};\n\n/**\n * @description Retrieves a single slot element from a collection of React children that matches the provided SlotComponent component.\n *\n * @throws { AssertionError } when throwOnMultipleSlotMatch is true and multiple slots are found\n */\nexport const getSingleSlot = (\n\tchildren: React.ReactNode,\n\tSlotComponent: FunctionalComponent,\n\toptions: SlotOptions = {}\n) => {\n\tconst {\n\t\terrorMessage = \"Only one instance of the SlotComponent is allowed\",\n\t\tthrowOnMultipleSlotMatch = false,\n\t} = options;\n\n\tconst actualChildren =\n\t\tisValidElement<InferProps<typeof ReactFragment>>(children) && children.type === ReactFragment\n\t\t\t? children.props.children\n\t\t\t: children;\n\n\tconst childrenArray = toArray<React.ReactNode>(actualChildren);\n\n\tconst shouldThrow =\n\t\tthrowOnMultipleSlotMatch && calculateSlotOccurrences(childrenArray, SlotComponent) > 1;\n\n\tif (shouldThrow) {\n\t\tthrow new AssertionError(errorMessage);\n\t}\n\n\tconst slotElement = childrenArray.find((child) => matchesSlotComponent(child, SlotComponent));\n\n\treturn slotElement;\n};\n\n// NOTE - You can imitate const type parameter by extending readonly[] | []\n\ntype MultipleSlotsOptions = {\n\t/**\n\t * @description The error message to throw when multiple slots are found for a given slot component\n\t * If a string is provided, the same message will be used for all slot components\n\t * If an array is provided, each string in the array will be used as the errorMessage for the corresponding slot component\n\t */\n\terrorMessage?: string | string[];\n\t/**\n\t * @description When true, an AssertionError will be thrown if multiple slots are found for a given slot component\n\t * If a boolean is provided, the same value will be used for all slot components\n\t * If an array is provided, each boolean in the array will be used as the throwOnMultipleSlotMatch value for the corresponding slot component\n\t */\n\tthrowOnMultipleSlotMatch?: boolean | boolean[];\n};\n\ntype GetMultipleSlotsResult<TSlotComponents extends FunctionalComponent[]> = {\n\tregularChildren: React.ReactNode[];\n\tslots: { [Key in keyof TSlotComponents]: ReturnType<TSlotComponents[Key]> };\n};\n\n/**\n * @description The same as getSingleSlot, but for multiple slot components\n */\nexport const getMultipleSlots = <const TSlotComponents extends FunctionalComponent[]>(\n\tchildren: React.ReactNode,\n\tSlotComponents: TSlotComponents,\n\toptions?: MultipleSlotsOptions\n): Prettify<GetMultipleSlotsResult<TSlotComponents>> => {\n\tconst { errorMessage, throwOnMultipleSlotMatch } = options ?? {};\n\n\tconst slots = SlotComponents.map((SlotComponent, index) =>\n\t\tgetSingleSlot(children, SlotComponent, {\n\t\t\terrorMessage: isArray(errorMessage) ? errorMessage[index] : errorMessage,\n\t\t\tthrowOnMultipleSlotMatch: isArray(throwOnMultipleSlotMatch)\n\t\t\t\t? throwOnMultipleSlotMatch[index]\n\t\t\t\t: throwOnMultipleSlotMatch,\n\t\t})\n\t);\n\n\tconst regularChildren = getRegularChildren(children, SlotComponents);\n\n\treturn { regularChildren, slots } as GetMultipleSlotsResult<TSlotComponents>;\n};\n\n/**\n * @description Returns all children that are not slot elements (i.e., don't match any of the provided slot components)\n */\nexport const getRegularChildren = (\n\tchildren: React.ReactNode,\n\tSlotComponentOrComponents: FunctionalComponent | FunctionalComponent[]\n) => {\n\tconst actualChildren =\n\t\tisValidElement<InferProps<typeof ReactFragment>>(children) && children.type === ReactFragment\n\t\t\t? children.props.children\n\t\t\t: children;\n\n\tconst childrenArray = toArray<React.ReactNode>(actualChildren);\n\n\tconst regularChildren = childrenArray.filter(\n\t\t(child) => !matchesAnySlotComponent(child, toArray(SlotComponentOrComponents))\n\t);\n\n\treturn regularChildren;\n};\n"],"mappings":";;;;;AAcA,MAAM,oBACL,cAC4D;AAC5D,QAAO,gBAAgB,aAAa,QAAQ,UAAU;AACtD;AAED,MAAM,uBACL,cAC+D;AAC/D,QAAO,mBAAmB,aAAa,QAAQ,UAAU;AACzD;;;;;;AAOD,MAAa,wBAAwB,OAAwB,kBAAuC;AACnG,KAAI,CAAC,eAAe,UAAU,CAAC,WAAW,MAAM,MAC/C,QAAO;CAGR,MAAM,oBAAoB,oBAAoB,MAAM,QAChD,MAAM,KAAK,gBACZ,MAAM;CAET,MAAM,wBACL,iBAAiB,sBACd,iBAAiB,kBACjB,kBAAkB,eAAe,cAAc;AAEnD,KAAI,sBACH,QAAO;AAGR,KAAI,MAAM,KAAK,SAAS,cAAc,KACrC,QAAO;AAGR,QAAO;AACP;;;;AAKD,MAAa,2BAA2B,OAAwB,mBAA0C;CACzG,MAAM,cAAc,eAAe,MAAM,kBAAkB,qBAAqB,OAAO;AAEvF,QAAO;AACP;;;;;AAiBD,MAAM,4BACL,eACA,kBACI;CACJ,IAAI,QAAQ;AAEZ,MAAK,MAAM,SAAS,eAAe;AAClC,MAAI,CAAC,qBAAqB,OAAO,eAAgB;AAEjD,WAAS;CACT;AAED,QAAO;AACP;;;;;;AAOD,MAAa,iBACZ,UACA,eACA,UAAuB,EAAE,KACrB;CACJ,MAAM,EACL,eAAe,qDACf,2BAA2B,OAC3B,GAAG;CAEJ,MAAM,iBACL,eAAiD,aAAa,SAAS,SAASA,WAC7E,SAAS,MAAM,WACf;CAEJ,MAAM,gBAAgB,QAAyB;CAE/C,MAAM,cACL,4BAA4B,yBAAyB,eAAe,iBAAiB;AAEtF,KAAI,YACH,OAAM,IAAI,eAAe;CAG1B,MAAM,cAAc,cAAc,MAAM,UAAU,qBAAqB,OAAO;AAE9E,QAAO;AACP;;;;AA2BD,MAAa,oBACZ,UACA,gBACA,YACuD;CACvD,MAAM,EAAE,cAAc,0BAA0B,GAAG,WAAW,EAAE;CAEhE,MAAM,QAAQ,eAAe,KAAK,eAAe,UAChD,cAAc,UAAU,eAAe;EACtC,cAAc,QAAQ,gBAAgB,aAAa,SAAS;EAC5D,0BAA0B,QAAQ,4BAC/B,yBAAyB,SACzB;EACH;CAGF,MAAM,kBAAkB,mBAAmB,UAAU;AAErD,QAAO;EAAE;EAAiB;EAAO;AACjC;;;;AAKD,MAAa,sBACZ,UACA,8BACI;CACJ,MAAM,iBACL,eAAiD,aAAa,SAAS,SAASA,WAC7E,SAAS,MAAM,WACf;CAEJ,MAAM,gBAAgB,QAAyB;CAE/C,MAAM,kBAAkB,cAAc,QACpC,UAAU,CAAC,wBAAwB,OAAO,QAAQ;AAGpD,QAAO;AACP"}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import * as _zayne_labs_toolkit_type_helpers0 from "@zayne-labs/toolkit-type-helpers";
|
|
2
|
-
import { Awaitable, SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
|
3
|
-
import * as react4 from "react";
|
|
4
|
-
import * as _zayne_labs_toolkit_core0 from "@zayne-labs/toolkit-core";
|
|
5
|
-
import { FileMeta, FileValidationErrorContext, FileValidationHooksAsync, FileValidationSettingsAsync } from "@zayne-labs/toolkit-core";
|
|
6
|
-
import { InferProps, PolymorphicProps } from "@zayne-labs/toolkit-react/utils";
|
|
7
|
-
|
|
8
|
-
//#region src/components/ui/drop-zone/drop-zone-context.d.ts
|
|
9
|
-
declare const DropZoneStoreContextProvider: (props: {
|
|
10
|
-
children: React.ReactNode;
|
|
11
|
-
store: _zayne_labs_toolkit_core0.StoreApi<DropZoneStore>;
|
|
12
|
-
}) => react4.FunctionComponentElement<react4.ProviderProps<_zayne_labs_toolkit_core0.StoreApi<DropZoneStore> | null>>, useDropZoneStoreContext: <TResult = DropZoneStore>(selector?: _zayne_labs_toolkit_type_helpers0.SelectorFn<DropZoneStore, TResult> | undefined) => TResult;
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/components/ui/drop-zone/use-drop-zone.d.ts
|
|
15
|
-
type ExtraProps = {
|
|
16
|
-
container?: InferProps<HTMLElement>;
|
|
17
|
-
input?: InferProps<"input">;
|
|
18
|
-
trigger?: InferProps<"button">;
|
|
19
|
-
};
|
|
20
|
-
type ClassNames = { [key in keyof ExtraProps]: string };
|
|
21
|
-
type UseDropZoneResult = {
|
|
22
|
-
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
23
|
-
propGetters: DropZonePropGetters;
|
|
24
|
-
storeApi: ReturnType<typeof createDropZoneStore>;
|
|
25
|
-
useDropZoneStore: typeof useDropZoneStoreContext;
|
|
26
|
-
};
|
|
27
|
-
type UseDropZoneProps = FileValidationSettingsAsync & {
|
|
28
|
-
/**
|
|
29
|
-
* CSS classes to apply to the various parts of the drop zone
|
|
30
|
-
*/
|
|
31
|
-
classNames?: ClassNames;
|
|
32
|
-
/**
|
|
33
|
-
* Whether to disallow preview for non-image files
|
|
34
|
-
* @default true
|
|
35
|
-
*/
|
|
36
|
-
disablePreviewForNonImageFiles?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Extra props to pass to various parts of the dropzone
|
|
39
|
-
*/
|
|
40
|
-
extraProps?: ExtraProps;
|
|
41
|
-
/**
|
|
42
|
-
* Initial files to populate the drop zone
|
|
43
|
-
*/
|
|
44
|
-
initialFiles?: FileMeta | FileMeta[] | null;
|
|
45
|
-
/**
|
|
46
|
-
* Whether to allow multiple files to be uploaded
|
|
47
|
-
*/
|
|
48
|
-
multiple?: boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Callback function to be called when internal files state changes
|
|
51
|
-
*/
|
|
52
|
-
onFilesChange?: (context: Pick<DropZoneState, "fileStateArray">) => void;
|
|
53
|
-
/**
|
|
54
|
-
* Callback function to be called when new files are uploaded
|
|
55
|
-
*/
|
|
56
|
-
onUpload?: (context: Pick<DropZoneState, "fileStateArray">) => Awaitable<void>;
|
|
57
|
-
/**
|
|
58
|
-
* Callback function to be called on each file upload as they occur
|
|
59
|
-
*/
|
|
60
|
-
onUploadError?: FileValidationHooksAsync["onError"];
|
|
61
|
-
/**
|
|
62
|
-
* Callback function to be called once after all file upload errors have occurred
|
|
63
|
-
*/
|
|
64
|
-
onUploadErrorCollection?: FileValidationHooksAsync["onErrorCollection"];
|
|
65
|
-
/**
|
|
66
|
-
* Callback function to be called on file upload success
|
|
67
|
-
*/
|
|
68
|
-
onUploadSuccess?: FileValidationHooksAsync["onSuccess"];
|
|
69
|
-
/**
|
|
70
|
-
* Whether clicking the drop zone area will open the default file picker or not
|
|
71
|
-
*
|
|
72
|
-
* @default true
|
|
73
|
-
*/
|
|
74
|
-
shouldOpenFilePickerOnAreaClick?: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* Custom validation function.
|
|
77
|
-
*
|
|
78
|
-
* If the function returns false, the file will be rejected
|
|
79
|
-
*
|
|
80
|
-
*/
|
|
81
|
-
validator?: FileValidationSettingsAsync["validator"];
|
|
82
|
-
};
|
|
83
|
-
declare const useDropZone: (props?: UseDropZoneProps) => UseDropZoneResult;
|
|
84
|
-
//#endregion
|
|
85
|
-
//#region src/components/ui/drop-zone/types.d.ts
|
|
86
|
-
type FileState = {
|
|
87
|
-
/**
|
|
88
|
-
* File object or file metadata
|
|
89
|
-
*/
|
|
90
|
-
file: File | FileMeta;
|
|
91
|
-
/**
|
|
92
|
-
* Unique ID for the file
|
|
93
|
-
*/
|
|
94
|
-
id: string;
|
|
95
|
-
/**
|
|
96
|
-
* Preview URL for the file
|
|
97
|
-
* - Will be undefined if `disallowPreviewForNonImageFiles` is set to `true` and the file is not an image
|
|
98
|
-
* - Can also be undefined if `URL.createObjectURL` fails
|
|
99
|
-
*/
|
|
100
|
-
preview: string | undefined;
|
|
101
|
-
};
|
|
102
|
-
type DropZonePropGetters = {
|
|
103
|
-
getContainerProps: (containerProps?: ExtraProps["container"]) => ExtraProps["container"];
|
|
104
|
-
getInputProps: (inputProps?: ExtraProps["input"]) => ExtraProps["input"];
|
|
105
|
-
getTriggerProps: (triggerProps?: ExtraProps["trigger"]) => ExtraProps["trigger"];
|
|
106
|
-
};
|
|
107
|
-
type DropZoneState = {
|
|
108
|
-
/**
|
|
109
|
-
* List of validation errors
|
|
110
|
-
*/
|
|
111
|
-
errors: FileValidationErrorContext[];
|
|
112
|
-
/**
|
|
113
|
-
* List of files with their preview URLs and unique IDs
|
|
114
|
-
*/
|
|
115
|
-
fileStateArray: FileState[];
|
|
116
|
-
/**
|
|
117
|
-
* Whether or not a file is currently being dragged over the drop zone
|
|
118
|
-
*/
|
|
119
|
-
isDraggingOver: boolean;
|
|
120
|
-
};
|
|
121
|
-
type DropZoneActions = {
|
|
122
|
-
addFiles: (files: File[] | FileList | null) => Awaitable<void>;
|
|
123
|
-
clearErrors: () => void;
|
|
124
|
-
clearFiles: () => void;
|
|
125
|
-
handleChange: (event: React.ChangeEvent<HTMLInputElement>) => Awaitable<void>;
|
|
126
|
-
handleDragEnter: (event: React.DragEvent<HTMLElement>) => void;
|
|
127
|
-
handleDragLeave: (event: React.DragEvent<HTMLElement>) => void;
|
|
128
|
-
handleDragOver: (event: React.DragEvent<HTMLElement>) => void;
|
|
129
|
-
handleDrop: (event: React.DragEvent<HTMLElement>) => Awaitable<void>;
|
|
130
|
-
openFilePicker: () => void;
|
|
131
|
-
removeFile: (fileToRemoveOrFileId: string | FileState) => void;
|
|
132
|
-
};
|
|
133
|
-
//#endregion
|
|
134
|
-
//#region src/components/ui/drop-zone/drop-zone-store.d.ts
|
|
135
|
-
type DropZoneStore = DropZoneState & {
|
|
136
|
-
actions: DropZoneActions;
|
|
137
|
-
};
|
|
138
|
-
declare const createDropZoneStore: (initStoreValues: Pick<UseDropZoneProps, "allowedFileTypes" | "disablePreviewForNonImageFiles" | "initialFiles" | "maxFileCount" | "maxFileSize" | "multiple" | "onFilesChange" | "onUpload" | "onUploadError" | "onUploadErrorCollection" | "onUploadSuccess" | "rejectDuplicateFiles" | "validator"> & {
|
|
139
|
-
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
140
|
-
}) => _zayne_labs_toolkit_core0.StoreApi<DropZoneStore>;
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/components/ui/drop-zone/drop-zone.d.ts
|
|
143
|
-
type DropZoneRootProps = UseDropZoneProps & {
|
|
144
|
-
children: react4.ReactNode;
|
|
145
|
-
};
|
|
146
|
-
declare function DropZoneRoot(props: DropZoneRootProps): react4.JSX.Element;
|
|
147
|
-
type DropZoneContextProps<TSlice> = {
|
|
148
|
-
children: react4.ReactNode | ((props: TSlice) => react4.ReactNode);
|
|
149
|
-
selector?: SelectorFn<DropZoneStore, TSlice>;
|
|
150
|
-
};
|
|
151
|
-
declare function DropZoneContext<TSlice = DropZoneStore>(props: DropZoneContextProps<TSlice>): react4.ReactNode;
|
|
152
|
-
type DropZoneContainerProps = ExtraProps["container"] & {
|
|
153
|
-
asChild?: boolean;
|
|
154
|
-
};
|
|
155
|
-
declare function DropZoneContainer<TElement extends react4.ElementType = "div">(props: PolymorphicProps<TElement, DropZoneContainerProps>): react4.JSX.Element;
|
|
156
|
-
type DropZoneInputProps = ExtraProps["input"] & {
|
|
157
|
-
asChild?: boolean;
|
|
158
|
-
};
|
|
159
|
-
declare function DropZoneInput(props: DropZoneInputProps): react4.JSX.Element;
|
|
160
|
-
type DropZoneAreaProps<TSlice> = {
|
|
161
|
-
children: react4.ReactNode | ((props: TSlice) => react4.ReactNode);
|
|
162
|
-
extraProps?: Pick<ExtraProps, "container" | "input">;
|
|
163
|
-
selector?: SelectorFn<DropZoneStore, TSlice>;
|
|
164
|
-
};
|
|
165
|
-
declare function DropZoneArea<TSlice = DropZoneStore>(props: DropZoneAreaProps<TSlice>): react4.JSX.Element;
|
|
166
|
-
type DropZoneTriggerProps = ExtraProps["trigger"] & {
|
|
167
|
-
asChild?: boolean;
|
|
168
|
-
};
|
|
169
|
-
declare function DropZoneTrigger(props: DropZoneTriggerProps): react4.JSX.Element;
|
|
170
|
-
type DropZoneFilePreviewProps = {
|
|
171
|
-
children: react4.ReactNode | ((props: Pick<DropZoneStore, "actions" | "fileStateArray">) => react4.ReactNode);
|
|
172
|
-
};
|
|
173
|
-
declare function DropZoneFilePreview(props: DropZoneFilePreviewProps): react4.ReactNode;
|
|
174
|
-
type DropZoneErrorPreviewProps = {
|
|
175
|
-
children: react4.ReactNode | ((props: Pick<DropZoneStore, "actions" | "errors">) => react4.ReactNode);
|
|
176
|
-
};
|
|
177
|
-
declare function DropZoneErrorPreview(props: DropZoneErrorPreviewProps): react4.ReactNode;
|
|
178
|
-
declare namespace drop_zone_parts_d_exports {
|
|
179
|
-
export { DropZoneArea as Area, DropZoneContainer as Container, DropZoneContext as Context, DropZoneErrorPreview as ErrorPreview, DropZoneFilePreview as FilePreview, DropZoneInput as Input, DropZoneRoot as Root, DropZoneTrigger as Trigger };
|
|
180
|
-
}
|
|
181
|
-
//#endregion
|
|
182
|
-
export { ClassNames, DropZoneArea, DropZoneContainer, DropZoneContext, DropZoneContextProps, DropZoneErrorPreview, DropZoneFilePreview, DropZoneInput, DropZoneRoot, DropZoneRootProps, DropZoneTrigger, ExtraProps, UseDropZoneProps, UseDropZoneResult, drop_zone_parts_d_exports, useDropZone, useDropZoneStoreContext };
|
|
183
|
-
//# sourceMappingURL=index-B-NUFudm.d.ts.map
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { CallbackFn, EmptyObject, Prettify, UnionToIntersection, UnknownObject } from "@zayne-labs/toolkit-type-helpers";
|
|
2
|
-
import * as react8 from "react";
|
|
3
|
-
|
|
4
|
-
//#region src/lib/utils/getSlotMap/getSlotMap.d.ts
|
|
5
|
-
type GetSlotName<TSlotComponentProps extends GetSlotComponentProps> = string extends TSlotComponentProps["name"] ? never : "default" extends TSlotComponentProps["name"] ? never : TSlotComponentProps["name"];
|
|
6
|
-
type GetSpecificSlotsType<TSlotComponentProps extends GetSlotComponentProps> = { [TName in keyof TSlotComponentProps as GetSlotName<TSlotComponentProps>]: Extract<TSlotComponentProps["children"], React.ReactNode> };
|
|
7
|
-
/**
|
|
8
|
-
* Maps slot names to their corresponding children types
|
|
9
|
-
*/
|
|
10
|
-
type GetSlotMapResult<TSlotComponentProps extends GetSlotComponentProps> = UnionToIntersection<GetSpecificSlotsType<TSlotComponentProps>> & {
|
|
11
|
-
default: React.ReactNode[];
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Symbol used to identify SlotComponent instances
|
|
15
|
-
*/
|
|
16
|
-
declare const slotComponentSymbol: unique symbol;
|
|
17
|
-
/**
|
|
18
|
-
* @description Creates a map of named slots from React children. Returns an object mapping slot names to their children,
|
|
19
|
-
* with a default slot for unmatched children.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* import { type GetSlotComponentProps, SlotComponent } from "@zayne-labs/toolkit-react/utils"
|
|
24
|
-
*
|
|
25
|
-
* type SlotProps = GetSlotComponentProps<"header" | "footer">;
|
|
26
|
-
*
|
|
27
|
-
* function Parent({ children }: { children: React.ReactNode }) {
|
|
28
|
-
* const slots = getSlotMap<SlotProps>(children);
|
|
29
|
-
*
|
|
30
|
-
* return (
|
|
31
|
-
* <div>
|
|
32
|
-
* <header>{slots.header}</header>
|
|
33
|
-
* <main>{slots.default}</main>
|
|
34
|
-
* <footer>{slots.footer}</footer>
|
|
35
|
-
* </div>
|
|
36
|
-
* );
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* Usage:
|
|
41
|
-
* ```tsx
|
|
42
|
-
* <Parent>
|
|
43
|
-
* <SlotComponent name="header">Header Content</SlotComponent>
|
|
44
|
-
* <div>Random stuff</div>
|
|
45
|
-
* <SlotComponent name="footer">Footer Content</SlotComponent>
|
|
46
|
-
* </Parent>
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
declare const getSlotMap: <TSlotComponentProps extends GetSlotComponentProps>(children: React.ReactNode) => Prettify<GetSlotMapResult<TSlotComponentProps>>;
|
|
50
|
-
/**
|
|
51
|
-
* @description Produce props for the SlotComponent
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* // Pattern One (slot or slots have same children type, which is just React.ReactNode by default)
|
|
56
|
-
* type SlotProps = GetSlotComponentProps<"header" | "content" | "footer">;
|
|
57
|
-
*
|
|
58
|
-
* // Pattern Two (some slots can have different children type)
|
|
59
|
-
* type SlotProps = GetSlotComponentProps<"header", React.ReactNode> | GetSlotComponentProps<"header", (renderProp: RenderProp) => React.ReactNode>;
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
type GetSlotComponentProps<TName extends string = string, TChildren extends CallbackFn<never, React.ReactNode> | React.ReactNode = CallbackFn<never, React.ReactNode> | React.ReactNode> = {
|
|
63
|
-
children: TChildren;
|
|
64
|
-
/**
|
|
65
|
-
* Name of the slot where content should be rendered
|
|
66
|
-
*/
|
|
67
|
-
name: TName;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* @description Creates a slot component
|
|
71
|
-
*/
|
|
72
|
-
declare const createSlotComponent: <TSlotComponentProps extends GetSlotComponentProps>() => {
|
|
73
|
-
(props: TSlotComponentProps): React.ReactNode;
|
|
74
|
-
slotSymbol: typeof slotComponentSymbol;
|
|
75
|
-
};
|
|
76
|
-
type SlotWithNameAndSymbol<TSlotComponentProps extends GetSlotComponentProps = GetSlotComponentProps, TOtherProps extends UnknownObject = EmptyObject> = {
|
|
77
|
-
(props: Pick<TSlotComponentProps, "children"> & TOtherProps): React.ReactNode;
|
|
78
|
-
readonly slotName?: TSlotComponentProps["name"];
|
|
79
|
-
readonly slotSymbol?: symbol;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* @description Adds a slot symbol and name to a slot component passed in
|
|
83
|
-
*/
|
|
84
|
-
declare const withSlotNameAndSymbol: <TSlotComponentProps extends GetSlotComponentProps, TOtherProps extends UnknownObject = EmptyObject>(name: TSlotComponentProps["name"], SlotComponent?: SlotWithNameAndSymbol<TSlotComponentProps, TOtherProps>) => SlotWithNameAndSymbol<TSlotComponentProps, TOtherProps>;
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region src/lib/utils/getSlot/getSlot.d.ts
|
|
87
|
-
type FunctionalComponent<TProps extends UnknownObject = never> = React.FunctionComponent<TProps>;
|
|
88
|
-
/**
|
|
89
|
-
* @description Checks if a react child (within the children array) matches the provided SlotComponent using multiple matching strategies:
|
|
90
|
-
* 1. Matches by slot symbol property
|
|
91
|
-
* 2. Matches by component name
|
|
92
|
-
*/
|
|
93
|
-
declare const matchesSlotComponent: (child: React.ReactNode, SlotComponent: FunctionalComponent) => boolean;
|
|
94
|
-
/**
|
|
95
|
-
* @description Checks if a react child (within the children array) matches any of the provided SlotComponents.
|
|
96
|
-
*/
|
|
97
|
-
declare const matchesAnySlotComponent: (child: React.ReactNode, SlotComponents: FunctionalComponent[]) => boolean;
|
|
98
|
-
type SlotOptions = {
|
|
99
|
-
/**
|
|
100
|
-
* @description The error message to throw when multiple slots are found for a given slot component
|
|
101
|
-
*/
|
|
102
|
-
errorMessage?: string;
|
|
103
|
-
/**
|
|
104
|
-
* @description When true, an AssertionError will be thrown if multiple slots are found for a given slot component
|
|
105
|
-
*/
|
|
106
|
-
throwOnMultipleSlotMatch?: boolean;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* @description Retrieves a single slot element from a collection of React children that matches the provided SlotComponent component.
|
|
110
|
-
*
|
|
111
|
-
* @throws { AssertionError } when throwOnMultipleSlotMatch is true and multiple slots are found
|
|
112
|
-
*/
|
|
113
|
-
declare const getSingleSlot: (children: React.ReactNode, SlotComponent: FunctionalComponent, options?: SlotOptions) => react8.ReactNode;
|
|
114
|
-
type MultipleSlotsOptions = {
|
|
115
|
-
/**
|
|
116
|
-
* @description The error message to throw when multiple slots are found for a given slot component
|
|
117
|
-
* If a string is provided, the same message will be used for all slot components
|
|
118
|
-
* If an array is provided, each string in the array will be used as the errorMessage for the corresponding slot component
|
|
119
|
-
*/
|
|
120
|
-
errorMessage?: string | string[];
|
|
121
|
-
/**
|
|
122
|
-
* @description When true, an AssertionError will be thrown if multiple slots are found for a given slot component
|
|
123
|
-
* If a boolean is provided, the same value will be used for all slot components
|
|
124
|
-
* If an array is provided, each boolean in the array will be used as the throwOnMultipleSlotMatch value for the corresponding slot component
|
|
125
|
-
*/
|
|
126
|
-
throwOnMultipleSlotMatch?: boolean | boolean[];
|
|
127
|
-
};
|
|
128
|
-
type GetMultipleSlotsResult<TSlotComponents extends FunctionalComponent[]> = {
|
|
129
|
-
regularChildren: React.ReactNode[];
|
|
130
|
-
slots: { [Key in keyof TSlotComponents]: ReturnType<TSlotComponents[Key]> };
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* @description The same as getSingleSlot, but for multiple slot components
|
|
134
|
-
*/
|
|
135
|
-
declare const getMultipleSlots: <const TSlotComponents extends FunctionalComponent[]>(children: React.ReactNode, SlotComponents: TSlotComponents, options?: MultipleSlotsOptions) => Prettify<GetMultipleSlotsResult<TSlotComponents>>;
|
|
136
|
-
/**
|
|
137
|
-
* @description Returns all children that are not slot elements (i.e., don't match any of the provided slot components)
|
|
138
|
-
*/
|
|
139
|
-
declare const getRegularChildren: (children: React.ReactNode, SlotComponentOrComponents: FunctionalComponent | FunctionalComponent[]) => react8.ReactNode[];
|
|
140
|
-
//#endregion
|
|
141
|
-
export { FunctionalComponent, GetSlotComponentProps, GetSlotMapResult, createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, slotComponentSymbol, withSlotNameAndSymbol };
|
|
142
|
-
//# sourceMappingURL=index-BNrCAe9Y.d.ts.map
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ExtractUnion, Prettify } from "@zayne-labs/toolkit-type-helpers";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { DiscriminatedRenderItemProps, PolymorphicProps } from "@zayne-labs/toolkit-react/utils";
|
|
4
|
-
|
|
5
|
-
//#region src/components/common/for/for.d.ts
|
|
6
|
-
type RenderPropFn<TArray> = (item: TArray extends readonly unknown[] ? ExtractUnion<TArray> : TArray extends number ? number : unknown, index: number, array: TArray extends readonly unknown[] ? TArray : TArray extends number ? number[] : unknown[]) => React.ReactNode;
|
|
7
|
-
type ForRenderProps<TArrayItem> = DiscriminatedRenderItemProps<RenderPropFn<TArrayItem>>;
|
|
8
|
-
type ForProps<TArray> = Prettify<{
|
|
9
|
-
each: TArray;
|
|
10
|
-
fallback?: React.ReactNode;
|
|
11
|
-
} & ForRenderProps<TArray>>;
|
|
12
|
-
declare function For<const TArray>(props: ForProps<TArray>): string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | null;
|
|
13
|
-
declare function ForWithWrapper<TArrayItem, TElement extends React.ElementType = "ul">(props: PolymorphicProps<TElement, ForProps<TArrayItem>>): React.JSX.Element;
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/components/common/for/getElementList.d.ts
|
|
16
|
-
type GetElementListResult<TVariant extends "base" | "withWrapper"> = TVariant extends "base" ? [typeof For] : [typeof ForWithWrapper];
|
|
17
|
-
declare const getElementList: <TVariant extends "base" | "withWrapper" = "withWrapper">(variant?: TVariant) => GetElementListResult<TVariant>;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { For, ForRenderProps, ForWithWrapper, getElementList };
|
|
20
|
-
//# sourceMappingURL=index-CnvH74ea.d.ts.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { FunctionalComponent, GetSlotComponentProps, GetSlotMapResult, createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, slotComponentSymbol, withSlotNameAndSymbol } from "../../index-BNrCAe9Y.js";
|
|
2
|
-
export { FunctionalComponent, GetSlotComponentProps, GetSlotMapResult, createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, slotComponentSymbol, withSlotNameAndSymbol };
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createSlotComponent, getSlotMap, slotComponentSymbol, withSlotNameAndSymbol } from "../../utils-ChjmDoRe.js";
|
|
2
|
-
import { getMultipleSlots, getRegularChildren, getSingleSlot, matchesAnySlotComponent, matchesSlotComponent } from "../../getSlot-Cf5ON6lE.js";
|
|
3
|
-
|
|
4
|
-
export { createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, slotComponentSymbol, withSlotNameAndSymbol };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"show-BabiXbf7.js","names":[],"sources":["../../src/components/common/show/show.tsx","../../src/components/common/show/show-parts.ts"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getMultipleSlots } from \"@/lib/utils/getSlot\";\nimport { assert, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ShowProps<TWhen> = {\n\tchildren: React.ReactNode | ((value: TWhen) => React.ReactNode);\n\tfallback?: React.ReactNode;\n\twhen: false | TWhen | null | undefined;\n};\n\nexport function ShowRoot<TWhen>(props: ShowProps<TWhen>) {\n\tconst { children, fallback = null, when } = props;\n\n\tconst resolvedChildren = isFunction(children) ? children(when as TWhen) : children;\n\n\tconst {\n\t\tregularChildren,\n\t\tslots: [contentSlot, fallBackSlot],\n\t} = getMultipleSlots(resolvedChildren, [ShowContent, ShowFallback], {\n\t\terrorMessage: [\n\t\t\t\"Only one <Show.Content> component is allowed\",\n\t\t\t\"Only one <Show.Fallback> or <Show.OtherWise> component is allowed\",\n\t\t],\n\t\tthrowOnMultipleSlotMatch: true,\n\t});\n\n\tif (!when) {\n\t\tassert(\n\t\t\t!(fallBackSlot && fallback),\n\t\t\t\"The fallback prop and <Show.Fallback> cannot be used at the same time.\"\n\t\t);\n\n\t\treturn fallBackSlot ?? fallback;\n\t}\n\n\treturn contentSlot ?? regularChildren;\n}\n\nexport function ShowContent({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nShowContent.slotSymbol = Symbol(\"show-content\");\n\nexport function ShowFallback({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nShowFallback.slotSymbol = Symbol(\"show-fallback\");\n","export {\n\tShowContent as Content,\n\tShowFallback as Fallback,\n\tShowFallback as Otherwise,\n\tShowRoot as Root,\n} from \"./show\";\n"],"mappings":";;;;;;AAaA,SAAgB,SAAgB,OAAyB;CACxD,MAAM,EAAE,UAAU,WAAW,MAAM,MAAM,GAAG;CAE5C,MAAM,mBAAmB,WAAW,YAAY,SAAS,QAAiB;CAE1E,MAAM,EACL,iBACA,OAAO,CAAC,aAAa,aAAa,EAClC,GAAG,iBAAiB,kBAAkB,CAAC,aAAa,aAAa,EAAE;EACnE,cAAc,CACb,gDACA,oEACA;EACD,0BAA0B;EAC1B;AAED,KAAI,CAAC,MAAM;AACV,SACC,EAAE,gBAAgB,WAClB;AAGD,SAAO,gBAAgB;CACvB;AAED,QAAO,eAAe;AACtB;AAED,SAAgB,YAAY,EAAE,UAAyC,EAAE;AACxE,QAAO;AACP;AACD,YAAY,aAAa,OAAO;AAEhC,SAAgB,aAAa,EAAE,UAAyC,EAAE;AACzE,QAAO;AACP;AACD,aAAa,aAAa,OAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"suspense-with-boundary-CEVORL8K.js","names":[],"sources":["../../src/components/common/suspense-with-boundary/suspense-with-boundary.tsx"],"sourcesContent":["import { Suspense } from \"react\";\nimport { ErrorBoundary, type ErrorBoundaryProps } from \"../error-boundary\";\n\nexport type SuspenseWithBoundaryProps = {\n\tchildren: React.ReactNode;\n\terrorFallback?: ErrorBoundaryProps[\"fallback\"];\n\tfallback?: React.ReactNode;\n};\n\nexport function SuspenseWithBoundary(props: SuspenseWithBoundaryProps) {\n\tconst { children, errorFallback, fallback } = props;\n\n\tconst errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };\n\tconst suspenseProps = Boolean(fallback) && { fallback };\n\n\treturn (\n\t\t<ErrorBoundary {...errorBoundaryProps}>\n\t\t\t<Suspense {...suspenseProps}>{children}</Suspense>\n\t\t</ErrorBoundary>\n\t);\n}\n"],"mappings":";;;;;AASA,SAAgB,qBAAqB,OAAkC;CACtE,MAAM,EAAE,UAAU,eAAe,UAAU,GAAG;CAE9C,MAAM,qBAAqB,QAAQ,kBAAkB,EAAE,UAAU,eAAe;CAChF,MAAM,gBAAgB,QAAQ,aAAa,EAAE,UAAU;AAEvD,QACC,oBAAC;EAAc,GAAI;YAClB,oBAAC;GAAS,GAAI;GAAgB;;;AAGhC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"switch-CCMD01Rs.js","names":[],"sources":["../../src/components/common/switch/switch.tsx","../../src/components/common/switch/switch-parts.ts"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getRegularChildren, getSingleSlot } from \"@/lib/utils/getSlot\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ValidSwitchComponentType = React.ReactElement<SwitchMatchProps<unknown>>;\n\ntype SwitchProps = {\n\tchildren: ValidSwitchComponentType | ValidSwitchComponentType[];\n\tvalue?: unknown;\n};\n\nconst defaultValueSymbol = Symbol(\"default-value\");\n\nexport function SwitchRoot(props: SwitchProps) {\n\tconst { children, value = defaultValueSymbol } = props;\n\n\tconst defaultCase = getSingleSlot(children, SwitchDefault, {\n\t\terrorMessage: \"Only one <Switch.Default> component is allowed\",\n\t\tthrowOnMultipleSlotMatch: true,\n\t});\n\n\tconst childrenCasesArray = getRegularChildren(children, SwitchDefault) as ValidSwitchComponentType[];\n\n\tconst matchedCase = childrenCasesArray.find((child) => {\n\t\t// == If value is defaultValueSymbol, match the cases in order like switch(true)\n\t\tif (value === defaultValueSymbol) {\n\t\t\treturn Boolean(child.props.when);\n\t\t}\n\n\t\t// == Otherwise, match the cases like switch(value)\n\t\treturn child.props.when === value;\n\t});\n\n\treturn matchedCase ?? defaultCase;\n}\n\ntype SwitchMatchProps<TWhen> = {\n\tchildren: React.ReactNode | ((value: TWhen) => React.ReactNode);\n\twhen: false | TWhen | null | undefined;\n};\n\nexport function SwitchMatch<TWhen>(props: SwitchMatchProps<TWhen>) {\n\tconst { children, when } = props;\n\n\tconst resolvedChildren = isFunction(children) ? children(when as TWhen) : children;\n\n\treturn resolvedChildren;\n}\n\nexport function SwitchDefault({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nSwitchDefault.slotSymbol = Symbol(\"switch-default\");\n","export { SwitchDefault as Default, SwitchMatch as Match, SwitchRoot as Root } from \"./switch\";\n"],"mappings":";;;;;;AAcA,MAAM,qBAAqB,OAAO;AAElC,SAAgB,WAAW,OAAoB;CAC9C,MAAM,EAAE,UAAU,QAAQ,oBAAoB,GAAG;CAEjD,MAAM,cAAc,cAAc,UAAU,eAAe;EAC1D,cAAc;EACd,0BAA0B;EAC1B;CAED,MAAM,qBAAqB,mBAAmB,UAAU;CAExD,MAAM,cAAc,mBAAmB,MAAM,UAAU;AAEtD,MAAI,UAAU,mBACb,QAAO,QAAQ,MAAM,MAAM;AAI5B,SAAO,MAAM,MAAM,SAAS;CAC5B;AAED,QAAO,eAAe;AACtB;AAOD,SAAgB,YAAmB,OAAgC;CAClE,MAAM,EAAE,UAAU,MAAM,GAAG;CAE3B,MAAM,mBAAmB,WAAW,YAAY,SAAS,QAAiB;AAE1E,QAAO;AACP;AAED,SAAgB,cAAc,EAAE,UAAyC,EAAE;AAC1E,QAAO;AACP;AACD,cAAc,aAAa,OAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"teleport-DfuYOzsj.js","names":[],"sources":["../../src/components/common/teleport/teleport.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { type AnyString, isString } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useEffect, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\n\ntype ValidHtmlTags = keyof HTMLElementTagNameMap;\n\ntype PortalProps = {\n\tchildren: React.ReactNode;\n\tinsertPosition?: InsertPosition;\n\tto: AnyString | HTMLElement | ValidHtmlTags | null;\n};\n\nfunction Teleport(props: PortalProps) {\n\tconst { children, insertPosition, to } = props;\n\n\tconst [portalContainer, setPortalContainer] = useState<HTMLElement | null>(null);\n\n\t/* eslint-disable react-hooks-extra/no-direct-set-state-in-use-effect -- Allow */\n\n\tuseEffect(() => {\n\t\tif (!to) return;\n\n\t\tif (insertPosition) return;\n\n\t\tconst destination = isString(to) ? document.querySelector<HTMLElement>(to) : to;\n\n\t\tdestination && setPortalContainer(destination);\n\t}, [to, insertPosition]);\n\n\tuseEffect(() => {\n\t\tif (!to) return;\n\n\t\tif (!insertPosition) return;\n\n\t\tconst destination = isString(to) ? document.querySelector<HTMLElement>(to) : to;\n\n\t\tconst tempWrapper = document.createElement(\"div\");\n\t\ttempWrapper.style.display = \"contents\";\n\n\t\tdestination?.insertAdjacentElement(insertPosition, tempWrapper);\n\n\t\tsetPortalContainer(tempWrapper);\n\n\t\treturn () => {\n\t\t\ttempWrapper.remove();\n\t\t};\n\t}, [to, insertPosition]);\n\n\t/* eslint-enable react-hooks-extra/no-direct-set-state-in-use-effect -- Allow */\n\n\treturn portalContainer && createPortal(children, portalContainer);\n}\n\nexport { Teleport };\n"],"mappings":";;;;;AAgBA,SAAS,SAAS,OAAoB;CACrC,MAAM,EAAE,UAAU,gBAAgB,IAAI,GAAG;CAEzC,MAAM,CAAC,iBAAiB,mBAAmB,GAAG,SAA6B;AAI3E,iBAAgB;AACf,MAAI,CAAC,GAAI;AAET,MAAI,eAAgB;EAEpB,MAAM,cAAc,SAAS,MAAM,SAAS,cAA2B,MAAM;AAE7E,iBAAe,mBAAmB;CAClC,GAAE,CAAC,IAAI,eAAe;AAEvB,iBAAgB;AACf,MAAI,CAAC,GAAI;AAET,MAAI,CAAC,eAAgB;EAErB,MAAM,cAAc,SAAS,MAAM,SAAS,cAA2B,MAAM;EAE7E,MAAM,cAAc,SAAS,cAAc;AAC3C,cAAY,MAAM,UAAU;AAE5B,eAAa,sBAAsB,gBAAgB;AAEnD,qBAAmB;AAEnB,eAAa;AACZ,eAAY;EACZ;CACD,GAAE,CAAC,IAAI,eAAe;AAIvB,QAAO,mBAAmB,aAAa,UAAU;AACjD"}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { isFunction } from "@zayne-labs/toolkit-type-helpers";
|
|
2
|
-
import { Fragment, isValidElement } from "react";
|
|
3
|
-
import { toArray } from "@zayne-labs/toolkit-core";
|
|
4
|
-
|
|
5
|
-
//#region src/lib/utils/getSlotMap/getSlotMap.ts
|
|
6
|
-
/**
|
|
7
|
-
* Symbol used to identify SlotComponent instances
|
|
8
|
-
*/
|
|
9
|
-
const slotComponentSymbol = Symbol("slot-component");
|
|
10
|
-
/**
|
|
11
|
-
* @description Creates a map of named slots from React children. Returns an object mapping slot names to their children,
|
|
12
|
-
* with a default slot for unmatched children.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```tsx
|
|
16
|
-
* import { type GetSlotComponentProps, SlotComponent } from "@zayne-labs/toolkit-react/utils"
|
|
17
|
-
*
|
|
18
|
-
* type SlotProps = GetSlotComponentProps<"header" | "footer">;
|
|
19
|
-
*
|
|
20
|
-
* function Parent({ children }: { children: React.ReactNode }) {
|
|
21
|
-
* const slots = getSlotMap<SlotProps>(children);
|
|
22
|
-
*
|
|
23
|
-
* return (
|
|
24
|
-
* <div>
|
|
25
|
-
* <header>{slots.header}</header>
|
|
26
|
-
* <main>{slots.default}</main>
|
|
27
|
-
* <footer>{slots.footer}</footer>
|
|
28
|
-
* </div>
|
|
29
|
-
* );
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* Usage:
|
|
34
|
-
* ```tsx
|
|
35
|
-
* <Parent>
|
|
36
|
-
* <SlotComponent name="header">Header Content</SlotComponent>
|
|
37
|
-
* <div>Random stuff</div>
|
|
38
|
-
* <SlotComponent name="footer">Footer Content</SlotComponent>
|
|
39
|
-
* </Parent>
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
const getSlotMap = (children) => {
|
|
43
|
-
const slots = { default: [] };
|
|
44
|
-
const isFragment = isValidElement(children) && children.type === Fragment;
|
|
45
|
-
const actualChildren = isFragment ? children.props.children : children;
|
|
46
|
-
const childrenArray = toArray(actualChildren);
|
|
47
|
-
for (const child of childrenArray) {
|
|
48
|
-
if (!isValidElement(child) || !isFunction(child.type)) {
|
|
49
|
-
slots.default.push(child);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
const childType = child.type;
|
|
53
|
-
const isSlotElement = childType.slotSymbol === slotComponentSymbol && Boolean(childType.slotName ?? child.props.name);
|
|
54
|
-
if (!isSlotElement) {
|
|
55
|
-
slots.default.push(child);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
const slotName = childType.slotName ?? child.props.name;
|
|
59
|
-
if (slotName === "default") {
|
|
60
|
-
slots.default.push(child);
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
slots[slotName] = child;
|
|
64
|
-
}
|
|
65
|
-
return slots;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* @description Creates a slot component
|
|
69
|
-
*/
|
|
70
|
-
const createSlotComponent = () => {
|
|
71
|
-
const SlotComponent = (props) => props.children;
|
|
72
|
-
SlotComponent.slotSymbol = slotComponentSymbol;
|
|
73
|
-
return SlotComponent;
|
|
74
|
-
};
|
|
75
|
-
function DefaultSlotComponent(props) {
|
|
76
|
-
return props.children;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* @description Adds a slot symbol and name to a slot component passed in
|
|
80
|
-
*/
|
|
81
|
-
const withSlotNameAndSymbol = (name, SlotComponent = DefaultSlotComponent) => {
|
|
82
|
-
SlotComponent.slotSymbol = slotComponentSymbol;
|
|
83
|
-
SlotComponent.slotName = name;
|
|
84
|
-
return SlotComponent;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
//#endregion
|
|
88
|
-
export { createSlotComponent, getSlotMap, slotComponentSymbol, withSlotNameAndSymbol };
|
|
89
|
-
//# sourceMappingURL=utils-ChjmDoRe.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils-ChjmDoRe.js","names":["slots: Record<string, TSlotComponentProps[\"children\"]> & { default: React.ReactNode[] }","ReactFragment"],"sources":["../../src/lib/utils/getSlotMap/getSlotMap.ts"],"sourcesContent":["import { toArray } from \"@zayne-labs/toolkit-core\";\nimport type { InferProps } from \"@zayne-labs/toolkit-react/utils\";\nimport {\n\ttype CallbackFn,\n\ttype EmptyObject,\n\ttype Prettify,\n\ttype UnionToIntersection,\n\ttype UnknownObject,\n\tisFunction,\n} from \"@zayne-labs/toolkit-type-helpers\";\nimport { Fragment as ReactFragment, isValidElement } from \"react\";\n\ntype GetSlotName<TSlotComponentProps extends GetSlotComponentProps> =\n\tstring extends TSlotComponentProps[\"name\"]\n\t\t? never\n\t\t: \"default\" extends TSlotComponentProps[\"name\"]\n\t\t\t? never\n\t\t\t: TSlotComponentProps[\"name\"];\n\ntype GetSpecificSlotsType<TSlotComponentProps extends GetSlotComponentProps> = {\n\t// This conditional before the remapping will prevent an Indexed Record type from showing up if the props are not passed, enhancing type safety\n\t[TName in keyof TSlotComponentProps as GetSlotName<TSlotComponentProps>]: Extract<\n\t\tTSlotComponentProps[\"children\"],\n\t\tReact.ReactNode\n\t>;\n};\n\n/**\n * Maps slot names to their corresponding children types\n */\nexport type GetSlotMapResult<TSlotComponentProps extends GetSlotComponentProps> = UnionToIntersection<\n\tGetSpecificSlotsType<TSlotComponentProps>\n> & { default: React.ReactNode[] };\n\n/**\n * Symbol used to identify SlotComponent instances\n */\nexport const slotComponentSymbol = Symbol(\"slot-component\");\n\n/**\n * @description Creates a map of named slots from React children. Returns an object mapping slot names to their children,\n * with a default slot for unmatched children.\n *\n * @example\n * ```tsx\n * import { type GetSlotComponentProps, SlotComponent } from \"@zayne-labs/toolkit-react/utils\"\n *\n * type SlotProps = GetSlotComponentProps<\"header\" | \"footer\">;\n *\n * function Parent({ children }: { children: React.ReactNode }) {\n * const slots = getSlotMap<SlotProps>(children);\n *\n * return (\n * <div>\n * <header>{slots.header}</header>\n * <main>{slots.default}</main>\n * <footer>{slots.footer}</footer>\n * </div>\n * );\n * }\n * ```\n *\n * Usage:\n * ```tsx\n * <Parent>\n * <SlotComponent name=\"header\">Header Content</SlotComponent>\n * <div>Random stuff</div>\n * <SlotComponent name=\"footer\">Footer Content</SlotComponent>\n * </Parent>\n * ```\n */\nexport const getSlotMap = <TSlotComponentProps extends GetSlotComponentProps>(\n\tchildren: React.ReactNode\n): Prettify<GetSlotMapResult<TSlotComponentProps>> => {\n\tconst slots: Record<string, TSlotComponentProps[\"children\"]> & { default: React.ReactNode[] } = {\n\t\tdefault: [],\n\t};\n\n\tconst isFragment = isValidElement<InferProps<HTMLElement>>(children) && children.type === ReactFragment;\n\n\tconst actualChildren = isFragment ? children.props.children : children;\n\n\tconst childrenArray = toArray<React.ReactNode>(actualChildren);\n\n\tfor (const child of childrenArray) {\n\t\tif (!isValidElement<TSlotComponentProps>(child) || !isFunction(child.type)) {\n\t\t\tslots.default.push(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst childType = child.type as SlotWithNameAndSymbol;\n\n\t\tconst isSlotElement =\n\t\t\tchildType.slotSymbol === slotComponentSymbol && Boolean(childType.slotName ?? child.props.name);\n\n\t\tif (!isSlotElement) {\n\t\t\tslots.default.push(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst slotName = childType.slotName ?? child.props.name;\n\n\t\tif (slotName === \"default\") {\n\t\t\tslots.default.push(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tslots[slotName] = child;\n\t}\n\n\treturn slots as GetSlotMapResult<TSlotComponentProps>;\n};\n\n/**\n * @description Produce props for the SlotComponent\n *\n * @example\n * ```ts\n * // Pattern One (slot or slots have same children type, which is just React.ReactNode by default)\n * type SlotProps = GetSlotComponentProps<\"header\" | \"content\" | \"footer\">;\n *\n * // Pattern Two (some slots can have different children type)\n * type SlotProps = GetSlotComponentProps<\"header\", React.ReactNode> | GetSlotComponentProps<\"header\", (renderProp: RenderProp) => React.ReactNode>;\n * ```\n */\nexport type GetSlotComponentProps<\n\tTName extends string = string,\n\tTChildren extends CallbackFn<never, React.ReactNode> | React.ReactNode =\n\t\t| CallbackFn<never, React.ReactNode>\n\t\t| React.ReactNode,\n> = {\n\tchildren: TChildren;\n\t/**\n\t * Name of the slot where content should be rendered\n\t */\n\tname: TName;\n};\n\n/**\n * @description Creates a slot component\n */\nexport const createSlotComponent = <TSlotComponentProps extends GetSlotComponentProps>() => {\n\tconst SlotComponent = (props: TSlotComponentProps) => props.children as React.ReactNode;\n\n\tSlotComponent.slotSymbol = slotComponentSymbol;\n\n\treturn SlotComponent;\n};\n\ntype SlotWithNameAndSymbol<\n\tTSlotComponentProps extends GetSlotComponentProps = GetSlotComponentProps,\n\tTOtherProps extends UnknownObject = EmptyObject,\n> = {\n\t(props: Pick<TSlotComponentProps, \"children\"> & TOtherProps): React.ReactNode;\n\treadonly slotName?: TSlotComponentProps[\"name\"];\n\treadonly slotSymbol?: symbol;\n};\n\nfunction DefaultSlotComponent(props: Pick<GetSlotComponentProps, \"children\">): React.ReactNode {\n\treturn props.children as React.ReactNode;\n}\n\n/**\n * @description Adds a slot symbol and name to a slot component passed in\n */\nexport const withSlotNameAndSymbol = <\n\tTSlotComponentProps extends GetSlotComponentProps,\n\tTOtherProps extends UnknownObject = EmptyObject,\n>(\n\tname: TSlotComponentProps[\"name\"],\n\tSlotComponent: SlotWithNameAndSymbol<TSlotComponentProps, TOtherProps> = DefaultSlotComponent\n) => {\n\t/* eslint-disable no-param-reassign -- This is necessary */\n\t// @ts-expect-error -- This is necessary for the time being, to prevent type errors and accidental overrides on consumer side\n\tSlotComponent.slotSymbol = slotComponentSymbol;\n\t// @ts-expect-error -- This is necessary for the time being, to prevent type errors and accidental overrides on consumer side\n\tSlotComponent.slotName = name;\n\n\t/* eslint-enable no-param-reassign -- This is necessary */\n\n\treturn SlotComponent;\n};\n"],"mappings":";;;;;;;;AAqCA,MAAa,sBAAsB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkC1C,MAAa,cACZ,aACqD;CACrD,MAAMA,QAA0F,EAC/F,SAAS,EAAE,EACX;CAED,MAAM,aAAa,eAAwC,aAAa,SAAS,SAASC;CAE1F,MAAM,iBAAiB,aAAa,SAAS,MAAM,WAAW;CAE9D,MAAM,gBAAgB,QAAyB;AAE/C,MAAK,MAAM,SAAS,eAAe;AAClC,MAAI,CAAC,eAAoC,UAAU,CAAC,WAAW,MAAM,OAAO;AAC3E,SAAM,QAAQ,KAAK;AACnB;EACA;EAED,MAAM,YAAY,MAAM;EAExB,MAAM,gBACL,UAAU,eAAe,uBAAuB,QAAQ,UAAU,YAAY,MAAM,MAAM;AAE3F,MAAI,CAAC,eAAe;AACnB,SAAM,QAAQ,KAAK;AACnB;EACA;EAED,MAAM,WAAW,UAAU,YAAY,MAAM,MAAM;AAEnD,MAAI,aAAa,WAAW;AAC3B,SAAM,QAAQ,KAAK;AACnB;EACA;AAED,QAAM,YAAY;CAClB;AAED,QAAO;AACP;;;;AA8BD,MAAa,4BAA+E;CAC3F,MAAM,iBAAiB,UAA+B,MAAM;AAE5D,eAAc,aAAa;AAE3B,QAAO;AACP;AAWD,SAAS,qBAAqB,OAAiE;AAC9F,QAAO,MAAM;AACb;;;;AAKD,MAAa,yBAIZ,MACA,gBAAyE,yBACrE;AAGJ,eAAc,aAAa;AAE3B,eAAc,WAAW;AAIzB,QAAO;AACP"}
|
|
File without changes
|