@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.
Files changed (87) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/components/media-editor/index.cjs +157 -107
  3. package/build/components/media-editor/index.cjs.map +1 -1
  4. package/build/components/media-editor/use-save-media-editor.cjs +18 -8
  5. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
  6. package/build/components/media-editor-canvas/index.cjs +9 -7
  7. package/build/components/media-editor-canvas/index.cjs.map +1 -1
  8. package/build/components/media-editor-crop-panel/index.cjs +9 -7
  9. package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
  10. package/build/components/media-editor-fine-rotation/index.cjs +9 -7
  11. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  12. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +32 -33
  13. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
  14. package/build/components/media-editor-modal/index.cjs +10 -7
  15. package/build/components/media-editor-modal/index.cjs.map +1 -1
  16. package/build/components/media-editor-panel/error-boundary.cjs +68 -0
  17. package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
  18. package/build/components/media-editor-panel/index.cjs +158 -0
  19. package/build/components/media-editor-panel/index.cjs.map +1 -0
  20. package/build/components/media-preview/index.cjs +143 -36
  21. package/build/components/media-preview/index.cjs.map +1 -1
  22. package/build/components/rotation-ruler/index.cjs +9 -7
  23. package/build/components/rotation-ruler/index.cjs.map +1 -1
  24. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  25. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
  26. package/build/index.cjs +10 -8
  27. package/build/private-apis.cjs.map +1 -1
  28. package/build/state/aspect-ratio-presets.cjs +2 -2
  29. package/build/state/aspect-ratio-presets.cjs.map +1 -1
  30. package/build/state/composite-reducer.cjs +9 -7
  31. package/build/state/composite-reducer.cjs.map +1 -1
  32. package/build/state/use-media-editor-state.cjs.map +1 -1
  33. package/build/store/index.cjs +11 -9
  34. package/build/store/index.cjs.map +1 -1
  35. package/build/utils/get-media-type.cjs +8 -0
  36. package/build/utils/get-media-type.cjs.map +1 -1
  37. package/build/utils/index.cjs +6 -0
  38. package/build-module/components/media-editor/index.mjs +142 -95
  39. package/build-module/components/media-editor/index.mjs.map +1 -1
  40. package/build-module/components/media-editor/use-save-media-editor.mjs +9 -1
  41. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
  42. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +32 -33
  43. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
  44. package/build-module/components/media-editor-modal/index.mjs +1 -0
  45. package/build-module/components/media-editor-modal/index.mjs.map +1 -1
  46. package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
  47. package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
  48. package/build-module/components/media-editor-panel/index.mjs +123 -0
  49. package/build-module/components/media-editor-panel/index.mjs.map +1 -0
  50. package/build-module/components/media-preview/index.mjs +123 -40
  51. package/build-module/components/media-preview/index.mjs.map +1 -1
  52. package/build-module/state/aspect-ratio-presets.mjs +2 -2
  53. package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
  54. package/build-module/state/use-media-editor-state.mjs.map +1 -1
  55. package/build-module/utils/get-media-type.mjs +8 -1
  56. package/build-module/utils/get-media-type.mjs.map +1 -1
  57. package/build-module/utils/index.mjs +1 -1
  58. package/build-style/style-rtl.css +18 -30
  59. package/build-style/style.css +18 -30
  60. package/build-types/components/media-editor/index.d.ts +8 -0
  61. package/build-types/components/media-editor/index.d.ts.map +1 -1
  62. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  63. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  64. package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
  65. package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
  66. package/build-types/components/media-editor-panel/index.d.ts +46 -0
  67. package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
  68. package/build-types/components/media-preview/index.d.ts.map +1 -1
  69. package/build-types/state/use-media-editor-state.d.ts +7 -2
  70. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  71. package/build-types/utils/get-media-type.d.ts +3 -1
  72. package/build-types/utils/get-media-type.d.ts.map +1 -1
  73. package/build-types/utils/index.d.ts +1 -1
  74. package/build-types/utils/index.d.ts.map +1 -1
  75. package/package.json +26 -22
  76. package/src/components/media-editor/index.tsx +209 -114
  77. package/src/components/media-editor/style.scss +21 -1
  78. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +55 -63
  79. package/src/components/media-editor-modal/index.tsx +3 -0
  80. package/src/components/media-editor-panel/error-boundary.tsx +88 -0
  81. package/src/components/media-editor-panel/index.tsx +211 -0
  82. package/src/components/media-preview/index.tsx +195 -36
  83. package/src/components/media-preview/style.scss +11 -32
  84. package/src/state/README.md +3 -1
  85. package/src/state/use-media-editor-state.ts +7 -2
  86. package/src/utils/get-media-type.ts +9 -1
  87. package/src/utils/index.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["NavigableRegion","__","VisuallyHidden","Tabs","Stack","createContext","useContext","Button","drawerRight","Modal","useRegistry","useState","useMemo","DropdownMenu","moreVertical","MenuGroup","MenuItem","keyboard","sprintf","_x","MediaEditorKeyboardShortcutsModal","close","useMediaEditor","undo","displayShortcut","redo","isAppleOS","backup","useViewportMatch","useReducedMotion","useSelect","coreStore","useDispatch","noticesStore","useRef","useCallback","getMediaTypeFromMimeType","useCropOptions","useSaveMediaEditor","MEDIA_EDITOR_NOTICES_CONTEXT","isKeyboardEvent","CROP_CONTROL_ATTR","SnackbarNotices","MediaEditorImageControls","MediaEditorCropPanel","MediaForm","MediaEditorFineRotation","MediaEditorProvider","WCSpinner","MediaEditorCanvas","MediaPreview","AnimatePresence","motion","ConfirmDialog","createPortal","MediaEditorStateProvider"],"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,iBAAA,GAAA,kBAAA,KAAA,CAACA,oBAAAA,iBAAD;EACC,WAAU;EACV,YAAA,GAAYC,gBAAAA,GAAAA,CAAI,gBAAiB;EAFlC,UAAA,CAQC,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,gBAAD;GAAgB,QAAS,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD,CAAK,CAAA;GAC3BD,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,gBAAiB;EACR,CAAA,GAChB,iBAAA,GAAA,kBAAA,KAAA,CAACE,cAAAA,KAAK,MAAN;GACC,WAAU;GACV,OAAQ;GACR,eAAgB;GAHjB,UAAA,CAQC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IACd,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACA,cAAAA,KAAK,MAAN;KAAW,SAAQ;KAChB,UAAA,KAAK,KAAO,QACb,iBAAA,GAAA,kBAAA,IA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AAI,SAAU;IAClC,mBAAA,GAAmBA,gBAAAA,GAAAA,CAAI,cAAe;IACtC,gBAAiB,uBAAwB,KAAM;IAC/C,iBAAkB;KACjB,uBAAwB,KAAM;KAC9B,gBAAgB;IACjB;IAEEA,WAAAA,GAAAA,gBAAAA,GAAAA,CACD,wDACD;GACc,CAAA;GACb,wBAAA,GACCqD,mBAAAA,aAAAA,CAAc,UAAU,oBAAqB,IAC7C;EACiB;;CAKtB,MAAM,eAA6C;EAClD;EACA;EACA,UAAU,CAAC,CAAE;EACb;EAIA,oBAAoB,2BAA2B;EAC/C;EACA;EACA;EACA,eAAe;EACf,UAAU;EACV,QAAQ;EACR;EACA;EACA,eAAe,CAAC,CAAE;EAClB,mBAAmB;CACpB;CAEA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,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,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,0BAAD,EAAA,UACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,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.cjs","names":["NavigableRegion","__","VisuallyHidden","Tabs","inertValue","Stack","createContext","useContext","useCropOptions","MediaEditorCropPanel","Button","drawerRight","Modal","useRegistry","useState","useMemo","DropdownMenu","moreVertical","MenuGroup","MenuItem","keyboard","sprintf","_x","MediaEditorKeyboardShortcutsModal","close","useMediaEditor","undo","displayShortcut","redo","isAppleOS","backup","useViewportMatch","useReducedMotion","useSelect","coreStore","useDispatch","noticesStore","useCallback","MEDIA_EDITOR_NOTICES_CONTEXT","useRef","useEffect","getMediaTypeFromMimeType","useSaveMediaEditor","withIgnoreIMEEvents","isKeyboardEvent","CROP_CONTROL_ATTR","SnackbarNotices","MediaEditorImageControls","useMediaEditorPanels","Slot","getPanelSlotName","MediaEditorFineRotation","WCSpinner","clsx","MediaEditorCanvas","MediaPreview","AnimatePresence","motion","ConfirmDialog","createPortal","MediaEditorProvider","SlotFillProvider","MediaEditorPanelsProvider","MediaEditorPanel","MediaForm","PluginArea","MEDIA_EDITOR_PLUGIN_SCOPE","MediaEditorStateProvider"],"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;;;;;;;;AASlC,MAAM,gBAAgB;;AAGtB,MAAM,aAAa;AAEnB,MAAM,mBAAmB,CAAE,OAAQ;AAGnC,MAAM,6BAA6B;AAQnC,MAAM,kBAAkB;CAEvB,MAAM,EAAE,OAAO,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AAA,GAAAA,CAAI,SAAU;OAEtB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC+D,wBAAAA,SAAD,CAAY,CAAA;MACK,CAAA;MAClB,iBAAA,GAAA,kBAAA,IAAA,CAACC,mBAAAA,YAAD;OACC,OAAQC,gCAAAA;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,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,0BAAD,EAAA,UACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,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"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -25,13 +27,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
27
  enumerable: true
26
28
  }) : target, mod));
27
29
  let _wordpress_api_fetch = require("@wordpress/api-fetch");
28
- _wordpress_api_fetch = __toESM(_wordpress_api_fetch);
29
30
  let _wordpress_data = require("@wordpress/data");
30
31
  let _wordpress_core_data = require("@wordpress/core-data");
31
32
  let _wordpress_element = require("@wordpress/element");
32
33
  let _wordpress_i18n = require("@wordpress/i18n");
33
34
  let _wordpress_notices = require("@wordpress/notices");
34
35
  let _wordpress_image_editor = require("@wordpress/image-editor");
36
+ _wordpress_api_fetch = __toESM(_wordpress_api_fetch);
35
37
  // packages/media-editor/src/components/media-editor/use-save-media-editor.ts
36
38
  const METADATA_EDIT_KEYS = [
37
39
  "title",
@@ -118,7 +120,15 @@ function useSaveMediaEditor({ session, id, isImage, media, onSaved, replacementS
118
120
  }
119
121
  } catch (error) {
120
122
  const message = error instanceof Error ? error.message : error?.message ?? (0, _wordpress_i18n.__)("An unknown error occurred.");
121
- createErrorNotice(isImage ? (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Could not save image. %s"), message) : (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Could not save media. %s"), message), {
123
+ createErrorNotice(isImage ? (0, _wordpress_i18n.sprintf)(
124
+ /** translators: %s: Error message. */
125
+ (0, _wordpress_i18n.__)("Could not save image. %s"),
126
+ message
127
+ ) : (0, _wordpress_i18n.sprintf)(
128
+ /** translators: %s: Error message. */
129
+ (0, _wordpress_i18n.__)("Could not save media. %s"),
130
+ message
131
+ ), {
122
132
  type: "snackbar",
123
133
  context: MEDIA_EDITOR_NOTICES_CONTEXT
124
134
  });
@@ -1 +1 @@
1
- {"version":3,"file":"use-save-media-editor.cjs","names":["getImageEdit","mapImageEdit","useRegistry","useDispatch","coreStore","noticesStore","useState","useCallback","apiFetch","__","sprintf"],"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,QAAA,GAAOA,wBAAAA,aAAAA,CAAc,QAAQ,YAAY,KAAM;CACrD,IAAK,CAAE,MACN,OAAO,CAAC;CAIT,QAAA,GAAOC,wBAAAA,aAAAA,CAA0B,MAA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AAK,UAAU,SAAS,GAAI;KAQ3B,MAAM,gBAAgB,iBAPD,SACnB,OAAQH,qBAAAA,KAAU,CAAC,CACnB,iCACA,YACA,cACA,QAGU,GACX,WACD;KAEA,QAAU,OAAA,GAAMI,qBAAAA,QAAAA,CAAU;MACzB,MAAM,gBAAiB,SAAU;MACjC,QAAQ;MACR,MAAM;OACL,KAAK;OACL;OACA,GAAG;MACJ;KACD,CAAE;KAEF,IAAK,OACJ,qBACC,YACA,cACA,OACA,KAAA,GACA,IACD;IAEF,OAAO,IACN,qBACA,CAAE,SACA,OAAQJ,qBAAAA,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,YAAA,GACtCK,gBAAAA,GAAAA,CAAI,4BAA6B;IACpC,kBACC,WAAA,GACGC,gBAAAA,QAAAA,EAAAA,GAEAD,gBAAAA,GAAAA,CAAI,0BAA2B,GAC/B,OACD,KAAA,GACCC,gBAAAA,QAAAA,EAAAA,GAEAD,gBAAAA,GAAAA,CAAI,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.cjs","names":["getImageEdit","mapImageEdit","useRegistry","useDispatch","coreStore","noticesStore","useState","useCallback","apiFetch","__","sprintf"],"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,QAAA,GAAOA,wBAAAA,aAAAA,CAAc,QAAQ,YAAY,KAAM;CACrD,IAAK,CAAE,MACN,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;CAAK;AACzB"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -25,7 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
27
  enumerable: true
26
28
  }) : target, mod));
27
29
  let clsx = require("clsx");
28
- clsx = __toESM(clsx);
29
30
  let _wordpress_element = require("@wordpress/element");
30
31
  let _wordpress_components = require("@wordpress/components");
31
32
  let _wordpress_i18n = require("@wordpress/i18n");
@@ -34,6 +35,7 @@ let ___media_editor_provider_index_tsx = require("../media-editor-provider/index
34
35
  let ______utils_index_ts = require("../../utils/index.cjs");
35
36
  let ______state_index_ts = require("../../state/index.cjs");
36
37
  let react_jsx_runtime = require("react/jsx-runtime");
38
+ clsx = __toESM(clsx);
37
39
  // packages/media-editor/src/components/media-editor-canvas/index.tsx
38
40
  /**
39
41
  * Editing surface for image media in the media editor modal. Pulls
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["useMediaEditorContext","useMediaEditor","useState","useCallback","getMediaTypeFromMimeType","__","WCSpinner","ImageEditorCanvas"],"sources":["../../../src/components/media-editor-canvas/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { Spinner as WCSpinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { ImageEditorCanvas } from '@wordpress/image-editor';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { useMediaEditor } from '../../state';\n\nexport interface MediaEditorCanvasProps {\n\t/** Whether external placement activity should reveal the grid. */\n\tisPlacementActive?: boolean;\n\t/** Fires when a canvas gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas gesture ends. */\n\tonGestureEnd?: () => void;\n\t/**\n\t * Disable crop interaction on the canvas. Set while the edit is saving,\n\t * so a drag cannot change the crop after the request was built.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls\n * its image editor controller from the surrounding `<MediaEditorStateProvider>`\n * so the bottom bar and Crop sidebar tab share the same state.\n *\n * Returns `null` for missing or non-image media so the modal's outer\n * guards can render a spinner or fall through to `<MediaPreview>`.\n *\n * @param props\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n * @param props.disabled\n */\nexport default function MediaEditorCanvas( {\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n\tdisabled = false,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst session = useMediaEditor();\n\tconst { beginGesture, endGesture, setSourceImage } = session;\n\n\t// Tracks whether the image pixels have actually loaded. The image editor's\n\t// geometry is driven by the known media dimensions, so its handles and\n\t// overlays would otherwise appear before the image finishes streaming in.\n\t// Stored with the URL it is for, so a new URL (restoring the original\n\t// swaps it in place) counts as loading until the image editor reports back.\n\tconst [ settled, setSettled ] = useState< {\n\t\turl: string | undefined;\n\t\tstatus: 'loaded' | 'error';\n\t} >();\n\n\tconst handleGestureStart = useCallback( () => {\n\t\tbeginGesture();\n\t\tonGestureStart?.();\n\t}, [ beginGesture, onGestureStart ] );\n\n\tconst handleGestureEnd = useCallback( () => {\n\t\tendGesture();\n\t\tonGestureEnd?.();\n\t}, [ endGesture, onGestureEnd ] );\n\n\tconst mediaUrl = media?.source_url;\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type );\n\tconst mediaWidth = Number( media?.media_details?.width );\n\tconst mediaHeight = Number( media?.media_details?.height );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! mediaUrl ||\n\t\t\t! Number.isFinite( mediaWidth ) ||\n\t\t\t! Number.isFinite( mediaHeight ) ||\n\t\t\tmediaWidth <= 0 ||\n\t\t\tmediaHeight <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tsetSourceImage( {\n\t\t\tsrc: mediaUrl,\n\t\t\tnaturalWidth: mediaWidth,\n\t\t\tnaturalHeight: mediaHeight,\n\t\t} );\n\t}, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );\n\n\tconst isImage = mediaType.type === 'image';\n\tconst status =\n\t\tsettled && settled.url === mediaUrl ? settled.status : 'loading';\n\tconst handleImageLoaded = useCallback( () => {\n\t\tsetSettled( { url: mediaUrl, status: 'loaded' } );\n\t}, [ mediaUrl ] );\n\tconst handleImageError = useCallback( () => {\n\t\tsetSettled( { url: mediaUrl, status: 'error' } );\n\t}, [ mediaUrl ] );\n\n\tif ( ! mediaUrl || ! isImage ) {\n\t\treturn null;\n\t}\n\n\tif ( status === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-canvas\">\n\t\t\t\t<div className=\"media-editor-canvas__error\" role=\"alert\">\n\t\t\t\t\t<p>{ __( 'Failed to load image.' ) }</p>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-canvas\">\n\t\t\t{ status === 'loading' && (\n\t\t\t\t<div className=\"media-editor-canvas__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * The image editor stays mounted while loading (hidden behind the\n\t\t\t * spinner) so the image decodes off-screen and reveals in one paint\n\t\t\t * instead of streaming in top-to-bottom. Until it's revealed it's\n\t\t\t * non-interactive (`pointer-events: none` in CSS).\n\t\t\t *\n\t\t\t * The crop area is never focused programmatically: the modal keeps\n\t\t\t * initial focus on the dialog frame, and users reach the crop area\n\t\t\t * by tabbing to it.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'media-editor-canvas__image-editor', {\n\t\t\t\t\t'is-loaded': status === 'loaded',\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<ImageEditorCanvas\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\tcontroller={ session.imageEditor }\n\t\t\t\t\tfreeformCrop\n\t\t\t\t\t// Keep the grid up while a sidebar placement control is in\n\t\t\t\t\t// use; otherwise show it only while the crop is changing.\n\t\t\t\t\tshowGrid={ isPlacementActive ? true : 'interactive' }\n\t\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\t\tonGestureEnd={ handleGestureEnd }\n\t\t\t\t\tonImageLoaded={ handleImageLoaded }\n\t\t\t\t\tonImageError={ handleImageError }\n\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAwB,kBAAmB,EAC1C,oBAAoB,OACpB,gBACA,cACA,WAAW,SACgB;CAC3B,MAAM,EAAE,WAAA,GAAUA,mCAAAA,sBAAAA,CAAsB;CACxC,MAAM,WAAA,GAAUC,qBAAAA,eAAAA,CAAe;CAC/B,MAAM,EAAE,cAAc,YAAY,mBAAmB;CAOrD,MAAM,CAAE,SAAS,eAAA,GAAeC,mBAAAA,SAAAA,CAG5B;CAEJ,MAAM,sBAAA,GAAqBC,mBAAAA,YAAAA,OAAmB;E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AAI,uBAAwB,EAAM,CAAA;EACnC,CAAA;CACD,CAAA;CAIP,OACC,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,WAAW,aACZ,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;GAAK,WAAU;GACd,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,SAAD,CAAY,CAAA;EACR,CAAA,GAYN,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;GACC,YAAA,GAAY,KAAA,QAAA,CAAM,qCAAqC,EACtD,aAAa,WAAW,SACzB,CAAE;GAEF,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,wBAAAA,mBAAD;IACC,KAAM;IACN,YAAa,QAAQ;IACrB,cAAA;IAGA,UAAW,oBAAoB,OAAO;IACtC,gBAAiB;IACjB,cAAe;IACf,eAAgB;IAChB,cAAe;IACJ;GACX,CAAA;EACG,CAAA,CACD;;AAEP"}
1
+ {"version":3,"file":"index.cjs","names":["useMediaEditorContext","useMediaEditor","useState","useCallback","getMediaTypeFromMimeType","useEffect","__","WCSpinner","clsx","ImageEditorCanvas"],"sources":["../../../src/components/media-editor-canvas/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { Spinner as WCSpinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { ImageEditorCanvas } from '@wordpress/image-editor';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { useMediaEditor } from '../../state';\n\nexport interface MediaEditorCanvasProps {\n\t/** Whether external placement activity should reveal the grid. */\n\tisPlacementActive?: boolean;\n\t/** Fires when a canvas gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas gesture ends. */\n\tonGestureEnd?: () => void;\n\t/**\n\t * Disable crop interaction on the canvas. Set while the edit is saving,\n\t * so a drag cannot change the crop after the request was built.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls\n * its image editor controller from the surrounding `<MediaEditorStateProvider>`\n * so the bottom bar and Crop sidebar tab share the same state.\n *\n * Returns `null` for missing or non-image media so the modal's outer\n * guards can render a spinner or fall through to `<MediaPreview>`.\n *\n * @param props\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n * @param props.disabled\n */\nexport default function MediaEditorCanvas( {\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n\tdisabled = false,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst session = useMediaEditor();\n\tconst { beginGesture, endGesture, setSourceImage } = session;\n\n\t// Tracks whether the image pixels have actually loaded. The image editor's\n\t// geometry is driven by the known media dimensions, so its handles and\n\t// overlays would otherwise appear before the image finishes streaming in.\n\t// Stored with the URL it is for, so a new URL (restoring the original\n\t// swaps it in place) counts as loading until the image editor reports back.\n\tconst [ settled, setSettled ] = useState< {\n\t\turl: string | undefined;\n\t\tstatus: 'loaded' | 'error';\n\t} >();\n\n\tconst handleGestureStart = useCallback( () => {\n\t\tbeginGesture();\n\t\tonGestureStart?.();\n\t}, [ beginGesture, onGestureStart ] );\n\n\tconst handleGestureEnd = useCallback( () => {\n\t\tendGesture();\n\t\tonGestureEnd?.();\n\t}, [ endGesture, onGestureEnd ] );\n\n\tconst mediaUrl = media?.source_url;\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type );\n\tconst mediaWidth = Number( media?.media_details?.width );\n\tconst mediaHeight = Number( media?.media_details?.height );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! mediaUrl ||\n\t\t\t! Number.isFinite( mediaWidth ) ||\n\t\t\t! Number.isFinite( mediaHeight ) ||\n\t\t\tmediaWidth <= 0 ||\n\t\t\tmediaHeight <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tsetSourceImage( {\n\t\t\tsrc: mediaUrl,\n\t\t\tnaturalWidth: mediaWidth,\n\t\t\tnaturalHeight: mediaHeight,\n\t\t} );\n\t}, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );\n\n\tconst isImage = mediaType.type === 'image';\n\tconst status =\n\t\tsettled && settled.url === mediaUrl ? settled.status : 'loading';\n\tconst handleImageLoaded = useCallback( () => {\n\t\tsetSettled( { url: mediaUrl, status: 'loaded' } );\n\t}, [ mediaUrl ] );\n\tconst handleImageError = useCallback( () => {\n\t\tsetSettled( { url: mediaUrl, status: 'error' } );\n\t}, [ mediaUrl ] );\n\n\tif ( ! mediaUrl || ! isImage ) {\n\t\treturn null;\n\t}\n\n\tif ( status === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-canvas\">\n\t\t\t\t<div className=\"media-editor-canvas__error\" role=\"alert\">\n\t\t\t\t\t<p>{ __( 'Failed to load image.' ) }</p>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-canvas\">\n\t\t\t{ status === 'loading' && (\n\t\t\t\t<div className=\"media-editor-canvas__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * The image editor stays mounted while loading (hidden behind the\n\t\t\t * spinner) so the image decodes off-screen and reveals in one paint\n\t\t\t * instead of streaming in top-to-bottom. Until it's revealed it's\n\t\t\t * non-interactive (`pointer-events: none` in CSS).\n\t\t\t *\n\t\t\t * The crop area is never focused programmatically: the modal keeps\n\t\t\t * initial focus on the dialog frame, and users reach the crop area\n\t\t\t * by tabbing to it.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'media-editor-canvas__image-editor', {\n\t\t\t\t\t'is-loaded': status === 'loaded',\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<ImageEditorCanvas\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\tcontroller={ session.imageEditor }\n\t\t\t\t\tfreeformCrop\n\t\t\t\t\t// Keep the grid up while a sidebar placement control is in\n\t\t\t\t\t// use; otherwise show it only while the crop is changing.\n\t\t\t\t\tshowGrid={ isPlacementActive ? true : 'interactive' }\n\t\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\t\tonGestureEnd={ handleGestureEnd }\n\t\t\t\t\tonImageLoaded={ handleImageLoaded }\n\t\t\t\t\tonImageError={ handleImageError }\n\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAwB,kBAAmB,EAC1C,oBAAoB,OACpB,gBACA,cACA,WAAW,SACgB;CAC3B,MAAM,EAAE,WAAA,GAAUA,mCAAAA,sBAAAA,CAAsB;CACxC,MAAM,WAAA,GAAUC,qBAAAA,eAAAA,CAAe;CAC/B,MAAM,EAAE,cAAc,YAAY,mBAAmB;CAOrD,MAAM,CAAE,SAAS,eAAA,GAAeC,mBAAAA,SAAAA,CAG5B;CAEJ,MAAM,sBAAA,GAAqBC,mBAAAA,YAAAA,OAAmB;EAC7C,aAAa;EACb,iBAAiB;CAClB,GAAG,CAAE,cAAc,cAAe,CAAE;CAEpC,MAAM,oBAAA,GAAmBA,mBAAAA,YAAAA,OAAmB;EAC3C,WAAW;EACX,eAAe;CAChB,GAAG,CAAE,YAAY,YAAa,CAAE;CAEhC,MAAM,WAAW,OAAO;CACxB,MAAM,aAAA,GAAYC,qBAAAA,yBAAAA,CAA0B,OAAO,SAAU;CAC7D,MAAM,aAAa,OAAQ,OAAO,eAAe,KAAM;CACvD,MAAM,cAAc,OAAQ,OAAO,eAAe,MAAO;CAEzDC,CAAAA,GAAAA,mBAAAA,UAAAA,OAAiB;EAChB,IACC,CAAE,YACF,CAAE,OAAO,SAAU,UAAW,KAC9B,CAAE,OAAO,SAAU,WAAY,KAC/B,cAAc,KACd,eAAe,GAEf;EAED,eAAgB;GAC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oB,OAAO;IACtC,gBAAiB;IACjB,cAAe;IACf,eAAgB;IAChB,cAAe;IACJ;GACX,CAAA;EACG,CAAA,CACD;;AAEP"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -29,8 +31,8 @@ let _wordpress_i18n = require("@wordpress/i18n");
29
31
  let _wordpress_icons = require("@wordpress/icons");
30
32
  let ______hooks_use_crop_gesture_handlers_ts = require("../../hooks/use-crop-gesture-handlers.cjs");
31
33
  let ___media_editor_image_controls_index_tsx = require("../media-editor-image-controls/index.cjs");
32
- ___media_editor_image_controls_index_tsx = __toESM(___media_editor_image_controls_index_tsx);
33
34
  let react_jsx_runtime = require("react/jsx-runtime");
35
+ ___media_editor_image_controls_index_tsx = __toESM(___media_editor_image_controls_index_tsx);
34
36
  // packages/media-editor/src/components/media-editor-crop-panel/index.tsx
35
37
  /**
36
38
  * Sidebar panel for crop controls: rotate, flip and zoom above the
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["Stack","CROP_CONTROL_ATTR","VisuallyHidden","__","MediaEditorImageControls","SelectControl","Icon","getAspectRatioIcon"],"sources":["../../../src/components/media-editor-crop-panel/index.tsx"],"sourcesContent":["import { SelectControl, Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, getAspectRatioIcon } from '@wordpress/icons';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorImageControls from '../media-editor-image-controls';\n\nexport interface MediaEditorCropPanelProps {\n\t/**\n\t * Selected aspect-ratio preset value as a string (so it round-trips\n\t * through `<SelectControl>`). `'0'` = free, `'-1'` = original, any\n\t * positive number = fixed ratio.\n\t */\n\taspectRatioValue: string;\n\t/** Setter for the aspect-ratio preset value. */\n\tonAspectRatioChange: ( value: string ) => void;\n\t/** Aspect-ratio presets to display in the selector. */\n\taspectRatioOptions: AspectRatioPreset[];\n\t/** Disable every control in the panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\n/**\n * Sidebar panel for crop controls: rotate, flip and zoom above the\n * aspect-ratio selector. Rendered where the panel docks; below that the\n * transform controls sit under the canvas instead, placed by the editor.\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.aspectRatioOptions\n * @param props.disabled\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\taspectRatioOptions,\n\tdisabled = false,\n}: MediaEditorCropPanelProps ) {\n\tconst items = aspectRatioOptions.map( ( preset ) => ( {\n\t\tlabel: preset.label,\n\t\tvalue: preset.value.toString(),\n\t} ) );\n\n\treturn (\n\t\t// Tag the whole panel as a crop-control region so the modal's\n\t\t// Cmd+Z handler doesn't mistake the SelectControl input for a\n\t\t// metadata field (which would suppress undo).\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"xl\"\n\t\t\t{ ...{ [ CROP_CONTROL_ATTR ]: true } }\n\t\t>\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Crop options' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<MediaEditorImageControls withLabels disabled={ disabled } />\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={\n\t\t\t\t\titems.find( ( item ) => item.value === aspectRatioValue ) ??\n\t\t\t\t\tnull\n\t\t\t\t}\n\t\t\t\tonValueChange={ ( item ) => {\n\t\t\t\t\tif ( item && item.value !== null ) {\n\t\t\t\t\t\tonAspectRatioChange( item.value );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\titems={ items }\n\t\t\t\ttrigger={\n\t\t\t\t\t<SelectControl.Trigger>\n\t\t\t\t\t\t{ ( item ) => (\n\t\t\t\t\t\t\t<span className=\"media-editor-crop-panel__aspect-ratio-option\">\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={ getAspectRatioIcon(\n\t\t\t\t\t\t\t\t\t\tNumber( item.value )\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<span className=\"media-editor-crop-panel__aspect-ratio-label\">\n\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</SelectControl.Trigger>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ items.map( ( item ) => (\n\t\t\t\t\t<SelectControl.Item\n\t\t\t\t\t\tkey={ item.value }\n\t\t\t\t\t\tvalue={ item }\n\t\t\t\t\t\tlabel={ item.label }\n\t\t\t\t\t>\n\t\t\t\t\t\t<SelectControl.ItemLabel>\n\t\t\t\t\t\t\t<span className=\"media-editor-crop-panel__aspect-ratio-option\">\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={ getAspectRatioIcon(\n\t\t\t\t\t\t\t\t\t\tNumber( item.value )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AA,kBAAA,IAAA,CAACC,iBAAAA,MAAD,EACC,OAAA,GAAOC,iBAAAA,mBAAAA,CACN,OAAQ,KAAK,KAAM,CACpB,EACA,CAAA,GACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;MAAM,WAAU;MACb,UAAA,KAAK;KACF,CAAA,CACD;IAEe,CAAA,EAAA,CAAA;IAGtB,UAAA,MAAM,KAAO,SACd,iBAAA,GAAA,kBAAA,IAAA,CAACF,cAAAA,cAAc,MAAf;KAEC,OAAQ;KACR,OAAQ,KAAK;KAEb,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACA,cAAAA,cAAc,WAAf,EAAA,UACC,iBAAA,GAAA,kBAAA,KAAA,CAAC,QAAD;MAAM,WAAU;MAAhB,UAAA,CACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,iBAAAA,MAAD,EACC,OAAA,GAAOC,iBAAAA,mBAAAA,CACN,OAAQ,KAAK,KAAM,CACpB,EACA,CAAA,GACC,KAAK,KACF;KACkB,CAAA,EAAA,CAAA;IACN,GAdb,KAAK,KAcQ,CACnB;GACY,CAAA;EACT;;AAET"}
1
+ {"version":3,"file":"index.cjs","names":["Stack","CROP_CONTROL_ATTR","VisuallyHidden","__","MediaEditorImageControls","SelectControl","Icon","getAspectRatioIcon"],"sources":["../../../src/components/media-editor-crop-panel/index.tsx"],"sourcesContent":["import { SelectControl, Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, getAspectRatioIcon } from '@wordpress/icons';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorImageControls from '../media-editor-image-controls';\n\nexport interface MediaEditorCropPanelProps {\n\t/**\n\t * Selected aspect-ratio preset value as a string (so it round-trips\n\t * through `<SelectControl>`). `'0'` = free, `'-1'` = original, any\n\t * positive number = fixed ratio.\n\t */\n\taspectRatioValue: string;\n\t/** Setter for the aspect-ratio preset value. */\n\tonAspectRatioChange: ( value: string ) => void;\n\t/** Aspect-ratio presets to display in the selector. */\n\taspectRatioOptions: AspectRatioPreset[];\n\t/** Disable every control in the panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\n/**\n * Sidebar panel for crop controls: rotate, flip and zoom above the\n * aspect-ratio selector. Rendered where the panel docks; below that the\n * transform controls sit under the canvas instead, placed by the editor.\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.aspectRatioOptions\n * @param props.disabled\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\taspectRatioOptions,\n\tdisabled = false,\n}: MediaEditorCropPanelProps ) {\n\tconst items = aspectRatioOptions.map( ( preset ) => ( {\n\t\tlabel: preset.label,\n\t\tvalue: preset.value.toString(),\n\t} ) );\n\n\treturn (\n\t\t// Tag the whole panel as a crop-control region so the modal's\n\t\t// Cmd+Z handler doesn't mistake the SelectControl input for a\n\t\t// metadata field (which would suppress undo).\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"xl\"\n\t\t\t{ ...{ [ CROP_CONTROL_ATTR ]: true } }\n\t\t>\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Crop options' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<MediaEditorImageControls withLabels disabled={ disabled } />\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={\n\t\t\t\t\titems.find( ( item ) => item.value === aspectRatioValue ) ??\n\t\t\t\t\tnull\n\t\t\t\t}\n\t\t\t\tonValueChange={ ( item ) => {\n\t\t\t\t\tif ( item && item.value !== null ) {\n\t\t\t\t\t\tonAspectRatioChange( item.value );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\titems={ items }\n\t\t\t\ttrigger={\n\t\t\t\t\t<SelectControl.Trigger>\n\t\t\t\t\t\t{ ( item ) => (\n\t\t\t\t\t\t\t<span className=\"media-editor-crop-panel__aspect-ratio-option\">\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={ getAspectRatioIcon(\n\t\t\t\t\t\t\t\t\t\tNumber( item.value )\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<span className=\"media-editor-crop-panel__aspect-ratio-label\">\n\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</SelectControl.Trigger>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ items.map( ( item ) => (\n\t\t\t\t\t<SelectControl.Item\n\t\t\t\t\t\tkey={ item.value }\n\t\t\t\t\t\tvalue={ item }\n\t\t\t\t\t\tlabel={ item.label }\n\t\t\t\t\t>\n\t\t\t\t\t\t<SelectControl.ItemLabel>\n\t\t\t\t\t\t\t<span className=\"media-editor-crop-panel__aspect-ratio-option\">\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={ getAspectRatioIcon(\n\t\t\t\t\t\t\t\t\t\tNumber( item.value )\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{ item.label }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</SelectControl.ItemLabel>\n\t\t\t\t\t</SelectControl.Item>\n\t\t\t\t) ) }\n\t\t\t</SelectControl>\n\t\t</Stack>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAwB,qBAAsB,EAC7C,kBACA,qBACA,oBACA,WAAW,SACmB;CAC9B,MAAM,QAAQ,mBAAmB,KAAO,YAAc;EACrD,OAAO,OAAO;EACd,OAAO,OAAO,MAAM,SAAS;CAC9B,EAAI;CAEJ,OAIC,i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AU;MAAhB,UAAA,CACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,iBAAAA,MAAD,EACC,OAAA,GAAOC,iBAAAA,mBAAAA,CACN,OAAQ,KAAK,KAAM,CACpB,EACA,CAAA,GACC,KAAK,KACF;KACkB,CAAA,EAAA,CAAA;IACN,GAdb,KAAK,KAcQ,CACnB;GACY,CAAA;EACT;;AAET"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -28,8 +30,8 @@ let _wordpress_i18n = require("@wordpress/i18n");
28
30
  let ______state_index_ts = require("../../state/index.cjs");
29
31
  let ______hooks_use_crop_gesture_handlers_ts = require("../../hooks/use-crop-gesture-handlers.cjs");
30
32
  let ___rotation_ruler_index_tsx = require("../rotation-ruler/index.cjs");
31
- ___rotation_ruler_index_tsx = __toESM(___rotation_ruler_index_tsx);
32
33
  let react_jsx_runtime = require("react/jsx-runtime");
34
+ ___rotation_ruler_index_tsx = __toESM(___rotation_ruler_index_tsx);
33
35
  // packages/media-editor/src/components/media-editor-fine-rotation/index.tsx
34
36
  /**
35
37
  * Fine-rotation slider for the media editor. It renders under the canvas so it
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["useMediaEditor","useCropGestureHandlers","RotationRuler","__"],"sources":["../../../src/components/media-editor-fine-rotation/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/**\n\t * Disable the ruler. Set while the edit is saving; `RotationRuler`\n\t * cancels an in-flight drag when this flips.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n * @param props.disabled\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n\tdisabled = false,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation, maxRotationOffset } =\n\t\tuseMediaEditor().imageEditor;\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a\n\t\t// 90° midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-maxRotationOffset + EPS,\n\t\t\tMath.min( maxRotationOffset - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"presentation\"\n\t\t\tclassName=\"media-editor-fine-rotation\"\n\t\t\t{ ...rotationGestureHandlers }\n\t\t>\n\t\t\t<RotationRuler\n\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\tmin={ -maxRotationOffset }\n\t\t\t\tmax={ maxRotationOffset }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\tdisabled={ disabled }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAwB,wBAAyB,EAChD,+BACA,WAAW,SACsB;CACjC,MAAM,EAAE,OAAO,aAAa,uBAAA,GAC3BA,qBAAAA,eAAAA,CAAe,CAAC,CAAC;CAIlB,MAAM,2BAAA,GAA0BC,yCAAAA,uBAAAA,CAAwB,EACvD,eAAe,MAChB,CAAE;CAKF,MAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;CAEtD,MAAM,YADa,MAAM,KAAK,eAAe,MAAM,KAAK,WACzB,KAAK;CACpC,MAAM,cAAe,MAAM,WAAW,aAAc;CAEpD,MAAM,wBAAyB,UAAmB;EAIjD,MAAM,MAAM;EACZ,MAAM,UAAU,KAAK,IACpB,CAAC,oBAAoB,KACrB,KAAK,IAAK,oBAAoB,KAAK,KAAM,CAC1C;EACA,gCAAgC;EAChC,YAAa,YAAY,UAAU,SAAU;CAC9C;CAEA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EACC,MAAK;EACL,WAAU;EACV,GAAK;EAEL,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,4BAAAA,SAAD;GACC,QAAA,GAAQC,gBAAAA,GAAAA,CAAI,eAAgB;GAC5B,KAAM,CAAC;GACP,KAAM;GACN,OAAQ;GACR,UAAW;GACA;EACX,CAAA;CACG,CAAA;AAEP"}
1
+ {"version":3,"file":"index.cjs","names":["useMediaEditor","useCropGestureHandlers","RotationRuler","__"],"sources":["../../../src/components/media-editor-fine-rotation/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/**\n\t * Disable the ruler. Set while the edit is saving; `RotationRuler`\n\t * cancels an in-flight drag when this flips.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n * @param props.disabled\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n\tdisabled = false,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation, maxRotationOffset } =\n\t\tuseMediaEditor().imageEditor;\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a\n\t\t// 90° midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-maxRotationOffset + EPS,\n\t\t\tMath.min( maxRotationOffset - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"presentation\"\n\t\t\tclassName=\"media-editor-fine-rotation\"\n\t\t\t{ ...rotationGestureHandlers }\n\t\t>\n\t\t\t<RotationRuler\n\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\tmin={ -maxRotationOffset }\n\t\t\t\tmax={ maxRotationOffset }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\tdisabled={ disabled }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAwB,wBAAyB,EAChD,+BACA,WAAW,SACsB;CACjC,MAAM,EAAE,OAAO,aAAa,uBAAA,GAC3BA,qBAAAA,eAAAA,CAAe,CAAC,CAAC;CAIlB,MAAM,2BAAA,GAA0BC,yCAAAA,uBAAAA,CAAwB,EACvD,eAAe,MAChB,CAAE;CAKF,MAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;CAEtD,MAAM,YADa,MAAM,KAAK,eAAe,MAAM,KAAK,WACzB,KAAK;CACpC,MAAM,cAAe,MAAM,WAAW,aAAc;CAEpD,MAAM,wBAAyB,UAAmB;EAIjD,MAAM,MAAM;EACZ,MAAM,UAAU,KAAK,IACpB,CAAC,oBAAoB,KACrB,KAAK,IAAK,oBAAoB,KAAK,KAAM,CAC1C;EACA,gCAAgC;EAChC,YAAa,YAAY,UAAU,SAAU;CAC9C;CAEA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EACC,MAAK;EACL,WAAU;EACV,GAAK;EAEL,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,4BAAAA,SAAD;GACC,QAAA,GAAQC,gBAAAA,GAAAA,CAAI,eAAgB;GAC5B,KAAM,CAAC;GACP,KAAM;GACN,OAAQ;GACR,UAAW;GACA;EACX,CAAA;CACG,CAAA;AAEP"}