@tap-payments/os-micro-frontend-shared 0.1.396 → 0.1.398-test.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/build/components/AnimatedSpinnerIcon/style.d.ts +0 -1
- package/build/components/Chip/style.d.ts +0 -1
- package/build/components/CountBadge/style.d.ts +0 -1
- package/build/components/Dialog/style.d.ts +0 -1
- package/build/components/FlippingCard/style.d.ts +0 -1
- package/build/components/ImageWrapper/ImageWrapper.d.ts +0 -1
- package/build/components/JSONViewer/style.d.ts +0 -1
- package/build/components/LeftPeekRightExpandingChip/style.d.ts +0 -1
- package/build/components/RightLeftExpandingCenterChip/style.d.ts +0 -1
- package/build/components/SearchButton/styles.d.ts +0 -1
- package/build/components/StatusIcons/AuthIcons/style.d.ts +0 -1
- package/build/components/StatusIcons/AuthorizationAutoIcons/style.d.ts +0 -1
- package/build/components/StatusIcons/ChargeStatusIcon/ChargeStatusIcon.d.ts +2 -24
- package/build/components/StatusIcons/ChargeStatusIcon/ChargeStatusIcon.js +23 -48
- package/build/components/StatusIcons/ChargeStatusIcon/ChargeStatusIconView.d.ts +10 -0
- package/build/components/StatusIcons/ChargeStatusIcon/ChargeStatusIconView.js +23 -0
- package/build/components/StatusIcons/ChargeStatusIcon/ChargeStatusSheetView.d.ts +9 -0
- package/build/components/StatusIcons/ChargeStatusIcon/ChargeStatusSheetView.js +9 -0
- package/build/components/StatusIcons/ChargeStatusIcon/ChargeStatusTextView.d.ts +10 -0
- package/build/components/StatusIcons/ChargeStatusIcon/ChargeStatusTextView.js +16 -0
- package/build/components/StatusIcons/ChargeStatusIcon/style.d.ts +0 -1
- package/build/components/StatusIcons/ChargeStatusIcon/type.d.ts +24 -0
- package/build/components/StatusIcons/ChargeStatusIcon/type.js +1 -0
- package/build/components/StatusIcons/SourceIcons/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ActionCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/AgreementCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ApplicationStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/AuthenticationCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/AuthenticationStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/AuthenticationTypeCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/BalanceCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ChannelsCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/CheckoutStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/DestinationStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/DueDateCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/IDButton/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/IntentsStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/InvoiceStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/PayoutReportCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/PayoutStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ProductsCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ReferenceCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ReferenceCell/style.js +3 -1
- package/build/components/TableCells/CustomCells/RefundChargeCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/RefundStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/SalesChannelCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/SegmentsCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/StatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/StatusCell/style.js +3 -1
- package/build/components/TableCells/CustomCells/TokenStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/style.d.ts +0 -1
- package/build/components/TableReports/components/DownloadButton/style.d.ts +0 -1
- package/build/components/TableReports/style.d.ts +0 -1
- package/build/components/TableReports/style.js +1 -1
- package/build/components/TreeDropdown/TreeDropdown.d.ts +4 -0
- package/build/components/TreeDropdown/TreeDropdown.js +67 -0
- package/build/components/TreeDropdown/TreeNodeItem/SelectionControl.d.ts +8 -0
- package/build/components/TreeDropdown/TreeNodeItem/SelectionControl.js +17 -0
- package/build/components/TreeDropdown/TreeNodeItem/TreeNodeItem.d.ts +12 -0
- package/build/components/TreeDropdown/TreeNodeItem/TreeNodeItem.js +64 -0
- package/build/components/TreeDropdown/TreeNodeItem/index.d.ts +2 -0
- package/build/components/TreeDropdown/TreeNodeItem/index.js +2 -0
- package/build/components/TreeDropdown/TreeNodeItem/style.d.ts +14 -0
- package/build/components/TreeDropdown/TreeNodeItem/style.js +46 -0
- package/build/components/TreeDropdown/TreeNodeList/List.d.ts +6 -0
- package/build/components/TreeDropdown/TreeNodeList/List.js +17 -0
- package/build/components/TreeDropdown/TreeNodeList/TreeNodeList.d.ts +17 -0
- package/build/components/TreeDropdown/TreeNodeList/TreeNodeList.js +36 -0
- package/build/components/TreeDropdown/TreeNodeList/index.d.ts +2 -0
- package/build/components/TreeDropdown/TreeNodeList/index.js +2 -0
- package/build/components/TreeDropdown/TreeNodeList/style.d.ts +7 -0
- package/build/components/TreeDropdown/TreeNodeList/style.js +60 -0
- package/build/components/TreeDropdown/context/TreeDropdownProvider.d.ts +15 -0
- package/build/components/TreeDropdown/context/TreeDropdownProvider.js +13 -0
- package/build/components/TreeDropdown/hooks/useSearch.d.ts +17 -0
- package/build/components/TreeDropdown/hooks/useSearch.js +38 -0
- package/build/components/TreeDropdown/hooks/useTreeDropdown.d.ts +12 -0
- package/build/components/TreeDropdown/hooks/useTreeDropdown.js +10 -0
- package/build/components/TreeDropdown/index.d.ts +4 -0
- package/build/components/TreeDropdown/index.js +4 -0
- package/build/components/TreeDropdown/style.d.ts +9 -0
- package/build/components/TreeDropdown/style.js +43 -0
- package/build/components/TreeDropdown/type.d.ts +89 -0
- package/build/components/TreeDropdown/type.js +6 -0
- package/build/components/TreeDropdown/utils.d.ts +21 -0
- package/build/components/TreeDropdown/utils.js +161 -0
- package/build/components/VirtualTables/components/style.d.ts +0 -1
- package/build/components/index.d.ts +2 -0
- package/build/components/index.js +2 -0
- package/build/hooks/index.d.ts +1 -0
- package/build/hooks/index.js +1 -0
- package/build/hooks/useScrolledTo.d.ts +13 -0
- package/build/hooks/useScrolledTo.js +45 -0
- package/package.json +3 -3
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Input, MenuItem } from '../index.js';
|
|
3
|
+
import { type SxProps, type Theme } from '@mui/material/styles';
|
|
4
|
+
import { PopperProps } from '@mui/material/Popper';
|
|
5
|
+
export type TreeNodeIcon = {
|
|
6
|
+
fileId: string;
|
|
7
|
+
width?: number | string;
|
|
8
|
+
height?: number | string;
|
|
9
|
+
};
|
|
10
|
+
export type ExtendableObject<T> = T extends Record<string, any> ? T & Record<string, any> : never;
|
|
11
|
+
export type OnTreeMountedParams = {
|
|
12
|
+
state: TreeMapper;
|
|
13
|
+
tree: TreeNode[];
|
|
14
|
+
selectedTree: TreeNode[];
|
|
15
|
+
};
|
|
16
|
+
export type TreeDropdownProps = {
|
|
17
|
+
onMounted?: (params: OnTreeMountedParams) => void;
|
|
18
|
+
onChange?: (tree: TreeNode[]) => void;
|
|
19
|
+
multiple?: boolean;
|
|
20
|
+
anchorEl: HTMLElement | null;
|
|
21
|
+
placement?: PopperProps['placement'];
|
|
22
|
+
sx?: SxProps<Theme>;
|
|
23
|
+
treeDefinition: TreeDefinition;
|
|
24
|
+
exposeOnlySelectedTree?: boolean;
|
|
25
|
+
IconComponent?: React.ComponentType<{
|
|
26
|
+
fileId: string;
|
|
27
|
+
width?: number | string;
|
|
28
|
+
height?: number | string;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
export type TreeDropdownRef = {
|
|
32
|
+
treeMapper: TreeMapper;
|
|
33
|
+
getFullTree: () => TreeNode[];
|
|
34
|
+
getSelectedTree: () => TreeNode[];
|
|
35
|
+
toggleAll: (selected: boolean) => void;
|
|
36
|
+
};
|
|
37
|
+
export type TreeNode = ExtendableObject<{
|
|
38
|
+
id: string;
|
|
39
|
+
label?: React.ReactNode;
|
|
40
|
+
hintText?: React.ReactNode;
|
|
41
|
+
icon?: TreeNodeIcon;
|
|
42
|
+
iconComponent?: React.ReactNode;
|
|
43
|
+
itemProps?: React.ComponentProps<typeof MenuItem>;
|
|
44
|
+
renderItem?: (params: {
|
|
45
|
+
nodeProps: TreeNode;
|
|
46
|
+
checked?: boolean;
|
|
47
|
+
indeterminate?: boolean;
|
|
48
|
+
onSelect: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
49
|
+
}) => React.ReactNode;
|
|
50
|
+
}> & TreeDefinition;
|
|
51
|
+
export type TreeDefinition = {
|
|
52
|
+
header?: React.ReactNode;
|
|
53
|
+
footer?: React.ReactNode;
|
|
54
|
+
/**
|
|
55
|
+
* [Optional] Used to determine the level of the node in the tree
|
|
56
|
+
* It will appear as data attribute over the list element.
|
|
57
|
+
* ```
|
|
58
|
+
* <div ... data-level-key="some-unique-key"> ... </div>
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
levelKey?: string;
|
|
62
|
+
searchProps?: {
|
|
63
|
+
/**
|
|
64
|
+
* ### [Required For Search]
|
|
65
|
+
* The function to get the value of the item for the search
|
|
66
|
+
*/
|
|
67
|
+
getValues: (item: TreeNode) => string[];
|
|
68
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
69
|
+
noResultsText?: React.ReactNode;
|
|
70
|
+
inputProps?: React.ComponentProps<typeof Input>;
|
|
71
|
+
};
|
|
72
|
+
children?: TreeNode[];
|
|
73
|
+
disablePromotion?: boolean;
|
|
74
|
+
status?: `${SelectedState}`;
|
|
75
|
+
};
|
|
76
|
+
export declare enum SelectedState {
|
|
77
|
+
CHECKED = "CHECKED",
|
|
78
|
+
UNCHECKED = "UNCHECKED",
|
|
79
|
+
INDETERMINATE = "INDETERMINATE"
|
|
80
|
+
}
|
|
81
|
+
export type SelectedItems = {
|
|
82
|
+
[key: string]: `${SelectedState}`;
|
|
83
|
+
};
|
|
84
|
+
export type TreeMapper = {
|
|
85
|
+
[nodeKey: string]: {
|
|
86
|
+
status: `${SelectedState}`;
|
|
87
|
+
_parents?: string[];
|
|
88
|
+
};
|
|
89
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TreeMapper, TreeNode } from './type';
|
|
2
|
+
export declare function promoteSingleChild(items: TreeNode[]): TreeNode[];
|
|
3
|
+
export declare const getAncestorIdsByNodeId: (nodeId: string, nodes: TreeNode[], path?: TreeNode[]) => TreeNode[] | null;
|
|
4
|
+
export declare function collectCheckedIds(nodes: TreeNode[], multiple: boolean, acc?: string[]): string[];
|
|
5
|
+
export declare function normalizeStructure(nodes: TreeNode[], parents?: string[], acc?: TreeMapper, isParentSelected?: boolean): TreeMapper;
|
|
6
|
+
export declare function initializeTreeMapper(nodes: TreeNode[], multiple: boolean): TreeMapper;
|
|
7
|
+
export declare function denormalizeTree(nodes: TreeNode[], state: TreeMapper): TreeNode[];
|
|
8
|
+
export declare function updateTreeSelection(tree: TreeMapper, targetNodeId: string, isChecked: boolean): TreeMapper;
|
|
9
|
+
export declare function extractSelectedBranches(nodes: TreeNode[]): TreeNode[];
|
|
10
|
+
export declare function resetTreeState(tree: TreeMapper): TreeMapper;
|
|
11
|
+
export declare function updateSelection(tree: TreeMapper, targetNode: string, isChecked: boolean, multiple: boolean): TreeMapper;
|
|
12
|
+
export type GetNodesByLevelOptions = {
|
|
13
|
+
filter?: (node: TreeNode) => boolean;
|
|
14
|
+
includeChildren?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function filterNodesByLevelKey(nodes: TreeNode[], levelKey: string): TreeNode[];
|
|
17
|
+
export declare const TreeManager: {
|
|
18
|
+
denormalizeTree: import("memoize-one").MemoizedFn<(tree: TreeNode[], mapper: TreeMapper) => TreeNode[]>;
|
|
19
|
+
extractSelectedBranches: import("memoize-one").MemoizedFn<(nodes: TreeNode[]) => TreeNode[]>;
|
|
20
|
+
filterNodesByLevelKey: import("memoize-one").MemoizedFn<(nodes: TreeNode[], levelKey: string) => TreeNode[]>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import memoizeOne from 'memoize-one';
|
|
2
|
+
import { SelectedState } from './type';
|
|
3
|
+
export function promoteSingleChild(items) {
|
|
4
|
+
function promote(item) {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
let children = item.children ? item.children.map(promote) : undefined;
|
|
7
|
+
// Promote children if exactly one child exists and it has children
|
|
8
|
+
if ((children === null || children === void 0 ? void 0 : children.length) === 1 && ((_a = children[0].children) === null || _a === void 0 ? void 0 : _a.length) && !children[0].disablePromotion) {
|
|
9
|
+
const onlyChild = children[0];
|
|
10
|
+
children = onlyChild.children;
|
|
11
|
+
item = Object.assign(Object.assign({}, item), { header: (_b = onlyChild.header) !== null && _b !== void 0 ? _b : item.header, footer: (_c = onlyChild.footer) !== null && _c !== void 0 ? _c : item.footer });
|
|
12
|
+
}
|
|
13
|
+
return Object.assign(Object.assign({}, item), { children });
|
|
14
|
+
}
|
|
15
|
+
return items.map(promote);
|
|
16
|
+
}
|
|
17
|
+
export const getAncestorIdsByNodeId = (nodeId, nodes, path = []) => {
|
|
18
|
+
for (const node of nodes) {
|
|
19
|
+
if (node.id === nodeId) {
|
|
20
|
+
return [...path, node];
|
|
21
|
+
}
|
|
22
|
+
if (node.children) {
|
|
23
|
+
const found = getAncestorIdsByNodeId(nodeId, node.children, [...path, node]);
|
|
24
|
+
if (found)
|
|
25
|
+
return found;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
export function collectCheckedIds(nodes, multiple, acc = []) {
|
|
31
|
+
for (const node of nodes) {
|
|
32
|
+
if (node.status === SelectedState.CHECKED) {
|
|
33
|
+
acc.push(node.id);
|
|
34
|
+
}
|
|
35
|
+
if (node.children) {
|
|
36
|
+
collectCheckedIds(node.children, multiple, acc);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return acc;
|
|
40
|
+
}
|
|
41
|
+
export function normalizeStructure(nodes, parents = [], acc = {}, isParentSelected = false) {
|
|
42
|
+
var _a;
|
|
43
|
+
for (const node of nodes) {
|
|
44
|
+
const status = isParentSelected ? SelectedState.CHECKED : (_a = node.status) !== null && _a !== void 0 ? _a : SelectedState.UNCHECKED;
|
|
45
|
+
acc[node.id] = Object.assign({ status }, (parents.length ? { _parents: parents } : {}));
|
|
46
|
+
if (node.children) {
|
|
47
|
+
normalizeStructure(node.children, [...parents, node.id], acc, status === SelectedState.CHECKED);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return acc;
|
|
51
|
+
}
|
|
52
|
+
export function initializeTreeMapper(nodes, multiple) {
|
|
53
|
+
const base = normalizeStructure(nodes);
|
|
54
|
+
const checkedIds = collectCheckedIds(nodes, multiple);
|
|
55
|
+
let next = base;
|
|
56
|
+
for (const id of checkedIds) {
|
|
57
|
+
next = updateTreeSelection(next, id, true);
|
|
58
|
+
}
|
|
59
|
+
return next;
|
|
60
|
+
}
|
|
61
|
+
export function denormalizeTree(nodes, state) {
|
|
62
|
+
return nodes.map((node) => {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
return (Object.assign(Object.assign({}, node), { status: (_b = (_a = state[node.id]) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : SelectedState.UNCHECKED, children: node.children ? denormalizeTree(node.children, state) : undefined }));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function buildChildrenMap(tree) {
|
|
68
|
+
var _a;
|
|
69
|
+
const map = {};
|
|
70
|
+
for (const key of Object.keys(tree)) {
|
|
71
|
+
const parents = tree[key]._parents;
|
|
72
|
+
if (!(parents === null || parents === void 0 ? void 0 : parents.length))
|
|
73
|
+
continue;
|
|
74
|
+
const parent = parents[parents.length - 1];
|
|
75
|
+
(_a = map[parent]) !== null && _a !== void 0 ? _a : (map[parent] = []);
|
|
76
|
+
map[parent].push(key);
|
|
77
|
+
}
|
|
78
|
+
return map;
|
|
79
|
+
}
|
|
80
|
+
export function updateTreeSelection(tree, targetNodeId, isChecked) {
|
|
81
|
+
const next = structuredClone(tree);
|
|
82
|
+
const childrenMap = buildChildrenMap(tree);
|
|
83
|
+
const targetStatus = isChecked ? SelectedState.CHECKED : SelectedState.UNCHECKED;
|
|
84
|
+
function updateDown(node) {
|
|
85
|
+
var _a;
|
|
86
|
+
next[node].status = targetStatus;
|
|
87
|
+
for (const child of (_a = childrenMap[node]) !== null && _a !== void 0 ? _a : []) {
|
|
88
|
+
updateDown(child);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function updateUp(node) {
|
|
92
|
+
var _a;
|
|
93
|
+
const parents = next[node]._parents;
|
|
94
|
+
if (!(parents === null || parents === void 0 ? void 0 : parents.length))
|
|
95
|
+
return;
|
|
96
|
+
const parent = parents[parents.length - 1];
|
|
97
|
+
const siblings = (_a = childrenMap[parent]) !== null && _a !== void 0 ? _a : [];
|
|
98
|
+
const statuses = siblings.map((id) => next[id].status);
|
|
99
|
+
if (statuses.every((s) => s === SelectedState.CHECKED)) {
|
|
100
|
+
next[parent].status = SelectedState.CHECKED;
|
|
101
|
+
}
|
|
102
|
+
else if (statuses.every((s) => s === SelectedState.UNCHECKED)) {
|
|
103
|
+
next[parent].status = SelectedState.UNCHECKED;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
next[parent].status = SelectedState.INDETERMINATE;
|
|
107
|
+
}
|
|
108
|
+
updateUp(parent);
|
|
109
|
+
}
|
|
110
|
+
updateDown(targetNodeId);
|
|
111
|
+
updateUp(targetNodeId);
|
|
112
|
+
return next;
|
|
113
|
+
}
|
|
114
|
+
export function extractSelectedBranches(nodes) {
|
|
115
|
+
function visit(node) {
|
|
116
|
+
var _a;
|
|
117
|
+
const children = (_a = node.children) === null || _a === void 0 ? void 0 : _a.map(visit).filter(Boolean);
|
|
118
|
+
const isSelected = node.status === SelectedState.CHECKED || node.status === SelectedState.INDETERMINATE;
|
|
119
|
+
if (isSelected || (children && children.length > 0)) {
|
|
120
|
+
return Object.assign(Object.assign({}, node), { children });
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return nodes.map(visit).filter(Boolean);
|
|
125
|
+
}
|
|
126
|
+
export function resetTreeState(tree) {
|
|
127
|
+
const next = {};
|
|
128
|
+
for (const key in tree) {
|
|
129
|
+
next[key] = Object.assign({ status: SelectedState.UNCHECKED }, (tree[key]._parents ? { _parents: tree[key]._parents } : {}));
|
|
130
|
+
}
|
|
131
|
+
return next;
|
|
132
|
+
}
|
|
133
|
+
export function updateSelection(tree, targetNode, isChecked, multiple) {
|
|
134
|
+
if (multiple) {
|
|
135
|
+
return updateTreeSelection(tree, targetNode, isChecked);
|
|
136
|
+
}
|
|
137
|
+
// SINGLE SELECT
|
|
138
|
+
if (!isChecked) {
|
|
139
|
+
// unchecking in single mode clears everything
|
|
140
|
+
return resetTreeState(tree);
|
|
141
|
+
}
|
|
142
|
+
const cleared = resetTreeState(tree);
|
|
143
|
+
return updateTreeSelection(cleared, targetNode, true);
|
|
144
|
+
}
|
|
145
|
+
export function filterNodesByLevelKey(nodes, levelKey) {
|
|
146
|
+
const result = [];
|
|
147
|
+
function walk(node) {
|
|
148
|
+
var _a;
|
|
149
|
+
if (node.levelKey === levelKey) {
|
|
150
|
+
result.push(node);
|
|
151
|
+
}
|
|
152
|
+
(_a = node.children) === null || _a === void 0 ? void 0 : _a.forEach((child) => walk(child));
|
|
153
|
+
}
|
|
154
|
+
nodes.forEach(walk);
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
export const TreeManager = {
|
|
158
|
+
denormalizeTree: memoizeOne((tree, mapper) => denormalizeTree(tree, mapper)),
|
|
159
|
+
extractSelectedBranches: memoizeOne((nodes) => extractSelectedBranches(nodes)),
|
|
160
|
+
filterNodesByLevelKey: memoizeOne((nodes, levelKey) => filterNodesByLevelKey(nodes, levelKey)),
|
|
161
|
+
};
|
package/build/hooks/index.d.ts
CHANGED
package/build/hooks/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
type UseScrolledToArgs = {
|
|
3
|
+
threshold?: number;
|
|
4
|
+
containerRef?: React.RefObject<HTMLElement>;
|
|
5
|
+
};
|
|
6
|
+
type ScrollSource = HTMLElement | React.UIEvent<HTMLElement, UIEvent>;
|
|
7
|
+
export declare function useScrolledTo({ threshold, containerRef }?: UseScrolledToArgs): {
|
|
8
|
+
handleScroll: (source: ScrollSource) => void;
|
|
9
|
+
scrolledToTop: boolean;
|
|
10
|
+
scrolledToBottom: boolean;
|
|
11
|
+
scrollable: boolean;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
const DEFAULT_THRESHOLD = 10;
|
|
3
|
+
export function useScrolledTo({ threshold = DEFAULT_THRESHOLD, containerRef } = {}) {
|
|
4
|
+
const [scrolledToTop, setScrolledToTop] = useState(true);
|
|
5
|
+
const [scrolledToBottom, setScrolledToBottom] = useState(false);
|
|
6
|
+
const [scrollable, setScrollable] = useState(false);
|
|
7
|
+
const updateFromElement = useCallback((el) => {
|
|
8
|
+
const { scrollTop, scrollHeight, clientHeight } = el;
|
|
9
|
+
setScrollable(scrollHeight > clientHeight + threshold);
|
|
10
|
+
setScrolledToTop(scrollTop <= threshold);
|
|
11
|
+
setScrolledToBottom(scrollHeight - (scrollTop + clientHeight) <= threshold);
|
|
12
|
+
}, [threshold]);
|
|
13
|
+
const handleScroll = useCallback((source) => {
|
|
14
|
+
if (!source)
|
|
15
|
+
return;
|
|
16
|
+
// React onScroll event
|
|
17
|
+
if ('currentTarget' in source) {
|
|
18
|
+
updateFromElement(source.currentTarget);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
// Direct HTMLElement
|
|
22
|
+
updateFromElement(source);
|
|
23
|
+
}, [updateFromElement]);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!(containerRef === null || containerRef === void 0 ? void 0 : containerRef.current))
|
|
26
|
+
return;
|
|
27
|
+
const element = containerRef.current;
|
|
28
|
+
// Initial calculation
|
|
29
|
+
handleScroll(element);
|
|
30
|
+
// Watch for container size changes
|
|
31
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
32
|
+
handleScroll(element);
|
|
33
|
+
});
|
|
34
|
+
resizeObserver.observe(element);
|
|
35
|
+
return () => {
|
|
36
|
+
resizeObserver.disconnect();
|
|
37
|
+
};
|
|
38
|
+
}, [containerRef, handleScroll]);
|
|
39
|
+
return {
|
|
40
|
+
handleScroll,
|
|
41
|
+
scrolledToTop,
|
|
42
|
+
scrolledToBottom,
|
|
43
|
+
scrollable,
|
|
44
|
+
};
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/os-micro-frontend-shared",
|
|
3
3
|
"description": "Shared components and utilities for Tap Payments micro frontends",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"testVersion":
|
|
4
|
+
"version": "0.1.398-test.1",
|
|
5
|
+
"testVersion": 1,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|
|
@@ -164,4 +164,4 @@
|
|
|
164
164
|
"publishConfig": {
|
|
165
165
|
"registry": "https://registry.npmjs.org/"
|
|
166
166
|
}
|
|
167
|
-
}
|
|
167
|
+
}
|