dn-react-text-editor 0.3.3 → 0.3.5

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.
@@ -17,6 +17,8 @@ declare const createCommands: (schema: Schema, view: EditorView, options?: {
17
17
  }) => void;
18
18
  wrapInList: (listType: string, attrs?: Attrs | null) => void;
19
19
  clear: () => void;
20
+ undo: () => void;
21
+ redo: () => void;
20
22
  attachFile: (files: File[]) => void;
21
23
  };
22
24
 
@@ -17,6 +17,8 @@ declare const createCommands: (schema: Schema, view: EditorView, options?: {
17
17
  }) => void;
18
18
  wrapInList: (listType: string, attrs?: Attrs | null) => void;
19
19
  clear: () => void;
20
+ undo: () => void;
21
+ redo: () => void;
20
22
  attachFile: (files: File[]) => void;
21
23
  };
22
24
 
package/dist/commands.js CHANGED
@@ -35,6 +35,7 @@ __export(commands_exports, {
35
35
  module.exports = __toCommonJS(commands_exports);
36
36
  var commands = __toESM(require("prosemirror-commands"));
37
37
  var schemaList = __toESM(require("prosemirror-schema-list"));
38
+ var history = __toESM(require("prosemirror-history"));
38
39
  var createCommands = (schema, view, options = {}) => {
39
40
  {
40
41
  const isBlockTypeActive = (node, attrs, excludes = []) => {
@@ -91,6 +92,14 @@ var createCommands = (schema, view, options = {}) => {
91
92
  );
92
93
  view.dispatch(tr);
93
94
  };
95
+ const undo2 = () => {
96
+ view.focus();
97
+ history.undo(view.state, view.dispatch);
98
+ };
99
+ const redo2 = () => {
100
+ view.focus();
101
+ history.redo(view.state, view.dispatch);
102
+ };
94
103
  return {
95
104
  isBlockTypeActive,
96
105
  setBlockType: setBlockType2,
@@ -98,6 +107,8 @@ var createCommands = (schema, view, options = {}) => {
98
107
  toggleMark: toggleMark2,
99
108
  wrapInList: wrapInList2,
100
109
  clear,
110
+ undo: undo2,
111
+ redo: redo2,
101
112
  attachFile: (files) => {
102
113
  options.attachFile?.(view, files);
103
114
  }
package/dist/commands.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/commands.tsx
2
2
  import * as commands from "prosemirror-commands";
3
3
  import * as schemaList from "prosemirror-schema-list";
4
+ import * as history from "prosemirror-history";
4
5
  var createCommands = (schema, view, options = {}) => {
5
6
  {
6
7
  const isBlockTypeActive = (node, attrs, excludes = []) => {
@@ -57,6 +58,14 @@ var createCommands = (schema, view, options = {}) => {
57
58
  );
58
59
  view.dispatch(tr);
59
60
  };
61
+ const undo2 = () => {
62
+ view.focus();
63
+ history.undo(view.state, view.dispatch);
64
+ };
65
+ const redo2 = () => {
66
+ view.focus();
67
+ history.redo(view.state, view.dispatch);
68
+ };
60
69
  return {
61
70
  isBlockTypeActive,
62
71
  setBlockType: setBlockType2,
@@ -64,6 +73,8 @@ var createCommands = (schema, view, options = {}) => {
64
73
  toggleMark: toggleMark2,
65
74
  wrapInList: wrapInList2,
66
75
  clear,
76
+ undo: undo2,
77
+ redo: redo2,
67
78
  attachFile: (files) => {
68
79
  options.attachFile?.(view, files);
69
80
  }
package/dist/index.js CHANGED
@@ -877,6 +877,7 @@ function createAttachFile({
877
877
  // src/commands.tsx
878
878
  var commands = __toESM(require("prosemirror-commands"));
879
879
  var schemaList = __toESM(require("prosemirror-schema-list"));
880
+ var history = __toESM(require("prosemirror-history"));
880
881
  var createCommands = (schema, view, options = {}) => {
881
882
  {
882
883
  const isBlockTypeActive = (node, attrs, excludes = []) => {
@@ -933,6 +934,14 @@ var createCommands = (schema, view, options = {}) => {
933
934
  );
934
935
  view.dispatch(tr);
935
936
  };
937
+ const undo3 = () => {
938
+ view.focus();
939
+ history.undo(view.state, view.dispatch);
940
+ };
941
+ const redo3 = () => {
942
+ view.focus();
943
+ history.redo(view.state, view.dispatch);
944
+ };
936
945
  return {
937
946
  isBlockTypeActive,
938
947
  setBlockType: setBlockType2,
@@ -940,6 +949,8 @@ var createCommands = (schema, view, options = {}) => {
940
949
  toggleMark: toggleMark2,
941
950
  wrapInList: wrapInList2,
942
951
  clear,
952
+ undo: undo3,
953
+ redo: redo3,
943
954
  attachFile: (files) => {
944
955
  options.attachFile?.(view, files);
945
956
  }
@@ -958,6 +969,7 @@ var TextEditorController = class {
958
969
  view;
959
970
  prosemirrorParser;
960
971
  prosemirrorSerializer;
972
+ element;
961
973
  get value() {
962
974
  if (this.props.mode === "text") {
963
975
  return this.toTextContent();
@@ -995,12 +1007,13 @@ var TextEditorController = class {
995
1007
  uploadFile: this.props.attachFile?.uploadFile
996
1008
  })(this.view, files);
997
1009
  }
998
- bind(container) {
1010
+ bind(element) {
1011
+ this.element = element;
999
1012
  const wrapper = document.createElement("div");
1000
1013
  wrapper.innerHTML = this.toInnerHTML(
1001
1014
  this.props.defaultValue ? String(this.props.defaultValue) : ""
1002
1015
  );
1003
- this.view = new import_prosemirror_view4.EditorView(container, {
1016
+ this.view = new import_prosemirror_view4.EditorView(element, {
1004
1017
  ...this.props.editor,
1005
1018
  attributes: (state) => {
1006
1019
  const propsAttributes = (() => {
@@ -1074,7 +1087,7 @@ var TextEditorController = class {
1074
1087
  this.view?.destroy();
1075
1088
  }
1076
1089
  };
1077
- var configTextEditorController = (options = {}) => {
1090
+ var configTextEditorController = (options = {} = {}) => {
1078
1091
  return (props) => new TextEditorController({
1079
1092
  ...props,
1080
1093
  className: props.className || options.className,
@@ -1086,6 +1099,7 @@ var configTextEditorController = (options = {}) => {
1086
1099
  // src/text_editor.tsx
1087
1100
  function TextEditor({
1088
1101
  controller: externalController,
1102
+ ref,
1089
1103
  name,
1090
1104
  className,
1091
1105
  autoFocus,
@@ -1116,6 +1130,7 @@ function TextEditor({
1116
1130
  []
1117
1131
  );
1118
1132
  const controller = externalController || innerController;
1133
+ (0, import_react2.useImperativeHandle)(ref, () => controller, [controller]);
1119
1134
  (0, import_react3.useEffect)(() => {
1120
1135
  const container = containerRef.current;
1121
1136
  if (!container) {
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/text_editor.tsx
2
2
  import React2, {
3
+ useImperativeHandle,
3
4
  useMemo
4
5
  } from "react";
5
6
  import { useEffect as useEffect2, useRef } from "react";
@@ -173,7 +174,7 @@ function placeholderPlugin(text) {
173
174
  }
174
175
 
175
176
  // src/text_editor_controller.tsx
176
- import { history } from "prosemirror-history";
177
+ import { history as history2 } from "prosemirror-history";
177
178
 
178
179
  // src/plugins/keymap.tsx
179
180
  import { TextSelection } from "prosemirror-state";
@@ -841,6 +842,7 @@ function createAttachFile({
841
842
  // src/commands.tsx
842
843
  import * as commands from "prosemirror-commands";
843
844
  import * as schemaList from "prosemirror-schema-list";
845
+ import * as history from "prosemirror-history";
844
846
  var createCommands = (schema, view, options = {}) => {
845
847
  {
846
848
  const isBlockTypeActive = (node, attrs, excludes = []) => {
@@ -897,6 +899,14 @@ var createCommands = (schema, view, options = {}) => {
897
899
  );
898
900
  view.dispatch(tr);
899
901
  };
902
+ const undo3 = () => {
903
+ view.focus();
904
+ history.undo(view.state, view.dispatch);
905
+ };
906
+ const redo3 = () => {
907
+ view.focus();
908
+ history.redo(view.state, view.dispatch);
909
+ };
900
910
  return {
901
911
  isBlockTypeActive,
902
912
  setBlockType: setBlockType2,
@@ -904,6 +914,8 @@ var createCommands = (schema, view, options = {}) => {
904
914
  toggleMark: toggleMark2,
905
915
  wrapInList: wrapInList2,
906
916
  clear,
917
+ undo: undo3,
918
+ redo: redo3,
907
919
  attachFile: (files) => {
908
920
  options.attachFile?.(view, files);
909
921
  }
@@ -922,6 +934,7 @@ var TextEditorController = class {
922
934
  view;
923
935
  prosemirrorParser;
924
936
  prosemirrorSerializer;
937
+ element;
925
938
  get value() {
926
939
  if (this.props.mode === "text") {
927
940
  return this.toTextContent();
@@ -959,12 +972,13 @@ var TextEditorController = class {
959
972
  uploadFile: this.props.attachFile?.uploadFile
960
973
  })(this.view, files);
961
974
  }
962
- bind(container) {
975
+ bind(element) {
976
+ this.element = element;
963
977
  const wrapper = document.createElement("div");
964
978
  wrapper.innerHTML = this.toInnerHTML(
965
979
  this.props.defaultValue ? String(this.props.defaultValue) : ""
966
980
  );
967
- this.view = new EditorView3(container, {
981
+ this.view = new EditorView3(element, {
968
982
  ...this.props.editor,
969
983
  attributes: (state) => {
970
984
  const propsAttributes = (() => {
@@ -986,7 +1000,7 @@ var TextEditorController = class {
986
1000
  doc: this.props.state?.doc || this.prosemirrorParser.parse(wrapper),
987
1001
  plugins: [
988
1002
  ...this.props.state?.plugins || [],
989
- history({
1003
+ history2({
990
1004
  newGroupDelay: this.props.updateDelay
991
1005
  }),
992
1006
  keymap(buildKeymap(this.schema)),
@@ -1038,7 +1052,7 @@ var TextEditorController = class {
1038
1052
  this.view?.destroy();
1039
1053
  }
1040
1054
  };
1041
- var configTextEditorController = (options = {}) => {
1055
+ var configTextEditorController = (options = {} = {}) => {
1042
1056
  return (props) => new TextEditorController({
1043
1057
  ...props,
1044
1058
  className: props.className || options.className,
@@ -1050,6 +1064,7 @@ var configTextEditorController = (options = {}) => {
1050
1064
  // src/text_editor.tsx
1051
1065
  function TextEditor({
1052
1066
  controller: externalController,
1067
+ ref,
1053
1068
  name,
1054
1069
  className,
1055
1070
  autoFocus,
@@ -1080,6 +1095,7 @@ function TextEditor({
1080
1095
  []
1081
1096
  );
1082
1097
  const controller = externalController || innerController;
1098
+ useImperativeHandle(ref, () => controller, [controller]);
1083
1099
  useEffect2(() => {
1084
1100
  const container = containerRef.current;
1085
1101
  if (!container) {
@@ -1,4 +1,4 @@
1
- import React, { DetailedHTMLProps, InputHTMLAttributes } from 'react';
1
+ import React, { DetailedHTMLProps, InputHTMLAttributes, Ref } from 'react';
2
2
  import { TextEditorController, TextEditorControllerProps } from './text_editor_controller.mjs';
3
3
  import 'prosemirror-model';
4
4
  import 'prosemirror-state';
@@ -12,7 +12,8 @@ type HTMLElementProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>,
12
12
  type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
13
13
  controller?: TextEditorController;
14
14
  name?: string;
15
+ ref?: Ref<TextEditorController>;
15
16
  } & TextEditorControllerProps;
16
- declare function TextEditor({ controller: externalController, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): React.JSX.Element;
17
+ declare function TextEditor({ controller: externalController, ref, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): React.JSX.Element;
17
18
 
18
19
  export { TextEditor, type TextEditorProps };
@@ -1,4 +1,4 @@
1
- import React, { DetailedHTMLProps, InputHTMLAttributes } from 'react';
1
+ import React, { DetailedHTMLProps, InputHTMLAttributes, Ref } from 'react';
2
2
  import { TextEditorController, TextEditorControllerProps } from './text_editor_controller.js';
3
3
  import 'prosemirror-model';
4
4
  import 'prosemirror-state';
@@ -12,7 +12,8 @@ type HTMLElementProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>,
12
12
  type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
13
13
  controller?: TextEditorController;
14
14
  name?: string;
15
+ ref?: Ref<TextEditorController>;
15
16
  } & TextEditorControllerProps;
16
- declare function TextEditor({ controller: externalController, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): React.JSX.Element;
17
+ declare function TextEditor({ controller: externalController, ref, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): React.JSX.Element;
17
18
 
18
19
  export { TextEditor, type TextEditorProps };
@@ -869,6 +869,7 @@ function createAttachFile({
869
869
  // src/commands.tsx
870
870
  var commands = __toESM(require("prosemirror-commands"));
871
871
  var schemaList = __toESM(require("prosemirror-schema-list"));
872
+ var history = __toESM(require("prosemirror-history"));
872
873
  var createCommands = (schema, view, options = {}) => {
873
874
  {
874
875
  const isBlockTypeActive = (node, attrs, excludes = []) => {
@@ -925,6 +926,14 @@ var createCommands = (schema, view, options = {}) => {
925
926
  );
926
927
  view.dispatch(tr);
927
928
  };
929
+ const undo3 = () => {
930
+ view.focus();
931
+ history.undo(view.state, view.dispatch);
932
+ };
933
+ const redo3 = () => {
934
+ view.focus();
935
+ history.redo(view.state, view.dispatch);
936
+ };
928
937
  return {
929
938
  isBlockTypeActive,
930
939
  setBlockType: setBlockType2,
@@ -932,6 +941,8 @@ var createCommands = (schema, view, options = {}) => {
932
941
  toggleMark: toggleMark2,
933
942
  wrapInList: wrapInList2,
934
943
  clear,
944
+ undo: undo3,
945
+ redo: redo3,
935
946
  attachFile: (files) => {
936
947
  options.attachFile?.(view, files);
937
948
  }
@@ -950,6 +961,7 @@ var TextEditorController = class {
950
961
  view;
951
962
  prosemirrorParser;
952
963
  prosemirrorSerializer;
964
+ element;
953
965
  get value() {
954
966
  if (this.props.mode === "text") {
955
967
  return this.toTextContent();
@@ -987,12 +999,13 @@ var TextEditorController = class {
987
999
  uploadFile: this.props.attachFile?.uploadFile
988
1000
  })(this.view, files);
989
1001
  }
990
- bind(container) {
1002
+ bind(element) {
1003
+ this.element = element;
991
1004
  const wrapper = document.createElement("div");
992
1005
  wrapper.innerHTML = this.toInnerHTML(
993
1006
  this.props.defaultValue ? String(this.props.defaultValue) : ""
994
1007
  );
995
- this.view = new import_prosemirror_view4.EditorView(container, {
1008
+ this.view = new import_prosemirror_view4.EditorView(element, {
996
1009
  ...this.props.editor,
997
1010
  attributes: (state) => {
998
1011
  const propsAttributes = (() => {
@@ -1070,6 +1083,7 @@ var TextEditorController = class {
1070
1083
  // src/text_editor.tsx
1071
1084
  function TextEditor({
1072
1085
  controller: externalController,
1086
+ ref,
1073
1087
  name,
1074
1088
  className,
1075
1089
  autoFocus,
@@ -1100,6 +1114,7 @@ function TextEditor({
1100
1114
  []
1101
1115
  );
1102
1116
  const controller = externalController || innerController;
1117
+ (0, import_react2.useImperativeHandle)(ref, () => controller, [controller]);
1103
1118
  (0, import_react3.useEffect)(() => {
1104
1119
  const container = containerRef.current;
1105
1120
  if (!container) {
@@ -1,5 +1,6 @@
1
1
  // src/text_editor.tsx
2
2
  import React2, {
3
+ useImperativeHandle,
3
4
  useMemo
4
5
  } from "react";
5
6
  import { useEffect as useEffect2, useRef } from "react";
@@ -173,7 +174,7 @@ function placeholderPlugin(text) {
173
174
  }
174
175
 
175
176
  // src/text_editor_controller.tsx
176
- import { history } from "prosemirror-history";
177
+ import { history as history2 } from "prosemirror-history";
177
178
 
178
179
  // src/plugins/keymap.tsx
179
180
  import { TextSelection } from "prosemirror-state";
@@ -841,6 +842,7 @@ function createAttachFile({
841
842
  // src/commands.tsx
842
843
  import * as commands from "prosemirror-commands";
843
844
  import * as schemaList from "prosemirror-schema-list";
845
+ import * as history from "prosemirror-history";
844
846
  var createCommands = (schema, view, options = {}) => {
845
847
  {
846
848
  const isBlockTypeActive = (node, attrs, excludes = []) => {
@@ -897,6 +899,14 @@ var createCommands = (schema, view, options = {}) => {
897
899
  );
898
900
  view.dispatch(tr);
899
901
  };
902
+ const undo3 = () => {
903
+ view.focus();
904
+ history.undo(view.state, view.dispatch);
905
+ };
906
+ const redo3 = () => {
907
+ view.focus();
908
+ history.redo(view.state, view.dispatch);
909
+ };
900
910
  return {
901
911
  isBlockTypeActive,
902
912
  setBlockType: setBlockType2,
@@ -904,6 +914,8 @@ var createCommands = (schema, view, options = {}) => {
904
914
  toggleMark: toggleMark2,
905
915
  wrapInList: wrapInList2,
906
916
  clear,
917
+ undo: undo3,
918
+ redo: redo3,
907
919
  attachFile: (files) => {
908
920
  options.attachFile?.(view, files);
909
921
  }
@@ -922,6 +934,7 @@ var TextEditorController = class {
922
934
  view;
923
935
  prosemirrorParser;
924
936
  prosemirrorSerializer;
937
+ element;
925
938
  get value() {
926
939
  if (this.props.mode === "text") {
927
940
  return this.toTextContent();
@@ -959,12 +972,13 @@ var TextEditorController = class {
959
972
  uploadFile: this.props.attachFile?.uploadFile
960
973
  })(this.view, files);
961
974
  }
962
- bind(container) {
975
+ bind(element) {
976
+ this.element = element;
963
977
  const wrapper = document.createElement("div");
964
978
  wrapper.innerHTML = this.toInnerHTML(
965
979
  this.props.defaultValue ? String(this.props.defaultValue) : ""
966
980
  );
967
- this.view = new EditorView3(container, {
981
+ this.view = new EditorView3(element, {
968
982
  ...this.props.editor,
969
983
  attributes: (state) => {
970
984
  const propsAttributes = (() => {
@@ -986,7 +1000,7 @@ var TextEditorController = class {
986
1000
  doc: this.props.state?.doc || this.prosemirrorParser.parse(wrapper),
987
1001
  plugins: [
988
1002
  ...this.props.state?.plugins || [],
989
- history({
1003
+ history2({
990
1004
  newGroupDelay: this.props.updateDelay
991
1005
  }),
992
1006
  keymap(buildKeymap(this.schema)),
@@ -1042,6 +1056,7 @@ var TextEditorController = class {
1042
1056
  // src/text_editor.tsx
1043
1057
  function TextEditor({
1044
1058
  controller: externalController,
1059
+ ref,
1045
1060
  name,
1046
1061
  className,
1047
1062
  autoFocus,
@@ -1072,6 +1087,7 @@ function TextEditor({
1072
1087
  []
1073
1088
  );
1074
1089
  const controller = externalController || innerController;
1090
+ useImperativeHandle(ref, () => controller, [controller]);
1075
1091
  useEffect2(() => {
1076
1092
  const container = containerRef.current;
1077
1093
  if (!container) {
@@ -29,12 +29,13 @@ declare class TextEditorController {
29
29
  view?: EditorView;
30
30
  prosemirrorParser: DOMParser;
31
31
  prosemirrorSerializer: DOMSerializer;
32
+ element?: HTMLElement;
32
33
  get value(): string;
33
34
  set value(value: string);
34
35
  constructor(props?: TextEditorControllerProps);
35
36
  toInnerHTML(value: string): string;
36
37
  attachFile(files: File[]): Promise<void>;
37
- bind(container: HTMLElement): void;
38
+ bind(element: HTMLElement): void;
38
39
  toHTML(): string;
39
40
  toTextContent(): string;
40
41
  get commands(): {
@@ -48,6 +49,8 @@ declare class TextEditorController {
48
49
  }) => void;
49
50
  wrapInList: (listType: string, attrs?: prosemirror_model.Attrs | null) => void;
50
51
  clear: () => void;
52
+ undo: () => void;
53
+ redo: () => void;
51
54
  attachFile: (files: File[]) => void;
52
55
  };
53
56
  dispose(): void;
@@ -29,12 +29,13 @@ declare class TextEditorController {
29
29
  view?: EditorView;
30
30
  prosemirrorParser: DOMParser;
31
31
  prosemirrorSerializer: DOMSerializer;
32
+ element?: HTMLElement;
32
33
  get value(): string;
33
34
  set value(value: string);
34
35
  constructor(props?: TextEditorControllerProps);
35
36
  toInnerHTML(value: string): string;
36
37
  attachFile(files: File[]): Promise<void>;
37
- bind(container: HTMLElement): void;
38
+ bind(element: HTMLElement): void;
38
39
  toHTML(): string;
39
40
  toTextContent(): string;
40
41
  get commands(): {
@@ -48,6 +49,8 @@ declare class TextEditorController {
48
49
  }) => void;
49
50
  wrapInList: (listType: string, attrs?: prosemirror_model.Attrs | null) => void;
50
51
  clear: () => void;
52
+ undo: () => void;
53
+ redo: () => void;
51
54
  attachFile: (files: File[]) => void;
52
55
  };
53
56
  dispose(): void;
@@ -834,6 +834,7 @@ function createAttachFile({
834
834
  // src/commands.tsx
835
835
  var commands = __toESM(require("prosemirror-commands"));
836
836
  var schemaList = __toESM(require("prosemirror-schema-list"));
837
+ var history = __toESM(require("prosemirror-history"));
837
838
  var createCommands = (schema, view, options = {}) => {
838
839
  {
839
840
  const isBlockTypeActive = (node, attrs, excludes = []) => {
@@ -890,6 +891,14 @@ var createCommands = (schema, view, options = {}) => {
890
891
  );
891
892
  view.dispatch(tr);
892
893
  };
894
+ const undo3 = () => {
895
+ view.focus();
896
+ history.undo(view.state, view.dispatch);
897
+ };
898
+ const redo3 = () => {
899
+ view.focus();
900
+ history.redo(view.state, view.dispatch);
901
+ };
893
902
  return {
894
903
  isBlockTypeActive,
895
904
  setBlockType: setBlockType2,
@@ -897,6 +906,8 @@ var createCommands = (schema, view, options = {}) => {
897
906
  toggleMark: toggleMark2,
898
907
  wrapInList: wrapInList2,
899
908
  clear,
909
+ undo: undo3,
910
+ redo: redo3,
900
911
  attachFile: (files) => {
901
912
  options.attachFile?.(view, files);
902
913
  }
@@ -915,6 +926,7 @@ var TextEditorController = class {
915
926
  view;
916
927
  prosemirrorParser;
917
928
  prosemirrorSerializer;
929
+ element;
918
930
  get value() {
919
931
  if (this.props.mode === "text") {
920
932
  return this.toTextContent();
@@ -952,12 +964,13 @@ var TextEditorController = class {
952
964
  uploadFile: this.props.attachFile?.uploadFile
953
965
  })(this.view, files);
954
966
  }
955
- bind(container) {
967
+ bind(element) {
968
+ this.element = element;
956
969
  const wrapper = document.createElement("div");
957
970
  wrapper.innerHTML = this.toInnerHTML(
958
971
  this.props.defaultValue ? String(this.props.defaultValue) : ""
959
972
  );
960
- this.view = new import_prosemirror_view4.EditorView(container, {
973
+ this.view = new import_prosemirror_view4.EditorView(element, {
961
974
  ...this.props.editor,
962
975
  attributes: (state) => {
963
976
  const propsAttributes = (() => {
@@ -1031,7 +1044,7 @@ var TextEditorController = class {
1031
1044
  this.view?.destroy();
1032
1045
  }
1033
1046
  };
1034
- var configTextEditorController = (options = {}) => {
1047
+ var configTextEditorController = (options = {} = {}) => {
1035
1048
  return (props) => new TextEditorController({
1036
1049
  ...props,
1037
1050
  className: props.className || options.className,
@@ -133,7 +133,7 @@ function placeholderPlugin(text) {
133
133
  }
134
134
 
135
135
  // src/text_editor_controller.tsx
136
- import { history } from "prosemirror-history";
136
+ import { history as history2 } from "prosemirror-history";
137
137
 
138
138
  // src/plugins/keymap.tsx
139
139
  import { TextSelection } from "prosemirror-state";
@@ -801,6 +801,7 @@ function createAttachFile({
801
801
  // src/commands.tsx
802
802
  import * as commands from "prosemirror-commands";
803
803
  import * as schemaList from "prosemirror-schema-list";
804
+ import * as history from "prosemirror-history";
804
805
  var createCommands = (schema, view, options = {}) => {
805
806
  {
806
807
  const isBlockTypeActive = (node, attrs, excludes = []) => {
@@ -857,6 +858,14 @@ var createCommands = (schema, view, options = {}) => {
857
858
  );
858
859
  view.dispatch(tr);
859
860
  };
861
+ const undo3 = () => {
862
+ view.focus();
863
+ history.undo(view.state, view.dispatch);
864
+ };
865
+ const redo3 = () => {
866
+ view.focus();
867
+ history.redo(view.state, view.dispatch);
868
+ };
860
869
  return {
861
870
  isBlockTypeActive,
862
871
  setBlockType: setBlockType2,
@@ -864,6 +873,8 @@ var createCommands = (schema, view, options = {}) => {
864
873
  toggleMark: toggleMark2,
865
874
  wrapInList: wrapInList2,
866
875
  clear,
876
+ undo: undo3,
877
+ redo: redo3,
867
878
  attachFile: (files) => {
868
879
  options.attachFile?.(view, files);
869
880
  }
@@ -882,6 +893,7 @@ var TextEditorController = class {
882
893
  view;
883
894
  prosemirrorParser;
884
895
  prosemirrorSerializer;
896
+ element;
885
897
  get value() {
886
898
  if (this.props.mode === "text") {
887
899
  return this.toTextContent();
@@ -919,12 +931,13 @@ var TextEditorController = class {
919
931
  uploadFile: this.props.attachFile?.uploadFile
920
932
  })(this.view, files);
921
933
  }
922
- bind(container) {
934
+ bind(element) {
935
+ this.element = element;
923
936
  const wrapper = document.createElement("div");
924
937
  wrapper.innerHTML = this.toInnerHTML(
925
938
  this.props.defaultValue ? String(this.props.defaultValue) : ""
926
939
  );
927
- this.view = new EditorView3(container, {
940
+ this.view = new EditorView3(element, {
928
941
  ...this.props.editor,
929
942
  attributes: (state) => {
930
943
  const propsAttributes = (() => {
@@ -946,7 +959,7 @@ var TextEditorController = class {
946
959
  doc: this.props.state?.doc || this.prosemirrorParser.parse(wrapper),
947
960
  plugins: [
948
961
  ...this.props.state?.plugins || [],
949
- history({
962
+ history2({
950
963
  newGroupDelay: this.props.updateDelay
951
964
  }),
952
965
  keymap(buildKeymap(this.schema)),
@@ -998,7 +1011,7 @@ var TextEditorController = class {
998
1011
  this.view?.destroy();
999
1012
  }
1000
1013
  };
1001
- var configTextEditorController = (options = {}) => {
1014
+ var configTextEditorController = (options = {} = {}) => {
1002
1015
  return (props) => new TextEditorController({
1003
1016
  ...props,
1004
1017
  className: props.className || options.className,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dn-react-text-editor",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.js",