@dloizides/ui-tables 1.13.0 → 1.15.0
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/CHANGELOG.md +105 -0
- package/README.md +11 -2
- package/dist/index.d.mts +22 -32
- package/dist/index.d.ts +22 -32
- package/dist/index.js +130 -425
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -377
- package/dist/index.mjs.map +1 -1
- package/package.json +119 -115
package/dist/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var react = require('react');
|
|
4
4
|
var reactNative = require('react-native');
|
|
5
5
|
var uiFeedback = require('@dloizides/ui-feedback');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var reactDom = require('react-dom');
|
|
8
|
-
|
|
9
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
|
|
11
|
-
var React4__default = /*#__PURE__*/_interopDefault(React4);
|
|
8
|
+
var uiForms = require('@dloizides/ui-forms');
|
|
12
9
|
|
|
13
10
|
// src/StatCard/StatCard.tsx
|
|
14
11
|
|
|
@@ -123,7 +120,7 @@ var styles = reactNative.StyleSheet.create({
|
|
|
123
120
|
lineHeight: VALUE_LINE_HEIGHT
|
|
124
121
|
}
|
|
125
122
|
});
|
|
126
|
-
var StatCard =
|
|
123
|
+
var StatCard = react.memo(({ label, value, testID }) => {
|
|
127
124
|
const { theme, t } = uiFeedback.useUi();
|
|
128
125
|
const { colors } = theme;
|
|
129
126
|
const formattedValue = value.toLocaleString();
|
|
@@ -655,21 +652,21 @@ var TAB_INDEX_ACTIVE = 0;
|
|
|
655
652
|
var TAB_INDEX_INACTIVE2 = -1;
|
|
656
653
|
var IS_WEB = reactNative.Platform.OS === "web";
|
|
657
654
|
function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
|
|
658
|
-
const [focusedKey, setFocusedKey] =
|
|
659
|
-
const nodes =
|
|
655
|
+
const [focusedKey, setFocusedKey] = react.useState(void 0);
|
|
656
|
+
const nodes = react.useRef(/* @__PURE__ */ new Map());
|
|
660
657
|
const tabbableKey = enabled ? resolveTabbableKey(rowKeys, focusedKey) : void 0;
|
|
661
|
-
const registerRow =
|
|
658
|
+
const registerRow = react.useCallback((key, node) => {
|
|
662
659
|
if (node === null || node === void 0) {
|
|
663
660
|
nodes.current.delete(key);
|
|
664
661
|
return;
|
|
665
662
|
}
|
|
666
663
|
nodes.current.set(key, node);
|
|
667
664
|
}, []);
|
|
668
|
-
const focusRow =
|
|
665
|
+
const focusRow = react.useCallback((key) => {
|
|
669
666
|
setFocusedKey(key);
|
|
670
667
|
nodes.current.get(key)?.focus?.();
|
|
671
668
|
}, []);
|
|
672
|
-
const handleKey =
|
|
669
|
+
const handleKey = react.useCallback(
|
|
673
670
|
(event, key) => {
|
|
674
671
|
const action = toRowNavAction(event.key);
|
|
675
672
|
if (action === void 0) return;
|
|
@@ -694,18 +691,18 @@ function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
|
|
|
694
691
|
},
|
|
695
692
|
[rowKeys, onToggleKey, onActivateKey, focusRow]
|
|
696
693
|
);
|
|
697
|
-
const keyDownFor =
|
|
694
|
+
const keyDownFor = react.useCallback(
|
|
698
695
|
(key) => {
|
|
699
696
|
if (!enabled || !IS_WEB) return void 0;
|
|
700
697
|
return (event) => handleKey(event, key);
|
|
701
698
|
},
|
|
702
699
|
[enabled, handleKey]
|
|
703
700
|
);
|
|
704
|
-
const tabIndexFor =
|
|
701
|
+
const tabIndexFor = react.useCallback(
|
|
705
702
|
(key) => key === tabbableKey ? TAB_INDEX_ACTIVE : TAB_INDEX_INACTIVE2,
|
|
706
703
|
[tabbableKey]
|
|
707
704
|
);
|
|
708
|
-
const onRowFocus =
|
|
705
|
+
const onRowFocus = react.useCallback((key) => setFocusedKey(key), []);
|
|
709
706
|
return { tabIndexFor, registerRow, onRowFocus, keyDownFor };
|
|
710
707
|
}
|
|
711
708
|
|
|
@@ -757,20 +754,20 @@ function useTableSelection({
|
|
|
757
754
|
const selected = selectedRowKeys ?? NO_KEYS;
|
|
758
755
|
const allMatching = allMatchingSelected ?? false;
|
|
759
756
|
const matching = matchingCount ?? NO_MATCHES;
|
|
760
|
-
const pageHeaderState =
|
|
757
|
+
const pageHeaderState = react.useMemo(
|
|
761
758
|
() => resolveHeaderCheckboxState(selected, pageKeys),
|
|
762
759
|
[selected, pageKeys]
|
|
763
760
|
);
|
|
764
761
|
const headerState = allMatching ? "all" /* All */ : pageHeaderState;
|
|
765
|
-
const bannerMode =
|
|
762
|
+
const bannerMode = react.useMemo(
|
|
766
763
|
() => onSelectAllMatchingChange === void 0 ? "hidden" /* Hidden */ : resolveSelectAllBannerMode(pageHeaderState, allMatching, pageKeys.length, matching),
|
|
767
764
|
[onSelectAllMatchingChange, pageHeaderState, allMatching, pageKeys.length, matching]
|
|
768
765
|
);
|
|
769
|
-
const isSelected =
|
|
766
|
+
const isSelected = react.useCallback(
|
|
770
767
|
(key) => isRowSelected(selected, key, allMatching),
|
|
771
768
|
[selected, allMatching]
|
|
772
769
|
);
|
|
773
|
-
const toggleRow =
|
|
770
|
+
const toggleRow = react.useCallback(
|
|
774
771
|
(key) => {
|
|
775
772
|
if (allMatching) {
|
|
776
773
|
onSelectAllMatchingChange?.(false);
|
|
@@ -781,7 +778,7 @@ function useTableSelection({
|
|
|
781
778
|
},
|
|
782
779
|
[allMatching, onSelectAllMatchingChange, onSelectionChange, pageKeys, selected]
|
|
783
780
|
);
|
|
784
|
-
const toggleAll =
|
|
781
|
+
const toggleAll = react.useCallback(() => {
|
|
785
782
|
if (allMatching) {
|
|
786
783
|
onSelectAllMatchingChange?.(false);
|
|
787
784
|
onSelectionChange?.(NO_KEYS);
|
|
@@ -789,7 +786,7 @@ function useTableSelection({
|
|
|
789
786
|
}
|
|
790
787
|
onSelectionChange?.(toggleAllOnPage(selected, pageKeys));
|
|
791
788
|
}, [allMatching, onSelectAllMatchingChange, onSelectionChange, selected, pageKeys]);
|
|
792
|
-
const toggleAllMatching =
|
|
789
|
+
const toggleAllMatching = react.useCallback(() => {
|
|
793
790
|
const next = !allMatching;
|
|
794
791
|
onSelectAllMatchingChange?.(next);
|
|
795
792
|
if (!next) onSelectionChange?.(NO_KEYS);
|
|
@@ -830,9 +827,9 @@ function DataTable(props) {
|
|
|
830
827
|
const stacked = width < stackBreakpoint;
|
|
831
828
|
const frame = { backgroundColor: colors.surface, borderColor: colors.border };
|
|
832
829
|
const interactive = onRowPress !== void 0;
|
|
833
|
-
const [hoveredKey, setHoveredKey] =
|
|
830
|
+
const [hoveredKey, setHoveredKey] = react.useState(void 0);
|
|
834
831
|
const hoverTint = softBrandTint(theme.palette.primary["500"]) ?? colors.background;
|
|
835
|
-
const rowKeys =
|
|
832
|
+
const rowKeys = react.useMemo(() => rows.map(keyExtractor), [rows, keyExtractor]);
|
|
836
833
|
const selection = useTableSelection({
|
|
837
834
|
pageKeys: rowKeys,
|
|
838
835
|
selectedRowKeys,
|
|
@@ -841,7 +838,7 @@ function DataTable(props) {
|
|
|
841
838
|
allMatchingSelected,
|
|
842
839
|
onSelectAllMatchingChange
|
|
843
840
|
});
|
|
844
|
-
const activateKey =
|
|
841
|
+
const activateKey = react.useCallback(
|
|
845
842
|
(key) => {
|
|
846
843
|
const row = rows[rowKeys.indexOf(key)];
|
|
847
844
|
if (row !== void 0) onRowPress?.(row);
|
|
@@ -854,7 +851,7 @@ function DataTable(props) {
|
|
|
854
851
|
onToggleKey: selection.selectable ? selection.toggleRow : void 0,
|
|
855
852
|
onActivateKey: interactive ? activateKey : void 0
|
|
856
853
|
});
|
|
857
|
-
const rowBackground =
|
|
854
|
+
const rowBackground = react.useCallback(
|
|
858
855
|
(row, index) => {
|
|
859
856
|
const tint = rowTint?.(row);
|
|
860
857
|
if (tint) return tint;
|
|
@@ -864,8 +861,9 @@ function DataTable(props) {
|
|
|
864
861
|
);
|
|
865
862
|
const rowBg = (row, index, key) => interactive && hoveredKey === key ? hoverTint : rowBackground(row, index);
|
|
866
863
|
const stateView = (label) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [tableStyles.wrap, frame, o?.wrap], testID, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [tableStyles.state, o?.state], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [tableStyles.stateText, { color: colors.textSecondary }, o?.stateText], children: label }) }) });
|
|
867
|
-
if (
|
|
868
|
-
|
|
864
|
+
if (rows.length === 0) {
|
|
865
|
+
return stateView(loading ? loadingLabel ?? t(TABLE_I18N.loading) : emptyLabel ?? t(TABLE_I18N.empty));
|
|
866
|
+
}
|
|
869
867
|
const renderRow = (row, key, style) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
870
868
|
DataTableRow,
|
|
871
869
|
{
|
|
@@ -901,7 +899,7 @@ function DataTable(props) {
|
|
|
901
899
|
}
|
|
902
900
|
);
|
|
903
901
|
if (stacked) {
|
|
904
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [tableStyles.wrap, frame, o?.wrap], testID, children: [
|
|
902
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [tableStyles.wrap, frame, o?.wrap], testID, "aria-busy": loading, children: [
|
|
905
903
|
banner,
|
|
906
904
|
rows.map((row, i) => {
|
|
907
905
|
const key = rowKeys[i] ?? keyExtractor(row);
|
|
@@ -923,6 +921,7 @@ function DataTable(props) {
|
|
|
923
921
|
{
|
|
924
922
|
style: [tableStyles.wrap, frame, o?.wrap],
|
|
925
923
|
testID,
|
|
924
|
+
"aria-busy": loading,
|
|
926
925
|
...keyboardNavigation ? { role: "grid" } : null,
|
|
927
926
|
children: [
|
|
928
927
|
banner,
|
|
@@ -1005,8 +1004,8 @@ function buildWebFixedStyle(rect, viewportWidth) {
|
|
|
1005
1004
|
};
|
|
1006
1005
|
}
|
|
1007
1006
|
function useTriggerRect(anchorRef, isOpen) {
|
|
1008
|
-
const [rect, setRect] =
|
|
1009
|
-
|
|
1007
|
+
const [rect, setRect] = react.useState(null);
|
|
1008
|
+
react.useLayoutEffect(() => {
|
|
1010
1009
|
if (!IS_WEB2 || !isOpen) return void 0;
|
|
1011
1010
|
const measure = () => {
|
|
1012
1011
|
setRect(readTriggerRect(anchorRef));
|
|
@@ -1022,7 +1021,7 @@ function useTriggerRect(anchorRef, isOpen) {
|
|
|
1022
1021
|
return rect;
|
|
1023
1022
|
}
|
|
1024
1023
|
function useDismissOnOutside(anchorRef, menuRef, isOpen, onClose) {
|
|
1025
|
-
|
|
1024
|
+
react.useEffect(() => {
|
|
1026
1025
|
if (!IS_WEB2 || !isOpen) return void 0;
|
|
1027
1026
|
const onMouseDown = (event) => {
|
|
1028
1027
|
const anchorNode = anchorRef.current;
|
|
@@ -1060,16 +1059,16 @@ function SizeDropdown({
|
|
|
1060
1059
|
triggerStyle,
|
|
1061
1060
|
triggerTextStyle
|
|
1062
1061
|
}) {
|
|
1063
|
-
const anchorRef =
|
|
1064
|
-
const menuRef =
|
|
1065
|
-
const [isOpen, setIsOpen] =
|
|
1066
|
-
const close =
|
|
1062
|
+
const anchorRef = react.useRef(null);
|
|
1063
|
+
const menuRef = react.useRef(null);
|
|
1064
|
+
const [isOpen, setIsOpen] = react.useState(false);
|
|
1065
|
+
const close = react.useCallback(() => {
|
|
1067
1066
|
setIsOpen(false);
|
|
1068
1067
|
}, []);
|
|
1069
|
-
const toggle =
|
|
1068
|
+
const toggle = react.useCallback(() => {
|
|
1070
1069
|
setIsOpen((prev) => !prev);
|
|
1071
1070
|
}, []);
|
|
1072
|
-
const select =
|
|
1071
|
+
const select = react.useCallback(
|
|
1073
1072
|
(size) => {
|
|
1074
1073
|
onPageSizeChange(size);
|
|
1075
1074
|
setIsOpen(false);
|
|
@@ -1353,80 +1352,23 @@ function Pager({
|
|
|
1353
1352
|
] });
|
|
1354
1353
|
}
|
|
1355
1354
|
var FIELD_GAP = 4;
|
|
1356
|
-
var LABEL_FONT = 11;
|
|
1357
|
-
var LABEL_LETTER_SPACING2 = 0.4;
|
|
1358
|
-
var INPUT_RADIUS = 8;
|
|
1359
|
-
var INPUT_PAD_H = 12;
|
|
1360
|
-
var INPUT_PAD_V = 10;
|
|
1361
|
-
var INPUT_FONT = 14;
|
|
1362
|
-
var INPUT_BORDER = 1;
|
|
1363
|
-
var DATE_ROW_GAP = 8;
|
|
1364
|
-
var CHEVRON_FONT2 = 10;
|
|
1365
|
-
var MENU_TOP_GAP3 = 4;
|
|
1366
|
-
var MENU_RADIUS = 8;
|
|
1367
|
-
var MENU_PAD_V2 = 4;
|
|
1368
|
-
var MENU_OPT_PAD_H = 12;
|
|
1369
|
-
var MENU_OPT_PAD_V2 = 8;
|
|
1370
|
-
var MENU_MIN_WIDTH2 = 160;
|
|
1371
|
-
var MENU_MAX_HEIGHT = 260;
|
|
1372
|
-
var MENU_Z = 1e3;
|
|
1373
|
-
var MENU_ELEVATION2 = 8;
|
|
1374
|
-
var MENU_BOX_SHADOW2 = "0px 2px 8px rgba(0, 0, 0, 0.15)";
|
|
1375
|
-
var OPTION_FONT = 14;
|
|
1376
|
-
var ERROR_FONT = 12;
|
|
1377
|
-
var ERROR_GAP = 3;
|
|
1378
1355
|
var SWITCH_ROW_GAP = 8;
|
|
1379
1356
|
var ACTION_PAD_H = 14;
|
|
1380
1357
|
var ACTION_PAD_V = 8;
|
|
1381
1358
|
var ACTION_RADIUS = 8;
|
|
1382
1359
|
var ACTION_FONT = 13;
|
|
1360
|
+
var ACTION_BORDER = 1;
|
|
1361
|
+
var NO_FORM_RHYTHM = 0;
|
|
1383
1362
|
var filterStyles = reactNative.StyleSheet.create({
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
fontSize: INPUT_FONT
|
|
1392
|
-
},
|
|
1393
|
-
/** The select trigger: a bordered field box matching the text inputs + a chevron. */
|
|
1394
|
-
selectTrigger: {
|
|
1395
|
-
flexDirection: "row",
|
|
1396
|
-
alignItems: "center",
|
|
1397
|
-
justifyContent: "space-between",
|
|
1398
|
-
gap: DATE_ROW_GAP,
|
|
1399
|
-
borderWidth: INPUT_BORDER,
|
|
1400
|
-
borderRadius: INPUT_RADIUS,
|
|
1401
|
-
paddingHorizontal: INPUT_PAD_H,
|
|
1402
|
-
paddingVertical: INPUT_PAD_V
|
|
1403
|
-
},
|
|
1404
|
-
selectTriggerText: { fontSize: INPUT_FONT, flexShrink: 1 },
|
|
1405
|
-
chevron: { fontSize: CHEVRON_FONT2 },
|
|
1406
|
-
dateRow: { flexDirection: "row", gap: DATE_ROW_GAP },
|
|
1407
|
-
dateCol: { gap: FIELD_GAP, flex: 1 },
|
|
1408
|
-
subLabel: { fontSize: LABEL_FONT, letterSpacing: LABEL_LETTER_SPACING2 },
|
|
1409
|
-
anchor: { position: "relative" },
|
|
1410
|
-
menu: {
|
|
1411
|
-
position: "absolute",
|
|
1412
|
-
top: "100%",
|
|
1413
|
-
left: 0,
|
|
1414
|
-
marginTop: MENU_TOP_GAP3,
|
|
1415
|
-
minWidth: MENU_MIN_WIDTH2,
|
|
1416
|
-
maxHeight: MENU_MAX_HEIGHT,
|
|
1417
|
-
borderWidth: INPUT_BORDER,
|
|
1418
|
-
borderRadius: MENU_RADIUS,
|
|
1419
|
-
paddingVertical: MENU_PAD_V2,
|
|
1420
|
-
zIndex: MENU_Z,
|
|
1421
|
-
boxShadow: MENU_BOX_SHADOW2,
|
|
1422
|
-
elevation: MENU_ELEVATION2,
|
|
1423
|
-
overflow: "hidden"
|
|
1424
|
-
},
|
|
1425
|
-
option: { paddingHorizontal: MENU_OPT_PAD_H, paddingVertical: MENU_OPT_PAD_V2 },
|
|
1426
|
-
optionText: { fontSize: OPTION_FONT },
|
|
1427
|
-
error: { fontSize: ERROR_FONT, marginTop: ERROR_GAP },
|
|
1363
|
+
/**
|
|
1364
|
+
* Merged onto `Field`'s container inside the bar. Zeroes the 16px bottom margin `Field` gives
|
|
1365
|
+
* a stacked form row: the bar is a flex ROW whose spacing comes from FilterBar's `gap`, so
|
|
1366
|
+
* inheriting the form rhythm would add a phantom gap under every field — a pixel change for
|
|
1367
|
+
* six live portals, which this wave must not make.
|
|
1368
|
+
*/
|
|
1369
|
+
fieldInBar: { marginBottom: NO_FORM_RHYTHM },
|
|
1428
1370
|
switchRow: { flexDirection: "row", alignItems: "center", gap: SWITCH_ROW_GAP, paddingVertical: FIELD_GAP },
|
|
1429
|
-
action: { paddingHorizontal: ACTION_PAD_H, paddingVertical: ACTION_PAD_V, borderRadius: ACTION_RADIUS, borderWidth:
|
|
1371
|
+
action: { paddingHorizontal: ACTION_PAD_H, paddingVertical: ACTION_PAD_V, borderRadius: ACTION_RADIUS, borderWidth: ACTION_BORDER },
|
|
1430
1372
|
actionText: { fontSize: ACTION_FONT, fontWeight: "600" }
|
|
1431
1373
|
});
|
|
1432
1374
|
var FILTER_HIT_SLOP = { top: 8, bottom: 8 };
|
|
@@ -1461,8 +1403,6 @@ function ActionButton({ label, hint, tone, disabled = false, onPress, testID })
|
|
|
1461
1403
|
}
|
|
1462
1404
|
);
|
|
1463
1405
|
}
|
|
1464
|
-
|
|
1465
|
-
// src/Filters/constants.ts
|
|
1466
1406
|
var FILTERS_TEST_ID = "ui-filters-declarative";
|
|
1467
1407
|
var FIELD_MIN_WIDTH = {
|
|
1468
1408
|
select: 150,
|
|
@@ -1472,8 +1412,6 @@ var FIELD_MIN_WIDTH = {
|
|
|
1472
1412
|
typeahead: 200,
|
|
1473
1413
|
boolean: 150
|
|
1474
1414
|
};
|
|
1475
|
-
var DEFAULT_TYPEAHEAD_MIN_CHARS = 1;
|
|
1476
|
-
var DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = 8;
|
|
1477
1415
|
var fieldTestID = (barTestID, key) => `${barTestID}-field-${key}`;
|
|
1478
1416
|
var applyTestID = (barTestID) => `${barTestID}-apply`;
|
|
1479
1417
|
var clearTestID = (barTestID) => `${barTestID}-clear`;
|
|
@@ -1495,29 +1433,12 @@ var FILTERS_I18N = {
|
|
|
1495
1433
|
from: "uiTables.filters.from",
|
|
1496
1434
|
to: "uiTables.filters.to"
|
|
1497
1435
|
};
|
|
1498
|
-
var GROW_FLEX = 1;
|
|
1499
|
-
function FieldShell({ field, barTestID, children }) {
|
|
1500
|
-
const { theme } = uiFeedback.useUi();
|
|
1501
|
-
const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
|
|
1502
|
-
const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
|
|
1503
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1504
|
-
reactNative.View,
|
|
1505
|
-
{
|
|
1506
|
-
style: [filterStyles.field, { minWidth }, grow, field.style],
|
|
1507
|
-
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1508
|
-
children: [
|
|
1509
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.label, { color: theme.colors.textSecondary }], children: field.label }),
|
|
1510
|
-
children
|
|
1511
|
-
]
|
|
1512
|
-
}
|
|
1513
|
-
);
|
|
1514
|
-
}
|
|
1515
1436
|
function BooleanField({ field, barTestID, value, onChange }) {
|
|
1516
1437
|
const { theme } = uiFeedback.useUi();
|
|
1517
1438
|
const { colors, palette } = theme;
|
|
1518
1439
|
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1519
1440
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.switchRow, testID, children: [
|
|
1520
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [
|
|
1441
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [uiForms.controlStyles.subLabel, { color: colors.text }], children: field.label }),
|
|
1521
1442
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1522
1443
|
reactNative.Switch,
|
|
1523
1444
|
{
|
|
@@ -1534,195 +1455,45 @@ function BooleanField({ field, barTestID, value, onChange }) {
|
|
|
1534
1455
|
)
|
|
1535
1456
|
] });
|
|
1536
1457
|
}
|
|
1537
|
-
var WEB_DATE_PROPS = typeof document !== "undefined" ? { type: "date" } : {};
|
|
1538
|
-
function DateInput(p) {
|
|
1539
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.dateCol, children: [
|
|
1540
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.subLabel, { color: p.muted }], children: p.label }),
|
|
1541
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1542
|
-
reactNative.TextInput,
|
|
1543
|
-
{
|
|
1544
|
-
accessibilityLabel: p.label,
|
|
1545
|
-
accessibilityHint: p.hint,
|
|
1546
|
-
placeholder: p.placeholder,
|
|
1547
|
-
placeholderTextColor: p.muted,
|
|
1548
|
-
value: p.value,
|
|
1549
|
-
onChangeText: p.onChangeText,
|
|
1550
|
-
onSubmitEditing: p.onSubmit,
|
|
1551
|
-
style: [filterStyles.input, { borderColor: p.border, backgroundColor: p.surface, color: p.color }],
|
|
1552
|
-
testID: `${p.testID}-${p.side}`,
|
|
1553
|
-
...WEB_DATE_PROPS
|
|
1554
|
-
}
|
|
1555
|
-
)
|
|
1556
|
-
] });
|
|
1557
|
-
}
|
|
1558
1458
|
function DateRangeField({ field, barTestID, value, onChange, onSubmit, fromLabel, toLabel }) {
|
|
1559
|
-
const { theme } = uiFeedback.useUi();
|
|
1560
|
-
const { colors } = theme;
|
|
1561
|
-
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1562
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: filterStyles.dateRow, testID: `${testID}-range`, children: [
|
|
1563
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1564
|
-
DateInput,
|
|
1565
|
-
{
|
|
1566
|
-
side: "from",
|
|
1567
|
-
label: field.fromLabel ?? fromLabel,
|
|
1568
|
-
placeholder: field.fromPlaceholder,
|
|
1569
|
-
value: value.from,
|
|
1570
|
-
color: colors.text,
|
|
1571
|
-
border: colors.border,
|
|
1572
|
-
surface: colors.surface,
|
|
1573
|
-
muted: colors.textSecondary,
|
|
1574
|
-
hint: field.accessibilityHint,
|
|
1575
|
-
testID,
|
|
1576
|
-
onChangeText: (from) => onChange({ from, to: value.to }),
|
|
1577
|
-
onSubmit
|
|
1578
|
-
}
|
|
1579
|
-
),
|
|
1580
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1581
|
-
DateInput,
|
|
1582
|
-
{
|
|
1583
|
-
side: "to",
|
|
1584
|
-
label: field.toLabel ?? toLabel,
|
|
1585
|
-
placeholder: field.toPlaceholder,
|
|
1586
|
-
value: value.to,
|
|
1587
|
-
color: colors.text,
|
|
1588
|
-
border: colors.border,
|
|
1589
|
-
surface: colors.surface,
|
|
1590
|
-
muted: colors.textSecondary,
|
|
1591
|
-
hint: field.accessibilityHint,
|
|
1592
|
-
testID,
|
|
1593
|
-
onChangeText: (to) => onChange({ from: value.from, to }),
|
|
1594
|
-
onSubmit
|
|
1595
|
-
}
|
|
1596
|
-
)
|
|
1597
|
-
] });
|
|
1598
|
-
}
|
|
1599
|
-
var IS_WEB3 = typeof document !== "undefined";
|
|
1600
|
-
var ESCAPE_KEY = "Escape";
|
|
1601
|
-
var ACTIVE_WEIGHT = "700";
|
|
1602
|
-
var IDLE_WEIGHT = "400";
|
|
1603
|
-
function useDismiss(anchorRef, menuRef, onDismiss) {
|
|
1604
|
-
React4.useEffect(() => {
|
|
1605
|
-
if (!IS_WEB3) return void 0;
|
|
1606
|
-
const onMouseDown = (event) => {
|
|
1607
|
-
const anchorNode = anchorRef.current;
|
|
1608
|
-
const menuNode = menuRef.current;
|
|
1609
|
-
const target = event.target instanceof Node ? event.target : null;
|
|
1610
|
-
const insideAnchor = anchorNode !== null && target !== null && anchorNode.contains(target);
|
|
1611
|
-
const insideMenu = menuNode !== null && target !== null && menuNode.contains(target);
|
|
1612
|
-
if (!insideAnchor && !insideMenu) onDismiss();
|
|
1613
|
-
};
|
|
1614
|
-
const onKeyDown = (event) => {
|
|
1615
|
-
if (event.key === ESCAPE_KEY) onDismiss();
|
|
1616
|
-
};
|
|
1617
|
-
document.addEventListener("mousedown", onMouseDown);
|
|
1618
|
-
document.addEventListener("keydown", onKeyDown);
|
|
1619
|
-
return () => {
|
|
1620
|
-
document.removeEventListener("mousedown", onMouseDown);
|
|
1621
|
-
document.removeEventListener("keydown", onKeyDown);
|
|
1622
|
-
};
|
|
1623
|
-
}, [anchorRef, menuRef, onDismiss]);
|
|
1624
|
-
}
|
|
1625
|
-
function AnchoredMenu({
|
|
1626
|
-
options,
|
|
1627
|
-
selectedValue,
|
|
1628
|
-
onSelect,
|
|
1629
|
-
onDismiss,
|
|
1630
|
-
colors,
|
|
1631
|
-
optionHint,
|
|
1632
|
-
testID,
|
|
1633
|
-
anchorRef
|
|
1634
|
-
}) {
|
|
1635
|
-
const menuRef = React4__default.default.useRef(null);
|
|
1636
|
-
useDismiss(anchorRef, menuRef, onDismiss);
|
|
1637
1459
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1638
|
-
|
|
1460
|
+
uiForms.DateRangeControl,
|
|
1639
1461
|
{
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
testID:
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
accessibilityRole: "menuitem",
|
|
1650
|
-
accessibilityLabel: opt.label,
|
|
1651
|
-
accessibilityHint: optionHint,
|
|
1652
|
-
accessibilityState: { selected: active },
|
|
1653
|
-
onPress: () => onSelect(opt.value),
|
|
1654
|
-
style: filterStyles.option,
|
|
1655
|
-
testID: `${testID}-option-${opt.value}`,
|
|
1656
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [filterStyles.optionText, { color: active ? colors.brand : colors.text, fontWeight: active ? ACTIVE_WEIGHT : IDLE_WEIGHT }], children: opt.label })
|
|
1657
|
-
},
|
|
1658
|
-
opt.value
|
|
1659
|
-
);
|
|
1660
|
-
})
|
|
1462
|
+
accessibilityHint: field.accessibilityHint,
|
|
1463
|
+
fromLabel: field.fromLabel ?? fromLabel,
|
|
1464
|
+
fromPlaceholder: field.fromPlaceholder,
|
|
1465
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1466
|
+
toLabel: field.toLabel ?? toLabel,
|
|
1467
|
+
toPlaceholder: field.toPlaceholder,
|
|
1468
|
+
value,
|
|
1469
|
+
onChange,
|
|
1470
|
+
onSubmit
|
|
1661
1471
|
}
|
|
1662
1472
|
);
|
|
1663
1473
|
}
|
|
1664
|
-
var CHEVRON_DOWN2 = "\u25BE";
|
|
1665
|
-
var CHEVRON_UP2 = "\u25B4";
|
|
1666
1474
|
function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
|
|
1667
|
-
const {
|
|
1668
|
-
const { colors, palette } = theme;
|
|
1669
|
-
const anchorRef = React4.useRef(null);
|
|
1670
|
-
const [isOpen, setIsOpen] = React4.useState(false);
|
|
1475
|
+
const { t } = uiFeedback.useUi();
|
|
1671
1476
|
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1672
|
-
const
|
|
1673
|
-
|
|
1674
|
-
return found?.label ?? field.placeholder ?? placeholder;
|
|
1675
|
-
}, [field.options, field.placeholder, placeholder, value]);
|
|
1477
|
+
const resolvedPlaceholder = field.placeholder ?? placeholder;
|
|
1478
|
+
const selectedLabel = field.options.find((o) => o.value === value)?.label ?? resolvedPlaceholder;
|
|
1676
1479
|
const triggerLabel = accessibleName(
|
|
1677
1480
|
t(FILTERS_I18N.selectTriggerLabel, field.label, selectedLabel),
|
|
1678
1481
|
FILTERS_I18N.selectTriggerLabel,
|
|
1679
1482
|
field.label
|
|
1680
1483
|
);
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1484
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1485
|
+
uiForms.SelectControl,
|
|
1486
|
+
{
|
|
1487
|
+
accessibilityHint: field.accessibilityHint ?? dropdownHint,
|
|
1488
|
+
accessibilityLabel: triggerLabel,
|
|
1489
|
+
options: field.options,
|
|
1490
|
+
optionHint,
|
|
1491
|
+
placeholder: resolvedPlaceholder,
|
|
1492
|
+
testID,
|
|
1493
|
+
value,
|
|
1494
|
+
onChange
|
|
1495
|
+
}
|
|
1693
1496
|
);
|
|
1694
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: filterStyles.anchor, children: [
|
|
1695
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1696
|
-
reactNative.Pressable,
|
|
1697
|
-
{
|
|
1698
|
-
accessibilityRole: "button",
|
|
1699
|
-
accessibilityLabel: triggerLabel,
|
|
1700
|
-
accessibilityHint: field.accessibilityHint ?? dropdownHint,
|
|
1701
|
-
accessibilityState: { expanded: isOpen },
|
|
1702
|
-
"aria-expanded": isOpen,
|
|
1703
|
-
onPress: toggle,
|
|
1704
|
-
style: [filterStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surface }],
|
|
1705
|
-
testID: `${testID}-trigger`,
|
|
1706
|
-
children: [
|
|
1707
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { numberOfLines: 1, style: [filterStyles.selectTriggerText, { color: value === "" ? colors.textSecondary : colors.text }], children: selectedLabel }),
|
|
1708
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { "aria-hidden": true, style: [filterStyles.chevron, { color: colors.textSecondary }], children: isOpen ? CHEVRON_UP2 : CHEVRON_DOWN2 })
|
|
1709
|
-
]
|
|
1710
|
-
}
|
|
1711
|
-
),
|
|
1712
|
-
isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1713
|
-
AnchoredMenu,
|
|
1714
|
-
{
|
|
1715
|
-
options: field.options,
|
|
1716
|
-
selectedValue: value,
|
|
1717
|
-
onSelect: select,
|
|
1718
|
-
onDismiss: close,
|
|
1719
|
-
colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
|
|
1720
|
-
optionHint,
|
|
1721
|
-
testID,
|
|
1722
|
-
anchorRef
|
|
1723
|
-
}
|
|
1724
|
-
) : null
|
|
1725
|
-
] });
|
|
1726
1497
|
}
|
|
1727
1498
|
function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
1728
1499
|
const { theme } = uiFeedback.useUi();
|
|
@@ -1739,121 +1510,32 @@ function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
|
1739
1510
|
value,
|
|
1740
1511
|
onChangeText: onChange,
|
|
1741
1512
|
onSubmitEditing: onSubmit,
|
|
1742
|
-
style: [
|
|
1513
|
+
style: [uiForms.controlStyles.input, { borderColor: colors.border, backgroundColor: colors.surface, color: colors.text }],
|
|
1743
1514
|
testID: `${field.testID ?? fieldTestID(barTestID, field.key)}-input`
|
|
1744
1515
|
}
|
|
1745
1516
|
);
|
|
1746
1517
|
}
|
|
1747
|
-
|
|
1748
|
-
// src/Filters/utils/suggest.ts
|
|
1749
|
-
var RANK_VALUE_EXACT = 0;
|
|
1750
|
-
var RANK_VALUE_PREFIX = 1;
|
|
1751
|
-
var RANK_LABEL_PREFIX = 2;
|
|
1752
|
-
var RANK_LABEL_CONTAINS = 3;
|
|
1753
|
-
var NO_MATCH = -1;
|
|
1754
|
-
function rankOf(option, needle) {
|
|
1755
|
-
const value = option.value.toLowerCase();
|
|
1756
|
-
const label = option.label.toLowerCase();
|
|
1757
|
-
if (value === needle) return RANK_VALUE_EXACT;
|
|
1758
|
-
if (value.startsWith(needle)) return RANK_VALUE_PREFIX;
|
|
1759
|
-
if (label.startsWith(needle)) return RANK_LABEL_PREFIX;
|
|
1760
|
-
if (label.includes(needle)) return RANK_LABEL_CONTAINS;
|
|
1761
|
-
return NO_MATCH;
|
|
1762
|
-
}
|
|
1763
|
-
function suggestOptions(options, query, minChars, limit) {
|
|
1764
|
-
const needle = query.trim().toLowerCase();
|
|
1765
|
-
if (needle.length < minChars) return [];
|
|
1766
|
-
const scored = [];
|
|
1767
|
-
for (const option of options) {
|
|
1768
|
-
const rank = rankOf(option, needle);
|
|
1769
|
-
if (rank !== NO_MATCH) scored.push({ option, rank });
|
|
1770
|
-
}
|
|
1771
|
-
scored.sort((a, b) => a.rank !== b.rank ? a.rank - b.rank : a.option.label.localeCompare(b.option.label));
|
|
1772
|
-
return scored.slice(0, limit).map((entry) => entry.option);
|
|
1773
|
-
}
|
|
1774
|
-
function isUnmatched(options, text) {
|
|
1775
|
-
const needle = text.trim().toLowerCase();
|
|
1776
|
-
if (needle === "") return false;
|
|
1777
|
-
return !options.some((o) => o.value.toLowerCase() === needle || o.label.toLowerCase() === needle);
|
|
1778
|
-
}
|
|
1779
|
-
var CLOSE_DELAY_MS = 140;
|
|
1780
1518
|
function TypeaheadField({ field, barTestID, value, onChange, onSubmit, optionHint }) {
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
const handleChange = React4.useCallback(
|
|
1798
|
-
(next) => {
|
|
1799
|
-
onChange(next);
|
|
1800
|
-
setIsOpen(true);
|
|
1801
|
-
},
|
|
1802
|
-
[onChange]
|
|
1803
|
-
);
|
|
1804
|
-
const pick = React4.useCallback(
|
|
1805
|
-
(optionValue) => {
|
|
1806
|
-
const opt = field.options.find((o) => o.value === optionValue);
|
|
1807
|
-
onChange(opt?.label ?? optionValue);
|
|
1808
|
-
setIsOpen(false);
|
|
1809
|
-
},
|
|
1810
|
-
[field.options, onChange]
|
|
1519
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1520
|
+
uiForms.TypeaheadControl,
|
|
1521
|
+
{
|
|
1522
|
+
accessibilityHint: field.accessibilityHint,
|
|
1523
|
+
accessibilityLabel: field.label,
|
|
1524
|
+
error: field.error,
|
|
1525
|
+
maxSuggestions: field.maxSuggestions ?? uiForms.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS,
|
|
1526
|
+
minChars: field.minChars ?? uiForms.DEFAULT_TYPEAHEAD_MIN_CHARS,
|
|
1527
|
+
options: field.options,
|
|
1528
|
+
optionHint,
|
|
1529
|
+
placeholder: field.placeholder,
|
|
1530
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1531
|
+
value,
|
|
1532
|
+
onChange,
|
|
1533
|
+
onSubmit
|
|
1534
|
+
}
|
|
1811
1535
|
);
|
|
1812
|
-
const handleBlur = React4.useCallback(() => {
|
|
1813
|
-
setTimeout(() => setIsOpen(false), CLOSE_DELAY_MS);
|
|
1814
|
-
}, []);
|
|
1815
|
-
const handleSubmit = React4.useCallback(() => {
|
|
1816
|
-
setIsOpen(false);
|
|
1817
|
-
onSubmit();
|
|
1818
|
-
}, [onSubmit]);
|
|
1819
|
-
const hasError = field.error !== void 0 && field.error !== "";
|
|
1820
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: filterStyles.anchor, children: [
|
|
1821
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1822
|
-
reactNative.TextInput,
|
|
1823
|
-
{
|
|
1824
|
-
accessibilityLabel: field.label,
|
|
1825
|
-
accessibilityHint: field.accessibilityHint,
|
|
1826
|
-
autoCapitalize: "none",
|
|
1827
|
-
autoCorrect: false,
|
|
1828
|
-
placeholder: field.placeholder,
|
|
1829
|
-
placeholderTextColor: colors.textSecondary,
|
|
1830
|
-
spellCheck: false,
|
|
1831
|
-
value,
|
|
1832
|
-
onChangeText: handleChange,
|
|
1833
|
-
onFocus: () => setIsOpen(true),
|
|
1834
|
-
onBlur: handleBlur,
|
|
1835
|
-
onSubmitEditing: handleSubmit,
|
|
1836
|
-
style: [filterStyles.input, { borderColor: hasError ? semantic.error["500"] : colors.border, backgroundColor: colors.surface, color: colors.text }],
|
|
1837
|
-
testID: `${testID}-input`
|
|
1838
|
-
}
|
|
1839
|
-
),
|
|
1840
|
-
showMenu ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1841
|
-
AnchoredMenu,
|
|
1842
|
-
{
|
|
1843
|
-
options: suggestions,
|
|
1844
|
-
selectedValue: value,
|
|
1845
|
-
onSelect: pick,
|
|
1846
|
-
onDismiss: () => setIsOpen(false),
|
|
1847
|
-
colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
|
|
1848
|
-
optionHint,
|
|
1849
|
-
testID,
|
|
1850
|
-
anchorRef
|
|
1851
|
-
}
|
|
1852
|
-
) : null,
|
|
1853
|
-
hasError ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [filterStyles.error, { color: semantic.error["500"] }], testID: `${testID}-error`, children: field.error }) : null
|
|
1854
|
-
] });
|
|
1855
1536
|
}
|
|
1856
1537
|
var EMPTY_RANGE = { from: "", to: "" };
|
|
1538
|
+
var GROW_FLEX = 1;
|
|
1857
1539
|
function asString(value) {
|
|
1858
1540
|
return typeof value === "string" ? value : "";
|
|
1859
1541
|
}
|
|
@@ -1930,7 +1612,18 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
|
|
|
1930
1612
|
);
|
|
1931
1613
|
}
|
|
1932
1614
|
})();
|
|
1933
|
-
|
|
1615
|
+
const minWidth = field.minWidth ?? FIELD_MIN_WIDTH[field.kind];
|
|
1616
|
+
const grow = field.grow === true ? { flexGrow: GROW_FLEX } : null;
|
|
1617
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1618
|
+
uiForms.Field,
|
|
1619
|
+
{
|
|
1620
|
+
containerStyle: [filterStyles.fieldInBar, { minWidth }, grow, field.style],
|
|
1621
|
+
label: field.label,
|
|
1622
|
+
labelVariant: "control",
|
|
1623
|
+
testID: field.testID ?? fieldTestID(barTestID, field.key),
|
|
1624
|
+
children: body
|
|
1625
|
+
}
|
|
1626
|
+
);
|
|
1934
1627
|
}
|
|
1935
1628
|
function Filters({
|
|
1936
1629
|
fields,
|
|
@@ -1954,16 +1647,16 @@ function Filters({
|
|
|
1954
1647
|
testID = FILTERS_TEST_ID
|
|
1955
1648
|
}) {
|
|
1956
1649
|
const { t } = uiFeedback.useUi();
|
|
1957
|
-
const setField =
|
|
1650
|
+
const setField = react.useCallback(
|
|
1958
1651
|
(key, value) => {
|
|
1959
1652
|
onChange({ ...values, [key]: value });
|
|
1960
1653
|
},
|
|
1961
1654
|
[onChange, values]
|
|
1962
1655
|
);
|
|
1963
|
-
const onSubmit =
|
|
1656
|
+
const onSubmit = react.useCallback(() => {
|
|
1964
1657
|
if (onApply !== void 0 && !applyDisabled) onApply();
|
|
1965
1658
|
}, [onApply, applyDisabled]);
|
|
1966
|
-
const strings =
|
|
1659
|
+
const strings = react.useMemo(
|
|
1967
1660
|
() => ({
|
|
1968
1661
|
selectPlaceholder: selectPlaceholder ?? t(FILTERS_I18N.selectPlaceholder),
|
|
1969
1662
|
dropdownHint: t(FILTERS_I18N.dropdownHint),
|
|
@@ -2026,37 +1719,37 @@ function shallowEqual(a, b) {
|
|
|
2026
1719
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
2027
1720
|
}
|
|
2028
1721
|
function useFilterDraft({ initial, onApply, onReset }) {
|
|
2029
|
-
const [draft, setDraft] =
|
|
2030
|
-
const [committed, setCommitted] =
|
|
2031
|
-
const setField =
|
|
1722
|
+
const [draft, setDraft] = react.useState(initial);
|
|
1723
|
+
const [committed, setCommitted] = react.useState(initial);
|
|
1724
|
+
const setField = react.useCallback((key, value) => {
|
|
2032
1725
|
setDraft((prev) => ({ ...prev, [key]: value }));
|
|
2033
1726
|
}, []);
|
|
2034
|
-
const apply =
|
|
1727
|
+
const apply = react.useCallback(() => {
|
|
2035
1728
|
setCommitted(draft);
|
|
2036
1729
|
onApply?.(draft);
|
|
2037
1730
|
}, [draft, onApply]);
|
|
2038
|
-
const reset =
|
|
1731
|
+
const reset = react.useCallback(() => {
|
|
2039
1732
|
setDraft(initial);
|
|
2040
1733
|
setCommitted(initial);
|
|
2041
1734
|
onReset?.();
|
|
2042
1735
|
}, [initial, onReset]);
|
|
2043
|
-
const dirty =
|
|
1736
|
+
const dirty = react.useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
|
|
2044
1737
|
return { draft, committed, setField, setDraft, apply, reset, dirty };
|
|
2045
1738
|
}
|
|
2046
1739
|
var DEFAULT_PAGE_SIZE = 10;
|
|
2047
1740
|
function usePagedRows(rows, options = {}) {
|
|
2048
1741
|
const pageSize = Math.max(1, options.pageSize ?? DEFAULT_PAGE_SIZE);
|
|
2049
|
-
const [currentPage, setCurrentPage] =
|
|
1742
|
+
const [currentPage, setCurrentPage] = react.useState(0);
|
|
2050
1743
|
const totalPages = Math.ceil(rows.length / pageSize);
|
|
2051
|
-
|
|
1744
|
+
react.useEffect(() => {
|
|
2052
1745
|
const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
2053
1746
|
if (currentPage > lastValidPage) setCurrentPage(lastValidPage);
|
|
2054
1747
|
}, [currentPage, totalPages]);
|
|
2055
|
-
const pageRows =
|
|
1748
|
+
const pageRows = react.useMemo(() => {
|
|
2056
1749
|
const start = currentPage * pageSize;
|
|
2057
1750
|
return rows.slice(start, start + pageSize);
|
|
2058
1751
|
}, [rows, currentPage, pageSize]);
|
|
2059
|
-
const setPage =
|
|
1752
|
+
const setPage = react.useCallback(
|
|
2060
1753
|
(page) => {
|
|
2061
1754
|
const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
2062
1755
|
const clamped = Math.min(Math.max(0, page), lastValidPage);
|
|
@@ -2074,11 +1767,25 @@ function usePagedRows(rows, options = {}) {
|
|
|
2074
1767
|
};
|
|
2075
1768
|
}
|
|
2076
1769
|
|
|
1770
|
+
Object.defineProperty(exports, "DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS", {
|
|
1771
|
+
enumerable: true,
|
|
1772
|
+
get: function () { return uiForms.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS; }
|
|
1773
|
+
});
|
|
1774
|
+
Object.defineProperty(exports, "DEFAULT_TYPEAHEAD_MIN_CHARS", {
|
|
1775
|
+
enumerable: true,
|
|
1776
|
+
get: function () { return uiForms.DEFAULT_TYPEAHEAD_MIN_CHARS; }
|
|
1777
|
+
});
|
|
1778
|
+
Object.defineProperty(exports, "isUnmatched", {
|
|
1779
|
+
enumerable: true,
|
|
1780
|
+
get: function () { return uiForms.isUnmatched; }
|
|
1781
|
+
});
|
|
1782
|
+
Object.defineProperty(exports, "suggestOptions", {
|
|
1783
|
+
enumerable: true,
|
|
1784
|
+
get: function () { return uiForms.suggestOptions; }
|
|
1785
|
+
});
|
|
2077
1786
|
exports.CARD_STACK_BREAKPOINT = CARD_STACK_BREAKPOINT;
|
|
2078
1787
|
exports.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
|
|
2079
1788
|
exports.DEFAULT_PAGE_SIZE_OPTIONS = DEFAULT_PAGE_SIZE_OPTIONS;
|
|
2080
|
-
exports.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
|
|
2081
|
-
exports.DEFAULT_TYPEAHEAD_MIN_CHARS = DEFAULT_TYPEAHEAD_MIN_CHARS;
|
|
2082
1789
|
exports.DataTable = DataTable;
|
|
2083
1790
|
exports.FIELD_MIN_WIDTH = FIELD_MIN_WIDTH;
|
|
2084
1791
|
exports.FILTERS_I18N = FILTERS_I18N;
|
|
@@ -2092,12 +1799,10 @@ exports.TABLE_TEST_IDS = TABLE_TEST_IDS;
|
|
|
2092
1799
|
exports.applyTestID = applyTestID;
|
|
2093
1800
|
exports.clearTestID = clearTestID;
|
|
2094
1801
|
exports.fieldTestID = fieldTestID;
|
|
2095
|
-
exports.isUnmatched = isUnmatched;
|
|
2096
1802
|
exports.rowDetailTestID = rowDetailTestID;
|
|
2097
1803
|
exports.rowSelectTestID = rowSelectTestID;
|
|
2098
1804
|
exports.rowTestID = rowTestID;
|
|
2099
1805
|
exports.selectAllTestID = selectAllTestID;
|
|
2100
|
-
exports.suggestOptions = suggestOptions;
|
|
2101
1806
|
exports.useFilterDraft = useFilterDraft;
|
|
2102
1807
|
exports.usePagedRows = usePagedRows;
|
|
2103
1808
|
//# sourceMappingURL=index.js.map
|