@zayne-labs/ui-react 0.9.15 → 0.9.17
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-BC0r1cBF.d.ts +104 -0
- package/dist/esm/index-BPeZJS-v.d.ts +191 -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-C4ub0yqe.d.ts +49 -0
- package/dist/esm/index-CTZr4PTO.d.ts +24 -0
- package/dist/esm/index-DKfm0Dyj.d.ts +61 -0
- package/dist/esm/index-DQ1yFGd2.d.ts +229 -0
- package/dist/esm/index-DmOz1yDZ.d.ts +14 -0
- package/dist/esm/index-DnaUCh8d.d.ts +15 -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 +5 -5
- package/dist/esm/await-parts-BJ6C-y1f.d.ts +0 -36
- package/dist/esm/chunk-2DHK7TOF.js +0 -336
- package/dist/esm/chunk-2DHK7TOF.js.map +0 -1
- package/dist/esm/chunk-3KZXPREF.js +0 -626
- package/dist/esm/chunk-3KZXPREF.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-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-KLEJZWKY.js +0 -45
- package/dist/esm/chunk-KLEJZWKY.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-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-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-Y5VBSXZS.js +0 -55
- package/dist/esm/chunk-Y5VBSXZS.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-Z6JJE4G6.js +0 -68
- package/dist/esm/chunk-Z6JJE4G6.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
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { createCustomContext, useCallbackRef } from '@zayne-labs/toolkit-react';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { useState, Component } from 'react';
|
|
4
|
-
import { isFunction } from '@zayne-labs/toolkit-type-helpers';
|
|
5
|
-
|
|
6
|
-
// src/components/common/error-boundary/error-boundary-context.ts
|
|
7
|
-
var [ErrorBoundaryContext, useErrorBoundaryContext] = createCustomContext({
|
|
8
|
-
hookName: "useErrorBoundaryContext",
|
|
9
|
-
name: "ErrorBoundaryContext",
|
|
10
|
-
providerName: "ErrorBoundaryContextProvider"
|
|
11
|
-
});
|
|
12
|
-
var useErrorBoundary = () => {
|
|
13
|
-
const { resetErrorBoundary } = useErrorBoundaryContext();
|
|
14
|
-
const [state, setState] = useState({
|
|
15
|
-
error: null,
|
|
16
|
-
hasError: false
|
|
17
|
-
});
|
|
18
|
-
if (state.hasError) {
|
|
19
|
-
throw state.error;
|
|
20
|
-
}
|
|
21
|
-
const resetBoundary = useCallbackRef(() => {
|
|
22
|
-
resetErrorBoundary();
|
|
23
|
-
setState({
|
|
24
|
-
error: null,
|
|
25
|
-
hasError: false
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
const showBoundary = useCallbackRef((error) => {
|
|
29
|
-
setState({
|
|
30
|
-
error,
|
|
31
|
-
hasError: true
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
return { resetBoundary, showBoundary };
|
|
35
|
-
};
|
|
36
|
-
var initialState = {
|
|
37
|
-
error: null,
|
|
38
|
-
hasError: false
|
|
39
|
-
};
|
|
40
|
-
var hasArrayChanged = (arrayOne = [], arrayTwo = []) => {
|
|
41
|
-
return arrayOne.length !== arrayTwo.length || arrayOne.some((item, index) => !Object.is(item, arrayTwo[index]));
|
|
42
|
-
};
|
|
43
|
-
var ErrorBoundary = class extends Component {
|
|
44
|
-
constructor(props) {
|
|
45
|
-
super(props);
|
|
46
|
-
this.state = initialState;
|
|
47
|
-
}
|
|
48
|
-
static getDerivedStateFromError(error) {
|
|
49
|
-
return { error, hasError: true };
|
|
50
|
-
}
|
|
51
|
-
componentDidCatch(error, info) {
|
|
52
|
-
this.props.onError?.({
|
|
53
|
-
error,
|
|
54
|
-
info
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
componentDidUpdate(prevProps, prevState) {
|
|
58
|
-
const { hasError } = this.state;
|
|
59
|
-
const { resetKeys } = this.props;
|
|
60
|
-
if (hasError && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
61
|
-
this.props.onReset?.({
|
|
62
|
-
next: resetKeys,
|
|
63
|
-
prev: prevProps.resetKeys,
|
|
64
|
-
reason: "keys"
|
|
65
|
-
});
|
|
66
|
-
this.setState(initialState);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
render() {
|
|
70
|
-
const { children, fallback } = this.props;
|
|
71
|
-
const { error, hasError } = this.state;
|
|
72
|
-
let childToRender = children;
|
|
73
|
-
if (hasError) {
|
|
74
|
-
switch (true) {
|
|
75
|
-
case isFunction(fallback): {
|
|
76
|
-
const fallbackRenderProps = {
|
|
77
|
-
error,
|
|
78
|
-
resetErrorBoundary: this.#resetErrorBoundary
|
|
79
|
-
};
|
|
80
|
-
childToRender = fallback(fallbackRenderProps);
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
case Boolean(fallback): {
|
|
84
|
-
childToRender = fallback;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
default: {
|
|
88
|
-
console.warn("No fallback provided to error boundary");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const contextValue = {
|
|
93
|
-
error,
|
|
94
|
-
hasError,
|
|
95
|
-
resetErrorBoundary: this.#resetErrorBoundary
|
|
96
|
-
};
|
|
97
|
-
return /* @__PURE__ */ React.createElement(ErrorBoundaryContext, { value: contextValue }, childToRender);
|
|
98
|
-
}
|
|
99
|
-
#resetErrorBoundary = (...parameters) => {
|
|
100
|
-
const { error } = this.state;
|
|
101
|
-
if (error !== null) {
|
|
102
|
-
this.props.onReset?.({
|
|
103
|
-
args: parameters,
|
|
104
|
-
reason: "imperative-api"
|
|
105
|
-
});
|
|
106
|
-
this.setState(initialState);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export { ErrorBoundary, useErrorBoundary, useErrorBoundaryContext };
|
|
112
|
-
//# sourceMappingURL=chunk-JC52CA2O.js.map
|
|
113
|
-
//# sourceMappingURL=chunk-JC52CA2O.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/common/error-boundary/error-boundary-context.ts","../../src/components/common/error-boundary/useErrorBoundary.ts","../../src/components/common/error-boundary/error-boundary.tsx"],"names":[],"mappings":";;;;;;AAQO,IAAM,CAAC,oBAAA,EAAsB,uBAAuB,CAAA,GAC1D,mBAA8C,CAAA;AAAA,EAC7C,QAAU,EAAA,yBAAA;AAAA,EACV,IAAM,EAAA,sBAAA;AAAA,EACN,YAAc,EAAA;AACf,CAAC;ACCK,IAAM,mBAAmB,MAA4B;AAC3D,EAAM,MAAA,EAAE,kBAAmB,EAAA,GAAI,uBAAwB,EAAA;AAEvD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,QAAwC,CAAA;AAAA,IACjE,KAAO,EAAA,IAAA;AAAA,IACP,QAAU,EAAA;AAAA,GACV,CAAA;AAED,EAAA,IAAI,MAAM,QAAU,EAAA;AACnB,IAAA,MAAM,KAAM,CAAA,KAAA;AAAA;AAGb,EAAM,MAAA,aAAA,GAAgB,eAAe,MAAM;AAC1C,IAAmB,kBAAA,EAAA;AAEnB,IAAS,QAAA,CAAA;AAAA,MACR,KAAO,EAAA,IAAA;AAAA,MACP,QAAU,EAAA;AAAA,KACV,CAAA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AI,UAAU,IAAM,EAAA;AACnB,MAAA,IAAA,CAAK,MAAM,OAAU,GAAA;AAAA,QACpB,IAAM,EAAA,UAAA;AAAA,QACN,MAAQ,EAAA;AAAA,OACR,CAAA;AAED,MAAA,IAAA,CAAK,SAAS,YAAY,CAAA;AAAA;AAC3B,GACD;AACD","file":"chunk-JC52CA2O.js","sourcesContent":["import { createCustomContext } from \"@zayne-labs/toolkit-react\";\n\nexport type ErrorBoundaryContextType = {\n\terror: unknown;\n\thasError: boolean;\n\tresetErrorBoundary: (...args: unknown[]) => void;\n};\n\nexport const [ErrorBoundaryContext, useErrorBoundaryContext] =\n\tcreateCustomContext<ErrorBoundaryContextType>({\n\t\thookName: \"useErrorBoundaryContext\",\n\t\tname: \"ErrorBoundaryContext\",\n\t\tproviderName: \"ErrorBoundaryContextProvider\",\n\t});\n","import { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport { useState } from \"react\";\nimport { useErrorBoundaryContext } from \"./error-boundary-context\";\n\ntype UseErrorBoundaryState<TError extends Error> =\n\t| {\n\t\t\terror: null;\n\t\t\thasError: false;\n\t }\n\t| {\n\t\t\terror: TError;\n\t\t\thasError: true;\n\t };\n\nexport const useErrorBoundary = <TError extends Error>() => {\n\tconst { resetErrorBoundary } = useErrorBoundaryContext();\n\n\tconst [state, setState] = useState<UseErrorBoundaryState<TError>>({\n\t\terror: null,\n\t\thasError: false,\n\t});\n\n\tif (state.hasError) {\n\t\tthrow state.error;\n\t}\n\n\tconst resetBoundary = useCallbackRef(() => {\n\t\tresetErrorBoundary();\n\n\t\tsetState({\n\t\t\terror: null,\n\t\t\thasError: false,\n\t\t});\n\t});\n\n\tconst showBoundary = useCallbackRef((error: TError) => {\n\t\tsetState({\n\t\t\terror,\n\t\t\thasError: true,\n\t\t});\n\t});\n\n\treturn { resetBoundary, showBoundary };\n};\n","import { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport * as React from \"react\";\nimport { Component } from \"react\";\nimport { ErrorBoundaryContext, type ErrorBoundaryContextType } from \"./error-boundary-context\";\nimport type { ErrorBoundaryProps, FallbackProps } from \"./types\";\n\ntype ErrorBoundaryState =\n\t| {\n\t\t\terror: Error;\n\t\t\thasError: true;\n\t }\n\t| {\n\t\t\terror: null;\n\t\t\thasError: false;\n\t };\n\nconst initialState: ErrorBoundaryState = {\n\terror: null,\n\thasError: false,\n};\n\nconst hasArrayChanged = (arrayOne: unknown[] = [], arrayTwo: unknown[] = []) => {\n\treturn (\n\t\tarrayOne.length !== arrayTwo.length\n\t\t|| arrayOne.some((item, index) => !Object.is(item, arrayTwo[index]))\n\t);\n};\n\n/**\n * Copied from react-error-boundary package\n * @see https://github.com/bvaughn/react-error-boundary\n */\n\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n\tconstructor(props: ErrorBoundaryProps) {\n\t\tsuper(props);\n\n\t\tthis.state = initialState;\n\t}\n\n\tstatic getDerivedStateFromError(error: Error) {\n\t\treturn { error, hasError: true };\n\t}\n\n\toverride componentDidCatch(error: Error, info: React.ErrorInfo) {\n\t\tthis.props.onError?.({\n\t\t\terror,\n\t\t\tinfo,\n\t\t});\n\t}\n\n\toverride componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: ErrorBoundaryState) {\n\t\tconst { hasError } = this.state;\n\t\tconst { resetKeys } = this.props;\n\n\t\t// == There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array, we'd end up resetting the error boundary immediately.\n\t\t// == This would likely trigger a second error to be thrown.\n\t\t// == So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.\n\n\t\tif (hasError && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {\n\t\t\tthis.props.onReset?.({\n\t\t\t\tnext: resetKeys,\n\t\t\t\tprev: prevProps.resetKeys,\n\t\t\t\treason: \"keys\",\n\t\t\t});\n\n\t\t\tthis.setState(initialState);\n\t\t}\n\t}\n\n\toverride render() {\n\t\tconst { children, fallback } = this.props;\n\t\tconst { error, hasError } = this.state;\n\n\t\tlet childToRender = children;\n\n\t\tif (hasError) {\n\t\t\tswitch (true) {\n\t\t\t\tcase isFunction(fallback): {\n\t\t\t\t\tconst fallbackRenderProps = {\n\t\t\t\t\t\terror,\n\t\t\t\t\t\tresetErrorBoundary: this.#resetErrorBoundary,\n\t\t\t\t\t} satisfies FallbackProps;\n\n\t\t\t\t\tchildToRender = fallback(fallbackRenderProps);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase Boolean(fallback): {\n\t\t\t\t\tchildToRender = fallback;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tconsole.warn(\"No fallback provided to error boundary\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst contextValue = {\n\t\t\terror,\n\t\t\thasError,\n\t\t\tresetErrorBoundary: this.#resetErrorBoundary,\n\t\t} satisfies ErrorBoundaryContextType;\n\n\t\treturn <ErrorBoundaryContext value={contextValue}>{childToRender}</ErrorBoundaryContext>;\n\t}\n\n\t#resetErrorBoundary = (...parameters: unknown[]) => {\n\t\tconst { error } = this.state;\n\n\t\tif (error !== null) {\n\t\t\tthis.props.onReset?.({\n\t\t\t\targs: parameters,\n\t\t\t\treason: \"imperative-api\",\n\t\t\t});\n\n\t\t\tthis.setState(initialState);\n\t\t}\n\t};\n}\n"]}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { cnMerge } from './chunk-OHG7GB7O.js';
|
|
2
|
-
import { slot_parts_exports } from './chunk-Y5VBSXZS.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-KLEJZWKY.js.map
|
|
45
|
-
//# sourceMappingURL=chunk-KLEJZWKY.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/ui/card/card.tsx","../../src/components/ui/card/card-parts.ts"],"names":[],"mappings":";;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,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-KLEJZWKY.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"]}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { getMultipleSlots } from './chunk-YO5LJ7ZJ.js';
|
|
2
|
-
import { __export } from './chunk-PZ5AY32C.js';
|
|
3
|
-
import 'react';
|
|
4
|
-
import { isFunction, assert } from '@zayne-labs/toolkit-type-helpers';
|
|
5
|
-
|
|
6
|
-
function ShowRoot(props) {
|
|
7
|
-
const { children, fallback, when } = props;
|
|
8
|
-
const resolvedChildren = isFunction(children) ? children(when) : children;
|
|
9
|
-
const {
|
|
10
|
-
regularChildren,
|
|
11
|
-
slots: [contentSlot, fallBackSlot]
|
|
12
|
-
} = getMultipleSlots(resolvedChildren, [ShowContent, ShowFallback], {
|
|
13
|
-
errorMessage: [
|
|
14
|
-
"Only one <Show.Content> component is allowed",
|
|
15
|
-
"Only one <Show.Fallback> or <Show.OtherWise> component is allowed"
|
|
16
|
-
],
|
|
17
|
-
throwOnMultipleSlotMatch: true
|
|
18
|
-
});
|
|
19
|
-
if (!when) {
|
|
20
|
-
assert(
|
|
21
|
-
!(fallBackSlot && fallback),
|
|
22
|
-
"The fallback prop and <Show.Fallback> cannot be used at the same time."
|
|
23
|
-
);
|
|
24
|
-
return fallBackSlot ?? fallback;
|
|
25
|
-
}
|
|
26
|
-
return contentSlot ?? regularChildren;
|
|
27
|
-
}
|
|
28
|
-
function ShowContent({ children }) {
|
|
29
|
-
return children;
|
|
30
|
-
}
|
|
31
|
-
ShowContent.slotSymbol = Symbol("show-content");
|
|
32
|
-
function ShowFallback({ children }) {
|
|
33
|
-
return children;
|
|
34
|
-
}
|
|
35
|
-
ShowFallback.slotSymbol = Symbol("show-fallback");
|
|
36
|
-
|
|
37
|
-
// src/components/common/show/show-parts.ts
|
|
38
|
-
var show_parts_exports = {};
|
|
39
|
-
__export(show_parts_exports, {
|
|
40
|
-
Content: () => ShowContent,
|
|
41
|
-
Fallback: () => ShowFallback,
|
|
42
|
-
Otherwise: () => ShowFallback,
|
|
43
|
-
Root: () => ShowRoot
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export { ShowContent, ShowFallback, ShowRoot, show_parts_exports };
|
|
47
|
-
//# sourceMappingURL=chunk-M7YXNGT6.js.map
|
|
48
|
-
//# sourceMappingURL=chunk-M7YXNGT6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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-M7YXNGT6.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,13 +0,0 @@
|
|
|
1
|
-
import { ErrorBoundary } from './chunk-JC52CA2O.js';
|
|
2
|
-
import { Suspense } from 'react';
|
|
3
|
-
|
|
4
|
-
function SuspenseWithBoundary(props) {
|
|
5
|
-
const { children, errorFallback, fallback } = props;
|
|
6
|
-
const errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };
|
|
7
|
-
const suspenseProps = Boolean(fallback) && { fallback };
|
|
8
|
-
return /* @__PURE__ */ React.createElement(ErrorBoundary, { ...errorBoundaryProps }, /* @__PURE__ */ React.createElement(Suspense, { ...suspenseProps }, children));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { SuspenseWithBoundary };
|
|
12
|
-
//# sourceMappingURL=chunk-MT2MQDK2.js.map
|
|
13
|
-
//# sourceMappingURL=chunk-MT2MQDK2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/common/suspense-with-boundary/suspense-with-boundary.tsx"],"names":[],"mappings":";;;AASO,SAAS,qBAAqB,KAAkC,EAAA;AACtE,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":"chunk-MT2MQDK2.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 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"]}
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
if (slotName === "default") {
|
|
27
|
-
slots.default.push(child);
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
slots[slotName] = child;
|
|
31
|
-
}
|
|
32
|
-
return slots;
|
|
33
|
-
};
|
|
34
|
-
var createSlotComponent = () => {
|
|
35
|
-
const SlotComponent = (props) => props.children;
|
|
36
|
-
SlotComponent.slotSymbol = slotComponentSymbol;
|
|
37
|
-
return SlotComponent;
|
|
38
|
-
};
|
|
39
|
-
function DefaultSlotComponent(props) {
|
|
40
|
-
return props.children;
|
|
41
|
-
}
|
|
42
|
-
var withSlotNameAndSymbol = (name, SlotComponent = DefaultSlotComponent) => {
|
|
43
|
-
SlotComponent.slotSymbol = slotComponentSymbol;
|
|
44
|
-
SlotComponent.slotName = name;
|
|
45
|
-
return SlotComponent;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export { createSlotComponent, getSlotMap, slotComponentSymbol, withSlotNameAndSymbol };
|
|
49
|
-
//# sourceMappingURL=chunk-N4274N5K.js.map
|
|
50
|
-
//# sourceMappingURL=chunk-N4274N5K.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/utils/getSlotMap/getSlotMap.ts"],"names":["ReactFragment"],"mappings":";;;;;AAqCa,IAAA,mBAAA,GAAsB,OAAO,gBAAgB;AAkC7C,IAAA,UAAA,GAAa,CACzB,QACqD,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;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AAA;AAGJ,EAAA,aAAA,CAAc,UAAa,GAAA,mBAAA;AAE3B,EAAA,aAAA,CAAc,QAAW,GAAA,IAAA;AAIzB,EAAO,OAAA,aAAA;AACR","file":"chunk-N4274N5K.js","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"]}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { isNumber, isArray } from '@zayne-labs/toolkit-type-helpers';
|
|
3
|
-
|
|
4
|
-
// src/components/common/for/for.tsx
|
|
5
|
-
function For(props) {
|
|
6
|
-
const { children, each, fallback = null, render } = props;
|
|
7
|
-
if (each == null || isNumber(each) && each === 0 || isArray(each) && each.length === 0) {
|
|
8
|
-
return fallback;
|
|
9
|
-
}
|
|
10
|
-
const resolvedArray = isNumber(each) ? [...Array(each).keys()] : each;
|
|
11
|
-
if (resolvedArray.length === 0) {
|
|
12
|
-
return fallback;
|
|
13
|
-
}
|
|
14
|
-
const JSXElementList = resolvedArray.map((...params) => {
|
|
15
|
-
return typeof children === "function" ? children(...params) : render(...params);
|
|
16
|
-
});
|
|
17
|
-
return JSXElementList;
|
|
18
|
-
}
|
|
19
|
-
function ForWithWrapper(props) {
|
|
20
|
-
const { as: ListContainer = "ul", children, className, each, ref, render, ...restOfListProps } = props;
|
|
21
|
-
return /* @__PURE__ */ React.createElement(ListContainer, { ref, className, ...restOfListProps }, /* @__PURE__ */ React.createElement(For, { ...{ children, each, render } }));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// src/components/common/for/getElementList.ts
|
|
25
|
-
var getElementList = (variant) => {
|
|
26
|
-
switch (variant) {
|
|
27
|
-
case "base": {
|
|
28
|
-
return [For];
|
|
29
|
-
}
|
|
30
|
-
case "withWrapper": {
|
|
31
|
-
return [ForWithWrapper];
|
|
32
|
-
}
|
|
33
|
-
default: {
|
|
34
|
-
return [ForWithWrapper];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export { For, ForWithWrapper, getElementList };
|
|
40
|
-
//# sourceMappingURL=chunk-NXZZXJRH.js.map
|
|
41
|
-
//# sourceMappingURL=chunk-NXZZXJRH.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/common/for/for.tsx","../../src/components/common/for/getElementList.ts"],"names":[],"mappings":";;;;AAwBO,SAA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OAAS;AAAA,IAChB,KAAK,MAAQ,EAAA;AACZ,MAAA,OAAO,CAAC,GAAG,CAAA;AAAA;AACZ,IACA,KAAK,aAAe,EAAA;AACnB,MAAA,OAAO,CAAC,cAAc,CAAA;AAAA;AACvB,IACA,SAAS;AACR,MAAA,OAAO,CAAC,cAAc,CAAA;AAAA;AACvB;AAEF","file":"chunk-NXZZXJRH.js","sourcesContent":["import * as React from \"react\";\n\nimport type { DiscriminatedRenderProps, PolymorphicProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { type ExtractUnion, type Prettify, isArray, isNumber } from \"@zayne-labs/toolkit-type-helpers\";\n\n// prettier-ignore\ntype RenderPropFn<TArray> = (\n\titem: TArray extends readonly unknown[] ? ExtractUnion<TArray> : TArray extends number ? number : unknown,\n\tindex: number,\n\tarray: TArray extends readonly unknown[] ? TArray : TArray extends number ? number[] : unknown[]\n) => React.ReactNode;\n\nexport type ForRenderProps<TArrayItem> = DiscriminatedRenderProps<RenderPropFn<TArrayItem>>;\n\n/* eslint-disable perfectionist/sort-intersection-types -- Prefer the object to come first before the render props */\ntype ForProps<TArray> = Prettify<\n\t{\n\t\teach: TArray;\n\t\tfallback?: React.ReactNode;\n\t} & ForRenderProps<TArray>\n>;\n\n/* eslint-enable perfectionist/sort-intersection-types -- Prefer the object to come first before the render props */\n\nexport function For<const TArray>(props: ForProps<TArray>) {\n\tconst { children, each, fallback = null, render } = props;\n\n\tif (each == null || (isNumber(each) && each === 0) || (isArray(each) && each.length === 0)) {\n\t\treturn fallback;\n\t}\n\n\tconst resolvedArray = isNumber(each) ? [...Array(each).keys()] : (each as unknown[]);\n\n\tif (resolvedArray.length === 0) {\n\t\treturn fallback;\n\t}\n\n\tconst JSXElementList = resolvedArray.map((...params) => {\n\t\ttype Params = Parameters<RenderPropFn<TArray>>;\n\n\t\treturn typeof children === \"function\"\n\t\t\t? children(...(params as Params))\n\t\t\t: render(...(params as Params));\n\t});\n\n\treturn JSXElementList;\n}\n\nexport function ForWithWrapper<TArrayItem, TElement extends React.ElementType = \"ul\">(\n\tprops: PolymorphicProps<TElement, ForProps<TArrayItem>>\n) {\n\tconst { as: ListContainer = \"ul\", children, className, each, ref, render, ...restOfListProps } = props;\n\n\treturn (\n\t\t<ListContainer ref={ref} className={className} {...restOfListProps}>\n\t\t\t<For {...({ children, each, render } as ForProps<TArrayItem>)} />\n\t\t</ListContainer>\n\t);\n}\n","import { For, ForWithWrapper } from \"./for\";\n\ntype GetElementListResult<TVariant extends \"base\" | \"withWrapper\"> = TVariant extends \"base\"\n\t? [typeof For]\n\t: [typeof ForWithWrapper];\n\nconst getElementList = <TVariant extends \"base\" | \"withWrapper\" = \"withWrapper\">(\n\tvariant?: TVariant\n): GetElementListResult<TVariant> => {\n\tswitch (variant) {\n\t\tcase \"base\": {\n\t\t\treturn [For] as never;\n\t\t}\n\t\tcase \"withWrapper\": {\n\t\t\treturn [ForWithWrapper] as never;\n\t\t}\n\t\tdefault: {\n\t\t\treturn [ForWithWrapper] as never;\n\t\t}\n\t}\n};\n\nexport { getElementList };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/utils/cn.ts"],"names":[],"mappings":";;;AAEO,IAAM,OAAU,GAAA,CAAA,GAAI,UAAiC,KAAA,OAAA,CAAQ,UAAU","file":"chunk-OHG7GB7O.js","sourcesContent":["import { type ClassNameValue, twMerge } from \"tailwind-merge\";\n\nexport const cnMerge = (...classNames: ClassNameValue[]) => twMerge(classNames);\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export { __export };
|
|
8
|
-
//# sourceMappingURL=chunk-PZ5AY32C.js.map
|
|
9
|
-
//# sourceMappingURL=chunk-PZ5AY32C.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-PZ5AY32C.js"}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { cnMerge } from './chunk-OHG7GB7O.js';
|
|
2
|
-
import { off, on, checkIsDeviceMobile } from '@zayne-labs/toolkit-core';
|
|
3
|
-
import { useCallbackRef } from '@zayne-labs/toolkit-react';
|
|
4
|
-
import { mergeTwoProps, composeRefs } from '@zayne-labs/toolkit-react/utils';
|
|
5
|
-
import { useRef } from 'react';
|
|
6
|
-
|
|
7
|
-
var updateCursor = (element) => {
|
|
8
|
-
element.style.cursor = "grabbing";
|
|
9
|
-
element.style.userSelect = "none";
|
|
10
|
-
};
|
|
11
|
-
var onScrollSnap = (action, element) => {
|
|
12
|
-
if (action === "remove") {
|
|
13
|
-
element.style.scrollSnapType = "none";
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
element.style.scrollSnapType = "";
|
|
17
|
-
};
|
|
18
|
-
var resetCursor = (element) => {
|
|
19
|
-
element.style.cursor = "";
|
|
20
|
-
element.style.userSelect = "";
|
|
21
|
-
};
|
|
22
|
-
var handleScrollSnap = (dragContainer) => {
|
|
23
|
-
const isMobile = checkIsDeviceMobile();
|
|
24
|
-
if (!isMobile) {
|
|
25
|
-
onScrollSnap("remove", dragContainer);
|
|
26
|
-
} else {
|
|
27
|
-
onScrollSnap("reset", dragContainer);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// src/components/ui/drag-scroll/use-drag-scroll.ts
|
|
32
|
-
var useDragScroll = (props) => {
|
|
33
|
-
const {
|
|
34
|
-
classNames,
|
|
35
|
-
extraItemProps,
|
|
36
|
-
extraRootProps,
|
|
37
|
-
orientation = "horizontal",
|
|
38
|
-
usage = "allScreens"
|
|
39
|
-
} = props ?? {};
|
|
40
|
-
const dragContainerRef = useRef(null);
|
|
41
|
-
const positionRef = useRef({ left: 0, top: 0, x: 0, y: 0 });
|
|
42
|
-
const handleMouseMove = useCallbackRef((event) => {
|
|
43
|
-
if (!dragContainerRef.current) return;
|
|
44
|
-
if (orientation === "horizontal" || orientation === "both") {
|
|
45
|
-
const dx = event.clientX - positionRef.current.x;
|
|
46
|
-
dragContainerRef.current.scrollLeft = positionRef.current.left - dx;
|
|
47
|
-
}
|
|
48
|
-
if (orientation === "vertical" || orientation === "both") {
|
|
49
|
-
const dy = event.clientY - positionRef.current.y;
|
|
50
|
-
dragContainerRef.current.scrollTop = positionRef.current.top - dy;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const handleMouseUpOrLeave = useCallbackRef(() => {
|
|
54
|
-
if (!dragContainerRef.current) return;
|
|
55
|
-
off("mousemove", dragContainerRef.current, handleMouseMove);
|
|
56
|
-
off("mouseup", dragContainerRef.current, handleMouseUpOrLeave);
|
|
57
|
-
off("mouseleave", dragContainerRef.current, handleMouseUpOrLeave);
|
|
58
|
-
resetCursor(dragContainerRef.current);
|
|
59
|
-
});
|
|
60
|
-
const handleMouseDown = useCallbackRef((event) => {
|
|
61
|
-
if (usage === "mobileAndTabletOnly" && window.innerWidth >= 768) return;
|
|
62
|
-
if (usage === "desktopOnly" && window.innerWidth < 768) return;
|
|
63
|
-
if (!dragContainerRef.current) return;
|
|
64
|
-
if (orientation === "horizontal" || orientation === "both") {
|
|
65
|
-
positionRef.current.x = event.clientX;
|
|
66
|
-
positionRef.current.left = dragContainerRef.current.scrollLeft;
|
|
67
|
-
}
|
|
68
|
-
if (orientation === "vertical" || orientation === "both") {
|
|
69
|
-
positionRef.current.y = event.clientY;
|
|
70
|
-
positionRef.current.top = dragContainerRef.current.scrollTop;
|
|
71
|
-
}
|
|
72
|
-
updateCursor(dragContainerRef.current);
|
|
73
|
-
on("mousemove", dragContainerRef.current, handleMouseMove);
|
|
74
|
-
on("mouseup", dragContainerRef.current, handleMouseUpOrLeave);
|
|
75
|
-
on("mouseleave", dragContainerRef.current, handleMouseUpOrLeave);
|
|
76
|
-
});
|
|
77
|
-
const refCallBack = useCallbackRef((node) => {
|
|
78
|
-
dragContainerRef.current = node;
|
|
79
|
-
node && handleScrollSnap(node);
|
|
80
|
-
const cleanup = on("mousedown", dragContainerRef.current, handleMouseDown);
|
|
81
|
-
return cleanup;
|
|
82
|
-
});
|
|
83
|
-
const getRootProps = (rootProps) => {
|
|
84
|
-
const mergedRootProps = mergeTwoProps(extraRootProps, rootProps);
|
|
85
|
-
return {
|
|
86
|
-
...mergedRootProps,
|
|
87
|
-
className: cnMerge(
|
|
88
|
-
`scrollbar-hidden flex w-full cursor-grab snap-x snap-mandatory overflow-y-hidden
|
|
89
|
-
overflow-x-scroll`,
|
|
90
|
-
orientation === "horizontal" && "flex-row",
|
|
91
|
-
orientation === "vertical" && "flex-col",
|
|
92
|
-
usage === "mobileAndTabletOnly" && "md:cursor-default md:flex-col",
|
|
93
|
-
usage === "desktopOnly" && "max-md:cursor-default max-md:flex-col",
|
|
94
|
-
classNames?.base,
|
|
95
|
-
mergedRootProps.className
|
|
96
|
-
),
|
|
97
|
-
"data-part": "root",
|
|
98
|
-
"data-scope": "drag-scroll",
|
|
99
|
-
"data-slot": "drag-scroll-root",
|
|
100
|
-
ref: composeRefs(
|
|
101
|
-
refCallBack,
|
|
102
|
-
mergedRootProps?.ref
|
|
103
|
-
)
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
const getItemProps = (itemProps) => {
|
|
107
|
-
const mergedItemProps = mergeTwoProps(extraItemProps, itemProps);
|
|
108
|
-
return {
|
|
109
|
-
...mergedItemProps,
|
|
110
|
-
className: cnMerge("snap-center snap-always", classNames?.item, mergedItemProps.className),
|
|
111
|
-
"data-part": "item",
|
|
112
|
-
"data-scope": "drag-scroll",
|
|
113
|
-
"data-slot": "drag-scroll-item"
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
return { getItemProps, getRootProps };
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export { useDragScroll };
|
|
120
|
-
//# sourceMappingURL=chunk-V5ZPMMIH.js.map
|
|
121
|
-
//# sourceMappingURL=chunk-V5ZPMMIH.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/ui/drag-scroll/utils.ts","../../src/components/ui/drag-scroll/use-drag-scroll.ts"],"names":[],"mappings":";;;;;;AAGO,IAAM,YAAA,GAAe,CAA+B,OAAsB,KAAA;AAChF,EAAA,OAAA,CAAQ,MAAM,MAAS,GAAA,UAAA;AACvB,EAAA,OAAA,CAAQ,MAAM,UAAa,GAAA,MAAA;AAC5B,CAAA;AAEO,IAAM,YAAA,GAAe,CAC3B,MAAA,EACA,OACI,KAAA;AACJ,EAAA,IAAI,WAAW,QAAU,EAAA;AACxB,IAAA,OAAA,CAAQ,MAAM,cAAiB,GAAA,MAAA;AAC/B,IAAA;AAAA;AAGD,EAAA,OAAA,CAAQ,MAAM,cAAiB,GAAA,EAAA;AAChC,CAAA;AAEO,IAAM,WAAA,GAAc,CAA+B,OAAsB,KAAA;AAC/E,EAAA,OAAA,CAAQ,MAAM,MAAS,GAAA,EAAA;AACvB,EAAA,OAAA,CAAQ,MAAM,UAAa,GAAA,EAAA;AAC5B,CAAA;AAGO,IAAM,gBAAA,GAAmB,CAAC,aAA+B,KAAA;AAC/D,EAAA,MAAM,WAAW,mBAAoB,EAAA;AAErC,EAAA,IAAI,CAAC,QAAU,EAAA;AACd,IAAA,YAAA,CAAa,UAAU,aAAa,CAAA;AAAA,GAC9B,MAAA;AACN,IAAA,YAAA,CAAa,SAAS,aAAa,CAAA;AAAA;AAErC,CAAA;;;ACVM,IAAA,aAAA,GAAgB,CACrB,KAC8C,KAAA;AAC9C,EAAM,MAAA;AAAA,IACL,UAAA;AAAA,IACA,cAAA;AAAA,IACA,cAAA;AAAA,IACA,WAAc,GAAA,YAAA;AAAA,IACd,KAAQ,GAAA;AAAA,GACT,GAAI,SAAS,EAAC;AAEd,EAAM,MAAA,gBAAA,GAAmB,OAAiB,IAAI,CAAA;AAE9C,EAAM,M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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,SAAW,EAAA,OAAA;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":"chunk-V5ZPMMIH.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"]}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { __export } from './chunk-PZ5AY32C.js';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { Children, isValidElement, cloneElement, Fragment } from 'react';
|
|
4
|
-
import { composeRefs, mergeProps } from '@zayne-labs/toolkit-react/utils';
|
|
5
|
-
import { isArray } from '@zayne-labs/toolkit-type-helpers';
|
|
6
|
-
|
|
7
|
-
function SlotSlottable({ children }) {
|
|
8
|
-
return children;
|
|
9
|
-
}
|
|
10
|
-
var isSlottable = (child) => {
|
|
11
|
-
return isValidElement(child) && child.type === SlotSlottable;
|
|
12
|
-
};
|
|
13
|
-
function SlotRoot(props) {
|
|
14
|
-
const { children, ...restOfSlotProps } = props;
|
|
15
|
-
const childrenArray = isArray(children) ? children : [children];
|
|
16
|
-
const slottable = childrenArray.find((element) => isSlottable(element));
|
|
17
|
-
if (slottable) {
|
|
18
|
-
const newElement = slottable.props.children;
|
|
19
|
-
if (Children.count(newElement) > 1) {
|
|
20
|
-
return Children.only(null);
|
|
21
|
-
}
|
|
22
|
-
const newElementChildren = childrenArray.map((child) => {
|
|
23
|
-
if (child === slottable) {
|
|
24
|
-
return isValidElement(newElement) && newElement.props.children;
|
|
25
|
-
}
|
|
26
|
-
return child;
|
|
27
|
-
});
|
|
28
|
-
return /* @__PURE__ */ React.createElement(SlotClone, { ...restOfSlotProps }, isValidElement(newElement) && cloneElement(newElement, void 0, newElementChildren));
|
|
29
|
-
}
|
|
30
|
-
return /* @__PURE__ */ React.createElement(SlotClone, { ...restOfSlotProps }, children);
|
|
31
|
-
}
|
|
32
|
-
function SlotClone(props) {
|
|
33
|
-
const { children, ref: forwardedRef, ...restOfSlotProps } = props;
|
|
34
|
-
if (!isValidElement(children)) {
|
|
35
|
-
return Children.count(children) > 1 ? Children.only(null) : null;
|
|
36
|
-
}
|
|
37
|
-
const childRef = children.props.ref ?? children.ref;
|
|
38
|
-
const mergedRef = forwardedRef ? composeRefs(forwardedRef, childRef) : childRef;
|
|
39
|
-
const clonedProps = {
|
|
40
|
-
...mergeProps(restOfSlotProps, children.props),
|
|
41
|
-
...children.type !== Fragment && { ref: mergedRef }
|
|
42
|
-
};
|
|
43
|
-
return cloneElement(children, clonedProps);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/components/common/slot/slot-parts.ts
|
|
47
|
-
var slot_parts_exports = {};
|
|
48
|
-
__export(slot_parts_exports, {
|
|
49
|
-
Root: () => SlotRoot,
|
|
50
|
-
Slottable: () => SlotSlottable
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export { SlotRoot, SlotSlottable, slot_parts_exports };
|
|
54
|
-
//# sourceMappingURL=chunk-Y5VBSXZS.js.map
|
|
55
|
-
//# sourceMappingURL=chunk-Y5VBSXZS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/common/slot/slot.tsx","../../src/components/common/slot/slot-parts.ts"],"names":["ReactFragment"],"mappings":";;;;;;AAYO,SAAS,aAAA,CAAc,EAAE,QAAA,EAAyC,EAAA;AACxE,EAAO,OAAA,QAAA;AACR;AAEA,IAAM,WAAA,GAAc,CAAC,KAAwD,KAAA;AAC5E,EAAA,OAAO,cAAe,CAAA,KAAK,CAAK,IAAA,KAAA,CAAM,IAAS,KAAA,aAAA;AAChD,CAAA;AAMO,SAAS,SAAS,KAA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AAI,QAAS,CAAA,IAAA,CAAK,IAAI,CAAI,GAAA,IAAA;AAAA;AAG7D,EAAA,MAAM,QAAY,GAAA,QAAA,CAAS,KAAM,CAAA,GAAA,IAC5B,QAAqC,CAAA,GAAA;AAE1C,EAAA,MAAM,SAAY,GAAA,YAAA,GAAe,WAAY,CAAA,YAAA,EAAc,QAAQ,CAAI,GAAA,QAAA;AAEvE,EAAA,MAAM,WAAc,GAAA;AAAA,IACnB,GAAG,UAAA,CAAW,eAAiB,EAAA,QAAA,CAAS,KAAK,CAAA;AAAA,IAC7C,GAAI,QAAS,CAAA,IAAA,KAASA,QAAiB,IAAA,EAAE,KAAK,SAAU;AAAA,GACzD;AAEA,EAAO,OAAA,YAAA,CAAa,UAAU,WAAW,CAAA;AAC1C;;;AClFA,IAAA,kBAAA,GAAA;AAAA,QAAA,CAAA,kBAAA,EAAA;AAAA,EAAA,IAAA,EAAA,MAAA,QAAA;AAAA,EAAA,SAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"chunk-Y5VBSXZS.js","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\tif (!isValidElement<UnknownProps>(children)) {\n\t\treturn Children.count(children) > 1 ? Children.only(null) : null;\n\t}\n\n\tconst childRef = (children.props.ref\n\t\t?? (children 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, children.props),\n\t\t...(children.type !== ReactFragment && { ref: mergedRef }),\n\t};\n\n\treturn cloneElement(children, clonedProps);\n}\n","export { SlotRoot as Root, SlotSlottable as Slottable } from \"./slot\";\n"]}
|