@underverse-ui/underverse 1.0.70 → 1.0.71
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/api-reference.json +1 -1
- package/dist/index.cjs +394 -204
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +310 -120
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20112,10 +20112,65 @@ var TableCaption = React52.forwardRef(({ className, ...props }, ref) => /* @__PU
|
|
|
20112
20112
|
TableCaption.displayName = "TableCaption";
|
|
20113
20113
|
|
|
20114
20114
|
// src/components/DataTable/DataTable.tsx
|
|
20115
|
-
import
|
|
20115
|
+
import React62 from "react";
|
|
20116
20116
|
|
|
20117
20117
|
// src/components/DataTable/components/DataTableBody.tsx
|
|
20118
|
+
import React53 from "react";
|
|
20118
20119
|
import { jsx as jsx62, jsxs as jsxs52 } from "react/jsx-runtime";
|
|
20120
|
+
function DataTableOverflowText({
|
|
20121
|
+
text,
|
|
20122
|
+
align
|
|
20123
|
+
}) {
|
|
20124
|
+
const triggerId = React53.useId();
|
|
20125
|
+
const [isOverflowing, setIsOverflowing] = React53.useState(false);
|
|
20126
|
+
const alignClass = align === "right" ? "text-right" : align === "center" ? "text-center" : "text-left";
|
|
20127
|
+
const measureOverflow = React53.useCallback(() => {
|
|
20128
|
+
if (typeof document === "undefined") return;
|
|
20129
|
+
const element = document.querySelector(`[data-underverse-datatable-cell="${triggerId}"]`);
|
|
20130
|
+
if (!element) return;
|
|
20131
|
+
setIsOverflowing(
|
|
20132
|
+
element.scrollWidth - element.clientWidth > 1 || element.scrollHeight - element.clientHeight > 1
|
|
20133
|
+
);
|
|
20134
|
+
}, [triggerId]);
|
|
20135
|
+
React53.useLayoutEffect(() => {
|
|
20136
|
+
measureOverflow();
|
|
20137
|
+
}, [measureOverflow, text]);
|
|
20138
|
+
React53.useEffect(() => {
|
|
20139
|
+
if (typeof document === "undefined") return;
|
|
20140
|
+
const element = document.querySelector(`[data-underverse-datatable-cell="${triggerId}"]`);
|
|
20141
|
+
if (!element) return;
|
|
20142
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
20143
|
+
const observer = new ResizeObserver(() => {
|
|
20144
|
+
measureOverflow();
|
|
20145
|
+
});
|
|
20146
|
+
observer.observe(element);
|
|
20147
|
+
return () => observer.disconnect();
|
|
20148
|
+
}, [measureOverflow, triggerId]);
|
|
20149
|
+
const trigger = /* @__PURE__ */ jsx62(
|
|
20150
|
+
"button",
|
|
20151
|
+
{
|
|
20152
|
+
type: "button",
|
|
20153
|
+
"data-underverse-datatable-cell": triggerId,
|
|
20154
|
+
onMouseEnter: measureOverflow,
|
|
20155
|
+
onFocus: measureOverflow,
|
|
20156
|
+
className: cn(
|
|
20157
|
+
"block w-full truncate bg-transparent p-0 font-inherit text-inherit select-text",
|
|
20158
|
+
"cursor-text",
|
|
20159
|
+
alignClass
|
|
20160
|
+
),
|
|
20161
|
+
children: text
|
|
20162
|
+
}
|
|
20163
|
+
);
|
|
20164
|
+
return /* @__PURE__ */ jsx62(
|
|
20165
|
+
Tooltip,
|
|
20166
|
+
{
|
|
20167
|
+
disabled: !isOverflowing,
|
|
20168
|
+
placement: "top",
|
|
20169
|
+
content: /* @__PURE__ */ jsx62("div", { className: cn("max-w-[min(40rem,calc(100vw-2rem))] whitespace-pre-wrap break-all select-text", alignClass), children: text }),
|
|
20170
|
+
children: trigger
|
|
20171
|
+
}
|
|
20172
|
+
);
|
|
20173
|
+
}
|
|
20119
20174
|
function DataTableBodyRows({
|
|
20120
20175
|
leafColumns,
|
|
20121
20176
|
displayedData,
|
|
@@ -20164,6 +20219,7 @@ function DataTableBodyRows({
|
|
|
20164
20219
|
return /* @__PURE__ */ jsx62(
|
|
20165
20220
|
TableCell,
|
|
20166
20221
|
{
|
|
20222
|
+
"data-underverse-column-key": col.key,
|
|
20167
20223
|
style: getStickyColumnStyle(col),
|
|
20168
20224
|
className: cn(
|
|
20169
20225
|
cellPadding,
|
|
@@ -20172,7 +20228,7 @@ function DataTableBodyRows({
|
|
|
20172
20228
|
showBorderLeft && "border-l border-border/60",
|
|
20173
20229
|
getStickyCellClass(col, isStripedRow)
|
|
20174
20230
|
),
|
|
20175
|
-
children: col.render ? col.render(value, row, idx) : String(value ?? "")
|
|
20231
|
+
children: col.render ? col.render(value, row, idx) : /* @__PURE__ */ jsx62(DataTableOverflowText, { text: String(value ?? ""), align: col.align })
|
|
20176
20232
|
},
|
|
20177
20233
|
col.key
|
|
20178
20234
|
);
|
|
@@ -20184,7 +20240,7 @@ function DataTableBodyRows({
|
|
|
20184
20240
|
}
|
|
20185
20241
|
|
|
20186
20242
|
// src/components/DataTable/components/DataTableHeader.tsx
|
|
20187
|
-
import
|
|
20243
|
+
import React54 from "react";
|
|
20188
20244
|
import { Filter as FilterIcon } from "lucide-react";
|
|
20189
20245
|
import { Fragment as Fragment22, jsx as jsx63, jsxs as jsxs53 } from "react/jsx-runtime";
|
|
20190
20246
|
function DataTableHeader({
|
|
@@ -20200,11 +20256,13 @@ function DataTableHeader({
|
|
|
20200
20256
|
setCurPage,
|
|
20201
20257
|
setFilters,
|
|
20202
20258
|
setSort,
|
|
20259
|
+
onAutoFitColumn,
|
|
20260
|
+
enableHeaderAutoFit,
|
|
20203
20261
|
getStickyHeaderClass,
|
|
20204
20262
|
getStickyHeaderCellStyle,
|
|
20205
20263
|
t
|
|
20206
20264
|
}) {
|
|
20207
|
-
const renderFilterControl =
|
|
20265
|
+
const renderFilterControl = React54.useCallback(
|
|
20208
20266
|
(col) => {
|
|
20209
20267
|
if (!col.filter) return null;
|
|
20210
20268
|
const key = col.key;
|
|
@@ -20257,7 +20315,7 @@ function DataTableHeader({
|
|
|
20257
20315
|
},
|
|
20258
20316
|
[filters, setCurPage, setFilters, size]
|
|
20259
20317
|
);
|
|
20260
|
-
const renderHeaderContent =
|
|
20318
|
+
const renderHeaderContent = React54.useCallback(
|
|
20261
20319
|
(col, isLeaf) => {
|
|
20262
20320
|
if (!isLeaf) {
|
|
20263
20321
|
return /* @__PURE__ */ jsx63(
|
|
@@ -20397,22 +20455,55 @@ function DataTableHeader({
|
|
|
20397
20455
|
const prevCol = prevCell?.column;
|
|
20398
20456
|
const isAfterFixedLeft = prevCol?.fixed === "left";
|
|
20399
20457
|
const showBorderLeft = columnDividers && cellIndex > 0 && !isAfterFixedLeft && !col.fixed;
|
|
20400
|
-
return /* @__PURE__ */
|
|
20458
|
+
return /* @__PURE__ */ jsxs53(
|
|
20401
20459
|
TableHead,
|
|
20402
20460
|
{
|
|
20403
20461
|
colSpan,
|
|
20404
20462
|
rowSpan,
|
|
20463
|
+
"data-underverse-column-key": isLeaf ? col.key : void 0,
|
|
20405
20464
|
style: {
|
|
20406
20465
|
width: col.width,
|
|
20407
20466
|
...getStickyHeaderCellStyle(headerCell)
|
|
20408
20467
|
},
|
|
20409
20468
|
className: cn(
|
|
20469
|
+
"relative",
|
|
20410
20470
|
(col.align === "right" || !col.align && headerAlign === "right") && "text-right",
|
|
20411
20471
|
(col.align === "center" || !col.align && headerAlign === "center") && "text-center",
|
|
20412
20472
|
showBorderLeft && "border-l border-border/60",
|
|
20413
20473
|
getStickyHeaderClass(col)
|
|
20414
20474
|
),
|
|
20415
|
-
children:
|
|
20475
|
+
children: [
|
|
20476
|
+
renderHeaderContent(col, isLeaf),
|
|
20477
|
+
isLeaf && enableHeaderAutoFit && /* @__PURE__ */ jsx63(
|
|
20478
|
+
Tooltip,
|
|
20479
|
+
{
|
|
20480
|
+
placement: "top",
|
|
20481
|
+
content: /* @__PURE__ */ jsx63("span", { className: "text-xs font-medium", children: "Double click to auto-fit" }),
|
|
20482
|
+
children: /* @__PURE__ */ jsx63(
|
|
20483
|
+
"button",
|
|
20484
|
+
{
|
|
20485
|
+
type: "button",
|
|
20486
|
+
"aria-label": `Auto fit ${String(col.title)}`,
|
|
20487
|
+
onClick: (event) => {
|
|
20488
|
+
event.preventDefault();
|
|
20489
|
+
event.stopPropagation();
|
|
20490
|
+
},
|
|
20491
|
+
onDoubleClick: (event) => {
|
|
20492
|
+
event.preventDefault();
|
|
20493
|
+
event.stopPropagation();
|
|
20494
|
+
onAutoFitColumn?.(col.key);
|
|
20495
|
+
},
|
|
20496
|
+
className: cn(
|
|
20497
|
+
"absolute inset-y-0 right-0 z-10 w-3 -mr-1",
|
|
20498
|
+
"cursor-col-resize select-none bg-transparent",
|
|
20499
|
+
"after:absolute after:inset-y-2 after:right-[3px] after:w-px after:bg-border/0 after:transition-colors",
|
|
20500
|
+
"hover:after:bg-primary/50 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary"
|
|
20501
|
+
)
|
|
20502
|
+
}
|
|
20503
|
+
)
|
|
20504
|
+
}
|
|
20505
|
+
)
|
|
20506
|
+
]
|
|
20416
20507
|
},
|
|
20417
20508
|
col.key
|
|
20418
20509
|
);
|
|
@@ -20420,7 +20511,7 @@ function DataTableHeader({
|
|
|
20420
20511
|
}
|
|
20421
20512
|
|
|
20422
20513
|
// src/components/DataTable/components/Pagination.tsx
|
|
20423
|
-
import
|
|
20514
|
+
import React55 from "react";
|
|
20424
20515
|
import { jsx as jsx64, jsxs as jsxs54 } from "react/jsx-runtime";
|
|
20425
20516
|
function DataTablePagination({
|
|
20426
20517
|
totalItems,
|
|
@@ -20432,7 +20523,7 @@ function DataTablePagination({
|
|
|
20432
20523
|
size
|
|
20433
20524
|
}) {
|
|
20434
20525
|
const totalPages = Math.ceil(totalItems / curPageSize);
|
|
20435
|
-
const pages =
|
|
20526
|
+
const pages = React55.useMemo(() => {
|
|
20436
20527
|
const result = [];
|
|
20437
20528
|
if (totalPages <= 5) {
|
|
20438
20529
|
for (let i = 1; i <= totalPages; i++) result.push(i);
|
|
@@ -20514,7 +20605,7 @@ function DataTablePagination({
|
|
|
20514
20605
|
}
|
|
20515
20606
|
|
|
20516
20607
|
// src/components/DataTable/components/Toolbar.tsx
|
|
20517
|
-
import
|
|
20608
|
+
import React56 from "react";
|
|
20518
20609
|
|
|
20519
20610
|
// src/components/DataTable/utils/headers.ts
|
|
20520
20611
|
function isLeafColumn(col) {
|
|
@@ -20635,7 +20726,7 @@ function DataTableToolbar({
|
|
|
20635
20726
|
const controlButtonClass = size === "sm" ? "h-7 px-2 text-xs" : size === "lg" ? "h-9 px-3 text-sm" : "h-8 px-2";
|
|
20636
20727
|
const iconClass = size === "sm" ? "w-3.5 h-3.5 mr-1" : "w-4 h-4 mr-1";
|
|
20637
20728
|
const captionClass = size === "sm" ? "text-xs" : size === "lg" ? "text-sm" : "text-sm";
|
|
20638
|
-
const leafCols =
|
|
20729
|
+
const leafCols = React56.useMemo(() => getLeafColumns(columns), [columns]);
|
|
20639
20730
|
return /* @__PURE__ */ jsxs55("div", { className: "flex items-center justify-between gap-4 mb-1", children: [
|
|
20640
20731
|
/* @__PURE__ */ jsx65("div", { className: captionClass + " text-muted-foreground", children: caption }),
|
|
20641
20732
|
/* @__PURE__ */ jsxs55("div", { className: "flex items-center gap-2", children: [
|
|
@@ -20703,10 +20794,10 @@ function DataTableToolbar({
|
|
|
20703
20794
|
}
|
|
20704
20795
|
|
|
20705
20796
|
// src/components/DataTable/hooks/useDebounced.ts
|
|
20706
|
-
import
|
|
20797
|
+
import React57 from "react";
|
|
20707
20798
|
function useDebounced(value, delay = 300) {
|
|
20708
|
-
const [debounced, setDebounced] =
|
|
20709
|
-
|
|
20799
|
+
const [debounced, setDebounced] = React57.useState(value);
|
|
20800
|
+
React57.useEffect(() => {
|
|
20710
20801
|
const id = setTimeout(() => setDebounced(value), delay);
|
|
20711
20802
|
return () => clearTimeout(id);
|
|
20712
20803
|
}, [value, delay]);
|
|
@@ -20714,7 +20805,7 @@ function useDebounced(value, delay = 300) {
|
|
|
20714
20805
|
}
|
|
20715
20806
|
|
|
20716
20807
|
// src/components/DataTable/hooks/useDataTableModel.ts
|
|
20717
|
-
import
|
|
20808
|
+
import React58 from "react";
|
|
20718
20809
|
|
|
20719
20810
|
// src/components/DataTable/utils/columns.ts
|
|
20720
20811
|
function getColumnWidth(col, fallback = 150) {
|
|
@@ -20742,22 +20833,22 @@ function useDataTableModel({
|
|
|
20742
20833
|
isServerMode,
|
|
20743
20834
|
total
|
|
20744
20835
|
}) {
|
|
20745
|
-
const visibleColsSet =
|
|
20746
|
-
const allLeafColumns =
|
|
20747
|
-
const columnMap =
|
|
20836
|
+
const visibleColsSet = React58.useMemo(() => new Set(visibleCols), [visibleCols]);
|
|
20837
|
+
const allLeafColumns = React58.useMemo(() => getLeafColumns(columns), [columns]);
|
|
20838
|
+
const columnMap = React58.useMemo(() => {
|
|
20748
20839
|
return new Map(allLeafColumns.map((column) => [column.key, column]));
|
|
20749
20840
|
}, [allLeafColumns]);
|
|
20750
|
-
const visibleColumns =
|
|
20841
|
+
const visibleColumns = React58.useMemo(() => {
|
|
20751
20842
|
return filterVisibleColumns(columns, visibleColsSet);
|
|
20752
20843
|
}, [columns, visibleColsSet]);
|
|
20753
|
-
const leafColumns =
|
|
20844
|
+
const leafColumns = React58.useMemo(() => {
|
|
20754
20845
|
return getLeafColumnsWithFixedInheritance(visibleColumns);
|
|
20755
20846
|
}, [visibleColumns]);
|
|
20756
|
-
const headerRows =
|
|
20757
|
-
const totalColumnsWidth =
|
|
20847
|
+
const headerRows = React58.useMemo(() => buildHeaderRows(visibleColumns), [visibleColumns]);
|
|
20848
|
+
const totalColumnsWidth = React58.useMemo(() => {
|
|
20758
20849
|
return leafColumns.reduce((sum, column) => sum + getColumnWidth(column), 0);
|
|
20759
20850
|
}, [leafColumns]);
|
|
20760
|
-
const processedData =
|
|
20851
|
+
const processedData = React58.useMemo(() => {
|
|
20761
20852
|
if (isServerMode) return data;
|
|
20762
20853
|
let result = [...data];
|
|
20763
20854
|
if (Object.keys(filters).length > 0) {
|
|
@@ -20789,7 +20880,7 @@ function useDataTableModel({
|
|
|
20789
20880
|
return result;
|
|
20790
20881
|
}, [columnMap, data, filters, isServerMode, sort]);
|
|
20791
20882
|
const totalItems = isServerMode ? total : processedData.length;
|
|
20792
|
-
const displayedData =
|
|
20883
|
+
const displayedData = React58.useMemo(() => {
|
|
20793
20884
|
if (isServerMode) return data;
|
|
20794
20885
|
const start = (curPage - 1) * curPageSize;
|
|
20795
20886
|
return processedData.slice(start, start + curPageSize);
|
|
@@ -20805,10 +20896,10 @@ function useDataTableModel({
|
|
|
20805
20896
|
}
|
|
20806
20897
|
|
|
20807
20898
|
// src/components/DataTable/hooks/useDataTableState.ts
|
|
20808
|
-
import
|
|
20899
|
+
import React60 from "react";
|
|
20809
20900
|
|
|
20810
20901
|
// src/components/DataTable/hooks/usePageSizeStorage.ts
|
|
20811
|
-
import
|
|
20902
|
+
import React59 from "react";
|
|
20812
20903
|
function readStoredPageSize(storageKey) {
|
|
20813
20904
|
if (typeof window === "undefined" || !storageKey) return null;
|
|
20814
20905
|
try {
|
|
@@ -20821,8 +20912,8 @@ function readStoredPageSize(storageKey) {
|
|
|
20821
20912
|
}
|
|
20822
20913
|
}
|
|
20823
20914
|
function usePageSizeStorage({ pageSize, storageKey }) {
|
|
20824
|
-
const storedPageSize =
|
|
20825
|
-
const [overrideState, setOverrideState] =
|
|
20915
|
+
const storedPageSize = React59.useMemo(() => readStoredPageSize(storageKey), [storageKey]);
|
|
20916
|
+
const [overrideState, setOverrideState] = React59.useState({
|
|
20826
20917
|
storageKey,
|
|
20827
20918
|
pageSize: null
|
|
20828
20919
|
});
|
|
@@ -20830,7 +20921,7 @@ function usePageSizeStorage({ pageSize, storageKey }) {
|
|
|
20830
20921
|
const persistedPageSize = storageKey ? overridePageSize ?? storedPageSize : null;
|
|
20831
20922
|
const loadedFromStorage = persistedPageSize != null;
|
|
20832
20923
|
const curPageSize = storageKey ? persistedPageSize ?? pageSize : overridePageSize ?? pageSize;
|
|
20833
|
-
const setCurPageSize =
|
|
20924
|
+
const setCurPageSize = React59.useCallback(
|
|
20834
20925
|
(nextPageSize) => {
|
|
20835
20926
|
const baseValue = storageKey ? persistedPageSize ?? pageSize : overridePageSize ?? pageSize;
|
|
20836
20927
|
const resolved = typeof nextPageSize === "function" ? nextPageSize(baseValue) : nextPageSize;
|
|
@@ -20859,17 +20950,17 @@ function useDataTableState({
|
|
|
20859
20950
|
size,
|
|
20860
20951
|
storageKey
|
|
20861
20952
|
}) {
|
|
20862
|
-
const allLeafColumns =
|
|
20863
|
-
const defaultVisibleLeafKeys =
|
|
20864
|
-
const knownLeafKeysRef =
|
|
20865
|
-
const [headerAlign, setHeaderAlign] =
|
|
20866
|
-
const [visibleCols, setVisibleCols] =
|
|
20867
|
-
const [filters, setFilters] =
|
|
20868
|
-
const [sort, setSort] =
|
|
20869
|
-
const [density, setDensity] =
|
|
20870
|
-
const [curPage, setCurPage] =
|
|
20953
|
+
const allLeafColumns = React60.useMemo(() => getLeafColumns(columns), [columns]);
|
|
20954
|
+
const defaultVisibleLeafKeys = React60.useMemo(() => allLeafColumns.filter((column) => column.visible !== false).map((column) => column.key), [allLeafColumns]);
|
|
20955
|
+
const knownLeafKeysRef = React60.useRef(new Set(defaultVisibleLeafKeys));
|
|
20956
|
+
const [headerAlign, setHeaderAlign] = React60.useState("left");
|
|
20957
|
+
const [visibleCols, setVisibleCols] = React60.useState(defaultVisibleLeafKeys);
|
|
20958
|
+
const [filters, setFilters] = React60.useState({});
|
|
20959
|
+
const [sort, setSort] = React60.useState(null);
|
|
20960
|
+
const [density, setDensity] = React60.useState(() => SIZE_TO_DENSITY[size]);
|
|
20961
|
+
const [curPage, setCurPage] = React60.useState(page);
|
|
20871
20962
|
const { curPageSize, setCurPageSize } = usePageSizeStorage({ pageSize, storageKey });
|
|
20872
|
-
|
|
20963
|
+
React60.useEffect(() => {
|
|
20873
20964
|
const knownLeafKeys = knownLeafKeysRef.current;
|
|
20874
20965
|
setVisibleCols((prev) => {
|
|
20875
20966
|
const prevSet = new Set(prev);
|
|
@@ -20877,10 +20968,10 @@ function useDataTableState({
|
|
|
20877
20968
|
});
|
|
20878
20969
|
knownLeafKeysRef.current = new Set(allLeafColumns.map((column) => column.key));
|
|
20879
20970
|
}, [allLeafColumns]);
|
|
20880
|
-
|
|
20971
|
+
React60.useEffect(() => {
|
|
20881
20972
|
setCurPage(page);
|
|
20882
20973
|
}, [page]);
|
|
20883
|
-
|
|
20974
|
+
React60.useEffect(() => {
|
|
20884
20975
|
setDensity(SIZE_TO_DENSITY[size]);
|
|
20885
20976
|
}, [size]);
|
|
20886
20977
|
return {
|
|
@@ -20902,7 +20993,7 @@ function useDataTableState({
|
|
|
20902
20993
|
}
|
|
20903
20994
|
|
|
20904
20995
|
// src/components/DataTable/hooks/useStickyColumns.ts
|
|
20905
|
-
import
|
|
20996
|
+
import React61 from "react";
|
|
20906
20997
|
|
|
20907
20998
|
// src/components/DataTable/utils/sticky.ts
|
|
20908
20999
|
function buildStickyLayout(visibleColumns) {
|
|
@@ -20949,8 +21040,8 @@ function resolveGroupStickyPosition(column, positions) {
|
|
|
20949
21040
|
|
|
20950
21041
|
// src/components/DataTable/hooks/useStickyColumns.ts
|
|
20951
21042
|
function useStickyColumns(visibleColumns) {
|
|
20952
|
-
const { positions, leftBoundaryKey, rightBoundaryKey } =
|
|
20953
|
-
const getStickyColumnStyle =
|
|
21043
|
+
const { positions, leftBoundaryKey, rightBoundaryKey } = React61.useMemo(() => buildStickyLayout(visibleColumns), [visibleColumns]);
|
|
21044
|
+
const getStickyColumnStyle = React61.useCallback(
|
|
20954
21045
|
(col) => {
|
|
20955
21046
|
const pos = resolveStickyPosition(col, positions);
|
|
20956
21047
|
if (!pos) return {};
|
|
@@ -20961,7 +21052,7 @@ function useStickyColumns(visibleColumns) {
|
|
|
20961
21052
|
},
|
|
20962
21053
|
[positions]
|
|
20963
21054
|
);
|
|
20964
|
-
const getBoundaryShadowClass =
|
|
21055
|
+
const getBoundaryShadowClass = React61.useCallback(
|
|
20965
21056
|
(col) => {
|
|
20966
21057
|
if (col.fixed === "left" && col.key === leftBoundaryKey) {
|
|
20967
21058
|
return "border-r border-border/80 shadow-[10px_0_16px_-10px_rgba(0,0,0,0.55)]";
|
|
@@ -20973,14 +21064,14 @@ function useStickyColumns(visibleColumns) {
|
|
|
20973
21064
|
},
|
|
20974
21065
|
[leftBoundaryKey, rightBoundaryKey]
|
|
20975
21066
|
);
|
|
20976
|
-
const getStickyHeaderClass =
|
|
21067
|
+
const getStickyHeaderClass = React61.useCallback(
|
|
20977
21068
|
(col) => {
|
|
20978
21069
|
if (!col.fixed) return "";
|
|
20979
21070
|
return cn("sticky", col.fixed === "left" && "left-0", col.fixed === "right" && "right-0", getBoundaryShadowClass(col), "z-50 !bg-muted");
|
|
20980
21071
|
},
|
|
20981
21072
|
[getBoundaryShadowClass]
|
|
20982
21073
|
);
|
|
20983
|
-
const getStickyCellClass =
|
|
21074
|
+
const getStickyCellClass = React61.useCallback(
|
|
20984
21075
|
(col, isStripedRow) => {
|
|
20985
21076
|
if (!col.fixed) return "";
|
|
20986
21077
|
return cn(
|
|
@@ -20993,7 +21084,7 @@ function useStickyColumns(visibleColumns) {
|
|
|
20993
21084
|
},
|
|
20994
21085
|
[getBoundaryShadowClass]
|
|
20995
21086
|
);
|
|
20996
|
-
const getStickyHeaderCellStyle =
|
|
21087
|
+
const getStickyHeaderCellStyle = React61.useCallback(
|
|
20997
21088
|
(headerCell) => {
|
|
20998
21089
|
const col = headerCell.column;
|
|
20999
21090
|
if (headerCell.isLeaf) {
|
|
@@ -21092,6 +21183,66 @@ function validateColumns(columns) {
|
|
|
21092
21183
|
|
|
21093
21184
|
// src/components/DataTable/DataTable.tsx
|
|
21094
21185
|
import { jsx as jsx66, jsxs as jsxs56 } from "react/jsx-runtime";
|
|
21186
|
+
function applyColumnWidthOverrides(columns, widthOverrides) {
|
|
21187
|
+
return columns.map((column) => {
|
|
21188
|
+
if (column.children?.length) {
|
|
21189
|
+
return {
|
|
21190
|
+
...column,
|
|
21191
|
+
children: applyColumnWidthOverrides(column.children, widthOverrides)
|
|
21192
|
+
};
|
|
21193
|
+
}
|
|
21194
|
+
const nextWidth = widthOverrides[column.key];
|
|
21195
|
+
if (nextWidth == null) {
|
|
21196
|
+
return column;
|
|
21197
|
+
}
|
|
21198
|
+
return {
|
|
21199
|
+
...column,
|
|
21200
|
+
width: nextWidth
|
|
21201
|
+
};
|
|
21202
|
+
});
|
|
21203
|
+
}
|
|
21204
|
+
function measureNaturalContentWidth(node) {
|
|
21205
|
+
if (typeof document === "undefined") return 0;
|
|
21206
|
+
const measurementRoot = document.createElement("div");
|
|
21207
|
+
measurementRoot.style.position = "absolute";
|
|
21208
|
+
measurementRoot.style.left = "-99999px";
|
|
21209
|
+
measurementRoot.style.top = "0";
|
|
21210
|
+
measurementRoot.style.visibility = "hidden";
|
|
21211
|
+
measurementRoot.style.pointerEvents = "none";
|
|
21212
|
+
measurementRoot.style.whiteSpace = "nowrap";
|
|
21213
|
+
measurementRoot.style.width = "max-content";
|
|
21214
|
+
measurementRoot.style.maxWidth = "none";
|
|
21215
|
+
measurementRoot.style.minWidth = "0";
|
|
21216
|
+
measurementRoot.style.overflow = "visible";
|
|
21217
|
+
const clone = (node.firstElementChild instanceof HTMLElement ? node.firstElementChild : node).cloneNode(true);
|
|
21218
|
+
if (!(clone instanceof HTMLElement)) {
|
|
21219
|
+
return 0;
|
|
21220
|
+
}
|
|
21221
|
+
const sourceStyle = window.getComputedStyle(node);
|
|
21222
|
+
const cloneStyle = window.getComputedStyle(clone);
|
|
21223
|
+
clone.style.width = "max-content";
|
|
21224
|
+
clone.style.maxWidth = "none";
|
|
21225
|
+
clone.style.minWidth = "0";
|
|
21226
|
+
clone.style.overflow = "visible";
|
|
21227
|
+
clone.style.textOverflow = "clip";
|
|
21228
|
+
clone.style.whiteSpace = cloneStyle.whiteSpace === "normal" ? "pre-wrap" : "nowrap";
|
|
21229
|
+
measurementRoot.appendChild(clone);
|
|
21230
|
+
document.body.appendChild(measurementRoot);
|
|
21231
|
+
const horizontalPadding = parseFloat(sourceStyle.paddingLeft || "0") + parseFloat(sourceStyle.paddingRight || "0");
|
|
21232
|
+
const horizontalBorder = parseFloat(sourceStyle.borderLeftWidth || "0") + parseFloat(sourceStyle.borderRightWidth || "0");
|
|
21233
|
+
const cloneRectWidth = clone.getBoundingClientRect().width;
|
|
21234
|
+
const cloneScrollWidth = clone.scrollWidth;
|
|
21235
|
+
const sourceScrollWidth = node.scrollWidth;
|
|
21236
|
+
const measuredContentWidth = Math.max(cloneRectWidth, cloneScrollWidth) || sourceScrollWidth;
|
|
21237
|
+
const measured = Math.ceil(measuredContentWidth + horizontalPadding + horizontalBorder);
|
|
21238
|
+
document.body.removeChild(measurementRoot);
|
|
21239
|
+
return measured;
|
|
21240
|
+
}
|
|
21241
|
+
function isNodeOverflowing(node) {
|
|
21242
|
+
const contentNode = node.firstElementChild instanceof HTMLElement ? node.firstElementChild : node;
|
|
21243
|
+
return node.scrollWidth > node.clientWidth + 1 || contentNode.scrollWidth > contentNode.clientWidth + 1;
|
|
21244
|
+
}
|
|
21245
|
+
var AUTO_FIT_BUFFER_PX = 8;
|
|
21095
21246
|
function DataTable({
|
|
21096
21247
|
columns,
|
|
21097
21248
|
data,
|
|
@@ -21115,9 +21266,15 @@ function DataTable({
|
|
|
21115
21266
|
stickyHeader = true,
|
|
21116
21267
|
maxHeight = 500,
|
|
21117
21268
|
useOverlayScrollbar = false,
|
|
21269
|
+
enableHeaderAutoFit = true,
|
|
21118
21270
|
labels
|
|
21119
21271
|
}) {
|
|
21120
21272
|
const t = useSmartTranslations("Common");
|
|
21273
|
+
const [columnWidthOverrides, setColumnWidthOverrides] = React62.useState({});
|
|
21274
|
+
const columnsWithWidthOverrides = React62.useMemo(
|
|
21275
|
+
() => applyColumnWidthOverrides(columns, columnWidthOverrides),
|
|
21276
|
+
[columnWidthOverrides, columns]
|
|
21277
|
+
);
|
|
21121
21278
|
const {
|
|
21122
21279
|
headerAlign,
|
|
21123
21280
|
setHeaderAlign,
|
|
@@ -21134,22 +21291,22 @@ function DataTable({
|
|
|
21134
21291
|
curPageSize,
|
|
21135
21292
|
setCurPageSize
|
|
21136
21293
|
} = useDataTableState({
|
|
21137
|
-
columns,
|
|
21294
|
+
columns: columnsWithWidthOverrides,
|
|
21138
21295
|
page,
|
|
21139
21296
|
pageSize,
|
|
21140
21297
|
size,
|
|
21141
21298
|
storageKey
|
|
21142
21299
|
});
|
|
21143
|
-
|
|
21300
|
+
React62.useEffect(() => {
|
|
21144
21301
|
if (process.env.NODE_ENV === "development") {
|
|
21145
|
-
const warnings = validateColumns(
|
|
21302
|
+
const warnings = validateColumns(columnsWithWidthOverrides);
|
|
21146
21303
|
warnings.forEach((w) => console.warn(`[DataTable] ${w}`));
|
|
21147
21304
|
}
|
|
21148
|
-
}, [
|
|
21305
|
+
}, [columnsWithWidthOverrides]);
|
|
21149
21306
|
const debouncedFilters = useDebounced(filters, 350);
|
|
21150
21307
|
const isServerMode = Boolean(onQueryChange);
|
|
21151
|
-
const hasEmittedQuery =
|
|
21152
|
-
|
|
21308
|
+
const hasEmittedQuery = React62.useRef(false);
|
|
21309
|
+
React62.useEffect(() => {
|
|
21153
21310
|
if (!onQueryChange) return;
|
|
21154
21311
|
if (!hasEmittedQuery.current) {
|
|
21155
21312
|
hasEmittedQuery.current = true;
|
|
@@ -21157,7 +21314,7 @@ function DataTable({
|
|
|
21157
21314
|
}
|
|
21158
21315
|
onQueryChange({ filters: debouncedFilters, sort, page: curPage, pageSize: curPageSize });
|
|
21159
21316
|
}, [debouncedFilters, sort, curPage, curPageSize, onQueryChange]);
|
|
21160
|
-
|
|
21317
|
+
React62.useEffect(() => {
|
|
21161
21318
|
if (process.env.NODE_ENV !== "development" || rowKey) return;
|
|
21162
21319
|
const hasQueryFeatures = columns.some((column) => column.sortable || column.filter) || Boolean(pageSizeOptions?.length) || isServerMode;
|
|
21163
21320
|
if (!hasQueryFeatures) return;
|
|
@@ -21169,7 +21326,7 @@ function DataTable({
|
|
|
21169
21326
|
const headerMinHeightClass = size === "sm" ? "min-h-9" : size === "lg" ? "min-h-11" : "min-h-10";
|
|
21170
21327
|
const sortIconClass = size === "sm" ? "w-3.5 h-3.5" : size === "lg" ? "w-4 h-4" : "w-3.5 h-3.5";
|
|
21171
21328
|
const { visibleColumns, leafColumns, headerRows, totalColumnsWidth, totalItems, displayedData } = useDataTableModel({
|
|
21172
|
-
columns,
|
|
21329
|
+
columns: columnsWithWidthOverrides,
|
|
21173
21330
|
data,
|
|
21174
21331
|
visibleCols,
|
|
21175
21332
|
filters,
|
|
@@ -21185,15 +21342,45 @@ function DataTable({
|
|
|
21185
21342
|
if (typeof rowKey === "function") return String(rowKey(row));
|
|
21186
21343
|
return String(row[rowKey]);
|
|
21187
21344
|
};
|
|
21188
|
-
const viewportRef =
|
|
21345
|
+
const viewportRef = React62.useRef(null);
|
|
21346
|
+
const tableRef = React62.useRef(null);
|
|
21189
21347
|
useOverlayScrollbarTarget(viewportRef, { enabled: useOverlayScrollbar });
|
|
21348
|
+
const autoFitColumn = React62.useCallback((columnKey) => {
|
|
21349
|
+
const tableElement = tableRef.current;
|
|
21350
|
+
if (!tableElement) return;
|
|
21351
|
+
const nodes = Array.from(
|
|
21352
|
+
tableElement.querySelectorAll(`[data-underverse-column-key="${columnKey}"]`)
|
|
21353
|
+
);
|
|
21354
|
+
if (nodes.length === 0) return;
|
|
21355
|
+
const hasOverflow = nodes.some((node) => isNodeOverflowing(node));
|
|
21356
|
+
if (!hasOverflow) return;
|
|
21357
|
+
const measuredWidth = nodes.reduce((maxWidth, node) => {
|
|
21358
|
+
const nextWidth2 = measureNaturalContentWidth(node);
|
|
21359
|
+
return Math.max(maxWidth, nextWidth2);
|
|
21360
|
+
}, 0);
|
|
21361
|
+
const currentRenderedWidth = nodes.reduce((maxWidth, node) => {
|
|
21362
|
+
const nextWidth2 = Math.max(
|
|
21363
|
+
Math.ceil(node.getBoundingClientRect().width || 0),
|
|
21364
|
+
node.offsetWidth || 0,
|
|
21365
|
+
node.clientWidth || 0
|
|
21366
|
+
);
|
|
21367
|
+
return Math.max(maxWidth, nextWidth2);
|
|
21368
|
+
}, 0);
|
|
21369
|
+
if (measuredWidth <= 0) return;
|
|
21370
|
+
if (currentRenderedWidth > 0 && measuredWidth <= currentRenderedWidth + AUTO_FIT_BUFFER_PX) return;
|
|
21371
|
+
const nextWidth = Math.max(80, measuredWidth + AUTO_FIT_BUFFER_PX);
|
|
21372
|
+
setColumnWidthOverrides((prev) => {
|
|
21373
|
+
if (prev[columnKey] === nextWidth) return prev;
|
|
21374
|
+
return { ...prev, [columnKey]: nextWidth };
|
|
21375
|
+
});
|
|
21376
|
+
}, []);
|
|
21190
21377
|
return /* @__PURE__ */ jsxs56("div", { className: cn("space-y-2", className), children: [
|
|
21191
21378
|
/* @__PURE__ */ jsx66(
|
|
21192
21379
|
DataTableToolbar,
|
|
21193
21380
|
{
|
|
21194
21381
|
caption,
|
|
21195
21382
|
toolbar,
|
|
21196
|
-
columns,
|
|
21383
|
+
columns: columnsWithWidthOverrides,
|
|
21197
21384
|
visibleCols,
|
|
21198
21385
|
setVisibleCols,
|
|
21199
21386
|
enableDensityToggle,
|
|
@@ -21223,6 +21410,7 @@ function DataTable({
|
|
|
21223
21410
|
children: /* @__PURE__ */ jsxs56(
|
|
21224
21411
|
Table,
|
|
21225
21412
|
{
|
|
21413
|
+
ref: tableRef,
|
|
21226
21414
|
disableContainer: true,
|
|
21227
21415
|
className: cn(
|
|
21228
21416
|
"table-fixed",
|
|
@@ -21245,6 +21433,8 @@ function DataTable({
|
|
|
21245
21433
|
setCurPage,
|
|
21246
21434
|
setFilters,
|
|
21247
21435
|
setSort,
|
|
21436
|
+
onAutoFitColumn: autoFitColumn,
|
|
21437
|
+
enableHeaderAutoFit,
|
|
21248
21438
|
getStickyHeaderClass,
|
|
21249
21439
|
getStickyHeaderCellStyle,
|
|
21250
21440
|
t
|
|
@@ -21291,10 +21481,10 @@ function DataTable({
|
|
|
21291
21481
|
var DataTable_default = DataTable;
|
|
21292
21482
|
|
|
21293
21483
|
// src/components/Form.tsx
|
|
21294
|
-
import * as
|
|
21484
|
+
import * as React63 from "react";
|
|
21295
21485
|
import { Controller, FormProvider, useFormContext, useForm } from "react-hook-form";
|
|
21296
21486
|
import { jsx as jsx67, jsxs as jsxs57 } from "react/jsx-runtime";
|
|
21297
|
-
var FormConfigContext =
|
|
21487
|
+
var FormConfigContext = React63.createContext({ size: "md" });
|
|
21298
21488
|
var FormWrapper = ({
|
|
21299
21489
|
children,
|
|
21300
21490
|
onSubmit,
|
|
@@ -21307,7 +21497,7 @@ var FormWrapper = ({
|
|
|
21307
21497
|
const methods = useForm({
|
|
21308
21498
|
defaultValues: initialValues
|
|
21309
21499
|
});
|
|
21310
|
-
|
|
21500
|
+
React63.useEffect(() => {
|
|
21311
21501
|
if (initialValues) {
|
|
21312
21502
|
methods.reset(initialValues);
|
|
21313
21503
|
}
|
|
@@ -21316,15 +21506,15 @@ var FormWrapper = ({
|
|
|
21316
21506
|
return /* @__PURE__ */ jsx67(FormProvider, { ...methods, children: /* @__PURE__ */ jsx67(FormConfigContext.Provider, { value: { size }, children: /* @__PURE__ */ jsx67("form", { onSubmit: methods.handleSubmit(onSubmit), className, ...formProps, children }) }) });
|
|
21317
21507
|
};
|
|
21318
21508
|
var Form = FormWrapper;
|
|
21319
|
-
var FormFieldContext =
|
|
21509
|
+
var FormFieldContext = React63.createContext({});
|
|
21320
21510
|
var FormField = ({
|
|
21321
21511
|
...props
|
|
21322
21512
|
}) => {
|
|
21323
21513
|
return /* @__PURE__ */ jsx67(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ jsx67(Controller, { ...props }) });
|
|
21324
21514
|
};
|
|
21325
21515
|
var useFormField = () => {
|
|
21326
|
-
const fieldContext =
|
|
21327
|
-
const itemContext =
|
|
21516
|
+
const fieldContext = React63.useContext(FormFieldContext);
|
|
21517
|
+
const itemContext = React63.useContext(FormItemContext);
|
|
21328
21518
|
const { getFieldState, formState } = useFormContext();
|
|
21329
21519
|
if (!fieldContext) {
|
|
21330
21520
|
throw new Error("useFormField must be used within FormField");
|
|
@@ -21340,16 +21530,16 @@ var useFormField = () => {
|
|
|
21340
21530
|
...fieldState
|
|
21341
21531
|
};
|
|
21342
21532
|
};
|
|
21343
|
-
var FormItemContext =
|
|
21344
|
-
var FormItem =
|
|
21345
|
-
const id =
|
|
21533
|
+
var FormItemContext = React63.createContext({});
|
|
21534
|
+
var FormItem = React63.forwardRef(({ className, ...props }, ref) => {
|
|
21535
|
+
const id = React63.useId();
|
|
21346
21536
|
return /* @__PURE__ */ jsx67(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsx67("div", { ref, className: cn("space-y-2", className), ...props }) });
|
|
21347
21537
|
});
|
|
21348
21538
|
FormItem.displayName = "FormItem";
|
|
21349
|
-
var FormLabel =
|
|
21539
|
+
var FormLabel = React63.forwardRef(
|
|
21350
21540
|
({ className, children, required, ...props }, ref) => {
|
|
21351
21541
|
const { error, formItemId } = useFormField();
|
|
21352
|
-
const config =
|
|
21542
|
+
const config = React63.useContext(FormConfigContext);
|
|
21353
21543
|
const sizeClass = config.size === "sm" ? "text-xs" : config.size === "lg" ? "text-base" : "text-sm";
|
|
21354
21544
|
return /* @__PURE__ */ jsxs57(Label, { ref, className: cn(sizeClass, error && "text-destructive", className), htmlFor: formItemId, ...props, children: [
|
|
21355
21545
|
children,
|
|
@@ -21358,7 +21548,7 @@ var FormLabel = React62.forwardRef(
|
|
|
21358
21548
|
}
|
|
21359
21549
|
);
|
|
21360
21550
|
FormLabel.displayName = "FormLabel";
|
|
21361
|
-
var FormControl =
|
|
21551
|
+
var FormControl = React63.forwardRef(({ ...props }, ref) => {
|
|
21362
21552
|
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
|
21363
21553
|
return /* @__PURE__ */ jsx67(
|
|
21364
21554
|
"div",
|
|
@@ -21372,12 +21562,12 @@ var FormControl = React62.forwardRef(({ ...props }, ref) => {
|
|
|
21372
21562
|
);
|
|
21373
21563
|
});
|
|
21374
21564
|
FormControl.displayName = "FormControl";
|
|
21375
|
-
var FormDescription =
|
|
21565
|
+
var FormDescription = React63.forwardRef(({ className, ...props }, ref) => {
|
|
21376
21566
|
const { formDescriptionId } = useFormField();
|
|
21377
21567
|
return /* @__PURE__ */ jsx67("p", { ref, id: formDescriptionId, className: cn("text-sm text-muted-foreground", className), ...props });
|
|
21378
21568
|
});
|
|
21379
21569
|
FormDescription.displayName = "FormDescription";
|
|
21380
|
-
var FormMessage =
|
|
21570
|
+
var FormMessage = React63.forwardRef(({ className, children, ...props }, ref) => {
|
|
21381
21571
|
const { error, formMessageId } = useFormField();
|
|
21382
21572
|
const body = error ? String(error?.message) : children;
|
|
21383
21573
|
if (!body) {
|
|
@@ -21386,7 +21576,7 @@ var FormMessage = React62.forwardRef(({ className, children, ...props }, ref) =>
|
|
|
21386
21576
|
return /* @__PURE__ */ jsx67("p", { ref, id: formMessageId, className: cn("text-sm font-medium text-destructive", className), ...props, children: body });
|
|
21387
21577
|
});
|
|
21388
21578
|
FormMessage.displayName = "FormMessage";
|
|
21389
|
-
var FormInput =
|
|
21579
|
+
var FormInput = React63.forwardRef(({ name, ...props }, ref) => /* @__PURE__ */ jsx67(FormConfigContext.Consumer, { children: ({ size }) => /* @__PURE__ */ jsx67(
|
|
21390
21580
|
FormField,
|
|
21391
21581
|
{
|
|
21392
21582
|
name,
|
|
@@ -21397,7 +21587,7 @@ var FormInput = React62.forwardRef(({ name, ...props }, ref) => /* @__PURE__ */
|
|
|
21397
21587
|
}
|
|
21398
21588
|
) }));
|
|
21399
21589
|
FormInput.displayName = "FormInput";
|
|
21400
|
-
var FormCheckbox =
|
|
21590
|
+
var FormCheckbox = React63.forwardRef(({ name, ...props }, ref) => /* @__PURE__ */ jsx67(FormConfigContext.Consumer, { children: ({ size }) => /* @__PURE__ */ jsx67(
|
|
21401
21591
|
FormField,
|
|
21402
21592
|
{
|
|
21403
21593
|
name,
|
|
@@ -21421,9 +21611,9 @@ var FormCheckbox = React62.forwardRef(({ name, ...props }, ref) => /* @__PURE__
|
|
|
21421
21611
|
}
|
|
21422
21612
|
) }));
|
|
21423
21613
|
FormCheckbox.displayName = "FormCheckbox";
|
|
21424
|
-
var FormActions =
|
|
21614
|
+
var FormActions = React63.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx67("div", { ref, className: cn("flex gap-2 justify-end", className), ...props }));
|
|
21425
21615
|
FormActions.displayName = "FormActions";
|
|
21426
|
-
var FormSubmitButton =
|
|
21616
|
+
var FormSubmitButton = React63.forwardRef(
|
|
21427
21617
|
({ children, loading: loading2, ...props }, ref) => /* @__PURE__ */ jsx67(FormConfigContext.Consumer, { children: ({ size }) => /* @__PURE__ */ jsx67(Button_default, { ref, type: "submit", size: props.size ?? size, disabled: loading2, ...props, children }) })
|
|
21428
21618
|
);
|
|
21429
21619
|
FormSubmitButton.displayName = "FormSubmitButton";
|
|
@@ -21713,7 +21903,7 @@ var VARIANT_STYLES_ALERT = {
|
|
|
21713
21903
|
};
|
|
21714
21904
|
|
|
21715
21905
|
// ../../lib/i18n/translation-adapter.tsx
|
|
21716
|
-
import * as
|
|
21906
|
+
import * as React65 from "react";
|
|
21717
21907
|
import { jsx as jsx72 } from "react/jsx-runtime";
|
|
21718
21908
|
function isUnresolvedTranslation2(value, namespace, key) {
|
|
21719
21909
|
return value === key || value === `${namespace}.${key}`;
|
|
@@ -21738,7 +21928,7 @@ function useTranslations(namespace) {
|
|
|
21738
21928
|
const nextIntlBridge = useNextIntlBridge();
|
|
21739
21929
|
const internalLocale = useUnderverseLocale();
|
|
21740
21930
|
const internalT = useUnderverseTranslations(namespace);
|
|
21741
|
-
return
|
|
21931
|
+
return React65.useCallback((key, params) => {
|
|
21742
21932
|
if (nextIntlBridge) {
|
|
21743
21933
|
const nextIntlResult = nextIntlBridge.translate(namespace, key, params);
|
|
21744
21934
|
if (nextIntlResult.translated && !isUnresolvedTranslation2(nextIntlResult.translated, namespace, key)) {
|
|
@@ -21763,7 +21953,7 @@ function useLocale2() {
|
|
|
21763
21953
|
}
|
|
21764
21954
|
|
|
21765
21955
|
// src/components/UEditor/UEditor.tsx
|
|
21766
|
-
import
|
|
21956
|
+
import React75, { useEffect as useEffect35, useImperativeHandle as useImperativeHandle3, useMemo as useMemo25, useRef as useRef32 } from "react";
|
|
21767
21957
|
import { useEditor, EditorContent } from "@tiptap/react";
|
|
21768
21958
|
|
|
21769
21959
|
// src/components/UEditor/extensions.ts
|
|
@@ -21803,7 +21993,7 @@ import { common, createLowlight } from "lowlight";
|
|
|
21803
21993
|
import { Extension } from "@tiptap/core";
|
|
21804
21994
|
import Suggestion from "@tiptap/suggestion";
|
|
21805
21995
|
import { ReactRenderer } from "@tiptap/react";
|
|
21806
|
-
import
|
|
21996
|
+
import React66, { forwardRef as forwardRef13, useEffect as useEffect30, useImperativeHandle, useRef as useRef26 } from "react";
|
|
21807
21997
|
import {
|
|
21808
21998
|
FileCode as FileCode2,
|
|
21809
21999
|
Heading1,
|
|
@@ -21846,9 +22036,9 @@ var DEFAULT_MESSAGES = {
|
|
|
21846
22036
|
tableDesc: "Insert a table"
|
|
21847
22037
|
};
|
|
21848
22038
|
function useResettingIndex2(resetToken) {
|
|
21849
|
-
const [state, setState] =
|
|
22039
|
+
const [state, setState] = React66.useState({ resetToken, index: 0 });
|
|
21850
22040
|
const selectedIndex = Object.is(state.resetToken, resetToken) ? state.index : 0;
|
|
21851
|
-
const setSelectedIndex =
|
|
22041
|
+
const setSelectedIndex = React66.useCallback((nextIndex) => {
|
|
21852
22042
|
setState((prev) => {
|
|
21853
22043
|
const prevIndex = Object.is(prev.resetToken, resetToken) ? prev.index : 0;
|
|
21854
22044
|
return {
|
|
@@ -22227,14 +22417,14 @@ import { Extension as Extension3 } from "@tiptap/core";
|
|
|
22227
22417
|
import Suggestion2 from "@tiptap/suggestion";
|
|
22228
22418
|
import { ReactRenderer as ReactRenderer2 } from "@tiptap/react";
|
|
22229
22419
|
import { PluginKey } from "@tiptap/pm/state";
|
|
22230
|
-
import
|
|
22420
|
+
import React67, { forwardRef as forwardRef14, useImperativeHandle as useImperativeHandle2 } from "react";
|
|
22231
22421
|
import { Smile as Smile2 } from "lucide-react";
|
|
22232
22422
|
import tippy2 from "tippy.js";
|
|
22233
22423
|
import { jsx as jsx74, jsxs as jsxs63 } from "react/jsx-runtime";
|
|
22234
22424
|
function useResettingIndex3(resetToken) {
|
|
22235
|
-
const [state, setState] =
|
|
22425
|
+
const [state, setState] = React67.useState({ resetToken, index: 0 });
|
|
22236
22426
|
const selectedIndex = Object.is(state.resetToken, resetToken) ? state.index : 0;
|
|
22237
|
-
const setSelectedIndex =
|
|
22427
|
+
const setSelectedIndex = React67.useCallback((nextIndex) => {
|
|
22238
22428
|
setState((prev) => {
|
|
22239
22429
|
const prevIndex = Object.is(prev.resetToken, resetToken) ? prev.index : 0;
|
|
22240
22430
|
return {
|
|
@@ -22875,7 +23065,7 @@ function buildUEditorExtensions({
|
|
|
22875
23065
|
}
|
|
22876
23066
|
|
|
22877
23067
|
// src/components/UEditor/toolbar.tsx
|
|
22878
|
-
import
|
|
23068
|
+
import React72, { useRef as useRef30, useState as useState44 } from "react";
|
|
22879
23069
|
import {
|
|
22880
23070
|
AlignCenter,
|
|
22881
23071
|
AlignJustify,
|
|
@@ -23362,7 +23552,7 @@ function fileToDataUrl2(file) {
|
|
|
23362
23552
|
reader.readAsDataURL(file);
|
|
23363
23553
|
});
|
|
23364
23554
|
}
|
|
23365
|
-
var ToolbarButton =
|
|
23555
|
+
var ToolbarButton = React72.forwardRef(({ onClick, onMouseDown, active, disabled, children, title, className }, ref) => {
|
|
23366
23556
|
const button = /* @__PURE__ */ jsx79(
|
|
23367
23557
|
"button",
|
|
23368
23558
|
{
|
|
@@ -24580,7 +24770,7 @@ async function prepareUEditorContentForSave({
|
|
|
24580
24770
|
}
|
|
24581
24771
|
|
|
24582
24772
|
// src/components/UEditor/table-controls.tsx
|
|
24583
|
-
import
|
|
24773
|
+
import React74 from "react";
|
|
24584
24774
|
|
|
24585
24775
|
// node_modules/prosemirror-model/dist/index.js
|
|
24586
24776
|
function findDiffStart(a, b, pos) {
|
|
@@ -28907,14 +29097,14 @@ function collectChildren(node) {
|
|
|
28907
29097
|
}
|
|
28908
29098
|
function TableControls({ editor, containerRef }) {
|
|
28909
29099
|
const t = useSmartTranslations("UEditor");
|
|
28910
|
-
const [layout, setLayout] =
|
|
28911
|
-
const [dragPreview, setDragPreview] =
|
|
28912
|
-
const layoutRef =
|
|
28913
|
-
const dragStateRef =
|
|
28914
|
-
|
|
29100
|
+
const [layout, setLayout] = React74.useState(null);
|
|
29101
|
+
const [dragPreview, setDragPreview] = React74.useState(null);
|
|
29102
|
+
const layoutRef = React74.useRef(null);
|
|
29103
|
+
const dragStateRef = React74.useRef(null);
|
|
29104
|
+
React74.useEffect(() => {
|
|
28915
29105
|
layoutRef.current = layout;
|
|
28916
29106
|
}, [layout]);
|
|
28917
|
-
const syncFromCell =
|
|
29107
|
+
const syncFromCell = React74.useCallback((cell) => {
|
|
28918
29108
|
const surface = containerRef.current;
|
|
28919
29109
|
if (!surface || !cell) {
|
|
28920
29110
|
setLayout(null);
|
|
@@ -28922,10 +29112,10 @@ function TableControls({ editor, containerRef }) {
|
|
|
28922
29112
|
}
|
|
28923
29113
|
setLayout(buildLayout(editor, surface, cell));
|
|
28924
29114
|
}, [containerRef, editor]);
|
|
28925
|
-
const syncFromSelection =
|
|
29115
|
+
const syncFromSelection = React74.useCallback(() => {
|
|
28926
29116
|
syncFromCell(getSelectedCell(editor));
|
|
28927
29117
|
}, [editor, syncFromCell]);
|
|
28928
|
-
const refreshCurrentLayout =
|
|
29118
|
+
const refreshCurrentLayout = React74.useCallback(() => {
|
|
28929
29119
|
setLayout((prev) => {
|
|
28930
29120
|
if (!prev) return prev;
|
|
28931
29121
|
const surface = containerRef.current;
|
|
@@ -28935,12 +29125,12 @@ function TableControls({ editor, containerRef }) {
|
|
|
28935
29125
|
return cell ? buildLayout(editor, surface, cell) : null;
|
|
28936
29126
|
});
|
|
28937
29127
|
}, [containerRef, editor]);
|
|
28938
|
-
const clearDrag =
|
|
29128
|
+
const clearDrag = React74.useCallback(() => {
|
|
28939
29129
|
dragStateRef.current = null;
|
|
28940
29130
|
setDragPreview(null);
|
|
28941
29131
|
document.body.style.cursor = "";
|
|
28942
29132
|
}, []);
|
|
28943
|
-
|
|
29133
|
+
React74.useEffect(() => {
|
|
28944
29134
|
const proseMirror = editor.view.dom;
|
|
28945
29135
|
const surface = containerRef.current;
|
|
28946
29136
|
if (!surface) return void 0;
|
|
@@ -28974,7 +29164,7 @@ function TableControls({ editor, containerRef }) {
|
|
|
28974
29164
|
editor.off("update", refreshCurrentLayout);
|
|
28975
29165
|
};
|
|
28976
29166
|
}, [clearDrag, containerRef, editor, refreshCurrentLayout, syncFromCell, syncFromSelection]);
|
|
28977
|
-
const runAtCellPos =
|
|
29167
|
+
const runAtCellPos = React74.useCallback((cellPos, command, options) => {
|
|
28978
29168
|
if (cellPos == null) return false;
|
|
28979
29169
|
focusCell(editor, cellPos);
|
|
28980
29170
|
const result = command(editor.chain().focus(null, { scrollIntoView: false })).run();
|
|
@@ -28983,17 +29173,17 @@ function TableControls({ editor, containerRef }) {
|
|
|
28983
29173
|
}
|
|
28984
29174
|
return result;
|
|
28985
29175
|
}, [editor, syncFromSelection]);
|
|
28986
|
-
const runAtActiveCell =
|
|
29176
|
+
const runAtActiveCell = React74.useCallback((command, options) => {
|
|
28987
29177
|
return runAtCellPos(layoutRef.current?.cellPos ?? null, command, options);
|
|
28988
29178
|
}, [runAtCellPos]);
|
|
28989
|
-
const getCurrentCornerCellPos =
|
|
29179
|
+
const getCurrentCornerCellPos = React74.useCallback(() => {
|
|
28990
29180
|
const activePos = layoutRef.current?.cellPos ?? editor.state.selection.from;
|
|
28991
29181
|
return getLastCellPosFromState(editor, activePos);
|
|
28992
29182
|
}, [editor]);
|
|
28993
|
-
const runAtCornerCell =
|
|
29183
|
+
const runAtCornerCell = React74.useCallback((command, options) => {
|
|
28994
29184
|
return runAtCellPos(getCurrentCornerCellPos(), command, options);
|
|
28995
29185
|
}, [getCurrentCornerCellPos, runAtCellPos]);
|
|
28996
|
-
const replaceTableAtCellPos =
|
|
29186
|
+
const replaceTableAtCellPos = React74.useCallback((cellPos, updateTable) => {
|
|
28997
29187
|
if (cellPos == null) return false;
|
|
28998
29188
|
const tableInfo = findTableInfo(editor, cellPos);
|
|
28999
29189
|
if (!tableInfo) return false;
|
|
@@ -29003,10 +29193,10 @@ function TableControls({ editor, containerRef }) {
|
|
|
29003
29193
|
requestAnimationFrame(syncFromSelection);
|
|
29004
29194
|
return true;
|
|
29005
29195
|
}, [editor, syncFromSelection]);
|
|
29006
|
-
const createEmptyCellNode =
|
|
29196
|
+
const createEmptyCellNode = React74.useCallback((cellNode) => {
|
|
29007
29197
|
return cellNode.type.createAndFill(cellNode.attrs) ?? cellNode;
|
|
29008
29198
|
}, []);
|
|
29009
|
-
const duplicateRowAt =
|
|
29199
|
+
const duplicateRowAt = React74.useCallback((rowIndex, cellPos) => {
|
|
29010
29200
|
return replaceTableAtCellPos(cellPos, (tableNode) => {
|
|
29011
29201
|
const rows = collectChildren(tableNode);
|
|
29012
29202
|
const rowNode = rows[rowIndex];
|
|
@@ -29015,7 +29205,7 @@ function TableControls({ editor, containerRef }) {
|
|
|
29015
29205
|
return tableNode.type.create(tableNode.attrs, rows);
|
|
29016
29206
|
});
|
|
29017
29207
|
}, [replaceTableAtCellPos]);
|
|
29018
|
-
const clearRowAt =
|
|
29208
|
+
const clearRowAt = React74.useCallback((rowIndex, cellPos) => {
|
|
29019
29209
|
return replaceTableAtCellPos(cellPos, (tableNode) => {
|
|
29020
29210
|
const rows = collectChildren(tableNode);
|
|
29021
29211
|
const rowNode = rows[rowIndex];
|
|
@@ -29025,7 +29215,7 @@ function TableControls({ editor, containerRef }) {
|
|
|
29025
29215
|
return tableNode.type.create(tableNode.attrs, rows);
|
|
29026
29216
|
});
|
|
29027
29217
|
}, [createEmptyCellNode, replaceTableAtCellPos]);
|
|
29028
|
-
const duplicateColumnAt =
|
|
29218
|
+
const duplicateColumnAt = React74.useCallback((columnIndex, cellPos) => {
|
|
29029
29219
|
return replaceTableAtCellPos(cellPos, (tableNode) => {
|
|
29030
29220
|
const rows = collectChildren(tableNode).map((rowNode) => {
|
|
29031
29221
|
const cells = collectChildren(rowNode);
|
|
@@ -29037,7 +29227,7 @@ function TableControls({ editor, containerRef }) {
|
|
|
29037
29227
|
return tableNode.type.create(tableNode.attrs, rows);
|
|
29038
29228
|
});
|
|
29039
29229
|
}, [replaceTableAtCellPos]);
|
|
29040
|
-
const clearColumnAt =
|
|
29230
|
+
const clearColumnAt = React74.useCallback((columnIndex, cellPos) => {
|
|
29041
29231
|
return replaceTableAtCellPos(cellPos, (tableNode) => {
|
|
29042
29232
|
const rows = collectChildren(tableNode).map((rowNode) => {
|
|
29043
29233
|
const cells = collectChildren(rowNode);
|
|
@@ -29049,7 +29239,7 @@ function TableControls({ editor, containerRef }) {
|
|
|
29049
29239
|
return tableNode.type.create(tableNode.attrs, rows);
|
|
29050
29240
|
});
|
|
29051
29241
|
}, [createEmptyCellNode, replaceTableAtCellPos]);
|
|
29052
|
-
const expandTableBy =
|
|
29242
|
+
const expandTableBy = React74.useCallback((rows, cols) => {
|
|
29053
29243
|
let ok = true;
|
|
29054
29244
|
for (let index = 0; index < rows; index += 1) {
|
|
29055
29245
|
ok = runAtCornerCell((chain) => chain.addRowAfter(), { sync: false });
|
|
@@ -29063,7 +29253,7 @@ function TableControls({ editor, containerRef }) {
|
|
|
29063
29253
|
return true;
|
|
29064
29254
|
}, [runAtCornerCell, syncFromSelection]);
|
|
29065
29255
|
const canExpandTable = Boolean(layout);
|
|
29066
|
-
|
|
29256
|
+
React74.useEffect(() => {
|
|
29067
29257
|
const handleMouseMove = (event) => {
|
|
29068
29258
|
const dragState = dragStateRef.current;
|
|
29069
29259
|
const activeLayout = layoutRef.current;
|
|
@@ -29150,7 +29340,7 @@ function TableControls({ editor, containerRef }) {
|
|
|
29150
29340
|
window.removeEventListener("blur", clearDrag);
|
|
29151
29341
|
};
|
|
29152
29342
|
}, [clearDrag, containerRef, editor, expandTableBy, syncFromSelection]);
|
|
29153
|
-
const menuItems =
|
|
29343
|
+
const menuItems = React74.useMemo(() => {
|
|
29154
29344
|
if (!layout) return [];
|
|
29155
29345
|
return [
|
|
29156
29346
|
{
|
|
@@ -29203,7 +29393,7 @@ function TableControls({ editor, containerRef }) {
|
|
|
29203
29393
|
}
|
|
29204
29394
|
];
|
|
29205
29395
|
}, [layout, runAtActiveCell, t]);
|
|
29206
|
-
const getRowHandleMenuItems =
|
|
29396
|
+
const getRowHandleMenuItems = React74.useCallback((rowHandle) => [
|
|
29207
29397
|
{
|
|
29208
29398
|
label: t("tableMenu.addRowBefore"),
|
|
29209
29399
|
icon: ArrowUp2,
|
|
@@ -29231,7 +29421,7 @@ function TableControls({ editor, containerRef }) {
|
|
|
29231
29421
|
destructive: true
|
|
29232
29422
|
}
|
|
29233
29423
|
], [clearRowAt, duplicateRowAt, runAtCellPos, t]);
|
|
29234
|
-
const getColumnHandleMenuItems =
|
|
29424
|
+
const getColumnHandleMenuItems = React74.useCallback((columnHandle) => [
|
|
29235
29425
|
{
|
|
29236
29426
|
label: t("tableMenu.addColumnBefore"),
|
|
29237
29427
|
icon: ArrowLeft2,
|
|
@@ -29579,7 +29769,7 @@ function getRelativeBoundaryMetrics(surface, table, row, cell) {
|
|
|
29579
29769
|
columnRight: cellRect.right - surfaceRect.left + surface.scrollLeft
|
|
29580
29770
|
};
|
|
29581
29771
|
}
|
|
29582
|
-
var UEditor =
|
|
29772
|
+
var UEditor = React75.forwardRef(({
|
|
29583
29773
|
content = "",
|
|
29584
29774
|
onChange,
|
|
29585
29775
|
onHtmlChange,
|
|
@@ -29607,32 +29797,32 @@ var UEditor = React74.forwardRef(({
|
|
|
29607
29797
|
const tableColumnGuideRef = useRef32(null);
|
|
29608
29798
|
const tableRowGuideRef = useRef32(null);
|
|
29609
29799
|
const rowResizeStateRef = useRef32(null);
|
|
29610
|
-
const setEditorResizeCursor =
|
|
29800
|
+
const setEditorResizeCursor = React75.useCallback((cursor) => {
|
|
29611
29801
|
const proseMirror = editorContentRef.current?.querySelector(".ProseMirror");
|
|
29612
29802
|
if (proseMirror) {
|
|
29613
29803
|
proseMirror.style.cursor = cursor;
|
|
29614
29804
|
}
|
|
29615
29805
|
}, []);
|
|
29616
|
-
const hideColumnGuide =
|
|
29806
|
+
const hideColumnGuide = React75.useCallback(() => {
|
|
29617
29807
|
editorContentRef.current?.classList.remove("resize-cursor");
|
|
29618
29808
|
const guide = tableColumnGuideRef.current;
|
|
29619
29809
|
if (guide) {
|
|
29620
29810
|
guide.style.opacity = "0";
|
|
29621
29811
|
}
|
|
29622
29812
|
}, []);
|
|
29623
|
-
const hideRowGuide =
|
|
29813
|
+
const hideRowGuide = React75.useCallback(() => {
|
|
29624
29814
|
editorContentRef.current?.classList.remove("resize-row-cursor");
|
|
29625
29815
|
const guide = tableRowGuideRef.current;
|
|
29626
29816
|
if (guide) {
|
|
29627
29817
|
guide.style.opacity = "0";
|
|
29628
29818
|
}
|
|
29629
29819
|
}, []);
|
|
29630
|
-
const clearAllTableResizeHover =
|
|
29820
|
+
const clearAllTableResizeHover = React75.useCallback(() => {
|
|
29631
29821
|
setEditorResizeCursor("");
|
|
29632
29822
|
hideColumnGuide();
|
|
29633
29823
|
hideRowGuide();
|
|
29634
29824
|
}, [hideColumnGuide, hideRowGuide, setEditorResizeCursor]);
|
|
29635
|
-
const showColumnGuide =
|
|
29825
|
+
const showColumnGuide = React75.useCallback((table, row, cell) => {
|
|
29636
29826
|
const surface = editorContentRef.current;
|
|
29637
29827
|
const guide = tableColumnGuideRef.current;
|
|
29638
29828
|
if (!surface || !guide) return;
|
|
@@ -29645,7 +29835,7 @@ var UEditor = React74.forwardRef(({
|
|
|
29645
29835
|
surface.classList.add("resize-cursor");
|
|
29646
29836
|
setEditorResizeCursor("col-resize");
|
|
29647
29837
|
}, [setEditorResizeCursor]);
|
|
29648
|
-
const showRowGuide =
|
|
29838
|
+
const showRowGuide = React75.useCallback((table, row, cell) => {
|
|
29649
29839
|
const surface = editorContentRef.current;
|
|
29650
29840
|
const guide = tableRowGuideRef.current;
|
|
29651
29841
|
if (!surface || !guide) return;
|