dn-react-text-editor 0.3.7 → 0.3.10

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.d.mts CHANGED
@@ -5,6 +5,7 @@ export { createInnerHTML, createTextEditorView } from './html.mjs';
5
5
  export { ConfigTextEditorOptions, TextEditorController, TextEditorControllerProps, configTextEditorController } from './text_editor_controller.mjs';
6
6
  import 'react/jsx-runtime';
7
7
  import 'react';
8
+ import './input.mjs';
8
9
  import 'orderedmap';
9
10
  import 'prosemirror-model';
10
11
  import 'prosemirror-view';
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { createInnerHTML, createTextEditorView } from './html.js';
5
5
  export { ConfigTextEditorOptions, TextEditorController, TextEditorControllerProps, configTextEditorController } from './text_editor_controller.js';
6
6
  import 'react/jsx-runtime';
7
7
  import 'react';
8
+ import './input.js';
8
9
  import 'orderedmap';
9
10
  import 'prosemirror-model';
10
11
  import 'prosemirror-view';
package/dist/index.js CHANGED
@@ -55,11 +55,10 @@ function TextEditorInput({ controller, onChange, ...props }) {
55
55
  (0, import_rxjs.filter)((tr) => tr.docChanged),
56
56
  (0, import_rxjs.debounceTime)(controller.props.updateDelay || 0)
57
57
  ).subscribe(() => {
58
- if (inputRef.current) {
59
- inputRef.current.value = controller.value;
60
- const event = new Event("input", { bubbles: true });
61
- inputRef.current.dispatchEvent(event);
62
- }
58
+ const input = inputRef.current;
59
+ if (!input) return;
60
+ input.value = controller.value;
61
+ onChange?.(controller.value);
63
62
  });
64
63
  return () => {
65
64
  sub.unsubscribe();
@@ -71,7 +70,6 @@ function TextEditorInput({ controller, onChange, ...props }) {
71
70
  ...props,
72
71
  ref: inputRef,
73
72
  type: "hidden",
74
- onInput: onChange,
75
73
  defaultValue: controller.props.defaultValue
76
74
  }
77
75
  );
@@ -989,7 +987,7 @@ var TextEditorController = class {
989
987
  this.view.dispatch(tr);
990
988
  }
991
989
  constructor(props = {}) {
992
- this.schema = createSchema();
990
+ this.schema = props.schema || createSchema();
993
991
  this.props = props;
994
992
  this.subject = new import_rxjs2.Subject();
995
993
  this.prosemirrorParser = import_prosemirror_model3.DOMParser.fromSchema(this.schema);
@@ -1131,7 +1129,7 @@ function TextEditor({
1131
1129
  []
1132
1130
  );
1133
1131
  (0, import_react2.useImperativeHandle)(ref, () => controller, [controller]);
1134
- (0, import_react3.useEffect)(() => {
1132
+ (0, import_react2.useLayoutEffect)(() => {
1135
1133
  const container = containerRef.current;
1136
1134
  if (!container) {
1137
1135
  return;
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  // src/text_editor.tsx
2
2
  import {
3
3
  useImperativeHandle,
4
+ useLayoutEffect,
4
5
  useMemo
5
6
  } from "react";
6
- import { useEffect as useEffect2, useRef as useRef2 } from "react";
7
+ import { useRef as useRef2 } from "react";
7
8
 
8
9
  // src/input.tsx
9
10
  import {
@@ -19,11 +20,10 @@ function TextEditorInput({ controller, onChange, ...props }) {
19
20
  filter((tr) => tr.docChanged),
20
21
  debounceTime(controller.props.updateDelay || 0)
21
22
  ).subscribe(() => {
22
- if (inputRef.current) {
23
- inputRef.current.value = controller.value;
24
- const event = new Event("input", { bubbles: true });
25
- inputRef.current.dispatchEvent(event);
26
- }
23
+ const input = inputRef.current;
24
+ if (!input) return;
25
+ input.value = controller.value;
26
+ onChange?.(controller.value);
27
27
  });
28
28
  return () => {
29
29
  sub.unsubscribe();
@@ -35,7 +35,6 @@ function TextEditorInput({ controller, onChange, ...props }) {
35
35
  ...props,
36
36
  ref: inputRef,
37
37
  type: "hidden",
38
- onInput: onChange,
39
38
  defaultValue: controller.props.defaultValue
40
39
  }
41
40
  );
@@ -955,7 +954,7 @@ var TextEditorController = class {
955
954
  this.view.dispatch(tr);
956
955
  }
957
956
  constructor(props = {}) {
958
- this.schema = createSchema();
957
+ this.schema = props.schema || createSchema();
959
958
  this.props = props;
960
959
  this.subject = new Subject();
961
960
  this.prosemirrorParser = DOMParser.fromSchema(this.schema);
@@ -1097,7 +1096,7 @@ function TextEditor({
1097
1096
  []
1098
1097
  );
1099
1098
  useImperativeHandle(ref, () => controller, [controller]);
1100
- useEffect2(() => {
1099
+ useLayoutEffect(() => {
1101
1100
  const container = containerRef.current;
1102
1101
  if (!container) {
1103
1102
  return;
package/dist/input.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { DetailedHTMLProps, HTMLAttributes, ChangeEvent } from 'react';
2
+ import { DetailedHTMLProps, HTMLAttributes } from 'react';
3
3
  import { TextEditorController } from './text_editor_controller.mjs';
4
4
  import 'prosemirror-model';
5
5
  import 'prosemirror-state';
@@ -9,10 +9,10 @@ import './schema.mjs';
9
9
  import 'orderedmap';
10
10
  import 'rxjs';
11
11
 
12
- type Props = Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
12
+ type Props = Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref" | "onChange"> & {
13
13
  controller: TextEditorController;
14
14
  name?: string;
15
- onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
15
+ onChange?: (value: string) => void;
16
16
  };
17
17
  declare function TextEditorInput({ controller, onChange, ...props }: Props): react_jsx_runtime.JSX.Element;
18
18
 
package/dist/input.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { DetailedHTMLProps, HTMLAttributes, ChangeEvent } from 'react';
2
+ import { DetailedHTMLProps, HTMLAttributes } from 'react';
3
3
  import { TextEditorController } from './text_editor_controller.js';
4
4
  import 'prosemirror-model';
5
5
  import 'prosemirror-state';
@@ -9,10 +9,10 @@ import './schema.js';
9
9
  import 'orderedmap';
10
10
  import 'rxjs';
11
11
 
12
- type Props = Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
12
+ type Props = Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref" | "onChange"> & {
13
13
  controller: TextEditorController;
14
14
  name?: string;
15
- onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
15
+ onChange?: (value: string) => void;
16
16
  };
17
17
  declare function TextEditorInput({ controller, onChange, ...props }: Props): react_jsx_runtime.JSX.Element;
18
18
 
package/dist/input.js CHANGED
@@ -33,11 +33,10 @@ function TextEditorInput({ controller, onChange, ...props }) {
33
33
  (0, import_rxjs.filter)((tr) => tr.docChanged),
34
34
  (0, import_rxjs.debounceTime)(controller.props.updateDelay || 0)
35
35
  ).subscribe(() => {
36
- if (inputRef.current) {
37
- inputRef.current.value = controller.value;
38
- const event = new Event("input", { bubbles: true });
39
- inputRef.current.dispatchEvent(event);
40
- }
36
+ const input = inputRef.current;
37
+ if (!input) return;
38
+ input.value = controller.value;
39
+ onChange?.(controller.value);
41
40
  });
42
41
  return () => {
43
42
  sub.unsubscribe();
@@ -49,7 +48,6 @@ function TextEditorInput({ controller, onChange, ...props }) {
49
48
  ...props,
50
49
  ref: inputRef,
51
50
  type: "hidden",
52
- onInput: onChange,
53
51
  defaultValue: controller.props.defaultValue
54
52
  }
55
53
  );
package/dist/input.mjs CHANGED
@@ -12,11 +12,10 @@ function TextEditorInput({ controller, onChange, ...props }) {
12
12
  filter((tr) => tr.docChanged),
13
13
  debounceTime(controller.props.updateDelay || 0)
14
14
  ).subscribe(() => {
15
- if (inputRef.current) {
16
- inputRef.current.value = controller.value;
17
- const event = new Event("input", { bubbles: true });
18
- inputRef.current.dispatchEvent(event);
19
- }
15
+ const input = inputRef.current;
16
+ if (!input) return;
17
+ input.value = controller.value;
18
+ onChange?.(controller.value);
20
19
  });
21
20
  return () => {
22
21
  sub.unsubscribe();
@@ -28,7 +27,6 @@ function TextEditorInput({ controller, onChange, ...props }) {
28
27
  ...props,
29
28
  ref: inputRef,
30
29
  type: "hidden",
31
- onInput: onChange,
32
30
  defaultValue: controller.props.defaultValue
33
31
  }
34
32
  );
@@ -1,4 +1,4 @@
1
- import { Plugin, EditorState } from 'prosemirror-state';
1
+ import { EditorState, Plugin } from 'prosemirror-state';
2
2
  import { DecorationSet } from 'prosemirror-view';
3
3
 
4
4
  declare const uploadPlaceholderPlugin: Plugin<DecorationSet>;
@@ -1,4 +1,4 @@
1
- import { Plugin, EditorState } from 'prosemirror-state';
1
+ import { EditorState, Plugin } from 'prosemirror-state';
2
2
  import { DecorationSet } from 'prosemirror-view';
3
3
 
4
4
  declare const uploadPlaceholderPlugin: Plugin<DecorationSet>;
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { DetailedHTMLProps, InputHTMLAttributes, Ref } from 'react';
3
+ import { TextEditorInput } from './input.mjs';
3
4
  import { TextEditorController, TextEditorControllerProps } from './text_editor_controller.mjs';
4
5
  import 'prosemirror-model';
5
6
  import 'prosemirror-state';
@@ -10,9 +11,10 @@ import 'orderedmap';
10
11
  import 'rxjs';
11
12
 
12
13
  type HTMLElementProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
13
- type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
14
+ type TextEditorProps = Omit<HTMLElementProps, "ref" | "onChange"> & {
14
15
  name?: string;
15
16
  ref?: Ref<TextEditorController>;
17
+ onChange?: Parameters<typeof TextEditorInput>[0]["onChange"];
16
18
  } & TextEditorControllerProps;
17
19
  declare function TextEditor({ ref, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): react_jsx_runtime.JSX.Element;
18
20
 
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { DetailedHTMLProps, InputHTMLAttributes, Ref } from 'react';
3
+ import { TextEditorInput } from './input.js';
3
4
  import { TextEditorController, TextEditorControllerProps } from './text_editor_controller.js';
4
5
  import 'prosemirror-model';
5
6
  import 'prosemirror-state';
@@ -10,9 +11,10 @@ import 'orderedmap';
10
11
  import 'rxjs';
11
12
 
12
13
  type HTMLElementProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
13
- type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
14
+ type TextEditorProps = Omit<HTMLElementProps, "ref" | "onChange"> & {
14
15
  name?: string;
15
16
  ref?: Ref<TextEditorController>;
17
+ onChange?: Parameters<typeof TextEditorInput>[0]["onChange"];
16
18
  } & TextEditorControllerProps;
17
19
  declare function TextEditor({ ref, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): react_jsx_runtime.JSX.Element;
18
20
 
@@ -47,11 +47,10 @@ function TextEditorInput({ controller, onChange, ...props }) {
47
47
  (0, import_rxjs.filter)((tr) => tr.docChanged),
48
48
  (0, import_rxjs.debounceTime)(controller.props.updateDelay || 0)
49
49
  ).subscribe(() => {
50
- if (inputRef.current) {
51
- inputRef.current.value = controller.value;
52
- const event = new Event("input", { bubbles: true });
53
- inputRef.current.dispatchEvent(event);
54
- }
50
+ const input = inputRef.current;
51
+ if (!input) return;
52
+ input.value = controller.value;
53
+ onChange?.(controller.value);
55
54
  });
56
55
  return () => {
57
56
  sub.unsubscribe();
@@ -63,7 +62,6 @@ function TextEditorInput({ controller, onChange, ...props }) {
63
62
  ...props,
64
63
  ref: inputRef,
65
64
  type: "hidden",
66
- onInput: onChange,
67
65
  defaultValue: controller.props.defaultValue
68
66
  }
69
67
  );
@@ -981,7 +979,7 @@ var TextEditorController = class {
981
979
  this.view.dispatch(tr);
982
980
  }
983
981
  constructor(props = {}) {
984
- this.schema = createSchema();
982
+ this.schema = props.schema || createSchema();
985
983
  this.props = props;
986
984
  this.subject = new import_rxjs2.Subject();
987
985
  this.prosemirrorParser = import_prosemirror_model3.DOMParser.fromSchema(this.schema);
@@ -1115,7 +1113,7 @@ function TextEditor({
1115
1113
  []
1116
1114
  );
1117
1115
  (0, import_react2.useImperativeHandle)(ref, () => controller, [controller]);
1118
- (0, import_react3.useEffect)(() => {
1116
+ (0, import_react2.useLayoutEffect)(() => {
1119
1117
  const container = containerRef.current;
1120
1118
  if (!container) {
1121
1119
  return;
@@ -1,9 +1,10 @@
1
1
  // src/text_editor.tsx
2
2
  import {
3
3
  useImperativeHandle,
4
+ useLayoutEffect,
4
5
  useMemo
5
6
  } from "react";
6
- import { useEffect as useEffect2, useRef as useRef2 } from "react";
7
+ import { useRef as useRef2 } from "react";
7
8
 
8
9
  // src/input.tsx
9
10
  import {
@@ -19,11 +20,10 @@ function TextEditorInput({ controller, onChange, ...props }) {
19
20
  filter((tr) => tr.docChanged),
20
21
  debounceTime(controller.props.updateDelay || 0)
21
22
  ).subscribe(() => {
22
- if (inputRef.current) {
23
- inputRef.current.value = controller.value;
24
- const event = new Event("input", { bubbles: true });
25
- inputRef.current.dispatchEvent(event);
26
- }
23
+ const input = inputRef.current;
24
+ if (!input) return;
25
+ input.value = controller.value;
26
+ onChange?.(controller.value);
27
27
  });
28
28
  return () => {
29
29
  sub.unsubscribe();
@@ -35,7 +35,6 @@ function TextEditorInput({ controller, onChange, ...props }) {
35
35
  ...props,
36
36
  ref: inputRef,
37
37
  type: "hidden",
38
- onInput: onChange,
39
38
  defaultValue: controller.props.defaultValue
40
39
  }
41
40
  );
@@ -955,7 +954,7 @@ var TextEditorController = class {
955
954
  this.view.dispatch(tr);
956
955
  }
957
956
  constructor(props = {}) {
958
- this.schema = createSchema();
957
+ this.schema = props.schema || createSchema();
959
958
  this.props = props;
960
959
  this.subject = new Subject();
961
960
  this.prosemirrorParser = DOMParser.fromSchema(this.schema);
@@ -1089,7 +1088,7 @@ function TextEditor({
1089
1088
  []
1090
1089
  );
1091
1090
  useImperativeHandle(ref, () => controller, [controller]);
1092
- useEffect2(() => {
1091
+ useLayoutEffect(() => {
1093
1092
  const container = containerRef.current;
1094
1093
  if (!container) {
1095
1094
  return;
@@ -8,6 +8,7 @@ import './schema.mjs';
8
8
  import 'orderedmap';
9
9
 
10
10
  type TextEditorControllerProps = {
11
+ schema?: Schema;
11
12
  mode?: "html" | "text";
12
13
  state?: Partial<EditorStateConfig>;
13
14
  editor?: Partial<DirectEditorProps>;
@@ -8,6 +8,7 @@ import './schema.js';
8
8
  import 'orderedmap';
9
9
 
10
10
  type TextEditorControllerProps = {
11
+ schema?: Schema;
11
12
  mode?: "html" | "text";
12
13
  state?: Partial<EditorStateConfig>;
13
14
  editor?: Partial<DirectEditorProps>;
@@ -945,7 +945,7 @@ var TextEditorController = class {
945
945
  this.view.dispatch(tr);
946
946
  }
947
947
  constructor(props = {}) {
948
- this.schema = createSchema();
948
+ this.schema = props.schema || createSchema();
949
949
  this.props = props;
950
950
  this.subject = new import_rxjs.Subject();
951
951
  this.prosemirrorParser = import_prosemirror_model3.DOMParser.fromSchema(this.schema);
@@ -912,7 +912,7 @@ var TextEditorController = class {
912
912
  this.view.dispatch(tr);
913
913
  }
914
914
  constructor(props = {}) {
915
- this.schema = createSchema();
915
+ this.schema = props.schema || createSchema();
916
916
  this.props = props;
917
917
  this.subject = new Subject();
918
918
  this.prosemirrorParser = DOMParser.fromSchema(this.schema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dn-react-text-editor",
3
- "version": "0.3.7",
3
+ "version": "0.3.10",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.js",