@dreamtree-org/twreact-ui 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -10
- package/ai-skills/dreamtree-ui.md +71 -12
- package/dist/ai-schema.json +452 -17
- package/dist/components/core/Accordion.d.ts.map +1 -1
- package/dist/components/core/Button.d.ts.map +1 -1
- package/dist/components/core/Checkbox.d.ts.map +1 -1
- package/dist/components/core/ColorPicker.d.ts.map +1 -1
- package/dist/components/core/DatePicker.d.ts.map +1 -1
- package/dist/components/core/DateRangePicker.d.ts.map +1 -1
- package/dist/components/core/Form.d.ts.map +1 -1
- package/dist/components/core/Input.d.ts.map +1 -1
- package/dist/components/core/LocationPicker.d.ts.map +1 -1
- package/dist/components/core/Popover.d.ts +4 -0
- package/dist/components/core/Popover.d.ts.map +1 -0
- package/dist/components/core/PriceRangePicker.d.ts.map +1 -1
- package/dist/components/core/ProgressBar.d.ts.map +1 -1
- package/dist/components/core/Radio.d.ts.map +1 -1
- package/dist/components/core/Rate.d.ts.map +1 -1
- package/dist/components/core/Select.d.ts.map +1 -1
- package/dist/components/core/Skeleton.d.ts.map +1 -1
- package/dist/components/core/Slider.d.ts +4 -0
- package/dist/components/core/Slider.d.ts.map +1 -0
- package/dist/components/core/SpeechToText.d.ts.map +1 -1
- package/dist/components/core/Switch.d.ts.map +1 -1
- package/dist/components/core/Table/ActionMenu.d.ts.map +1 -1
- package/dist/components/core/Table/ColumnMenu.d.ts +2 -1
- package/dist/components/core/Table/ColumnMenu.d.ts.map +1 -1
- package/dist/components/core/Table/MobileCard.d.ts +2 -2
- package/dist/components/core/Table/MobileCard.d.ts.map +1 -1
- package/dist/components/core/Table/Table.d.ts.map +1 -1
- package/dist/components/core/Table/TableRow.d.ts +4 -2
- package/dist/components/core/Table/TableRow.d.ts.map +1 -1
- package/dist/components/core/Tabs.d.ts.map +1 -1
- package/dist/components/core/Textarea.d.ts +4 -0
- package/dist/components/core/Textarea.d.ts.map +1 -0
- package/dist/components/core/ThreeDotPopover.d.ts.map +1 -1
- package/dist/components/core/Tooltip.d.ts.map +1 -1
- package/dist/components/feedback/Dialog.d.ts.map +1 -1
- package/dist/components/feedback/Drawer.d.ts +4 -0
- package/dist/components/feedback/Drawer.d.ts.map +1 -0
- package/dist/components/feedback/Toast.d.ts +14 -5
- package/dist/components/feedback/Toast.d.ts.map +1 -1
- package/dist/components/feedback/Tour.d.ts +4 -0
- package/dist/components/feedback/Tour.d.ts.map +1 -0
- package/dist/components/feedback/TourSpotlight.d.ts +9 -0
- package/dist/components/feedback/TourSpotlight.d.ts.map +1 -0
- package/dist/components/navigation/Breadcrumbs.d.ts.map +1 -1
- package/dist/components/navigation/FootNav.d.ts.map +1 -1
- package/dist/components/navigation/Navbar.d.ts.map +1 -1
- package/dist/components/navigation/Sidebar.d.ts +8 -2
- package/dist/components/navigation/Sidebar.d.ts.map +1 -1
- package/dist/components/utility/Badge.d.ts.map +1 -1
- package/dist/components/utility/FileUpload.d.ts.map +1 -1
- package/dist/components/utility/Sortable.d.ts +4 -0
- package/dist/components/utility/Sortable.d.ts.map +1 -0
- package/dist/esm/_vendor/object-assign/index.js +99 -0
- package/dist/esm/_vendor/prop-types/_vendor/react-is/cjs/react-is.development.js +190 -0
- package/dist/esm/_vendor/prop-types/_vendor/react-is/cjs/react-is.production.min.js +26 -0
- package/dist/esm/_vendor/prop-types/_vendor/react-is/index.js +19 -0
- package/dist/esm/_vendor/prop-types/checkPropTypes.js +115 -0
- package/dist/esm/_vendor/prop-types/factoryWithThrowingShims.js +74 -0
- package/dist/esm/_vendor/prop-types/factoryWithTypeCheckers.js +625 -0
- package/dist/esm/_vendor/prop-types/index.js +30 -0
- package/dist/esm/_vendor/prop-types/lib/ReactPropTypesSecret.js +21 -0
- package/dist/esm/_vendor/prop-types/lib/has.js +11 -0
- package/dist/esm/_virtual/_commonjsHelpers.js +5 -0
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +329 -0
- package/dist/esm/_virtual/index.js +3 -0
- package/dist/esm/_virtual/index2.js +3 -0
- package/dist/esm/_virtual/react-is.development.js +3 -0
- package/dist/esm/_virtual/react-is.production.min.js +3 -0
- package/dist/esm/components/blocks/AppShell.js +205 -0
- package/dist/esm/components/blocks/ConfirmDialog.js +57 -0
- package/dist/esm/components/blocks/EmptyState.js +44 -0
- package/dist/esm/components/blocks/ErrorState.js +53 -0
- package/dist/esm/components/blocks/LoadingState.js +134 -0
- package/dist/esm/components/blocks/PageHeader.js +51 -0
- package/dist/esm/components/blocks/StatCard.js +79 -0
- package/dist/esm/components/blocks/StatusPill.js +55 -0
- package/dist/esm/components/core/Accordion.js +260 -0
- package/dist/esm/components/core/Button.js +59 -0
- package/dist/esm/components/core/Checkbox.js +188 -0
- package/dist/esm/components/core/ColorPicker.js +348 -0
- package/dist/esm/components/core/DatePicker.js +436 -0
- package/dist/esm/components/core/DateRangePicker.js +494 -0
- package/dist/esm/components/core/Form.js +522 -0
- package/dist/esm/components/core/Input.js +179 -0
- package/dist/esm/components/core/Loader.js +141 -0
- package/dist/esm/components/core/LocationPicker.js +161 -0
- package/dist/esm/components/core/Popover.js +171 -0
- package/dist/esm/components/core/PriceRangePicker.js +376 -0
- package/dist/esm/components/core/ProgressBar.js +152 -0
- package/dist/esm/components/core/Radio.js +156 -0
- package/dist/esm/components/core/Rate.js +197 -0
- package/dist/esm/components/core/RoundedTag.js +118 -0
- package/dist/esm/components/core/Select.js +857 -0
- package/dist/esm/components/core/Skeleton.js +100 -0
- package/dist/esm/components/core/Slider.js +134 -0
- package/dist/esm/components/core/SpeechToText.js +226 -0
- package/dist/esm/components/core/Switch.js +207 -0
- package/dist/esm/components/core/Table/ActionMenu.js +251 -0
- package/dist/esm/components/core/Table/ColumnMenu.js +55 -0
- package/dist/esm/components/core/Table/FieldInput.js +157 -0
- package/dist/esm/components/core/Table/MobileCard.js +187 -0
- package/dist/esm/components/core/Table/MobileFilters.js +72 -0
- package/dist/esm/components/core/Table/Pagination.js +157 -0
- package/dist/esm/components/core/Table/Table.js +1533 -0
- package/dist/esm/components/core/Table/TableRow.js +254 -0
- package/dist/esm/components/core/Table/constants.js +35 -0
- package/dist/esm/components/core/Table/helpers.js +124 -0
- package/dist/esm/components/core/Table/useClickOutside.js +26 -0
- package/dist/esm/components/core/Tabs.js +289 -0
- package/dist/esm/components/core/TextToSpeech.js +52 -0
- package/dist/esm/components/core/Textarea.js +125 -0
- package/dist/esm/components/core/ThreeDotPopover.js +160 -0
- package/dist/esm/components/core/Tooltip.js +372 -0
- package/dist/esm/components/feedback/Alert.js +96 -0
- package/dist/esm/components/feedback/Dialog.js +200 -0
- package/dist/esm/components/feedback/Drawer.js +171 -0
- package/dist/esm/components/feedback/Toast.js +362 -0
- package/dist/esm/components/feedback/Tour.js +214 -0
- package/dist/esm/components/feedback/TourSpotlight.js +71 -0
- package/dist/esm/components/navigation/Breadcrumbs.js +75 -0
- package/dist/esm/components/navigation/Dropdown.js +53 -0
- package/dist/esm/components/navigation/FootNav.js +51 -0
- package/dist/esm/components/navigation/Navbar.js +437 -0
- package/dist/esm/components/navigation/Sidebar.js +567 -0
- package/dist/esm/components/utility/Avatar.js +89 -0
- package/dist/esm/components/utility/Badge.js +47 -0
- package/dist/esm/components/utility/Card.js +85 -0
- package/dist/esm/components/utility/Carousel.js +97 -0
- package/dist/esm/components/utility/Condition.js +9 -0
- package/dist/esm/components/utility/FileUpload.js +177 -0
- package/dist/esm/components/utility/Pagination.js +111 -0
- package/dist/esm/components/utility/Sortable.js +190 -0
- package/dist/esm/components/utility/Stepper.js +101 -0
- package/dist/esm/hooks/useApi.js +169 -0
- package/dist/esm/hooks/useControllableState.js +32 -0
- package/dist/esm/hooks/useFocusTrap.js +85 -0
- package/dist/esm/hooks/useLatestRef.js +20 -0
- package/dist/esm/hooks/useMixins.js +100 -0
- package/dist/esm/hooks/useScrollLock.js +26 -0
- package/dist/esm/hooks/useSliderValues.js +135 -0
- package/dist/esm/hooks/useSortable.js +188 -0
- package/dist/esm/hooks/useTheme.js +53 -0
- package/dist/esm/hooks/useTourTarget.js +92 -0
- package/dist/esm/index.js +65 -0
- package/dist/esm/store/index.js +26 -0
- package/dist/esm/store/store.js +107 -0
- package/dist/esm/store/storeSlice.js +45 -0
- package/dist/esm/utils/cn.js +11 -0
- package/dist/esm/utils/emitter.js +169 -0
- package/dist/esm/utils/helpers.js +161 -0
- package/dist/esm/utils/position.js +134 -0
- package/dist/hooks/useApi.d.ts +2 -1
- package/dist/hooks/useApi.d.ts.map +1 -1
- package/dist/hooks/useControllableState.d.ts +11 -0
- package/dist/hooks/useControllableState.d.ts.map +1 -0
- package/dist/hooks/useFocusTrap.d.ts +15 -0
- package/dist/hooks/useFocusTrap.d.ts.map +1 -0
- package/dist/hooks/useLatestRef.d.ts +8 -0
- package/dist/hooks/useLatestRef.d.ts.map +1 -0
- package/dist/hooks/useMixins.d.ts.map +1 -1
- package/dist/hooks/useScrollLock.d.ts +2 -0
- package/dist/hooks/useScrollLock.d.ts.map +1 -0
- package/dist/hooks/useSliderValues.d.ts +43 -0
- package/dist/hooks/useSliderValues.d.ts.map +1 -0
- package/dist/hooks/useSortable.d.ts +32 -0
- package/dist/hooks/useSortable.d.ts.map +1 -0
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/hooks/useTourTarget.d.ts +15 -0
- package/dist/hooks/useTourTarget.d.ts.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.esm.css +1 -1
- package/dist/index.esm.js +4800 -2212
- package/dist/index.js +4805 -2210
- package/dist/types/index.d.ts +193 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/position.d.ts +30 -0
- package/dist/utils/position.d.ts.map +1 -0
- package/doc/README.md +7 -1
- package/mcp/catalog.snapshot.json +911 -212
- package/package.json +14 -2
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { objectSpread2 as _objectSpread2, defineProperty as _defineProperty } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
|
3
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { cn } from '../../../utils/cn.js';
|
|
6
|
+
import { Trash2, MoreVertical } from 'lucide-react';
|
|
7
|
+
import ActionMenu from './ActionMenu.js';
|
|
8
|
+
import { getRowKey, resolveActions, rowHasDetails, getActionLabelText } from './helpers.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Desktop table row component
|
|
12
|
+
*/
|
|
13
|
+
function TableRow(_ref) {
|
|
14
|
+
var _theme$accentColor, _theme$rowHover;
|
|
15
|
+
var row = _ref.row,
|
|
16
|
+
rowIndexInPage = _ref.rowIndexInPage,
|
|
17
|
+
startIndex = _ref.startIndex,
|
|
18
|
+
selectedRows = _ref.selectedRows,
|
|
19
|
+
expandedRows = _ref.expandedRows,
|
|
20
|
+
rowClass = _ref.rowClass,
|
|
21
|
+
stripedRows = _ref.stripedRows,
|
|
22
|
+
theme = _ref.theme,
|
|
23
|
+
onRowClick = _ref.onRowClick,
|
|
24
|
+
hasDetails = _ref.hasDetails,
|
|
25
|
+
hasDetailsColumn = _ref.hasDetailsColumn,
|
|
26
|
+
showSerial = _ref.showSerial,
|
|
27
|
+
selectable = _ref.selectable,
|
|
28
|
+
visibleColumns = _ref.visibleColumns,
|
|
29
|
+
cellClass = _ref.cellClass,
|
|
30
|
+
withAction = _ref.withAction,
|
|
31
|
+
visibleCount = _ref.visibleCount,
|
|
32
|
+
DetailsComponent = _ref.DetailsComponent,
|
|
33
|
+
actionsToUse = _ref.actionsToUse,
|
|
34
|
+
activeActionRowKey = _ref.activeActionRowKey,
|
|
35
|
+
activeAnchorEl = _ref.activeAnchorEl,
|
|
36
|
+
registerActionButton = _ref.registerActionButton,
|
|
37
|
+
actionMenuRef = _ref.actionMenuRef,
|
|
38
|
+
toggleExpandRow = _ref.toggleExpandRow,
|
|
39
|
+
handleSelectRow = _ref.handleSelectRow,
|
|
40
|
+
toggleActions = _ref.toggleActions,
|
|
41
|
+
handleOnAction = _ref.handleOnAction,
|
|
42
|
+
closeActionMenu = _ref.closeActionMenu,
|
|
43
|
+
renderCell = _ref.renderCell,
|
|
44
|
+
_ref$interactive = _ref.interactive,
|
|
45
|
+
interactive = _ref$interactive === void 0 ? false : _ref$interactive,
|
|
46
|
+
_ref$activeCell = _ref.activeCell,
|
|
47
|
+
activeCell = _ref$activeCell === void 0 ? null : _ref$activeCell,
|
|
48
|
+
_ref$editingCell = _ref.editingCell,
|
|
49
|
+
editingCell = _ref$editingCell === void 0 ? null : _ref$editingCell,
|
|
50
|
+
_ref$onCellClick = _ref.onCellClick,
|
|
51
|
+
onCellClick = _ref$onCellClick === void 0 ? null : _ref$onCellClick,
|
|
52
|
+
_ref$onCellDoubleClic = _ref.onCellDoubleClick,
|
|
53
|
+
onCellDoubleClick = _ref$onCellDoubleClic === void 0 ? null : _ref$onCellDoubleClic,
|
|
54
|
+
_ref$renderInteractiv = _ref.renderInteractiveCellInput,
|
|
55
|
+
renderInteractiveCellInput = _ref$renderInteractiv === void 0 ? null : _ref$renderInteractiv,
|
|
56
|
+
_ref$invalidCellSet = _ref.invalidCellSet,
|
|
57
|
+
invalidCellSet = _ref$invalidCellSet === void 0 ? null : _ref$invalidCellSet,
|
|
58
|
+
_ref$pendingEdits = _ref.pendingEdits,
|
|
59
|
+
pendingEdits = _ref$pendingEdits === void 0 ? null : _ref$pendingEdits,
|
|
60
|
+
_ref$isNewRow = _ref.isNewRow,
|
|
61
|
+
isNewRow = _ref$isNewRow === void 0 ? false : _ref$isNewRow,
|
|
62
|
+
_ref$onDeleteNewRow = _ref.onDeleteNewRow,
|
|
63
|
+
onDeleteNewRow = _ref$onDeleteNewRow === void 0 ? null : _ref$onDeleteNewRow,
|
|
64
|
+
_ref$showColumnPicker = _ref.showColumnPicker,
|
|
65
|
+
showColumnPicker = _ref$showColumnPicker === void 0 ? true : _ref$showColumnPicker,
|
|
66
|
+
_ref$wrapCells = _ref.wrapCells,
|
|
67
|
+
wrapCells = _ref$wrapCells === void 0 ? false : _ref$wrapCells;
|
|
68
|
+
var globalIndex = startIndex + rowIndexInPage;
|
|
69
|
+
var key = getRowKey(row, globalIndex);
|
|
70
|
+
var actionCellKey = "actions-".concat(key);
|
|
71
|
+
var isSelected = Boolean(selectedRows === null || selectedRows === void 0 ? void 0 : selectedRows.has(key));
|
|
72
|
+
var isExpanded = Boolean(expandedRows === null || expandedRows === void 0 ? void 0 : expandedRows.has(key));
|
|
73
|
+
// Only this row's actions are resolved. Memoized so that opening one row's
|
|
74
|
+
// menu (which re-renders every row) does not re-invoke a function-valued
|
|
75
|
+
// `actions` prop for all the other rows.
|
|
76
|
+
var _React$useMemo = React.useMemo(function () {
|
|
77
|
+
return resolveActions(actionsToUse, row, globalIndex);
|
|
78
|
+
}, [actionsToUse, row, globalIndex]),
|
|
79
|
+
inlineActions = _React$useMemo.inlineActions,
|
|
80
|
+
menuActions = _React$useMemo.menuActions;
|
|
81
|
+
var showDetailsToggle = rowHasDetails(hasDetails, row, globalIndex);
|
|
82
|
+
var extraRowClass = typeof rowClass === "function" ? rowClass({
|
|
83
|
+
row: row,
|
|
84
|
+
rowIndex: globalIndex
|
|
85
|
+
}) : "";
|
|
86
|
+
var safeExtraRowClass = typeof extraRowClass === "string" ? extraRowClass.trim() : "";
|
|
87
|
+
var stripeColors = theme === null || theme === void 0 ? void 0 : theme.stripedColors;
|
|
88
|
+
var stripeBg = stripedRows && !isSelected && Array.isArray(stripeColors) && stripeColors.length > 0 ? stripeColors[globalIndex % stripeColors.length] : undefined;
|
|
89
|
+
var rowKey = isNewRow ? row._key : key;
|
|
90
|
+
var isRowActive = interactive && (activeCell === null || activeCell === void 0 ? void 0 : activeCell.rowKey) === rowKey;
|
|
91
|
+
var effectiveRow = React.useMemo(function () {
|
|
92
|
+
if (!interactive || !pendingEdits || !pendingEdits[rowKey]) return row;
|
|
93
|
+
return _objectSpread2(_objectSpread2({}, row), pendingEdits[rowKey]);
|
|
94
|
+
}, [interactive, pendingEdits, rowKey, row]);
|
|
95
|
+
return jsxs(React.Fragment, {
|
|
96
|
+
children: [jsxs("tr", {
|
|
97
|
+
style: stripeBg ? {
|
|
98
|
+
backgroundColor: stripeBg
|
|
99
|
+
} : undefined,
|
|
100
|
+
className: cn(theme !== null && theme !== void 0 && theme.rowHover ? ["hover:" + theme.rowHover] : [], {
|
|
101
|
+
"cursor-pointer": !!onRowClick,
|
|
102
|
+
"bg-primary-50": isSelected,
|
|
103
|
+
"bg-primary-50/20": isRowActive && !isSelected,
|
|
104
|
+
"bg-amber-50/40": isNewRow && !isSelected && !isRowActive
|
|
105
|
+
}, safeExtraRowClass),
|
|
106
|
+
onClick: function onClick() {
|
|
107
|
+
return onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(effectiveRow, globalIndex);
|
|
108
|
+
},
|
|
109
|
+
children: [hasDetailsColumn && jsx("td", {
|
|
110
|
+
className: "px-4 py-4 text-sm",
|
|
111
|
+
children: showDetailsToggle && jsx("button", {
|
|
112
|
+
type: "button",
|
|
113
|
+
onClick: function onClick(e) {
|
|
114
|
+
e.stopPropagation();
|
|
115
|
+
toggleExpandRow(effectiveRow, rowIndexInPage);
|
|
116
|
+
},
|
|
117
|
+
"aria-expanded": isExpanded,
|
|
118
|
+
"aria-label": isExpanded ? "Collapse row details" : "Expand row details",
|
|
119
|
+
className: "p-1 rounded hover:bg-gray-100",
|
|
120
|
+
children: isExpanded ? "▾" : "▸"
|
|
121
|
+
})
|
|
122
|
+
}), showSerial && jsx("td", {
|
|
123
|
+
className: "px-4 py-4 whitespace-nowrap text-sm",
|
|
124
|
+
children: globalIndex + 1
|
|
125
|
+
}), selectable && jsx("td", {
|
|
126
|
+
className: "px-6 py-4",
|
|
127
|
+
onClick: function onClick(e) {
|
|
128
|
+
return e.stopPropagation();
|
|
129
|
+
},
|
|
130
|
+
children: jsx("input", {
|
|
131
|
+
type: "checkbox",
|
|
132
|
+
className: "rounded border-gray-300",
|
|
133
|
+
checked: isSelected,
|
|
134
|
+
onChange: function onChange() {
|
|
135
|
+
return handleSelectRow(effectiveRow, rowIndexInPage);
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
}), visibleColumns.map(function (column, columnIndex) {
|
|
139
|
+
var extraCellClass = typeof cellClass === "function" ? cellClass({
|
|
140
|
+
row: effectiveRow,
|
|
141
|
+
rowIndex: globalIndex,
|
|
142
|
+
column: column,
|
|
143
|
+
columnIndex: columnIndex
|
|
144
|
+
}) : "";
|
|
145
|
+
var safeExtraCellClass = typeof extraCellClass === "string" ? extraCellClass.trim() : "";
|
|
146
|
+
var isCellActive = interactive && (activeCell === null || activeCell === void 0 ? void 0 : activeCell.rowKey) === rowKey && (activeCell === null || activeCell === void 0 ? void 0 : activeCell.colKey) === column.key;
|
|
147
|
+
var isCellEditing = interactive && (editingCell === null || editingCell === void 0 ? void 0 : editingCell.rowKey) === rowKey && (editingCell === null || editingCell === void 0 ? void 0 : editingCell.colKey) === column.key;
|
|
148
|
+
var isCellInvalid = interactive && (invalidCellSet === null || invalidCellSet === void 0 ? void 0 : invalidCellSet.has("".concat(rowKey, ":").concat(column.key)));
|
|
149
|
+
// Per-column `wrap` wins over the table-level `wrapCells` default.
|
|
150
|
+
var wrapCell = typeof column.wrap === "boolean" ? column.wrap : wrapCells;
|
|
151
|
+
return jsx("td", {
|
|
152
|
+
title: isCellInvalid ? "Field \"".concat(column.label || column.key, "\" is required or invalid") : undefined,
|
|
153
|
+
className: cn("px-6 py-4 text-sm transition-all", wrapCell ? "whitespace-normal break-words" : "whitespace-nowrap", {
|
|
154
|
+
"ring-2 ring-error-500 ring-inset bg-error-50/40 relative z-10": isCellInvalid && !isCellEditing,
|
|
155
|
+
"ring-2 ring-error-600 ring-inset bg-white p-1 z-20 relative": isCellEditing && isCellInvalid,
|
|
156
|
+
"ring-2 ring-primary-500 ring-inset bg-primary-50/50 relative z-10": isCellActive && !isCellEditing && !isCellInvalid,
|
|
157
|
+
"ring-2 ring-primary-600 ring-inset bg-white p-1 z-20 relative": isCellEditing && !isCellInvalid
|
|
158
|
+
}, safeExtraCellClass),
|
|
159
|
+
onClick: function onClick() {
|
|
160
|
+
if (interactive && onCellClick) {
|
|
161
|
+
onCellClick(rowKey, column.key, effectiveRow, column, globalIndex);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
onDoubleClick: function onDoubleClick() {
|
|
165
|
+
if (interactive && onCellDoubleClick && column.editable !== false) {
|
|
166
|
+
onCellDoubleClick(rowKey, column.key, effectiveRow, column, globalIndex);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
children: isCellEditing && renderInteractiveCellInput ? renderInteractiveCellInput(column, effectiveRow, globalIndex, rowKey) : renderCell(column, effectiveRow, globalIndex)
|
|
170
|
+
}, column.key);
|
|
171
|
+
}), showColumnPicker && jsx("td", {
|
|
172
|
+
className: "px-4 py-4"
|
|
173
|
+
}), withAction && jsx("td", {
|
|
174
|
+
className: "px-4 py-4 text-sm text-right",
|
|
175
|
+
onClick: function onClick(e) {
|
|
176
|
+
return e.stopPropagation();
|
|
177
|
+
},
|
|
178
|
+
children: jsxs("div", {
|
|
179
|
+
className: "flex items-center justify-end gap-1",
|
|
180
|
+
children: [isNewRow && onDeleteNewRow && jsx("button", {
|
|
181
|
+
type: "button",
|
|
182
|
+
onClick: function onClick(e) {
|
|
183
|
+
e.stopPropagation();
|
|
184
|
+
onDeleteNewRow(row._key || key);
|
|
185
|
+
},
|
|
186
|
+
className: "p-1.5 text-error-600 hover:text-error-800 hover:bg-error-50 rounded",
|
|
187
|
+
title: "Delete new row",
|
|
188
|
+
children: jsx(Trash2, {
|
|
189
|
+
className: "w-4 h-4"
|
|
190
|
+
})
|
|
191
|
+
}), inlineActions.map(function (action, idx) {
|
|
192
|
+
var _action$icon, _action$name;
|
|
193
|
+
var actionLabel = getActionLabelText(action);
|
|
194
|
+
return jsx("button", {
|
|
195
|
+
type: "button",
|
|
196
|
+
title: actionLabel,
|
|
197
|
+
"aria-label": actionLabel,
|
|
198
|
+
disabled: action.disabled,
|
|
199
|
+
onClick: function onClick(e) {
|
|
200
|
+
e.stopPropagation();
|
|
201
|
+
if (action.disabled) return;
|
|
202
|
+
handleOnAction(action, row);
|
|
203
|
+
},
|
|
204
|
+
className: cn("p-1 rounded", action.disabled ? "opacity-50 cursor-not-allowed" : "hover:bg-gray-100"),
|
|
205
|
+
children: action.render ? action.render(row) : (_action$icon = action.icon) !== null && _action$icon !== void 0 ? _action$icon : jsx("span", {
|
|
206
|
+
className: "text-xs",
|
|
207
|
+
children: actionLabel
|
|
208
|
+
})
|
|
209
|
+
}, (_action$name = action.name) !== null && _action$name !== void 0 ? _action$name : "inline-".concat(idx));
|
|
210
|
+
}), menuActions.length > 0 && jsxs("div", {
|
|
211
|
+
className: "relative inline-block",
|
|
212
|
+
children: [jsx("button", {
|
|
213
|
+
ref: function ref(el) {
|
|
214
|
+
return registerActionButton === null || registerActionButton === void 0 ? void 0 : registerActionButton(actionCellKey, el);
|
|
215
|
+
},
|
|
216
|
+
onClick: function onClick(e) {
|
|
217
|
+
return toggleActions(e, actionCellKey, row);
|
|
218
|
+
},
|
|
219
|
+
"aria-expanded": activeActionRowKey === actionCellKey,
|
|
220
|
+
className: "p-1 rounded hover:bg-gray-100",
|
|
221
|
+
title: "Actions",
|
|
222
|
+
children: jsx(MoreVertical, {
|
|
223
|
+
className: "h-4 w-4"
|
|
224
|
+
})
|
|
225
|
+
}), activeActionRowKey === actionCellKey && jsx(ActionMenu, {
|
|
226
|
+
actions: menuActions,
|
|
227
|
+
row: row,
|
|
228
|
+
onAction: function onAction(action) {
|
|
229
|
+
return handleOnAction(action, row);
|
|
230
|
+
},
|
|
231
|
+
menuRef: actionMenuRef,
|
|
232
|
+
anchorEl: activeAnchorEl,
|
|
233
|
+
onClose: closeActionMenu,
|
|
234
|
+
theme: theme
|
|
235
|
+
})]
|
|
236
|
+
})]
|
|
237
|
+
})
|
|
238
|
+
})]
|
|
239
|
+
}), showDetailsToggle && isExpanded && DetailsComponent && jsx("tr", {
|
|
240
|
+
children: jsx("td", {
|
|
241
|
+
colSpan: visibleCount,
|
|
242
|
+
className: cn(_defineProperty(_defineProperty({
|
|
243
|
+
"px-6 py-4": true
|
|
244
|
+
}, (_theme$accentColor = theme === null || theme === void 0 ? void 0 : theme.accentColor) !== null && _theme$accentColor !== void 0 ? _theme$accentColor : "bg-gray-50", true), (_theme$rowHover = theme === null || theme === void 0 ? void 0 : theme.rowHover) !== null && _theme$rowHover !== void 0 ? _theme$rowHover : "bg-gray-50", true)),
|
|
245
|
+
children: jsx(DetailsComponent, {
|
|
246
|
+
row: row,
|
|
247
|
+
index: globalIndex
|
|
248
|
+
})
|
|
249
|
+
})
|
|
250
|
+
})]
|
|
251
|
+
}, key);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { TableRow as default };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import { Edit, Trash, Eye } from 'lucide-react';
|
|
5
|
+
|
|
6
|
+
var DEFAULT_ACTIONS = [{
|
|
7
|
+
name: "edit",
|
|
8
|
+
label: "Edit",
|
|
9
|
+
onClick: function onClick() {
|
|
10
|
+
return console.log("Edit action clicked");
|
|
11
|
+
},
|
|
12
|
+
icon: jsx(Edit, {
|
|
13
|
+
size: 16
|
|
14
|
+
})
|
|
15
|
+
}, {
|
|
16
|
+
name: "delete",
|
|
17
|
+
label: "Delete",
|
|
18
|
+
onClick: function onClick() {
|
|
19
|
+
return console.log("Delete action clicked");
|
|
20
|
+
},
|
|
21
|
+
icon: jsx(Trash, {
|
|
22
|
+
size: 16
|
|
23
|
+
})
|
|
24
|
+
}, {
|
|
25
|
+
name: "view",
|
|
26
|
+
label: "View",
|
|
27
|
+
onClick: function onClick() {
|
|
28
|
+
return console.log("View action clicked");
|
|
29
|
+
},
|
|
30
|
+
icon: jsx(Eye, {
|
|
31
|
+
size: 16
|
|
32
|
+
})
|
|
33
|
+
}];
|
|
34
|
+
|
|
35
|
+
export { DEFAULT_ACTIONS };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { createForOfIteratorHelper as _createForOfIteratorHelper, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray, typeof as _typeof } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate a unique key for a row based on id, _id, or index
|
|
5
|
+
*/
|
|
6
|
+
var getRowKey = function getRowKey(row, globalIndex) {
|
|
7
|
+
if (row == null) return String(globalIndex);
|
|
8
|
+
if (row._key !== undefined && row._key !== null) return String(row._key);
|
|
9
|
+
if (row.id !== undefined && row.id !== null) return String(row.id);
|
|
10
|
+
if (row._id !== undefined && row._id !== null) return String(row._id);
|
|
11
|
+
return String(globalIndex);
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Resolve a value that may be supplied directly or as a per-row producer.
|
|
15
|
+
* Used for an action's `label`, `icon`, `hidden` and `disabled`.
|
|
16
|
+
*/
|
|
17
|
+
var callIfFn = function callIfFn(value, row, index) {
|
|
18
|
+
return typeof value === "function" ? value(row, index) : value;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Does THIS row get an expand toggle?
|
|
22
|
+
* `hasDetails` is either a boolean (every row) or a `(row, index)` predicate.
|
|
23
|
+
*/
|
|
24
|
+
var rowHasDetails = function rowHasDetails(hasDetails, row, index) {
|
|
25
|
+
return typeof hasDetails === "function" ? !!hasDetails(row, index) : !!hasDetails;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Best-effort accessible name for an action. `label` may be an arbitrary
|
|
29
|
+
* ReactNode, so fall back to `name` and finally to a generic string.
|
|
30
|
+
*/
|
|
31
|
+
var getActionLabelText = function getActionLabelText(action) {
|
|
32
|
+
return typeof (action === null || action === void 0 ? void 0 : action.label) === "string" && action.label.trim() || typeof (action === null || action === void 0 ? void 0 : action.name) === "string" && action.name.trim() || "Action";
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Patch `defaults` with `overrides`, matched by `name`.
|
|
36
|
+
*
|
|
37
|
+
* Result order is the defaults' order, then any unmatched or unnamed overrides
|
|
38
|
+
* appended. Each match is a shallow spread, so `{ name: "edit", onClick }`
|
|
39
|
+
* keeps the default's `label` and `icon`, and `{ name: "delete", hidden: true }`
|
|
40
|
+
* removes a default without needing a dedicated API.
|
|
41
|
+
*
|
|
42
|
+
* @param {Array} overrides consumer-supplied actions
|
|
43
|
+
* @param {Array} defaults the built-in action set
|
|
44
|
+
* @returns {Array}
|
|
45
|
+
*/
|
|
46
|
+
var mergeDefaultActions = function mergeDefaultActions(overrides, defaults) {
|
|
47
|
+
if (!Array.isArray(overrides)) return defaults;
|
|
48
|
+
if (!Array.isArray(defaults) || defaults.length === 0) return overrides;
|
|
49
|
+
var byName = new Map();
|
|
50
|
+
var _iterator = _createForOfIteratorHelper(overrides),
|
|
51
|
+
_step;
|
|
52
|
+
try {
|
|
53
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
54
|
+
var action = _step.value;
|
|
55
|
+
if (action && action.name) byName.set(action.name, action);
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
_iterator.e(err);
|
|
59
|
+
} finally {
|
|
60
|
+
_iterator.f();
|
|
61
|
+
}
|
|
62
|
+
var merged = defaults.map(function (d) {
|
|
63
|
+
return d !== null && d !== void 0 && d.name && byName.has(d.name) ? _objectSpread2(_objectSpread2({}, d), byName.get(d.name)) : d;
|
|
64
|
+
});
|
|
65
|
+
var defaultNames = new Set(defaults.map(function (d) {
|
|
66
|
+
return d === null || d === void 0 ? void 0 : d.name;
|
|
67
|
+
}).filter(Boolean));
|
|
68
|
+
var appended = overrides.filter(function (a) {
|
|
69
|
+
return a && (!a.name || !defaultNames.has(a.name));
|
|
70
|
+
});
|
|
71
|
+
return [].concat(_toConsumableArray(merged), _toConsumableArray(appended));
|
|
72
|
+
};
|
|
73
|
+
var EMPTY_RESOLVED = Object.freeze({
|
|
74
|
+
inlineActions: Object.freeze([]),
|
|
75
|
+
menuActions: Object.freeze([])
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Normalize the `actions` prop for a single row.
|
|
79
|
+
*
|
|
80
|
+
* Accepts either an array or a `(row, index) => array` producer. Entries whose
|
|
81
|
+
* `hidden` resolves truthy are dropped; `label`/`icon` are resolved against the
|
|
82
|
+
* row; `disabled` is coerced to a boolean; `inline` entries are split out so
|
|
83
|
+
* they can render as icon buttons in the cell rather than inside the menu.
|
|
84
|
+
*
|
|
85
|
+
* `render` is deliberately passed through untouched — it is already a
|
|
86
|
+
* `(row) => ReactNode` renderer with its own contract, not a value producer.
|
|
87
|
+
*
|
|
88
|
+
* @param {Array|Function} actions array, or (row, index) => array
|
|
89
|
+
* @param {object} row
|
|
90
|
+
* @param {number} index the GLOBAL row index (startIndex + rowIndexInPage)
|
|
91
|
+
* @returns {{ inlineActions: Array, menuActions: Array }}
|
|
92
|
+
*/
|
|
93
|
+
var resolveActions = function resolveActions(actions, row, index) {
|
|
94
|
+
var source = typeof actions === "function" ? actions(row, index) : actions;
|
|
95
|
+
if (!Array.isArray(source) || source.length === 0) return EMPTY_RESOLVED;
|
|
96
|
+
var inlineActions = [];
|
|
97
|
+
var menuActions = [];
|
|
98
|
+
var _iterator2 = _createForOfIteratorHelper(source),
|
|
99
|
+
_step2;
|
|
100
|
+
try {
|
|
101
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
102
|
+
var action = _step2.value;
|
|
103
|
+
if (!action || _typeof(action) !== "object") continue;
|
|
104
|
+
if (callIfFn(action.hidden, row, index)) continue;
|
|
105
|
+
var resolved = _objectSpread2(_objectSpread2({}, action), {}, {
|
|
106
|
+
label: callIfFn(action.label, row, index),
|
|
107
|
+
icon: callIfFn(action.icon, row, index),
|
|
108
|
+
disabled: !!callIfFn(action.disabled, row, index),
|
|
109
|
+
inline: !!action.inline
|
|
110
|
+
});
|
|
111
|
+
(resolved.inline ? inlineActions : menuActions).push(resolved);
|
|
112
|
+
}
|
|
113
|
+
} catch (err) {
|
|
114
|
+
_iterator2.e(err);
|
|
115
|
+
} finally {
|
|
116
|
+
_iterator2.f();
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
inlineActions: inlineActions,
|
|
120
|
+
menuActions: menuActions
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export { getActionLabelText, getRowKey, mergeDefaultActions, resolveActions, rowHasDetails };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook to detect clicks outside of specified refs
|
|
6
|
+
* @param {Array} refs - Array of React refs to check
|
|
7
|
+
* @param {boolean} isActive - Whether the hook should be active
|
|
8
|
+
* @param {Function} onClickOutside - Callback when click is detected outside
|
|
9
|
+
*/
|
|
10
|
+
function useClickOutside(refs, isActive, onClickOutside) {
|
|
11
|
+
useEffect(function () {
|
|
12
|
+
if (!isActive) return;
|
|
13
|
+
var handler = function handler(e) {
|
|
14
|
+
var isOutside = refs.every(function (ref) {
|
|
15
|
+
return !ref.current || !ref.current.contains(e.target);
|
|
16
|
+
});
|
|
17
|
+
if (isOutside) onClickOutside();
|
|
18
|
+
};
|
|
19
|
+
document.addEventListener("mousedown", handler, true);
|
|
20
|
+
return function () {
|
|
21
|
+
return document.removeEventListener("mousedown", handler, true);
|
|
22
|
+
};
|
|
23
|
+
}, [refs, isActive, onClickOutside]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { useClickOutside };
|