@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
@@ -1,19 +1,20 @@
1
+ import clsx from 'clsx';
1
2
  import {
2
3
  Button,
3
4
  Spinner,
4
5
  __experimentalConfirmDialog as ConfirmDialog,
5
6
  } from '@wordpress/components';
6
- import { Stack, Tabs } from '@wordpress/ui';
7
+ import { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';
7
8
  import { useViewportMatch } from '@wordpress/compose';
8
9
  import { useDispatch, useSelect } from '@wordpress/data';
9
10
  import { store as coreStore } from '@wordpress/core-data';
11
+ import { NavigableRegion } from '@wordpress/admin-ui';
10
12
  import {
11
13
  createContext,
12
14
  createPortal,
13
15
  useCallback,
14
16
  useContext,
15
17
  useEffect,
16
- useMemo,
17
18
  useRef,
18
19
  useState,
19
20
  } from '@wordpress/element';
@@ -26,20 +27,14 @@ import {
26
27
  } from '@wordpress/keycodes';
27
28
  import { SnackbarNotices, store as noticesStore } from '@wordpress/notices';
28
29
  import type { Field } from '@wordpress/dataviews';
29
- import {
30
- ComplementaryArea,
31
- InterfaceSkeleton,
32
- PinnedItems,
33
- // @ts-expect-error `@wordpress/interface` is not typed yet.
34
- } from '@wordpress/interface';
35
30
  import type { KeyboardEvent as ReactKeyboardEvent, ReactNode } from 'react';
36
31
  import { MediaEditorProvider } from '../media-editor-provider';
37
32
  import type { Media } from '../media-editor-provider';
38
33
  import MediaPreview from '../media-preview';
39
34
  import MediaEditorCanvas from '../media-editor-canvas';
40
35
  import MediaEditorFineRotation from '../media-editor-fine-rotation';
41
- import MediaEditorImageControls from '../media-editor-image-controls';
42
36
  import MediaEditorCropPanel from '../media-editor-crop-panel';
37
+ import MediaEditorImageControls from '../media-editor-image-controls';
43
38
  import MediaForm from '../media-form';
44
39
  import { getMediaTypeFromMimeType } from '../../utils';
45
40
  import { MediaEditorStateProvider, useMediaEditor } from '../../state';
@@ -62,10 +57,21 @@ const ATTACHMENT_EMBED_QUERY = { _embed: 'author,wp:attached-to' } as const;
62
57
 
63
58
  const PLACEMENT_CONTROL_IDLE_MS = 300;
64
59
 
65
- interface EditorTab {
60
+ /**
61
+ * Identifier for the details panel, and the panel the sidebar opens on before
62
+ * the user picks another. The sidebar tracks which panel is open rather than
63
+ * whether one is, so a further panel is a new id here and a new entry in the
64
+ * tab list — not a change to the state's shape.
65
+ */
66
+ const DETAILS_PANEL = 'details';
67
+
68
+ /** Identifier for the crop panel. Images only; other media has nothing to crop. */
69
+ const CROP_PANEL = 'crop';
70
+
71
+ interface MediaEditorTab {
66
72
  id: string;
67
73
  title: string;
68
- panel: JSX.Element;
74
+ render: () => JSX.Element;
69
75
  }
70
76
 
71
77
  export interface MediaEditorFrameProps {
@@ -77,6 +83,13 @@ export interface MediaEditorFrameProps {
77
83
  * all.
78
84
  */
79
85
  isImage: boolean;
86
+ /**
87
+ * `narrow` below the `small` breakpoint, where the frame's header has no
88
+ * room for the history cluster beside its other controls. A frame uses
89
+ * this to place that cluster, not to decide whether it renders —
90
+ * `HistoryActions` returns nothing on its own when the canvas is off
91
+ * screen.
92
+ */
80
93
  layout: 'wide' | 'narrow';
81
94
  onRequestClose: () => void;
82
95
  onKeyDown: ( event: ReactKeyboardEvent< HTMLElement > ) => void;
@@ -96,70 +109,66 @@ export interface MediaEditorProps {
96
109
  noticesClassName?: string;
97
110
  noticesPortalElement?: Element | null;
98
111
  shouldCloseOnEsc?: boolean;
99
- /**
100
- * The `@wordpress/interface` scope for the details sidebar and its pinned
101
- * items. Frames should pass a distinct scope so that sidebar visibility —
102
- * which is persisted per scope to user meta — is remembered separately for
103
- * each surface. The modal is a transient surface where a collapsed sidebar
104
- * is a reasonable choice; the full-screen route is one where the sidebar is
105
- * the primary metadata surface and should open by default. Sharing a scope
106
- * would let a choice made in one decide the other's starting state.
107
- *
108
- * @default 'media-editor'
109
- */
110
- scope?: string;
111
112
  }
112
113
 
113
114
  interface MediaEditorSidebarProps {
114
- tabs: EditorTab[];
115
- activeTabId?: string;
116
- onTabChange: ( tabId: string ) => void;
117
- scope: string;
115
+ tabs: MediaEditorTab[];
116
+ /** The open panel's id. Always one of `tabs`. */
117
+ activeTab: string;
118
+ onSelectTab: ( tab: string ) => void;
118
119
  }
119
120
 
120
121
  function MediaEditorSidebar( {
121
122
  tabs,
122
- activeTabId,
123
- onTabChange,
124
- scope,
123
+ activeTab,
124
+ onSelectTab,
125
125
  }: MediaEditorSidebarProps ) {
126
126
  return (
127
- <ComplementaryArea
128
- scope={ scope }
129
- identifier="media-editor/details"
130
- title={ __( 'Details' ) }
131
- icon={ drawerRight }
132
- isActiveByDefault
127
+ <NavigableRegion
133
128
  className="media-editor__sidebar"
134
- panelClassName="media-editor__sidebar-panel"
135
- headerClassName="media-editor__sidebar-header"
136
- closeLabel={ __( 'Close media panel' ) }
137
- // Makes `Tabs.Root` the container, so the tab list passed as
138
- // `header` and the panels below share a subtree across the fill.
139
- render={
140
- <Tabs.Root
141
- value={ activeTabId }
142
- onValueChange={ ( value ) =>
143
- onTabChange( value as string )
144
- }
145
- />
146
- }
147
- header={
148
- <Tabs.List variant="minimal">
149
- { tabs.map( ( tab ) => (
150
- <Tabs.Tab key={ tab.id } value={ tab.id }>
151
- { tab.title }
152
- </Tabs.Tab>
153
- ) ) }
154
- </Tabs.List>
155
- }
129
+ ariaLabel={ __( 'Media settings' ) }
156
130
  >
157
- { tabs.map( ( tab ) => (
158
- <Tabs.Panel key={ tab.id } value={ tab.id } tabIndex={ -1 }>
159
- { tab.panel }
160
- </Tabs.Panel>
161
- ) ) }
162
- </ComplementaryArea>
131
+ { /* No visible heading and no close button: the strip below names
132
+ the open panel and the header's pressed toggle dismisses it.
133
+ The heading stays for screen readers, which read neither as
134
+ this region's title. */ }
135
+ <VisuallyHidden render={ <h2 /> }>
136
+ { __( 'Media settings' ) }
137
+ </VisuallyHidden>
138
+ <Tabs.Root
139
+ className="media-editor__tabs"
140
+ value={ activeTab }
141
+ onValueChange={ onSelectTab }
142
+ >
143
+ { /* `Tabs.List` sizes itself to its tabs (`width: fit-content`),
144
+ so the rule under the strip is drawn by this wrapper
145
+ instead, which spans the column. */ }
146
+ <div className="media-editor__tablist">
147
+ <Tabs.List variant="minimal">
148
+ { tabs.map( ( tab ) => (
149
+ <Tabs.Tab key={ tab.id } value={ tab.id }>
150
+ { tab.title }
151
+ </Tabs.Tab>
152
+ ) ) }
153
+ </Tabs.List>
154
+ </div>
155
+ { /* One `Tabs.Panel` per tab: the counts have to match or
156
+ `Tabs.Root` throws in dev. Only the active one paints
157
+ anything — the rest render nothing. */ }
158
+ { tabs.map( ( tab ) => (
159
+ <Tabs.Panel
160
+ key={ tab.id }
161
+ value={ tab.id }
162
+ tabIndex={ -1 }
163
+ className="media-editor__panel"
164
+ >
165
+ <Stack direction="column" gap="lg">
166
+ { tab.render() }
167
+ </Stack>
168
+ </Tabs.Panel>
169
+ ) ) }
170
+ </Tabs.Root>
171
+ </NavigableRegion>
163
172
  );
164
173
  }
165
174
 
@@ -175,8 +184,16 @@ interface MediaEditorFrameContextValue {
175
184
  hasMedia: boolean;
176
185
  hasChanges: boolean;
177
186
  isUndoRedoDisabled: boolean;
178
- scope: string;
179
187
  aspectRatioPresets?: AspectRatioPreset[];
188
+ /** `true` above `large`, where the panel docks beside the canvas. */
189
+ isWide: boolean;
190
+ /** The open panel's id, or `null` when none is. */
191
+ activePanel: string | null;
192
+ /**
193
+ * Opens the sidebar on the last-shown panel, or closes it when one is
194
+ * already open.
195
+ */
196
+ onTogglePanel: () => void;
180
197
  onCancel: () => void;
181
198
  onSave: () => void;
182
199
  onReset: () => void;
@@ -213,7 +230,9 @@ export interface HeaderActionsProps {
213
230
  }
214
231
 
215
232
  function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
216
- const { isImage, isSaving, onCancel, scope } = useMediaEditorFrameContext();
233
+ const { isImage, isSaving, onCancel, isWide, activePanel, onTogglePanel } =
234
+ useMediaEditorFrameContext();
235
+ const isPanelOpen = !! activePanel;
217
236
  const [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );
218
237
  return (
219
238
  <Stack
@@ -230,7 +249,21 @@ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
230
249
  onClick={ () => setIsShortcutsModalOpen( true ) }
231
250
  />
232
251
  ) }
233
- <PinnedItems.Slot scope={ scope } />
252
+ { /* The sidebar holds more than one panel, so this opens and
253
+ closes the sidebar rather than naming a panel: reopening
254
+ returns to whichever tab was last showing, and the tab strip
255
+ inside switches between them. */ }
256
+ <Button
257
+ size="compact"
258
+ icon={ drawerRight }
259
+ label={ __( 'Media settings' ) }
260
+ isPressed={ isPanelOpen }
261
+ // Only a docked column really expands beside the canvas; below
262
+ // that the panel replaces the view, which the pressed state
263
+ // already describes.
264
+ aria-expanded={ isWide ? isPanelOpen : undefined }
265
+ onClick={ onTogglePanel }
266
+ />
234
267
  { showCloseButton && (
235
268
  <Button
236
269
  size="compact"
@@ -251,7 +284,7 @@ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
251
284
  }
252
285
 
253
286
  function HistoryActions() {
254
- const { isImage, isUndoRedoDisabled, onReset } =
287
+ const { isImage, isUndoRedoDisabled, onReset, isWide, activePanel } =
255
288
  useMediaEditorFrameContext();
256
289
  const {
257
290
  reset,
@@ -263,9 +296,15 @@ function HistoryActions() {
263
296
  beginGesture,
264
297
  endGesture,
265
298
  } = useMediaEditor();
266
- // Non-image media has no edit history. Checked after the hooks above so
267
- // the hook order stays stable across renders.
268
- if ( ! isImage ) {
299
+ // Reset, undo and redo act on the cropper, so they only appear where the
300
+ // canvas does. Non-image media has no edit history at all; below the dock
301
+ // breakpoint an open panel replaces the canvas, and leaving these behind
302
+ // would put an enabled, destructive Reset next to metadata fields it does
303
+ // not touch — clicking it would discard a crop the user cannot see.
304
+ // (Metadata edits have no undo of their own; a history spanning both is a
305
+ // larger change than hiding these.) Checked after the hooks above so the
306
+ // hook order stays stable across renders.
307
+ if ( ! isImage || ( ! isWide && !! activePanel ) ) {
269
308
  return null;
270
309
  }
271
310
  const handleUndo = () => {
@@ -375,22 +414,6 @@ function SaveActions( { size = 'default' }: SaveActionsProps ) {
375
414
  );
376
415
  }
377
416
 
378
- function ImageControls() {
379
- const { isImage, aspectRatioPresets } = useMediaEditorFrameContext();
380
- // Non-image media has nothing to transform. Placement is the frame's call:
381
- // render this only in the `narrow` layout, since above that breakpoint the
382
- // Crop panel holds these controls already.
383
- if ( ! isImage ) {
384
- return null;
385
- }
386
- return (
387
- <MediaEditorImageControls
388
- showAspectRatioControl
389
- aspectRatioPresets={ aspectRatioPresets }
390
- />
391
- );
392
- }
393
-
394
417
  function MediaEditorContent( {
395
418
  fields = [],
396
419
  id,
@@ -401,19 +424,55 @@ function MediaEditorContent( {
401
424
  noticesClassName = 'media-editor__snackbar',
402
425
  noticesPortalElement,
403
426
  shouldCloseOnEsc = false,
404
- scope = 'media-editor',
405
427
  }: MediaEditorProps ) {
406
428
  const cropper = useMediaEditor();
407
- // The sidebar is a side column from the `small` breakpoint up and collapses
408
- // to an overlay below it — mirroring InterfaceSkeleton's behaviour, shifted
409
- // from `medium` to `small` (see the matching CSS overrides in style.scss).
410
- // Track that single breakpoint: in "panel mode" (≥ small) the
411
- // rotate/flip/zoom controls live in the Crop panel; below it they have no
412
- // panel to live in and the frame places them instead. (The fine-rotation
413
- // ruler always sits under the canvas.)
414
- const isPanelLayout = useViewportMatch( 'small' );
415
- const layout: 'wide' | 'narrow' = isPanelLayout ? 'wide' : 'narrow';
416
-
429
+ // Width decides whether the settings panel docks beside the canvas or
430
+ // takes the whole body. It docks from `small` (600px): the modal is the
431
+ // viewport less a 16px margin either side, so a 320px panel and the
432
+ // canvas column's 2 x 24px gutters still leave the canvas ~200px there
433
+ // and ~380px by 782px. Tight, but a full-screen panel would have hidden
434
+ // the image altogether — you could not crop and preview at once.
435
+ //
436
+ // The same line moves the transform controls: docked, the Crop panel
437
+ // carries them; below it they fall back to a row under the canvas.
438
+ //
439
+ // The choice is not carried across openings: the modal is transient, and
440
+ // re-opening with the panel hidden on a wide screen is how #81487 read to
441
+ // people in the first place. Within one opening it does hold — see
442
+ // `hasChosenPanelRef` below.
443
+ const isWide = useViewportMatch( 'small' );
444
+ // `null` when nothing is open, otherwise the open panel's id.
445
+ const [ activePanel, setActivePanel ] = useState< string | null >(
446
+ isWide ? DETAILS_PANEL : null
447
+ );
448
+ // Width picks the starting panel, but only until the user picks one. After
449
+ // that their choice holds for the rest of the session: closing the panel
450
+ // and then resizing — or crossing the breakpoint by rotating a tablet —
451
+ // should not reopen something they just dismissed.
452
+ const hasChosenPanelRef = useRef( false );
453
+ // The panel the toggle reopens, and the one width picks until the user
454
+ // picks their own. Tracked separately from `hasChosenPanelRef` because
455
+ // the two answer different questions: whether the panel should be open,
456
+ // and which tab it should show.
457
+ const lastPanelRef = useRef( DETAILS_PANEL );
458
+ const hasChosenTabRef = useRef( false );
459
+ // Switching tabs says nothing about whether the panel should be open, so
460
+ // it leaves `hasChosenPanelRef` alone: picking Details on a wide screen
461
+ // and then dragging the window narrow should still hand the canvas the
462
+ // full width.
463
+ const selectPanel = useCallback( ( panel: string ) => {
464
+ hasChosenTabRef.current = true;
465
+ lastPanelRef.current = panel;
466
+ setActivePanel( panel );
467
+ }, [] );
468
+ const togglePanel = useCallback( () => {
469
+ hasChosenPanelRef.current = true;
470
+ setActivePanel( ( open ) => ( open ? null : lastPanelRef.current ) );
471
+ }, [] );
472
+ // Below `small` a frame's header cannot fit the history cluster alongside
473
+ // its own controls, so it moves that cluster elsewhere. The same width
474
+ // undocks the panel, so this is `isWide` rather than a second query.
475
+ const layout: 'wide' | 'narrow' = isWide ? 'wide' : 'narrow';
417
476
  const { media, hasEdits } = useSelect(
418
477
  ( select ) => {
419
478
  const {
@@ -500,14 +559,38 @@ function MediaEditorContent( {
500
559
 
501
560
  const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
502
561
  const isImage = !! media && mediaType === 'image';
562
+
563
+ // Until the user picks a panel, follow the breakpoint: dragging a window
564
+ // narrow hands the canvas the full width instead of leaving a panel
565
+ // wedged beside it.
566
+ //
567
+ // Docked, the panel opens on Crop: the canvas is still beside it and
568
+ // cropping is what the editor is for. Below `small` an open panel covers
569
+ // the canvas, and crop controls with no crop in sight are not worth
570
+ // opening on, so Details leads there. Non-image media has no Crop tab at
571
+ // all (see `tabs`), so it always gets Details. `isImage` comes from a
572
+ // record that resolves after mount, which is why this runs in an effect
573
+ // rather than seeding `useState`.
574
+ useEffect( () => {
575
+ if ( hasChosenPanelRef.current && hasChosenTabRef.current ) {
576
+ return;
577
+ }
578
+ const defaultPanel = isWide && isImage ? CROP_PANEL : DETAILS_PANEL;
579
+ if ( ! hasChosenTabRef.current ) {
580
+ lastPanelRef.current = defaultPanel;
581
+ }
582
+ if ( ! hasChosenPanelRef.current ) {
583
+ setActivePanel( isWide ? lastPanelRef.current : null );
584
+ }
585
+ }, [ isWide, isImage ] );
586
+ // Only `resetCropOptions` is needed here, for the Reset button; the
587
+ // aspect-ratio members are read by `MediaEditorImageControls` itself.
503
588
  const {
504
589
  aspectRatioValue,
505
590
  setAspectRatioValue,
506
591
  aspectRatioOptions,
507
592
  resetCropOptions,
508
- } = useCropOptions( {
509
- aspectRatioPresets,
510
- } );
593
+ } = useCropOptions( { aspectRatioPresets } );
511
594
  const { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {
512
595
  cropper,
513
596
  id,
@@ -516,59 +599,6 @@ function MediaEditorContent( {
516
599
  onSaved,
517
600
  } );
518
601
 
519
- const tabs = useMemo< EditorTab[] >( () => {
520
- const detailsTab: EditorTab = {
521
- id: 'details',
522
- title: __( 'Details' ),
523
- panel: (
524
- <Stack
525
- className="media-editor__panel"
526
- direction="column"
527
- gap="lg"
528
- >
529
- <MediaForm />
530
- </Stack>
531
- ),
532
- };
533
- if ( ! isImage ) {
534
- return [ detailsTab ];
535
- }
536
- return [
537
- {
538
- id: 'crop',
539
- title: __( 'Crop' ),
540
- panel: (
541
- <Stack
542
- className="media-editor__panel"
543
- direction="column"
544
- gap="lg"
545
- >
546
- <MediaEditorCropPanel
547
- aspectRatioValue={ aspectRatioValue }
548
- onAspectRatioChange={ setAspectRatioValue }
549
- aspectRatioOptions={ aspectRatioOptions }
550
- showTransformControls={ isPanelLayout }
551
- />
552
- </Stack>
553
- ),
554
- },
555
- detailsTab,
556
- ];
557
- }, [
558
- isImage,
559
- aspectRatioValue,
560
- setAspectRatioValue,
561
- aspectRatioOptions,
562
- isPanelLayout,
563
- ] );
564
-
565
- // Control the active tab from state here so the selection survives the
566
- // sidebar closing (which unmounts the `ComplementaryArea` Fill and its
567
- // tabs). Fall back to the first tab until one is picked, so images open on
568
- // Crop.
569
- const [ selectedTabId, setSelectedTabId ] = useState< string >();
570
- const activeTabId = selectedTabId ?? tabs[ 0 ]?.id;
571
-
572
602
  const handleChange = ( updates: Partial< Media > ) => {
573
603
  editEntityRecord( 'postType', 'attachment', id, updates );
574
604
  };
@@ -637,6 +667,45 @@ function MediaEditorContent( {
637
667
  />
638
668
  );
639
669
 
670
+ // Below `small` the panel is full screen, so an open one replaces the
671
+ // canvas and these never share the screen with the Crop panel's copies:
672
+ // this row is what reaches rotate/flip/zoom while the panel is closed,
673
+ // with aspect ratio joining them as a dropdown. From `small` up the Crop
674
+ // panel docks beside the canvas and carries them instead.
675
+ const imageControls =
676
+ isImage && ! isWide ? (
677
+ <MediaEditorImageControls
678
+ showAspectRatioControl
679
+ aspectRatioPresets={ aspectRatioPresets }
680
+ />
681
+ ) : null;
682
+
683
+ // Crop leads, since it is what the docked panel opens on. Non-image media
684
+ // has nothing to crop and gets Details alone, which is why the sidebar
685
+ // takes this list rather than deriving it.
686
+ const tabs: MediaEditorTab[] = [
687
+ ...( isImage
688
+ ? [
689
+ {
690
+ id: CROP_PANEL,
691
+ title: __( 'Crop' ),
692
+ render: () => (
693
+ <MediaEditorCropPanel
694
+ aspectRatioValue={ aspectRatioValue }
695
+ onAspectRatioChange={ setAspectRatioValue }
696
+ aspectRatioOptions={ aspectRatioOptions }
697
+ />
698
+ ),
699
+ },
700
+ ]
701
+ : [] ),
702
+ {
703
+ id: DETAILS_PANEL,
704
+ title: __( 'Details' ),
705
+ render: () => <MediaForm />,
706
+ },
707
+ ];
708
+
640
709
  const ruler = isImage ? (
641
710
  <MediaEditorFineRotation
642
711
  onPlacementControlInteraction={ signalPlacementControlInteraction }
@@ -655,52 +724,58 @@ function MediaEditorContent( {
655
724
  <Spinner />
656
725
  </div>
657
726
  ) : (
658
- <>
659
- <MediaEditorSidebar
660
- tabs={ tabs }
661
- activeTabId={ activeTabId }
662
- onTabChange={ setSelectedTabId }
663
- scope={ scope }
664
- />
665
- <InterfaceSkeleton
666
- className="media-editor__skeleton"
667
- labels={ {
668
- body: isImage
727
+ <div
728
+ className={ clsx( 'media-editor__body', {
729
+ 'has-panel-open': !! activePanel,
730
+ } ) }
731
+ >
732
+ <NavigableRegion
733
+ className="media-editor__content"
734
+ ariaLabel={
735
+ isImage
669
736
  ? __( 'Image editor' )
670
- : __( 'Media preview' ),
671
- sidebar: __( 'Media details' ),
672
- } }
673
- content={
674
- <div className="media-editor__content">
675
- <div className="media-editor__canvas-area">
676
- { isImage ? (
677
- <MediaEditorCanvas
678
- isPlacementActive={
679
- isPlacementActive
680
- }
681
- onGestureStart={
682
- handleCanvasGestureStart
683
- }
684
- onGestureEnd={
685
- handleCanvasGestureEnd
686
- }
687
- />
688
- ) : (
689
- <MediaPreview />
690
- ) }
691
- </div>
692
- { isImage && (
693
- <div className="media-editor__canvas-toolbar">
694
- { ruler }
695
- </div>
696
- ) }
697
- </div>
698
- }
699
- sidebar={
700
- <ComplementaryArea.Slot scope={ scope } />
737
+ : __( 'Media preview' )
701
738
  }
702
- />
703
- </>
739
+ >
740
+ <div className="media-editor__canvas-area">
741
+ { isImage ? (
742
+ <MediaEditorCanvas
743
+ isPlacementActive={ isPlacementActive }
744
+ onGestureStart={
745
+ handleCanvasGestureStart
746
+ }
747
+ onGestureEnd={ handleCanvasGestureEnd }
748
+ />
749
+ ) : (
750
+ <MediaPreview />
751
+ ) }
752
+ </div>
753
+ { isImage && (
754
+ <div className="media-editor__canvas-toolbar">
755
+ { ruler }
756
+ { imageControls }
757
+ </div>
758
+ ) }
759
+ </NavigableRegion>
760
+ { !! activePanel && (
761
+ <MediaEditorSidebar
762
+ tabs={ tabs }
763
+ // Swapping the edited media can drop the Crop
764
+ // tab out from under an open panel — saving a
765
+ // crop moves the editor to a new id, which may
766
+ // resolve as non-image. Fall back rather than
767
+ // hand `Tabs.Root` a value no tab matches.
768
+ activeTab={
769
+ tabs.some(
770
+ ( tab ) => tab.id === activePanel
771
+ )
772
+ ? activePanel
773
+ : DETAILS_PANEL
774
+ }
775
+ onSelectTab={ selectPanel }
776
+ />
777
+ ) }
778
+ </div>
704
779
  ) }
705
780
  </div>
706
781
  <ConfirmDialog
@@ -731,8 +806,10 @@ function MediaEditorContent( {
731
806
  hasMedia: !! media,
732
807
  hasChanges,
733
808
  isUndoRedoDisabled: isCropInteractionActive,
734
- scope,
735
809
  aspectRatioPresets,
810
+ isWide,
811
+ activePanel,
812
+ onTogglePanel: togglePanel,
736
813
  onCancel: handleRequestClose,
737
814
  onSave: saveMediaEditor,
738
815
  onReset: resetCropOptions,
@@ -769,6 +846,5 @@ export function MediaEditor( props: MediaEditorProps ) {
769
846
  MediaEditor.HeaderActions = HeaderActions;
770
847
  MediaEditor.HistoryActions = HistoryActions;
771
848
  MediaEditor.SaveActions = SaveActions;
772
- MediaEditor.ImageControls = ImageControls;
773
849
 
774
850
  export default MediaEditor;