@navikt/ds-react 8.4.1 → 8.5.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/cjs/accordion/Accordion.d.ts +10 -0
- package/cjs/accordion/Accordion.js +2 -2
- package/cjs/accordion/Accordion.js.map +1 -1
- package/cjs/data/table/helpers/table-cell.d.ts +2 -2
- package/cjs/data/table/helpers/table-cell.js +2 -5
- package/cjs/data/table/helpers/table-cell.js.map +1 -1
- package/cjs/data/table/helpers/table-focus.d.ts +26 -2
- package/cjs/data/table/helpers/table-focus.js +60 -9
- package/cjs/data/table/helpers/table-focus.js.map +1 -1
- package/cjs/data/table/helpers/table-grid-nav.d.ts +40 -10
- package/cjs/data/table/helpers/table-grid-nav.js +102 -25
- package/cjs/data/table/helpers/table-grid-nav.js.map +1 -1
- package/cjs/data/table/helpers/table-keyboard.d.ts +24 -3
- package/cjs/data/table/helpers/table-keyboard.js +25 -5
- package/cjs/data/table/helpers/table-keyboard.js.map +1 -1
- package/cjs/data/table/hooks/useGridCache.d.ts +17 -0
- package/cjs/data/table/hooks/useGridCache.js +65 -0
- package/cjs/data/table/hooks/useGridCache.js.map +1 -0
- package/cjs/data/table/root/DataTableRoot.d.ts +14 -4
- package/cjs/data/table/root/DataTableRoot.js +4 -6
- package/cjs/data/table/root/DataTableRoot.js.map +1 -1
- package/cjs/data/table/root/useTableKeyboardNav.d.ts +10 -4
- package/cjs/data/table/root/useTableKeyboardNav.js +70 -99
- package/cjs/data/table/root/useTableKeyboardNav.js.map +1 -1
- package/cjs/data/token-filter/AutoSuggest.d.ts +21 -0
- package/cjs/data/token-filter/AutoSuggest.js +129 -0
- package/cjs/data/token-filter/AutoSuggest.js.map +1 -0
- package/cjs/data/token-filter/TokenFilter.d.ts +11 -0
- package/cjs/data/token-filter/TokenFilter.js +91 -0
- package/cjs/data/token-filter/TokenFilter.js.map +1 -0
- package/cjs/data/token-filter/TokenFilter.types.d.ts +46 -0
- package/cjs/data/token-filter/TokenFilter.types.js +3 -0
- package/cjs/data/token-filter/TokenFilter.types.js.map +1 -0
- package/cjs/data/token-filter/helpers/generate-autocomplete-options.d.ts +70 -0
- package/cjs/data/token-filter/helpers/generate-autocomplete-options.js +171 -0
- package/cjs/data/token-filter/helpers/generate-autocomplete-options.js.map +1 -0
- package/cjs/data/token-filter/helpers/parse-query-text.d.ts +31 -0
- package/cjs/data/token-filter/helpers/parse-query-text.js +91 -0
- package/cjs/data/token-filter/helpers/parse-query-text.js.map +1 -0
- package/cjs/link-card/LinkCard.d.ts +13 -0
- package/cjs/link-card/LinkCard.js +2 -2
- package/cjs/link-card/LinkCard.js.map +1 -1
- package/cjs/process/Process.d.ts +1 -1
- package/cjs/tooltip/Tooltip.js +1 -1
- package/cjs/tooltip/Tooltip.js.map +1 -1
- package/esm/accordion/Accordion.d.ts +10 -0
- package/esm/accordion/Accordion.js +2 -2
- package/esm/accordion/Accordion.js.map +1 -1
- package/esm/data/table/helpers/table-cell.d.ts +2 -2
- package/esm/data/table/helpers/table-cell.js +2 -5
- package/esm/data/table/helpers/table-cell.js.map +1 -1
- package/esm/data/table/helpers/table-focus.d.ts +26 -2
- package/esm/data/table/helpers/table-focus.js +55 -9
- package/esm/data/table/helpers/table-focus.js.map +1 -1
- package/esm/data/table/helpers/table-grid-nav.d.ts +40 -10
- package/esm/data/table/helpers/table-grid-nav.js +96 -24
- package/esm/data/table/helpers/table-grid-nav.js.map +1 -1
- package/esm/data/table/helpers/table-keyboard.d.ts +24 -3
- package/esm/data/table/helpers/table-keyboard.js +24 -4
- package/esm/data/table/helpers/table-keyboard.js.map +1 -1
- package/esm/data/table/hooks/useGridCache.d.ts +17 -0
- package/esm/data/table/hooks/useGridCache.js +63 -0
- package/esm/data/table/hooks/useGridCache.js.map +1 -0
- package/esm/data/table/root/DataTableRoot.d.ts +14 -4
- package/esm/data/table/root/DataTableRoot.js +4 -6
- package/esm/data/table/root/DataTableRoot.js.map +1 -1
- package/esm/data/table/root/useTableKeyboardNav.d.ts +10 -4
- package/esm/data/table/root/useTableKeyboardNav.js +75 -104
- package/esm/data/table/root/useTableKeyboardNav.js.map +1 -1
- package/esm/data/token-filter/AutoSuggest.d.ts +21 -0
- package/esm/data/token-filter/AutoSuggest.js +93 -0
- package/esm/data/token-filter/AutoSuggest.js.map +1 -0
- package/esm/data/token-filter/TokenFilter.d.ts +11 -0
- package/esm/data/token-filter/TokenFilter.js +55 -0
- package/esm/data/token-filter/TokenFilter.js.map +1 -0
- package/esm/data/token-filter/TokenFilter.types.d.ts +46 -0
- package/esm/data/token-filter/TokenFilter.types.js +2 -0
- package/esm/data/token-filter/TokenFilter.types.js.map +1 -0
- package/esm/data/token-filter/helpers/generate-autocomplete-options.d.ts +70 -0
- package/esm/data/token-filter/helpers/generate-autocomplete-options.js +169 -0
- package/esm/data/token-filter/helpers/generate-autocomplete-options.js.map +1 -0
- package/esm/data/token-filter/helpers/parse-query-text.d.ts +31 -0
- package/esm/data/token-filter/helpers/parse-query-text.js +87 -0
- package/esm/data/token-filter/helpers/parse-query-text.js.map +1 -0
- package/esm/link-card/LinkCard.d.ts +13 -0
- package/esm/link-card/LinkCard.js +2 -2
- package/esm/link-card/LinkCard.js.map +1 -1
- package/esm/process/Process.d.ts +1 -1
- package/esm/tooltip/Tooltip.js +2 -2
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/package.json +3 -3
- package/src/accordion/Accordion.tsx +19 -2
- package/src/data/table/helpers/table-cell.ts +2 -7
- package/src/data/table/helpers/table-focus.ts +70 -9
- package/src/data/table/helpers/table-grid-nav.test.ts +659 -0
- package/src/data/table/helpers/table-grid-nav.ts +128 -32
- package/src/data/table/helpers/table-keyboard.test.ts +27 -27
- package/src/data/table/helpers/table-keyboard.ts +34 -4
- package/src/data/table/hooks/useGridCache.ts +73 -0
- package/src/data/table/root/DataTableRoot.tsx +21 -11
- package/src/data/table/root/useTableKeyboardNav.ts +110 -128
- package/src/data/token-filter/AutoSuggest.tsx +179 -0
- package/src/data/token-filter/TokenFilter.tsx +124 -0
- package/src/data/token-filter/TokenFilter.types.ts +79 -0
- package/src/data/token-filter/helpers/generate-autocomplete-options.ts +244 -0
- package/src/data/token-filter/helpers/parse-query-text.test.ts +410 -0
- package/src/data/token-filter/helpers/parse-query-text.ts +148 -0
- package/src/link-card/LinkCard.tsx +15 -1
- package/src/process/Process.tsx +1 -1
- package/src/tooltip/Tooltip.tsx +3 -3
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useValueAsRef } from "../../../utils/hooks/index.js";
|
|
3
|
+
import { buildTableGridMap } from "../helpers/table-grid-nav.js";
|
|
4
|
+
/**
|
|
5
|
+
* Manages the table grid cache and observes DOM changes that require grid rebuilding.
|
|
6
|
+
* Watches for structural changes (rows/cells added/removed) and attribute changes
|
|
7
|
+
* (colspan, rowspan, hidden, style) that affect grid layout and focusability.
|
|
8
|
+
*/
|
|
9
|
+
function useGridCache(tableRef, enabled) {
|
|
10
|
+
const gridCacheRef = useRef({
|
|
11
|
+
grid: null,
|
|
12
|
+
dirty: true,
|
|
13
|
+
});
|
|
14
|
+
const [activeCell, setActiveCell] = useState(null);
|
|
15
|
+
const activeCellRef = useValueAsRef(activeCell).current;
|
|
16
|
+
const observerRef = useRef(null);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!tableRef || !enabled) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
observerRef.current = new MutationObserver(() => {
|
|
22
|
+
gridCacheRef.current.dirty = true;
|
|
23
|
+
if (activeCellRef && !activeCellRef.isConnected) {
|
|
24
|
+
setActiveCell(null);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
observerRef.current.observe(tableRef, {
|
|
28
|
+
subtree: true,
|
|
29
|
+
childList: true,
|
|
30
|
+
attributes: true,
|
|
31
|
+
attributeFilter: ["colspan", "rowspan", "hidden", "style"],
|
|
32
|
+
});
|
|
33
|
+
return () => {
|
|
34
|
+
if (observerRef.current) {
|
|
35
|
+
observerRef.current.disconnect();
|
|
36
|
+
observerRef.current = null;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}, [tableRef, enabled, activeCellRef]);
|
|
40
|
+
/**
|
|
41
|
+
* If keyboard-nav is re-enabled, mark grid as dirty since
|
|
42
|
+
* the table might have changed while it was disabled.
|
|
43
|
+
*/
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (enabled) {
|
|
46
|
+
gridCacheRef.current.dirty = true;
|
|
47
|
+
}
|
|
48
|
+
}, [enabled]);
|
|
49
|
+
const getTableGrid = useCallback((_tableRef) => {
|
|
50
|
+
if (gridCacheRef.current.dirty || !gridCacheRef.current.grid) {
|
|
51
|
+
gridCacheRef.current.grid = buildTableGridMap(_tableRef);
|
|
52
|
+
gridCacheRef.current.dirty = false;
|
|
53
|
+
}
|
|
54
|
+
return gridCacheRef.current.grid;
|
|
55
|
+
}, []);
|
|
56
|
+
return {
|
|
57
|
+
getTableGrid,
|
|
58
|
+
activeCell,
|
|
59
|
+
setActiveCell,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export { useGridCache };
|
|
63
|
+
//# sourceMappingURL=useGridCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGridCache.js","sourceRoot":"","sources":["../../../../src/data/table/hooks/useGridCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAkB,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9E;;;;GAIG;AACH,SAAS,YAAY,CAAC,QAAiC,EAAE,OAAgB;IACvE,MAAM,YAAY,GAAG,MAAM,CAAY;QACrC,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC;IAEH,M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AAY,GAAG,WAAW,CAAC,CAAC,SAA2B,EAAE,EAAE;QAC/D,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAC7D,YAAY,CAAC,OAAO,CAAC,IAAI,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;YACzD,YAAY,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QACrC,CAAC;QAED,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC;IACnC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,YAAY;QACZ,UAAU;QACV,aAAa;KACd,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -9,17 +9,27 @@ import { DataTableTr, type DataTableTrProps } from "../tr/DataTableTr.js";
|
|
|
9
9
|
interface DataTableProps extends React.HTMLAttributes<HTMLTableElement> {
|
|
10
10
|
children: React.ReactNode;
|
|
11
11
|
rowDensity?: "condensed" | "normal" | "spacious";
|
|
12
|
+
/**
|
|
13
|
+
* Zebra striped table
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
zebraStripes?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Truncate content in cells and show ellipsis for overflowed text.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
truncateContent?: boolean;
|
|
12
22
|
/**
|
|
13
23
|
* Enables keyboard navigation for table rows and cells.
|
|
14
24
|
* @default false
|
|
15
25
|
*/
|
|
16
26
|
withKeyboardNav?: boolean;
|
|
17
27
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
28
|
+
* Custom callback to determine if navigation should be blocked.
|
|
29
|
+
* Called before default blocking logic.
|
|
30
|
+
* Requires `withKeyboardNav` to be `true`.
|
|
20
31
|
*/
|
|
21
|
-
|
|
22
|
-
truncateContent?: boolean;
|
|
32
|
+
shouldBlockNavigation?: (event: KeyboardEvent) => boolean;
|
|
23
33
|
}
|
|
24
34
|
interface DataTableRootComponent extends React.ForwardRefExoticComponent<DataTableProps & React.RefAttributes<HTMLTableElement>> {
|
|
25
35
|
/**
|
|
@@ -21,18 +21,16 @@ import { DataTableThead, } from "../thead/DataTableThead.js";
|
|
|
21
21
|
import { DataTableTr } from "../tr/DataTableTr.js";
|
|
22
22
|
import { useTableKeyboardNav } from "./useTableKeyboardNav.js";
|
|
23
23
|
const DataTable = forwardRef((_a, forwardedRef) => {
|
|
24
|
-
var { className, rowDensity = "normal", withKeyboardNav = false, zebraStripes = false, truncateContent = true } = _a, rest = __rest(_a, ["className", "rowDensity", "withKeyboardNav", "zebraStripes", "truncateContent"]);
|
|
24
|
+
var { className, rowDensity = "normal", withKeyboardNav = false, zebraStripes = false, truncateContent = true, shouldBlockNavigation } = _a, rest = __rest(_a, ["className", "rowDensity", "withKeyboardNav", "zebraStripes", "truncateContent", "shouldBlockNavigation"]);
|
|
25
25
|
const [tableRef, setTableRef] = useState(null);
|
|
26
26
|
const mergedRef = useMergeRefs(forwardedRef, setTableRef);
|
|
27
|
-
const {
|
|
27
|
+
const { tabIndex } = useTableKeyboardNav(tableRef, {
|
|
28
28
|
enabled: withKeyboardNav,
|
|
29
|
+
shouldBlockNavigation,
|
|
29
30
|
});
|
|
30
31
|
return (React.createElement("div", { className: "aksel-data-table__border-wrapper" },
|
|
31
32
|
React.createElement("div", { className: "aksel-data-table__scroll-wrapper" },
|
|
32
|
-
React.createElement("table", Object.assign({}, rest, { ref: mergedRef, className: cl("aksel-data-table", className,
|
|
33
|
-
"aksel-data-table--zebra-stripes": zebraStripes,
|
|
34
|
-
"aksel-data-table--truncate-content": truncateContent,
|
|
35
|
-
}), "data-density": rowDensity, tabIndex: tableTabIndex, onFocus: onFocus })))));
|
|
33
|
+
React.createElement("table", Object.assign({}, rest, { ref: mergedRef, className: cl("aksel-data-table", className), "data-zebra-stripes": zebraStripes, "data-truncate-content": truncateContent, "data-density": rowDensity, tabIndex: tabIndex })))));
|
|
36
34
|
});
|
|
37
35
|
DataTable.Caption = DataTableCaption;
|
|
38
36
|
DataTable.Thead = DataTableThead;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableRoot.js","sourceRoot":"","sources":["../../../../src/data/table/root/DataTableRoot.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EACL,gBAAgB,GAEjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,cAAc,GAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAyB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EACL,cAAc,GAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAyB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EACL,cAAc,GAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAyB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"DataTableRoot.js","sourceRoot":"","sources":["../../../../src/data/table/root/DataTableRoot.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EACL,gBAAgB,GAEjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,cAAc,GAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAyB,MAAM,mBA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,CAAC;AAC3B,SAAS,CAAC,EAAE,GAAG,WAAW,CAAC;AAC3B,SAAS,CAAC,EAAE,GAAG,WAAW,CAAC;AAC3B,SAAS,CAAC,KAAK,GAAG,cAAc,CAAC;AAEjC,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,cAAc,EACd,WAAW,EACX,cAAc,EACd,WAAW,GACZ,CAAC;AACF,eAAe,SAAS,CAAC"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
type UseTableKeyboardNavOptions = {
|
|
2
2
|
enabled: boolean;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Custom callback to determine if navigation should be blocked.
|
|
5
|
+
* Called before default blocking logic.
|
|
6
|
+
*/
|
|
7
|
+
shouldBlockNavigation?: (event: KeyboardEvent) => boolean;
|
|
8
|
+
};
|
|
9
|
+
declare function useTableKeyboardNav(tableRef: HTMLTableElement | null, { enabled, shouldBlockNavigation: customBlockFn }: UseTableKeyboardNavOptions): {
|
|
10
|
+
tabIndex: number | undefined;
|
|
6
11
|
};
|
|
7
12
|
export { useTableKeyboardNav };
|
|
13
|
+
export type { UseTableKeyboardNavOptions };
|
|
@@ -1,67 +1,93 @@
|
|
|
1
|
-
import { useEffect
|
|
1
|
+
import { useEffect } from "react";
|
|
2
2
|
import { useEventCallback } from "../../../utils/hooks/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
activeCellRef.current = activeCell;
|
|
11
|
-
const observerRef = useRef(null);
|
|
12
|
-
const gridCacheRef = useRef({
|
|
13
|
-
grid: null,
|
|
14
|
-
dirty: true,
|
|
15
|
-
});
|
|
3
|
+
import { focusInitialTableTarget } from "../helpers/table-cell.js";
|
|
4
|
+
import { focusCellAndUpdateTabIndex } from "../helpers/table-focus.js";
|
|
5
|
+
import { findFirstCell, findFirstCellInRow, findLastCell, findLastCellInRow, findNextFocusableCell, } from "../helpers/table-grid-nav.js";
|
|
6
|
+
import { getNavigationAction, shouldBlockNavigation, } from "../helpers/table-keyboard.js";
|
|
7
|
+
import { useGridCache } from "../hooks/useGridCache.js";
|
|
8
|
+
function useTableKeyboardNav(tableRef, { enabled, shouldBlockNavigation: customBlockFn }) {
|
|
9
|
+
const { getTableGrid, activeCell, setActiveCell } = useGridCache(tableRef, enabled);
|
|
16
10
|
/**
|
|
17
|
-
*
|
|
18
|
-
* - Save original tabIndex of cells and restore when navigating away?
|
|
11
|
+
* Executes a navigation action and returns the target cell.
|
|
19
12
|
*/
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
const executeNavigationAction = useEventCallback((action) => {
|
|
14
|
+
if (!tableRef) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
let currentCell = activeCell;
|
|
18
|
+
currentCell !== null && currentCell !== void 0 ? currentCell : (currentCell = focusInitialTableTarget(tableRef));
|
|
19
|
+
if (!currentCell) {
|
|
23
20
|
return null;
|
|
24
21
|
}
|
|
25
|
-
const { grid, positions
|
|
22
|
+
const { grid, positions } = getTableGrid(tableRef);
|
|
26
23
|
const currentPos = positions.get(currentCell);
|
|
27
|
-
|
|
24
|
+
let nextCell = null;
|
|
25
|
+
switch (action.type) {
|
|
26
|
+
case "delta": {
|
|
27
|
+
if (!currentPos) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
nextCell = findNextFocusableCell(grid, currentPos, action.delta, currentCell);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case "home": {
|
|
34
|
+
if (!currentPos) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
nextCell = findFirstCellInRow(grid, currentPos.y);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case "end": {
|
|
41
|
+
if (!currentPos) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
nextCell = findLastCellInRow(grid, currentPos.y);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "tableStart": {
|
|
48
|
+
nextCell = findFirstCell(grid);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case "tableEnd": {
|
|
52
|
+
nextCell = findLastCell(grid);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!nextCell || nextCell === currentCell) {
|
|
28
57
|
return null;
|
|
29
58
|
}
|
|
30
|
-
|
|
31
|
-
return nextCell
|
|
32
|
-
? focusCellAndUpdateTabIndex(nextCell, currentCell)
|
|
33
|
-
: null;
|
|
59
|
+
return focusCellAndUpdateTabIndex(nextCell, currentCell);
|
|
34
60
|
});
|
|
35
61
|
/**
|
|
36
|
-
* Handles keyboard navigation with arrow keys.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* TODO:
|
|
40
|
-
* - Check for other "blocking" scenarios, like actionmenus, dropdown etc
|
|
41
|
-
* - Consider having acallback user can hook into to determine if navigation should be blocked
|
|
42
|
-
* - Consider adding Home, End, PageUp, PageDown navigation
|
|
43
|
-
*
|
|
62
|
+
* Handles keyboard navigation with arrow keys, Home/End, and PageUp/PageDown.
|
|
63
|
+
* Checks if navigation should be blocked based on current focus context.
|
|
44
64
|
*/
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
const handleTableKeyDown = useEventCallback((event) => {
|
|
66
|
+
if (customBlockFn === null || customBlockFn === void 0 ? void 0 : customBlockFn(event)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (shouldBlockNavigation(event)) {
|
|
48
70
|
return;
|
|
49
71
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
event.preventDefault();
|
|
54
|
-
newCell = navigateByArrowKey(delta);
|
|
72
|
+
const action = getNavigationAction(event);
|
|
73
|
+
if (!action) {
|
|
74
|
+
return;
|
|
55
75
|
}
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
const newCell = executeNavigationAction(action);
|
|
56
78
|
newCell && setActiveCell(newCell);
|
|
57
79
|
});
|
|
58
80
|
/**
|
|
59
81
|
* When focus is moved to elements inside a cell like inputs, checkbox etc
|
|
60
82
|
* we want to update the active cell to the parent td/th, so that keyboard navigation continues to work as expected from there.
|
|
61
83
|
*/
|
|
62
|
-
const
|
|
84
|
+
const handleTableFocusIn = useEventCallback((event) => {
|
|
63
85
|
var _a;
|
|
64
86
|
const target = event.target;
|
|
87
|
+
if (tableRef && target === tableRef) {
|
|
88
|
+
focusInitialTableTarget(tableRef);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
65
91
|
const newCell = (_a = target === null || target === void 0 ? void 0 : target.closest("td, th")) !== null && _a !== void 0 ? _a : null;
|
|
66
92
|
if (!newCell || newCell === activeCell) {
|
|
67
93
|
return;
|
|
@@ -74,77 +100,22 @@ function useTableKeyboardNav(tableRef, { enabled }) {
|
|
|
74
100
|
}
|
|
75
101
|
});
|
|
76
102
|
/**
|
|
77
|
-
*
|
|
78
|
-
* - We want to check if elements are removed/added, like when filtering table, pagination etc
|
|
79
|
-
* - Changes in colspan/rowspan that can affect the grid structure
|
|
80
|
-
* - Hidden attribute or styles that can affect focusability of cells
|
|
81
|
-
*
|
|
82
|
-
* We also check if the active cell is removed from the DOM, and clear it if so.
|
|
103
|
+
* Attach event listeners for keyboard navigation and focus management.
|
|
83
104
|
*/
|
|
84
105
|
useEffect(() => {
|
|
85
106
|
if (!tableRef || !enabled) {
|
|
86
107
|
return;
|
|
87
108
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (activeCellRef.current && !activeCellRef.current.isConnected) {
|
|
91
|
-
setActiveCell(null);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
observerRef.current.observe(tableRef, {
|
|
95
|
-
subtree: true,
|
|
96
|
-
childList: true,
|
|
97
|
-
attributes: true,
|
|
98
|
-
attributeFilter: ["colspan", "rowspan", "hidden", "style"],
|
|
99
|
-
});
|
|
100
|
-
return () => {
|
|
101
|
-
if (observerRef.current) {
|
|
102
|
-
observerRef.current.disconnect();
|
|
103
|
-
observerRef.current = null;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}, [tableRef, enabled]);
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
if (!tableRef || !enabled) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
tableRef.addEventListener("keydown", onKeyDown);
|
|
112
|
-
tableRef.addEventListener("focusin", onFocusIn);
|
|
109
|
+
tableRef.addEventListener("keydown", handleTableKeyDown);
|
|
110
|
+
tableRef.addEventListener("focusin", handleTableFocusIn);
|
|
113
111
|
return () => {
|
|
114
|
-
tableRef.removeEventListener("keydown",
|
|
115
|
-
tableRef.removeEventListener("focusin",
|
|
112
|
+
tableRef.removeEventListener("keydown", handleTableKeyDown);
|
|
113
|
+
tableRef.removeEventListener("focusin", handleTableFocusIn);
|
|
116
114
|
};
|
|
117
|
-
}, [tableRef,
|
|
118
|
-
/*
|
|
119
|
-
* If keyboard-nav is re-enabled, we need to make sure to update the grid cache,
|
|
120
|
-
* since the table might have changed while it was disabled.
|
|
121
|
-
*/
|
|
122
|
-
useEffect(() => {
|
|
123
|
-
if (!enabled) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
gridCacheRef.current.dirty = true;
|
|
127
|
-
}, [enabled]);
|
|
115
|
+
}, [tableRef, handleTableKeyDown, handleTableFocusIn, enabled]);
|
|
128
116
|
return {
|
|
129
117
|
/* Table should only have tabIndex until the focus is moved inside and is enabled */
|
|
130
|
-
|
|
131
|
-
/*
|
|
132
|
-
* Allows us to capture focus on the table when navigating with Tab from outside, and move it to the first cell.
|
|
133
|
-
* We only want to do this if no cell is already focused.
|
|
134
|
-
*/
|
|
135
|
-
onFocus: () => {
|
|
136
|
-
if (!tableRef) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const focusedElement = document.activeElement;
|
|
140
|
-
const cellInTable = focusedElement === null || focusedElement === void 0 ? void 0 : focusedElement.closest("td, th");
|
|
141
|
-
/* Assume onFocusIn handler has updates cell */
|
|
142
|
-
if (cellInTable && tableRef.contains(cellInTable)) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const firstCell = getFirstCell(tableRef);
|
|
146
|
-
return firstCell ? focusCell(firstCell) : null;
|
|
147
|
-
},
|
|
118
|
+
tabIndex: enabled ? (activeCell ? undefined : 0) : undefined,
|
|
148
119
|
};
|
|
149
120
|
}
|
|
150
121
|
export { useTableKeyboardNav };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTableKeyboardNav.js","sourceRoot":"","sources":["../../../../src/data/table/root/useTableKeyboardNav.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useTableKeyboardNav.js","sourceRoot":"","sources":["../../../../src/data/table/root/useTableKeyboardNav.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAWrD,SAAS,mBAAmB,CAC1B,QAAiC,EACjC,EAAE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAA8B;IAE7E,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,YAAY,CAC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: string;
|
|
5
|
+
tags?: string[];
|
|
6
|
+
filteringTags?: string[];
|
|
7
|
+
description?: string;
|
|
8
|
+
}
|
|
9
|
+
interface AutoSuggestGroup {
|
|
10
|
+
label: string;
|
|
11
|
+
options: AutoSuggestOption[];
|
|
12
|
+
}
|
|
13
|
+
interface AutoSuggestProps {
|
|
14
|
+
options: AutoSuggestGroup[];
|
|
15
|
+
value: string;
|
|
16
|
+
filterText: string;
|
|
17
|
+
onSelect: (value: string) => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
declare const AutoSuggest: React.ForwardRefExoticComponent<AutoSuggestProps & React.RefAttributes<HTMLDivElement>>;
|
|
21
|
+
export { AutoSuggest };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React, { forwardRef, useMemo } from "react";
|
|
13
|
+
import { cl } from "../../utils/helpers/index.js";
|
|
14
|
+
const AutoSuggest = forwardRef(({ options, value, filterText, onSelect, className }, ref) => {
|
|
15
|
+
console.info({ options, value, filterText });
|
|
16
|
+
/* const highlightedText = filterText === undefined ? value : filterText; */
|
|
17
|
+
/* const filterValue = (value || "").toLowerCase();
|
|
18
|
+
|
|
19
|
+
const filteredGroups = options
|
|
20
|
+
.map((group) => ({
|
|
21
|
+
...group,
|
|
22
|
+
options: group.options.filter((option) => {
|
|
23
|
+
const searchableText = [
|
|
24
|
+
option.label,
|
|
25
|
+
option.description,
|
|
26
|
+
...(option.filteringTags ?? []),
|
|
27
|
+
...(option.tags ?? []),
|
|
28
|
+
]
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.join(" ")
|
|
31
|
+
.toLowerCase();
|
|
32
|
+
return searchableText.includes(filterValue);
|
|
33
|
+
}),
|
|
34
|
+
}))
|
|
35
|
+
.filter((group) => group.options.length > 0); */
|
|
36
|
+
const { items } = useAutosuggestItems({ options, filterValue: filterText });
|
|
37
|
+
console.info({ items });
|
|
38
|
+
return (React.createElement("div", { ref: ref, className: cl("aksel-auto-suggest", className) }, options.map((group) => (React.createElement("div", { key: group.label, className: "aksel-auto-suggest__group" },
|
|
39
|
+
React.createElement("div", { className: "aksel-auto-suggest__group-label" }, group.label),
|
|
40
|
+
React.createElement("ul", { className: "aksel-auto-suggest__list" }, group.options.map((option) => (React.createElement("li", { key: option.value, className: "aksel-auto-suggest__item" },
|
|
41
|
+
React.createElement("button", { type: "button", className: "aksel-auto-suggest__button", onClick: () => onSelect(option.value) },
|
|
42
|
+
React.createElement("span", { className: "aksel-auto-suggest__label" }, option.label),
|
|
43
|
+
option.description && (React.createElement("span", { className: "aksel-auto-suggest__description" }, option.description)),
|
|
44
|
+
option.tags && option.tags.length > 0 && (React.createElement("div", { className: "aksel-auto-suggest__tags" }, option.tags.map((tag) => (React.createElement("span", { key: tag, className: "aksel-auto-suggest__tag" }, tag)))))))))))))));
|
|
45
|
+
});
|
|
46
|
+
function useAutosuggestItems({ options, filterValue }) {
|
|
47
|
+
const { items } = useMemo(() => createItems(options), [options]);
|
|
48
|
+
const filteredItems = useMemo(() => {
|
|
49
|
+
const localFilteredItems = items;
|
|
50
|
+
if (filterValue) {
|
|
51
|
+
localFilteredItems.unshift({
|
|
52
|
+
value: filterValue,
|
|
53
|
+
type: "use-entered",
|
|
54
|
+
label: `Use "${filterValue}"`,
|
|
55
|
+
option: { value: filterValue },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return localFilteredItems;
|
|
59
|
+
}, [items, filterValue]);
|
|
60
|
+
return { items: filteredItems };
|
|
61
|
+
}
|
|
62
|
+
function createItems(options) {
|
|
63
|
+
const items = [];
|
|
64
|
+
const itemToGroup = new WeakMap();
|
|
65
|
+
for (const option of options) {
|
|
66
|
+
if (isGroup(option)) {
|
|
67
|
+
for (const item of flattenGroup(option, itemToGroup)) {
|
|
68
|
+
items.push(item);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
items.push(Object.assign(Object.assign({}, option), { option }));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { items };
|
|
76
|
+
}
|
|
77
|
+
function flattenGroup(group, map) {
|
|
78
|
+
var _a;
|
|
79
|
+
const { options } = group, rest = __rest(group, ["options"]);
|
|
80
|
+
const groupItem = Object.assign(Object.assign({}, rest), { type: "parent", option: group });
|
|
81
|
+
const items = [groupItem];
|
|
82
|
+
for (const option of options) {
|
|
83
|
+
const childOption = Object.assign(Object.assign({}, option), { type: "child", disabled: (_a = option.disabled) !== null && _a !== void 0 ? _a : false, option, parent: group });
|
|
84
|
+
items.push(childOption);
|
|
85
|
+
map.set(childOption, groupItem);
|
|
86
|
+
}
|
|
87
|
+
return items;
|
|
88
|
+
}
|
|
89
|
+
function isGroup(optionOrGroup) {
|
|
90
|
+
return "options" in optionOrGroup;
|
|
91
|
+
}
|
|
92
|
+
export { AutoSuggest };
|
|
93
|
+
//# sourceMappingURL=AutoSuggest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoSuggest.js","sourceRoot":"","sources":["../../../src/data/token-filter/AutoSuggest.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AA2BzC,MAAM,WAAW,GAAG,UAAU,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C,EAAE,CAAC;gBACrD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,iCAAM,MAAM,KAAE,MAAM,IAAG,CAAC;QACpC,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC;AAED,SAAS,YAAY,CACnB,KAAgC,EAChC,GAA8C;;IAE9C,MAAM,EAAE,OAAO,KAAc,KAAK,EAAd,IAAI,UAAK,KAAK,EAA5B,WAAoB,CAAQ,CAAC;IAEnC,MAAM,SAAS,mCAAyB,IAAI,KAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,GAAE,CAAC;IAE9E,MAAM,KAAK,GAAsB,CAAC,SAAS,CAAC,CAAC;IAE7C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,WAAW,mCACZ,MAAM,KACT,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,MAAA,MAAM,CAAC,QAAQ,mCAAI,KAAK,EAClC,MAAM,EACN,MAAM,EAAE,KAAK,GACd,CAAC;QAEF,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAExB,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,OAAO,CACd,aAA+D;IAE/D,OAAO,SAAS,IAAI,aAAa,CAAC;AACpC,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { QueryFilterQuery, QueryFilteringOptions, QueryFilteringProperties } from "./TokenFilter.types.js";
|
|
3
|
+
type TokenFilterProps = {
|
|
4
|
+
query: QueryFilterQuery;
|
|
5
|
+
onChange: (newQuery: QueryFilterQuery) => void;
|
|
6
|
+
className?: string;
|
|
7
|
+
filteringOptions: QueryFilteringOptions;
|
|
8
|
+
filteringProperties: QueryFilteringProperties;
|
|
9
|
+
};
|
|
10
|
+
export declare const TokenFilter: React.ForwardRefExoticComponent<TokenFilterProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, { forwardRef, useState } from "react";
|
|
2
|
+
import { Popover } from "../../popover/index.js";
|
|
3
|
+
import { cl } from "../../utils/helpers/index.js";
|
|
4
|
+
import { generateAutoCompleteOptions } from "./helpers/generate-autocomplete-options.js";
|
|
5
|
+
import { parseQueryText } from "./helpers/parse-query-text.js";
|
|
6
|
+
export const TokenFilter = forwardRef(({ query, className, filteringProperties, filteringOptions }, ref) => {
|
|
7
|
+
const [inputAnchor, setInputAnchor] = useState(null);
|
|
8
|
+
const [filterText, setFilterText] = useState("");
|
|
9
|
+
const { properties, options } = derrivedFilterState(filteringProperties, filteringOptions);
|
|
10
|
+
const queryState = parseQueryText(filterText, properties);
|
|
11
|
+
const autoCompleteOptions = generateAutoCompleteOptions(queryState, properties, options);
|
|
12
|
+
/* const handleSelectOption = (value: string) => {
|
|
13
|
+
setFilterText(value);
|
|
14
|
+
}; */
|
|
15
|
+
return (React.createElement("div", { ref: ref, className: cl("aksel-property-filter", className), role: "search" },
|
|
16
|
+
React.createElement("input", { type: "text", className: "aksel-property-filter__input", placeholder: "Type to filter...", ref: setInputAnchor, value: filterText, onChange: (e) => setFilterText(e.target.value) }),
|
|
17
|
+
React.createElement(Popover, { anchorEl: inputAnchor, open: filterText.length > 0, onClose: () => setFilterText("") }, "a"),
|
|
18
|
+
query.tokens.map((token, index) => {
|
|
19
|
+
return (React.createElement("div", { key: index, className: "aksel-property-filter__token" },
|
|
20
|
+
React.createElement("strong", null, token.propertyKey),
|
|
21
|
+
" ",
|
|
22
|
+
token.operator,
|
|
23
|
+
" "));
|
|
24
|
+
}),
|
|
25
|
+
React.createElement("ul", null, filteringProperties.map((prop) => (React.createElement("li", { key: prop.key }, prop.propertyLabel)))),
|
|
26
|
+
React.createElement("pre", null, JSON.stringify(queryState, null, 2)),
|
|
27
|
+
React.createElement("pre", null, JSON.stringify(autoCompleteOptions, null, 2))));
|
|
28
|
+
});
|
|
29
|
+
function derrivedFilterState(filteringProperties, filteringOptions) {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
const propertyMap = new Map();
|
|
32
|
+
for (const property of filteringProperties) {
|
|
33
|
+
propertyMap.set(property.key, {
|
|
34
|
+
propertyKey: property.key,
|
|
35
|
+
propertyLabel: (_a = property === null || property === void 0 ? void 0 : property.propertyLabel) !== null && _a !== void 0 ? _a : "",
|
|
36
|
+
groupValuesLabel: (_b = property === null || property === void 0 ? void 0 : property.groupValuesLabel) !== null && _b !== void 0 ? _b : "",
|
|
37
|
+
propertyGroup: property === null || property === void 0 ? void 0 : property.group,
|
|
38
|
+
/* operators: (property?.operators ?? []).map(op => (typeof op === 'string' ? op : op.operator)), */
|
|
39
|
+
/* defaultOperator: property?.defaultOperator ?? '=', */
|
|
40
|
+
externalProperty: property,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const internalOptions = filteringOptions.map((option) => {
|
|
44
|
+
var _a, _b, _c, _d, _e;
|
|
45
|
+
return ({
|
|
46
|
+
property: (_a = propertyMap.get(option.propertyKey)) !== null && _a !== void 0 ? _a : null,
|
|
47
|
+
value: option.value,
|
|
48
|
+
label: (_c = (_b = option.label) !== null && _b !== void 0 ? _b : option.value) !== null && _c !== void 0 ? _c : "",
|
|
49
|
+
tags: (_d = option.tags) !== null && _d !== void 0 ? _d : [],
|
|
50
|
+
filteringTags: (_e = option.filteringTags) !== null && _e !== void 0 ? _e : [],
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
return { properties: [...propertyMap.values()], options: internalOptions };
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=TokenFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenFilter.js","source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