@contentful/field-editor-rich-text 3.20.7 → 3.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.
@@ -19,10 +19,13 @@ function _interop_require_default(obj) {
19
19
  }
20
20
  const ButtonRedo = ()=>{
21
21
  const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
22
+ const onClickHandler = ()=>{
23
+ editor.redo('toolbar');
24
+ };
22
25
  return _react.default.createElement(_ToolbarButton.ToolbarButton, {
23
26
  title: "Redo",
24
27
  testId: "redo-toolbar-button",
25
- onClick: editor.redo,
28
+ onClick: onClickHandler,
26
29
  isActive: false,
27
30
  isDisabled: editor.history.redos.length === 0
28
31
  }, _react.default.createElement(_f36components.Icon, {
@@ -19,10 +19,13 @@ function _interop_require_default(obj) {
19
19
  }
20
20
  const ButtonUndo = ()=>{
21
21
  const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
22
+ const onClickHandler = ()=>{
23
+ editor.undo('toolbar');
24
+ };
22
25
  return _react.default.createElement(_ToolbarButton.ToolbarButton, {
23
26
  title: "Undo",
24
27
  testId: "undo-toolbar-button",
25
- onClick: editor.undo,
28
+ onClick: onClickHandler,
26
29
  isActive: false,
27
30
  isDisabled: editor.history.undos.length === 0
28
31
  }, _react.default.createElement(_f36components.Icon, {
@@ -76,7 +76,7 @@ const createTrackingPlugin = (onAction)=>{
76
76
  return {
77
77
  key: 'TrackingPlugin',
78
78
  withOverrides: (editor)=>{
79
- const { insertData } = editor;
79
+ const { insertData, undo, redo } = editor;
80
80
  editor.tracking = trackingActions;
81
81
  editor.insertData = (data)=>{
82
82
  const isCopyAndPaste = data.types.length !== 0;
@@ -95,6 +95,22 @@ const createTrackingPlugin = (onAction)=>{
95
95
  }
96
96
  insertData(data);
97
97
  };
98
+ editor.undo = (source)=>{
99
+ undo();
100
+ if (source === 'toolbar') {
101
+ editor.tracking.onToolbarAction('undo');
102
+ } else {
103
+ editor.tracking.onShortcutAction('undo');
104
+ }
105
+ };
106
+ editor.redo = (source)=>{
107
+ redo();
108
+ if (source === 'toolbar') {
109
+ editor.tracking.onToolbarAction('redo');
110
+ } else {
111
+ editor.tracking.onShortcutAction('redo');
112
+ }
113
+ };
98
114
  return editor;
99
115
  }
100
116
  };
@@ -4,10 +4,13 @@ import { useContentfulEditor } from '../../ContentfulEditorProvider';
4
4
  import { ToolbarButton } from '../../plugins/shared/ToolbarButton';
5
5
  export const ButtonRedo = ()=>{
6
6
  const editor = useContentfulEditor();
7
+ const onClickHandler = ()=>{
8
+ editor.redo('toolbar');
9
+ };
7
10
  return React.createElement(ToolbarButton, {
8
11
  title: "Redo",
9
12
  testId: "redo-toolbar-button",
10
- onClick: editor.redo,
13
+ onClick: onClickHandler,
11
14
  isActive: false,
12
15
  isDisabled: editor.history.redos.length === 0
13
16
  }, React.createElement(Icon, {
@@ -4,10 +4,13 @@ import { useContentfulEditor } from '../../ContentfulEditorProvider';
4
4
  import { ToolbarButton } from '../../plugins/shared/ToolbarButton';
5
5
  export const ButtonUndo = ()=>{
6
6
  const editor = useContentfulEditor();
7
+ const onClickHandler = ()=>{
8
+ editor.undo('toolbar');
9
+ };
7
10
  return React.createElement(ToolbarButton, {
8
11
  title: "Undo",
9
12
  testId: "undo-toolbar-button",
10
- onClick: editor.undo,
13
+ onClick: onClickHandler,
11
14
  isActive: false,
12
15
  isDisabled: editor.history.undos.length === 0
13
16
  }, React.createElement(Icon, {
@@ -58,7 +58,7 @@ export const createTrackingPlugin = (onAction)=>{
58
58
  return {
59
59
  key: 'TrackingPlugin',
60
60
  withOverrides: (editor)=>{
61
- const { insertData } = editor;
61
+ const { insertData, undo, redo } = editor;
62
62
  editor.tracking = trackingActions;
63
63
  editor.insertData = (data)=>{
64
64
  const isCopyAndPaste = data.types.length !== 0;
@@ -77,6 +77,22 @@ export const createTrackingPlugin = (onAction)=>{
77
77
  }
78
78
  insertData(data);
79
79
  };
80
+ editor.undo = (source)=>{
81
+ undo();
82
+ if (source === 'toolbar') {
83
+ editor.tracking.onToolbarAction('undo');
84
+ } else {
85
+ editor.tracking.onShortcutAction('undo');
86
+ }
87
+ };
88
+ editor.redo = (source)=>{
89
+ redo();
90
+ if (source === 'toolbar') {
91
+ editor.tracking.onToolbarAction('redo');
92
+ } else {
93
+ editor.tracking.onShortcutAction('redo');
94
+ }
95
+ };
80
96
  return editor;
81
97
  }
82
98
  };
@@ -26,6 +26,14 @@ export type Value = Element[];
26
26
  export type ReactEditor = p.TReactEditor<Value>;
27
27
  export interface PlateEditor extends p.PlateEditor<Value> {
28
28
  tracking: TrackingPluginActions;
29
+ undo: {
30
+ (): void;
31
+ (source: 'toolbar' | 'shortcut'): void;
32
+ };
33
+ redo: {
34
+ (): void;
35
+ (source: 'toolbar' | 'shortcut'): void;
36
+ };
29
37
  }
30
38
  export type Node = p.ElementOf<PlateEditor> | p.TextOf<PlateEditor>;
31
39
  export type Path = p.TPath;
@@ -1,5 +1,5 @@
1
1
  import { PlatePlugin } from '../../internal/types';
2
- export type RichTextTrackingActionName = 'edit' | 'insert' | 'remove' | 'mark' | 'unmark' | 'insertTable' | 'insertTableRow' | 'insertTableColumn' | 'removeTable' | 'removeTableRow' | 'removeTableColumn' | 'paste' | 'invalidTablePaste' | 'cancelCreateHyperlinkDialog' | 'cancelEditHyperlinkDialog' | 'linkRendered' | 'openCreateHyperlinkDialog' | 'openEditHyperlinkDialog' | 'unlinkHyperlinks' | 'openCreateEmbedDialog' | 'cancelCreateEmbedDialog' | 'openRichTextCommandPalette' | 'cancelRichTextCommandPalette';
2
+ export type RichTextTrackingActionName = 'edit' | 'insert' | 'remove' | 'mark' | 'unmark' | 'insertTable' | 'insertTableRow' | 'insertTableColumn' | 'removeTable' | 'removeTableRow' | 'removeTableColumn' | 'paste' | 'invalidTablePaste' | 'undo' | 'redo' | 'cancelCreateHyperlinkDialog' | 'cancelEditHyperlinkDialog' | 'linkRendered' | 'openCreateHyperlinkDialog' | 'openEditHyperlinkDialog' | 'unlinkHyperlinks' | 'openCreateEmbedDialog' | 'cancelCreateEmbedDialog' | 'openRichTextCommandPalette' | 'cancelRichTextCommandPalette';
3
3
  export type RichTextTrackingActionHandler = (name: RichTextTrackingActionName, data: Record<string, unknown>) => unknown;
4
4
  export interface TrackingPluginActions {
5
5
  onViewportAction: (actionName: RichTextTrackingActionName, data?: Record<string, unknown>) => ReturnType<RichTextTrackingActionHandler>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "3.20.7",
3
+ "version": "3.21.0",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -86,5 +86,5 @@
86
86
  "publishConfig": {
87
87
  "registry": "https://npm.pkg.github.com/"
88
88
  },
89
- "gitHead": "aba605cb270ad856f7a9712305d0eba5e1f03423"
89
+ "gitHead": "272847c9c563f75cd1bfbf71f807d6dd319c6f51"
90
90
  }