@wordpress/media-editor 0.17.0 → 0.17.2-next.v.202609031004.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 (53) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/build/components/media-editor/index.cjs +152 -133
  3. package/build/components/media-editor/index.cjs.map +3 -3
  4. package/build/components/media-editor-crop-panel/index.cjs +2 -3
  5. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  6. package/build/components/media-editor-modal/index.cjs +7 -21
  7. package/build/components/media-editor-modal/index.cjs.map +2 -2
  8. package/build-module/components/media-editor/index.mjs +154 -140
  9. package/build-module/components/media-editor/index.mjs.map +2 -2
  10. package/build-module/components/media-editor-crop-panel/index.mjs +2 -3
  11. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  12. package/build-module/components/media-editor-modal/index.mjs +9 -23
  13. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  14. package/build-style/style-rtl.css +66 -106
  15. package/build-style/style.css +66 -106
  16. package/build-types/components/media-editor/index.d.ts +7 -14
  17. package/build-types/components/media-editor/index.d.ts.map +1 -1
  18. package/build-types/components/media-editor-crop-panel/index.d.ts +4 -11
  19. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  20. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  21. package/package.json +21 -21
  22. package/src/components/media-editor/index.tsx +276 -200
  23. package/src/components/media-editor/style.scss +136 -134
  24. package/src/components/media-editor-crop-panel/index.tsx +4 -12
  25. package/src/components/media-editor-crop-panel/test/{index.tsx → index.jsdom.test.tsx} +2 -10
  26. package/src/components/media-editor-modal/index.tsx +9 -29
  27. package/src/components/media-editor-modal/style.scss +8 -49
  28. package/src/components/media-editor-modal/test/build-modifiers.test.ts +24 -14
  29. package/src/components/rotation-ruler/style.scss +1 -1
  30. package/src/image-editor/core/math/test/sanitize.ts +1 -0
  31. package/src/image-editor/core/test/camera.ts +2 -3
  32. package/src/image-editor/core/test/interaction-controller.ts +50 -40
  33. package/src/image-editor/core/test/preview-export-parity.ts +31 -23
  34. package/src/image-editor/core/test/render-camera-bridge.ts +1 -0
  35. package/src/image-editor/core/test/state.ts +1 -0
  36. package/src/image-editor/core/test/stencil-math.ts +1 -0
  37. package/src/image-editor/core/transforms/test/pipeline.ts +1 -0
  38. package/src/store/test/reducer.ts +9 -8
  39. package/tsconfig.build.json +1 -1
  40. package/tsconfig.build.tsbuildinfo +1 -1
  41. package/tsconfig.json +3 -3
  42. /package/src/components/media-editor/test/{use-crop-options.tsx → use-crop-options.jsdom.test.tsx} +0 -0
  43. /package/src/components/media-editor-image-controls/test/{index.tsx → index.jsdom.test.tsx} +0 -0
  44. /package/src/components/media-editor-modal/test/{index.tsx → index.jsdom.test.tsx} +0 -0
  45. /package/src/components/rotation-ruler/test/{index.tsx → index.jsdom.test.tsx} +0 -0
  46. /package/src/image-editor/core/export/test/{canvas-renderer.ts → canvas-renderer.jsdom.test.ts} +0 -0
  47. /package/src/image-editor/react/components/stencils/test/{rectangle-stencil.tsx → rectangle-stencil.jsdom.test.tsx} +0 -0
  48. /package/src/image-editor/react/components/test/{cropper.tsx → cropper.jsdom.test.tsx} +0 -0
  49. /package/src/image-editor/react/hooks/test/{use-aria-announcer.ts → use-aria-announcer.jsdom.test.ts} +0 -0
  50. /package/src/image-editor/react/hooks/test/{use-cropper-reducer.ts → use-cropper-reducer.jsdom.test.ts} +0 -0
  51. /package/src/image-editor/react/hooks/test/{use-interaction.ts → use-interaction.jsdom.test.ts} +0 -0
  52. /package/src/image-editor/react/hooks/test/{use-transform-style.ts → use-transform-style.jsdom.test.ts} +0 -0
  53. /package/src/state/test/{use-media-editor-state.ts → use-media-editor-state.jsdom.test.ts} +0 -0
@@ -47,8 +47,7 @@ var import_jsx_runtime = (
47
47
  function MediaEditorCropPanel({
48
48
  aspectRatioValue,
49
49
  onAspectRatioChange,
50
- aspectRatioOptions,
51
- showTransformControls = false
50
+ aspectRatioOptions
52
51
  }) {
53
52
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
54
53
  import_ui.Stack,
@@ -58,7 +57,7 @@ function MediaEditorCropPanel({
58
57
  ...{ [import_use_crop_gesture_handlers.CROP_CONTROL_ATTR]: true },
59
58
  children: [
60
59
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.VisuallyHidden, { render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {}), children: (0, import_i18n.__)("Crop options") }),
61
- showTransformControls && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor_image_controls.default, { withLabels: true }),
60
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor_image_controls.default, { withLabels: true }),
62
61
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
63
62
  import_components.SelectControl,
64
63
  {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/media-editor-crop-panel/index.tsx"],
4
- "sourcesContent": ["import { SelectControl } from '@wordpress/components';\nimport { Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorImageControls from '../media-editor-image-controls';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\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/**\n\t * When `true`, render the rotate/flip/zoom image controls at the top of\n\t * the panel. Used on wide viewports where the footer no longer carries\n\t * them.\n\t */\n\tshowTransformControls?: boolean;\n}\n\n/**\n * Sidebar panel for crop controls. Renders the aspect-ratio selector, plus the\n * rotate/flip and zoom controls on wide viewports (these move to the footer\n * toolbar when the sidebar collapses).\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.aspectRatioOptions\n * @param props.showTransformControls\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\taspectRatioOptions,\n\tshowTransformControls = false,\n}: MediaEditorCropPanelProps ) {\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{ showTransformControls && <MediaEditorImageControls withLabels /> }\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\tonChange={ onAspectRatioChange }\n\t\t\t\toptions={ aspectRatioOptions.map( ( preset ) => ( {\n\t\t\t\t\tlabel: preset.label,\n\t\t\t\t\tvalue: preset.value.toString(),\n\t\t\t\t} ) ) }\n\t\t\t/>\n\t\t</Stack>\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA8B;AAC9B,gBAAsC;AACtC,kBAAmB;AACnB,uCAAkC;AAClC,yCAAqC;AA0CnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAVa,SAAR,qBAAuC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA,wBAAwB;AACzB,GAA+B;AAC9B,SAIC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,KAAI;AAAA,MACF,GAAG,EAAE,CAAE,kDAAkB,GAAG,KAAK;AAAA,MAEnC;AAAA,oDAAC,4BAAe,QAAS,4CAAC,QAAG,GAC1B,8BAAI,cAAe,GACtB;AAAA,QACE,yBAAyB,4CAAC,mCAAAA,SAAA,EAAyB,YAAU,MAAC;AAAA,QAChE;AAAA,UAAC;AAAA;AAAA,YACA,WAAQ,gBAAI,cAAe;AAAA,YAC3B,OAAQ;AAAA,YACR,UAAW;AAAA,YACX,SAAU,mBAAmB,IAAK,CAAE,YAAc;AAAA,cACjD,OAAO,OAAO;AAAA,cACd,OAAO,OAAO,MAAM,SAAS;AAAA,YAC9B,EAAI;AAAA;AAAA,QACL;AAAA;AAAA;AAAA,EACD;AAEF;",
4
+ "sourcesContent": ["import { SelectControl } from '@wordpress/components';\nimport { Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorImageControls from '../media-editor-image-controls';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\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}\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 */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\taspectRatioOptions,\n}: MediaEditorCropPanelProps ) {\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 />\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\tonChange={ onAspectRatioChange }\n\t\t\t\toptions={ aspectRatioOptions.map( ( preset ) => ( {\n\t\t\t\t\tlabel: preset.label,\n\t\t\t\t\tvalue: preset.value.toString(),\n\t\t\t\t} ) ) }\n\t\t\t/>\n\t\t</Stack>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA8B;AAC9B,gBAAsC;AACtC,kBAAmB;AACnB,uCAAkC;AAClC,yCAAqC;AAkCnC;AAAA;AAAA;AAAA;AAAA;AAAA;AATa,SAAR,qBAAuC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AACD,GAA+B;AAC9B,SAIC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,KAAI;AAAA,MACF,GAAG,EAAE,CAAE,kDAAkB,GAAG,KAAK;AAAA,MAEnC;AAAA,oDAAC,4BAAe,QAAS,4CAAC,QAAG,GAC1B,8BAAI,cAAe,GACtB;AAAA,QACA,4CAAC,mCAAAA,SAAA,EAAyB,YAAU,MAAC;AAAA,QACrC;AAAA,UAAC;AAAA;AAAA,YACA,WAAQ,gBAAI,cAAe;AAAA,YAC3B,OAAQ;AAAA,YACR,UAAW;AAAA,YACX,SAAU,mBAAmB,IAAK,CAAE,YAAc;AAAA,cACjD,OAAO,OAAO;AAAA,cACd,OAAO,OAAO,MAAM,SAAS;AAAA,YAC9B,EAAI;AAAA;AAAA,QACL;AAAA;AAAA;AAAA,EACD;AAEF;",
6
6
  "names": ["MediaEditorImageControls"]
7
7
  }
@@ -41,31 +41,18 @@ var import_keyboard_shortcuts = require("@wordpress/keyboard-shortcuts");
41
41
  var import_notices = require("@wordpress/notices");
42
42
  var import_media_editor = __toESM(require("../media-editor/index.cjs"));
43
43
  var import_store = require("../../store/index.cjs");
44
- var import_jsx_runtime = (
45
- // Sidebar is a column: the image controls live in the Crop
46
- // panel, so the footer is just History + Cancel/Save.
47
- require("react/jsx-runtime")
48
- );
49
- function ModalFooter({ layout }) {
50
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
44
+ var import_jsx_runtime = require("react/jsx-runtime");
45
+ function ModalFooter() {
46
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
51
47
  "div",
52
48
  {
53
- className: `media-editor-modal__footer is-${layout}`,
49
+ className: "media-editor-modal__footer",
54
50
  role: "region",
55
51
  "aria-label": (0, import_i18n.__)("Editor actions"),
56
- children: layout === "wide" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
52
+ children: [
57
53
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor.default.HistoryActions, {}),
58
54
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor.default.SaveActions, {})
59
- ] }) : (
60
- // Sidebar collapsed: the image controls drop into the footer.
61
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
62
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor.default.ImageControls, {}),
63
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-modal__footer-row", children: [
64
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor.default.HistoryActions, {}),
65
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor.default.SaveActions, {})
66
- ] })
67
- ] })
68
- )
55
+ ]
69
56
  }
70
57
  );
71
58
  }
@@ -133,7 +120,6 @@ function MediaEditorModal({
133
120
  },
134
121
  renderFrame: ({
135
122
  children,
136
- layout,
137
123
  onRequestClose,
138
124
  onKeyDown,
139
125
  shouldCloseOnClickOutside
@@ -155,7 +141,7 @@ function MediaEditorModal({
155
141
  headerActions: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor.default.HeaderActions, { showCloseButton: true }),
156
142
  children: [
157
143
  children,
158
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalFooter, { layout })
144
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalFooter, {})
159
145
  ]
160
146
  }
161
147
  )
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/media-editor-modal/index.tsx"],
4
- "sourcesContent": ["import { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\ninterface ModalFooterProps {\n\tlayout: 'wide' | 'narrow';\n}\n\n/**\n * The modal's footer chrome. The fine-rotation ruler always lives under the\n * canvas (in `media-editor__content`), never here, so it stays constrained to\n * the canvas column at every viewport. One JSX tree per layout; DOM order\n * matches visual order.\n */\nfunction ModalFooter( { layout }: ModalFooterProps ) {\n\treturn (\n\t\t<div\n\t\t\tclassName={ `media-editor-modal__footer is-${ layout }` }\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t{ layout === 'wide' ? (\n\t\t\t\t// Sidebar is a column: the image controls live in the Crop\n\t\t\t\t// panel, so the footer is just History + Cancel/Save.\n\t\t\t\t<>\n\t\t\t\t\t<MediaEditor.HistoryActions />\n\t\t\t\t\t<MediaEditor.SaveActions />\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\t// Sidebar collapsed: the image controls drop into the footer.\n\t\t\t\t<>\n\t\t\t\t\t<MediaEditor.ImageControls />\n\t\t\t\t\t<div className=\"media-editor-modal__footer-row\">\n\t\t\t\t\t\t<MediaEditor.HistoryActions />\n\t\t\t\t\t\t<MediaEditor.SaveActions />\n\t\t\t\t\t</div>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onClose } = useSelect( ( select ) => {\n\t\tconst { isOpen, getId, getOnUpdate, getOnClose } =\n\t\t\tselect( mediaEditorStore );\n\t\treturn {\n\t\t\tisModalOpen: isOpen(),\n\t\t\tid: getId(),\n\t\t\tonUpdate: getOnUpdate(),\n\t\t\tonClose: getOnClose(),\n\t\t};\n\t}, [] );\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tonUpdate( {\n\t\t\t\t\t\t\t\t\t\tid: previous.id,\n\t\t\t\t\t\t\t\t\t\turl: previous.url,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\tlayout,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<ShortcutProvider\n\t\t\t\t\tclassName=\"media-editor-modal__shortcut-scope\"\n\t\t\t\t\tonKeyDown={ stopKeyDownPropagation }\n\t\t\t\t>\n\t\t\t\t\t<Modal\n\t\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\t\theaderActions={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter layout={ layout } />\n\t\t\t\t\t</Modal>\n\t\t\t\t</ShortcutProvider>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],
5
- "mappings": "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",
4
+ "sourcesContent": ["import { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\n/**\n * The modal's footer chrome. The fine-rotation ruler and the image controls\n * both live under the canvas (in `media-editor__content`), never here, so the\n * footer has one layout at every width: History on the left, Cancel/Save on\n * the right.\n */\nfunction ModalFooter() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"media-editor-modal__footer\"\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t<MediaEditor.HistoryActions />\n\t\t\t<MediaEditor.SaveActions />\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onClose } = useSelect( ( select ) => {\n\t\tconst { isOpen, getId, getOnUpdate, getOnClose } =\n\t\t\tselect( mediaEditorStore );\n\t\treturn {\n\t\t\tisModalOpen: isOpen(),\n\t\t\tid: getId(),\n\t\t\tonUpdate: getOnUpdate(),\n\t\t\tonClose: getOnClose(),\n\t\t};\n\t}, [] );\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tonUpdate( {\n\t\t\t\t\t\t\t\t\t\tid: previous.id,\n\t\t\t\t\t\t\t\t\t\turl: previous.url,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<ShortcutProvider\n\t\t\t\t\tclassName=\"media-editor-modal__shortcut-scope\"\n\t\t\t\t\tonKeyDown={ stopKeyDownPropagation }\n\t\t\t\t>\n\t\t\t\t\t<Modal\n\t\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\t\theaderActions={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter />\n\t\t\t\t\t</Modal>\n\t\t\t\t</ShortcutProvider>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAsB;AACtB,kBAAuC;AACvC,kBAAmB;AACnB,gCAAiC;AACjC,qBAAsC;AAGtC,0BAAwB;AAExB,mBAA0C;AA2BxC;AAFF,SAAS,cAAc;AACtB,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,MAAK;AAAA,MACL,kBAAa,gBAAI,gBAAiB;AAAA,MAElC;AAAA,oDAAC,oBAAAA,QAAY,gBAAZ,EAA2B;AAAA,QAC5B,4CAAC,oBAAAA,QAAY,aAAZ,EAAwB;AAAA;AAAA;AAAA,EAC1B;AAEF;AAEO,SAAS,iBAAkB;AAAA,EACjC,SAAS,CAAC;AAAA,EACV;AACD,GAA2B;AAC1B,QAAM,EAAE,aAAa,IAAI,UAAU,QAAQ,QAAI,uBAAW,CAAE,WAAY;AACvE,UAAM,EAAE,QAAQ,OAAO,aAAa,WAAW,IAC9C,OAAQ,aAAAC,KAAiB;AAC1B,WAAO;AAAA,MACN,aAAa,OAAO;AAAA,MACpB,IAAI,MAAM;AAAA,MACV,UAAU,YAAY;AAAA,MACtB,SAAS,WAAW;AAAA,IACrB;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,EAAE,sBAAsB,QAAI,yBAAa,aAAAA,KAAiB;AAChE,QAAM,EAAE,oBAAoB,QAAI,yBAAa,eAAAC,KAAa;AAE1D,MAAK,CAAE,eAAe,CAAE,IAAK;AAC5B,WAAO;AAAA,EACR;AAEA,QAAM,gBACL,OAAO,aAAa,cAAc,OAAO,SAAS;AAMnD,QAAM,yBAAyB,CAC9B,UACI;AACJ,UAAM,gBAAgB;AAAA,EACvB;AAEA,QAAM,cAAc,MAAM;AACzB,0BAAsB;AACtB,cAAU;AAAA,EACX;AAEA,SACC;AAAA,IAAC,oBAAAF;AAAA,IAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,kBAAgB;AAAA,MAChB,kBAAiB;AAAA,MACjB,sBAAuB;AAAA,MACvB,SAAU;AAAA,MACV,SAAU,CAAE,EAAE,IAAI,SAAS,KAAK,SAAS,MAAO;AAC/C,YAAK,WAAW,UAAW;AAC1B,gBAAM,SAAiC;AAAA,YACtC,IAAI;AAAA,YACJ;AAAA,UACD;AACA,mBAAU,MAAO;AAAA,QAClB;AACA,oBAAY;AACZ,YAAK,YAAY,YAAY,SAAS,MAAM,UAAW;AAItD,kCAAqB,gBAAI,eAAgB,GAAG;AAAA,YAC3C,MAAM;AAAA,YACN,SAAS;AAAA,cACR;AAAA,gBACC,WAAO,gBAAI,MAAO;AAAA,gBAClB,SAAS,MAAM;AACd,2BAAU;AAAA,oBACT,IAAI,SAAS;AAAA,oBACb,KAAK,SAAS;AAAA,kBACf,CAAE;AAAA,gBACH;AAAA,cACD;AAAA,YACD;AAAA,UACD,CAAE;AAAA,QACH;AAAA,MACD;AAAA,MACA,aAAc,CAAE;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD,MACC;AAAA,QAAC;AAAA;AAAA,UACA,WAAU;AAAA,UACV,WAAY;AAAA,UAEZ;AAAA,YAAC;AAAA;AAAA,cACA,WAAU;AAAA,cACV,WAAQ,gBAAI,YAAa;AAAA,cACzB,MAAK;AAAA,cACL,eAAgB;AAAA,cAChB;AAAA,cACA;AAAA,cACA;AAAA,cACA,eACC,4CAAC,oBAAAA,QAAY,eAAZ,EAA0B,iBAAe,MAAC;AAAA,cAG1C;AAAA;AAAA,gBACF,4CAAC,eAAY;AAAA;AAAA;AAAA,UACd;AAAA;AAAA,MACD;AAAA;AAAA,EAEF;AAEF;AAEA,IAAO,6BAAQ;",
6
6
  "names": ["MediaEditor", "mediaEditorStore", "noticesStore"]
7
7
  }
@@ -1,20 +1,21 @@
1
1
  // packages/media-editor/src/components/media-editor/index.tsx
2
+ import clsx from "clsx";
2
3
  import {
3
4
  Button,
4
5
  Spinner,
5
6
  __experimentalConfirmDialog as ConfirmDialog
6
7
  } from "@wordpress/components";
7
- import { Stack, Tabs } from "@wordpress/ui";
8
+ import { Stack, Tabs, VisuallyHidden } from "@wordpress/ui";
8
9
  import { useViewportMatch } from "@wordpress/compose";
9
10
  import { useDispatch, useSelect } from "@wordpress/data";
10
11
  import { store as coreStore } from "@wordpress/core-data";
12
+ import { NavigableRegion } from "@wordpress/admin-ui";
11
13
  import {
12
14
  createContext,
13
15
  createPortal,
14
16
  useCallback,
15
17
  useContext,
16
18
  useEffect,
17
- useMemo,
18
19
  useRef,
19
20
  useState
20
21
  } from "@wordpress/element";
@@ -26,17 +27,12 @@ import {
26
27
  isKeyboardEvent
27
28
  } from "@wordpress/keycodes";
28
29
  import { SnackbarNotices, store as noticesStore } from "@wordpress/notices";
29
- import {
30
- ComplementaryArea,
31
- InterfaceSkeleton,
32
- PinnedItems
33
- } from "@wordpress/interface";
34
30
  import { MediaEditorProvider } from "../media-editor-provider/index.mjs";
35
31
  import MediaPreview from "../media-preview/index.mjs";
36
32
  import MediaEditorCanvas from "../media-editor-canvas/index.mjs";
37
33
  import MediaEditorFineRotation from "../media-editor-fine-rotation/index.mjs";
38
- import MediaEditorImageControls from "../media-editor-image-controls/index.mjs";
39
34
  import MediaEditorCropPanel from "../media-editor-crop-panel/index.mjs";
35
+ import MediaEditorImageControls from "../media-editor-image-controls/index.mjs";
40
36
  import MediaForm from "../media-form/index.mjs";
41
37
  import { getMediaTypeFromMimeType } from "../../utils/index.mjs";
42
38
  import { MediaEditorStateProvider, useMediaEditor } from "../../state/index.mjs";
@@ -47,36 +43,45 @@ import {
47
43
  useSaveMediaEditor
48
44
  } from "./use-save-media-editor.mjs";
49
45
  import { useCropOptions } from "./use-crop-options.mjs";
50
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
46
+ import { jsx, jsxs } from "react/jsx-runtime";
51
47
  var ATTACHMENT_EMBED_QUERY = { _embed: "author,wp:attached-to" };
52
48
  var PLACEMENT_CONTROL_IDLE_MS = 300;
49
+ var DETAILS_PANEL = "details";
50
+ var CROP_PANEL = "crop";
53
51
  function MediaEditorSidebar({
54
52
  tabs,
55
- activeTabId,
56
- onTabChange,
57
- scope
53
+ activeTab,
54
+ onSelectTab
58
55
  }) {
59
- return /* @__PURE__ */ jsx(
60
- ComplementaryArea,
56
+ return /* @__PURE__ */ jsxs(
57
+ NavigableRegion,
61
58
  {
62
- scope,
63
- identifier: "media-editor/details",
64
- title: __("Details"),
65
- icon: drawerRight,
66
- isActiveByDefault: true,
67
59
  className: "media-editor__sidebar",
68
- panelClassName: "media-editor__sidebar-panel",
69
- headerClassName: "media-editor__sidebar-header",
70
- closeLabel: __("Close media panel"),
71
- render: /* @__PURE__ */ jsx(
72
- Tabs.Root,
73
- {
74
- value: activeTabId,
75
- onValueChange: (value) => onTabChange(value)
76
- }
77
- ),
78
- header: /* @__PURE__ */ jsx(Tabs.List, { variant: "minimal", children: tabs.map((tab) => /* @__PURE__ */ jsx(Tabs.Tab, { value: tab.id, children: tab.title }, tab.id)) }),
79
- children: tabs.map((tab) => /* @__PURE__ */ jsx(Tabs.Panel, { value: tab.id, tabIndex: -1, children: tab.panel }, tab.id))
60
+ ariaLabel: __("Media settings"),
61
+ children: [
62
+ /* @__PURE__ */ jsx(VisuallyHidden, { render: /* @__PURE__ */ jsx("h2", {}), children: __("Media settings") }),
63
+ /* @__PURE__ */ jsxs(
64
+ Tabs.Root,
65
+ {
66
+ className: "media-editor__tabs",
67
+ value: activeTab,
68
+ onValueChange: onSelectTab,
69
+ children: [
70
+ /* @__PURE__ */ jsx("div", { className: "media-editor__tablist", children: /* @__PURE__ */ jsx(Tabs.List, { variant: "minimal", children: tabs.map((tab) => /* @__PURE__ */ jsx(Tabs.Tab, { value: tab.id, children: tab.title }, tab.id)) }) }),
71
+ tabs.map((tab) => /* @__PURE__ */ jsx(
72
+ Tabs.Panel,
73
+ {
74
+ value: tab.id,
75
+ tabIndex: -1,
76
+ className: "media-editor__panel",
77
+ children: /* @__PURE__ */ jsx(Stack, { direction: "column", gap: "lg", children: tab.render() })
78
+ },
79
+ tab.id
80
+ ))
81
+ ]
82
+ }
83
+ )
84
+ ]
80
85
  }
81
86
  );
82
87
  }
@@ -91,7 +96,8 @@ function useMediaEditorFrameContext() {
91
96
  return context;
92
97
  }
93
98
  function HeaderActions({ showCloseButton = false }) {
94
- const { isImage, isSaving, onCancel, scope } = useMediaEditorFrameContext();
99
+ const { isImage, isSaving, onCancel, isWide, activePanel, onTogglePanel } = useMediaEditorFrameContext();
100
+ const isPanelOpen = !!activePanel;
95
101
  const [isShortcutsModalOpen, setIsShortcutsModalOpen] = useState(false);
96
102
  return /* @__PURE__ */ jsxs(
97
103
  Stack,
@@ -110,7 +116,17 @@ function HeaderActions({ showCloseButton = false }) {
110
116
  onClick: () => setIsShortcutsModalOpen(true)
111
117
  }
112
118
  ),
113
- /* @__PURE__ */ jsx(PinnedItems.Slot, { scope }),
119
+ /* @__PURE__ */ jsx(
120
+ Button,
121
+ {
122
+ size: "compact",
123
+ icon: drawerRight,
124
+ label: __("Media settings"),
125
+ isPressed: isPanelOpen,
126
+ "aria-expanded": isWide ? isPanelOpen : void 0,
127
+ onClick: onTogglePanel
128
+ }
129
+ ),
114
130
  showCloseButton && /* @__PURE__ */ jsx(
115
131
  Button,
116
132
  {
@@ -133,7 +149,7 @@ function HeaderActions({ showCloseButton = false }) {
133
149
  );
134
150
  }
135
151
  function HistoryActions() {
136
- const { isImage, isUndoRedoDisabled, onReset } = useMediaEditorFrameContext();
152
+ const { isImage, isUndoRedoDisabled, onReset, isWide, activePanel } = useMediaEditorFrameContext();
137
153
  const {
138
154
  reset,
139
155
  isDirty,
@@ -144,7 +160,7 @@ function HistoryActions() {
144
160
  beginGesture,
145
161
  endGesture
146
162
  } = useMediaEditor();
147
- if (!isImage) {
163
+ if (!isImage || !isWide && !!activePanel) {
148
164
  return null;
149
165
  }
150
166
  const handleUndo = () => {
@@ -253,19 +269,6 @@ function SaveActions({ size = "default" }) {
253
269
  }
254
270
  );
255
271
  }
256
- function ImageControls() {
257
- const { isImage, aspectRatioPresets } = useMediaEditorFrameContext();
258
- if (!isImage) {
259
- return null;
260
- }
261
- return /* @__PURE__ */ jsx(
262
- MediaEditorImageControls,
263
- {
264
- showAspectRatioControl: true,
265
- aspectRatioPresets
266
- }
267
- );
268
- }
269
272
  function MediaEditorContent({
270
273
  fields = [],
271
274
  id,
@@ -275,12 +278,26 @@ function MediaEditorContent({
275
278
  renderFrame,
276
279
  noticesClassName = "media-editor__snackbar",
277
280
  noticesPortalElement,
278
- shouldCloseOnEsc = false,
279
- scope = "media-editor"
281
+ shouldCloseOnEsc = false
280
282
  }) {
281
283
  const cropper = useMediaEditor();
282
- const isPanelLayout = useViewportMatch("small");
283
- const layout = isPanelLayout ? "wide" : "narrow";
284
+ const isWide = useViewportMatch("small");
285
+ const [activePanel, setActivePanel] = useState(
286
+ isWide ? DETAILS_PANEL : null
287
+ );
288
+ const hasChosenPanelRef = useRef(false);
289
+ const lastPanelRef = useRef(DETAILS_PANEL);
290
+ const hasChosenTabRef = useRef(false);
291
+ const selectPanel = useCallback((panel) => {
292
+ hasChosenTabRef.current = true;
293
+ lastPanelRef.current = panel;
294
+ setActivePanel(panel);
295
+ }, []);
296
+ const togglePanel = useCallback(() => {
297
+ hasChosenPanelRef.current = true;
298
+ setActivePanel((open) => open ? null : lastPanelRef.current);
299
+ }, []);
300
+ const layout = isWide ? "wide" : "narrow";
284
301
  const { media, hasEdits } = useSelect(
285
302
  (select) => {
286
303
  const {
@@ -349,14 +366,24 @@ function MediaEditorContent({
349
366
  }, [id, invalidateResolution]);
350
367
  const mediaType = getMediaTypeFromMimeType(media?.mime_type).type;
351
368
  const isImage = !!media && mediaType === "image";
369
+ useEffect(() => {
370
+ if (hasChosenPanelRef.current && hasChosenTabRef.current) {
371
+ return;
372
+ }
373
+ const defaultPanel = isWide && isImage ? CROP_PANEL : DETAILS_PANEL;
374
+ if (!hasChosenTabRef.current) {
375
+ lastPanelRef.current = defaultPanel;
376
+ }
377
+ if (!hasChosenPanelRef.current) {
378
+ setActivePanel(isWide ? lastPanelRef.current : null);
379
+ }
380
+ }, [isWide, isImage]);
352
381
  const {
353
382
  aspectRatioValue,
354
383
  setAspectRatioValue,
355
384
  aspectRatioOptions,
356
385
  resetCropOptions
357
- } = useCropOptions({
358
- aspectRatioPresets
359
- });
386
+ } = useCropOptions({ aspectRatioPresets });
360
387
  const { isSaving, save: saveMediaEditor } = useSaveMediaEditor({
361
388
  cropper,
362
389
  id,
@@ -364,56 +391,6 @@ function MediaEditorContent({
364
391
  media,
365
392
  onSaved
366
393
  });
367
- const tabs = useMemo(() => {
368
- const detailsTab = {
369
- id: "details",
370
- title: __("Details"),
371
- panel: /* @__PURE__ */ jsx(
372
- Stack,
373
- {
374
- className: "media-editor__panel",
375
- direction: "column",
376
- gap: "lg",
377
- children: /* @__PURE__ */ jsx(MediaForm, {})
378
- }
379
- )
380
- };
381
- if (!isImage) {
382
- return [detailsTab];
383
- }
384
- return [
385
- {
386
- id: "crop",
387
- title: __("Crop"),
388
- panel: /* @__PURE__ */ jsx(
389
- Stack,
390
- {
391
- className: "media-editor__panel",
392
- direction: "column",
393
- gap: "lg",
394
- children: /* @__PURE__ */ jsx(
395
- MediaEditorCropPanel,
396
- {
397
- aspectRatioValue,
398
- onAspectRatioChange: setAspectRatioValue,
399
- aspectRatioOptions,
400
- showTransformControls: isPanelLayout
401
- }
402
- )
403
- }
404
- )
405
- },
406
- detailsTab
407
- ];
408
- }, [
409
- isImage,
410
- aspectRatioValue,
411
- setAspectRatioValue,
412
- aspectRatioOptions,
413
- isPanelLayout
414
- ]);
415
- const [selectedTabId, setSelectedTabId] = useState();
416
- const activeTabId = selectedTabId ?? tabs[0]?.id;
417
394
  const handleChange = (updates) => {
418
395
  editEntityRecord("postType", "attachment", id, updates);
419
396
  };
@@ -471,6 +448,34 @@ function MediaEditorContent({
471
448
  context: MEDIA_EDITOR_NOTICES_CONTEXT
472
449
  }
473
450
  );
451
+ const imageControls = isImage && !isWide ? /* @__PURE__ */ jsx(
452
+ MediaEditorImageControls,
453
+ {
454
+ showAspectRatioControl: true,
455
+ aspectRatioPresets
456
+ }
457
+ ) : null;
458
+ const tabs = [
459
+ ...isImage ? [
460
+ {
461
+ id: CROP_PANEL,
462
+ title: __("Crop"),
463
+ render: () => /* @__PURE__ */ jsx(
464
+ MediaEditorCropPanel,
465
+ {
466
+ aspectRatioValue,
467
+ onAspectRatioChange: setAspectRatioValue,
468
+ aspectRatioOptions
469
+ }
470
+ )
471
+ }
472
+ ] : [],
473
+ {
474
+ id: DETAILS_PANEL,
475
+ title: __("Details"),
476
+ render: () => /* @__PURE__ */ jsx(MediaForm, {})
477
+ }
478
+ ];
474
479
  const ruler = isImage ? /* @__PURE__ */ jsx(
475
480
  MediaEditorFineRotation,
476
481
  {
@@ -484,39 +489,47 @@ function MediaEditorContent({
484
489
  onChange: handleChange,
485
490
  settings: { fields },
486
491
  children: [
487
- /* @__PURE__ */ jsx("div", { className: "media-editor", children: !media ? /* @__PURE__ */ jsx("div", { className: "media-editor__loading", children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
488
- /* @__PURE__ */ jsx(
489
- MediaEditorSidebar,
490
- {
491
- tabs,
492
- activeTabId,
493
- onTabChange: setSelectedTabId,
494
- scope
495
- }
496
- ),
497
- /* @__PURE__ */ jsx(
498
- InterfaceSkeleton,
499
- {
500
- className: "media-editor__skeleton",
501
- labels: {
502
- body: isImage ? __("Image editor") : __("Media preview"),
503
- sidebar: __("Media details")
504
- },
505
- content: /* @__PURE__ */ jsxs("div", { className: "media-editor__content", children: [
506
- /* @__PURE__ */ jsx("div", { className: "media-editor__canvas-area", children: isImage ? /* @__PURE__ */ jsx(
507
- MediaEditorCanvas,
508
- {
509
- isPlacementActive,
510
- onGestureStart: handleCanvasGestureStart,
511
- onGestureEnd: handleCanvasGestureEnd
512
- }
513
- ) : /* @__PURE__ */ jsx(MediaPreview, {}) }),
514
- isImage && /* @__PURE__ */ jsx("div", { className: "media-editor__canvas-toolbar", children: ruler })
515
- ] }),
516
- sidebar: /* @__PURE__ */ jsx(ComplementaryArea.Slot, { scope })
517
- }
518
- )
519
- ] }) }),
492
+ /* @__PURE__ */ jsx("div", { className: "media-editor", children: !media ? /* @__PURE__ */ jsx("div", { className: "media-editor__loading", children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsxs(
493
+ "div",
494
+ {
495
+ className: clsx("media-editor__body", {
496
+ "has-panel-open": !!activePanel
497
+ }),
498
+ children: [
499
+ /* @__PURE__ */ jsxs(
500
+ NavigableRegion,
501
+ {
502
+ className: "media-editor__content",
503
+ ariaLabel: isImage ? __("Image editor") : __("Media preview"),
504
+ children: [
505
+ /* @__PURE__ */ jsx("div", { className: "media-editor__canvas-area", children: isImage ? /* @__PURE__ */ jsx(
506
+ MediaEditorCanvas,
507
+ {
508
+ isPlacementActive,
509
+ onGestureStart: handleCanvasGestureStart,
510
+ onGestureEnd: handleCanvasGestureEnd
511
+ }
512
+ ) : /* @__PURE__ */ jsx(MediaPreview, {}) }),
513
+ isImage && /* @__PURE__ */ jsxs("div", { className: "media-editor__canvas-toolbar", children: [
514
+ ruler,
515
+ imageControls
516
+ ] })
517
+ ]
518
+ }
519
+ ),
520
+ !!activePanel && /* @__PURE__ */ jsx(
521
+ MediaEditorSidebar,
522
+ {
523
+ tabs,
524
+ activeTab: tabs.some(
525
+ (tab) => tab.id === activePanel
526
+ ) ? activePanel : DETAILS_PANEL,
527
+ onSelectTab: selectPanel
528
+ }
529
+ )
530
+ ]
531
+ }
532
+ ) }),
520
533
  /* @__PURE__ */ jsx(
521
534
  ConfirmDialog,
522
535
  {
@@ -543,8 +556,10 @@ function MediaEditorContent({
543
556
  hasMedia: !!media,
544
557
  hasChanges,
545
558
  isUndoRedoDisabled: isCropInteractionActive,
546
- scope,
547
559
  aspectRatioPresets,
560
+ isWide,
561
+ activePanel,
562
+ onTogglePanel: togglePanel,
548
563
  onCancel: handleRequestClose,
549
564
  onSave: saveMediaEditor,
550
565
  onReset: resetCropOptions
@@ -567,7 +582,6 @@ function MediaEditor(props) {
567
582
  MediaEditor.HeaderActions = HeaderActions;
568
583
  MediaEditor.HistoryActions = HistoryActions;
569
584
  MediaEditor.SaveActions = SaveActions;
570
- MediaEditor.ImageControls = ImageControls;
571
585
  var media_editor_default = MediaEditor;
572
586
  export {
573
587
  MediaEditor,