@wordpress/media-editor 0.23.0 → 0.24.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/CHANGELOG.md +16 -0
- package/build/components/media-editor/index.cjs +157 -107
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +18 -8
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +9 -7
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +9 -7
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +9 -7
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +32 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-preview/index.cjs +143 -36
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +2 -2
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +9 -7
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +142 -95
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +9 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +32 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-preview/index.mjs +123 -40
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +2 -2
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +18 -30
- package/build-style/style.css +18 -30
- package/build-types/components/media-editor/index.d.ts +8 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +7 -2
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +26 -22
- package/src/components/media-editor/index.tsx +209 -114
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +55 -63
- package/src/components/media-editor-modal/index.tsx +3 -0
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-preview/index.tsx +195 -36
- package/src/components/media-preview/style.scss +11 -32
- package/src/state/README.md +3 -1
- package/src/state/use-media-editor-state.ts +7 -2
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["coreStore","noticesStore","WCSpinner","AnimatePresence","motion","ConfirmDialog"],"sources":["../../../src/components/media-editor/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport {\n\tButton,\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tModal,\n\tSpinner as WCSpinner,\n\t__experimentalConfirmDialog as ConfirmDialog,\n\t__unstableAnimatePresence as AnimatePresence,\n\t__unstableMotion as motion,\n} from '@wordpress/components';\nimport { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';\nimport { useReducedMotion, useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, useRegistry, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { NavigableRegion } from '@wordpress/admin-ui';\nimport {\n\tcreateContext,\n\tcreatePortal,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tbackup,\n\tclose,\n\tdrawerRight,\n\tkeyboard,\n\tmoreVertical,\n\tredo,\n\tundo,\n} from '@wordpress/icons';\nimport {\n\tdisplayShortcut,\n\tisAppleOS,\n\tisKeyboardEvent,\n} from '@wordpress/keycodes';\nimport { SnackbarNotices, store as noticesStore } from '@wordpress/notices';\nimport type { Action, ActionModal, Field, Form } from '@wordpress/dataviews';\nimport type {\n\tKeyboardEvent as ReactKeyboardEvent,\n\tReactElement,\n\tReactNode,\n} from 'react';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport { MediaEditorProvider } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\nimport MediaPreview from '../media-preview';\nimport MediaEditorCanvas from '../media-editor-canvas';\nimport MediaEditorFineRotation from '../media-editor-fine-rotation';\nimport MediaEditorCropPanel from '../media-editor-crop-panel';\nimport MediaEditorImageControls from '../media-editor-image-controls';\nimport MediaForm from '../media-form';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { MediaEditorStateProvider, useMediaEditor } from '../../state';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorKeyboardShortcutsModal from '../media-editor-keyboard-shortcuts-modal';\nimport {\n\tMEDIA_EDITOR_NOTICES_CONTEXT,\n\tuseSaveMediaEditor,\n\ttype MediaEditorSaveResult,\n} from './use-save-media-editor';\nimport { useCropOptions } from './use-crop-options';\n\nexport type { MediaEditorSaveResult } from './use-save-media-editor';\n\n// Embed query for the attachment's author and parent post. Shared between\n// the `getEntityRecord` read and the matching `invalidateResolution` so the\n// two stay in lockstep.\nconst ATTACHMENT_EMBED_QUERY = { _embed: 'author,wp:attached-to' } as const;\n\nconst PLACEMENT_CONTROL_IDLE_MS = 300;\n\n/**\n * Identifier for the details panel, and the panel the sidebar opens on before\n * the user picks another. The sidebar tracks which panel is open rather than\n * whether one is, so a further panel is a new id here and a new entry in the\n * tab list — not a change to the state's shape.\n */\nconst DETAILS_PANEL = 'details';\n\n/** Identifier for the crop panel. Images only; other media has nothing to crop. */\nconst CROP_PANEL = 'crop';\n\n// Matches the editor's sidebar in `ComplementaryArea`.\nconst SIDEBAR_ANIMATION_DURATION = 0.3;\n\ntype SidebarTransition = {\n\ttype: 'tween';\n\tduration: number;\n\tease: number[];\n};\n\nconst sidebarVariants = {\n\t// `auto` leaves the width to the sidebar's stylesheet.\n\topen: { width: 'auto' },\n\t// Takes the transition from `AnimatePresence`'s `custom` prop, so a\n\t// sidebar that is already closing still gets the current one.\n\tclosed: ( transition: SidebarTransition ) => ( {\n\t\twidth: 0,\n\t\ttransition,\n\t} ),\n};\n\ninterface MediaEditorTab {\n\tid: string;\n\ttitle: string;\n\trender: () => ReactElement;\n}\n\nexport interface MediaEditorFrameProps {\n\tchildren: ReactNode;\n\t/**\n\t * Whether the media being edited is an image. The history and transform\n\t * clusters render nothing for other media types, so a frame uses this to\n\t * decide whether the container it would put them in is worth rendering at\n\t * all.\n\t */\n\tisImage: boolean;\n\t/**\n\t * `narrow` below the `small` breakpoint, where the frame's header has no\n\t * room for the history cluster beside its other controls. A frame uses\n\t * this to place that cluster, not to decide whether it renders —\n\t * `HistoryActions` returns nothing on its own when the canvas is off\n\t * screen.\n\t */\n\tlayout: 'wide' | 'narrow';\n\tonRequestClose: () => void;\n\tonKeyDown: ( event: ReactKeyboardEvent< HTMLElement > ) => void;\n\tshouldCloseOnClickOutside: boolean;\n\tisSaving: boolean;\n\thasChanges: boolean;\n\thasMedia: boolean;\n}\n\nexport interface MediaEditorProps {\n\tfields?: Field< Media >[];\n\tform?: Form;\n\tid: number;\n\taspectRatioPresets?: AspectRatioPreset[];\n\tonClose?: () => void;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/** Called with the original's id when the user chooses \"Edit original\". */\n\tonEditOriginal?: ( originalId: number ) => void;\n\trenderFrame: ( props: MediaEditorFrameProps ) => ReactElement;\n\tnoticesClassName?: string;\n\tnoticesPortalElement?: Element | null;\n\tshouldCloseOnEsc?: boolean;\n}\n\ninterface MediaEditorSidebarProps {\n\ttabs: MediaEditorTab[];\n\t/** The open panel's id. Always one of `tabs`. */\n\tactiveTab: string;\n\tonSelectTab: ( tab: string ) => void;\n\t/** Freeze the open panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\nfunction MediaEditorSidebar( {\n\ttabs,\n\tactiveTab,\n\tonSelectTab,\n\tdisabled = false,\n}: MediaEditorSidebarProps ) {\n\treturn (\n\t\t<NavigableRegion\n\t\t\tclassName=\"media-editor__sidebar\"\n\t\t\tariaLabel={ __( 'Media settings' ) }\n\t\t>\n\t\t\t{ /* No visible heading and no close button: the strip below names\n\t\t\t the open panel and the header's pressed toggle dismisses it.\n\t\t\t The heading stays for screen readers, which read neither as\n\t\t\t this region's title. */ }\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Media settings' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<Tabs.Root\n\t\t\t\tclassName=\"media-editor__tabs\"\n\t\t\t\tvalue={ activeTab }\n\t\t\t\tonValueChange={ onSelectTab }\n\t\t\t>\n\t\t\t\t{ /* `Tabs.List` sizes itself to its tabs (`width: fit-content`),\n\t\t\t\t so the rule under the strip is drawn by this wrapper\n\t\t\t\t instead, which spans the column. */ }\n\t\t\t\t<div className=\"media-editor__tablist\">\n\t\t\t\t\t<Tabs.List variant=\"minimal\">\n\t\t\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t\t\t<Tabs.Tab\n\t\t\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\t\t\tvalue={ tab.id }\n\t\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ tab.title }\n\t\t\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</Tabs.List>\n\t\t\t\t</div>\n\t\t\t\t{ /* One `Tabs.Panel` per tab: the counts have to match or\n\t\t\t\t `Tabs.Root` throws in dev. Only the active one paints\n\t\t\t\t anything — the rest render nothing. */ }\n\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t<Tabs.Panel\n\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\tvalue={ tab.id }\n\t\t\t\t\t\ttabIndex={ -1 }\n\t\t\t\t\t\tclassName=\"media-editor__panel\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<Stack direction=\"column\" gap=\"lg\">\n\t\t\t\t\t\t\t{ tab.render() }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t</Tabs.Panel>\n\t\t\t\t) ) }\n\t\t\t</Tabs.Root>\n\t\t</NavigableRegion>\n\t);\n}\n\n/**\n * Everything the frame's action clusters need from the editor. Supplied by\n * context rather than by props so the clusters can be module-level components:\n * a component created during a render has a new identity on every pass, which\n * remounts its subtree and drops focus mid-interaction.\n */\ninterface MediaEditorFrameContextValue {\n\tisImage: boolean;\n\tisSaving: boolean;\n\thasMedia: boolean;\n\thasChanges: boolean;\n\tisUndoRedoDisabled: boolean;\n\taspectRatioPresets?: AspectRatioPreset[];\n\t/** `true` above `large`, where the panel docks beside the canvas. */\n\tisWide: boolean;\n\t/** The open panel's id, or `null` when none is. */\n\tactivePanel: string | null;\n\t/**\n\t * Opens the sidebar on the last-shown panel, or closes it when one is\n\t * already open.\n\t */\n\tonTogglePanel: () => void;\n\tonCancel: () => void;\n\tonSave: () => void;\n\t/**\n\t * When `true`, the media has a lineage root to restore to, so the\n\t * history menu shows its \"Restore original\" item.\n\t */\n\tcanRestoreOriginal: boolean;\n\t/**\n\t * When `true`, another attachment has replaced the edited one in the\n\t * image editor this session (today, only the original), so the menu item is\n\t * disabled.\n\t */\n\tisSourceReplaced: boolean;\n\t/** Whether the frame opens the original itself. */\n\topensOriginal: boolean;\n\t/**\n\t * Load the lineage root into the image editor, or hand it to the\n\t * frame.\n\t */\n\tonRestoreOriginal: () => void;\n}\n\nconst MediaEditorFrameContext =\n\tcreateContext< MediaEditorFrameContextValue | null >( null );\n\n/**\n * Hook to access the media editor's frame context.\n *\n * Must be used within a MediaEditor component.\n *\n * @return MediaEditorFrameContextValue the action clusters render from.\n */\nfunction useMediaEditorFrameContext(): MediaEditorFrameContextValue {\n\tconst context = useContext( MediaEditorFrameContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditorFrameContext must be used within MediaEditor'\n\t\t);\n\t}\n\treturn context;\n}\n\nexport interface HeaderActionsProps {\n\t/**\n\t * Whether to include a Close button. Frames with a dismissal affordance of\n\t * their own — a route's breadcrumbs, say — leave it out.\n\t *\n\t * @default false\n\t */\n\tshowCloseButton?: boolean;\n}\n\nfunction PanelToggle() {\n\tconst { isWide, activePanel, onTogglePanel } = useMediaEditorFrameContext();\n\tconst isPanelOpen = !! activePanel;\n\t// The sidebar holds more than one panel, so this opens and closes the\n\t// sidebar rather than naming a panel: reopening returns to whichever tab\n\t// was last showing, and the tab strip inside switches between them.\n\treturn (\n\t\t<Button\n\t\t\tsize=\"compact\"\n\t\t\ticon={ drawerRight }\n\t\t\tlabel={ __( 'Media settings' ) }\n\t\t\tisPressed={ isPanelOpen }\n\t\t\t// Only a docked column really expands beside the canvas; below\n\t\t\t// that the panel replaces the view, which the pressed state\n\t\t\t// already describes.\n\t\t\taria-expanded={ isWide ? isPanelOpen : undefined }\n\t\t\tonClick={ onTogglePanel }\n\t\t/>\n\t);\n}\n\nfunction getActionLabel( action: Action< Media >, items: Media[] ) {\n\treturn typeof action.label === 'string'\n\t\t? action.label\n\t\t: action.label( items );\n}\n\ninterface MediaActionModalProps {\n\taction: ActionModal< Media >;\n\titems: Media[];\n\tcloseModal: () => void;\n}\n\n// A copy of the `ActionModal` in `@wordpress/dataviews`, which isn't\n// exported. It could be replaced if dataviews exports it.\nfunction MediaActionModal( {\n\taction,\n\titems,\n\tcloseModal,\n}: MediaActionModalProps ) {\n\tconst header =\n\t\ttypeof action.modalHeader === 'function'\n\t\t\t? action.modalHeader( items )\n\t\t\t: action.modalHeader;\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ header || getActionLabel( action, items ) }\n\t\t\t__experimentalHideHeader={ !! action.hideModalHeader }\n\t\t\tonRequestClose={ closeModal }\n\t\t\tfocusOnMount={ action.modalFocusOnMount ?? true }\n\t\t\tsize={ action.modalSize || 'medium' }\n\t\t>\n\t\t\t<action.RenderModal items={ items } closeModal={ closeModal } />\n\t\t</Modal>\n\t);\n}\n\nexport interface MoreMenuProps {\n\t/**\n\t * Actions for the attachment, such as those from the entity actions API.\n\t * Only the ones whose `isEligible` passes for `item` are shown.\n\t */\n\tactions?: Action< Media >[];\n\t/**\n\t * The attachment the actions apply to, with anything their `isEligible`\n\t * checks need, such as `permissions`. Without it no actions are shown.\n\t */\n\titem?: Media;\n}\n\nfunction MoreMenu( { actions = [], item }: MoreMenuProps ) {\n\tconst { isImage, isSaving } = useMediaEditorFrameContext();\n\tconst registry = useRegistry();\n\tconst [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );\n\tconst [ activeModalAction, setActiveModalAction ] =\n\t\tuseState< ActionModal< Media > | null >( null );\n\n\tconst items = item ? [ item ] : [];\n\tconst eligibleActions = useMemo(\n\t\t() =>\n\t\t\titem\n\t\t\t\t? actions.filter(\n\t\t\t\t\t\t( action ) =>\n\t\t\t\t\t\t\t! action.isEligible || action.isEligible( item )\n\t\t\t\t\t)\n\t\t\t\t: [],\n\t\t[ actions, item ]\n\t);\n\n\tif ( ! isImage && ! eligibleActions.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\ticon={ moreVertical }\n\t\t\t\tlabel={ __( 'More options' ) }\n\t\t\t\ttoggleProps={ { size: 'compact' } }\n\t\t\t>\n\t\t\t\t{ ( { onClose: closeMenu } ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ isImage && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\ticon={ keyboard }\n\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsShortcutsModalOpen( true );\n\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Keyboard shortcuts' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ !! eligibleActions.length && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t{ eligibleActions.map( ( action ) => {\n\t\t\t\t\t\t\t\t\tconst label = getActionLabel(\n\t\t\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\t\t\titems\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ action.id }\n\t\t\t\t\t\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t\t\t\t\t\tisSaving || action.disabled\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t\t\t\tif ( 'RenderModal' in action ) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsetActiveModalAction(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\taction\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\taction.callback( items, {\n\t\t\t\t\t\t\t\t\t\t\t\t\tregistry,\n\t\t\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ 'RenderModal' in action\n\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: Action label. Use the ellipsis and spacing appropriate for your language. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'%s…',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'menu item requiring further input'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlabel\n\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t: label }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ isShortcutsModalOpen && (\n\t\t\t\t<MediaEditorKeyboardShortcutsModal\n\t\t\t\t\tonClose={ () => setIsShortcutsModalOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ activeModalAction && (\n\t\t\t\t<MediaActionModal\n\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\titems={ items }\n\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {\n\tconst { isSaving, onCancel } = useMediaEditorFrameContext();\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__header-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<PanelToggle />\n\t\t\t<MoreMenu />\n\t\t\t{ showCloseButton && (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ close }\n\t\t\t\t\tlabel={ __( 'Close' ) }\n\t\t\t\t\tonClick={ onCancel }\n\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction HistoryActions() {\n\tconst {\n\t\tisImage,\n\t\tisSaving,\n\t\tisUndoRedoDisabled,\n\t\tisWide,\n\t\tactivePanel,\n\t\tcanRestoreOriginal,\n\t\tisSourceReplaced,\n\t\topensOriginal,\n\t\tonRestoreOriginal,\n\t} = useMediaEditorFrameContext();\n\tconst {\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t} = useMediaEditor();\n\t// Reset, undo and redo act on the image edits, so they only appear where\n\t// the canvas does. Non-image media has no edit history at all; below the dock\n\t// breakpoint an open panel replaces the canvas, and leaving these behind\n\t// would put an enabled, destructive Reset next to metadata fields it does\n\t// not touch — clicking it would discard a crop the user cannot see.\n\t// (Metadata edits have no undo of their own; a history spanning both is a\n\t// larger change than hiding these.) Checked after the hooks above so the\n\t// hook order stays stable across renders.\n\tif ( ! isImage || ( ! isWide && !! activePanel ) ) {\n\t\treturn null;\n\t}\n\tconst handleUndo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tundoCrop();\n\t};\n\tconst handleRedo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tredoCrop();\n\t};\n\tconst handleReset = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\treset();\n\t};\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__history-actions\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ undo }\n\t\t\t\tlabel={ __( 'Undo' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tshortcut={ displayShortcut.primary( 'z' ) }\n\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasUndo }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleUndo }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ redo }\n\t\t\t\tlabel={ __( 'Redo' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tshortcut={\n\t\t\t\t\tisAppleOS()\n\t\t\t\t\t\t? displayShortcut.primaryShift( 'z' )\n\t\t\t\t\t\t: displayShortcut.primary( 'y' )\n\t\t\t\t}\n\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasRedo }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleRedo }\n\t\t\t/>\n\t\t\t<DropdownMenu\n\t\t\t\ticon={ backup }\n\t\t\t\tlabel={ __( 'History' ) }\n\t\t\t\tpopoverProps={ { placement: 'top-start' } }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tsize: 'compact',\n\t\t\t\t\tdisabled:\n\t\t\t\t\t\tisUndoRedoDisabled ||\n\t\t\t\t\t\t( ! isDirty && ! canRestoreOriginal ),\n\t\t\t\t\taccessibleWhenDisabled: true,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ ( { onClose: closeMenu } ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! isDirty }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\thandleReset();\n\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Reset image edits' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t{ canRestoreOriginal && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tdisabled={ isSourceReplaced || isSaving }\n\t\t\t\t\t\t\t\t\tinfo={ __( 'Discards unsaved changes.' ) }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonRestoreOriginal();\n\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ opensOriginal\n\t\t\t\t\t\t\t\t\t\t? __( 'Edit original' )\n\t\t\t\t\t\t\t\t\t\t: __( 'Restore original' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t</Stack>\n\t);\n}\n\nexport interface SaveActionsProps {\n\t/**\n\t * Button height. Footers take the 40px default; frames placing these in a\n\t * page header pass `compact` to match the header's other controls.\n\t *\n\t * @default 'default'\n\t */\n\tsize?: 'default' | 'compact';\n}\n\nfunction SaveActions( { size = 'default' }: SaveActionsProps ) {\n\tconst { isSaving, hasMedia, hasChanges, onCancel, onSave } =\n\t\tuseMediaEditorFrameContext();\n\tconst saveDisabled = isSaving || ! hasMedia || ! hasChanges;\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__save-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tsize={ size }\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t\tonClick={ onCancel }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tsize={ size }\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ onSave }\n\t\t\t\tisBusy={ isSaving }\n\t\t\t\tdisabled={ saveDisabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t{ __( 'Save' ) }\n\t\t\t</Button>\n\t\t</Stack>\n\t);\n}\n\nfunction MediaEditorContent( {\n\tfields = [],\n\tform,\n\tid,\n\taspectRatioPresets,\n\tonClose,\n\tonSaved,\n\tonEditOriginal,\n\trenderFrame,\n\tnoticesClassName = 'media-editor__snackbar',\n\tnoticesPortalElement,\n\tshouldCloseOnEsc = false,\n}: MediaEditorProps ) {\n\tconst session = useMediaEditor();\n\t// Width decides whether the settings panel docks beside the canvas or\n\t// takes the whole body. It docks from `small` (600px): the modal is the\n\t// viewport less a 16px margin either side, so a 320px panel and the\n\t// canvas column's 2 x 24px gutters still leave the canvas ~200px there\n\t// and ~380px by 782px. Tight, but a full-screen panel would have hidden\n\t// the image altogether — you could not crop and preview at once.\n\t//\n\t// The same line moves the transform controls: docked, the Crop panel\n\t// carries them; below it they fall back to a row under the canvas.\n\t//\n\t// The choice is not carried across openings: the modal is transient, and\n\t// re-opening with the panel hidden on a wide screen is how #81487 read to\n\t// people in the first place. Within one opening it does hold — see\n\t// `chosenPanel` below.\n\tconst isWide = useViewportMatch( 'small' );\n\t// Below `small` the open panel replaces the canvas instead of sitting\n\t// beside it, so there is nothing to animate.\n\tconst disableSidebarMotion = useReducedMotion() || ! isWide;\n\tconst sidebarTransition: SidebarTransition = {\n\t\ttype: 'tween',\n\t\tduration: disableSidebarMotion ? 0 : SIDEBAR_ANIMATION_DURATION,\n\t\tease: [ 0.6, 0, 0.4, 1 ],\n\t};\n\t// Width picks the starting panel, but only until the user opens or closes\n\t// it. After that their choice holds for the rest of the session: closing\n\t// the panel and then resizing — or crossing the breakpoint by rotating a\n\t// tablet — should not reopen something they just dismissed. `undefined`\n\t// until then, otherwise `null` for closed or the open panel's id.\n\tconst [ chosenPanel, setChosenPanel ] = useState< string | null >();\n\t// The tab the user picked, `null` until they pick one. Tracked separately\n\t// from `chosenPanel` because the two answer different questions: whether\n\t// the panel should be open, and which tab it should show.\n\tconst [ chosenTab, setChosenTab ] = useState< string | null >( null );\n\t// Below `small` a frame's header cannot fit the history cluster alongside\n\t// its own controls, so it moves that cluster elsewhere. The same width\n\t// undocks the panel, so this is `isWide` rather than a second query.\n\tconst layout: 'wide' | 'narrow' = isWide ? 'wide' : 'narrow';\n\tconst sourceMedia = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tid\n\t\t\t) as Media,\n\t\t[ id ]\n\t);\n\n\tconst { clearEntityRecordEdits, editEntityRecord, invalidateResolution } =\n\t\tuseDispatch( coreStore );\n\tconst { removeAllNotices } = useDispatch( noticesStore );\n\n\tconst [ isDiscardDialogOpen, setIsDiscardDialogOpen ] = useState( false );\n\tconst [ isPlacementActive, setIsPlacementActive ] = useState( false );\n\tconst [ isCanvasGestureActive, setIsCanvasGestureActive ] =\n\t\tuseState( false );\n\t// Whether another attachment has replaced `id` in the image editor this\n\t// session (today, the original via \"Restore original image\"). Stays a\n\t// distinct flag (not derived from the image editor) so a bare replacement\n\t// counts as a change even though swapping the source resets the\n\t// image editor's own dirty baseline.\n\tconst [ isSourceReplaced, setIsSourceReplaced ] = useState( false );\n\tconst placementControlTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\n\tconst signalPlacementControlInteraction = useCallback( () => {\n\t\tsetIsPlacementActive( true );\n\t\tclearTimeout( placementControlTimerRef.current );\n\t\tplacementControlTimerRef.current = setTimeout( () => {\n\t\t\tsetIsPlacementActive( false );\n\t\t}, PLACEMENT_CONTROL_IDLE_MS );\n\t}, [] );\n\tconst handleCanvasGestureStart = useCallback( () => {\n\t\tsetIsCanvasGestureActive( true );\n\t}, [] );\n\tconst handleCanvasGestureEnd = useCallback( () => {\n\t\tsetIsCanvasGestureActive( false );\n\t}, [] );\n\tconst isCropInteractionActive = isPlacementActive || isCanvasGestureActive;\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( placementControlTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Restore-original: the edit root the edited attachment descends from,\n\t// exposed by the server as the root-level `edit_root` id on the\n\t// attachment (edit context, embeddable via the `wp:edit-root` link).\n\t// Fetch the original's record for the URL and natural dimensions the\n\t// image editor needs to seed itself.\n\tconst originalId: number | undefined = sourceMedia?.edit_root;\n\tconst originalRecord = useSelect(\n\t\t( select ) =>\n\t\t\toriginalId\n\t\t\t\t? ( select( coreStore ).getEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\toriginalId\n\t\t\t\t\t) as Media | undefined )\n\t\t\t\t: undefined,\n\t\t[ originalId ]\n\t);\n\tconst originalWidth = Number( originalRecord?.media_details?.width );\n\tconst originalHeight = Number( originalRecord?.media_details?.height );\n\tconst originalUrl = originalRecord?.source_url;\n\tconst originalSource =\n\t\toriginalId &&\n\t\toriginalRecord &&\n\t\ttypeof originalUrl === 'string' &&\n\t\toriginalUrl.length > 0 &&\n\t\tNumber.isFinite( originalWidth ) &&\n\t\toriginalWidth > 0 &&\n\t\tNumber.isFinite( originalHeight ) &&\n\t\toriginalHeight > 0\n\t\t\t? {\n\t\t\t\t\tid: originalId,\n\t\t\t\t\turl: originalUrl,\n\t\t\t\t\tmedia: originalRecord,\n\t\t\t\t}\n\t\t\t: undefined;\n\tconst canRestoreOriginal = !! originalSource;\n\tconst replacementSource =\n\t\tisSourceReplaced && originalSource\n\t\t\t? {\n\t\t\t\t\tid: originalSource.id,\n\t\t\t\t\turl: originalSource.url,\n\t\t\t\t\tmedia: originalSource.media,\n\t\t\t\t}\n\t\t\t: undefined;\n\t// Details and pending edits follow the attachment shown on the canvas.\n\t// Keep `sourceMedia` separate for the snackbar's previous attachment.\n\tconst activeId = replacementSource?.id ?? id;\n\tconst { media, hasEdits } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEditedEntityRecord,\n\t\t\t\tgetEntityRecord,\n\t\t\t\thasEditsForEntityRecord,\n\t\t\t} = select( coreStore );\n\t\t\t// Fetch embedded author and attached-post data for Details.\n\t\t\tgetEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tactiveId,\n\t\t\t\tATTACHMENT_EMBED_QUERY\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tmedia: getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tactiveId\n\t\t\t\t) as Media,\n\t\t\t\thasEdits: hasEditsForEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tactiveId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ activeId ]\n\t);\n\t// Refresh embedded data on opening or switching to the original.\n\tuseEffect( () => {\n\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t'postType',\n\t\t\t'attachment',\n\t\t\tactiveId,\n\t\t\tATTACHMENT_EMBED_QUERY,\n\t\t] );\n\t}, [ activeId, invalidateResolution ] );\n\tconst handleRestoreOriginal = useCallback( () => {\n\t\t// Restoring discards every pending edit, as the menu item says, so\n\t\t// nothing staged against the attachment being replaced reaches a save.\n\t\tclearEntityRecordEdits( 'postType', 'attachment', id );\n\t\tif ( onEditOriginal && originalId ) {\n\t\t\tonEditOriginal( originalId );\n\t\t\treturn;\n\t\t}\n\t\tsetIsSourceReplaced( true );\n\t}, [ clearEntityRecordEdits, id, onEditOriginal, originalId ] );\n\n\t// A bare replacement has no image editor change, so OR the flag in explicitly.\n\tconst hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;\n\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;\n\tconst isImage = !! media && mediaType === 'image';\n\n\t// Docked, the panel opens on Crop: the canvas is still beside it and\n\t// cropping is what the editor is for. Below `small` an open panel covers\n\t// the canvas, and crop controls with no crop in sight are not worth\n\t// opening on, so Details leads there. Non-image media has no Crop tab at\n\t// all (see `tabs`), so it always gets Details.\n\tconst currentTab =\n\t\tchosenTab ?? ( isWide && isImage ? CROP_PANEL : DETAILS_PANEL );\n\t// `null` when nothing is open, otherwise the open panel's id. Until the\n\t// user opens or closes the panel, follow the breakpoint: dragging a window\n\t// narrow hands the canvas the full width instead of leaving a panel\n\t// wedged beside it.\n\tlet activePanel = chosenPanel;\n\tif ( activePanel === undefined ) {\n\t\tactivePanel = isWide ? currentTab : null;\n\t}\n\t// Switching tabs says nothing about whether the panel should be open, so\n\t// it leaves `chosenPanel` unset: picking Details on a wide screen and then\n\t// dragging the window narrow should still hand the canvas the full width.\n\tconst selectPanel = useCallback( ( panel: string ) => {\n\t\tsetChosenTab( panel );\n\t\tsetChosenPanel( ( chosen ) =>\n\t\t\tchosen === undefined ? chosen : panel\n\t\t);\n\t}, [] );\n\tconst togglePanel = useCallback( () => {\n\t\tsetChosenPanel( activePanel ? null : currentTab );\n\t}, [ activePanel, currentTab ] );\n\tconst { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =\n\t\tuseCropOptions( { aspectRatioPresets } );\n\tconst { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {\n\t\tsession,\n\t\tid,\n\t\tisImage,\n\t\tmedia: sourceMedia,\n\t\tonSaved,\n\t\treplacementSource,\n\t} );\n\n\tconst handleChange = ( updates: Partial< Media > ) => {\n\t\t// A save reads the pending edits once and then waits. An edit\n\t\t// arriving after that read misses the request, and a crop save\n\t\t// then clears the edits for this id, so it would be lost rather\n\t\t// than merely late. It would also land on the attachment being\n\t\t// replaced, not the new one the modal moves to.\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\teditEntityRecord( 'postType', 'attachment', activeId, updates );\n\t};\n\n\tconst discardAndClose = () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tclearEntityRecordEdits( 'postType', 'attachment', activeId );\n\t\tsetIsSourceReplaced( false );\n\t\tonClose?.();\n\t};\n\n\tconst handleRequestClose = () => {\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( hasChanges ) {\n\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\treturn;\n\t\t}\n\t\tdiscardAndClose();\n\t};\n\n\tconst handleKeyDown = ( event: ReactKeyboardEvent< HTMLElement > ) => {\n\t\tconst isUndoShortcut = isKeyboardEvent.primary( event, 'z' );\n\t\tconst isRedoShortcut =\n\t\t\tisKeyboardEvent.primaryShift( event, 'z' ) ||\n\t\t\t( ! isAppleOS() && isKeyboardEvent.primary( event, 'y' ) );\n\t\tif ( ( isUndoShortcut || isRedoShortcut ) && isImage ) {\n\t\t\tconst target = event.target as HTMLElement;\n\t\t\tconst isMetadataField =\n\t\t\t\t( target.tagName === 'INPUT' ||\n\t\t\t\t\ttarget.tagName === 'TEXTAREA' ||\n\t\t\t\t\ttarget.isContentEditable ) &&\n\t\t\t\t! target.closest( `[${ CROP_CONTROL_ATTR }]` );\n\t\t\tif ( ! isMetadataField ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( isCropInteractionActive || isSaving ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif ( isRedoShortcut ) {\n\t\t\t\t\tsession.redo();\n\t\t\t\t} else {\n\t\t\t\t\tsession.undo();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif ( shouldCloseOnEsc ) {\n\t\t\tif ( event.code !== 'Escape' && event.key !== 'Escape' ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( isSaving ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( hasChanges ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\t}\n\t\t}\n\t};\n\n\tconst snackbar = (\n\t\t<SnackbarNotices\n\t\t\tclassName={ noticesClassName }\n\t\t\tcontext={ MEDIA_EDITOR_NOTICES_CONTEXT }\n\t\t/>\n\t);\n\n\t// Below `small` the panel is full screen, so an open one replaces the\n\t// canvas and these never share the screen with the Crop panel's copies:\n\t// this row is what reaches rotate/flip/zoom while the panel is closed,\n\t// with aspect ratio joining them as a dropdown. From `small` up the Crop\n\t// panel docks beside the canvas and carries them instead.\n\tconst imageControls =\n\t\tisImage && ! isWide ? (\n\t\t\t<MediaEditorImageControls\n\t\t\t\tshowAspectRatioControl\n\t\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t/>\n\t\t) : null;\n\n\t// Crop leads, since it is what the docked panel opens on. Non-image media\n\t// has nothing to crop and gets Details alone, which is why the sidebar\n\t// takes this list rather than deriving it.\n\tconst tabs: MediaEditorTab[] = [\n\t\t...( isImage\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: CROP_PANEL,\n\t\t\t\t\t\ttitle: __( 'Crop' ),\n\t\t\t\t\t\trender: () => (\n\t\t\t\t\t\t\t<MediaEditorCropPanel\n\t\t\t\t\t\t\t\taspectRatioValue={ aspectRatioValue }\n\t\t\t\t\t\t\t\tonAspectRatioChange={ setAspectRatioValue }\n\t\t\t\t\t\t\t\taspectRatioOptions={ aspectRatioOptions }\n\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [] ),\n\t\t{\n\t\t\tid: DETAILS_PANEL,\n\t\t\ttitle: __( 'Details' ),\n\t\t\trender: () => <MediaForm />,\n\t\t},\n\t];\n\n\tconst ruler = isImage ? (\n\t\t<MediaEditorFineRotation\n\t\t\tonPlacementControlInteraction={ signalPlacementControlInteraction }\n\t\t\tdisabled={ isSaving }\n\t\t/>\n\t) : null;\n\n\tconst children = (\n\t\t<MediaEditorProvider\n\t\t\tvalue={ media ?? undefined }\n\t\t\tonChange={ handleChange }\n\t\t\tsettings={ {\n\t\t\t\t// Disable the fields while saving, so the guard in\n\t\t\t\t// `handleChange` is not silently swallowing typing.\n\t\t\t\t// `readOnly` would swap the field's layout mid-save;\n\t\t\t\t// disabled keeps it in place and greys it out.\n\t\t\t\tfields: isSaving\n\t\t\t\t\t? fields.map( ( field ) => ( {\n\t\t\t\t\t\t\t...field,\n\t\t\t\t\t\t\tisDisabled: true,\n\t\t\t\t\t\t} ) )\n\t\t\t\t\t: fields,\n\t\t\t\tform,\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"media-editor\">\n\t\t\t\t{ ! media ? (\n\t\t\t\t\t<div className=\"media-editor__loading\">\n\t\t\t\t\t\t<WCSpinner />\n\t\t\t\t\t</div>\n\t\t\t\t) : (\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ clsx( 'media-editor__body', {\n\t\t\t\t\t\t\t'has-panel-open': !! activePanel,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<NavigableRegion\n\t\t\t\t\t\t\tclassName=\"media-editor__content\"\n\t\t\t\t\t\t\tariaLabel={\n\t\t\t\t\t\t\t\tisImage\n\t\t\t\t\t\t\t\t\t? __( 'Image editor' )\n\t\t\t\t\t\t\t\t\t: __( 'Media preview' )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div className=\"media-editor__canvas-area\">\n\t\t\t\t\t\t\t\t{ isImage ? (\n\t\t\t\t\t\t\t\t\t<MediaEditorCanvas\n\t\t\t\t\t\t\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\t\t\t\t\t\t\tonGestureStart={\n\t\t\t\t\t\t\t\t\t\t\thandleCanvasGestureStart\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonGestureEnd={ handleCanvasGestureEnd }\n\t\t\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t<MediaPreview />\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t{ isImage && (\n\t\t\t\t\t\t\t\t<div className=\"media-editor__canvas-toolbar\">\n\t\t\t\t\t\t\t\t\t{ ruler }\n\t\t\t\t\t\t\t\t\t{ imageControls }\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</NavigableRegion>\n\t\t\t\t\t\t<AnimatePresence\n\t\t\t\t\t\t\tinitial={ false }\n\t\t\t\t\t\t\tcustom={ sidebarTransition }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ !! activePanel && (\n\t\t\t\t\t\t\t\t<motion.div\n\t\t\t\t\t\t\t\t\tclassName=\"media-editor__sidebar-container\"\n\t\t\t\t\t\t\t\t\tvariants={ sidebarVariants }\n\t\t\t\t\t\t\t\t\tinitial=\"closed\"\n\t\t\t\t\t\t\t\t\tanimate=\"open\"\n\t\t\t\t\t\t\t\t\texit=\"closed\"\n\t\t\t\t\t\t\t\t\ttransition={ sidebarTransition }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<MediaEditorSidebar\n\t\t\t\t\t\t\t\t\t\ttabs={ tabs }\n\t\t\t\t\t\t\t\t\t\t// Swapping the edited media can drop the\n\t\t\t\t\t\t\t\t\t\t// Crop tab out from under an open panel —\n\t\t\t\t\t\t\t\t\t\t// saving a crop moves the editor to a new\n\t\t\t\t\t\t\t\t\t\t// id, which may resolve as non-image.\n\t\t\t\t\t\t\t\t\t\t// Fall back rather than hand `Tabs.Root`\n\t\t\t\t\t\t\t\t\t\t// a value no tab matches.\n\t\t\t\t\t\t\t\t\t\tactiveTab={\n\t\t\t\t\t\t\t\t\t\t\ttabs.some(\n\t\t\t\t\t\t\t\t\t\t\t\t( tab ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\ttab.id === activePanel\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t? activePanel\n\t\t\t\t\t\t\t\t\t\t\t\t: DETAILS_PANEL\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonSelectTab={ selectPanel }\n\t\t\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</motion.div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</AnimatePresence>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ isDiscardDialogOpen }\n\t\t\t\tconfirmButtonText={ __( 'Discard' ) }\n\t\t\t\tcancelButtonText={ __( 'Keep editing' ) }\n\t\t\t\tonCancel={ () => setIsDiscardDialogOpen( false ) }\n\t\t\t\tonConfirm={ () => {\n\t\t\t\t\tsetIsDiscardDialogOpen( false );\n\t\t\t\t\tdiscardAndClose();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ __(\n\t\t\t\t\t'Are you sure you want to discard your unsaved changes?'\n\t\t\t\t) }\n\t\t\t</ConfirmDialog>\n\t\t\t{ noticesPortalElement\n\t\t\t\t? createPortal( snackbar, noticesPortalElement )\n\t\t\t\t: snackbar }\n\t\t</MediaEditorProvider>\n\t);\n\n\t// Rebuilt each render, like the elements it replaces: consumers re-render\n\t// as they always did, but the cluster component types stay stable.\n\tconst contextValue: MediaEditorFrameContextValue = {\n\t\tisImage,\n\t\tisSaving,\n\t\thasMedia: !! media,\n\t\thasChanges,\n\t\t// Saving freezes the whole edit surface: `save()` reads the\n\t\t// modifiers once and then awaits, so anything changed after that\n\t\t// would be silently dropped when the save resolves.\n\t\tisUndoRedoDisabled: isCropInteractionActive || isSaving,\n\t\taspectRatioPresets,\n\t\tisWide,\n\t\tactivePanel,\n\t\tonTogglePanel: togglePanel,\n\t\tonCancel: handleRequestClose,\n\t\tonSave: saveMediaEditor,\n\t\tcanRestoreOriginal,\n\t\tisSourceReplaced,\n\t\topensOriginal: !! onEditOriginal,\n\t\tonRestoreOriginal: handleRestoreOriginal,\n\t};\n\n\treturn (\n\t\t<MediaEditorFrameContext.Provider value={ contextValue }>\n\t\t\t{ renderFrame( {\n\t\t\t\tchildren,\n\t\t\t\tisImage,\n\t\t\t\tlayout,\n\t\t\t\tonRequestClose: handleRequestClose,\n\t\t\t\tonKeyDown: handleKeyDown,\n\t\t\t\tshouldCloseOnClickOutside: ! hasChanges && ! isSaving,\n\t\t\t\tisSaving,\n\t\t\t\thasChanges,\n\t\t\t\thasMedia: !! media,\n\t\t\t} ) }\n\t\t</MediaEditorFrameContext.Provider>\n\t);\n}\n\nexport function MediaEditor( props: MediaEditorProps ) {\n\treturn (\n\t\t<MediaEditorStateProvider key={ props.id }>\n\t\t\t<MediaEditorContent { ...props } />\n\t\t</MediaEditorStateProvider>\n\t);\n}\n\n// Attached to `MediaEditor` so frames import and arrange them, the way\n// `DataViewsPicker` exposes its own sub-components. They read what they need\n// from context, so a frame only chooses where they go and how they look.\nMediaEditor.HeaderActions = HeaderActions;\nMediaEditor.PanelToggle = PanelToggle;\nMediaEditor.MoreMenu = MoreMenu;\nMediaEditor.HistoryActions = HistoryActions;\nMediaEditor.SaveActions = SaveActions;\n\nexport default MediaEditor;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,MAAM,yBAAyB,EAAE,QAAQ,wBAAwB;AAEjE,MAAM,4BAA4B;;;;;;;AAQlC,MAAM,gBAAgB;;AAGtB,MAAM,aAAa;AAGnB,MAAM,6BAA6B;AAQnC,MAAM,kBAAkB;CAEvB,MAAM,EAAE,OAAO,OAAO;CAGtB,SAAU,gBAAqC;EAC9C,OAAO;EACP;CACD;AACD;AAyDA,SAAS,mBAAoB,EAC5B,MACA,WACA,aACA,WAAW,SACiB;CAC5B,OACC,qBAAC,iBAAD;EACC,WAAU;EACV,WAAY,GAAI,gBAAiB;E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f,UAAU;EACV,QAAQ;EACR;EACA;EACA,eAAe,CAAC,CAAE;EAClB,mBAAmB;CACpB;CAEA,OACC,oBAAC,wBAAwB,UAAzB;EAAkC,OAAQ;EACvC,UAAA,YAAa;GACd;GACA;GACA;GACA,gBAAgB;GAChB,WAAW;GACX,2BAA2B,CAAE,cAAc,CAAE;GAC7C;GACA;GACA,UAAU,CAAC,CAAE;EACd,CAAE;CAC+B,CAAA;AAEpC;AAEA,SAAgB,YAAa,OAA0B;CACtD,OACC,oBAAC,0BAAD,EAAA,UACC,oBAAC,oBAAD,EAAoB,GAAK,MAAS,CAAA,EACT,GAFM,MAAM,EAEZ;AAE5B;AAKA,YAAY,gBAAgB;AAC5B,YAAY,cAAc;AAC1B,YAAY,WAAW;AACvB,YAAY,iBAAiB;AAC7B,YAAY,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["coreStore","noticesStore","WCSpinner","AnimatePresence","motion","ConfirmDialog"],"sources":["../../../src/components/media-editor/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport {\n\tButton,\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tModal,\n\tSpinner as WCSpinner,\n\t__experimentalConfirmDialog as ConfirmDialog,\n\t__unstableAnimatePresence as AnimatePresence,\n\t__unstableMotion as motion,\n\tSlot,\n\tSlotFillProvider,\n} from '@wordpress/components';\nimport { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';\nimport { PluginArea } from '@wordpress/plugins';\nimport { useReducedMotion, useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, useRegistry, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { NavigableRegion } from '@wordpress/admin-ui';\nimport {\n\tcreateContext,\n\tcreatePortal,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tbackup,\n\tclose,\n\tdrawerRight,\n\tkeyboard,\n\tmoreVertical,\n\tredo,\n\tundo,\n} from '@wordpress/icons';\nimport {\n\tdisplayShortcut,\n\tisAppleOS,\n\tisKeyboardEvent,\n\twithIgnoreIMEEvents,\n} from '@wordpress/keycodes';\nimport { SnackbarNotices, store as noticesStore } from '@wordpress/notices';\nimport { inertValue } from '@wordpress/react-inert-value';\nimport type { Action, ActionModal, Field, Form } from '@wordpress/dataviews';\nimport type {\n\tKeyboardEvent as ReactKeyboardEvent,\n\tReactElement,\n\tReactNode,\n} from 'react';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport { MediaEditorProvider } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\nimport MediaPreview from '../media-preview';\nimport MediaEditorCanvas from '../media-editor-canvas';\nimport MediaEditorFineRotation from '../media-editor-fine-rotation';\nimport MediaEditorCropPanel from '../media-editor-crop-panel';\nimport MediaEditorImageControls from '../media-editor-image-controls';\nimport MediaForm from '../media-form';\nimport MediaEditorPanel, {\n\tMEDIA_EDITOR_PLUGIN_SCOPE,\n\tMediaEditorPanelsProvider,\n\tgetPanelSlotName,\n\tuseMediaEditorPanels,\n\ttype MediaEditorPanelFillProps,\n} from '../media-editor-panel';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { MediaEditorStateProvider, useMediaEditor } from '../../state';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorKeyboardShortcutsModal from '../media-editor-keyboard-shortcuts-modal';\nimport {\n\tMEDIA_EDITOR_NOTICES_CONTEXT,\n\tuseSaveMediaEditor,\n\ttype MediaEditorSaveResult,\n} from './use-save-media-editor';\nimport { useCropOptions } from './use-crop-options';\n\nexport type { MediaEditorSaveResult } from './use-save-media-editor';\n\n// Embed query for the attachment's author and parent post. Shared between\n// the `getEntityRecord` read and the matching `invalidateResolution` so the\n// two stay in lockstep.\nconst ATTACHMENT_EMBED_QUERY = { _embed: 'author,wp:attached-to' } as const;\n\nconst PLACEMENT_CONTROL_IDLE_MS = 300;\n\n/**\n * The Details panel's id. Every media type has this panel, so the sidebar\n * shows it when the requested panel doesn't exist.\n *\n * The sidebar stores the open panel's id, so adding a panel only needs a new\n * id and a new tab.\n */\nconst DETAILS_PANEL = 'core/details';\n\n/** Identifier for the crop panel. Images only; other media has nothing to crop. */\nconst CROP_PANEL = 'core/crop';\n\nconst CROP_MEDIA_TYPES = [ 'image' ] as const;\n\n// Matches the editor's sidebar in `ComplementaryArea`.\nconst SIDEBAR_ANIMATION_DURATION = 0.3;\n\ntype SidebarTransition = {\n\ttype: 'tween';\n\tduration: number;\n\tease: number[];\n};\n\nconst sidebarVariants = {\n\t// `auto` leaves the width to the sidebar's stylesheet.\n\topen: { width: 'auto' },\n\t// Takes the transition from `AnimatePresence`'s `custom` prop, so a\n\t// sidebar that is already closing still gets the current one.\n\tclosed: ( transition: SidebarTransition ) => ( {\n\t\twidth: 0,\n\t\ttransition,\n\t} ),\n};\n\ninterface MediaEditorTab {\n\tid: string;\n\ttitle: string;\n\trender: () => ReactElement;\n}\n\nexport interface MediaEditorFrameProps {\n\tchildren: ReactNode;\n\t/**\n\t * Whether the media being edited is an image. The history and transform\n\t * clusters render nothing for other media types, so a frame uses this to\n\t * decide whether the container it would put them in is worth rendering at\n\t * all.\n\t */\n\tisImage: boolean;\n\t/**\n\t * `narrow` below the `small` breakpoint, where the frame's header has no\n\t * room for the history cluster beside its other controls. A frame uses\n\t * this to place that cluster, not to decide whether it renders —\n\t * `HistoryActions` returns nothing on its own when the canvas is off\n\t * screen.\n\t */\n\tlayout: 'wide' | 'narrow';\n\tonRequestClose: () => void;\n\tonKeyDown: ( event: ReactKeyboardEvent< HTMLElement > ) => void;\n\tshouldCloseOnClickOutside: boolean;\n\tisSaving: boolean;\n\thasChanges: boolean;\n\thasMedia: boolean;\n}\n\nexport interface MediaEditorProps {\n\tfields?: Field< Media >[];\n\tform?: Form;\n\tid: number;\n\taspectRatioPresets?: AspectRatioPreset[];\n\tonClose?: () => void;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/** Called with the original's id when the user chooses \"Edit original\". */\n\tonEditOriginal?: ( originalId: number ) => void;\n\trenderFrame: ( props: MediaEditorFrameProps ) => ReactElement;\n\tnoticesClassName?: string;\n\tnoticesPortalElement?: Element | null;\n\tshouldCloseOnEsc?: boolean;\n\t/**\n\t * The id of the panel to open on, which is also shown as the first tab.\n\t * Below `small`, or when no tab has this id, the sidebar opens on\n\t * Details.\n\t *\n\t * @default 'core/details'\n\t */\n\tdefaultPanel?: string;\n}\n\ninterface MediaEditorSidebarProps {\n\ttabs: MediaEditorTab[];\n\t/** The open panel's id. Always one of `tabs`. */\n\tactiveTab: string;\n\tonSelectTab: ( tab: string ) => void;\n\t/** Freeze the open panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\nfunction MediaEditorSidebar( {\n\ttabs,\n\tactiveTab,\n\tonSelectTab,\n\tdisabled = false,\n}: MediaEditorSidebarProps ) {\n\treturn (\n\t\t<NavigableRegion\n\t\t\tclassName=\"media-editor__sidebar\"\n\t\t\tariaLabel={ __( 'Media settings' ) }\n\t\t>\n\t\t\t{ /* No visible heading and no close button: the strip below names\n\t\t\t the open panel and the header's pressed toggle dismisses it.\n\t\t\t The heading stays for screen readers, which read neither as\n\t\t\t this region's title. */ }\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Media settings' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<Tabs.Root\n\t\t\t\tclassName=\"media-editor__tabs\"\n\t\t\t\tvalue={ activeTab }\n\t\t\t\tonValueChange={ onSelectTab }\n\t\t\t>\n\t\t\t\t{ /* `Tabs.List` sizes itself to its tabs (`width: fit-content`),\n\t\t\t\t so the rule under the strip is drawn by this wrapper\n\t\t\t\t instead, which spans the column. */ }\n\t\t\t\t<div className=\"media-editor__tablist\">\n\t\t\t\t\t<Tabs.List variant=\"minimal\">\n\t\t\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t\t\t<Tabs.Tab\n\t\t\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\t\t\tvalue={ tab.id }\n\t\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ tab.title }\n\t\t\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</Tabs.List>\n\t\t\t\t</div>\n\t\t\t\t{ /* One `Tabs.Panel` per tab: the counts have to match or\n\t\t\t\t `Tabs.Root` throws in dev. Only the active one paints\n\t\t\t\t anything — the rest render nothing. */ }\n\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t<Tabs.Panel\n\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\tvalue={ tab.id }\n\t\t\t\t\t\ttabIndex={ -1 }\n\t\t\t\t\t\tclassName=\"media-editor__panel\"\n\t\t\t\t\t\t// A save reads the session once and then waits, so\n\t\t\t\t\t\t// nothing in the panel may act on it meanwhile.\n\t\t\t\t\t\t// `inert` covers panels that ignore `disabled`.\n\t\t\t\t\t\tinert={ inertValue( disabled ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Stack direction=\"column\" gap=\"lg\">\n\t\t\t\t\t\t\t{ tab.render() }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t</Tabs.Panel>\n\t\t\t\t) ) }\n\t\t\t</Tabs.Root>\n\t\t</NavigableRegion>\n\t);\n}\n\n/**\n * Everything the frame's action clusters need from the editor. Supplied by\n * context rather than by props so the clusters can be module-level components:\n * a component created during a render has a new identity on every pass, which\n * remounts its subtree and drops focus mid-interaction.\n */\ninterface MediaEditorFrameContextValue {\n\tisImage: boolean;\n\tisSaving: boolean;\n\thasMedia: boolean;\n\thasChanges: boolean;\n\tisUndoRedoDisabled: boolean;\n\taspectRatioPresets?: AspectRatioPreset[];\n\t/** `true` above `large`, where the panel docks beside the canvas. */\n\tisWide: boolean;\n\t/** The open panel's id, or `null` when none is. */\n\tactivePanel: string | null;\n\t/**\n\t * Opens the sidebar on the last-shown panel, or closes it when one is\n\t * already open.\n\t */\n\tonTogglePanel: () => void;\n\tonCancel: () => void;\n\tonSave: () => void;\n\t/**\n\t * When `true`, the media has a lineage root to restore to, so the\n\t * history menu shows its \"Restore original\" item.\n\t */\n\tcanRestoreOriginal: boolean;\n\t/**\n\t * When `true`, another attachment has replaced the edited one in the\n\t * image editor this session (today, only the original), so the menu item is\n\t * disabled.\n\t */\n\tisSourceReplaced: boolean;\n\t/** Whether the frame opens the original itself. */\n\topensOriginal: boolean;\n\t/**\n\t * Load the lineage root into the image editor, or hand it to the\n\t * frame.\n\t */\n\tonRestoreOriginal: () => void;\n}\n\nconst MediaEditorFrameContext =\n\tcreateContext< MediaEditorFrameContextValue | null >( null );\n\n/**\n * Hook to access the media editor's frame context.\n *\n * Must be used within a MediaEditor component.\n *\n * @return MediaEditorFrameContextValue the action clusters render from.\n */\nfunction useMediaEditorFrameContext(): MediaEditorFrameContextValue {\n\tconst context = useContext( MediaEditorFrameContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditorFrameContext must be used within MediaEditor'\n\t\t);\n\t}\n\treturn context;\n}\n\nfunction CropPanelContent( { disabled }: MediaEditorPanelFillProps ) {\n\tconst { aspectRatioPresets } = useMediaEditorFrameContext();\n\tconst { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =\n\t\tuseCropOptions( { aspectRatioPresets } );\n\treturn (\n\t\t<MediaEditorCropPanel\n\t\t\taspectRatioValue={ aspectRatioValue }\n\t\t\tonAspectRatioChange={ setAspectRatioValue }\n\t\t\taspectRatioOptions={ aspectRatioOptions }\n\t\t\tdisabled={ disabled }\n\t\t/>\n\t);\n}\n\nexport interface HeaderActionsProps {\n\t/**\n\t * Whether to include a Close button. Frames with a dismissal affordance of\n\t * their own — a route's breadcrumbs, say — leave it out.\n\t *\n\t * @default false\n\t */\n\tshowCloseButton?: boolean;\n}\n\nfunction PanelToggle() {\n\tconst { isWide, activePanel, onTogglePanel } = useMediaEditorFrameContext();\n\tconst isPanelOpen = !! activePanel;\n\t// The sidebar holds more than one panel, so this opens and closes the\n\t// sidebar rather than naming a panel: reopening returns to whichever tab\n\t// was last showing, and the tab strip inside switches between them.\n\treturn (\n\t\t<Button\n\t\t\tsize=\"compact\"\n\t\t\ticon={ drawerRight }\n\t\t\tlabel={ __( 'Media settings' ) }\n\t\t\tisPressed={ isPanelOpen }\n\t\t\t// Only a docked column really expands beside the canvas; below\n\t\t\t// that the panel replaces the view, which the pressed state\n\t\t\t// already describes.\n\t\t\taria-expanded={ isWide ? isPanelOpen : undefined }\n\t\t\tonClick={ onTogglePanel }\n\t\t/>\n\t);\n}\n\nfunction getActionLabel( action: Action< Media >, items: Media[] ) {\n\treturn typeof action.label === 'string'\n\t\t? action.label\n\t\t: action.label( items );\n}\n\ninterface MediaActionModalProps {\n\taction: ActionModal< Media >;\n\titems: Media[];\n\tcloseModal: () => void;\n}\n\n// A copy of the `ActionModal` in `@wordpress/dataviews`, which isn't\n// exported. It could be replaced if dataviews exports it.\nfunction MediaActionModal( {\n\taction,\n\titems,\n\tcloseModal,\n}: MediaActionModalProps ) {\n\tconst header =\n\t\ttypeof action.modalHeader === 'function'\n\t\t\t? action.modalHeader( items )\n\t\t\t: action.modalHeader;\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ header || getActionLabel( action, items ) }\n\t\t\t__experimentalHideHeader={ !! action.hideModalHeader }\n\t\t\tonRequestClose={ closeModal }\n\t\t\tfocusOnMount={ action.modalFocusOnMount ?? true }\n\t\t\tsize={ action.modalSize || 'medium' }\n\t\t>\n\t\t\t<action.RenderModal items={ items } closeModal={ closeModal } />\n\t\t</Modal>\n\t);\n}\n\nexport interface MoreMenuProps {\n\t/**\n\t * Actions for the attachment, such as those from the entity actions API.\n\t * Only the ones whose `isEligible` passes for `item` are shown.\n\t */\n\tactions?: Action< Media >[];\n\t/**\n\t * The attachment the actions apply to, with anything their `isEligible`\n\t * checks need, such as `permissions`. Without it no actions are shown.\n\t */\n\titem?: Media;\n}\n\nfunction MoreMenu( { actions = [], item }: MoreMenuProps ) {\n\tconst { isImage, isSaving } = useMediaEditorFrameContext();\n\tconst registry = useRegistry();\n\tconst [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );\n\tconst [ activeModalAction, setActiveModalAction ] =\n\t\tuseState< ActionModal< Media > | null >( null );\n\n\tconst items = item ? [ item ] : [];\n\tconst eligibleActions = useMemo(\n\t\t() =>\n\t\t\titem\n\t\t\t\t? actions.filter(\n\t\t\t\t\t\t( action ) =>\n\t\t\t\t\t\t\t! action.isEligible || action.isEligible( item )\n\t\t\t\t\t)\n\t\t\t\t: [],\n\t\t[ actions, item ]\n\t);\n\n\tif ( ! isImage && ! eligibleActions.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\ticon={ moreVertical }\n\t\t\t\tlabel={ __( 'More options' ) }\n\t\t\t\ttoggleProps={ { size: 'compact' } }\n\t\t\t>\n\t\t\t\t{ ( { onClose: closeMenu } ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ isImage && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\ticon={ keyboard }\n\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsShortcutsModalOpen( true );\n\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Keyboard shortcuts' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ !! eligibleActions.length && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t{ eligibleActions.map( ( action ) => {\n\t\t\t\t\t\t\t\t\tconst label = getActionLabel(\n\t\t\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\t\t\titems\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ action.id }\n\t\t\t\t\t\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t\t\t\t\t\tisSaving || action.disabled\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t\t\t\tif ( 'RenderModal' in action ) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsetActiveModalAction(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\taction\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\taction.callback( items, {\n\t\t\t\t\t\t\t\t\t\t\t\t\tregistry,\n\t\t\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ 'RenderModal' in action\n\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: Action label. Use the ellipsis and spacing appropriate for your language. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'%s…',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'menu item requiring further input'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlabel\n\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t: label }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ isShortcutsModalOpen && (\n\t\t\t\t<MediaEditorKeyboardShortcutsModal\n\t\t\t\t\tonClose={ () => setIsShortcutsModalOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ activeModalAction && (\n\t\t\t\t<MediaActionModal\n\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\titems={ items }\n\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {\n\tconst { isSaving, onCancel } = useMediaEditorFrameContext();\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__header-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<PanelToggle />\n\t\t\t<MoreMenu />\n\t\t\t{ showCloseButton && (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ close }\n\t\t\t\t\tlabel={ __( 'Close' ) }\n\t\t\t\t\tonClick={ onCancel }\n\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction HistoryActions() {\n\tconst {\n\t\tisImage,\n\t\tisSaving,\n\t\tisUndoRedoDisabled,\n\t\tisWide,\n\t\tactivePanel,\n\t\tcanRestoreOriginal,\n\t\tisSourceReplaced,\n\t\topensOriginal,\n\t\tonRestoreOriginal,\n\t} = useMediaEditorFrameContext();\n\tconst {\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t} = useMediaEditor();\n\t// Reset, undo and redo act on the image edits, so they only appear where\n\t// the canvas does. Non-image media has no edit history at all; below the dock\n\t// breakpoint an open panel replaces the canvas, and leaving these behind\n\t// would put an enabled, destructive Reset next to metadata fields it does\n\t// not touch — clicking it would discard a crop the user cannot see.\n\t// (Metadata edits have no undo of their own; a history spanning both is a\n\t// larger change than hiding these.) Checked after the hooks above so the\n\t// hook order stays stable across renders.\n\tif ( ! isImage || ( ! isWide && !! activePanel ) ) {\n\t\treturn null;\n\t}\n\tconst handleUndo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tundoCrop();\n\t};\n\tconst handleRedo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tredoCrop();\n\t};\n\tconst handleReset = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\treset();\n\t};\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__history-actions\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ undo }\n\t\t\t\tlabel={ __( 'Undo' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tshortcut={ displayShortcut.primary( 'z' ) }\n\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasUndo }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleUndo }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ redo }\n\t\t\t\tlabel={ __( 'Redo' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tshortcut={\n\t\t\t\t\tisAppleOS()\n\t\t\t\t\t\t? displayShortcut.primaryShift( 'z' )\n\t\t\t\t\t\t: displayShortcut.primary( 'y' )\n\t\t\t\t}\n\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasRedo }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleRedo }\n\t\t\t/>\n\t\t\t<DropdownMenu\n\t\t\t\ticon={ backup }\n\t\t\t\tlabel={ __( 'History' ) }\n\t\t\t\tpopoverProps={ { placement: 'top-start' } }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tsize: 'compact',\n\t\t\t\t\tdisabled:\n\t\t\t\t\t\tisUndoRedoDisabled ||\n\t\t\t\t\t\t( ! isDirty && ! canRestoreOriginal ),\n\t\t\t\t\taccessibleWhenDisabled: true,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ ( { onClose: closeMenu } ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! isDirty }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\thandleReset();\n\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Reset image edits' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t{ canRestoreOriginal && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tdisabled={ isSourceReplaced || isSaving }\n\t\t\t\t\t\t\t\t\tinfo={ __( 'Discards unsaved changes.' ) }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonRestoreOriginal();\n\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ opensOriginal\n\t\t\t\t\t\t\t\t\t\t? __( 'Edit original' )\n\t\t\t\t\t\t\t\t\t\t: __( 'Restore original' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t</Stack>\n\t);\n}\n\nexport interface SaveActionsProps {\n\t/**\n\t * Button height. Footers take the 40px default; frames placing these in a\n\t * page header pass `compact` to match the header's other controls.\n\t *\n\t * @default 'default'\n\t */\n\tsize?: 'default' | 'compact';\n}\n\nfunction SaveActions( { size = 'default' }: SaveActionsProps ) {\n\tconst { isSaving, hasMedia, hasChanges, onCancel, onSave } =\n\t\tuseMediaEditorFrameContext();\n\tconst saveDisabled = isSaving || ! hasMedia || ! hasChanges;\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__save-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tsize={ size }\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t\tonClick={ onCancel }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tsize={ size }\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ onSave }\n\t\t\t\tisBusy={ isSaving }\n\t\t\t\tdisabled={ saveDisabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t{ __( 'Save' ) }\n\t\t\t</Button>\n\t\t</Stack>\n\t);\n}\n\nfunction MediaEditorContent( {\n\tfields = [],\n\tform,\n\tid,\n\taspectRatioPresets,\n\tonClose,\n\tonSaved,\n\tonEditOriginal,\n\trenderFrame,\n\tnoticesClassName = 'media-editor__snackbar',\n\tnoticesPortalElement,\n\tshouldCloseOnEsc = false,\n\tdefaultPanel = DETAILS_PANEL,\n}: MediaEditorProps ) {\n\tconst session = useMediaEditor();\n\t// Width decides whether the settings panel docks beside the canvas or\n\t// takes the whole body. It docks from `small` (600px): the modal is the\n\t// viewport less a 16px margin either side, so a 320px panel and the\n\t// canvas column's 2 x 24px gutters still leave the canvas ~200px there\n\t// and ~380px by 782px. Tight, but a full-screen panel would have hidden\n\t// the image altogether — you could not crop and preview at once.\n\t//\n\t// The same line moves the transform controls: docked, the Crop panel\n\t// carries them; below it they fall back to a row under the canvas.\n\t//\n\t// The choice is not carried across openings: the modal is transient, and\n\t// re-opening with the panel hidden on a wide screen is how #81487 read to\n\t// people in the first place. Within one opening it does hold — see\n\t// `chosenPanel` below.\n\tconst isWide = useViewportMatch( 'small' );\n\t// Below `small` the open panel replaces the canvas instead of sitting\n\t// beside it, so there is nothing to animate.\n\tconst disableSidebarMotion = useReducedMotion() || ! isWide;\n\tconst sidebarTransition: SidebarTransition = {\n\t\ttype: 'tween',\n\t\tduration: disableSidebarMotion ? 0 : SIDEBAR_ANIMATION_DURATION,\n\t\tease: [ 0.6, 0, 0.4, 1 ],\n\t};\n\t// Width picks the starting panel, but only until the user opens or closes\n\t// it. After that their choice holds for the rest of the session: closing\n\t// the panel and then resizing — or crossing the breakpoint by rotating a\n\t// tablet — should not reopen something they just dismissed. `undefined`\n\t// until then, otherwise `null` for closed or the open panel's id.\n\tconst [ chosenPanel, setChosenPanel ] = useState< string | null >();\n\t// The tab the user picked, `null` until they pick one. Tracked separately\n\t// from `chosenPanel` because the two answer different questions: whether\n\t// the panel should be open, and which tab it should show.\n\tconst [ chosenTab, setChosenTab ] = useState< string | null >( null );\n\t// Below `small` a frame's header cannot fit the history cluster alongside\n\t// its own controls, so it moves that cluster elsewhere. The same width\n\t// undocks the panel, so this is `isWide` rather than a second query.\n\tconst layout: 'wide' | 'narrow' = isWide ? 'wide' : 'narrow';\n\tconst sourceMedia = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tid\n\t\t\t) as Media,\n\t\t[ id ]\n\t);\n\n\tconst { clearEntityRecordEdits, editEntityRecord, invalidateResolution } =\n\t\tuseDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\t// `PluginArea` drops a plugin whose render throws; tell the user.\n\tconst handlePluginError = useCallback(\n\t\t( name: string ) => {\n\t\t\tcreateErrorNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: plugin name */\n\t\t\t\t\t__(\n\t\t\t\t\t\t'The \"%s\" plugin has encountered an error and cannot be rendered.'\n\t\t\t\t\t),\n\t\t\t\t\tname\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar', context: MEDIA_EDITOR_NOTICES_CONTEXT }\n\t\t\t);\n\t\t},\n\t\t[ createErrorNotice ]\n\t);\n\n\tconst [ isDiscardDialogOpen, setIsDiscardDialogOpen ] = useState( false );\n\tconst [ isPlacementActive, setIsPlacementActive ] = useState( false );\n\tconst [ isCanvasGestureActive, setIsCanvasGestureActive ] =\n\t\tuseState( false );\n\t// Whether another attachment has replaced `id` in the image editor this\n\t// session (today, the original via \"Restore original image\"). Stays a\n\t// distinct flag (not derived from the image editor) so a bare replacement\n\t// counts as a change even though swapping the source resets the\n\t// image editor's own dirty baseline.\n\tconst [ isSourceReplaced, setIsSourceReplaced ] = useState( false );\n\tconst placementControlTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\n\tconst signalPlacementControlInteraction = useCallback( () => {\n\t\tsetIsPlacementActive( true );\n\t\tclearTimeout( placementControlTimerRef.current );\n\t\tplacementControlTimerRef.current = setTimeout( () => {\n\t\t\tsetIsPlacementActive( false );\n\t\t}, PLACEMENT_CONTROL_IDLE_MS );\n\t}, [] );\n\tconst handleCanvasGestureStart = useCallback( () => {\n\t\tsetIsCanvasGestureActive( true );\n\t}, [] );\n\tconst handleCanvasGestureEnd = useCallback( () => {\n\t\tsetIsCanvasGestureActive( false );\n\t}, [] );\n\tconst isCropInteractionActive = isPlacementActive || isCanvasGestureActive;\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( placementControlTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Restore-original: the edit root the edited attachment descends from,\n\t// exposed by the server as the root-level `edit_root` id on the\n\t// attachment (edit context, embeddable via the `wp:edit-root` link).\n\t// Fetch the original's record for the URL and natural dimensions the\n\t// image editor needs to seed itself.\n\tconst originalId: number | undefined = sourceMedia?.edit_root;\n\tconst originalRecord = useSelect(\n\t\t( select ) =>\n\t\t\toriginalId\n\t\t\t\t? ( select( coreStore ).getEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\toriginalId\n\t\t\t\t\t) as Media | undefined )\n\t\t\t\t: undefined,\n\t\t[ originalId ]\n\t);\n\tconst originalWidth = Number( originalRecord?.media_details?.width );\n\tconst originalHeight = Number( originalRecord?.media_details?.height );\n\tconst originalUrl = originalRecord?.source_url;\n\tconst originalSource =\n\t\toriginalId &&\n\t\toriginalRecord &&\n\t\ttypeof originalUrl === 'string' &&\n\t\toriginalUrl.length > 0 &&\n\t\tNumber.isFinite( originalWidth ) &&\n\t\toriginalWidth > 0 &&\n\t\tNumber.isFinite( originalHeight ) &&\n\t\toriginalHeight > 0\n\t\t\t? {\n\t\t\t\t\tid: originalId,\n\t\t\t\t\turl: originalUrl,\n\t\t\t\t\tmedia: originalRecord,\n\t\t\t\t}\n\t\t\t: undefined;\n\tconst canRestoreOriginal = !! originalSource;\n\tconst replacementSource =\n\t\tisSourceReplaced && originalSource\n\t\t\t? {\n\t\t\t\t\tid: originalSource.id,\n\t\t\t\t\turl: originalSource.url,\n\t\t\t\t\tmedia: originalSource.media,\n\t\t\t\t}\n\t\t\t: undefined;\n\t// Details and pending edits follow the attachment shown on the canvas.\n\t// Keep `sourceMedia` separate for the snackbar's previous attachment.\n\tconst activeId = replacementSource?.id ?? id;\n\tconst { media, hasEdits } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEditedEntityRecord,\n\t\t\t\tgetEntityRecord,\n\t\t\t\thasEditsForEntityRecord,\n\t\t\t} = select( coreStore );\n\t\t\t// Fetch embedded author and attached-post data for Details.\n\t\t\tgetEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tactiveId,\n\t\t\t\tATTACHMENT_EMBED_QUERY\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tmedia: getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tactiveId\n\t\t\t\t) as Media,\n\t\t\t\thasEdits: hasEditsForEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tactiveId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ activeId ]\n\t);\n\t// Refresh embedded data on opening or switching to the original.\n\tuseEffect( () => {\n\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t'postType',\n\t\t\t'attachment',\n\t\t\tactiveId,\n\t\t\tATTACHMENT_EMBED_QUERY,\n\t\t] );\n\t}, [ activeId, invalidateResolution ] );\n\tconst handleRestoreOriginal = useCallback( () => {\n\t\t// Restoring discards every pending edit, as the menu item says, so\n\t\t// nothing staged against the attachment being replaced reaches a save.\n\t\tclearEntityRecordEdits( 'postType', 'attachment', id );\n\t\tif ( onEditOriginal && originalId ) {\n\t\t\tonEditOriginal( originalId );\n\t\t\treturn;\n\t\t}\n\t\tsetIsSourceReplaced( true );\n\t}, [ clearEntityRecordEdits, id, onEditOriginal, originalId ] );\n\n\t// A bare replacement has no image editor change, so OR the flag in explicitly.\n\t// Nothing saves named edits (`session.edits`), so `hasOutputEdits` leaves\n\t// them out: counting them would enable Save for a change it then drops.\n\tconst hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;\n\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;\n\tconst isImage = !! media && mediaType === 'image';\n\n\t// Below `small` the panel covers the canvas, so open on Details rather\n\t// than a panel that needs the canvas in view. If no tab matches\n\t// `defaultPanel`, the sidebar shows Details (see `activeTab` below).\n\tconst currentTab = chosenTab ?? ( isWide ? defaultPanel : DETAILS_PANEL );\n\t// `null` when nothing is open, otherwise the open panel's id. Until the\n\t// user opens or closes the panel, follow the breakpoint: dragging a window\n\t// narrow hands the canvas the full width instead of leaving a panel\n\t// wedged beside it.\n\tlet activePanel = chosenPanel;\n\tif ( activePanel === undefined ) {\n\t\tactivePanel = isWide ? currentTab : null;\n\t}\n\t// Switching tabs says nothing about whether the panel should be open, so\n\t// it leaves `chosenPanel` unset: picking Details on a wide screen and then\n\t// dragging the window narrow should still hand the canvas the full width.\n\tconst selectPanel = useCallback( ( panel: string ) => {\n\t\tsetChosenTab( panel );\n\t\tsetChosenPanel( ( chosen ) =>\n\t\t\tchosen === undefined ? chosen : panel\n\t\t);\n\t}, [] );\n\tconst togglePanel = useCallback( () => {\n\t\tsetChosenPanel( activePanel ? null : currentTab );\n\t}, [ activePanel, currentTab ] );\n\tconst { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {\n\t\tsession,\n\t\tid,\n\t\tisImage,\n\t\tmedia: sourceMedia,\n\t\tonSaved,\n\t\treplacementSource,\n\t} );\n\n\tconst handleChange = ( updates: Partial< Media > ) => {\n\t\t// A save reads the pending edits once and then waits. An edit\n\t\t// arriving after that read misses the request, and a crop save\n\t\t// then clears the edits for this id, so it would be lost rather\n\t\t// than merely late. It would also land on the attachment being\n\t\t// replaced, not the new one the modal moves to.\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\teditEntityRecord( 'postType', 'attachment', activeId, updates );\n\t};\n\n\tconst discardAndClose = () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tclearEntityRecordEdits( 'postType', 'attachment', activeId );\n\t\tsetIsSourceReplaced( false );\n\t\tonClose?.();\n\t};\n\n\tconst handleRequestClose = () => {\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( hasChanges ) {\n\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\treturn;\n\t\t}\n\t\tdiscardAndClose();\n\t};\n\n\tconst handleKeyDown = withIgnoreIMEEvents(\n\t\t( event: ReactKeyboardEvent< HTMLElement > ) => {\n\t\t\tconst isUndoShortcut = isKeyboardEvent.primary( event, 'z' );\n\t\t\tconst isRedoShortcut =\n\t\t\t\tisKeyboardEvent.primaryShift( event, 'z' ) ||\n\t\t\t\t( ! isAppleOS() && isKeyboardEvent.primary( event, 'y' ) );\n\t\t\tif ( ( isUndoShortcut || isRedoShortcut ) && isImage ) {\n\t\t\t\tconst target = event.target as HTMLElement;\n\t\t\t\tconst isMetadataField =\n\t\t\t\t\t( target.tagName === 'INPUT' ||\n\t\t\t\t\t\ttarget.tagName === 'TEXTAREA' ||\n\t\t\t\t\t\ttarget.isContentEditable ) &&\n\t\t\t\t\t! target.closest( `[${ CROP_CONTROL_ATTR }]` );\n\t\t\t\tif ( ! isMetadataField ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tif ( isCropInteractionActive || isSaving ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif ( isRedoShortcut ) {\n\t\t\t\t\t\tsession.redo();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsession.undo();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( shouldCloseOnEsc ) {\n\t\t\t\tif ( event.code !== 'Escape' && event.key !== 'Escape' ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif ( isSaving ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif ( hasChanges ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t);\n\n\tconst snackbar = (\n\t\t<SnackbarNotices\n\t\t\tclassName={ noticesClassName }\n\t\t\tcontext={ MEDIA_EDITOR_NOTICES_CONTEXT }\n\t\t/>\n\t);\n\n\t// Below `small` the panel is full screen, so an open one replaces the\n\t// canvas and these never share the screen with the Crop panel's copies:\n\t// this row is what reaches rotate/flip/zoom while the panel is closed,\n\t// with aspect ratio joining them as a dropdown. From `small` up the Crop\n\t// panel docks beside the canvas and carries them instead.\n\tconst imageControls =\n\t\tisImage && ! isWide ? (\n\t\t\t<MediaEditorImageControls\n\t\t\t\tshowAspectRatioControl\n\t\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t/>\n\t\t) : null;\n\n\tconst { panels, contextValue: panelsContextValue } = useMediaEditorPanels();\n\tconst availableTabs: MediaEditorTab[] = panels\n\t\t.filter(\n\t\t\t( panel ) =>\n\t\t\t\t! panel.mediaTypes || panel.mediaTypes.includes( mediaType )\n\t\t)\n\t\t.map( ( panel ) => ( {\n\t\t\tid: panel.name,\n\t\t\ttitle: panel.title,\n\t\t\trender: () => (\n\t\t\t\t<Slot\n\t\t\t\t\tbubblesVirtually\n\t\t\t\t\tname={ getPanelSlotName( panel.name ) }\n\t\t\t\t\tfillProps={ { disabled: isSaving } }\n\t\t\t\t/>\n\t\t\t),\n\t\t} ) );\n\t// Put the default panel first and keep the others in order.\n\tconst defaultTab = availableTabs.find( ( tab ) => tab.id === defaultPanel );\n\tconst tabs = defaultTab\n\t\t? [\n\t\t\t\tdefaultTab,\n\t\t\t\t...availableTabs.filter( ( tab ) => tab !== defaultTab ),\n\t\t\t]\n\t\t: availableTabs;\n\n\tconst ruler = isImage ? (\n\t\t<MediaEditorFineRotation\n\t\t\tonPlacementControlInteraction={ signalPlacementControlInteraction }\n\t\t\tdisabled={ isSaving }\n\t\t/>\n\t) : null;\n\n\tconst children = (\n\t\t<>\n\t\t\t<div className=\"media-editor\">\n\t\t\t\t{ ! media ? (\n\t\t\t\t\t<div className=\"media-editor__loading\">\n\t\t\t\t\t\t<WCSpinner />\n\t\t\t\t\t</div>\n\t\t\t\t) : (\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ clsx( 'media-editor__body', {\n\t\t\t\t\t\t\t'has-panel-open': !! activePanel,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<NavigableRegion\n\t\t\t\t\t\t\tclassName=\"media-editor__content\"\n\t\t\t\t\t\t\tariaLabel={\n\t\t\t\t\t\t\t\tisImage\n\t\t\t\t\t\t\t\t\t? __( 'Image editor' )\n\t\t\t\t\t\t\t\t\t: __( 'Media preview' )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div className=\"media-editor__canvas-area\">\n\t\t\t\t\t\t\t\t{ isImage ? (\n\t\t\t\t\t\t\t\t\t<MediaEditorCanvas\n\t\t\t\t\t\t\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\t\t\t\t\t\t\tonGestureStart={\n\t\t\t\t\t\t\t\t\t\t\thandleCanvasGestureStart\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonGestureEnd={ handleCanvasGestureEnd }\n\t\t\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t<MediaPreview />\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t{ isImage && (\n\t\t\t\t\t\t\t\t<div className=\"media-editor__canvas-toolbar\">\n\t\t\t\t\t\t\t\t\t{ ruler }\n\t\t\t\t\t\t\t\t\t{ imageControls }\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</NavigableRegion>\n\t\t\t\t\t\t<AnimatePresence\n\t\t\t\t\t\t\tinitial={ false }\n\t\t\t\t\t\t\tcustom={ sidebarTransition }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ !! activePanel && (\n\t\t\t\t\t\t\t\t<motion.div\n\t\t\t\t\t\t\t\t\tclassName=\"media-editor__sidebar-container\"\n\t\t\t\t\t\t\t\t\tvariants={ sidebarVariants }\n\t\t\t\t\t\t\t\t\tinitial=\"closed\"\n\t\t\t\t\t\t\t\t\tanimate=\"open\"\n\t\t\t\t\t\t\t\t\texit=\"closed\"\n\t\t\t\t\t\t\t\t\ttransition={ sidebarTransition }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ /* Panels announce their tabs after the\n\t\t\t\t\t\t\t\t\t first render. Waiting for them outside\n\t\t\t\t\t\t\t\t\t this container would slide it in on\n\t\t\t\t\t\t\t\t\t every open. */ }\n\t\t\t\t\t\t\t\t\t{ tabs.length > 0 && (\n\t\t\t\t\t\t\t\t\t\t<MediaEditorSidebar\n\t\t\t\t\t\t\t\t\t\t\ttabs={ tabs }\n\t\t\t\t\t\t\t\t\t\t\t// Swapping the edited media can drop the\n\t\t\t\t\t\t\t\t\t\t\t// Crop tab out from under an open panel —\n\t\t\t\t\t\t\t\t\t\t\t// saving a crop moves the editor to a new\n\t\t\t\t\t\t\t\t\t\t\t// id, which may resolve as non-image.\n\t\t\t\t\t\t\t\t\t\t\t// Fall back rather than hand `Tabs.Root`\n\t\t\t\t\t\t\t\t\t\t\t// a value no tab matches.\n\t\t\t\t\t\t\t\t\t\t\tactiveTab={\n\t\t\t\t\t\t\t\t\t\t\t\ttabs.some(\n\t\t\t\t\t\t\t\t\t\t\t\t\t( tab ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttab.id === activePanel\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t\t? activePanel\n\t\t\t\t\t\t\t\t\t\t\t\t\t: DETAILS_PANEL\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonSelectTab={ selectPanel }\n\t\t\t\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</motion.div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</AnimatePresence>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ isDiscardDialogOpen }\n\t\t\t\tconfirmButtonText={ __( 'Discard' ) }\n\t\t\t\tcancelButtonText={ __( 'Keep editing' ) }\n\t\t\t\tonCancel={ () => setIsDiscardDialogOpen( false ) }\n\t\t\t\tonConfirm={ () => {\n\t\t\t\t\tsetIsDiscardDialogOpen( false );\n\t\t\t\t\tdiscardAndClose();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ __(\n\t\t\t\t\t'Are you sure you want to discard your unsaved changes?'\n\t\t\t\t) }\n\t\t\t</ConfirmDialog>\n\t\t\t{ noticesPortalElement\n\t\t\t\t? createPortal( snackbar, noticesPortalElement )\n\t\t\t\t: snackbar }\n\t\t</>\n\t);\n\n\t// Rebuilt each render, like the elements it replaces: consumers re-render\n\t// as they always did, but the cluster component types stay stable.\n\tconst contextValue: MediaEditorFrameContextValue = {\n\t\tisImage,\n\t\tisSaving,\n\t\thasMedia: !! media,\n\t\thasChanges,\n\t\t// Saving freezes the whole edit surface: `save()` reads the\n\t\t// modifiers once and then awaits, so anything changed after that\n\t\t// would be silently dropped when the save resolves.\n\t\tisUndoRedoDisabled: isCropInteractionActive || isSaving,\n\t\taspectRatioPresets,\n\t\tisWide,\n\t\tactivePanel,\n\t\tonTogglePanel: togglePanel,\n\t\tonCancel: handleRequestClose,\n\t\tonSave: saveMediaEditor,\n\t\tcanRestoreOriginal,\n\t\tisSourceReplaced,\n\t\topensOriginal: !! onEditOriginal,\n\t\tonRestoreOriginal: handleRestoreOriginal,\n\t};\n\n\treturn (\n\t\t<MediaEditorFrameContext.Provider value={ contextValue }>\n\t\t\t{ renderFrame( {\n\t\t\t\tchildren: (\n\t\t\t\t\t<MediaEditorProvider\n\t\t\t\t\t\tvalue={ media ?? undefined }\n\t\t\t\t\t\tonChange={ handleChange }\n\t\t\t\t\t\tsettings={ {\n\t\t\t\t\t\t\t// Disable the fields while saving, so the guard in\n\t\t\t\t\t\t\t// `handleChange` is not silently swallowing typing.\n\t\t\t\t\t\t\t// `readOnly` would swap the field's layout mid-save;\n\t\t\t\t\t\t\t// disabled keeps it in place and greys it out.\n\t\t\t\t\t\t\tfields: isSaving\n\t\t\t\t\t\t\t\t? fields.map( ( field ) => ( {\n\t\t\t\t\t\t\t\t\t\t...field,\n\t\t\t\t\t\t\t\t\t\tisDisabled: true,\n\t\t\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t\t\t: fields,\n\t\t\t\t\t\t\tform,\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<SlotFillProvider>\n\t\t\t\t\t\t\t<MediaEditorPanelsProvider\n\t\t\t\t\t\t\t\tvalue={ panelsContextValue }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ /* Inside the session and `MediaEditorProvider`, so\n\t\t\t\t\t\t\t\t panel content can read both. */ }\n\t\t\t\t\t\t\t\t<MediaEditorPanel\n\t\t\t\t\t\t\t\t\tname={ CROP_PANEL }\n\t\t\t\t\t\t\t\t\ttitle={ __( 'Crop' ) }\n\t\t\t\t\t\t\t\t\tmediaTypes={ CROP_MEDIA_TYPES }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ ( { disabled } ) => (\n\t\t\t\t\t\t\t\t\t\t<CropPanelContent\n\t\t\t\t\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</MediaEditorPanel>\n\t\t\t\t\t\t\t\t<MediaEditorPanel\n\t\t\t\t\t\t\t\t\tname={ DETAILS_PANEL }\n\t\t\t\t\t\t\t\t\ttitle={ __( 'Details' ) }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<MediaForm />\n\t\t\t\t\t\t\t\t</MediaEditorPanel>\n\t\t\t\t\t\t\t\t<PluginArea\n\t\t\t\t\t\t\t\t\tscope={ MEDIA_EDITOR_PLUGIN_SCOPE }\n\t\t\t\t\t\t\t\t\tonError={ handlePluginError }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t</MediaEditorPanelsProvider>\n\t\t\t\t\t\t</SlotFillProvider>\n\t\t\t\t\t</MediaEditorProvider>\n\t\t\t\t),\n\t\t\t\tisImage,\n\t\t\t\tlayout,\n\t\t\t\tonRequestClose: handleRequestClose,\n\t\t\t\tonKeyDown: handleKeyDown,\n\t\t\t\tshouldCloseOnClickOutside: ! hasChanges && ! isSaving,\n\t\t\t\tisSaving,\n\t\t\t\thasChanges,\n\t\t\t\thasMedia: !! media,\n\t\t\t} ) }\n\t\t</MediaEditorFrameContext.Provider>\n\t);\n}\n\nexport function MediaEditor( props: MediaEditorProps ) {\n\treturn (\n\t\t<MediaEditorStateProvider key={ props.id }>\n\t\t\t<MediaEditorContent { ...props } />\n\t\t</MediaEditorStateProvider>\n\t);\n}\n\n// Attached to `MediaEditor` so frames import and arrange them, the way\n// `DataViewsPicker` exposes its own sub-components. They read what they need\n// from context, so a frame only chooses where they go and how they look.\nMediaEditor.HeaderActions = HeaderActions;\nMediaEditor.PanelToggle = PanelToggle;\nMediaEditor.MoreMenu = MoreMenu;\nMediaEditor.HistoryActions = HistoryActions;\nMediaEditor.SaveActions = SaveActions;\n\nexport default MediaEditor;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,MAAM,yBAAyB,EAAE,QAAQ,wBAAwB;AAEjE,MAAM,4BAA4B;;;;;;;;AAS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AEe,CAAA;MAClB,oBAAC,kBAAD;OACC,MAAO;OACP,OAAQ,GAAI,SAAU;OAEtB,UAAA,oBAAC,WAAD,CAAY,CAAA;MACK,CAAA;MAClB,oBAAC,YAAD;OACC,OAAQ;OACR,SAAU;MACV,CAAA;MACC;KACwB;IACV,CAAA,EAAA,CAAA;GACE,CAAA;GAEtB;GACA;GACA,gBAAgB;GAChB,WAAW;GACX,2BAA2B,CAAE,cAAc,CAAE;GAC7C;GACA;GACA,UAAU,CAAC,CAAE;EACd,CAAE;CAC+B,CAAA;AAEpC;AAEA,SAAgB,YAAa,OAA0B;CACtD,OACC,oBAAC,0BAAD,EAAA,UACC,oBAAC,oBAAD,EAAoB,GAAK,MAAS,CAAA,EACT,GAFM,MAAM,EAEZ;AAE5B;AAKA,YAAY,gBAAgB;AAC5B,YAAY,cAAc;AAC1B,YAAY,WAAW;AACvB,YAAY,iBAAiB;AAC7B,YAAY,cAAc"}
|
|
@@ -91,7 +91,15 @@ function useSaveMediaEditor({ session, id, isImage, media, onSaved, replacementS
|
|
|
91
91
|
}
|
|
92
92
|
} catch (error) {
|
|
93
93
|
const message = error instanceof Error ? error.message : error?.message ?? __("An unknown error occurred.");
|
|
94
|
-
createErrorNotice(isImage ? sprintf(
|
|
94
|
+
createErrorNotice(isImage ? sprintf(
|
|
95
|
+
/** translators: %s: Error message. */
|
|
96
|
+
__("Could not save image. %s"),
|
|
97
|
+
message
|
|
98
|
+
) : sprintf(
|
|
99
|
+
/** translators: %s: Error message. */
|
|
100
|
+
__("Could not save media. %s"),
|
|
101
|
+
message
|
|
102
|
+
), {
|
|
95
103
|
type: "snackbar",
|
|
96
104
|
context: MEDIA_EDITOR_NOTICES_CONTEXT
|
|
97
105
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-save-media-editor.mjs","names":["coreStore","noticesStore"],"sources":["../../../src/components/media-editor/use-save-media-editor.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getImageEdit, mapImageEdit } from '@wordpress/image-editor';\nimport type { Media } from '../media-editor-provider';\nimport type { MediaEditorSession } from '../../state';\n\n/**\n * A single modifier in the Core REST `/edit` payload. Order is\n * significant — the server applies modifiers sequentially (see\n * `WP_REST_Attachments_Controller::edit_media_item`).\n *\n * Shape/units:\n * - `flip`: booleans per axis.\n * - `rotate`: `angle` in degrees, clockwise-positive (matches the\n * image editor's own convention; Core negates it internally for\n * `WP_Image_Editor::rotate`, which is counterclockwise-positive).\n * - `crop`: percentages (0–100) of the image's dimensions **at the\n * moment the crop is applied**. Because modifiers are applied in\n * order, after a preceding `rotate` the server's\n * `WP_Image_Editor::get_size()` reports the full post-rotate AABB,\n * so the percentages are of that AABB. Origin is top-left.\n */\ntype Modifier =\n\t| {\n\t\t\ttype: 'flip';\n\t\t\targs: { flip: { horizontal: boolean; vertical: boolean } };\n\t }\n\t| { type: 'rotate'; args: { angle: number } }\n\t| {\n\t\t\ttype: 'crop';\n\t\t\targs: { left: number; top: number; width: number; height: number };\n\t };\n\n// Details-tab edits are bundled into transformed `/edit` requests. Core's\n// endpoint only accepts this whitelist.\nconst METADATA_EDIT_KEYS = [\n\t'title',\n\t'caption',\n\t'description',\n\t'alt_text',\n\t'post',\n] as const;\n\n// Scope media editor snackbars so they don't leak into the host editor/page.\nexport const MEDIA_EDITOR_NOTICES_CONTEXT = 'media-editor';\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n\tprevious?: {\n\t\tid: number;\n\t\turl?: string;\n\t};\n}\n\ninterface UseSaveMediaEditorArgs {\n\tsession: MediaEditorSession;\n\tid: number;\n\tisImage: boolean;\n\tmedia?: Media | null;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/**\n\t * When another attachment has replaced the edited one (today, the original\n\t * via \"Restore original image\"), the save targets the replacement:\n\t * - with no fresh crop, the block is repointed at the replacement and any\n\t * changed details are saved there (no `/edit`);\n\t * - with a fresh crop, `/edit` runs against the replacement's id and url.\n\t */\n\treplacementSource?: {\n\t\tid: number;\n\t\turl?: string;\n\t\tmedia: Media;\n\t};\n}\n\ninterface UseSaveMediaEditorReturn {\n\tisSaving: boolean;\n\tsave: () => Promise< void >;\n}\n\nfunction getCropModifiers( session: MediaEditorSession ): Modifier[] {\n\tif ( ! session.hasOutputEdits ) {\n\t\treturn [];\n\t}\n\tconst edit = getImageEdit( session.imageEditor.state );\n\tif ( ! edit ) {\n\t\treturn [];\n\t}\n\n\t// Core applies modifiers in the order they arrive.\n\treturn mapImageEdit< Modifier >( edit, {\n\t\tflip: ( flip ) => ( { type: 'flip', args: { flip } } ),\n\t\trotation: ( angle ) => ( { type: 'rotate', args: { angle } } ),\n\t\tcrop: ( { x, y, width, height } ) => ( {\n\t\t\ttype: 'crop',\n\t\t\targs: {\n\t\t\t\tleft: x * 100,\n\t\t\t\ttop: y * 100,\n\t\t\t\twidth: width * 100,\n\t\t\t\theight: height * 100,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\nfunction getMetadataEdits(\n\tpendingEdits: PendingMetadataEdits,\n\tmedia?: Media | null\n): Record< string, unknown > {\n\tconst metadataEdits: Record< string, unknown > = {};\n\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t}\n\t}\n\t// The `/edit` endpoint creates a new attachment for the crop and doesn't\n\t// inherit `post_parent` from the source (unlike title/caption/etc.), so\n\t// carry the existing value across when the user hasn't explicitly edited\n\t// it. Use a defined-check so an explicit `0` (unattached) is preserved.\n\tif ( ! ( 'post' in metadataEdits ) && media?.post !== undefined ) {\n\t\tmetadataEdits.post = media.post;\n\t}\n\treturn metadataEdits;\n}\n\nexport function useSaveMediaEditor( {\n\tsession,\n\tid,\n\tisImage,\n\tmedia,\n\tonSaved,\n\treplacementSource,\n}: UseSaveMediaEditorArgs ): UseSaveMediaEditorReturn {\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst save = useCallback( async () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\t\t\tconst modifiers = getCropModifiers( session );\n\n\t\t\t// A replacement retargets the save; without one the current\n\t\t\t// attachment is both source and target as before.\n\t\t\tconst targetId = replacementSource?.id ?? id;\n\t\t\tconst targetUrl = replacementSource?.url ?? media?.source_url;\n\t\t\tconst targetMedia = replacementSource?.media ?? media;\n\n\t\t\t// Both a fresh crop and a bare replacement swap the block's image,\n\t\t\t// so both offer an Undo back to the current attachment.\n\t\t\tconst previous =\n\t\t\t\t( modifiers.length > 0 || replacementSource ) && media\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\turl: media.source_url,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\n\n\t\t\tif ( modifiers.length > 0 ) {\n\t\t\t\tconst pendingEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.getEntityRecordNonTransientEdits(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t) as PendingMetadataEdits;\n\t\t\t\tconst metadataEdits = getMetadataEdits(\n\t\t\t\t\tpendingEdits,\n\t\t\t\t\ttargetMedia\n\t\t\t\t);\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ targetId }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: targetUrl,\n\t\t\t\t\t\tmodifiers,\n\t\t\t\t\t\t...metadataEdits,\n\t\t\t\t\t},\n\t\t\t\t} ) ) as Media;\n\n\t\t\t\tif ( saved ) {\n\t\t\t\t\treceiveEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tsaved,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\treplacementSource &&\n\t\t\t\t! registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// A bare replacement only repoints the block. The replacement\n\t\t\t\t// already exists and has no changes to persist.\n\t\t\t\tsaved = replacementSource.media;\n\t\t\t} else {\n\t\t\t\tsaved = ( await saveEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\ttargetId,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? targetMedia ) as Media | null;\n\n\t\t\tif ( next && next.id !== targetId ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', targetId );\n\t\t\t}\n\n\t\t\tif ( next && next.id ) {\n\t\t\t\tif ( next.id === id ) {\n\t\t\t\t\tsession.reset();\n\t\t\t\t}\n\t\t\t\tonSaved?.( {\n\t\t\t\t\tid: next.id,\n\t\t\t\t\turl: next.source_url,\n\t\t\t\t\tmedia: next,\n\t\t\t\t\tprevious,\n\t\t\t\t} );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tconst message =\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: ( ( error as { message?: string } )?.message ??\n\t\t\t\t\t\t__( 'An unknown error occurred.' ) );\n\t\t\tcreateErrorNotice(\n\t\t\t\tisImage\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save image. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t)\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save media. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tcontext: MEDIA_EDITOR_NOTICES_CONTEXT,\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t}, [\n\t\tclearEntityRecordEdits,\n\t\tcreateErrorNotice,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t\treceiveEntityRecords,\n\t\tregistry,\n\t\tremoveAllNotices,\n\t\treplacementSource,\n\t\tsaveEditedEntityRecord,\n\t\tsession,\n\t] );\n\n\treturn { isSaving, save };\n}\n"],"mappings":";;;;;;;;AAuCA,MAAM,qBAAqB;CAC1B;CACA;CACA;CACA;CACA;AACD;AAGA,MAAa,+BAA+B;AAuC5C,SAAS,iBAAkB,SAA0C;CACpE,IAAK,CAAE,QAAQ,gBACd,OAAO,CAAC;CAET,MAAM,OAAO,aAAc,QAAQ,YAAY,KAAM;CACrD,IAAK,CAAE,MACN,OAAO,CAAC;CAIT,OAAO,aAA0B,MAAM;EACtC,OAAQ,UAAY;GAAE,MAAM;GAAQ,MAAM,EAAE,KAAK;EAAE;EACnD,WAAY,WAAa;GAAE,MAAM;GAAU,MAAM,EAAE,MAAM;EAAE;EAC3D,OAAQ,EAAE,GAAG,GAAG,OAAO,cAAg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IACN,qBACA,CAAE,SACA,OAAQA,KAAU,CAAC,CACnB,wBACA,YACA,cACA,QACD,GAID,QAAQ,kBAAkB;SAE1B,QAAU,MAAM,uBACf,YACA,cACA,UACA,EAAE,cAAc,KAAK,CACtB;IAGD,MAAM,OAAS,SAAS;IAExB,IAAK,QAAQ,KAAK,OAAO,UACxB,uBAAwB,YAAY,cAAc,QAAS;IAG5D,IAAK,QAAQ,KAAK,IAAK;KACtB,IAAK,KAAK,OAAO,IAChB,QAAQ,MAAM;KAEf,UAAW;MACV,IAAI,KAAK;MACT,KAAK,KAAK;MACV,OAAO;MACP;KACD,CAAE;IACH;GACD,SAAU,OAAQ;IACjB,MAAM,UACL,iBAAiB,QACd,MAAM,UACF,OAAiC,WACtC,GAAI,4BAA6B;IACpC,kBACC,UACG,QAEA,GAAI,0BAA2B,GAC/B,OACD,IACC,QAEA,GAAI,0BAA2B,GAC/B,OACD,GACF;KACC,MAAM;KACN,SAAS;IACV,CACD;GACD,UAAU;IACT,YAAa,KAAM;GACpB;EACD,GAAG;GACF;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD,CAEsB;CAAE;AACzB"}
|
|
1
|
+
{"version":3,"file":"use-save-media-editor.mjs","names":["coreStore","noticesStore"],"sources":["../../../src/components/media-editor/use-save-media-editor.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getImageEdit, mapImageEdit } from '@wordpress/image-editor';\nimport type { Media } from '../media-editor-provider';\nimport type { MediaEditorSession } from '../../state';\n\n/**\n * A single modifier in the Core REST `/edit` payload. Order is\n * significant — the server applies modifiers sequentially (see\n * `WP_REST_Attachments_Controller::edit_media_item`).\n *\n * Shape/units:\n * - `flip`: booleans per axis.\n * - `rotate`: `angle` in degrees, clockwise-positive (matches the\n * image editor's own convention; Core negates it internally for\n * `WP_Image_Editor::rotate`, which is counterclockwise-positive).\n * - `crop`: percentages (0–100) of the image's dimensions **at the\n * moment the crop is applied**. Because modifiers are applied in\n * order, after a preceding `rotate` the server's\n * `WP_Image_Editor::get_size()` reports the full post-rotate AABB,\n * so the percentages are of that AABB. Origin is top-left.\n */\ntype Modifier =\n\t| {\n\t\t\ttype: 'flip';\n\t\t\targs: { flip: { horizontal: boolean; vertical: boolean } };\n\t }\n\t| { type: 'rotate'; args: { angle: number } }\n\t| {\n\t\t\ttype: 'crop';\n\t\t\targs: { left: number; top: number; width: number; height: number };\n\t };\n\n// Details-tab edits are bundled into transformed `/edit` requests. Core's\n// endpoint only accepts this whitelist.\nconst METADATA_EDIT_KEYS = [\n\t'title',\n\t'caption',\n\t'description',\n\t'alt_text',\n\t'post',\n] as const;\n\n// Scope media editor snackbars so they don't leak into the host editor/page.\nexport const MEDIA_EDITOR_NOTICES_CONTEXT = 'media-editor';\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n\tprevious?: {\n\t\tid: number;\n\t\turl?: string;\n\t};\n}\n\ninterface UseSaveMediaEditorArgs {\n\tsession: MediaEditorSession;\n\tid: number;\n\tisImage: boolean;\n\tmedia?: Media | null;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/**\n\t * When another attachment has replaced the edited one (today, the original\n\t * via \"Restore original image\"), the save targets the replacement:\n\t * - with no fresh crop, the block is repointed at the replacement and any\n\t * changed details are saved there (no `/edit`);\n\t * - with a fresh crop, `/edit` runs against the replacement's id and url.\n\t */\n\treplacementSource?: {\n\t\tid: number;\n\t\turl?: string;\n\t\tmedia: Media;\n\t};\n}\n\ninterface UseSaveMediaEditorReturn {\n\tisSaving: boolean;\n\tsave: () => Promise< void >;\n}\n\nfunction getCropModifiers( session: MediaEditorSession ): Modifier[] {\n\tif ( ! session.hasOutputEdits ) {\n\t\treturn [];\n\t}\n\tconst edit = getImageEdit( session.imageEditor.state );\n\tif ( ! edit ) {\n\t\treturn [];\n\t}\n\n\t// Core applies modifiers in the order they arrive.\n\treturn mapImageEdit< Modifier >( edit, {\n\t\tflip: ( flip ) => ( { type: 'flip', args: { flip } } ),\n\t\trotation: ( angle ) => ( { type: 'rotate', args: { angle } } ),\n\t\tcrop: ( { x, y, width, height } ) => ( {\n\t\t\ttype: 'crop',\n\t\t\targs: {\n\t\t\t\tleft: x * 100,\n\t\t\t\ttop: y * 100,\n\t\t\t\twidth: width * 100,\n\t\t\t\theight: height * 100,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\nfunction getMetadataEdits(\n\tpendingEdits: PendingMetadataEdits,\n\tmedia?: Media | null\n): Record< string, unknown > {\n\tconst metadataEdits: Record< string, unknown > = {};\n\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t}\n\t}\n\t// The `/edit` endpoint creates a new attachment for the crop and doesn't\n\t// inherit `post_parent` from the source (unlike title/caption/etc.), so\n\t// carry the existing value across when the user hasn't explicitly edited\n\t// it. Use a defined-check so an explicit `0` (unattached) is preserved.\n\tif ( ! ( 'post' in metadataEdits ) && media?.post !== undefined ) {\n\t\tmetadataEdits.post = media.post;\n\t}\n\treturn metadataEdits;\n}\n\nexport function useSaveMediaEditor( {\n\tsession,\n\tid,\n\tisImage,\n\tmedia,\n\tonSaved,\n\treplacementSource,\n}: UseSaveMediaEditorArgs ): UseSaveMediaEditorReturn {\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst save = useCallback( async () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\t\t\tconst modifiers = getCropModifiers( session );\n\n\t\t\t// A replacement retargets the save; without one the current\n\t\t\t// attachment is both source and target as before.\n\t\t\tconst targetId = replacementSource?.id ?? id;\n\t\t\tconst targetUrl = replacementSource?.url ?? media?.source_url;\n\t\t\tconst targetMedia = replacementSource?.media ?? media;\n\n\t\t\t// Both a fresh crop and a bare replacement swap the block's image,\n\t\t\t// so both offer an Undo back to the current attachment.\n\t\t\tconst previous =\n\t\t\t\t( modifiers.length > 0 || replacementSource ) && media\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\turl: media.source_url,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\n\n\t\t\tif ( modifiers.length > 0 ) {\n\t\t\t\tconst pendingEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.getEntityRecordNonTransientEdits(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t) as PendingMetadataEdits;\n\t\t\t\tconst metadataEdits = getMetadataEdits(\n\t\t\t\t\tpendingEdits,\n\t\t\t\t\ttargetMedia\n\t\t\t\t);\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ targetId }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: targetUrl,\n\t\t\t\t\t\tmodifiers,\n\t\t\t\t\t\t...metadataEdits,\n\t\t\t\t\t},\n\t\t\t\t} ) ) as Media;\n\n\t\t\t\tif ( saved ) {\n\t\t\t\t\treceiveEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tsaved,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\treplacementSource &&\n\t\t\t\t! registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// A bare replacement only repoints the block. The replacement\n\t\t\t\t// already exists and has no changes to persist.\n\t\t\t\tsaved = replacementSource.media;\n\t\t\t} else {\n\t\t\t\tsaved = ( await saveEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\ttargetId,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? targetMedia ) as Media | null;\n\n\t\t\tif ( next && next.id !== targetId ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', targetId );\n\t\t\t}\n\n\t\t\tif ( next && next.id ) {\n\t\t\t\tif ( next.id === id ) {\n\t\t\t\t\tsession.reset();\n\t\t\t\t}\n\t\t\t\tonSaved?.( {\n\t\t\t\t\tid: next.id,\n\t\t\t\t\turl: next.source_url,\n\t\t\t\t\tmedia: next,\n\t\t\t\t\tprevious,\n\t\t\t\t} );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tconst message =\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: ( ( error as { message?: string } )?.message ??\n\t\t\t\t\t\t__( 'An unknown error occurred.' ) );\n\t\t\tcreateErrorNotice(\n\t\t\t\tisImage\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save image. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t)\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save media. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tcontext: MEDIA_EDITOR_NOTICES_CONTEXT,\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t}, [\n\t\tclearEntityRecordEdits,\n\t\tcreateErrorNotice,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t\treceiveEntityRecords,\n\t\tregistry,\n\t\tremoveAllNotices,\n\t\treplacementSource,\n\t\tsaveEditedEntityRecord,\n\t\tsession,\n\t] );\n\n\treturn { isSaving, save };\n}\n"],"mappings":";;;;;;;;AAuCA,MAAM,qBAAqB;CAC1B;CACA;CACA;CACA;CACA;AACD;AAGA,MAAa,+BAA+B;AAuC5C,SAAS,iBAAkB,SAA0C;CACpE,IAAK,CAAE,QAAQ,gBACd,OAAO,CAAC;CAET,MAAM,OAAO,aAAc,QAAQ,YAAY,KAAM;CACrD,IAAK,CAAE,MACN,OAAO,CAAC;CAIT,OAAO,aAA0B,MAAM;EACtC,OAAQ,UAAY;GAAE,MAAM;GAAQ,MAAM,EAAE,KAAK;EAAE;EACnD,WAAY,WAAa;GAAE,MAAM;GAAU,MAAM,EAAE,MAAM;EAAE;EAC3D,OAAQ,EAAE,GAAG,GAAG,OAAO,cAAgB;GACtC,MAAM;GACN,MAAM;IACL,MAAM,IAAI;IACV,KAAK,IAAI;IACT,OAAO,QAAQ;IACf,QAAQ,SAAS;GAClB;EACD;CACD,CAAE;AACH;AAEA,SAAS,iBACR,cACA,OAC4B;CAC5B,MAAM,gBAA2C,CAAC;CAClD,KAAM,MAAM,OAAO,oBAClB,IAAK,gBAAgB,OAAO,cAC3B,cAAe,OAAQ,aAAc;CAOvC,IAAK,EAAI,UAAU,kBAAmB,OAAO,SAAS,KAAA,GACrD,cAAc,OAAO,MAAM;CAE5B,OAAO;AACR;AAEA,SAAg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ACV,OAAO;MACP;KACD,CAAE;IACH;GACD,SAAU,OAAQ;IACjB,MAAM,UACL,iBAAiB,QACd,MAAM,UACF,OAAiC,WACtC,GAAI,4BAA6B;IACpC,kBACC,UACG;;KAEA,GAAI,0BAA2B;KAC/B;IACD,IACC;;KAEA,GAAI,0BAA2B;KAC/B;IACD,GACF;KACC,MAAM;KACN,SAAS;IACV,CACD;GACD,UAAU;IACT,YAAa,KAAM;GACpB;EACD,GAAG;GACF;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD,CAEmB;CAAK;AACzB"}
|
|
@@ -2,6 +2,7 @@ import { Modal } from "@wordpress/components";
|
|
|
2
2
|
import { Fragment } from "@wordpress/element";
|
|
3
3
|
import { __ } from "@wordpress/i18n";
|
|
4
4
|
import { displayShortcutList, shortcutAriaLabel } from "@wordpress/keycodes";
|
|
5
|
+
import { VisuallyHidden } from "@wordpress/ui";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
// packages/media-editor/src/components/media-editor-keyboard-shortcuts-modal/index.tsx
|
|
7
8
|
const SHORTCUTS = [
|
|
@@ -21,15 +22,13 @@ const SHORTCUTS = [
|
|
|
21
22
|
},
|
|
22
23
|
{
|
|
23
24
|
description: __("Pan"),
|
|
24
|
-
keyCombination: {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
ariaLabel: __("Arrow keys")
|
|
32
|
-
}
|
|
25
|
+
keyCombination: { character: [
|
|
26
|
+
"↑",
|
|
27
|
+
"↓",
|
|
28
|
+
"←",
|
|
29
|
+
"→"
|
|
30
|
+
] },
|
|
31
|
+
label: __("Arrow keys")
|
|
33
32
|
},
|
|
34
33
|
{
|
|
35
34
|
description: __("Zoom in"),
|
|
@@ -67,31 +66,31 @@ const SHORTCUTS = [
|
|
|
67
66
|
"↓",
|
|
68
67
|
"←",
|
|
69
68
|
"→"
|
|
70
|
-
]
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
label: __("Shift + Arrow keys")
|
|
73
72
|
}
|
|
74
73
|
];
|
|
75
|
-
function KeyCombinationDisplay({ keyCombination }) {
|
|
76
|
-
const {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
let label;
|
|
84
|
-
if (ariaLabel) label = ariaLabel;
|
|
85
|
-
else if (modifier) label = shortcutAriaLabel[modifier](charString);
|
|
86
|
-
else label = charString;
|
|
87
|
-
return /* @__PURE__ */ jsx("kbd", {
|
|
74
|
+
function KeyCombinationDisplay({ keyCombination, label }) {
|
|
75
|
+
const { character, modifier } = keyCombination;
|
|
76
|
+
const normalizedModifier = modifier ?? "undefined";
|
|
77
|
+
const characters = Array.isArray(character) ? character : [character];
|
|
78
|
+
const formatted = displayShortcutList[normalizedModifier](characters[0] ?? "");
|
|
79
|
+
const prefix = formatted.slice(0, -1);
|
|
80
|
+
const keys = Array.isArray(character) ? [...prefix, ...character] : formatted;
|
|
81
|
+
return /* @__PURE__ */ jsxs("kbd", {
|
|
88
82
|
className: "media-editor-keyboard-shortcuts-modal__shortcut-term",
|
|
89
83
|
dir: "ltr",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
children: [/* @__PURE__ */ jsx(VisuallyHidden, {
|
|
85
|
+
render: /* @__PURE__ */ jsx("span", {}),
|
|
86
|
+
children: label || shortcutAriaLabel[normalizedModifier](characters.join(""))
|
|
87
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
88
|
+
"aria-hidden": "true",
|
|
89
|
+
children: keys.map((key, keyIndex) => key === "+" && keyIndex < prefix.length ? /* @__PURE__ */ jsx(Fragment, { children: key }, keyIndex) : /* @__PURE__ */ jsx("kbd", {
|
|
90
|
+
className: "media-editor-keyboard-shortcuts-modal__shortcut-key",
|
|
91
|
+
children: key
|
|
92
|
+
}, keyIndex))
|
|
93
|
+
})]
|
|
95
94
|
});
|
|
96
95
|
}
|
|
97
96
|
function MediaEditorKeyboardShortcutsModal({ onClose }) {
|
|
@@ -105,12 +104,12 @@ function MediaEditorKeyboardShortcutsModal({ onClose }) {
|
|
|
105
104
|
}), /* @__PURE__ */ jsx("ul", {
|
|
106
105
|
className: "media-editor-keyboard-shortcuts-modal__shortcut-list",
|
|
107
106
|
role: "list",
|
|
108
|
-
children: SHORTCUTS.map((
|
|
107
|
+
children: SHORTCUTS.map((shortcut, index) => /* @__PURE__ */ jsxs("li", {
|
|
109
108
|
className: "media-editor-keyboard-shortcuts-modal__shortcut",
|
|
110
109
|
children: [/* @__PURE__ */ jsx("span", {
|
|
111
110
|
className: "media-editor-keyboard-shortcuts-modal__shortcut-description",
|
|
112
|
-
children: description
|
|
113
|
-
}), /* @__PURE__ */ jsx(KeyCombinationDisplay, {
|
|
111
|
+
children: shortcut.description
|
|
112
|
+
}), /* @__PURE__ */ jsx(KeyCombinationDisplay, { ...shortcut })]
|
|
114
113
|
}, index))
|
|
115
114
|
})]
|
|
116
115
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-keyboard-shortcuts-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { Fragment } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tdisplayShortcutList,\n\tshortcutAriaLabel,\n\ttype WPKeycodeModifier,\n} from '@wordpress/keycodes';\n\
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-keyboard-shortcuts-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { Fragment } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tdisplayShortcutList,\n\tshortcutAriaLabel,\n\ttype WPKeycodeModifier,\n} from '@wordpress/keycodes';\nimport { VisuallyHidden } from '@wordpress/ui';\n\ntype KeyCombinationDisplayProps =\n\t| {\n\t\t\tkeyCombination: {\n\t\t\t\tcharacter: string;\n\t\t\t\tmodifier?: WPKeycodeModifier | null;\n\t\t\t};\n\t\t\tlabel?: string;\n\t }\n\t| {\n\t\t\tkeyCombination: {\n\t\t\t\tcharacter: string[];\n\t\t\t\tmodifier?: WPKeycodeModifier | null;\n\t\t\t};\n\t\t\tlabel: string;\n\t };\n\ntype ShortcutEntry = KeyCombinationDisplayProps & {\n\tdescription: string;\n};\n\nconst SHORTCUTS: ShortcutEntry[] = [\n\t{\n\t\tdescription: __( 'Undo' ),\n\t\tkeyCombination: { modifier: 'primary', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Redo' ),\n\t\tkeyCombination: { modifier: 'primaryShift', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Pan' ),\n\t\tkeyCombination: {\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t},\n\t\tlabel: __( 'Arrow keys' ),\n\t},\n\t{\n\t\tdescription: __( 'Zoom in' ),\n\t\tkeyCombination: { character: '+' },\n\t},\n\t{\n\t\tdescription: __( 'Zoom out' ),\n\t\tkeyCombination: { character: '-' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° clockwise' ),\n\t\tkeyCombination: { character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° counter-clockwise' ),\n\t\tkeyCombination: { modifier: 'shift', character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Flip horizontal' ),\n\t\tkeyCombination: { character: 'H' },\n\t},\n\t{\n\t\tdescription: __( 'Flip vertical' ),\n\t\tkeyCombination: { character: 'V' },\n\t},\n\t{\n\t\tdescription: __( 'Pan or resize crop (large step)' ),\n\t\tkeyCombination: {\n\t\t\tmodifier: 'shift',\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t},\n\t\tlabel: __( 'Shift + Arrow keys' ),\n\t},\n];\n\nfunction KeyCombinationDisplay( {\n\tkeyCombination,\n\tlabel,\n}: KeyCombinationDisplayProps ) {\n\tconst { character, modifier } = keyCombination;\n\tconst normalizedModifier = modifier ?? 'undefined';\n\tconst characters = Array.isArray( character ) ? character : [ character ];\n\tconst formatted = displayShortcutList[ normalizedModifier ](\n\t\tcharacters[ 0 ] ?? ''\n\t);\n\tconst prefix = formatted.slice( 0, -1 );\n\tconst keys = Array.isArray( character )\n\t\t? [ ...prefix, ...character ]\n\t\t: formatted;\n\n\treturn (\n\t\t<kbd\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-term\"\n\t\t\tdir=\"ltr\"\n\t\t>\n\t\t\t<VisuallyHidden render={ <span /> }>\n\t\t\t\t{ label ||\n\t\t\t\t\tshortcutAriaLabel[ normalizedModifier ](\n\t\t\t\t\t\tcharacters.join( '' )\n\t\t\t\t\t) }\n\t\t\t</VisuallyHidden>\n\t\t\t<span aria-hidden=\"true\">\n\t\t\t\t{ keys.map( ( key, keyIndex ) =>\n\t\t\t\t\tkey === '+' && keyIndex < prefix.length ? (\n\t\t\t\t\t\t<Fragment key={ keyIndex }>{ key }</Fragment>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<kbd\n\t\t\t\t\t\t\tkey={ keyIndex }\n\t\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-key\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ key }\n\t\t\t\t\t\t</kbd>\n\t\t\t\t\t)\n\t\t\t\t) }\n\t\t\t</span>\n\t\t</kbd>\n\t);\n}\n\ninterface MediaEditorKeyboardShortcutsModalProps {\n\tonClose: () => void;\n}\n\nexport default function MediaEditorKeyboardShortcutsModal( {\n\tonClose,\n}: MediaEditorKeyboardShortcutsModalProps ) {\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal\"\n\t\t\ttitle={ __( 'Keyboard shortcuts' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t<p className=\"media-editor-keyboard-shortcuts-modal__note\">\n\t\t\t\t{ __(\n\t\t\t\t\t'These shortcuts work when the image editor has focus.'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t{ /*\n\t\t\t * Disable reason: The `list` ARIA role is redundant but\n\t\t\t * Safari+VoiceOver won't announce the list otherwise.\n\t\t\t */ }\n\t\t\t{ /* eslint-disable jsx-a11y/no-redundant-roles */ }\n\t\t\t<ul\n\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-list\"\n\t\t\t\trole=\"list\"\n\t\t\t>\n\t\t\t\t{ SHORTCUTS.map( ( shortcut, index ) => (\n\t\t\t\t\t<li\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"media-editor-keyboard-shortcuts-modal__shortcut-description\">\n\t\t\t\t\t\t\t{ shortcut.description }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<KeyCombinationDisplay { ...shortcut } />\n\t\t\t\t\t</li>\n\t\t\t\t) ) }\n\t\t\t</ul>\n\t\t\t{ /* eslint-enable jsx-a11y/no-redundant-roles */ }\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;;AA8BA,MAAM,YAA6B;CAClC;EACC,aAAa,GAAI,MAAO;EACxB,gBAAgB;GAAE,UAAU;GAAW,WAAW;EAAI;CACvD;CACA;EACC,aAAa,GAAI,MAAO;EACxB,gBAAgB;GAAE,UAAU;GAAgB,WAAW;EAAI;CAC5D;CACA;EACC,aAAa,GAAI,KAAM;EACvB,gBAAgB,EACf,WAAW;GAAE;GAAK;GAAK;GAAK;EAAI,EACjC;EACA,OAAO,GAAI,YAAa;CACzB;CACA;EACC,aAAa,GAAI,SAAU;EAC3B,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,UAAW;EAC5B,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAA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OAAD;EACC,WAAU;EACV,OAAQ,GAAI,oBAAqB;EACjC,gBAAiB;EAHlB,UAAA,CAKC,oBAAC,KAAD;GAAG,WAAU;GACV,UAAA,GACD,uDACD;EACE,CAAA,GAMH,oBAAC,MAAD;GACC,WAAU;GACV,MAAK;GAEH,UAAA,UAAU,KAAO,UAAU,UAC5B,qBAAC,MAAD;IAEC,WAAU;IAFX,UAAA,CAIC,oBAAC,QAAD;KAAM,WAAU;KACb,UAAA,SAAS;IACN,CAAA,GACN,oBAAC,uBAAD,EAAuB,GAAK,SAAY,CAAA,CACrC;GAPG,GAAA,KAOH,CACH;EACC,CAAA,CAEE;;AAET"}
|
|
@@ -51,6 +51,7 @@ function MediaEditorModal({ fields = [], form, aspectRatioPresets }) {
|
|
|
51
51
|
shouldCloseOnEsc: true,
|
|
52
52
|
noticesClassName: "media-editor-modal__snackbar",
|
|
53
53
|
noticesPortalElement: portalElement,
|
|
54
|
+
defaultPanel: "core/crop",
|
|
54
55
|
onClose: handleClose,
|
|
55
56
|
onSaved: ({ id: savedId, url, previous }) => {
|
|
56
57
|
if (savedId && onUpdate) onUpdate({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["mediaEditorStore","noticesStore"],"sources":["../../../src/components/media-editor-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Form the fields are laid out with in the Details tab. When omitted,\n\t * a default layout of the core attachment fields is used.\n\t */\n\tform?: Form;\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\n/**\n * The modal's footer chrome. The fine-rotation ruler and the image controls\n * both live under the canvas (in `media-editor__content`), never here, so the\n * footer has one layout at every width: History on the left, Cancel/Save on\n * the right.\n */\nfunction ModalFooter() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"media-editor-modal__footer\"\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t<MediaEditor.HistoryActions />\n\t\t\t<MediaEditor.SaveActions />\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\tform,\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } =\n\t\t\t\tselect( mediaEditorStore );\n\t\t\treturn {\n\t\t\t\tisModalOpen: isOpen(),\n\t\t\t\tid: getId(),\n\t\t\t\tonUpdate: getOnUpdate(),\n\t\t\t\tonUndo: getOnUndo(),\n\t\t\t\tonClose: getOnClose(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\tform={ form }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tif ( onUndo ) {\n\t\t\t\t\t\t\t\t\t\tonUndo();\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonUpdate( {\n\t\t\t\t\t\t\t\t\t\tid: previous.id,\n\t\t\t\t\t\t\t\t\t\turl: previous.url,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<ShortcutProvider\n\t\t\t\t\tclassName=\"media-editor-modal__shortcut-scope\"\n\t\t\t\t\tonKeyDown={ stopKeyDownPropagation }\n\t\t\t\t>\n\t\t\t\t\t<Modal\n\t\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\t\theaderActions={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter />\n\t\t\t\t\t</Modal>\n\t\t\t\t</ShortcutProvider>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAS,cAAc;CACtB,OACC,qBAAC,OAAD;EACC,WAAU;EACV,MAAK;EACL,cAAa,GAAI,gBAAiB;EAHnC,UAAA,CAKC,oBAAC,YAAY,gBAAb,CAA6B,CAAA,GAC7B,oBAAC,YAAY,aAAb,CAA0B,CAAA,CACtB;;AAEP;AAEA,SAAgB,iBAAkB,EACjC,SAAS,CAAC,GACV,MACA,sBAC0B;CAC1B,MAAM,EAAE,aAAa,IAAI,UAAU,QAAQ,YAAY,WACpD,WAAY;EACb,MAAM,EAAE,QAAQ,OAAO,aAAa,WAAW,eAC9C,OAAQA,OAAiB;EAC1B,OAAO;GACN,aAAa,OAAO;GACpB,IAAI,MAAM;GACV,UAAU,YAAY;GACtB,QAAQ,UAAU;GAClB,SAAS,WAAW;EACrB;CACD,GACA,CAAC,CACF;CAEA,MAAM,EAAE,0BAA0B,YAAaA,OAAiB;CAChE,MAAM,EAAE,wBAAwB,YAAaC,KAAa;CAE1D,IAAK,CAAE,eAAe,CAAE,IACvB,OAAO;CAGR,MAAM,gBACL,OAAO,aAAa,cAAc,OAAO,SAAS;CAMnD,MAAM,0BACL,UACI;EACJ,MAAM,gBAAgB;CACvB;CAEA,MAAM,oBAAoB;EACzB,sBAAsB;EACtB,UAAU;CACX;CAEA,OACC,oBAAC,aAAD;EACM;EACI;EACF;EACc;EACrB,kBAAA;EACA,kBAAiB;EACjB,sBAAuB;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["mediaEditorStore","noticesStore"],"sources":["../../../src/components/media-editor-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Form the fields are laid out with in the Details tab. When omitted,\n\t * a default layout of the core attachment fields is used.\n\t */\n\tform?: Form;\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\n/**\n * The modal's footer chrome. The fine-rotation ruler and the image controls\n * both live under the canvas (in `media-editor__content`), never here, so the\n * footer has one layout at every width: History on the left, Cancel/Save on\n * the right.\n */\nfunction ModalFooter() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"media-editor-modal__footer\"\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t<MediaEditor.HistoryActions />\n\t\t\t<MediaEditor.SaveActions />\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\tform,\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } =\n\t\t\t\tselect( mediaEditorStore );\n\t\t\treturn {\n\t\t\t\tisModalOpen: isOpen(),\n\t\t\t\tid: getId(),\n\t\t\t\tonUpdate: getOnUpdate(),\n\t\t\t\tonUndo: getOnUndo(),\n\t\t\t\tonClose: getOnClose(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\tform={ form }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\t// Rotate, flip and aspect ratio are only in the Crop panel for now.\n\t\t\t// This can go once they move under the canvas (#87282).\n\t\t\tdefaultPanel=\"core/crop\"\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tif ( onUndo ) {\n\t\t\t\t\t\t\t\t\t\tonUndo();\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonUpdate( {\n\t\t\t\t\t\t\t\t\t\tid: previous.id,\n\t\t\t\t\t\t\t\t\t\turl: previous.url,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<ShortcutProvider\n\t\t\t\t\tclassName=\"media-editor-modal__shortcut-scope\"\n\t\t\t\t\tonKeyDown={ stopKeyDownPropagation }\n\t\t\t\t>\n\t\t\t\t\t<Modal\n\t\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\t\theaderActions={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter />\n\t\t\t\t\t</Modal>\n\t\t\t\t</ShortcutProvider>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAS,cAAc;CACtB,OACC,qBAAC,OAAD;EACC,WAAU;EACV,MAAK;EACL,cAAa,GAAI,gBAAiB;EAHnC,UAAA,CAKC,oBAAC,YAAY,gBAAb,CAA6B,CAAA,GAC7B,oBAAC,YAAY,aAAb,CAA0B,CAAA,CACtB;;AAEP;AAEA,SAAgB,iBAAkB,EACjC,SAAS,CAAC,GACV,MACA,sBAC0B;CAC1B,MAAM,EAAE,aAAa,IAAI,UAAU,QAAQ,YAAY,WACpD,WAAY;EACb,MAAM,EAAE,QAAQ,OAAO,aAAa,WAAW,eAC9C,OAAQA,OAAi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@@
|
|
|
1
|
+
import { Component } from "@wordpress/element";
|
|
2
|
+
import { speak } from "@wordpress/a11y";
|
|
3
|
+
import { useCopyToClipboard } from "@wordpress/compose";
|
|
4
|
+
import { __, _x, sprintf } from "@wordpress/i18n";
|
|
5
|
+
import { Notice } from "@wordpress/ui";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// packages/media-editor/src/components/media-editor-panel/error-boundary.tsx
|
|
8
|
+
function getMessage(title) {
|
|
9
|
+
return {
|
|
10
|
+
title: sprintf(
|
|
11
|
+
/** translators: %s: the panel's title. */
|
|
12
|
+
__("The \"%s\" panel could not be shown"),
|
|
13
|
+
title
|
|
14
|
+
),
|
|
15
|
+
description: __("An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.")
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function CopyErrorButton({ error }) {
|
|
19
|
+
const ref = useCopyToClipboard(() => {
|
|
20
|
+
const { message, stack } = error ?? {};
|
|
21
|
+
return [[error, message].find((part) => typeof part === "string" && part) ?? "An unknown error occurred.", stack].filter((part) => typeof part === "string" && part).join("\n\n");
|
|
22
|
+
});
|
|
23
|
+
return /* @__PURE__ */ jsx(Notice.ActionButton, {
|
|
24
|
+
variant: "outline",
|
|
25
|
+
ref,
|
|
26
|
+
children: _x("Copy error", "button label")
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Keeps a panel's failure inside its tab, so the rest of the editor stays
|
|
31
|
+
* usable.
|
|
32
|
+
*/
|
|
33
|
+
var MediaEditorPanelErrorBoundary = class extends Component {
|
|
34
|
+
state = {
|
|
35
|
+
hasError: false,
|
|
36
|
+
error: null
|
|
37
|
+
};
|
|
38
|
+
static getDerivedStateFromError(error) {
|
|
39
|
+
return {
|
|
40
|
+
hasError: true,
|
|
41
|
+
error
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
componentDidCatch() {
|
|
45
|
+
const { title, description } = getMessage(this.props.title);
|
|
46
|
+
speak(`${title}. ${description}`, "assertive");
|
|
47
|
+
}
|
|
48
|
+
render() {
|
|
49
|
+
if (!this.state.hasError) return this.props.children;
|
|
50
|
+
const { title, description } = getMessage(this.props.title);
|
|
51
|
+
return /* @__PURE__ */ jsxs(Notice.Root, {
|
|
52
|
+
intent: "error",
|
|
53
|
+
children: [
|
|
54
|
+
/* @__PURE__ */ jsx(Notice.Title, { children: title }),
|
|
55
|
+
/* @__PURE__ */ jsx(Notice.Description, { children: description }),
|
|
56
|
+
/* @__PURE__ */ jsx(Notice.Actions, { children: /* @__PURE__ */ jsx(CopyErrorButton, { error: this.state.error }) })
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export { MediaEditorPanelErrorBoundary as default };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=error-boundary.mjs.map
|