@particle-academy/react-fancy 2.8.0 → 2.8.1
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/index.cjs +64 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11152,12 +11152,30 @@ function countCardChildren(children) {
|
|
|
11152
11152
|
n += 1;
|
|
11153
11153
|
return;
|
|
11154
11154
|
}
|
|
11155
|
-
|
|
11156
|
-
|
|
11157
|
-
}
|
|
11155
|
+
const inner = child.props.children;
|
|
11156
|
+
if (inner !== void 0) n += countCardChildren(inner);
|
|
11158
11157
|
});
|
|
11159
11158
|
return n;
|
|
11160
11159
|
}
|
|
11160
|
+
function findCardIndex(children, cardId) {
|
|
11161
|
+
let idx = -1;
|
|
11162
|
+
let i = 0;
|
|
11163
|
+
function walk2(nodes) {
|
|
11164
|
+
Children.forEach(nodes, (child) => {
|
|
11165
|
+
if (idx !== -1) return;
|
|
11166
|
+
if (!isValidElement(child)) return;
|
|
11167
|
+
if (child.type === KanbanCard) {
|
|
11168
|
+
if (child.props.id === cardId) idx = i;
|
|
11169
|
+
i += 1;
|
|
11170
|
+
return;
|
|
11171
|
+
}
|
|
11172
|
+
const inner = child.props.children;
|
|
11173
|
+
if (inner !== void 0) walk2(inner);
|
|
11174
|
+
});
|
|
11175
|
+
}
|
|
11176
|
+
walk2(children);
|
|
11177
|
+
return idx;
|
|
11178
|
+
}
|
|
11161
11179
|
function KanbanColumn({
|
|
11162
11180
|
children,
|
|
11163
11181
|
id,
|
|
@@ -11170,26 +11188,46 @@ function KanbanColumn({
|
|
|
11170
11188
|
const { onCardMove, draggedCard, dragSource, registerColumn } = useKanban();
|
|
11171
11189
|
const [dragOver, setDragOver] = useState(false);
|
|
11172
11190
|
const [dropIndex, setDropIndex] = useState(null);
|
|
11191
|
+
const [dropY, setDropY] = useState(null);
|
|
11173
11192
|
const cardsRef = useRef(null);
|
|
11174
11193
|
useEffect(() => registerColumn(id), [id, registerColumn]);
|
|
11175
|
-
const
|
|
11194
|
+
const updateDrop = useCallback((clientY) => {
|
|
11176
11195
|
const container = cardsRef.current;
|
|
11177
11196
|
if (!container) {
|
|
11178
11197
|
setDropIndex(null);
|
|
11198
|
+
setDropY(null);
|
|
11179
11199
|
return;
|
|
11180
11200
|
}
|
|
11181
|
-
const
|
|
11182
|
-
|
|
11201
|
+
const all = Array.from(
|
|
11202
|
+
container.querySelectorAll(
|
|
11203
|
+
"[data-react-fancy-kanban-card]"
|
|
11204
|
+
)
|
|
11205
|
+
);
|
|
11206
|
+
const cards = all.filter(
|
|
11207
|
+
(el) => el.closest("[data-react-fancy-kanban-column]") === cardsRef.current?.closest("[data-react-fancy-kanban-column]")
|
|
11183
11208
|
);
|
|
11209
|
+
const containerRect = container.getBoundingClientRect();
|
|
11210
|
+
if (cards.length === 0) {
|
|
11211
|
+
setDropIndex(0);
|
|
11212
|
+
setDropY(0);
|
|
11213
|
+
return;
|
|
11214
|
+
}
|
|
11184
11215
|
let idx = cards.length;
|
|
11216
|
+
let yRel = 0;
|
|
11185
11217
|
for (let i = 0; i < cards.length; i++) {
|
|
11186
11218
|
const rect = cards[i].getBoundingClientRect();
|
|
11187
11219
|
if (clientY < rect.top + rect.height / 2) {
|
|
11188
11220
|
idx = i;
|
|
11221
|
+
yRel = rect.top - containerRect.top;
|
|
11189
11222
|
break;
|
|
11190
11223
|
}
|
|
11191
11224
|
}
|
|
11225
|
+
if (idx === cards.length) {
|
|
11226
|
+
const last = cards[cards.length - 1].getBoundingClientRect();
|
|
11227
|
+
yRel = last.bottom - containerRect.top;
|
|
11228
|
+
}
|
|
11192
11229
|
setDropIndex(idx);
|
|
11230
|
+
setDropY(yRel);
|
|
11193
11231
|
}, []);
|
|
11194
11232
|
const handleDragOver = useCallback(
|
|
11195
11233
|
(e) => {
|
|
@@ -11197,14 +11235,15 @@ function KanbanColumn({
|
|
|
11197
11235
|
e.preventDefault();
|
|
11198
11236
|
e.stopPropagation();
|
|
11199
11237
|
setDragOver(true);
|
|
11200
|
-
|
|
11238
|
+
updateDrop(e.clientY);
|
|
11201
11239
|
},
|
|
11202
|
-
[draggedCard,
|
|
11240
|
+
[draggedCard, updateDrop]
|
|
11203
11241
|
);
|
|
11204
11242
|
const handleDragLeave = useCallback((e) => {
|
|
11205
11243
|
if (e.currentTarget.contains(e.relatedTarget)) return;
|
|
11206
11244
|
setDragOver(false);
|
|
11207
11245
|
setDropIndex(null);
|
|
11246
|
+
setDropY(null);
|
|
11208
11247
|
}, []);
|
|
11209
11248
|
const handleDrop = useCallback(
|
|
11210
11249
|
(e) => {
|
|
@@ -11212,16 +11251,15 @@ function KanbanColumn({
|
|
|
11212
11251
|
e.preventDefault();
|
|
11213
11252
|
e.stopPropagation();
|
|
11214
11253
|
const target = dropIndex ?? 0;
|
|
11215
|
-
if (dragSource
|
|
11254
|
+
if (dragSource) {
|
|
11216
11255
|
let finalIdx = target;
|
|
11217
11256
|
if (dragSource === id) {
|
|
11218
11257
|
const srcIdx = findCardIndex(children, draggedCard);
|
|
11219
|
-
if (srcIdx !== -1 && target > srcIdx)
|
|
11220
|
-
finalIdx = target - 1;
|
|
11221
|
-
}
|
|
11258
|
+
if (srcIdx !== -1 && target > srcIdx) finalIdx = target - 1;
|
|
11222
11259
|
if (srcIdx === finalIdx) {
|
|
11223
11260
|
setDragOver(false);
|
|
11224
11261
|
setDropIndex(null);
|
|
11262
|
+
setDropY(null);
|
|
11225
11263
|
return;
|
|
11226
11264
|
}
|
|
11227
11265
|
}
|
|
@@ -11229,27 +11267,13 @@ function KanbanColumn({
|
|
|
11229
11267
|
}
|
|
11230
11268
|
setDragOver(false);
|
|
11231
11269
|
setDropIndex(null);
|
|
11270
|
+
setDropY(null);
|
|
11232
11271
|
},
|
|
11233
11272
|
[draggedCard, dragSource, dropIndex, id, onCardMove, children]
|
|
11234
11273
|
);
|
|
11235
11274
|
const cardCount = countCardChildren(children);
|
|
11236
|
-
if (hideWhenEmpty && cardCount === 0 && !draggedCard)
|
|
11237
|
-
|
|
11238
|
-
}
|
|
11239
|
-
let cardSeen = 0;
|
|
11240
|
-
const showIndicator = draggedCard !== null && dropIndex !== null && dragOver;
|
|
11241
|
-
const renderedChildren = Children.toArray(children).map((child, i) => {
|
|
11242
|
-
const isCard = isValidElement(child) && child.type === KanbanCard;
|
|
11243
|
-
const indicator = showIndicator && isCard && cardSeen === dropIndex ? /* @__PURE__ */ jsx(DropIndicator, {}, `drop-${i}`) : null;
|
|
11244
|
-
if (isCard) cardSeen += 1;
|
|
11245
|
-
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
11246
|
-
indicator,
|
|
11247
|
-
child
|
|
11248
|
-
] }, i);
|
|
11249
|
-
});
|
|
11250
|
-
if (showIndicator && dropIndex === cardCount) {
|
|
11251
|
-
renderedChildren.push(/* @__PURE__ */ jsx(DropIndicator, {}, "drop-end"));
|
|
11252
|
-
}
|
|
11275
|
+
if (hideWhenEmpty && cardCount === 0 && !draggedCard) return null;
|
|
11276
|
+
const showIndicator = draggedCard !== null && dropIndex !== null && dropY !== null && dragOver;
|
|
11253
11277
|
const overWip = wipLimit !== void 0 && cardCount > wipLimit;
|
|
11254
11278
|
return /* @__PURE__ */ jsx(KanbanColumnContext.Provider, { value: id, children: /* @__PURE__ */ jsxs(
|
|
11255
11279
|
"div",
|
|
@@ -11284,36 +11308,22 @@ function KanbanColumn({
|
|
|
11284
11308
|
}
|
|
11285
11309
|
)
|
|
11286
11310
|
] }),
|
|
11287
|
-
/* @__PURE__ */
|
|
11311
|
+
/* @__PURE__ */ jsxs("div", { ref: cardsRef, className: "relative flex flex-1 flex-col gap-2", children: [
|
|
11312
|
+
children,
|
|
11313
|
+
showIndicator && /* @__PURE__ */ jsx(
|
|
11314
|
+
"div",
|
|
11315
|
+
{
|
|
11316
|
+
"data-react-fancy-kanban-drop-indicator": "",
|
|
11317
|
+
style: { top: dropY },
|
|
11318
|
+
className: "pointer-events-none absolute left-0 right-0 h-0.5 -translate-y-1/2 rounded-full bg-blue-500/80 shadow-[0_0_0_3px_rgba(59,130,246,0.15)]"
|
|
11319
|
+
}
|
|
11320
|
+
)
|
|
11321
|
+
] })
|
|
11288
11322
|
]
|
|
11289
11323
|
}
|
|
11290
11324
|
) });
|
|
11291
11325
|
}
|
|
11292
11326
|
KanbanColumn.displayName = "KanbanColumn";
|
|
11293
|
-
function DropIndicator() {
|
|
11294
|
-
return /* @__PURE__ */ jsx(
|
|
11295
|
-
"div",
|
|
11296
|
-
{
|
|
11297
|
-
"data-react-fancy-kanban-drop-indicator": "",
|
|
11298
|
-
className: "h-0.5 -my-1 rounded-full bg-blue-500/80"
|
|
11299
|
-
}
|
|
11300
|
-
);
|
|
11301
|
-
}
|
|
11302
|
-
function findCardIndex(children, cardId) {
|
|
11303
|
-
let idx = -1;
|
|
11304
|
-
let i = 0;
|
|
11305
|
-
Children.forEach(children, (child) => {
|
|
11306
|
-
if (idx !== -1) return;
|
|
11307
|
-
if (!isValidElement(child)) return;
|
|
11308
|
-
if (child.type === KanbanCard) {
|
|
11309
|
-
if (child.props.id === cardId) {
|
|
11310
|
-
idx = i;
|
|
11311
|
-
}
|
|
11312
|
-
i += 1;
|
|
11313
|
-
}
|
|
11314
|
-
});
|
|
11315
|
-
return idx;
|
|
11316
|
-
}
|
|
11317
11327
|
function KanbanColumnHandle({
|
|
11318
11328
|
children,
|
|
11319
11329
|
className
|