klun-ui 0.4.0 → 0.4.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.
@@ -3,6 +3,9 @@
3
3
  var chunkTPGAXYFU_cjs = require('./chunk-TPGAXYFU.cjs');
4
4
  var react = require('react');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
+ var core = require('@dnd-kit/core');
7
+ var sortable = require('@dnd-kit/sortable');
8
+ var utilities = require('@dnd-kit/utilities');
6
9
  var reactDom = require('react-dom');
7
10
  var client = require('react-dom/client');
8
11
 
@@ -3344,15 +3347,70 @@ var DiffViewer = react.forwardRef(function DiffViewer2({
3344
3347
  );
3345
3348
  });
3346
3349
  DiffViewer.displayName = "DiffViewer";
3347
- var Kanban = react.forwardRef(function Kanban2({ columns = [], onMove, onCardClick, renderCard, columnFooter, columnWidth = 280, className, style, ...props }, ref) {
3348
- const [drag, setDrag] = react.useState(null);
3349
- const [overColumn, setOverColumn] = react.useState(null);
3350
- const handleDrop = (column, index) => {
3351
- if (drag && (drag.fromColumn !== column.id || index !== index)) {
3352
- onMove?.(drag.cardId, drag.fromColumn, column.id, index);
3353
- }
3354
- setDrag(null);
3355
- setOverColumn(null);
3350
+ function draggedCenterY(active, delta) {
3351
+ const translated = active.rect.current.translated;
3352
+ if (translated) return translated.top + translated.height / 2;
3353
+ const initial = active.rect.current.initial;
3354
+ return initial ? initial.top + delta.y + initial.height / 2 : null;
3355
+ }
3356
+ function resolveMove(columns, activeId, overId, after) {
3357
+ if (activeId === overId) return null;
3358
+ const from = columns.find((c) => c.cards.some((k2) => k2.id === activeId));
3359
+ if (!from) return null;
3360
+ const overCard = columns.flatMap((c) => c.cards).find((k2) => k2.id === overId);
3361
+ const to = overCard ? columns.find((c) => c.cards.some((k2) => k2.id === overCard.id)) : columns.find((c) => c.id === overId);
3362
+ if (!to) return null;
3363
+ const rest = to.cards.filter((k2) => k2.id !== activeId);
3364
+ const toIndex = overCard ? rest.findIndex((k2) => k2.id === overCard.id) + (after ? 1 : 0) : rest.length;
3365
+ if (to.id === from.id && from.cards.findIndex((k2) => k2.id === activeId) === toIndex) {
3366
+ return null;
3367
+ }
3368
+ return { fromColumn: from.id, toColumn: to.id, toIndex };
3369
+ }
3370
+ var Kanban = react.forwardRef(function Kanban2({
3371
+ columns = [],
3372
+ onMove,
3373
+ onCardClick,
3374
+ renderCard,
3375
+ columnFooter,
3376
+ columnWidth = 280,
3377
+ className,
3378
+ style,
3379
+ ...props
3380
+ }, ref) {
3381
+ const [over, setOver] = react.useState(null);
3382
+ const sensors = core.useSensors(
3383
+ core.useSensor(core.PointerSensor, { activationConstraint: { distance: 4 } }),
3384
+ core.useSensor(core.KeyboardSensor, { coordinateGetter: sortable.sortableKeyboardCoordinates })
3385
+ );
3386
+ const columnOf = (cardId) => columns.find((c) => c.cards.some((k2) => k2.id === cardId));
3387
+ const computeOver = ({
3388
+ active,
3389
+ delta,
3390
+ over: o
3391
+ }) => {
3392
+ if (!o) return null;
3393
+ const overId = String(o.id);
3394
+ const column = columnOf(overId);
3395
+ if (!column) return { columnId: overId };
3396
+ const centerY = draggedCenterY(active, delta);
3397
+ return {
3398
+ columnId: column.id,
3399
+ cardId: overId,
3400
+ after: centerY != null && centerY > o.rect.top + o.rect.height / 2
3401
+ };
3402
+ };
3403
+ const handleDragEnd = ({ active, delta, over: o }) => {
3404
+ setOver(null);
3405
+ if (!o) return;
3406
+ const overId = String(o.id);
3407
+ const column = columnOf(overId);
3408
+ const centerY = column ? draggedCenterY(active, delta) : null;
3409
+ const after = centerY != null && centerY > o.rect.top + o.rect.height / 2;
3410
+ const target = resolveMove(columns, String(active.id), overId, after);
3411
+ if (target) {
3412
+ onMove?.(String(active.id), target.fromColumn, target.toColumn, target.toIndex);
3413
+ }
3356
3414
  };
3357
3415
  return /* @__PURE__ */ jsxRuntime.jsx(
3358
3416
  "div",
@@ -3361,87 +3419,118 @@ var Kanban = react.forwardRef(function Kanban2({ columns = [], onMove, onCardCli
3361
3419
  className: chunkTPGAXYFU_cjs.cx("klun-kanban", className),
3362
3420
  style: { ...style, ["--klun-kanban-col"]: `${columnWidth}px` },
3363
3421
  ...props,
3364
- children: columns.map((column) => {
3365
- const over = overColumn === column.id && drag;
3366
- const full = column.limit !== void 0 && column.cards.length >= column.limit;
3367
- return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: chunkTPGAXYFU_cjs.cx("klun-kanban__column", over && "klun-kanban__column--over"), children: [
3368
- /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "klun-kanban__header", children: [
3369
- column.accent ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-kanban__dot", style: { background: column.accent } }) : null,
3370
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-kanban__title", children: column.title }),
3371
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: chunkTPGAXYFU_cjs.cx("klun-kanban__count", full && "klun-kanban__count--full"), children: [
3372
- column.cards.length,
3373
- column.limit !== void 0 ? ` / ${column.limit}` : ""
3374
- ] })
3375
- ] }),
3376
- /* @__PURE__ */ jsxRuntime.jsxs(
3377
- "div",
3422
+ children: /* @__PURE__ */ jsxRuntime.jsx(
3423
+ core.DndContext,
3424
+ {
3425
+ sensors,
3426
+ collisionDetection: core.closestCorners,
3427
+ onDragOver: (e) => setOver(computeOver(e)),
3428
+ onDragMove: (e) => setOver(computeOver(e)),
3429
+ onDragEnd: handleDragEnd,
3430
+ children: columns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(
3431
+ KanbanColumnView,
3378
3432
  {
3379
- className: "klun-kanban__list",
3380
- onDragOver: (e) => {
3381
- if (!drag) return;
3382
- e.preventDefault();
3383
- setOverColumn(column.id);
3384
- },
3385
- onDrop: (e) => {
3386
- e.preventDefault();
3387
- handleDrop(column, column.cards.length);
3388
- },
3389
- children: [
3390
- column.cards.map((card, index) => /* @__PURE__ */ jsxRuntime.jsx(
3391
- "article",
3392
- {
3393
- draggable: true,
3394
- onDragStart: (e) => {
3395
- e.dataTransfer.effectAllowed = "move";
3396
- e.dataTransfer.setData("text/plain", card.id);
3397
- setDrag({ cardId: card.id, fromColumn: column.id });
3398
- },
3399
- onDragEnd: () => {
3400
- setDrag(null);
3401
- setOverColumn(null);
3402
- },
3403
- onDragOver: (e) => {
3404
- if (!drag) return;
3405
- e.preventDefault();
3406
- e.stopPropagation();
3407
- const rect = e.currentTarget.getBoundingClientRect();
3408
- const after = e.clientY - rect.top > rect.height / 2;
3409
- setOverColumn(column.id);
3410
- setDrag((d) => d ? { ...d, overColumn: column.id, overIndex: index + (after ? 1 : 0) } : d);
3411
- },
3412
- onDrop: (e) => {
3413
- e.preventDefault();
3414
- e.stopPropagation();
3415
- handleDrop(column, index);
3416
- },
3417
- onClick: () => onCardClick?.(card, column.id),
3418
- className: chunkTPGAXYFU_cjs.cx(
3419
- "klun-kanban__card",
3420
- drag?.cardId === card.id && "klun-kanban__card--dragging",
3421
- over && drag?.overIndex === index && "klun-kanban__card--dropbefore",
3422
- over && drag?.overIndex === index + 1 && "klun-kanban__card--dropafter"
3423
- ),
3424
- style: card.accent ? { boxShadow: `inset 3px 0 0 ${card.accent}` } : void 0,
3425
- children: renderCard ? renderCard(card, column.id) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3426
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__card-title", children: card.title }),
3427
- card.description ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__card-desc", children: card.description }) : null,
3428
- card.tags?.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__card-tags", children: card.tags.map((t, i) => /* @__PURE__ */ jsxRuntime.jsx("span", { children: t }, i)) }) : null,
3429
- card.meta ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__card-meta", children: card.meta }) : null
3430
- ] })
3431
- },
3432
- card.id
3433
- )),
3434
- column.cards.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__empty", children: "Drop a card here" }) : null
3435
- ]
3436
- }
3437
- ),
3438
- columnFooter ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__footer", children: columnFooter(column) }) : null
3439
- ] }, column.id);
3440
- })
3433
+ column,
3434
+ over,
3435
+ onCardClick,
3436
+ renderCard,
3437
+ columnFooter
3438
+ },
3439
+ column.id
3440
+ ))
3441
+ }
3442
+ )
3441
3443
  }
3442
3444
  );
3443
3445
  });
3444
3446
  Kanban.displayName = "Kanban";
3447
+ function KanbanColumnView({
3448
+ column,
3449
+ over,
3450
+ onCardClick,
3451
+ renderCard,
3452
+ columnFooter
3453
+ }) {
3454
+ const { setNodeRef } = core.useDroppable({ id: column.id });
3455
+ const isOver = over?.columnId === column.id;
3456
+ const full = column.limit !== void 0 && column.cards.length >= column.limit;
3457
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: chunkTPGAXYFU_cjs.cx("klun-kanban__column", isOver && "klun-kanban__column--over"), children: [
3458
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "klun-kanban__header", children: [
3459
+ column.accent ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-kanban__dot", style: { background: column.accent } }) : null,
3460
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-kanban__title", children: column.title }),
3461
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: chunkTPGAXYFU_cjs.cx("klun-kanban__count", full && "klun-kanban__count--full"), children: [
3462
+ column.cards.length,
3463
+ column.limit !== void 0 ? ` / ${column.limit}` : ""
3464
+ ] })
3465
+ ] }),
3466
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: setNodeRef, className: "klun-kanban__list", children: [
3467
+ /* @__PURE__ */ jsxRuntime.jsx(
3468
+ sortable.SortableContext,
3469
+ {
3470
+ items: column.cards.map((c) => c.id),
3471
+ strategy: sortable.verticalListSortingStrategy,
3472
+ children: column.cards.map((card) => /* @__PURE__ */ jsxRuntime.jsx(
3473
+ KanbanCardView,
3474
+ {
3475
+ card,
3476
+ columnId: column.id,
3477
+ dropBefore: isOver && over?.cardId === card.id && over?.after === false,
3478
+ dropAfter: isOver && over?.cardId === card.id && over?.after === true,
3479
+ onCardClick,
3480
+ renderCard
3481
+ },
3482
+ card.id
3483
+ ))
3484
+ }
3485
+ ),
3486
+ column.cards.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__empty", children: "Drop a card here" }) : null
3487
+ ] }),
3488
+ columnFooter ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__footer", children: columnFooter(column) }) : null
3489
+ ] });
3490
+ }
3491
+ function KanbanCardView({
3492
+ card,
3493
+ columnId,
3494
+ dropBefore,
3495
+ dropAfter,
3496
+ onCardClick,
3497
+ renderCard
3498
+ }) {
3499
+ const {
3500
+ attributes,
3501
+ listeners: listeners2,
3502
+ setNodeRef,
3503
+ transform,
3504
+ transition,
3505
+ isDragging
3506
+ } = sortable.useSortable({ id: card.id });
3507
+ return /* @__PURE__ */ jsxRuntime.jsx(
3508
+ "article",
3509
+ {
3510
+ ref: setNodeRef,
3511
+ ...attributes,
3512
+ ...listeners2,
3513
+ onClick: () => onCardClick?.(card, columnId),
3514
+ className: chunkTPGAXYFU_cjs.cx(
3515
+ "klun-kanban__card",
3516
+ isDragging && "klun-kanban__card--dragging",
3517
+ dropBefore && "klun-kanban__card--dropbefore",
3518
+ dropAfter && "klun-kanban__card--dropafter"
3519
+ ),
3520
+ style: {
3521
+ transform: utilities.CSS.Transform.toString(transform),
3522
+ transition,
3523
+ ...card.accent ? { boxShadow: `inset 3px 0 0 ${card.accent}` } : null
3524
+ },
3525
+ children: renderCard ? renderCard(card, columnId) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3526
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__card-title", children: card.title }),
3527
+ card.description ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__card-desc", children: card.description }) : null,
3528
+ card.tags?.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__card-tags", children: card.tags.map((t, i) => /* @__PURE__ */ jsxRuntime.jsx("span", { children: t }, i)) }) : null,
3529
+ card.meta ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-kanban__card-meta", children: card.meta }) : null
3530
+ ] })
3531
+ }
3532
+ );
3533
+ }
3445
3534
  function VirtualTable({
3446
3535
  rows = [],
3447
3536
  columns = [],
@@ -4036,6 +4125,16 @@ function rowsToCsv(columns, rows) {
4036
4125
  const body = rows.map((r) => cols.map((c) => csvCell(c.copyValue ? c.copyValue(r) : r[c.key])).join(",")).join("\n");
4037
4126
  return head + "\n" + body;
4038
4127
  }
4128
+ function reorderRows(rows, fromId, toId, getRowId) {
4129
+ const ids = rows.map(getRowId);
4130
+ const from = ids.indexOf(fromId);
4131
+ const to = ids.indexOf(toId);
4132
+ if (from < 0 || to < 0 || from === to) return null;
4133
+ const next = rows.slice();
4134
+ const [moved] = next.splice(from, 1);
4135
+ next.splice(to, 0, moved);
4136
+ return { next, from, to };
4137
+ }
4039
4138
  function downloadCsv(filename, csv) {
4040
4139
  const blob = new Blob(["\uFEFF" + csv], { type: "text/csv;charset=utf-8;" });
4041
4140
  const url = URL.createObjectURL(blob);
@@ -4598,351 +4697,387 @@ function TableHead({
4598
4697
  })
4599
4698
  ] }) });
4600
4699
  }
4601
- function TableBody({
4602
- loading,
4603
- loadingRows,
4700
+ function TableRow(props) {
4701
+ if (!props.dragCol) return /* @__PURE__ */ jsxRuntime.jsx(RowBase, { ...props });
4702
+ return /* @__PURE__ */ jsxRuntime.jsx(SortableRow, { ...props });
4703
+ }
4704
+ function SortableRow(props) {
4705
+ const {
4706
+ attributes,
4707
+ listeners: listeners2,
4708
+ setNodeRef,
4709
+ setActivatorNodeRef,
4710
+ transform,
4711
+ transition,
4712
+ isDragging
4713
+ } = sortable.useSortable({ id: props.node.id });
4714
+ return /* @__PURE__ */ jsxRuntime.jsx(
4715
+ RowBase,
4716
+ {
4717
+ ...props,
4718
+ sortable: {
4719
+ attributes,
4720
+ listeners: listeners2,
4721
+ setNodeRef,
4722
+ setActivatorNodeRef,
4723
+ isDragging,
4724
+ style: { transform: utilities.CSS.Transform.toString(transform), transition }
4725
+ }
4726
+ }
4727
+ );
4728
+ }
4729
+ function RowBase({
4730
+ sortable,
4731
+ node,
4732
+ index,
4604
4733
  dragCol,
4605
- expandCol,
4606
- selectable,
4607
- visibleColumns,
4608
- pageRows,
4609
- colCount,
4610
- empty,
4611
- displayRows,
4612
- treeOpen,
4613
- setTreeOpen,
4734
+ tree,
4735
+ indentSize,
4736
+ zebra,
4614
4737
  selected,
4738
+ rowStatus,
4615
4739
  onRowClick,
4616
4740
  rowHref,
4741
+ expandCol,
4742
+ expandable,
4617
4743
  expanded,
4618
4744
  setExpanded,
4619
- expandable,
4620
- rowStatus,
4621
- drag,
4622
- setDrag,
4623
- reorder,
4624
- zebra,
4625
- contextMenu,
4626
- copyable,
4627
- copyRow,
4628
- setMenu,
4629
- leftFixed,
4630
- vBorderClass,
4745
+ treeOpen,
4746
+ setTreeOpen,
4747
+ selectable,
4631
4748
  selectionType,
4632
4749
  onSelectRow,
4750
+ visibleColumns,
4751
+ leftFixed,
4752
+ vBorderClass,
4633
4753
  fixedCell,
4634
4754
  editing,
4635
4755
  setEditing,
4636
4756
  startEdit,
4637
4757
  commitEdit,
4638
4758
  cancelEdit,
4639
- tree,
4640
- indentSize,
4759
+ contextMenu,
4760
+ copyable,
4761
+ copyRow,
4762
+ setMenu,
4763
+ colCount,
4641
4764
  onCopy
4642
4765
  }) {
4643
4766
  const { table } = useLocale();
4644
- const skel = /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-table__skel" });
4645
- return /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: loading ? Array.from({ length: loadingRows }).map((_, i) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: i ? "klun-table__row--bordered" : void 0, children: [
4646
- dragCol ? /* @__PURE__ */ jsxRuntime.jsx("td", { className: "klun-table__td" }) : null,
4647
- expandCol ? /* @__PURE__ */ jsxRuntime.jsx("td", { className: "klun-table__td", children: skel }) : null,
4648
- selectable ? /* @__PURE__ */ jsxRuntime.jsx("td", { className: "klun-table__td", children: skel }) : null,
4649
- visibleColumns.map((c) => /* @__PURE__ */ jsxRuntime.jsx("td", { className: "klun-table__td", children: skel }, c.key))
4650
- ] }, "sk" + i)) : pageRows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: colCount, className: "klun-table__empty-cell", children: empty != null ? empty : /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "klun-table__empty", children: [
4651
- /* @__PURE__ */ jsxRuntime.jsx("i", { className: "ri-inbox-line klun-table__empty-icon" }),
4652
- table.noData
4653
- ] }) }) }) : displayRows.map((node, i) => {
4654
- const row = node.row;
4655
- const id = node.id;
4656
- const depth = node.depth;
4657
- const treeHasKids = node.hasChildren;
4658
- const treeIsOpen = treeOpen.has(id);
4659
- const toggleTree = () => {
4660
- const n = new Set(treeOpen);
4661
- n.has(id) ? n.delete(id) : n.add(id);
4662
- setTreeOpen(n);
4663
- };
4664
- const on = selected.includes(id);
4665
- const clickable = !!(onRowClick || rowHref);
4666
- const isOpen = expanded.has(id);
4667
- const canExpand = expandCol && (!expandable.rowExpandable || expandable.rowExpandable(row));
4668
- const toggleRow = () => {
4669
- const next = new Set(expanded);
4670
- next.has(id) ? next.delete(id) : next.add(id);
4671
- setExpanded(next);
4672
- expandable?.onExpand?.(row, !isOpen);
4673
- };
4674
- const st = rowStatus ? rowStatus(row) : null;
4675
- const dragging = !!(drag && drag.id === id);
4676
- const dropOver = !!(drag && drag.overId === id && drag.id !== id);
4677
- const borderTop = i > 0;
4678
- const tdBorder = borderTop ? "klun-table__td--bordered" : "";
4679
- return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
4680
- /* @__PURE__ */ jsxRuntime.jsxs(
4681
- "tr",
4682
- {
4683
- className: chunkTPGAXYFU_cjs.cx(
4684
- "klun-table__row",
4685
- on && "klun-table__row--selected",
4686
- zebra && i % 2 === 1 && "klun-table__row--zebra",
4687
- st && `klun-table__row--status-${st}`,
4688
- clickable && "klun-table__row--clickable",
4689
- dragging && "klun-table__row--dragging",
4690
- dropOver && "klun-table__row--dropover",
4691
- dropOver && drag.after && "klun-table__row--dropover-after"
4692
- ),
4693
- onClick: clickable ? () => rowHref ? window.location.href = rowHref(row) : onRowClick(row) : void 0,
4694
- onDragOver: dragCol && drag ? (e) => {
4695
- e.preventDefault();
4696
- const r = e.currentTarget.getBoundingClientRect();
4697
- const after = e.clientY - r.top > r.height / 2;
4698
- if (drag.overId !== id || drag.after !== after)
4699
- setDrag((dd) => dd ? { ...dd, overId: id, after } : dd);
4700
- } : void 0,
4701
- onDrop: dragCol && drag ? (e) => {
4767
+ const row = node.row;
4768
+ const id = node.id;
4769
+ const depth = node.depth;
4770
+ const treeHasKids = node.hasChildren;
4771
+ const treeIsOpen = treeOpen.has(id);
4772
+ const toggleTree = () => {
4773
+ const n = new Set(treeOpen);
4774
+ n.has(id) ? n.delete(id) : n.add(id);
4775
+ setTreeOpen(n);
4776
+ };
4777
+ const on = selected.includes(id);
4778
+ const clickable = !!(onRowClick || rowHref);
4779
+ const isOpen = expanded.has(id);
4780
+ const canExpand = expandCol && (!expandable.rowExpandable || expandable.rowExpandable(row));
4781
+ const toggleRow = () => {
4782
+ const next = new Set(expanded);
4783
+ next.has(id) ? next.delete(id) : next.add(id);
4784
+ setExpanded(next);
4785
+ expandable?.onExpand?.(row, !isOpen);
4786
+ };
4787
+ const st = rowStatus ? rowStatus(row) : null;
4788
+ const tdBorder = index > 0 ? "klun-table__td--bordered" : "";
4789
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
4790
+ /* @__PURE__ */ jsxRuntime.jsxs(
4791
+ "tr",
4792
+ {
4793
+ ref: sortable?.setNodeRef,
4794
+ style: sortable?.style,
4795
+ className: chunkTPGAXYFU_cjs.cx(
4796
+ "klun-table__row",
4797
+ on && "klun-table__row--selected",
4798
+ zebra && index % 2 === 1 && "klun-table__row--zebra",
4799
+ st && `klun-table__row--status-${st}`,
4800
+ clickable && "klun-table__row--clickable",
4801
+ sortable?.isDragging && "klun-table__row--dragging"
4802
+ ),
4803
+ onClick: clickable ? () => rowHref ? window.location.href = rowHref(row) : onRowClick(row) : void 0,
4804
+ onContextMenu: contextMenu || copyable ? (e) => {
4805
+ const custom = contextMenu ? contextMenu(row, { copyRow, copyText }) : null;
4806
+ const items2 = custom && custom.length ? custom : [
4807
+ {
4808
+ label: table.copyRow,
4809
+ icon: "ri-file-copy-line",
4810
+ onClick: () => copyRow(row)
4811
+ }
4812
+ ];
4813
+ if (items2 && items2.length) {
4702
4814
  e.preventDefault();
4703
- reorder(drag.id, id, drag.after);
4704
- setDrag(null);
4705
- } : void 0,
4706
- onContextMenu: contextMenu || copyable ? (e) => {
4707
- const custom = contextMenu ? contextMenu(row, { copyRow, copyText }) : null;
4708
- const items2 = custom && custom.length ? custom : [
4709
- {
4710
- label: table.copyRow,
4711
- icon: "ri-file-copy-line",
4712
- onClick: () => copyRow(row)
4713
- }
4714
- ];
4715
- if (items2 && items2.length) {
4716
- e.preventDefault();
4717
- setMenu({ x: e.clientX, y: e.clientY, items: items2 });
4815
+ setMenu({ x: e.clientX, y: e.clientY, items: items2 });
4816
+ }
4817
+ } : void 0,
4818
+ children: [
4819
+ dragCol ? /* @__PURE__ */ jsxRuntime.jsx(
4820
+ "td",
4821
+ {
4822
+ ref: sortable?.setActivatorNodeRef,
4823
+ ...sortable?.attributes,
4824
+ ...sortable?.listeners,
4825
+ onClick: (e) => e.stopPropagation(),
4826
+ "aria-label": table.dragToReorder,
4827
+ title: table.dragToReorder,
4828
+ className: chunkTPGAXYFU_cjs.cx("klun-table__td", "klun-table__td--util", tdBorder),
4829
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-table__draghandle", children: /* @__PURE__ */ jsxRuntime.jsx("i", { className: "ri-draggable" }) })
4718
4830
  }
4719
- } : void 0,
4720
- children: [
4721
- dragCol ? /* @__PURE__ */ jsxRuntime.jsx("td", { className: chunkTPGAXYFU_cjs.cx("klun-table__td", "klun-table__td--util", tdBorder), children: /* @__PURE__ */ jsxRuntime.jsx(
4831
+ ) : null,
4832
+ expandCol ? /* @__PURE__ */ jsxRuntime.jsx(
4833
+ "td",
4834
+ {
4835
+ className: chunkTPGAXYFU_cjs.cx(
4836
+ "klun-table__td",
4837
+ "klun-table__td--lead",
4838
+ tdBorder,
4839
+ (leftFixed.length || selectable) && "klun-table__cell--fixed klun-table__cell--fixed-body"
4840
+ ),
4841
+ style: leftFixed.length || selectable ? { left: 0 } : void 0,
4842
+ children: canExpand ? /* @__PURE__ */ jsxRuntime.jsx(
4843
+ "button",
4844
+ {
4845
+ type: "button",
4846
+ "aria-label": isOpen ? table.collapse : table.expand,
4847
+ "aria-expanded": isOpen,
4848
+ onClick: (e) => {
4849
+ e.stopPropagation();
4850
+ toggleRow();
4851
+ },
4852
+ className: "klun-table__expand-btn",
4853
+ children: /* @__PURE__ */ jsxRuntime.jsx(
4854
+ "i",
4855
+ {
4856
+ className: chunkTPGAXYFU_cjs.cx(
4857
+ "ri-arrow-right-s-line",
4858
+ "klun-table__chevron",
4859
+ isOpen && "klun-table__chevron--open"
4860
+ )
4861
+ }
4862
+ )
4863
+ }
4864
+ ) : null
4865
+ }
4866
+ ) : null,
4867
+ selectable ? /* @__PURE__ */ jsxRuntime.jsx(
4868
+ "td",
4869
+ {
4870
+ className: chunkTPGAXYFU_cjs.cx(
4871
+ "klun-table__td",
4872
+ tdBorder,
4873
+ vBorderClass,
4874
+ leftFixed.length && "klun-table__cell--fixed klun-table__cell--fixed-body"
4875
+ ),
4876
+ style: leftFixed.length ? { left: expandCol ? 44 : 0 } : void 0,
4877
+ children: selectionType === "radio" ? /* @__PURE__ */ jsxRuntime.jsx(
4878
+ "button",
4879
+ {
4880
+ type: "button",
4881
+ role: "radio",
4882
+ "aria-checked": on,
4883
+ onClick: (e) => {
4884
+ e.stopPropagation();
4885
+ onSelectRow?.(id);
4886
+ },
4887
+ className: chunkTPGAXYFU_cjs.cx("klun-table__radio", on && "klun-table__radio--on"),
4888
+ children: on ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-table__radio-dot" }) : null
4889
+ }
4890
+ ) : /* @__PURE__ */ jsxRuntime.jsx(Check, { checked: on, onChange: () => onSelectRow?.(id) })
4891
+ }
4892
+ ) : null,
4893
+ visibleColumns.map((c, ci) => {
4894
+ const fx = fixedCell(c, false);
4895
+ const last = ci === visibleColumns.length - 1;
4896
+ const content = c.render ? c.render(row) : row[c.key];
4897
+ const inner = c.copyable ? /* @__PURE__ */ jsxRuntime.jsxs(
4722
4898
  "span",
4723
4899
  {
4724
- draggable: true,
4725
- onDragStart: (e) => {
4726
- e.stopPropagation();
4727
- setDrag({ id, overId: id, after: false });
4728
- try {
4729
- e.dataTransfer.effectAllowed = "move";
4730
- e.dataTransfer.setData("text/plain", String(id));
4731
- } catch (x) {
4732
- }
4900
+ className: "klun-table__copycell",
4901
+ onMouseEnter: (e) => {
4902
+ const b = e.currentTarget.querySelector(
4903
+ "[data-copy]"
4904
+ );
4905
+ if (b) b.style.opacity = "1";
4733
4906
  },
4734
- onDragEnd: () => setDrag(null),
4907
+ onMouseLeave: (e) => {
4908
+ const b = e.currentTarget.querySelector(
4909
+ "[data-copy]"
4910
+ );
4911
+ if (b) b.style.opacity = "0";
4912
+ },
4913
+ children: [
4914
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: c.ellipsis ? "klun-table__ellipsis" : void 0, children: content }),
4915
+ /* @__PURE__ */ jsxRuntime.jsx(
4916
+ "button",
4917
+ {
4918
+ type: "button",
4919
+ "data-copy": true,
4920
+ "aria-label": table.copy,
4921
+ onClick: (e) => {
4922
+ e.stopPropagation();
4923
+ copyText(c.copyValue ? c.copyValue(row) : row[c.key]);
4924
+ onCopy?.("cell", row, c.key);
4925
+ },
4926
+ className: "klun-table__copybtn",
4927
+ children: /* @__PURE__ */ jsxRuntime.jsx("i", { className: "ri-file-copy-line" })
4928
+ }
4929
+ )
4930
+ ]
4931
+ }
4932
+ ) : content;
4933
+ const isEditing = editing && editing.id === id && editing.key === c.key;
4934
+ const editor = isEditing ? c.editor === "select" ? /* @__PURE__ */ jsxRuntime.jsx(
4935
+ "select",
4936
+ {
4937
+ autoFocus: true,
4938
+ value: editing.value ?? "",
4735
4939
  onClick: (e) => e.stopPropagation(),
4736
- "aria-label": table.dragToReorder,
4737
- title: table.dragToReorder,
4738
- className: "klun-table__draghandle",
4739
- children: /* @__PURE__ */ jsxRuntime.jsx("i", { className: "ri-draggable" })
4940
+ onChange: (e) => setEditing((ed) => ed ? { ...ed, value: e.target.value } : ed),
4941
+ onBlur: commitEdit,
4942
+ onKeyDown: (e) => {
4943
+ if (e.key === "Enter") commitEdit();
4944
+ if (e.key === "Escape") cancelEdit();
4945
+ },
4946
+ className: "klun-table__editor",
4947
+ children: (c.options || []).map((o) => {
4948
+ const ov = typeof o === "object" ? o.value : o;
4949
+ const ol = typeof o === "object" ? o.label : o;
4950
+ return /* @__PURE__ */ jsxRuntime.jsx("option", { value: ov, children: ol }, ov);
4951
+ })
4740
4952
  }
4741
- ) }) : null,
4742
- expandCol ? /* @__PURE__ */ jsxRuntime.jsx(
4743
- "td",
4953
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
4954
+ "input",
4744
4955
  {
4745
- className: chunkTPGAXYFU_cjs.cx(
4746
- "klun-table__td",
4747
- "klun-table__td--lead",
4748
- tdBorder,
4749
- (leftFixed.length || selectable) && "klun-table__cell--fixed klun-table__cell--fixed-body"
4750
- ),
4751
- style: leftFixed.length || selectable ? { left: 0 } : void 0,
4752
- children: canExpand ? /* @__PURE__ */ jsxRuntime.jsx(
4753
- "button",
4754
- {
4755
- type: "button",
4756
- "aria-label": isOpen ? table.collapse : table.expand,
4757
- "aria-expanded": isOpen,
4758
- onClick: (e) => {
4759
- e.stopPropagation();
4760
- toggleRow();
4761
- },
4762
- className: "klun-table__expand-btn",
4763
- children: /* @__PURE__ */ jsxRuntime.jsx(
4764
- "i",
4765
- {
4766
- className: chunkTPGAXYFU_cjs.cx(
4767
- "ri-arrow-right-s-line",
4768
- "klun-table__chevron",
4769
- isOpen && "klun-table__chevron--open"
4770
- )
4771
- }
4772
- )
4773
- }
4774
- ) : null
4956
+ autoFocus: true,
4957
+ type: c.editor === "number" ? "number" : "text",
4958
+ value: editing.value ?? "",
4959
+ onClick: (e) => e.stopPropagation(),
4960
+ onChange: (e) => setEditing((ed) => ed ? { ...ed, value: e.target.value } : ed),
4961
+ onBlur: commitEdit,
4962
+ onKeyDown: (e) => {
4963
+ if (e.key === "Enter") commitEdit();
4964
+ if (e.key === "Escape") cancelEdit();
4965
+ },
4966
+ className: "klun-table__editor",
4967
+ style: { textAlign: c.align || "left" }
4775
4968
  }
4776
- ) : null,
4777
- selectable ? /* @__PURE__ */ jsxRuntime.jsx(
4969
+ ) : null;
4970
+ return /* @__PURE__ */ jsxRuntime.jsx(
4778
4971
  "td",
4779
4972
  {
4973
+ onDoubleClick: c.editable && !isEditing ? (e) => {
4974
+ e.stopPropagation();
4975
+ startEdit(id, c, row);
4976
+ } : void 0,
4780
4977
  className: chunkTPGAXYFU_cjs.cx(
4781
4978
  "klun-table__td",
4782
4979
  tdBorder,
4783
- vBorderClass,
4784
- leftFixed.length && "klun-table__cell--fixed klun-table__cell--fixed-body"
4980
+ isEditing && "klun-table__td--editing",
4981
+ (c.nowrap || c.ellipsis) && "klun-table__td--nowrap",
4982
+ c.ellipsis && "klun-table__td--ellipsis",
4983
+ c.editable && !isEditing && "klun-table__td--editable",
4984
+ !last && vBorderClass,
4985
+ fx.cls
4785
4986
  ),
4786
- style: leftFixed.length ? { left: expandCol ? 44 : 0 } : void 0,
4787
- children: selectionType === "radio" ? /* @__PURE__ */ jsxRuntime.jsx(
4788
- "button",
4789
- {
4790
- type: "button",
4791
- role: "radio",
4792
- "aria-checked": on,
4793
- onClick: (e) => {
4794
- e.stopPropagation();
4795
- onSelectRow?.(id);
4796
- },
4797
- className: chunkTPGAXYFU_cjs.cx("klun-table__radio", on && "klun-table__radio--on"),
4798
- children: on ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-table__radio-dot" }) : null
4799
- }
4800
- ) : /* @__PURE__ */ jsxRuntime.jsx(Check, { checked: on, onChange: () => onSelectRow?.(id) })
4801
- }
4802
- ) : null,
4803
- visibleColumns.map((c, ci) => {
4804
- const fx = fixedCell(c, false);
4805
- const last = ci === visibleColumns.length - 1;
4806
- const content = c.render ? c.render(row) : row[c.key];
4807
- const inner = c.copyable ? /* @__PURE__ */ jsxRuntime.jsxs(
4808
- "span",
4809
- {
4810
- className: "klun-table__copycell",
4811
- onMouseEnter: (e) => {
4812
- const b = e.currentTarget.querySelector(
4813
- "[data-copy]"
4814
- );
4815
- if (b) b.style.opacity = "1";
4816
- },
4817
- onMouseLeave: (e) => {
4818
- const b = e.currentTarget.querySelector(
4819
- "[data-copy]"
4820
- );
4821
- if (b) b.style.opacity = "0";
4822
- },
4823
- children: [
4824
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: c.ellipsis ? "klun-table__ellipsis" : void 0, children: content }),
4825
- /* @__PURE__ */ jsxRuntime.jsx(
4826
- "button",
4827
- {
4828
- type: "button",
4829
- "data-copy": true,
4830
- "aria-label": table.copy,
4831
- onClick: (e) => {
4832
- e.stopPropagation();
4833
- copyText(c.copyValue ? c.copyValue(row) : row[c.key]);
4834
- onCopy?.("cell", row, c.key);
4835
- },
4836
- className: "klun-table__copybtn",
4837
- children: /* @__PURE__ */ jsxRuntime.jsx("i", { className: "ri-file-copy-line" })
4838
- }
4839
- )
4840
- ]
4841
- }
4842
- ) : content;
4843
- const isEditing = editing && editing.id === id && editing.key === c.key;
4844
- const editor = isEditing ? c.editor === "select" ? /* @__PURE__ */ jsxRuntime.jsx(
4845
- "select",
4846
- {
4847
- autoFocus: true,
4848
- value: editing.value ?? "",
4849
- onClick: (e) => e.stopPropagation(),
4850
- onChange: (e) => setEditing((ed) => ed ? { ...ed, value: e.target.value } : ed),
4851
- onBlur: commitEdit,
4852
- onKeyDown: (e) => {
4853
- if (e.key === "Enter") commitEdit();
4854
- if (e.key === "Escape") cancelEdit();
4855
- },
4856
- className: "klun-table__editor",
4857
- children: (c.options || []).map((o) => {
4858
- const ov = typeof o === "object" ? o.value : o;
4859
- const ol = typeof o === "object" ? o.label : o;
4860
- return /* @__PURE__ */ jsxRuntime.jsx("option", { value: ov, children: ol }, ov);
4861
- })
4862
- }
4863
- ) : /* @__PURE__ */ jsxRuntime.jsx(
4864
- "input",
4865
- {
4866
- autoFocus: true,
4867
- type: c.editor === "number" ? "number" : "text",
4868
- value: editing.value ?? "",
4869
- onClick: (e) => e.stopPropagation(),
4870
- onChange: (e) => setEditing((ed) => ed ? { ...ed, value: e.target.value } : ed),
4871
- onBlur: commitEdit,
4872
- onKeyDown: (e) => {
4873
- if (e.key === "Enter") commitEdit();
4874
- if (e.key === "Escape") cancelEdit();
4875
- },
4876
- className: "klun-table__editor",
4877
- style: { textAlign: c.align || "left" }
4878
- }
4879
- ) : null;
4880
- return /* @__PURE__ */ jsxRuntime.jsx(
4881
- "td",
4882
- {
4883
- onDoubleClick: c.editable && !isEditing ? (e) => {
4884
- e.stopPropagation();
4885
- startEdit(id, c, row);
4886
- } : void 0,
4887
- className: chunkTPGAXYFU_cjs.cx(
4888
- "klun-table__td",
4889
- tdBorder,
4890
- isEditing && "klun-table__td--editing",
4891
- (c.nowrap || c.ellipsis) && "klun-table__td--nowrap",
4892
- c.ellipsis && "klun-table__td--ellipsis",
4893
- c.editable && !isEditing && "klun-table__td--editable",
4894
- !last && vBorderClass,
4895
- fx.cls
4896
- ),
4897
- style: {
4898
- textAlign: c.align || "left",
4899
- ...c.ellipsis ? { maxWidth: c.width || 200 } : null,
4900
- ...fx.style
4901
- },
4902
- title: c.editable && !isEditing ? table.editHint : c.ellipsis && typeof content === "string" ? content : void 0,
4903
- children: isEditing ? editor : tree && ci === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "klun-table__tree-cell", children: [
4904
- /* @__PURE__ */ jsxRuntime.jsx(
4905
- "span",
4906
- {
4907
- className: "klun-table__tree-indent",
4908
- style: { width: depth * indentSize }
4909
- }
4910
- ),
4911
- treeHasKids ? /* @__PURE__ */ jsxRuntime.jsx(
4912
- "button",
4913
- {
4914
- type: "button",
4915
- "aria-label": treeIsOpen ? table.collapse : table.expand,
4916
- "aria-expanded": treeIsOpen,
4917
- onClick: (e) => {
4918
- e.stopPropagation();
4919
- toggleTree();
4920
- },
4921
- className: "klun-table__tree-toggle",
4922
- children: /* @__PURE__ */ jsxRuntime.jsx(
4923
- "i",
4924
- {
4925
- className: chunkTPGAXYFU_cjs.cx(
4926
- "ri-arrow-right-s-line",
4927
- "klun-table__chevron",
4928
- treeIsOpen && "klun-table__chevron--open"
4929
- )
4930
- }
4931
- )
4932
- }
4933
- ) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-table__tree-spacer" }),
4934
- inner
4935
- ] }) : inner
4987
+ style: {
4988
+ textAlign: c.align || "left",
4989
+ ...c.ellipsis ? { maxWidth: c.width || 200 } : null,
4990
+ ...fx.style
4936
4991
  },
4937
- c.key
4938
- );
4939
- })
4940
- ]
4941
- }
4942
- ),
4943
- expandCol && isOpen ? /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "klun-table__expand-row", children: /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: colCount, className: "klun-table__expand-cell", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-table__expand-panel", children: expandable.render(row) }) }) }) : null
4944
- ] }, id);
4945
- }) });
4992
+ title: c.editable && !isEditing ? table.editHint : c.ellipsis && typeof content === "string" ? content : void 0,
4993
+ children: isEditing ? editor : tree && ci === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "klun-table__tree-cell", children: [
4994
+ /* @__PURE__ */ jsxRuntime.jsx(
4995
+ "span",
4996
+ {
4997
+ className: "klun-table__tree-indent",
4998
+ style: { width: depth * indentSize }
4999
+ }
5000
+ ),
5001
+ treeHasKids ? /* @__PURE__ */ jsxRuntime.jsx(
5002
+ "button",
5003
+ {
5004
+ type: "button",
5005
+ "aria-label": treeIsOpen ? table.collapse : table.expand,
5006
+ "aria-expanded": treeIsOpen,
5007
+ onClick: (e) => {
5008
+ e.stopPropagation();
5009
+ toggleTree();
5010
+ },
5011
+ className: "klun-table__tree-toggle",
5012
+ children: /* @__PURE__ */ jsxRuntime.jsx(
5013
+ "i",
5014
+ {
5015
+ className: chunkTPGAXYFU_cjs.cx(
5016
+ "ri-arrow-right-s-line",
5017
+ "klun-table__chevron",
5018
+ treeIsOpen && "klun-table__chevron--open"
5019
+ )
5020
+ }
5021
+ )
5022
+ }
5023
+ ) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-table__tree-spacer" }),
5024
+ inner
5025
+ ] }) : inner
5026
+ },
5027
+ c.key
5028
+ );
5029
+ })
5030
+ ]
5031
+ }
5032
+ ),
5033
+ expandCol && isOpen ? /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "klun-table__expand-row", children: /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: colCount, className: "klun-table__expand-cell", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-table__expand-panel", children: expandable.render(row) }) }) }) : null
5034
+ ] });
5035
+ }
5036
+ function TableBody({
5037
+ loading,
5038
+ loadingRows,
5039
+ pageRows,
5040
+ empty,
5041
+ displayRows,
5042
+ dragCol,
5043
+ expandCol,
5044
+ selectable,
5045
+ visibleColumns,
5046
+ colCount,
5047
+ ...row
5048
+ }) {
5049
+ const { table } = useLocale();
5050
+ const skel = /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-table__skel" });
5051
+ const bodyRows = displayRows.map((node, index) => /* @__PURE__ */ jsxRuntime.jsx(
5052
+ TableRow,
5053
+ {
5054
+ node,
5055
+ index,
5056
+ dragCol,
5057
+ expandCol,
5058
+ selectable,
5059
+ visibleColumns,
5060
+ colCount,
5061
+ ...row
5062
+ },
5063
+ node.id
5064
+ ));
5065
+ return /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: loading ? Array.from({ length: loadingRows }).map((_, i) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: i ? "klun-table__row--bordered" : void 0, children: [
5066
+ dragCol ? /* @__PURE__ */ jsxRuntime.jsx("td", { className: "klun-table__td" }) : null,
5067
+ expandCol ? /* @__PURE__ */ jsxRuntime.jsx("td", { className: "klun-table__td", children: skel }) : null,
5068
+ selectable ? /* @__PURE__ */ jsxRuntime.jsx("td", { className: "klun-table__td", children: skel }) : null,
5069
+ visibleColumns.map((c) => /* @__PURE__ */ jsxRuntime.jsx("td", { className: "klun-table__td", children: skel }, c.key))
5070
+ ] }, "sk" + i)) : pageRows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: colCount, className: "klun-table__empty-cell", children: empty != null ? empty : /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "klun-table__empty", children: [
5071
+ /* @__PURE__ */ jsxRuntime.jsx("i", { className: "ri-inbox-line klun-table__empty-icon" }),
5072
+ table.noData
5073
+ ] }) }) }) : dragCol ? /* @__PURE__ */ jsxRuntime.jsx(
5074
+ sortable.SortableContext,
5075
+ {
5076
+ items: displayRows.map((n) => n.id),
5077
+ strategy: sortable.verticalListSortingStrategy,
5078
+ children: bodyRows
5079
+ }
5080
+ ) : bodyRows });
4946
5081
  }
4947
5082
  function TableFooter({
4948
5083
  summary,
@@ -5145,28 +5280,6 @@ function useExpandedRows({
5145
5280
  }, [tree, pageRows, treeOpen, childrenKey, getRowId]);
5146
5281
  return { treeOpen, setTreeOpen, expanded, setExpanded, displayRows };
5147
5282
  }
5148
- function useRowReorder({
5149
- rows,
5150
- getRowId,
5151
- onReorder
5152
- }) {
5153
- const [drag, setDrag] = react.useState(null);
5154
- const reorder = (fromId, toId, after) => {
5155
- if (fromId === toId) return;
5156
- const ids = rows.map(getRowId);
5157
- const from = ids.indexOf(fromId);
5158
- const to = ids.indexOf(toId);
5159
- if (from < 0 || to < 0) return;
5160
- const next = rows.slice();
5161
- const [moved] = next.splice(from, 1);
5162
- let insert = rows.findIndex((r, i) => getRowId(r, i) === toId);
5163
- if (after) insert += 1;
5164
- if (from < insert) insert -= 1;
5165
- next.splice(insert, 0, moved);
5166
- onReorder?.(next, from, insert);
5167
- };
5168
- return { drag, setDrag, reorder };
5169
- }
5170
5283
  function useCellEdit({
5171
5284
  columns,
5172
5285
  rows,
@@ -5190,6 +5303,27 @@ function useCellEdit({
5190
5303
  const cancelEdit = () => setEditing(null);
5191
5304
  return { editing, setEditing, startEdit, commitEdit, cancelEdit };
5192
5305
  }
5306
+ var dragModifiers = [({ transform }) => ({ ...transform, x: 0 })];
5307
+ function RowsDnd({
5308
+ enabled,
5309
+ sensors,
5310
+ onDragEnd,
5311
+ instructions,
5312
+ children
5313
+ }) {
5314
+ if (!enabled) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
5315
+ return /* @__PURE__ */ jsxRuntime.jsx(
5316
+ core.DndContext,
5317
+ {
5318
+ sensors,
5319
+ collisionDetection: core.closestCenter,
5320
+ modifiers: dragModifiers,
5321
+ onDragEnd,
5322
+ accessibility: { screenReaderInstructions: { draggable: instructions } },
5323
+ children
5324
+ }
5325
+ );
5326
+ }
5193
5327
  var DENSITY = {
5194
5328
  compact: "klun-table--compact",
5195
5329
  comfortable: "klun-table--comfortable",
@@ -5203,7 +5337,7 @@ function Table({
5203
5337
  selected = [],
5204
5338
  onSelectRow,
5205
5339
  onSelectAll,
5206
- sortable = false,
5340
+ sortable: sortable$1 = false,
5207
5341
  sort,
5208
5342
  onSortChange,
5209
5343
  defaultSort = null,
@@ -5336,7 +5470,16 @@ function Table({
5336
5470
  );
5337
5471
  const showToolbar = title != null || toolbar != null || !!exportable || columnSettings;
5338
5472
  const clearSelection = () => onSelectAll && onSelectAll([]);
5339
- const { drag, setDrag, reorder } = useRowReorder({ rows, getRowId, onReorder });
5473
+ const { table: t } = useLocale();
5474
+ const sensors = core.useSensors(
5475
+ core.useSensor(core.PointerSensor, { activationConstraint: { distance: 4 } }),
5476
+ core.useSensor(core.KeyboardSensor, { coordinateGetter: sortable.sortableKeyboardCoordinates })
5477
+ );
5478
+ const handleDragEnd = ({ active, over }) => {
5479
+ if (!over) return;
5480
+ const moved = reorderRows(rows, active.id, over.id, getRowId);
5481
+ if (moved) onReorder?.(moved.next, moved.from, moved.to);
5482
+ };
5340
5483
  const { editing, setEditing, startEdit, commitEdit, cancelEdit } = useCellEdit({
5341
5484
  columns,
5342
5485
  rows,
@@ -5379,113 +5522,119 @@ function Table({
5379
5522
  }
5380
5523
  ),
5381
5524
  /* @__PURE__ */ jsxRuntime.jsx(
5382
- "div",
5525
+ RowsDnd,
5383
5526
  {
5384
- className: "klun-table__scroller",
5385
- style: stickyHeader ? {
5386
- ["--klun-table-max-height"]: `${style && style.maxHeight || 420}${typeof (style && style.maxHeight) === "number" ? "px" : ""}`
5387
- } : void 0,
5388
- children: /* @__PURE__ */ jsxRuntime.jsxs(
5389
- "table",
5527
+ enabled: dragCol,
5528
+ sensors,
5529
+ onDragEnd: handleDragEnd,
5530
+ instructions: t.dragToReorder,
5531
+ children: /* @__PURE__ */ jsxRuntime.jsx(
5532
+ "div",
5390
5533
  {
5391
- className: chunkTPGAXYFU_cjs.cx(
5392
- "klun-table__table",
5393
- Object.keys(colW).length && "klun-table__table--fixed-layout"
5394
- ),
5395
- children: [
5396
- /* @__PURE__ */ jsxRuntime.jsxs("colgroup", { children: [
5397
- dragCol ? /* @__PURE__ */ jsxRuntime.jsx("col", { className: "klun-table__col-util" }) : null,
5398
- expandCol ? /* @__PURE__ */ jsxRuntime.jsx("col", { className: "klun-table__col-lead" }) : null,
5399
- selectable ? /* @__PURE__ */ jsxRuntime.jsx("col", { className: "klun-table__col-lead" }) : null,
5400
- columns.map((c) => {
5401
- const w = widthOf(c);
5402
- return hiddenCols.has(c.key) ? null : /* @__PURE__ */ jsxRuntime.jsx("col", { style: w ? { width: w } : void 0 }, c.key);
5403
- })
5404
- ] }),
5405
- caption ? /* @__PURE__ */ jsxRuntime.jsx("caption", { className: "klun-table__caption", children: caption }) : null,
5406
- /* @__PURE__ */ jsxRuntime.jsx(
5407
- TableHead,
5408
- {
5409
- dragCol,
5410
- expandCol,
5411
- selectable,
5412
- leftFixed,
5413
- vBorderClass,
5414
- selectionType,
5415
- allOn,
5416
- someOn,
5417
- toggleAll,
5418
- visibleColumns,
5419
- sortable,
5420
- activeSort,
5421
- resizable,
5422
- widthOf,
5423
- fixedCell,
5424
- setSort,
5425
- activeFilters,
5426
- setFilter,
5427
- startResize
5428
- }
5429
- ),
5430
- /* @__PURE__ */ jsxRuntime.jsx(
5431
- TableBody,
5432
- {
5433
- loading,
5434
- loadingRows,
5435
- dragCol,
5436
- expandCol,
5437
- selectable,
5438
- visibleColumns,
5439
- pageRows,
5440
- colCount,
5441
- empty,
5442
- displayRows,
5443
- treeOpen,
5444
- setTreeOpen,
5445
- selected,
5446
- onRowClick,
5447
- rowHref,
5448
- expanded,
5449
- setExpanded,
5450
- expandable,
5451
- rowStatus,
5452
- drag,
5453
- setDrag,
5454
- reorder,
5455
- zebra,
5456
- contextMenu,
5457
- copyable,
5458
- copyRow,
5459
- setMenu,
5460
- leftFixed,
5461
- vBorderClass,
5462
- selectionType,
5463
- onSelectRow,
5464
- fixedCell,
5465
- editing,
5466
- setEditing,
5467
- startEdit,
5468
- commitEdit,
5469
- cancelEdit,
5470
- tree,
5471
- indentSize,
5472
- onCopy
5473
- }
5474
- ),
5475
- /* @__PURE__ */ jsxRuntime.jsx(
5476
- TableFooter,
5477
- {
5478
- summary,
5479
- expandCol,
5480
- selectable,
5481
- pageRows,
5482
- visibleColumns,
5483
- vBorderClass,
5484
- footer,
5485
- colCount
5486
- }
5487
- )
5488
- ]
5534
+ className: "klun-table__scroller",
5535
+ style: stickyHeader ? {
5536
+ ["--klun-table-max-height"]: `${style && style.maxHeight || 420}${typeof (style && style.maxHeight) === "number" ? "px" : ""}`
5537
+ } : void 0,
5538
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
5539
+ "table",
5540
+ {
5541
+ className: chunkTPGAXYFU_cjs.cx(
5542
+ "klun-table__table",
5543
+ Object.keys(colW).length && "klun-table__table--fixed-layout"
5544
+ ),
5545
+ children: [
5546
+ /* @__PURE__ */ jsxRuntime.jsxs("colgroup", { children: [
5547
+ dragCol ? /* @__PURE__ */ jsxRuntime.jsx("col", { className: "klun-table__col-util" }) : null,
5548
+ expandCol ? /* @__PURE__ */ jsxRuntime.jsx("col", { className: "klun-table__col-lead" }) : null,
5549
+ selectable ? /* @__PURE__ */ jsxRuntime.jsx("col", { className: "klun-table__col-lead" }) : null,
5550
+ columns.map((c) => {
5551
+ const w = widthOf(c);
5552
+ return hiddenCols.has(c.key) ? null : /* @__PURE__ */ jsxRuntime.jsx("col", { style: w ? { width: w } : void 0 }, c.key);
5553
+ })
5554
+ ] }),
5555
+ caption ? /* @__PURE__ */ jsxRuntime.jsx("caption", { className: "klun-table__caption", children: caption }) : null,
5556
+ /* @__PURE__ */ jsxRuntime.jsx(
5557
+ TableHead,
5558
+ {
5559
+ dragCol,
5560
+ expandCol,
5561
+ selectable,
5562
+ leftFixed,
5563
+ vBorderClass,
5564
+ selectionType,
5565
+ allOn,
5566
+ someOn,
5567
+ toggleAll,
5568
+ visibleColumns,
5569
+ sortable: sortable$1,
5570
+ activeSort,
5571
+ resizable,
5572
+ widthOf,
5573
+ fixedCell,
5574
+ setSort,
5575
+ activeFilters,
5576
+ setFilter,
5577
+ startResize
5578
+ }
5579
+ ),
5580
+ /* @__PURE__ */ jsxRuntime.jsx(
5581
+ TableBody,
5582
+ {
5583
+ loading,
5584
+ loadingRows,
5585
+ dragCol,
5586
+ expandCol,
5587
+ selectable,
5588
+ visibleColumns,
5589
+ pageRows,
5590
+ colCount,
5591
+ empty,
5592
+ displayRows,
5593
+ treeOpen,
5594
+ setTreeOpen,
5595
+ selected,
5596
+ onRowClick,
5597
+ rowHref,
5598
+ expanded,
5599
+ setExpanded,
5600
+ expandable,
5601
+ rowStatus,
5602
+ zebra,
5603
+ contextMenu,
5604
+ copyable,
5605
+ copyRow,
5606
+ setMenu,
5607
+ leftFixed,
5608
+ vBorderClass,
5609
+ selectionType,
5610
+ onSelectRow,
5611
+ fixedCell,
5612
+ editing,
5613
+ setEditing,
5614
+ startEdit,
5615
+ commitEdit,
5616
+ cancelEdit,
5617
+ tree,
5618
+ indentSize,
5619
+ onCopy
5620
+ }
5621
+ ),
5622
+ /* @__PURE__ */ jsxRuntime.jsx(
5623
+ TableFooter,
5624
+ {
5625
+ summary,
5626
+ expandCol,
5627
+ selectable,
5628
+ pageRows,
5629
+ visibleColumns,
5630
+ vBorderClass,
5631
+ footer,
5632
+ colCount
5633
+ }
5634
+ )
5635
+ ]
5636
+ }
5637
+ )
5489
5638
  }
5490
5639
  )
5491
5640
  }
@@ -12256,5 +12405,5 @@ exports.useSize = useSize;
12256
12405
  exports.viVN = viVN;
12257
12406
  exports.zhCN = zhCN;
12258
12407
  exports.zhTW = zhTW;
12259
- //# sourceMappingURL=chunk-XLK6BYW3.cjs.map
12260
- //# sourceMappingURL=chunk-XLK6BYW3.cjs.map
12408
+ //# sourceMappingURL=chunk-IETPQZRQ.cjs.map
12409
+ //# sourceMappingURL=chunk-IETPQZRQ.cjs.map