dn-react-text-editor 0.3.4 → 0.3.6

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/dist/index.js CHANGED
@@ -969,6 +969,7 @@ var TextEditorController = class {
969
969
  view;
970
970
  prosemirrorParser;
971
971
  prosemirrorSerializer;
972
+ element;
972
973
  get value() {
973
974
  if (this.props.mode === "text") {
974
975
  return this.toTextContent();
@@ -1006,12 +1007,13 @@ var TextEditorController = class {
1006
1007
  uploadFile: this.props.attachFile?.uploadFile
1007
1008
  })(this.view, files);
1008
1009
  }
1009
- bind(container) {
1010
+ bind(element) {
1011
+ this.element = element;
1010
1012
  const wrapper = document.createElement("div");
1011
1013
  wrapper.innerHTML = this.toInnerHTML(
1012
1014
  this.props.defaultValue ? String(this.props.defaultValue) : ""
1013
1015
  );
1014
- this.view = new import_prosemirror_view4.EditorView(container, {
1016
+ this.view = new import_prosemirror_view4.EditorView(element, {
1015
1017
  ...this.props.editor,
1016
1018
  attributes: (state) => {
1017
1019
  const propsAttributes = (() => {
@@ -1085,8 +1087,8 @@ var TextEditorController = class {
1085
1087
  this.view?.destroy();
1086
1088
  }
1087
1089
  };
1088
- var configTextEditorController = (options = {} = {}) => {
1089
- return (props) => new TextEditorController({
1090
+ var configTextEditorController = (options = {}) => {
1091
+ return (props = {}) => new TextEditorController({
1090
1092
  ...props,
1091
1093
  className: props.className || options.className,
1092
1094
  style: props.style || options.style,
@@ -1096,7 +1098,7 @@ var configTextEditorController = (options = {} = {}) => {
1096
1098
 
1097
1099
  // src/text_editor.tsx
1098
1100
  function TextEditor({
1099
- controller: externalController,
1101
+ ref,
1100
1102
  name,
1101
1103
  className,
1102
1104
  autoFocus,
@@ -1112,7 +1114,7 @@ function TextEditor({
1112
1114
  ...props
1113
1115
  } = {}) {
1114
1116
  const containerRef = (0, import_react3.useRef)(null);
1115
- const innerController = (0, import_react2.useMemo)(
1117
+ const controller = (0, import_react2.useMemo)(
1116
1118
  () => new TextEditorController({
1117
1119
  mode,
1118
1120
  state,
@@ -1126,7 +1128,7 @@ function TextEditor({
1126
1128
  }),
1127
1129
  []
1128
1130
  );
1129
- const controller = externalController || innerController;
1131
+ (0, import_react2.useImperativeHandle)(ref, () => controller, [controller]);
1130
1132
  (0, import_react3.useEffect)(() => {
1131
1133
  const container = containerRef.current;
1132
1134
  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";
@@ -933,6 +934,7 @@ var TextEditorController = class {
933
934
  view;
934
935
  prosemirrorParser;
935
936
  prosemirrorSerializer;
937
+ element;
936
938
  get value() {
937
939
  if (this.props.mode === "text") {
938
940
  return this.toTextContent();
@@ -970,12 +972,13 @@ var TextEditorController = class {
970
972
  uploadFile: this.props.attachFile?.uploadFile
971
973
  })(this.view, files);
972
974
  }
973
- bind(container) {
975
+ bind(element) {
976
+ this.element = element;
974
977
  const wrapper = document.createElement("div");
975
978
  wrapper.innerHTML = this.toInnerHTML(
976
979
  this.props.defaultValue ? String(this.props.defaultValue) : ""
977
980
  );
978
- this.view = new EditorView3(container, {
981
+ this.view = new EditorView3(element, {
979
982
  ...this.props.editor,
980
983
  attributes: (state) => {
981
984
  const propsAttributes = (() => {
@@ -1049,8 +1052,8 @@ var TextEditorController = class {
1049
1052
  this.view?.destroy();
1050
1053
  }
1051
1054
  };
1052
- var configTextEditorController = (options = {} = {}) => {
1053
- return (props) => new TextEditorController({
1055
+ var configTextEditorController = (options = {}) => {
1056
+ return (props = {}) => new TextEditorController({
1054
1057
  ...props,
1055
1058
  className: props.className || options.className,
1056
1059
  style: props.style || options.style,
@@ -1060,7 +1063,7 @@ var configTextEditorController = (options = {} = {}) => {
1060
1063
 
1061
1064
  // src/text_editor.tsx
1062
1065
  function TextEditor({
1063
- controller: externalController,
1066
+ ref,
1064
1067
  name,
1065
1068
  className,
1066
1069
  autoFocus,
@@ -1076,7 +1079,7 @@ function TextEditor({
1076
1079
  ...props
1077
1080
  } = {}) {
1078
1081
  const containerRef = useRef(null);
1079
- const innerController = useMemo(
1082
+ const controller = useMemo(
1080
1083
  () => new TextEditorController({
1081
1084
  mode,
1082
1085
  state,
@@ -1090,7 +1093,7 @@ function TextEditor({
1090
1093
  }),
1091
1094
  []
1092
1095
  );
1093
- const controller = externalController || innerController;
1096
+ useImperativeHandle(ref, () => controller, [controller]);
1094
1097
  useEffect2(() => {
1095
1098
  const container = containerRef.current;
1096
1099
  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';
@@ -10,9 +10,9 @@ import 'rxjs';
10
10
 
11
11
  type HTMLElementProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
12
12
  type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
13
- controller?: TextEditorController;
14
13
  name?: string;
14
+ ref?: Ref<TextEditorController>;
15
15
  } & TextEditorControllerProps;
16
- declare function TextEditor({ controller: externalController, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): React.JSX.Element;
16
+ declare function TextEditor({ ref, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): React.JSX.Element;
17
17
 
18
18
  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';
@@ -10,9 +10,9 @@ import 'rxjs';
10
10
 
11
11
  type HTMLElementProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
12
12
  type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
13
- controller?: TextEditorController;
14
13
  name?: string;
14
+ ref?: Ref<TextEditorController>;
15
15
  } & TextEditorControllerProps;
16
- declare function TextEditor({ controller: externalController, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): React.JSX.Element;
16
+ declare function TextEditor({ ref, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): React.JSX.Element;
17
17
 
18
18
  export { TextEditor, type TextEditorProps };
@@ -961,6 +961,7 @@ var TextEditorController = class {
961
961
  view;
962
962
  prosemirrorParser;
963
963
  prosemirrorSerializer;
964
+ element;
964
965
  get value() {
965
966
  if (this.props.mode === "text") {
966
967
  return this.toTextContent();
@@ -998,12 +999,13 @@ var TextEditorController = class {
998
999
  uploadFile: this.props.attachFile?.uploadFile
999
1000
  })(this.view, files);
1000
1001
  }
1001
- bind(container) {
1002
+ bind(element) {
1003
+ this.element = element;
1002
1004
  const wrapper = document.createElement("div");
1003
1005
  wrapper.innerHTML = this.toInnerHTML(
1004
1006
  this.props.defaultValue ? String(this.props.defaultValue) : ""
1005
1007
  );
1006
- this.view = new import_prosemirror_view4.EditorView(container, {
1008
+ this.view = new import_prosemirror_view4.EditorView(element, {
1007
1009
  ...this.props.editor,
1008
1010
  attributes: (state) => {
1009
1011
  const propsAttributes = (() => {
@@ -1080,7 +1082,7 @@ var TextEditorController = class {
1080
1082
 
1081
1083
  // src/text_editor.tsx
1082
1084
  function TextEditor({
1083
- controller: externalController,
1085
+ ref,
1084
1086
  name,
1085
1087
  className,
1086
1088
  autoFocus,
@@ -1096,7 +1098,7 @@ function TextEditor({
1096
1098
  ...props
1097
1099
  } = {}) {
1098
1100
  const containerRef = (0, import_react3.useRef)(null);
1099
- const innerController = (0, import_react2.useMemo)(
1101
+ const controller = (0, import_react2.useMemo)(
1100
1102
  () => new TextEditorController({
1101
1103
  mode,
1102
1104
  state,
@@ -1110,7 +1112,7 @@ function TextEditor({
1110
1112
  }),
1111
1113
  []
1112
1114
  );
1113
- const controller = externalController || innerController;
1115
+ (0, import_react2.useImperativeHandle)(ref, () => controller, [controller]);
1114
1116
  (0, import_react3.useEffect)(() => {
1115
1117
  const container = containerRef.current;
1116
1118
  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";
@@ -933,6 +934,7 @@ var TextEditorController = class {
933
934
  view;
934
935
  prosemirrorParser;
935
936
  prosemirrorSerializer;
937
+ element;
936
938
  get value() {
937
939
  if (this.props.mode === "text") {
938
940
  return this.toTextContent();
@@ -970,12 +972,13 @@ var TextEditorController = class {
970
972
  uploadFile: this.props.attachFile?.uploadFile
971
973
  })(this.view, files);
972
974
  }
973
- bind(container) {
975
+ bind(element) {
976
+ this.element = element;
974
977
  const wrapper = document.createElement("div");
975
978
  wrapper.innerHTML = this.toInnerHTML(
976
979
  this.props.defaultValue ? String(this.props.defaultValue) : ""
977
980
  );
978
- this.view = new EditorView3(container, {
981
+ this.view = new EditorView3(element, {
979
982
  ...this.props.editor,
980
983
  attributes: (state) => {
981
984
  const propsAttributes = (() => {
@@ -1052,7 +1055,7 @@ var TextEditorController = class {
1052
1055
 
1053
1056
  // src/text_editor.tsx
1054
1057
  function TextEditor({
1055
- controller: externalController,
1058
+ ref,
1056
1059
  name,
1057
1060
  className,
1058
1061
  autoFocus,
@@ -1068,7 +1071,7 @@ function TextEditor({
1068
1071
  ...props
1069
1072
  } = {}) {
1070
1073
  const containerRef = useRef(null);
1071
- const innerController = useMemo(
1074
+ const controller = useMemo(
1072
1075
  () => new TextEditorController({
1073
1076
  mode,
1074
1077
  state,
@@ -1082,7 +1085,7 @@ function TextEditor({
1082
1085
  }),
1083
1086
  []
1084
1087
  );
1085
- const controller = externalController || innerController;
1088
+ useImperativeHandle(ref, () => controller, [controller]);
1086
1089
  useEffect2(() => {
1087
1090
  const container = containerRef.current;
1088
1091
  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(): {
@@ -55,6 +56,6 @@ declare class TextEditorController {
55
56
  dispose(): void;
56
57
  }
57
58
  type ConfigTextEditorOptions = Pick<TextEditorControllerProps, "className" | "style" | "attachFile">;
58
- declare const configTextEditorController: (options?: ConfigTextEditorOptions) => (props: TextEditorControllerProps) => TextEditorController;
59
+ declare const configTextEditorController: (options?: ConfigTextEditorOptions) => (props?: TextEditorControllerProps) => TextEditorController;
59
60
 
60
61
  export { type ConfigTextEditorOptions, TextEditorController, type TextEditorControllerProps, configTextEditorController };
@@ -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(): {
@@ -55,6 +56,6 @@ declare class TextEditorController {
55
56
  dispose(): void;
56
57
  }
57
58
  type ConfigTextEditorOptions = Pick<TextEditorControllerProps, "className" | "style" | "attachFile">;
58
- declare const configTextEditorController: (options?: ConfigTextEditorOptions) => (props: TextEditorControllerProps) => TextEditorController;
59
+ declare const configTextEditorController: (options?: ConfigTextEditorOptions) => (props?: TextEditorControllerProps) => TextEditorController;
59
60
 
60
61
  export { type ConfigTextEditorOptions, TextEditorController, type TextEditorControllerProps, configTextEditorController };
@@ -926,6 +926,7 @@ var TextEditorController = class {
926
926
  view;
927
927
  prosemirrorParser;
928
928
  prosemirrorSerializer;
929
+ element;
929
930
  get value() {
930
931
  if (this.props.mode === "text") {
931
932
  return this.toTextContent();
@@ -963,12 +964,13 @@ var TextEditorController = class {
963
964
  uploadFile: this.props.attachFile?.uploadFile
964
965
  })(this.view, files);
965
966
  }
966
- bind(container) {
967
+ bind(element) {
968
+ this.element = element;
967
969
  const wrapper = document.createElement("div");
968
970
  wrapper.innerHTML = this.toInnerHTML(
969
971
  this.props.defaultValue ? String(this.props.defaultValue) : ""
970
972
  );
971
- this.view = new import_prosemirror_view4.EditorView(container, {
973
+ this.view = new import_prosemirror_view4.EditorView(element, {
972
974
  ...this.props.editor,
973
975
  attributes: (state) => {
974
976
  const propsAttributes = (() => {
@@ -1042,8 +1044,8 @@ var TextEditorController = class {
1042
1044
  this.view?.destroy();
1043
1045
  }
1044
1046
  };
1045
- var configTextEditorController = (options = {} = {}) => {
1046
- return (props) => new TextEditorController({
1047
+ var configTextEditorController = (options = {}) => {
1048
+ return (props = {}) => new TextEditorController({
1047
1049
  ...props,
1048
1050
  className: props.className || options.className,
1049
1051
  style: props.style || options.style,
@@ -893,6 +893,7 @@ var TextEditorController = class {
893
893
  view;
894
894
  prosemirrorParser;
895
895
  prosemirrorSerializer;
896
+ element;
896
897
  get value() {
897
898
  if (this.props.mode === "text") {
898
899
  return this.toTextContent();
@@ -930,12 +931,13 @@ var TextEditorController = class {
930
931
  uploadFile: this.props.attachFile?.uploadFile
931
932
  })(this.view, files);
932
933
  }
933
- bind(container) {
934
+ bind(element) {
935
+ this.element = element;
934
936
  const wrapper = document.createElement("div");
935
937
  wrapper.innerHTML = this.toInnerHTML(
936
938
  this.props.defaultValue ? String(this.props.defaultValue) : ""
937
939
  );
938
- this.view = new EditorView3(container, {
940
+ this.view = new EditorView3(element, {
939
941
  ...this.props.editor,
940
942
  attributes: (state) => {
941
943
  const propsAttributes = (() => {
@@ -1009,8 +1011,8 @@ var TextEditorController = class {
1009
1011
  this.view?.destroy();
1010
1012
  }
1011
1013
  };
1012
- var configTextEditorController = (options = {} = {}) => {
1013
- return (props) => new TextEditorController({
1014
+ var configTextEditorController = (options = {}) => {
1015
+ return (props = {}) => new TextEditorController({
1014
1016
  ...props,
1015
1017
  className: props.className || options.className,
1016
1018
  style: props.style || options.style,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dn-react-text-editor",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.js",