ar-design 0.3.79 → 0.3.80
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.
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
.ar-table > .content > table {
|
|
54
|
+
display: table;
|
|
54
55
|
border-collapse: collapse;
|
|
55
56
|
width: 100%;
|
|
56
57
|
}
|
|
@@ -139,6 +140,23 @@
|
|
|
139
140
|
|
|
140
141
|
.ar-table > .content > table > tbody > tr {
|
|
141
142
|
border-bottom: solid 1px var(--gray-200);
|
|
143
|
+
|
|
144
|
+
&.draggable {
|
|
145
|
+
> td:first-child {
|
|
146
|
+
position: relative;
|
|
147
|
+
padding-left: 20px;
|
|
148
|
+
|
|
149
|
+
&:first-child::before {
|
|
150
|
+
content: "⋮⋮";
|
|
151
|
+
position: absolute;
|
|
152
|
+
left: 8px;
|
|
153
|
+
top: 50%;
|
|
154
|
+
transform: translateY(-50%);
|
|
155
|
+
color: var(--gray-400);
|
|
156
|
+
cursor: move;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
142
160
|
}
|
|
143
161
|
.ar-table > .content > table > tbody > tr:last-child {
|
|
144
162
|
border-bottom: none;
|
|
@@ -72,6 +72,7 @@ interface IProps<T> extends IChildren {
|
|
|
72
72
|
previousSelections?: T[];
|
|
73
73
|
searchedParams?: (params: SearchedParam | null, query: string, operator: FilterOperator) => void;
|
|
74
74
|
onEditable?: (item: T, index: number) => void;
|
|
75
|
+
onDnD?: (item: T[]) => void;
|
|
75
76
|
pagination?: {
|
|
76
77
|
totalRecords: number;
|
|
77
78
|
perPage: number;
|
|
@@ -27,12 +27,14 @@ const filterOption = [
|
|
|
27
27
|
{ value: FilterOperator.NotBlank, text: "Boş değil" },
|
|
28
28
|
];
|
|
29
29
|
const { Row, Column } = Grid;
|
|
30
|
-
const Table = forwardRef(({ children, trackBy, title, description, data, columns, actions, rowBackgroundColor, selections, previousSelections, searchedParams, onEditable, pagination, config = { isSearchable: false }, }, ref) => {
|
|
30
|
+
const Table = forwardRef(({ children, trackBy, title, description, data, columns, actions, rowBackgroundColor, selections, previousSelections, searchedParams, onEditable, onDnD, pagination, config = { isSearchable: false }, }, ref) => {
|
|
31
31
|
// refs
|
|
32
32
|
const _innerRef = useRef(null);
|
|
33
33
|
const _tableWrapper = useRef(null);
|
|
34
34
|
const _tableContent = useRef(null);
|
|
35
|
+
const _tBody = useRef(null);
|
|
35
36
|
const _tBodyTR = useRef([]);
|
|
37
|
+
const _dragItem = useRef();
|
|
36
38
|
const _checkboxItems = useRef([]);
|
|
37
39
|
const _filterCheckboxItems = useRef([]);
|
|
38
40
|
// refs -> Search
|
|
@@ -358,7 +360,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
358
360
|
return (React.createElement(Fragment, { key: `row-${index}` },
|
|
359
361
|
React.createElement("tr", { key: `row-${index}`, ref: (element) => {
|
|
360
362
|
_tBodyTR.current[index] = element;
|
|
361
|
-
}, style: { ..._rowColor } },
|
|
363
|
+
}, style: { ..._rowColor }, ...(onDnD && data.length > 1 ? { className: "draggable", draggable: true } : {}) },
|
|
362
364
|
selections && (React.createElement("td", { className: "flex justify-content-center sticky-left", "data-sticky-position": "left" },
|
|
363
365
|
React.createElement(Checkbox, { ref: (element) => (_checkboxItems.current[index] = element), variant: "filled", color: "green", checked: selectionItems.some((selectionItem) => trackBy?.(selectionItem) === trackBy?.(item)), onChange: (event) => {
|
|
364
366
|
if (event.target.checked)
|
|
@@ -444,6 +446,13 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
444
446
|
showSubitems[`${index}.${subindex}`] && _subitem && (React.createElement(SubitemList, { items: _subitem, columns: columns, index: subindex, depth: depth + 0.75, level: level + 1 }))));
|
|
445
447
|
});
|
|
446
448
|
};
|
|
449
|
+
const renderTBody = useMemo(() => {
|
|
450
|
+
return getData.length > 0 ? (getData.map((item, index) => React.createElement(React.Fragment, { key: index }, renderRow(item, index, 1)))) : (React.createElement("tr", null,
|
|
451
|
+
React.createElement("td", { colSpan: columns.length || 1 },
|
|
452
|
+
React.createElement("div", { className: "no-item" },
|
|
453
|
+
React.createElement(ARIcon, { icon: "Inbox-Fill", fill: "var(--gray-300)", size: 64, style: { position: "relative", zIndex: 1 } }),
|
|
454
|
+
React.createElement("span", null, "No Data")))));
|
|
455
|
+
}, [getData, showSubitems, columns]);
|
|
447
456
|
// useEffects
|
|
448
457
|
useEffect(() => {
|
|
449
458
|
if (Utils.DeepEqual(previousSelections, selectionItems))
|
|
@@ -512,6 +521,82 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
512
521
|
handleFilterPopupContent(filterCurrentColumn, filterCurrentDataType, filterCurrentIndex);
|
|
513
522
|
}
|
|
514
523
|
}, [checkboxSelectedParams, filterPopupOption, filterPopupOptionSearchText]);
|
|
524
|
+
useLayoutEffect(() => {
|
|
525
|
+
// @DND
|
|
526
|
+
if (!onDnD || !_tBody.current || data.length === 0)
|
|
527
|
+
return;
|
|
528
|
+
_tBody.current.childNodes.forEach((item) => {
|
|
529
|
+
const _item = item;
|
|
530
|
+
// Events
|
|
531
|
+
_item.ondragstart = (event) => {
|
|
532
|
+
const dragItem = event.currentTarget;
|
|
533
|
+
_dragItem.current = dragItem;
|
|
534
|
+
dragItem.classList.add("drag-item");
|
|
535
|
+
if (event.dataTransfer) {
|
|
536
|
+
// #region Shadow
|
|
537
|
+
const shadow = document.createElement("div");
|
|
538
|
+
shadow.innerHTML = `
|
|
539
|
+
<div class="ar-dnd-shadow">
|
|
540
|
+
<i class="bi bi-gear-wide-connected"></i>
|
|
541
|
+
<span>Dragging...</span>
|
|
542
|
+
</div>
|
|
543
|
+
`;
|
|
544
|
+
shadow.style.position = "absolute";
|
|
545
|
+
shadow.style.top = "-9999px";
|
|
546
|
+
document.body.appendChild(shadow);
|
|
547
|
+
event.dataTransfer.setDragImage(shadow, 0, 0);
|
|
548
|
+
// #endregion
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
_item.ondragover = (event) => {
|
|
552
|
+
event.preventDefault();
|
|
553
|
+
const overItem = event.currentTarget;
|
|
554
|
+
const rect = overItem.getBoundingClientRect();
|
|
555
|
+
// Otomatik scroll.
|
|
556
|
+
if (rect.top < 250)
|
|
557
|
+
window.scrollBy(0, -20);
|
|
558
|
+
if (rect.bottom > window.innerHeight - 150)
|
|
559
|
+
window.scrollBy(0, 20);
|
|
560
|
+
// Gerçek taşıma işlemi.
|
|
561
|
+
if (_dragItem.current !== overItem) {
|
|
562
|
+
if (_tBody.current && _dragItem.current) {
|
|
563
|
+
const dragItemIndex = [..._tBody.current.children].indexOf(_dragItem.current);
|
|
564
|
+
const dropItemIndex = [..._tBody.current.children].indexOf(overItem);
|
|
565
|
+
if (dragItemIndex === -1 || dropItemIndex === -1)
|
|
566
|
+
return;
|
|
567
|
+
_tBody.current.insertBefore(_dragItem.current, dragItemIndex < dropItemIndex ? overItem.nextSibling : overItem);
|
|
568
|
+
const movedItem = data.splice(dragItemIndex, 1)[0];
|
|
569
|
+
if (movedItem) {
|
|
570
|
+
data.splice(dropItemIndex, 0, movedItem);
|
|
571
|
+
onDnD?.(data);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
_item.ondragend = (event) => {
|
|
577
|
+
const item = event.currentTarget;
|
|
578
|
+
item.classList.remove("drag-item");
|
|
579
|
+
item.classList.add("end-item");
|
|
580
|
+
setTimeout(() => {
|
|
581
|
+
item.classList.remove("end-item");
|
|
582
|
+
if (item.classList.length === 0)
|
|
583
|
+
item.removeAttribute("class");
|
|
584
|
+
}, 1000);
|
|
585
|
+
};
|
|
586
|
+
});
|
|
587
|
+
_tBody.current.ondragover = (event) => event.preventDefault();
|
|
588
|
+
return () => {
|
|
589
|
+
if (!_tBody.current)
|
|
590
|
+
return;
|
|
591
|
+
_tBody.current.childNodes.forEach((item) => {
|
|
592
|
+
const _item = item;
|
|
593
|
+
_item.ondragstart = null;
|
|
594
|
+
_item.ondragover = null;
|
|
595
|
+
_item.ondragend = null;
|
|
596
|
+
});
|
|
597
|
+
_tBody.current.ondragover = null;
|
|
598
|
+
};
|
|
599
|
+
}, [data]);
|
|
515
600
|
useLayoutEffect(() => {
|
|
516
601
|
const heights = _tBodyTR.current.map((el) => (el ? el.getBoundingClientRect().height : 0));
|
|
517
602
|
setTimeout(() => handleScroll(), 0);
|
|
@@ -639,11 +724,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
|
|
|
639
724
|
element: (React.createElement(ARIcon, { viewBox: "0 0 16 16", size: 24, icon: "Filter", fill: "var(--dark)", strokeWidth: 0 })),
|
|
640
725
|
} }))))));
|
|
641
726
|
})))),
|
|
642
|
-
React.createElement("tbody",
|
|
643
|
-
React.createElement("td", { colSpan: columns.length },
|
|
644
|
-
React.createElement("div", { className: "no-item" },
|
|
645
|
-
React.createElement(ARIcon, { icon: "Inbox-Fill", fill: "var(--gray-300)", size: 64, style: { position: "relative", zIndex: 1 } }),
|
|
646
|
-
React.createElement("span", null, "No Data")))))))),
|
|
727
|
+
React.createElement("tbody", { ref: _tBody }, renderTBody))),
|
|
647
728
|
React.createElement(FilterPopup, { tableContent: _tableContent, coordinate: filterButtonCoordinate, buttons: _filterButton }, filterPopupContent),
|
|
648
729
|
pagination && pagination.totalRecords > pagination.perPage && (React.createElement("div", { className: "footer" },
|
|
649
730
|
React.createElement("span", null,
|