@zayne-labs/ui-react 0.9.16 → 0.9.18
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/esm/await-Fe4LFRKd.js +89 -0
- package/dist/esm/await-Fe4LFRKd.js.map +1 -0
- package/dist/esm/card-DRjs-vtv.js +54 -0
- package/dist/esm/card-DRjs-vtv.js.map +1 -0
- package/dist/esm/carousel-Dznupnx8.js +270 -0
- package/dist/esm/carousel-Dznupnx8.js.map +1 -0
- package/dist/esm/chunk-Cl8Af3a2.js +11 -0
- package/dist/esm/cn-_FbtIrlZ.js +8 -0
- package/dist/esm/cn-_FbtIrlZ.js.map +1 -0
- package/dist/esm/common-BYWy8Q78.js +0 -0
- package/dist/esm/components/common/await/index.d.ts +6 -14
- package/dist/esm/components/common/await/index.js +10 -8
- package/dist/esm/components/common/error-boundary/index.d.ts +2 -17
- package/dist/esm/components/common/error-boundary/index.js +6 -4
- package/dist/esm/components/common/for/index.d.ts +2 -10
- package/dist/esm/components/common/for/index.js +3 -4
- package/dist/esm/components/common/index.d.ts +11 -13
- package/dist/esm/components/common/index.js +13 -14
- package/dist/esm/components/common/show/index.d.ts +2 -26
- package/dist/esm/components/common/show/index.js +7 -5
- package/dist/esm/components/common/slot/index.d.ts +2 -12
- package/dist/esm/components/common/slot/index.js +3 -4
- package/dist/esm/components/common/suspense-with-boundary/index.d.ts +3 -11
- package/dist/esm/components/common/suspense-with-boundary/index.js +4 -5
- package/dist/esm/components/common/switch/index.d.ts +2 -25
- package/dist/esm/components/common/switch/index.js +7 -5
- package/dist/esm/components/common/teleport/index.d.ts +2 -12
- package/dist/esm/components/common/teleport/index.js +3 -4
- package/dist/esm/components/ui/card/index.d.ts +2 -17
- package/dist/esm/components/ui/card/index.js +5 -6
- package/dist/esm/components/ui/carousel/index.d.ts +2 -95
- package/dist/esm/components/ui/carousel/index.js +18 -16
- package/dist/esm/components/ui/drag-scroll/index.d.ts +2 -21
- package/dist/esm/components/ui/drag-scroll/index.js +4 -5
- package/dist/esm/components/ui/drop-zone/index.d.ts +3 -11
- package/dist/esm/components/ui/drop-zone/index.js +18 -16
- package/dist/esm/components/ui/form/index.d.ts +2 -228
- package/dist/esm/components/ui/form/index.js +10 -8
- package/dist/esm/components/ui/index.d.ts +7 -11
- package/dist/esm/components/ui/index.js +19 -20
- package/dist/esm/drag-scroll-BLjij7aI.js +111 -0
- package/dist/esm/drag-scroll-BLjij7aI.js.map +1 -0
- package/dist/esm/drop-zone-_YK9C3Xj.js +313 -0
- package/dist/esm/drop-zone-_YK9C3Xj.js.map +1 -0
- package/dist/esm/error-boundary-B3ycUZ1t.js +126 -0
- package/dist/esm/error-boundary-B3ycUZ1t.js.map +1 -0
- package/dist/esm/for-aTw1TgJo.js +42 -0
- package/dist/esm/for-aTw1TgJo.js.map +1 -0
- package/dist/esm/form-DytCfL6R.js +590 -0
- package/dist/esm/form-DytCfL6R.js.map +1 -0
- package/dist/esm/getSlot-BIcGgBwN.js +85 -0
- package/dist/esm/getSlot-BIcGgBwN.js.map +1 -0
- package/dist/esm/{getSlotMap-DTkxtGhd.d.ts → getSlotMap-DA_uhXqU.d.ts} +17 -16
- package/dist/esm/index--1COprHP.d.ts +32 -0
- package/dist/esm/index-1UCPJf7B.d.ts +19 -0
- package/dist/esm/index-ASoFjmZ6.d.ts +196 -0
- package/dist/esm/index-BC0r1cBF.d.ts +104 -0
- package/dist/esm/index-BSJ30pGj.d.ts +68 -0
- package/dist/esm/{for-BH5FhFuV.d.ts → index-BhpBx8dH.d.ts} +14 -6
- package/dist/esm/index-BuSQsDCX.d.ts +22 -0
- package/dist/esm/index-C0XZoIZD.d.ts +35 -0
- package/dist/esm/index-CTZr4PTO.d.ts +24 -0
- package/dist/esm/index-CqlM1M0j.d.ts +14 -0
- package/dist/esm/index-D-j2Cn1J.d.ts +61 -0
- package/dist/esm/index-DQ1yFGd2.d.ts +229 -0
- package/dist/esm/index-DnaUCh8d.d.ts +15 -0
- package/dist/esm/index-TBkPiipk.d.ts +49 -0
- package/dist/esm/lib/utils/index.d.ts +3 -61
- package/dist/esm/lib/utils/index.js +4 -5
- package/dist/esm/show-BgYrfIxJ.js +41 -0
- package/dist/esm/show-BgYrfIxJ.js.map +1 -0
- package/dist/esm/slot-RXTKo4L7.js +58 -0
- package/dist/esm/slot-RXTKo4L7.js.map +1 -0
- package/dist/esm/suspense-with-boundary-TrQxYRG6.js +21 -0
- package/dist/esm/suspense-with-boundary-TrQxYRG6.js.map +1 -0
- package/dist/esm/switch-PF5xTJfr.js +42 -0
- package/dist/esm/switch-PF5xTJfr.js.map +1 -0
- package/dist/esm/teleport-dlSjWj_t.js +32 -0
- package/dist/esm/teleport-dlSjWj_t.js.map +1 -0
- package/dist/esm/utils-D4YNWj2X.js +89 -0
- package/dist/esm/utils-D4YNWj2X.js.map +1 -0
- package/package.json +4 -3
- package/dist/esm/await-parts-BJ6C-y1f.d.ts +0 -36
- package/dist/esm/chunk-6QJYHPBL.js +0 -45
- package/dist/esm/chunk-6QJYHPBL.js.map +0 -1
- package/dist/esm/chunk-BJ7WR4XW.js +0 -274
- package/dist/esm/chunk-BJ7WR4XW.js.map +0 -1
- package/dist/esm/chunk-CWUEUCR5.js +0 -3
- package/dist/esm/chunk-CWUEUCR5.js.map +0 -1
- package/dist/esm/chunk-D6QZA3UT.js +0 -56
- package/dist/esm/chunk-D6QZA3UT.js.map +0 -1
- package/dist/esm/chunk-EYWTW54R.js +0 -42
- package/dist/esm/chunk-EYWTW54R.js.map +0 -1
- package/dist/esm/chunk-G5BNZM66.js +0 -32
- package/dist/esm/chunk-G5BNZM66.js.map +0 -1
- package/dist/esm/chunk-JC52CA2O.js +0 -113
- package/dist/esm/chunk-JC52CA2O.js.map +0 -1
- package/dist/esm/chunk-M7YXNGT6.js +0 -48
- package/dist/esm/chunk-M7YXNGT6.js.map +0 -1
- package/dist/esm/chunk-MRYXZN2P.js +0 -336
- package/dist/esm/chunk-MRYXZN2P.js.map +0 -1
- package/dist/esm/chunk-MT2MQDK2.js +0 -13
- package/dist/esm/chunk-MT2MQDK2.js.map +0 -1
- package/dist/esm/chunk-N4274N5K.js +0 -50
- package/dist/esm/chunk-N4274N5K.js.map +0 -1
- package/dist/esm/chunk-NXZZXJRH.js +0 -41
- package/dist/esm/chunk-NXZZXJRH.js.map +0 -1
- package/dist/esm/chunk-OHG7GB7O.js +0 -8
- package/dist/esm/chunk-OHG7GB7O.js.map +0 -1
- package/dist/esm/chunk-P5QP73HG.js +0 -626
- package/dist/esm/chunk-P5QP73HG.js.map +0 -1
- package/dist/esm/chunk-PZ5AY32C.js +0 -9
- package/dist/esm/chunk-PZ5AY32C.js.map +0 -1
- package/dist/esm/chunk-V5ZPMMIH.js +0 -121
- package/dist/esm/chunk-V5ZPMMIH.js.map +0 -1
- package/dist/esm/chunk-YO5LJ7ZJ.js +0 -74
- package/dist/esm/chunk-YO5LJ7ZJ.js.map +0 -1
- package/dist/esm/chunk-YSDKXBU7.js +0 -68
- package/dist/esm/chunk-YSDKXBU7.js.map +0 -1
- package/dist/esm/components/common/await/index.js.map +0 -1
- package/dist/esm/components/common/error-boundary/index.js.map +0 -1
- package/dist/esm/components/common/for/index.js.map +0 -1
- package/dist/esm/components/common/index.js.map +0 -1
- package/dist/esm/components/common/show/index.js.map +0 -1
- package/dist/esm/components/common/slot/index.js.map +0 -1
- package/dist/esm/components/common/suspense-with-boundary/index.js.map +0 -1
- package/dist/esm/components/common/switch/index.js.map +0 -1
- package/dist/esm/components/common/teleport/index.js.map +0 -1
- package/dist/esm/components/ui/card/index.js.map +0 -1
- package/dist/esm/components/ui/carousel/index.js.map +0 -1
- package/dist/esm/components/ui/drag-scroll/index.js.map +0 -1
- package/dist/esm/components/ui/drop-zone/index.js.map +0 -1
- package/dist/esm/components/ui/form/index.js.map +0 -1
- package/dist/esm/components/ui/index.js.map +0 -1
- package/dist/esm/drop-zone-parts-CvseSoXA.d.ts +0 -186
- package/dist/esm/error-boundary-BD0X61Sg.d.ts +0 -28
- package/dist/esm/lib/utils/index.js.map +0 -1
- package/dist/esm/types-mdfDDNrr.d.ts +0 -25
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
|
+
import { getMultipleSlots$1 as getMultipleSlots } from "./getSlot-BIcGgBwN.js";
|
|
3
|
+
import "react";
|
|
4
|
+
import { assert, isFunction } from "@zayne-labs/toolkit-type-helpers";
|
|
5
|
+
|
|
6
|
+
//#region src/components/common/show/show.tsx
|
|
7
|
+
function ShowRoot(props) {
|
|
8
|
+
const { children, fallback = null, when } = props;
|
|
9
|
+
const resolvedChildren = isFunction(children) ? children(when) : children;
|
|
10
|
+
const { regularChildren, slots: [contentSlot, fallBackSlot] } = getMultipleSlots(resolvedChildren, [ShowContent, ShowFallback], {
|
|
11
|
+
errorMessage: ["Only one <Show.Content> component is allowed", "Only one <Show.Fallback> or <Show.OtherWise> component is allowed"],
|
|
12
|
+
throwOnMultipleSlotMatch: true
|
|
13
|
+
});
|
|
14
|
+
if (!when) {
|
|
15
|
+
assert(!(fallBackSlot && fallback), "The fallback prop and <Show.Fallback> cannot be used at the same time.");
|
|
16
|
+
return fallBackSlot ?? fallback;
|
|
17
|
+
}
|
|
18
|
+
return contentSlot ?? regularChildren;
|
|
19
|
+
}
|
|
20
|
+
function ShowContent({ children }) {
|
|
21
|
+
return children;
|
|
22
|
+
}
|
|
23
|
+
ShowContent.slotSymbol = Symbol("show-content");
|
|
24
|
+
function ShowFallback({ children }) {
|
|
25
|
+
return children;
|
|
26
|
+
}
|
|
27
|
+
ShowFallback.slotSymbol = Symbol("show-fallback");
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/components/common/show/show-parts.ts
|
|
31
|
+
var show_parts_exports = {};
|
|
32
|
+
__export(show_parts_exports, {
|
|
33
|
+
Content: () => ShowContent,
|
|
34
|
+
Fallback: () => ShowFallback,
|
|
35
|
+
Otherwise: () => ShowFallback,
|
|
36
|
+
Root: () => ShowRoot
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { ShowContent, ShowFallback, ShowRoot, show_parts_exports };
|
|
41
|
+
//# sourceMappingURL=show-BgYrfIxJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"show-BgYrfIxJ.js","names":["props: ShowProps<TWhen>"],"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,SAAgBA,OAAyB;CACxD,MAAM,EAAE,UAAU,WAAW,MAAM,MAAM,GAAG;CAE5C,MAAM,mBAAmB,WAAW,SAAS,GAAG,SAAS,KAAc,GAAG;CAE1E,MAAM,EACL,iBACA,OAAO,CAAC,aAAa,aAAa,EAClC,GAAG,iBAAiB,kBAAkB,CAAC,aAAa,YAAa,GAAE;EACnE,cAAc,CACb,gDACA,mEACA;EACD,0BAA0B;CAC1B,EAAC;AAEF,MAAK,MAAM;AACV,WACG,gBAAgB,WAClB,yEACA;AAED,SAAO,gBAAgB;CACvB;AAED,QAAO,eAAe;AACtB;AAED,SAAgB,YAAY,EAAE,UAAyC,EAAE;AACxE,QAAO;AACP;AACD,YAAY,aAAa,OAAO,eAAe;AAE/C,SAAgB,aAAa,EAAE,UAAyC,EAAE;AACzE,QAAO;AACP;AACD,aAAa,aAAa,OAAO,gBAAgB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
|
+
import { Children, Fragment, cloneElement, isValidElement } from "react";
|
|
3
|
+
import { isArray } from "@zayne-labs/toolkit-type-helpers";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { composeRefs, mergeProps } from "@zayne-labs/toolkit-react/utils";
|
|
6
|
+
|
|
7
|
+
//#region src/components/common/slot/slot.tsx
|
|
8
|
+
function SlotSlottable({ children }) {
|
|
9
|
+
return children;
|
|
10
|
+
}
|
|
11
|
+
const isSlottable = (child) => {
|
|
12
|
+
return isValidElement(child) && child.type === SlotSlottable;
|
|
13
|
+
};
|
|
14
|
+
function SlotRoot(props) {
|
|
15
|
+
const { children,...restOfSlotProps } = props;
|
|
16
|
+
const childrenArray = isArray(children) ? children : [children];
|
|
17
|
+
const slottable = childrenArray.find((element) => isSlottable(element));
|
|
18
|
+
if (slottable) {
|
|
19
|
+
const newElement = slottable.props.children;
|
|
20
|
+
if (Children.count(newElement) > 1) return Children.only(null);
|
|
21
|
+
const newElementChildren = childrenArray.map((child) => {
|
|
22
|
+
if (child === slottable) return isValidElement(newElement) && newElement.props.children;
|
|
23
|
+
return child;
|
|
24
|
+
});
|
|
25
|
+
return /* @__PURE__ */ jsx(SlotClone, {
|
|
26
|
+
...restOfSlotProps,
|
|
27
|
+
children: isValidElement(newElement) && cloneElement(newElement, void 0, newElementChildren)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return /* @__PURE__ */ jsx(SlotClone, {
|
|
31
|
+
...restOfSlotProps,
|
|
32
|
+
children
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function SlotClone(props) {
|
|
36
|
+
const { children, ref: forwardedRef,...restOfSlotProps } = props;
|
|
37
|
+
const resolvedChildren = isArray(children) && children.length === 1 ? children[0] : children;
|
|
38
|
+
if (!isValidElement(resolvedChildren)) return Children.count(resolvedChildren) > 1 ? Children.only(null) : null;
|
|
39
|
+
const childRef = resolvedChildren.props.ref ?? resolvedChildren.ref;
|
|
40
|
+
const mergedRef = forwardedRef ? composeRefs(forwardedRef, childRef) : childRef;
|
|
41
|
+
const clonedProps = {
|
|
42
|
+
...mergeProps(restOfSlotProps, resolvedChildren.props),
|
|
43
|
+
...resolvedChildren.type !== Fragment && { ref: mergedRef }
|
|
44
|
+
};
|
|
45
|
+
return cloneElement(resolvedChildren, clonedProps);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/components/common/slot/slot-parts.ts
|
|
50
|
+
var slot_parts_exports = {};
|
|
51
|
+
__export(slot_parts_exports, {
|
|
52
|
+
Root: () => SlotRoot,
|
|
53
|
+
Slottable: () => SlotSlottable
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { SlotRoot, SlotSlottable, slot_parts_exports };
|
|
58
|
+
//# sourceMappingURL=slot-RXTKo4L7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot-RXTKo4L7.js","names":["child: React.ReactNode","props: SlotProps","props: SlotCloneProps","ReactFragment"],"sources":["../../src/components/common/slot/slot.tsx","../../src/components/common/slot/slot-parts.ts"],"sourcesContent":["import * as React from \"react\";\n\nimport { type InferProps, composeRefs, mergeProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { Children, Fragment as ReactFragment, cloneElement, isValidElement } from \"react\";\n\ntype SlotProps = InferProps<HTMLElement>;\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * ----------------------------------------------------------------------------------------------- */\n\nexport function SlotSlottable({ children }: Pick<SlotProps, \"children\">) {\n\treturn children;\n}\n\nconst isSlottable = (child: React.ReactNode): child is React.ReactElement => {\n\treturn isValidElement(child) && child.type === SlotSlottable;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * ----------------------------------------------------------------------------------------------- */\n\nexport function SlotRoot(props: SlotProps) {\n\tconst { children, ...restOfSlotProps } = props;\n\n\tconst childrenArray = isArray<React.ReactNode>(children) ? children : [children];\n\tconst slottable = childrenArray.find((element) => isSlottable(element));\n\n\tif (slottable) {\n\t\t// == The new element to render is the one passed as a child of `Slottable`\n\t\tconst newElement = (slottable.props as SlotProps).children;\n\n\t\tif (Children.count(newElement) > 1) {\n\t\t\treturn Children.only(null);\n\t\t}\n\n\t\tconst newElementChildren = childrenArray.map((child) => {\n\t\t\tif (child === slottable) {\n\t\t\t\t// == Because the new element will be the one rendered, we are only interested in grabbing its children (`newElement.props.children`)\n\t\t\t\treturn isValidElement<SlotProps>(newElement) && newElement.props.children;\n\t\t\t}\n\n\t\t\treturn child;\n\t\t});\n\n\t\treturn (\n\t\t\t<SlotClone {...restOfSlotProps}>\n\t\t\t\t{isValidElement(newElement) && cloneElement(newElement, undefined, newElementChildren)}\n\t\t\t</SlotClone>\n\t\t);\n\t}\n\n\treturn <SlotClone {...restOfSlotProps}>{children}</SlotClone>;\n}\n\ntype SlotCloneProps = {\n\tchildren: React.ReactNode;\n\tref?: React.RefObject<HTMLElement>;\n};\n\ntype UnknownProps = Record<string, unknown>;\n\nfunction SlotClone(props: SlotCloneProps) {\n\tconst { children, ref: forwardedRef, ...restOfSlotProps } = props;\n\n\tconst resolvedChildren = isArray(children) && children.length === 1 ? children[0] : children;\n\n\tif (!isValidElement<UnknownProps>(resolvedChildren)) {\n\t\treturn Children.count(resolvedChildren) > 1 ? Children.only(null) : null;\n\t}\n\n\tconst childRef = (resolvedChildren.props.ref\n\t\t?? (resolvedChildren as unknown as UnknownProps).ref) as React.Ref<HTMLElement>;\n\n\tconst mergedRef = forwardedRef ? composeRefs(forwardedRef, childRef) : childRef;\n\n\tconst clonedProps = {\n\t\t...mergeProps(restOfSlotProps, resolvedChildren.props),\n\t\t...(resolvedChildren.type !== ReactFragment && { ref: mergedRef }),\n\t};\n\n\treturn cloneElement(resolvedChildren, clonedProps);\n}\n","export { SlotRoot as Root, SlotSlottable as Slottable } from \"./slot\";\n"],"mappings":";;;;;;;AAYA,SAAgB,cAAc,EAAE,UAAuC,EAAE;AACxE,QAAO;AACP;AAED,MAAM,cAAc,CAACA,UAAwD;AAC5E,QAAO,eAAe,MAAM,IAAI,MAAM,SAAS;AAC/C;AAMD,SAAgB,SAASC,OAAkB;CAC1C,MAAM,EAAE,SAAU,GAAG,iBAAiB,GAAG;CAEzC,MAAM,gBAAgB,QAAyB,SAAS,GAAG,WAAW,CAAC,QAAS;CAChF,MAAM,YAAY,cAAc,KAAK,CAAC,YAAY,YAAY,QAAQ,CAAC;AAEvE,KAAI,WAAW;EAEd,MAAM,aAAc,UAAU,MAAoB;AAElD,MAAI,SAAS,MAAM,WAAW,GAAG,EAChC,QAAO,SAAS,KAAK,KAAK;EAG3B,MAAM,qBAAqB,cAAc,IAAI,CAAC,UAAU;AACvD,OAAI,UAAU,UAEb,QAAO,eAA0B,WAAW,IAAI,WAAW,MAAM;AAGlE,UAAO;EACP,EAAC;AAEF,yBACC,IAAC;GAAU,GAAI;aACb,eAAe,WAAW,IAAI,aAAa,oBAAuB,mBAAmB;IAC3E;CAEb;AAED,wBAAO,IAAC;EAAU,GAAI;EAAkB;GAAqB;AAC7D;AASD,SAAS,UAAUC,OAAuB;CACzC,MAAM,EAAE,UAAU,KAAK,aAAc,GAAG,iBAAiB,GAAG;CAE5D,MAAM,mBAAmB,QAAQ,SAAS,IAAI,SAAS,WAAW,IAAI,SAAS,KAAK;AAEpF,MAAK,eAA6B,iBAAiB,CAClD,QAAO,SAAS,MAAM,iBAAiB,GAAG,IAAI,SAAS,KAAK,KAAK,GAAG;CAGrE,MAAM,WAAY,iBAAiB,MAAM,OACpC,iBAA6C;CAElD,MAAM,YAAY,eAAe,YAAY,cAAc,SAAS,GAAG;CAEvE,MAAM,cAAc;EACnB,GAAG,WAAW,iBAAiB,iBAAiB,MAAM;EACtD,GAAI,iBAAiB,SAASC,YAAiB,EAAE,KAAK,UAAW;CACjE;AAED,QAAO,aAAa,kBAAkB,YAAY;AAClD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ErrorBoundary } from "./error-boundary-B3ycUZ1t.js";
|
|
2
|
+
import { Suspense } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/components/common/suspense-with-boundary/suspense-with-boundary.tsx
|
|
6
|
+
function SuspenseWithBoundary(props) {
|
|
7
|
+
const { children, errorFallback, fallback } = props;
|
|
8
|
+
const errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };
|
|
9
|
+
const suspenseProps = Boolean(fallback) && { fallback };
|
|
10
|
+
return /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
11
|
+
...errorBoundaryProps,
|
|
12
|
+
children: /* @__PURE__ */ jsx(Suspense, {
|
|
13
|
+
...suspenseProps,
|
|
14
|
+
children
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { SuspenseWithBoundary };
|
|
21
|
+
//# sourceMappingURL=suspense-with-boundary-TrQxYRG6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspense-with-boundary-TrQxYRG6.js","names":["props: SuspenseWithBoundaryProps"],"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,qBAAqBA,OAAkC;CACtE,MAAM,EAAE,UAAU,eAAe,UAAU,GAAG;CAE9C,MAAM,qBAAqB,QAAQ,cAAc,IAAI,EAAE,UAAU,cAAe;CAChF,MAAM,gBAAgB,QAAQ,SAAS,IAAI,EAAE,SAAU;AAEvD,wBACC,IAAC;EAAc,GAAI;4BAClB,IAAC;GAAS,GAAI;GAAgB;IAAoB;GACnC;AAEjB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
|
+
import { getRegularChildren$1 as getRegularChildren, getSingleSlot$1 as getSingleSlot } from "./getSlot-BIcGgBwN.js";
|
|
3
|
+
import "react";
|
|
4
|
+
import { isFunction } from "@zayne-labs/toolkit-type-helpers";
|
|
5
|
+
|
|
6
|
+
//#region src/components/common/switch/switch.tsx
|
|
7
|
+
const defaultValueSymbol = Symbol("default-value");
|
|
8
|
+
function SwitchRoot(props) {
|
|
9
|
+
const { children, value = defaultValueSymbol } = props;
|
|
10
|
+
const defaultCase = getSingleSlot(children, SwitchDefault, {
|
|
11
|
+
errorMessage: "Only one <Switch.Default> component is allowed",
|
|
12
|
+
throwOnMultipleSlotMatch: true
|
|
13
|
+
});
|
|
14
|
+
const childrenCasesArray = getRegularChildren(children, SwitchDefault);
|
|
15
|
+
const matchedCase = childrenCasesArray.find((child) => {
|
|
16
|
+
if (value === defaultValueSymbol) return Boolean(child.props.when);
|
|
17
|
+
return child.props.when === value;
|
|
18
|
+
});
|
|
19
|
+
return matchedCase ?? defaultCase;
|
|
20
|
+
}
|
|
21
|
+
function SwitchMatch(props) {
|
|
22
|
+
const { children, when } = props;
|
|
23
|
+
const resolvedChildren = isFunction(children) ? children(when) : children;
|
|
24
|
+
return resolvedChildren;
|
|
25
|
+
}
|
|
26
|
+
function SwitchDefault({ children }) {
|
|
27
|
+
return children;
|
|
28
|
+
}
|
|
29
|
+
SwitchDefault.slotSymbol = Symbol("switch-default");
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/components/common/switch/switch-parts.ts
|
|
33
|
+
var switch_parts_exports = {};
|
|
34
|
+
__export(switch_parts_exports, {
|
|
35
|
+
Default: () => SwitchDefault,
|
|
36
|
+
Match: () => SwitchMatch,
|
|
37
|
+
Root: () => SwitchRoot
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { SwitchDefault, SwitchMatch, SwitchRoot, switch_parts_exports };
|
|
42
|
+
//# sourceMappingURL=switch-PF5xTJfr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch-PF5xTJfr.js","names":["props: SwitchProps","props: SwitchMatchProps<TWhen>"],"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,gBAAgB;AAElD,SAAgB,WAAWA,OAAoB;CAC9C,MAAM,EAAE,UAAU,QAAQ,oBAAoB,GAAG;CAEjD,MAAM,cAAc,cAAc,UAAU,eAAe;EAC1D,cAAc;EACd,0BAA0B;CAC1B,EAAC;CAEF,MAAM,qBAAqB,mBAAmB,UAAU,cAAc;CAEtE,MAAM,cAAc,mBAAmB,KAAK,CAAC,UAAU;AAEtD,MAAI,UAAU,mBACb,QAAO,QAAQ,MAAM,MAAM,KAAK;AAIjC,SAAO,MAAM,MAAM,SAAS;CAC5B,EAAC;AAEF,QAAO,eAAe;AACtB;AAOD,SAAgB,YAAmBC,OAAgC;CAClE,MAAM,EAAE,UAAU,MAAM,GAAG;CAE3B,MAAM,mBAAmB,WAAW,SAAS,GAAG,SAAS,KAAc,GAAG;AAE1E,QAAO;AACP;AAED,SAAgB,cAAc,EAAE,UAAyC,EAAE;AAC1E,QAAO;AACP;AACD,cAAc,aAAa,OAAO,iBAAiB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { isString } from "@zayne-labs/toolkit-type-helpers";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
|
|
5
|
+
//#region src/components/common/teleport/teleport.tsx
|
|
6
|
+
function Teleport(props) {
|
|
7
|
+
const { children, insertPosition, to } = props;
|
|
8
|
+
const [portalContainer, setPortalContainer] = useState(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!to) return;
|
|
11
|
+
if (insertPosition) return;
|
|
12
|
+
const destination = isString(to) ? document.querySelector(to) : to;
|
|
13
|
+
destination && setPortalContainer(destination);
|
|
14
|
+
}, [to, insertPosition]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!to) return;
|
|
17
|
+
if (!insertPosition) return;
|
|
18
|
+
const destination = isString(to) ? document.querySelector(to) : to;
|
|
19
|
+
const tempWrapper = document.createElement("div");
|
|
20
|
+
tempWrapper.style.display = "contents";
|
|
21
|
+
destination?.insertAdjacentElement(insertPosition, tempWrapper);
|
|
22
|
+
setPortalContainer(tempWrapper);
|
|
23
|
+
return () => {
|
|
24
|
+
tempWrapper.remove();
|
|
25
|
+
};
|
|
26
|
+
}, [to, insertPosition]);
|
|
27
|
+
return portalContainer && createPortal(children, portalContainer);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { Teleport };
|
|
32
|
+
//# sourceMappingURL=teleport-dlSjWj_t.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"teleport-dlSjWj_t.js","names":["props: PortalProps"],"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,SAASA,OAAoB;CACrC,MAAM,EAAE,UAAU,gBAAgB,IAAI,GAAG;CAEzC,MAAM,CAAC,iBAAiB,mBAAmB,GAAG,SAA6B,KAAK;AAIhF,WAAU,MAAM;AACf,OAAK,GAAI;AAET,MAAI,eAAgB;EAEpB,MAAM,cAAc,SAAS,GAAG,GAAG,SAAS,cAA2B,GAAG,GAAG;AAE7E,iBAAe,mBAAmB,YAAY;CAC9C,GAAE,CAAC,IAAI,cAAe,EAAC;AAExB,WAAU,MAAM;AACf,OAAK,GAAI;AAET,OAAK,eAAgB;EAErB,MAAM,cAAc,SAAS,GAAG,GAAG,SAAS,cAA2B,GAAG,GAAG;EAE7E,MAAM,cAAc,SAAS,cAAc,MAAM;AACjD,cAAY,MAAM,UAAU;AAE5B,eAAa,sBAAsB,gBAAgB,YAAY;AAE/D,qBAAmB,YAAY;AAE/B,SAAO,MAAM;AACZ,eAAY,QAAQ;EACpB;CACD,GAAE,CAAC,IAAI,cAAe,EAAC;AAIxB,QAAO,mBAAmB,aAAa,UAAU,gBAAgB;AACjE"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Fragment, isValidElement } from "react";
|
|
2
|
+
import { toArray } from "@zayne-labs/toolkit-core";
|
|
3
|
+
import { isFunction } from "@zayne-labs/toolkit-type-helpers";
|
|
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-D4YNWj2X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-D4YNWj2X.js","names":["children: React.ReactNode","slots: Record<string, TSlotComponentProps[\"children\"]> & { default: React.ReactNode[] }","ReactFragment","props: TSlotComponentProps","props: Pick<GetSlotComponentProps, \"children\">","name: TSlotComponentProps[\"name\"]","SlotComponent: SlotWithNameAndSymbol<TSlotComponentProps, TOtherProps>"],"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,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkC3D,MAAa,aAAa,CACzBA,aACqD;CACrD,MAAMC,QAA0F,EAC/F,SAAS,CAAE,EACX;CAED,MAAM,aAAa,eAAwC,SAAS,IAAI,SAAS,SAASC;CAE1F,MAAM,iBAAiB,aAAa,SAAS,MAAM,WAAW;CAE9D,MAAM,gBAAgB,QAAyB,eAAe;AAE9D,MAAK,MAAM,SAAS,eAAe;AAClC,OAAK,eAAoC,MAAM,KAAK,WAAW,MAAM,KAAK,EAAE;AAC3E,SAAM,QAAQ,KAAK,MAAM;AACzB;EACA;EAED,MAAM,YAAY,MAAM;EAExB,MAAM,gBACL,UAAU,eAAe,uBAAuB,QAAQ,UAAU,YAAY,MAAM,MAAM,KAAK;AAEhG,OAAK,eAAe;AACnB,SAAM,QAAQ,KAAK,MAAM;AACzB;EACA;EAED,MAAM,WAAW,UAAU,YAAY,MAAM,MAAM;AAEnD,MAAI,aAAa,WAAW;AAC3B,SAAM,QAAQ,KAAK,MAAM;AACzB;EACA;AAED,QAAM,YAAY;CAClB;AAED,QAAO;AACP;;;;AA8BD,MAAa,sBAAsB,MAAyD;CAC3F,MAAM,gBAAgB,CAACC,UAA+B,MAAM;AAE5D,eAAc,aAAa;AAE3B,QAAO;AACP;AAWD,SAAS,qBAAqBC,OAAiE;AAC9F,QAAO,MAAM;AACb;;;;AAKD,MAAa,wBAAwB,CAIpCC,MACAC,gBAAyE,yBACrE;AAGJ,eAAc,aAAa;AAE3B,eAAc,WAAW;AAIzB,QAAO;AACP"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/ui-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.18",
|
|
5
5
|
"description": "A composable UI/UI-utilities components library. ",
|
|
6
6
|
"author": "Ryan Zayne",
|
|
7
7
|
"license": "MIT",
|
|
@@ -75,7 +75,8 @@
|
|
|
75
75
|
"size-limit": "11.2.0",
|
|
76
76
|
"tailwind-merge": "3.3.0",
|
|
77
77
|
"tailwindcss": "^4.1.7",
|
|
78
|
-
"
|
|
78
|
+
"tsdown": "^0.12.3",
|
|
79
|
+
"tsup": "^8.5.0",
|
|
79
80
|
"typescript": "5.8.3",
|
|
80
81
|
"zustand": "5.0.5"
|
|
81
82
|
},
|
|
@@ -95,7 +96,7 @@
|
|
|
95
96
|
}
|
|
96
97
|
],
|
|
97
98
|
"scripts": {
|
|
98
|
-
"build": "concurrently '
|
|
99
|
+
"build": "concurrently 'pnpm:build:tailwind' 'tsdown'",
|
|
99
100
|
"build:dev": "cross-env NODE_ENV=development tsup",
|
|
100
101
|
"build:tailwind": "tailwindcss -i css/style.css -o ./dist/style.css",
|
|
101
102
|
"build:test": "concurrently --prefix-colors \"yellow.bold,#7da4f8.bold,magenta\" --names PUBLINT,TSUP 'pnpm:lint:publint' 'pnpm:build:dev'",
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { a as GetSlotComponentProps } from './getSlotMap-DTkxtGhd.js';
|
|
3
|
-
import { E as ErrorBoundaryProps } from './types-mdfDDNrr.js';
|
|
4
|
-
import { SuspenseWithBoundaryProps } from './components/common/suspense-with-boundary/index.js';
|
|
5
|
-
|
|
6
|
-
type RenderPropFn<TValue> = (result: TValue) => React.ReactNode;
|
|
7
|
-
type ChildrenType<TValue> = React.ReactNode | RenderPropFn<TValue>;
|
|
8
|
-
type AwaitRootProps<TValue> = Pick<SuspenseWithBoundaryProps, "errorFallback" | "fallback"> & {
|
|
9
|
-
asChild?: boolean;
|
|
10
|
-
children: ChildrenType<TValue>;
|
|
11
|
-
promise: Promise<TValue>;
|
|
12
|
-
wrapperVariant?: "all" | "none" | "only-errorBoundary" | "only-suspense";
|
|
13
|
-
};
|
|
14
|
-
declare function AwaitRoot<TValue>(props: AwaitRootProps<TValue>): React.JSX.Element;
|
|
15
|
-
type AwaitSuccessProps<TValue = unknown> = GetSlotComponentProps<"default", ChildrenType<TValue>>;
|
|
16
|
-
declare function AwaitSuccess<TPromiseOrValue, TValue = Awaited<TPromiseOrValue>>(props: Pick<AwaitSuccessProps<TValue>, "children">): React.ReactNode;
|
|
17
|
-
type AwaitPendingProps = GetSlotComponentProps<"pending", React.SuspenseProps["fallback"]>;
|
|
18
|
-
declare const AwaitPending: {
|
|
19
|
-
(props: Pick<AwaitPendingProps, "children">): React.ReactNode;
|
|
20
|
-
readonly slotName?: "pending" | undefined;
|
|
21
|
-
readonly slotSymbol?: symbol;
|
|
22
|
-
};
|
|
23
|
-
type AwaitErrorProps = GetSlotComponentProps<"error", ErrorBoundaryProps["fallback"]>;
|
|
24
|
-
declare const AwaitError: {
|
|
25
|
-
(props: Pick<AwaitErrorProps, "children"> & {
|
|
26
|
-
asChild?: boolean;
|
|
27
|
-
}): React.ReactNode;
|
|
28
|
-
readonly slotName?: "error" | undefined;
|
|
29
|
-
readonly slotSymbol?: symbol;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
declare namespace awaitParts {
|
|
33
|
-
export { AwaitError as Error, AwaitPending as Pending, AwaitRoot as Root, AwaitSuccess as Success };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { AwaitRoot as A, awaitParts as a, AwaitSuccess as b, AwaitPending as c, AwaitError as d };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { cnMerge } from './chunk-OHG7GB7O.js';
|
|
2
|
-
import { slot_parts_exports } from './chunk-D6QZA3UT.js';
|
|
3
|
-
import { __export } from './chunk-PZ5AY32C.js';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
|
|
6
|
-
function CardRoot(props) {
|
|
7
|
-
const { as: Element = "article", ...restOfProps } = props;
|
|
8
|
-
return /* @__PURE__ */ React.createElement(Element, { ...restOfProps });
|
|
9
|
-
}
|
|
10
|
-
function CardHeader(props) {
|
|
11
|
-
const { as: Element = "header", ...restOfProps } = props;
|
|
12
|
-
return /* @__PURE__ */ React.createElement(Element, { ...restOfProps });
|
|
13
|
-
}
|
|
14
|
-
function CardTitle(props) {
|
|
15
|
-
const { as: Element = "h3", className, ...restOfProps } = props;
|
|
16
|
-
return /* @__PURE__ */ React.createElement(Element, { className: cnMerge("font-semibold", className), ...restOfProps });
|
|
17
|
-
}
|
|
18
|
-
function CardDescription(props) {
|
|
19
|
-
const { as: Element = "p", className, ...restOfProps } = props;
|
|
20
|
-
return /* @__PURE__ */ React.createElement(Element, { className: cnMerge("text-shadcn-muted-foreground text-sm", className), ...restOfProps });
|
|
21
|
-
}
|
|
22
|
-
function CardContent(props) {
|
|
23
|
-
const { as: Element = "div", ...restOfProps } = props;
|
|
24
|
-
return /* @__PURE__ */ React.createElement(Element, { ...restOfProps });
|
|
25
|
-
}
|
|
26
|
-
function CardFooter(props) {
|
|
27
|
-
const { as: Element = "footer", asChild, ...restOfProps } = props;
|
|
28
|
-
const Component = asChild ? slot_parts_exports.Root : Element;
|
|
29
|
-
return /* @__PURE__ */ React.createElement(Component, { ...restOfProps });
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// src/components/ui/card/card-parts.ts
|
|
33
|
-
var card_parts_exports = {};
|
|
34
|
-
__export(card_parts_exports, {
|
|
35
|
-
Content: () => CardContent,
|
|
36
|
-
Description: () => CardDescription,
|
|
37
|
-
Footer: () => CardFooter,
|
|
38
|
-
Header: () => CardHeader,
|
|
39
|
-
Root: () => CardRoot,
|
|
40
|
-
Title: () => CardTitle
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
export { CardContent, CardDescription, CardFooter, CardHeader, CardRoot, CardTitle, card_parts_exports };
|
|
44
|
-
//# sourceMappingURL=chunk-6QJYHPBL.js.map
|
|
45
|
-
//# sourceMappingURL=chunk-6QJYHPBL.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/ui/card/card.tsx","../../src/components/ui/card/card-parts.ts"],"names":[],"mappings":";;;;;AAMO,SAAS,SACf,KACC,EAAA;AACD,EAAA,MAAM,EAAE,EAAI,EAAA,OAAA,GAAU,SAAW,EAAA,GAAG,aAAgB,GAAA,KAAA;AAEpD,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,OAAS,EAAA,EAAA,GAAG,WAAa,EAAA,CAAA;AAClC;AAEO,SAAS,WACf,KACC,EAAA;AACD,EAAA,MAAM,EAAE,EAAI,EAAA,OAAA,GAAU,QAAU,EAAA,GAAG,aAAgB,GAAA,KAAA;AAEnD,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,OAAS,EAAA,EAAA,GAAG,WAAa,EAAA,CAAA;AAClC;AAEO,SAAS,UAAqD,KAAmC,EAAA;AACvG,EAAA,MAAM,EAAE,EAAI,EAAA,OAAA,GAAU,MAAM,SAAW,EAAA,GAAG,aAAgB,GAAA,KAAA;AAE1D,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,WAAQ,SAAW,EAAA,OAAA,CAAQ,iBAAiB,SAAS,CAAA,EAAI,GAAG,WAAa,EAAA,CAAA;AAClF;AAEO,SAAS,gBACf,KACC,EAAA;AACD,EAAA,MAAM,EAAE,EAAI,EAAA,OAAA,GAAU,KAAK,SAAW,EAAA,GAAG,aAAgB,GAAA,KAAA;AAEzD,EACC,uBAAA,KAAA,CAAA,aAAA,CAAC,WAAQ,SAAW,EAAA,OAAA,CAAQ,wCAAwC,SAAS,CAAA,EAAI,GAAG,WAAa,EAAA,CAAA;AAEnG;AAEO,SAAS,YACf,KACC,EAAA;AACD,EAAA,MAAM,EAAE,EAAI,EAAA,OAAA,GAAU,KAAO,EAAA,GAAG,aAAgB,GAAA,KAAA;AAEhD,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,OAAS,EAAA,EAAA,GAAG,WAAa,EAAA,CAAA;AAClC;AAEO,SAAS,WACf,KACC,EAAA;AACD,EAAA,MAAM,EAAE,EAAI,EAAA,OAAA,GAAU,UAAU,OAAS,EAAA,GAAG,aAAgB,GAAA,KAAA;AAE5D,EAAM,MAAA,SAAA,GAAY,OAAU,GAAA,kBAAA,CAAK,IAAO,GAAA,OAAA;AAExC,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,SAAW,EAAA,EAAA,GAAG,WAAa,EAAA,CAAA;AACpC;;;ACtDA,IAAA,kBAAA,GAAA;AAAA,QAAA,CAAA,kBAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA,WAAA;AAAA,EAAA,WAAA,EAAA,MAAA,eAAA;AAAA,EAAA,MAAA,EAAA,MAAA,UAAA;AAAA,EAAA,MAAA,EAAA,MAAA,UAAA;AAAA,EAAA,IAAA,EAAA,MAAA,QAAA;AAAA,EAAA,KAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"chunk-6QJYHPBL.js","sourcesContent":["import * as React from \"react\";\n\nimport { Slot } from \"@/components/common/slot\";\nimport { cnMerge } from \"@/lib/utils/cn\";\nimport type { PolymorphicProps } from \"@zayne-labs/toolkit-react/utils\";\n\nexport function CardRoot<TElement extends React.ElementType = \"article\">(\n\tprops: PolymorphicProps<TElement>\n) {\n\tconst { as: Element = \"article\", ...restOfProps } = props;\n\n\treturn <Element {...restOfProps} />;\n}\n\nexport function CardHeader<TElement extends React.ElementType = \"header\">(\n\tprops: PolymorphicProps<TElement>\n) {\n\tconst { as: Element = \"header\", ...restOfProps } = props;\n\n\treturn <Element {...restOfProps} />;\n}\n\nexport function CardTitle<TElement extends React.ElementType = \"h3\">(props: PolymorphicProps<TElement>) {\n\tconst { as: Element = \"h3\", className, ...restOfProps } = props;\n\n\treturn <Element className={cnMerge(\"font-semibold\", className)} {...restOfProps} />;\n}\n\nexport function CardDescription<TElement extends React.ElementType = \"p\">(\n\tprops: PolymorphicProps<TElement>\n) {\n\tconst { as: Element = \"p\", className, ...restOfProps } = props;\n\n\treturn (\n\t\t<Element className={cnMerge(\"text-shadcn-muted-foreground text-sm\", className)} {...restOfProps} />\n\t);\n}\n\nexport function CardContent<TElement extends React.ElementType = \"div\">(\n\tprops: PolymorphicProps<TElement>\n) {\n\tconst { as: Element = \"div\", ...restOfProps } = props;\n\n\treturn <Element {...restOfProps} />;\n}\n\nexport function CardFooter<TElement extends React.ElementType = \"footer\">(\n\tprops: PolymorphicProps<TElement, { asChild?: boolean }>\n) {\n\tconst { as: Element = \"footer\", asChild, ...restOfProps } = props;\n\n\tconst Component = asChild ? Slot.Root : Element;\n\n\treturn <Component {...restOfProps} />;\n}\n","export {\n\tCardContent as Content,\n\tCardDescription as Description,\n\tCardFooter as Footer,\n\tCardHeader as Header,\n\tCardRoot as Root,\n\tCardTitle as Title,\n} from \"./card\";\n"]}
|