@wordpress/media-editor 0.3.1-next.v.202602241322.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-types/components/media-editor/index.d.ts +42 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -0
- package/build-types/components/media-editor/use-crop-options.d.ts +35 -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 +26 -0
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts +31 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -0
- package/build-types/components/media-editor-fine-rotation/index.d.ts +15 -0
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -0
- package/build-types/components/media-editor-image-controls/index.d.ts +46 -0
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -0
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +6 -0
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +83 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +20 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/index.d.ts +46 -0
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts +14 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts +61 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts +41 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -0
- package/build-types/image-editor/core/camera.d.ts +107 -0
- package/build-types/image-editor/core/camera.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +83 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -0
- package/build-types/image-editor/core/containment.d.ts +75 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -0
- 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/export/canvas-renderer.d.ts +106 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +10 -0
- package/build-types/image-editor/core/index.d.ts.map +1 -0
- package/build-types/image-editor/core/interaction-controller.d.ts +194 -0
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -0
- package/build-types/image-editor/core/math/rotation.d.ts +18 -0
- package/build-types/image-editor/core/math/rotation.d.ts.map +1 -0
- package/build-types/image-editor/core/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 +75 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -0
- package/build-types/image-editor/core/state.d.ts +54 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -0
- package/build-types/image-editor/core/stencil-math.d.ts +97 -0
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -0
- package/build-types/image-editor/core/transform-style.d.ts +23 -0
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts +27 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -0
- package/build-types/image-editor/core/types.d.ts +255 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -0
- package/build-types/image-editor/core/viewport-state.d.ts +7 -0
- package/build-types/image-editor/core/viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/index.d.ts +16 -0
- package/build-types/image-editor/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +41 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper.d.ts +62 -0
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -0
- package/build-types/image-editor/react/components/index.d.ts +4 -0
- package/build-types/image-editor/react/components/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/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/overlays/dimming-overlay.d.ts +20 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +33 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -0
- package/build-types/image-editor/react/components/viewport-provider.d.ts +9 -0
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -0
- 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 +5 -0
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-cropper-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 +63 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +19 -0
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts +6 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts +16 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -0
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/private-apis.d.ts +2 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/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 +96 -0
- package/build-types/state/types.d.ts.map +1 -0
- package/build-types/state/use-media-editor-state.d.ts +101 -0
- package/build-types/state/use-media-editor-state.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +29 -0
- package/build-types/store/actions.d.ts.map +1 -0
- package/build-types/store/constants.d.ts +2 -0
- package/build-types/store/constants.d.ts.map +1 -0
- package/build-types/store/index.d.ts +4 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/store/reducer.d.ts +26 -0
- package/build-types/store/reducer.d.ts.map +1 -0
- package/build-types/store/selectors.d.ts +9 -0
- package/build-types/store/selectors.d.ts.map +1 -0
- package/package.json +6 -6
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { type CropperState } from '../image-editor';
|
|
5
|
+
import { type CropOptionsSlice, type MediaEditorAction, type MediaEditorState } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Pure composite reducer for the media editor.
|
|
8
|
+
*
|
|
9
|
+
* Delegates `CROPPER`-tagged actions to the framework-agnostic
|
|
10
|
+
* `cropperReducer` and owns first-class transitions for the sidebar
|
|
11
|
+
* `cropOptions` slice. `RESTORE_SNAPSHOT` replaces the whole composite
|
|
12
|
+
* in one transaction (used by undo/redo).
|
|
13
|
+
*
|
|
14
|
+
* Note: this reducer carries NO history of its own. Snapshots and
|
|
15
|
+
* stacks live in the `useMediaEditorState` hook that wraps it.
|
|
16
|
+
*
|
|
17
|
+
* @param state Current composite state.
|
|
18
|
+
* @param action Action to apply.
|
|
19
|
+
* @return Next composite state.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mediaEditorReducer(state: MediaEditorState, action: MediaEditorAction): MediaEditorState;
|
|
22
|
+
/**
|
|
23
|
+
* Value-equality check for two composite states. Used by the history
|
|
24
|
+
* machinery to dedup snapshots when an action turned out to be a no-op.
|
|
25
|
+
*
|
|
26
|
+
* @param a First composite state.
|
|
27
|
+
* @param b Second composite state.
|
|
28
|
+
* @return Whether `a` and `b` are value-equal across all slices.
|
|
29
|
+
*/
|
|
30
|
+
export declare function areMediaEditorStatesEqual(a: MediaEditorState, b: MediaEditorState): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Build the initial composite state from optional partial overrides.
|
|
33
|
+
*
|
|
34
|
+
* @param initialCropper Initial cropper-slice fields to merge.
|
|
35
|
+
* @param initialOptions Initial cropOptions-slice fields to merge.
|
|
36
|
+
* @return Composite initial state.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildInitialMediaEditorState(initialCropper: CropperState, initialOptions?: Partial<CropOptionsSlice>): MediaEditorState;
|
|
39
|
+
//# sourceMappingURL=composite-reducer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composite-reducer.d.ts","sourceRoot":"","sources":["../../src/state/composite-reducer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAIN,KAAK,YAAY,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,iBAAiB,GACvB,gBAAgB,CAgElB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACxC,CAAC,EAAE,gBAAgB,EACnB,CAAC,EAAE,gBAAgB,GACjB,OAAO,CAQT;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC3C,cAAc,EAAE,YAAY,EAC5B,cAAc,CAAC,EAAE,OAAO,CAAE,gBAAgB,CAAE,GAC1C,gBAAgB,CAKlB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { useMediaEditorState, resolveAspectRatio, } from './use-media-editor-state';
|
|
2
|
+
export type { MediaEditorController } from './use-media-editor-state';
|
|
3
|
+
export { MediaEditorStateProvider, useMediaEditor, } from './media-editor-state-provider';
|
|
4
|
+
export { mediaEditorReducer, areMediaEditorStatesEqual, buildInitialMediaEditorState, } from './composite-reducer';
|
|
5
|
+
export { DEFAULT_CROP_OPTIONS } from './types';
|
|
6
|
+
export type { CropOptionsSlice, MediaEditorState, MediaEditorAction, } from './types';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,mBAAmB,EACnB,kBAAkB,GAClB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EACN,wBAAwB,EACxB,cAAc,GACd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,kBAAkB,EAClB,yBAAyB,EACzB,4BAA4B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EACX,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { CropperState } from '../image-editor';
|
|
5
|
+
import { type MediaEditorController } from './use-media-editor-state';
|
|
6
|
+
import type { CropOptionsSlice } from './types';
|
|
7
|
+
interface MediaEditorStateProviderProps {
|
|
8
|
+
/** Optional cropper-slice initial state. */
|
|
9
|
+
initialCropperState?: Partial<CropperState>;
|
|
10
|
+
/** Optional cropOptions-slice initial state. */
|
|
11
|
+
initialCropOptions?: Partial<CropOptionsSlice>;
|
|
12
|
+
/** Child components. */
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Provider that vends the composite media-editor controller via
|
|
17
|
+
* context. Wrap the media editor in this so every consumer
|
|
18
|
+
* (canvas, toolbar, sidebar) reads from the same store.
|
|
19
|
+
*
|
|
20
|
+
* @param props
|
|
21
|
+
* @param props.initialCropperState
|
|
22
|
+
* @param props.initialCropOptions
|
|
23
|
+
* @param props.children
|
|
24
|
+
*/
|
|
25
|
+
export declare function MediaEditorStateProvider({ initialCropperState, initialCropOptions, children }: MediaEditorStateProviderProps): import("react").JSX.Element;
|
|
26
|
+
/**
|
|
27
|
+
* Consume the composite media-editor controller. Throws if used
|
|
28
|
+
* outside a `<MediaEditorStateProvider>`.
|
|
29
|
+
*
|
|
30
|
+
* @return The composite controller.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useMediaEditor(): MediaEditorController;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=media-editor-state-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-editor-state-provider.d.ts","sourceRoot":"","sources":["../../src/state/media-editor-state-provider.tsx"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAEN,KAAK,qBAAqB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAMhD,UAAU,6BAA6B;IACtC,4CAA4C;IAC5C,mBAAmB,CAAC,EAAE,OAAO,CAAE,YAAY,CAAE,CAAC;IAC9C,gDAAgD;IAChD,kBAAkB,CAAC,EAAE,OAAO,CAAE,gBAAgB,CAAE,CAAC;IACjD,wBAAwB;IACxB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAE,EACzC,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,EACR,EAAE,6BAA6B,+BAW/B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,qBAAqB,CAQtD"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { CropperAction, CropperState, NormalizedRect, Size } from '../image-editor';
|
|
5
|
+
/**
|
|
6
|
+
* Sidebar control state for the cropper. Lives in the composite store
|
|
7
|
+
* so it participates in the same undo history as cropper geometry.
|
|
8
|
+
*/
|
|
9
|
+
export interface CropOptionsSlice {
|
|
10
|
+
/**
|
|
11
|
+
* Selected aspect-ratio preset as a string (round-trippable through
|
|
12
|
+
* `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive
|
|
13
|
+
* decimal = fixed ratio.
|
|
14
|
+
*/
|
|
15
|
+
aspectRatioValue: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Default values for the crop-options slice. Mirrors the initial state
|
|
19
|
+
* used by the sidebar before the user has touched anything.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_CROP_OPTIONS: CropOptionsSlice;
|
|
22
|
+
/**
|
|
23
|
+
* The full composite state for the media editor — cropper geometry
|
|
24
|
+
* plus the sidebar control slice. Future feature slices (text
|
|
25
|
+
* overlays, filters, …) extend this object.
|
|
26
|
+
*
|
|
27
|
+
* Every undo/redo snapshot is a full `MediaEditorState`. Slices stay
|
|
28
|
+
* referentially equal across actions that don't touch them.
|
|
29
|
+
*/
|
|
30
|
+
export interface MediaEditorState {
|
|
31
|
+
cropper: CropperState;
|
|
32
|
+
cropOptions: CropOptionsSlice;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Composite reducer action union.
|
|
36
|
+
*
|
|
37
|
+
* Cropper geometry actions are wrapped in a `CROPPER` envelope and
|
|
38
|
+
* delegated to the pure `cropperReducer`. Sidebar and history
|
|
39
|
+
* concerns are first-class actions on this reducer.
|
|
40
|
+
*/
|
|
41
|
+
export type MediaEditorAction =
|
|
42
|
+
/**
|
|
43
|
+
* Delegate to the underlying cropper reducer. Used for every
|
|
44
|
+
* geometry transition (pan / zoom / rotation / flip / cropRect /
|
|
45
|
+
* settle / etc.).
|
|
46
|
+
*/
|
|
47
|
+
{
|
|
48
|
+
type: 'CROPPER';
|
|
49
|
+
action: CropperAction;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Set the aspect-ratio preset. Atomically updates the preset key
|
|
53
|
+
* and the cropRect (computed from the resolved ratio and the
|
|
54
|
+
* current visualSize). One transaction = one undo entry.
|
|
55
|
+
*/
|
|
56
|
+
| {
|
|
57
|
+
type: 'SET_ASPECT_RATIO_VALUE';
|
|
58
|
+
payload: {
|
|
59
|
+
/** Preset key as it appears in the dropdown. */
|
|
60
|
+
presetKey: string;
|
|
61
|
+
/**
|
|
62
|
+
* Resolved width/height ratio. `undefined` = Free
|
|
63
|
+
* (no lock; cropRect stays where it is).
|
|
64
|
+
*/
|
|
65
|
+
resolved: number | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Rendered image size used to compute the inscribed
|
|
68
|
+
* rect. Caller supplies it because the reducer is
|
|
69
|
+
* framework-agnostic and has no DOM access.
|
|
70
|
+
*/
|
|
71
|
+
visualSize: Size;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Reset cropOptions to defaults. */
|
|
75
|
+
| {
|
|
76
|
+
type: 'RESET_CROP_OPTIONS';
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Replace the entire composite state with `payload`. Used by
|
|
80
|
+
* undo/redo to restore a full snapshot atomically.
|
|
81
|
+
*/
|
|
82
|
+
| {
|
|
83
|
+
type: 'RESTORE_SNAPSHOT';
|
|
84
|
+
payload: MediaEditorState;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Adjust the cropper's cropRect in response to a viewport change
|
|
88
|
+
* (e.g., window resize). Behaviorally identical to a `CROPPER
|
|
89
|
+
* SET_CROP_RECT` dispatch, but tagged so the hook layer can skip
|
|
90
|
+
* history recording — viewport reshapes aren't editor actions.
|
|
91
|
+
*/
|
|
92
|
+
| {
|
|
93
|
+
type: 'VIEWPORT_ADJUST_CROP_RECT';
|
|
94
|
+
payload: NormalizedRect;
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/state/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACX,aAAa,EACb,YAAY,EACZ,cAAc,EACd,IAAI,EACJ,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAElC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,YAAY,CAAC;IACtB,WAAW,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB;AAC5B;;;;GAIG;AACD;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;CACrB;AACH;;;;GAIG;GACD;IACA,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE;QACR,gDAAgD;QAChD,SAAS,EAAE,MAAM,CAAC;QAClB;;;WAGG;QACH,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;QAC7B;;;;WAIG;QACH,UAAU,EAAE,IAAI,CAAC;KACjB,CAAC;CACD;AACH,qCAAqC;GACnC;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE;AAChC;;;GAGG;GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE;AACzD;;;;;GAKG;GACD;IACA,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,cAAc,CAAC;CACvB,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { type CropperController, type CropperState, type NormalizedRect, type Size } from '../image-editor';
|
|
5
|
+
import type { CropOptionsSlice } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Resolve an aspect-ratio preset value (the string the dropdown
|
|
8
|
+
* round-trips) into a numeric width/height ratio for the cropper.
|
|
9
|
+
*
|
|
10
|
+
* - `'0'` → `undefined` (Free; no lock)
|
|
11
|
+
* - `'-1'` (Original) → image's natural width / height, or `undefined`
|
|
12
|
+
* if no image is loaded.
|
|
13
|
+
* - Any positive decimal → the parsed number.
|
|
14
|
+
*
|
|
15
|
+
* Centralizing here means the dropdown, the action dispatcher, and
|
|
16
|
+
* the test harness all resolve the same way.
|
|
17
|
+
*
|
|
18
|
+
* @param presetKey Preset value from the dropdown.
|
|
19
|
+
* @param cropperImage The cropper's loaded image, or `null`.
|
|
20
|
+
* @return The resolved ratio, or `undefined` for Free / unresolvable.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveAspectRatio(presetKey: string, cropperImage: CropperState['image'] | null): number | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The composite controller exposed by `useMediaEditorState`.
|
|
25
|
+
*
|
|
26
|
+
* Satisfies `CropperController` (so a `<Cropper>` can take this
|
|
27
|
+
* controller directly via the `controller` prop) and adds slice
|
|
28
|
+
* setters, undo/redo, gesture boundaries, and viewport reporting.
|
|
29
|
+
*/
|
|
30
|
+
export interface MediaEditorController extends CropperController {
|
|
31
|
+
/** The cropOptions slice. */
|
|
32
|
+
cropOptions: CropOptionsSlice;
|
|
33
|
+
/** Set the aspect-ratio preset. Atomic with the cropRect reshape. */
|
|
34
|
+
setAspectRatioValue: (presetKey: string) => void;
|
|
35
|
+
/** Reset cropOptions to defaults. */
|
|
36
|
+
resetCropOptions: () => void;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the cropper geometry differs from the initial baseline.
|
|
39
|
+
*/
|
|
40
|
+
isCropperDirty: boolean;
|
|
41
|
+
/** Whether there's an undoable change in history. */
|
|
42
|
+
hasUndo: boolean;
|
|
43
|
+
/** Whether there's a redoable change in history. */
|
|
44
|
+
hasRedo: boolean;
|
|
45
|
+
/** Undo the last committed action across all slices. */
|
|
46
|
+
undo: () => void;
|
|
47
|
+
/** Redo the last undone action across all slices. */
|
|
48
|
+
redo: () => void;
|
|
49
|
+
/**
|
|
50
|
+
* Open a gesture boundary. During a gesture all state-changing
|
|
51
|
+
* actions coalesce into one undo entry — the snapshot taken at
|
|
52
|
+
* `beginGesture`. Pair with `endGesture` on pointer-up / key-up.
|
|
53
|
+
*/
|
|
54
|
+
beginGesture: () => void;
|
|
55
|
+
/** Close a gesture boundary and commit the pre-gesture snapshot. */
|
|
56
|
+
endGesture: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Report the current rendered image size to the controller. The
|
|
59
|
+
* Cropper component calls this whenever its visualSize changes;
|
|
60
|
+
* the controller needs it to compute aspect-ratio reshapes.
|
|
61
|
+
*/
|
|
62
|
+
setVisualSize: (size: Size) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Reshape the cropRect in response to a viewport change. Behaves
|
|
65
|
+
* like `setCropRect` but does NOT record an undo entry — window
|
|
66
|
+
* resizes aren't editor actions.
|
|
67
|
+
*/
|
|
68
|
+
adjustCropRectForViewport: (rect: NormalizedRect) => void;
|
|
69
|
+
}
|
|
70
|
+
interface InitialMediaEditorState {
|
|
71
|
+
cropper?: Partial<CropperState>;
|
|
72
|
+
cropOptions?: Partial<CropOptionsSlice>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Composite store for the media editor.
|
|
76
|
+
*
|
|
77
|
+
* Owns the only undo/redo history for the editor. Cropper geometry
|
|
78
|
+
* actions and sidebar cropOptions actions flow through the same
|
|
79
|
+
* reducer and the same history stack.
|
|
80
|
+
*
|
|
81
|
+
* History semantics:
|
|
82
|
+
* - Each action's pre-state is pushed to the undo stack before the
|
|
83
|
+
* action commits, unless a gesture is open or the action is a
|
|
84
|
+
* no-op (post-state value-equal to pre-state).
|
|
85
|
+
* - During a gesture (`beginGesture` → `endGesture`) all mutations
|
|
86
|
+
* coalesce: only the pre-gesture snapshot is pushed, at gesture
|
|
87
|
+
* end. Any pending gesture is flushed on undo/redo.
|
|
88
|
+
* - Viewport-driven cropRect reshapes (window resize) use a
|
|
89
|
+
* dedicated non-recording dispatch path so they never produce
|
|
90
|
+
* undo entries.
|
|
91
|
+
*
|
|
92
|
+
* `isDirty` tracks the full editor session, including undoable UI
|
|
93
|
+
* state. Use `isCropperDirty` when deciding whether the image output
|
|
94
|
+
* needs saving.
|
|
95
|
+
*
|
|
96
|
+
* @param initialState Optional seed for the cropper and cropOptions slices.
|
|
97
|
+
* @return The composite controller.
|
|
98
|
+
*/
|
|
99
|
+
export declare function useMediaEditorState(initialState?: InitialMediaEditorState): MediaEditorController;
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=use-media-editor-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-media-editor-state.d.ts","sourceRoot":"","sources":["../../src/state/use-media-editor-state.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,OAAO,EAQN,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,IAAI,EACT,MAAM,iBAAiB,CAAC;AAMzB,OAAO,KAAK,EACX,gBAAgB,EAGhB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CACjC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,YAAY,CAAE,OAAO,CAAE,GAAG,IAAI,GAC1C,MAAM,GAAG,SAAS,CAmBpB;AAaD;;;;;;GAMG;AACH,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC/D,6BAA6B;IAC7B,WAAW,EAAE,gBAAgB,CAAC;IAC9B,qEAAqE;IACrE,mBAAmB,EAAE,CAAE,SAAS,EAAE,MAAM,KAAM,IAAI,CAAC;IACnD,qCAAqC;IACrC,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B;;OAEG;IACH,cAAc,EAAE,OAAO,CAAC;IACxB,qDAAqD;IACrD,OAAO,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,OAAO,EAAE,OAAO,CAAC;IACjB,wDAAwD;IACxD,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,qDAAqD;IACrD,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB;;;;OAIG;IACH,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,oEAAoE;IACpE,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB;;;;OAIG;IACH,aAAa,EAAE,CAAE,IAAI,EAAE,IAAI,KAAM,IAAI,CAAC;IACtC;;;;OAIG;IACH,yBAAyB,EAAE,CAAE,IAAI,EAAE,cAAc,KAAM,IAAI,CAAC;CAC5D;AAED,UAAU,uBAAuB;IAChC,OAAO,CAAC,EAAE,OAAO,CAAE,YAAY,CAAE,CAAC;IAClC,WAAW,CAAC,EAAE,OAAO,CAAE,gBAAgB,CAAE,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,mBAAmB,CAClC,YAAY,CAAC,EAAE,uBAAuB,GACpC,qBAAqB,CA8SvB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape passed to `onUpdate` after a successful save. Deliberately normalized
|
|
3
|
+
* and minimal: `url` instead of REST's `source_url`, so consumers can drop
|
|
4
|
+
* it straight into block attributes (matches the legacy `ImageEditor`'s
|
|
5
|
+
* `onSaveImage` shape at
|
|
6
|
+
* `packages/block-editor/src/components/image-editor/use-save-image.js`).
|
|
7
|
+
* Keeping this decoupled from the REST field names also leaves room to reuse
|
|
8
|
+
* the modal outside a WordPress REST context (e.g. native/Electron hosts).
|
|
9
|
+
*/
|
|
10
|
+
export interface MediaEditorModalUpdate {
|
|
11
|
+
id: number;
|
|
12
|
+
url?: string;
|
|
13
|
+
}
|
|
14
|
+
interface OpenMediaEditorModalArgs {
|
|
15
|
+
id: number;
|
|
16
|
+
onUpdate?: (updated: MediaEditorModalUpdate) => void;
|
|
17
|
+
onClose?: () => void;
|
|
18
|
+
}
|
|
19
|
+
export declare function openMediaEditorModal({ id, onUpdate, onClose }: OpenMediaEditorModalArgs): {
|
|
20
|
+
type: 'OPEN_MEDIA_EDITOR_MODAL';
|
|
21
|
+
id: number;
|
|
22
|
+
onUpdate: ((updated: MediaEditorModalUpdate) => void) | null;
|
|
23
|
+
onClose: (() => void) | null;
|
|
24
|
+
};
|
|
25
|
+
export declare function closeMediaEditorModal(): {
|
|
26
|
+
type: 'CLOSE_MEDIA_EDITOR_MODAL';
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/store/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,sBAAsB;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED,UAAU,wBAAwB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,CAAE,OAAO,EAAE,sBAAsB,KAAM,IAAI,CAAC;IACvD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,wBAAgB,oBAAoB,CAAE,EACrC,EAAE,EACF,QAAQ,EACR,OAAO,EACP,EAAE,wBAAwB;UAEnB,yBAAyB;;yBAVV,sBAAsB,KAAM,IAAI;oBACtC,IAAI;EAcpB;AAED,wBAAgB,qBAAqB;IAC3B,IAAI,EAAE,0BAA0B;EACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/store/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as actions from './actions';
|
|
2
|
+
import * as selectors from './selectors';
|
|
3
|
+
export declare const store: import("@wordpress/data").StoreDescriptor<import("@wordpress/data").ReduxStoreConfig<unknown, typeof actions, typeof selectors>>;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAGzC,eAAO,MAAM,KAAK,kIAIf,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { MediaEditorModalUpdate } from './actions';
|
|
5
|
+
type OnUpdateCallback = (updated: MediaEditorModalUpdate) => void;
|
|
6
|
+
type OnCloseCallback = () => void;
|
|
7
|
+
export interface State {
|
|
8
|
+
isOpen: boolean;
|
|
9
|
+
id: number | null;
|
|
10
|
+
onUpdate: OnUpdateCallback | null;
|
|
11
|
+
onClose: OnCloseCallback | null;
|
|
12
|
+
}
|
|
13
|
+
export declare const DEFAULT_STATE: State;
|
|
14
|
+
type Action = {
|
|
15
|
+
type: 'OPEN_MEDIA_EDITOR_MODAL';
|
|
16
|
+
id: number;
|
|
17
|
+
onUpdate: OnUpdateCallback | null;
|
|
18
|
+
onClose: OnCloseCallback | null;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'CLOSE_MEDIA_EDITOR_MODAL';
|
|
21
|
+
};
|
|
22
|
+
export default function reducer(state: State | undefined, action: Action | {
|
|
23
|
+
type: string;
|
|
24
|
+
}): State;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/store/reducer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAExD,KAAK,gBAAgB,GAAG,CAAE,OAAO,EAAE,sBAAsB,KAAM,IAAI,CAAC;AACpE,KAAK,eAAe,GAAG,MAAM,IAAI,CAAC;AAElC,MAAM,WAAW,KAAK;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAClC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;CAChC;AAED,eAAO,MAAM,aAAa,EAAE,KAK3B,CAAC;AAEF,KAAK,MAAM,GACR;IACA,IAAI,EAAE,yBAAyB,CAAC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAClC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;CAC/B,GACD;IAAE,IAAI,EAAE,0BAA0B,CAAA;CAAE,CAAC;AAExC,MAAM,CAAC,OAAO,UAAU,OAAO,CAC9B,KAAK,EAAE,KAAK,YAAgB,EAC5B,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B,KAAK,CAkBP"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { State } from './reducer';
|
|
5
|
+
export declare function isOpen(state: State): boolean;
|
|
6
|
+
export declare function getId(state: State): number | null;
|
|
7
|
+
export declare function getOnUpdate(state: State): ((updated: import("./actions").MediaEditorModalUpdate) => void) | null;
|
|
8
|
+
export declare function getOnClose(state: State): (() => void) | null;
|
|
9
|
+
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/store/selectors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,wBAAgB,MAAM,CAAE,KAAK,EAAE,KAAK,GAAI,OAAO,CAE9C;AAED,wBAAgB,KAAK,CAAE,KAAK,EAAE,KAAK,GAAI,MAAM,GAAG,IAAI,CAEnD;AAED,wBAAgB,WAAW,CAAE,KAAK,EAAE,KAAK,0EAExC;AAED,wBAAgB,UAAU,CAAE,KAAK,EAAE,KAAK,uBAEvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/media-editor",
|
|
3
|
-
"version": "0.3.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Media editor components for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/runtime": "^7.16.0",
|
|
45
|
-
"@wordpress/components": "^32.
|
|
46
|
-
"@wordpress/dataviews": "^12.
|
|
47
|
-
"@wordpress/element": "^6.40.1
|
|
48
|
-
"@wordpress/i18n": "^6.13.1
|
|
45
|
+
"@wordpress/components": "^32.2.1",
|
|
46
|
+
"@wordpress/dataviews": "^12.0.1",
|
|
47
|
+
"@wordpress/element": "^6.40.1",
|
|
48
|
+
"@wordpress/i18n": "^6.13.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "^18.0.0"
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "adb6623c9f32490cfc73c7ac7f122578c1f10c65"
|
|
57
57
|
}
|