@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.
- package/CHANGELOG.md +1 -1
- package/build/components/media-editor/index.cjs +43 -11
- package/build/components/media-editor/index.cjs.map +2 -2
- package/build/components/media-editor-canvas/index.cjs +4 -2
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +4 -2
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-fine-rotation/index.cjs +4 -2
- package/build/components/media-editor-fine-rotation/index.cjs.map +2 -2
- package/build/components/media-editor-image-controls/index.cjs +17 -4
- package/build/components/media-editor-image-controls/index.cjs.map +2 -2
- package/build/components/rotation-ruler/index.cjs +1 -0
- package/build/components/rotation-ruler/index.cjs.map +2 -2
- package/build/components/rotation-ruler/use-ruler-drag.cjs +7 -2
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs +3 -0
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs +5 -3
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +12 -5
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs +31 -0
- package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +43 -11
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor-canvas/index.mjs +4 -2
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +4 -2
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs +4 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +2 -2
- package/build-module/components/media-editor-image-controls/index.mjs +17 -4
- package/build-module/components/media-editor-image-controls/index.mjs.map +2 -2
- package/build-module/components/rotation-ruler/index.mjs +1 -0
- package/build-module/components/rotation-ruler/index.mjs.map +2 -2
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +7 -2
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs +3 -0
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +5 -3
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +12 -5
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs +31 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
- package/build-style/style-rtl.css +5 -12
- package/build-style/style.css +5 -12
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts +7 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +4 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts +7 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +7 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +7 -0
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/global.d.ts +1 -0
- package/package.json +23 -22
- package/src/components/media-editor/index.tsx +42 -5
- package/src/components/media-editor/test/{use-crop-options.tsx → use-crop-options.jsdom.test.tsx} +1 -0
- package/src/components/media-editor-canvas/index.tsx +8 -0
- package/src/components/media-editor-crop-panel/index.tsx +6 -1
- package/src/components/media-editor-crop-panel/test/{index.tsx → index.jsdom.test.tsx} +5 -2
- package/src/components/media-editor-fine-rotation/index.tsx +8 -0
- package/src/components/media-editor-image-controls/index.tsx +22 -3
- package/src/components/media-editor-image-controls/test/{index.tsx → index.jsdom.test.tsx} +37 -0
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +24 -14
- package/src/components/media-editor-modal/test/{index.tsx → index.jsdom.test.tsx} +65 -35
- package/src/components/rotation-ruler/index.tsx +1 -0
- package/src/components/rotation-ruler/style.scss +1 -1
- package/src/components/rotation-ruler/test/{index.tsx → index.jsdom.test.tsx} +42 -4
- package/src/components/rotation-ruler/use-ruler-drag.ts +10 -2
- package/src/image-editor/core/export/test/{canvas-renderer.ts → canvas-renderer.jsdom.test.ts} +76 -63
- package/src/image-editor/core/interaction-controller.ts +8 -0
- package/src/image-editor/core/math/test/sanitize.ts +1 -0
- package/src/image-editor/core/test/camera.ts +2 -3
- package/src/image-editor/core/test/interaction-controller.ts +50 -40
- package/src/image-editor/core/test/preview-export-parity.ts +31 -23
- package/src/image-editor/core/test/render-camera-bridge.ts +1 -0
- package/src/image-editor/core/test/state.ts +1 -0
- package/src/image-editor/core/test/stencil-math.ts +1 -0
- package/src/image-editor/core/transforms/test/pipeline.ts +1 -0
- package/src/image-editor/react/components/cropper.tsx +12 -1
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +22 -6
- package/src/image-editor/react/components/stencils/test/{rectangle-stencil.tsx → rectangle-stencil.jsdom.test.tsx} +54 -36
- package/src/image-editor/react/components/test/{cropper.tsx → cropper.jsdom.test.tsx} +304 -0
- package/src/image-editor/react/hooks/test/{use-aria-announcer.ts → use-aria-announcer.jsdom.test.ts} +57 -44
- package/src/image-editor/react/hooks/test/{use-cropper-reducer.ts → use-cropper-reducer.jsdom.test.ts} +1 -0
- package/src/image-editor/react/hooks/test/{use-interaction.ts → use-interaction.jsdom.test.ts} +17 -16
- package/src/image-editor/react/hooks/test/{use-transform-style.ts → use-transform-style.jsdom.test.ts} +1 -0
- package/src/image-editor/react/hooks/use-interaction.ts +47 -0
- package/src/state/test/{use-media-editor-state.ts → use-media-editor-state.jsdom.test.ts} +1 -0
- package/src/store/test/reducer.ts +9 -8
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +8 -3
|
@@ -51,7 +51,8 @@ var CROP_PANEL = "crop";
|
|
|
51
51
|
function MediaEditorSidebar({
|
|
52
52
|
tabs,
|
|
53
53
|
activeTab,
|
|
54
|
-
onSelectTab
|
|
54
|
+
onSelectTab,
|
|
55
|
+
disabled = false
|
|
55
56
|
}) {
|
|
56
57
|
return /* @__PURE__ */ jsxs(
|
|
57
58
|
NavigableRegion,
|
|
@@ -67,7 +68,15 @@ function MediaEditorSidebar({
|
|
|
67
68
|
value: activeTab,
|
|
68
69
|
onValueChange: onSelectTab,
|
|
69
70
|
children: [
|
|
70
|
-
/* @__PURE__ */ jsx("div", { className: "media-editor__tablist", children: /* @__PURE__ */ jsx(Tabs.List, { variant: "minimal", children: tabs.map((tab) => /* @__PURE__ */ jsx(
|
|
71
|
+
/* @__PURE__ */ jsx("div", { className: "media-editor__tablist", children: /* @__PURE__ */ jsx(Tabs.List, { variant: "minimal", children: tabs.map((tab) => /* @__PURE__ */ jsx(
|
|
72
|
+
Tabs.Tab,
|
|
73
|
+
{
|
|
74
|
+
value: tab.id,
|
|
75
|
+
disabled,
|
|
76
|
+
children: tab.title
|
|
77
|
+
},
|
|
78
|
+
tab.id
|
|
79
|
+
)) }) }),
|
|
71
80
|
tabs.map((tab) => /* @__PURE__ */ jsx(
|
|
72
81
|
Tabs.Panel,
|
|
73
82
|
{
|
|
@@ -176,6 +185,9 @@ function HistoryActions() {
|
|
|
176
185
|
redoCrop();
|
|
177
186
|
};
|
|
178
187
|
const handleReset = () => {
|
|
188
|
+
if (isUndoRedoDisabled) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
179
191
|
beginGesture();
|
|
180
192
|
reset();
|
|
181
193
|
onReset();
|
|
@@ -193,7 +205,7 @@ function HistoryActions() {
|
|
|
193
205
|
{
|
|
194
206
|
size: "compact",
|
|
195
207
|
variant: "tertiary",
|
|
196
|
-
disabled: !isDirty,
|
|
208
|
+
disabled: isUndoRedoDisabled || !isDirty,
|
|
197
209
|
accessibleWhenDisabled: true,
|
|
198
210
|
onClick: handleReset,
|
|
199
211
|
children: __("Reset")
|
|
@@ -392,6 +404,9 @@ function MediaEditorContent({
|
|
|
392
404
|
onSaved
|
|
393
405
|
});
|
|
394
406
|
const handleChange = (updates) => {
|
|
407
|
+
if (isSaving) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
395
410
|
editEntityRecord("postType", "attachment", id, updates);
|
|
396
411
|
};
|
|
397
412
|
const discardAndClose = () => {
|
|
@@ -417,7 +432,7 @@ function MediaEditorContent({
|
|
|
417
432
|
const isMetadataField = (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) && !target.closest(`[${CROP_CONTROL_ATTR}]`);
|
|
418
433
|
if (!isMetadataField) {
|
|
419
434
|
event.preventDefault();
|
|
420
|
-
if (isCropInteractionActive) {
|
|
435
|
+
if (isCropInteractionActive || isSaving) {
|
|
421
436
|
return;
|
|
422
437
|
}
|
|
423
438
|
if (isRedoShortcut) {
|
|
@@ -452,7 +467,8 @@ function MediaEditorContent({
|
|
|
452
467
|
MediaEditorImageControls,
|
|
453
468
|
{
|
|
454
469
|
showAspectRatioControl: true,
|
|
455
|
-
aspectRatioPresets
|
|
470
|
+
aspectRatioPresets,
|
|
471
|
+
disabled: isSaving
|
|
456
472
|
}
|
|
457
473
|
) : null;
|
|
458
474
|
const tabs = [
|
|
@@ -465,7 +481,8 @@ function MediaEditorContent({
|
|
|
465
481
|
{
|
|
466
482
|
aspectRatioValue,
|
|
467
483
|
onAspectRatioChange: setAspectRatioValue,
|
|
468
|
-
aspectRatioOptions
|
|
484
|
+
aspectRatioOptions,
|
|
485
|
+
disabled: isSaving
|
|
469
486
|
}
|
|
470
487
|
)
|
|
471
488
|
}
|
|
@@ -479,7 +496,8 @@ function MediaEditorContent({
|
|
|
479
496
|
const ruler = isImage ? /* @__PURE__ */ jsx(
|
|
480
497
|
MediaEditorFineRotation,
|
|
481
498
|
{
|
|
482
|
-
onPlacementControlInteraction: signalPlacementControlInteraction
|
|
499
|
+
onPlacementControlInteraction: signalPlacementControlInteraction,
|
|
500
|
+
disabled: isSaving
|
|
483
501
|
}
|
|
484
502
|
) : null;
|
|
485
503
|
const children = /* @__PURE__ */ jsxs(
|
|
@@ -487,7 +505,16 @@ function MediaEditorContent({
|
|
|
487
505
|
{
|
|
488
506
|
value: media ?? void 0,
|
|
489
507
|
onChange: handleChange,
|
|
490
|
-
settings: {
|
|
508
|
+
settings: {
|
|
509
|
+
// Disable the fields while saving, so the guard in
|
|
510
|
+
// `handleChange` is not silently swallowing typing.
|
|
511
|
+
// `readOnly` would swap the field's layout mid-save;
|
|
512
|
+
// disabled keeps it in place and greys it out.
|
|
513
|
+
fields: isSaving ? fields.map((field) => ({
|
|
514
|
+
...field,
|
|
515
|
+
isDisabled: true
|
|
516
|
+
})) : fields
|
|
517
|
+
},
|
|
491
518
|
children: [
|
|
492
519
|
/* @__PURE__ */ jsx("div", { className: "media-editor", children: !media ? /* @__PURE__ */ jsx("div", { className: "media-editor__loading", children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsxs(
|
|
493
520
|
"div",
|
|
@@ -507,7 +534,8 @@ function MediaEditorContent({
|
|
|
507
534
|
{
|
|
508
535
|
isPlacementActive,
|
|
509
536
|
onGestureStart: handleCanvasGestureStart,
|
|
510
|
-
onGestureEnd: handleCanvasGestureEnd
|
|
537
|
+
onGestureEnd: handleCanvasGestureEnd,
|
|
538
|
+
disabled: isSaving
|
|
511
539
|
}
|
|
512
540
|
) : /* @__PURE__ */ jsx(MediaPreview, {}) }),
|
|
513
541
|
isImage && /* @__PURE__ */ jsxs("div", { className: "media-editor__canvas-toolbar", children: [
|
|
@@ -524,7 +552,8 @@ function MediaEditorContent({
|
|
|
524
552
|
activeTab: tabs.some(
|
|
525
553
|
(tab) => tab.id === activePanel
|
|
526
554
|
) ? activePanel : DETAILS_PANEL,
|
|
527
|
-
onSelectTab: selectPanel
|
|
555
|
+
onSelectTab: selectPanel,
|
|
556
|
+
disabled: isSaving
|
|
528
557
|
}
|
|
529
558
|
)
|
|
530
559
|
]
|
|
@@ -555,7 +584,10 @@ function MediaEditorContent({
|
|
|
555
584
|
isSaving,
|
|
556
585
|
hasMedia: !!media,
|
|
557
586
|
hasChanges,
|
|
558
|
-
|
|
587
|
+
// Saving freezes the whole edit surface: `save()` reads the
|
|
588
|
+
// modifiers once and then awaits, so anything changed after that
|
|
589
|
+
// would be silently dropped when the save resolves.
|
|
590
|
+
isUndoRedoDisabled: isCropInteractionActive || isSaving,
|
|
559
591
|
aspectRatioPresets,
|
|
560
592
|
isWide,
|
|
561
593
|
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,OAAO,UAAU;AACjB;AAAA,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AAY,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;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,IACA;AAAA,IACA,eAAe;AAAA,IACf,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,SAAS;AAAA,EACV;AAEA,SACC,oBAAC,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,oBAAC,4BACA,8BAAC,sBAAqB,GAAG,OAAQ,KADF,MAAM,EAEtC;AAEF;AAKA,YAAY,gBAAgB;AAC5B,YAAY,iBAAiB;AAC7B,YAAY,cAAc;AAE1B,IAAO,uBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -11,7 +11,8 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
function MediaEditorCanvas({
|
|
12
12
|
isPlacementActive = false,
|
|
13
13
|
onGestureStart,
|
|
14
|
-
onGestureEnd
|
|
14
|
+
onGestureEnd,
|
|
15
|
+
disabled = false
|
|
15
16
|
}) {
|
|
16
17
|
const { media } = useMediaEditorContext();
|
|
17
18
|
const controller = useMediaEditor();
|
|
@@ -89,7 +90,8 @@ function MediaEditorCanvas({
|
|
|
89
90
|
showGrid: "interactive",
|
|
90
91
|
isPlacementActive,
|
|
91
92
|
onGestureStart: handleGestureStart,
|
|
92
|
-
onGestureEnd: handleGestureEnd
|
|
93
|
+
onGestureEnd: handleGestureEnd,
|
|
94
|
+
disabled
|
|
93
95
|
}
|
|
94
96
|
)
|
|
95
97
|
}
|
|
@@ -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,OAAO,UAAU;AACjB,SAAS,aAAa,WAAW,SAAS,gBAAgB;AAC1D,SAAS,eAAe;AACxB,SAAS,UAAU;AACnB,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AACzC,SAAS,eAAe;AACxB,SAAS,gBAAgB,0BAA0B;
|
|
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"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
|
|
8
8
|
function MediaEditorCropPanel({
|
|
9
9
|
aspectRatioValue,
|
|
10
10
|
onAspectRatioChange,
|
|
11
|
-
aspectRatioOptions
|
|
11
|
+
aspectRatioOptions,
|
|
12
|
+
disabled = false
|
|
12
13
|
}) {
|
|
13
14
|
return (
|
|
14
15
|
// Tag the whole panel as a crop-control region so the modal's
|
|
@@ -22,13 +23,14 @@ function MediaEditorCropPanel({
|
|
|
22
23
|
...{ [CROP_CONTROL_ATTR]: true },
|
|
23
24
|
children: [
|
|
24
25
|
/* @__PURE__ */ jsx(VisuallyHidden, { render: /* @__PURE__ */ jsx("h2", {}), children: __("Crop options") }),
|
|
25
|
-
/* @__PURE__ */ jsx(MediaEditorImageControls, { withLabels: true }),
|
|
26
|
+
/* @__PURE__ */ jsx(MediaEditorImageControls, { withLabels: true, disabled }),
|
|
26
27
|
/* @__PURE__ */ jsx(
|
|
27
28
|
SelectControl,
|
|
28
29
|
{
|
|
29
30
|
label: __("Aspect ratio"),
|
|
30
31
|
value: aspectRatioValue,
|
|
31
32
|
onChange: onAspectRatioChange,
|
|
33
|
+
disabled,
|
|
32
34
|
options: aspectRatioOptions.map((preset) => ({
|
|
33
35
|
label: preset.label,
|
|
34
36
|
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,SAAS,qBAAqB;AAC9B,SAAS,OAAO,sBAAsB;AACtC,SAAS,UAAU;AACnB,SAAS,yBAAyB;AAClC,OAAO,8BAA8B;
|
|
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,SAAS,qBAAqB;AAC9B,SAAS,OAAO,sBAAsB;AACtC,SAAS,UAAU;AACnB,SAAS,yBAAyB;AAClC,OAAO,8BAA8B;AAsCnC,SAK0B,KAL1B;AAVa,SAAR,qBAAuC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AACZ,GAA+B;AAC9B;AAAA;AAAA;AAAA;AAAA,IAIC;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,KAAI;AAAA,QACF,GAAG,EAAE,CAAE,iBAAkB,GAAG,KAAK;AAAA,QAEnC;AAAA,8BAAC,kBAAe,QAAS,oBAAC,QAAG,GAC1B,aAAI,cAAe,GACtB;AAAA,UACA,oBAAC,4BAAyB,YAAU,MAAC,UAAsB;AAAA,UAC3D;AAAA,YAAC;AAAA;AAAA,cACA,OAAQ,GAAI,cAAe;AAAA,cAC3B,OAAQ;AAAA,cACR,UAAW;AAAA,cACX;AAAA,cACA,SAAU,mBAAmB,IAAK,CAAE,YAAc;AAAA,gBACjD,OAAO,OAAO;AAAA,gBACd,OAAO,OAAO,MAAM,SAAS;AAAA,cAC9B,EAAI;AAAA;AAAA,UACL;AAAA;AAAA;AAAA,IACD;AAAA;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,7 +6,8 @@ import { MAX_ROTATION_OFFSET } from "../../image-editor/core/constants.mjs";
|
|
|
6
6
|
import RotationRuler from "../rotation-ruler/index.mjs";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
function MediaEditorFineRotation({
|
|
9
|
-
onPlacementControlInteraction
|
|
9
|
+
onPlacementControlInteraction,
|
|
10
|
+
disabled = false
|
|
10
11
|
}) {
|
|
11
12
|
const { state, setRotation } = useMediaEditor();
|
|
12
13
|
const rotationGestureHandlers = useCropGestureHandlers({
|
|
@@ -38,7 +39,8 @@ function MediaEditorFineRotation({
|
|
|
38
39
|
min: -MAX_ROTATION_OFFSET,
|
|
39
40
|
max: MAX_ROTATION_OFFSET,
|
|
40
41
|
value: fineOffset,
|
|
41
|
-
onChange: handleRotationSlider
|
|
42
|
+
onChange: handleRotationSlider,
|
|
43
|
+
disabled
|
|
42
44
|
}
|
|
43
45
|
)
|
|
44
46
|
}
|
|
@@ -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,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAC/B,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,OAAO,mBAAmB;
|
|
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,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAC/B,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,OAAO,mBAAmB;AA6DvB;AAvCY,SAAR,wBAA0C;AAAA,EAChD;AAAA,EACA,WAAW;AACZ,GAAkC;AACjC,QAAM,EAAE,OAAO,YAAY,IAAI,eAAe;AAI9C,QAAM,0BAA0B,uBAAwB;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,sBAAsB;AAAA,MACvB,KAAK,IAAK,sBAAsB,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;AAAA;AAAA,UACA,OAAQ,GAAI,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": []
|
|
7
7
|
}
|
|
@@ -28,7 +28,8 @@ function MediaEditorImageControls({
|
|
|
28
28
|
withLabels = false,
|
|
29
29
|
showAspectRatioControl = false,
|
|
30
30
|
aspectRatioPresets,
|
|
31
|
-
zoomFactor = DEFAULT_ZOOM_FACTOR
|
|
31
|
+
zoomFactor = DEFAULT_ZOOM_FACTOR,
|
|
32
|
+
disabled = false
|
|
32
33
|
}) {
|
|
33
34
|
const { state, setFlip, snapRotate90, setZoom } = useMediaEditor();
|
|
34
35
|
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } = useCropOptions({ aspectRatioPresets });
|
|
@@ -47,6 +48,8 @@ function MediaEditorImageControls({
|
|
|
47
48
|
icon: rotateLeft,
|
|
48
49
|
label: __("Rotate 90° counter-clockwise"),
|
|
49
50
|
showTooltip: true,
|
|
51
|
+
disabled,
|
|
52
|
+
accessibleWhenDisabled: true,
|
|
50
53
|
onClick: () => snapRotate90(-1)
|
|
51
54
|
}
|
|
52
55
|
),
|
|
@@ -57,6 +60,8 @@ function MediaEditorImageControls({
|
|
|
57
60
|
icon: rotateRight,
|
|
58
61
|
label: __("Rotate 90° clockwise"),
|
|
59
62
|
showTooltip: true,
|
|
63
|
+
disabled,
|
|
64
|
+
accessibleWhenDisabled: true,
|
|
60
65
|
onClick: () => snapRotate90(1)
|
|
61
66
|
}
|
|
62
67
|
)
|
|
@@ -70,6 +75,8 @@ function MediaEditorImageControls({
|
|
|
70
75
|
label: __("Flip horizontal"),
|
|
71
76
|
showTooltip: true,
|
|
72
77
|
isPressed: state.flip.horizontal,
|
|
78
|
+
disabled,
|
|
79
|
+
accessibleWhenDisabled: true,
|
|
73
80
|
onClick: () => setFlip({
|
|
74
81
|
horizontal: !state.flip.horizontal,
|
|
75
82
|
vertical: state.flip.vertical
|
|
@@ -84,6 +91,8 @@ function MediaEditorImageControls({
|
|
|
84
91
|
label: __("Flip vertical"),
|
|
85
92
|
showTooltip: true,
|
|
86
93
|
isPressed: state.flip.vertical,
|
|
94
|
+
disabled,
|
|
95
|
+
accessibleWhenDisabled: true,
|
|
87
96
|
onClick: () => setFlip({
|
|
88
97
|
horizontal: state.flip.horizontal,
|
|
89
98
|
vertical: !state.flip.vertical
|
|
@@ -99,7 +108,7 @@ function MediaEditorImageControls({
|
|
|
99
108
|
icon: plus,
|
|
100
109
|
label: __("Zoom in"),
|
|
101
110
|
showTooltip: true,
|
|
102
|
-
disabled: state.zoom >= MAX_ZOOM,
|
|
111
|
+
disabled: disabled || state.zoom >= MAX_ZOOM,
|
|
103
112
|
accessibleWhenDisabled: true,
|
|
104
113
|
onClick: () => zoomByFactor(zoomFactor)
|
|
105
114
|
}
|
|
@@ -111,7 +120,7 @@ function MediaEditorImageControls({
|
|
|
111
120
|
icon: lineSolid,
|
|
112
121
|
label: __("Zoom out"),
|
|
113
122
|
showTooltip: true,
|
|
114
|
-
disabled: state.zoom <= minZoom,
|
|
123
|
+
disabled: disabled || state.zoom <= minZoom,
|
|
115
124
|
accessibleWhenDisabled: true,
|
|
116
125
|
onClick: () => zoomByFactor(1 / zoomFactor)
|
|
117
126
|
}
|
|
@@ -123,7 +132,7 @@ function MediaEditorImageControls({
|
|
|
123
132
|
icon: aspectRatioIcon,
|
|
124
133
|
label: __("Aspect ratio"),
|
|
125
134
|
popoverProps: { placement: "top" },
|
|
126
|
-
toggleProps: { size: "compact" },
|
|
135
|
+
toggleProps: { size: "compact", disabled },
|
|
127
136
|
children: ({ onClose }) => /* @__PURE__ */ jsx(MenuGroup, { label: __("Aspect ratio"), children: aspectRatioOptions.map((preset) => {
|
|
128
137
|
const value = preset.value.toString();
|
|
129
138
|
const isSelected = value === aspectRatioValue;
|
|
@@ -133,7 +142,11 @@ function MediaEditorImageControls({
|
|
|
133
142
|
role: "menuitemradio",
|
|
134
143
|
isSelected,
|
|
135
144
|
icon: isSelected ? check : void 0,
|
|
145
|
+
disabled,
|
|
136
146
|
onClick: () => {
|
|
147
|
+
if (disabled) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
137
150
|
setAspectRatioValue(value);
|
|
138
151
|
onClose();
|
|
139
152
|
},
|