@wordpress/media-editor 0.17.2-next.v.202608281122.0 → 0.18.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 (103) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/build/components/media-editor/index.cjs +43 -11
  3. package/build/components/media-editor/index.cjs.map +2 -2
  4. package/build/components/media-editor-canvas/index.cjs +4 -2
  5. package/build/components/media-editor-canvas/index.cjs.map +2 -2
  6. package/build/components/media-editor-crop-panel/index.cjs +4 -2
  7. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  8. package/build/components/media-editor-fine-rotation/index.cjs +4 -2
  9. package/build/components/media-editor-fine-rotation/index.cjs.map +2 -2
  10. package/build/components/media-editor-image-controls/index.cjs +17 -4
  11. package/build/components/media-editor-image-controls/index.cjs.map +2 -2
  12. package/build/components/rotation-ruler/index.cjs +1 -0
  13. package/build/components/rotation-ruler/index.cjs.map +2 -2
  14. package/build/components/rotation-ruler/use-ruler-drag.cjs +7 -2
  15. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +2 -2
  16. package/build/image-editor/core/interaction-controller.cjs +3 -0
  17. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  18. package/build/image-editor/react/components/cropper.cjs +5 -3
  19. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  20. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +12 -5
  21. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  22. package/build/image-editor/react/hooks/use-interaction.cjs +31 -0
  23. package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
  24. package/build-module/components/media-editor/index.mjs +43 -11
  25. package/build-module/components/media-editor/index.mjs.map +2 -2
  26. package/build-module/components/media-editor-canvas/index.mjs +4 -2
  27. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  28. package/build-module/components/media-editor-crop-panel/index.mjs +4 -2
  29. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  30. package/build-module/components/media-editor-fine-rotation/index.mjs +4 -2
  31. package/build-module/components/media-editor-fine-rotation/index.mjs.map +2 -2
  32. package/build-module/components/media-editor-image-controls/index.mjs +17 -4
  33. package/build-module/components/media-editor-image-controls/index.mjs.map +2 -2
  34. package/build-module/components/rotation-ruler/index.mjs +1 -0
  35. package/build-module/components/rotation-ruler/index.mjs.map +2 -2
  36. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +7 -2
  37. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +2 -2
  38. package/build-module/image-editor/core/interaction-controller.mjs +3 -0
  39. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  40. package/build-module/image-editor/react/components/cropper.mjs +5 -3
  41. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  42. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +12 -5
  43. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  44. package/build-module/image-editor/react/hooks/use-interaction.mjs +31 -0
  45. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
  46. package/build-style/style-rtl.css +5 -12
  47. package/build-style/style.css +5 -12
  48. package/build-types/components/media-editor/index.d.ts.map +1 -1
  49. package/build-types/components/media-editor-canvas/index.d.ts +7 -1
  50. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  51. package/build-types/components/media-editor-crop-panel/index.d.ts +4 -1
  52. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  53. package/build-types/components/media-editor-fine-rotation/index.d.ts +7 -1
  54. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  55. package/build-types/components/media-editor-image-controls/index.d.ts +7 -1
  56. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  57. package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
  58. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  59. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  60. package/build-types/image-editor/react/components/cropper.d.ts +7 -0
  61. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  62. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  63. package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -0
  64. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
  65. package/global.d.ts +1 -0
  66. package/package.json +23 -22
  67. package/src/components/media-editor/index.tsx +42 -5
  68. package/src/components/media-editor/test/{use-crop-options.tsx → use-crop-options.jsdom.test.tsx} +1 -0
  69. package/src/components/media-editor-canvas/index.tsx +8 -0
  70. package/src/components/media-editor-crop-panel/index.tsx +6 -1
  71. package/src/components/media-editor-crop-panel/test/{index.tsx → index.jsdom.test.tsx} +5 -2
  72. package/src/components/media-editor-fine-rotation/index.tsx +8 -0
  73. package/src/components/media-editor-image-controls/index.tsx +22 -3
  74. package/src/components/media-editor-image-controls/test/{index.tsx → index.jsdom.test.tsx} +37 -0
  75. package/src/components/media-editor-modal/test/build-modifiers.test.ts +24 -14
  76. package/src/components/media-editor-modal/test/{index.tsx → index.jsdom.test.tsx} +65 -35
  77. package/src/components/rotation-ruler/index.tsx +1 -0
  78. package/src/components/rotation-ruler/style.scss +1 -1
  79. package/src/components/rotation-ruler/test/{index.tsx → index.jsdom.test.tsx} +42 -4
  80. package/src/components/rotation-ruler/use-ruler-drag.ts +10 -2
  81. package/src/image-editor/core/export/test/{canvas-renderer.ts → canvas-renderer.jsdom.test.ts} +76 -63
  82. package/src/image-editor/core/interaction-controller.ts +8 -0
  83. package/src/image-editor/core/math/test/sanitize.ts +1 -0
  84. package/src/image-editor/core/test/camera.ts +2 -3
  85. package/src/image-editor/core/test/interaction-controller.ts +50 -40
  86. package/src/image-editor/core/test/preview-export-parity.ts +31 -23
  87. package/src/image-editor/core/test/render-camera-bridge.ts +1 -0
  88. package/src/image-editor/core/test/state.ts +1 -0
  89. package/src/image-editor/core/test/stencil-math.ts +1 -0
  90. package/src/image-editor/core/transforms/test/pipeline.ts +1 -0
  91. package/src/image-editor/react/components/cropper.tsx +12 -1
  92. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +22 -6
  93. package/src/image-editor/react/components/stencils/test/{rectangle-stencil.tsx → rectangle-stencil.jsdom.test.tsx} +54 -36
  94. package/src/image-editor/react/components/test/{cropper.tsx → cropper.jsdom.test.tsx} +304 -0
  95. package/src/image-editor/react/hooks/test/{use-aria-announcer.ts → use-aria-announcer.jsdom.test.ts} +57 -44
  96. package/src/image-editor/react/hooks/test/{use-cropper-reducer.ts → use-cropper-reducer.jsdom.test.ts} +1 -0
  97. package/src/image-editor/react/hooks/test/{use-interaction.ts → use-interaction.jsdom.test.ts} +17 -16
  98. package/src/image-editor/react/hooks/test/{use-transform-style.ts → use-transform-style.jsdom.test.ts} +1 -0
  99. package/src/image-editor/react/hooks/use-interaction.ts +47 -0
  100. package/src/state/test/{use-media-editor-state.ts → use-media-editor-state.jsdom.test.ts} +1 -0
  101. package/src/store/test/reducer.ts +9 -8
  102. package/tsconfig.build.tsbuildinfo +1 -1
  103. package/tsconfig.json +8 -3
package/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- ## 0.17.1-next.0 (2026-08-28)
5
+ ## 0.18.0 (2026-09-10)
6
6
 
7
7
  ### Internal
8
8
 
@@ -67,7 +67,8 @@ var CROP_PANEL = "crop";
67
67
  function MediaEditorSidebar({
68
68
  tabs,
69
69
  activeTab,
70
- onSelectTab
70
+ onSelectTab,
71
+ disabled = false
71
72
  }) {
72
73
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
73
74
  import_admin_ui.NavigableRegion,
@@ -83,7 +84,15 @@ function MediaEditorSidebar({
83
84
  value: activeTab,
84
85
  onValueChange: onSelectTab,
85
86
  children: [
86
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor__tablist", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Tabs.List, { variant: "minimal", children: tabs.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Tabs.Tab, { value: tab.id, children: tab.title }, tab.id)) }) }),
87
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor__tablist", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Tabs.List, { variant: "minimal", children: tabs.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
88
+ import_ui.Tabs.Tab,
89
+ {
90
+ value: tab.id,
91
+ disabled,
92
+ children: tab.title
93
+ },
94
+ tab.id
95
+ )) }) }),
87
96
  tabs.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
88
97
  import_ui.Tabs.Panel,
89
98
  {
@@ -192,6 +201,9 @@ function HistoryActions() {
192
201
  redoCrop();
193
202
  };
194
203
  const handleReset = () => {
204
+ if (isUndoRedoDisabled) {
205
+ return;
206
+ }
195
207
  beginGesture();
196
208
  reset();
197
209
  onReset();
@@ -209,7 +221,7 @@ function HistoryActions() {
209
221
  {
210
222
  size: "compact",
211
223
  variant: "tertiary",
212
- disabled: !isDirty,
224
+ disabled: isUndoRedoDisabled || !isDirty,
213
225
  accessibleWhenDisabled: true,
214
226
  onClick: handleReset,
215
227
  children: (0, import_i18n.__)("Reset")
@@ -408,6 +420,9 @@ function MediaEditorContent({
408
420
  onSaved
409
421
  });
410
422
  const handleChange = (updates) => {
423
+ if (isSaving) {
424
+ return;
425
+ }
411
426
  editEntityRecord("postType", "attachment", id, updates);
412
427
  };
413
428
  const discardAndClose = () => {
@@ -433,7 +448,7 @@ function MediaEditorContent({
433
448
  const isMetadataField = (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) && !target.closest(`[${import_use_crop_gesture_handlers.CROP_CONTROL_ATTR}]`);
434
449
  if (!isMetadataField) {
435
450
  event.preventDefault();
436
- if (isCropInteractionActive) {
451
+ if (isCropInteractionActive || isSaving) {
437
452
  return;
438
453
  }
439
454
  if (isRedoShortcut) {
@@ -468,7 +483,8 @@ function MediaEditorContent({
468
483
  import_media_editor_image_controls.default,
469
484
  {
470
485
  showAspectRatioControl: true,
471
- aspectRatioPresets
486
+ aspectRatioPresets,
487
+ disabled: isSaving
472
488
  }
473
489
  ) : null;
474
490
  const tabs = [
@@ -481,7 +497,8 @@ function MediaEditorContent({
481
497
  {
482
498
  aspectRatioValue,
483
499
  onAspectRatioChange: setAspectRatioValue,
484
- aspectRatioOptions
500
+ aspectRatioOptions,
501
+ disabled: isSaving
485
502
  }
486
503
  )
487
504
  }
@@ -495,7 +512,8 @@ function MediaEditorContent({
495
512
  const ruler = isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
496
513
  import_media_editor_fine_rotation.default,
497
514
  {
498
- onPlacementControlInteraction: signalPlacementControlInteraction
515
+ onPlacementControlInteraction: signalPlacementControlInteraction,
516
+ disabled: isSaving
499
517
  }
500
518
  ) : null;
501
519
  const children = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
@@ -503,7 +521,16 @@ function MediaEditorContent({
503
521
  {
504
522
  value: media ?? void 0,
505
523
  onChange: handleChange,
506
- settings: { fields },
524
+ settings: {
525
+ // Disable the fields while saving, so the guard in
526
+ // `handleChange` is not silently swallowing typing.
527
+ // `readOnly` would swap the field's layout mid-save;
528
+ // disabled keeps it in place and greys it out.
529
+ fields: isSaving ? fields.map((field) => ({
530
+ ...field,
531
+ isDisabled: true
532
+ })) : fields
533
+ },
507
534
  children: [
508
535
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor", children: !media ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor__loading", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {}) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
509
536
  "div",
@@ -523,7 +550,8 @@ function MediaEditorContent({
523
550
  {
524
551
  isPlacementActive,
525
552
  onGestureStart: handleCanvasGestureStart,
526
- onGestureEnd: handleCanvasGestureEnd
553
+ onGestureEnd: handleCanvasGestureEnd,
554
+ disabled: isSaving
527
555
  }
528
556
  ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_preview.default, {}) }),
529
557
  isImage && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor__canvas-toolbar", children: [
@@ -540,7 +568,8 @@ function MediaEditorContent({
540
568
  activeTab: tabs.some(
541
569
  (tab) => tab.id === activePanel
542
570
  ) ? activePanel : DETAILS_PANEL,
543
- onSelectTab: selectPanel
571
+ onSelectTab: selectPanel,
572
+ disabled: isSaving
544
573
  }
545
574
  )
546
575
  ]
@@ -571,7 +600,10 @@ function MediaEditorContent({
571
600
  isSaving,
572
601
  hasMedia: !!media,
573
602
  hasChanges,
574
- isUndoRedoDisabled: isCropInteractionActive,
603
+ // Saving freezes the whole edit surface: `save()` reads the
604
+ // modifiers once and then awaits, so anything changed after that
605
+ // would be silently dropped when the save resolves.
606
+ isUndoRedoDisabled: isCropInteractionActive || isSaving,
575
607
  aspectRatioPresets,
576
608
  isWide,
577
609
  activePanel,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/media-editor/index.tsx"],
4
- "sourcesContent": ["import clsx from 'clsx';\nimport {\n\tButton,\n\tSpinner,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, 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\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { close, drawerRight, keyboard, redo, undo } from '@wordpress/icons';\nimport {\n\tdisplayShortcut,\n\tisAppleOS,\n\tisKeyboardEvent,\n} from '@wordpress/keycodes';\nimport { SnackbarNotices, store as noticesStore } from '@wordpress/notices';\nimport type { Field } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent, ReactNode } from 'react';\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 type { AspectRatioPreset } from '../../image-editor/core/constants';\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\ninterface MediaEditorTab {\n\tid: string;\n\ttitle: string;\n\trender: () => JSX.Element;\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\tid: number;\n\taspectRatioPresets?: AspectRatioPreset[];\n\tonClose?: () => void;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\trenderFrame: ( props: MediaEditorFrameProps ) => JSX.Element;\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}\n\nfunction MediaEditorSidebar( {\n\ttabs,\n\tactiveTab,\n\tonSelectTab,\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 key={ tab.id } value={ tab.id }>\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\tonReset: () => 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 HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {\n\tconst { isImage, isSaving, onCancel, isWide, activePanel, onTogglePanel } =\n\t\tuseMediaEditorFrameContext();\n\tconst isPanelOpen = !! activePanel;\n\tconst [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );\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{ isImage && (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ keyboard }\n\t\t\t\t\tlabel={ __( 'Keyboard shortcuts' ) }\n\t\t\t\t\tonClick={ () => setIsShortcutsModalOpen( true ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ /* The sidebar holds more than one panel, so this opens and\n\t\t\t closes the sidebar rather than naming a panel: reopening\n\t\t\t returns to whichever tab was last showing, and the tab strip\n\t\t\t inside switches between them. */ }\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ drawerRight }\n\t\t\t\tlabel={ __( 'Media settings' ) }\n\t\t\t\tisPressed={ isPanelOpen }\n\t\t\t\t// Only a docked column really expands beside the canvas; below\n\t\t\t\t// that the panel replaces the view, which the pressed state\n\t\t\t\t// already describes.\n\t\t\t\taria-expanded={ isWide ? isPanelOpen : undefined }\n\t\t\t\tonClick={ onTogglePanel }\n\t\t\t/>\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\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</Stack>\n\t);\n}\n\nfunction HistoryActions() {\n\tconst { isImage, isUndoRedoDisabled, onReset, isWide, activePanel } =\n\t\tuseMediaEditorFrameContext();\n\tconst {\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t\tbeginGesture,\n\t\tendGesture,\n\t} = useMediaEditor();\n\t// Reset, undo and redo act on the cropper, so they only appear where the\n\t// 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\tbeginGesture();\n\t\treset();\n\t\tonReset();\n\t\tendGesture();\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\tvariant=\"tertiary\"\n\t\t\t\tdisabled={ ! isDirty }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleReset }\n\t\t\t>\n\t\t\t\t{ __( 'Reset' ) }\n\t\t\t</Button>\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</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\tid,\n\taspectRatioPresets,\n\tonClose,\n\tonSaved,\n\trenderFrame,\n\tnoticesClassName = 'media-editor__snackbar',\n\tnoticesPortalElement,\n\tshouldCloseOnEsc = false,\n}: MediaEditorProps ) {\n\tconst cropper = 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// `hasChosenPanelRef` below.\n\tconst isWide = useViewportMatch( 'small' );\n\t// `null` when nothing is open, otherwise the open panel's id.\n\tconst [ activePanel, setActivePanel ] = useState< string | null >(\n\t\tisWide ? DETAILS_PANEL : null\n\t);\n\t// Width picks the starting panel, but only until the user picks one. After\n\t// that their choice holds for the rest of the session: closing the panel\n\t// and then resizing — or crossing the breakpoint by rotating a tablet —\n\t// should not reopen something they just dismissed.\n\tconst hasChosenPanelRef = useRef( false );\n\t// The panel the toggle reopens, and the one width picks until the user\n\t// picks their own. Tracked separately from `hasChosenPanelRef` because\n\t// the two answer different questions: whether the panel should be open,\n\t// and which tab it should show.\n\tconst lastPanelRef = useRef( DETAILS_PANEL );\n\tconst hasChosenTabRef = useRef( false );\n\t// Switching tabs says nothing about whether the panel should be open, so\n\t// it leaves `hasChosenPanelRef` alone: picking Details on a wide screen\n\t// and then dragging the window narrow should still hand the canvas the\n\t// full width.\n\tconst selectPanel = useCallback( ( panel: string ) => {\n\t\thasChosenTabRef.current = true;\n\t\tlastPanelRef.current = panel;\n\t\tsetActivePanel( panel );\n\t}, [] );\n\tconst togglePanel = useCallback( () => {\n\t\thasChosenPanelRef.current = true;\n\t\tsetActivePanel( ( open ) => ( open ? null : lastPanelRef.current ) );\n\t}, [] );\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 { 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// Trigger an _embed fetch so `_embedded.author` and\n\t\t\t// `_embedded['wp:attached-to']` land on the record for the Details\n\t\t\t// fields to read. `getEditedEntityRecord` doesn't formally accept a\n\t\t\t// query, so we can't embed via that selector directly.\n\t\t\tgetEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tid,\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\tid\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\tid\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ id ]\n\t);\n\n\tconst hasChanges = cropper.isCropperDirty || hasEdits;\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\tconst placementControlTimerRef =\n\t\tuseRef< ReturnType< typeof setTimeout > >();\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\tuseEffect( () => {\n\t\tsetIsPlacementActive( false );\n\t\tsetIsCanvasGestureActive( false );\n\t}, [ id ] );\n\n\t// Bust the cached `_embed` resolution each time the editor mounts (or the\n\t// id changes) so embedded data such as the attached post's title or the\n\t// author's name reflects any edits made elsewhere since the last open.\n\tuseEffect( () => {\n\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t'postType',\n\t\t\t'attachment',\n\t\t\tid,\n\t\t\tATTACHMENT_EMBED_QUERY,\n\t\t] );\n\t}, [ id, invalidateResolution ] );\n\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;\n\tconst isImage = !! media && mediaType === 'image';\n\n\t// Until the user picks a 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\t//\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. `isImage` comes from a\n\t// record that resolves after mount, which is why this runs in an effect\n\t// rather than seeding `useState`.\n\tuseEffect( () => {\n\t\tif ( hasChosenPanelRef.current && hasChosenTabRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tconst defaultPanel = isWide && isImage ? CROP_PANEL : DETAILS_PANEL;\n\t\tif ( ! hasChosenTabRef.current ) {\n\t\t\tlastPanelRef.current = defaultPanel;\n\t\t}\n\t\tif ( ! hasChosenPanelRef.current ) {\n\t\t\tsetActivePanel( isWide ? lastPanelRef.current : null );\n\t\t}\n\t}, [ isWide, isImage ] );\n\t// Only `resetCropOptions` is needed here, for the Reset button; the\n\t// aspect-ratio members are read by `MediaEditorImageControls` itself.\n\tconst {\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue,\n\t\taspectRatioOptions,\n\t\tresetCropOptions,\n\t} = useCropOptions( { aspectRatioPresets } );\n\tconst { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {\n\t\tcropper,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t} );\n\n\tconst handleChange = ( updates: Partial< Media > ) => {\n\t\teditEntityRecord( 'postType', 'attachment', id, updates );\n\t};\n\n\tconst discardAndClose = () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tclearEntityRecordEdits( 'postType', 'attachment', id );\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 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif ( isRedoShortcut ) {\n\t\t\t\t\tcropper.redo();\n\t\t\t\t} else {\n\t\t\t\t\tcropper.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/>\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/>\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\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/>\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={ { fields } }\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<Spinner />\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/>\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{ !! activePanel && (\n\t\t\t\t\t\t\t<MediaEditorSidebar\n\t\t\t\t\t\t\t\ttabs={ tabs }\n\t\t\t\t\t\t\t\t// Swapping the edited media can drop the Crop\n\t\t\t\t\t\t\t\t// tab out from under an open panel — saving a\n\t\t\t\t\t\t\t\t// crop moves the editor to a new id, which may\n\t\t\t\t\t\t\t\t// resolve as non-image. Fall back rather than\n\t\t\t\t\t\t\t\t// hand `Tabs.Root` a value no tab matches.\n\t\t\t\t\t\t\t\tactiveTab={\n\t\t\t\t\t\t\t\t\ttabs.some(\n\t\t\t\t\t\t\t\t\t\t( tab ) => tab.id === activePanel\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t? activePanel\n\t\t\t\t\t\t\t\t\t\t: DETAILS_PANEL\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonSelectTab={ selectPanel }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\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\tisUndoRedoDisabled: isCropInteractionActive,\n\t\taspectRatioPresets,\n\t\tisWide,\n\t\tactivePanel,\n\t\tonTogglePanel: togglePanel,\n\t\tonCancel: handleRequestClose,\n\t\tonSave: saveMediaEditor,\n\t\tonReset: resetCropOptions,\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.HistoryActions = HistoryActions;\nMediaEditor.SaveActions = SaveActions;\n\nexport default MediaEditor;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,wBAIO;AACP,gBAA4C;AAC5C,qBAAiC;AACjC,kBAAuC;AACvC,uBAAmC;AACnC,sBAAgC;AAChC,qBAQO;A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AAAA,UAAC,kBAAAC;AAAA,UAAA;AAAA,YACA,QAAS;AAAA,YACT,uBAAoB,gBAAI,SAAU;AAAA,YAClC,sBAAmB,gBAAI,cAAe;AAAA,YACtC,UAAW,MAAM,uBAAwB,KAAM;AAAA,YAC/C,WAAY,MAAM;AACjB,qCAAwB,KAAM;AAC9B,8BAAgB;AAAA,YACjB;AAAA,YAEE;AAAA,cACD;AAAA,YACD;AAAA;AAAA,QACD;AAAA,QACE,2BACC,6BAAc,UAAU,oBAAqB,IAC7C;AAAA;AAAA;AAAA,EACJ;AAKD,QAAM,eAA6C;AAAA,IAClD;AAAA,IACA;AAAA,IACA,UAAU,CAAC,CAAE;AAAA,IACb;AAAA,IACA,oBAAoB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,SAAS;AAAA,EACV;AAEA,SACC,4CAAC,wBAAwB,UAAxB,EAAiC,OAAQ,cACvC,sBAAa;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB,WAAW;AAAA,IACX,2BAA2B,CAAE,cAAc,CAAE;AAAA,IAC7C;AAAA,IACA;AAAA,IACA,UAAU,CAAC,CAAE;AAAA,EACd,CAAE,GACH;AAEF;AAEO,SAAS,YAAa,OAA0B;AACtD,SACC,4CAAC,yCACA,sDAAC,sBAAqB,GAAG,OAAQ,KADF,MAAM,EAEtC;AAEF;AAKA,YAAY,gBAAgB;AAC5B,YAAY,iBAAiB;AAC7B,YAAY,cAAc;AAE1B,IAAO,uBAAQ;",
4
+ "sourcesContent": ["import clsx from 'clsx';\nimport {\n\tButton,\n\tSpinner,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, 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\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { close, drawerRight, keyboard, redo, undo } from '@wordpress/icons';\nimport {\n\tdisplayShortcut,\n\tisAppleOS,\n\tisKeyboardEvent,\n} from '@wordpress/keycodes';\nimport { SnackbarNotices, store as noticesStore } from '@wordpress/notices';\nimport type { Field } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent, ReactNode } from 'react';\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 type { AspectRatioPreset } from '../../image-editor/core/constants';\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\ninterface MediaEditorTab {\n\tid: string;\n\ttitle: string;\n\trender: () => JSX.Element;\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\tid: number;\n\taspectRatioPresets?: AspectRatioPreset[];\n\tonClose?: () => void;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\trenderFrame: ( props: MediaEditorFrameProps ) => JSX.Element;\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\tonReset: () => 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 HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {\n\tconst { isImage, isSaving, onCancel, isWide, activePanel, onTogglePanel } =\n\t\tuseMediaEditorFrameContext();\n\tconst isPanelOpen = !! activePanel;\n\tconst [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );\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{ isImage && (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ keyboard }\n\t\t\t\t\tlabel={ __( 'Keyboard shortcuts' ) }\n\t\t\t\t\tonClick={ () => setIsShortcutsModalOpen( true ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ /* The sidebar holds more than one panel, so this opens and\n\t\t\t closes the sidebar rather than naming a panel: reopening\n\t\t\t returns to whichever tab was last showing, and the tab strip\n\t\t\t inside switches between them. */ }\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ drawerRight }\n\t\t\t\tlabel={ __( 'Media settings' ) }\n\t\t\t\tisPressed={ isPanelOpen }\n\t\t\t\t// Only a docked column really expands beside the canvas; below\n\t\t\t\t// that the panel replaces the view, which the pressed state\n\t\t\t\t// already describes.\n\t\t\t\taria-expanded={ isWide ? isPanelOpen : undefined }\n\t\t\t\tonClick={ onTogglePanel }\n\t\t\t/>\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\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</Stack>\n\t);\n}\n\nfunction HistoryActions() {\n\tconst { isImage, isUndoRedoDisabled, onReset, isWide, activePanel } =\n\t\tuseMediaEditorFrameContext();\n\tconst {\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t\tbeginGesture,\n\t\tendGesture,\n\t} = useMediaEditor();\n\t// Reset, undo and redo act on the cropper, so they only appear where the\n\t// 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\tbeginGesture();\n\t\treset();\n\t\tonReset();\n\t\tendGesture();\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\tvariant=\"tertiary\"\n\t\t\t\tdisabled={ isUndoRedoDisabled || ! isDirty }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleReset }\n\t\t\t>\n\t\t\t\t{ __( 'Reset' ) }\n\t\t\t</Button>\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</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\tid,\n\taspectRatioPresets,\n\tonClose,\n\tonSaved,\n\trenderFrame,\n\tnoticesClassName = 'media-editor__snackbar',\n\tnoticesPortalElement,\n\tshouldCloseOnEsc = false,\n}: MediaEditorProps ) {\n\tconst cropper = 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// `hasChosenPanelRef` below.\n\tconst isWide = useViewportMatch( 'small' );\n\t// `null` when nothing is open, otherwise the open panel's id.\n\tconst [ activePanel, setActivePanel ] = useState< string | null >(\n\t\tisWide ? DETAILS_PANEL : null\n\t);\n\t// Width picks the starting panel, but only until the user picks one. After\n\t// that their choice holds for the rest of the session: closing the panel\n\t// and then resizing — or crossing the breakpoint by rotating a tablet —\n\t// should not reopen something they just dismissed.\n\tconst hasChosenPanelRef = useRef( false );\n\t// The panel the toggle reopens, and the one width picks until the user\n\t// picks their own. Tracked separately from `hasChosenPanelRef` because\n\t// the two answer different questions: whether the panel should be open,\n\t// and which tab it should show.\n\tconst lastPanelRef = useRef( DETAILS_PANEL );\n\tconst hasChosenTabRef = useRef( false );\n\t// Switching tabs says nothing about whether the panel should be open, so\n\t// it leaves `hasChosenPanelRef` alone: picking Details on a wide screen\n\t// and then dragging the window narrow should still hand the canvas the\n\t// full width.\n\tconst selectPanel = useCallback( ( panel: string ) => {\n\t\thasChosenTabRef.current = true;\n\t\tlastPanelRef.current = panel;\n\t\tsetActivePanel( panel );\n\t}, [] );\n\tconst togglePanel = useCallback( () => {\n\t\thasChosenPanelRef.current = true;\n\t\tsetActivePanel( ( open ) => ( open ? null : lastPanelRef.current ) );\n\t}, [] );\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 { 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// Trigger an _embed fetch so `_embedded.author` and\n\t\t\t// `_embedded['wp:attached-to']` land on the record for the Details\n\t\t\t// fields to read. `getEditedEntityRecord` doesn't formally accept a\n\t\t\t// query, so we can't embed via that selector directly.\n\t\t\tgetEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tid,\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\tid\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\tid\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ id ]\n\t);\n\n\tconst hasChanges = cropper.isCropperDirty || hasEdits;\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\tconst placementControlTimerRef =\n\t\tuseRef< ReturnType< typeof setTimeout > >();\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\tuseEffect( () => {\n\t\tsetIsPlacementActive( false );\n\t\tsetIsCanvasGestureActive( false );\n\t}, [ id ] );\n\n\t// Bust the cached `_embed` resolution each time the editor mounts (or the\n\t// id changes) so embedded data such as the attached post's title or the\n\t// author's name reflects any edits made elsewhere since the last open.\n\tuseEffect( () => {\n\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t'postType',\n\t\t\t'attachment',\n\t\t\tid,\n\t\t\tATTACHMENT_EMBED_QUERY,\n\t\t] );\n\t}, [ id, invalidateResolution ] );\n\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;\n\tconst isImage = !! media && mediaType === 'image';\n\n\t// Until the user picks a 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\t//\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. `isImage` comes from a\n\t// record that resolves after mount, which is why this runs in an effect\n\t// rather than seeding `useState`.\n\tuseEffect( () => {\n\t\tif ( hasChosenPanelRef.current && hasChosenTabRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tconst defaultPanel = isWide && isImage ? CROP_PANEL : DETAILS_PANEL;\n\t\tif ( ! hasChosenTabRef.current ) {\n\t\t\tlastPanelRef.current = defaultPanel;\n\t\t}\n\t\tif ( ! hasChosenPanelRef.current ) {\n\t\t\tsetActivePanel( isWide ? lastPanelRef.current : null );\n\t\t}\n\t}, [ isWide, isImage ] );\n\t// Only `resetCropOptions` is needed here, for the Reset button; the\n\t// aspect-ratio members are read by `MediaEditorImageControls` itself.\n\tconst {\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue,\n\t\taspectRatioOptions,\n\t\tresetCropOptions,\n\t} = useCropOptions( { aspectRatioPresets } );\n\tconst { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {\n\t\tcropper,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\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', id, updates );\n\t};\n\n\tconst discardAndClose = () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tclearEntityRecordEdits( 'postType', 'attachment', id );\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\tcropper.redo();\n\t\t\t\t} else {\n\t\t\t\t\tcropper.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 ]\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 } ) )\n\t\t\t\t\t: fields,\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<Spinner />\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{ !! activePanel && (\n\t\t\t\t\t\t\t<MediaEditorSidebar\n\t\t\t\t\t\t\t\ttabs={ tabs }\n\t\t\t\t\t\t\t\t// Swapping the edited media can drop the Crop\n\t\t\t\t\t\t\t\t// tab out from under an open panel — saving a\n\t\t\t\t\t\t\t\t// crop moves the editor to a new id, which may\n\t\t\t\t\t\t\t\t// resolve as non-image. Fall back rather than\n\t\t\t\t\t\t\t\t// hand `Tabs.Root` a value no tab matches.\n\t\t\t\t\t\t\t\tactiveTab={\n\t\t\t\t\t\t\t\t\ttabs.some(\n\t\t\t\t\t\t\t\t\t\t( tab ) => tab.id === activePanel\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t? activePanel\n\t\t\t\t\t\t\t\t\t\t: DETAILS_PANEL\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonSelectTab={ selectPanel }\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</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\tonReset: resetCropOptions,\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.HistoryActions = HistoryActions;\nMediaEditor.SaveActions = SaveActions;\n\nexport default MediaEditor;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,wBAIO;AACP,gBAA4C;AAC5C,qBAAiC;AACjC,kBAAuC;AACvC,uBAAmC;AACnC,sBAAgC;AAChC,qBAQO;AACP,kBAAmB;AACnB,mBAAyD;AACzD,sBAIO;AACP,qBAAuD;A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qB,GAAG,OAAQ,KADF,MAAM,EAEtC;AAEF;AAKA,YAAY,gBAAgB;AAC5B,YAAY,iBAAiB;AAC7B,YAAY,cAAc;AAE1B,IAAO,uBAAQ;",
6
6
  "names": ["MediaEditorKeyboardShortcutsModal", "coreStore", "noticesStore", "MediaEditorImageControls", "MediaEditorCropPanel", "MediaForm", "MediaEditorFineRotation", "clsx", "MediaEditorCanvas", "MediaPreview", "ConfirmDialog"]
7
7
  }
@@ -45,7 +45,8 @@ var import_jsx_runtime = require("react/jsx-runtime");
45
45
  function MediaEditorCanvas({
46
46
  isPlacementActive = false,
47
47
  onGestureStart,
48
- onGestureEnd
48
+ onGestureEnd,
49
+ disabled = false
49
50
  }) {
50
51
  const { media } = (0, import_media_editor_provider.useMediaEditorContext)();
51
52
  const controller = (0, import_state.useMediaEditor)();
@@ -123,7 +124,8 @@ function MediaEditorCanvas({
123
124
  showGrid: "interactive",
124
125
  isPlacementActive,
125
126
  onGestureStart: handleGestureStart,
126
- onGestureEnd: handleGestureEnd
127
+ onGestureEnd: handleGestureEnd,
128
+ disabled
127
129
  }
128
130
  )
129
131
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/media-editor-canvas/index.tsx"],
4
- "sourcesContent": ["import clsx from 'clsx';\nimport { useCallback, useEffect, useMemo, useState } from '@wordpress/element';\nimport { Spinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { Cropper } from '../../image-editor';\nimport { useMediaEditor, resolveAspectRatio } 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 cropper gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas cropper gesture ends. */\n\tonGestureEnd?: () => void;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls\n * its cropper 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 */\nexport default function MediaEditorCanvas( {\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst controller = useMediaEditor();\n\tconst { aspectRatioValue } = controller.cropOptions;\n\tconst cropperImage = controller.state.image;\n\tconst { beginGesture, endGesture, setImage } = controller;\n\n\t// Tracks whether the image pixels have actually loaded. The cropper'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\tconst [ status, setStatus ] = useState< 'loading' | 'loaded' | 'error' >(\n\t\t'loading'\n\t);\n\n\t// Resolved aspect ratio is derived from the preset key + the\n\t// loaded image (for the \"Original\" preset). The reducer doesn't\n\t// store this number — only the preset key — so it's a render-time\n\t// derivation here.\n\tconst aspectRatio = useMemo(\n\t\t() => resolveAspectRatio( aspectRatioValue, cropperImage ),\n\t\t[ aspectRatioValue, cropperImage ]\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\tcropperImage ||\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\tsetImage( {\n\t\t\tsrc: mediaUrl,\n\t\t\tnaturalWidth: mediaWidth,\n\t\t\tnaturalHeight: mediaHeight,\n\t\t} );\n\t}, [ cropperImage, mediaUrl, mediaWidth, mediaHeight, setImage ] );\n\n\tconst isImage = mediaType.type === 'image';\n\n\t// Probe the image to know when its pixels have loaded (or failed),\n\t// independent of the cropper. The browser shares one fetch/cache with the\n\t// cropper's own `<img>`, so this adds no network cost. The cropper stays\n\t// framework-pure — load/error handling lives here in the wrapper layer.\n\tuseEffect( () => {\n\t\tif ( ! mediaUrl || ! isImage ) {\n\t\t\treturn;\n\t\t}\n\t\tsetStatus( 'loading' );\n\t\tconst probe = new window.Image();\n\t\tprobe.onload = () => setStatus( 'loaded' );\n\t\tprobe.onerror = () => setStatus( 'error' );\n\t\tprobe.src = mediaUrl;\n\t\t// Cached images may already be complete before listeners attach.\n\t\tif ( probe.complete ) {\n\t\t\tsetStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );\n\t\t}\n\t\treturn () => {\n\t\t\tprobe.onload = null;\n\t\t\tprobe.onerror = null;\n\t\t};\n\t}, [ mediaUrl, isImage ] );\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<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * The cropper 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__cropper', {\n\t\t\t\t\t'is-loaded': status === 'loaded',\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<Cropper\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\tcontroller={ controller }\n\t\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\t\tfreeformCrop\n\t\t\t\t\tshowGrid=\"interactive\"\n\t\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\t\tonGestureEnd={ handleGestureEnd }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,qBAA0D;AAC1D,wBAAwB;AACxB,kBAAmB;AACnB,mCAAsC;AACtC,mBAAyC;AACzC,0BAAwB;AACxB,mBAAmD;AAqH9C;AA7FU,SAAR,kBAAoC;AAAA,EAC1C,oBAAoB;AAAA,EACpB;AAAA,EACA;AACD,GAA4B;AAC3B,QAAM,EAAE,MAAM,QAAI,oDAAsB;AACxC,QAAM,iBAAa,6BAAe;AAClC,QAAM,EAAE,iBAAiB,IAAI,WAAW;AACxC,QAAM,eAAe,WAAW,MAAM;AACtC,QAAM,EAAE,cAAc,YAAY,SAAS,IAAI;AAK/C,QAAM,CAAE,QAAQ,SAAU,QAAI;AAAA,IAC7B;AAAA,EACD;AAMA,QAAM,kBAAc;AAAA,IACnB,UAAM,iCAAoB,kBAAkB,YAAa;AAAA,IACzD,CAAE,kBAAkB,Y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AAI,WAAU,8BAA6B,MAAK,SAChD,sDAAC,OAAI,8BAAI,uBAAwB,GAAG,GACrC,GACD;AAAA,EAEF;AAEA,SACC,6CAAC,SAAI,WAAU,uBACZ;AAAA,eAAW,aACZ,4CAAC,SAAI,WAAU,gCACd,sDAAC,6BAAQ,GACV;AAAA,IAYD;AAAA,MAAC;AAAA;AAAA,QACA,eAAY,YAAAA,SAAM,gCAAgC;AAAA,UACjD,aAAa,WAAW;AAAA,QACzB,CAAE;AAAA,QAEF;AAAA,UAAC;AAAA;AAAA,YACA,KAAM;AAAA,YACN;AAAA,YACA;AAAA,YACA,cAAY;AAAA,YACZ,UAAS;AAAA,YACT;AAAA,YACA,gBAAiB;AAAA,YACjB,cAAe;AAAA;AAAA,QAChB;AAAA;AAAA,IACD;AAAA,KACD;AAEF;",
4
+ "sourcesContent": ["import clsx from 'clsx';\nimport { useCallback, useEffect, useMemo, useState } from '@wordpress/element';\nimport { Spinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { Cropper } from '../../image-editor';\nimport { useMediaEditor, resolveAspectRatio } 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 cropper gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas cropper 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 cropper 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 controller = useMediaEditor();\n\tconst { aspectRatioValue } = controller.cropOptions;\n\tconst cropperImage = controller.state.image;\n\tconst { beginGesture, endGesture, setImage } = controller;\n\n\t// Tracks whether the image pixels have actually loaded. The cropper'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\tconst [ status, setStatus ] = useState< 'loading' | 'loaded' | 'error' >(\n\t\t'loading'\n\t);\n\n\t// Resolved aspect ratio is derived from the preset key + the\n\t// loaded image (for the \"Original\" preset). The reducer doesn't\n\t// store this number — only the preset key — so it's a render-time\n\t// derivation here.\n\tconst aspectRatio = useMemo(\n\t\t() => resolveAspectRatio( aspectRatioValue, cropperImage ),\n\t\t[ aspectRatioValue, cropperImage ]\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\tcropperImage ||\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\tsetImage( {\n\t\t\tsrc: mediaUrl,\n\t\t\tnaturalWidth: mediaWidth,\n\t\t\tnaturalHeight: mediaHeight,\n\t\t} );\n\t}, [ cropperImage, mediaUrl, mediaWidth, mediaHeight, setImage ] );\n\n\tconst isImage = mediaType.type === 'image';\n\n\t// Probe the image to know when its pixels have loaded (or failed),\n\t// independent of the cropper. The browser shares one fetch/cache with the\n\t// cropper's own `<img>`, so this adds no network cost. The cropper stays\n\t// framework-pure — load/error handling lives here in the wrapper layer.\n\tuseEffect( () => {\n\t\tif ( ! mediaUrl || ! isImage ) {\n\t\t\treturn;\n\t\t}\n\t\tsetStatus( 'loading' );\n\t\tconst probe = new window.Image();\n\t\tprobe.onload = () => setStatus( 'loaded' );\n\t\tprobe.onerror = () => setStatus( 'error' );\n\t\tprobe.src = mediaUrl;\n\t\t// Cached images may already be complete before listeners attach.\n\t\tif ( probe.complete ) {\n\t\t\tsetStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );\n\t\t}\n\t\treturn () => {\n\t\t\tprobe.onload = null;\n\t\t\tprobe.onerror = null;\n\t\t};\n\t}, [ mediaUrl, isImage ] );\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<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * The cropper 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__cropper', {\n\t\t\t\t\t'is-loaded': status === 'loaded',\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<Cropper\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\tcontroller={ controller }\n\t\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\t\tfreeformCrop\n\t\t\t\t\tshowGrid=\"interactive\"\n\t\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\t\tonGestureEnd={ handleGestureEnd }\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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,qBAA0D;AAC1D,wBAAwB;AACxB,kBAAmB;AACnB,mCAAsC;AACtC,mBAAyC;AACzC,0BAAwB;AACxB,mBAAmD;AA4H9C;AA9FU,SAAR,kBAAoC;AAAA,EAC1C,oBAAoB;AAAA,EACpB;AAAA,EACA;AAAA,EACA,WAAW;AACZ,GAA4B;AAC3B,QAAM,EAAE,MAAM,QAAI,oDAAsB;AACxC,QAAM,iBAAa,6BAAe;AAClC,QAAM,EAAE,iBAAiB,IAAI,WAAW;AACxC,QAAM,eAAe,WAAW,MAAM;AACtC,QAAM,EAAE,cAAc,YAAY,SAAS,IAAI;AAK/C,QAAM,CAAE,QAAQ,SAAU,QAAI;AAAA,IAC7B;AAAA,EACD;AAMA,QAAM,kBAAc;AAAA,IACnB,UAAM,iCAAoB,kBAAkB,YAAa;AAAA,IACzD,CAAE,kBAAkB,YAAa;AAAA,EAClC;AAEA,QAAM,yBAAqB,4BAAa,MAAM;AAC7C,iBAAa;AACb,qBAAiB;AAAA,EAClB,GAAG,CAAE,cAAc,c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AI,WAAU,uBACZ;AAAA,eAAW,aACZ,4CAAC,SAAI,WAAU,gCACd,sDAAC,6BAAQ,GACV;AAAA,IAYD;AAAA,MAAC;AAAA;AAAA,QACA,eAAY,YAAAA,SAAM,gCAAgC;AAAA,UACjD,aAAa,WAAW;AAAA,QACzB,CAAE;AAAA,QAEF;AAAA,UAAC;AAAA;AAAA,YACA,KAAM;AAAA,YACN;AAAA,YACA;AAAA,YACA,cAAY;AAAA,YACZ,UAAS;AAAA,YACT;AAAA,YACA,gBAAiB;AAAA,YACjB,cAAe;AAAA,YACf;AAAA;AAAA,QACD;AAAA;AAAA,IACD;AAAA,KACD;AAEF;",
6
6
  "names": ["clsx"]
7
7
  }
@@ -47,7 +47,8 @@ var import_jsx_runtime = (
47
47
  function MediaEditorCropPanel({
48
48
  aspectRatioValue,
49
49
  onAspectRatioChange,
50
- aspectRatioOptions
50
+ aspectRatioOptions,
51
+ disabled = false
51
52
  }) {
52
53
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
53
54
  import_ui.Stack,
@@ -57,13 +58,14 @@ function MediaEditorCropPanel({
57
58
  ...{ [import_use_crop_gesture_handlers.CROP_CONTROL_ATTR]: true },
58
59
  children: [
59
60
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.VisuallyHidden, { render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {}), children: (0, import_i18n.__)("Crop options") }),
60
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor_image_controls.default, { withLabels: true }),
61
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor_image_controls.default, { withLabels: true, disabled }),
61
62
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
62
63
  import_components.SelectControl,
63
64
  {
64
65
  label: (0, import_i18n.__)("Aspect ratio"),
65
66
  value: aspectRatioValue,
66
67
  onChange: onAspectRatioChange,
68
+ disabled,
67
69
  options: aspectRatioOptions.map((preset) => ({
68
70
  label: preset.label,
69
71
  value: preset.value.toString()
@@ -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}\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;",
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/** 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\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={ aspectRatioValue }\n\t\t\t\tonChange={ onAspectRatioChange }\n\t\t\t\tdisabled={ disabled }\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;AAsCnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAVa,SAAR,qBAAuC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AACZ,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,UAAsB;AAAA,QAC3D;AAAA,UAAC;AAAA;AAAA,YACA,WAAQ,gBAAI,cAAe;AAAA,YAC3B,OAAQ;AAAA,YACR,UAAW;AAAA,YACX;AAAA,YACA,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
  }
@@ -40,7 +40,8 @@ var import_constants = require("../../image-editor/core/constants.cjs");
40
40
  var import_rotation_ruler = __toESM(require("../rotation-ruler/index.cjs"));
41
41
  var import_jsx_runtime = require("react/jsx-runtime");
42
42
  function MediaEditorFineRotation({
43
- onPlacementControlInteraction
43
+ onPlacementControlInteraction,
44
+ disabled = false
44
45
  }) {
45
46
  const { state, setRotation } = (0, import_state.useMediaEditor)();
46
47
  const rotationGestureHandlers = (0, import_use_crop_gesture_handlers.useCropGestureHandlers)({
@@ -72,7 +73,8 @@ function MediaEditorFineRotation({
72
73
  min: -import_constants.MAX_ROTATION_OFFSET,
73
74
  max: import_constants.MAX_ROTATION_OFFSET,
74
75
  value: fineOffset,
75
- onChange: handleRotationSlider
76
+ onChange: handleRotationSlider,
77
+ disabled
76
78
  }
77
79
  )
78
80
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/media-editor-fine-rotation/index.tsx"],
4
- "sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\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 */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation } = useMediaEditor();\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-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - 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={ -MAX_ROTATION_OFFSET }\n\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmB;AACnB,mBAA+B;AAC/B,uCAAuC;AACvC,uBAAoC;AACpC,4BAA0B;AAsDvB;AAtCY,SAAR,wBAA0C;AAAA,EAChD;AACD,GAAkC;AACjC,QAAM,EAAE,OAAO,YAAY,QAAI,6BAAe;AAI9C,QAAM,8BAA0B,yDAAwB;AAAA,IACvD,eAAe;AAAA,EAChB,CAAE;AAKF,QAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;AACtD,QAAM,aAAa,MAAM,KAAK,eAAe,MAAM,KAAK;AACxD,QAAM,YAAY,aAAa,KAAK;AACpC,QAAM,cAAe,MAAM,WAAW,aAAc;AAEpD,QAAM,uBAAuB,CAAE,UAAmB;AAIjD,UAAM,MAAM;AACZ,UAAM,UAAU,KAAK;AAAA,MACpB,CAAC,uCAAsB;AAAA,MACvB,KAAK,IAAK,uCAAsB,KAAK,KAAM;AAAA,IAC5C;AACA,oCAAgC;AAChC,gBAAa,YAAY,UAAU,SAAU;AAAA,EAC9C;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,WAAU;AAAA,MACR,GAAG;AAAA,MAEL;AAAA,QAAC,sBAAAA;AAAA,QAAA;AAAA,UACA,WAAQ,gBAAI,eAAgB;AAAA,UAC5B,KAAM,CAAC;AAAA,UACP,KAAM;AAAA,UACN,OAAQ;AAAA,UACR,UAAW;AAAA;AAAA,MACZ;AAAA;AAAA,EACD;AAEF;",
4
+ "sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\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 } = useMediaEditor();\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-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - 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={ -MAX_ROTATION_OFFSET }\n\t\t\t\tmax={ MAX_ROTATION_OFFSET }\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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmB;AACnB,mBAA+B;AAC/B,uCAAuC;AACvC,uBAAoC;AACpC,4BAA0B;AA6DvB;AAvCY,SAAR,wBAA0C;AAAA,EAChD;AAAA,EACA,WAAW;AACZ,GAAkC;AACjC,QAAM,EAAE,OAAO,YAAY,QAAI,6BAAe;AAI9C,QAAM,8BAA0B,yDAAwB;AAAA,IACvD,eAAe;AAAA,EAChB,CAAE;AAKF,QAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;AACtD,QAAM,aAAa,MAAM,KAAK,eAAe,MAAM,KAAK;AACxD,QAAM,YAAY,aAAa,KAAK;AACpC,QAAM,cAAe,MAAM,WAAW,aAAc;AAEpD,QAAM,uBAAuB,CAAE,UAAmB;AAIjD,UAAM,MAAM;AACZ,UAAM,UAAU,KAAK;AAAA,MACpB,CAAC,uCAAsB;AAAA,MACvB,KAAK,IAAK,uCAAsB,KAAK,KAAM;AAAA,IAC5C;AACA,oCAAgC;AAChC,gBAAa,YAAY,UAAU,SAAU;AAAA,EAC9C;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,WAAU;AAAA,MACR,GAAG;AAAA,MAEL;AAAA,QAAC,sBAAAA;AAAA,QAAA;AAAA,UACA,WAAQ,gBAAI,eAAgB;AAAA,UAC5B,KAAM,CAAC;AAAA,UACP,KAAM;AAAA,UACN,OAAQ;AAAA,UACR,UAAW;AAAA,UACX;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF;",
6
6
  "names": ["RotationRuler"]
7
7
  }
@@ -37,7 +37,8 @@ function MediaEditorImageControls({
37
37
  withLabels = false,
38
38
  showAspectRatioControl = false,
39
39
  aspectRatioPresets,
40
- zoomFactor = DEFAULT_ZOOM_FACTOR
40
+ zoomFactor = DEFAULT_ZOOM_FACTOR,
41
+ disabled = false
41
42
  }) {
42
43
  const { state, setFlip, snapRotate90, setZoom } = (0, import_state.useMediaEditor)();
43
44
  const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } = (0, import_use_crop_options.useCropOptions)({ aspectRatioPresets });
@@ -56,6 +57,8 @@ function MediaEditorImageControls({
56
57
  icon: import_icons.rotateLeft,
57
58
  label: (0, import_i18n.__)("Rotate 90° counter-clockwise"),
58
59
  showTooltip: true,
60
+ disabled,
61
+ accessibleWhenDisabled: true,
59
62
  onClick: () => snapRotate90(-1)
60
63
  }
61
64
  ),
@@ -66,6 +69,8 @@ function MediaEditorImageControls({
66
69
  icon: import_icons.rotateRight,
67
70
  label: (0, import_i18n.__)("Rotate 90° clockwise"),
68
71
  showTooltip: true,
72
+ disabled,
73
+ accessibleWhenDisabled: true,
69
74
  onClick: () => snapRotate90(1)
70
75
  }
71
76
  )
@@ -79,6 +84,8 @@ function MediaEditorImageControls({
79
84
  label: (0, import_i18n.__)("Flip horizontal"),
80
85
  showTooltip: true,
81
86
  isPressed: state.flip.horizontal,
87
+ disabled,
88
+ accessibleWhenDisabled: true,
82
89
  onClick: () => setFlip({
83
90
  horizontal: !state.flip.horizontal,
84
91
  vertical: state.flip.vertical
@@ -93,6 +100,8 @@ function MediaEditorImageControls({
93
100
  label: (0, import_i18n.__)("Flip vertical"),
94
101
  showTooltip: true,
95
102
  isPressed: state.flip.vertical,
103
+ disabled,
104
+ accessibleWhenDisabled: true,
96
105
  onClick: () => setFlip({
97
106
  horizontal: state.flip.horizontal,
98
107
  vertical: !state.flip.vertical
@@ -108,7 +117,7 @@ function MediaEditorImageControls({
108
117
  icon: import_icons.plus,
109
118
  label: (0, import_i18n.__)("Zoom in"),
110
119
  showTooltip: true,
111
- disabled: state.zoom >= import_constants.MAX_ZOOM,
120
+ disabled: disabled || state.zoom >= import_constants.MAX_ZOOM,
112
121
  accessibleWhenDisabled: true,
113
122
  onClick: () => zoomByFactor(zoomFactor)
114
123
  }
@@ -120,7 +129,7 @@ function MediaEditorImageControls({
120
129
  icon: import_icons.lineSolid,
121
130
  label: (0, import_i18n.__)("Zoom out"),
122
131
  showTooltip: true,
123
- disabled: state.zoom <= minZoom,
132
+ disabled: disabled || state.zoom <= minZoom,
124
133
  accessibleWhenDisabled: true,
125
134
  onClick: () => zoomByFactor(1 / zoomFactor)
126
135
  }
@@ -132,7 +141,7 @@ function MediaEditorImageControls({
132
141
  icon: import_icons.aspectRatio,
133
142
  label: (0, import_i18n.__)("Aspect ratio"),
134
143
  popoverProps: { placement: "top" },
135
- toggleProps: { size: "compact" },
144
+ toggleProps: { size: "compact", disabled },
136
145
  children: ({ onClose }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuGroup, { label: (0, import_i18n.__)("Aspect ratio"), children: aspectRatioOptions.map((preset) => {
137
146
  const value = preset.value.toString();
138
147
  const isSelected = value === aspectRatioValue;
@@ -142,7 +151,11 @@ function MediaEditorImageControls({
142
151
  role: "menuitemradio",
143
152
  isSelected,
144
153
  icon: isSelected ? import_icons.check : void 0,
154
+ disabled,
145
155
  onClick: () => {
156
+ if (disabled) {
157
+ return;
158
+ }
146
159
  setAspectRatioValue(value);
147
160
  onClose();
148
161
  },