@strapi/upload 5.55.1 → 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/useAIMetadataAvailability.js +14 -0
- package/dist/admin/hooks/useAIMetadataAvailability.js.map +1 -0
- package/dist/admin/hooks/useAIMetadataAvailability.mjs +12 -0
- package/dist/admin/hooks/useAIMetadataAvailability.mjs.map +1 -0
- package/dist/admin/hooks/useAIMetadataEnabled.js +7 -5
- package/dist/admin/hooks/useAIMetadataEnabled.js.map +1 -1
- package/dist/admin/hooks/useAIMetadataEnabled.mjs +7 -5
- package/dist/admin/hooks/useAIMetadataEnabled.mjs.map +1 -1
- package/dist/admin/hooks/useTracking.js +4 -10
- package/dist/admin/hooks/useTracking.js.map +1 -1
- package/dist/admin/hooks/useTracking.mjs +5 -10
- package/dist/admin/hooks/useTracking.mjs.map +1 -1
- package/dist/admin/legacy/hooks/useAIMetadataAvailability.js +14 -0
- package/dist/admin/legacy/hooks/useAIMetadataAvailability.js.map +1 -0
- package/dist/admin/legacy/hooks/useAIMetadataAvailability.mjs +12 -0
- package/dist/admin/legacy/hooks/useAIMetadataAvailability.mjs.map +1 -0
- package/dist/admin/legacy/hooks/useAIMetadataEnabled.js +23 -0
- package/dist/admin/legacy/hooks/useAIMetadataEnabled.js.map +1 -0
- package/dist/admin/legacy/hooks/useAIMetadataEnabled.mjs +21 -0
- package/dist/admin/legacy/hooks/useAIMetadataEnabled.mjs.map +1 -0
- package/dist/admin/legacy/hooks/useTracking.js +5 -3
- package/dist/admin/legacy/hooks/useTracking.js.map +1 -1
- package/dist/admin/legacy/hooks/useTracking.mjs +5 -3
- 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 +6 -5
- package/dist/admin/legacy/pages/App/MediaLibrary.js.map +1 -1
- package/dist/admin/legacy/pages/App/MediaLibrary.mjs +6 -5
- 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/DeleteItemsDialog.js +4 -2
- package/dist/admin/pages/Assets/components/DeleteItemsDialog.js.map +1 -1
- package/dist/admin/pages/Assets/components/DeleteItemsDialog.mjs +4 -2
- package/dist/admin/pages/Assets/components/DeleteItemsDialog.mjs.map +1 -1
- 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 +10 -3
- package/dist/admin/pages/SettingsPage/SettingsPage.js.map +1 -1
- package/dist/admin/pages/SettingsPage/SettingsPage.mjs +10 -3
- package/dist/admin/pages/SettingsPage/SettingsPage.mjs.map +1 -1
- package/dist/admin/services/api.js.map +1 -1
- package/dist/admin/services/api.mjs.map +1 -1
- package/dist/admin/src/hooks/useAIMetadataAvailability.d.ts +5 -0
- package/dist/admin/src/hooks/useAIMetadataEnabled.d.ts +5 -3
- package/dist/admin/src/hooks/useTracking.d.ts +0 -7
- package/dist/admin/src/legacy/components/EditAssetDialog/PreviewBox/PreviewComponents.d.ts +2 -2
- package/dist/admin/src/legacy/hooks/useAIMetadataAvailability.d.ts +5 -0
- package/dist/admin/src/legacy/hooks/useAIMetadataEnabled.d.ts +12 -0
- package/dist/admin/src/legacy/hooks/useSettings.d.ts +1 -0
- package/dist/admin/src/pages/Assets/components/ActionsMenuContent.d.ts +2 -2
- 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 +9 -3
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +9 -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/bootstrap.js +7 -0
- package/dist/server/bootstrap.js.map +1 -1
- package/dist/server/bootstrap.mjs +7 -0
- package/dist/server/bootstrap.mjs.map +1 -1
- 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-file.js +51 -4
- package/dist/server/controllers/admin-folder-file.js.map +1 -1
- package/dist/server/controllers/admin-folder-file.mjs +52 -5
- package/dist/server/controllers/admin-folder-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/admin-settings.js +2 -1
- package/dist/server/controllers/admin-settings.js.map +1 -1
- package/dist/server/controllers/admin-settings.mjs +2 -1
- package/dist/server/controllers/admin-settings.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/errors.js +12 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/errors.mjs +10 -0
- package/dist/server/errors.mjs.map +1 -0
- 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/ai-metadata-provider.js +83 -0
- package/dist/server/services/ai-metadata-provider.js.map +1 -0
- package/dist/server/services/ai-metadata-provider.mjs +61 -0
- package/dist/server/services/ai-metadata-provider.mjs.map +1 -0
- package/dist/server/services/ai-metadata-strapi-managed.js +48 -0
- package/dist/server/services/ai-metadata-strapi-managed.js.map +1 -0
- package/dist/server/services/ai-metadata-strapi-managed.mjs +46 -0
- package/dist/server/services/ai-metadata-strapi-managed.mjs.map +1 -0
- package/dist/server/services/ai-metadata.js +5 -58
- package/dist/server/services/ai-metadata.js.map +1 -1
- package/dist/server/services/ai-metadata.mjs +6 -39
- package/dist/server/services/ai-metadata.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 +9 -6
- package/dist/server/services/folder.js.map +1 -1
- package/dist/server/services/folder.mjs +9 -6
- package/dist/server/services/folder.mjs.map +1 -1
- package/dist/server/services/index.js +3 -1
- package/dist/server/services/index.js.map +1 -1
- package/dist/server/services/index.mjs +3 -1
- package/dist/server/services/index.mjs.map +1 -1
- package/dist/server/services/metrics.js +1 -1
- package/dist/server/services/metrics.js.map +1 -1
- package/dist/server/services/metrics.mjs +1 -1
- package/dist/server/services/metrics.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/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/admin-folder-file.d.ts.map +1 -1
- package/dist/server/src/controllers/admin-folder.d.ts.map +1 -1
- package/dist/server/src/controllers/admin-settings.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/errors.d.ts +6 -0
- package/dist/server/src/errors.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +6 -1
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/mcp/ambient-instance.d.ts +3 -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/ai-metadata-provider.d.ts +26 -0
- package/dist/server/src/services/ai-metadata-provider.d.ts.map +1 -0
- package/dist/server/src/services/ai-metadata-strapi-managed.d.ts +7 -0
- package/dist/server/src/services/ai-metadata-strapi-managed.d.ts.map +1 -0
- package/dist/server/src/services/ai-metadata.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/folder.d.ts +5 -2
- package/dist/server/src/services/folder.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +6 -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/dist/server/src/utils/images.d.ts +2 -2
- package/dist/server/src/utils/images.d.ts.map +1 -1
- package/dist/server/src/utils/index.d.ts +2 -0
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/dist/server/utils/images.js +6 -7
- package/dist/server/utils/images.js.map +1 -1
- package/dist/server/utils/images.mjs +6 -7
- package/dist/server/utils/images.mjs.map +1 -1
- package/dist/server/utils/index.js.map +1 -1
- package/dist/server/utils/index.mjs.map +1 -1
- package/dist/shared/contracts/settings.d.ts +6 -0
- package/package.json +11 -11
- package/dist/admin/legacy/hooks/useAiAvailability.js +0 -22
- package/dist/admin/legacy/hooks/useAiAvailability.js.map +0 -1
- package/dist/admin/legacy/hooks/useAiAvailability.mjs +0 -20
- package/dist/admin/legacy/hooks/useAiAvailability.mjs.map +0 -1
- package/dist/admin/src/legacy/hooks/useAiAvailability.d.ts +0 -4
|
@@ -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,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
|
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,IAA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BAAAA,cAAAA;AACAf,wBAAAA;;;;;IAKP,qBACEC,eAAA,CAAAC,mBAAA,EAAA;;0BACEC,cAAA,CAAC4B,KAAAA,EAAAA;gBAAIC,GAAAA,EAAKjD,SAAAA;gBAAWyC,KAAAA,EAAOvD,aAAAA;gBAAegE,aAAW,EAAA;;YAMrD,CAAC3D,QAAAA,KACCE,SAAAA,iBACC2B,cAAA,CAAC+B,iCAAAA,EAAAA;gBAAiB1D,SAAAA,EAAWA,SAAAA;0BAC1B,CAAC,EAAE2D,KAAK,EAAEC,UAAU,EAAEC,KAAK,EAAEC,OAAO,EAAE,iBACrCrC,eAAA,CAAAC,mBAAA,EAAA;;4BACGY,UAAAA,CACCqB,KAAAA,GAAQ,KAAKC,UAAAA,iBACXnC,eAAA,CAAAC,mBAAA,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
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MainAreaContextMenu.mjs","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;;;;;;;;;;;AAWC,IACM,MAAMS,mBAAAA,GAAsB,CAAC,EAClCC,cAAc,EACdC,aAAa,EACbC,eAAe,EACfC,QAAQ,EACiB,GAAA;IACzB,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;AAC1B,IAAA,MAAM,CAACjB,QAAAA,EAAUkB,WAAAA,CAAY,GAAGC,QAAAA,CAAgC,IAAA,CAAA;AAChE,IAAA,MAAM,CAACC,OAAAA,EAASC,UAAAA,CAAW,GAAGF,QAAAA,CAA6B,IAAA,CAAA;AAE3D,IAAA,MAAMG,YAAYC,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AAAA,CAAkB,cAAA,CAAA;oCACtBC,cAAAA,EAAgB;AAClB,iCAAA;;AAEF,0CAAAhB,GAAA,CAACK,KAAKkB,IAAI,EAAA;gCAACC,QAAAA,EAAUnD,eAAAA;AAAiBoD,gCAAAA,SAAAA,gBAAWzB,GAAA,CAAC4B,IAAAA,EAAAA,EAAAA,CAAAA;0CAC/CrD,aAAAA,CAAc;AACbuC,oCAAAA,EAAAA,EAAIC,iBAAAA,CAAkB,iBAAA,CAAA;oCACtBC,cAAAA,EAAgB;AAClB,iCAAA;;;;;;;;AAOd;;;;"}
|
|
1
|
+
{"version":3,"file":"MainAreaContextMenu.mjs","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,GAA+B;IAAER,MAAAA,EAAQ;AAAE,CAAA;AAmCjD;;;;;;;;;;;AAWC,IACM,MAAMS,mBAAAA,GAAsB,CAAC,EAClCC,cAAc,EACdC,aAAa,EACbC,eAAe,EACfC,QAAQ,EACRC,oBAAoBpB,oBAAoB,EACxCqB,SAAS,EACgB,GAAA;IACzB,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;AAC1B,IAAA,MAAM,CAACnB,QAAAA,EAAUoB,WAAAA,CAAY,GAAGC,QAAAA,CAAgC,IAAA,CAAA;AAChE,IAAA,MAAM,CAACC,OAAAA,EA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GAAGlE,mBAAmB;AAAEmE,wBAAAA,GAAAA,EAAKlE,UAAUqC,CAAAA,IAAK,CAAA;AAAG8B,wBAAAA,IAAAA,EAAMnE,UAAUmC,CAAAA,IAAK;AAAE;;8BAEjFO,IAAA,CAAC0B,kBAAAA,EAAAA;oBACCC,gBAAAA,EAAiB,cAAA;oBACjBC,MAAAA,EAAQ,CAAA;oBACRnE,QAAAA,EAAS,OAAA;;;;oBAIToE,gBAAAA,EAAkB,CAACxC,KAAAA,GAAUA,KAAAA,CAAMG,cAAc,EAAA;;AAEhDsB,wBAAAA,cAAAA;AACAf,wBAAAA;;;;;IAKP,qBACEC,IAAA,CAAAC,QAAA,EAAA;;0BACEC,GAAA,CAAC4B,KAAAA,EAAAA;gBAAIC,GAAAA,EAAKjD,SAAAA;gBAAWyC,KAAAA,EAAOvD,aAAAA;gBAAegE,aAAW,EAAA;;YAMrD,CAAC3D,QAAAA,KACCE,SAAAA,iBACC2B,GAAA,CAAC+B,gBAAAA,EAAAA;gBAAiB1D,SAAAA,EAAWA,SAAAA;0BAC1B,CAAC,EAAE2D,KAAK,EAAEC,UAAU,EAAEC,KAAK,EAAEC,OAAO,EAAE,iBACrCrC,IAAA,CAAAC,QAAA,EAAA;;4BACGY,UAAAA,CACCqB,KAAAA,GAAQ,KAAKC,UAAAA,iBACXnC,IAAA,CAAAC,QAAA,EAAA;;AACGmC,oCAAAA,KAAAA;AACD,kDAAAlC,GAAA,CAACC,KAAKmC,SAAS,EAAA,EAAA;;AAEf,6BAAA,CAAA,GAAA,IAAA,CAAA;AAILD,4BAAAA;;;AAKPxB,aAAAA,CAAAA,GAAAA,UAAAA,CAAW,IAAA,CACb;;;AAGR;;;;"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var designSystem = require('@strapi/design-system');
|
|
6
|
+
var icons = require('@strapi/icons');
|
|
7
|
+
var reactIntl = require('react-intl');
|
|
8
|
+
var useMediaLibraryPermissions = require('../../../hooks/useMediaLibraryPermissions.js');
|
|
9
|
+
var buildDragSetFromSelection = require('../../../utils/buildDragSetFromSelection.js');
|
|
10
|
+
var translations = require('../../../utils/translations.js');
|
|
11
|
+
var useAssetSelection = require('../hooks/useAssetSelection.js');
|
|
12
|
+
var useFolderNavigation = require('../hooks/useFolderNavigation.js');
|
|
13
|
+
var BulkMoveDialog = require('./BulkMoveDialog.js');
|
|
14
|
+
var DeleteItemsDialog = require('./DeleteItemsDialog.js');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The actions that apply to the current selection — move and delete — with no
|
|
18
|
+
* opinion about which menu shows them.
|
|
19
|
+
*
|
|
20
|
+
* Two menus offer them: the one a right-click on a selected item opens, and the
|
|
21
|
+
* background menu, which prepends them to its own creation actions whenever
|
|
22
|
+
* something is selected. Sharing the items keeps the two from drifting, and
|
|
23
|
+
* keeps one copy of the dialogs they open.
|
|
24
|
+
*
|
|
25
|
+
* Only move and delete: the rest of an item's menu has no meaning for a set —
|
|
26
|
+
* there is no one link to copy and no one file to replace.
|
|
27
|
+
*/ const SelectionActions = ({ locations, children })=>{
|
|
28
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
29
|
+
// Move and delete are both `assets.update` server-side — one flag gates both.
|
|
30
|
+
const { canUpdate, isLoading: isLoadingPermissions } = useMediaLibraryPermissions.useMediaLibraryPermissions();
|
|
31
|
+
const { selectedIds, selectedFolderIds, clear } = useAssetSelection.useAssetSelection();
|
|
32
|
+
const { currentFolderId } = useFolderNavigation.useFolderNavigation();
|
|
33
|
+
const [isMoveOpen, setIsMoveOpen] = React.useState(false);
|
|
34
|
+
const [isDeleteOpen, setIsDeleteOpen] = React.useState(false);
|
|
35
|
+
const count = selectedIds.size + selectedFolderIds.size;
|
|
36
|
+
const isBusy = isMoveOpen || isDeleteOpen;
|
|
37
|
+
// `canUpdate` is `false` until the RBAC check settles. Reading it before then
|
|
38
|
+
// would hide the actions on first render, or close a menu before it paints.
|
|
39
|
+
const hasActions = isLoadingPermissions || canUpdate;
|
|
40
|
+
const moveItems = React.useMemo(()=>buildDragSetFromSelection.buildDragSetFromSelection(selectedIds, selectedFolderIds, locations, currentFolderId), [
|
|
41
|
+
selectedIds,
|
|
42
|
+
selectedFolderIds,
|
|
43
|
+
locations,
|
|
44
|
+
currentFolderId
|
|
45
|
+
]);
|
|
46
|
+
const items = /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
47
|
+
children: [
|
|
48
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Label, {
|
|
49
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
|
|
50
|
+
variant: "sigma",
|
|
51
|
+
textColor: "neutral600",
|
|
52
|
+
children: formatMessage({
|
|
53
|
+
id: translations.getTranslationKey('list.bulk-actions.selected-count'),
|
|
54
|
+
defaultMessage: '{count, plural, =1 {# item selected} other {# items selected}}'
|
|
55
|
+
}, {
|
|
56
|
+
count
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
}),
|
|
60
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Separator, {}),
|
|
61
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Item, {
|
|
62
|
+
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.ArrowRight, {}),
|
|
63
|
+
onSelect: ()=>setIsMoveOpen(true),
|
|
64
|
+
children: formatMessage({
|
|
65
|
+
id: translations.getTranslationKey('list.bulk-actions.move'),
|
|
66
|
+
defaultMessage: 'Move'
|
|
67
|
+
})
|
|
68
|
+
}),
|
|
69
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Menu.Item, {
|
|
70
|
+
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Trash, {}),
|
|
71
|
+
variant: "danger",
|
|
72
|
+
onSelect: ()=>setIsDeleteOpen(true),
|
|
73
|
+
children: formatMessage({
|
|
74
|
+
id: translations.getTranslationKey('list.bulk-actions.delete'),
|
|
75
|
+
defaultMessage: 'Delete'
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
const dialogs = /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
81
|
+
children: [
|
|
82
|
+
isMoveOpen && /*#__PURE__*/ jsxRuntime.jsx(BulkMoveDialog.BulkMoveDialog, {
|
|
83
|
+
open: true,
|
|
84
|
+
onClose: ()=>setIsMoveOpen(false),
|
|
85
|
+
items: moveItems,
|
|
86
|
+
onSuccess: clear
|
|
87
|
+
}),
|
|
88
|
+
isDeleteOpen && /*#__PURE__*/ jsxRuntime.jsx(DeleteItemsDialog.DeleteItemsDialog, {
|
|
89
|
+
open: true,
|
|
90
|
+
onClose: ()=>setIsDeleteOpen(false),
|
|
91
|
+
target: {
|
|
92
|
+
fileIds: Array.from(selectedIds),
|
|
93
|
+
folderIds: Array.from(selectedFolderIds)
|
|
94
|
+
},
|
|
95
|
+
onSuccess: clear
|
|
96
|
+
})
|
|
97
|
+
]
|
|
98
|
+
});
|
|
99
|
+
return /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
100
|
+
children: children({
|
|
101
|
+
count,
|
|
102
|
+
hasActions,
|
|
103
|
+
items,
|
|
104
|
+
dialogs,
|
|
105
|
+
isBusy
|
|
106
|
+
})
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
exports.SelectionActions = SelectionActions;
|
|
111
|
+
//# sourceMappingURL=SelectionActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionActions.js","sources":["../../../../../admin/src/pages/Assets/components/SelectionActions.tsx"],"sourcesContent":["import { useMemo, useState, type ReactNode } from 'react';\n\nimport { Menu, Typography } from '@strapi/design-system';\nimport { ArrowRight, Trash } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\n\nimport { useMediaLibraryPermissions } from '../../../hooks/useMediaLibraryPermissions';\nimport { buildDragSetFromSelection } from '../../../utils/buildDragSetFromSelection';\nimport { getTranslationKey } from '../../../utils/translations';\nimport { useAssetSelection } from '../hooks/useAssetSelection';\nimport { useFolderNavigation } from '../hooks/useFolderNavigation';\n\nimport { BulkMoveDialog } from './BulkMoveDialog';\nimport { DeleteItemsDialog } from './DeleteItemsDialog';\n\nimport type { ItemLocations } from '../../../utils/itemLocations';\n\ninterface SelectionActionsRender {\n /** How many items the actions would act on. Zero means nothing is selected. */\n count: number;\n /**\n * Whether there is anything to offer. False for a role that can read but not\n * update; true while the RBAC check is still settling, so a menu built on it\n * does not flash empty.\n */\n hasActions: boolean;\n /** The count label, a separator, then Move and Delete. */\n items: ReactNode;\n /** Rendered outside `Menu.Root` — a dialog has to outlive the menu that opened it. */\n dialogs: ReactNode;\n /** True while a dialog is open, for callers that unmount once nothing is on screen. */\n isBusy: boolean;\n}\n\ninterface SelectionActionsProps {\n /**\n * Real location of every loaded row, so the move dialog validates each\n * selected item against its own parent — same input the bulk bar takes.\n */\n locations: ItemLocations;\n children: (actions: SelectionActionsRender) => ReactNode;\n}\n\n/**\n * The actions that apply to the current selection — move and delete — with no\n * opinion about which menu shows them.\n *\n * Two menus offer them: the one a right-click on a selected item opens, and the\n * background menu, which prepends them to its own creation actions whenever\n * something is selected. Sharing the items keeps the two from drifting, and\n * keeps one copy of the dialogs they open.\n *\n * Only move and delete: the rest of an item's menu has no meaning for a set —\n * there is no one link to copy and no one file to replace.\n */\nexport const SelectionActions = ({ locations, children }: SelectionActionsProps) => {\n const { formatMessage } = useIntl();\n // Move and delete are both `assets.update` server-side — one flag gates both.\n const { canUpdate, isLoading: isLoadingPermissions } = useMediaLibraryPermissions();\n const { selectedIds, selectedFolderIds, clear } = useAssetSelection();\n const { currentFolderId } = useFolderNavigation();\n const [isMoveOpen, setIsMoveOpen] = useState(false);\n const [isDeleteOpen, setIsDeleteOpen] = useState(false);\n\n const count = selectedIds.size + selectedFolderIds.size;\n const isBusy = isMoveOpen || isDeleteOpen;\n // `canUpdate` is `false` until the RBAC check settles. Reading it before then\n // would hide the actions on first render, or close a menu before it paints.\n const hasActions = isLoadingPermissions || canUpdate;\n\n const moveItems = useMemo(\n () => buildDragSetFromSelection(selectedIds, selectedFolderIds, locations, currentFolderId),\n [selectedIds, selectedFolderIds, locations, currentFolderId]\n );\n\n const items = (\n <>\n {/* A label rather than a `Menu.Item`: it states what the actions below\n will act on and is not itself selectable. */}\n <Menu.Label>\n <Typography variant=\"sigma\" textColor=\"neutral600\">\n {formatMessage(\n {\n id: getTranslationKey('list.bulk-actions.selected-count'),\n defaultMessage: '{count, plural, =1 {# item selected} other {# items selected}}',\n },\n { count }\n )}\n </Typography>\n </Menu.Label>\n <Menu.Separator />\n <Menu.Item startIcon={<ArrowRight />} onSelect={() => setIsMoveOpen(true)}>\n {formatMessage({\n id: getTranslationKey('list.bulk-actions.move'),\n defaultMessage: 'Move',\n })}\n </Menu.Item>\n <Menu.Item startIcon={<Trash />} variant=\"danger\" onSelect={() => setIsDeleteOpen(true)}>\n {formatMessage({\n id: getTranslationKey('list.bulk-actions.delete'),\n defaultMessage: 'Delete',\n })}\n </Menu.Item>\n </>\n );\n\n const dialogs = (\n <>\n {isMoveOpen && (\n <BulkMoveDialog\n open\n onClose={() => setIsMoveOpen(false)}\n items={moveItems}\n onSuccess={clear}\n />\n )}\n {isDeleteOpen && (\n <DeleteItemsDialog\n open\n onClose={() => setIsDeleteOpen(false)}\n target={{\n fileIds: Array.from(selectedIds),\n folderIds: Array.from(selectedFolderIds),\n }}\n onSuccess={clear}\n />\n )}\n </>\n );\n\n return <>{children({ count, hasActions, items, dialogs, isBusy })}</>;\n};\n"],"names":["SelectionActions","locations","children","formatMessage","useIntl","canUpdate","isLoading","isLoadingPermissions","useMediaLibraryPermissions","selectedIds","selectedFolderIds","clear","useAssetSelection","currentFolderId","useFolderNavigation","isMoveOpen","setIsMoveOpen","useState","isDeleteOpen","setIsDeleteOpen","count","size","isBusy","hasActions","moveItems","useMemo","buildDragSetFromSelection","items","_jsxs","_Fragment","_jsx","Menu","Label","Typography","variant","textColor","id","getTranslationKey","defaultMessage","Separator","Item","startIcon","ArrowRight","onSelect","Trash","dialogs","BulkMoveDialog","open","onClose","onSuccess","DeleteItemsDialog","target","fileIds","Array","from","folderIds"],"mappings":";;;;;;;;;;;;;;;AA2CA;;;;;;;;;;;UAYaA,gBAAAA,GAAmB,CAAC,EAAEC,SAAS,EAAEC,QAAQ,EAAyB,GAAA;IAC7E,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;;AAE1B,IAAA,MAAM,EAAEC,SAAS,EAAEC,SAAAA,EAAWC,oBAAoB,EAAE,GAAGC,qDAAAA,EAAAA;AACvD,IAAA,MAAM,EAAEC,WAAW,EAAEC,iBAAiB,EAAEC,KAAK,EAAE,GAAGC,mCAAAA,EAAAA;IAClD,MAAM,EAAEC,eAAe,EAAE,GAAGC,uCAAAA,EAAAA;AAC5B,IAAA,MAAM,CAACC,UAAAA,EAAYC,aAAAA,CAAc,GAAGC,cAAAA,CAAS,KAAA,CAAA;AAC7C,IAAA,MAAM,CAACC,YAAAA,EAAcC,eAAAA,CAAgB,GAAGF,cAAAA,CAAS,KAAA,CAAA;AAEjD,IAAA,MAAMG,KAAAA,GAAQX,WAAAA,CAAYY,IAAI,GAAGX,kBAAkBW,IAAI;AACvD,IAAA,MAAMC,SAASP,UAAAA,IAAcG,YAAAA;;;AAG7B,IAAA,MAAMK,aAAahB,oBAAAA,IAAwBF,SAAAA;AAE3C,IAAA,MAAMmB,YAAYC,aAAAA,CAChB,IAAMC,oDAA0BjB,WAAAA,EAAaC,iBAAAA,EAAmBT,WAAWY,eAAAA,CAAAA,EAC3E;AAACJ,QAAAA,WAAAA;AAAaC,QAAAA,iBAAAA;AAAmBT,QAAAA,SAAAA;AAAWY,QAAAA;AAAgB,KAAA,CAAA;AAG9D,IAAA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AAc,KAAA,CAAA;gBAC7BW,KAAAA,EAAOH,SAAAA;gBACPyB,SAAAA,EAAWtC;;AAGdO,YAAAA,YAAAA,kBACCY,cAAA,CAACoB,mCAAAA,EAAAA;gBACCH,IAAI,EAAA,IAAA;AACJC,gBAAAA,OAAAA,EAAS,IAAM7B,eAAAA,CAAgB,KAAA,CAAA;gBAC/BgC,MAAAA,EAAQ;oBACNC,OAAAA,EAASC,KAAAA,CAAMC,IAAI,CAAC7C,WAAAA,CAAAA;oBACpB8C,SAAAA,EAAWF,KAAAA,CAAMC,IAAI,CAAC5C,iBAAAA;AACxB,iBAAA;gBACAuC,SAAAA,EAAWtC;;;;IAMnB,qBAAOmB,cAAA,CAAAD,mBAAA,EAAA;kBAAG3B,QAAAA,CAAS;AAAEkB,YAAAA,KAAAA;AAAOG,YAAAA,UAAAA;AAAYI,YAAAA,KAAAA;AAAOkB,YAAAA,OAAAA;AAASvB,YAAAA;AAAO,SAAA;;AACjE;;;;"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useMemo } from 'react';
|
|
3
|
+
import { Menu, Typography } from '@strapi/design-system';
|
|
4
|
+
import { ArrowRight, Trash } from '@strapi/icons';
|
|
5
|
+
import { useIntl } from 'react-intl';
|
|
6
|
+
import { useMediaLibraryPermissions } from '../../../hooks/useMediaLibraryPermissions.mjs';
|
|
7
|
+
import { buildDragSetFromSelection } from '../../../utils/buildDragSetFromSelection.mjs';
|
|
8
|
+
import { getTranslationKey } from '../../../utils/translations.mjs';
|
|
9
|
+
import { useAssetSelection } from '../hooks/useAssetSelection.mjs';
|
|
10
|
+
import { useFolderNavigation } from '../hooks/useFolderNavigation.mjs';
|
|
11
|
+
import { BulkMoveDialog } from './BulkMoveDialog.mjs';
|
|
12
|
+
import { DeleteItemsDialog } from './DeleteItemsDialog.mjs';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The actions that apply to the current selection — move and delete — with no
|
|
16
|
+
* opinion about which menu shows them.
|
|
17
|
+
*
|
|
18
|
+
* Two menus offer them: the one a right-click on a selected item opens, and the
|
|
19
|
+
* background menu, which prepends them to its own creation actions whenever
|
|
20
|
+
* something is selected. Sharing the items keeps the two from drifting, and
|
|
21
|
+
* keeps one copy of the dialogs they open.
|
|
22
|
+
*
|
|
23
|
+
* Only move and delete: the rest of an item's menu has no meaning for a set —
|
|
24
|
+
* there is no one link to copy and no one file to replace.
|
|
25
|
+
*/ const SelectionActions = ({ locations, children })=>{
|
|
26
|
+
const { formatMessage } = useIntl();
|
|
27
|
+
// Move and delete are both `assets.update` server-side — one flag gates both.
|
|
28
|
+
const { canUpdate, isLoading: isLoadingPermissions } = useMediaLibraryPermissions();
|
|
29
|
+
const { selectedIds, selectedFolderIds, clear } = useAssetSelection();
|
|
30
|
+
const { currentFolderId } = useFolderNavigation();
|
|
31
|
+
const [isMoveOpen, setIsMoveOpen] = useState(false);
|
|
32
|
+
const [isDeleteOpen, setIsDeleteOpen] = useState(false);
|
|
33
|
+
const count = selectedIds.size + selectedFolderIds.size;
|
|
34
|
+
const isBusy = isMoveOpen || isDeleteOpen;
|
|
35
|
+
// `canUpdate` is `false` until the RBAC check settles. Reading it before then
|
|
36
|
+
// would hide the actions on first render, or close a menu before it paints.
|
|
37
|
+
const hasActions = isLoadingPermissions || canUpdate;
|
|
38
|
+
const moveItems = useMemo(()=>buildDragSetFromSelection(selectedIds, selectedFolderIds, locations, currentFolderId), [
|
|
39
|
+
selectedIds,
|
|
40
|
+
selectedFolderIds,
|
|
41
|
+
locations,
|
|
42
|
+
currentFolderId
|
|
43
|
+
]);
|
|
44
|
+
const items = /*#__PURE__*/ jsxs(Fragment, {
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ jsx(Menu.Label, {
|
|
47
|
+
children: /*#__PURE__*/ jsx(Typography, {
|
|
48
|
+
variant: "sigma",
|
|
49
|
+
textColor: "neutral600",
|
|
50
|
+
children: formatMessage({
|
|
51
|
+
id: getTranslationKey('list.bulk-actions.selected-count'),
|
|
52
|
+
defaultMessage: '{count, plural, =1 {# item selected} other {# items selected}}'
|
|
53
|
+
}, {
|
|
54
|
+
count
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
}),
|
|
58
|
+
/*#__PURE__*/ jsx(Menu.Separator, {}),
|
|
59
|
+
/*#__PURE__*/ jsx(Menu.Item, {
|
|
60
|
+
startIcon: /*#__PURE__*/ jsx(ArrowRight, {}),
|
|
61
|
+
onSelect: ()=>setIsMoveOpen(true),
|
|
62
|
+
children: formatMessage({
|
|
63
|
+
id: getTranslationKey('list.bulk-actions.move'),
|
|
64
|
+
defaultMessage: 'Move'
|
|
65
|
+
})
|
|
66
|
+
}),
|
|
67
|
+
/*#__PURE__*/ jsx(Menu.Item, {
|
|
68
|
+
startIcon: /*#__PURE__*/ jsx(Trash, {}),
|
|
69
|
+
variant: "danger",
|
|
70
|
+
onSelect: ()=>setIsDeleteOpen(true),
|
|
71
|
+
children: formatMessage({
|
|
72
|
+
id: getTranslationKey('list.bulk-actions.delete'),
|
|
73
|
+
defaultMessage: 'Delete'
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
const dialogs = /*#__PURE__*/ jsxs(Fragment, {
|
|
79
|
+
children: [
|
|
80
|
+
isMoveOpen && /*#__PURE__*/ jsx(BulkMoveDialog, {
|
|
81
|
+
open: true,
|
|
82
|
+
onClose: ()=>setIsMoveOpen(false),
|
|
83
|
+
items: moveItems,
|
|
84
|
+
onSuccess: clear
|
|
85
|
+
}),
|
|
86
|
+
isDeleteOpen && /*#__PURE__*/ jsx(DeleteItemsDialog, {
|
|
87
|
+
open: true,
|
|
88
|
+
onClose: ()=>setIsDeleteOpen(false),
|
|
89
|
+
target: {
|
|
90
|
+
fileIds: Array.from(selectedIds),
|
|
91
|
+
folderIds: Array.from(selectedFolderIds)
|
|
92
|
+
},
|
|
93
|
+
onSuccess: clear
|
|
94
|
+
})
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
98
|
+
children: children({
|
|
99
|
+
count,
|
|
100
|
+
hasActions,
|
|
101
|
+
items,
|
|
102
|
+
dialogs,
|
|
103
|
+
isBusy
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { SelectionActions };
|
|
109
|
+
//# sourceMappingURL=SelectionActions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionActions.mjs","sources":["../../../../../admin/src/pages/Assets/components/SelectionActions.tsx"],"sourcesContent":["import { useMemo, useState, type ReactNode } from 'react';\n\nimport { Menu, Typography } from '@strapi/design-system';\nimport { ArrowRight, Trash } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\n\nimport { useMediaLibraryPermissions } from '../../../hooks/useMediaLibraryPermissions';\nimport { buildDragSetFromSelection } from '../../../utils/buildDragSetFromSelection';\nimport { getTranslationKey } from '../../../utils/translations';\nimport { useAssetSelection } from '../hooks/useAssetSelection';\nimport { useFolderNavigation } from '../hooks/useFolderNavigation';\n\nimport { BulkMoveDialog } from './BulkMoveDialog';\nimport { DeleteItemsDialog } from './DeleteItemsDialog';\n\nimport type { ItemLocations } from '../../../utils/itemLocations';\n\ninterface SelectionActionsRender {\n /** How many items the actions would act on. Zero means nothing is selected. */\n count: number;\n /**\n * Whether there is anything to offer. False for a role that can read but not\n * update; true while the RBAC check is still settling, so a menu built on it\n * does not flash empty.\n */\n hasActions: boolean;\n /** The count label, a separator, then Move and Delete. */\n items: ReactNode;\n /** Rendered outside `Menu.Root` — a dialog has to outlive the menu that opened it. */\n dialogs: ReactNode;\n /** True while a dialog is open, for callers that unmount once nothing is on screen. */\n isBusy: boolean;\n}\n\ninterface SelectionActionsProps {\n /**\n * Real location of every loaded row, so the move dialog validates each\n * selected item against its own parent — same input the bulk bar takes.\n */\n locations: ItemLocations;\n children: (actions: SelectionActionsRender) => ReactNode;\n}\n\n/**\n * The actions that apply to the current selection — move and delete — with no\n * opinion about which menu shows them.\n *\n * Two menus offer them: the one a right-click on a selected item opens, and the\n * background menu, which prepends them to its own creation actions whenever\n * something is selected. Sharing the items keeps the two from drifting, and\n * keeps one copy of the dialogs they open.\n *\n * Only move and delete: the rest of an item's menu has no meaning for a set —\n * there is no one link to copy and no one file to replace.\n */\nexport const SelectionActions = ({ locations, children }: SelectionActionsProps) => {\n const { formatMessage } = useIntl();\n // Move and delete are both `assets.update` server-side — one flag gates both.\n const { canUpdate, isLoading: isLoadingPermissions } = useMediaLibraryPermissions();\n const { selectedIds, selectedFolderIds, clear } = useAssetSelection();\n const { currentFolderId } = useFolderNavigation();\n const [isMoveOpen, setIsMoveOpen] = useState(false);\n const [isDeleteOpen, setIsDeleteOpen] = useState(false);\n\n const count = selectedIds.size + selectedFolderIds.size;\n const isBusy = isMoveOpen || isDeleteOpen;\n // `canUpdate` is `false` until the RBAC check settles. Reading it before then\n // would hide the actions on first render, or close a menu before it paints.\n const hasActions = isLoadingPermissions || canUpdate;\n\n const moveItems = useMemo(\n () => buildDragSetFromSelection(selectedIds, selectedFolderIds, locations, currentFolderId),\n [selectedIds, selectedFolderIds, locations, currentFolderId]\n );\n\n const items = (\n <>\n {/* A label rather than a `Menu.Item`: it states what the actions below\n will act on and is not itself selectable. */}\n <Menu.Label>\n <Typography variant=\"sigma\" textColor=\"neutral600\">\n {formatMessage(\n {\n id: getTranslationKey('list.bulk-actions.selected-count'),\n defaultMessage: '{count, plural, =1 {# item selected} other {# items selected}}',\n },\n { count }\n )}\n </Typography>\n </Menu.Label>\n <Menu.Separator />\n <Menu.Item startIcon={<ArrowRight />} onSelect={() => setIsMoveOpen(true)}>\n {formatMessage({\n id: getTranslationKey('list.bulk-actions.move'),\n defaultMessage: 'Move',\n })}\n </Menu.Item>\n <Menu.Item startIcon={<Trash />} variant=\"danger\" onSelect={() => setIsDeleteOpen(true)}>\n {formatMessage({\n id: getTranslationKey('list.bulk-actions.delete'),\n defaultMessage: 'Delete',\n })}\n </Menu.Item>\n </>\n );\n\n const dialogs = (\n <>\n {isMoveOpen && (\n <BulkMoveDialog\n open\n onClose={() => setIsMoveOpen(false)}\n items={moveItems}\n onSuccess={clear}\n />\n )}\n {isDeleteOpen && (\n <DeleteItemsDialog\n open\n onClose={() => setIsDeleteOpen(false)}\n target={{\n fileIds: Array.from(selectedIds),\n folderIds: Array.from(selectedFolderIds),\n }}\n onSuccess={clear}\n />\n )}\n </>\n );\n\n return <>{children({ count, hasActions, items, dialogs, isBusy })}</>;\n};\n"],"names":["SelectionActions","locations","children","formatMessage","useIntl","canUpdate","isLoading","isLoadingPermissions","useMediaLibraryPermissions","selectedIds","selectedFolderIds","clear","useAssetSelection","currentFolderId","useFolderNavigation","isMoveOpen","setIsMoveOpen","useState","isDeleteOpen","setIsDeleteOpen","count","size","isBusy","hasActions","moveItems","useMemo","buildDragSetFromSelection","items","_jsxs","_Fragment","_jsx","Menu","Label","Typography","variant","textColor","id","getTranslationKey","defaultMessage","Separator","Item","startIcon","ArrowRight","onSelect","Trash","dialogs","BulkMoveDialog","open","onClose","onSuccess","DeleteItemsDialog","target","fileIds","Array","from","folderIds"],"mappings":";;;;;;;;;;;;;AA2CA;;;;;;;;;;;UAYaA,gBAAAA,GAAmB,CAAC,EAAEC,SAAS,EAAEC,QAAQ,EAAyB,GAAA;IAC7E,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;;AAE1B,IAAA,MAAM,EAAEC,SAAS,EAAEC,SAAAA,EAAWC,oBAAoB,EAAE,GAAGC,0BAAAA,EAAAA;AACvD,IAAA,MAAM,EAAEC,WAAW,EAAEC,iBAAiB,EAAEC,KAAK,EAAE,GAAGC,iBAAAA,EAAAA;IAClD,MAAM,EAAEC,eAAe,EAAE,GAAGC,mBAAAA,EAAAA;AAC5B,IAAA,MAAM,CAACC,UAAAA,EAAYC,aAAAA,CAAc,G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