This commit is contained in:
2025-11-11 00:48:07 +01:00
parent 992d7038e5
commit 70b9443e66
11 changed files with 258 additions and 137 deletions
+19 -22
View File
@@ -14,11 +14,15 @@ export const isPrimaryPointerEvent = (event) => {
return type === 'click' || type === 'pointerdown' || type === 'pointerup';
};
const EntryType = Object.freeze({
document: 'document',
folder: 'folder',
});
export const useEntryPointer = ({
resolveDocumentRowKey,
resolveFolderRowKey,
onSelectDocument,
onSelectFolder,
onSelectEntry,
onInspectDocument,
}) =>
useCallback(
@@ -28,41 +32,34 @@ export const useEntryPointer = ({
}
const { type, id } = entry;
if (type !== 'document' && type !== 'folder') {
if (type !== EntryType.document && type !== EntryType.folder) {
return;
}
const rowKey = entry.key
|| (type === 'document' ? resolveDocumentRowKey?.(id) : resolveFolderRowKey?.(id));
|| (type === EntryType.document ? resolveDocumentRowKey?.(id) : resolveFolderRowKey?.(id));
if (!rowKey) {
return;
}
const modifierClick = isPointerModifierEvent(event);
const primaryClick = isPrimaryPointerEvent(event);
const metadata = { modifierClick, primaryClick, rowKey };
const metadata = { modifierClick, primaryClick, rowKey, type, id };
if (type === 'document') {
if (typeof onSelectDocument === 'function') {
onSelectDocument(id, event, metadata);
}
if (!modifierClick && primaryClick && typeof onInspectDocument === 'function') {
onInspectDocument(id, metadata);
}
return;
if (typeof onSelectEntry === 'function') {
onSelectEntry(entry, event, metadata);
}
if (typeof onSelectFolder === 'function') {
onSelectFolder(id, event, metadata);
if (
type === EntryType.document
&& !modifierClick
&& primaryClick
&& typeof onInspectDocument === 'function'
) {
onInspectDocument(id, metadata);
}
},
[
resolveDocumentRowKey,
resolveFolderRowKey,
onSelectDocument,
onSelectFolder,
onInspectDocument,
],
[resolveDocumentRowKey, resolveFolderRowKey, onSelectEntry, onInspectDocument],
);
export default useEntryPointer;