@strapi/upload 5.56.0 → 5.57.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/dist/admin/hooks/useTracking.js +2 -8
- package/dist/admin/hooks/useTracking.js.map +1 -1
- package/dist/admin/hooks/useTracking.mjs +3 -8
- package/dist/admin/hooks/useTracking.mjs.map +1 -1
- package/dist/admin/legacy/hooks/useTracking.js +3 -1
- package/dist/admin/legacy/hooks/useTracking.js.map +1 -1
- package/dist/admin/legacy/hooks/useTracking.mjs +3 -1
- package/dist/admin/legacy/hooks/useTracking.mjs.map +1 -1
- package/dist/admin/legacy/pages/App/ConfigureTheView/ConfigureTheView.js +2 -1
- package/dist/admin/legacy/pages/App/ConfigureTheView/ConfigureTheView.js.map +1 -1
- package/dist/admin/legacy/pages/App/ConfigureTheView/ConfigureTheView.mjs +2 -1
- package/dist/admin/legacy/pages/App/ConfigureTheView/ConfigureTheView.mjs.map +1 -1
- package/dist/admin/legacy/pages/App/MediaLibrary.js +2 -1
- package/dist/admin/legacy/pages/App/MediaLibrary.js.map +1 -1
- package/dist/admin/legacy/pages/App/MediaLibrary.mjs +2 -1
- package/dist/admin/legacy/pages/App/MediaLibrary.mjs.map +1 -1
- package/dist/admin/pages/Assets/AssetsPage.js +24 -12
- package/dist/admin/pages/Assets/AssetsPage.js.map +1 -1
- package/dist/admin/pages/Assets/AssetsPage.mjs +25 -13
- package/dist/admin/pages/Assets/AssetsPage.mjs.map +1 -1
- package/dist/admin/pages/Assets/components/AssetActions.js +326 -0
- package/dist/admin/pages/Assets/components/AssetActions.js.map +1 -0
- package/dist/admin/pages/Assets/components/AssetActions.mjs +324 -0
- package/dist/admin/pages/Assets/components/AssetActions.mjs.map +1 -0
- package/dist/admin/pages/Assets/components/AssetActionsMenu.js +28 -309
- package/dist/admin/pages/Assets/components/AssetActionsMenu.js.map +1 -1
- package/dist/admin/pages/Assets/components/AssetActionsMenu.mjs +31 -312
- package/dist/admin/pages/Assets/components/AssetActionsMenu.mjs.map +1 -1
- package/dist/admin/pages/Assets/components/AssetContextMenu.js +79 -0
- package/dist/admin/pages/Assets/components/AssetContextMenu.js.map +1 -0
- package/dist/admin/pages/Assets/components/AssetContextMenu.mjs +77 -0
- package/dist/admin/pages/Assets/components/AssetContextMenu.mjs.map +1 -0
- package/dist/admin/pages/Assets/components/AssetDetails/AssetCropEditor.js +87 -5
- package/dist/admin/pages/Assets/components/AssetDetails/AssetCropEditor.js.map +1 -1
- package/dist/admin/pages/Assets/components/AssetDetails/AssetCropEditor.mjs +89 -7
- package/dist/admin/pages/Assets/components/AssetDetails/AssetCropEditor.mjs.map +1 -1
- package/dist/admin/pages/Assets/components/AssetDetails/AssetDetailsDrawer.js +3 -3
- package/dist/admin/pages/Assets/components/AssetDetails/AssetDetailsDrawer.js.map +1 -1
- package/dist/admin/pages/Assets/components/AssetDetails/AssetDetailsDrawer.mjs +3 -3
- package/dist/admin/pages/Assets/components/AssetDetails/AssetDetailsDrawer.mjs.map +1 -1
- package/dist/admin/pages/Assets/components/AssetDetails/useCropImg.js +62 -5
- package/dist/admin/pages/Assets/components/AssetDetails/useCropImg.js.map +1 -1
- package/dist/admin/pages/Assets/components/AssetDetails/useCropImg.mjs +60 -6
- package/dist/admin/pages/Assets/components/AssetDetails/useCropImg.mjs.map +1 -1
- package/dist/admin/pages/Assets/components/AssetsGrid.js +27 -4
- package/dist/admin/pages/Assets/components/AssetsGrid.js.map +1 -1
- package/dist/admin/pages/Assets/components/AssetsGrid.mjs +27 -4
- package/dist/admin/pages/Assets/components/AssetsGrid.mjs.map +1 -1
- package/dist/admin/pages/Assets/components/AssetsTable.js +27 -4
- package/dist/admin/pages/Assets/components/AssetsTable.js.map +1 -1
- package/dist/admin/pages/Assets/components/AssetsTable.mjs +27 -4
- package/dist/admin/pages/Assets/components/AssetsTable.mjs.map +1 -1
- package/dist/admin/pages/Assets/components/CursorAnchoredMenu.js +77 -0
- package/dist/admin/pages/Assets/components/CursorAnchoredMenu.js.map +1 -0
- package/dist/admin/pages/Assets/components/CursorAnchoredMenu.mjs +75 -0
- package/dist/admin/pages/Assets/components/CursorAnchoredMenu.mjs.map +1 -0
- package/dist/admin/pages/Assets/components/FolderActions.js +139 -0
- package/dist/admin/pages/Assets/components/FolderActions.js.map +1 -0
- package/dist/admin/pages/Assets/components/FolderActions.mjs +137 -0
- package/dist/admin/pages/Assets/components/FolderActions.mjs.map +1 -0
- package/dist/admin/pages/Assets/components/FolderActionsMenu.js +25 -119
- package/dist/admin/pages/Assets/components/FolderActionsMenu.js.map +1 -1
- package/dist/admin/pages/Assets/components/FolderActionsMenu.mjs +27 -121
- package/dist/admin/pages/Assets/components/FolderActionsMenu.mjs.map +1 -1
- package/dist/admin/pages/Assets/components/FolderContextMenu.js +67 -0
- package/dist/admin/pages/Assets/components/FolderContextMenu.js.map +1 -0
- package/dist/admin/pages/Assets/components/FolderContextMenu.mjs +65 -0
- package/dist/admin/pages/Assets/components/FolderContextMenu.mjs.map +1 -0
- package/dist/admin/pages/Assets/components/FolderTree/FolderTree.js +139 -45
- package/dist/admin/pages/Assets/components/FolderTree/FolderTree.js.map +1 -1
- package/dist/admin/pages/Assets/components/FolderTree/FolderTree.mjs +140 -47
- package/dist/admin/pages/Assets/components/FolderTree/FolderTree.mjs.map +1 -1
- package/dist/admin/pages/Assets/components/FolderTree/FolderTreeRowMenu.js +115 -0
- package/dist/admin/pages/Assets/components/FolderTree/FolderTreeRowMenu.js.map +1 -0
- package/dist/admin/pages/Assets/components/FolderTree/FolderTreeRowMenu.mjs +113 -0
- package/dist/admin/pages/Assets/components/FolderTree/FolderTreeRowMenu.mjs.map +1 -0
- package/dist/admin/pages/Assets/components/ItemContextMenu.js +125 -0
- package/dist/admin/pages/Assets/components/ItemContextMenu.js.map +1 -0
- package/dist/admin/pages/Assets/components/ItemContextMenu.mjs +122 -0
- package/dist/admin/pages/Assets/components/ItemContextMenu.mjs.map +1 -0
- package/dist/admin/pages/Assets/components/MainAreaContextMenu.js +88 -63
- package/dist/admin/pages/Assets/components/MainAreaContextMenu.js.map +1 -1
- package/dist/admin/pages/Assets/components/MainAreaContextMenu.mjs +88 -63
- package/dist/admin/pages/Assets/components/MainAreaContextMenu.mjs.map +1 -1
- package/dist/admin/pages/Assets/components/SelectionActions.js +111 -0
- package/dist/admin/pages/Assets/components/SelectionActions.js.map +1 -0
- package/dist/admin/pages/Assets/components/SelectionActions.mjs +109 -0
- package/dist/admin/pages/Assets/components/SelectionActions.mjs.map +1 -0
- package/dist/admin/pages/Assets/components/SelectionContextMenu.js +82 -0
- package/dist/admin/pages/Assets/components/SelectionContextMenu.js.map +1 -0
- package/dist/admin/pages/Assets/components/SelectionContextMenu.mjs +80 -0
- package/dist/admin/pages/Assets/components/SelectionContextMenu.mjs.map +1 -0
- package/dist/admin/pages/Assets/hooks/useAssetSelection.js +10 -0
- package/dist/admin/pages/Assets/hooks/useAssetSelection.js.map +1 -1
- package/dist/admin/pages/Assets/hooks/useAssetSelection.mjs +10 -0
- package/dist/admin/pages/Assets/hooks/useAssetSelection.mjs.map +1 -1
- package/dist/admin/pages/SettingsPage/SettingsPage.js +8 -1
- package/dist/admin/pages/SettingsPage/SettingsPage.js.map +1 -1
- package/dist/admin/pages/SettingsPage/SettingsPage.mjs +8 -1
- package/dist/admin/pages/SettingsPage/SettingsPage.mjs.map +1 -1
- package/dist/admin/src/hooks/useTracking.d.ts +0 -7
- package/dist/admin/src/pages/Assets/components/AssetActions.d.ts +70 -0
- package/dist/admin/src/pages/Assets/components/AssetActionsMenu.d.ts +5 -14
- package/dist/admin/src/pages/Assets/components/AssetContextMenu.d.ts +27 -0
- package/dist/admin/src/pages/Assets/components/AssetDetails/useCropImg.d.ts +16 -0
- package/dist/admin/src/pages/Assets/components/CursorAnchoredMenu.d.ts +32 -0
- package/dist/admin/src/pages/Assets/components/FolderActions.d.ts +48 -0
- package/dist/admin/src/pages/Assets/components/FolderActionsMenu.d.ts +4 -8
- package/dist/admin/src/pages/Assets/components/FolderContextMenu.d.ts +21 -0
- package/dist/admin/src/pages/Assets/components/FolderTree/FolderTree.d.ts +5 -1
- package/dist/admin/src/pages/Assets/components/FolderTree/FolderTreeRowMenu.d.ts +25 -0
- package/dist/admin/src/pages/Assets/components/ItemContextMenu.d.ts +53 -0
- package/dist/admin/src/pages/Assets/components/MainAreaContextMenu.d.ts +15 -1
- package/dist/admin/src/pages/Assets/components/SelectionActions.d.ts +40 -0
- package/dist/admin/src/pages/Assets/components/SelectionContextMenu.d.ts +25 -0
- package/dist/admin/src/pages/Assets/hooks/useAssetSelection.d.ts +5 -0
- package/dist/admin/src/utils/mediaLibraryVersion.d.ts +18 -0
- package/dist/admin/translations/en.json.js +8 -3
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +8 -3
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/dist/admin/utils/mediaLibraryVersion.js +24 -0
- package/dist/admin/utils/mediaLibraryVersion.js.map +1 -0
- package/dist/admin/utils/mediaLibraryVersion.mjs +20 -0
- package/dist/admin/utils/mediaLibraryVersion.mjs.map +1 -0
- package/dist/server/controllers/admin-file.js +2 -2
- package/dist/server/controllers/admin-file.js.map +1 -1
- package/dist/server/controllers/admin-file.mjs +2 -2
- package/dist/server/controllers/admin-file.mjs.map +1 -1
- package/dist/server/controllers/admin-folder.js +5 -5
- package/dist/server/controllers/admin-folder.js.map +1 -1
- package/dist/server/controllers/admin-folder.mjs +5 -5
- package/dist/server/controllers/admin-folder.mjs.map +1 -1
- package/dist/server/controllers/content-api.js +30 -7
- package/dist/server/controllers/content-api.js.map +1 -1
- package/dist/server/controllers/content-api.mjs +30 -7
- package/dist/server/controllers/content-api.mjs.map +1 -1
- package/dist/server/controllers/validation/admin/folder-file.js +4 -4
- package/dist/server/controllers/validation/admin/folder-file.js.map +1 -1
- package/dist/server/controllers/validation/admin/folder-file.mjs +2 -2
- package/dist/server/controllers/validation/admin/folder-file.mjs.map +1 -1
- package/dist/server/controllers/validation/admin/folder.js +3 -4
- package/dist/server/controllers/validation/admin/folder.js.map +1 -1
- package/dist/server/controllers/validation/admin/folder.mjs +3 -4
- package/dist/server/controllers/validation/admin/folder.mjs.map +1 -1
- package/dist/server/controllers/validation/admin/upload.js +1 -2
- package/dist/server/controllers/validation/admin/upload.js.map +1 -1
- package/dist/server/controllers/validation/admin/upload.mjs +1 -2
- package/dist/server/controllers/validation/admin/upload.mjs.map +1 -1
- package/dist/server/controllers/validation/admin/utils.js +1 -2
- package/dist/server/controllers/validation/admin/utils.js.map +1 -1
- package/dist/server/controllers/validation/admin/utils.mjs +1 -2
- package/dist/server/controllers/validation/admin/utils.mjs.map +1 -1
- package/dist/server/migrations/unsign-richtext-and-blocks-urls.js +2 -2
- package/dist/server/migrations/unsign-richtext-and-blocks-urls.js.map +1 -1
- package/dist/server/migrations/unsign-richtext-and-blocks-urls.mjs +1 -1
- package/dist/server/migrations/unsign-richtext-and-blocks-urls.mjs.map +1 -1
- package/dist/server/routes/content-api.js +3 -3
- package/dist/server/routes/content-api.js.map +1 -1
- package/dist/server/routes/content-api.mjs +3 -3
- package/dist/server/routes/content-api.mjs.map +1 -1
- package/dist/server/routes/validation/upload.js +8 -0
- package/dist/server/routes/validation/upload.js.map +1 -1
- package/dist/server/routes/validation/upload.mjs +8 -0
- package/dist/server/routes/validation/upload.mjs.map +1 -1
- package/dist/server/services/api-upload-folder.js +3 -3
- package/dist/server/services/api-upload-folder.js.map +1 -1
- package/dist/server/services/api-upload-folder.mjs +3 -3
- package/dist/server/services/api-upload-folder.mjs.map +1 -1
- package/dist/server/services/extensions/utils.js +19 -15
- package/dist/server/services/extensions/utils.js.map +1 -1
- package/dist/server/services/extensions/utils.mjs +19 -15
- package/dist/server/services/extensions/utils.mjs.map +1 -1
- package/dist/server/services/file.js +2 -2
- package/dist/server/services/file.js.map +1 -1
- package/dist/server/services/file.mjs +1 -1
- package/dist/server/services/file.mjs.map +1 -1
- package/dist/server/services/folder.js +5 -5
- package/dist/server/services/folder.js.map +1 -1
- package/dist/server/services/folder.mjs +5 -5
- package/dist/server/services/folder.mjs.map +1 -1
- package/dist/server/services/provider.js +3 -4
- package/dist/server/services/provider.js.map +1 -1
- package/dist/server/services/provider.mjs +3 -4
- package/dist/server/services/provider.mjs.map +1 -1
- package/dist/server/services/upload.js +5 -6
- package/dist/server/services/upload.js.map +1 -1
- package/dist/server/services/upload.mjs +4 -5
- package/dist/server/services/upload.mjs.map +1 -1
- package/dist/server/services/weekly-metrics.js +2 -2
- package/dist/server/services/weekly-metrics.js.map +1 -1
- package/dist/server/services/weekly-metrics.mjs +2 -2
- package/dist/server/services/weekly-metrics.mjs.map +1 -1
- package/dist/server/src/controllers/admin-folder.d.ts.map +1 -1
- package/dist/server/src/controllers/content-api.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/admin/folder.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/admin/upload.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/admin/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/mcp/ambient-instance.d.ts.map +1 -1
- package/dist/server/src/routes/validation/upload.d.ts +4 -0
- package/dist/server/src/routes/validation/upload.d.ts.map +1 -1
- package/dist/server/src/services/extensions/utils.d.ts +33 -1
- package/dist/server/src/services/extensions/utils.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/provider.d.ts.map +1 -1
- package/dist/server/src/services/upload.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useRef, useCallback, useMemo, createContext, useContext } from 'react';
|
|
3
|
+
import { useMediaLibraryPermissions } from '../../../hooks/useMediaLibraryPermissions.mjs';
|
|
4
|
+
import { useAssetSelection } from '../hooks/useAssetSelection.mjs';
|
|
5
|
+
import { AssetContextMenu } from './AssetContextMenu.mjs';
|
|
6
|
+
import { FolderContextMenu } from './FolderContextMenu.mjs';
|
|
7
|
+
import { SelectionContextMenu } from './SelectionContextMenu.mjs';
|
|
8
|
+
|
|
9
|
+
const ItemContextMenuContext = /*#__PURE__*/ createContext(null);
|
|
10
|
+
/**
|
|
11
|
+
* Called by the list items. Returns `null` outside the provider — the asset
|
|
12
|
+
* picker renders the same cards without a context menu, and a missing provider
|
|
13
|
+
* there should be a no-op rather than a crash.
|
|
14
|
+
*/ const useItemContextMenuTrigger = ()=>useContext(ItemContextMenuContext);
|
|
15
|
+
/**
|
|
16
|
+
* Mirrors what each menu would render once open. Folders have no gated actions
|
|
17
|
+
* yet, so they always have a menu.
|
|
18
|
+
*/ const hasItemActions = (permissions, isForSelection, payload)=>{
|
|
19
|
+
if (isForSelection) {
|
|
20
|
+
return permissions.canUpdate;
|
|
21
|
+
}
|
|
22
|
+
if (payload.kind === 'asset') {
|
|
23
|
+
return permissions.canUpdate || permissions.canCopyLink || permissions.canDownload;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Owns the right-click menu for the list, above both the grid and the table so
|
|
29
|
+
* one instance serves either view and the selection case has the `locations` it
|
|
30
|
+
* needs.
|
|
31
|
+
*
|
|
32
|
+
* The rule, in one place:
|
|
33
|
+
*
|
|
34
|
+
* - right-clicking an item **inside a multi-selection** opens the selection
|
|
35
|
+
* menu, acting on all of it — the file-manager behaviour, and the menu leads
|
|
36
|
+
* with the count so what it acts on is stated before the actions are
|
|
37
|
+
* - **anything else** replaces the selection with the clicked item and opens
|
|
38
|
+
* that item's own menu. That includes right-clicking an unselected item while
|
|
39
|
+
* others are selected: every file manager drops the old selection there, and
|
|
40
|
+
* the visible deselection is what stops the menu looking like it applies to
|
|
41
|
+
* items it doesn't
|
|
42
|
+
*/ const ItemContextMenuProvider = ({ locations, children })=>{
|
|
43
|
+
const { isSelected, selectOnly, selectedKeys } = useAssetSelection();
|
|
44
|
+
// Resolved here, once, and handed to each menu as it opens. Mounted with the
|
|
45
|
+
// list, so by the time anyone right-clicks the answer is in — a menu that
|
|
46
|
+
// asked for itself would render empty for a tick.
|
|
47
|
+
const permissions = useMediaLibraryPermissions();
|
|
48
|
+
const [state, setState] = useState(null);
|
|
49
|
+
const nextId = useRef(0);
|
|
50
|
+
const openForItem = useCallback((event, key, payload)=>{
|
|
51
|
+
const isForSelection = isSelected(key) && selectedKeys.size > 1;
|
|
52
|
+
if (!permissions.isLoading && !hasItemActions(permissions, isForSelection, payload)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Only once we know we're handling it — declining would otherwise cost the
|
|
56
|
+
// browser's own menu too.
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
const position = {
|
|
59
|
+
x: event.clientX,
|
|
60
|
+
y: event.clientY
|
|
61
|
+
};
|
|
62
|
+
const returnFocusTo = event.currentTarget instanceof HTMLElement ? event.currentTarget : null;
|
|
63
|
+
nextId.current += 1;
|
|
64
|
+
const id = nextId.current;
|
|
65
|
+
if (isForSelection) {
|
|
66
|
+
setState({
|
|
67
|
+
id,
|
|
68
|
+
position,
|
|
69
|
+
returnFocusTo,
|
|
70
|
+
payload: null
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// Replace the selection *before* the menu renders, so the highlight has
|
|
75
|
+
// already moved by the time the user reads the menu.
|
|
76
|
+
selectOnly(key);
|
|
77
|
+
setState({
|
|
78
|
+
id,
|
|
79
|
+
position,
|
|
80
|
+
returnFocusTo,
|
|
81
|
+
payload
|
|
82
|
+
});
|
|
83
|
+
}, [
|
|
84
|
+
isSelected,
|
|
85
|
+
selectOnly,
|
|
86
|
+
selectedKeys,
|
|
87
|
+
permissions
|
|
88
|
+
]);
|
|
89
|
+
// Only the menu that is still on screen may close it.
|
|
90
|
+
const close = useCallback((id)=>setState((prev)=>prev?.id === id ? null : prev), []);
|
|
91
|
+
const value = useMemo(()=>openForItem, [
|
|
92
|
+
openForItem
|
|
93
|
+
]);
|
|
94
|
+
return /*#__PURE__*/ jsxs(ItemContextMenuContext.Provider, {
|
|
95
|
+
value: value,
|
|
96
|
+
children: [
|
|
97
|
+
children,
|
|
98
|
+
state !== null && (state.payload === null ? /*#__PURE__*/ jsx(SelectionContextMenu, {
|
|
99
|
+
position: state.position,
|
|
100
|
+
returnFocusTo: state.returnFocusTo,
|
|
101
|
+
locations: locations,
|
|
102
|
+
onClose: ()=>close(state.id)
|
|
103
|
+
}, state.id) : state.payload.kind === 'asset' ? /*#__PURE__*/ jsx(AssetContextMenu, {
|
|
104
|
+
asset: state.payload.asset,
|
|
105
|
+
dragData: state.payload.dragData,
|
|
106
|
+
permissions: permissions,
|
|
107
|
+
position: state.position,
|
|
108
|
+
returnFocusTo: state.returnFocusTo,
|
|
109
|
+
onClose: ()=>close(state.id)
|
|
110
|
+
}, state.id) : /*#__PURE__*/ jsx(FolderContextMenu, {
|
|
111
|
+
folder: state.payload.folder,
|
|
112
|
+
dragData: state.payload.dragData,
|
|
113
|
+
position: state.position,
|
|
114
|
+
returnFocusTo: state.returnFocusTo,
|
|
115
|
+
onClose: ()=>close(state.id)
|
|
116
|
+
}, state.id))
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export { ItemContextMenuProvider, useItemContextMenuTrigger };
|
|
122
|
+
//# sourceMappingURL=ItemContextMenu.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemContextMenu.mjs","sources":["../../../../../admin/src/pages/Assets/components/ItemContextMenu.tsx"],"sourcesContent":["import {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\n\nimport { useMediaLibraryPermissions } from '../../../hooks/useMediaLibraryPermissions';\nimport { useAssetSelection } from '../hooks/useAssetSelection';\n\nimport { AssetContextMenu } from './AssetContextMenu';\nimport { FolderContextMenu } from './FolderContextMenu';\nimport { SelectionContextMenu } from './SelectionContextMenu';\n\nimport type { AssetActionPermissions } from './AssetActions';\nimport type { CursorPosition } from './CursorAnchoredMenu';\nimport type { File } from '../../../../../shared/contracts/files';\nimport type { Folder } from '../../../../../shared/contracts/folders';\nimport type { DragFileData, DragFolderData } from '../../../types/dnd';\nimport type { ItemLocations } from '../../../utils/itemLocations';\nimport type { ItemKey } from '../utils/selection';\n\n/**\n * What a card or row hands over when it is right-clicked. It passes its own\n * asset rather than a key alone, so nothing here has to resolve keys back to\n * items — the item is already in scope where the gesture happens.\n */\nexport type ContextMenuPayload =\n | { kind: 'asset'; asset: File; dragData: DragFileData }\n | { kind: 'folder'; folder: Folder; dragData: DragFolderData };\n\ntype OpenForItem = (event: React.MouseEvent, key: ItemKey, payload: ContextMenuPayload) => void;\n\nconst ItemContextMenuContext = createContext<OpenForItem | null>(null);\n\n/**\n * Called by the list items. Returns `null` outside the provider — the asset\n * picker renders the same cards without a context menu, and a missing provider\n * there should be a no-op rather than a crash.\n */\nexport const useItemContextMenuTrigger = (): OpenForItem | null =>\n useContext(ItemContextMenuContext);\n\ninterface OpenState {\n /**\n * Distinguishes one opening from the next.\n *\n * A right-click while a menu is open is two events: `pointerdown`, which\n * Radix treats as \"dismiss\", then `contextmenu`, which opens the next menu.\n * The dismissed menu's own effect runs *after* the new one has mounted, so a\n * plain `close()` would clear state that no longer belongs to it — and the\n * second right-click would appear to do nothing.\n */\n id: number;\n position: CursorPosition;\n /** The card or row that was right-clicked. */\n returnFocusTo: HTMLElement | null;\n payload: ContextMenuPayload | null;\n}\n\n/**\n * Mirrors what each menu would render once open. Folders have no gated actions\n * yet, so they always have a menu.\n */\nconst hasItemActions = (\n permissions: AssetActionPermissions,\n isForSelection: boolean,\n payload: ContextMenuPayload\n) => {\n if (isForSelection) {\n return permissions.canUpdate;\n }\n\n if (payload.kind === 'asset') {\n return permissions.canUpdate || permissions.canCopyLink || permissions.canDownload;\n }\n\n return true;\n};\n\ninterface ItemContextMenuProviderProps {\n /**\n * Real location of every loaded row, so a selection move validates each item\n * against its own parent — same input the bulk bar takes.\n */\n locations: ItemLocations;\n children: ReactNode;\n}\n\n/**\n * Owns the right-click menu for the list, above both the grid and the table so\n * one instance serves either view and the selection case has the `locations` it\n * needs.\n *\n * The rule, in one place:\n *\n * - right-clicking an item **inside a multi-selection** opens the selection\n * menu, acting on all of it — the file-manager behaviour, and the menu leads\n * with the count so what it acts on is stated before the actions are\n * - **anything else** replaces the selection with the clicked item and opens\n * that item's own menu. That includes right-clicking an unselected item while\n * others are selected: every file manager drops the old selection there, and\n * the visible deselection is what stops the menu looking like it applies to\n * items it doesn't\n */\nexport const ItemContextMenuProvider = ({ locations, children }: ItemContextMenuProviderProps) => {\n const { isSelected, selectOnly, selectedKeys } = useAssetSelection();\n // Resolved here, once, and handed to each menu as it opens. Mounted with the\n // list, so by the time anyone right-clicks the answer is in — a menu that\n // asked for itself would render empty for a tick.\n const permissions = useMediaLibraryPermissions();\n const [state, setState] = useState<OpenState | null>(null);\n const nextId = useRef(0);\n\n const openForItem = useCallback<OpenForItem>(\n (event, key, payload) => {\n const isForSelection = isSelected(key) && selectedKeys.size > 1;\n\n if (!permissions.isLoading && !hasItemActions(permissions, isForSelection, payload)) {\n return;\n }\n\n // Only once we know we're handling it — declining would otherwise cost the\n // browser's own menu too.\n event.preventDefault();\n\n const position = { x: event.clientX, y: event.clientY };\n const returnFocusTo = event.currentTarget instanceof HTMLElement ? event.currentTarget : null;\n nextId.current += 1;\n const id = nextId.current;\n\n if (isForSelection) {\n setState({ id, position, returnFocusTo, payload: null });\n return;\n }\n\n // Replace the selection *before* the menu renders, so the highlight has\n // already moved by the time the user reads the menu.\n selectOnly(key);\n setState({ id, position, returnFocusTo, payload });\n },\n [isSelected, selectOnly, selectedKeys, permissions]\n );\n\n // Only the menu that is still on screen may close it.\n const close = useCallback(\n (id: number) => setState((prev) => (prev?.id === id ? null : prev)),\n []\n );\n\n const value = useMemo(() => openForItem, [openForItem]);\n\n return (\n <ItemContextMenuContext.Provider value={value}>\n {children}\n {state !== null &&\n (state.payload === null ? (\n <SelectionContextMenu\n key={state.id}\n position={state.position}\n returnFocusTo={state.returnFocusTo}\n locations={locations}\n onClose={() => close(state.id)}\n />\n ) : state.payload.kind === 'asset' ? (\n <AssetContextMenu\n // A fresh menu per gesture: the actions carry dialog state, and\n // reusing the instance across two right-clicks would carry it over.\n // Keyed on the opening rather than the item, so right-clicking the\n // same card twice still remounts.\n key={state.id}\n asset={state.payload.asset}\n dragData={state.payload.dragData}\n permissions={permissions}\n position={state.position}\n returnFocusTo={state.returnFocusTo}\n onClose={() => close(state.id)}\n />\n ) : (\n <FolderContextMenu\n key={state.id}\n folder={state.payload.folder}\n dragData={state.payload.dragData}\n position={state.position}\n returnFocusTo={state.returnFocusTo}\n onClose={() => close(state.id)}\n />\n ))}\n </ItemContextMenuContext.Provider>\n );\n};\n"],"names":["ItemContextMenuContext","createContext","useItemContextMenuTrigger","useContext","hasItemActions","permissions","isForSelection","payload","canUpdate","kind","canCopyLink","canDownload","ItemContextMenuProvider","locations","children","isSelected","selectOnly","selectedKeys","useAssetSelection","useMediaLibraryPermissions","state","setState","useState","nextId","useRef","openForItem","useCallback","event","key","size","isLoading","preventDefault","position","x","clientX","y","clientY","returnFocusTo","currentTarget","HTMLElement","current","id","close","prev","value","useMemo","_jsxs","Provider","_jsx","SelectionContextMenu","onClose","AssetContextMenu","asset","dragData","FolderContextMenu","folder"],"mappings":";;;;;;;;AAoCA,MAAMA,uCAAyBC,aAAAA,CAAkC,IAAA,CAAA;AAEjE;;;;AAIC,IACM,MAAMC,yBAAAA,GAA4B,IACvCC,WAAWH,sBAAAA;AAmBb;;;AAGC,IACD,MAAMI,cAAAA,GAAiB,CACrBC,WAAAA,EACAC,cAAAA,EACAC,OAAAA,GAAAA;AAEA,IAAA,IAAID,cAAAA,EAAgB;AAClB,QAAA,OAAOD,YAAYG,SAAS;AAC9B,IAAA;IAEA,IAAID,OAAAA,CAAQE,IAAI,KAAK,OAAA,EAAS;AAC5B,QAAA,OAAOJ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b,OAAO,CAAC6C,KAAK;gBAC1BC,QAAAA,EAAUjC,KAAAA,CAAMb,OAAO,CAAC8C,QAAQ;gBAChChD,WAAAA,EAAaA,WAAAA;AACb2B,gBAAAA,QAAAA,EAAUZ,MAAMY,QAAQ;AACxBK,gBAAAA,aAAAA,EAAejB,MAAMiB,aAAa;gBAClCa,OAAAA,EAAS,IAAMR,KAAAA,CAAMtB,KAAAA,CAAMqB,EAAE;eANxBrB,KAAAA,CAAMqB,EAAE,kBASfO,GAAA,CAACM,iBAAAA,EAAAA;gBAECC,MAAAA,EAAQnC,KAAAA,CAAMb,OAAO,CAACgD,MAAM;gBAC5BF,QAAAA,EAAUjC,KAAAA,CAAMb,OAAO,CAAC8C,QAAQ;AAChCrB,gBAAAA,QAAAA,EAAUZ,MAAMY,QAAQ;AACxBK,gBAAAA,aAAAA,EAAejB,MAAMiB,aAAa;gBAClCa,OAAAA,EAAS,IAAMR,KAAAA,CAAMtB,KAAAA,CAAMqB,EAAE;AALxBrB,aAAAA,EAAAA,KAAAA,CAAMqB,EAAE,CAOjB;;;AAGR;;;;"}
|
|
@@ -7,6 +7,7 @@ var icons = require('@strapi/icons');
|
|
|
7
7
|
var reactIntl = require('react-intl');
|
|
8
8
|
var translations = require('../../../utils/translations.js');
|
|
9
9
|
var ActionsMenuContent = require('./ActionsMenuContent.js');
|
|
10
|
+
var SelectionActions = require('./SelectionActions.js');
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* The admin layout marks the element that scrolls the main column. Listening on
|
|
@@ -71,13 +72,13 @@ const LOCATOR_STYLE = {
|
|
|
71
72
|
* Deliberately background-only. Right-clicking an asset, a folder or a table
|
|
72
73
|
* row is left alone — those carry `data-native-context-menu` and keep the
|
|
73
74
|
* browser's menu (which is what you want over a thumbnail or a filename).
|
|
74
|
-
*/ const MainAreaContextMenu = ({ onCreateFolder, onImportFiles, onImportFromUrl, disabled })=>{
|
|
75
|
+
*/ const MainAreaContextMenu = ({ onCreateFolder, onImportFiles, onImportFromUrl, disabled, containerSelector = SCROLL_ROOT_SELECTOR, locations })=>{
|
|
75
76
|
const { formatMessage } = reactIntl.useIntl();
|
|
76
77
|
const [position, setPosition] = React.useState(null);
|
|
77
78
|
const [locator, setLocator] = React.useState(null);
|
|
78
79
|
const anchorRef = React.useCallback((node)=>setLocator(node), []);
|
|
79
80
|
React.useEffect(()=>{
|
|
80
|
-
const container = locator?.closest(
|
|
81
|
+
const container = locator?.closest(containerSelector);
|
|
81
82
|
if (!container || disabled) {
|
|
82
83
|
return;
|
|
83
84
|
}
|
|
@@ -101,8 +102,81 @@ const LOCATOR_STYLE = {
|
|
|
101
102
|
return ()=>container.removeEventListener('contextmenu', handleContextMenu);
|
|
102
103
|
}, [
|
|
103
104
|
locator,
|
|
104
|
-
disabled
|
|
105
|
+
disabled,
|
|
106
|
+
containerSelector
|
|
105
107
|
]);
|
|
108
|
+
const createItems = /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
109
|
+
children: [
|
|
110
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Item, {
|
|
111
|
+
onSelect: onCreateFolder,
|
|
112
|
+
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Folder, {}),
|
|
113
|
+
children: formatMessage({
|
|
114
|
+
id: translations.getTranslationKey('folder.create.title'),
|
|
115
|
+
defaultMessage: 'New folder'
|
|
116
|
+
})
|
|
117
|
+
}),
|
|
118
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Item, {
|
|
119
|
+
onSelect: onImportFiles,
|
|
120
|
+
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Files, {}),
|
|
121
|
+
children: formatMessage({
|
|
122
|
+
id: translations.getTranslationKey('import-files'),
|
|
123
|
+
defaultMessage: 'File upload'
|
|
124
|
+
})
|
|
125
|
+
}),
|
|
126
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Item, {
|
|
127
|
+
onSelect: onImportFromUrl,
|
|
128
|
+
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Link, {}),
|
|
129
|
+
children: formatMessage({
|
|
130
|
+
id: translations.getTranslationKey('import-from-url'),
|
|
131
|
+
defaultMessage: 'File upload from URL'
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
/**
|
|
137
|
+
* `selectionItems` leads the menu when something is selected, so the actions
|
|
138
|
+
* that apply to the selection come before the ones that create new things.
|
|
139
|
+
*/ const renderMenu = (selectionItems)=>/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Menu.Root, {
|
|
140
|
+
modal: false,
|
|
141
|
+
open: position !== null,
|
|
142
|
+
onOpenChange: (open)=>{
|
|
143
|
+
if (!open) {
|
|
144
|
+
setPosition(null);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
children: [
|
|
148
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Trigger, {
|
|
149
|
+
tabIndex: -1,
|
|
150
|
+
// No visible content, so the name has to come from `aria-label` —
|
|
151
|
+
// the trigger's `label` prop renders as button text, which would
|
|
152
|
+
// defeat the point of an invisible anchor. Radix points the menu's
|
|
153
|
+
// `aria-labelledby` at this element, so it names the menu too.
|
|
154
|
+
endIcon: null,
|
|
155
|
+
"aria-label": formatMessage({
|
|
156
|
+
id: translations.getTranslationKey('list.context-menu.label'),
|
|
157
|
+
defaultMessage: 'Media library actions'
|
|
158
|
+
}),
|
|
159
|
+
style: {
|
|
160
|
+
...CURSOR_ANCHOR_STYLE,
|
|
161
|
+
top: position?.y ?? 0,
|
|
162
|
+
left: position?.x ?? 0
|
|
163
|
+
}
|
|
164
|
+
}),
|
|
165
|
+
/*#__PURE__*/ jsxRuntime.jsxs(ActionsMenuContent.ActionsMenuContent, {
|
|
166
|
+
popoverPlacement: "bottom-start",
|
|
167
|
+
zIndex: 2,
|
|
168
|
+
minWidth: "22rem",
|
|
169
|
+
// The anchor is invisible and sits wherever the cursor was, so
|
|
170
|
+
// handing focus back to it on close would be a focus ring nobody can
|
|
171
|
+
// see. Let it fall to the body instead.
|
|
172
|
+
onCloseAutoFocus: (event)=>event.preventDefault(),
|
|
173
|
+
children: [
|
|
174
|
+
selectionItems,
|
|
175
|
+
createItems
|
|
176
|
+
]
|
|
177
|
+
})
|
|
178
|
+
]
|
|
179
|
+
});
|
|
106
180
|
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
107
181
|
children: [
|
|
108
182
|
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
@@ -110,69 +184,20 @@ const LOCATOR_STYLE = {
|
|
|
110
184
|
style: LOCATOR_STYLE,
|
|
111
185
|
"aria-hidden": true
|
|
112
186
|
}),
|
|
113
|
-
!disabled && /*#__PURE__*/ jsxRuntime.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
onOpenChange: (open)=>{
|
|
117
|
-
if (!open) {
|
|
118
|
-
setPosition(null);
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
children: [
|
|
122
|
-
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Trigger, {
|
|
123
|
-
tabIndex: -1,
|
|
124
|
-
// No visible content, so the name has to come from `aria-label` —
|
|
125
|
-
// the trigger's `label` prop renders as button text, which would
|
|
126
|
-
// defeat the point of an invisible anchor. Radix points the menu's
|
|
127
|
-
// `aria-labelledby` at this element, so it names the menu too.
|
|
128
|
-
endIcon: null,
|
|
129
|
-
"aria-label": formatMessage({
|
|
130
|
-
id: translations.getTranslationKey('list.context-menu.label'),
|
|
131
|
-
defaultMessage: 'Media library actions'
|
|
132
|
-
}),
|
|
133
|
-
style: {
|
|
134
|
-
...CURSOR_ANCHOR_STYLE,
|
|
135
|
-
top: position?.y ?? 0,
|
|
136
|
-
left: position?.x ?? 0
|
|
137
|
-
}
|
|
138
|
-
}),
|
|
139
|
-
/*#__PURE__*/ jsxRuntime.jsxs(ActionsMenuContent.ActionsMenuContent, {
|
|
140
|
-
popoverPlacement: "bottom-start",
|
|
141
|
-
zIndex: 2,
|
|
142
|
-
minWidth: "22rem",
|
|
143
|
-
// The anchor is invisible and sits wherever the cursor was, so
|
|
144
|
-
// handing focus back to it on close would be a focus ring nobody can
|
|
145
|
-
// see. Let it fall to the body instead.
|
|
146
|
-
onCloseAutoFocus: (event)=>event.preventDefault(),
|
|
187
|
+
!disabled && (locations ? /*#__PURE__*/ jsxRuntime.jsx(SelectionActions.SelectionActions, {
|
|
188
|
+
locations: locations,
|
|
189
|
+
children: ({ count, hasActions, items, dialogs })=>/*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
147
190
|
children: [
|
|
148
|
-
/*#__PURE__*/ jsxRuntime.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}),
|
|
156
|
-
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Item, {
|
|
157
|
-
onSelect: onImportFiles,
|
|
158
|
-
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Files, {}),
|
|
159
|
-
children: formatMessage({
|
|
160
|
-
id: translations.getTranslationKey('import-files'),
|
|
161
|
-
defaultMessage: 'File upload'
|
|
162
|
-
})
|
|
163
|
-
}),
|
|
164
|
-
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Item, {
|
|
165
|
-
onSelect: onImportFromUrl,
|
|
166
|
-
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Link, {}),
|
|
167
|
-
children: formatMessage({
|
|
168
|
-
id: translations.getTranslationKey('import-from-url'),
|
|
169
|
-
defaultMessage: 'File upload from URL'
|
|
170
|
-
})
|
|
171
|
-
})
|
|
191
|
+
renderMenu(count > 0 && hasActions ? /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
192
|
+
children: [
|
|
193
|
+
items,
|
|
194
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Separator, {})
|
|
195
|
+
]
|
|
196
|
+
}) : null),
|
|
197
|
+
dialogs
|
|
172
198
|
]
|
|
173
199
|
})
|
|
174
|
-
|
|
175
|
-
})
|
|
200
|
+
}) : renderMenu(null))
|
|
176
201
|
]
|
|
177
202
|
});
|
|
178
203
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MainAreaContextMenu.js","sources":["../../../../../admin/src/pages/Assets/components/MainAreaContextMenu.tsx"],"sourcesContent":["import { useCallback, useEffect, useState, type CSSProperties } from 'react';\n\nimport { Menu } from '@strapi/design-system';\nimport { Files, Folder as FolderIcon, Link } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\n\nimport { getTranslationKey } from '../../../utils/translations';\n\nimport { ActionsMenuContent } from './ActionsMenuContent';\n\n/**\n * The admin layout marks the element that scrolls the main column. Listening on\n * it rather than a wrapper of our own is what makes the whole column part of the\n * hit area: it carries a responsive `padding-bottom` (16 / 24 / 40px) that no\n * descendant can cover, and that strip is exactly where a right-click \"below the\n * list\" lands.\n */\nconst SCROLL_ROOT_SELECTOR = '[data-strapi-main-content]';\n\n/**\n * Subtrees that keep the browser's own context menu instead of opening the\n * create menu.\n *\n * `data-native-context-menu` is the explicit opt-out carried by the list items\n * themselves (asset cards, folder cards, table rows) and by the bulk actions\n * bar — right-clicking one of those must behave exactly as it does today. The\n * rest are the generic cases where the native menu is the useful one: links,\n * buttons and anything the user can type into or select text in.\n *\n * `thead` covers the table's header row, which is chrome rather than empty\n * background even though it carries no `data-native-context-menu` item.\n */\nconst NATIVE_CONTEXT_MENU_SELECTOR = [\n '[data-native-context-menu]',\n 'thead',\n 'a',\n 'button',\n 'input',\n 'textarea',\n 'select',\n '[contenteditable=\"true\"]',\n].join(', ');\n\n/**\n * The menu is anchored to a zero-sized element parked at the cursor, because\n * the design system's `Menu` is a dropdown: it positions its content against a\n * trigger, and there is no real trigger for a right-click on empty space.\n *\n * Inline styles rather than a `styled` wrapper — the trigger renders a design\n * system `Button`, and losing the specificity race with its own class would put\n * a stray button on the page.\n */\nconst CURSOR_ANCHOR_STYLE: CSSProperties = {\n position: 'fixed',\n width: 0,\n height: 0,\n minWidth: 0,\n minHeight: 0,\n padding: 0,\n border: 0,\n opacity: 0,\n overflow: 'hidden',\n pointerEvents: 'none',\n};\n\nconst LOCATOR_STYLE: CSSProperties = { height: 0 };\n\ninterface CursorPosition {\n x: number;\n y: number;\n}\n\ninterface MainAreaContextMenuProps {\n /** Opens the \"new folder\" dialog in the folder currently on screen. */\n onCreateFolder: () => void;\n /** Opens the native file picker — same entry point as the header \"New\" menu. */\n onImportFiles: () => void;\n /** Opens the \"import from URL\" dialog. */\n onImportFromUrl: () => void;\n /**\n * RBAC gate — without `assets.create` there is nothing to offer, so the\n * right-click falls through to the browser. Required (not defaulted) so a\n * permission gate can't silently regress to permissive.\n */\n disabled: boolean;\n}\n\n/**\n * Drive/Dropbox-style right-click on the empty parts of the assets area: the\n * same creation actions the header \"New\" menu offers, acting on the folder\n * currently open.\n *\n * Renders no wrapper — it finds the scrolling column and listens there, so the\n * hit area is the whole column including the padding below the list.\n *\n * Deliberately background-only. Right-clicking an asset, a folder or a table\n * row is left alone — those carry `data-native-context-menu` and keep the\n * browser's menu (which is what you want over a thumbnail or a filename).\n */\nexport const MainAreaContextMenu = ({\n onCreateFolder,\n onImportFiles,\n onImportFromUrl,\n disabled,\n}: MainAreaContextMenuProps) => {\n const { formatMessage } = useIntl();\n const [position, setPosition] = useState<CursorPosition | null>(null);\n const [locator, setLocator] = useState<HTMLElement | null>(null);\n\n const anchorRef = useCallback((node: HTMLElement | null) => setLocator(node), []);\n\n useEffect(() => {\n const container = locator?.closest<HTMLElement>(SCROLL_ROOT_SELECTOR);\n\n if (!container || disabled) {\n return;\n }\n\n const handleContextMenu = (event: MouseEvent) => {\n if (!(event.target instanceof Element)) {\n return;\n }\n\n if (event.target.closest(NATIVE_CONTEXT_MENU_SELECTOR)) {\n return;\n }\n\n event.preventDefault();\n // A right-click while the menu is open reaches Radix's dismiss listener\n // first, which closes it; re-anchoring here reopens it under the new\n // cursor rather than leaving the user with a menu that just vanished.\n setPosition({ x: event.clientX, y: event.clientY });\n };\n\n container.addEventListener('contextmenu', handleContextMenu);\n\n return () => container.removeEventListener('contextmenu', handleContextMenu);\n }, [locator, disabled]);\n\n return (\n <>\n <div ref={anchorRef} style={LOCATOR_STYLE} aria-hidden />\n {/* Non-modal, like the row-level menus: a right-click elsewhere is both\n \"close this\" and \"open that\", which a modal layer would swallow.\n Skipped entirely without the permission — the anchor is a real\n (if invisible) button, and one that can never open is noise in the\n accessibility tree. */}\n {!disabled && (\n <Menu.Root\n modal={false}\n open={position !== null}\n onOpenChange={(open) => {\n if (!open) {\n setPosition(null);\n }\n }}\n >\n <Menu.Trigger\n tabIndex={-1}\n // No visible content, so the name has to come from `aria-label` —\n // the trigger's `label` prop renders as button text, which would\n // defeat the point of an invisible anchor. Radix points the menu's\n // `aria-labelledby` at this element, so it names the menu too.\n endIcon={null}\n aria-label={formatMessage({\n id: getTranslationKey('list.context-menu.label'),\n defaultMessage: 'Media library actions',\n })}\n style={{ ...CURSOR_ANCHOR_STYLE, top: position?.y ?? 0, left: position?.x ?? 0 }}\n />\n <ActionsMenuContent\n popoverPlacement=\"bottom-start\"\n zIndex={2}\n minWidth=\"22rem\"\n // The anchor is invisible and sits wherever the cursor was, so\n // handing focus back to it on close would be a focus ring nobody can\n // see. Let it fall to the body instead.\n onCloseAutoFocus={(event) => event.preventDefault()}\n >\n <Menu.Item onSelect={onCreateFolder} startIcon={<FolderIcon />}>\n {formatMessage({\n id: getTranslationKey('folder.create.title'),\n defaultMessage: 'New folder',\n })}\n </Menu.Item>\n <Menu.Item onSelect={onImportFiles} startIcon={<Files />}>\n {formatMessage({\n id: getTranslationKey('import-files'),\n defaultMessage: 'File upload',\n })}\n </Menu.Item>\n <Menu.Item onSelect={onImportFromUrl} startIcon={<Link />}>\n {formatMessage({\n id: getTranslationKey('import-from-url'),\n defaultMessage: 'File upload from URL',\n })}\n </Menu.Item>\n </ActionsMenuContent>\n </Menu.Root>\n )}\n </>\n );\n};\n"],"names":["SCROLL_ROOT_SELECTOR","NATIVE_CONTEXT_MENU_SELECTOR","join","CURSOR_ANCHOR_STYLE","position","width","height","minWidth","minHeight","padding","border","opacity","overflow","pointerEvents","LOCATOR_STYLE","MainAreaContextMenu","onCreateFolder","onImportFiles","onImportFromUrl","disabled","formatMessage","useIntl","setPosition","useState","locator","setLocator","anchorRef","useCallback","node","useEffect","container","closest","handleContextMenu","event","target","Element","preventDefault","x","clientX","y","clientY","addEventListener","removeEventListener","_jsxs","_Fragment","_jsx","div","ref","style","aria-hidden","Menu","Root","modal","open","onOpenChange","Trigger","tabIndex","endIcon","aria-label","id","getTranslationKey","defaultMessage","top","left","ActionsMenuContent","popoverPlacement","zIndex","onCloseAutoFocus","Item","onSelect","startIcon","FolderIcon","Files","Link"],"mappings":";;;;;;;;;;AAUA;;;;;;AAMC,IACD,MAAMA,oBAAAA,GAAuB,4BAAA;AAE7B;;;;;;;;;;;;AAYC,IACD,MAAMC,4BAAAA,GAA+B;AACnC,IAAA,4BAAA;AACA,IAAA,OAAA;AACA,IAAA,GAAA;AACA,IAAA,QAAA;AACA,IAAA,OAAA;AACA,IAAA,UAAA;AACA,IAAA,QAAA;AACA,IAAA;AACD,CAAA,CAACC,IAAI,CAAC,IAAA,CAAA;AAEP;;;;;;;;AAQC,IACD,MAAMC,mBAAAA,GAAqC;IACzCC,QAAAA,EAAU,OAAA;IACVC,KAAAA,EAAO,CAAA;IACPC,MAAAA,EAAQ,CAAA;IACRC,QAAAA,EAAU,CAAA;IACVC,SAAAA,EAAW,CAAA;IACXC,OAAAA,EAAS,CAAA;IACTC,MAAAA,EAAQ,CAAA;IACRC,OAAAA,EAAS,CAAA;IACTC,QAAAA,EAAU,QAAA;IACVC,aAAAA,EAAe;AACjB,CAAA;AAEA,MAAMC,aAAAA,GAA+B;IAAER,MAAAA,EAAQ;AAAE,CAAA;AAsBjD;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cAAA,CAAC0B,YAAAA,EAAAA,EAAAA,CAAAA;0CAC9CnD,aAAAA,CAAc;AACbuC,oCAAAA,EAAAA,EAAIC,8BAAAA,CAAkB,qBAAA,CAAA;oCACtBC,cAAAA,EAAgB;AAClB,iCAAA;;AAEF,0CAAAhB,cAAA,CAACK,kBAAKkB,IAAI,EAAA;gCAACC,QAAAA,EAAUpD,aAAAA;AAAeqD,gCAAAA,SAAAA,gBAAWzB,cAAA,CAAC2B,WAAAA,EAAAA,EAAAA,CAAAA;0CAC7CpD,aAAAA,CAAc;AACbuC,oCAAAA,EAAAA,EAAIC,8BAAAA,CAAkB,cAAA,CAAA;oCACtBC,cAAAA,EAAgB;AAClB,iCAAA;;AAEF,0CAAAhB,cAAA,CAACK,kBAAKkB,IAAI,EAAA;gCAACC,QAAAA,EAAUnD,eAAAA;AAAiBoD,gCAAAA,SAAAA,gBAAWzB,cAAA,CAAC4B,UAAAA,EAAAA,EAAAA,CAAAA;0CAC/CrD,aAAAA,CAAc;AACbuC,oCAAAA,EAAAA,EAAIC,8BAAAA,CAAkB,iBAAA,CAAA;oCACtBC,cAAAA,EAAgB;AAClB,iCAAA;;;;;;;;AAOd;;;;"}
|
|
1
|
+
{"version":3,"file":"MainAreaContextMenu.js","sources":["../../../../../admin/src/pages/Assets/components/MainAreaContextMenu.tsx"],"sourcesContent":["import { useCallback, useEffect, useState, type CSSProperties, type ReactNode } from 'react';\n\nimport { Menu } from '@strapi/design-system';\nimport { Files, Folder as FolderIcon, Link } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\n\nimport { getTranslationKey } from '../../../utils/translations';\n\nimport { ActionsMenuContent } from './ActionsMenuContent';\nimport { SelectionActions } from './SelectionActions';\n\nimport type { ItemLocations } from '../../../utils/itemLocations';\n\n/**\n * The admin layout marks the element that scrolls the main column. Listening on\n * it rather than a wrapper of our own is what makes the whole column part of the\n * hit area: it carries a responsive `padding-bottom` (16 / 24 / 40px) that no\n * descendant can cover, and that strip is exactly where a right-click \"below the\n * list\" lands.\n */\nconst SCROLL_ROOT_SELECTOR = '[data-strapi-main-content]';\n\n/**\n * Subtrees that keep the browser's own context menu instead of opening the\n * create menu.\n *\n * `data-native-context-menu` is the explicit opt-out carried by the list items\n * themselves (asset cards, folder cards, table rows) and by the bulk actions\n * bar — right-clicking one of those must behave exactly as it does today. The\n * rest are the generic cases where the native menu is the useful one: links,\n * buttons and anything the user can type into or select text in.\n *\n * `thead` covers the table's header row, which is chrome rather than empty\n * background even though it carries no `data-native-context-menu` item.\n */\nconst NATIVE_CONTEXT_MENU_SELECTOR = [\n '[data-native-context-menu]',\n 'thead',\n 'a',\n 'button',\n 'input',\n 'textarea',\n 'select',\n '[contenteditable=\"true\"]',\n].join(', ');\n\n/**\n * The menu is anchored to a zero-sized element parked at the cursor, because\n * the design system's `Menu` is a dropdown: it positions its content against a\n * trigger, and there is no real trigger for a right-click on empty space.\n *\n * Inline styles rather than a `styled` wrapper — the trigger renders a design\n * system `Button`, and losing the specificity race with its own class would put\n * a stray button on the page.\n */\nconst CURSOR_ANCHOR_STYLE: CSSProperties = {\n position: 'fixed',\n width: 0,\n height: 0,\n minWidth: 0,\n minHeight: 0,\n padding: 0,\n border: 0,\n opacity: 0,\n overflow: 'hidden',\n pointerEvents: 'none',\n};\n\nconst LOCATOR_STYLE: CSSProperties = { height: 0 };\n\ninterface CursorPosition {\n x: number;\n y: number;\n}\n\ninterface MainAreaContextMenuProps {\n /** Opens the \"new folder\" dialog in the folder currently on screen. */\n onCreateFolder: () => void;\n /** Opens the native file picker — same entry point as the header \"New\" menu. */\n onImportFiles: () => void;\n /** Opens the \"import from URL\" dialog. */\n onImportFromUrl: () => void;\n /**\n * RBAC gate — without `assets.create` there is nothing to offer, so the\n * right-click falls through to the browser. Required (not defaulted) so a\n * permission gate can't silently regress to permissive.\n */\n disabled: boolean;\n /**\n * The element to listen on, found from where this renders. Defaults to the\n * scrolling main column.\n */\n containerSelector?: string;\n /**\n * Real location of every loaded row. Supplying it turns on the selection\n * section: with items selected, their bulk actions lead the menu, above the\n * creation ones. Omitted, the menu offers creation only — which is what the\n * folder tree wants, where the asset selection is not what you are pointing\n * at.\n */\n locations?: ItemLocations;\n}\n\n/**\n * Drive/Dropbox-style right-click on the empty parts of the assets area: the\n * same creation actions the header \"New\" menu offers, acting on the folder\n * currently open.\n *\n * Renders no wrapper — it finds the scrolling column and listens there, so the\n * hit area is the whole column including the padding below the list.\n *\n * Deliberately background-only. Right-clicking an asset, a folder or a table\n * row is left alone — those carry `data-native-context-menu` and keep the\n * browser's menu (which is what you want over a thumbnail or a filename).\n */\nexport const MainAreaContextMenu = ({\n onCreateFolder,\n onImportFiles,\n onImportFromUrl,\n disabled,\n containerSelector = SCROLL_ROOT_SELECTOR,\n locations,\n}: MainAreaContextMenuProps) => {\n const { formatMessage } = useIntl();\n const [position, setPosition] = useState<CursorPosition | null>(null);\n const [locator, setLocator] = useState<HTMLElement | null>(null);\n\n const anchorRef = useCallback((node: HTMLElement | null) => setLocator(node), []);\n\n useEffect(() => {\n const container = locator?.closest<HTMLElement>(containerSelector);\n\n if (!container || disabled) {\n return;\n }\n\n const handleContextMenu = (event: MouseEvent) => {\n if (!(event.target instanceof Element)) {\n return;\n }\n\n if (event.target.closest(NATIVE_CONTEXT_MENU_SELECTOR)) {\n return;\n }\n\n event.preventDefault();\n // A right-click while the menu is open reaches Radix's dismiss listener\n // first, which closes it; re-anchoring here reopens it under the new\n // cursor rather than leaving the user with a menu that just vanished.\n setPosition({ x: event.clientX, y: event.clientY });\n };\n\n container.addEventListener('contextmenu', handleContextMenu);\n\n return () => container.removeEventListener('contextmenu', handleContextMenu);\n }, [locator, disabled, containerSelector]);\n\n const createItems = (\n <>\n <Menu.Item onSelect={onCreateFolder} startIcon={<FolderIcon />}>\n {formatMessage({\n id: getTranslationKey('folder.create.title'),\n defaultMessage: 'New folder',\n })}\n </Menu.Item>\n <Menu.Item onSelect={onImportFiles} startIcon={<Files />}>\n {formatMessage({\n id: getTranslationKey('import-files'),\n defaultMessage: 'File upload',\n })}\n </Menu.Item>\n <Menu.Item onSelect={onImportFromUrl} startIcon={<Link />}>\n {formatMessage({\n id: getTranslationKey('import-from-url'),\n defaultMessage: 'File upload from URL',\n })}\n </Menu.Item>\n </>\n );\n\n /**\n * `selectionItems` leads the menu when something is selected, so the actions\n * that apply to the selection come before the ones that create new things.\n */\n const renderMenu = (selectionItems: ReactNode) => (\n <Menu.Root\n modal={false}\n open={position !== null}\n onOpenChange={(open) => {\n if (!open) {\n setPosition(null);\n }\n }}\n >\n <Menu.Trigger\n tabIndex={-1}\n // No visible content, so the name has to come from `aria-label` —\n // the trigger's `label` prop renders as button text, which would\n // defeat the point of an invisible anchor. Radix points the menu's\n // `aria-labelledby` at this element, so it names the menu too.\n endIcon={null}\n aria-label={formatMessage({\n id: getTranslationKey('list.context-menu.label'),\n defaultMessage: 'Media library actions',\n })}\n style={{ ...CURSOR_ANCHOR_STYLE, top: position?.y ?? 0, left: position?.x ?? 0 }}\n />\n <ActionsMenuContent\n popoverPlacement=\"bottom-start\"\n zIndex={2}\n minWidth=\"22rem\"\n // The anchor is invisible and sits wherever the cursor was, so\n // handing focus back to it on close would be a focus ring nobody can\n // see. Let it fall to the body instead.\n onCloseAutoFocus={(event) => event.preventDefault()}\n >\n {selectionItems}\n {createItems}\n </ActionsMenuContent>\n </Menu.Root>\n );\n\n return (\n <>\n <div ref={anchorRef} style={LOCATOR_STYLE} aria-hidden />\n {/* Non-modal, like the row-level menus: a right-click elsewhere is both\n \"close this\" and \"open that\", which a modal layer would swallow.\n Skipped entirely without the permission — the anchor is a real\n (if invisible) button, and one that can never open is noise in the\n accessibility tree. */}\n {!disabled &&\n (locations ? (\n <SelectionActions locations={locations}>\n {({ count, hasActions, items, dialogs }) => (\n <>\n {renderMenu(\n count > 0 && hasActions ? (\n <>\n {items}\n <Menu.Separator />\n </>\n ) : null\n )}\n {/* Outside the menu: Radix unmounts its content on close, and a\n dialog opened from an item has to outlive it. */}\n {dialogs}\n </>\n )}\n </SelectionActions>\n ) : (\n renderMenu(null)\n ))}\n </>\n );\n};\n"],"names":["SCROLL_ROOT_SELECTOR","NATIVE_CONTEXT_MENU_SELECTOR","join","CURSOR_ANCHOR_STYLE","position","width","height","minWidth","minHeight","padding","border","opacity","overflow","pointerEvents","LOCATOR_STYLE","MainAreaContextMenu","onCreateFolder","onImportFiles","onImportFromUrl","disabled","containerSelector","locations","formatMessage","useIntl","setPosition","useState","locator","setLocator","anchorRef","useCallback","node","useEffect","container","closest","handleContextMenu","event","target","Element","preventDefault","x","clientX","y","clientY","addEventListener","removeEventListener","createItems","_jsxs","_Fragment","_jsx","Menu","Item","onSelect","startIcon","FolderIcon","id","getTranslationKey","defaultMessage","Files","Link","renderMenu","selectionItems","Root","modal","open","onOpenChange","Trigger","tabIndex","endIcon","aria-label","style","top","left","ActionsMenuContent","popoverPlacement","zIndex","onCloseAutoFocus","div","ref","aria-hidden","SelectionActions","count","hasActions","items","dialogs","Separator"],"mappings":";;;;;;;;;;;AAaA;;;;;;AAMC,IACD,MAAMA,oBAAAA,GAAuB,4BAAA;AAE7B;;;;;;;;;;;;AAYC,IACD,MAAMC,4BAAAA,GAA+B;AACnC,IAAA,4BAAA;AACA,IAAA,OAAA;AACA,IAAA,GAAA;AACA,IAAA,QAAA;AACA,IAAA,OAAA;AACA,IAAA,UAAA;AACA,IAAA,QAAA;AACA,IAAA;AACD,CAAA,CAACC,IAAI,CAAC,IAAA,CAAA;AAEP;;;;;;;;AAQC,IACD,MAAMC,mBAAAA,GAAqC;IACzCC,QAAAA,EAAU,OAAA;IACVC,KAAAA,EAAO,CAAA;IACPC,MAAAA,EAAQ,CAAA;IACRC,QAAAA,EAAU,CAAA;IACVC,SAAAA,EAAW,CAAA;IACXC,OAAAA,EAAS,CAAA;IACTC,MAAAA,EAAQ,CAAA;IACRC,OAAAA,EAAS,CAAA;IACTC,QAAAA,EAAU,QAAA;IACVC,aAAAA,EAAe;AACjB,CAAA;AAEA,MAAMC,aAAAA,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,EAAA;;AACGmC,oCAAAA,KAAAA;AACD,kDAAAlC,cAAA,CAACC,kBAAKmC,SAAS,EAAA,EAAA;;AAEf,6BAAA,CAAA,GAAA,IAAA,CAAA;AAILD,4BAAAA;;;AAKPxB,aAAAA,CAAAA,GAAAA,UAAAA,CAAW,IAAA,CACb;;;AAGR;;;;"}
|
|
@@ -5,6 +5,7 @@ import { Folder, Files, Link } from '@strapi/icons';
|
|
|
5
5
|
import { useIntl } from 'react-intl';
|
|
6
6
|
import { getTranslationKey } from '../../../utils/translations.mjs';
|
|
7
7
|
import { ActionsMenuContent } from './ActionsMenuContent.mjs';
|
|
8
|
+
import { SelectionActions } from './SelectionActions.mjs';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* The admin layout marks the element that scrolls the main column. Listening on
|
|
@@ -69,13 +70,13 @@ const LOCATOR_STYLE = {
|
|
|
69
70
|
* Deliberately background-only. Right-clicking an asset, a folder or a table
|
|
70
71
|
* row is left alone — those carry `data-native-context-menu` and keep the
|
|
71
72
|
* browser's menu (which is what you want over a thumbnail or a filename).
|
|
72
|
-
*/ const MainAreaContextMenu = ({ onCreateFolder, onImportFiles, onImportFromUrl, disabled })=>{
|
|
73
|
+
*/ const MainAreaContextMenu = ({ onCreateFolder, onImportFiles, onImportFromUrl, disabled, containerSelector = SCROLL_ROOT_SELECTOR, locations })=>{
|
|
73
74
|
const { formatMessage } = useIntl();
|
|
74
75
|
const [position, setPosition] = useState(null);
|
|
75
76
|
const [locator, setLocator] = useState(null);
|
|
76
77
|
const anchorRef = useCallback((node)=>setLocator(node), []);
|
|
77
78
|
useEffect(()=>{
|
|
78
|
-
const container = locator?.closest(
|
|
79
|
+
const container = locator?.closest(containerSelector);
|
|
79
80
|
if (!container || disabled) {
|
|
80
81
|
return;
|
|
81
82
|
}
|
|
@@ -99,8 +100,81 @@ const LOCATOR_STYLE = {
|
|
|
99
100
|
return ()=>container.removeEventListener('contextmenu', handleContextMenu);
|
|
100
101
|
}, [
|
|
101
102
|
locator,
|
|
102
|
-
disabled
|
|
103
|
+
disabled,
|
|
104
|
+
containerSelector
|
|
103
105
|
]);
|
|
106
|
+
const createItems = /*#__PURE__*/ jsxs(Fragment, {
|
|
107
|
+
children: [
|
|
108
|
+
/*#__PURE__*/ jsx(Menu.Item, {
|
|
109
|
+
onSelect: onCreateFolder,
|
|
110
|
+
startIcon: /*#__PURE__*/ jsx(Folder, {}),
|
|
111
|
+
children: formatMessage({
|
|
112
|
+
id: getTranslationKey('folder.create.title'),
|
|
113
|
+
defaultMessage: 'New folder'
|
|
114
|
+
})
|
|
115
|
+
}),
|
|
116
|
+
/*#__PURE__*/ jsx(Menu.Item, {
|
|
117
|
+
onSelect: onImportFiles,
|
|
118
|
+
startIcon: /*#__PURE__*/ jsx(Files, {}),
|
|
119
|
+
children: formatMessage({
|
|
120
|
+
id: getTranslationKey('import-files'),
|
|
121
|
+
defaultMessage: 'File upload'
|
|
122
|
+
})
|
|
123
|
+
}),
|
|
124
|
+
/*#__PURE__*/ jsx(Menu.Item, {
|
|
125
|
+
onSelect: onImportFromUrl,
|
|
126
|
+
startIcon: /*#__PURE__*/ jsx(Link, {}),
|
|
127
|
+
children: formatMessage({
|
|
128
|
+
id: getTranslationKey('import-from-url'),
|
|
129
|
+
defaultMessage: 'File upload from URL'
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
]
|
|
133
|
+
});
|
|
134
|
+
/**
|
|
135
|
+
* `selectionItems` leads the menu when something is selected, so the actions
|
|
136
|
+
* that apply to the selection come before the ones that create new things.
|
|
137
|
+
*/ const renderMenu = (selectionItems)=>/*#__PURE__*/ jsxs(Menu.Root, {
|
|
138
|
+
modal: false,
|
|
139
|
+
open: position !== null,
|
|
140
|
+
onOpenChange: (open)=>{
|
|
141
|
+
if (!open) {
|
|
142
|
+
setPosition(null);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
children: [
|
|
146
|
+
/*#__PURE__*/ jsx(Menu.Trigger, {
|
|
147
|
+
tabIndex: -1,
|
|
148
|
+
// No visible content, so the name has to come from `aria-label` —
|
|
149
|
+
// the trigger's `label` prop renders as button text, which would
|
|
150
|
+
// defeat the point of an invisible anchor. Radix points the menu's
|
|
151
|
+
// `aria-labelledby` at this element, so it names the menu too.
|
|
152
|
+
endIcon: null,
|
|
153
|
+
"aria-label": formatMessage({
|
|
154
|
+
id: getTranslationKey('list.context-menu.label'),
|
|
155
|
+
defaultMessage: 'Media library actions'
|
|
156
|
+
}),
|
|
157
|
+
style: {
|
|
158
|
+
...CURSOR_ANCHOR_STYLE,
|
|
159
|
+
top: position?.y ?? 0,
|
|
160
|
+
left: position?.x ?? 0
|
|
161
|
+
}
|
|
162
|
+
}),
|
|
163
|
+
/*#__PURE__*/ jsxs(ActionsMenuContent, {
|
|
164
|
+
popoverPlacement: "bottom-start",
|
|
165
|
+
zIndex: 2,
|
|
166
|
+
minWidth: "22rem",
|
|
167
|
+
// The anchor is invisible and sits wherever the cursor was, so
|
|
168
|
+
// handing focus back to it on close would be a focus ring nobody can
|
|
169
|
+
// see. Let it fall to the body instead.
|
|
170
|
+
onCloseAutoFocus: (event)=>event.preventDefault(),
|
|
171
|
+
children: [
|
|
172
|
+
selectionItems,
|
|
173
|
+
createItems
|
|
174
|
+
]
|
|
175
|
+
})
|
|
176
|
+
]
|
|
177
|
+
});
|
|
104
178
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
105
179
|
children: [
|
|
106
180
|
/*#__PURE__*/ jsx("div", {
|
|
@@ -108,69 +182,20 @@ const LOCATOR_STYLE = {
|
|
|
108
182
|
style: LOCATOR_STYLE,
|
|
109
183
|
"aria-hidden": true
|
|
110
184
|
}),
|
|
111
|
-
!disabled && /*#__PURE__*/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
onOpenChange: (open)=>{
|
|
115
|
-
if (!open) {
|
|
116
|
-
setPosition(null);
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
children: [
|
|
120
|
-
/*#__PURE__*/ jsx(Menu.Trigger, {
|
|
121
|
-
tabIndex: -1,
|
|
122
|
-
// No visible content, so the name has to come from `aria-label` —
|
|
123
|
-
// the trigger's `label` prop renders as button text, which would
|
|
124
|
-
// defeat the point of an invisible anchor. Radix points the menu's
|
|
125
|
-
// `aria-labelledby` at this element, so it names the menu too.
|
|
126
|
-
endIcon: null,
|
|
127
|
-
"aria-label": formatMessage({
|
|
128
|
-
id: getTranslationKey('list.context-menu.label'),
|
|
129
|
-
defaultMessage: 'Media library actions'
|
|
130
|
-
}),
|
|
131
|
-
style: {
|
|
132
|
-
...CURSOR_ANCHOR_STYLE,
|
|
133
|
-
top: position?.y ?? 0,
|
|
134
|
-
left: position?.x ?? 0
|
|
135
|
-
}
|
|
136
|
-
}),
|
|
137
|
-
/*#__PURE__*/ jsxs(ActionsMenuContent, {
|
|
138
|
-
popoverPlacement: "bottom-start",
|
|
139
|
-
zIndex: 2,
|
|
140
|
-
minWidth: "22rem",
|
|
141
|
-
// The anchor is invisible and sits wherever the cursor was, so
|
|
142
|
-
// handing focus back to it on close would be a focus ring nobody can
|
|
143
|
-
// see. Let it fall to the body instead.
|
|
144
|
-
onCloseAutoFocus: (event)=>event.preventDefault(),
|
|
185
|
+
!disabled && (locations ? /*#__PURE__*/ jsx(SelectionActions, {
|
|
186
|
+
locations: locations,
|
|
187
|
+
children: ({ count, hasActions, items, dialogs })=>/*#__PURE__*/ jsxs(Fragment, {
|
|
145
188
|
children: [
|
|
146
|
-
/*#__PURE__*/
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}),
|
|
154
|
-
/*#__PURE__*/ jsx(Menu.Item, {
|
|
155
|
-
onSelect: onImportFiles,
|
|
156
|
-
startIcon: /*#__PURE__*/ jsx(Files, {}),
|
|
157
|
-
children: formatMessage({
|
|
158
|
-
id: getTranslationKey('import-files'),
|
|
159
|
-
defaultMessage: 'File upload'
|
|
160
|
-
})
|
|
161
|
-
}),
|
|
162
|
-
/*#__PURE__*/ jsx(Menu.Item, {
|
|
163
|
-
onSelect: onImportFromUrl,
|
|
164
|
-
startIcon: /*#__PURE__*/ jsx(Link, {}),
|
|
165
|
-
children: formatMessage({
|
|
166
|
-
id: getTranslationKey('import-from-url'),
|
|
167
|
-
defaultMessage: 'File upload from URL'
|
|
168
|
-
})
|
|
169
|
-
})
|
|
189
|
+
renderMenu(count > 0 && hasActions ? /*#__PURE__*/ jsxs(Fragment, {
|
|
190
|
+
children: [
|
|
191
|
+
items,
|
|
192
|
+
/*#__PURE__*/ jsx(Menu.Separator, {})
|
|
193
|
+
]
|
|
194
|
+
}) : null),
|
|
195
|
+
dialogs
|
|
170
196
|
]
|
|
171
197
|
})
|
|
172
|
-
|
|
173
|
-
})
|
|
198
|
+
}) : renderMenu(null))
|
|
174
199
|
]
|
|
175
200
|
});
|
|
176
201
|
};
|