@martinsura/ui 0.1.7 → 0.1.9
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 +24 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -5
- package/dist/index.d.ts +12 -5
- package/dist/index.js +24 -15
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -1660,6 +1660,12 @@ function useGrid(defaults, storageKey) {
|
|
|
1660
1660
|
};
|
|
1661
1661
|
return { ...state, onChange, apiQuery };
|
|
1662
1662
|
}
|
|
1663
|
+
function getNestedValue(obj, path) {
|
|
1664
|
+
return path.split(".").reduce((acc, key) => {
|
|
1665
|
+
if (acc == null || typeof acc !== "object") return void 0;
|
|
1666
|
+
return acc[key];
|
|
1667
|
+
}, obj);
|
|
1668
|
+
}
|
|
1663
1669
|
var columnTypeWidth2 = {
|
|
1664
1670
|
date: 100,
|
|
1665
1671
|
datetime: 130,
|
|
@@ -1745,10 +1751,13 @@ var Pagination = ({ current, pageSize, total, onChange, showPageNumberChanger, s
|
|
|
1745
1751
|
};
|
|
1746
1752
|
var Grid = (props) => {
|
|
1747
1753
|
const { grid } = props;
|
|
1754
|
+
const items = props.items ?? [];
|
|
1755
|
+
const totalCount = props.totalCount ?? 0;
|
|
1756
|
+
const loading = props.loading ?? false;
|
|
1748
1757
|
const sc = tableSizeConfig[props.size ?? "middle"];
|
|
1749
1758
|
const verticalBorders = props.verticalBorders ?? false;
|
|
1750
|
-
const isInitialLoading =
|
|
1751
|
-
const isEmpty = !
|
|
1759
|
+
const isInitialLoading = loading && items.length === 0;
|
|
1760
|
+
const isEmpty = !loading && items.length === 0;
|
|
1752
1761
|
const handleSort = (col) => {
|
|
1753
1762
|
if (col.sortBy === void 0) return;
|
|
1754
1763
|
const isCurrent = grid.sortBy === col.sortBy;
|
|
@@ -1757,20 +1766,20 @@ var Grid = (props) => {
|
|
|
1757
1766
|
direction: isCurrent && grid.direction === SortDirection.Asc ? SortDirection.Desc : SortDirection.Asc
|
|
1758
1767
|
});
|
|
1759
1768
|
};
|
|
1760
|
-
|
|
1769
|
+
items.map((item) => getKey2(item, items, props.rowKey));
|
|
1761
1770
|
const selectedKeys = new Set(
|
|
1762
|
-
(props.selection?.selectedItems ?? []).map((item) => getKey2(item,
|
|
1771
|
+
(props.selection?.selectedItems ?? []).map((item) => getKey2(item, items, props.rowKey))
|
|
1763
1772
|
);
|
|
1764
|
-
const allSelected =
|
|
1765
|
-
const someSelected = !allSelected &&
|
|
1773
|
+
const allSelected = items.length > 0 && items.every((item) => selectedKeys.has(getKey2(item, items, props.rowKey)));
|
|
1774
|
+
const someSelected = !allSelected && items.some((item) => selectedKeys.has(getKey2(item, items, props.rowKey)));
|
|
1766
1775
|
const toggleAll = () => {
|
|
1767
1776
|
if (!props.selection) return;
|
|
1768
|
-
props.selection.onChange(allSelected ? [] : [...
|
|
1777
|
+
props.selection.onChange(allSelected ? [] : [...items]);
|
|
1769
1778
|
};
|
|
1770
1779
|
const toggleRow = (item) => {
|
|
1771
1780
|
if (!props.selection) return;
|
|
1772
|
-
const key = getKey2(item,
|
|
1773
|
-
const next = selectedKeys.has(key) ? props.selection.selectedItems.filter((s) => getKey2(s,
|
|
1781
|
+
const key = getKey2(item, items, props.rowKey);
|
|
1782
|
+
const next = selectedKeys.has(key) ? props.selection.selectedItems.filter((s) => getKey2(s, items, props.rowKey) !== key) : [...props.selection.selectedItems, item];
|
|
1774
1783
|
props.selection.onChange(next);
|
|
1775
1784
|
};
|
|
1776
1785
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -1782,7 +1791,7 @@ var Grid = (props) => {
|
|
|
1782
1791
|
props.className
|
|
1783
1792
|
),
|
|
1784
1793
|
children: [
|
|
1785
|
-
|
|
1794
|
+
loading && !isInitialLoading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: tailwindMerge.twMerge("absolute inset-0 z-10 bg-white/60 flex items-center justify-center", props.classNames?.overlay), children: /* @__PURE__ */ jsxRuntime.jsx(Spinner, { size: "large", color: "primary" }) }),
|
|
1786
1795
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: tailwindMerge.twMerge("w-full border-collapse", props.classNames?.table), children: [
|
|
1787
1796
|
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: tailwindMerge.twMerge("bg-(--ui-primary) text-(--ui-primary-text)", props.classNames?.headerRow), children: [
|
|
1788
1797
|
props.selection && /* @__PURE__ */ jsxRuntime.jsx("th", { className: tailwindMerge.twMerge(sc.th, "w-9", verticalBorders && tableHeaderVerticalBorderClass, props.classNames?.headerCell), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1837,8 +1846,8 @@ var Grid = (props) => {
|
|
|
1837
1846
|
className: tailwindMerge.twMerge("px-3", props.classNames?.emptyCell),
|
|
1838
1847
|
children: /* @__PURE__ */ jsxRuntime.jsx(Empty, { size: "compact", text: props.emptyText ?? "\u017D\xE1dn\xE9 z\xE1znamy", className: sc.emptyPy })
|
|
1839
1848
|
}
|
|
1840
|
-
) }) :
|
|
1841
|
-
const key = getKey2(item,
|
|
1849
|
+
) }) : items.map((item, rowIdx) => {
|
|
1850
|
+
const key = getKey2(item, items, props.rowKey);
|
|
1842
1851
|
const isSelected = selectedKeys.has(key);
|
|
1843
1852
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1844
1853
|
"tr",
|
|
@@ -1869,7 +1878,7 @@ var Grid = (props) => {
|
|
|
1869
1878
|
}
|
|
1870
1879
|
),
|
|
1871
1880
|
props.columns.map((col, colIdx) => {
|
|
1872
|
-
const content = col.render ? col.render(item) : col.dataField ? formatCellValue(item
|
|
1881
|
+
const content = col.render ? col.render(item) : col.dataField ? formatCellValue(getNestedValue(item, col.dataField), col.type) : null;
|
|
1873
1882
|
const centeredContent = col.align === "center";
|
|
1874
1883
|
const rightAlignedContent = col.align === "right";
|
|
1875
1884
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1912,7 +1921,7 @@ var Grid = (props) => {
|
|
|
1912
1921
|
{
|
|
1913
1922
|
current: grid.pageNumber,
|
|
1914
1923
|
pageSize: grid.pageSize,
|
|
1915
|
-
total:
|
|
1924
|
+
total: totalCount,
|
|
1916
1925
|
showPageNumberChanger: props.showPageNumberChanger ?? false,
|
|
1917
1926
|
showPageSizeChanger: props.showPageSizeChanger ?? false,
|
|
1918
1927
|
onChange: (page, pageSize) => grid.onChange({ pageNumber: page, pageSize }),
|
|
@@ -5357,6 +5366,7 @@ exports.TreeSelectInput = TreeSelectInput;
|
|
|
5357
5366
|
exports.UploadInput = UploadInput;
|
|
5358
5367
|
exports.UploadProvider = UploadProvider;
|
|
5359
5368
|
exports.getIcon = getIcon;
|
|
5369
|
+
exports.getNestedValue = getNestedValue;
|
|
5360
5370
|
exports.initUI = initUI;
|
|
5361
5371
|
exports.notification = notification;
|
|
5362
5372
|
exports.registerIcons = registerIcons;
|