@wordpress/media-editor 0.8.1-next.v.202605131032.0 → 0.10.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/index.cjs +34 -135
- package/build/components/media-editor/index.cjs.map +3 -3
- package/build/components/media-editor/use-crop-options.cjs +87 -0
- package/build/components/media-editor/use-crop-options.cjs.map +7 -0
- package/build/components/media-editor/use-save-media-editor.cjs +185 -0
- package/build/components/media-editor/use-save-media-editor.cjs.map +7 -0
- package/build/components/media-editor-canvas/index.cjs +32 -11
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +66 -83
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-modal/index.cjs +40 -11
- package/build/components/media-editor-modal/index.cjs.map +3 -3
- package/build/components/media-editor-toolbar/index.cjs +7 -3
- package/build/components/media-editor-toolbar/index.cjs.map +2 -2
- package/build/components/media-form/index.cjs +19 -1
- package/build/components/media-form/index.cjs.map +3 -3
- package/build/components/media-form/sidebar-datetime-view.cjs +53 -0
- package/build/components/media-form/sidebar-datetime-view.cjs.map +7 -0
- package/build/components/rotation-ruler/index.cjs +8 -2
- package/build/components/rotation-ruler/index.cjs.map +2 -2
- package/build/hooks/use-crop-gesture-handlers.cjs +41 -4
- package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
- package/build/image-editor/core/camera.cjs +29 -11
- package/build/image-editor/core/camera.cjs.map +2 -2
- package/build/image-editor/core/constants.cjs +6 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs +71 -34
- package/build/image-editor/core/containment.cjs.map +2 -2
- package/build/image-editor/core/crop-rect.cjs +48 -0
- package/build/image-editor/core/crop-rect.cjs.map +7 -0
- package/build/image-editor/core/index.cjs +12 -0
- package/build/image-editor/core/index.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/math/sanitize.cjs +92 -0
- package/build/image-editor/core/math/sanitize.cjs.map +7 -0
- package/build/image-editor/core/setter-helpers.cjs +64 -0
- package/build/image-editor/core/setter-helpers.cjs.map +7 -0
- package/build/image-editor/core/source-region.cjs +16 -14
- package/build/image-editor/core/source-region.cjs.map +2 -2
- package/build/image-editor/core/state.cjs +20 -10
- package/build/image-editor/core/state.cjs.map +2 -2
- package/build/image-editor/core/stencil-math.cjs +31 -20
- package/build/image-editor/core/stencil-math.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs +12 -6
- package/build/image-editor/core/transform-style.cjs.map +2 -2
- package/build/image-editor/core/types.cjs.map +1 -1
- package/build/image-editor/index.cjs +12 -2
- package/build/image-editor/index.cjs.map +2 -2
- package/build/image-editor/react/components/cropper-provider.cjs +2 -2
- package/build/image-editor/react/components/cropper-provider.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs +121 -48
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +172 -0
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +20 -10
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +71 -0
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +7 -0
- package/build/image-editor/react/hooks/index.cjs +6 -3
- package/build/image-editor/react/hooks/index.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +3 -1
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +113 -0
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +7 -0
- 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 +115 -0
- package/build/state/composite-reducer.cjs.map +7 -0
- package/build/state/index.cjs +48 -0
- package/build/state/index.cjs.map +7 -0
- package/build/state/media-editor-state-provider.cjs +58 -0
- package/build/state/media-editor-state-provider.cjs.map +7 -0
- package/build/state/types.cjs +34 -0
- package/build/state/types.cjs.map +7 -0
- package/build/state/use-media-editor-state.cjs +298 -0
- package/build/state/use-media-editor-state.cjs.map +7 -0
- package/build-module/components/media-editor/index.mjs +40 -140
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-crop-options.mjs +61 -0
- package/build-module/components/media-editor/use-crop-options.mjs.map +7 -0
- package/build-module/components/media-editor/use-save-media-editor.mjs +151 -0
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +33 -12
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +68 -83
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-modal/index.mjs +40 -11
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-toolbar/index.mjs +7 -3
- package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
- package/build-module/components/media-form/index.mjs +9 -1
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/media-form/sidebar-datetime-view.mjs +32 -0
- package/build-module/components/media-form/sidebar-datetime-view.mjs.map +7 -0
- package/build-module/components/rotation-ruler/index.mjs +8 -2
- package/build-module/components/rotation-ruler/index.mjs.map +2 -2
- package/build-module/hooks/use-crop-gesture-handlers.mjs +41 -4
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
- package/build-module/image-editor/core/camera.mjs +34 -11
- package/build-module/image-editor/core/camera.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs +4 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs +75 -34
- package/build-module/image-editor/core/containment.mjs.map +2 -2
- package/build-module/image-editor/core/crop-rect.mjs +23 -0
- package/build-module/image-editor/core/crop-rect.mjs.map +7 -0
- package/build-module/image-editor/core/index.mjs +12 -0
- package/build-module/image-editor/core/index.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/math/sanitize.mjs +63 -0
- package/build-module/image-editor/core/math/sanitize.mjs.map +7 -0
- package/build-module/image-editor/core/setter-helpers.mjs +39 -0
- package/build-module/image-editor/core/setter-helpers.mjs.map +7 -0
- package/build-module/image-editor/core/source-region.mjs +16 -14
- package/build-module/image-editor/core/source-region.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs +25 -11
- package/build-module/image-editor/core/state.mjs.map +2 -2
- package/build-module/image-editor/core/stencil-math.mjs +30 -19
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs +12 -6
- package/build-module/image-editor/core/transform-style.mjs.map +2 -2
- package/build-module/image-editor/index.mjs +11 -2
- package/build-module/image-editor/index.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper-provider.mjs +3 -3
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +122 -49
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +147 -0
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +20 -10
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +46 -0
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/index.mjs +4 -2
- package/build-module/image-editor/react/hooks/index.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +3 -1
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +100 -0
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +7 -0
- 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 +94 -0
- package/build-module/state/composite-reducer.mjs.map +7 -0
- package/build-module/state/index.mjs +26 -0
- package/build-module/state/index.mjs.map +7 -0
- package/build-module/state/media-editor-state-provider.mjs +34 -0
- package/build-module/state/media-editor-state-provider.mjs.map +7 -0
- package/build-module/state/types.mjs +9 -0
- package/build-module/state/types.mjs.map +7 -0
- package/build-module/state/use-media-editor-state.mjs +289 -0
- package/build-module/state/use-media-editor-state.mjs.map +7 -0
- package/build-style/style-rtl.css +46 -9
- package/build-style/style.css +46 -9
- package/build-types/components/media-editor/index.d.ts +4 -7
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +37 -0
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -0
- package/build-types/components/media-editor/use-save-media-editor.d.ts +29 -0
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -0
- package/build-types/components/media-editor-canvas/index.d.ts +5 -10
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +4 -16
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-form/sidebar-datetime-view.d.ts +10 -0
- package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
- package/build-types/hooks/use-crop-gesture-handlers.d.ts +13 -14
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +18 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/containment.d.ts +10 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -1
- package/build-types/image-editor/core/crop-rect.d.ts +19 -0
- package/build-types/image-editor/core/crop-rect.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +3 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +5 -1
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +70 -0
- package/build-types/image-editor/core/math/sanitize.d.ts.map +1 -0
- package/build-types/image-editor/core/setter-helpers.d.ts +24 -0
- package/build-types/image-editor/core/setter-helpers.d.ts.map +1 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -1
- package/build-types/image-editor/core/state.d.ts +12 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts +23 -18
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -1
- package/build-types/image-editor/core/types.d.ts +23 -4
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/index.d.ts +4 -4
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +11 -7
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +6 -4
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +36 -0
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +2 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +47 -0
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/index.d.ts +4 -2
- package/build-types/image-editor/react/hooks/index.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-cropper-reducer.d.ts +58 -0
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +39 -0
- package/build-types/state/composite-reducer.d.ts.map +1 -0
- package/build-types/state/index.d.ts +7 -0
- package/build-types/state/index.d.ts.map +1 -0
- package/build-types/state/media-editor-state-provider.d.ts +34 -0
- package/build-types/state/media-editor-state-provider.d.ts.map +1 -0
- package/build-types/state/types.d.ts +104 -0
- package/build-types/state/types.d.ts.map +1 -0
- package/build-types/state/use-media-editor-state.d.ts +104 -0
- package/build-types/state/use-media-editor-state.d.ts.map +1 -0
- package/package.json +19 -17
- package/src/components/media-editor/index.tsx +52 -188
- package/src/components/media-editor/test/use-crop-options.tsx +164 -0
- package/src/components/media-editor/use-crop-options.ts +115 -0
- package/src/components/media-editor/use-save-media-editor.ts +214 -0
- package/src/components/media-editor-canvas/index.tsx +56 -24
- package/src/components/media-editor-crop-panel/index.tsx +25 -61
- package/src/components/media-editor-crop-panel/test/index.tsx +17 -43
- package/src/components/media-editor-modal/index.tsx +50 -12
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +14 -0
- package/src/components/media-editor-modal/test/index.tsx +143 -0
- package/src/components/media-editor-toolbar/index.tsx +9 -5
- package/src/components/media-form/index.tsx +15 -1
- package/src/components/media-form/sidebar-datetime-view.tsx +47 -0
- package/src/components/media-form/test/sidebar-datetime-view.test.tsx +96 -0
- package/src/components/rotation-ruler/README.md +11 -25
- package/src/components/rotation-ruler/index.tsx +17 -2
- package/src/components/rotation-ruler/style.scss +49 -13
- package/src/hooks/use-crop-gesture-handlers.ts +66 -17
- package/src/image-editor/README.md +28 -129
- package/src/image-editor/core/camera.ts +51 -26
- package/src/image-editor/core/constants.ts +19 -0
- package/src/image-editor/core/containment.ts +102 -49
- package/src/image-editor/core/crop-rect.ts +45 -0
- package/src/image-editor/core/index.ts +16 -4
- package/src/image-editor/core/interaction-controller.ts +5 -1
- package/src/image-editor/core/math/sanitize.ts +158 -0
- package/src/image-editor/core/math/test/sanitize.ts +244 -0
- package/src/image-editor/core/setter-helpers.ts +66 -0
- package/src/image-editor/core/source-region.ts +21 -14
- package/src/image-editor/core/state.ts +67 -15
- package/src/image-editor/core/stencil-math.ts +55 -35
- package/src/image-editor/core/test/camera.ts +367 -1
- package/src/image-editor/core/test/state.ts +101 -8
- package/src/image-editor/core/test/stencil-math.ts +193 -0
- package/src/image-editor/core/transform-style.ts +21 -6
- package/src/image-editor/core/types.ts +24 -4
- package/src/image-editor/docs/architecture.md +48 -89
- package/src/image-editor/docs/recipes.md +123 -659
- package/src/image-editor/index.ts +12 -3
- package/src/image-editor/react/components/cropper-provider.tsx +16 -12
- package/src/image-editor/react/components/cropper.scss +23 -4
- package/src/image-editor/react/components/cropper.tsx +197 -90
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +269 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +22 -9
- package/src/image-editor/react/components/test/cropper.tsx +55 -13
- package/src/image-editor/react/hooks/build-cropper-setters.ts +105 -0
- package/src/image-editor/react/hooks/index.ts +4 -2
- package/src/image-editor/react/hooks/test/{use-cropper-state.ts → use-cropper-reducer.ts} +142 -286
- package/src/image-editor/react/hooks/use-aria-announcer.ts +3 -1
- package/src/image-editor/react/hooks/use-cropper-reducer.ts +204 -0
- package/src/image-editor/react/hooks/use-interaction.ts +3 -2
- package/src/image-editor/stories/rectangle-crop.story.tsx +7 -17
- package/src/state/composite-reducer.ts +152 -0
- package/src/state/index.ts +20 -0
- package/src/state/media-editor-state-provider.tsx +70 -0
- package/src/state/test/use-media-editor-state.ts +402 -0
- package/src/state/types.ts +107 -0
- package/src/state/use-media-editor-state.ts +488 -0
- package/tsconfig.json +2 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/image-editor/react/hooks/use-cropper-state.cjs +0 -277
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +0 -262
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -97
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
- package/src/image-editor/docs/roadmap.md +0 -66
- package/src/image-editor/react/hooks/use-cropper-state.ts +0 -457
|
@@ -6,102 +6,87 @@ import {
|
|
|
6
6
|
} from "@wordpress/components";
|
|
7
7
|
import { Stack, VisuallyHidden } from "@wordpress/ui";
|
|
8
8
|
import { __, sprintf } from "@wordpress/i18n";
|
|
9
|
-
import {
|
|
10
|
-
import { useCropGestureHandlers } from "../../hooks/use-crop-gesture-handlers.mjs";
|
|
9
|
+
import { useMediaEditor } from "../../state/index.mjs";
|
|
11
10
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from "../../image-editor/core/
|
|
11
|
+
useCropGestureHandlers,
|
|
12
|
+
CROP_CONTROL_ATTR
|
|
13
|
+
} from "../../hooks/use-crop-gesture-handlers.mjs";
|
|
14
|
+
import { MAX_ZOOM } from "../../image-editor/core/constants.mjs";
|
|
15
|
+
import { getMinZoom } from "../../image-editor/core/containment.mjs";
|
|
17
16
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
18
|
-
function resolveAspectRatio(value, imageAspectRatio) {
|
|
19
|
-
const num = parseFloat(value);
|
|
20
|
-
if (num === 0) {
|
|
21
|
-
return void 0;
|
|
22
|
-
}
|
|
23
|
-
if (num === ORIGINAL_ASPECT_RATIO && imageAspectRatio) {
|
|
24
|
-
return imageAspectRatio;
|
|
25
|
-
}
|
|
26
|
-
if (num > 0) {
|
|
27
|
-
return num;
|
|
28
|
-
}
|
|
29
|
-
return void 0;
|
|
30
|
-
}
|
|
31
17
|
function MediaEditorCropPanel({
|
|
32
18
|
aspectRatioValue,
|
|
33
19
|
onAspectRatioChange,
|
|
34
20
|
freeformCrop,
|
|
35
21
|
onFreeformChange,
|
|
36
22
|
onPlacementControlInteraction,
|
|
37
|
-
|
|
23
|
+
aspectRatioOptions
|
|
38
24
|
}) {
|
|
39
|
-
const { state, setZoom } =
|
|
25
|
+
const { state, setZoom } = useMediaEditor();
|
|
40
26
|
const zoomGestureHandlers = useCropGestureHandlers();
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
onFreeformChange(true);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
return /* @__PURE__ */ jsxs(Stack, { direction: "column", gap: "md", children: [
|
|
52
|
-
/* @__PURE__ */ jsx(VisuallyHidden, { render: /* @__PURE__ */ jsx("h2", {}), children: __("Crop options") }),
|
|
53
|
-
/* @__PURE__ */ jsx(
|
|
54
|
-
SelectControl,
|
|
55
|
-
{
|
|
56
|
-
__next40pxDefaultSize: true,
|
|
57
|
-
__nextHasNoMarginBottom: true,
|
|
58
|
-
label: __("Aspect ratio"),
|
|
59
|
-
value: aspectRatioValue,
|
|
60
|
-
onChange: handleAspectRatioChange,
|
|
61
|
-
options: aspectRatioOptions.map((preset) => ({
|
|
62
|
-
label: preset.label,
|
|
63
|
-
value: preset.value.toString()
|
|
64
|
-
}))
|
|
65
|
-
}
|
|
66
|
-
),
|
|
67
|
-
/* @__PURE__ */ jsx(
|
|
68
|
-
ToggleControl,
|
|
69
|
-
{
|
|
70
|
-
__nextHasNoMarginBottom: true,
|
|
71
|
-
label: __("Resize crop area"),
|
|
72
|
-
help: __("Show handles to adjust the crop box."),
|
|
73
|
-
checked: freeformCrop,
|
|
74
|
-
onChange: onFreeformChange
|
|
75
|
-
}
|
|
76
|
-
),
|
|
77
|
-
/* @__PURE__ */ jsx("div", { role: "presentation", ...zoomGestureHandlers, children: /* @__PURE__ */ jsx(
|
|
78
|
-
RangeControl,
|
|
27
|
+
const minZoom = getMinZoom(state);
|
|
28
|
+
return (
|
|
29
|
+
// Tag the whole panel as a crop-control region so the modal's
|
|
30
|
+
// Cmd+Z handler doesn't mistake the SelectControl / ToggleControl
|
|
31
|
+
// inputs for metadata fields (which would suppress undo).
|
|
32
|
+
/* @__PURE__ */ jsxs(
|
|
33
|
+
Stack,
|
|
79
34
|
{
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)
|
|
98
|
-
|
|
35
|
+
direction: "column",
|
|
36
|
+
gap: "md",
|
|
37
|
+
...{ [CROP_CONTROL_ATTR]: true },
|
|
38
|
+
children: [
|
|
39
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { render: /* @__PURE__ */ jsx("h2", {}), children: __("Crop options") }),
|
|
40
|
+
/* @__PURE__ */ jsx(
|
|
41
|
+
SelectControl,
|
|
42
|
+
{
|
|
43
|
+
__next40pxDefaultSize: true,
|
|
44
|
+
label: __("Aspect ratio"),
|
|
45
|
+
value: aspectRatioValue,
|
|
46
|
+
onChange: onAspectRatioChange,
|
|
47
|
+
options: aspectRatioOptions.map((preset) => ({
|
|
48
|
+
label: preset.label,
|
|
49
|
+
value: preset.value.toString()
|
|
50
|
+
}))
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
/* @__PURE__ */ jsx(
|
|
54
|
+
ToggleControl,
|
|
55
|
+
{
|
|
56
|
+
label: __("Show resize handles"),
|
|
57
|
+
checked: freeformCrop,
|
|
58
|
+
onChange: onFreeformChange
|
|
59
|
+
}
|
|
60
|
+
),
|
|
61
|
+
/* @__PURE__ */ jsx("div", { role: "presentation", ...zoomGestureHandlers, children: /* @__PURE__ */ jsx(
|
|
62
|
+
RangeControl,
|
|
63
|
+
{
|
|
64
|
+
__next40pxDefaultSize: true,
|
|
65
|
+
label: __("Zoom"),
|
|
66
|
+
min: minZoom,
|
|
67
|
+
max: MAX_ZOOM,
|
|
68
|
+
step: 0.1,
|
|
69
|
+
value: state.zoom,
|
|
70
|
+
onChange: (value) => {
|
|
71
|
+
onPlacementControlInteraction?.();
|
|
72
|
+
setZoom(typeof value === "number" ? value : minZoom);
|
|
73
|
+
},
|
|
74
|
+
renderTooltipContent: (value) => {
|
|
75
|
+
const zoom = typeof value === "number" ? value : minZoom;
|
|
76
|
+
return sprintf(
|
|
77
|
+
/* translators: %d: zoom level as a percentage. */
|
|
78
|
+
__("%d%%"),
|
|
79
|
+
Math.round(zoom * 100)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
) })
|
|
84
|
+
]
|
|
99
85
|
}
|
|
100
|
-
)
|
|
101
|
-
|
|
86
|
+
)
|
|
87
|
+
);
|
|
102
88
|
}
|
|
103
89
|
export {
|
|
104
|
-
MediaEditorCropPanel as default
|
|
105
|
-
resolveAspectRatio
|
|
90
|
+
MediaEditorCropPanel as default
|
|
106
91
|
};
|
|
107
92
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -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 {\n\tRangeControl,\n\tSelectControl,\n\tToggleControl,\n} from '@wordpress/components';\nimport { Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,OAAO,sBAAsB;AACtC,SAAS,IAAI,eAAe;AAK5B,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tRangeControl,\n\tSelectControl,\n\tToggleControl,\n} 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\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/** Whether the cropper is in freeform (resize-handle) mode. */\n\tfreeformCrop: boolean;\n\t/** Setter for freeform mode. */\n\tonFreeformChange: ( value: boolean ) => 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 \u2014 aspect-ratio presets and\n * freeform toggle. The tactile verbs (rotate, flip) live in the\n * bottom toolbar instead.\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.freeformCrop\n * @param props.onFreeformChange\n * @param props.onPlacementControlInteraction\n * @param props.aspectRatioOptions\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\tfreeformCrop,\n\tonFreeformChange,\n\tonPlacementControlInteraction,\n\taspectRatioOptions,\n}: MediaEditorCropPanelProps ) {\n\tconst { state, setZoom } = useMediaEditor();\n\tconst zoomGestureHandlers = useCropGestureHandlers();\n\tconst minZoom = getMinZoom( state );\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 / ToggleControl\n\t\t// inputs for metadata fields (which would suppress undo).\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"md\"\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<ToggleControl\n\t\t\t\tlabel={ __( 'Show resize handles' ) }\n\t\t\t\tchecked={ freeformCrop }\n\t\t\t\tonChange={ onFreeformChange }\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={ minZoom }\n\t\t\t\t\tmax={ MAX_ZOOM }\n\t\t\t\t\tstep={ 0.1 }\n\t\t\t\t\tvalue={ state.zoom }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tonPlacementControlInteraction?.();\n\t\t\t\t\t\tsetZoom( typeof value === 'number' ? value : minZoom );\n\t\t\t\t\t} }\n\t\t\t\t\trenderTooltipContent={ ( value ) => {\n\t\t\t\t\t\tconst zoom =\n\t\t\t\t\t\t\ttypeof value === 'number' ? value : minZoom;\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( zoom * 100 )\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;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,OAAO,sBAAsB;AACtC,SAAS,IAAI,eAAe;AAK5B,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAkDzB,SAK0B,KAL1B;AAhBa,SAAR,qBAAuC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA+B;AAC9B,QAAM,EAAE,OAAO,QAAQ,IAAI,eAAe;AAC1C,QAAM,sBAAsB,uBAAuB;AACnD,QAAM,UAAU,WAAY,KAAM;AAElC;AAAA;AAAA;AAAA;AAAA,IAIC;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,KAAI;AAAA,QACF,GAAG,EAAE,CAAE,iBAAkB,GAAG,KAAK;AAAA,QAEnC;AAAA,8BAAC,kBAAe,QAAS,oBAAC,QAAG,GAC1B,aAAI,cAAe,GACtB;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,OAAQ,GAAI,cAAe;AAAA,cAC3B,OAAQ;AAAA,cACR,UAAW;AAAA,cACX,SAAU,mBAAmB,IAAK,CAAE,YAAc;AAAA,gBACjD,OAAO,OAAO;AAAA,gBACd,OAAO,OAAO,MAAM,SAAS;AAAA,cAC9B,EAAI;AAAA;AAAA,UACL;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,OAAQ,GAAI,qBAAsB;AAAA,cAClC,SAAU;AAAA,cACV,UAAW;AAAA;AAAA,UACZ;AAAA,UACA,oBAAC,SAAI,MAAK,gBAAiB,GAAG,qBAC7B;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,OAAQ,GAAI,MAAO;AAAA,cACnB,KAAM;AAAA,cACN,KAAM;AAAA,cACN,MAAO;AAAA,cACP,OAAQ,MAAM;AAAA,cACd,UAAW,CAAE,UAAW;AACvB,gDAAgC;AAChC,wBAAS,OAAO,UAAU,WAAW,QAAQ,OAAQ;AAAA,cACtD;AAAA,cACA,sBAAuB,CAAE,UAAW;AACnC,sBAAM,OACL,OAAO,UAAU,WAAW,QAAQ;AACrC,uBAAO;AAAA;AAAA,kBAEN,GAAI,MAAO;AAAA,kBACX,KAAK,MAAO,OAAO,GAAI;AAAA,gBACxB;AAAA,cACD;AAAA;AAAA,UACD,GACD;AAAA;AAAA;AAAA,IACD;AAAA;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { Modal } from "@wordpress/components";
|
|
3
3
|
import { useDispatch, useSelect } from "@wordpress/data";
|
|
4
4
|
import { __ } from "@wordpress/i18n";
|
|
5
|
+
import { ShortcutProvider } from "@wordpress/keyboard-shortcuts";
|
|
6
|
+
import { store as noticesStore } from "@wordpress/notices";
|
|
5
7
|
import MediaEditor from "../media-editor/index.mjs";
|
|
6
8
|
import { store as mediaEditorStore } from "../../store/index.mjs";
|
|
7
9
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -18,10 +20,14 @@ function MediaEditorModal({
|
|
|
18
20
|
};
|
|
19
21
|
}, []);
|
|
20
22
|
const { closeMediaEditorModal } = useDispatch(mediaEditorStore);
|
|
23
|
+
const { createSuccessNotice } = useDispatch(noticesStore);
|
|
21
24
|
if (!isModalOpen || !id) {
|
|
22
25
|
return null;
|
|
23
26
|
}
|
|
24
27
|
const portalElement = typeof document === "undefined" ? null : document.body;
|
|
28
|
+
const stopKeyDownPropagation = (event) => {
|
|
29
|
+
event.stopPropagation();
|
|
30
|
+
};
|
|
25
31
|
return /* @__PURE__ */ jsx(
|
|
26
32
|
MediaEditor,
|
|
27
33
|
{
|
|
@@ -33,7 +39,7 @@ function MediaEditorModal({
|
|
|
33
39
|
noticesClassName: "media-editor-modal__snackbar",
|
|
34
40
|
noticesPortalElement: portalElement,
|
|
35
41
|
onClose: closeMediaEditorModal,
|
|
36
|
-
onSaved: ({ id: savedId, url }) => {
|
|
42
|
+
onSaved: ({ id: savedId, url, previous }) => {
|
|
37
43
|
if (savedId && onUpdate) {
|
|
38
44
|
const update = {
|
|
39
45
|
id: savedId,
|
|
@@ -42,6 +48,22 @@ function MediaEditorModal({
|
|
|
42
48
|
onUpdate(update);
|
|
43
49
|
}
|
|
44
50
|
closeMediaEditorModal();
|
|
51
|
+
if (previous && savedId !== previous.id && onUpdate) {
|
|
52
|
+
createSuccessNotice(__("Image edited."), {
|
|
53
|
+
type: "snackbar",
|
|
54
|
+
actions: [
|
|
55
|
+
{
|
|
56
|
+
label: __("Undo"),
|
|
57
|
+
onClick: () => {
|
|
58
|
+
onUpdate({
|
|
59
|
+
id: previous.id,
|
|
60
|
+
url: previous.url
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
45
67
|
},
|
|
46
68
|
renderFrame: ({
|
|
47
69
|
children,
|
|
@@ -50,17 +72,24 @@ function MediaEditorModal({
|
|
|
50
72
|
onKeyDown,
|
|
51
73
|
shouldCloseOnClickOutside
|
|
52
74
|
}) => /* @__PURE__ */ jsx(
|
|
53
|
-
|
|
75
|
+
ShortcutProvider,
|
|
54
76
|
{
|
|
55
|
-
className: "media-editor-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
className: "media-editor-modal__shortcut-scope",
|
|
78
|
+
onKeyDown: stopKeyDownPropagation,
|
|
79
|
+
children: /* @__PURE__ */ jsx(
|
|
80
|
+
Modal,
|
|
81
|
+
{
|
|
82
|
+
className: "media-editor-modal",
|
|
83
|
+
title: __("Edit media"),
|
|
84
|
+
size: "fill",
|
|
85
|
+
isDismissible: false,
|
|
86
|
+
shouldCloseOnClickOutside,
|
|
87
|
+
onKeyDown,
|
|
88
|
+
onRequestClose,
|
|
89
|
+
headerActions,
|
|
90
|
+
children
|
|
91
|
+
}
|
|
92
|
+
)
|
|
64
93
|
}
|
|
65
94
|
)
|
|
66
95
|
}
|
|
@@ -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 type { Field } from '@wordpress/dataviews';\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 } = select( mediaEditorStore );\n\t\treturn {\n\t\t\tisModalOpen: isOpen(),\n\t\t\tid: getId(),\n\t\t\tonUpdate: getOnUpdate(),\n\t\t};\n\t}, [] );\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\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\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={ closeMediaEditorModal }\n\t\t\tonSaved={ ( { id: savedId, url } ) => {\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\tcloseMediaEditorModal();\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\theaderActions,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<Modal\n\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\theaderActions={ headerActions }\n\t\t\t\t>\n\t\t\t\t\t{ children }\n\t\t\t\t</Modal>\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;
|
|
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 } = select( mediaEditorStore );\n\t\treturn {\n\t\t\tisModalOpen: isOpen(),\n\t\t\tid: getId(),\n\t\t\tonUpdate: getOnUpdate(),\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\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={ closeMediaEditorModal }\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\tcloseMediaEditorModal();\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\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</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;AAsGrC;AAnFE,SAAS,iBAAkB;AAAA,EACjC,SAAS,CAAC;AAAA,EACV;AACD,GAA2B;AAC1B,QAAM,EAAE,aAAa,IAAI,SAAS,IAAI,UAAW,CAAE,WAAY;AAC9D,UAAM,EAAE,QAAQ,OAAO,YAAY,IAAI,OAAQ,gBAAiB;AAChE,WAAO;AAAA,MACN,aAAa,OAAO;AAAA,MACpB,IAAI,MAAM;AAAA,MACV,UAAU,YAAY;AAAA,IACvB;AAAA,EAC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B;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cAEE;AAAA;AAAA,UACH;AAAA;AAAA,MACD;AAAA;AAAA,EAEF;AAEF;AAEA,IAAO,6BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
undo,
|
|
12
12
|
redo
|
|
13
13
|
} from "@wordpress/icons";
|
|
14
|
-
import {
|
|
14
|
+
import { useMediaEditor } from "../../state/index.mjs";
|
|
15
15
|
import { useCropGestureHandlers } from "../../hooks/use-crop-gesture-handlers.mjs";
|
|
16
16
|
import { MAX_ROTATION_OFFSET } from "../../image-editor/core/constants.mjs";
|
|
17
17
|
import RotationRuler from "../rotation-ruler/index.mjs";
|
|
@@ -31,14 +31,18 @@ function MediaEditorToolbar({
|
|
|
31
31
|
hasUndo,
|
|
32
32
|
hasRedo,
|
|
33
33
|
undo: undoCrop,
|
|
34
|
-
redo: redoCrop
|
|
35
|
-
|
|
34
|
+
redo: redoCrop,
|
|
35
|
+
beginGesture,
|
|
36
|
+
endGesture
|
|
37
|
+
} = useMediaEditor();
|
|
36
38
|
const rotationGestureHandlers = useCropGestureHandlers({
|
|
37
39
|
commitOnKeyUp: false
|
|
38
40
|
});
|
|
39
41
|
const handleReset = () => {
|
|
42
|
+
beginGesture();
|
|
40
43
|
reset();
|
|
41
44
|
onReset?.();
|
|
45
|
+
endGesture();
|
|
42
46
|
};
|
|
43
47
|
const handleUndo = () => {
|
|
44
48
|
if (isUndoRedoDisabled) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor-toolbar/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { displayShortcut, isAppleOS } from '@wordpress/keycodes';\nimport {\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tundo,\n\tredo,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";AAGA,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,SAAS,UAAU;AACnB,SAAS,iBAAiB,iBAAiB;AAC3C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { displayShortcut, isAppleOS } from '@wordpress/keycodes';\nimport {\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tundo,\n\tredo,\n} from '@wordpress/icons';\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 MediaEditorToolbarProps {\n\t/**\n\t * Extra work to run when the user clicks Reset \u2014 e.g. clearing\n\t * aspect-ratio / freeform state that lives outside the cropper\n\t * controller.\n\t */\n\tonReset?: () => void;\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/** Whether undo/redo should be unavailable during an active gesture. */\n\tisUndoRedoDisabled?: boolean;\n}\n\n/**\n * Toolbar for the media editor modal. Hosts the tactile cropper verbs \u2014\n * rotate, flip, fine rotation, reset \u2014 so they stay within thumb reach\n * when the toolbar sits at the bottom of the modal. Aspect-ratio presets\n * and freeform toggle live in the Crop sidebar tab instead.\n * @param props\n * @param props.onReset\n * @param props.onPlacementControlInteraction\n * @param props.isUndoRedoDisabled\n */\nexport default function MediaEditorToolbar( {\n\tonReset,\n\tonPlacementControlInteraction,\n\tisUndoRedoDisabled = false,\n}: MediaEditorToolbarProps ) {\n\tconst {\n\t\tstate,\n\t\tsetRotation,\n\t\tsetFlip,\n\t\tsnapRotate90,\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t\tbeginGesture,\n\t\tendGesture,\n\t} = useMediaEditor();\n\t// `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\tconst handleReset = () => {\n\t\tbeginGesture();\n\t\treset();\n\t\tonReset?.();\n\t\tendGesture();\n\t};\n\tconst handleUndo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tundoCrop();\n\t};\n\tconst handleRedo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tredoCrop();\n\t};\n\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<Stack\n\t\t\tclassName=\"media-editor-toolbar\"\n\t\t\tdirection=\"row\"\n\t\t\talign=\"center\"\n\t\t\tjustify=\"center\"\n\t\t\tgap=\"sm\"\n\t\t\twrap=\"wrap\"\n\t\t>\n\t\t\t<div\n\t\t\t\trole=\"presentation\"\n\t\t\t\tclassName=\"media-editor-toolbar__rotation-slider\"\n\t\t\t\t{ ...rotationGestureHandlers }\n\t\t\t>\n\t\t\t\t<RotationRuler\n\t\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\t\tvalue={ fineOffset }\n\t\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div className=\"media-editor-toolbar__action-cluster\">\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ rotateLeft }\n\t\t\t\t\tlabel={ __( 'Rotate 90\u00B0 counter-clockwise' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ rotateRight }\n\t\t\t\t\tlabel={ __( 'Rotate 90\u00B0 clockwise' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ flipHorizontal }\n\t\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ flipVertical }\n\t\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ undo }\n\t\t\t\t\tlabel={ __( 'Undo' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tshortcut={ displayShortcut.primary( 'z' ) }\n\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasUndo }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleUndo }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ redo }\n\t\t\t\t\tlabel={ __( 'Redo' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tshortcut={\n\t\t\t\t\t\tisAppleOS()\n\t\t\t\t\t\t\t? displayShortcut.primaryShift( 'z' )\n\t\t\t\t\t\t\t: displayShortcut.primary( 'y' )\n\t\t\t\t\t}\n\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasRedo }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleRedo }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tdisabled={ ! isDirty }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleReset }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</Button>\n\t\t\t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cACvB,SAAU,MACT,QAAS;AAAA,gBACR,YAAY,MAAM,KAAK;AAAA,gBACvB,UAAU,CAAE,MAAM,KAAK;AAAA,cACxB,CAAE;AAAA;AAAA,UAEJ;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,MAAO;AAAA,cACP,OAAQ,GAAI,MAAO;AAAA,cACnB,aAAW;AAAA,cACX,UAAW,gBAAgB,QAAS,GAAI;AAAA,cACxC,UAAW,sBAAsB,CAAE;AAAA,cACnC,wBAAsB;AAAA,cACtB,SAAU;AAAA;AAAA,UACX;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,MAAO;AAAA,cACP,OAAQ,GAAI,MAAO;AAAA,cACnB,aAAW;AAAA,cACX,UACC,UAAU,IACP,gBAAgB,aAAc,GAAI,IAClC,gBAAgB,QAAS,GAAI;AAAA,cAEjC,UAAW,sBAAsB,CAAE;AAAA,cACnC,wBAAsB;AAAA,cACtB,SAAU;AAAA;AAAA,UACX;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,SAAQ;AAAA,cACR,UAAW,CAAE;AAAA,cACb,wBAAsB;AAAA,cACtB,SAAU;AAAA,cAER,aAAI,OAAQ;AAAA;AAAA,UACf;AAAA,WACD;AAAA;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,13 +3,21 @@ import { DataForm } from "@wordpress/dataviews";
|
|
|
3
3
|
import { Spinner, __experimentalVStack as VStack } from "@wordpress/components";
|
|
4
4
|
import { VisuallyHidden } from "@wordpress/ui";
|
|
5
5
|
import { __ } from "@wordpress/i18n";
|
|
6
|
+
import { useMemo } from "@wordpress/element";
|
|
6
7
|
import { useMediaEditorContext } from "../media-editor-provider/index.mjs";
|
|
8
|
+
import SidebarDatetimeView from "./sidebar-datetime-view.mjs";
|
|
7
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
10
|
function MediaForm({
|
|
9
11
|
form: formOverrides,
|
|
10
12
|
header
|
|
11
13
|
}) {
|
|
12
14
|
const { media, fields, onChange } = useMediaEditorContext();
|
|
15
|
+
const formFields = useMemo(
|
|
16
|
+
() => fields.map(
|
|
17
|
+
(field) => field.type === "datetime" && field.readOnly ? { ...field, render: SidebarDatetimeView } : field
|
|
18
|
+
),
|
|
19
|
+
[fields]
|
|
20
|
+
);
|
|
13
21
|
if (!media || !onChange) {
|
|
14
22
|
return /* @__PURE__ */ jsx("div", { className: "media-editor-form media-editor-form--loading", children: /* @__PURE__ */ jsx(Spinner, {}) });
|
|
15
23
|
}
|
|
@@ -40,7 +48,7 @@ function MediaForm({
|
|
|
40
48
|
DataForm,
|
|
41
49
|
{
|
|
42
50
|
data: media,
|
|
43
|
-
fields,
|
|
51
|
+
fields: formFields,
|
|
44
52
|
form,
|
|
45
53
|
onChange
|
|
46
54
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-form/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { DataForm } from '@wordpress/dataviews';\nimport type { Form, Field } from '@wordpress/dataviews';\nimport { Spinner, __experimentalVStack as VStack } from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst { media, fields, onChange } = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Default form structure with panel layout\n\tconst defaultForm: Form = {\n\t\tlayout: {\n\t\t\ttype: 'panel',\n\t\t},\n\t\tfields: fields.map( ( field: Field< Media > ) => {\n\t\t\t// Use regular layout for main editable fields\n\t\t\tif (\n\t\t\t\t[ 'title', 'alt_text', 'caption', 'description' ].includes(\n\t\t\t\t\tfield.id\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\tid: field.id,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'regular',\n\t\t\t\t\t\tlabelPosition: 'top',\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn field.id;\n\t\t} ),\n\t};\n\n\tconst form = formOverrides || defaultForm;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={
|
|
5
|
-
"mappings": ";AAGA,SAAS,gBAAgB;AAEzB,SAAS,SAAS,wBAAwB,cAAc;AACxD,SAAS,sBAAsB;AAC/B,SAAS,UAAU;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { DataForm } from '@wordpress/dataviews';\nimport type { Form, Field } from '@wordpress/dataviews';\nimport { Spinner, __experimentalVStack as VStack } from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport type { ReactNode } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\nimport SidebarDatetimeView from './sidebar-datetime-view';\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst { media, fields, onChange } = useMediaEditorContext();\n\n\t// Render readonly datetime fields compactly in the sidebar: date only,\n\t// with the full datetime exposed on hover via Tooltip and `title`.\n\tconst formFields = useMemo(\n\t\t() =>\n\t\t\tfields.map( ( field: Field< Media > ) =>\n\t\t\t\tfield.type === 'datetime' && field.readOnly\n\t\t\t\t\t? { ...field, render: SidebarDatetimeView }\n\t\t\t\t\t: field\n\t\t\t),\n\t\t[ fields ]\n\t);\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Default form structure with panel layout\n\tconst defaultForm: Form = {\n\t\tlayout: {\n\t\t\ttype: 'panel',\n\t\t},\n\t\tfields: fields.map( ( field: Field< Media > ) => {\n\t\t\t// Use regular layout for main editable fields\n\t\t\tif (\n\t\t\t\t[ 'title', 'alt_text', 'caption', 'description' ].includes(\n\t\t\t\t\tfield.id\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\tid: field.id,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'regular',\n\t\t\t\t\t\tlabelPosition: 'top',\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn field.id;\n\t\t} ),\n\t};\n\n\tconst form = formOverrides || defaultForm;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ formFields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,gBAAgB;AAEzB,SAAS,SAAS,wBAAwB,cAAc;AACxD,SAAS,sBAAsB;AAC/B,SAAS,UAAU;AACnB,SAAS,eAAe;AAMxB,SAAS,6BAA6B;AAEtC,OAAO,yBAAyB;AA0C5B,cAiCD,YAjCC;AArBW,SAAR,UAA4B;AAAA,EAClC,MAAM;AAAA,EACN;AACD,GAAoB;AACnB,QAAM,EAAE,OAAO,QAAQ,SAAS,IAAI,sBAAsB;AAI1D,QAAM,aAAa;AAAA,IAClB,MACC,OAAO;AAAA,MAAK,CAAE,UACb,MAAM,SAAS,cAAc,MAAM,WAChC,EAAE,GAAG,OAAO,QAAQ,oBAAoB,IACxC;AAAA,IACJ;AAAA,IACD,CAAE,MAAO;AAAA,EACV;AAEA,MAAK,CAAE,SAAS,CAAE,UAAW;AAC5B,WACC,oBAAC,SAAI,WAAU,gDACd,8BAAC,WAAQ,GACV;AAAA,EAEF;AAGA,QAAM,cAAoB;AAAA,IACzB,QAAQ;AAAA,MACP,MAAM;AAAA,IACP;AAAA,IACA,QAAQ,OAAO,IAAK,CAAE,UAA2B;AAEhD,UACC,CAAE,SAAS,YAAY,WAAW,aAAc,EAAE;AAAA,QACjD,MAAM;AAAA,MACP,GACC;AACD,eAAO;AAAA,UACN,IAAI,MAAM;AAAA,UACV,QAAQ;AAAA,YACP,MAAM;AAAA,YACN,eAAe;AAAA,UAChB;AAAA,QACD;AAAA,MACD;AACA,aAAO,MAAM;AAAA,IACd,CAAE;AAAA,EACH;AAEA,QAAM,OAAO,iBAAiB;AAE9B,SACC,oBAAC,SAAI,WAAU,qBACd,+BAAC,UAAO,SAAU,GACjB;AAAA,wBAAC,kBAAe,QAAS,oBAAC,QAAG,GAC1B,aAAI,eAAgB,GACvB;AAAA,IACE;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP,QAAS;AAAA,QACT;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// packages/media-editor/src/components/media-form/sidebar-datetime-view.tsx
|
|
2
|
+
import { dateI18n, getDate, getSettings } from "@wordpress/date";
|
|
3
|
+
import { Tooltip as WCTooltip } from "@wordpress/components";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
function SidebarDatetimeView({
|
|
6
|
+
item,
|
|
7
|
+
field
|
|
8
|
+
}) {
|
|
9
|
+
const value = field.getValue({ item });
|
|
10
|
+
if (!value) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const settings = getSettings();
|
|
14
|
+
const dateOnly = dateI18n(settings.formats.date, getDate(value));
|
|
15
|
+
const fullDatetime = dateI18n(
|
|
16
|
+
settings.formats.datetimeAbbreviated,
|
|
17
|
+
getDate(value)
|
|
18
|
+
);
|
|
19
|
+
return /* @__PURE__ */ jsx(WCTooltip, { text: fullDatetime, placement: "top", children: /* @__PURE__ */ jsx(
|
|
20
|
+
"time",
|
|
21
|
+
{
|
|
22
|
+
dateTime: value,
|
|
23
|
+
"aria-label": fullDatetime,
|
|
24
|
+
tabIndex: -1,
|
|
25
|
+
children: dateOnly
|
|
26
|
+
}
|
|
27
|
+
) });
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
SidebarDatetimeView as default
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=sidebar-datetime-view.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/media-form/sidebar-datetime-view.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dateI18n, getDate, getSettings } from '@wordpress/date';\nimport { Tooltip as WCTooltip } from '@wordpress/components';\nimport type { NormalizedField } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { Media } from '../media-editor-provider';\n\nexport default function SidebarDatetimeView( {\n\titem,\n\tfield,\n}: {\n\titem: Media;\n\tfield: NormalizedField< Media >;\n} ) {\n\tconst value = field.getValue( { item } ) as string | null | undefined;\n\tif ( ! value ) {\n\t\treturn null;\n\t}\n\tconst settings = getSettings();\n\tconst dateOnly = dateI18n( settings.formats.date, getDate( value ) );\n\tconst fullDatetime = dateI18n(\n\t\tsettings.formats.datetimeAbbreviated,\n\t\tgetDate( value )\n\t);\n\t// `aria-label` makes assistive tech announce the full date (the visible\n\t// text is a shortened summary; `<time dateTime>` is for machines, not\n\t// announced by screen readers). `tabIndex={-1}` keeps the Tooltip anchor\n\t// out of the keyboard tab order \u2014 Ariakit's `useFocusable` preserves an\n\t// explicit `tabIndex` on non-natively-focusable elements rather than\n\t// defaulting it to `0`. The Tooltip remains available on mouse hover.\n\treturn (\n\t\t<WCTooltip text={ fullDatetime } placement=\"top\">\n\t\t\t<time\n\t\t\t\tdateTime={ value }\n\t\t\t\taria-label={ fullDatetime }\n\t\t\t\ttabIndex={ -1 }\n\t\t\t>\n\t\t\t\t{ dateOnly }\n\t\t\t</time>\n\t\t</WCTooltip>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU,SAAS,mBAAmB;AAC/C,SAAS,WAAW,iBAAiB;AAiClC;AAzBY,SAAR,oBAAsC;AAAA,EAC5C;AAAA,EACA;AACD,GAGI;AACH,QAAM,QAAQ,MAAM,SAAU,EAAE,KAAK,CAAE;AACvC,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AACA,QAAM,WAAW,YAAY;AAC7B,QAAM,WAAW,SAAU,SAAS,QAAQ,MAAM,QAAS,KAAM,CAAE;AACnE,QAAM,eAAe;AAAA,IACpB,SAAS,QAAQ;AAAA,IACjB,QAAS,KAAM;AAAA,EAChB;AAOA,SACC,oBAAC,aAAU,MAAO,cAAe,WAAU,OAC1C;AAAA,IAAC;AAAA;AAAA,MACA,UAAW;AAAA,MACX,cAAa;AAAA,MACb,UAAW;AAAA,MAET;AAAA;AAAA,EACH,GACD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -86,7 +86,9 @@ function RotationRuler(props) {
|
|
|
86
86
|
}, [value, pxPerUnit]);
|
|
87
87
|
const closestMajor = Math.round(value / MAJOR_INTERVAL) * MAJOR_INTERVAL;
|
|
88
88
|
const onMajor = Math.abs(value - closestMajor) < 0.01;
|
|
89
|
-
const
|
|
89
|
+
const numberText = onMajor ? `${closestMajor}` : formatValue(value);
|
|
90
|
+
const isNegative = numberText.startsWith("-");
|
|
91
|
+
const digits = isNegative ? numberText.slice(1) : numberText;
|
|
90
92
|
const majorTicks = ticks.filter((tick) => tick.kind === "major");
|
|
91
93
|
return /* @__PURE__ */ jsxs(
|
|
92
94
|
"div",
|
|
@@ -154,7 +156,11 @@ function RotationRuler(props) {
|
|
|
154
156
|
]
|
|
155
157
|
}
|
|
156
158
|
) }),
|
|
157
|
-
/* @__PURE__ */ jsx("div", { className: "rotation-ruler__active-label", "aria-hidden": "true", children:
|
|
159
|
+
/* @__PURE__ */ jsx("div", { className: "rotation-ruler__active-label", "aria-hidden": "true", children: /* @__PURE__ */ jsxs("span", { className: "rotation-ruler__active-label-number", children: [
|
|
160
|
+
isNegative && /* @__PURE__ */ jsx("span", { className: "rotation-ruler__active-label-sign", children: "-" }),
|
|
161
|
+
digits,
|
|
162
|
+
/* @__PURE__ */ jsx("span", { className: "rotation-ruler__active-label-unit", children: unit })
|
|
163
|
+
] }) }),
|
|
158
164
|
/* @__PURE__ */ jsx("div", { className: "rotation-ruler__pointer", "aria-hidden": "true" })
|
|
159
165
|
]
|
|
160
166
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/rotation-ruler/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useId, useMemo, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useRulerDrag, clampValue } from './use-ruler-drag';\n\nexport interface RotationRulerProps {\n\t/** Current value. */\n\tvalue: number;\n\t/** Called with the next value on each change. */\n\tonChange: ( value: number ) => void;\n\t/** Lower bound of the range. Default: -45. */\n\tmin?: number;\n\t/** Upper bound of the range. Default: 45. */\n\tmax?: number;\n\t/**\n\t * Value step for drag and keyboard arrows. Default: 1. Drag values\n\t * are quantized to multiples of `step`. Holding Shift during drag\n\t * or with arrow keys halves the step for precision adjustment.\n\t */\n\tstep?: number;\n\t/** Accessible label for the slider input. */\n\tlabel: string;\n\t/**\n\t * Unit suffix shown in the active label and `aria-valuetext`.\n\t * Default: `\u00B0`.\n\t */\n\tunit?: string;\n\t/** CSS pixels of pointer travel per `step`. Default: 6. */\n\tpixelsPerStep?: number;\n\t/** Optional extra class for the wrapper. */\n\tclassName?: string;\n\t/**\n\t * Optional id for the underlying input; auto-generated when\n\t * omitted.\n\t */\n\tid?: string;\n\t/** When true, ignores all input. */\n\tdisabled?: boolean;\n}\n\nconst STRIP_HEIGHT = 32;\nconst LABEL_BASELINE_Y = 11;\nconst MAJOR_INTERVAL = 15;\nconst TICK_HEIGHT_MINOR = 4;\nconst TICK_HEIGHT_MID = 8;\nconst TICK_HEIGHT_MAJOR = 14;\n\ntype TickKind = 'minor' | 'mid' | 'major';\ninterface Tick {\n\tvalue: number;\n\tkind: TickKind;\n\theight: number;\n}\n\n/**\n * Build the tick list for the ruler strip.\n *\n * @param min Lower bound of the ruler in value units.\n * @param max Upper bound of the ruler in value units.\n */\nfunction useTicks( min: number, max: number ): Tick[] {\n\treturn useMemo( () => {\n\t\tconst out: Tick[] = [];\n\t\tfor ( let v = Math.ceil( min ); v <= Math.floor( max ); v += 1 ) {\n\t\t\tlet kind: TickKind = 'minor';\n\t\t\tlet height = TICK_HEIGHT_MINOR;\n\t\t\tif ( v % 15 === 0 ) {\n\t\t\t\tkind = 'major';\n\t\t\t\theight = TICK_HEIGHT_MAJOR;\n\t\t\t} else if ( v % 5 === 0 ) {\n\t\t\t\tkind = 'mid';\n\t\t\t\theight = TICK_HEIGHT_MID;\n\t\t\t}\n\t\t\tout.push( { value: v, kind, height } );\n\t\t}\n\t\treturn out;\n\t}, [ min, max ] );\n}\n\n/**\n * Format a numeric ruler value for display, trimming a trailing `.0`.\n *\n * @param value Value to format.\n */\nfunction formatValue( value: number ): string {\n\tconst rounded = Math.round( value * 10 ) / 10;\n\treturn Number.isInteger( rounded )\n\t\t? rounded.toFixed( 0 )\n\t\t: rounded.toFixed( 1 );\n}\n\n/**\n * Horizontal \"scrub-the-ruler\" slider for fine-grained numeric input\n * such as rotation in degrees.\n *\n * Renders a visually hidden `<input type=\"range\">` for assistive\n * technologies and keyboard input alongside a decorative tick strip\n * that the user can drag with a pointer.\n *\n * @param props Component props. See `RotationRulerProps`.\n */\nexport default function RotationRuler( props: RotationRulerProps ) {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin = -45,\n\t\tmax = 45,\n\t\tstep = 1,\n\t\tlabel,\n\t\tunit = '\u00B0',\n\t\tpixelsPerStep = 6,\n\t\tclassName,\n\t\tid,\n\t\tdisabled = false,\n\t} = props;\n\tconst inputRef = useRef< HTMLInputElement >( null );\n\tconst generatedId = useId();\n\tconst inputId = id ?? generatedId;\n\n\tconst dragHandlers = useRulerDrag( {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart: () => inputRef.current?.focus(),\n\t} );\n\n\tconst handleKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\t// WAI-ARIA slider keyboard pattern: Up/Right increment,\n\t\t// Down/Left decrement. Home / End / PageUp / PageDown fall\n\t\t// through to native input.\n\t\tconst isIncrement =\n\t\t\tevent.key === 'ArrowRight' || event.key === 'ArrowUp';\n\t\tconst isDecrement =\n\t\t\tevent.key === 'ArrowLeft' || event.key === 'ArrowDown';\n\t\tif ( ! isIncrement && ! isDecrement ) {\n\t\t\treturn;\n\t\t}\n\t\t// Always prevent default so the native input's own arrow-key\n\t\t// stepping doesn't double-fire `onChange` after our custom emit.\n\t\tevent.preventDefault();\n\t\tif ( disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst direction = isIncrement ? 1 : -1;\n\t\t// Shift halves the step for precision adjustment\n\t\t// (e.g. 0.5\u00B0 rotation when step is 1\u00B0). Same modifier works\n\t\t// on drag \u2014 see `useRulerDrag`.\n\t\tconst magnitude = event.shiftKey ? step / 2 : step;\n\t\tconst next = clampValue( value + direction * magnitude, min, max );\n\t\tif ( next !== value ) {\n\t\t\tonChange( next );\n\t\t}\n\t};\n\n\tconst display = `${ formatValue( value ) }${ unit }`;\n\tconst ticks = useTicks( min, max );\n\t// Visual scale is locked to the gesture: 1 step of pointer travel\n\t// (`pixelsPerStep`) maps to `step` value units, so 1 value unit\n\t// renders at `pixelsPerStep / step` CSS pixels. This keeps the\n\t// ticks moving in lock-step with the pointer no matter what the\n\t// caller chooses for `pixelsPerStep` and `step`.\n\tconst pxPerUnit = pixelsPerStep / step;\n\t// `left: 50%` puts the SVG's left edge at the strip's centerline, so\n\t// without an additional `-50%` self-offset all ticks would render to\n\t// the right of the pointer. Combine the centering offset with the\n\t// value-driven offset so value=0 lands the SVG's center on the\n\t// pointer.\n\tconst stripStyle: CSSProperties = useMemo( () => {\n\t\tconst offset = -value * pxPerUnit;\n\t\treturn {\n\t\t\ttransform: `translateX(calc(-50% + ${ offset }px))`,\n\t\t};\n\t}, [ value, pxPerUnit ] );\n\n\t// Closest major (every 15\u00B0) to current value. Its normal label is\n\t// suppressed and replaced by the active label, which sits exactly\n\t// under the pointer and shows the precise current value when off-\n\t// major (e.g. \"-7\u00B0\") or the major itself when on-major (e.g. \"0\u00B0\").\n\tconst closestMajor = Math.round( value / MAJOR_INTERVAL ) * MAJOR_INTERVAL;\n\tconst onMajor = Math.abs( value - closestMajor ) < 0.01;\n\tconst
|
|
5
|
-
"mappings": ";AAGA,OAAO,UAAU;AAMjB,SAAS,OAAO,SAAS,cAAc;AAKvC,SAAS,cAAc,kBAAkB;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useId, useMemo, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useRulerDrag, clampValue } from './use-ruler-drag';\n\nexport interface RotationRulerProps {\n\t/** Current value. */\n\tvalue: number;\n\t/** Called with the next value on each change. */\n\tonChange: ( value: number ) => void;\n\t/** Lower bound of the range. Default: -45. */\n\tmin?: number;\n\t/** Upper bound of the range. Default: 45. */\n\tmax?: number;\n\t/**\n\t * Value step for drag and keyboard arrows. Default: 1. Drag values\n\t * are quantized to multiples of `step`. Holding Shift during drag\n\t * or with arrow keys halves the step for precision adjustment.\n\t */\n\tstep?: number;\n\t/** Accessible label for the slider input. */\n\tlabel: string;\n\t/**\n\t * Unit suffix shown in the active label and `aria-valuetext`.\n\t * Default: `\u00B0`.\n\t */\n\tunit?: string;\n\t/** CSS pixels of pointer travel per `step`. Default: 6. */\n\tpixelsPerStep?: number;\n\t/** Optional extra class for the wrapper. */\n\tclassName?: string;\n\t/**\n\t * Optional id for the underlying input; auto-generated when\n\t * omitted.\n\t */\n\tid?: string;\n\t/** When true, ignores all input. */\n\tdisabled?: boolean;\n}\n\nconst STRIP_HEIGHT = 32;\nconst LABEL_BASELINE_Y = 11;\nconst MAJOR_INTERVAL = 15;\nconst TICK_HEIGHT_MINOR = 4;\nconst TICK_HEIGHT_MID = 8;\nconst TICK_HEIGHT_MAJOR = 14;\n\ntype TickKind = 'minor' | 'mid' | 'major';\ninterface Tick {\n\tvalue: number;\n\tkind: TickKind;\n\theight: number;\n}\n\n/**\n * Build the tick list for the ruler strip.\n *\n * @param min Lower bound of the ruler in value units.\n * @param max Upper bound of the ruler in value units.\n */\nfunction useTicks( min: number, max: number ): Tick[] {\n\treturn useMemo( () => {\n\t\tconst out: Tick[] = [];\n\t\tfor ( let v = Math.ceil( min ); v <= Math.floor( max ); v += 1 ) {\n\t\t\tlet kind: TickKind = 'minor';\n\t\t\tlet height = TICK_HEIGHT_MINOR;\n\t\t\tif ( v % 15 === 0 ) {\n\t\t\t\tkind = 'major';\n\t\t\t\theight = TICK_HEIGHT_MAJOR;\n\t\t\t} else if ( v % 5 === 0 ) {\n\t\t\t\tkind = 'mid';\n\t\t\t\theight = TICK_HEIGHT_MID;\n\t\t\t}\n\t\t\tout.push( { value: v, kind, height } );\n\t\t}\n\t\treturn out;\n\t}, [ min, max ] );\n}\n\n/**\n * Format a numeric ruler value for display, trimming a trailing `.0`.\n *\n * @param value Value to format.\n */\nfunction formatValue( value: number ): string {\n\tconst rounded = Math.round( value * 10 ) / 10;\n\treturn Number.isInteger( rounded )\n\t\t? rounded.toFixed( 0 )\n\t\t: rounded.toFixed( 1 );\n}\n\n/**\n * Horizontal \"scrub-the-ruler\" slider for fine-grained numeric input\n * such as rotation in degrees.\n *\n * Renders a visually hidden `<input type=\"range\">` for assistive\n * technologies and keyboard input alongside a decorative tick strip\n * that the user can drag with a pointer.\n *\n * @param props Component props. See `RotationRulerProps`.\n */\nexport default function RotationRuler( props: RotationRulerProps ) {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin = -45,\n\t\tmax = 45,\n\t\tstep = 1,\n\t\tlabel,\n\t\tunit = '\u00B0',\n\t\tpixelsPerStep = 6,\n\t\tclassName,\n\t\tid,\n\t\tdisabled = false,\n\t} = props;\n\tconst inputRef = useRef< HTMLInputElement >( null );\n\tconst generatedId = useId();\n\tconst inputId = id ?? generatedId;\n\n\tconst dragHandlers = useRulerDrag( {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart: () => inputRef.current?.focus(),\n\t} );\n\n\tconst handleKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\t// WAI-ARIA slider keyboard pattern: Up/Right increment,\n\t\t// Down/Left decrement. Home / End / PageUp / PageDown fall\n\t\t// through to native input.\n\t\tconst isIncrement =\n\t\t\tevent.key === 'ArrowRight' || event.key === 'ArrowUp';\n\t\tconst isDecrement =\n\t\t\tevent.key === 'ArrowLeft' || event.key === 'ArrowDown';\n\t\tif ( ! isIncrement && ! isDecrement ) {\n\t\t\treturn;\n\t\t}\n\t\t// Always prevent default so the native input's own arrow-key\n\t\t// stepping doesn't double-fire `onChange` after our custom emit.\n\t\tevent.preventDefault();\n\t\tif ( disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst direction = isIncrement ? 1 : -1;\n\t\t// Shift halves the step for precision adjustment\n\t\t// (e.g. 0.5\u00B0 rotation when step is 1\u00B0). Same modifier works\n\t\t// on drag \u2014 see `useRulerDrag`.\n\t\tconst magnitude = event.shiftKey ? step / 2 : step;\n\t\tconst next = clampValue( value + direction * magnitude, min, max );\n\t\tif ( next !== value ) {\n\t\t\tonChange( next );\n\t\t}\n\t};\n\n\tconst display = `${ formatValue( value ) }${ unit }`;\n\tconst ticks = useTicks( min, max );\n\t// Visual scale is locked to the gesture: 1 step of pointer travel\n\t// (`pixelsPerStep`) maps to `step` value units, so 1 value unit\n\t// renders at `pixelsPerStep / step` CSS pixels. This keeps the\n\t// ticks moving in lock-step with the pointer no matter what the\n\t// caller chooses for `pixelsPerStep` and `step`.\n\tconst pxPerUnit = pixelsPerStep / step;\n\t// `left: 50%` puts the SVG's left edge at the strip's centerline, so\n\t// without an additional `-50%` self-offset all ticks would render to\n\t// the right of the pointer. Combine the centering offset with the\n\t// value-driven offset so value=0 lands the SVG's center on the\n\t// pointer.\n\tconst stripStyle: CSSProperties = useMemo( () => {\n\t\tconst offset = -value * pxPerUnit;\n\t\treturn {\n\t\t\ttransform: `translateX(calc(-50% + ${ offset }px))`,\n\t\t};\n\t}, [ value, pxPerUnit ] );\n\n\t// Closest major (every 15\u00B0) to current value. Its normal label is\n\t// suppressed and replaced by the active label, which sits exactly\n\t// under the pointer and shows the precise current value when off-\n\t// major (e.g. \"-7\u00B0\") or the major itself when on-major (e.g. \"0\u00B0\").\n\tconst closestMajor = Math.round( value / MAJOR_INTERVAL ) * MAJOR_INTERVAL;\n\tconst onMajor = Math.abs( value - closestMajor ) < 0.01;\n\t// Split the number into sign + digits so the sign is rendered in a\n\t// separate span and excluded from the active label's centering, the\n\t// same way the unit is.\n\tconst numberText = onMajor ? `${ closestMajor }` : formatValue( value );\n\tconst isNegative = numberText.startsWith( '-' );\n\tconst digits = isNegative ? numberText.slice( 1 ) : numberText;\n\tconst majorTicks = ticks.filter( ( tick ) => tick.kind === 'major' );\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ clsx( 'rotation-ruler', className ) }\n\t\t\trole=\"presentation\"\n\t\t\tdata-disabled={ disabled || undefined }\n\t\t\t{ ...dragHandlers }\n\t\t>\n\t\t\t<input\n\t\t\t\tref={ inputRef }\n\t\t\t\tid={ inputId }\n\t\t\t\ttype=\"range\"\n\t\t\t\tclassName=\"rotation-ruler__input\"\n\t\t\t\tmin={ min }\n\t\t\t\tmax={ max }\n\t\t\t\tstep=\"any\"\n\t\t\t\tvalue={ value }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taria-label={ label }\n\t\t\t\taria-valuetext={ display }\n\t\t\t\tonChange={ ( event ) =>\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tclampValue( event.target.valueAsNumber, min, max )\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tonKeyDown={ handleKeyDown }\n\t\t\t/>\n\t\t\t<div className=\"rotation-ruler__strip\" aria-hidden=\"true\">\n\t\t\t\t<svg\n\t\t\t\t\tclassName=\"rotation-ruler__ticks\"\n\t\t\t\t\tstyle={ stripStyle }\n\t\t\t\t\twidth={ ( max - min ) * pxPerUnit }\n\t\t\t\t\theight={ STRIP_HEIGHT }\n\t\t\t\t\tviewBox={ `${ min * pxPerUnit } 0 ${\n\t\t\t\t\t\t( max - min ) * pxPerUnit\n\t\t\t\t\t} ${ STRIP_HEIGHT }` }\n\t\t\t\t\tpreserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t>\n\t\t\t\t\t{ ticks.map( ( tick ) => (\n\t\t\t\t\t\t<line\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx1={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\tx2={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty1={ STRIP_HEIGHT - tick.height }\n\t\t\t\t\t\t\ty2={ STRIP_HEIGHT }\n\t\t\t\t\t\t\tclassName={ `rotation-ruler__tick rotation-ruler__tick--${ tick.kind }` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t\t{ majorTicks.map( ( tick ) => (\n\t\t\t\t\t\t<text\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty={ LABEL_BASELINE_Y }\n\t\t\t\t\t\t\ttextAnchor=\"middle\"\n\t\t\t\t\t\t\tclassName=\"rotation-ruler__label\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ tick.value }\n\t\t\t\t\t\t\t{ unit }\n\t\t\t\t\t\t</text>\n\t\t\t\t\t) ) }\n\t\t\t\t</svg>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__active-label\" aria-hidden=\"true\">\n\t\t\t\t<span className=\"rotation-ruler__active-label-number\">\n\t\t\t\t\t{ isNegative && (\n\t\t\t\t\t\t<span className=\"rotation-ruler__active-label-sign\">\n\t\t\t\t\t\t\t-\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ digits }\n\t\t\t\t\t<span className=\"rotation-ruler__active-label-unit\">\n\t\t\t\t\t\t{ unit }\n\t\t\t\t\t</span>\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__pointer\" aria-hidden=\"true\" />\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AAMjB,SAAS,OAAO,SAAS,cAAc;AAKvC,SAAS,cAAc,kBAAkB;AAoMtC,cAyCG,YAzCH;AA/JH,IAAM,eAAe;AACrB,IAAM,mBAAmB;AACzB,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAC1B,IAAM,kBAAkB;AACxB,IAAM,oBAAoB;AAe1B,SAAS,SAAU,KAAa,KAAsB;AACrD,SAAO,QAAS,MAAM;AACrB,UAAM,MAAc,CAAC;AACrB,aAAU,IAAI,KAAK,KAAM,GAAI,GAAG,KAAK,KAAK,MAAO,GAAI,GAAG,KAAK,GAAI;AAChE,UAAI,OAAiB;AACrB,UAAI,SAAS;AACb,UAAK,IAAI,OAAO,GAAI;AACnB,eAAO;AACP,iBAAS;AAAA,MACV,WAAY,IAAI,MAAM,GAAI;AACzB,eAAO;AACP,iBAAS;AAAA,MACV;AACA,UAAI,KAAM,EAAE,OAAO,GAAG,MAAM,OAAO,CAAE;AAAA,IACtC;AACA,WAAO;AAAA,EACR,GAAG,CAAE,KAAK,GAAI,CAAE;AACjB;AAOA,SAAS,YAAa,OAAwB;AAC7C,QAAM,UAAU,KAAK,MAAO,QAAQ,EAAG,IAAI;AAC3C,SAAO,OAAO,UAA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