@zayne-labs/ui-react 0.8.19 → 0.9.2
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 +16 -0
- package/css/preset.css +2 -0
- package/dist/esm/chunk-ET4KZBFA.js +49 -0
- package/dist/esm/chunk-ET4KZBFA.js.map +1 -0
- package/dist/esm/chunk-IUEPHHGO.js +74 -0
- package/dist/esm/chunk-IUEPHHGO.js.map +1 -0
- package/dist/esm/{common/show/index.js → chunk-V5DSTESN.js} +5 -5
- package/dist/esm/chunk-V5DSTESN.js.map +1 -0
- package/dist/esm/{common → components/common}/await/index.d.ts +2 -2
- package/dist/esm/{common → components/common}/await/index.js +5 -6
- package/dist/esm/components/common/await/index.js.map +1 -0
- package/dist/esm/{common → components/common}/error-boundary/index.d.ts +2 -2
- package/dist/esm/components/common/error-boundary/index.js +4 -0
- package/dist/esm/components/common/for/index.js +4 -0
- package/dist/esm/components/common/show/index.js +5 -0
- package/dist/esm/components/common/slot/index.js +4 -0
- package/dist/esm/components/common/slot/index.js.map +1 -0
- package/dist/esm/{common → components/common}/suspense-with-boundary/index.d.ts +1 -1
- package/dist/esm/{common → components/common}/suspense-with-boundary/index.js +2 -2
- package/dist/esm/components/common/suspense-with-boundary/index.js.map +1 -0
- package/dist/esm/{common → components/common}/switch/index.js +2 -2
- package/dist/esm/components/common/switch/index.js.map +1 -0
- package/dist/esm/{common → components/common}/teleport/index.js +1 -1
- package/dist/esm/components/common/teleport/index.js.map +1 -0
- package/dist/esm/{ui → components/ui}/card/index.js +3 -3
- package/dist/esm/components/ui/card/index.js.map +1 -0
- package/dist/esm/{ui → components/ui}/carousel/index.d.ts +11 -9
- package/dist/esm/{ui → components/ui}/carousel/index.js +12 -10
- package/dist/esm/components/ui/carousel/index.js.map +1 -0
- package/dist/esm/{ui → components/ui}/drag-scroll/index.js +2 -2
- package/dist/esm/components/ui/drag-scroll/index.js.map +1 -0
- package/dist/esm/{ui → components/ui}/drop-zone/index.d.ts +31 -27
- package/dist/esm/{ui → components/ui}/drop-zone/index.js +59 -49
- package/dist/esm/components/ui/drop-zone/index.js.map +1 -0
- package/dist/esm/{ui → components/ui}/form/index.d.ts +29 -13
- package/dist/esm/{ui → components/ui}/form/index.js +208 -103
- package/dist/esm/components/ui/form/index.js.map +1 -0
- package/dist/esm/lib/utils/getSlot/index.d.ts +60 -0
- package/dist/esm/lib/utils/getSlot/index.js +4 -0
- package/dist/esm/lib/utils/getSlot/index.js.map +1 -0
- package/dist/esm/lib/utils/getSlotMap/index.d.ts +82 -0
- package/dist/esm/lib/utils/getSlotMap/index.js +4 -0
- package/dist/esm/lib/utils/getSlotMap/index.js.map +1 -0
- package/dist/style.css +19 -3
- package/package.json +10 -9
- package/dist/esm/common/await/index.js.map +0 -1
- package/dist/esm/common/error-boundary/index.js +0 -4
- package/dist/esm/common/for/index.js +0 -4
- package/dist/esm/common/show/index.js.map +0 -1
- package/dist/esm/common/slot/index.js +0 -4
- package/dist/esm/common/suspense-with-boundary/index.js.map +0 -1
- package/dist/esm/common/switch/index.js.map +0 -1
- package/dist/esm/common/teleport/index.js.map +0 -1
- package/dist/esm/ui/card/index.js.map +0 -1
- package/dist/esm/ui/carousel/index.js.map +0 -1
- package/dist/esm/ui/drag-scroll/index.js.map +0 -1
- package/dist/esm/ui/drop-zone/index.js.map +0 -1
- package/dist/esm/ui/form/index.js.map +0 -1
- /package/dist/esm/{common → components/common}/error-boundary/index.js.map +0 -0
- /package/dist/esm/{common → components/common}/for/index.d.ts +0 -0
- /package/dist/esm/{common → components/common}/for/index.js.map +0 -0
- /package/dist/esm/{common → components/common}/show/index.d.ts +0 -0
- /package/dist/esm/{common/slot → components/common/show}/index.js.map +0 -0
- /package/dist/esm/{common → components/common}/slot/index.d.ts +0 -0
- /package/dist/esm/{common → components/common}/switch/index.d.ts +0 -0
- /package/dist/esm/{common → components/common}/teleport/index.d.ts +0 -0
- /package/dist/esm/{ui → components/ui}/card/index.d.ts +0 -0
- /package/dist/esm/{ui → components/ui}/drag-scroll/index.d.ts +0 -0
package/css/preset.css
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { toArray } from '@zayne-labs/toolkit-core';
|
|
2
|
+
import { isFunction } from '@zayne-labs/toolkit-type-helpers';
|
|
3
|
+
import { isValidElement, Fragment } from 'react';
|
|
4
|
+
|
|
5
|
+
// src/lib/utils/getSlotMap/getSlotMap.ts
|
|
6
|
+
var slotComponentSymbol = Symbol("slot-component");
|
|
7
|
+
var getSlotMap = (children) => {
|
|
8
|
+
const slots = {
|
|
9
|
+
default: []
|
|
10
|
+
};
|
|
11
|
+
const isFragment = isValidElement(children) && children.type === Fragment;
|
|
12
|
+
const actualChildren = isFragment ? children.props.children : children;
|
|
13
|
+
const childrenArray = toArray(actualChildren);
|
|
14
|
+
for (const child of childrenArray) {
|
|
15
|
+
if (!isValidElement(child) || !isFunction(child.type)) {
|
|
16
|
+
slots.default.push(child);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const childType = child.type;
|
|
20
|
+
const isSlotElement = childType.slotSymbol === slotComponentSymbol && Boolean(childType.slotName ?? child.props.name);
|
|
21
|
+
if (!isSlotElement) {
|
|
22
|
+
slots.default.push(child);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const slotName = childType.slotName ?? child.props.name;
|
|
26
|
+
const getSlotChild = () => {
|
|
27
|
+
return child;
|
|
28
|
+
};
|
|
29
|
+
slots[slotName] = getSlotChild();
|
|
30
|
+
}
|
|
31
|
+
return slots;
|
|
32
|
+
};
|
|
33
|
+
var createSlotComponent = () => {
|
|
34
|
+
const SlotComponent = (props) => props.children;
|
|
35
|
+
SlotComponent.slotSymbol = slotComponentSymbol;
|
|
36
|
+
return SlotComponent;
|
|
37
|
+
};
|
|
38
|
+
function DefaultSlotComponent(props) {
|
|
39
|
+
return props.children;
|
|
40
|
+
}
|
|
41
|
+
var withSlotNameAndSymbol = (name, SlotComponent = DefaultSlotComponent) => {
|
|
42
|
+
SlotComponent.slotSymbol = slotComponentSymbol;
|
|
43
|
+
SlotComponent.slotName = name;
|
|
44
|
+
return SlotComponent;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { createSlotComponent, getSlotMap, slotComponentSymbol, withSlotNameAndSymbol };
|
|
48
|
+
//# sourceMappingURL=chunk-ET4KZBFA.js.map
|
|
49
|
+
//# sourceMappingURL=chunk-ET4KZBFA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/utils/getSlotMap/getSlotMap.ts"],"names":["ReactFragment"],"mappings":";;;;;AA4Ba,IAAA,mBAAA,GAAsB,OAAO,gBAAgB;AA0C7C,IAAA,UAAA,GAAa,CACzB,QAEqD,KAAA;AACrD,EAAA,MAAM,KAA0F,GAAA;AAAA,IAC/F,SAAS;AAAC,GACX;AAEA,EAAA,MAAM,UAAa,GAAA,cAAA,CAAwC,QAAQ,CAAA,IAAK,SAAS,IAAS,KAAAA,QAAA;AAE1F,EAAA,MAAM,cAAiB,GAAA,UAAA,GAAa,QAAS,CAAA,KAAA,CAAM,QAAW,GAAA,QAAA;AAE9D,EAAM,MAAA,aAAA,GAAgB,QAAyB,cAAc,CAAA;AAE7D,EAAA,KAAA,MAAW,SAAS,aAAe,EAAA;AAClC,IAAI,IAAA,CAAC,eAAoC,KAAK,CAAA,IAAK,CAAC,UAAW,CAAA,KAAA,CAAM,IAAI,CAAG,EAAA;AAC3E,MAAM,KAAA,CAAA,OAAA,CAAQ,KAAK,KAAK,CAAA;AACxB,MAAA;AAAA;AAGD,IAAA,MAAM,YAAY,KAAM,CAAA,IAAA;AAExB,IAAM,MAAA,aAAA,GACL,UAAU,UAAe,KAAA,mBAAA,IAAuB,QAAQ,SAAU,CAAA,QAAA,IAAY,KAAM,CAAA,KAAA,CAAM,IAAI,CAAA;AAE/F,IAAA,IAAI,CAAC,aAAe,EAAA;AACnB,MAAM,KAAA,CAAA,OAAA,CAAQ,KAAK,KAAK,CAAA;AACxB,MAAA;AAAA;AAGD,IAAA,MAAM,QAAW,GAAA,SAAA,CAAU,QAAY,IAAA,KAAA,CAAM,KAAM,CAAA,IAAA;AAEnD,IAAA,MAAM,eAAe,MAAM;AAC1B,MAAO,OAAA,KAAA;AAAA,KACR;AAEA,IAAM,KAAA,CAAA,QAAQ,IAAI,YAAa,EAAA;AAAA;AAGhC,EAAO,OAAA,KAAA;AACR;AA8BO,IAAM,sBAAsB,MAAyD;AAC3F,EAAM,MAAA,aAAA,GAAgB,CAAC,KAAA,KAA+B,KAAM,CAAA,QAAA;AAE5D,EAAA,aAAA,CAAc,UAAa,GAAA,mBAAA;AAE3B,EAAO,OAAA,aAAA;AACR;AAWA,SAAS,qBAAqB,KAAiE,EAAA;AAC9F,EAAA,OAAO,KAAM,CAAA,QAAA;AACd;AAEO,IAAM,qBAAwB,GAAA,CAIpC,IACA,EAAA,aAAA,GAA0E,oBACtE,KAAA;AAGJ,EAAA,aAAA,CAAc,UAAa,GAAA,mBAAA;AAE3B,EAAA,aAAA,CAAc,QAAW,GAAA,IAAA;AAIzB,EAAO,OAAA,aAAA;AACR","file":"chunk-ET4KZBFA.js","sourcesContent":["import { toArray } from \"@zayne-labs/toolkit-core\";\nimport type { InferProps } from \"@zayne-labs/toolkit-react/utils\";\nimport {\n\ttype CallbackFn,\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 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 string extends TSlotComponentProps[\"name\"]\n\t\t? never\n\t\t: TSlotComponentProps[\"name\"]]: TSlotComponentProps[\"children\"];\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// type GetSlotMapOptions = {\n// \t/**\n// \t * If false, the function will bail out early and return only the default slot with the actual children.\n// \t * @default true\n// \t */\n// \t// condition?: boolean;\n// };\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\t// options?: GetSlotMapOptions\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\tconst getSlotChild = () => {\n\t\t\treturn child;\n\t\t};\n\n\t\tslots[slotName] = getSlotChild();\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\t/** Content to render in the slot */\n\tchildren: TChildren;\n\t/** Name of the slot where content should be rendered */\n\tname: TName;\n};\n\n/**\n * @description Slot component created by createSlotComponent\n */\n\nexport const createSlotComponent = <TSlotComponentProps extends GetSlotComponentProps>() => {\n\tconst SlotComponent = (props: TSlotComponentProps) => props.children;\n\n\tSlotComponent.slotSymbol = slotComponentSymbol;\n\n\treturn SlotComponent;\n};\n\ntype SlotWithNameAndSymbol<\n\tTSlotComponentProps extends GetSlotComponentProps = GetSlotComponentProps,\n\tTActualProps extends UnknownObject = UnknownObject,\n> = {\n\t(props: Pick<TSlotComponentProps, \"children\"> & TActualProps): 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\nexport const withSlotNameAndSymbol = <\n\tTSlotComponentProps extends GetSlotComponentProps,\n\tTActualProps extends UnknownObject = UnknownObject,\n>(\n\tname: TSlotComponentProps[\"name\"],\n\tSlotComponent: SlotWithNameAndSymbol<TSlotComponentProps, TActualProps> = 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"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { toArray } from '@zayne-labs/toolkit-core';
|
|
2
|
+
import { isFunction, isArray, AssertionError } from '@zayne-labs/toolkit-type-helpers';
|
|
3
|
+
import { isValidElement, Fragment } from 'react';
|
|
4
|
+
|
|
5
|
+
// src/lib/utils/getSlot/getSlot.ts
|
|
6
|
+
var isWithSlotSymbol = (component) => {
|
|
7
|
+
return "slotSymbol" in component && Boolean(component.slotSymbol);
|
|
8
|
+
};
|
|
9
|
+
var isWithSlotReference = (component) => {
|
|
10
|
+
return "slotReference" in component && Boolean(component.slotReference);
|
|
11
|
+
};
|
|
12
|
+
var matchesSlotComponent = (child, SlotComponent) => {
|
|
13
|
+
if (!isValidElement(child) || !isFunction(child.type)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const resolvedChildType = isWithSlotReference(child.type) ? child.type.slotReference : child.type;
|
|
17
|
+
const hasMatchingSlotSymbol = isWithSlotSymbol(resolvedChildType) && isWithSlotSymbol(SlotComponent) && resolvedChildType.slotSymbol === SlotComponent.slotSymbol;
|
|
18
|
+
if (hasMatchingSlotSymbol) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (child.type.name === SlotComponent.name) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
var matchesAnySlotComponent = (child, SlotComponents) => {
|
|
27
|
+
const matchesSlot = SlotComponents.some((SlotComponent) => matchesSlotComponent(child, SlotComponent));
|
|
28
|
+
return matchesSlot;
|
|
29
|
+
};
|
|
30
|
+
var calculateSlotOccurrences = (childrenArray, SlotComponent) => {
|
|
31
|
+
let count = 0;
|
|
32
|
+
for (const child of childrenArray) {
|
|
33
|
+
if (!matchesSlotComponent(child, SlotComponent)) continue;
|
|
34
|
+
count += 1;
|
|
35
|
+
}
|
|
36
|
+
return count;
|
|
37
|
+
};
|
|
38
|
+
var getSingleSlot = (children, SlotComponent, options = {}) => {
|
|
39
|
+
const {
|
|
40
|
+
errorMessage = "Only one instance of the SlotComponent is allowed",
|
|
41
|
+
throwOnMultipleSlotMatch = false
|
|
42
|
+
} = options;
|
|
43
|
+
const actualChildren = isValidElement(children) && children.type === Fragment ? children.props.children : children;
|
|
44
|
+
const childrenArray = toArray(actualChildren);
|
|
45
|
+
const shouldThrow = throwOnMultipleSlotMatch && calculateSlotOccurrences(childrenArray, SlotComponent) > 1;
|
|
46
|
+
if (shouldThrow) {
|
|
47
|
+
throw new AssertionError(errorMessage);
|
|
48
|
+
}
|
|
49
|
+
const slotElement = childrenArray.find((child) => matchesSlotComponent(child, SlotComponent));
|
|
50
|
+
return slotElement;
|
|
51
|
+
};
|
|
52
|
+
var getMultipleSlots = (children, SlotComponents, options) => {
|
|
53
|
+
const { errorMessage, throwOnMultipleSlotMatch } = options ?? {};
|
|
54
|
+
const slots = SlotComponents.map(
|
|
55
|
+
(SlotComponent, index) => getSingleSlot(children, SlotComponent, {
|
|
56
|
+
errorMessage: isArray(errorMessage) ? errorMessage[index] : errorMessage,
|
|
57
|
+
throwOnMultipleSlotMatch: isArray(throwOnMultipleSlotMatch) ? throwOnMultipleSlotMatch[index] : throwOnMultipleSlotMatch
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
const regularChildren = getRegularChildren(children, SlotComponents);
|
|
61
|
+
return { regularChildren, slots };
|
|
62
|
+
};
|
|
63
|
+
var getRegularChildren = (children, SlotComponentOrComponents) => {
|
|
64
|
+
const actualChildren = isValidElement(children) && children.type === Fragment ? children.props.children : children;
|
|
65
|
+
const childrenArray = toArray(actualChildren);
|
|
66
|
+
const regularChildren = childrenArray.filter(
|
|
67
|
+
(child) => !matchesAnySlotComponent(child, toArray(SlotComponentOrComponents))
|
|
68
|
+
);
|
|
69
|
+
return regularChildren;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { getMultipleSlots, getRegularChildren, getSingleSlot, matchesAnySlotComponent, matchesSlotComponent };
|
|
73
|
+
//# sourceMappingURL=chunk-IUEPHHGO.js.map
|
|
74
|
+
//# sourceMappingURL=chunk-IUEPHHGO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/utils/getSlot/getSlot.ts"],"names":["ReactFragment"],"mappings":";;;;;AAcA,IAAM,gBAAA,GAAmB,CACxB,SAC4D,KAAA;AAC5D,EAAA,OAAO,YAAgB,IAAA,SAAA,IAAa,OAAQ,CAAA,SAAA,CAAU,UAAU,CAAA;AACjE,CAAA;AAEA,IAAM,mBAAA,GAAsB,CAC3B,SAC+D,KAAA;AAC/D,EAAA,OAAO,eAAmB,IAAA,SAAA,IAAa,OAAQ,CAAA,SAAA,CAAU,aAAa,CAAA;AACvE,CAAA;AAOa,IAAA,oBAAA,GAAuB,CAAC,KAAA,EAAwB,aAAuC,KAAA;AACnG,EAAI,IAAA,CAAC,eAAe,KAAK,CAAA,IAAK,CAAC,UAAW,CAAA,KAAA,CAAM,IAAI,CAAG,EAAA;AACtD,IAAO,OAAA,KAAA;AAAA;AAGR,EAAM,MAAA,iBAAA,GAAoB,oBAAoB,KAAM,CAAA,IAAI,IACpD,KAAM,CAAA,IAAA,CAAK,gBACZ,KAAM,CAAA,IAAA;AAET,EAAM,MAAA,qBAAA,GACL,iBAAiB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/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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getMultipleSlots } from './chunk-IUEPHHGO.js';
|
|
2
|
+
import { __export } from './chunk-PZ5AY32C.js';
|
|
2
3
|
import 'react';
|
|
3
|
-
import { getMultipleSlots } from '@zayne-labs/toolkit-react/utils';
|
|
4
4
|
import { isFunction, assert } from '@zayne-labs/toolkit-type-helpers';
|
|
5
5
|
|
|
6
6
|
function ShowRoot(props) {
|
|
@@ -43,6 +43,6 @@ __export(show_parts_exports, {
|
|
|
43
43
|
Root: () => ShowRoot
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
export {
|
|
47
|
-
//# sourceMappingURL=
|
|
48
|
-
//# sourceMappingURL=
|
|
46
|
+
export { ShowContent, ShowFallback, ShowRoot, show_parts_exports };
|
|
47
|
+
//# sourceMappingURL=chunk-V5DSTESN.js.map
|
|
48
|
+
//# sourceMappingURL=chunk-V5DSTESN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/common/show/show.tsx","../../src/components/common/show/show-parts.ts"],"names":[],"mappings":";;;;;AAaO,SAAS,SAAgB,KAAyB,EAAA;AACxD,EAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,IAAA,EAAS,GAAA,KAAA;AAErC,EAAA,MAAM,mBAAmB,UAAW,CAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,IAAa,CAAI,GAAA,QAAA;AAE1E,EAAM,MAAA;AAAA,IACL,eAAA;AAAA,IACA,KAAA,EAAO,CAAC,WAAA,EAAa,YAAY;AAAA,MAC9B,gBAAiB,CAAA,gBAAA,EAAkB,CAAC,WAAA,EAAa,YAAY,CAAG,EAAA;AAAA,IACnE,YAAc,EAAA;AAAA,MACb,8CAAA;AAAA,MACA;AAAA,KACD;AAAA,IACA,wBAA0B,EAAA;AAAA,GAC1B,CAAA;AAED,EAAA,IAAI,CAAC,IAAM,EAAA;AACV,IAAA,MAAA;AAAA,MACC,EAAE,YAAgB,IAAA,QAAA,CAAA;AAAA,MAClB;AAAA,KACD;AAEA,IAAA,OAAO,YAAgB,IAAA,QAAA;AAAA;AAGxB,EAAA,OAAO,WAAe,IAAA,eAAA;AACvB;AAEO,SAAS,WAAA,CAAY,EAAE,QAAA,EAA2C,EAAA;AACxE,EAAO,OAAA,QAAA;AACR;AACA,WAAY,CAAA,UAAA,GAAa,OAAO,cAAc,CAAA;AAEvC,SAAS,YAAA,CAAa,EAAE,QAAA,EAA2C,EAAA;AACzE,EAAO,OAAA,QAAA;AACR;AACA,YAAa,CAAA,UAAA,GAAa,OAAO,eAAe,CAAA;;;ACjDhD,IAAA,kBAAA,GAAA;AAAA,QAAA,CAAA,kBAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA,WAAA;AAAA,EAAA,QAAA,EAAA,MAAA,YAAA;AAAA,EAAA,SAAA,EAAA,MAAA,YAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"chunk-V5DSTESN.js","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, 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"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DiscriminatedRenderProps } from '@zayne-labs/toolkit-react/utils';
|
|
3
3
|
import { SuspenseWithBoundaryProps } from '../suspense-with-boundary/index.js';
|
|
4
|
-
import '
|
|
4
|
+
import '../../../types-CeWumkhm.js';
|
|
5
5
|
|
|
6
6
|
type RenderPropFn<TValue> = (result: TValue) => React.ReactNode;
|
|
7
7
|
type AwaitProps<TValue> = AwaitInnerProps<TValue> & Pick<SuspenseWithBoundaryProps, "errorFallback" | "fallback"> & {
|
|
8
8
|
withErrorBoundary?: boolean;
|
|
9
9
|
};
|
|
10
10
|
declare function Await<TValue>(props: AwaitProps<TValue>): React.JSX.Element;
|
|
11
|
-
type AwaitInnerProps<TValue> = DiscriminatedRenderProps<
|
|
11
|
+
type AwaitInnerProps<TValue> = DiscriminatedRenderProps<RenderPropFn<TValue>> & {
|
|
12
12
|
asChild?: boolean;
|
|
13
13
|
promise: Promise<TValue>;
|
|
14
14
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Slot } from '
|
|
2
|
-
import { ErrorBoundary } from '
|
|
3
|
-
import '
|
|
1
|
+
import { Slot } from '../../../chunk-2P3P5AXH.js';
|
|
2
|
+
import { ErrorBoundary } from '../../../chunk-7LEVEBD2.js';
|
|
3
|
+
import '../../../chunk-PZ5AY32C.js';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { Fragment, Suspense, use } from 'react';
|
|
6
|
-
import { isFunction } from '@zayne-labs/toolkit-type-helpers';
|
|
7
6
|
|
|
8
7
|
function Await(props) {
|
|
9
8
|
const { errorFallback, fallback, withErrorBoundary = true, ...restOfProps } = props;
|
|
@@ -16,8 +15,8 @@ function AwaitInner(props) {
|
|
|
16
15
|
const result = use(promise);
|
|
17
16
|
const Component = asChild ? Slot : Fragment;
|
|
18
17
|
const slotProps = asChild && { promise, result };
|
|
19
|
-
const selectedChildren = children
|
|
20
|
-
const resolvedChildren =
|
|
18
|
+
const selectedChildren = typeof children === "function" ? children : render;
|
|
19
|
+
const resolvedChildren = selectedChildren(result);
|
|
21
20
|
return /* @__PURE__ */ React.createElement(Component, { ...slotProps }, resolvedChildren);
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/common/await/await.tsx"],"names":["ReactFragment"],"mappings":";;;;;;AAkBO,SAAS,MAAc,KAA2B,EAAA;AACxD,EAAA,MAAM,EAAE,aAAe,EAAA,QAAA,EAAU,oBAAoB,IAAM,EAAA,GAAG,aAAgB,GAAA,KAAA;AAE9E,EAAM,MAAA,iBAAA,GAAoB,oBAAoB,aAAgB,GAAAA,QAAA;AAE9D,EAAA,MAAM,qBAAqB,OAAQ,CAAA,aAAa,CAAK,IAAA,EAAE,UAAU,aAAc,EAAA;AAE/E,EAAA,uBACE,KAAA,CAAA,aAAA,CAAA,iBAAA,EAAA,EAAmB,GAAG,kBAAA,EAAA,kBACrB,KAAA,CAAA,aAAA,CAAA,QAAA,EAAA,EAAS,QACT,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,UAAY,EAAA,EAAA,GAAG,WAAa,EAAA,CAC9B,CACD,CAAA;AAEF;AAOA,SAAS,WAAmB,KAAgC,EAAA;AAC3D,EAAA,MAAM,EAAE,OAAA,EAAS,QAAU,EAAA,OAAA,EAAS,QAAW,GAAA,KAAA;AAE/C,EAAM,MAAA,MAAA,GAAS,IAAI,OAAO,CAAA;AAE1B,EAAM,MAAA,SAAA,GAAY,UAAU,IAAO,GAAAA,QAAA;AAEnC,EAAA,MAAM,SAAY,GAAA,OAAA,IAAW,EAAE,OAAA,EAAS,MAAO,EAAA;AAE/C,EAAA,MAAM,gBAAmB,GAAA,OAAO,QAAa,KAAA,UAAA,GAAa,QAAW,GAAA,MAAA;AAErE,EAAM,MAAA,gBAAA,GAAmB,iBAAiB,MAAM,CAAA;AAEhD,EAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,SAAA,EAAA,EAAW,GAAG,SAAA,EAAA,EAAY,gBAAiB,CAAA;AACpD","file":"index.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport type { DiscriminatedRenderProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { Fragment as ReactFragment, Suspense, use } from \"react\";\nimport { ErrorBoundary } from \"../error-boundary\";\nimport { Slot } from \"../slot\";\nimport type { SuspenseWithBoundaryProps } from \"../suspense-with-boundary\";\n\ntype RenderPropFn<TValue> = (result: TValue) => React.ReactNode;\n\ntype AwaitProps<TValue> = AwaitInnerProps<TValue>\n\t& Pick<SuspenseWithBoundaryProps, \"errorFallback\" | \"fallback\"> & {\n\t\twithErrorBoundary?: boolean;\n\t};\n\n// TODO - Add Support for Slot components\nexport function Await<TValue>(props: AwaitProps<TValue>) {\n\tconst { errorFallback, fallback, withErrorBoundary = true, ...restOfProps } = props;\n\n\tconst WithErrorBoundary = withErrorBoundary ? ErrorBoundary : ReactFragment;\n\n\tconst errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };\n\n\treturn (\n\t\t<WithErrorBoundary {...errorBoundaryProps}>\n\t\t\t<Suspense fallback={fallback}>\n\t\t\t\t<AwaitInner {...restOfProps} />\n\t\t\t</Suspense>\n\t\t</WithErrorBoundary>\n\t);\n}\n\nexport type AwaitInnerProps<TValue> = DiscriminatedRenderProps<RenderPropFn<TValue>> & {\n\tasChild?: boolean;\n\tpromise: Promise<TValue>;\n};\n\nfunction AwaitInner<TValue>(props: AwaitInnerProps<TValue>) {\n\tconst { asChild, children, promise, render } = props;\n\n\tconst result = use(promise);\n\n\tconst Component = asChild ? Slot : ReactFragment;\n\n\tconst slotProps = asChild && { promise, result };\n\n\tconst selectedChildren = typeof children === \"function\" ? children : render;\n\n\tconst resolvedChildren = selectedChildren(result);\n\n\treturn <Component {...slotProps}>{resolvedChildren}</Component>;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as ErrorBoundaryProps } from '
|
|
2
|
-
export { F as FallbackProps } from '
|
|
1
|
+
import { E as ErrorBoundaryProps } from '../../../types-CeWumkhm.js';
|
|
2
|
+
export { F as FallbackProps } from '../../../types-CeWumkhm.js';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { Component } from 'react';
|
|
5
5
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ErrorBoundary } from '
|
|
2
|
-
import '
|
|
1
|
+
import { ErrorBoundary } from '../../../chunk-7LEVEBD2.js';
|
|
2
|
+
import '../../../chunk-PZ5AY32C.js';
|
|
3
3
|
import { Suspense } from 'react';
|
|
4
4
|
|
|
5
5
|
function SuspenseWithBoundaryRoot(props) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/common/suspense-with-boundary/suspense-with-boundary.tsx"],"names":[],"mappings":";;;;AASO,SAAS,yBAAyB,KAAkC,EAAA;AAC1E,EAAA,MAAM,EAAE,QAAA,EAAU,aAAe,EAAA,QAAA,EAAa,GAAA,KAAA;AAE9C,EAAA,MAAM,qBAAqB,OAAQ,CAAA,aAAa,CAAK,IAAA,EAAE,UAAU,aAAc,EAAA;AAC/E,EAAA,MAAM,aAAgB,GAAA,OAAA,CAAQ,QAAQ,CAAA,IAAK,EAAE,QAAS,EAAA;AAEtD,EACC,uBAAA,KAAA,CAAA,aAAA,CAAC,iBAAe,GAAG,kBAAA,EAAA,sCACjB,QAAU,EAAA,EAAA,GAAG,aAAgB,EAAA,EAAA,QAAS,CACxC,CAAA;AAEF","file":"index.js","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 SuspenseWithBoundaryRoot(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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getSingleSlot, getRegularChildren } from '../../../chunk-IUEPHHGO.js';
|
|
2
|
+
import { __export } from '../../../chunk-PZ5AY32C.js';
|
|
2
3
|
import 'react';
|
|
3
|
-
import { getSingleSlot, getRegularChildren } from '@zayne-labs/toolkit-react/utils';
|
|
4
4
|
import { isFunction } from '@zayne-labs/toolkit-type-helpers';
|
|
5
5
|
|
|
6
6
|
var defaultConditionSymbol = Symbol("condition-default");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/common/switch/switch.tsx","../../../../../src/components/common/switch/switch-parts.ts"],"names":[],"mappings":";;;;;AAmBA,IAAM,sBAAA,GAAyB,OAAO,mBAAmB,CAAA;AAElD,SAAS,WAA8B,KAAgC,EAAA;AAC7E,EAAA,MAAM,EAAE,QAAA,EAAU,SAAY,GAAA,sBAAA,EAA2B,GAAA,KAAA;AAEzD,EAAM,MAAA,WAAA,GAAc,aAAc,CAAA,QAAA,EAAU,aAAe,EAAA;AAAA,IAC1D,YAAc,EAAA,gDAAA;AAAA,IACd,wBAA0B,EAAA;AAAA,GAC1B,CAAA;AAED,EAAM,MAAA,kBAAA,GAAqB,kBAAmB,CAAA,QAAA,EAAU,aAAa,CAAA;AAErE,EAAA,MAAM,cAAc,kBAAmB,CAAA,IAAA;AAAA,IAAK,CAAC,UAC5C,SAAc,KAAA,sBAAA,GAAyB,MAAM,KAAM,CAAA,IAAA,GAAO,KAAM,CAAA,KAAA,CAAM,IAAS,KAAA;AAAA,GAChF;AAEA,EAAA,OAAO,WAAe,IAAA,WAAA;AACvB;AAEO,SAAS,YAAmB,KAAgC,EAAA;AAClE,EAAM,MAAA,EAAE,QAAU,EAAA,IAAA,EAAS,GAAA,KAAA;AAE3B,EAAA,IAAI,CAAC,IAAM,EAAA;AACV,IAAO,OAAA,IAAA;AAAA;AAGR,EAAA,MAAM,mBAAmB,UAAW,CAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,IAAI,CAAI,GAAA,QAAA;AAEjE,EAAO,OAAA,gBAAA;AACR;AAEO,SAAS,aAAA,CAAc,EAAE,QAAA,EAA2C,EAAA;AAC1E,EAAO,OAAA,QAAA;AACR;AACA,aAAc,CAAA,UAAA,GAAa,OAAO,gBAAgB,CAAA;;;ACrDlD,IAAA,oBAAA,GAAA;AAAA,QAAA,CAAA,oBAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA,aAAA;AAAA,EAAA,KAAA,EAAA,MAAA,WAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","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>;\n\ntype SwitchProps<TCondition> = {\n\tchildren: ValidSwitchComponentType | ValidSwitchComponentType[];\n\tcondition?: TCondition;\n};\n\ntype SwitchMatchProps<TWhen = unknown> = {\n\tchildren: React.ReactNode | ((value: TWhen) => React.ReactNode);\n\twhen: false | TWhen | null | undefined;\n};\n\nconst defaultConditionSymbol = Symbol(\"condition-default\");\n\nexport function SwitchRoot<TCondition = true>(props: SwitchProps<TCondition>) {\n\tconst { children, condition = defaultConditionSymbol } = 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\tcondition === defaultConditionSymbol ? child.props.when : child.props.when === condition\n\t);\n\n\treturn matchedCase ?? defaultCase;\n}\n\nexport function SwitchMatch<TWhen>(props: SwitchMatchProps<TWhen>) {\n\tconst { children, when } = props;\n\n\tif (!when) {\n\t\treturn null;\n\t}\n\n\tconst resolvedChildren = isFunction(children) ? children(when) : 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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/common/teleport/teleport.tsx"],"names":[],"mappings":";;;;;AAgBA,SAAS,SAAS,KAAoB,EAAA;AACrC,EAAA,MAAM,EAAE,QAAA,EAAU,cAAgB,EAAA,EAAA,EAAO,GAAA,KAAA;AAEzC,EAAA,MAAM,CAAC,eAAA,EAAiB,kBAAkB,CAAA,GAAI,SAA6B,IAAI,CAAA;AAI/E,EAAA,SAAA,CAAU,MAAM;AACf,IAAA,IAAI,CAAC,EAAI,EAAA;AAET,IAAA,IAAI,cAAgB,EAAA;AAEpB,IAAA,MAAM,cAAc,QAAS,CAAA,EAAE,IAAI,QAAS,CAAA,aAAA,CAA2B,EAAE,CAAI,GAAA,EAAA;AAE7E,IAAA,WAAA,IAAe,mBAAmB,WAAW,CAAA;AAAA,GAC3C,EAAA,CAAC,EAAI,EAAA,cAAc,CAAC,CAAA;AAEvB,EAAA,SAAA,CAAU,MAAM;AACf,IAAA,IAAI,CAAC,EAAI,EAAA;AAET,IAAA,IAAI,CAAC,cAAgB,EAAA;AAErB,IAAA,MAAM,cAAc,QAAS,CAAA,EAAE,IAAI,QAAS,CAAA,aAAA,CAA2B,EAAE,CAAI,GAAA,EAAA;AAE7E,IAAM,MAAA,WAAA,GAAc,QAAS,CAAA,aAAA,CAAc,KAAK,CAAA;AAChD,IAAA,WAAA,CAAY,MAAM,OAAU,GAAA,UAAA;AAE5B,IAAa,WAAA,EAAA,qBAAA,CAAsB,gBAAgB,WAAW,CAAA;AAE9D,IAAA,kBAAA,CAAmB,WAAW,CAAA;AAE9B,IAAA,OAAO,MAAM;AACZ,MAAA,WAAA,CAAY,MAAO,EAAA;AAAA,KACpB;AAAA,GACE,EAAA,CAAC,EAAI,EAAA,cAAc,CAAC,CAAA;AAIvB,EAAO,OAAA,eAAA,IAAmB,YAAa,CAAA,QAAA,EAAU,eAAe,CAAA;AACjE","file":"index.js","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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { cnMerge } from '
|
|
2
|
-
import { Slot } from '
|
|
3
|
-
import { __export } from '
|
|
1
|
+
import { cnMerge } from '../../../chunk-OHG7GB7O.js';
|
|
2
|
+
import { Slot } from '../../../chunk-2P3P5AXH.js';
|
|
3
|
+
import { __export } from '../../../chunk-PZ5AY32C.js';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
|
|
6
6
|
function CardRoot(props) {
|
|
@@ -0,0 +1 @@
|
|
|
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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A,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":"index.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 : 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"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React$1 from 'react';
|
|
2
2
|
import { DiscriminatedRenderProps, PolymorphicProps } from '@zayne-labs/toolkit-react/utils';
|
|
3
3
|
import { StoreApi } from '@zayne-labs/toolkit-core';
|
|
4
|
-
import { Prettify } from '@zayne-labs/toolkit-type-helpers';
|
|
4
|
+
import { UnionDiscriminator, Prettify } from '@zayne-labs/toolkit-type-helpers';
|
|
5
5
|
|
|
6
6
|
type ImagesType = Array<Record<string, string>> | string[];
|
|
7
7
|
type CarouselStore<TImages extends ImagesType = ImagesType> = {
|
|
@@ -45,14 +45,16 @@ type CarouselControlProps = {
|
|
|
45
45
|
defaultIcon?: string;
|
|
46
46
|
iconContainer?: string;
|
|
47
47
|
};
|
|
48
|
-
icon?:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
icon?: UnionDiscriminator<[
|
|
49
|
+
{
|
|
50
|
+
icon?: React.ReactElement;
|
|
51
|
+
iconType: "nextIcon" | "prevIcon";
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
next?: React.ReactElement;
|
|
55
|
+
prev?: React.ReactElement;
|
|
56
|
+
}
|
|
57
|
+
]>;
|
|
56
58
|
};
|
|
57
59
|
type CarouselIndicatorProps = {
|
|
58
60
|
classNames?: {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { cnMerge } from '
|
|
2
|
-
import { getElementList } from '
|
|
3
|
-
import {
|
|
1
|
+
import { cnMerge } from '../../../chunk-OHG7GB7O.js';
|
|
2
|
+
import { getElementList } from '../../../chunk-DW3FXTFL.js';
|
|
3
|
+
import { show_parts_exports } from '../../../chunk-V5DSTESN.js';
|
|
4
|
+
import '../../../chunk-IUEPHHGO.js';
|
|
5
|
+
import { __export } from '../../../chunk-PZ5AY32C.js';
|
|
4
6
|
import * as React3 from 'react';
|
|
5
7
|
import { useEffect, useState } from 'react';
|
|
6
8
|
import { useConstant, useAnimationInterval, useCallbackRef } from '@zayne-labs/toolkit-react';
|
|
@@ -135,18 +137,18 @@ function CarouselButton(props) {
|
|
|
135
137
|
}
|
|
136
138
|
function CarouselControls(props) {
|
|
137
139
|
const { classNames, icon } = props;
|
|
138
|
-
return /* @__PURE__ */ React3.createElement("div", { className: cnMerge("absolute inset-0 flex justify-between", classNames?.base) },
|
|
140
|
+
return /* @__PURE__ */ React3.createElement("div", { className: cnMerge("absolute inset-0 flex justify-between", classNames?.base) }, /* @__PURE__ */ React3.createElement(show_parts_exports.Root, { when: icon?.iconType }, /* @__PURE__ */ React3.createElement(
|
|
139
141
|
CarouselButton,
|
|
140
142
|
{
|
|
141
143
|
variant: "prev",
|
|
142
144
|
classNames: {
|
|
143
145
|
defaultIcon: classNames?.defaultIcon,
|
|
144
146
|
iconContainer: cnMerge(
|
|
145
|
-
icon
|
|
147
|
+
icon?.iconType === "nextIcon" && "rotate-180",
|
|
146
148
|
classNames?.iconContainer
|
|
147
149
|
)
|
|
148
150
|
},
|
|
149
|
-
icon: icon
|
|
151
|
+
icon: icon?.icon
|
|
150
152
|
}
|
|
151
153
|
), /* @__PURE__ */ React3.createElement(
|
|
152
154
|
CarouselButton,
|
|
@@ -155,13 +157,13 @@ function CarouselControls(props) {
|
|
|
155
157
|
classNames: {
|
|
156
158
|
defaultIcon: classNames?.defaultIcon,
|
|
157
159
|
iconContainer: cnMerge(
|
|
158
|
-
icon
|
|
160
|
+
icon?.iconType === "prevIcon" && "rotate-180",
|
|
159
161
|
classNames?.iconContainer
|
|
160
162
|
)
|
|
161
163
|
},
|
|
162
|
-
icon: icon
|
|
164
|
+
icon: icon?.icon
|
|
163
165
|
}
|
|
164
|
-
)
|
|
166
|
+
), /* @__PURE__ */ React3.createElement(show_parts_exports.Otherwise, null, /* @__PURE__ */ React3.createElement(
|
|
165
167
|
CarouselButton,
|
|
166
168
|
{
|
|
167
169
|
variant: "prev",
|
|
@@ -181,7 +183,7 @@ function CarouselControls(props) {
|
|
|
181
183
|
},
|
|
182
184
|
icon: icon?.next
|
|
183
185
|
}
|
|
184
|
-
)));
|
|
186
|
+
))));
|
|
185
187
|
}
|
|
186
188
|
function CarouselItemGroup(props) {
|
|
187
189
|
const { children, className, each, render } = props;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/carousel/carousel-store-context.tsx","../../../../../src/components/ui/carousel/icons.tsx","../../../../../src/components/ui/carousel/useCarouselOptions.ts","../../../../../src/components/ui/carousel/carousel.tsx","../../../../../src/components/ui/carousel/carousel-parts.ts"],"names":["React","React2"],"mappings":";;;;;;;;;;;AASA,IAAM,CAAC,QAAA,EAAU,uBAAuB,CAAA,GAAI,oBAAoC,CAAA;AAAA,EAC/E,QAAU,EAAA,kBAAA;AAAA,EACV,IAAM,EAAA,sBAAA;AAAA,EACN,YAAc,EAAA;AACf,CAAC,CAAA;AAGD,IAAM,mBAAA,GAAsB,CAC3B,WACI,KAAA;AACJ,EAAM,MAAA,EAAE,MAAQ,EAAA,eAAA,EAAoB,GAAA,WAAA;AAEpC,EAAA,MAAM,oBAAuB,GAAA,MAAA,EAAiC,CAAA,CAAC,KAAK,GAAS,MAAA;AAAA,IAC5E,YAAc,EAAA,CAAA;AAAA,IACd,MAAA;AAAA,IACA,QAAA,EAAU,OAAO,MAAS,GAAA,CAAA;AAAA;AAAA,IAG1B,OAAS,EAAA;AAAA;AAAA,MAGR,eAAe,MAAM;AACpB,QAAA,MAAM,EAAE,YAAA,EAAc,QAAS,EAAA,GAAI,GAAI,EAAA;AACvC,QAAA,MAAM,EAAE,SAAA,EAAc,GAAA,GAAA,EAAM,CAAA,OAAA;AAE5B,QAAA,IAAI,iBAAiB,QA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AA,iBAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\n\nimport { useConstant } from \"@zayne-labs/toolkit-react\";\nimport { createZustandContext } from \"@zayne-labs/toolkit-react/zustand\";\nimport type { PrettyOmit } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useEffect } from \"react\";\nimport { create } from \"zustand\";\nimport type { CarouselProviderProps, CarouselStore, ImagesType } from \"./types\";\n\nconst [Provider, useCarouselStoreContext] = createZustandContext<CarouselStore>({\n\thookName: \"useCarouselStore\",\n\tname: \"CarouselStoreContext\",\n\tproviderName: \"CarouselContextProvider\",\n});\n\n// CarouselStore Creation\nconst createCarouselStore = <TImages extends ImagesType>(\n\tstoreValues: PrettyOmit<CarouselProviderProps<TImages>, \"children\">\n) => {\n\tconst { images, onSlideBtnClick } = storeValues;\n\n\tconst useInitCarouselStore = create<CarouselStore<TImages>>()((set, get) => ({\n\t\tcurrentSlide: 0,\n\t\timages,\n\t\tmaxSlide: images.length - 1,\n\n\t\t/* eslint-disable perfectionist/sort-objects -- actions should be last */\n\t\tactions: {\n\t\t\t/* eslint-enable perfectionist/sort-objects -- actions should be last */\n\n\t\t\tgoToNextSlide: () => {\n\t\t\t\tconst { currentSlide, maxSlide } = get();\n\t\t\t\tconst { goToSlide } = get().actions;\n\n\t\t\t\tif (currentSlide === maxSlide) {\n\t\t\t\t\tgoToSlide(0);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tgoToSlide(currentSlide + 1);\n\t\t\t},\n\n\t\t\tgoToPreviousSlide: () => {\n\t\t\t\tconst { currentSlide, maxSlide } = get();\n\t\t\t\tconst { goToSlide } = get().actions;\n\n\t\t\t\tif (currentSlide === 0) {\n\t\t\t\t\tgoToSlide(maxSlide);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tgoToSlide(currentSlide - 1);\n\t\t\t},\n\n\t\t\tgoToSlide: (newValue) => {\n\t\t\t\tonSlideBtnClick?.();\n\n\t\t\t\tset({ currentSlide: newValue });\n\t\t\t},\n\t\t},\n\t}));\n\n\treturn useInitCarouselStore;\n};\n\nconst useCarousel = <TImages extends ImagesType>(\n\tprops: Omit<CarouselProviderProps<TImages>, \"children\">\n) => {\n\tconst { images, onSlideBtnClick } = props;\n\n\tconst useInitCarouselStore = useConstant(() => createCarouselStore({ images, onSlideBtnClick }));\n\n\t// == To set images again when a page is mounted, preventing stale images from previous page\n\tuseEffect(() => {\n\t\tuseInitCarouselStore.setState({ images });\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- useInitCarouselStore is stable\n\t}, [images]);\n\n\treturn useInitCarouselStore;\n};\n\n// == Provider Component\nfunction CarouselContextProvider<TImages extends ImagesType>(props: CarouselProviderProps<TImages>) {\n\tconst { children, images, onSlideBtnClick } = props;\n\n\tconst useInitCarouselStore = useCarousel({ images, onSlideBtnClick });\n\n\treturn <Provider value={useInitCarouselStore}>{children}</Provider>;\n}\n\n// eslint-disable-next-line react-refresh/only-export-components -- It's fine\nexport { useCarouselStoreContext, CarouselContextProvider };\n","import * as React from \"react\";\n\nexport const ChevronLeftIcon = (props: React.SVGProps<SVGSVGElement>) => (\n\t<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1em\" height=\"1em\" viewBox=\"0 0 24 24\" {...props}>\n\t\t<g fill=\"none\" stroke=\"currentColor\" strokeLinecap=\"round\" strokeLinejoin=\"round\" strokeWidth=\"2\">\n\t\t\t<circle cx=\"12\" cy=\"12\" r=\"10\" />\n\t\t\t<path d=\"m14 16l-4-4l4-4\" />\n\t\t</g>\n\t</svg>\n);\n","import { useAnimationInterval, useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport { useState } from \"react\";\nimport { useCarouselStoreContext } from \"./carousel-store-context\";\n\ntype CarouselOptions = {\n\tautoSlideInterval?: number;\n\thasAutoSlide?: boolean;\n\tshouldPauseOnHover?: boolean;\n};\n\nconst useCarouselOptions = (options: CarouselOptions = {}) => {\n\tconst { autoSlideInterval = 5000, hasAutoSlide = false, shouldPauseOnHover = false } = options;\n\n\tconst { goToNextSlide } = useCarouselStoreContext((state) => state.actions);\n\n\tconst [isPaused, setIsPaused] = useState(false);\n\n\tconst shouldAutoSlide = hasAutoSlide && !isPaused;\n\n\tuseAnimationInterval({\n\t\tintervalDuration: shouldAutoSlide ? autoSlideInterval : null,\n\t\tonAnimation: goToNextSlide,\n\t});\n\n\tconst pauseAutoSlide = useCallbackRef(() => shouldPauseOnHover && setIsPaused(true));\n\n\tconst resumeAutoSlide = useCallbackRef(() => shouldPauseOnHover && setIsPaused(false));\n\n\treturn { pauseAutoSlide, resumeAutoSlide };\n};\n\nexport { useCarouselOptions };\n","\"use client\";\n\nimport * as React from \"react\";\n\nimport { Show } from \"@/components/common\";\nimport { getElementList } from \"@/components/common/for\";\nimport { cnMerge } from \"@/lib/utils/cn\";\nimport type { CssWithCustomProperties, PolymorphicProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { useCarouselStoreContext } from \"./carousel-store-context\";\nimport { ChevronLeftIcon } from \"./icons\";\nimport type {\n\tCarouselButtonsProps,\n\tCarouselContentProps,\n\tCarouselControlProps,\n\tCarouselIndicatorProps,\n\tCarouselWrapperProps,\n\tOtherCarouselProps,\n} from \"./types\";\nimport { useCarouselOptions } from \"./useCarouselOptions\";\n\n// TODO - Add dragging and swiping support\nexport function CarouselContent<TElement extends React.ElementType = \"article\">(\n\tprops: PolymorphicProps<TElement, CarouselContentProps>\n) {\n\tconst {\n\t\tas: HtmlElement = \"article\",\n\t\tautoSlideInterval,\n\t\tchildren,\n\t\tclassNames,\n\t\thasAutoSlide,\n\t\tshouldPauseOnHover,\n\t} = props;\n\n\tconst { pauseAutoSlide, resumeAutoSlide } = useCarouselOptions({\n\t\tautoSlideInterval,\n\t\thasAutoSlide,\n\t\tshouldPauseOnHover,\n\t});\n\n\t// FIXME - Prevent touch swipe on mobile using a cover element or allow swipe but it must update the state appropriately\n\treturn (\n\t\t<HtmlElement\n\t\t\tdata-id=\"Carousel\"\n\t\t\tclassName={cnMerge(\"relative select-none\", classNames?.base)}\n\t\t\tonMouseEnter={pauseAutoSlide}\n\t\t\tonMouseLeave={resumeAutoSlide}\n\t\t>\n\t\t\t<div\n\t\t\t\tdata-id=\"Scroll Container\"\n\t\t\t\tclassName={cnMerge(\n\t\t\t\t\t\"flex size-full overflow-x-scroll [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\",\n\t\t\t\t\tclassNames?.scrollContainer\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t</HtmlElement>\n\t);\n}\n\nexport function CarouselButton(props: CarouselButtonsProps) {\n\tconst { classNames, icon, variant } = props;\n\n\tconst { goToNextSlide, goToPreviousSlide } = useCarouselStoreContext((state) => state.actions);\n\n\treturn (\n\t\t<button\n\t\t\ttype=\"button\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t\"z-30 flex h-full w-fit items-center\",\n\t\t\t\tvariant === \"prev\" ? \"justify-start\" : \"justify-end\",\n\t\t\t\tclassNames?.base\n\t\t\t)}\n\t\t\tonClick={variant === \"prev\" ? goToPreviousSlide : goToNextSlide}\n\t\t>\n\t\t\t<span className={cnMerge(\"transition-transform active:scale-[1.06]\", classNames?.iconContainer)}>\n\t\t\t\t{icon ?? (\n\t\t\t\t\t<ChevronLeftIcon\n\t\t\t\t\t\tclassName={cnMerge(variant === \"next\" && \"rotate-180\", classNames?.defaultIcon)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</span>\n\t\t</button>\n\t);\n}\n\nexport function CarouselControls(props: CarouselControlProps) {\n\tconst { classNames, icon } = props;\n\n\treturn (\n\t\t<div className={cnMerge(\"absolute inset-0 flex justify-between\", classNames?.base)}>\n\t\t\t<Show.Root when={icon?.iconType}>\n\t\t\t\t<CarouselButton\n\t\t\t\t\tvariant=\"prev\"\n\t\t\t\t\tclassNames={{\n\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\ticonContainer: cnMerge(\n\t\t\t\t\t\t\ticon?.iconType === \"nextIcon\" && \"rotate-180\",\n\t\t\t\t\t\t\tclassNames?.iconContainer\n\t\t\t\t\t\t),\n\t\t\t\t\t}}\n\t\t\t\t\ticon={icon?.icon}\n\t\t\t\t/>\n\n\t\t\t\t<CarouselButton\n\t\t\t\t\tvariant=\"next\"\n\t\t\t\t\tclassNames={{\n\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\ticonContainer: cnMerge(\n\t\t\t\t\t\t\ticon?.iconType === \"prevIcon\" && \"rotate-180\",\n\t\t\t\t\t\t\tclassNames?.iconContainer\n\t\t\t\t\t\t),\n\t\t\t\t\t}}\n\t\t\t\t\ticon={icon?.icon}\n\t\t\t\t/>\n\n\t\t\t\t<Show.Otherwise>\n\t\t\t\t\t<CarouselButton\n\t\t\t\t\t\tvariant=\"prev\"\n\t\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\t\ticonContainer: classNames?.iconContainer,\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ticon={icon?.prev}\n\t\t\t\t\t/>\n\n\t\t\t\t\t<CarouselButton\n\t\t\t\t\t\tvariant=\"next\"\n\t\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t\tdefaultIcon: classNames?.defaultIcon,\n\t\t\t\t\t\t\ticonContainer: classNames?.iconContainer,\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ticon={icon?.next}\n\t\t\t\t\t/>\n\t\t\t\t</Show.Otherwise>\n\t\t\t</Show.Root>\n\t\t</div>\n\t);\n}\n\nexport function CarouselItemGroup<TArrayItem>(props: CarouselWrapperProps<TArrayItem>) {\n\tconst { children, className, each, render } = props;\n\n\tconst [ItemList] = getElementList(\"base\");\n\tconst currentSlide = useCarouselStoreContext((state) => state.currentSlide);\n\tconst images = useCarouselStoreContext((state) => each ?? (state.images as TArrayItem[]));\n\n\treturn (\n\t\t<ul\n\t\t\tdata-id=\"Carousel Image Wrapper\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t`flex w-full shrink-0 snap-center [transform:translate3d(var(--translate-distance),0,0)]\n\t\t\t\t[transition:transform_800ms_ease]`,\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tstyle={\n\t\t\t\t{\n\t\t\t\t\t\"--translate-distance\": `-${currentSlide * 100}%`,\n\t\t\t\t} satisfies CssWithCustomProperties as CssWithCustomProperties\n\t\t\t}\n\t\t>\n\t\t\t{typeof render === \"function\" ? (\n\t\t\t\t<ItemList each={images} render={render} />\n\t\t\t) : (\n\t\t\t\t<ItemList each={images}>{children}</ItemList>\n\t\t\t)}\n\t\t</ul>\n\t);\n}\n\nexport function CarouselItem({ children, className, ...restOfProps }: OtherCarouselProps) {\n\treturn (\n\t\t<li\n\t\t\tclassName={cnMerge(\"flex w-full shrink-0 snap-center justify-center\", className)}\n\t\t\t{...restOfProps}\n\t\t>\n\t\t\t{children}\n\t\t</li>\n\t);\n}\n\nexport function CarouselCaption<TElement extends React.ElementType = \"div\">(\n\tprops: PolymorphicProps<TElement, OtherCarouselProps>\n) {\n\tconst { as: HtmlElement = \"div\", children, className } = props;\n\n\treturn (\n\t\t<HtmlElement data-id=\"Carousel Caption\" className={cnMerge(\"absolute z-10\", className)}>\n\t\t\t{children}\n\t\t</HtmlElement>\n\t);\n}\n\nexport function CarouselIndicatorGroup<TArrayItem>(props: CarouselWrapperProps<TArrayItem>) {\n\tconst { children, className, each, render } = props;\n\n\tconst images = useCarouselStoreContext((state) => each ?? (state.images as TArrayItem[]));\n\tconst [IndicatorList] = getElementList(\"base\");\n\n\treturn (\n\t\t<ul\n\t\t\tdata-id=\"Carousel Indicators\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t\"absolute bottom-[25px] z-[2] flex w-full items-center justify-center gap-[15px]\",\n\t\t\t\tclassName\n\t\t\t)}\n\t\t>\n\t\t\t{typeof render === \"function\" ? (\n\t\t\t\t<IndicatorList each={images} render={render} />\n\t\t\t) : (\n\t\t\t\t<IndicatorList each={images}>{children}</IndicatorList>\n\t\t\t)}\n\t\t</ul>\n\t);\n}\n\nexport function CarouselIndicator(props: CarouselIndicatorProps) {\n\tconst { classNames, currentIndex } = props;\n\n\tconst {\n\t\tactions: { goToSlide },\n\t\tcurrentSlide,\n\t} = useCarouselStoreContext((state) => state);\n\n\treturn (\n\t\t<li className={cnMerge(\"inline-flex\", classNames?.base)}>\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tonClick={() => goToSlide(currentIndex)}\n\t\t\t\tclassName={cnMerge(\n\t\t\t\t\t\"size-[6px] rounded-[50%]\",\n\t\t\t\t\tclassNames?.base,\n\t\t\t\t\tcurrentIndex === currentSlide && [\"w-[35px] rounded-[5px]\", classNames?.isActive]\n\t\t\t\t)}\n\t\t\t/>\n\t\t</li>\n\t);\n}\n","export { CarouselContextProvider as Root } from \"./carousel-store-context\";\nexport {\n\tCarouselContent as Content,\n\tCarouselControls as Controls,\n\tCarouselButton as Button,\n\tCarouselItem as Item,\n\tCarouselItemGroup as ItemGroup,\n\tCarouselCaption as Caption,\n\tCarouselIndicator as Indicator,\n\tCarouselIndicatorGroup as IndicatorGroup,\n} from \"./carousel\";\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { cnMerge } from '
|
|
2
|
-
import '
|
|
1
|
+
import { cnMerge } from '../../../chunk-OHG7GB7O.js';
|
|
2
|
+
import '../../../chunk-PZ5AY32C.js';
|
|
3
3
|
import { off, on, checkIsDeviceMobile } from '@zayne-labs/toolkit-core';
|
|
4
4
|
import { useCallbackRef } from '@zayne-labs/toolkit-react';
|
|
5
5
|
import { mergeTwoProps, composeRefs } from '@zayne-labs/toolkit-react/utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/drag-scroll/utils.ts","../../../../../src/components/ui/drag-scroll/use-drag-scroll.ts"],"names":[],"mappings":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;AAAA,QACV,CAAA;AAAA,qBAAA,CAAA;AAAA,QAEA,gBAAgB,YAAgB,IAAA,UAAA;AAAA,QAChC,gBAAgB,UAAc,IAAA,UAAA;AAAA,QAC9B,UAAU,qBAAyB,IAAA,+BAAA;AAAA,QACnC,UAAU,aAAiB,IAAA,uCAAA;AAAA,QAC3B,UAAY,EAAA,IAAA;AAAA,QACZ,eAAgB,CAAA;AAAA,OACjB;AAAA,MACA,WAAa,EAAA,MAAA;AAAA,MACb,YAAc,EAAA,aAAA;AAAA,MACd,WAAa,EAAA,kBAAA;AAAA,MACb,GAAK,EAAA,WAAA;AAAA,QACJ,WAAA;AAAA,QACC,eAA+D,EAAA;AAAA;AACjE,KACD;AAAA,GACD;AAEA,EAAM,MAAA,YAAA,GAAyE,CAAC,SAAc,KAAA;AAC7F,IAAM,MAAA,eAAA,GAAkB,aAAc,CAAA,cAAA,EAAgB,SAAS,CAAA;AAE/D,IAAO,OAAA;AAAA,MACN,GAAG,eAAA;AAAA,MACH,WAAW,OAAQ,CAAA,yBAAA,EAA2B,UAAY,EAAA,IAAA,EAAM,gBAAgB,SAAS,CAAA;AAAA,MACzF,WAAa,EAAA,MAAA;AAAA,MACb,YAAc,EAAA,aAAA;AAAA,MACd,WAAa,EAAA;AAAA,KACd;AAAA,GACD;AAEA,EAAO,OAAA,EAAE,cAAc,YAAa,EAAA;AACrC","file":"index.js","sourcesContent":["import { checkIsDeviceMobile } from \"@zayne-labs/toolkit-core\";\n\n/* eslint-disable no-param-reassign -- Mutation is needed here since it's an element */\nexport const updateCursor = <TElement extends HTMLElement>(element: TElement) => {\n\telement.style.cursor = \"grabbing\";\n\telement.style.userSelect = \"none\";\n};\n\nexport const onScrollSnap = <TElement extends HTMLElement>(\n\taction: \"remove\" | \"reset\",\n\telement: TElement\n) => {\n\tif (action === \"remove\") {\n\t\telement.style.scrollSnapType = \"none\";\n\t\treturn;\n\t}\n\n\telement.style.scrollSnapType = \"\";\n};\n\nexport const resetCursor = <TElement extends HTMLElement>(element: TElement) => {\n\telement.style.cursor = \"\";\n\telement.style.userSelect = \"\";\n};\n/* eslint-enable no-param-reassign -- Mutation is needed here since it's an element */\n\nexport const handleScrollSnap = (dragContainer: HTMLElement) => {\n\tconst isMobile = checkIsDeviceMobile();\n\n\tif (!isMobile) {\n\t\tonScrollSnap(\"remove\", dragContainer);\n\t} else {\n\t\tonScrollSnap(\"reset\", dragContainer);\n\t}\n};\n","import { cnMerge } from \"@/lib/utils/cn\";\nimport { off, on } from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport { type InferProps, composeRefs, mergeTwoProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { type RefCallback, useRef } from \"react\";\nimport { handleScrollSnap, resetCursor, updateCursor } from \"./utils\";\n\ntype ItemProps<TItemElement extends HTMLElement> = Omit<InferProps<TItemElement>, \"children\">;\n\ntype RootProps<TElement extends HTMLElement> = Omit<InferProps<TElement>, \"children\">;\n\ntype DragScrollProps<TElement extends HTMLElement, TItemElement extends HTMLElement> = {\n\tclassNames?: { base?: string; item?: string };\n\textraItemProps?: ItemProps<TItemElement>;\n\textraRootProps?: InferProps<TElement>;\n\torientation?: \"both\" | \"horizontal\" | \"vertical\";\n\tusage?: \"allScreens\" | \"desktopOnly\" | \"mobileAndTabletOnly\";\n};\n\ntype DragScrollResult<TElement extends HTMLElement, TItemElement extends HTMLElement> = {\n\tgetItemProps: (itemProps?: ItemProps<TItemElement>) => ItemProps<TItemElement>;\n\tgetRootProps: (rootProps?: RootProps<TElement>) => RootProps<TElement>;\n};\n\nconst useDragScroll = <TElement extends HTMLElement, TItemElement extends HTMLElement = HTMLElement>(\n\tprops?: DragScrollProps<TElement, TItemElement>\n): DragScrollResult<TElement, TItemElement> => {\n\tconst {\n\t\tclassNames,\n\t\textraItemProps,\n\t\textraRootProps,\n\t\torientation = \"horizontal\",\n\t\tusage = \"allScreens\",\n\t} = props ?? {};\n\n\tconst dragContainerRef = useRef<TElement>(null);\n\n\tconst positionRef = useRef({ left: 0, top: 0, x: 0, y: 0 });\n\n\tconst handleMouseMove = useCallbackRef((event: MouseEvent) => {\n\t\tif (!dragContainerRef.current) return;\n\n\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\t// == calculate the current change in the horizontal scroll position based on the difference between the previous mouse position and the new mouse position\n\t\t\tconst dx = event.clientX - positionRef.current.x;\n\n\t\t\t// == Assign the scrollLeft of the container to the difference between its previous horizontal scroll position and the change in the mouse position\n\t\t\tdragContainerRef.current.scrollLeft = positionRef.current.left - dx;\n\t\t}\n\n\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\t// == calculate the current change in the vertical scroll position based on the difference between the previous mouse position and the new mouse position\n\t\t\tconst dy = event.clientY - positionRef.current.y;\n\n\t\t\t// == Assign the scrollTop of the container to the difference between its previous vertical scroll position and the change in the mouse position\n\t\t\tdragContainerRef.current.scrollTop = positionRef.current.top - dy;\n\t\t}\n\t});\n\n\tconst handleMouseUpOrLeave = useCallbackRef(() => {\n\t\tif (!dragContainerRef.current) return;\n\n\t\toff(\"mousemove\", dragContainerRef.current, handleMouseMove);\n\t\toff(\"mouseup\", dragContainerRef.current, handleMouseUpOrLeave);\n\t\toff(\"mouseleave\", dragContainerRef.current, handleMouseUpOrLeave);\n\n\t\tresetCursor(dragContainerRef.current);\n\t});\n\n\tconst handleMouseDown = useCallbackRef((event: MouseEvent) => {\n\t\tif (usage === \"mobileAndTabletOnly\" && window.innerWidth >= 768) return;\n\t\tif (usage === \"desktopOnly\" && window.innerWidth < 768) return;\n\n\t\tif (!dragContainerRef.current) return;\n\n\t\t// == Update all initial position properties stored in the positionRef\n\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\tpositionRef.current.x = event.clientX;\n\t\t\tpositionRef.current.left = dragContainerRef.current.scrollLeft;\n\t\t}\n\n\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\tpositionRef.current.y = event.clientY;\n\t\t\tpositionRef.current.top = dragContainerRef.current.scrollTop;\n\t\t}\n\n\t\tupdateCursor(dragContainerRef.current);\n\n\t\ton(\"mousemove\", dragContainerRef.current, handleMouseMove);\n\t\ton(\"mouseup\", dragContainerRef.current, handleMouseUpOrLeave);\n\t\ton(\"mouseleave\", dragContainerRef.current, handleMouseUpOrLeave);\n\t});\n\n\tconst refCallBack: RefCallback<TElement> = useCallbackRef((node) => {\n\t\tdragContainerRef.current = node;\n\n\t\tnode && handleScrollSnap(node);\n\n\t\tconst cleanup = on(\"mousedown\", dragContainerRef.current, handleMouseDown);\n\n\t\treturn cleanup;\n\t});\n\n\tconst getRootProps: DragScrollResult<TElement, TItemElement>[\"getRootProps\"] = (rootProps) => {\n\t\tconst mergedRootProps = mergeTwoProps(extraRootProps, rootProps);\n\n\t\treturn {\n\t\t\t...mergedRootProps,\n\t\t\tclassName: cnMerge(\n\t\t\t\t`scrollbar-hidden flex w-full cursor-grab snap-x snap-mandatory overflow-y-hidden\n\t\t\t\toverflow-x-scroll`,\n\t\t\t\torientation === \"horizontal\" && \"flex-row\",\n\t\t\t\torientation === \"vertical\" && \"flex-col\",\n\t\t\t\tusage === \"mobileAndTabletOnly\" && \"md:cursor-default md:flex-col\",\n\t\t\t\tusage === \"desktopOnly\" && \"max-md:cursor-default max-md:flex-col\",\n\t\t\t\tclassNames?.base,\n\t\t\t\tmergedRootProps.className\n\t\t\t),\n\t\t\t\"data-part\": \"root\",\n\t\t\t\"data-scope\": \"drag-scroll\",\n\t\t\t\"data-slot\": \"drag-scroll-root\",\n\t\t\tref: composeRefs(\n\t\t\t\trefCallBack,\n\t\t\t\t(mergedRootProps as { ref?: React.Ref<TElement> } | undefined)?.ref\n\t\t\t),\n\t\t};\n\t};\n\n\tconst getItemProps: DragScrollResult<TElement, TItemElement>[\"getItemProps\"] = (itemProps) => {\n\t\tconst mergedItemProps = mergeTwoProps(extraItemProps, itemProps);\n\n\t\treturn {\n\t\t\t...mergedItemProps,\n\t\t\tclassName: cnMerge(\"snap-center snap-always\", classNames?.item, mergedItemProps.className),\n\t\t\t\"data-part\": \"item\",\n\t\t\t\"data-scope\": \"drag-scroll\",\n\t\t\t\"data-slot\": \"drag-scroll-item\",\n\t\t};\n\t};\n\n\treturn { getItemProps, getRootProps };\n};\n\nexport { useDragScroll };\n"]}
|