@wordpress/media-editor 0.10.0 → 0.10.1
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/build/components/media-editor/index.cjs +185 -42
- package/build/components/media-editor/index.cjs.map +3 -3
- package/build/components/media-editor/use-crop-options.cjs +2 -26
- package/build/components/media-editor/use-crop-options.cjs.map +2 -2
- package/build/components/media-editor-canvas/index.cjs +2 -2
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +24 -21
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-fine-rotation/index.cjs +81 -0
- package/build/components/media-editor-fine-rotation/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +25 -7
- package/build/components/media-editor-modal/index.cjs.map +2 -2
- package/build/components/media-editor-transform-controls/index.cjs +84 -0
- package/build/components/media-editor-transform-controls/index.cjs.map +7 -0
- package/build/hooks/use-crop-gesture-handlers.cjs +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs +1 -1
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +1 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +1 -3
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs +1 -1
- package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
- package/build/state/composite-reducer.cjs +2 -14
- package/build/state/composite-reducer.cjs.map +2 -2
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +2 -2
- package/build/state/use-media-editor-state.cjs +0 -11
- package/build/state/use-media-editor-state.cjs.map +2 -2
- package/build/store/actions.cjs +4 -2
- package/build/store/actions.cjs.map +2 -2
- package/build/store/reducer.cjs +5 -3
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs +5 -0
- package/build/store/selectors.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +191 -44
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-crop-options.mjs +3 -27
- package/build-module/components/media-editor/use-crop-options.mjs.map +2 -2
- package/build-module/components/media-editor-canvas/index.mjs +2 -2
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +25 -26
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs +50 -0
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +26 -8
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-transform-controls/index.mjs +68 -0
- package/build-module/components/media-editor-transform-controls/index.mjs.map +7 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs +1 -1
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +1 -1
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +1 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +1 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs +1 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
- package/build-module/state/composite-reducer.mjs +2 -14
- package/build-module/state/composite-reducer.mjs.map +2 -2
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +2 -2
- package/build-module/state/use-media-editor-state.mjs +0 -11
- package/build-module/state/use-media-editor-state.mjs.map +2 -2
- package/build-module/store/actions.mjs +4 -2
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/reducer.mjs +5 -3
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs +4 -0
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-style/style-rtl.css +51 -35
- package/build-style/style.css +51 -35
- package/build-types/components/media-editor/index.d.ts +14 -2
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +3 -5
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +3 -10
- 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 +14 -0
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-transform-controls/index.d.ts +8 -0
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
- 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-aria-announcer.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/types.d.ts +3 -11
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +2 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +3 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +3 -0
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +1 -0
- package/build-types/store/selectors.d.ts.map +1 -1
- package/package.json +20 -19
- package/src/components/media-editor/index.tsx +226 -57
- package/src/components/media-editor/style.scss +0 -9
- package/src/components/media-editor/test/use-crop-options.tsx +1 -55
- package/src/components/media-editor/use-crop-options.ts +6 -42
- package/src/components/media-editor-canvas/index.tsx +2 -2
- package/src/components/media-editor-crop-panel/index.tsx +35 -33
- package/src/components/media-editor-crop-panel/test/index.tsx +39 -20
- package/src/components/media-editor-fine-rotation/index.tsx +74 -0
- package/src/components/media-editor-modal/index.tsx +20 -4
- package/src/components/media-editor-modal/style.scss +80 -0
- package/src/components/media-editor-modal/test/index.tsx +3 -0
- package/src/components/media-editor-transform-controls/index.tsx +70 -0
- package/src/components/media-editor-transform-controls/style.scss +8 -0
- package/src/hooks/use-crop-gesture-handlers.ts +1 -3
- package/src/image-editor/docs/recipes.md +2 -2
- package/src/image-editor/react/components/cropper.tsx +1 -3
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +1 -3
- package/src/image-editor/react/hooks/use-aria-announcer.ts +1 -3
- package/src/image-editor/react/hooks/use-interaction.ts +2 -3
- package/src/state/composite-reducer.ts +2 -17
- package/src/state/test/use-media-editor-state.ts +3 -75
- package/src/state/types.ts +3 -9
- package/src/state/use-media-editor-state.ts +3 -19
- package/src/store/actions.ts +3 -0
- package/src/store/reducer.ts +6 -1
- package/src/store/selectors.ts +4 -0
- package/src/store/test/reducer.ts +9 -0
- package/src/style.scss +1 -1
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/media-editor-toolbar/index.cjs +0 -218
- package/build/components/media-editor-toolbar/index.cjs.map +0 -7
- package/build-module/components/media-editor-toolbar/index.mjs +0 -194
- package/build-module/components/media-editor-toolbar/index.mjs.map +0 -7
- package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
- package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
- package/src/components/media-editor-toolbar/index.tsx +0 -213
- package/src/components/media-editor-toolbar/style.scss +0 -49
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tFlex,\n\tSpinner,\n\t__experimentalConfirmDialog as ConfirmDialog,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tcreatePortal,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { close, drawerRight, keyboard } from '@wordpress/icons';\nimport { isAppleOS, isKeyboardEvent } from '@wordpress/keycodes';\nimport { SnackbarNotices, store as noticesStore } from '@wordpress/notices';\nimport type { Field } from '@wordpress/dataviews';\nimport {\n\tComplementaryArea,\n\tInterfaceSkeleton,\n\tPinnedItems,\n\t// No type declarations available for @wordpress/interface.\n\t// @ts-expect-error\n} from '@wordpress/interface';\nimport type {\n\tJSX,\n\tKeyboardEvent as ReactKeyboardEvent,\n\tReactNode,\n} from 'react';\n\n/**\n * Internal dependencies\n */\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 MediaEditorToolbar from '../media-editor-toolbar';\nimport MediaEditorCropPanel from '../media-editor-crop-panel';\nimport MediaForm from '../media-form';\nimport { unlock } from '../../lock-unlock';\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\nconst { Tabs } = unlock( componentsPrivateApis );\n\ninterface EditorTab {\n\tid: string;\n\ttitle: string;\n\tpanel: JSX.Element;\n}\n\nexport interface MediaEditorFrameProps {\n\tchildren: ReactNode;\n\theaderActions: ReactNode;\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\tshowCloseButton?: boolean;\n\tshouldCloseOnEsc?: boolean;\n}\n\nfunction MediaEditorSidebar( { tabs }: { tabs: EditorTab[] } ) {\n\tconst tabsContextValue = useContext( Tabs.Context );\n\treturn (\n\t\t<ComplementaryArea\n\t\t\tscope=\"media-editor\"\n\t\t\tidentifier=\"media-editor/details\"\n\t\t\ttitle={ __( 'Details' ) }\n\t\t\ticon={ drawerRight }\n\t\t\tisActiveByDefault\n\t\t\tclassName=\"media-editor__sidebar\"\n\t\t\tpanelClassName=\"media-editor__sidebar-panel\"\n\t\t\theaderClassName=\"media-editor__sidebar-header\"\n\t\t\theader={\n\t\t\t\t<Tabs.Context.Provider value={ tabsContextValue }>\n\t\t\t\t\t<Tabs.TabList>\n\t\t\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t\t\t<Tabs.Tab key={ tab.id } tabId={ 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.TabList>\n\t\t\t\t</Tabs.Context.Provider>\n\t\t\t}\n\t\t>\n\t\t\t<Tabs.Context.Provider value={ tabsContextValue }>\n\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t<Tabs.TabPanel\n\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\ttabId={ tab.id }\n\t\t\t\t\t\tfocusable={ false }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ tab.panel }\n\t\t\t\t\t</Tabs.TabPanel>\n\t\t\t\t) ) }\n\t\t\t</Tabs.Context.Provider>\n\t\t</ComplementaryArea>\n\t);\n}\n\ninterface HeaderActionsProps {\n\tisSaving: boolean;\n\thasMedia: boolean;\n\thasChanges: boolean;\n\tisImage: boolean;\n\tshowCloseButton?: boolean;\n\tonCancel: () => void;\n\tonSave: () => void;\n}\n\nfunction HeaderActions( {\n\tisSaving,\n\thasMedia,\n\thasChanges,\n\tisImage,\n\tshowCloseButton = false,\n\tonCancel,\n\tonSave,\n}: HeaderActionsProps ) {\n\tconst saveDisabled = isSaving || ! hasMedia || ! hasChanges;\n\tconst [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );\n\treturn (\n\t\t<Flex\n\t\t\tclassName=\"media-editor__header-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\texpanded={ false }\n\t\t\tgap={ 2 }\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<PinnedItems.Slot scope=\"media-editor\" />\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\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\tsize=\"compact\"\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\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</Flex>\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\tshowCloseButton = false,\n\tshouldCloseOnEsc = false,\n}: MediaEditorProps ) {\n\tconst cropper = useMediaEditor();\n\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 = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\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\tconst {\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue,\n\t\taspectRatioOptions,\n\t\tfreeformCrop,\n\t\tsetFreeformCrop,\n\t\tresetCropOptions,\n\t} = useCropOptions( {\n\t\taspectRatioPresets,\n\t} );\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 tabs = useMemo< EditorTab[] >( () => {\n\t\tconst detailsTab: EditorTab = {\n\t\t\tid: 'details',\n\t\t\ttitle: __( 'Details' ),\n\t\t\tpanel: (\n\t\t\t\t<Stack\n\t\t\t\t\tclassName=\"media-editor__panel\"\n\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\tgap=\"lg\"\n\t\t\t\t>\n\t\t\t\t\t<MediaForm />\n\t\t\t\t</Stack>\n\t\t\t),\n\t\t};\n\t\tif ( ! isImage ) {\n\t\t\treturn [ detailsTab ];\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\tid: 'crop',\n\t\t\t\ttitle: __( 'Crop' ),\n\t\t\t\tpanel: (\n\t\t\t\t\t<Stack\n\t\t\t\t\t\tclassName=\"media-editor__panel\"\n\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\tgap=\"lg\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<MediaEditorCropPanel\n\t\t\t\t\t\t\taspectRatioValue={ aspectRatioValue }\n\t\t\t\t\t\t\tonAspectRatioChange={ setAspectRatioValue }\n\t\t\t\t\t\t\tfreeformCrop={ freeformCrop }\n\t\t\t\t\t\t\tonFreeformChange={ setFreeformCrop }\n\t\t\t\t\t\t\tonPlacementControlInteraction={\n\t\t\t\t\t\t\t\tsignalPlacementControlInteraction\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\taspectRatioOptions={ aspectRatioOptions }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Stack>\n\t\t\t\t),\n\t\t\t},\n\t\t\tdetailsTab,\n\t\t];\n\t}, [\n\t\tisImage,\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue,\n\t\tfreeformCrop,\n\t\tsetFreeformCrop,\n\t\taspectRatioOptions,\n\t\tsignalPlacementControlInteraction,\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\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<>\n\t\t\t\t\t\t<Tabs>\n\t\t\t\t\t\t\t<MediaEditorSidebar tabs={ tabs } />\n\t\t\t\t\t\t</Tabs>\n\t\t\t\t\t\t<InterfaceSkeleton\n\t\t\t\t\t\t\tclassName=\"media-editor__skeleton\"\n\t\t\t\t\t\t\tlabels={ {\n\t\t\t\t\t\t\t\tbody: isImage\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\tsidebar: __( 'Media details' ),\n\t\t\t\t\t\t\t\tfooter: __( 'Image editing tools' ),\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tcontent={\n\t\t\t\t\t\t\t\t<div className=\"media-editor__canvas\">\n\t\t\t\t\t\t\t\t\t{ isImage ? (\n\t\t\t\t\t\t\t\t\t\t<MediaEditorCanvas\n\t\t\t\t\t\t\t\t\t\t\tfocusOnMount\n\t\t\t\t\t\t\t\t\t\t\tisPlacementActive={\n\t\t\t\t\t\t\t\t\t\t\t\tisPlacementActive\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonGestureStart={\n\t\t\t\t\t\t\t\t\t\t\t\thandleCanvasGestureStart\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonGestureEnd={\n\t\t\t\t\t\t\t\t\t\t\t\thandleCanvasGestureEnd\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t<MediaPreview />\n\t\t\t\t\t\t\t\t\t) }\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\tfooter={\n\t\t\t\t\t\t\t\tisImage ? (\n\t\t\t\t\t\t\t\t\t<MediaEditorToolbar\n\t\t\t\t\t\t\t\t\t\tonReset={ resetCropOptions }\n\t\t\t\t\t\t\t\t\t\tonPlacementControlInteraction={\n\t\t\t\t\t\t\t\t\t\t\tsignalPlacementControlInteraction\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tisUndoRedoDisabled={\n\t\t\t\t\t\t\t\t\t\t\tisCropInteractionActive\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) : undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsidebar={\n\t\t\t\t\t\t\t\t<ComplementaryArea.Slot scope=\"media-editor\" />\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</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\treturn renderFrame( {\n\t\tchildren,\n\t\theaderActions: (\n\t\t\t<HeaderActions\n\t\t\t\tisSaving={ isSaving }\n\t\t\t\thasMedia={ !! media }\n\t\t\t\thasChanges={ hasChanges }\n\t\t\t\tisImage={ isImage }\n\t\t\t\tshowCloseButton={ showCloseButton }\n\t\t\t\tonCancel={ handleRequestClose }\n\t\t\t\tonSave={ saveMediaEditor }\n\t\t\t/>\n\t\t),\n\t\tonRequestClose: handleRequestClose,\n\t\tonKeyDown: handleKeyDown,\n\t\tshouldCloseOnClickOutside: ! hasChanges && ! isSaving,\n\t\tisSaving,\n\t\thasChanges,\n\t\thasMedia: !! media,\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\nexport default MediaEditor;\n"],
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAA+B;AAAA,EAC/B,eAAe;AAAA,OACT;AACP,SAAS,aAAa;AACtB,SAAS,aAAa,iBAAiB;AACvC,SAAS,SAAS,iBAAiB;AACnC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AACnB,SAAS,OAAO,aAAa,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tFlex,\n\tSpinner,\n\t__experimentalConfirmDialog as ConfirmDialog,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tcreatePortal,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\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 {\n\tComplementaryArea,\n\tInterfaceSkeleton,\n\tPinnedItems,\n\t// No type declarations available for @wordpress/interface.\n\t// @ts-expect-error\n} from '@wordpress/interface';\nimport type { KeyboardEvent as ReactKeyboardEvent, ReactNode } from 'react';\n\n/**\n * Internal dependencies\n */\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 MediaEditorTransformControls from '../media-editor-transform-controls';\nimport MediaEditorCropPanel from '../media-editor-crop-panel';\nimport MediaForm from '../media-form';\nimport { unlock } from '../../lock-unlock';\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\nconst { Tabs } = unlock( componentsPrivateApis );\n\ninterface EditorTab {\n\tid: string;\n\ttitle: string;\n\tpanel: JSX.Element;\n}\n\nexport interface MediaEditorFrameProps {\n\tchildren: ReactNode;\n\theaderActions: ReactNode;\n\tfooterActions: ReactNode;\n\t/**\n\t * Footer layout selector. Frames apply this to the footer container\n\t * as a modifier class.\n\t *\n\t * - `wide` \u2014 single row: History | Ruler | Transform | Cancel/Save.\n\t * - `medium` \u2014 two rows: ruler on top; History | Transform | Cancel/Save\n\t * beneath.\n\t * - `narrow` \u2014 three rows: ruler; transform (centered); History |\n\t * Cancel/Save.\n\t */\n\tfooterLayout: 'wide' | 'medium' | '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\tshowCloseButton?: boolean;\n\tshouldCloseOnEsc?: boolean;\n}\n\nfunction MediaEditorSidebar( { tabs }: { tabs: EditorTab[] } ) {\n\tconst tabsContextValue = useContext( Tabs.Context );\n\treturn (\n\t\t<ComplementaryArea\n\t\t\tscope=\"media-editor\"\n\t\t\tidentifier=\"media-editor/details\"\n\t\t\ttitle={ __( 'Details' ) }\n\t\t\ticon={ drawerRight }\n\t\t\tisActiveByDefault\n\t\t\tclassName=\"media-editor__sidebar\"\n\t\t\tpanelClassName=\"media-editor__sidebar-panel\"\n\t\t\theaderClassName=\"media-editor__sidebar-header\"\n\t\t\theader={\n\t\t\t\t<Tabs.Context.Provider value={ tabsContextValue }>\n\t\t\t\t\t<Tabs.TabList>\n\t\t\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t\t\t<Tabs.Tab key={ tab.id } tabId={ 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.TabList>\n\t\t\t\t</Tabs.Context.Provider>\n\t\t\t}\n\t\t>\n\t\t\t<Tabs.Context.Provider value={ tabsContextValue }>\n\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t<Tabs.TabPanel\n\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\ttabId={ tab.id }\n\t\t\t\t\t\tfocusable={ false }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ tab.panel }\n\t\t\t\t\t</Tabs.TabPanel>\n\t\t\t\t) ) }\n\t\t\t</Tabs.Context.Provider>\n\t\t</ComplementaryArea>\n\t);\n}\n\ninterface HeaderActionsProps {\n\tisSaving: boolean;\n\tisImage: boolean;\n\tshowCloseButton?: boolean;\n\tonCancel: () => void;\n}\n\nfunction HeaderActions( {\n\tisSaving,\n\tisImage,\n\tshowCloseButton = false,\n\tonCancel,\n}: HeaderActionsProps ) {\n\tconst [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );\n\treturn (\n\t\t<Flex\n\t\t\tclassName=\"media-editor__header-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\texpanded={ false }\n\t\t\tgap={ 2 }\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<PinnedItems.Slot scope=\"media-editor\" />\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</Flex>\n\t);\n}\n\ninterface HistoryActionsProps {\n\tisUndoRedoDisabled?: boolean;\n\tonReset: () => void;\n}\n\nfunction HistoryActions( {\n\tisUndoRedoDisabled = false,\n\tonReset,\n}: HistoryActionsProps ) {\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\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<Flex\n\t\t\tclassName=\"media-editor__history-actions\"\n\t\t\texpanded={ false }\n\t\t\tgap={ 2 }\n\t\t>\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\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</Flex>\n\t);\n}\n\ninterface FooterActionsProps {\n\tisSaving: boolean;\n\thasMedia: boolean;\n\thasChanges: boolean;\n\tonCancel: () => void;\n\tonSave: () => void;\n}\n\nfunction FooterActions( {\n\tisSaving,\n\thasMedia,\n\thasChanges,\n\tonCancel,\n\tonSave,\n}: FooterActionsProps ) {\n\tconst saveDisabled = isSaving || ! hasMedia || ! hasChanges;\n\treturn (\n\t\t<Flex\n\t\t\tclassName=\"media-editor__footer-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\texpanded={ false }\n\t\t\tgap={ 2 }\n\t\t>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\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\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</Flex>\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\tshowCloseButton = false,\n\tshouldCloseOnEsc = false,\n}: MediaEditorProps ) {\n\tconst cropper = useMediaEditor();\n\t// Three footer layouts, picked from the viewport so DOM order matches\n\t// visual order in all three (no `order` reshuffling needed):\n\t// wide (\u2265 xlarge): single row.\n\t// medium (\u2265 medium): ruler on top; rest beneath.\n\t// narrow (< medium): ruler, then transform centered, then history/save.\n\tconst isWideViewport = useViewportMatch( 'xlarge' );\n\tconst isMediumViewport = useViewportMatch( 'medium' );\n\tlet footerLayout: 'wide' | 'medium' | 'narrow' = 'narrow';\n\tif ( isWideViewport ) {\n\t\tfooterLayout = 'wide';\n\t} else if ( isMediumViewport ) {\n\t\tfooterLayout = 'medium';\n\t}\n\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\tconst {\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue,\n\t\taspectRatioOptions,\n\t\tresetCropOptions,\n\t} = useCropOptions( {\n\t\taspectRatioPresets,\n\t} );\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 tabs = useMemo< EditorTab[] >( () => {\n\t\tconst detailsTab: EditorTab = {\n\t\t\tid: 'details',\n\t\t\ttitle: __( 'Details' ),\n\t\t\tpanel: (\n\t\t\t\t<Stack\n\t\t\t\t\tclassName=\"media-editor__panel\"\n\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\tgap=\"lg\"\n\t\t\t\t>\n\t\t\t\t\t<MediaForm />\n\t\t\t\t</Stack>\n\t\t\t),\n\t\t};\n\t\tif ( ! isImage ) {\n\t\t\treturn [ detailsTab ];\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\tid: 'crop',\n\t\t\t\ttitle: __( 'Crop' ),\n\t\t\t\tpanel: (\n\t\t\t\t\t<Stack\n\t\t\t\t\t\tclassName=\"media-editor__panel\"\n\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\tgap=\"lg\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<MediaEditorCropPanel\n\t\t\t\t\t\t\taspectRatioValue={ aspectRatioValue }\n\t\t\t\t\t\t\tonAspectRatioChange={ setAspectRatioValue }\n\t\t\t\t\t\t\tonPlacementControlInteraction={\n\t\t\t\t\t\t\t\tsignalPlacementControlInteraction\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\taspectRatioOptions={ aspectRatioOptions }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Stack>\n\t\t\t\t),\n\t\t\t},\n\t\t\tdetailsTab,\n\t\t];\n\t}, [\n\t\tisImage,\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue,\n\t\taspectRatioOptions,\n\t\tsignalPlacementControlInteraction,\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\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<>\n\t\t\t\t\t\t<Tabs>\n\t\t\t\t\t\t\t<MediaEditorSidebar tabs={ tabs } />\n\t\t\t\t\t\t</Tabs>\n\t\t\t\t\t\t<InterfaceSkeleton\n\t\t\t\t\t\t\tclassName=\"media-editor__skeleton\"\n\t\t\t\t\t\t\tlabels={ {\n\t\t\t\t\t\t\t\tbody: isImage\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\tsidebar: __( 'Media details' ),\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tcontent={\n\t\t\t\t\t\t\t\t<div className=\"media-editor__canvas\">\n\t\t\t\t\t\t\t\t\t{ isImage ? (\n\t\t\t\t\t\t\t\t\t\t<MediaEditorCanvas\n\t\t\t\t\t\t\t\t\t\t\tfocusOnMount\n\t\t\t\t\t\t\t\t\t\t\tisPlacementActive={\n\t\t\t\t\t\t\t\t\t\t\t\tisPlacementActive\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonGestureStart={\n\t\t\t\t\t\t\t\t\t\t\t\thandleCanvasGestureStart\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonGestureEnd={\n\t\t\t\t\t\t\t\t\t\t\t\thandleCanvasGestureEnd\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t<MediaPreview />\n\t\t\t\t\t\t\t\t\t) }\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\tsidebar={\n\t\t\t\t\t\t\t\t<ComplementaryArea.Slot scope=\"media-editor\" />\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</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\tconst history = isImage ? (\n\t\t<HistoryActions\n\t\t\tisUndoRedoDisabled={ isCropInteractionActive }\n\t\t\tonReset={ resetCropOptions }\n\t\t/>\n\t) : null;\n\tconst ruler = isImage ? (\n\t\t<MediaEditorFineRotation\n\t\t\tonPlacementControlInteraction={ signalPlacementControlInteraction }\n\t\t/>\n\t) : null;\n\tconst transform = isImage ? <MediaEditorTransformControls /> : null;\n\tconst actions = (\n\t\t<FooterActions\n\t\t\tisSaving={ isSaving }\n\t\t\thasMedia={ !! media }\n\t\t\thasChanges={ hasChanges }\n\t\t\tonCancel={ handleRequestClose }\n\t\t\tonSave={ saveMediaEditor }\n\t\t/>\n\t);\n\n\t// One JSX tree per layout. DOM order matches visual order in all three.\n\t// `.media-editor-modal__footer-toolbar` (wide only) groups ruler +\n\t// transform with the centered cluster and divider that the wide layout\n\t// has always had.\n\tlet footerActions: ReactNode;\n\tif ( footerLayout === 'wide' ) {\n\t\tfooterActions = (\n\t\t\t<>\n\t\t\t\t{ history }\n\t\t\t\t{ isImage && (\n\t\t\t\t\t<div className=\"media-editor-modal__footer-toolbar\">\n\t\t\t\t\t\t{ ruler }\n\t\t\t\t\t\t{ transform }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t{ actions }\n\t\t\t</>\n\t\t);\n\t} else if ( footerLayout === 'medium' ) {\n\t\tfooterActions = (\n\t\t\t<>\n\t\t\t\t{ ruler }\n\t\t\t\t<div className=\"media-editor-modal__footer-row\">\n\t\t\t\t\t{ history }\n\t\t\t\t\t{ transform }\n\t\t\t\t\t{ actions }\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\n\t} else {\n\t\tfooterActions = (\n\t\t\t<>\n\t\t\t\t{ ruler }\n\t\t\t\t{ transform }\n\t\t\t\t<div className=\"media-editor-modal__footer-row\">\n\t\t\t\t\t{ history }\n\t\t\t\t\t{ actions }\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn renderFrame( {\n\t\tchildren,\n\t\theaderActions: (\n\t\t\t<HeaderActions\n\t\t\t\tisSaving={ isSaving }\n\t\t\t\tisImage={ isImage }\n\t\t\t\tshowCloseButton={ showCloseButton }\n\t\t\t\tonCancel={ handleRequestClose }\n\t\t\t/>\n\t\t),\n\t\tfooterActions,\n\t\tfooterLayout,\n\t\tonRequestClose: handleRequestClose,\n\t\tonKeyDown: handleKeyDown,\n\t\tshouldCloseOnClickOutside: ! hasChanges && ! isSaving,\n\t\tisSaving,\n\t\thasChanges,\n\t\thasMedia: !! media,\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\nexport default MediaEditor;\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAA+B;AAAA,EAC/B,eAAe;AAAA,OACT;AACP,SAAS,aAAa;AACtB,SAAS,wBAAwB;AACjC,SAAS,aAAa,iBAAiB;AACvC,SAAS,SAAS,iBAAiB;AACnC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AACnB,SAAS,OAAO,aAAa,UAAU,MAAM,YAAY;AACzD;AAAA,EACC;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QACA;AAAA,QACA,UAAW;AAAA;AAAA,IACZ;AAAA,IAED;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;AACH;AAEO,SAAS,YAAa,OAA0B;AACtD,SACC,oBAAC,4BACA,8BAAC,sBAAqB,GAAG,OAAQ,KADF,MAAM,EAEtC;AAEF;AAEA,IAAO,uBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// packages/media-editor/src/components/media-editor/use-crop-options.ts
|
|
2
|
-
import {
|
|
2
|
+
import { useMemo } from "@wordpress/element";
|
|
3
3
|
import { DEFAULT_ASPECT_RATIOS } from "../../image-editor/core/constants.mjs";
|
|
4
4
|
import { useMediaEditor, resolveAspectRatio } from "../../state/index.mjs";
|
|
5
|
-
var FREE_ASPECT_RATIO_VALUE = "0";
|
|
6
5
|
function getAspectRatioOptions(aspectRatioPresets) {
|
|
7
6
|
return [
|
|
8
7
|
...DEFAULT_ASPECT_RATIOS.filter((preset) => preset.value <= 0),
|
|
@@ -13,7 +12,7 @@ function useCropOptions({
|
|
|
13
12
|
aspectRatioPresets
|
|
14
13
|
} = {}) {
|
|
15
14
|
const controller = useMediaEditor();
|
|
16
|
-
const { aspectRatioValue
|
|
15
|
+
const { aspectRatioValue } = controller.cropOptions;
|
|
17
16
|
const cropperImage = controller.state.image;
|
|
18
17
|
const aspectRatioOptions = useMemo(
|
|
19
18
|
() => getAspectRatioOptions(aspectRatioPresets),
|
|
@@ -23,33 +22,10 @@ function useCropOptions({
|
|
|
23
22
|
() => resolveAspectRatio(aspectRatioValue, cropperImage),
|
|
24
23
|
[aspectRatioValue, cropperImage]
|
|
25
24
|
);
|
|
26
|
-
const { beginGesture, endGesture, setAspectRatioValue, setFreeformCrop } = controller;
|
|
27
|
-
const setAspectRatioValueWithFreeformSync = useCallback(
|
|
28
|
-
(value) => {
|
|
29
|
-
const shouldReenableFreeform = value === FREE_ASPECT_RATIO_VALUE && !freeformCrop;
|
|
30
|
-
if (!shouldReenableFreeform) {
|
|
31
|
-
setAspectRatioValue(value);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
beginGesture();
|
|
35
|
-
setAspectRatioValue(value);
|
|
36
|
-
setFreeformCrop(true);
|
|
37
|
-
endGesture();
|
|
38
|
-
},
|
|
39
|
-
[
|
|
40
|
-
freeformCrop,
|
|
41
|
-
beginGesture,
|
|
42
|
-
endGesture,
|
|
43
|
-
setAspectRatioValue,
|
|
44
|
-
setFreeformCrop
|
|
45
|
-
]
|
|
46
|
-
);
|
|
47
25
|
return {
|
|
48
26
|
aspectRatioValue,
|
|
49
|
-
setAspectRatioValue:
|
|
27
|
+
setAspectRatioValue: controller.setAspectRatioValue,
|
|
50
28
|
aspectRatioOptions,
|
|
51
|
-
freeformCrop,
|
|
52
|
-
setFreeformCrop: controller.setFreeformCrop,
|
|
53
29
|
resolvedAspectRatio,
|
|
54
30
|
resetCropOptions: controller.resetCropOptions
|
|
55
31
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor/use-crop-options.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";AAGA,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { DEFAULT_ASPECT_RATIOS } from '../../image-editor/core/constants';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\nimport { useMediaEditor, resolveAspectRatio } from '../../state';\n\ninterface UseCropOptionsArgs {\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\ninterface UseCropOptionsReturn {\n\taspectRatioValue: string;\n\tsetAspectRatioValue: ( value: string ) => void;\n\taspectRatioOptions: AspectRatioPreset[];\n\tresolvedAspectRatio: number | undefined;\n\tresetCropOptions: () => void;\n}\n\n/**\n * Build the preset list shown in the dropdown \u2014 always include the\n * non-numeric presets (Free, Original) and append either the\n * caller-supplied set or the defaults.\n *\n * @param aspectRatioPresets Optional caller-supplied presets.\n * @return The full preset list to render.\n */\nexport function getAspectRatioOptions(\n\taspectRatioPresets?: AspectRatioPreset[]\n): AspectRatioPreset[] {\n\treturn [\n\t\t...DEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value <= 0 ),\n\t\t...( aspectRatioPresets ??\n\t\t\tDEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value > 0 ) ),\n\t];\n}\n\n/**\n * Thin selector over the composite media-editor store for the Crop\n * sidebar tab. Reads the cropOptions slice (preset key) and exposes\n * the corresponding setters plus a render-time `resolvedAspectRatio`\n * derivation.\n *\n * No local React state, no refs, no synchronization effects \u2014 the\n * composite store is the single source of truth.\n *\n * @param args\n * @param args.aspectRatioPresets Optional caller-supplied aspect-ratio presets.\n */\nexport function useCropOptions( {\n\taspectRatioPresets,\n}: UseCropOptionsArgs = {} ): UseCropOptionsReturn {\n\tconst controller = useMediaEditor();\n\tconst { aspectRatioValue } = controller.cropOptions;\n\tconst cropperImage = controller.state.image;\n\n\tconst aspectRatioOptions = useMemo(\n\t\t() => getAspectRatioOptions( aspectRatioPresets ),\n\t\t[ aspectRatioPresets ]\n\t);\n\n\tconst resolvedAspectRatio = useMemo(\n\t\t() => resolveAspectRatio( aspectRatioValue, cropperImage ),\n\t\t[ aspectRatioValue, cropperImage ]\n\t);\n\n\treturn {\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue: controller.setAspectRatioValue,\n\t\taspectRatioOptions,\n\t\tresolvedAspectRatio,\n\t\tresetCropOptions: controller.resetCropOptions,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,eAAe;AAKxB,SAAS,6BAA6B;AAEtC,SAAS,gBAAgB,0BAA0B;AAsB5C,SAAS,sBACf,oBACsB;AACtB,SAAO;AAAA,IACN,GAAG,sBAAsB,OAAQ,CAAE,WAAY,OAAO,SAAS,CAAE;AAAA,IACjE,GAAK,sBACJ,sBAAsB,OAAQ,CAAE,WAAY,OAAO,QAAQ,CAAE;AAAA,EAC/D;AACD;AAcO,SAAS,eAAgB;AAAA,EAC/B;AACD,IAAwB,CAAC,GAA0B;AAClD,QAAM,aAAa,eAAe;AAClC,QAAM,EAAE,iBAAiB,IAAI,WAAW;AACxC,QAAM,eAAe,WAAW,MAAM;AAEtC,QAAM,qBAAqB;AAAA,IAC1B,MAAM,sBAAuB,kBAAmB;AAAA,IAChD,CAAE,kBAAmB;AAAA,EACtB;AAEA,QAAM,sBAAsB;AAAA,IAC3B,MAAM,mBAAoB,kBAAkB,YAAa;AAAA,IACzD,CAAE,kBAAkB,YAAa;AAAA,EAClC;AAEA,SAAO;AAAA,IACN;AAAA,IACA,qBAAqB,WAAW;AAAA,IAChC;AAAA,IACA;AAAA,IACA,kBAAkB,WAAW;AAAA,EAC9B;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -13,7 +13,7 @@ function MediaEditorCanvas({
|
|
|
13
13
|
}) {
|
|
14
14
|
const { media } = useMediaEditorContext();
|
|
15
15
|
const controller = useMediaEditor();
|
|
16
|
-
const { aspectRatioValue
|
|
16
|
+
const { aspectRatioValue } = controller.cropOptions;
|
|
17
17
|
const cropperImage = controller.state.image;
|
|
18
18
|
const { beginGesture, endGesture, setImage } = controller;
|
|
19
19
|
const aspectRatio = useMemo(
|
|
@@ -51,7 +51,7 @@ function MediaEditorCanvas({
|
|
|
51
51
|
src: mediaUrl,
|
|
52
52
|
controller,
|
|
53
53
|
aspectRatio,
|
|
54
|
-
freeformCrop,
|
|
54
|
+
freeformCrop: true,
|
|
55
55
|
focusOnMount,
|
|
56
56
|
showGrid: "interactive",
|
|
57
57
|
isPlacementActive,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor-canvas/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\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/** Focus the crop area when the canvas mounts. */\n\tfocusOnMount?: boolean;\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.focusOnMount\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n */\nexport default function MediaEditorCanvas( {\n\tfocusOnMount,\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst controller = useMediaEditor();\n\tconst { aspectRatioValue
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa,WAAW,eAAe;AAKhD,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AACzC,SAAS,eAAe;AACxB,SAAS,gBAAgB,0BAA0B;AAuFhD;AA5DY,SAAR,kBAAoC;AAAA,EAC1C;AAAA,EACA,oBAAoB;AAAA,EACpB;AAAA,EACA;AACD,GAA4B;AAC3B,QAAM,EAAE,MAAM,IAAI,sBAAsB;AACxC,QAAM,aAAa,eAAe;AAClC,QAAM,EAAE,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\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/** Focus the crop area when the canvas mounts. */\n\tfocusOnMount?: boolean;\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.focusOnMount\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n */\nexport default function MediaEditorCanvas( {\n\tfocusOnMount,\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// 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 \u2014 only the preset key \u2014 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\tif ( ! mediaUrl || mediaType.type !== 'image' ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-canvas\">\n\t\t\t<Cropper\n\t\t\t\tsrc={ mediaUrl }\n\t\t\t\tcontroller={ controller }\n\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\tfreeformCrop\n\t\t\t\tfocusOnMount={ focusOnMount }\n\t\t\t\tshowGrid=\"interactive\"\n\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\tonGestureEnd={ handleGestureEnd }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa,WAAW,eAAe;AAKhD,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AACzC,SAAS,eAAe;AACxB,SAAS,gBAAgB,0BAA0B;AAuFhD;AA5DY,SAAR,kBAAoC;AAAA,EAC1C;AAAA,EACA,oBAAoB;AAA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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
// packages/media-editor/src/components/media-editor-crop-panel/index.tsx
|
|
2
|
-
import {
|
|
3
|
-
RangeControl,
|
|
4
|
-
SelectControl,
|
|
5
|
-
ToggleControl
|
|
6
|
-
} from "@wordpress/components";
|
|
2
|
+
import { RangeControl, SelectControl } from "@wordpress/components";
|
|
7
3
|
import { Stack, VisuallyHidden } from "@wordpress/ui";
|
|
8
4
|
import { __, sprintf } from "@wordpress/i18n";
|
|
9
5
|
import { useMediaEditor } from "../../state/index.mjs";
|
|
@@ -14,26 +10,34 @@ import {
|
|
|
14
10
|
import { MAX_ZOOM } from "../../image-editor/core/constants.mjs";
|
|
15
11
|
import { getMinZoom } from "../../image-editor/core/containment.mjs";
|
|
16
12
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
var ZOOM_PERCENTAGE_SCALE = 100;
|
|
14
|
+
var MAX_ZOOM_PERCENTAGE = MAX_ZOOM * ZOOM_PERCENTAGE_SCALE;
|
|
15
|
+
function getZoomPercentageForDisplay(zoom) {
|
|
16
|
+
return Math.round(zoom * ZOOM_PERCENTAGE_SCALE);
|
|
17
|
+
}
|
|
18
|
+
function getMinZoomPercentageForDisplay(zoom) {
|
|
19
|
+
return Math.ceil(zoom * ZOOM_PERCENTAGE_SCALE);
|
|
20
|
+
}
|
|
17
21
|
function MediaEditorCropPanel({
|
|
18
22
|
aspectRatioValue,
|
|
19
23
|
onAspectRatioChange,
|
|
20
|
-
freeformCrop,
|
|
21
|
-
onFreeformChange,
|
|
22
24
|
onPlacementControlInteraction,
|
|
23
25
|
aspectRatioOptions
|
|
24
26
|
}) {
|
|
25
27
|
const { state, setZoom } = useMediaEditor();
|
|
26
28
|
const zoomGestureHandlers = useCropGestureHandlers();
|
|
27
29
|
const minZoom = getMinZoom(state);
|
|
30
|
+
const zoomPercentage = getZoomPercentageForDisplay(state.zoom);
|
|
31
|
+
const minZoomPercentage = getMinZoomPercentageForDisplay(minZoom);
|
|
28
32
|
return (
|
|
29
33
|
// Tag the whole panel as a crop-control region so the modal's
|
|
30
|
-
// Cmd+Z handler doesn't mistake the SelectControl
|
|
31
|
-
//
|
|
34
|
+
// Cmd+Z handler doesn't mistake the SelectControl input for a
|
|
35
|
+
// metadata field (which would suppress undo).
|
|
32
36
|
/* @__PURE__ */ jsxs(
|
|
33
37
|
Stack,
|
|
34
38
|
{
|
|
35
39
|
direction: "column",
|
|
36
|
-
gap: "
|
|
40
|
+
gap: "xl",
|
|
37
41
|
...{ [CROP_CONTROL_ATTR]: true },
|
|
38
42
|
children: [
|
|
39
43
|
/* @__PURE__ */ jsx(VisuallyHidden, { render: /* @__PURE__ */ jsx("h2", {}), children: __("Crop options") }),
|
|
@@ -50,33 +54,28 @@ function MediaEditorCropPanel({
|
|
|
50
54
|
}))
|
|
51
55
|
}
|
|
52
56
|
),
|
|
53
|
-
/* @__PURE__ */ jsx(
|
|
54
|
-
ToggleControl,
|
|
55
|
-
{
|
|
56
|
-
label: __("Show resize handles"),
|
|
57
|
-
checked: freeformCrop,
|
|
58
|
-
onChange: onFreeformChange
|
|
59
|
-
}
|
|
60
|
-
),
|
|
61
57
|
/* @__PURE__ */ jsx("div", { role: "presentation", ...zoomGestureHandlers, children: /* @__PURE__ */ jsx(
|
|
62
58
|
RangeControl,
|
|
63
59
|
{
|
|
64
60
|
__next40pxDefaultSize: true,
|
|
65
|
-
label: __("Zoom"),
|
|
66
|
-
min:
|
|
67
|
-
max:
|
|
68
|
-
step:
|
|
69
|
-
|
|
61
|
+
label: __("Zoom (%)"),
|
|
62
|
+
min: minZoomPercentage,
|
|
63
|
+
max: MAX_ZOOM_PERCENTAGE,
|
|
64
|
+
step: 1,
|
|
65
|
+
shiftStep: 10,
|
|
66
|
+
value: zoomPercentage,
|
|
70
67
|
onChange: (value) => {
|
|
71
68
|
onPlacementControlInteraction?.();
|
|
72
|
-
setZoom(
|
|
69
|
+
setZoom(
|
|
70
|
+
typeof value === "number" ? value / ZOOM_PERCENTAGE_SCALE : minZoom
|
|
71
|
+
);
|
|
73
72
|
},
|
|
74
73
|
renderTooltipContent: (value) => {
|
|
75
|
-
const
|
|
74
|
+
const percentage = typeof value === "number" ? value : minZoomPercentage;
|
|
76
75
|
return sprintf(
|
|
77
76
|
/* translators: %d: zoom level as a percentage. */
|
|
78
77
|
__("%d%%"),
|
|
79
|
-
Math.round(
|
|
78
|
+
Math.round(percentage)
|
|
80
79
|
);
|
|
81
80
|
}
|
|
82
81
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor-crop-panel/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";AAGA
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { RangeControl, SelectControl } from '@wordpress/components';\nimport { Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditor } from '../../state';\nimport {\n\tuseCropGestureHandlers,\n\tCROP_CONTROL_ATTR,\n} from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ZOOM } from '../../image-editor/core/constants';\nimport { getMinZoom } from '../../image-editor/core/containment';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\n\nconst ZOOM_PERCENTAGE_SCALE = 100;\nconst MAX_ZOOM_PERCENTAGE = MAX_ZOOM * ZOOM_PERCENTAGE_SCALE;\n\nfunction getZoomPercentageForDisplay( zoom: number ): number {\n\treturn Math.round( zoom * ZOOM_PERCENTAGE_SCALE );\n}\n\nfunction getMinZoomPercentageForDisplay( zoom: number ): number {\n\treturn Math.ceil( zoom * ZOOM_PERCENTAGE_SCALE );\n}\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/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/** Aspect-ratio presets to display in the selector. */\n\taspectRatioOptions: AspectRatioPreset[];\n}\n\n/**\n * Sidebar panel for crop-shape controls. The tactile verbs (rotate, flip)\n * live in the bottom toolbar instead.\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.onPlacementControlInteraction\n * @param props.aspectRatioOptions\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\tonPlacementControlInteraction,\n\taspectRatioOptions,\n}: MediaEditorCropPanelProps ) {\n\tconst { state, setZoom } = useMediaEditor();\n\tconst zoomGestureHandlers = useCropGestureHandlers();\n\tconst minZoom = getMinZoom( state );\n\tconst zoomPercentage = getZoomPercentageForDisplay( state.zoom );\n\tconst minZoomPercentage = getMinZoomPercentageForDisplay( minZoom );\n\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<SelectControl\n\t\t\t\t__next40pxDefaultSize\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\t<div role=\"presentation\" { ...zoomGestureHandlers }>\n\t\t\t\t<RangeControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Zoom (%)' ) }\n\t\t\t\t\tmin={ minZoomPercentage }\n\t\t\t\t\tmax={ MAX_ZOOM_PERCENTAGE }\n\t\t\t\t\tstep={ 1 }\n\t\t\t\t\tshiftStep={ 10 }\n\t\t\t\t\tvalue={ zoomPercentage }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tonPlacementControlInteraction?.();\n\t\t\t\t\t\tsetZoom(\n\t\t\t\t\t\t\ttypeof value === 'number'\n\t\t\t\t\t\t\t\t? value / ZOOM_PERCENTAGE_SCALE\n\t\t\t\t\t\t\t\t: minZoom\n\t\t\t\t\t\t);\n\t\t\t\t\t} }\n\t\t\t\t\trenderTooltipContent={ ( value ) => {\n\t\t\t\t\t\tconst percentage =\n\t\t\t\t\t\t\ttypeof value === 'number'\n\t\t\t\t\t\t\t\t? value\n\t\t\t\t\t\t\t\t: minZoomPercentage;\n\t\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t\t/* translators: %d: zoom level as a percentage. */\n\t\t\t\t\t\t\t__( '%d%%' ),\n\t\t\t\t\t\t\tMath.round( percentage )\n\t\t\t\t\t\t);\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</Stack>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,cAAc,qBAAqB;AAC5C,SAAS,OAAO,sBAAsB;AACtC,SAAS,IAAI,eAAe;AAK5B,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAsDzB,SAK0B,KAL1B;AAnDF,IAAM,wBAAwB;AAC9B,IAAM,sBAAsB,WAAW;AAEvC,SAAS,4BAA6B,MAAuB;AAC5D,SAAO,KAAK,MAAO,OAAO,qB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AA;AAAA,kBAEN,GAAI,MAAO;AAAA,kBACX,KAAK,MAAO,UAAW;AAAA,gBACxB;AAAA,cACD;AAAA;AAAA,UACD,GACD;AAAA;AAAA;AAAA,IACD;AAAA;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// packages/media-editor/src/components/media-editor-fine-rotation/index.tsx
|
|
2
|
+
import { __ } from "@wordpress/i18n";
|
|
3
|
+
import { useMediaEditor } from "../../state/index.mjs";
|
|
4
|
+
import { useCropGestureHandlers } from "../../hooks/use-crop-gesture-handlers.mjs";
|
|
5
|
+
import { MAX_ROTATION_OFFSET } from "../../image-editor/core/constants.mjs";
|
|
6
|
+
import RotationRuler from "../rotation-ruler/index.mjs";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function MediaEditorFineRotation({
|
|
9
|
+
onPlacementControlInteraction
|
|
10
|
+
}) {
|
|
11
|
+
const { state, setRotation } = useMediaEditor();
|
|
12
|
+
const rotationGestureHandlers = useCropGestureHandlers({
|
|
13
|
+
commitOnKeyUp: false
|
|
14
|
+
});
|
|
15
|
+
const baseAngle = Math.round(state.rotation / 90) * 90;
|
|
16
|
+
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
17
|
+
const visualDir = singleFlip ? -1 : 1;
|
|
18
|
+
const fineOffset = (state.rotation - baseAngle) * visualDir;
|
|
19
|
+
const handleRotationSlider = (value) => {
|
|
20
|
+
const EPS = 0.01;
|
|
21
|
+
const clamped = Math.max(
|
|
22
|
+
-MAX_ROTATION_OFFSET + EPS,
|
|
23
|
+
Math.min(MAX_ROTATION_OFFSET - EPS, value)
|
|
24
|
+
);
|
|
25
|
+
onPlacementControlInteraction?.();
|
|
26
|
+
setRotation(baseAngle + clamped * visualDir);
|
|
27
|
+
};
|
|
28
|
+
return /* @__PURE__ */ jsx(
|
|
29
|
+
"div",
|
|
30
|
+
{
|
|
31
|
+
role: "presentation",
|
|
32
|
+
className: "media-editor-fine-rotation",
|
|
33
|
+
...rotationGestureHandlers,
|
|
34
|
+
children: /* @__PURE__ */ jsx(
|
|
35
|
+
RotationRuler,
|
|
36
|
+
{
|
|
37
|
+
label: __("Fine rotation"),
|
|
38
|
+
min: -MAX_ROTATION_OFFSET,
|
|
39
|
+
max: MAX_ROTATION_OFFSET,
|
|
40
|
+
value: fineOffset,
|
|
41
|
+
onChange: handleRotationSlider
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
MediaEditorFineRotation as default
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/media-editor-fine-rotation/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\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 footer. Lives separately from\n * the snap-rotate / flip buttons so the footer can place the two halves on\n * different rows at intermediate viewport widths.\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 \u00B1MAX lands state on a\n\t\t// 90\u00B0 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": ";AAGA,SAAS,UAAU;AAKnB,SAAS,sBAAsB;AAC/B,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,OAAO,mBAAmB;AAqDvB;AAtCY,SAAR,wBAA0C;AAAA,EAChD;AACD,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;AAAA,MACZ;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -6,17 +6,18 @@ import { ShortcutProvider } from "@wordpress/keyboard-shortcuts";
|
|
|
6
6
|
import { store as noticesStore } from "@wordpress/notices";
|
|
7
7
|
import MediaEditor from "../media-editor/index.mjs";
|
|
8
8
|
import { store as mediaEditorStore } from "../../store/index.mjs";
|
|
9
|
-
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
function MediaEditorModal({
|
|
11
11
|
fields = [],
|
|
12
12
|
aspectRatioPresets
|
|
13
13
|
}) {
|
|
14
|
-
const { isModalOpen, id, onUpdate } = useSelect((select) => {
|
|
15
|
-
const { isOpen, getId, getOnUpdate } = select(mediaEditorStore);
|
|
14
|
+
const { isModalOpen, id, onUpdate, onClose } = useSelect((select) => {
|
|
15
|
+
const { isOpen, getId, getOnUpdate, getOnClose } = select(mediaEditorStore);
|
|
16
16
|
return {
|
|
17
17
|
isModalOpen: isOpen(),
|
|
18
18
|
id: getId(),
|
|
19
|
-
onUpdate: getOnUpdate()
|
|
19
|
+
onUpdate: getOnUpdate(),
|
|
20
|
+
onClose: getOnClose()
|
|
20
21
|
};
|
|
21
22
|
}, []);
|
|
22
23
|
const { closeMediaEditorModal } = useDispatch(mediaEditorStore);
|
|
@@ -28,6 +29,10 @@ function MediaEditorModal({
|
|
|
28
29
|
const stopKeyDownPropagation = (event) => {
|
|
29
30
|
event.stopPropagation();
|
|
30
31
|
};
|
|
32
|
+
const handleClose = () => {
|
|
33
|
+
closeMediaEditorModal();
|
|
34
|
+
onClose?.();
|
|
35
|
+
};
|
|
31
36
|
return /* @__PURE__ */ jsx(
|
|
32
37
|
MediaEditor,
|
|
33
38
|
{
|
|
@@ -38,7 +43,7 @@ function MediaEditorModal({
|
|
|
38
43
|
shouldCloseOnEsc: true,
|
|
39
44
|
noticesClassName: "media-editor-modal__snackbar",
|
|
40
45
|
noticesPortalElement: portalElement,
|
|
41
|
-
onClose:
|
|
46
|
+
onClose: handleClose,
|
|
42
47
|
onSaved: ({ id: savedId, url, previous }) => {
|
|
43
48
|
if (savedId && onUpdate) {
|
|
44
49
|
const update = {
|
|
@@ -47,7 +52,7 @@ function MediaEditorModal({
|
|
|
47
52
|
};
|
|
48
53
|
onUpdate(update);
|
|
49
54
|
}
|
|
50
|
-
|
|
55
|
+
handleClose();
|
|
51
56
|
if (previous && savedId !== previous.id && onUpdate) {
|
|
52
57
|
createSuccessNotice(__("Image edited."), {
|
|
53
58
|
type: "snackbar",
|
|
@@ -68,6 +73,8 @@ function MediaEditorModal({
|
|
|
68
73
|
renderFrame: ({
|
|
69
74
|
children,
|
|
70
75
|
headerActions,
|
|
76
|
+
footerActions,
|
|
77
|
+
footerLayout,
|
|
71
78
|
onRequestClose,
|
|
72
79
|
onKeyDown,
|
|
73
80
|
shouldCloseOnClickOutside
|
|
@@ -76,7 +83,7 @@ function MediaEditorModal({
|
|
|
76
83
|
{
|
|
77
84
|
className: "media-editor-modal__shortcut-scope",
|
|
78
85
|
onKeyDown: stopKeyDownPropagation,
|
|
79
|
-
children: /* @__PURE__ */
|
|
86
|
+
children: /* @__PURE__ */ jsxs(
|
|
80
87
|
Modal,
|
|
81
88
|
{
|
|
82
89
|
className: "media-editor-modal",
|
|
@@ -87,7 +94,18 @@ function MediaEditorModal({
|
|
|
87
94
|
onKeyDown,
|
|
88
95
|
onRequestClose,
|
|
89
96
|
headerActions,
|
|
90
|
-
children
|
|
97
|
+
children: [
|
|
98
|
+
children,
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
"div",
|
|
101
|
+
{
|
|
102
|
+
className: `media-editor-modal__footer is-${footerLayout}`,
|
|
103
|
+
role: "region",
|
|
104
|
+
"aria-label": __("Editor actions"),
|
|
105
|
+
children: footerActions
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
]
|
|
91
109
|
}
|
|
92
110
|
)
|
|
93
111
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor-modal/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\n\n/**\n * Internal dependencies\n */\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate } = useSelect( ( select ) => {\n\t\tconst { isOpen, getId, getOnUpdate }
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa;AACtB,SAAS,aAAa,iBAAiB;AACvC,SAAS,UAAU;AACnB,SAAS,wBAAwB;AACjC,SAAS,SAAS,oBAAoB;AAOtC,OAAO,iBAAiB;AAExB,SAAS,SAAS,wBAAwB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\n\n/**\n * Internal dependencies\n */\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onClose } = useSelect( ( select ) => {\n\t\tconst { isOpen, getId, getOnUpdate, getOnClose } =\n\t\t\tselect( mediaEditorStore );\n\t\treturn {\n\t\t\tisModalOpen: isOpen(),\n\t\t\tid: getId(),\n\t\t\tonUpdate: getOnUpdate(),\n\t\t\tonClose: getOnClose(),\n\t\t};\n\t}, [] );\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshowCloseButton\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tonUpdate( {\n\t\t\t\t\t\t\t\t\t\tid: previous.id,\n\t\t\t\t\t\t\t\t\t\turl: previous.url,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\theaderActions,\n\t\t\t\tfooterActions,\n\t\t\t\tfooterLayout,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<ShortcutProvider\n\t\t\t\t\tclassName=\"media-editor-modal__shortcut-scope\"\n\t\t\t\t\tonKeyDown={ stopKeyDownPropagation }\n\t\t\t\t>\n\t\t\t\t\t<Modal\n\t\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\t\theaderActions={ headerActions }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName={ `media-editor-modal__footer is-${ footerLayout }` }\n\t\t\t\t\t\t\trole=\"region\"\n\t\t\t\t\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ footerActions }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Modal>\n\t\t\t\t</ShortcutProvider>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa;AACtB,SAAS,aAAa,iBAAiB;AACvC,SAAS,UAAU;AACnB,SAAS,wBAAwB;AACjC,SAAS,SAAS,oBAAoB;AAOtC,OAAO,iBAAiB;AAExB,SAAS,SAAS,wBAAwB;AA+GrC,SAWC,KAXD;AA5FE,SAAS,iBAAkB;AAAA,EACjC,SAAS,CAAC;AAAA,EACV;AACD,GAA2B;AAC1B,QAAM,EAAE,aAAa,IAAI,UAAU,QAAQ,IAAI,UAAW,CAAE,WAAY;AACvE,UAAM,EAAE,QAAQ,OAAO,aAAa,WAAW,IAC9C,OAAQ,gBAAiB;AAC1B,WAAO;AAAA,MACN,aAAa,OAAO;AAAA,MACpB,IAAI,MAAM;AAAA,MACV,UAAU,YAAY;AAAA,MACtB,SAAS,WAAW;AAAA,IACrB;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,EAAE,sBAAsB,IAAI,YAAa,gBAAiB;AAChE,QAAM,EAAE,oBAAoB,IAAI,YAAa,YAAa;AAE1D,MAAK,CAAE,eAAe,CAAE,IAAK;AAC5B,WAAO;AAAA,EACR;AAEA,QAAM,gBACL,OAAO,aAAa,cAAc,OAAO,SAAS;AAMnD,QAAM,yBAAyB,CAC9B,UACI;AACJ,UAAM,gBAAgB;AAAA,EACvB;AAEA,QAAM,cAAc,MAAM;AACzB,0BAAsB;AACtB,cAAU;AAAA,EACX;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,iBAAe;AAAA,MACf,kBAAgB;AAAA,MAChB,kBAAiB;AAAA,MACjB,sBAAuB;AAAA,MACvB,SAAU;AA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