@wordpress/media-editor 0.7.0 → 0.8.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/build/components/media-editor-canvas/index.cjs +54 -0
- package/build/components/media-editor-canvas/index.cjs.map +7 -0
- package/build/components/media-editor-crop-panel/index.cjs +116 -0
- package/build/components/media-editor-crop-panel/index.cjs.map +7 -0
- package/build/components/media-editor-modal/build-modifiers.cjs +91 -0
- package/build/components/media-editor-modal/build-modifiers.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +497 -0
- package/build/components/media-editor-modal/index.cjs.map +7 -0
- package/build/components/media-editor-toolbar/index.cjs +146 -0
- package/build/components/media-editor-toolbar/index.cjs.map +7 -0
- package/build/components/media-preview/index.cjs +1 -1
- package/build/components/media-preview/index.cjs.map +2 -2
- package/build/image-editor/core/camera.cjs +194 -0
- package/build/image-editor/core/camera.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +81 -0
- package/build/image-editor/core/constants.cjs.map +7 -0
- package/build/image-editor/core/containment.cjs +245 -0
- package/build/image-editor/core/containment.cjs.map +7 -0
- package/build/image-editor/core/export/canvas-renderer.cjs +151 -0
- package/build/image-editor/core/export/canvas-renderer.cjs.map +7 -0
- package/build/image-editor/core/index.cjs +50 -0
- package/build/image-editor/core/index.cjs.map +7 -0
- package/build/image-editor/core/interaction-controller.cjs +608 -0
- package/build/image-editor/core/interaction-controller.cjs.map +7 -0
- package/build/image-editor/core/math/rotation.cjs +41 -0
- package/build/image-editor/core/math/rotation.cjs.map +7 -0
- package/build/image-editor/core/source-region.cjs +95 -0
- package/build/image-editor/core/source-region.cjs.map +7 -0
- package/build/image-editor/core/state.cjs +269 -0
- package/build/image-editor/core/state.cjs.map +7 -0
- package/build/image-editor/core/stencil-math.cjs +197 -0
- package/build/image-editor/core/stencil-math.cjs.map +7 -0
- package/build/image-editor/core/transform-style.cjs +46 -0
- package/build/image-editor/core/transform-style.cjs.map +7 -0
- package/build/image-editor/core/transforms/pipeline.cjs +43 -0
- package/build/image-editor/core/transforms/pipeline.cjs.map +7 -0
- package/build/image-editor/core/types.cjs +19 -0
- package/build/image-editor/core/types.cjs.map +7 -0
- package/build/image-editor/index.cjs +57 -0
- package/build/image-editor/index.cjs.map +7 -0
- package/build/image-editor/react/components/cropper-provider.cjs +50 -0
- package/build/image-editor/react/components/cropper-provider.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +365 -0
- package/build/image-editor/react/components/cropper.cjs.map +7 -0
- package/build/image-editor/react/components/index.cjs +36 -0
- package/build/image-editor/react/components/index.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +58 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +91 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +351 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +7 -0
- package/build/image-editor/react/hooks/index.cjs +31 -0
- package/build/image-editor/react/hooks/index.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +68 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs +158 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +161 -0
- package/build/image-editor/react/hooks/use-interaction.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs +38 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +7 -0
- package/build/index.cjs +5 -2
- package/build/index.cjs.map +2 -2
- package/build/lock-unlock.cjs +37 -0
- package/build/lock-unlock.cjs.map +7 -0
- package/build/private-apis.cjs +38 -0
- package/build/private-apis.cjs.map +7 -0
- package/build/store/actions.cjs +45 -0
- package/build/store/actions.cjs.map +7 -0
- package/build/store/constants.cjs +31 -0
- package/build/store/constants.cjs.map +7 -0
- package/build/store/index.cjs +51 -0
- package/build/store/index.cjs.map +7 -0
- package/build/store/reducer.cjs +51 -0
- package/build/store/reducer.cjs.map +7 -0
- package/build/store/selectors.cjs +43 -0
- package/build/store/selectors.cjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +33 -0
- package/build-module/components/media-editor-canvas/index.mjs.map +7 -0
- package/build-module/components/media-editor-crop-panel/index.mjs +100 -0
- package/build-module/components/media-editor-crop-panel/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs +66 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +483 -0
- package/build-module/components/media-editor-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-toolbar/index.mjs +130 -0
- package/build-module/components/media-editor-toolbar/index.mjs.map +7 -0
- package/build-module/components/media-preview/index.mjs +1 -1
- package/build-module/components/media-preview/index.mjs.map +2 -2
- package/build-module/image-editor/core/camera.mjs +163 -0
- package/build-module/image-editor/core/camera.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +51 -0
- package/build-module/image-editor/core/constants.mjs.map +7 -0
- package/build-module/image-editor/core/containment.mjs +218 -0
- package/build-module/image-editor/core/containment.mjs.map +7 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs +120 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +7 -0
- package/build-module/image-editor/core/index.mjs +24 -0
- package/build-module/image-editor/core/index.mjs.map +7 -0
- package/build-module/image-editor/core/interaction-controller.mjs +583 -0
- package/build-module/image-editor/core/interaction-controller.mjs.map +7 -0
- package/build-module/image-editor/core/math/rotation.mjs +15 -0
- package/build-module/image-editor/core/math/rotation.mjs.map +7 -0
- package/build-module/image-editor/core/source-region.mjs +69 -0
- package/build-module/image-editor/core/source-region.mjs.map +7 -0
- package/build-module/image-editor/core/state.mjs +242 -0
- package/build-module/image-editor/core/state.mjs.map +7 -0
- package/build-module/image-editor/core/stencil-math.mjs +169 -0
- package/build-module/image-editor/core/stencil-math.mjs.map +7 -0
- package/build-module/image-editor/core/transform-style.mjs +21 -0
- package/build-module/image-editor/core/transform-style.mjs.map +7 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs +17 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +7 -0
- package/build-module/image-editor/core/types.mjs +1 -0
- package/build-module/image-editor/core/types.mjs.map +7 -0
- package/build-module/image-editor/index.mjs +30 -0
- package/build-module/image-editor/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs +26 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +337 -0
- package/build-module/image-editor/react/components/cropper.mjs.map +7 -0
- package/build-module/image-editor/react/components/index.mjs +9 -0
- package/build-module/image-editor/react/components/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +33 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +66 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +330 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/index.mjs +6 -0
- package/build-module/image-editor/react/hooks/index.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +43 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +137 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +138 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +13 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +7 -0
- package/build-module/index.mjs +3 -1
- package/build-module/index.mjs.map +2 -2
- package/build-module/lock-unlock.mjs +11 -0
- package/build-module/lock-unlock.mjs.map +7 -0
- package/build-module/private-apis.mjs +13 -0
- package/build-module/private-apis.mjs.map +7 -0
- package/build-module/store/actions.mjs +19 -0
- package/build-module/store/actions.mjs.map +7 -0
- package/build-module/store/constants.mjs +6 -0
- package/build-module/store/constants.mjs.map +7 -0
- package/build-module/store/index.mjs +16 -0
- package/build-module/store/index.mjs.map +7 -0
- package/build-module/store/reducer.mjs +26 -0
- package/build-module/store/reducer.mjs.map +7 -0
- package/build-module/store/selectors.mjs +16 -0
- package/build-module/store/selectors.mjs.map +7 -0
- package/build-style/style-rtl.css +315 -0
- package/build-style/style.css +315 -0
- package/build-types/components/media-editor-canvas/index.d.ts +22 -0
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts +45 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +83 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +20 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-toolbar/index.d.ts +21 -0
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts +107 -0
- package/build-types/image-editor/core/camera.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +46 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -0
- package/build-types/image-editor/core/containment.d.ts +61 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +106 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +8 -0
- package/build-types/image-editor/core/index.d.ts.map +1 -0
- package/build-types/image-editor/core/interaction-controller.d.ts +178 -0
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -0
- package/build-types/image-editor/core/math/rotation.d.ts +18 -0
- package/build-types/image-editor/core/math/rotation.d.ts.map +1 -0
- package/build-types/image-editor/core/source-region.d.ts +75 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -0
- package/build-types/image-editor/core/state.d.ts +42 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -0
- package/build-types/image-editor/core/stencil-math.d.ts +79 -0
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -0
- package/build-types/image-editor/core/transform-style.d.ts +23 -0
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts +27 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -0
- package/build-types/image-editor/core/types.d.ts +211 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -0
- package/build-types/image-editor/index.d.ts +16 -0
- package/build-types/image-editor/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +37 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper.d.ts +59 -0
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -0
- package/build-types/image-editor/react/components/index.d.ts +4 -0
- package/build-types/image-editor/react/components/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +32 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/index.d.ts +3 -0
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +68 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +60 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts +16 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -0
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/private-apis.d.ts +2 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +27 -0
- package/build-types/store/actions.d.ts.map +1 -0
- package/build-types/store/constants.d.ts +2 -0
- package/build-types/store/constants.d.ts.map +1 -0
- package/build-types/store/index.d.ts +4 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/store/reducer.d.ts +23 -0
- package/build-types/store/reducer.d.ts.map +1 -0
- package/build-types/store/selectors.d.ts +8 -0
- package/build-types/store/selectors.d.ts.map +1 -0
- package/package.json +21 -8
- package/src/components/media-editor-canvas/index.tsx +56 -0
- package/src/components/media-editor-canvas/style.scss +9 -0
- package/src/components/media-editor-crop-panel/index.tsx +143 -0
- package/src/components/media-editor-modal/build-modifiers.ts +164 -0
- package/src/components/media-editor-modal/index.tsx +639 -0
- package/src/components/media-editor-modal/style.scss +139 -0
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +343 -0
- package/src/components/media-editor-toolbar/index.tsx +150 -0
- package/src/components/media-editor-toolbar/style.scss +21 -0
- package/src/components/media-preview/index.tsx +2 -1
- package/src/image-editor/README.md +162 -0
- package/src/image-editor/core/camera.ts +352 -0
- package/src/image-editor/core/constants.ts +93 -0
- package/src/image-editor/core/containment.ts +435 -0
- package/src/image-editor/core/export/canvas-renderer.ts +253 -0
- package/src/image-editor/core/export/test/canvas-renderer.ts +813 -0
- package/src/image-editor/core/index.ts +35 -0
- package/src/image-editor/core/interaction-controller.ts +889 -0
- package/src/image-editor/core/math/rotation.ts +26 -0
- package/src/image-editor/core/source-region.ts +166 -0
- package/src/image-editor/core/state.ts +428 -0
- package/src/image-editor/core/stencil-math.ts +330 -0
- package/src/image-editor/core/test/camera.ts +593 -0
- package/src/image-editor/core/test/interaction-controller.ts +996 -0
- package/src/image-editor/core/test/preview-export-parity.ts +242 -0
- package/src/image-editor/core/test/render-camera-bridge.ts +348 -0
- package/src/image-editor/core/test/state.ts +762 -0
- package/src/image-editor/core/test/stencil-math.ts +321 -0
- package/src/image-editor/core/transform-style.ts +44 -0
- package/src/image-editor/core/transforms/pipeline.ts +43 -0
- package/src/image-editor/core/transforms/test/pipeline.ts +269 -0
- package/src/image-editor/core/types.ts +177 -0
- package/src/image-editor/docs/architecture.md +96 -0
- package/src/image-editor/docs/recipes.md +720 -0
- package/src/image-editor/docs/roadmap.md +66 -0
- package/src/image-editor/index.ts +43 -0
- package/src/image-editor/react/components/cropper-provider.tsx +73 -0
- package/src/image-editor/react/components/cropper.scss +195 -0
- package/src/image-editor/react/components/cropper.tsx +534 -0
- package/src/image-editor/react/components/index.ts +3 -0
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +57 -0
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +80 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +513 -0
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +265 -0
- package/src/image-editor/react/components/test/cropper.tsx +140 -0
- package/src/image-editor/react/hooks/index.ts +2 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +913 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +218 -0
- package/src/image-editor/react/hooks/test/use-transform-style.ts +146 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +64 -0
- package/src/image-editor/react/hooks/use-cropper-state.ts +238 -0
- package/src/image-editor/react/hooks/use-interaction.ts +223 -0
- package/src/image-editor/react/hooks/use-transform-style.ts +30 -0
- package/src/image-editor/stories/rectangle-crop.story.tsx +1085 -0
- package/src/image-editor/stories/style.css +94 -0
- package/src/image-editor/style.scss +1 -0
- package/src/index.ts +3 -0
- package/src/lock-unlock.ts +10 -0
- package/src/private-apis.ts +12 -0
- package/src/store/actions.ts +33 -0
- package/src/store/constants.ts +1 -0
- package/src/store/index.ts +20 -0
- package/src/store/reducer.ts +48 -0
- package/src/store/selectors.ts +16 -0
- package/src/store/test/reducer.ts +57 -0
- package/src/style.scss +4 -0
- package/tsconfig.json +10 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/image-editor/react/hooks/use-cropper-state.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useReducer, useCallback, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tTransformOperation,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tFlip,\n} from '../../core/types';\nimport { DEFAULT_STATE } from '../../core/constants';\nimport { exportCroppedImage } from '../../core/export/canvas-renderer';\nimport {\n\tcropperReducer,\n\tenforceContainment,\n\tisStateDirty,\n} from '../../core/state';\n\n/**\n * The return type of the useCropperState hook.\n *\n * The hook exposes its state through named setter methods rather\n * than a raw dispatch function. Each setter has a specific\n * behavioral contract (see individual JSDoc) that maps 1:1 to a\n * reducer action internally. Keeping the reducer actions private\n * lets the implementation evolve without breaking consumers.\n */\nexport interface UseCropperStateReturn {\n\t/** The current cropper state (read-only). */\n\tstate: CropperState;\n\t/** Set the loaded image (natural size and src). */\n\tsetImage: ( image: CropperState[ 'image' ] ) => void;\n\t/**\n\t * Set the image pan offset in normalized coordinates. Use\n\t * `setCropRect` for the crop rectangle.\n\t */\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\t/** Set the zoom level. Clamped to [1, 10]. */\n\tsetZoom: ( zoom: number ) => void;\n\t/** Set zoom and pan together so focal-point zoom remains atomic. */\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\t/** Set the rotation in degrees. Normalized to [0, 360). */\n\tsetRotation: ( rotation: number ) => void;\n\t/** Set the flip state. */\n\tsetFlip: ( flip: Flip ) => void;\n\t/** Snap rotate 90\u00B0 preserving the image selection (Google Photos style). */\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\t/** Set the crop rectangle in normalized coordinates. */\n\tsetCropRect: ( rect: NormalizedRect ) => void;\n\t/**\n\t * Settle the crop rect after a resize drag: expand to fill the\n\t * available visual area while preserving the framed image region.\n\t * Typically called from a stencil's `onResizeEnd` callback.\n\t */\n\tsettleCrop: () => void;\n\t/** Apply a transform operation through the pipeline. */\n\tapplyOperation: ( op: TransformOperation ) => void;\n\t/** Reset the state. Optionally merge partial state overrides. */\n\treset: ( resetState?: Partial< CropperState > ) => void;\n\t/** Whether the current state differs from the initial state. */\n\tisDirty: boolean;\n\t/**\n\t * Export the cropped image as a Blob. Throws on failure \u2014 see\n\t * `exportCroppedImage` in core for the error semantics (image\n\t * load errors, CORS taint, missing canvas context). Wrap in\n\t * try/catch if you need to recover.\n\t */\n\tgetCroppedImage: ( mimeType?: string, quality?: number ) => Promise< Blob >;\n}\n\n/**\n * Reducer-based state management hook for the image editor.\n *\n * Provides the full cropper state and named setter methods for\n * every supported transition. The reducer and containment logic\n * live in core/state.ts (framework-agnostic); this hook is a thin\n * React wrapper around that pure reducer, with memoized callbacks.\n *\n * @param initialState Optional partial state to merge with DEFAULT_STATE.\n * @return The cropper state, setters, and utilities.\n */\nexport function useCropperState(\n\tinitialState?: Partial< CropperState >\n): UseCropperStateReturn {\n\tconst [ state, dispatch ] = useReducer(\n\t\tcropperReducer,\n\t\tinitialState,\n\t\t( init ) => enforceContainment( { ...DEFAULT_STATE, ...init } )\n\t);\n\n\tconst initialRef = useRef< CropperState >(\n\t\tenforceContainment( { ...DEFAULT_STATE, ...initialState } )\n\t);\n\t// Keep a ref to the latest state so callbacks with stable identity\n\t// (reset, setImage) can read fresh state without re-creating themselves.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\n\tconst setImage = useCallback(\n\t\t( image: CropperState[ 'image' ] ) => {\n\t\t\tdispatch( { type: 'SET_IMAGE', payload: image } );\n\t\t\t// Refresh the \"clean\" snapshot to match the post-load state\n\t\t\t// produced by the reducer. Otherwise containment can nudge\n\t\t\t// pan/zoom by tiny amounts on load and `isDirty` would\n\t\t\t// report true from the start.\n\t\t\tinitialRef.current = enforceContainment( {\n\t\t\t\t...initialRef.current,\n\t\t\t\timage,\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setPan = useCallback(\n\t\t( pan: NormalizedPoint ) => {\n\t\t\tdispatch( { type: 'SET_PAN', payload: pan } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setZoom = useCallback(\n\t\t( zoom: number ) => {\n\t\t\tdispatch( { type: 'SET_ZOOM', payload: zoom } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setZoomAtPoint = useCallback(\n\t\t( zoom: number, pan: NormalizedPoint ) => {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\t\t\tpayload: { zoom, pan },\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setRotation = useCallback(\n\t\t( rotation: number ) => {\n\t\t\tdispatch( { type: 'SET_ROTATION', payload: rotation } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setFlip = useCallback(\n\t\t( flip: Flip ) => {\n\t\t\tdispatch( { type: 'SET_FLIP', payload: flip } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst snapRotate90 = useCallback(\n\t\t( direction: 1 | -1 ) => {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SNAP_ROTATE_90',\n\t\t\t\tpayload: { direction },\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setCropRect = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tdispatch( { type: 'SET_CROP_RECT', payload: rect } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst settleCrop = useCallback( () => {\n\t\tdispatch( { type: 'SETTLE_CROP' } );\n\t}, [ dispatch ] );\n\n\tconst applyOperation = useCallback(\n\t\t( op: TransformOperation ) => {\n\t\t\tdispatch( { type: 'APPLY_OPERATION', payload: op } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst reset = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tdispatch( { type: 'RESET', payload: resetState } );\n\t\t\t// Mirror the reducer's RESET exactly so isDirty stays in\n\t\t\t// sync. RESET preserves the currently-loaded image; the\n\t\t\t// containment step can tweak pan/zoom/cropRect by float ulp,\n\t\t\t// which we must fold into the \"initial\" snapshot or isDirty\n\t\t\t// would report true after a reset.\n\t\t\tinitialRef.current = enforceContainment( {\n\t\t\t\t...DEFAULT_STATE,\n\t\t\t\timage: stateRef.current.image,\n\t\t\t\t...resetState,\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst isDirty = isStateDirty( state, initialRef.current );\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded \u2014 call setImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.image.src,\n\t\t\t\tstate,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state ]\n\t);\n\n\tconst controller: UseCropperStateReturn = {\n\t\tstate,\n\t\tsetImage,\n\t\tsetPan,\n\t\tsetZoom,\n\t\tsetZoomAtPoint,\n\t\tsetRotation,\n\t\tsetFlip,\n\t\tsnapRotate90,\n\t\tsetCropRect,\n\t\tsettleCrop,\n\t\tapplyOperation,\n\t\treset,\n\t\tisDirty,\n\t\tgetCroppedImage,\n\t};\n\treturn controller;\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// packages/media-editor/src/image-editor/react/hooks/use-interaction.ts
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "@wordpress/element";
|
|
3
|
+
import {
|
|
4
|
+
InteractionController
|
|
5
|
+
} from "../../core/interaction-controller.mjs";
|
|
6
|
+
var KEYBOARD_INTERACTION_IDLE_MS = 300;
|
|
7
|
+
function isHandledKeyboardPan(event) {
|
|
8
|
+
switch (event.key) {
|
|
9
|
+
case "ArrowUp":
|
|
10
|
+
case "ArrowDown":
|
|
11
|
+
case "ArrowLeft":
|
|
12
|
+
case "ArrowRight":
|
|
13
|
+
return true;
|
|
14
|
+
default:
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function useInteraction(state, actions, containerSize, imageSize, options) {
|
|
19
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
20
|
+
const [isZooming, setIsZooming] = useState(false);
|
|
21
|
+
const [isGestureActive, setIsGestureActive] = useState(false);
|
|
22
|
+
const [isKeyboardPanning, setIsKeyboardPanning] = useState(false);
|
|
23
|
+
const keyboardInteractionTimerRef = useRef();
|
|
24
|
+
const stateRef = useRef(state);
|
|
25
|
+
stateRef.current = state;
|
|
26
|
+
const containerSizeRef = useRef(containerSize);
|
|
27
|
+
containerSizeRef.current = containerSize;
|
|
28
|
+
const imageSizeRef = useRef(imageSize);
|
|
29
|
+
imageSizeRef.current = imageSize;
|
|
30
|
+
const optionsRef = useRef(options);
|
|
31
|
+
optionsRef.current = options;
|
|
32
|
+
const actionsRef = useRef(actions);
|
|
33
|
+
actionsRef.current = actions;
|
|
34
|
+
const controllerRef = useRef(null);
|
|
35
|
+
const startPlacementGesture = useCallback(() => {
|
|
36
|
+
setIsGestureActive(true);
|
|
37
|
+
}, []);
|
|
38
|
+
const stopPlacementGesture = useCallback(() => {
|
|
39
|
+
setIsGestureActive(false);
|
|
40
|
+
}, []);
|
|
41
|
+
const signalKeyboardPlacement = useCallback(() => {
|
|
42
|
+
setIsKeyboardPanning(true);
|
|
43
|
+
clearTimeout(keyboardInteractionTimerRef.current);
|
|
44
|
+
keyboardInteractionTimerRef.current = setTimeout(() => {
|
|
45
|
+
setIsKeyboardPanning(false);
|
|
46
|
+
}, KEYBOARD_INTERACTION_IDLE_MS);
|
|
47
|
+
}, []);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
return () => {
|
|
50
|
+
clearTimeout(keyboardInteractionTimerRef.current);
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const controller = new InteractionController({
|
|
55
|
+
getState: () => stateRef.current,
|
|
56
|
+
actions: {
|
|
57
|
+
setPan: (pan) => actionsRef.current.setPan(pan),
|
|
58
|
+
setZoom: (zoom) => actionsRef.current.setZoom(zoom),
|
|
59
|
+
setZoomAtPoint: (zoom, pan) => actionsRef.current.setZoomAtPoint(zoom, pan),
|
|
60
|
+
snapRotate90: (direction) => actionsRef.current.snapRotate90(direction)
|
|
61
|
+
},
|
|
62
|
+
getContainerSize: () => containerSizeRef.current,
|
|
63
|
+
getImageSize: () => imageSizeRef.current,
|
|
64
|
+
get minZoom() {
|
|
65
|
+
return optionsRef.current?.minZoom;
|
|
66
|
+
},
|
|
67
|
+
get maxZoom() {
|
|
68
|
+
return optionsRef.current?.maxZoom;
|
|
69
|
+
},
|
|
70
|
+
get zoomSpeed() {
|
|
71
|
+
return optionsRef.current?.zoomSpeed;
|
|
72
|
+
},
|
|
73
|
+
get keyboardStep() {
|
|
74
|
+
return optionsRef.current?.keyboardStep;
|
|
75
|
+
},
|
|
76
|
+
get doubleTapZoom() {
|
|
77
|
+
return optionsRef.current?.doubleTapZoom;
|
|
78
|
+
},
|
|
79
|
+
onGestureStart: () => {
|
|
80
|
+
startPlacementGesture();
|
|
81
|
+
optionsRef.current?.onGestureStart?.();
|
|
82
|
+
},
|
|
83
|
+
onGestureEnd: () => {
|
|
84
|
+
stopPlacementGesture();
|
|
85
|
+
optionsRef.current?.onGestureEnd?.();
|
|
86
|
+
},
|
|
87
|
+
onStatusChange: (status) => {
|
|
88
|
+
setIsDragging(status.isDragging);
|
|
89
|
+
setIsZooming(status.isZooming);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
controllerRef.current = controller;
|
|
93
|
+
return () => {
|
|
94
|
+
controller.destroy();
|
|
95
|
+
controllerRef.current = null;
|
|
96
|
+
};
|
|
97
|
+
}, [startPlacementGesture, stopPlacementGesture]);
|
|
98
|
+
const onPointerDown = useCallback((e) => {
|
|
99
|
+
const el = e.currentTarget;
|
|
100
|
+
controllerRef.current?.handlePointerDown(e.nativeEvent, el);
|
|
101
|
+
}, []);
|
|
102
|
+
const onTouchStart = useCallback((e) => {
|
|
103
|
+
const el = e.currentTarget;
|
|
104
|
+
const rect = el.getBoundingClientRect();
|
|
105
|
+
controllerRef.current?.handleTouchStart(
|
|
106
|
+
e.nativeEvent,
|
|
107
|
+
rect,
|
|
108
|
+
el.ownerDocument
|
|
109
|
+
);
|
|
110
|
+
}, []);
|
|
111
|
+
const onKeyDown = useCallback(
|
|
112
|
+
(e) => {
|
|
113
|
+
if (isHandledKeyboardPan(e.nativeEvent)) {
|
|
114
|
+
signalKeyboardPlacement();
|
|
115
|
+
}
|
|
116
|
+
controllerRef.current?.handleKeyDown(e.nativeEvent);
|
|
117
|
+
},
|
|
118
|
+
[signalKeyboardPlacement]
|
|
119
|
+
);
|
|
120
|
+
const onWheelNative = useCallback((e) => {
|
|
121
|
+
controllerRef.current?.handleWheel(e);
|
|
122
|
+
}, []);
|
|
123
|
+
return {
|
|
124
|
+
handlers: {
|
|
125
|
+
onPointerDown,
|
|
126
|
+
onTouchStart,
|
|
127
|
+
onKeyDown
|
|
128
|
+
},
|
|
129
|
+
onWheelNative,
|
|
130
|
+
isDragging,
|
|
131
|
+
isZooming,
|
|
132
|
+
isPlacementActive: isGestureActive || isKeyboardPanning || isZooming
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
useInteraction
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=use-interaction.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/image-editor/react/hooks/use-interaction.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from '../../core/types';\nimport {\n\tInteractionController,\n\ttype CropperInteractionActions,\n} from '../../core/interaction-controller';\n\n/**\n * The return type of the useInteraction hook.\n */\nexport interface UseInteractionReturn {\n\t/** Event handler props to spread on the container element. */\n\thandlers: {\n\t\tonPointerDown: ( e: React.PointerEvent ) => void;\n\t\tonTouchStart: ( e: React.TouchEvent ) => void;\n\t\tonKeyDown: ( e: React.KeyboardEvent ) => void;\n\t};\n\t/** Native wheel handler \u2014 must be registered with { passive: false }. */\n\tonWheelNative: ( e: WheelEvent ) => void;\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n\t/** Whether the user is currently performing a placement interaction. */\n\tisPlacementActive: boolean;\n}\n\n/**\n * Options for the useInteraction hook.\n */\nexport interface UseInteractionOptions {\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.01. */\n\tzoomSpeed?: number;\n\t/** Pan step size in normalized coords for keyboard events. Defaults to 0.05. */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n}\n\n/** How long keyboard placement stays active after the latest handled key. */\nconst KEYBOARD_INTERACTION_IDLE_MS = 300;\n\nfunction isHandledKeyboardPan( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase 'ArrowUp':\n\t\tcase 'ArrowDown':\n\t\tcase 'ArrowLeft':\n\t\tcase 'ArrowRight':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Mouse, touch, and keyboard event handling for pan, zoom,\n * and crop manipulation.\n *\n * Returns event handler props to spread on the container element.\n * Uses requestAnimationFrame for drag/pinch updates to avoid\n * layout thrashing.\n *\n * @param state The current cropper state.\n * @param actions Named state updates for cropper interactions.\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param options Optional configuration for zoom and keyboard behavior.\n * @return Event handler props for the container element.\n */\nexport function useInteraction(\n\tstate: CropperState,\n\tactions: CropperInteractionActions,\n\tcontainerSize: Size,\n\timageSize?: Size,\n\toptions?: UseInteractionOptions\n): UseInteractionReturn {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\tconst [ isZooming, setIsZooming ] = useState( false );\n\tconst [ isGestureActive, setIsGestureActive ] = useState( false );\n\tconst [ isKeyboardPanning, setIsKeyboardPanning ] = useState( false );\n\tconst keyboardInteractionTimerRef =\n\t\tuseRef< ReturnType< typeof setTimeout > >();\n\n\t// Keep mutable refs so the controller always reads fresh values\n\t// without needing to be recreated.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\tconst containerSizeRef = useRef( containerSize );\n\tcontainerSizeRef.current = containerSize;\n\tconst imageSizeRef = useRef( imageSize );\n\timageSizeRef.current = imageSize;\n\tconst optionsRef = useRef( options );\n\toptionsRef.current = options;\n\tconst actionsRef = useRef( actions );\n\tactionsRef.current = actions;\n\n\tconst controllerRef = useRef< InteractionController | null >( null );\n\tconst startPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( true );\n\t}, [] );\n\tconst stopPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( false );\n\t}, [] );\n\tconst signalKeyboardPlacement = useCallback( () => {\n\t\tsetIsKeyboardPanning( true );\n\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\tkeyboardInteractionTimerRef.current = setTimeout( () => {\n\t\t\tsetIsKeyboardPanning( false );\n\t\t}, KEYBOARD_INTERACTION_IDLE_MS );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Create / destroy the controller. The controller reads all volatile\n\t// values through refs, so it can stay mounted across render updates.\n\tuseEffect( () => {\n\t\tconst controller = new InteractionController( {\n\t\t\tgetState: () => stateRef.current,\n\t\t\tactions: {\n\t\t\t\tsetPan: ( pan ) => actionsRef.current.setPan( pan ),\n\t\t\t\tsetZoom: ( zoom ) => actionsRef.current.setZoom( zoom ),\n\t\t\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\t\t\tactionsRef.current.setZoomAtPoint( zoom, pan ),\n\t\t\t\tsnapRotate90: ( direction ) =>\n\t\t\t\t\tactionsRef.current.snapRotate90( direction ),\n\t\t\t},\n\t\t\tgetContainerSize: () => containerSizeRef.current,\n\t\t\tgetImageSize: () => imageSizeRef.current,\n\t\t\tget minZoom() {\n\t\t\t\treturn optionsRef.current?.minZoom;\n\t\t\t},\n\t\t\tget maxZoom() {\n\t\t\t\treturn optionsRef.current?.maxZoom;\n\t\t\t},\n\t\t\tget zoomSpeed() {\n\t\t\t\treturn optionsRef.current?.zoomSpeed;\n\t\t\t},\n\t\t\tget keyboardStep() {\n\t\t\t\treturn optionsRef.current?.keyboardStep;\n\t\t\t},\n\t\t\tget doubleTapZoom() {\n\t\t\t\treturn optionsRef.current?.doubleTapZoom;\n\t\t\t},\n\t\t\tonGestureStart: () => {\n\t\t\t\tstartPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t\t},\n\t\t\tonGestureEnd: () => {\n\t\t\t\tstopPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t\t},\n\t\t\tonStatusChange: ( status ) => {\n\t\t\t\tsetIsDragging( status.isDragging );\n\t\t\t\tsetIsZooming( status.isZooming );\n\t\t\t},\n\t\t} );\n\t\tcontrollerRef.current = controller;\n\t\treturn () => {\n\t\t\tcontroller.destroy();\n\t\t\tcontrollerRef.current = null;\n\t\t};\n\t}, [ startPlacementGesture, stopPlacementGesture ] );\n\n\tconst onPointerDown = useCallback( ( e: React.PointerEvent ) => {\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tcontrollerRef.current?.handlePointerDown( e.nativeEvent, el );\n\t}, [] );\n\n\tconst onTouchStart = useCallback( ( e: React.TouchEvent ) => {\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tconst rect = el.getBoundingClientRect();\n\t\tcontrollerRef.current?.handleTouchStart(\n\t\t\te.nativeEvent,\n\t\t\trect,\n\t\t\tel.ownerDocument\n\t\t);\n\t}, [] );\n\n\tconst onKeyDown = useCallback(\n\t\t( e: React.KeyboardEvent ) => {\n\t\t\tif ( isHandledKeyboardPan( e.nativeEvent ) ) {\n\t\t\t\tsignalKeyboardPlacement();\n\t\t\t}\n\t\t\tcontrollerRef.current?.handleKeyDown( e.nativeEvent );\n\t\t},\n\t\t[ signalKeyboardPlacement ]\n\t);\n\n\tconst onWheelNative = useCallback( ( e: WheelEvent ) => {\n\t\tcontrollerRef.current?.handleWheel( e );\n\t}, [] );\n\n\treturn {\n\t\thandlers: {\n\t\t\tonPointerDown,\n\t\t\tonTouchStart,\n\t\t\tonKeyDown,\n\t\t},\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isGestureActive || isKeyboardPanning || isZooming,\n\t};\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// packages/media-editor/src/image-editor/react/hooks/use-transform-style.ts
|
|
2
|
+
import { useMemo } from "@wordpress/element";
|
|
3
|
+
import { computeTransformStyle } from "../../core/transform-style.mjs";
|
|
4
|
+
function useTransformStyle(state, imageSize) {
|
|
5
|
+
return useMemo(
|
|
6
|
+
() => computeTransformStyle(state, imageSize),
|
|
7
|
+
[state, imageSize]
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
useTransformStyle
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=use-transform-style.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/image-editor/react/hooks/use-transform-style.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from '../../core/types';\nimport { computeTransformStyle } from '../../core/transform-style';\n\n/**\n * React hook that computes a memoized CSS matrix() transform string\n * from the cropper state.\n *\n * Delegates to the pure `computeTransformStyle` function in core.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function useTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\treturn useMemo(\n\t\t() => computeTransformStyle( state, imageSize ),\n\t\t[ state, imageSize ]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,eAAe;AAMxB,SAAS,6BAA6B;AAY/B,SAAS,kBACf,OACA,WACS;AACT,SAAO;AAAA,IACN,MAAM,sBAAuB,OAAO,SAAU;AAAA,IAC9C,CAAE,OAAO,SAAU;AAAA,EACpB;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.mjs
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
import { MediaEditorProvider } from "./components/media-editor-provider/index.mjs";
|
|
3
3
|
import { default as default2 } from "./components/media-preview/index.mjs";
|
|
4
4
|
import { default as default3 } from "./components/media-form/index.mjs";
|
|
5
|
+
import { privateApis } from "./private-apis.mjs";
|
|
5
6
|
export {
|
|
6
7
|
MediaEditorProvider,
|
|
7
8
|
default3 as MediaForm,
|
|
8
|
-
default2 as MediaPreview
|
|
9
|
+
default2 as MediaPreview,
|
|
10
|
+
privateApis
|
|
9
11
|
};
|
|
10
12
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Components\nexport { MediaEditorProvider } from './components/media-editor-provider';\nexport { default as MediaPreview } from './components/media-preview';\nexport { default as MediaForm } from './components/media-form';\n\n// Types\nexport type {\n\tMedia,\n\tMediaEditorProviderProps,\n} from './components/media-editor-provider';\nexport type { MediaPreviewProps } from './components/media-preview';\nexport type { MediaFormProps } from './components/media-form';\n\n// Re-export commonly used dataviews types for convenience\nexport type { Field, Form } from '@wordpress/dataviews';\n"],
|
|
5
|
-
"mappings": ";AACA,SAAS,2BAA2B;AACpC,SAAoB,WAAXA,gBAA+B;AACxC,SAAoB,WAAXA,gBAA4B;",
|
|
4
|
+
"sourcesContent": ["// Components\nexport { MediaEditorProvider } from './components/media-editor-provider';\nexport { default as MediaPreview } from './components/media-preview';\nexport { default as MediaForm } from './components/media-form';\n\n// Types\nexport type {\n\tMedia,\n\tMediaEditorProviderProps,\n} from './components/media-editor-provider';\nexport type { MediaPreviewProps } from './components/media-preview';\nexport type { MediaFormProps } from './components/media-form';\n\n// Re-export commonly used dataviews types for convenience\nexport type { Field, Form } from '@wordpress/dataviews';\n\n// Private APIs (experimental \u2014 not for use outside of core packages).\nexport { privateApis } from './private-apis';\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,2BAA2B;AACpC,SAAoB,WAAXA,gBAA+B;AACxC,SAAoB,WAAXA,gBAA4B;AAcrC,SAAS,mBAAmB;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// packages/media-editor/src/lock-unlock.ts
|
|
2
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from "@wordpress/private-apis";
|
|
3
|
+
var { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
4
|
+
"I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
|
|
5
|
+
"@wordpress/media-editor"
|
|
6
|
+
);
|
|
7
|
+
export {
|
|
8
|
+
lock,
|
|
9
|
+
unlock
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=lock-unlock.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lock-unlock.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/media-editor'\n\t);\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,wDAAwD;AAE1D,IAAM,EAAE,MAAM,OAAO,IAC3B;AAAA,EACC;AAAA,EACA;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// packages/media-editor/src/private-apis.ts
|
|
2
|
+
import { lock } from "./lock-unlock.mjs";
|
|
3
|
+
import { store } from "./store/index.mjs";
|
|
4
|
+
import { MediaEditorModal } from "./components/media-editor-modal/index.mjs";
|
|
5
|
+
var privateApis = {};
|
|
6
|
+
lock(privateApis, {
|
|
7
|
+
store,
|
|
8
|
+
MediaEditorModal
|
|
9
|
+
});
|
|
10
|
+
export {
|
|
11
|
+
privateApis
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=private-apis.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/private-apis.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport { store } from './store';\nimport { MediaEditorModal } from './components/media-editor-modal';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tstore,\n\tMediaEditorModal,\n} );\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,wBAAwB;AAE1B,IAAM,cAAc,CAAC;AAC5B,KAAM,aAAa;AAAA,EAClB;AAAA,EACA;AACD,CAAE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// packages/media-editor/src/store/actions.ts
|
|
2
|
+
function openMediaEditorModal({
|
|
3
|
+
id,
|
|
4
|
+
onUpdate
|
|
5
|
+
}) {
|
|
6
|
+
return {
|
|
7
|
+
type: "OPEN_MEDIA_EDITOR_MODAL",
|
|
8
|
+
id,
|
|
9
|
+
onUpdate: onUpdate ?? null
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function closeMediaEditorModal() {
|
|
13
|
+
return { type: "CLOSE_MEDIA_EDITOR_MODAL" };
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
closeMediaEditorModal,
|
|
17
|
+
openMediaEditorModal
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=actions.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/actions.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Shape passed to `onUpdate` after a successful save. Deliberately normalized\n * and minimal: `url` instead of REST's `source_url`, so consumers can drop\n * it straight into block attributes (matches the legacy `ImageEditor`'s\n * `onSaveImage` shape at\n * `packages/block-editor/src/components/image-editor/use-save-image.js`).\n * Keeping this decoupled from the REST field names also leaves room to reuse\n * the modal outside a WordPress REST context (e.g. native/Electron hosts).\n */\nexport interface MediaEditorModalUpdate {\n\tid: number;\n\turl?: string;\n}\n\ninterface OpenMediaEditorModalArgs {\n\tid: number;\n\tonUpdate?: ( updated: MediaEditorModalUpdate ) => void;\n}\n\nexport function openMediaEditorModal( {\n\tid,\n\tonUpdate,\n}: OpenMediaEditorModalArgs ) {\n\treturn {\n\t\ttype: 'OPEN_MEDIA_EDITOR_MODAL' as const,\n\t\tid,\n\t\tonUpdate: onUpdate ?? null,\n\t};\n}\n\nexport function closeMediaEditorModal() {\n\treturn { type: 'CLOSE_MEDIA_EDITOR_MODAL' as const };\n}\n"],
|
|
5
|
+
"mappings": ";AAmBO,SAAS,qBAAsB;AAAA,EACrC;AAAA,EACA;AACD,GAA8B;AAC7B,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA,UAAU,YAAY;AAAA,EACvB;AACD;AAEO,SAAS,wBAAwB;AACvC,SAAO,EAAE,MAAM,2BAAoC;AACpD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// packages/media-editor/src/store/index.ts
|
|
2
|
+
import { createReduxStore, register } from "@wordpress/data";
|
|
3
|
+
import reducer from "./reducer.mjs";
|
|
4
|
+
import * as actions from "./actions.mjs";
|
|
5
|
+
import * as selectors from "./selectors.mjs";
|
|
6
|
+
import { STORE_NAME } from "./constants.mjs";
|
|
7
|
+
var store = createReduxStore(STORE_NAME, {
|
|
8
|
+
reducer,
|
|
9
|
+
actions,
|
|
10
|
+
selectors
|
|
11
|
+
});
|
|
12
|
+
register(store);
|
|
13
|
+
export {
|
|
14
|
+
store
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,kBAAkB,gBAAgB;AAK3C,OAAO,aAAa;AACpB,YAAY,aAAa;AACzB,YAAY,eAAe;AAC3B,SAAS,kBAAkB;AAEpB,IAAM,QAAQ,iBAAkB,YAAY;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAEF,SAAU,KAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// packages/media-editor/src/store/reducer.ts
|
|
2
|
+
var DEFAULT_STATE = {
|
|
3
|
+
isOpen: false,
|
|
4
|
+
id: null,
|
|
5
|
+
onUpdate: null
|
|
6
|
+
};
|
|
7
|
+
function reducer(state = DEFAULT_STATE, action) {
|
|
8
|
+
switch (action.type) {
|
|
9
|
+
case "OPEN_MEDIA_EDITOR_MODAL": {
|
|
10
|
+
const { id, onUpdate } = action;
|
|
11
|
+
return {
|
|
12
|
+
isOpen: true,
|
|
13
|
+
id,
|
|
14
|
+
onUpdate
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
case "CLOSE_MEDIA_EDITOR_MODAL":
|
|
18
|
+
return DEFAULT_STATE;
|
|
19
|
+
}
|
|
20
|
+
return state;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
DEFAULT_STATE,
|
|
24
|
+
reducer as default
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=reducer.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/reducer.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { MediaEditorModalUpdate } from './actions';\n\ntype OnUpdateCallback = ( updated: MediaEditorModalUpdate ) => void;\n\nexport interface State {\n\tisOpen: boolean;\n\tid: number | null;\n\tonUpdate: OnUpdateCallback | null;\n}\n\nexport const DEFAULT_STATE: State = {\n\tisOpen: false,\n\tid: null,\n\tonUpdate: null,\n};\n\ntype Action =\n\t| {\n\t\t\ttype: 'OPEN_MEDIA_EDITOR_MODAL';\n\t\t\tid: number;\n\t\t\tonUpdate: OnUpdateCallback | null;\n\t }\n\t| { type: 'CLOSE_MEDIA_EDITOR_MODAL' };\n\nexport default function reducer(\n\tstate: State = DEFAULT_STATE,\n\taction: Action | { type: string }\n): State {\n\tswitch ( action.type ) {\n\t\tcase 'OPEN_MEDIA_EDITOR_MODAL': {\n\t\t\tconst { id, onUpdate } = action as Extract<\n\t\t\t\tAction,\n\t\t\t\t{ type: 'OPEN_MEDIA_EDITOR_MODAL' }\n\t\t\t>;\n\t\t\treturn {\n\t\t\t\tisOpen: true,\n\t\t\t\tid,\n\t\t\t\tonUpdate,\n\t\t\t};\n\t\t}\n\t\tcase 'CLOSE_MEDIA_EDITOR_MODAL':\n\t\t\treturn DEFAULT_STATE;\n\t}\n\treturn state;\n}\n"],
|
|
5
|
+
"mappings": ";AAaO,IAAM,gBAAuB;AAAA,EACnC,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,UAAU;AACX;AAUe,SAAR,QACN,QAAe,eACf,QACQ;AACR,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,2BAA2B;AAC/B,YAAM,EAAE,IAAI,SAAS,IAAI;AAIzB,aAAO;AAAA,QACN,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,KAAK;AACJ,aAAO;AAAA,EACT;AACA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// packages/media-editor/src/store/selectors.ts
|
|
2
|
+
function isOpen(state) {
|
|
3
|
+
return state.isOpen;
|
|
4
|
+
}
|
|
5
|
+
function getId(state) {
|
|
6
|
+
return state.id;
|
|
7
|
+
}
|
|
8
|
+
function getOnUpdate(state) {
|
|
9
|
+
return state.onUpdate;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
getId,
|
|
13
|
+
getOnUpdate,
|
|
14
|
+
isOpen
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=selectors.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/selectors.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { State } from './reducer';\n\nexport function isOpen( state: State ): boolean {\n\treturn state.isOpen;\n}\n\nexport function getId( state: State ): number | null {\n\treturn state.id;\n}\n\nexport function getOnUpdate( state: State ) {\n\treturn state.onUpdate;\n}\n"],
|
|
5
|
+
"mappings": ";AAKO,SAAS,OAAQ,OAAwB;AAC/C,SAAO,MAAM;AACd;AAEO,SAAS,MAAO,OAA8B;AACpD,SAAO,MAAM;AACd;AAEO,SAAS,YAAa,OAAe;AAC3C,SAAO,MAAM;AACd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|