@wordpress/media-editor 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/build/components/media-editor/index.cjs +157 -107
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +18 -8
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +9 -7
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +9 -7
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +9 -7
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +32 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-preview/index.cjs +143 -36
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +2 -2
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +9 -7
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +142 -95
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +9 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +32 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-preview/index.mjs +123 -40
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +2 -2
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +18 -30
- package/build-style/style.css +18 -30
- package/build-types/components/media-editor/index.d.ts +8 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +7 -2
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +26 -22
- package/src/components/media-editor/index.tsx +209 -114
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +55 -63
- package/src/components/media-editor-modal/index.tsx +3 -0
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-preview/index.tsx +195 -36
- package/src/components/media-preview/style.scss +11 -32
- package/src/state/README.md +3 -1
- package/src/state/use-media-editor-state.ts +7 -2
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
|
@@ -9,8 +9,11 @@ import {
|
|
|
9
9
|
__experimentalConfirmDialog as ConfirmDialog,
|
|
10
10
|
__unstableAnimatePresence as AnimatePresence,
|
|
11
11
|
__unstableMotion as motion,
|
|
12
|
+
Slot,
|
|
13
|
+
SlotFillProvider,
|
|
12
14
|
} from '@wordpress/components';
|
|
13
15
|
import { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';
|
|
16
|
+
import { PluginArea } from '@wordpress/plugins';
|
|
14
17
|
import { useReducedMotion, useViewportMatch } from '@wordpress/compose';
|
|
15
18
|
import { useDispatch, useRegistry, useSelect } from '@wordpress/data';
|
|
16
19
|
import { store as coreStore } from '@wordpress/core-data';
|
|
@@ -39,8 +42,10 @@ import {
|
|
|
39
42
|
displayShortcut,
|
|
40
43
|
isAppleOS,
|
|
41
44
|
isKeyboardEvent,
|
|
45
|
+
withIgnoreIMEEvents,
|
|
42
46
|
} from '@wordpress/keycodes';
|
|
43
47
|
import { SnackbarNotices, store as noticesStore } from '@wordpress/notices';
|
|
48
|
+
import { inertValue } from '@wordpress/react-inert-value';
|
|
44
49
|
import type { Action, ActionModal, Field, Form } from '@wordpress/dataviews';
|
|
45
50
|
import type {
|
|
46
51
|
KeyboardEvent as ReactKeyboardEvent,
|
|
@@ -56,6 +61,13 @@ import MediaEditorFineRotation from '../media-editor-fine-rotation';
|
|
|
56
61
|
import MediaEditorCropPanel from '../media-editor-crop-panel';
|
|
57
62
|
import MediaEditorImageControls from '../media-editor-image-controls';
|
|
58
63
|
import MediaForm from '../media-form';
|
|
64
|
+
import MediaEditorPanel, {
|
|
65
|
+
MEDIA_EDITOR_PLUGIN_SCOPE,
|
|
66
|
+
MediaEditorPanelsProvider,
|
|
67
|
+
getPanelSlotName,
|
|
68
|
+
useMediaEditorPanels,
|
|
69
|
+
type MediaEditorPanelFillProps,
|
|
70
|
+
} from '../media-editor-panel';
|
|
59
71
|
import { getMediaTypeFromMimeType } from '../../utils';
|
|
60
72
|
import { MediaEditorStateProvider, useMediaEditor } from '../../state';
|
|
61
73
|
import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
|
|
@@ -77,15 +89,18 @@ const ATTACHMENT_EMBED_QUERY = { _embed: 'author,wp:attached-to' } as const;
|
|
|
77
89
|
const PLACEMENT_CONTROL_IDLE_MS = 300;
|
|
78
90
|
|
|
79
91
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
92
|
+
* The Details panel's id. Every media type has this panel, so the sidebar
|
|
93
|
+
* shows it when the requested panel doesn't exist.
|
|
94
|
+
*
|
|
95
|
+
* The sidebar stores the open panel's id, so adding a panel only needs a new
|
|
96
|
+
* id and a new tab.
|
|
84
97
|
*/
|
|
85
|
-
const DETAILS_PANEL = 'details';
|
|
98
|
+
const DETAILS_PANEL = 'core/details';
|
|
86
99
|
|
|
87
100
|
/** Identifier for the crop panel. Images only; other media has nothing to crop. */
|
|
88
|
-
const CROP_PANEL = 'crop';
|
|
101
|
+
const CROP_PANEL = 'core/crop';
|
|
102
|
+
|
|
103
|
+
const CROP_MEDIA_TYPES = [ 'image' ] as const;
|
|
89
104
|
|
|
90
105
|
// Matches the editor's sidebar in `ComplementaryArea`.
|
|
91
106
|
const SIDEBAR_ANIMATION_DURATION = 0.3;
|
|
@@ -151,6 +166,14 @@ export interface MediaEditorProps {
|
|
|
151
166
|
noticesClassName?: string;
|
|
152
167
|
noticesPortalElement?: Element | null;
|
|
153
168
|
shouldCloseOnEsc?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* The id of the panel to open on, which is also shown as the first tab.
|
|
171
|
+
* Below `small`, or when no tab has this id, the sidebar opens on
|
|
172
|
+
* Details.
|
|
173
|
+
*
|
|
174
|
+
* @default 'core/details'
|
|
175
|
+
*/
|
|
176
|
+
defaultPanel?: string;
|
|
154
177
|
}
|
|
155
178
|
|
|
156
179
|
interface MediaEditorSidebarProps {
|
|
@@ -210,6 +233,10 @@ function MediaEditorSidebar( {
|
|
|
210
233
|
value={ tab.id }
|
|
211
234
|
tabIndex={ -1 }
|
|
212
235
|
className="media-editor__panel"
|
|
236
|
+
// A save reads the session once and then waits, so
|
|
237
|
+
// nothing in the panel may act on it meanwhile.
|
|
238
|
+
// `inert` covers panels that ignore `disabled`.
|
|
239
|
+
inert={ inertValue( disabled ) }
|
|
213
240
|
>
|
|
214
241
|
<Stack direction="column" gap="lg">
|
|
215
242
|
{ tab.render() }
|
|
@@ -285,6 +312,20 @@ function useMediaEditorFrameContext(): MediaEditorFrameContextValue {
|
|
|
285
312
|
return context;
|
|
286
313
|
}
|
|
287
314
|
|
|
315
|
+
function CropPanelContent( { disabled }: MediaEditorPanelFillProps ) {
|
|
316
|
+
const { aspectRatioPresets } = useMediaEditorFrameContext();
|
|
317
|
+
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
|
|
318
|
+
useCropOptions( { aspectRatioPresets } );
|
|
319
|
+
return (
|
|
320
|
+
<MediaEditorCropPanel
|
|
321
|
+
aspectRatioValue={ aspectRatioValue }
|
|
322
|
+
onAspectRatioChange={ setAspectRatioValue }
|
|
323
|
+
aspectRatioOptions={ aspectRatioOptions }
|
|
324
|
+
disabled={ disabled }
|
|
325
|
+
/>
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
288
329
|
export interface HeaderActionsProps {
|
|
289
330
|
/**
|
|
290
331
|
* Whether to include a Close button. Frames with a dismissal affordance of
|
|
@@ -680,6 +721,7 @@ function MediaEditorContent( {
|
|
|
680
721
|
noticesClassName = 'media-editor__snackbar',
|
|
681
722
|
noticesPortalElement,
|
|
682
723
|
shouldCloseOnEsc = false,
|
|
724
|
+
defaultPanel = DETAILS_PANEL,
|
|
683
725
|
}: MediaEditorProps ) {
|
|
684
726
|
const session = useMediaEditor();
|
|
685
727
|
// Width decides whether the settings panel docks beside the canvas or
|
|
@@ -731,7 +773,23 @@ function MediaEditorContent( {
|
|
|
731
773
|
|
|
732
774
|
const { clearEntityRecordEdits, editEntityRecord, invalidateResolution } =
|
|
733
775
|
useDispatch( coreStore );
|
|
734
|
-
const { removeAllNotices } = useDispatch( noticesStore );
|
|
776
|
+
const { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );
|
|
777
|
+
// `PluginArea` drops a plugin whose render throws; tell the user.
|
|
778
|
+
const handlePluginError = useCallback(
|
|
779
|
+
( name: string ) => {
|
|
780
|
+
createErrorNotice(
|
|
781
|
+
sprintf(
|
|
782
|
+
/* translators: %s: plugin name */
|
|
783
|
+
__(
|
|
784
|
+
'The "%s" plugin has encountered an error and cannot be rendered.'
|
|
785
|
+
),
|
|
786
|
+
name
|
|
787
|
+
),
|
|
788
|
+
{ type: 'snackbar', context: MEDIA_EDITOR_NOTICES_CONTEXT }
|
|
789
|
+
);
|
|
790
|
+
},
|
|
791
|
+
[ createErrorNotice ]
|
|
792
|
+
);
|
|
735
793
|
|
|
736
794
|
const [ isDiscardDialogOpen, setIsDiscardDialogOpen ] = useState( false );
|
|
737
795
|
const [ isPlacementActive, setIsPlacementActive ] = useState( false );
|
|
@@ -865,18 +923,17 @@ function MediaEditorContent( {
|
|
|
865
923
|
}, [ clearEntityRecordEdits, id, onEditOriginal, originalId ] );
|
|
866
924
|
|
|
867
925
|
// A bare replacement has no image editor change, so OR the flag in explicitly.
|
|
926
|
+
// Nothing saves named edits (`session.edits`), so `hasOutputEdits` leaves
|
|
927
|
+
// them out: counting them would enable Save for a change it then drops.
|
|
868
928
|
const hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;
|
|
869
929
|
|
|
870
930
|
const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
|
|
871
931
|
const isImage = !! media && mediaType === 'image';
|
|
872
932
|
|
|
873
|
-
//
|
|
874
|
-
//
|
|
875
|
-
// the
|
|
876
|
-
|
|
877
|
-
// all (see `tabs`), so it always gets Details.
|
|
878
|
-
const currentTab =
|
|
879
|
-
chosenTab ?? ( isWide && isImage ? CROP_PANEL : DETAILS_PANEL );
|
|
933
|
+
// Below `small` the panel covers the canvas, so open on Details rather
|
|
934
|
+
// than a panel that needs the canvas in view. If no tab matches
|
|
935
|
+
// `defaultPanel`, the sidebar shows Details (see `activeTab` below).
|
|
936
|
+
const currentTab = chosenTab ?? ( isWide ? defaultPanel : DETAILS_PANEL );
|
|
880
937
|
// `null` when nothing is open, otherwise the open panel's id. Until the
|
|
881
938
|
// user opens or closes the panel, follow the breakpoint: dragging a window
|
|
882
939
|
// narrow hands the canvas the full width instead of leaving a panel
|
|
@@ -897,8 +954,6 @@ function MediaEditorContent( {
|
|
|
897
954
|
const togglePanel = useCallback( () => {
|
|
898
955
|
setChosenPanel( activePanel ? null : currentTab );
|
|
899
956
|
}, [ activePanel, currentTab ] );
|
|
900
|
-
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
|
|
901
|
-
useCropOptions( { aspectRatioPresets } );
|
|
902
957
|
const { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {
|
|
903
958
|
session,
|
|
904
959
|
id,
|
|
@@ -938,45 +993,47 @@ function MediaEditorContent( {
|
|
|
938
993
|
discardAndClose();
|
|
939
994
|
};
|
|
940
995
|
|
|
941
|
-
const handleKeyDown = (
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
target.tagName === '
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
996
|
+
const handleKeyDown = withIgnoreIMEEvents(
|
|
997
|
+
( event: ReactKeyboardEvent< HTMLElement > ) => {
|
|
998
|
+
const isUndoShortcut = isKeyboardEvent.primary( event, 'z' );
|
|
999
|
+
const isRedoShortcut =
|
|
1000
|
+
isKeyboardEvent.primaryShift( event, 'z' ) ||
|
|
1001
|
+
( ! isAppleOS() && isKeyboardEvent.primary( event, 'y' ) );
|
|
1002
|
+
if ( ( isUndoShortcut || isRedoShortcut ) && isImage ) {
|
|
1003
|
+
const target = event.target as HTMLElement;
|
|
1004
|
+
const isMetadataField =
|
|
1005
|
+
( target.tagName === 'INPUT' ||
|
|
1006
|
+
target.tagName === 'TEXTAREA' ||
|
|
1007
|
+
target.isContentEditable ) &&
|
|
1008
|
+
! target.closest( `[${ CROP_CONTROL_ATTR }]` );
|
|
1009
|
+
if ( ! isMetadataField ) {
|
|
1010
|
+
event.preventDefault();
|
|
1011
|
+
if ( isCropInteractionActive || isSaving ) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if ( isRedoShortcut ) {
|
|
1015
|
+
session.redo();
|
|
1016
|
+
} else {
|
|
1017
|
+
session.undo();
|
|
1018
|
+
}
|
|
962
1019
|
}
|
|
963
1020
|
}
|
|
964
|
-
}
|
|
965
1021
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1022
|
+
if ( shouldCloseOnEsc ) {
|
|
1023
|
+
if ( event.code !== 'Escape' && event.key !== 'Escape' ) {
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
if ( isSaving ) {
|
|
1027
|
+
event.preventDefault();
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
if ( hasChanges ) {
|
|
1031
|
+
event.preventDefault();
|
|
1032
|
+
setIsDiscardDialogOpen( true );
|
|
1033
|
+
}
|
|
977
1034
|
}
|
|
978
1035
|
}
|
|
979
|
-
|
|
1036
|
+
);
|
|
980
1037
|
|
|
981
1038
|
const snackbar = (
|
|
982
1039
|
<SnackbarNotices
|
|
@@ -999,32 +1056,31 @@ function MediaEditorContent( {
|
|
|
999
1056
|
/>
|
|
1000
1057
|
) : null;
|
|
1001
1058
|
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
];
|
|
1059
|
+
const { panels, contextValue: panelsContextValue } = useMediaEditorPanels();
|
|
1060
|
+
const availableTabs: MediaEditorTab[] = panels
|
|
1061
|
+
.filter(
|
|
1062
|
+
( panel ) =>
|
|
1063
|
+
! panel.mediaTypes || panel.mediaTypes.includes( mediaType )
|
|
1064
|
+
)
|
|
1065
|
+
.map( ( panel ) => ( {
|
|
1066
|
+
id: panel.name,
|
|
1067
|
+
title: panel.title,
|
|
1068
|
+
render: () => (
|
|
1069
|
+
<Slot
|
|
1070
|
+
bubblesVirtually
|
|
1071
|
+
name={ getPanelSlotName( panel.name ) }
|
|
1072
|
+
fillProps={ { disabled: isSaving } }
|
|
1073
|
+
/>
|
|
1074
|
+
),
|
|
1075
|
+
} ) );
|
|
1076
|
+
// Put the default panel first and keep the others in order.
|
|
1077
|
+
const defaultTab = availableTabs.find( ( tab ) => tab.id === defaultPanel );
|
|
1078
|
+
const tabs = defaultTab
|
|
1079
|
+
? [
|
|
1080
|
+
defaultTab,
|
|
1081
|
+
...availableTabs.filter( ( tab ) => tab !== defaultTab ),
|
|
1082
|
+
]
|
|
1083
|
+
: availableTabs;
|
|
1028
1084
|
|
|
1029
1085
|
const ruler = isImage ? (
|
|
1030
1086
|
<MediaEditorFineRotation
|
|
@@ -1034,23 +1090,7 @@ function MediaEditorContent( {
|
|
|
1034
1090
|
) : null;
|
|
1035
1091
|
|
|
1036
1092
|
const children = (
|
|
1037
|
-
|
|
1038
|
-
value={ media ?? undefined }
|
|
1039
|
-
onChange={ handleChange }
|
|
1040
|
-
settings={ {
|
|
1041
|
-
// Disable the fields while saving, so the guard in
|
|
1042
|
-
// `handleChange` is not silently swallowing typing.
|
|
1043
|
-
// `readOnly` would swap the field's layout mid-save;
|
|
1044
|
-
// disabled keeps it in place and greys it out.
|
|
1045
|
-
fields: isSaving
|
|
1046
|
-
? fields.map( ( field ) => ( {
|
|
1047
|
-
...field,
|
|
1048
|
-
isDisabled: true,
|
|
1049
|
-
} ) )
|
|
1050
|
-
: fields,
|
|
1051
|
-
form,
|
|
1052
|
-
} }
|
|
1053
|
-
>
|
|
1093
|
+
<>
|
|
1054
1094
|
<div className="media-editor">
|
|
1055
1095
|
{ ! media ? (
|
|
1056
1096
|
<div className="media-editor__loading">
|
|
@@ -1104,25 +1144,31 @@ function MediaEditorContent( {
|
|
|
1104
1144
|
exit="closed"
|
|
1105
1145
|
transition={ sidebarTransition }
|
|
1106
1146
|
>
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1147
|
+
{ /* Panels announce their tabs after the
|
|
1148
|
+
first render. Waiting for them outside
|
|
1149
|
+
this container would slide it in on
|
|
1150
|
+
every open. */ }
|
|
1151
|
+
{ tabs.length > 0 && (
|
|
1152
|
+
<MediaEditorSidebar
|
|
1153
|
+
tabs={ tabs }
|
|
1154
|
+
// Swapping the edited media can drop the
|
|
1155
|
+
// Crop tab out from under an open panel —
|
|
1156
|
+
// saving a crop moves the editor to a new
|
|
1157
|
+
// id, which may resolve as non-image.
|
|
1158
|
+
// Fall back rather than hand `Tabs.Root`
|
|
1159
|
+
// a value no tab matches.
|
|
1160
|
+
activeTab={
|
|
1161
|
+
tabs.some(
|
|
1162
|
+
( tab ) =>
|
|
1163
|
+
tab.id === activePanel
|
|
1164
|
+
)
|
|
1165
|
+
? activePanel
|
|
1166
|
+
: DETAILS_PANEL
|
|
1167
|
+
}
|
|
1168
|
+
onSelectTab={ selectPanel }
|
|
1169
|
+
disabled={ isSaving }
|
|
1170
|
+
/>
|
|
1171
|
+
) }
|
|
1126
1172
|
</motion.div>
|
|
1127
1173
|
) }
|
|
1128
1174
|
</AnimatePresence>
|
|
@@ -1146,7 +1192,7 @@ function MediaEditorContent( {
|
|
|
1146
1192
|
{ noticesPortalElement
|
|
1147
1193
|
? createPortal( snackbar, noticesPortalElement )
|
|
1148
1194
|
: snackbar }
|
|
1149
|
-
|
|
1195
|
+
</>
|
|
1150
1196
|
);
|
|
1151
1197
|
|
|
1152
1198
|
// Rebuilt each render, like the elements it replaces: consumers re-render
|
|
@@ -1175,7 +1221,56 @@ function MediaEditorContent( {
|
|
|
1175
1221
|
return (
|
|
1176
1222
|
<MediaEditorFrameContext.Provider value={ contextValue }>
|
|
1177
1223
|
{ renderFrame( {
|
|
1178
|
-
children
|
|
1224
|
+
children: (
|
|
1225
|
+
<MediaEditorProvider
|
|
1226
|
+
value={ media ?? undefined }
|
|
1227
|
+
onChange={ handleChange }
|
|
1228
|
+
settings={ {
|
|
1229
|
+
// Disable the fields while saving, so the guard in
|
|
1230
|
+
// `handleChange` is not silently swallowing typing.
|
|
1231
|
+
// `readOnly` would swap the field's layout mid-save;
|
|
1232
|
+
// disabled keeps it in place and greys it out.
|
|
1233
|
+
fields: isSaving
|
|
1234
|
+
? fields.map( ( field ) => ( {
|
|
1235
|
+
...field,
|
|
1236
|
+
isDisabled: true,
|
|
1237
|
+
} ) )
|
|
1238
|
+
: fields,
|
|
1239
|
+
form,
|
|
1240
|
+
} }
|
|
1241
|
+
>
|
|
1242
|
+
<SlotFillProvider>
|
|
1243
|
+
<MediaEditorPanelsProvider
|
|
1244
|
+
value={ panelsContextValue }
|
|
1245
|
+
>
|
|
1246
|
+
{ /* Inside the session and `MediaEditorProvider`, so
|
|
1247
|
+
panel content can read both. */ }
|
|
1248
|
+
<MediaEditorPanel
|
|
1249
|
+
name={ CROP_PANEL }
|
|
1250
|
+
title={ __( 'Crop' ) }
|
|
1251
|
+
mediaTypes={ CROP_MEDIA_TYPES }
|
|
1252
|
+
>
|
|
1253
|
+
{ ( { disabled } ) => (
|
|
1254
|
+
<CropPanelContent
|
|
1255
|
+
disabled={ disabled }
|
|
1256
|
+
/>
|
|
1257
|
+
) }
|
|
1258
|
+
</MediaEditorPanel>
|
|
1259
|
+
<MediaEditorPanel
|
|
1260
|
+
name={ DETAILS_PANEL }
|
|
1261
|
+
title={ __( 'Details' ) }
|
|
1262
|
+
>
|
|
1263
|
+
<MediaForm />
|
|
1264
|
+
</MediaEditorPanel>
|
|
1265
|
+
<PluginArea
|
|
1266
|
+
scope={ MEDIA_EDITOR_PLUGIN_SCOPE }
|
|
1267
|
+
onError={ handlePluginError }
|
|
1268
|
+
/>
|
|
1269
|
+
{ children }
|
|
1270
|
+
</MediaEditorPanelsProvider>
|
|
1271
|
+
</SlotFillProvider>
|
|
1272
|
+
</MediaEditorProvider>
|
|
1273
|
+
),
|
|
1179
1274
|
isImage,
|
|
1180
1275
|
layout,
|
|
1181
1276
|
onRequestClose: handleRequestClose,
|
|
@@ -120,6 +120,13 @@
|
|
|
120
120
|
height: 100%;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
// The grey stage is for previewing media. Without a preview, e.g. for
|
|
124
|
+
// a zip file or a file that failed to load, the placeholder sits on
|
|
125
|
+
// the surface instead.
|
|
126
|
+
&:has(.media-editor-preview.is-placeholder) {
|
|
127
|
+
background: none;
|
|
128
|
+
}
|
|
129
|
+
|
|
123
130
|
img,
|
|
124
131
|
video {
|
|
125
132
|
max-width: 100%;
|
|
@@ -168,6 +175,18 @@
|
|
|
168
175
|
}
|
|
169
176
|
}
|
|
170
177
|
|
|
178
|
+
// The grey stage normally marks the panel's edge. Without it, e.g. for a
|
|
179
|
+
// file without a preview, the panel takes a border instead.
|
|
180
|
+
.media-editor__body:has(.media-editor-preview.is-placeholder)
|
|
181
|
+
.media-editor__sidebar {
|
|
182
|
+
@include break-small() {
|
|
183
|
+
// Matches the page header's bottom border in the route.
|
|
184
|
+
border-inline-start:
|
|
185
|
+
var(--wpds-border-width-xs) solid
|
|
186
|
+
var(--wpds-color-stroke-surface-neutral-weak);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
171
190
|
// The strip and the open pane, stacked. No inline padding: the pane below
|
|
172
191
|
// scrolls, and a gutter here would inset its scrollbar from the sidebar
|
|
173
192
|
// edge. The strip and the pane carry their own instead.
|
|
@@ -222,9 +241,10 @@
|
|
|
222
241
|
.media-editor__body.has-panel-open .media-editor__content {
|
|
223
242
|
display: none;
|
|
224
243
|
|
|
244
|
+
// Only remove the right margin, so the route's bottom margin still applies.
|
|
225
245
|
@include break-small() {
|
|
226
246
|
display: flex;
|
|
227
|
-
margin: 0
|
|
247
|
+
margin-right: 0;
|
|
228
248
|
}
|
|
229
249
|
}
|
|
230
250
|
|
|
@@ -6,20 +6,27 @@ import {
|
|
|
6
6
|
shortcutAriaLabel,
|
|
7
7
|
type WPKeycodeModifier,
|
|
8
8
|
} from '@wordpress/keycodes';
|
|
9
|
+
import { VisuallyHidden } from '@wordpress/ui';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
11
|
+
type KeyCombinationDisplayProps =
|
|
12
|
+
| {
|
|
13
|
+
keyCombination: {
|
|
14
|
+
character: string;
|
|
15
|
+
modifier?: WPKeycodeModifier | null;
|
|
16
|
+
};
|
|
17
|
+
label?: string;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
keyCombination: {
|
|
21
|
+
character: string[];
|
|
22
|
+
modifier?: WPKeycodeModifier | null;
|
|
23
|
+
};
|
|
24
|
+
label: string;
|
|
25
|
+
};
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
type ShortcutEntry = KeyCombinationDisplayProps & {
|
|
20
28
|
description: string;
|
|
21
|
-
|
|
22
|
-
}
|
|
29
|
+
};
|
|
23
30
|
|
|
24
31
|
const SHORTCUTS: ShortcutEntry[] = [
|
|
25
32
|
{
|
|
@@ -34,8 +41,8 @@ const SHORTCUTS: ShortcutEntry[] = [
|
|
|
34
41
|
description: __( 'Pan' ),
|
|
35
42
|
keyCombination: {
|
|
36
43
|
character: [ '↑', '↓', '←', '→' ],
|
|
37
|
-
ariaLabel: __( 'Arrow keys' ),
|
|
38
44
|
},
|
|
45
|
+
label: __( 'Arrow keys' ),
|
|
39
46
|
},
|
|
40
47
|
{
|
|
41
48
|
description: __( 'Zoom in' ),
|
|
@@ -66,64 +73,51 @@ const SHORTCUTS: ShortcutEntry[] = [
|
|
|
66
73
|
keyCombination: {
|
|
67
74
|
modifier: 'shift',
|
|
68
75
|
character: [ '↑', '↓', '←', '→' ],
|
|
69
|
-
ariaLabel: __( 'Shift + Arrow keys' ),
|
|
70
76
|
},
|
|
77
|
+
label: __( 'Shift + Arrow keys' ),
|
|
71
78
|
},
|
|
72
79
|
];
|
|
73
80
|
|
|
74
81
|
function KeyCombinationDisplay( {
|
|
75
82
|
keyCombination,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} else {
|
|
89
|
-
keys = character;
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
keys = modifier
|
|
93
|
-
? displayShortcutList[ modifier ]( character )
|
|
94
|
-
: [ character ];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const charString = Array.isArray( character )
|
|
98
|
-
? character.join( '' )
|
|
99
|
-
: character;
|
|
100
|
-
let label: string;
|
|
101
|
-
if ( ariaLabel ) {
|
|
102
|
-
label = ariaLabel;
|
|
103
|
-
} else if ( modifier ) {
|
|
104
|
-
label = shortcutAriaLabel[ modifier ]( charString );
|
|
105
|
-
} else {
|
|
106
|
-
label = charString;
|
|
107
|
-
}
|
|
83
|
+
label,
|
|
84
|
+
}: KeyCombinationDisplayProps ) {
|
|
85
|
+
const { character, modifier } = keyCombination;
|
|
86
|
+
const normalizedModifier = modifier ?? 'undefined';
|
|
87
|
+
const characters = Array.isArray( character ) ? character : [ character ];
|
|
88
|
+
const formatted = displayShortcutList[ normalizedModifier ](
|
|
89
|
+
characters[ 0 ] ?? ''
|
|
90
|
+
);
|
|
91
|
+
const prefix = formatted.slice( 0, -1 );
|
|
92
|
+
const keys = Array.isArray( character )
|
|
93
|
+
? [ ...prefix, ...character ]
|
|
94
|
+
: formatted;
|
|
108
95
|
|
|
109
96
|
return (
|
|
110
97
|
<kbd
|
|
111
98
|
className="media-editor-keyboard-shortcuts-modal__shortcut-term"
|
|
112
99
|
dir="ltr"
|
|
113
|
-
aria-label={ label }
|
|
114
100
|
>
|
|
115
|
-
{
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
101
|
+
<VisuallyHidden render={ <span /> }>
|
|
102
|
+
{ label ||
|
|
103
|
+
shortcutAriaLabel[ normalizedModifier ](
|
|
104
|
+
characters.join( '' )
|
|
105
|
+
) }
|
|
106
|
+
</VisuallyHidden>
|
|
107
|
+
<span aria-hidden="true">
|
|
108
|
+
{ keys.map( ( key, keyIndex ) =>
|
|
109
|
+
key === '+' && keyIndex < prefix.length ? (
|
|
110
|
+
<Fragment key={ keyIndex }>{ key }</Fragment>
|
|
111
|
+
) : (
|
|
112
|
+
<kbd
|
|
113
|
+
key={ keyIndex }
|
|
114
|
+
className="media-editor-keyboard-shortcuts-modal__shortcut-key"
|
|
115
|
+
>
|
|
116
|
+
{ key }
|
|
117
|
+
</kbd>
|
|
118
|
+
)
|
|
119
|
+
) }
|
|
120
|
+
</span>
|
|
127
121
|
</kbd>
|
|
128
122
|
);
|
|
129
123
|
}
|
|
@@ -155,17 +149,15 @@ export default function MediaEditorKeyboardShortcutsModal( {
|
|
|
155
149
|
className="media-editor-keyboard-shortcuts-modal__shortcut-list"
|
|
156
150
|
role="list"
|
|
157
151
|
>
|
|
158
|
-
{ SHORTCUTS.map( (
|
|
152
|
+
{ SHORTCUTS.map( ( shortcut, index ) => (
|
|
159
153
|
<li
|
|
160
154
|
key={ index }
|
|
161
155
|
className="media-editor-keyboard-shortcuts-modal__shortcut"
|
|
162
156
|
>
|
|
163
157
|
<span className="media-editor-keyboard-shortcuts-modal__shortcut-description">
|
|
164
|
-
{ description }
|
|
158
|
+
{ shortcut.description }
|
|
165
159
|
</span>
|
|
166
|
-
<KeyCombinationDisplay
|
|
167
|
-
keyCombination={ keyCombination }
|
|
168
|
-
/>
|
|
160
|
+
<KeyCombinationDisplay { ...shortcut } />
|
|
169
161
|
</li>
|
|
170
162
|
) ) }
|
|
171
163
|
</ul>
|
|
@@ -104,6 +104,9 @@ export function MediaEditorModal( {
|
|
|
104
104
|
shouldCloseOnEsc
|
|
105
105
|
noticesClassName="media-editor-modal__snackbar"
|
|
106
106
|
noticesPortalElement={ portalElement }
|
|
107
|
+
// Rotate, flip and aspect ratio are only in the Crop panel for now.
|
|
108
|
+
// This can go once they move under the canvas (#87282).
|
|
109
|
+
defaultPanel="core/crop"
|
|
107
110
|
onClose={ handleClose }
|
|
108
111
|
onSaved={ ( { id: savedId, url, previous } ) => {
|
|
109
112
|
if ( savedId && onUpdate ) {
|