dn-react-text-editor 0.3.6 → 0.3.9

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/html.d.mts CHANGED
@@ -1,8 +1,9 @@
1
- import React, { DetailedHTMLProps } from 'react';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { DetailedHTMLProps, HTMLAttributes } from 'react';
2
3
 
3
4
  declare function createInnerHTML(raw: string): string;
4
5
  declare function createTextEditorView(options?: {
5
6
  className?: string;
6
- }): ({ className, dangerouslySetInnerHTML, ...props }: DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>) => React.JSX.Element;
7
+ }): ({ className, dangerouslySetInnerHTML, ...props }: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>) => react_jsx_runtime.JSX.Element;
7
8
 
8
9
  export { createInnerHTML, createTextEditorView };
package/dist/html.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import React, { DetailedHTMLProps } from 'react';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { DetailedHTMLProps, HTMLAttributes } from 'react';
2
3
 
3
4
  declare function createInnerHTML(raw: string): string;
4
5
  declare function createTextEditorView(options?: {
5
6
  className?: string;
6
- }): ({ className, dangerouslySetInnerHTML, ...props }: DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>) => React.JSX.Element;
7
+ }): ({ className, dangerouslySetInnerHTML, ...props }: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>) => react_jsx_runtime.JSX.Element;
7
8
 
8
9
  export { createInnerHTML, createTextEditorView };
package/dist/html.js CHANGED
@@ -88,7 +88,7 @@ function cn(...classes) {
88
88
  }
89
89
 
90
90
  // src/html.tsx
91
- var import_react = __toESM(require("react"));
91
+ var import_jsx_runtime = require("react/jsx-runtime");
92
92
  function createInnerHTML(raw) {
93
93
  return raw.replace(/<\/p>/g, "<br></p>").replace(/(<p><br><\/p>)+$/g, "").replace(
94
94
  /<code class="language-(\w+)">([\s\S]*?)<\/code>/g,
@@ -116,7 +116,7 @@ function createTextEditorView(options = {}) {
116
116
  dangerouslySetInnerHTML,
117
117
  ...props
118
118
  }) {
119
- return /* @__PURE__ */ import_react.default.createElement(
119
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
120
120
  "div",
121
121
  {
122
122
  ...props,
package/dist/html.mjs CHANGED
@@ -51,7 +51,7 @@ function cn(...classes) {
51
51
  }
52
52
 
53
53
  // src/html.tsx
54
- import React from "react";
54
+ import { jsx } from "react/jsx-runtime";
55
55
  function createInnerHTML(raw) {
56
56
  return raw.replace(/<\/p>/g, "<br></p>").replace(/(<p><br><\/p>)+$/g, "").replace(
57
57
  /<code class="language-(\w+)">([\s\S]*?)<\/code>/g,
@@ -79,7 +79,7 @@ function createTextEditorView(options = {}) {
79
79
  dangerouslySetInnerHTML,
80
80
  ...props
81
81
  }) {
82
- return /* @__PURE__ */ React.createElement(
82
+ return /* @__PURE__ */ jsx(
83
83
  "div",
84
84
  {
85
85
  ...props,
package/dist/index.d.mts CHANGED
@@ -3,7 +3,9 @@ export { createSchema } from './schema.mjs';
3
3
  export { AttachFile, AttachFileOptions, GenerateMetadata, UploadFile, createAttachFile } from './attach_file.mjs';
4
4
  export { createInnerHTML, createTextEditorView } from './html.mjs';
5
5
  export { ConfigTextEditorOptions, TextEditorController, TextEditorControllerProps, configTextEditorController } from './text_editor_controller.mjs';
6
+ import 'react/jsx-runtime';
6
7
  import 'react';
8
+ import './input.mjs';
7
9
  import 'orderedmap';
8
10
  import 'prosemirror-model';
9
11
  import 'prosemirror-view';
package/dist/index.d.ts CHANGED
@@ -3,7 +3,9 @@ export { createSchema } from './schema.js';
3
3
  export { AttachFile, AttachFileOptions, GenerateMetadata, UploadFile, createAttachFile } from './attach_file.js';
4
4
  export { createInnerHTML, createTextEditorView } from './html.js';
5
5
  export { ConfigTextEditorOptions, TextEditorController, TextEditorControllerProps, configTextEditorController } from './text_editor_controller.js';
6
+ import 'react/jsx-runtime';
6
7
  import 'react';
8
+ import './input.js';
7
9
  import 'orderedmap';
8
10
  import 'prosemirror-model';
9
11
  import 'prosemirror-view';
package/dist/index.js CHANGED
@@ -41,36 +41,35 @@ __export(index_exports, {
41
41
  module.exports = __toCommonJS(index_exports);
42
42
 
43
43
  // src/text_editor.tsx
44
- var import_react2 = __toESM(require("react"));
44
+ var import_react2 = require("react");
45
45
  var import_react3 = require("react");
46
46
 
47
47
  // src/input.tsx
48
- var import_react = __toESM(require("react"));
48
+ var import_react = require("react");
49
49
  var import_rxjs = require("rxjs");
50
+ var import_jsx_runtime = require("react/jsx-runtime");
50
51
  function TextEditorInput({ controller, onChange, ...props }) {
51
- const inputRef = import_react.default.useRef(null);
52
+ const inputRef = (0, import_react.useRef)(null);
52
53
  (0, import_react.useEffect)(() => {
53
54
  const sub = controller.subject.pipe(
54
55
  (0, import_rxjs.filter)((tr) => tr.docChanged),
55
56
  (0, import_rxjs.debounceTime)(controller.props.updateDelay || 0)
56
57
  ).subscribe(() => {
57
- if (inputRef.current) {
58
- inputRef.current.value = controller.value;
59
- const event = new Event("input", { bubbles: true });
60
- inputRef.current.dispatchEvent(event);
61
- }
58
+ const input = inputRef.current;
59
+ if (!input) return;
60
+ input.value = controller.value;
61
+ onChange?.(controller.value);
62
62
  });
63
63
  return () => {
64
64
  sub.unsubscribe();
65
65
  };
66
66
  }, []);
67
- return /* @__PURE__ */ import_react.default.createElement(
67
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
68
68
  "input",
69
69
  {
70
70
  ...props,
71
71
  ref: inputRef,
72
72
  type: "hidden",
73
- onInput: onChange,
74
73
  defaultValue: controller.props.defaultValue
75
74
  }
76
75
  );
@@ -1097,6 +1096,7 @@ var configTextEditorController = (options = {}) => {
1097
1096
  };
1098
1097
 
1099
1098
  // src/text_editor.tsx
1099
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1100
1100
  function TextEditor({
1101
1101
  ref,
1102
1102
  name,
@@ -1129,7 +1129,7 @@ function TextEditor({
1129
1129
  []
1130
1130
  );
1131
1131
  (0, import_react2.useImperativeHandle)(ref, () => controller, [controller]);
1132
- (0, import_react3.useEffect)(() => {
1132
+ (0, import_react2.useLayoutEffect)(() => {
1133
1133
  const container = containerRef.current;
1134
1134
  if (!container) {
1135
1135
  return;
@@ -1139,19 +1139,22 @@ function TextEditor({
1139
1139
  controller.dispose();
1140
1140
  };
1141
1141
  }, [controller]);
1142
- return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement("div", { ...props, ref: containerRef, className }), /* @__PURE__ */ import_react2.default.createElement(
1143
- TextEditorInput,
1144
- {
1145
- name,
1146
- controller,
1147
- onChange
1148
- }
1149
- ));
1142
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1143
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...props, ref: containerRef, className }),
1144
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1145
+ TextEditorInput,
1146
+ {
1147
+ name,
1148
+ controller,
1149
+ onChange
1150
+ }
1151
+ )
1152
+ ] });
1150
1153
  }
1151
1154
 
1152
1155
  // src/html.tsx
1153
1156
  var import_html_entities = require("html-entities");
1154
- var import_react4 = __toESM(require("react"));
1157
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1155
1158
  function createInnerHTML(raw) {
1156
1159
  return raw.replace(/<\/p>/g, "<br></p>").replace(/(<p><br><\/p>)+$/g, "").replace(
1157
1160
  /<code class="language-(\w+)">([\s\S]*?)<\/code>/g,
@@ -1179,7 +1182,7 @@ function createTextEditorView(options = {}) {
1179
1182
  dangerouslySetInnerHTML,
1180
1183
  ...props
1181
1184
  }) {
1182
- return /* @__PURE__ */ import_react4.default.createElement(
1185
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1183
1186
  "div",
1184
1187
  {
1185
1188
  ...props,
package/dist/index.mjs CHANGED
@@ -1,39 +1,40 @@
1
1
  // src/text_editor.tsx
2
- import React2, {
2
+ import {
3
3
  useImperativeHandle,
4
+ useLayoutEffect,
4
5
  useMemo
5
6
  } from "react";
6
- import { useEffect as useEffect2, useRef } from "react";
7
+ import { useRef as useRef2 } from "react";
7
8
 
8
9
  // src/input.tsx
9
- import React, {
10
- useEffect
10
+ import {
11
+ useEffect,
12
+ useRef
11
13
  } from "react";
12
14
  import { debounceTime, filter } from "rxjs";
15
+ import { jsx } from "react/jsx-runtime";
13
16
  function TextEditorInput({ controller, onChange, ...props }) {
14
- const inputRef = React.useRef(null);
17
+ const inputRef = useRef(null);
15
18
  useEffect(() => {
16
19
  const sub = controller.subject.pipe(
17
20
  filter((tr) => tr.docChanged),
18
21
  debounceTime(controller.props.updateDelay || 0)
19
22
  ).subscribe(() => {
20
- if (inputRef.current) {
21
- inputRef.current.value = controller.value;
22
- const event = new Event("input", { bubbles: true });
23
- inputRef.current.dispatchEvent(event);
24
- }
23
+ const input = inputRef.current;
24
+ if (!input) return;
25
+ input.value = controller.value;
26
+ onChange?.(controller.value);
25
27
  });
26
28
  return () => {
27
29
  sub.unsubscribe();
28
30
  };
29
31
  }, []);
30
- return /* @__PURE__ */ React.createElement(
32
+ return /* @__PURE__ */ jsx(
31
33
  "input",
32
34
  {
33
35
  ...props,
34
36
  ref: inputRef,
35
37
  type: "hidden",
36
- onInput: onChange,
37
38
  defaultValue: controller.props.defaultValue
38
39
  }
39
40
  );
@@ -1062,6 +1063,7 @@ var configTextEditorController = (options = {}) => {
1062
1063
  };
1063
1064
 
1064
1065
  // src/text_editor.tsx
1066
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
1065
1067
  function TextEditor({
1066
1068
  ref,
1067
1069
  name,
@@ -1078,7 +1080,7 @@ function TextEditor({
1078
1080
  style,
1079
1081
  ...props
1080
1082
  } = {}) {
1081
- const containerRef = useRef(null);
1083
+ const containerRef = useRef2(null);
1082
1084
  const controller = useMemo(
1083
1085
  () => new TextEditorController({
1084
1086
  mode,
@@ -1094,7 +1096,7 @@ function TextEditor({
1094
1096
  []
1095
1097
  );
1096
1098
  useImperativeHandle(ref, () => controller, [controller]);
1097
- useEffect2(() => {
1099
+ useLayoutEffect(() => {
1098
1100
  const container = containerRef.current;
1099
1101
  if (!container) {
1100
1102
  return;
@@ -1104,19 +1106,22 @@ function TextEditor({
1104
1106
  controller.dispose();
1105
1107
  };
1106
1108
  }, [controller]);
1107
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", { ...props, ref: containerRef, className }), /* @__PURE__ */ React2.createElement(
1108
- TextEditorInput,
1109
- {
1110
- name,
1111
- controller,
1112
- onChange
1113
- }
1114
- ));
1109
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1110
+ /* @__PURE__ */ jsx2("div", { ...props, ref: containerRef, className }),
1111
+ /* @__PURE__ */ jsx2(
1112
+ TextEditorInput,
1113
+ {
1114
+ name,
1115
+ controller,
1116
+ onChange
1117
+ }
1118
+ )
1119
+ ] });
1115
1120
  }
1116
1121
 
1117
1122
  // src/html.tsx
1118
1123
  import { decode } from "html-entities";
1119
- import React3 from "react";
1124
+ import { jsx as jsx3 } from "react/jsx-runtime";
1120
1125
  function createInnerHTML(raw) {
1121
1126
  return raw.replace(/<\/p>/g, "<br></p>").replace(/(<p><br><\/p>)+$/g, "").replace(
1122
1127
  /<code class="language-(\w+)">([\s\S]*?)<\/code>/g,
@@ -1144,7 +1149,7 @@ function createTextEditorView(options = {}) {
1144
1149
  dangerouslySetInnerHTML,
1145
1150
  ...props
1146
1151
  }) {
1147
- return /* @__PURE__ */ React3.createElement(
1152
+ return /* @__PURE__ */ jsx3(
1148
1153
  "div",
1149
1154
  {
1150
1155
  ...props,
package/dist/input.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import React, { DetailedHTMLProps, HTMLAttributes } from 'react';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { DetailedHTMLProps, HTMLAttributes } from 'react';
2
3
  import { TextEditorController } from './text_editor_controller.mjs';
3
4
  import 'prosemirror-model';
4
5
  import 'prosemirror-state';
@@ -8,11 +9,11 @@ import './schema.mjs';
8
9
  import 'orderedmap';
9
10
  import 'rxjs';
10
11
 
11
- type Props = Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
12
+ type Props = Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref" | "onChange"> & {
12
13
  controller: TextEditorController;
13
14
  name?: string;
14
- onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
15
+ onChange?: (value: string) => void;
15
16
  };
16
- declare function TextEditorInput({ controller, onChange, ...props }: Props): React.JSX.Element;
17
+ declare function TextEditorInput({ controller, onChange, ...props }: Props): react_jsx_runtime.JSX.Element;
17
18
 
18
19
  export { TextEditorInput };
package/dist/input.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import React, { DetailedHTMLProps, HTMLAttributes } from 'react';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { DetailedHTMLProps, HTMLAttributes } from 'react';
2
3
  import { TextEditorController } from './text_editor_controller.js';
3
4
  import 'prosemirror-model';
4
5
  import 'prosemirror-state';
@@ -8,11 +9,11 @@ import './schema.js';
8
9
  import 'orderedmap';
9
10
  import 'rxjs';
10
11
 
11
- type Props = Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
12
+ type Props = Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref" | "onChange"> & {
12
13
  controller: TextEditorController;
13
14
  name?: string;
14
- onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
15
+ onChange?: (value: string) => void;
15
16
  };
16
- declare function TextEditorInput({ controller, onChange, ...props }: Props): React.JSX.Element;
17
+ declare function TextEditorInput({ controller, onChange, ...props }: Props): react_jsx_runtime.JSX.Element;
17
18
 
18
19
  export { TextEditorInput };
package/dist/input.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/input.tsx
@@ -33,32 +23,31 @@ __export(input_exports, {
33
23
  TextEditorInput: () => TextEditorInput
34
24
  });
35
25
  module.exports = __toCommonJS(input_exports);
36
- var import_react = __toESM(require("react"));
26
+ var import_react = require("react");
37
27
  var import_rxjs = require("rxjs");
28
+ var import_jsx_runtime = require("react/jsx-runtime");
38
29
  function TextEditorInput({ controller, onChange, ...props }) {
39
- const inputRef = import_react.default.useRef(null);
30
+ const inputRef = (0, import_react.useRef)(null);
40
31
  (0, import_react.useEffect)(() => {
41
32
  const sub = controller.subject.pipe(
42
33
  (0, import_rxjs.filter)((tr) => tr.docChanged),
43
34
  (0, import_rxjs.debounceTime)(controller.props.updateDelay || 0)
44
35
  ).subscribe(() => {
45
- if (inputRef.current) {
46
- inputRef.current.value = controller.value;
47
- const event = new Event("input", { bubbles: true });
48
- inputRef.current.dispatchEvent(event);
49
- }
36
+ const input = inputRef.current;
37
+ if (!input) return;
38
+ input.value = controller.value;
39
+ onChange?.(controller.value);
50
40
  });
51
41
  return () => {
52
42
  sub.unsubscribe();
53
43
  };
54
44
  }, []);
55
- return /* @__PURE__ */ import_react.default.createElement(
45
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
56
46
  "input",
57
47
  {
58
48
  ...props,
59
49
  ref: inputRef,
60
50
  type: "hidden",
61
- onInput: onChange,
62
51
  defaultValue: controller.props.defaultValue
63
52
  }
64
53
  );
package/dist/input.mjs CHANGED
@@ -1,32 +1,32 @@
1
1
  // src/input.tsx
2
- import React, {
3
- useEffect
2
+ import {
3
+ useEffect,
4
+ useRef
4
5
  } from "react";
5
6
  import { debounceTime, filter } from "rxjs";
7
+ import { jsx } from "react/jsx-runtime";
6
8
  function TextEditorInput({ controller, onChange, ...props }) {
7
- const inputRef = React.useRef(null);
9
+ const inputRef = useRef(null);
8
10
  useEffect(() => {
9
11
  const sub = controller.subject.pipe(
10
12
  filter((tr) => tr.docChanged),
11
13
  debounceTime(controller.props.updateDelay || 0)
12
14
  ).subscribe(() => {
13
- if (inputRef.current) {
14
- inputRef.current.value = controller.value;
15
- const event = new Event("input", { bubbles: true });
16
- inputRef.current.dispatchEvent(event);
17
- }
15
+ const input = inputRef.current;
16
+ if (!input) return;
17
+ input.value = controller.value;
18
+ onChange?.(controller.value);
18
19
  });
19
20
  return () => {
20
21
  sub.unsubscribe();
21
22
  };
22
23
  }, []);
23
- return /* @__PURE__ */ React.createElement(
24
+ return /* @__PURE__ */ jsx(
24
25
  "input",
25
26
  {
26
27
  ...props,
27
28
  ref: inputRef,
28
29
  type: "hidden",
29
- onInput: onChange,
30
30
  defaultValue: controller.props.defaultValue
31
31
  }
32
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,4 +1,6 @@
1
- import React, { DetailedHTMLProps, InputHTMLAttributes, Ref } from 'react';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { DetailedHTMLProps, InputHTMLAttributes, Ref } from 'react';
3
+ import { TextEditorInput } from './input.mjs';
2
4
  import { TextEditorController, TextEditorControllerProps } from './text_editor_controller.mjs';
3
5
  import 'prosemirror-model';
4
6
  import 'prosemirror-state';
@@ -9,10 +11,11 @@ import 'orderedmap';
9
11
  import 'rxjs';
10
12
 
11
13
  type HTMLElementProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
12
- type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
14
+ type TextEditorProps = Omit<HTMLElementProps, "ref" | "onChange"> & {
13
15
  name?: string;
14
16
  ref?: Ref<TextEditorController>;
17
+ onChange?: Parameters<typeof TextEditorInput>[0]["onChange"];
15
18
  } & TextEditorControllerProps;
16
- declare function TextEditor({ ref, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): React.JSX.Element;
19
+ declare function TextEditor({ ref, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): react_jsx_runtime.JSX.Element;
17
20
 
18
21
  export { TextEditor, type TextEditorProps };
@@ -1,4 +1,6 @@
1
- import React, { DetailedHTMLProps, InputHTMLAttributes, Ref } from 'react';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { DetailedHTMLProps, InputHTMLAttributes, Ref } from 'react';
3
+ import { TextEditorInput } from './input.js';
2
4
  import { TextEditorController, TextEditorControllerProps } from './text_editor_controller.js';
3
5
  import 'prosemirror-model';
4
6
  import 'prosemirror-state';
@@ -9,10 +11,11 @@ import 'orderedmap';
9
11
  import 'rxjs';
10
12
 
11
13
  type HTMLElementProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
12
- type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
14
+ type TextEditorProps = Omit<HTMLElementProps, "ref" | "onChange"> & {
13
15
  name?: string;
14
16
  ref?: Ref<TextEditorController>;
17
+ onChange?: Parameters<typeof TextEditorInput>[0]["onChange"];
15
18
  } & TextEditorControllerProps;
16
- declare function TextEditor({ ref, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): React.JSX.Element;
19
+ declare function TextEditor({ ref, name, className, autoFocus, onChange, mode, state, editor, defaultValue, updateDelay, placeholder, attachFile, style, ...props }?: TextEditorProps): react_jsx_runtime.JSX.Element;
17
20
 
18
21
  export { TextEditor, type TextEditorProps };
@@ -33,36 +33,35 @@ __export(text_editor_exports, {
33
33
  TextEditor: () => TextEditor
34
34
  });
35
35
  module.exports = __toCommonJS(text_editor_exports);
36
- var import_react2 = __toESM(require("react"));
36
+ var import_react2 = require("react");
37
37
  var import_react3 = require("react");
38
38
 
39
39
  // src/input.tsx
40
- var import_react = __toESM(require("react"));
40
+ var import_react = require("react");
41
41
  var import_rxjs = require("rxjs");
42
+ var import_jsx_runtime = require("react/jsx-runtime");
42
43
  function TextEditorInput({ controller, onChange, ...props }) {
43
- const inputRef = import_react.default.useRef(null);
44
+ const inputRef = (0, import_react.useRef)(null);
44
45
  (0, import_react.useEffect)(() => {
45
46
  const sub = controller.subject.pipe(
46
47
  (0, import_rxjs.filter)((tr) => tr.docChanged),
47
48
  (0, import_rxjs.debounceTime)(controller.props.updateDelay || 0)
48
49
  ).subscribe(() => {
49
- if (inputRef.current) {
50
- inputRef.current.value = controller.value;
51
- const event = new Event("input", { bubbles: true });
52
- inputRef.current.dispatchEvent(event);
53
- }
50
+ const input = inputRef.current;
51
+ if (!input) return;
52
+ input.value = controller.value;
53
+ onChange?.(controller.value);
54
54
  });
55
55
  return () => {
56
56
  sub.unsubscribe();
57
57
  };
58
58
  }, []);
59
- return /* @__PURE__ */ import_react.default.createElement(
59
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
60
60
  "input",
61
61
  {
62
62
  ...props,
63
63
  ref: inputRef,
64
64
  type: "hidden",
65
- onInput: onChange,
66
65
  defaultValue: controller.props.defaultValue
67
66
  }
68
67
  );
@@ -1081,6 +1080,7 @@ var TextEditorController = class {
1081
1080
  };
1082
1081
 
1083
1082
  // src/text_editor.tsx
1083
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1084
1084
  function TextEditor({
1085
1085
  ref,
1086
1086
  name,
@@ -1113,7 +1113,7 @@ function TextEditor({
1113
1113
  []
1114
1114
  );
1115
1115
  (0, import_react2.useImperativeHandle)(ref, () => controller, [controller]);
1116
- (0, import_react3.useEffect)(() => {
1116
+ (0, import_react2.useLayoutEffect)(() => {
1117
1117
  const container = containerRef.current;
1118
1118
  if (!container) {
1119
1119
  return;
@@ -1123,14 +1123,17 @@ function TextEditor({
1123
1123
  controller.dispose();
1124
1124
  };
1125
1125
  }, [controller]);
1126
- return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement("div", { ...props, ref: containerRef, className }), /* @__PURE__ */ import_react2.default.createElement(
1127
- TextEditorInput,
1128
- {
1129
- name,
1130
- controller,
1131
- onChange
1132
- }
1133
- ));
1126
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1127
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...props, ref: containerRef, className }),
1128
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1129
+ TextEditorInput,
1130
+ {
1131
+ name,
1132
+ controller,
1133
+ onChange
1134
+ }
1135
+ )
1136
+ ] });
1134
1137
  }
1135
1138
  // Annotate the CommonJS export names for ESM import in node:
1136
1139
  0 && (module.exports = {
@@ -1,39 +1,40 @@
1
1
  // src/text_editor.tsx
2
- import React2, {
2
+ import {
3
3
  useImperativeHandle,
4
+ useLayoutEffect,
4
5
  useMemo
5
6
  } from "react";
6
- import { useEffect as useEffect2, useRef } from "react";
7
+ import { useRef as useRef2 } from "react";
7
8
 
8
9
  // src/input.tsx
9
- import React, {
10
- useEffect
10
+ import {
11
+ useEffect,
12
+ useRef
11
13
  } from "react";
12
14
  import { debounceTime, filter } from "rxjs";
15
+ import { jsx } from "react/jsx-runtime";
13
16
  function TextEditorInput({ controller, onChange, ...props }) {
14
- const inputRef = React.useRef(null);
17
+ const inputRef = useRef(null);
15
18
  useEffect(() => {
16
19
  const sub = controller.subject.pipe(
17
20
  filter((tr) => tr.docChanged),
18
21
  debounceTime(controller.props.updateDelay || 0)
19
22
  ).subscribe(() => {
20
- if (inputRef.current) {
21
- inputRef.current.value = controller.value;
22
- const event = new Event("input", { bubbles: true });
23
- inputRef.current.dispatchEvent(event);
24
- }
23
+ const input = inputRef.current;
24
+ if (!input) return;
25
+ input.value = controller.value;
26
+ onChange?.(controller.value);
25
27
  });
26
28
  return () => {
27
29
  sub.unsubscribe();
28
30
  };
29
31
  }, []);
30
- return /* @__PURE__ */ React.createElement(
32
+ return /* @__PURE__ */ jsx(
31
33
  "input",
32
34
  {
33
35
  ...props,
34
36
  ref: inputRef,
35
37
  type: "hidden",
36
- onInput: onChange,
37
38
  defaultValue: controller.props.defaultValue
38
39
  }
39
40
  );
@@ -1054,6 +1055,7 @@ var TextEditorController = class {
1054
1055
  };
1055
1056
 
1056
1057
  // src/text_editor.tsx
1058
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
1057
1059
  function TextEditor({
1058
1060
  ref,
1059
1061
  name,
@@ -1070,7 +1072,7 @@ function TextEditor({
1070
1072
  style,
1071
1073
  ...props
1072
1074
  } = {}) {
1073
- const containerRef = useRef(null);
1075
+ const containerRef = useRef2(null);
1074
1076
  const controller = useMemo(
1075
1077
  () => new TextEditorController({
1076
1078
  mode,
@@ -1086,7 +1088,7 @@ function TextEditor({
1086
1088
  []
1087
1089
  );
1088
1090
  useImperativeHandle(ref, () => controller, [controller]);
1089
- useEffect2(() => {
1091
+ useLayoutEffect(() => {
1090
1092
  const container = containerRef.current;
1091
1093
  if (!container) {
1092
1094
  return;
@@ -1096,14 +1098,17 @@ function TextEditor({
1096
1098
  controller.dispose();
1097
1099
  };
1098
1100
  }, [controller]);
1099
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", { ...props, ref: containerRef, className }), /* @__PURE__ */ React2.createElement(
1100
- TextEditorInput,
1101
- {
1102
- name,
1103
- controller,
1104
- onChange
1105
- }
1106
- ));
1101
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1102
+ /* @__PURE__ */ jsx2("div", { ...props, ref: containerRef, className }),
1103
+ /* @__PURE__ */ jsx2(
1104
+ TextEditorInput,
1105
+ {
1106
+ name,
1107
+ controller,
1108
+ onChange
1109
+ }
1110
+ )
1111
+ ] });
1107
1112
  }
1108
1113
  export {
1109
1114
  TextEditor
package/package.json CHANGED
@@ -1,59 +1,59 @@
1
1
  {
2
- "name": "dn-react-text-editor",
3
- "version": "0.3.6",
4
- "types": "./dist/index.d.ts",
5
- "main": "./dist/index.mjs",
6
- "module": "./dist/index.js",
7
- "sideEffects": false,
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js"
2
+ "name": "dn-react-text-editor",
3
+ "version": "0.3.9",
4
+ "types": "./dist/index.d.ts",
5
+ "main": "./dist/index.mjs",
6
+ "module": "./dist/index.js",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./prosemirror": {
15
+ "types": "./dist/prosemirror/index.d.ts",
16
+ "import": "./dist/prosemirror/index.mjs",
17
+ "require": "./dist/prosemirror/index.js"
18
+ }
13
19
  },
14
- "./prosemirror": {
15
- "types": "./dist/prosemirror/index.d.ts",
16
- "import": "./dist/prosemirror/index.mjs",
17
- "require": "./dist/prosemirror/index.js"
20
+ "scripts": {
21
+ "build": "NODE_OPTIONS='--max-old-space-size=16384' tsup",
22
+ "dev": "tsup --watch"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/dndnsoft/dn-react-text-editor.git"
27
+ },
28
+ "author": "",
29
+ "license": "MIT",
30
+ "bugs": {
31
+ "url": "https://github.com/dndnsoft/dn-react-text-editor/issues"
32
+ },
33
+ "homepage": "https://github.com/dndnsoft/dn-react-text-editor#readme",
34
+ "description": "",
35
+ "devDependencies": {
36
+ "@types/node": "^24.10.1",
37
+ "@types/react": "^19",
38
+ "@types/react-dom": "^19",
39
+ "tsup": "^8.5.1",
40
+ "typescript": "^5.7.3"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^19",
44
+ "react-dom": "^19"
45
+ },
46
+ "dependencies": {
47
+ "highlight.js": "^11.11.1",
48
+ "html-entities": "^2.6.0",
49
+ "prosemirror-commands": "^1.7.1",
50
+ "prosemirror-highlightjs": "^0.9.1",
51
+ "prosemirror-history": "^1.5.0",
52
+ "prosemirror-keymap": "^1.2.3",
53
+ "prosemirror-model": "^1.25.4",
54
+ "prosemirror-schema-list": "^1.5.1",
55
+ "prosemirror-state": "^1.4.4",
56
+ "prosemirror-view": "^1.41.3",
57
+ "rxjs": "^7.8.2"
18
58
  }
19
- },
20
- "scripts": {
21
- "build": "NODE_OPTIONS='--max-old-space-size=16384' tsup",
22
- "dev": "tsup --watch"
23
- },
24
- "repository": {
25
- "type": "git",
26
- "url": "git+https://github.com/dndnsoft/dn-react-text-editor.git"
27
- },
28
- "author": "",
29
- "license": "MIT",
30
- "bugs": {
31
- "url": "https://github.com/dndnsoft/dn-react-text-editor/issues"
32
- },
33
- "homepage": "https://github.com/dndnsoft/dn-react-text-editor#readme",
34
- "description": "",
35
- "devDependencies": {
36
- "@types/node": "^24.10.1",
37
- "@types/react": "^19",
38
- "@types/react-dom": "^19",
39
- "tsup": "^8.5.1",
40
- "typescript": "^5.7.3"
41
- },
42
- "peerDependencies": {
43
- "react": "^19",
44
- "react-dom": "^19"
45
- },
46
- "dependencies": {
47
- "highlight.js": "^11.11.1",
48
- "html-entities": "^2.6.0",
49
- "prosemirror-commands": "^1.7.1",
50
- "prosemirror-highlightjs": "^0.9.1",
51
- "prosemirror-history": "^1.5.0",
52
- "prosemirror-keymap": "^1.2.3",
53
- "prosemirror-model": "^1.25.4",
54
- "prosemirror-schema-list": "^1.5.1",
55
- "prosemirror-state": "^1.4.4",
56
- "prosemirror-view": "^1.41.3",
57
- "rxjs": "^7.8.2"
58
- }
59
- }
59
+ }