@wordpress/media-editor 0.21.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/components/media-editor/index.cjs +533 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -155
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -55
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +76 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -710
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +134 -112
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -294
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -673
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -32
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +98 -96
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +43 -46
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -124
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -29
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +68 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +106 -90
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -686
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -90
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -286
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +4 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +1 -1
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +1 -0
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +2 -1
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/components/media-editor/index.tsx +215 -162
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -2
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +16 -26
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-preview/index.tsx +66 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +1 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +19 -27
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +2 -2
- package/src/state/index.ts +1 -0
- package/src/state/types.ts +2 -6
- package/src/state/use-media-editor-state.ts +7 -5
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
|
@@ -1,133 +1,97 @@
|
|
|
1
|
-
// packages/media-editor/src/components/media-editor-modal/index.tsx
|
|
2
1
|
import { Modal } from "@wordpress/components";
|
|
3
2
|
import { useDispatch, useSelect } from "@wordpress/data";
|
|
4
3
|
import { __ } from "@wordpress/i18n";
|
|
5
4
|
import { ShortcutProvider } from "@wordpress/keyboard-shortcuts";
|
|
6
|
-
import { store
|
|
5
|
+
import { store } from "@wordpress/notices";
|
|
7
6
|
import MediaEditor from "../media-editor/index.mjs";
|
|
8
|
-
import { store as
|
|
7
|
+
import { store as store$1 } from "../../store/index.mjs";
|
|
9
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
// packages/media-editor/src/components/media-editor-modal/index.tsx
|
|
10
|
+
/**
|
|
11
|
+
* The modal's footer chrome. The fine-rotation ruler and the image controls
|
|
12
|
+
* both live under the canvas (in `media-editor__content`), never here, so the
|
|
13
|
+
* footer has one layout at every width: History on the left, Cancel/Save on
|
|
14
|
+
* the right.
|
|
15
|
+
*/
|
|
10
16
|
function ModalFooter() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
children: [
|
|
18
|
-
/* @__PURE__ */ jsx(MediaEditor.HistoryActions, {}),
|
|
19
|
-
/* @__PURE__ */ jsx(MediaEditor.SaveActions, {})
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
);
|
|
17
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
18
|
+
className: "media-editor-modal__footer",
|
|
19
|
+
role: "region",
|
|
20
|
+
"aria-label": __("Editor actions"),
|
|
21
|
+
children: [/* @__PURE__ */ jsx(MediaEditor.HistoryActions, {}), /* @__PURE__ */ jsx(MediaEditor.SaveActions, {})]
|
|
22
|
+
});
|
|
23
23
|
}
|
|
24
|
-
function MediaEditorModal({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
renderFrame: ({
|
|
97
|
-
children,
|
|
98
|
-
onRequestClose,
|
|
99
|
-
onKeyDown,
|
|
100
|
-
shouldCloseOnClickOutside
|
|
101
|
-
}) => /* @__PURE__ */ jsx(
|
|
102
|
-
ShortcutProvider,
|
|
103
|
-
{
|
|
104
|
-
className: "media-editor-modal__shortcut-scope",
|
|
105
|
-
onKeyDown: stopKeyDownPropagation,
|
|
106
|
-
children: /* @__PURE__ */ jsxs(
|
|
107
|
-
Modal,
|
|
108
|
-
{
|
|
109
|
-
className: "media-editor-modal",
|
|
110
|
-
title: __("Edit media"),
|
|
111
|
-
size: "fill",
|
|
112
|
-
isDismissible: false,
|
|
113
|
-
shouldCloseOnClickOutside,
|
|
114
|
-
onKeyDown,
|
|
115
|
-
onRequestClose,
|
|
116
|
-
headerActions: /* @__PURE__ */ jsx(MediaEditor.HeaderActions, { showCloseButton: true }),
|
|
117
|
-
children: [
|
|
118
|
-
children,
|
|
119
|
-
/* @__PURE__ */ jsx(ModalFooter, {})
|
|
120
|
-
]
|
|
121
|
-
}
|
|
122
|
-
)
|
|
123
|
-
}
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
);
|
|
24
|
+
function MediaEditorModal({ fields = [], form, aspectRatioPresets }) {
|
|
25
|
+
const { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect((select) => {
|
|
26
|
+
const { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } = select(store$1);
|
|
27
|
+
return {
|
|
28
|
+
isModalOpen: isOpen(),
|
|
29
|
+
id: getId(),
|
|
30
|
+
onUpdate: getOnUpdate(),
|
|
31
|
+
onUndo: getOnUndo(),
|
|
32
|
+
onClose: getOnClose()
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
const { closeMediaEditorModal } = useDispatch(store$1);
|
|
36
|
+
const { createSuccessNotice } = useDispatch(store);
|
|
37
|
+
if (!isModalOpen || !id) return null;
|
|
38
|
+
const portalElement = typeof document === "undefined" ? null : document.body;
|
|
39
|
+
const stopKeyDownPropagation = (event) => {
|
|
40
|
+
event.stopPropagation();
|
|
41
|
+
};
|
|
42
|
+
const handleClose = () => {
|
|
43
|
+
closeMediaEditorModal();
|
|
44
|
+
onClose?.();
|
|
45
|
+
};
|
|
46
|
+
return /* @__PURE__ */ jsx(MediaEditor, {
|
|
47
|
+
id,
|
|
48
|
+
fields,
|
|
49
|
+
form,
|
|
50
|
+
aspectRatioPresets,
|
|
51
|
+
shouldCloseOnEsc: true,
|
|
52
|
+
noticesClassName: "media-editor-modal__snackbar",
|
|
53
|
+
noticesPortalElement: portalElement,
|
|
54
|
+
onClose: handleClose,
|
|
55
|
+
onSaved: ({ id: savedId, url, previous }) => {
|
|
56
|
+
if (savedId && onUpdate) onUpdate({
|
|
57
|
+
id: savedId,
|
|
58
|
+
url
|
|
59
|
+
});
|
|
60
|
+
handleClose();
|
|
61
|
+
if (previous && savedId !== previous.id && onUpdate) createSuccessNotice(__("Image edited."), {
|
|
62
|
+
type: "snackbar",
|
|
63
|
+
actions: [{
|
|
64
|
+
label: __("Undo"),
|
|
65
|
+
onClick: () => {
|
|
66
|
+
if (onUndo) {
|
|
67
|
+
onUndo();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
onUpdate({
|
|
71
|
+
id: previous.id,
|
|
72
|
+
url: previous.url
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}]
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
renderFrame: ({ children, onRequestClose, onKeyDown, shouldCloseOnClickOutside }) => /* @__PURE__ */ jsx(ShortcutProvider, {
|
|
79
|
+
className: "media-editor-modal__shortcut-scope",
|
|
80
|
+
onKeyDown: stopKeyDownPropagation,
|
|
81
|
+
children: /* @__PURE__ */ jsxs(Modal, {
|
|
82
|
+
className: "media-editor-modal",
|
|
83
|
+
title: __("Edit media"),
|
|
84
|
+
size: "fill",
|
|
85
|
+
isDismissible: false,
|
|
86
|
+
shouldCloseOnClickOutside,
|
|
87
|
+
onKeyDown,
|
|
88
|
+
onRequestClose,
|
|
89
|
+
headerActions: /* @__PURE__ */ jsx(MediaEditor.HeaderActions, { showCloseButton: true }),
|
|
90
|
+
children: [children, /* @__PURE__ */ jsx(ModalFooter, {})]
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
});
|
|
127
94
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
media_editor_modal_default as default
|
|
132
|
-
};
|
|
133
|
-
//# sourceMappingURL=index.mjs.map
|
|
95
|
+
export { MediaEditorModal, MediaEditorModal as default };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-editor-modal/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { 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, Form } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\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 * Form the fields are laid out with in the Details tab. When omitted,\n\t * a default layout of the core attachment fields is used.\n\t */\n\tform?: Form;\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\n/**\n * The modal's footer chrome. The fine-rotation ruler and the image controls\n * both live under the canvas (in `media-editor__content`), never here, so the\n * footer has one layout at every width: History on the left, Cancel/Save on\n * the right.\n */\nfunction ModalFooter() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"media-editor-modal__footer\"\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t<MediaEditor.HistoryActions />\n\t\t\t<MediaEditor.SaveActions />\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\tform,\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } =\n\t\t\t\tselect( mediaEditorStore );\n\t\t\treturn {\n\t\t\t\tisModalOpen: isOpen(),\n\t\t\t\tid: getId(),\n\t\t\t\tonUpdate: getOnUpdate(),\n\t\t\t\tonUndo: getOnUndo(),\n\t\t\t\tonClose: getOnClose(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\tform={ form }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tif ( onUndo ) {\n\t\t\t\t\t\t\t\t\t\tonUndo();\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\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\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={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter />\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": ";AAAA,SAAS,aAAa;AACtB,SAAS,aAAa,iBAAiB;AACvC,SAAS,UAAU;AACnB,SAAS,wBAAwB;AACjC,SAAS,SAAS,oBAAoB;AAGtC,OAAO,iBAAiB;AAExB,SAAS,SAAS,wBAAwB;AAgCxC,SAKC,KALD;AAFF,SAAS,cAAc;AACtB,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,MAAK;AAAA,MACL,cAAa,GAAI,gBAAiB;AAAA,MAElC;AAAA,4BAAC,YAAY,gBAAZ,EAA2B;AAAA,QAC5B,oBAAC,YAAY,aAAZ,EAAwB;AAAA;AAAA;AAAA,EAC1B;AAEF;AAEO,SAAS,iBAAkB;AAAA,EACjC,SAAS,CAAC;AAAA,EACV;AAAA,EACA;AACD,GAA2B;AAC1B,QAAM,EAAE,aAAa,IAAI,UAAU,QAAQ,QAAQ,IAAI;AAAA,IACtD,CAAE,WAAY;AACb,YAAM,EAAE,QAAQ,OAAO,aAAa,WAAW,WAAW,IACzD,OAAQ,gBAAiB;AAC1B,aAAO;AAAA,QACN,aAAa,OAAO;AAAA,QACpB,IAAI,MAAM;AAAA,QACV,UAAU,YAAY;AAAA,QACtB,QAAQ,UAAU;AAAA,QAClB,SAAS,WAAW;AAAA,MACrB;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AAEA,QAAM,EAAE,sBAAsB,IAAI,YAAa,gBAAiB;AAChE,QAAM,EAAE,oBAAoB,IAAI,YAAa,YAAa;AAE1D,MAAK,CAAE,eAAe,CAAE,IAAK;AAC5B,WAAO;AAAA,EACR;AAEA,QAAM,gBACL,OAAO,aAAa,cAAc,OAAO,SAAS;AAMnD,QAAM,yBAAyB,CAC9B,UACI;AACJ,UAAM,gBAAgB;AAAA,EACvB;AAEA,QAAM,cAAc,MAAM;AACzB,0BAAsB;AACtB,cAAU;AAAA,EACX;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,kBAAgB;AAAA,MAChB,kBAAiB;AAAA,MACjB,sBAAuB;AAAA,MACvB,SAAU;AAAA,MACV,SAAU,CAAE,EAAE,IAAI,SAAS,KAAK,SAAS,MAAO;AAC/C,YAAK,WAAW,UAAW;AAC1B,gBAAM,SAAiC;AAAA,YACtC,IAAI;AAAA,YACJ;AAAA,UACD;AACA,mBAAU,MAAO;AAAA,QAClB;AACA,oBAAY;AACZ,YAAK,YAAY,YAAY,SAAS,MAAM,UAAW;AAItD,8BAAqB,GAAI,eAAgB,GAAG;AAAA,YAC3C,MAAM;AAAA,YACN,SAAS;AAAA,cACR;AAAA,gBACC,OAAO,GAAI,MAAO;AAAA,gBAClB,SAAS,MAAM;AACd,sBAAK,QAAS;AACb,2BAAO;AACP;AAAA,kBACD;AACA,2BAAU;AAAA,oBACT,IAAI,SAAS;AAAA,oBACb,KAAK,SAAS;AAAA,kBACf,CAAE;AAAA,gBACH;AAAA,cACD;AAAA,YACD;AAAA,UACD,CAAE;AAAA,QACH;AAAA,MACD;AAAA,MACA,aAAc,CAAE;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD,MACC;AAAA,QAAC;AAAA;AAAA,UACA,WAAU;AAAA,UACV,WAAY;AAAA,UAEZ;AAAA,YAAC;AAAA;AAAA,cACA,WAAU;AAAA,cACV,OAAQ,GAAI,YAAa;AAAA,cACzB,MAAK;AAAA,cACL,eAAgB;AAAA,cAChB;AAAA,cACA;AAAA,cACA;AAAA,cACA,eACC,oBAAC,YAAY,eAAZ,EAA0B,iBAAe,MAAC;AAAA,cAG1C;AAAA;AAAA,gBACF,oBAAC,eAAY;AAAA;AAAA;AAAA,UACd;AAAA;AAAA,MACD;AAAA;AAAA,EAEF;AAEF;AAEA,IAAO,6BAAQ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["mediaEditorStore","noticesStore"],"sources":["../../../src/components/media-editor-modal/index.tsx"],"sourcesContent":["import { 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, Form } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\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 * Form the fields are laid out with in the Details tab. When omitted,\n\t * a default layout of the core attachment fields is used.\n\t */\n\tform?: Form;\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\n/**\n * The modal's footer chrome. The fine-rotation ruler and the image controls\n * both live under the canvas (in `media-editor__content`), never here, so the\n * footer has one layout at every width: History on the left, Cancel/Save on\n * the right.\n */\nfunction ModalFooter() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"media-editor-modal__footer\"\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t<MediaEditor.HistoryActions />\n\t\t\t<MediaEditor.SaveActions />\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\tform,\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } =\n\t\t\t\tselect( mediaEditorStore );\n\t\t\treturn {\n\t\t\t\tisModalOpen: isOpen(),\n\t\t\t\tid: getId(),\n\t\t\t\tonUpdate: getOnUpdate(),\n\t\t\t\tonUndo: getOnUndo(),\n\t\t\t\tonClose: getOnClose(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\tform={ form }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tif ( onUndo ) {\n\t\t\t\t\t\t\t\t\t\tonUndo();\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\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\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={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter />\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"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAS,cAAc;CACtB,OACC,qBAAC,OAAD;EACC,WAAU;EACV,MAAK;EACL,cAAa,GAAI,gBAAiB;EAHnC,UAAA,CAKC,oBAAC,YAAY,gBAAb,CAA6B,CAAA,GAC7B,oBAAC,YAAY,aAAb,CAA0B,CAAA,CACtB;;AAEP;AAEA,SAAgB,iBAAkB,EACjC,SAAS,CAAC,GACV,MACA,sBAC0B;CAC1B,MAAM,EAAE,aAAa,IAAI,UAAU,QAAQ,YAAY,WACpD,WAAY;EACb,MAAM,EAAE,QAAQ,OAAO,aAAa,WAAW,eAC9C,OAAQA,OAAiB;EAC1B,OAAO;GACN,aAAa,OAAO;GACpB,IAAI,MAAM;GACV,UAAU,YAAY;GACtB,QAAQ,UAAU;GAClB,SAAS,WAAW;EACrB;CACD,GACA,CAAC,CACF;CAEA,MAAM,EAAE,0BAA0B,YAAaA,OAAiB;CAChE,MAAM,EAAE,wBAAwB,YAAaC,KAAa;CAE1D,IAAK,CAAE,eAAe,CAAE,IACvB,OAAO;CAGR,MAAM,gBACL,OAAO,aAAa,cAAc,OAAO,SAAS;CAMnD,MAAM,0BACL,UACI;EACJ,MAAM,gBAAgB;CACvB;CAEA,MAAM,oBAAoB;EACzB,sBAAsB;EACtB,UAAU;CACX;CAEA,OACC,oBAAC,aAAD;EACM;EACI;EACF;EACc;EACrB,kBAAA;EACA,kBAAiB;EACjB,sBAAuB;EACvB,SAAU;EACV,UAAY,EAAE,IAAI,SAAS,KAAK,eAAgB;GAC/C,IAAK,WAAW,UAKf,SAAU;IAHT,IAAI;IACJ;GAEc,CAAE;GAElB,YAAY;GACZ,IAAK,YAAY,YAAY,SAAS,MAAM,UAI3C,oBAAqB,GAAI,eAAgB,GAAG;IAC3C,MAAM;IACN,SAAS,CACR;KACC,OAAO,GAAI,MAAO;KAClB,eAAe;MACd,IAAK,QAAS;OACb,OAAO;OACP;MACD;MACA,SAAU;OACT,IAAI,SAAS;OACb,KAAK,SAAS;MACf,CAAE;KACH;IACD,CACD;GACD,CAAE;EAEJ;EACA,cAAgB,EACf,UACA,gBACA,WACA,gCAEA,oBAAC,kBAAD;GACC,WAAU;GACV,WAAY;GAEZ,UAAA,qBAAC,OAAD;IACC,WAAU;IACV,OAAQ,GAAI,YAAa;IACzB,MAAK;IACL,eAAgB;IACY;IAChB;IACK;IACjB,eACC,oBAAC,YAAY,eAAb,EAA2B,iBAAA,KAAiB,CAAA;IAT9C,UAAA,CAYG,UACF,oBAAC,aAAD,CAAc,CAAA,CACR;;EACU,CAAA;CAEnB,CAAA;AAEH"}
|
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
// packages/media-editor/src/components/media-editor-provider/index.tsx
|
|
2
1
|
import { createContext, useContext } from "@wordpress/element";
|
|
3
2
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
form: settings.form
|
|
18
|
-
};
|
|
19
|
-
return /* @__PURE__ */ jsx(MediaEditorContext.Provider, { value: contextValue, children });
|
|
3
|
+
// packages/media-editor/src/components/media-editor-provider/index.tsx
|
|
4
|
+
const MediaEditorContext = createContext(void 0);
|
|
5
|
+
function MediaEditorProvider({ value, onChange, settings = {}, children }) {
|
|
6
|
+
const contextValue = {
|
|
7
|
+
media: value,
|
|
8
|
+
onChange,
|
|
9
|
+
fields: settings.fields || [],
|
|
10
|
+
form: settings.form
|
|
11
|
+
};
|
|
12
|
+
return /* @__PURE__ */ jsx(MediaEditorContext.Provider, {
|
|
13
|
+
value: contextValue,
|
|
14
|
+
children
|
|
15
|
+
});
|
|
20
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Hook to access the MediaEditor context.
|
|
19
|
+
*
|
|
20
|
+
* Must be used within a MediaEditorProvider component.
|
|
21
|
+
*
|
|
22
|
+
* @return MediaEditorContextValue value with media, onChange, and fields, etc.
|
|
23
|
+
*/
|
|
21
24
|
function useMediaEditorContext() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"useMediaEditorContext must be used within MediaEditorProvider"
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
return context;
|
|
25
|
+
const context = useContext(MediaEditorContext);
|
|
26
|
+
if (!context) throw new Error("useMediaEditorContext must be used within MediaEditorProvider");
|
|
27
|
+
return context;
|
|
29
28
|
}
|
|
30
|
-
export {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=index.mjs.map
|
|
29
|
+
export { MediaEditorProvider, useMediaEditorContext };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-editor-provider/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createContext, useContext } from '@wordpress/element';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { ReactNode } from 'react';\n\n/**\n * Media object from WordPress REST API.\n */\nexport interface Media {\n\tid?: number;\n\tsource_url?: string;\n\tmime_type?: string;\n\talt_text?: string;\n\ttitle?: string | { rendered?: string; raw?: string };\n\tcaption?: string | { rendered?: string; raw?: string };\n\tdescription?: string | { rendered?: string; raw?: string };\n\t[ key: string ]: any;\n}\n\n/**\n * Context value for MediaEditor.\n */\nexport interface MediaEditorContextValue {\n\tmedia?: Media;\n\tonChange?: ( updates: Partial< Media > ) => void;\n\tfields: Field< Media >[];\n\tform?: Form;\n}\n\n/**\n * Props for MediaEditorProvider.\n */\nexport interface MediaEditorProviderProps {\n\t/** The media object to edit. */\n\tvalue?: Media;\n\t/**\n\t * Callback when media is updated.\n\t *\n\t * Optional - if not provided, the MediaEditor can be used in a read-only mode,\n\t * useful for preview-only scenarios.\n\t */\n\tonChange?: ( updates: Partial< Media > ) => void;\n\t/** Configuration settings for the media editor. */\n\tsettings?: {\n\t\tfields?: Field< Media >[];\n\t\t/**\n\t\t * The form the fields are laid out with. When omitted, `MediaForm`\n\t\t * uses a default layout of the core attachment fields.\n\t\t */\n\t\tform?: Form;\n\t};\n\t/** Child components. */\n\tchildren: ReactNode;\n}\n\nconst MediaEditorContext = createContext< MediaEditorContextValue | undefined >(\n\tundefined\n);\n\nexport function MediaEditorProvider( {\n\tvalue,\n\tonChange,\n\tsettings = {},\n\tchildren,\n}: MediaEditorProviderProps ) {\n\tconst contextValue: MediaEditorContextValue = {\n\t\tmedia: value,\n\t\tonChange,\n\t\tfields: settings.fields || [],\n\t\tform: settings.form,\n\t};\n\n\treturn (\n\t\t<MediaEditorContext.Provider value={ contextValue }>\n\t\t\t{ children }\n\t\t</MediaEditorContext.Provider>\n\t);\n}\n\n/**\n * Hook to access the MediaEditor context.\n *\n * Must be used within a MediaEditorProvider component.\n *\n * @return MediaEditorContextValue value with media, onChange, and fields, etc.\n */\nexport function useMediaEditorContext(): MediaEditorContextValue {\n\tconst context = useContext( MediaEditorContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditorContext must be used within MediaEditorProvider'\n\t\t);\n\t}\n\treturn context;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,eAAe,kBAAkB;AAwExC;AAlBF,IAAM,qBAAqB;AAAA,EAC1B;AACD;AAEO,SAAS,oBAAqB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ;AACD,GAA8B;AAC7B,QAAM,eAAwC;AAAA,IAC7C,OAAO;AAAA,IACP;AAAA,IACA,QAAQ,SAAS,UAAU,CAAC;AAAA,IAC5B,MAAM,SAAS;AAAA,EAChB;AAEA,SACC,oBAAC,mBAAmB,UAAnB,EAA4B,OAAQ,cAClC,UACH;AAEF;AASO,SAAS,wBAAiD;AAChE,QAAM,UAAU,WAAY,kBAAmB;AAC/C,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-provider/index.tsx"],"sourcesContent":["import { createContext, useContext } from '@wordpress/element';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { ReactNode } from 'react';\n\n/**\n * Media object from WordPress REST API.\n */\nexport interface Media {\n\tid?: number;\n\tsource_url?: string;\n\tmime_type?: string;\n\talt_text?: string;\n\ttitle?: string | { rendered?: string; raw?: string };\n\tcaption?: string | { rendered?: string; raw?: string };\n\tdescription?: string | { rendered?: string; raw?: string };\n\t[ key: string ]: any;\n}\n\n/**\n * Context value for MediaEditor.\n */\nexport interface MediaEditorContextValue {\n\tmedia?: Media;\n\tonChange?: ( updates: Partial< Media > ) => void;\n\tfields: Field< Media >[];\n\tform?: Form;\n}\n\n/**\n * Props for MediaEditorProvider.\n */\nexport interface MediaEditorProviderProps {\n\t/** The media object to edit. */\n\tvalue?: Media;\n\t/**\n\t * Callback when media is updated.\n\t *\n\t * Optional - if not provided, the MediaEditor can be used in a read-only mode,\n\t * useful for preview-only scenarios.\n\t */\n\tonChange?: ( updates: Partial< Media > ) => void;\n\t/** Configuration settings for the media editor. */\n\tsettings?: {\n\t\tfields?: Field< Media >[];\n\t\t/**\n\t\t * The form the fields are laid out with. When omitted, `MediaForm`\n\t\t * uses a default layout of the core attachment fields.\n\t\t */\n\t\tform?: Form;\n\t};\n\t/** Child components. */\n\tchildren: ReactNode;\n}\n\nconst MediaEditorContext = createContext< MediaEditorContextValue | undefined >(\n\tundefined\n);\n\nexport function MediaEditorProvider( {\n\tvalue,\n\tonChange,\n\tsettings = {},\n\tchildren,\n}: MediaEditorProviderProps ) {\n\tconst contextValue: MediaEditorContextValue = {\n\t\tmedia: value,\n\t\tonChange,\n\t\tfields: settings.fields || [],\n\t\tform: settings.form,\n\t};\n\n\treturn (\n\t\t<MediaEditorContext.Provider value={ contextValue }>\n\t\t\t{ children }\n\t\t</MediaEditorContext.Provider>\n\t);\n}\n\n/**\n * Hook to access the MediaEditor context.\n *\n * Must be used within a MediaEditorProvider component.\n *\n * @return MediaEditorContextValue value with media, onChange, and fields, etc.\n */\nexport function useMediaEditorContext(): MediaEditorContextValue {\n\tconst context = useContext( MediaEditorContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditorContext must be used within MediaEditorProvider'\n\t\t);\n\t}\n\treturn context;\n}\n"],"mappings":";;;AAsDA,MAAM,qBAAqB,cAC1B,KAAA,CACD;AAEA,SAAgB,oBAAqB,EACpC,OACA,UACA,WAAW,CAAC,GACZ,YAC6B;CAC7B,MAAM,eAAwC;EAC7C,OAAO;EACP;EACA,QAAQ,SAAS,UAAU,CAAC;EAC5B,MAAM,SAAS;CAChB;CAEA,OACC,oBAAC,mBAAmB,UAApB;EAA6B,OAAQ;EAClC;CAC0B,CAAA;AAE/B;;;;;;;;AASA,SAAgB,wBAAiD;CAChE,MAAM,UAAU,WAAY,kBAAmB;CAC/C,IAAK,CAAE,SACN,MAAM,IAAI,MACT,+DACD;CAED,OAAO;AACR"}
|
|
@@ -1,63 +1,75 @@
|
|
|
1
|
-
// packages/media-editor/src/components/media-form/index.tsx
|
|
2
1
|
import { DataForm } from "@wordpress/dataviews";
|
|
3
|
-
import {
|
|
4
|
-
Spinner as WCSpinner,
|
|
5
|
-
__experimentalVStack as VStack
|
|
6
|
-
} from "@wordpress/components";
|
|
2
|
+
import { Spinner, __experimentalVStack } from "@wordpress/components";
|
|
7
3
|
import { VisuallyHidden } from "@wordpress/ui";
|
|
8
4
|
import { __ } from "@wordpress/i18n";
|
|
9
5
|
import { useMediaEditorContext } from "../media-editor-provider/index.mjs";
|
|
10
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
7
|
+
// packages/media-editor/src/components/media-form/index.tsx
|
|
8
|
+
const DEFAULT_FORM = {
|
|
9
|
+
layout: { type: "panel" },
|
|
10
|
+
fields: [
|
|
11
|
+
...[
|
|
12
|
+
"title",
|
|
13
|
+
"alt_text",
|
|
14
|
+
"caption",
|
|
15
|
+
"description"
|
|
16
|
+
].map((id) => ({
|
|
17
|
+
id,
|
|
18
|
+
layout: {
|
|
19
|
+
type: "regular",
|
|
20
|
+
labelPosition: "top"
|
|
21
|
+
}
|
|
22
|
+
})),
|
|
23
|
+
"date",
|
|
24
|
+
"author",
|
|
25
|
+
"filename",
|
|
26
|
+
"mime_type",
|
|
27
|
+
"filesize",
|
|
28
|
+
"media_dimensions",
|
|
29
|
+
"attached_to"
|
|
30
|
+
]
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
32
|
+
/**
|
|
33
|
+
* MediaForm component for editing media metadata.
|
|
34
|
+
*
|
|
35
|
+
* Renders a DataForm with fields for editing media properties like
|
|
36
|
+
* title, alt text, caption, description, etc. The fields are laid out with
|
|
37
|
+
* the `form` prop, else the form of the provider settings, else a default
|
|
38
|
+
* form of the core attachment fields.
|
|
39
|
+
*
|
|
40
|
+
* @param props - Component props.
|
|
41
|
+
* @param props.form - Optional form configuration, which takes precedence
|
|
42
|
+
* over the form of the provider settings.
|
|
43
|
+
* @param props.header - Optional header content to display above the form.
|
|
44
|
+
* @return The MediaForm component.
|
|
45
|
+
*/
|
|
46
|
+
function MediaForm({ form: formOverrides, header }) {
|
|
47
|
+
const { media, fields, form: settingsForm, onChange } = useMediaEditorContext();
|
|
48
|
+
if (!media || !onChange) return /* @__PURE__ */ jsx("div", {
|
|
49
|
+
className: "media-editor-form media-editor-form--loading",
|
|
50
|
+
children: /* @__PURE__ */ jsx(Spinner, {})
|
|
51
|
+
});
|
|
52
|
+
const form = formOverrides || settingsForm || DEFAULT_FORM;
|
|
53
|
+
return /* @__PURE__ */ jsx("div", {
|
|
54
|
+
className: "media-editor-form",
|
|
55
|
+
children: /* @__PURE__ */ jsxs(__experimentalVStack, {
|
|
56
|
+
spacing: 4,
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsx(VisuallyHidden, {
|
|
59
|
+
render: /* @__PURE__ */ jsx("h2", {}),
|
|
60
|
+
children: __("Media details")
|
|
61
|
+
}),
|
|
62
|
+
header,
|
|
63
|
+
/* @__PURE__ */ jsx(DataForm, {
|
|
64
|
+
data: media,
|
|
65
|
+
fields,
|
|
66
|
+
form,
|
|
67
|
+
onChange
|
|
68
|
+
})
|
|
69
|
+
]
|
|
70
|
+
})
|
|
71
|
+
});
|
|
59
72
|
}
|
|
60
|
-
export {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//# sourceMappingURL=index.mjs.map
|
|
73
|
+
export { MediaForm as default };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-form/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { DataForm } from '@wordpress/dataviews';\nimport type { Form } from '@wordpress/dataviews';\nimport {\n\tSpinner as WCSpinner,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\nimport { useMediaEditorContext } from '../media-editor-provider';\n\n/*\n * The form used when neither the component nor the provider settings have\n * one, mirroring the `form` of the `attachment` view configuration on the\n * server. It lists the core attachment fields in a fixed order, so the layout\n * does not depend on the order the fields are passed in: the editable fields\n * first, in a regular layout, then the metadata and the file information, in\n * panels. A field it lists that is not passed renders nothing.\n */\nconst DEFAULT_FORM: Form = {\n\tlayout: {\n\t\ttype: 'panel',\n\t},\n\tfields: [\n\t\t...[ 'title', 'alt_text', 'caption', 'description' ].map( ( id ) => ( {\n\t\t\tid,\n\t\t\tlayout: {\n\t\t\t\ttype: 'regular' as const,\n\t\t\t\tlabelPosition: 'top' as const,\n\t\t\t},\n\t\t} ) ),\n\t\t'date',\n\t\t'author',\n\t\t'filename',\n\t\t'mime_type',\n\t\t'filesize',\n\t\t'media_dimensions',\n\t\t'attached_to',\n\t],\n};\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. The fields are laid out with\n * the `form` prop, else the form of the provider settings, else a default\n * form of the core attachment fields.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration, which takes precedence\n * over the form of the provider settings.\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 {\n\t\tmedia,\n\t\tfields,\n\t\tform: settingsForm,\n\t\tonChange,\n\t} = 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<WCSpinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst form = formOverrides || settingsForm || DEFAULT_FORM;\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={ fields }\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": ";AAAA,SAAS,gBAAgB;AAEzB;AAAA,EACC,WAAW;AAAA,EACX,wBAAwB;AAAA,OAClB;AACP,SAAS,sBAAsB;AAC/B,SAAS,UAAU;AAEnB,SAAS,6BAA6B;AAoElC,cASD,YATC;AA1DJ,IAAM,eAAqB;AAAA,EAC1B,QAAQ;AAAA,IACP,MAAM;AAAA,EACP;AAAA,EACA,QAAQ;AAAA,IACP,GAAG,CAAE,SAAS,YAAY,WAAW,aAAc,EAAE,IAAK,CAAE,QAAU;AAAA,MACrE;AAAA,MACA,QAAQ;AAAA,QACP,MAAM;AAAA,QACN,eAAe;AAAA,MAChB;AAAA,IACD,EAAI;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAwBe,SAAR,UAA4B;AAAA,EAClC,MAAM;AAAA,EACN;AACD,GAAoB;AACnB,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN;AAAA,EACD,IAAI,sBAAsB;AAE1B,MAAK,CAAE,SAAS,CAAE,UAAW;AAC5B,WACC,oBAAC,SAAI,WAAU,gDACd,8BAAC,aAAU,GACZ;AAAA,EAEF;AAEA,QAAM,OAAO,iBAAiB,gBAAgB;AAE9C,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;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["WCSpinner","VStack"],"sources":["../../../src/components/media-form/index.tsx"],"sourcesContent":["import { DataForm } from '@wordpress/dataviews';\nimport type { Form } from '@wordpress/dataviews';\nimport {\n\tSpinner as WCSpinner,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\nimport { useMediaEditorContext } from '../media-editor-provider';\n\n/*\n * The form used when neither the component nor the provider settings have\n * one, mirroring the `form` of the `attachment` view configuration on the\n * server. It lists the core attachment fields in a fixed order, so the layout\n * does not depend on the order the fields are passed in: the editable fields\n * first, in a regular layout, then the metadata and the file information, in\n * panels. A field it lists that is not passed renders nothing.\n */\nconst DEFAULT_FORM: Form = {\n\tlayout: {\n\t\ttype: 'panel',\n\t},\n\tfields: [\n\t\t...[ 'title', 'alt_text', 'caption', 'description' ].map( ( id ) => ( {\n\t\t\tid,\n\t\t\tlayout: {\n\t\t\t\ttype: 'regular' as const,\n\t\t\t\tlabelPosition: 'top' as const,\n\t\t\t},\n\t\t} ) ),\n\t\t'date',\n\t\t'author',\n\t\t'filename',\n\t\t'mime_type',\n\t\t'filesize',\n\t\t'media_dimensions',\n\t\t'attached_to',\n\t],\n};\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. The fields are laid out with\n * the `form` prop, else the form of the provider settings, else a default\n * form of the core attachment fields.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration, which takes precedence\n * over the form of the provider settings.\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 {\n\t\tmedia,\n\t\tfields,\n\t\tform: settingsForm,\n\t\tonChange,\n\t} = 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<WCSpinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst form = formOverrides || settingsForm || DEFAULT_FORM;\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={ fields }\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"],"mappings":";;;;;;;AAmBA,MAAM,eAAqB;CAC1B,QAAQ,EACP,MAAM,QACP;CACA,QAAQ;EACP,GAAG;GAAE;GAAS;GAAY;GAAW;EAAc,CAAC,CAAC,KAAO,QAAU;GACrE;GACA,QAAQ;IACP,MAAM;IACN,eAAe;GAChB;EACD,EAAI;EACJ;EACA;EACA;EACA;EACA;EACA;EACA;CACD;AACD;;;;;;;;;;;;;;;AAwBA,SAAwB,UAAW,EAClC,MAAM,eACN,UACmB;CACnB,MAAM,EACL,OACA,QACA,MAAM,cACN,aACG,sBAAsB;CAE1B,IAAK,CAAE,SAAS,CAAE,UACjB,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,oBAACA,SAAD,CAAY,CAAA;CACR,CAAA;CAIP,MAAM,OAAO,iBAAiB,gBAAgB;CAE9C,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,qBAACC,sBAAD;GAAQ,SAAU;GAAlB,UAAA;IACC,oBAAC,gBAAD;KAAgB,QAAS,oBAAC,MAAD,CAAK,CAAA;KAC3B,UAAA,GAAI,eAAgB;IACP,CAAA;IACd;IACF,oBAAC,UAAD;KACC,MAAO;KACE;KACF;KACI;IACX,CAAA;GACM;;CACJ,CAAA;AAEP"}
|