@expcat/tigercat-react 1.2.37 → 1.2.41
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/{chunk-2CJKAO2I.mjs → chunk-2VE2CP7E.mjs} +144 -9
- package/dist/{chunk-JNRUOQNT.js → chunk-36I5APFX.js} +2 -2
- package/dist/{chunk-C3NKZZQQ.js → chunk-AE2QE2C6.js} +2 -2
- package/dist/{chunk-4XOWNEZA.mjs → chunk-C44WSDEY.mjs} +19 -4
- package/dist/{chunk-6HELKWFN.js → chunk-JIFSUUGA.js} +19 -4
- package/dist/{chunk-AKZY7QYA.js → chunk-JLQBG5XU.js} +23 -17
- package/dist/{chunk-L2CAJUXH.js → chunk-LHBE3N3U.js} +162 -27
- package/dist/{chunk-IAONLOJN.js → chunk-LYYL2JMP.js} +2 -2
- package/dist/{chunk-UKBVJWP3.mjs → chunk-MV54EEKO.mjs} +1 -1
- package/dist/{chunk-KRFD27WA.js → chunk-OBY4FYRZ.js} +2 -2
- package/dist/{chunk-O4UDB6ZE.mjs → chunk-TANTMMR7.mjs} +1 -1
- package/dist/{chunk-WVTUGFWO.mjs → chunk-TYZNV54N.mjs} +23 -17
- package/dist/{chunk-ZGPOMSGD.mjs → chunk-WYGO6XC7.mjs} +232 -74
- package/dist/{chunk-MIINT2WV.js → chunk-XUETAIF3.js} +264 -106
- package/dist/{chunk-VE2YEFG2.mjs → chunk-ZDS5WL22.mjs} +1 -1
- package/dist/{chunk-73OAHAPC.mjs → chunk-ZL44XLSB.mjs} +1 -1
- package/dist/components/ChatWindow.js +3 -3
- package/dist/components/ChatWindow.mjs +2 -2
- package/dist/components/DataTableWithToolbar.d.mts +2 -2
- package/dist/components/DataTableWithToolbar.d.ts +2 -2
- package/dist/components/DataTableWithToolbar.js +12 -3
- package/dist/components/DataTableWithToolbar.mjs +11 -2
- package/dist/components/Dropdown.js +2 -2
- package/dist/components/Dropdown.mjs +1 -1
- package/dist/components/DropdownItem.js +3 -3
- package/dist/components/DropdownItem.mjs +2 -2
- package/dist/components/DropdownMenu.js +2 -2
- package/dist/components/DropdownMenu.mjs +1 -1
- package/dist/components/Popconfirm.js +3 -3
- package/dist/components/Popconfirm.mjs +2 -2
- package/dist/components/Popover.js +3 -3
- package/dist/components/Popover.mjs +2 -2
- package/dist/components/Table.d.mts +2 -2
- package/dist/components/Table.d.ts +2 -2
- package/dist/components/Table.js +9 -2
- package/dist/components/Table.mjs +8 -1
- package/dist/components/Tooltip.js +3 -3
- package/dist/components/Tooltip.mjs +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -20
- package/dist/index.mjs +20 -20
- package/dist/{types-mtq1tZJd.d.ts → types-CHmCMNEM.d.mts} +1 -0
- package/dist/{types-mtq1tZJd.d.mts → types-CHmCMNEM.d.ts} +1 -0
- package/package.json +2 -2
- package/dist/{chunk-7KPALCG3.js → chunk-ABTJVM3X.js} +2 -2
- package/dist/{chunk-GYFR2O27.mjs → chunk-OXDX6CH2.mjs} +3 -3
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Table
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WYGO6XC7.mjs";
|
|
4
4
|
import {
|
|
5
5
|
Select
|
|
6
6
|
} from "./chunk-T4OVGM4X.mjs";
|
|
7
|
+
import {
|
|
8
|
+
Popover
|
|
9
|
+
} from "./chunk-TANTMMR7.mjs";
|
|
10
|
+
import {
|
|
11
|
+
useTigerConfig
|
|
12
|
+
} from "./chunk-QAIBQHIO.mjs";
|
|
7
13
|
import {
|
|
8
14
|
Input
|
|
9
15
|
} from "./chunk-WNLUUD5N.mjs";
|
|
16
|
+
import {
|
|
17
|
+
Checkbox
|
|
18
|
+
} from "./chunk-MSHCPJIJ.mjs";
|
|
10
19
|
import {
|
|
11
20
|
Button
|
|
12
21
|
} from "./chunk-USWK2S3Y.mjs";
|
|
@@ -14,15 +23,25 @@ import {
|
|
|
14
23
|
// src/components/DataTableWithToolbar.tsx
|
|
15
24
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
16
25
|
import {
|
|
17
|
-
classNames
|
|
26
|
+
classNames,
|
|
27
|
+
getImmediateTigerLocale,
|
|
28
|
+
getTableLabels,
|
|
29
|
+
isLazyTigerLocale,
|
|
30
|
+
mergeTigerLocale,
|
|
31
|
+
resolveTigerLocale
|
|
18
32
|
} from "@expcat/tigercat-core";
|
|
19
33
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
20
34
|
var DataTableWithToolbar = ({
|
|
21
35
|
toolbar,
|
|
36
|
+
locale,
|
|
37
|
+
labels,
|
|
22
38
|
onSearchChange,
|
|
23
39
|
onSearch,
|
|
24
40
|
onFiltersChange,
|
|
25
41
|
onBulkAction,
|
|
42
|
+
hiddenColumnKeys,
|
|
43
|
+
defaultHiddenColumnKeys,
|
|
44
|
+
onHiddenColumnsChange,
|
|
26
45
|
pagination = false,
|
|
27
46
|
onPageChange,
|
|
28
47
|
onPageSizeChange,
|
|
@@ -30,10 +49,14 @@ var DataTableWithToolbar = ({
|
|
|
30
49
|
tableClassName,
|
|
31
50
|
...tableProps
|
|
32
51
|
}) => {
|
|
52
|
+
const config = useTigerConfig();
|
|
33
53
|
const previousPageSizeRef = useRef(
|
|
34
54
|
pagination && typeof pagination === "object" ? pagination.pageSize ?? pagination.defaultPageSize ?? 10 : void 0
|
|
35
55
|
);
|
|
36
56
|
const [internalSearch, setInternalSearch] = useState(toolbar?.defaultSearchValue ?? "");
|
|
57
|
+
const [internalHiddenKeys, setInternalHiddenKeys] = useState(
|
|
58
|
+
defaultHiddenColumnKeys ?? hiddenColumnKeys ?? []
|
|
59
|
+
);
|
|
37
60
|
const [internalFilters, setInternalFilters] = useState(
|
|
38
61
|
() => {
|
|
39
62
|
const initial = {};
|
|
@@ -45,11 +68,42 @@ var DataTableWithToolbar = ({
|
|
|
45
68
|
return initial;
|
|
46
69
|
}
|
|
47
70
|
);
|
|
71
|
+
const immediateTableLocale = useMemo(
|
|
72
|
+
() => locale ? getImmediateTigerLocale(locale) : void 0,
|
|
73
|
+
[locale]
|
|
74
|
+
);
|
|
75
|
+
const [resolvedTableLocale, setResolvedTableLocale] = useState(
|
|
76
|
+
immediateTableLocale
|
|
77
|
+
);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
let active = true;
|
|
80
|
+
setResolvedTableLocale(immediateTableLocale);
|
|
81
|
+
if (locale && isLazyTigerLocale(locale)) {
|
|
82
|
+
resolveTigerLocale(locale).then((nextLocale) => {
|
|
83
|
+
if (active) setResolvedTableLocale(nextLocale);
|
|
84
|
+
}).catch(() => {
|
|
85
|
+
if (active) setResolvedTableLocale(immediateTableLocale);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return () => {
|
|
89
|
+
active = false;
|
|
90
|
+
};
|
|
91
|
+
}, [locale, immediateTableLocale]);
|
|
92
|
+
const tableLocale = useMemo(
|
|
93
|
+
() => mergeTigerLocale(config.locale, resolvedTableLocale),
|
|
94
|
+
[config.locale, resolvedTableLocale]
|
|
95
|
+
);
|
|
96
|
+
const tableLabels = useMemo(() => getTableLabels(tableLocale, labels), [labels, tableLocale]);
|
|
48
97
|
useEffect(() => {
|
|
49
98
|
if (toolbar?.searchValue !== void 0) {
|
|
50
99
|
setInternalSearch(toolbar.searchValue ?? "");
|
|
51
100
|
}
|
|
52
101
|
}, [toolbar?.searchValue]);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (hiddenColumnKeys !== void 0) {
|
|
104
|
+
setInternalHiddenKeys(hiddenColumnKeys);
|
|
105
|
+
}
|
|
106
|
+
}, [hiddenColumnKeys]);
|
|
53
107
|
useEffect(() => {
|
|
54
108
|
if (pagination && typeof pagination === "object") {
|
|
55
109
|
previousPageSizeRef.current = pagination.pageSize ?? pagination.defaultPageSize ?? 10;
|
|
@@ -81,10 +135,22 @@ var DataTableWithToolbar = ({
|
|
|
81
135
|
);
|
|
82
136
|
const hasFilters = Boolean(toolbar?.filters && toolbar.filters.length > 0);
|
|
83
137
|
const hasBulkActions = Boolean(toolbar?.bulkActions && toolbar.bulkActions.length > 0);
|
|
138
|
+
const hasColumnSettings = Boolean(toolbar?.showColumnSettings);
|
|
139
|
+
const resolvedHiddenKeys = hiddenColumnKeys ?? internalHiddenKeys;
|
|
140
|
+
const handleHiddenColumnsChange = (nextHiddenKeys) => {
|
|
141
|
+
if (hiddenColumnKeys === void 0) {
|
|
142
|
+
setInternalHiddenKeys(nextHiddenKeys);
|
|
143
|
+
}
|
|
144
|
+
onHiddenColumnsChange?.(nextHiddenKeys);
|
|
145
|
+
};
|
|
146
|
+
const handleToggleColumnVisibility = (columnKey, visible) => {
|
|
147
|
+
const nextHiddenKeys = visible ? resolvedHiddenKeys.filter((key) => key !== columnKey) : [...resolvedHiddenKeys, columnKey];
|
|
148
|
+
handleHiddenColumnsChange(nextHiddenKeys);
|
|
149
|
+
};
|
|
84
150
|
const { bordered = false, ...remainingTableProps } = tableProps;
|
|
85
151
|
const selectedKeys = toolbar?.selectedKeys ?? tableProps.rowSelection?.selectedRowKeys ?? [];
|
|
86
152
|
const selectedCount = toolbar?.selectedCount ?? selectedKeys.length;
|
|
87
|
-
const bulkLabel = toolbar?.bulkActionsLabel ??
|
|
153
|
+
const bulkLabel = toolbar?.bulkActionsLabel ?? tableLabels.selectedText;
|
|
88
154
|
const wrapperClasses = useMemo(
|
|
89
155
|
() => classNames(
|
|
90
156
|
"tiger-data-table-with-toolbar flex flex-col",
|
|
@@ -131,8 +197,72 @@ var DataTableWithToolbar = ({
|
|
|
131
197
|
}
|
|
132
198
|
previousPageSizeRef.current = pageSize;
|
|
133
199
|
};
|
|
200
|
+
const renderColumnSettings = () => {
|
|
201
|
+
const lockedKeys = new Set(toolbar?.columnSettings?.lockedColumnKeys ?? []);
|
|
202
|
+
const panelTitle = toolbar?.columnSettings?.title ?? tableLabels.columnSettingsText;
|
|
203
|
+
return /* @__PURE__ */ jsx(
|
|
204
|
+
Popover,
|
|
205
|
+
{
|
|
206
|
+
trigger: "click",
|
|
207
|
+
placement: "bottom-end",
|
|
208
|
+
titleContent: panelTitle,
|
|
209
|
+
contentContent: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2 min-w-[160px]", children: tableProps.columns.map((column) => {
|
|
210
|
+
const locked = lockedKeys.has(column.key) || column.hideable === false;
|
|
211
|
+
return /* @__PURE__ */ jsx(
|
|
212
|
+
Checkbox,
|
|
213
|
+
{
|
|
214
|
+
size: "sm",
|
|
215
|
+
checked: !resolvedHiddenKeys.includes(column.key),
|
|
216
|
+
disabled: locked,
|
|
217
|
+
onChange: (checked) => handleToggleColumnVisibility(column.key, checked),
|
|
218
|
+
children: column.title
|
|
219
|
+
},
|
|
220
|
+
column.key
|
|
221
|
+
);
|
|
222
|
+
}) }),
|
|
223
|
+
children: /* @__PURE__ */ jsx(
|
|
224
|
+
Button,
|
|
225
|
+
{
|
|
226
|
+
size: "sm",
|
|
227
|
+
variant: "outline",
|
|
228
|
+
className: "shrink-0 px-2",
|
|
229
|
+
"aria-label": tableLabels.columnSettingsAriaLabel,
|
|
230
|
+
children: /* @__PURE__ */ jsxs(
|
|
231
|
+
"svg",
|
|
232
|
+
{
|
|
233
|
+
className: "w-3.5 h-3.5",
|
|
234
|
+
fill: "none",
|
|
235
|
+
stroke: "currentColor",
|
|
236
|
+
strokeWidth: "2",
|
|
237
|
+
viewBox: "0 0 24 24",
|
|
238
|
+
"aria-hidden": "true",
|
|
239
|
+
children: [
|
|
240
|
+
/* @__PURE__ */ jsx(
|
|
241
|
+
"path",
|
|
242
|
+
{
|
|
243
|
+
strokeLinecap: "round",
|
|
244
|
+
strokeLinejoin: "round",
|
|
245
|
+
d: "M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"
|
|
246
|
+
}
|
|
247
|
+
),
|
|
248
|
+
/* @__PURE__ */ jsx(
|
|
249
|
+
"path",
|
|
250
|
+
{
|
|
251
|
+
strokeLinecap: "round",
|
|
252
|
+
strokeLinejoin: "round",
|
|
253
|
+
d: "M15 12a3 3 0 11-6 0 3 3 0 016 0z"
|
|
254
|
+
}
|
|
255
|
+
)
|
|
256
|
+
]
|
|
257
|
+
}
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
);
|
|
263
|
+
};
|
|
134
264
|
const renderToolbar = () => {
|
|
135
|
-
if (!hasSearch && !hasFilters && !hasBulkActions) return null;
|
|
265
|
+
if (!hasSearch && !hasFilters && !hasBulkActions && !hasColumnSettings) return null;
|
|
136
266
|
return /* @__PURE__ */ jsxs(
|
|
137
267
|
"div",
|
|
138
268
|
{
|
|
@@ -141,7 +271,7 @@ var DataTableWithToolbar = ({
|
|
|
141
271
|
bordered ? "bg-[var(--tiger-surface-muted,#f9fafb)] dark:bg-gray-800/10 px-4 py-3.5 border-b border-[var(--tiger-border,#e5e7eb)]" : "bg-[var(--tiger-surface-muted,#f9fafb)]/80 dark:bg-gray-800/30 px-4 py-3.5 border border-[var(--tiger-border,#e5e7eb)] rounded-[var(--tiger-radius-md,0.5rem)] shadow-sm"
|
|
142
272
|
),
|
|
143
273
|
role: "toolbar",
|
|
144
|
-
"aria-label":
|
|
274
|
+
"aria-label": tableLabels.toolbarAriaLabel,
|
|
145
275
|
children: [
|
|
146
276
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 flex-wrap flex-1 min-w-0", children: [
|
|
147
277
|
hasSearch ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 w-full sm:w-auto sm:min-w-[220px] sm:max-w-[320px]", children: [
|
|
@@ -151,7 +281,7 @@ var DataTableWithToolbar = ({
|
|
|
151
281
|
type: "search",
|
|
152
282
|
size: "sm",
|
|
153
283
|
value: searchValue,
|
|
154
|
-
placeholder: toolbar?.searchPlaceholder ??
|
|
284
|
+
placeholder: toolbar?.searchPlaceholder ?? tableLabels.searchPlaceholder,
|
|
155
285
|
prefix: /* @__PURE__ */ jsx(
|
|
156
286
|
"svg",
|
|
157
287
|
{
|
|
@@ -187,7 +317,7 @@ var DataTableWithToolbar = ({
|
|
|
187
317
|
className: "whitespace-nowrap shrink-0 rounded-[var(--tiger-radius-md,0.5rem)] px-3",
|
|
188
318
|
onClick: handleSearchSubmit,
|
|
189
319
|
disabled: !onSearch && !toolbar?.onSearch,
|
|
190
|
-
children: toolbar?.searchButtonText ??
|
|
320
|
+
children: toolbar?.searchButtonText ?? tableLabels.searchButtonText
|
|
191
321
|
}
|
|
192
322
|
) : null
|
|
193
323
|
] }) : null,
|
|
@@ -226,7 +356,8 @@ var DataTableWithToolbar = ({
|
|
|
226
356
|
bulkLabel,
|
|
227
357
|
" ",
|
|
228
358
|
selectedCount,
|
|
229
|
-
"
|
|
359
|
+
" ",
|
|
360
|
+
tableLabels.selectedItemsText
|
|
230
361
|
] })
|
|
231
362
|
] }) : null,
|
|
232
363
|
toolbar?.bulkActions?.map((action) => /* @__PURE__ */ jsx(
|
|
@@ -240,7 +371,8 @@ var DataTableWithToolbar = ({
|
|
|
240
371
|
},
|
|
241
372
|
action.key
|
|
242
373
|
))
|
|
243
|
-
] }) : null
|
|
374
|
+
] }) : null,
|
|
375
|
+
hasColumnSettings ? /* @__PURE__ */ jsx("div", { className: classNames("shrink-0", !hasBulkActions && "ml-auto"), children: renderColumnSettings() }) : null
|
|
244
376
|
]
|
|
245
377
|
}
|
|
246
378
|
);
|
|
@@ -251,7 +383,10 @@ var DataTableWithToolbar = ({
|
|
|
251
383
|
Table,
|
|
252
384
|
{
|
|
253
385
|
...remainingTableProps,
|
|
386
|
+
locale,
|
|
387
|
+
labels,
|
|
254
388
|
bordered,
|
|
389
|
+
hiddenColumnKeys: resolvedHiddenKeys,
|
|
255
390
|
pagination,
|
|
256
391
|
className: classNames(tableClassName, bordered && "border-none rounded-none shadow-none"),
|
|
257
392
|
onPageChange: handleTablePageChange
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkJIFSUUGAjs = require('./chunk-JIFSUUGA.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkSTTQ5LXXjs = require('./chunk-STTQ5LXX.js');
|
|
@@ -84,7 +84,7 @@ var Popconfirm = ({
|
|
|
84
84
|
floatingRef,
|
|
85
85
|
actualPlacement,
|
|
86
86
|
floatingStyles: baseFloatingStyles
|
|
87
|
-
} =
|
|
87
|
+
} = _chunkJIFSUUGAjs.usePopup.call(void 0, {
|
|
88
88
|
open,
|
|
89
89
|
defaultOpen,
|
|
90
90
|
disabled,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkJLQBG5XUjs = require('./chunk-JLQBG5XU.js');
|
|
4
4
|
|
|
5
5
|
// src/components/DropdownItem.tsx
|
|
6
6
|
var _react = require('react');
|
|
@@ -17,7 +17,7 @@ var DropdownItem = ({
|
|
|
17
17
|
children,
|
|
18
18
|
...buttonProps
|
|
19
19
|
}) => {
|
|
20
|
-
const context = _react.useContext.call(void 0,
|
|
20
|
+
const context = _react.useContext.call(void 0, _chunkJLQBG5XUjs.DropdownContext);
|
|
21
21
|
const handleClick = (event) => {
|
|
22
22
|
if (disabled) {
|
|
23
23
|
event.preventDefault();
|
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
import { useCallback, useMemo, useRef, useState } from "react";
|
|
9
9
|
import {
|
|
10
10
|
getTransformOrigin,
|
|
11
|
-
|
|
11
|
+
FLOATING_OVERLAY_Z_INDEX,
|
|
12
|
+
buildTriggerHandlerMap,
|
|
13
|
+
restoreFocus
|
|
12
14
|
} from "@expcat/tigercat-core";
|
|
13
15
|
function usePopup(options) {
|
|
14
16
|
const {
|
|
@@ -46,6 +48,19 @@ function usePopup(options) {
|
|
|
46
48
|
},
|
|
47
49
|
[disabled, isControlled, onOpenChange]
|
|
48
50
|
);
|
|
51
|
+
const restoreTriggerFocus = useCallback(() => {
|
|
52
|
+
const trigger2 = triggerRef.current;
|
|
53
|
+
const target = trigger2?.querySelector(
|
|
54
|
+
'button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"])'
|
|
55
|
+
) ?? trigger2;
|
|
56
|
+
window.setTimeout(() => {
|
|
57
|
+
restoreFocus(target, { preventScroll: true });
|
|
58
|
+
}, 0);
|
|
59
|
+
}, []);
|
|
60
|
+
const closeAndRestoreFocus = useCallback(() => {
|
|
61
|
+
setVisible(false);
|
|
62
|
+
restoreTriggerFocus();
|
|
63
|
+
}, [restoreTriggerFocus, setVisible]);
|
|
49
64
|
const handleToggle = useCallback(() => {
|
|
50
65
|
if (!disabled) setVisible(!currentVisible);
|
|
51
66
|
}, [disabled, currentVisible, setVisible]);
|
|
@@ -59,12 +74,12 @@ function usePopup(options) {
|
|
|
59
74
|
useClickOutside({
|
|
60
75
|
enabled: currentVisible && effectiveTrigger === "click",
|
|
61
76
|
refs: [containerRef, floatingRef],
|
|
62
|
-
onOutsideClick:
|
|
77
|
+
onOutsideClick: closeAndRestoreFocus,
|
|
63
78
|
defer: true
|
|
64
79
|
});
|
|
65
80
|
useEscapeKey({
|
|
66
81
|
enabled: currentVisible && effectiveTrigger !== "manual",
|
|
67
|
-
onEscape:
|
|
82
|
+
onEscape: closeAndRestoreFocus
|
|
68
83
|
});
|
|
69
84
|
const floatingStyles = useMemo(
|
|
70
85
|
() => ({
|
|
@@ -72,7 +87,7 @@ function usePopup(options) {
|
|
|
72
87
|
left: x,
|
|
73
88
|
top: y,
|
|
74
89
|
transformOrigin: getTransformOrigin(actualPlacement),
|
|
75
|
-
zIndex:
|
|
90
|
+
zIndex: FLOATING_OVERLAY_Z_INDEX
|
|
76
91
|
}),
|
|
77
92
|
[x, y, actualPlacement]
|
|
78
93
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -9,6 +9,8 @@ var _react = require('react');
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
|
|
13
|
+
|
|
12
14
|
var _tigercatcore = require('@expcat/tigercat-core');
|
|
13
15
|
function usePopup(options) {
|
|
14
16
|
const {
|
|
@@ -46,6 +48,19 @@ function usePopup(options) {
|
|
|
46
48
|
},
|
|
47
49
|
[disabled, isControlled, onOpenChange]
|
|
48
50
|
);
|
|
51
|
+
const restoreTriggerFocus = _react.useCallback.call(void 0, () => {
|
|
52
|
+
const trigger2 = triggerRef.current;
|
|
53
|
+
const target = _nullishCoalesce(_optionalChain([trigger2, 'optionalAccess', _2 => _2.querySelector, 'call', _3 => _3(
|
|
54
|
+
'button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"])'
|
|
55
|
+
)]), () => ( trigger2));
|
|
56
|
+
window.setTimeout(() => {
|
|
57
|
+
_tigercatcore.restoreFocus.call(void 0, target, { preventScroll: true });
|
|
58
|
+
}, 0);
|
|
59
|
+
}, []);
|
|
60
|
+
const closeAndRestoreFocus = _react.useCallback.call(void 0, () => {
|
|
61
|
+
setVisible(false);
|
|
62
|
+
restoreTriggerFocus();
|
|
63
|
+
}, [restoreTriggerFocus, setVisible]);
|
|
49
64
|
const handleToggle = _react.useCallback.call(void 0, () => {
|
|
50
65
|
if (!disabled) setVisible(!currentVisible);
|
|
51
66
|
}, [disabled, currentVisible, setVisible]);
|
|
@@ -59,12 +74,12 @@ function usePopup(options) {
|
|
|
59
74
|
_chunkSTTQ5LXXjs.useClickOutside.call(void 0, {
|
|
60
75
|
enabled: currentVisible && effectiveTrigger === "click",
|
|
61
76
|
refs: [containerRef, floatingRef],
|
|
62
|
-
onOutsideClick:
|
|
77
|
+
onOutsideClick: closeAndRestoreFocus,
|
|
63
78
|
defer: true
|
|
64
79
|
});
|
|
65
80
|
_chunkSTTQ5LXXjs.useEscapeKey.call(void 0, {
|
|
66
81
|
enabled: currentVisible && effectiveTrigger !== "manual",
|
|
67
|
-
onEscape:
|
|
82
|
+
onEscape: closeAndRestoreFocus
|
|
68
83
|
});
|
|
69
84
|
const floatingStyles = _react.useMemo.call(void 0,
|
|
70
85
|
() => ({
|
|
@@ -72,7 +87,7 @@ function usePopup(options) {
|
|
|
72
87
|
left: x,
|
|
73
88
|
top: y,
|
|
74
89
|
transformOrigin: _tigercatcore.getTransformOrigin.call(void 0, actualPlacement),
|
|
75
|
-
zIndex:
|
|
90
|
+
zIndex: _tigercatcore.FLOATING_OVERLAY_Z_INDEX
|
|
76
91
|
}),
|
|
77
92
|
[x, y, actualPlacement]
|
|
78
93
|
);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
var _chunkSTTQ5LXXjs = require('./chunk-STTQ5LXX.js');
|
|
6
7
|
|
|
7
8
|
// src/components/Dropdown.tsx
|
|
@@ -28,6 +29,7 @@ var _react = require('react'); var _react2 = _interopRequireDefault(_react);
|
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
|
|
32
|
+
|
|
31
33
|
var _tigercatcore = require('@expcat/tigercat-core');
|
|
32
34
|
var _jsxruntime = require('react/jsx-runtime');
|
|
33
35
|
var DropdownContext = _react.createContext.call(void 0, null);
|
|
@@ -50,6 +52,7 @@ var Dropdown = ({
|
|
|
50
52
|
defaultOpen = false,
|
|
51
53
|
closeOnClick = true,
|
|
52
54
|
showArrow = true,
|
|
55
|
+
portal = true,
|
|
53
56
|
className,
|
|
54
57
|
style,
|
|
55
58
|
onOpenChange,
|
|
@@ -125,7 +128,7 @@ var Dropdown = ({
|
|
|
125
128
|
}, []);
|
|
126
129
|
_chunkSTTQ5LXXjs.useClickOutside.call(void 0, {
|
|
127
130
|
enabled: trigger === "click" && visible,
|
|
128
|
-
refs: [containerRef],
|
|
131
|
+
refs: [containerRef, floatingRef],
|
|
129
132
|
onOutsideClick: () => setVisible(false)
|
|
130
133
|
});
|
|
131
134
|
_chunkSTTQ5LXXjs.useEscapeKey.call(void 0, {
|
|
@@ -151,12 +154,13 @@ var Dropdown = ({
|
|
|
151
154
|
[className]
|
|
152
155
|
);
|
|
153
156
|
const triggerClasses = _react.useMemo.call(void 0, () => _tigercatcore.getDropdownTriggerClasses.call(void 0, disabled), [disabled]);
|
|
154
|
-
const menuWrapperClasses = _tigercatcore.classNames.call(void 0, "absolute
|
|
157
|
+
const menuWrapperClasses = _tigercatcore.classNames.call(void 0, "absolute", _tigercatcore.DROPDOWN_ENTER_CLASS);
|
|
155
158
|
const menuWrapperStyles = _react.useMemo.call(void 0,
|
|
156
159
|
() => ({
|
|
157
160
|
position: "absolute",
|
|
158
161
|
left: x,
|
|
159
162
|
top: y,
|
|
163
|
+
zIndex: _tigercatcore.FLOATING_OVERLAY_Z_INDEX,
|
|
160
164
|
transformOrigin: _tigercatcore.getTransformOrigin.call(void 0, placement)
|
|
161
165
|
}),
|
|
162
166
|
[x, y, placement]
|
|
@@ -195,6 +199,22 @@ var Dropdown = ({
|
|
|
195
199
|
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: _tigercatcore.DROPDOWN_CHEVRON_PATH })
|
|
196
200
|
}
|
|
197
201
|
) : null;
|
|
202
|
+
const menuWrapperNode = /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
203
|
+
"div",
|
|
204
|
+
{
|
|
205
|
+
ref: floatingRef,
|
|
206
|
+
className: menuWrapperClasses,
|
|
207
|
+
style: menuWrapperStyles,
|
|
208
|
+
hidden: !visible,
|
|
209
|
+
"data-tiger-dropdown-menu": "",
|
|
210
|
+
onMouseEnter: handleMouseEnter,
|
|
211
|
+
onMouseLeave: handleMouseLeave,
|
|
212
|
+
onKeyDown: handleMenuKeyDown,
|
|
213
|
+
children: menuElement && _react2.default.isValidElement(menuElement) ? _react2.default.cloneElement(menuElement, {
|
|
214
|
+
id: menuId
|
|
215
|
+
}) : menuElement
|
|
216
|
+
}
|
|
217
|
+
);
|
|
198
218
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DropdownContext.Provider, { value: contextValue, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { ref: containerRef, className: containerClasses, style, ...divProps, children: [
|
|
199
219
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
200
220
|
"div",
|
|
@@ -213,21 +233,7 @@ var Dropdown = ({
|
|
|
213
233
|
]
|
|
214
234
|
}
|
|
215
235
|
),
|
|
216
|
-
|
|
217
|
-
"div",
|
|
218
|
-
{
|
|
219
|
-
ref: floatingRef,
|
|
220
|
-
className: menuWrapperClasses,
|
|
221
|
-
style: menuWrapperStyles,
|
|
222
|
-
hidden: !visible,
|
|
223
|
-
onMouseEnter: handleMouseEnter,
|
|
224
|
-
onMouseLeave: handleMouseLeave,
|
|
225
|
-
onKeyDown: handleMenuKeyDown,
|
|
226
|
-
children: menuElement && _react2.default.isValidElement(menuElement) ? _react2.default.cloneElement(menuElement, {
|
|
227
|
-
id: menuId
|
|
228
|
-
}) : menuElement
|
|
229
|
-
}
|
|
230
|
-
)
|
|
236
|
+
portal ? _chunkSTTQ5LXXjs.renderBodyPortal.call(void 0, menuWrapperNode) : menuWrapperNode
|
|
231
237
|
] }) });
|
|
232
238
|
};
|
|
233
239
|
|