@wordpress/media-editor 0.20.0 → 0.21.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +2 -1
  3. package/build/components/media-editor/index.cjs +7 -16
  4. package/build/components/media-editor/index.cjs.map +3 -3
  5. package/build/components/media-editor/use-crop-options.cjs +1 -2
  6. package/build/components/media-editor/use-crop-options.cjs.map +2 -2
  7. package/build/components/media-editor-canvas/index.cjs.map +3 -3
  8. package/build/components/media-editor-crop-panel/index.cjs +12 -8
  9. package/build/components/media-editor-crop-panel/index.cjs.map +3 -3
  10. package/build/components/media-editor-modal/index.cjs +2 -0
  11. package/build/components/media-editor-modal/index.cjs.map +2 -2
  12. package/build/components/media-editor-provider/index.cjs +2 -1
  13. package/build/components/media-editor-provider/index.cjs.map +2 -2
  14. package/build/components/media-form/index.cjs +28 -28
  15. package/build/components/media-form/index.cjs.map +3 -3
  16. package/build/components/media-preview/index.cjs.map +3 -3
  17. package/build/image-editor/react/components/cropper.cjs +1 -11
  18. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  19. package/build/state/composite-reducer.cjs +33 -8
  20. package/build/state/composite-reducer.cjs.map +3 -3
  21. package/build/state/index.cjs.map +1 -1
  22. package/build/state/types.cjs.map +1 -1
  23. package/build/state/use-media-editor-state.cjs +20 -7
  24. package/build/state/use-media-editor-state.cjs.map +2 -2
  25. package/build-module/components/media-editor/index.mjs +9 -18
  26. package/build-module/components/media-editor/index.mjs.map +2 -2
  27. package/build-module/components/media-editor/use-crop-options.mjs +1 -2
  28. package/build-module/components/media-editor/use-crop-options.mjs.map +2 -2
  29. package/build-module/components/media-editor-canvas/index.mjs +2 -2
  30. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  31. package/build-module/components/media-editor-crop-panel/index.mjs +13 -9
  32. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  33. package/build-module/components/media-editor-modal/index.mjs +2 -0
  34. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  35. package/build-module/components/media-editor-provider/index.mjs +2 -1
  36. package/build-module/components/media-editor-provider/index.mjs.map +2 -2
  37. package/build-module/components/media-form/index.mjs +33 -30
  38. package/build-module/components/media-form/index.mjs.map +2 -2
  39. package/build-module/components/media-preview/index.mjs +2 -2
  40. package/build-module/components/media-preview/index.mjs.map +2 -2
  41. package/build-module/image-editor/react/components/cropper.mjs +1 -11
  42. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  43. package/build-module/state/composite-reducer.mjs +23 -8
  44. package/build-module/state/composite-reducer.mjs.map +2 -2
  45. package/build-module/state/index.mjs.map +1 -1
  46. package/build-module/state/types.mjs.map +1 -1
  47. package/build-module/state/use-media-editor-state.mjs +20 -7
  48. package/build-module/state/use-media-editor-state.mjs.map +2 -2
  49. package/build-types/components/media-editor/index.d.ts +2 -1
  50. package/build-types/components/media-editor/index.d.ts.map +1 -1
  51. package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
  52. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  53. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  54. package/build-types/components/media-editor-modal/index.d.ts +7 -2
  55. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  56. package/build-types/components/media-editor-provider/index.d.ts +7 -1
  57. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  58. package/build-types/components/media-form/index.d.ts +5 -2
  59. package/build-types/components/media-form/index.d.ts.map +1 -1
  60. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  61. package/build-types/state/composite-reducer.d.ts +1 -1
  62. package/build-types/state/composite-reducer.d.ts.map +1 -1
  63. package/build-types/state/index.d.ts +1 -1
  64. package/build-types/state/index.d.ts.map +1 -1
  65. package/build-types/state/types.d.ts +34 -5
  66. package/build-types/state/types.d.ts.map +1 -1
  67. package/build-types/state/use-media-editor-state.d.ts +16 -5
  68. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  69. package/package.json +33 -22
  70. package/src/components/media-editor/index.tsx +12 -22
  71. package/src/components/media-editor/use-crop-options.ts +0 -2
  72. package/src/components/media-editor-canvas/index.tsx +2 -2
  73. package/src/components/media-editor-crop-panel/index.tsx +17 -9
  74. package/src/components/media-editor-image-controls/style.scss +1 -1
  75. package/src/components/media-editor-modal/index.tsx +8 -1
  76. package/src/components/media-editor-provider/index.tsx +8 -1
  77. package/src/components/media-form/index.tsx +48 -42
  78. package/src/components/media-preview/index.tsx +2 -2
  79. package/src/image-editor/docs/architecture.md +4 -0
  80. package/src/image-editor/react/components/cropper.tsx +1 -15
  81. package/src/state/composite-reducer.ts +24 -11
  82. package/src/state/index.ts +2 -0
  83. package/src/state/types.ts +37 -5
  84. package/src/state/use-media-editor-state.ts +46 -11
  85. package/global.d.ts +0 -5
  86. package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
  87. package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
  88. package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
  89. package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
  90. package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
  91. package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
  92. package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
  93. package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
  94. package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
  95. package/src/image-editor/core/math/test/sanitize.ts +0 -242
  96. package/src/image-editor/core/test/camera.ts +0 -1218
  97. package/src/image-editor/core/test/interaction-controller.ts +0 -1299
  98. package/src/image-editor/core/test/preview-export-parity.ts +0 -249
  99. package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
  100. package/src/image-editor/core/test/state.ts +0 -876
  101. package/src/image-editor/core/test/stencil-math.ts +0 -665
  102. package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
  103. package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
  104. package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
  105. package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
  106. package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
  107. package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
  108. package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
  109. package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
  110. package/src/image-editor/stories/style.module.css +0 -65
  111. package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
  112. package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
  113. package/src/store/test/reducer.ts +0 -64
  114. package/tsconfig.build.json +0 -26
  115. package/tsconfig.build.tsbuildinfo +0 -1
  116. package/tsconfig.json +0 -37
@@ -1,5 +1,5 @@
1
1
  import { createContext, useContext } from '@wordpress/element';
2
- import type { Field } from '@wordpress/dataviews';
2
+ import type { Field, Form } from '@wordpress/dataviews';
3
3
  import type { ReactNode } from 'react';
4
4
 
5
5
  /**
@@ -23,6 +23,7 @@ export interface MediaEditorContextValue {
23
23
  media?: Media;
24
24
  onChange?: ( updates: Partial< Media > ) => void;
25
25
  fields: Field< Media >[];
26
+ form?: Form;
26
27
  }
27
28
 
28
29
  /**
@@ -41,6 +42,11 @@ export interface MediaEditorProviderProps {
41
42
  /** Configuration settings for the media editor. */
42
43
  settings?: {
43
44
  fields?: Field< Media >[];
45
+ /**
46
+ * The form the fields are laid out with. When omitted, `MediaForm`
47
+ * uses a default layout of the core attachment fields.
48
+ */
49
+ form?: Form;
44
50
  };
45
51
  /** Child components. */
46
52
  children: ReactNode;
@@ -60,6 +66,7 @@ export function MediaEditorProvider( {
60
66
  media: value,
61
67
  onChange,
62
68
  fields: settings.fields || [],
69
+ form: settings.form,
63
70
  };
64
71
 
65
72
  return (
@@ -1,11 +1,43 @@
1
1
  import { DataForm } from '@wordpress/dataviews';
2
- import type { Form, Field } from '@wordpress/dataviews';
3
- import { Spinner, __experimentalVStack as VStack } from '@wordpress/components';
2
+ import type { Form } from '@wordpress/dataviews';
3
+ import {
4
+ Spinner as WCSpinner,
5
+ __experimentalVStack as VStack,
6
+ } from '@wordpress/components';
4
7
  import { VisuallyHidden } from '@wordpress/ui';
5
8
  import { __ } from '@wordpress/i18n';
6
9
  import type { ReactNode } from 'react';
7
10
  import { useMediaEditorContext } from '../media-editor-provider';
8
- import type { Media } from '../media-editor-provider';
11
+
12
+ /*
13
+ * The form used when neither the component nor the provider settings have
14
+ * one, mirroring the `form` of the `attachment` view configuration on the
15
+ * server. It lists the core attachment fields in a fixed order, so the layout
16
+ * does not depend on the order the fields are passed in: the editable fields
17
+ * first, in a regular layout, then the metadata and the file information, in
18
+ * panels. A field it lists that is not passed renders nothing.
19
+ */
20
+ const DEFAULT_FORM: Form = {
21
+ layout: {
22
+ type: 'panel',
23
+ },
24
+ fields: [
25
+ ...[ 'title', 'alt_text', 'caption', 'description' ].map( ( id ) => ( {
26
+ id,
27
+ layout: {
28
+ type: 'regular' as const,
29
+ labelPosition: 'top' as const,
30
+ },
31
+ } ) ),
32
+ 'date',
33
+ 'author',
34
+ 'filename',
35
+ 'mime_type',
36
+ 'filesize',
37
+ 'media_dimensions',
38
+ 'attached_to',
39
+ ],
40
+ };
9
41
 
10
42
  /**
11
43
  * Props for MediaForm component.
@@ -19,10 +51,13 @@ export interface MediaFormProps {
19
51
  * MediaForm component for editing media metadata.
20
52
  *
21
53
  * Renders a DataForm with fields for editing media properties like
22
- * title, alt text, caption, description, etc.
54
+ * title, alt text, caption, description, etc. The fields are laid out with
55
+ * the `form` prop, else the form of the provider settings, else a default
56
+ * form of the core attachment fields.
23
57
  *
24
58
  * @param props - Component props.
25
- * @param props.form - Optional form configuration.
59
+ * @param props.form - Optional form configuration, which takes precedence
60
+ * over the form of the provider settings.
26
61
  * @param props.header - Optional header content to display above the form.
27
62
  * @return The MediaForm component.
28
63
  */
@@ -30,51 +65,22 @@ export default function MediaForm( {
30
65
  form: formOverrides,
31
66
  header,
32
67
  }: MediaFormProps ) {
33
- const { media, fields, onChange } = useMediaEditorContext();
68
+ const {
69
+ media,
70
+ fields,
71
+ form: settingsForm,
72
+ onChange,
73
+ } = useMediaEditorContext();
34
74
 
35
75
  if ( ! media || ! onChange ) {
36
76
  return (
37
77
  <div className="media-editor-form media-editor-form--loading">
38
- <Spinner />
78
+ <WCSpinner />
39
79
  </div>
40
80
  );
41
81
  }
42
82
 
43
- // Fields that use a regular (non-panel) layout, rendered at the top.
44
- const regularFieldIds = [ 'title', 'alt_text', 'caption', 'description' ];
45
-
46
- // Place the non-panel (regular layout) fields at the top of the array,
47
- // with the remaining panel fields below.
48
- const sortedFields = [
49
- ...fields.filter( ( field: Field< Media > ) =>
50
- regularFieldIds.includes( field.id )
51
- ),
52
- ...fields.filter(
53
- ( field: Field< Media > ) => ! regularFieldIds.includes( field.id )
54
- ),
55
- ];
56
-
57
- // Default form structure with panel layout
58
- const defaultForm: Form = {
59
- layout: {
60
- type: 'panel',
61
- },
62
- fields: sortedFields.map( ( field: Field< Media > ) => {
63
- // Use regular layout for main editable fields
64
- if ( regularFieldIds.includes( field.id ) ) {
65
- return {
66
- id: field.id,
67
- layout: {
68
- type: 'regular',
69
- labelPosition: 'top',
70
- },
71
- };
72
- }
73
- return field.id;
74
- } ),
75
- };
76
-
77
- const form = formOverrides || defaultForm;
83
+ const form = formOverrides || settingsForm || DEFAULT_FORM;
78
84
 
79
85
  return (
80
86
  <div className="media-editor-form">
@@ -1,4 +1,4 @@
1
- import { Spinner } from '@wordpress/components';
1
+ import { Spinner as WCSpinner } from '@wordpress/components';
2
2
  import { useState } from '@wordpress/element';
3
3
  import { __ } from '@wordpress/i18n';
4
4
  import { useMediaEditorContext } from '../media-editor-provider';
@@ -130,7 +130,7 @@ export default function MediaPreview( props: MediaPreviewProps ) {
130
130
  >
131
131
  { mediaType.type === 'image' && loadingState === 'loading' && (
132
132
  <div className="media-editor-preview__spinner">
133
- <Spinner />
133
+ <WCSpinner />
134
134
  </div>
135
135
  ) }
136
136
  <MediaPreviewContent
@@ -41,6 +41,10 @@ The core reducer is framework-agnostic and serializable. React and media-editor
41
41
 
42
42
  `useMediaEditorState()` returns the media editor session. The session owns the source image, every editing slice, the shared undo/redo history, gesture boundaries, and whether the edits change the saved image (`hasOutputEdits`). The cropper is one participant: `session.cropper` is a geometry-only `CropperController` that a `<Cropper>` takes via its `controller` prop, and its `isDirty` covers geometry alone. Replacing the source image (`setSourceImage`, which the cropper's `setImage` also calls) starts a fresh session with default geometry and crop options, a clean baseline, and no history. Save code asks the session, not the cropper, whether image output needs saving.
43
43
 
44
+ The session also holds named edits other than crop: `session.edits`, set with `session.setEdit( name, value )` and removed by passing `undefined`. They share the crop history, so undo, redo and gestures treat them like any crop change, and a different source image clears them. Values are plain data (`EditValue`: strings, numbers, booleans, `null`, and arrays and objects of those), because the session compares them by content to tell a real change from a no-op. Edits do not yet count towards `hasOutputEdits`; nothing saves them.
45
+
46
+ `session.reset()` puts every slice back to its starting state in one undo entry: default geometry and crop options, no edits, same image. The Reset button calls it; it does not compose per-slice resets itself.
47
+
44
48
  ### Viewport
45
49
 
46
50
  Viewport pan/zoom lets the user inspect or follow the crop area without changing the crop output. It is not part of export and should not create undo entries.
@@ -967,23 +967,9 @@ function CropperInner(
967
967
  };
968
968
  }
969
969
 
970
- // Forward the root element to the consumer's ref.
971
- const setContainerRef = useCallback(
972
- ( element: HTMLDivElement | null ) => {
973
- if ( typeof ref === 'function' ) {
974
- ref( element );
975
- } else if ( ref ) {
976
- (
977
- ref as React.MutableRefObject< HTMLDivElement | null >
978
- ).current = element;
979
- }
980
- },
981
- [ ref ]
982
- );
983
-
984
970
  return (
985
971
  <div
986
- ref={ setContainerRef }
972
+ ref={ ref }
987
973
  className={ clsx(
988
974
  'wp-media-editor-image-editor',
989
975
  isDragging && 'wp-media-editor-image-editor--dragging',
@@ -1,3 +1,4 @@
1
+ import fastDeepEqual from 'fast-deep-equal/es6/index.js';
1
2
  import {
2
3
  cropperReducer,
3
4
  areCropperStatesEqual,
@@ -64,21 +65,31 @@ export function mediaEditorReducer(
64
65
  payload: newCropRect,
65
66
  } );
66
67
  return {
68
+ ...state,
67
69
  cropper: nextCropper,
68
70
  cropOptions: nextCropOptions,
69
71
  };
70
72
  }
71
- case 'RESET_CROP_OPTIONS': {
72
- if (
73
- state.cropOptions.aspectRatioValue ===
74
- DEFAULT_CROP_OPTIONS.aspectRatioValue
75
- ) {
73
+ case 'RESET': {
74
+ const next = buildInitialMediaEditorState(
75
+ cropperReducer( state.cropper, { type: 'RESET' } )
76
+ );
77
+ return areMediaEditorStatesEqual( state, next ) ? state : next;
78
+ }
79
+ case 'SET_EDIT': {
80
+ const { name, value } = action.payload;
81
+ if ( value === undefined ) {
82
+ if ( ! Object.hasOwn( state.edits, name ) ) {
83
+ return state;
84
+ }
85
+ const edits = { ...state.edits };
86
+ delete edits[ name ];
87
+ return { ...state, edits };
88
+ }
89
+ if ( fastDeepEqual( state.edits[ name ], value ) ) {
76
90
  return state;
77
91
  }
78
- return {
79
- ...state,
80
- cropOptions: { ...DEFAULT_CROP_OPTIONS },
81
- };
92
+ return { ...state, edits: { ...state.edits, [ name ]: value } };
82
93
  }
83
94
  case 'RESTORE_SNAPSHOT':
84
95
  return action.payload;
@@ -112,13 +123,14 @@ export function areMediaEditorStatesEqual(
112
123
  }
113
124
  return (
114
125
  areCropperStatesEqual( a.cropper, b.cropper ) &&
115
- a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue
126
+ a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&
127
+ fastDeepEqual( a.edits, b.edits )
116
128
  );
117
129
  }
118
130
 
119
131
  /**
120
132
  * Build the composite state a session starts from: the given cropper
121
- * slice and default crop options.
133
+ * slice, default crop options, and no edits.
122
134
  *
123
135
  * @param cropper The cropper slice.
124
136
  * @return Composite initial state.
@@ -129,5 +141,6 @@ export function buildInitialMediaEditorState(
129
141
  return {
130
142
  cropper,
131
143
  cropOptions: { ...DEFAULT_CROP_OPTIONS },
144
+ edits: {},
132
145
  };
133
146
  }
@@ -15,6 +15,8 @@ export {
15
15
  export { DEFAULT_CROP_OPTIONS } from './types';
16
16
  export type {
17
17
  CropOptionsSlice,
18
+ EditsSlice,
19
+ EditValue,
18
20
  MediaEditorState,
19
21
  MediaEditorAction,
20
22
  } from './types';
@@ -27,9 +27,31 @@ export const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {
27
27
  };
28
28
 
29
29
  /**
30
- * The full composite state for the media editor — cropper geometry
31
- * plus the sidebar control slice. Future feature slices (text
32
- * overlays, filters, …) extend this object.
30
+ * A value an edit can hold: plain data only, because the session
31
+ * compares values by content to tell a real change from a no-op.
32
+ * Anything else, such as a `Blob`, would compare equal to any other
33
+ * and the change would be dropped — keep bytes behind a URL instead.
34
+ *
35
+ * Objects must satisfy the index signature, so type a value with a
36
+ * `type` alias rather than an `interface`.
37
+ */
38
+ export type EditValue =
39
+ | string
40
+ | number
41
+ | boolean
42
+ | null
43
+ | EditValue[]
44
+ | { [ key: string ]: EditValue };
45
+
46
+ /**
47
+ * Named edits other than crop, keyed by edit name (for example
48
+ * `my-plugin/vignette`). An edit that is not present means "no edit".
49
+ */
50
+ export type EditsSlice = Record< string, EditValue >;
51
+
52
+ /**
53
+ * The full composite state for the media editor — cropper geometry,
54
+ * the sidebar control slice, and named edits.
33
55
  *
34
56
  * Every undo/redo snapshot is a full `MediaEditorState`. Slices stay
35
57
  * referentially equal across actions that don't touch them.
@@ -37,6 +59,7 @@ export const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {
37
59
  export interface MediaEditorState {
38
60
  cropper: CropperState;
39
61
  cropOptions: CropOptionsSlice;
62
+ edits: EditsSlice;
40
63
  }
41
64
 
42
65
  /**
@@ -79,8 +102,17 @@ export type MediaEditorAction =
79
102
  visualSize: Size;
80
103
  };
81
104
  }
82
- /** Reset cropOptions to defaults. */
83
- | { type: 'RESET_CROP_OPTIONS' }
105
+ /**
106
+ * Put every slice back to its starting state, keeping the image:
107
+ * default geometry, default crop options, no edits. One action,
108
+ * so one undo entry.
109
+ */
110
+ | { type: 'RESET' }
111
+ /** Set a named edit, or remove it when `value` is `undefined`. */
112
+ | {
113
+ type: 'SET_EDIT';
114
+ payload: { name: string; value: EditValue | undefined };
115
+ }
84
116
  /**
85
117
  * Replace the entire composite state with `payload`. Used by
86
118
  * undo/redo to restore a full snapshot atomically.
@@ -25,6 +25,8 @@ import {
25
25
  } from './composite-reducer';
26
26
  import type {
27
27
  CropOptionsSlice,
28
+ EditsSlice,
29
+ EditValue,
28
30
  MediaEditorAction,
29
31
  MediaEditorState,
30
32
  } from './types';
@@ -102,8 +104,19 @@ export interface MediaEditorSession {
102
104
  cropOptions: CropOptionsSlice;
103
105
  /** Set the aspect-ratio preset. Atomic with the cropRect reshape. */
104
106
  setAspectRatioValue: ( presetKey: string ) => void;
105
- /** Reset cropOptions to defaults. */
106
- resetCropOptions: () => void;
107
+ /**
108
+ * Put every slice back to its starting state in one undo entry:
109
+ * default geometry and crop options, no edits. Keeps the image.
110
+ */
111
+ reset: () => void;
112
+ /** The named edits other than crop, keyed by edit name. */
113
+ edits: EditsSlice;
114
+ /**
115
+ * Set a named edit, or remove it by passing `undefined`. Recorded
116
+ * in the session history like any crop change. Setting a value
117
+ * equal in content to the current one is a no-op.
118
+ */
119
+ setEdit: ( name: string, value: EditValue | undefined ) => void;
107
120
  /**
108
121
  * Replace the image being edited. A different image starts a
109
122
  * fresh session: default geometry and crop options, a clean
@@ -143,8 +156,8 @@ export interface MediaEditorSession {
143
156
  * The media editor session.
144
157
  *
145
158
  * Owns the only undo/redo history for the editor. Cropper geometry
146
- * actions and sidebar cropOptions actions flow through the same
147
- * reducer and the same history stack.
159
+ * actions, sidebar cropOptions actions and named edits flow through
160
+ * the same reducer and the same history stack.
148
161
  *
149
162
  * History semantics:
150
163
  * - Each action's pre-state is pushed to the undo stack before the
@@ -303,7 +316,7 @@ export function useMediaEditorState(): MediaEditorSession {
303
316
  setHasRedo( false );
304
317
  }, [] );
305
318
 
306
- const reset = useCallback(
319
+ const resetCropper = useCallback(
307
320
  ( resetState?: Partial< CropperState > ) => {
308
321
  dispatchWithHistory( {
309
322
  type: 'CROPPER',
@@ -335,10 +348,28 @@ export function useMediaEditorState(): MediaEditorSession {
335
348
  [ dispatchWithHistory ]
336
349
  );
337
350
 
338
- const resetCropOptions = useCallback( () => {
339
- dispatchWithHistory( { type: 'RESET_CROP_OPTIONS' } );
351
+ // =====================================================================
352
+ // Session
353
+ // =====================================================================
354
+
355
+ const reset = useCallback( () => {
356
+ dispatchWithHistory( { type: 'RESET' } );
340
357
  }, [ dispatchWithHistory ] );
341
358
 
359
+ // =====================================================================
360
+ // Edits-slice setters
361
+ // =====================================================================
362
+
363
+ const setEdit = useCallback(
364
+ ( name: string, value: EditValue | undefined ) => {
365
+ dispatchWithHistory( {
366
+ type: 'SET_EDIT',
367
+ payload: { name, value },
368
+ } );
369
+ },
370
+ [ dispatchWithHistory ]
371
+ );
372
+
342
373
  // =====================================================================
343
374
  // History
344
375
  // =====================================================================
@@ -421,7 +452,7 @@ export function useMediaEditorState(): MediaEditorSession {
421
452
  ...cropperSetters,
422
453
  state: state.cropper,
423
454
  setImage: setSourceImage,
424
- reset,
455
+ reset: resetCropper,
425
456
  isDirty: isCropperDirty,
426
457
  getCroppedImage,
427
458
  setVisualSize,
@@ -431,7 +462,7 @@ export function useMediaEditorState(): MediaEditorSession {
431
462
  cropperSetters,
432
463
  state.cropper,
433
464
  setSourceImage,
434
- reset,
465
+ resetCropper,
435
466
  isCropperDirty,
436
467
  getCroppedImage,
437
468
  setVisualSize,
@@ -444,8 +475,10 @@ export function useMediaEditorState(): MediaEditorSession {
444
475
  cropper,
445
476
  cropOptions: state.cropOptions,
446
477
  setAspectRatioValue,
447
- resetCropOptions,
478
+ edits: state.edits,
479
+ setEdit,
448
480
  setSourceImage,
481
+ reset,
449
482
  isDirty,
450
483
  // Only geometry changes the saved image so far.
451
484
  hasOutputEdits: isCropperDirty,
@@ -460,8 +493,10 @@ export function useMediaEditorState(): MediaEditorSession {
460
493
  cropper,
461
494
  state.cropOptions,
462
495
  setAspectRatioValue,
463
- resetCropOptions,
496
+ state.edits,
497
+ setEdit,
464
498
  setSourceImage,
499
+ reset,
465
500
  isDirty,
466
501
  isCropperDirty,
467
502
  hasUndo,
package/global.d.ts DELETED
@@ -1,5 +0,0 @@
1
- /*
2
- * With typeRoots set in tsconfig, global types outside those directories,
3
- * like the jest-dom matchers, must be referenced explicitly.
4
- */
5
- import '@testing-library/jest-dom/vitest';