@bioturing/components 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Badge/component.js +7 -20
- package/dist/components/Badge/component.js.map +1 -1
- package/dist/components/ColorSelect/component.js +138 -0
- package/dist/components/ColorSelect/component.js.map +1 -0
- package/dist/components/ColorSelect/style.css +1 -0
- package/dist/components/DragDrop/context.js +18 -0
- package/dist/components/DragDrop/context.js.map +1 -0
- package/dist/components/DragDrop/draggable.js +64 -0
- package/dist/components/DragDrop/draggable.js.map +1 -0
- package/dist/components/DragDrop/droppable.js +48 -0
- package/dist/components/DragDrop/droppable.js.map +1 -0
- package/dist/components/DragDrop/hooks.js +139 -0
- package/dist/components/DragDrop/hooks.js.map +1 -0
- package/dist/components/DragDrop/index.js +45 -0
- package/dist/components/DragDrop/index.js.map +1 -0
- package/dist/components/DragDrop/style.css +1 -0
- package/dist/components/IconButton/component.js +54 -43
- package/dist/components/IconButton/component.js.map +1 -1
- package/dist/components/IconButton/style.css +1 -1
- package/dist/components/Nav/context.js +7 -0
- package/dist/components/Nav/context.js.map +1 -0
- package/dist/components/Nav/group.js +16 -0
- package/dist/components/Nav/group.js.map +1 -0
- package/dist/components/Nav/heading.js +16 -0
- package/dist/components/Nav/heading.js.map +1 -0
- package/dist/components/Nav/index.js +13 -0
- package/dist/components/Nav/index.js.map +1 -0
- package/dist/components/Nav/item.js +36 -0
- package/dist/components/Nav/item.js.map +1 -0
- package/dist/components/Nav/style.css +1 -0
- package/dist/components/PopupPanel/component.js +69 -74
- package/dist/components/PopupPanel/component.js.map +1 -1
- package/dist/components/Stack/Stack.js +40 -34
- package/dist/components/Stack/Stack.js.map +1 -1
- package/dist/components/Stack/StackChild.js +59 -54
- package/dist/components/Stack/StackChild.js.map +1 -1
- package/dist/components/Tag/component.js +59 -24
- package/dist/components/Tag/component.js.map +1 -1
- package/dist/components/Tag/style.css +1 -1
- package/dist/components/ThemeProvider/component.js +18 -18
- package/dist/components/ThemeProvider/component.js.map +1 -1
- package/dist/components/ThemeProvider/style.css +1 -1
- package/dist/components/Toast/component.js +29 -35
- package/dist/components/Toast/component.js.map +1 -1
- package/dist/components/Tooltip/component.js +4 -22
- package/dist/components/Tooltip/component.js.map +1 -1
- package/dist/components/VerticalCollapsiblePanel/component.js +37 -37
- package/dist/components/VerticalCollapsiblePanel/component.js.map +1 -1
- package/dist/components/hooks/useCharts.js +19 -17
- package/dist/components/hooks/useCharts.js.map +1 -1
- package/dist/components/utils/colors.js +5 -0
- package/dist/components/utils/colors.js.map +1 -0
- package/dist/index.d.ts +724 -23
- package/dist/index.js +186 -162
- package/dist/index.js.map +1 -1
- package/dist/metadata.js +45 -7
- package/dist/metadata.js.map +1 -1
- package/dist/tailwind.css +1 -1
- package/dist/tokens/and-theme/tokens.js +13 -7
- package/dist/tokens/and-theme/tokens.js.map +1 -1
- package/dist/tokens/charts/{tokens.js → palettes/cloudscape.js} +22 -12
- package/dist/tokens/charts/palettes/cloudscape.js.map +1 -0
- package/dist/tokens/charts/palettes/colorbrewer.js +1525 -0
- package/dist/tokens/charts/palettes/colorbrewer.js.map +1 -0
- package/dist/tokens/charts/palettes/index.js +61 -0
- package/dist/tokens/charts/palettes/index.js.map +1 -0
- package/dist/tokens/charts/palettes/tableau.js +112 -0
- package/dist/tokens/charts/palettes/tableau.js.map +1 -0
- package/dist/tokens/utils.js.map +1 -1
- package/package.json +2 -2
- package/dist/tokens/charts/index.js +0 -18
- package/dist/tokens/charts/index.js.map +0 -1
- package/dist/tokens/charts/tokens.js.map +0 -1
|
@@ -1,26 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import { jsx as e } from "react/jsx-runtime";
|
|
3
|
+
import n from "antd/es/badge";
|
|
4
|
+
import i from "antd/es/badge/Ribbon";
|
|
5
5
|
import './style.css';/* empty css */
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const l = ({ count: s, showZero: t, ...o }) => {
|
|
9
|
-
const r = c(), e = i();
|
|
10
|
-
return /* @__PURE__ */ n(
|
|
11
|
-
a,
|
|
12
|
-
{
|
|
13
|
-
count: s,
|
|
14
|
-
showZero: t,
|
|
15
|
-
className: d(r("badge"), e),
|
|
16
|
-
...o
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
}, x = Object.assign(l, {
|
|
20
|
-
Ribbon: m
|
|
6
|
+
const m = ({ count: t, showZero: o, ...r }) => /* @__PURE__ */ e(n, { count: t, showZero: o, ...r }), d = Object.assign(m, {
|
|
7
|
+
Ribbon: i
|
|
21
8
|
});
|
|
22
9
|
export {
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
d as Badge,
|
|
11
|
+
m as InternalBadge
|
|
25
12
|
};
|
|
26
13
|
//# sourceMappingURL=component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sources":["../../../src/components/Badge/component.tsx"],"sourcesContent":["\"use client\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../src/components/Badge/component.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n default as AntdBadge,\n type BadgeProps as AntdBadgeProps,\n} from \"antd/es/badge\";\nimport Ribbon from \"antd/es/badge/Ribbon\";\n\n// Import component-specific styles\nimport \"./style.css\";\n\nexport type BadgeProps = AntdBadgeProps;\n\nexport const InternalBadge = ({ count, showZero, ...rest }: BadgeProps) => {\n return <AntdBadge count={count} showZero={showZero} {...rest} />;\n};\n\nexport const Badge = Object.assign(InternalBadge, {\n Ribbon,\n});\n"],"names":["InternalBadge","count","showZero","rest","jsx","AntdBadge","Badge","Ribbon"],"mappings":";;;;;AAaO,MAAMA,IAAgB,CAAC,EAAE,OAAAC,GAAO,UAAAC,GAAU,GAAGC,QAC1C,gBAAAC,EAAAC,GAAA,EAAU,OAAAJ,GAAc,UAAAC,GAAqB,GAAGC,GAAM,GAGnDG,IAAQ,OAAO,OAAON,GAAe;AAAA,EAChD,QAAAO;AACF,CAAC;"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as a, jsxs as P } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef as q, useState as V, useRef as U, useCallback as v, useMemo as b } from "react";
|
|
4
|
+
import W from "antd/es/color-picker";
|
|
5
|
+
import { Stack as z } from "../Stack/index.js";
|
|
6
|
+
import './style.css';/* empty css */
|
|
7
|
+
import { isValidHexColor as F } from "../utils/colors.js";
|
|
8
|
+
import { toast as G } from "../Toast/function.js";
|
|
9
|
+
import { Tag as J } from "../Tag/component.js";
|
|
10
|
+
import { useCls as L } from "../utils/antdUtils.js";
|
|
11
|
+
import { useControlledState as I } from "../hooks/useControlledState.js";
|
|
12
|
+
import { Tooltip as Q } from "../Tooltip/component.js";
|
|
13
|
+
const X = ({
|
|
14
|
+
className: Z,
|
|
15
|
+
value: K,
|
|
16
|
+
defaultValue: M,
|
|
17
|
+
onChange: i,
|
|
18
|
+
colorPickerProps: w,
|
|
19
|
+
presetColors: m,
|
|
20
|
+
open: R,
|
|
21
|
+
onOpenChange: u,
|
|
22
|
+
defaultOpen: T,
|
|
23
|
+
...j
|
|
24
|
+
}, y) => {
|
|
25
|
+
const l = L(), [s, n] = I(
|
|
26
|
+
K,
|
|
27
|
+
i,
|
|
28
|
+
M
|
|
29
|
+
), [r, f] = V(""), [C, d] = V(""), [g, o] = I(
|
|
30
|
+
R,
|
|
31
|
+
u,
|
|
32
|
+
T
|
|
33
|
+
), [B, h] = V(!1), k = U(null), x = v(() => {
|
|
34
|
+
const t = r.trim().split(/[;,\s]+/).filter(Boolean).map(
|
|
35
|
+
(p) => p.trim().toUpperCase()
|
|
36
|
+
), c = [], A = t.reduce((p, S) => (F(S, !0) ? p.push(S) : c.push(S), p), []);
|
|
37
|
+
c.length && G(`Invalid colors: ${c.join(", ")}`);
|
|
38
|
+
const E = /* @__PURE__ */ new Set([...s, ...A]);
|
|
39
|
+
i && i([...E]), u && u(!1), f(""), d(""), o(!1), requestAnimationFrame(() => {
|
|
40
|
+
o(!0);
|
|
41
|
+
});
|
|
42
|
+
}, [r, s, i, u, o]), D = v(
|
|
43
|
+
(e) => {
|
|
44
|
+
e.key === "Enter" && x(), e.key === "Backspace" && !r && (e.ctrlKey || e.metaKey ? n([]) : n(s.slice(0, -1)));
|
|
45
|
+
},
|
|
46
|
+
[x, r, s, n]
|
|
47
|
+
), H = b(
|
|
48
|
+
() => s.map((e, t) => /* @__PURE__ */ a(Q, { title: e, children: /* @__PURE__ */ a(
|
|
49
|
+
J,
|
|
50
|
+
{
|
|
51
|
+
className: l("color-select-tag"),
|
|
52
|
+
closable: !0,
|
|
53
|
+
onClose: () => n(s.filter((c) => c !== e)),
|
|
54
|
+
icon: /* @__PURE__ */ a(
|
|
55
|
+
"span",
|
|
56
|
+
{
|
|
57
|
+
className: l("color-select-swatch"),
|
|
58
|
+
style: { backgroundColor: e }
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
) }, `${e}-${t}`)),
|
|
63
|
+
[s, l, n]
|
|
64
|
+
), N = v(
|
|
65
|
+
(e) => {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
},
|
|
68
|
+
[]
|
|
69
|
+
), $ = b(
|
|
70
|
+
() => /* @__PURE__ */ a(
|
|
71
|
+
W,
|
|
72
|
+
{
|
|
73
|
+
value: C,
|
|
74
|
+
onChange: (e) => {
|
|
75
|
+
d(e.toHexString()), f(e.toHexString());
|
|
76
|
+
},
|
|
77
|
+
open: g,
|
|
78
|
+
arrow: !1,
|
|
79
|
+
presets: m ? [{ label: "Preset Colors", colors: m }] : void 0,
|
|
80
|
+
...w,
|
|
81
|
+
panelRender: (e) => /* @__PURE__ */ a("div", { ref: k, onMouseDown: N, children: e }),
|
|
82
|
+
children: /* @__PURE__ */ a(
|
|
83
|
+
"input",
|
|
84
|
+
{
|
|
85
|
+
placeholder: "Select or enter a color list",
|
|
86
|
+
className: l("color-select-input"),
|
|
87
|
+
value: r,
|
|
88
|
+
type: "text",
|
|
89
|
+
ref: y,
|
|
90
|
+
onChange: (e) => {
|
|
91
|
+
const t = e.target.value;
|
|
92
|
+
f(t), F(t, !0) && d(t), t.length > 7 || t.length == 7 && !t.startsWith("#") ? o(!1) : o(!0);
|
|
93
|
+
},
|
|
94
|
+
onKeyDown: D,
|
|
95
|
+
onFocus: () => {
|
|
96
|
+
h(!0), o(!0);
|
|
97
|
+
},
|
|
98
|
+
onBlur: () => {
|
|
99
|
+
h(!1), o(!1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
[
|
|
106
|
+
C,
|
|
107
|
+
g,
|
|
108
|
+
m,
|
|
109
|
+
w,
|
|
110
|
+
r,
|
|
111
|
+
l,
|
|
112
|
+
y,
|
|
113
|
+
D,
|
|
114
|
+
h,
|
|
115
|
+
o,
|
|
116
|
+
N,
|
|
117
|
+
k
|
|
118
|
+
]
|
|
119
|
+
);
|
|
120
|
+
return /* @__PURE__ */ P(
|
|
121
|
+
z,
|
|
122
|
+
{
|
|
123
|
+
wrap: !0,
|
|
124
|
+
gap: 4,
|
|
125
|
+
className: l("color-select"),
|
|
126
|
+
"data-focus": B || void 0,
|
|
127
|
+
...j,
|
|
128
|
+
children: [
|
|
129
|
+
H,
|
|
130
|
+
$
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
}, Y = q(X), ie = Y;
|
|
135
|
+
export {
|
|
136
|
+
ie as ColorSelect
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../src/components/ColorSelect/component.tsx"],"sourcesContent":["\"use client\";\nimport React, {\n ComponentPropsWithoutRef,\n forwardRef,\n useRef,\n useState,\n useCallback,\n useMemo,\n} from \"react\";\nimport ColorPicker from \"antd/es/color-picker\";\nimport { type ColorPickerProps } from \"antd/es/color-picker\";\nimport { useCls, isValidHexColor } from \"../utils\";\nimport { useControlledState } from \"../hooks\";\nimport { Tag } from \"../Tag\";\nimport { Stack } from \"../Stack\";\nimport { toast } from \"../Toast\";\n\n// Import component-specific styles\nimport \"./style.css\";\nimport { Tooltip } from \"../Tooltip\";\n\n/**\n * Props for the ColorSelect component.\n */\nexport interface ColorSelectProps\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\"> {\n /** Controlled list of selected hex colors */\n value?: string[];\n /** Default list of selected hex colors for uncontrolled usage */\n defaultValue?: string[];\n /** Callback invoked when selected colors change */\n onChange?: (value: string[]) => void;\n /** Props to pass through to the Ant Design ColorPicker, excluding value/onChange/onChangeComplete */\n colorPickerProps?: Omit<\n ColorPickerProps,\n \"value\" | \"onChange\" | \"onChangeComplete\"\n >;\n /** Preset color swatches displayed in the picker */\n presetColors?: string[];\n /** Controlled open state of the ColorPicker dropdown */\n open?: boolean;\n /** Callback invoked when open state changes */\n onOpenChange?: (open: boolean) => void;\n /** Default open state for uncontrolled usage */\n defaultOpen?: boolean;\n}\n\n/**\n * ColorSelectInner - Combines an input and Ant Design ColorPicker for selecting multiple colors.\n * Supports preset color swatches and freeform hex entry, displaying selections as tags.\n * Controlled/uncontrolled APIs for `value` and `open`, emitting invalid input notifications via toast.\n * @param props - {@link ColorSelectProps}\n * @param ref - ref to the input element\n * @returns JSX.Element\n */\nconst ColorSelectInner = (\n {\n className,\n value: valueProp,\n defaultValue,\n onChange,\n colorPickerProps,\n presetColors,\n open: openProp,\n onOpenChange,\n defaultOpen,\n ...rest\n },\n ref: React.Ref<React.ComponentRef<\"input\">>\n) => {\n const cls = useCls();\n const [value, setValue] = useControlledState<string[]>(\n valueProp,\n onChange,\n defaultValue\n );\n const [searchValue, setSearchValue] = useState(\"\");\n const [tmpValue, setTmpValue] = useState(\"\");\n const [open, setOpen] = useControlledState<boolean>(\n openProp,\n onOpenChange,\n defaultOpen\n );\n\n const [isFocus, setIsFocus] = useState(false);\n\n const popupRef = useRef<HTMLDivElement>(null);\n\n const onEnter = useCallback(() => {\n const searchValueSplit = searchValue\n .trim()\n .split(/[;,\\s]+/)\n .filter(Boolean);\n const addedValues = searchValueSplit.map((gene) =>\n gene.trim().toUpperCase()\n );\n const inValidValues: string[] = [];\n const validAddedValues = addedValues.reduce((acc, curr) => {\n if (!isValidHexColor(curr, true)) {\n inValidValues.push(curr);\n } else {\n acc.push(curr);\n }\n return acc;\n }, [] as string[]);\n if (inValidValues.length) {\n toast(`Invalid colors: ${inValidValues.join(\", \")}`);\n }\n const newColors = new Set([...value, ...validAddedValues]);\n if (onChange) onChange([...newColors]);\n if (onOpenChange) onOpenChange(false);\n setSearchValue(\"\");\n setTmpValue(\"\");\n setOpen(false);\n requestAnimationFrame(() => {\n setOpen(true);\n });\n }, [searchValue, value, onChange, onOpenChange, setOpen]);\n\n const onInputKeyDown = useCallback(\n (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\") onEnter();\n if (e.key === \"Backspace\" && !searchValue) {\n if (e.ctrlKey || e.metaKey) {\n setValue([]);\n } else {\n setValue(value.slice(0, -1));\n }\n }\n },\n [onEnter, searchValue, value, setValue]\n );\n\n const renderedTags = useMemo(\n () =>\n value.map((color, index) => (\n <Tooltip title={color} key={`${color}-${index}`}>\n <Tag\n className={cls(\"color-select-tag\")}\n closable\n onClose={() => setValue(value.filter((v) => v !== color))}\n icon={\n <span\n className={cls(\"color-select-swatch\")}\n style={{ backgroundColor: color }}\n />\n }\n />\n </Tooltip>\n )),\n [value, cls, setValue]\n );\n\n const handlePopupMouseDown = useCallback(\n (e: React.MouseEvent<HTMLDivElement>) => {\n // Prevent input blur when clicking popup\n e.preventDefault();\n },\n []\n );\n\n const renderedColorPicker = useMemo(\n () => (\n <ColorPicker\n value={tmpValue}\n onChange={(color) => {\n // setValue([...value, color]);\n setTmpValue(color.toHexString());\n setSearchValue(color.toHexString());\n }}\n open={open}\n arrow={false}\n presets={\n presetColors\n ? [{ label: \"Preset Colors\", colors: presetColors }]\n : undefined\n }\n {...colorPickerProps}\n panelRender={(panel) => (\n <div ref={popupRef} onMouseDown={handlePopupMouseDown}>\n {panel}\n </div>\n )}\n >\n <input\n placeholder=\"Select or enter a color list\"\n className={cls(\"color-select-input\")}\n value={searchValue}\n type=\"text\"\n ref={ref}\n onChange={(e) => {\n const currValue = e.target.value;\n setSearchValue(currValue);\n if (isValidHexColor(currValue, true)) setTmpValue(currValue);\n if (\n currValue.length > 7 ||\n (currValue.length == 7 && !currValue.startsWith(\"#\"))\n ) {\n setOpen(false);\n } else {\n setOpen(true);\n }\n }}\n onKeyDown={onInputKeyDown}\n onFocus={() => {\n setIsFocus(true);\n setOpen(true);\n }}\n onBlur={() => {\n // Check if the new focus target is inside the popup\n setIsFocus(false);\n setOpen(false);\n }}\n />\n </ColorPicker>\n ),\n [\n tmpValue,\n open,\n presetColors,\n colorPickerProps,\n searchValue,\n cls,\n ref,\n onInputKeyDown,\n setIsFocus,\n setOpen,\n handlePopupMouseDown,\n popupRef,\n ]\n );\n\n return (\n <Stack\n wrap\n gap={4}\n className={cls(\"color-select\")}\n data-focus={isFocus || undefined}\n {...rest}\n >\n {renderedTags}\n {renderedColorPicker}\n </Stack>\n );\n};\n\n// Use forwardRef with type assertion\nconst MainColorSelect = forwardRef(ColorSelectInner);\n\nexport const ColorSelect = MainColorSelect;\n"],"names":["ColorSelectInner","className","valueProp","defaultValue","onChange","colorPickerProps","presetColors","openProp","onOpenChange","defaultOpen","rest","ref","cls","useCls","value","setValue","useControlledState","searchValue","setSearchValue","useState","tmpValue","setTmpValue","open","setOpen","isFocus","setIsFocus","popupRef","useRef","onEnter","useCallback","addedValues","gene","inValidValues","validAddedValues","acc","curr","isValidHexColor","toast","newColors","onInputKeyDown","renderedTags","useMemo","color","index","jsx","Tooltip","Tag","v","handlePopupMouseDown","renderedColorPicker","ColorPicker","panel","currValue","jsxs","Stack","MainColorS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,QAAA8B;AAAA,QACAS;AAAA,MAAA;AAAA,IAAA;AAAA,EACH;AAEJ,GAGMM,IAAkBC,EAAWxD,CAAgB,GAEtCyD,KAAcF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@layer components{.ds-color-select{border-color:var(--ds-color-border);border-radius:var(--ds-border-radius);padding:.25rem;background:var(--ds-color-bg-container);border-width:var(--ds-line-width);border-style:var(--ds-line-type);transition:all var(--ds-motion-duration-mid)}.ds-color-select[data-focus=true]{border-color:var(--ds-input-color-border-active);box-shadow:var(--ds-input-shadow-active);outline:0;background-color:var(--ds-input-active-bg)}.ds-color-select .ds-tag{margin-right:0}.ds-color-select-option,.ds-color-select-tag{display:flex;align-items:center;gap:.5rem}.ds-color-select-swatch{width:16px;height:16px;border-radius:9999px;border:1px solid var(--ds-color-border);flex-shrink:0}.ds-color-select-input{outline:none;border:none;background:transparent;color:var(--ds-color-text);font-size:var(--ds-font-size);font-family:var(--ds-font-family);line-height:var(--ds-line-height);flex:1;min-width:11rem;width:100%;margin-left:.25rem}.ds-color-select-input:first-child{margin-left:.7rem}}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext as t, useContext as o } from "react";
|
|
3
|
+
const e = t({
|
|
4
|
+
active: null,
|
|
5
|
+
setActive: () => {
|
|
6
|
+
},
|
|
7
|
+
onDragStart: void 0,
|
|
8
|
+
onDragEnd: void 0,
|
|
9
|
+
onDrop: void 0,
|
|
10
|
+
isDragging: !1,
|
|
11
|
+
setIsDragging: () => {
|
|
12
|
+
}
|
|
13
|
+
}), r = () => o(e);
|
|
14
|
+
export {
|
|
15
|
+
e as DragDropContext,
|
|
16
|
+
r as useDragDropContext
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../../../src/components/DragDrop/context.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, useContext } from \"react\";\nimport { type DragDropContextType, type Data } from \"./types\";\n\n/**\n * Drag context for sharing state between components\n */\nexport const DragDropContext = createContext<DragDropContextType>({\n active: null,\n setActive: () => {},\n onDragStart: undefined,\n onDragEnd: undefined,\n onDrop: undefined,\n isDragging: false,\n setIsDragging: () => {},\n});\n\n/**\n * Hook to access the Drag context\n */\nexport const useDragDropContext = <T extends Data = Data>() =>\n useContext(DragDropContext) as DragDropContextType<T>;\n"],"names":["DragDropContext","createContext","useDragDropContext","useContext"],"mappings":";;AAQO,MAAMA,IAAkBC,EAAmC;AAAA,EAChE,QAAQ;AAAA,EACR,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,aAAa;AAAA,EACb,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,eAAe,MAAM;AAAA,EAAA;AACvB,CAAC,GAKYC,IAAqB,MAChCC,EAAWH,CAAe;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as p } from "react/jsx-runtime";
|
|
3
|
+
import { useDraggable as A } from "./hooks.js";
|
|
4
|
+
import { useRender as D } from "@base-ui-components/react/use-render";
|
|
5
|
+
import { DotsSixVerticalIcon as C } from "@bioturing/assets";
|
|
6
|
+
import { isValidElement as N, cloneElement as R } from "react";
|
|
7
|
+
import { useCls as V } from "../utils/antdUtils.js";
|
|
8
|
+
import { clsx as h } from "../utils/cn.js";
|
|
9
|
+
const F = ({
|
|
10
|
+
id: t,
|
|
11
|
+
children: e,
|
|
12
|
+
className: o,
|
|
13
|
+
disabled: s = !1,
|
|
14
|
+
data: n,
|
|
15
|
+
style: d,
|
|
16
|
+
render: i,
|
|
17
|
+
onDragEnd: g,
|
|
18
|
+
onDragStart: E,
|
|
19
|
+
indicator: l = !0,
|
|
20
|
+
onlyIndicatorDraggable: m = !1,
|
|
21
|
+
...b
|
|
22
|
+
}) => {
|
|
23
|
+
const c = V(), { attributes: a, listeners: f, isDragging: u, setNodeRef: x } = A({
|
|
24
|
+
id: t,
|
|
25
|
+
data: n,
|
|
26
|
+
disabled: s,
|
|
27
|
+
onDragEnd: g,
|
|
28
|
+
onDragStart: E
|
|
29
|
+
}), r = l === !0 ? /* @__PURE__ */ p(C, { className: c("draggable-indicator") }) : l, y = [
|
|
30
|
+
N(r) ? m ? R(r, {
|
|
31
|
+
...a,
|
|
32
|
+
...f
|
|
33
|
+
}) : r : null,
|
|
34
|
+
...Array.isArray(e) ? e : [e]
|
|
35
|
+
];
|
|
36
|
+
return D({
|
|
37
|
+
render: i || /* @__PURE__ */ p("div", { className: h(c("draggable"), o) }),
|
|
38
|
+
ref: x,
|
|
39
|
+
props: {
|
|
40
|
+
children: y,
|
|
41
|
+
className: o,
|
|
42
|
+
style: {
|
|
43
|
+
...d,
|
|
44
|
+
touchAction: "none",
|
|
45
|
+
// Prevents scrolling on touch devices while dragging
|
|
46
|
+
cursor: s ? "default" : "grab",
|
|
47
|
+
opacity: u ? 0.5 : 1
|
|
48
|
+
// Visual feedback when dragging
|
|
49
|
+
},
|
|
50
|
+
...b,
|
|
51
|
+
...a,
|
|
52
|
+
...m ? {} : f
|
|
53
|
+
},
|
|
54
|
+
state: {
|
|
55
|
+
isDragging: u,
|
|
56
|
+
id: t,
|
|
57
|
+
data: n
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
F as Draggable
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=draggable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draggable.js","sources":["../../../src/components/DragDrop/draggable.tsx"],"sourcesContent":["\"use client\";\n\nimport { useDraggable } from \"./hooks\";\nimport { clsx, useCls } from \"../utils\";\nimport { useRender } from \"@base-ui-components/react/use-render\";\nimport type { Data, DragDropDraggableProps } from \"./types\";\nimport { DotsSixVerticalIcon } from \"@bioturing/assets\";\nimport { cloneElement, isValidElement, HTMLProps } from \"react\";\n\n/**\n * A draggable item component that can be used within the Drag context\n */\nexport const Draggable = <T extends Data = Data>({\n id,\n children,\n className,\n disabled = false,\n data,\n style,\n render,\n onDragEnd,\n onDragStart,\n indicator = true,\n onlyIndicatorDraggable = false,\n ...rest\n}: DragDropDraggableProps<T>) => {\n const cls = useCls();\n\n const { attributes, listeners, isDragging, setNodeRef } = useDraggable({\n id,\n data,\n disabled,\n onDragEnd,\n onDragStart,\n });\n\n const indicatorIcon =\n indicator === true ? (\n <DotsSixVerticalIcon className={cls(\"draggable-indicator\")} />\n ) : (\n indicator\n );\n const indicatorElement = isValidElement(indicatorIcon)\n ? onlyIndicatorDraggable\n ? cloneElement(indicatorIcon, {\n ...attributes,\n ...listeners,\n })\n : indicatorIcon\n : null;\n\n const combinedChildren = [\n indicatorElement,\n ...(Array.isArray(children) ? children : [children]),\n ];\n\n const renderedElement = useRender({\n render: render ? (\n render\n ) : (\n <div className={clsx(cls(\"draggable\"), className)} />\n ),\n ref: setNodeRef,\n props: {\n children: combinedChildren,\n className,\n style: {\n ...style,\n touchAction: \"none\", // Prevents scrolling on touch devices while dragging\n cursor: disabled ? \"default\" : \"grab\",\n opacity: isDragging ? 0.5 : 1, // Visual feedback when dragging\n },\n ...rest,\n ...attributes,\n ...(!onlyIndicatorDraggable ? listeners : {}),\n },\n state: {\n isDragging,\n id,\n data,\n },\n });\n\n return renderedElement;\n};\n"],"names":["Draggable","id","children","className","disabled","data","style","render","onDragEnd","onDragStart","indicator","onlyIndicatorDraggable","rest","cls","useCls","attributes","listeners","isDragging","setNodeRef","useDraggable","indicatorIcon","jsx","DotsSixVerticalIcon","combinedChildren","isValidElement","cloneElement","useRender","clsx"],"mappings":";;;;;;;;AAYO,MAAMA,IAAY,CAAwB;AAAA,EAC/C,IAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,MAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA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+
import { useDroppable as z } from "./hooks.js";
|
|
4
|
+
import { ArrowsOutCardinalIcon as N } from "@bioturing/assets";
|
|
5
|
+
import { useRender as b } from "@base-ui-components/react/use-render";
|
|
6
|
+
import { useCls as C } from "../utils/antdUtils.js";
|
|
7
|
+
import { clsx as D } from "../utils/cn.js";
|
|
8
|
+
const g = ({
|
|
9
|
+
id: o,
|
|
10
|
+
children: n,
|
|
11
|
+
className: s,
|
|
12
|
+
disabled: i = !1,
|
|
13
|
+
placeholder: d = "Drop items here",
|
|
14
|
+
icon: l = /* @__PURE__ */ r(N, { size: 24 }),
|
|
15
|
+
render: t,
|
|
16
|
+
onDrop: c,
|
|
17
|
+
validate: m,
|
|
18
|
+
...p
|
|
19
|
+
}) => {
|
|
20
|
+
const e = C(), { isOver: a, setNodeRef: f, attributes: u, listeners: h } = z({
|
|
21
|
+
id: o,
|
|
22
|
+
disabled: i,
|
|
23
|
+
onDrop: c,
|
|
24
|
+
validate: m
|
|
25
|
+
}), v = /* @__PURE__ */ x("div", { className: e("drop-zone-content"), children: [
|
|
26
|
+
/* @__PURE__ */ r("div", { className: e("drop-zone-icon"), children: l }),
|
|
27
|
+
/* @__PURE__ */ r("div", { className: e("drop-zone-text"), children: d })
|
|
28
|
+
] });
|
|
29
|
+
return b({
|
|
30
|
+
render: t || /* @__PURE__ */ r("div", { className: D(e("drop-zone"), s) }),
|
|
31
|
+
ref: f,
|
|
32
|
+
props: {
|
|
33
|
+
children: n || v,
|
|
34
|
+
className: s,
|
|
35
|
+
...u,
|
|
36
|
+
...h,
|
|
37
|
+
...p
|
|
38
|
+
},
|
|
39
|
+
state: {
|
|
40
|
+
isOver: a,
|
|
41
|
+
id: o
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
g as Droppable
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=droppable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"droppable.js","sources":["../../../src/components/DragDrop/droppable.tsx"],"sourcesContent":["\"use client\";\n\nimport { useDroppable } from \"./hooks\";\nimport { clsx, useCls } from \"../utils\";\nimport { ArrowsOutCardinalIcon } from \"@bioturing/assets\";\nimport { useRender } from \"@base-ui-components/react/use-render\";\nimport type { Data, DragDropDroppableProps } from \"./types\";\n\n/**\n * A drop zone component that can receive draggable items\n * Styled similarly to the Upload component's droppable area\n */\nexport const Droppable = <T extends Data = Data>({\n id,\n children,\n className,\n disabled = false,\n placeholder = \"Drop items here\",\n icon = <ArrowsOutCardinalIcon size={24} />,\n render,\n onDrop,\n validate,\n ...rest\n}: DragDropDroppableProps<T>) => {\n const cls = useCls();\n const { isOver, setNodeRef, attributes, listeners, valid } = useDroppable({\n id,\n disabled,\n onDrop,\n validate,\n });\n\n // Default content when no children are provided\n const defaultContent = (\n <div className={cls(\"drop-zone-content\")}>\n <div className={cls(\"drop-zone-icon\")}>{icon}</div>\n <div className={cls(\"drop-zone-text\")}>{placeholder}</div>\n </div>\n );\n\n const renderedElement = useRender({\n render: render ? (\n render\n ) : (\n <div className={clsx(cls(\"drop-zone\"), className)} />\n ),\n ref: setNodeRef,\n props: {\n children: children || defaultContent,\n className: className,\n ...attributes,\n ...listeners,\n ...rest,\n },\n state: {\n isOver,\n id,\n },\n });\n\n return renderedElement;\n};\n"],"names":["Droppable","id","children","className","disabled","placeholder","icon","jsx","ArrowsOutCardinalIcon","render","onDrop","validate","rest","cls","useCls","isOver","setNodeRef","attributes","listeners","useDroppable","defaultContent","jsxs","useRender","clsx"],"mappings":";;;;;;;AAYO,MAAMA,IAAY,CAAwB;AAAA,EAC/C,IAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,aAAAC,IAAc;AAAA,EACd,MAAAC,IAAO,gBAAAC,EAACC,GAAsB,EAAA,MAAM,GAAI,CAAA;AAAA,EACxC,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,UAAAC;AAAA,EACA,GAAGC;AACL,MAAiC;AAC/B,QAAMC,IAAMC,EAAO,GACb,EAAE,QAAAC,GAAQ,YAAAC,GAAY,YAAAC,GAAY,WAAAC,EAAiB,IAAIC,EAAa;AAAA,IACxE,IAAAlB;AAAA,IACA,UAAAG;AAAA,IACA,QAAAM;AAAA,IACA,UAAAC;AAAA,EAAA,CACD,GAGKS,IACH,gBAAAC,EAAA,OAAA,EAAI,WAAWR,EAAI,mBAAmB,GACrC,UAAA;AAAA,IAAA,gBAAAN,EAAC,OAAI,EAAA,WAAWM,EAAI,gBAAgB,GAAI,UAAKP,GAAA;AAAA,sBAC5C,OAAI,EAAA,WAAWO,EAAI,gBAAgB,GAAI,UAAYR,EAAA,CAAA;AAAA,EAAA,GACtD;AAuBK,SApBiBiB,EAAU;AAAA,IAChC,QAAQb,KAGL,gBAAAF,EAAA,OAAA,EAAI,WAAWgB,EAAKV,EAAI,WAAW,GAAGV,CAAS,EAAG,CAAA;AAAA,IAErD,KAAKa;AAAA,IACL,OAAO;AAAA,MACL,UAAUd,KAAYkB;AAAA,MACtB,WAAAjB;AAAA,MACA,GAAGc;AAAA,MACH,GAAGC;AAAA,MACH,GAAGN;AAAA,IACL;AAAA,IACA,OAAO;AAAA,MACL,QAAAG;AAAA,MACA,IAAAd;AAAA,IAAA;AAAA,EACF,CACD;AAGH;"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { useState as C, useRef as R, useCallback as u, useEffect as J } from "react";
|
|
2
|
+
import { useDragDropContext as A } from "./context.js";
|
|
3
|
+
function z({
|
|
4
|
+
id: c,
|
|
5
|
+
data: t,
|
|
6
|
+
disabled: n = !1,
|
|
7
|
+
onDragStart: h,
|
|
8
|
+
onDragEnd: E
|
|
9
|
+
}) {
|
|
10
|
+
const [g, i] = C(!1), x = R(null), r = R(null), y = u((a) => {
|
|
11
|
+
x.current = a;
|
|
12
|
+
}, []), {
|
|
13
|
+
setActive: o,
|
|
14
|
+
onDragStart: m,
|
|
15
|
+
onDragEnd: v,
|
|
16
|
+
setIsDragging: p
|
|
17
|
+
} = A(), d = h || m, f = E || v, I = u(
|
|
18
|
+
(a) => {
|
|
19
|
+
var D, N, O, T;
|
|
20
|
+
if (n) return;
|
|
21
|
+
i(!0), p(!0);
|
|
22
|
+
const l = { data: t, id: c };
|
|
23
|
+
o(l), d && d({ active: l });
|
|
24
|
+
const e = JSON.stringify({ id: c, data: t });
|
|
25
|
+
(D = a.dataTransfer) == null || D.setData("application/json", e), (N = a.dataTransfer) == null || N.setData("text/plain", e);
|
|
26
|
+
const s = x.current;
|
|
27
|
+
if (s) {
|
|
28
|
+
const j = s.getBoundingClientRect();
|
|
29
|
+
r.current = s.cloneNode(!0), r.current.style.maxWidth = "400px", r.current.style.position = "absolute", r.current.style.pointerEvents = "none", r.current.style.top = "-99px", r.current.style.left = "-99px", r.current.style.zIndex = "-1", (O = s.parentElement) == null || O.appendChild(r.current), (T = a.dataTransfer) == null || T.setDragImage(
|
|
30
|
+
r.current,
|
|
31
|
+
a.clientX - j.left,
|
|
32
|
+
a.clientY - j.top
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
[c, t, n, d, o, p]
|
|
37
|
+
), S = u(
|
|
38
|
+
(a) => {
|
|
39
|
+
var l;
|
|
40
|
+
n || (i(!1), p(!1), (l = r.current) == null || l.remove(), f && f({ active: { data: t, id: c }, over: null }));
|
|
41
|
+
},
|
|
42
|
+
[c, t, n, f, p]
|
|
43
|
+
);
|
|
44
|
+
return {
|
|
45
|
+
isDragging: g,
|
|
46
|
+
setNodeRef: y,
|
|
47
|
+
attributes: {
|
|
48
|
+
draggable: !n,
|
|
49
|
+
role: "button",
|
|
50
|
+
"aria-pressed": g,
|
|
51
|
+
tabIndex: n ? -1 : 0,
|
|
52
|
+
"data-dragging": g ? !0 : void 0,
|
|
53
|
+
"data-disabled": n ? !0 : void 0
|
|
54
|
+
},
|
|
55
|
+
listeners: {
|
|
56
|
+
onDragStart: I,
|
|
57
|
+
onDragEnd: S
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function B({
|
|
62
|
+
id: c,
|
|
63
|
+
disabled: t = !1,
|
|
64
|
+
validate: n = () => !0,
|
|
65
|
+
onDrop: h
|
|
66
|
+
}) {
|
|
67
|
+
const [E, g] = C(!1), [i, x] = C(void 0), r = R(null), y = u((e) => {
|
|
68
|
+
r.current = e;
|
|
69
|
+
}, []), {
|
|
70
|
+
active: o,
|
|
71
|
+
setActive: m,
|
|
72
|
+
onDragEnd: v,
|
|
73
|
+
onDrop: p,
|
|
74
|
+
isDragging: d
|
|
75
|
+
} = A(), f = h || p;
|
|
76
|
+
J(() => {
|
|
77
|
+
o && n && x(n(o));
|
|
78
|
+
}, [o, n]);
|
|
79
|
+
const I = u(
|
|
80
|
+
(e) => {
|
|
81
|
+
t || (e.preventDefault(), g(!0));
|
|
82
|
+
},
|
|
83
|
+
[t]
|
|
84
|
+
), S = u(
|
|
85
|
+
(e) => {
|
|
86
|
+
t || (e.preventDefault(), e.dataTransfer.dropEffect = "move");
|
|
87
|
+
},
|
|
88
|
+
[t]
|
|
89
|
+
), a = u(
|
|
90
|
+
(e) => {
|
|
91
|
+
t || e.currentTarget === e.target && g(!1);
|
|
92
|
+
},
|
|
93
|
+
[t]
|
|
94
|
+
), l = u(
|
|
95
|
+
(e) => {
|
|
96
|
+
if (!t && (e.preventDefault(), !!i))
|
|
97
|
+
try {
|
|
98
|
+
const s = e.dataTransfer.getData("application/json");
|
|
99
|
+
let D;
|
|
100
|
+
if (s)
|
|
101
|
+
D = JSON.parse(s);
|
|
102
|
+
else if (o)
|
|
103
|
+
D = o;
|
|
104
|
+
else
|
|
105
|
+
return;
|
|
106
|
+
f && f(D), v && o && v({
|
|
107
|
+
active: D,
|
|
108
|
+
over: { id: c }
|
|
109
|
+
}), g(!1), m(null);
|
|
110
|
+
} catch (s) {
|
|
111
|
+
console.error("Error processing drop:", s);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
[t, c, o, f, v, m, i]
|
|
115
|
+
);
|
|
116
|
+
return {
|
|
117
|
+
isOver: E,
|
|
118
|
+
setNodeRef: y,
|
|
119
|
+
attributes: {
|
|
120
|
+
"data-droppable": !0,
|
|
121
|
+
"data-over": E ? !0 : void 0,
|
|
122
|
+
"data-disabled": t ? !0 : void 0,
|
|
123
|
+
"data-dragging": d ? !0 : void 0,
|
|
124
|
+
"data-valid": i === !0 ? !0 : void 0
|
|
125
|
+
},
|
|
126
|
+
valid: i,
|
|
127
|
+
listeners: {
|
|
128
|
+
onDragEnter: I,
|
|
129
|
+
onDragOver: S,
|
|
130
|
+
onDragLeave: a,
|
|
131
|
+
onDrop: l
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
z as useDraggable,
|
|
137
|
+
B as useDroppable
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../src/components/DragDrop/hooks.ts"],"sourcesContent":["import { useCallback, useRef, useState, useEffect } from \"react\";\n\nimport {\n DraggableInfo,\n type Data,\n type UseDraggableProps,\n type UseDroppableProps,\n} from \"./types\";\nimport { useDragDropContext } from \"./context\";\n\n/**\n * Hook for making an element draggable using HTML5 drag and drop API\n */\nexport function useDraggable<T extends Data = Data>({\n id,\n data,\n disabled = false,\n onDragStart: onDragStartProp,\n onDragEnd: onDragEndProp,\n}: UseDraggableProps<T>) {\n const [isDragging, setIsDragging] = useState(false);\n const nodeRef = useRef<HTMLElement | null>(null);\n const thumbnailNodeRef = useRef<HTMLElement | null>(null);\n\n const setNodeRef = useCallback((node: HTMLElement | null) => {\n nodeRef.current = node;\n }, []);\n\n const {\n setActive,\n onDragStart: onDragStartContext,\n onDragEnd: onDragEndContext,\n setIsDragging: setIsDraggingContext,\n } = useDragDropContext();\n\n const onDragStart = onDragStartProp || onDragStartContext;\n const onDragEnd = onDragEndProp || onDragEndContext;\n\n const handleDragStart = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n\n setIsDragging(true);\n setIsDraggingContext(true);\n\n // Update the active item in context\n const dragItem = { data, id };\n setActive(dragItem);\n\n // Call the onDragStart callback if available\n if (onDragStart) {\n onDragStart({ active: dragItem });\n }\n\n // Set data transfer\n const dataPayload = JSON.stringify({ id, data });\n e.dataTransfer?.setData(\"application/json\", dataPayload);\n\n // For Firefox compatibility\n e.dataTransfer?.setData(\"text/plain\", dataPayload);\n\n // Set drag image (optional)\n const node = nodeRef.current;\n if (node) {\n const nodeRect = node.getBoundingClientRect();\n\n thumbnailNodeRef.current = node.cloneNode(true) as HTMLElement;\n thumbnailNodeRef.current.style.maxWidth = \"400px\";\n thumbnailNodeRef.current.style.position = \"absolute\";\n thumbnailNodeRef.current.style.pointerEvents = \"none\";\n thumbnailNodeRef.current.style.top = \"-99px\";\n thumbnailNodeRef.current.style.left = \"-99px\";\n thumbnailNodeRef.current.style.zIndex = \"-1\";\n\n node.parentElement?.appendChild(thumbnailNodeRef.current);\n\n // Use the node itself as the drag image\n e.dataTransfer?.setDragImage(\n thumbnailNodeRef.current,\n e.clientX - nodeRect.left,\n e.clientY - nodeRect.top\n );\n }\n },\n [id, data, disabled, onDragStart, setActive, setIsDraggingContext]\n );\n\n const handleDragEnd = useCallback(\n (_e: React.DragEvent) => {\n if (disabled) return;\n\n setIsDragging(false);\n setIsDraggingContext(false);\n thumbnailNodeRef.current?.remove();\n\n if (onDragEnd) {\n onDragEnd({ active: { data, id }, over: null });\n }\n },\n [id, data, disabled, onDragEnd, setIsDraggingContext]\n );\n\n return {\n isDragging,\n setNodeRef,\n attributes: {\n draggable: !disabled,\n role: \"button\",\n \"aria-pressed\": isDragging,\n tabIndex: disabled ? -1 : 0,\n \"data-dragging\": isDragging ? true : undefined,\n \"data-disabled\": disabled ? true : undefined,\n },\n listeners: {\n onDragStart: handleDragStart,\n onDragEnd: handleDragEnd,\n },\n };\n}\n\n/**\n * Hook for making an element a drop target using HTML5 drag and drop API\n */\nexport function useDroppable<T extends Data = Data>({\n id,\n disabled = false,\n validate = () => true,\n onDrop: onDropProp,\n}: UseDroppableProps<T>) {\n const [isOver, setIsOver] = useState(false);\n const [valid, setValid] = useState(undefined);\n const nodeRef = useRef<HTMLElement | null>(null);\n\n const setNodeRef = useCallback((node: HTMLElement | null) => {\n nodeRef.current = node;\n }, []);\n\n const {\n active,\n setActive,\n onDragEnd,\n onDrop: onDropContext,\n isDragging,\n } = useDragDropContext<T>();\n\n const onDrop = onDropProp || onDropContext;\n\n useEffect(() => {\n if (active && validate) {\n setValid(validate(active));\n }\n }, [active, validate]);\n\n const handleDragEnter = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n setIsOver(true);\n },\n [disabled]\n );\n\n const handleDragOver = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault(); // Necessary to allow dropping\n e.dataTransfer.dropEffect = \"move\";\n },\n [disabled]\n );\n\n const handleDragLeave = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n // Only set isOver to false if we're leaving this element (not a child)\n if (e.currentTarget === e.target) {\n setIsOver(false);\n }\n },\n [disabled]\n );\n\n const handleDrop = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n if (!valid) return;\n\n try {\n // Try to get data from dataTransfer\n const jsonData = e.dataTransfer.getData(\"application/json\");\n let draggedItem: DraggableInfo<T>;\n\n if (jsonData) {\n draggedItem = JSON.parse(jsonData);\n } else if (active) {\n // Fall back to active item from context if dataTransfer is not available\n draggedItem = active;\n } else {\n return; // No item to drop\n }\n\n // Call the component's onDrop handler if provided\n if (onDrop) {\n onDrop(draggedItem);\n }\n\n // Call the onDragEnd callback from context if available\n if (onDragEnd && active) {\n onDragEnd({\n active: draggedItem,\n over: { id },\n });\n }\n\n setIsOver(false);\n\n // Reset the active item in context\n setActive(null);\n } catch (error) {\n console.error(\"Error processing drop:\", error);\n }\n },\n [disabled, id, active, onDrop, onDragEnd, setActive, valid]\n );\n\n return {\n isOver,\n setNodeRef,\n attributes: {\n \"data-droppable\": true,\n \"data-over\": isOver ? true : undefined,\n \"data-disabled\": disabled ? true : undefined,\n \"data-dragging\": isDragging ? true : undefined,\n \"data-valid\": valid === true ? true : undefined,\n },\n valid,\n listeners: {\n onDragEnter: handleDragEnter,\n onDragOver: handleDragOver,\n onDragLeave: handleDragLeave,\n onDrop: handleDrop,\n },\n };\n}\n"],"names":["useDraggable","id","data","disabled","onDragStartProp","onDragEndProp","isDragging","setIsDragging","useState","nodeRef","useRef","thumbnailNodeRef","setNodeRef","useCallback","node","setActive","onDragStartContext","onDragEndContext","setIsDraggingContext","useDragDropContext","onDragStart","onDragEnd","handleDragStart","e","dragItem","dataPayload","_a","_b","nodeRect","_c","_d","handleDragEnd","_e","useDroppable","validate","onDropProp","isOver","setIsOver","valid","setValid","active","onDropContext","onDrop","useEffect","handleDragEnter","handleDragOver","handleDragLeave","handleDrop","jsonData","draggedItem","error"],"mappings":";;AAaO,SAASA,EAAoC;AAAA,EAClD,IAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,aAAaC;AAAA,EACb,WAAWC;AACb,GAAyB;AACvB,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAS,EAAK,GAC5CC,IAAUC,EAA2B,IAAI,GACzCC,IAAmBD,EAA2B,IAAI,GAElDE,IAAaC,EAAY,CAACC,MAA6B;AAC3D,IAAAL,EAAQ,UAAUK;AAAA,EACpB,GAAG,EAAE,GAEC;AAAA,IACJ,WAAAC;AAAA,IACA,aAAaC;AAAA,IACb,WAAWC;AAAA,IACX,eAAeC;AAAA,MACbC,EAAmB,GAEjBC,IAAchB,KAAmBY,GACjCK,IAAYhB,KAAiBY,GAE7BK,IAAkBT;AAAA,IACtB,CAACU,MAAuB;;AACtB,UAAIpB,EAAU;AAEd,MAAAI,EAAc,EAAI,GAClBW,E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
3
|
+
import { useState as o } from "react";
|
|
4
|
+
import { Draggable as f } from "./draggable.js";
|
|
5
|
+
import { Droppable as u } from "./droppable.js";
|
|
6
|
+
import { DragDropContext as d } from "./context.js";
|
|
7
|
+
import './style.css';/* empty css */
|
|
8
|
+
import { useCls as v } from "../utils/antdUtils.js";
|
|
9
|
+
import { clsx as x } from "../utils/cn.js";
|
|
10
|
+
function b({
|
|
11
|
+
children: t,
|
|
12
|
+
// These callbacks are passed to child components via context
|
|
13
|
+
onDragEnd: n,
|
|
14
|
+
onDragStart: e,
|
|
15
|
+
onDrop: a,
|
|
16
|
+
className: s
|
|
17
|
+
}) {
|
|
18
|
+
const i = v(), [c, g] = o(null), [m, p] = o(!1), D = {
|
|
19
|
+
active: c,
|
|
20
|
+
setActive: (l) => {
|
|
21
|
+
g(l);
|
|
22
|
+
},
|
|
23
|
+
isDragging: m,
|
|
24
|
+
setIsDragging: p,
|
|
25
|
+
onDragStart: e,
|
|
26
|
+
onDragEnd: n,
|
|
27
|
+
onDrop: a
|
|
28
|
+
};
|
|
29
|
+
return /* @__PURE__ */ r(d.Provider, { value: D, children: /* @__PURE__ */ r("div", { className: x(i("drag-container"), s), children: t }) });
|
|
30
|
+
}
|
|
31
|
+
const O = Object.assign(b, {
|
|
32
|
+
/**
|
|
33
|
+
* Item that can be dragged
|
|
34
|
+
*/
|
|
35
|
+
Draggable: f,
|
|
36
|
+
/**
|
|
37
|
+
* Zone where items can be dropped
|
|
38
|
+
*/
|
|
39
|
+
Droppable: u
|
|
40
|
+
});
|
|
41
|
+
export {
|
|
42
|
+
O as DragDrop,
|
|
43
|
+
b as DragDropRoot
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/DragDrop/index.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type DragEndEvent,\n type DragStartEvent,\n type Data as DragData,\n type UniqueIdentifier,\n type DragDropDraggableProps,\n type DragDropDroppableProps,\n type DragDropProps,\n} from \"./types\";\nimport { useState } from \"react\";\nimport { clsx, useCls } from \"../utils\";\nimport { Draggable } from \"./draggable\";\nimport { Droppable } from \"./droppable\";\nimport { DragDropContext } from \"./context\";\n\n// Import component-specific styles\nimport \"./style.css\";\n\n/**\n * The root component for the drag and drop functionality\n */\nexport function DragDropRoot<T extends DragData = DragData>({\n children,\n // These callbacks are passed to child components via context\n onDragEnd: _onDragEnd,\n onDragStart: _onDragStart,\n onDrop: _onDrop,\n className,\n}: DragDropProps<T>) {\n const cls = useCls();\n const [active, setActive] = useState<{\n data: T;\n id: UniqueIdentifier;\n } | null>(null);\n\n const [isDragging, setIsDragging] = useState(false);\n\n // These functions are now handled directly in the Item and DropZone components\n\n // Create context value for child components\n const contextValue = {\n active,\n setActive: (item: { data: unknown; id: UniqueIdentifier } | null) => {\n setActive(item as { data: T; id: UniqueIdentifier } | null);\n },\n isDragging,\n setIsDragging,\n onDragStart: _onDragStart,\n onDragEnd: _onDragEnd,\n onDrop: _onDrop,\n };\n\n return (\n <DragDropContext.Provider value={contextValue}>\n <div className={clsx(cls(\"drag-container\"), className)}>{children}</div>\n </DragDropContext.Provider>\n );\n}\n\n/**\n * Drag component with subcomponents\n */\nexport const DragDrop = Object.assign(DragDropRoot, {\n /**\n * Item that can be dragged\n */\n Draggable,\n\n /**\n * Zone where items can be dropped\n */\n Droppable,\n});\n\nexport type {\n DragEndEvent,\n DragStartEvent,\n DragDropDraggableProps,\n DragDropDroppableProps,\n DragData,\n DragDropProps,\n};\n"],"names":["DragDropRoot","children","_onDragEnd","_onDragStart","_onDrop","className","cls","useCls","active","setActive","useState","isDragging","setIsDragging","contextValue","item","DragDropContext","jsx","clsx","DragDrop","Draggable","Droppable"],"mappings":";;;;;;;;;AAuBO,SAASA,EAA4C;AAAA,EAC1D,UAAAC;AAAA;AAAA,EAEA,WAAWC;AAAA,EACX,aAAaC;AAAA,EACb,QAAQC;AAAA,EACR,WAAAC;AACF,GAAqB;AACnB,QAAMC,IAAMC,EAAO,GACb,CAACC,GAAQC,CAAS,IAAIC,EAGlB,IAAI,GAER,CAACC,GAAYC,CAAa,IAAIF,EAAS,EAAK,GAK5CG,IAAe;AAAA,IACnB,QAAAL;AAAA,IACA,WAAW,CAACM,MAAyD;AACnE,MAAAL,EAAUK,CAAgD;AAAA,IAC5D;AAAA,IACA,YAAAH;AAAA,IACA,eAAAC;AAAA,IACA,aAAaT;AAAA,IACb,WAAWD;AAAA,IACX,QAAQE;AAAA,EACV;AAEA,2BACGW,EAAgB,UAAhB,EAAyB,OAAOF,GAC/B,UAAC,gBAAAG,EAAA,OAAA,EAAI,WAAWC,EAAKX,EAAI,gBAAgB,GAAGD,CAAS,GAAI,UAAAJ,EAAS,CAAA,GACpE;AAEJ;AAKa,MAAAiB,IAAW,OAAO,OAAOlB,GAAc;AAAA;AAAA;AAAA;AAAA,EAIlD,WAAAmB;AAAA;AAAA;AAAA;AAAA,EAKA,WAAAC;AACF,CAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ds-drag-container{position:relative}.ds-draggable{position:relative;cursor:grab;-webkit-user-select:none;user-select:none;background-color:var(--ds-color-bg-container);border:1px solid var(--ds-color-border);border-radius:var(--ds-border-radius);padding:.5rem;margin-bottom:.5rem;display:flex;max-width:100%;gap:.5rem;transition:background-color .2s,border-color .2s,box-shadow .2s}.ds-draggable[data-dragging]{opacity:.5;box-shadow:0 2px 8px #00000026;z-index:1}.ds-draggable[data-disabled]{cursor:not-allowed;opacity:.5;background-color:var(--ds-color-bg-disabled)}.ds-draggable:hover{border-color:var(--ds-color-primary)}.ds-draggable .ds-draggable-indicator{font-size:1.25rem;color:var(--ds-color-icon)}.ds-drop-zone{position:relative;width:100%;background-color:var(--ds-color-fill-alter);border:1px dashed var(--ds-color-border);border-radius:var(--ds-border-radius);padding:.75rem;display:flex;align-items:center;justify-content:center;transition:border-color .1s,background-color .1s}.ds-drop-zone[data-disabled=true]{cursor:not-allowed;background-color:var(--ds-color-bg-disabled);border-color:var(--ds-color-border)}.ds-drop-zone[data-dropping][data-valid],.ds-drop-zone[data-over][data-valid]{border-color:var(--ds-color-primary);background-color:var(--ds-color-primary-bg)}.ds-drop-zone[data-dragging][data-valid]{border-color:var(--ds-color-primary)}.ds-drop-zone .ds-drop-zone-content{display:flex;align-items:center;justify-content:center;text-align:center;gap:.5rem}.ds-drop-zone .ds-drop-zone-icon{font-size:1.25rem;color:var(--ds-color-icon)}.ds-drop-zone .ds-drop-zone-text{color:var(--ds-color-text-description);font-size:var(--ds-font-size)}
|