dn-react-text-editor 0.2.0 → 0.2.2
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/create_text_editor.d.mts +2 -2
- package/dist/create_text_editor.d.ts +2 -2
- package/dist/create_text_editor.js +20 -13
- package/dist/create_text_editor.mjs +20 -13
- package/dist/index.js +20 -13
- package/dist/index.mjs +20 -13
- package/dist/text_editor_controller.js +4 -4
- package/dist/text_editor_controller.mjs +4 -4
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DetailedHTMLProps, InputHTMLAttributes, Ref, FC } from 'react';
|
|
2
2
|
import { Transaction } from 'prosemirror-state';
|
|
3
3
|
import { EditorView } from 'prosemirror-view';
|
|
4
4
|
import { createSchema } from './schema.mjs';
|
|
@@ -23,6 +23,6 @@ type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
|
|
|
23
23
|
ref?: Ref<TextEditorController>;
|
|
24
24
|
name?: string;
|
|
25
25
|
} & TextEditorControllerProps;
|
|
26
|
-
declare function createTextEditor(options?: CreateTextEditorOptions):
|
|
26
|
+
declare function createTextEditor(options?: CreateTextEditorOptions): FC<TextEditorProps>;
|
|
27
27
|
|
|
28
28
|
export { type TextEditorController, type TextEditorProps, createTextEditor };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DetailedHTMLProps, InputHTMLAttributes, Ref, FC } from 'react';
|
|
2
2
|
import { Transaction } from 'prosemirror-state';
|
|
3
3
|
import { EditorView } from 'prosemirror-view';
|
|
4
4
|
import { createSchema } from './schema.js';
|
|
@@ -23,6 +23,6 @@ type TextEditorProps = Omit<HTMLElementProps, "ref"> & {
|
|
|
23
23
|
ref?: Ref<TextEditorController>;
|
|
24
24
|
name?: string;
|
|
25
25
|
} & TextEditorControllerProps;
|
|
26
|
-
declare function createTextEditor(options?: CreateTextEditorOptions):
|
|
26
|
+
declare function createTextEditor(options?: CreateTextEditorOptions): FC<TextEditorProps>;
|
|
27
27
|
|
|
28
28
|
export { type TextEditorController, type TextEditorProps, createTextEditor };
|
|
@@ -916,7 +916,7 @@ function createAttachFile({
|
|
|
916
916
|
var import_prosemirror_model3 = require("prosemirror-model");
|
|
917
917
|
var import_rxjs2 = require("rxjs");
|
|
918
918
|
function createTextEditorController(container, schema, options, {
|
|
919
|
-
mode,
|
|
919
|
+
mode = "html",
|
|
920
920
|
state,
|
|
921
921
|
editor,
|
|
922
922
|
defaultValue,
|
|
@@ -928,10 +928,10 @@ function createTextEditorController(container, schema, options, {
|
|
|
928
928
|
const prosemirrorSerializer = import_prosemirror_model3.DOMSerializer.fromSchema(schema);
|
|
929
929
|
const wrapper = document.createElement("div");
|
|
930
930
|
const toInnerHTML = (value) => {
|
|
931
|
-
if (mode === "
|
|
932
|
-
return value;
|
|
931
|
+
if (mode === "text") {
|
|
932
|
+
return value.split("\n").map((line) => `<p>${line}</p>`).join("");
|
|
933
933
|
}
|
|
934
|
-
return value
|
|
934
|
+
return value;
|
|
935
935
|
};
|
|
936
936
|
wrapper.innerHTML = toInnerHTML(defaultValue ? String(defaultValue) : "");
|
|
937
937
|
const attachFile = createAttachFile({
|
|
@@ -1037,32 +1037,38 @@ function createTextEditor(options = {}) {
|
|
|
1037
1037
|
ref,
|
|
1038
1038
|
className,
|
|
1039
1039
|
autoFocus,
|
|
1040
|
-
placeholder,
|
|
1041
|
-
defaultValue,
|
|
1042
1040
|
onChange,
|
|
1041
|
+
mode,
|
|
1042
|
+
state,
|
|
1043
|
+
editor,
|
|
1044
|
+
defaultValue,
|
|
1043
1045
|
updateDelay,
|
|
1046
|
+
placeholder,
|
|
1044
1047
|
...props
|
|
1045
1048
|
} = {}) {
|
|
1046
1049
|
const containerRef = (0, import_react3.useRef)(null);
|
|
1047
1050
|
const controllerRef = (0, import_react3.useRef)(null);
|
|
1048
|
-
(0, import_react2.useImperativeHandle)(ref, () => {
|
|
1051
|
+
(0, import_react2.useImperativeHandle)(ref || controllerRef, () => {
|
|
1049
1052
|
const container = containerRef.current;
|
|
1050
1053
|
const textEditorController = createTextEditorController(
|
|
1051
1054
|
container,
|
|
1052
1055
|
schema,
|
|
1053
1056
|
options,
|
|
1054
|
-
|
|
1057
|
+
{
|
|
1058
|
+
mode,
|
|
1059
|
+
state,
|
|
1060
|
+
editor,
|
|
1061
|
+
defaultValue,
|
|
1062
|
+
updateDelay,
|
|
1063
|
+
placeholder
|
|
1064
|
+
}
|
|
1055
1065
|
);
|
|
1056
1066
|
controllerRef.current = textEditorController;
|
|
1057
1067
|
return textEditorController;
|
|
1058
1068
|
});
|
|
1059
1069
|
(0, import_react3.useEffect)(() => {
|
|
1060
|
-
const controller = controllerRef.current;
|
|
1061
|
-
if (!controller) {
|
|
1062
|
-
return;
|
|
1063
|
-
}
|
|
1064
1070
|
if (autoFocus) {
|
|
1065
|
-
|
|
1071
|
+
controllerRef.current?.view.focus();
|
|
1066
1072
|
}
|
|
1067
1073
|
}, []);
|
|
1068
1074
|
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(
|
|
@@ -1070,6 +1076,7 @@ function createTextEditor(options = {}) {
|
|
|
1070
1076
|
{
|
|
1071
1077
|
ref: controllerRef,
|
|
1072
1078
|
updateDelay,
|
|
1079
|
+
defaultValue,
|
|
1073
1080
|
onChange
|
|
1074
1081
|
}
|
|
1075
1082
|
));
|
|
@@ -888,7 +888,7 @@ function createAttachFile({
|
|
|
888
888
|
import { DOMParser, DOMSerializer } from "prosemirror-model";
|
|
889
889
|
import { Subject } from "rxjs";
|
|
890
890
|
function createTextEditorController(container, schema, options, {
|
|
891
|
-
mode,
|
|
891
|
+
mode = "html",
|
|
892
892
|
state,
|
|
893
893
|
editor,
|
|
894
894
|
defaultValue,
|
|
@@ -900,10 +900,10 @@ function createTextEditorController(container, schema, options, {
|
|
|
900
900
|
const prosemirrorSerializer = DOMSerializer.fromSchema(schema);
|
|
901
901
|
const wrapper = document.createElement("div");
|
|
902
902
|
const toInnerHTML = (value) => {
|
|
903
|
-
if (mode === "
|
|
904
|
-
return value;
|
|
903
|
+
if (mode === "text") {
|
|
904
|
+
return value.split("\n").map((line) => `<p>${line}</p>`).join("");
|
|
905
905
|
}
|
|
906
|
-
return value
|
|
906
|
+
return value;
|
|
907
907
|
};
|
|
908
908
|
wrapper.innerHTML = toInnerHTML(defaultValue ? String(defaultValue) : "");
|
|
909
909
|
const attachFile = createAttachFile({
|
|
@@ -1009,32 +1009,38 @@ function createTextEditor(options = {}) {
|
|
|
1009
1009
|
ref,
|
|
1010
1010
|
className,
|
|
1011
1011
|
autoFocus,
|
|
1012
|
-
placeholder,
|
|
1013
|
-
defaultValue,
|
|
1014
1012
|
onChange,
|
|
1013
|
+
mode,
|
|
1014
|
+
state,
|
|
1015
|
+
editor,
|
|
1016
|
+
defaultValue,
|
|
1015
1017
|
updateDelay,
|
|
1018
|
+
placeholder,
|
|
1016
1019
|
...props
|
|
1017
1020
|
} = {}) {
|
|
1018
1021
|
const containerRef = useRef(null);
|
|
1019
1022
|
const controllerRef = useRef(null);
|
|
1020
|
-
useImperativeHandle(ref, () => {
|
|
1023
|
+
useImperativeHandle(ref || controllerRef, () => {
|
|
1021
1024
|
const container = containerRef.current;
|
|
1022
1025
|
const textEditorController = createTextEditorController(
|
|
1023
1026
|
container,
|
|
1024
1027
|
schema,
|
|
1025
1028
|
options,
|
|
1026
|
-
|
|
1029
|
+
{
|
|
1030
|
+
mode,
|
|
1031
|
+
state,
|
|
1032
|
+
editor,
|
|
1033
|
+
defaultValue,
|
|
1034
|
+
updateDelay,
|
|
1035
|
+
placeholder
|
|
1036
|
+
}
|
|
1027
1037
|
);
|
|
1028
1038
|
controllerRef.current = textEditorController;
|
|
1029
1039
|
return textEditorController;
|
|
1030
1040
|
});
|
|
1031
1041
|
useEffect2(() => {
|
|
1032
|
-
const controller = controllerRef.current;
|
|
1033
|
-
if (!controller) {
|
|
1034
|
-
return;
|
|
1035
|
-
}
|
|
1036
1042
|
if (autoFocus) {
|
|
1037
|
-
|
|
1043
|
+
controllerRef.current?.view.focus();
|
|
1038
1044
|
}
|
|
1039
1045
|
}, []);
|
|
1040
1046
|
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", { ...props, ref: containerRef, className }), /* @__PURE__ */ React2.createElement(
|
|
@@ -1042,6 +1048,7 @@ function createTextEditor(options = {}) {
|
|
|
1042
1048
|
{
|
|
1043
1049
|
ref: controllerRef,
|
|
1044
1050
|
updateDelay,
|
|
1051
|
+
defaultValue,
|
|
1045
1052
|
onChange
|
|
1046
1053
|
}
|
|
1047
1054
|
));
|
package/dist/index.js
CHANGED
|
@@ -922,7 +922,7 @@ function createAttachFile({
|
|
|
922
922
|
var import_prosemirror_model3 = require("prosemirror-model");
|
|
923
923
|
var import_rxjs2 = require("rxjs");
|
|
924
924
|
function createTextEditorController(container, schema, options, {
|
|
925
|
-
mode,
|
|
925
|
+
mode = "html",
|
|
926
926
|
state,
|
|
927
927
|
editor,
|
|
928
928
|
defaultValue,
|
|
@@ -934,10 +934,10 @@ function createTextEditorController(container, schema, options, {
|
|
|
934
934
|
const prosemirrorSerializer = import_prosemirror_model3.DOMSerializer.fromSchema(schema);
|
|
935
935
|
const wrapper = document.createElement("div");
|
|
936
936
|
const toInnerHTML = (value) => {
|
|
937
|
-
if (mode === "
|
|
938
|
-
return value;
|
|
937
|
+
if (mode === "text") {
|
|
938
|
+
return value.split("\n").map((line) => `<p>${line}</p>`).join("");
|
|
939
939
|
}
|
|
940
|
-
return value
|
|
940
|
+
return value;
|
|
941
941
|
};
|
|
942
942
|
wrapper.innerHTML = toInnerHTML(defaultValue ? String(defaultValue) : "");
|
|
943
943
|
const attachFile = createAttachFile({
|
|
@@ -1043,32 +1043,38 @@ function createTextEditor(options = {}) {
|
|
|
1043
1043
|
ref,
|
|
1044
1044
|
className,
|
|
1045
1045
|
autoFocus,
|
|
1046
|
-
placeholder,
|
|
1047
|
-
defaultValue,
|
|
1048
1046
|
onChange,
|
|
1047
|
+
mode,
|
|
1048
|
+
state,
|
|
1049
|
+
editor,
|
|
1050
|
+
defaultValue,
|
|
1049
1051
|
updateDelay,
|
|
1052
|
+
placeholder,
|
|
1050
1053
|
...props
|
|
1051
1054
|
} = {}) {
|
|
1052
1055
|
const containerRef = (0, import_react3.useRef)(null);
|
|
1053
1056
|
const controllerRef = (0, import_react3.useRef)(null);
|
|
1054
|
-
(0, import_react2.useImperativeHandle)(ref, () => {
|
|
1057
|
+
(0, import_react2.useImperativeHandle)(ref || controllerRef, () => {
|
|
1055
1058
|
const container = containerRef.current;
|
|
1056
1059
|
const textEditorController = createTextEditorController(
|
|
1057
1060
|
container,
|
|
1058
1061
|
schema,
|
|
1059
1062
|
options,
|
|
1060
|
-
|
|
1063
|
+
{
|
|
1064
|
+
mode,
|
|
1065
|
+
state,
|
|
1066
|
+
editor,
|
|
1067
|
+
defaultValue,
|
|
1068
|
+
updateDelay,
|
|
1069
|
+
placeholder
|
|
1070
|
+
}
|
|
1061
1071
|
);
|
|
1062
1072
|
controllerRef.current = textEditorController;
|
|
1063
1073
|
return textEditorController;
|
|
1064
1074
|
});
|
|
1065
1075
|
(0, import_react3.useEffect)(() => {
|
|
1066
|
-
const controller = controllerRef.current;
|
|
1067
|
-
if (!controller) {
|
|
1068
|
-
return;
|
|
1069
|
-
}
|
|
1070
1076
|
if (autoFocus) {
|
|
1071
|
-
|
|
1077
|
+
controllerRef.current?.view.focus();
|
|
1072
1078
|
}
|
|
1073
1079
|
}, []);
|
|
1074
1080
|
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(
|
|
@@ -1076,6 +1082,7 @@ function createTextEditor(options = {}) {
|
|
|
1076
1082
|
{
|
|
1077
1083
|
ref: controllerRef,
|
|
1078
1084
|
updateDelay,
|
|
1085
|
+
defaultValue,
|
|
1079
1086
|
onChange
|
|
1080
1087
|
}
|
|
1081
1088
|
));
|
package/dist/index.mjs
CHANGED
|
@@ -888,7 +888,7 @@ function createAttachFile({
|
|
|
888
888
|
import { DOMParser, DOMSerializer } from "prosemirror-model";
|
|
889
889
|
import { Subject } from "rxjs";
|
|
890
890
|
function createTextEditorController(container, schema, options, {
|
|
891
|
-
mode,
|
|
891
|
+
mode = "html",
|
|
892
892
|
state,
|
|
893
893
|
editor,
|
|
894
894
|
defaultValue,
|
|
@@ -900,10 +900,10 @@ function createTextEditorController(container, schema, options, {
|
|
|
900
900
|
const prosemirrorSerializer = DOMSerializer.fromSchema(schema);
|
|
901
901
|
const wrapper = document.createElement("div");
|
|
902
902
|
const toInnerHTML = (value) => {
|
|
903
|
-
if (mode === "
|
|
904
|
-
return value;
|
|
903
|
+
if (mode === "text") {
|
|
904
|
+
return value.split("\n").map((line) => `<p>${line}</p>`).join("");
|
|
905
905
|
}
|
|
906
|
-
return value
|
|
906
|
+
return value;
|
|
907
907
|
};
|
|
908
908
|
wrapper.innerHTML = toInnerHTML(defaultValue ? String(defaultValue) : "");
|
|
909
909
|
const attachFile = createAttachFile({
|
|
@@ -1009,32 +1009,38 @@ function createTextEditor(options = {}) {
|
|
|
1009
1009
|
ref,
|
|
1010
1010
|
className,
|
|
1011
1011
|
autoFocus,
|
|
1012
|
-
placeholder,
|
|
1013
|
-
defaultValue,
|
|
1014
1012
|
onChange,
|
|
1013
|
+
mode,
|
|
1014
|
+
state,
|
|
1015
|
+
editor,
|
|
1016
|
+
defaultValue,
|
|
1015
1017
|
updateDelay,
|
|
1018
|
+
placeholder,
|
|
1016
1019
|
...props
|
|
1017
1020
|
} = {}) {
|
|
1018
1021
|
const containerRef = useRef(null);
|
|
1019
1022
|
const controllerRef = useRef(null);
|
|
1020
|
-
useImperativeHandle(ref, () => {
|
|
1023
|
+
useImperativeHandle(ref || controllerRef, () => {
|
|
1021
1024
|
const container = containerRef.current;
|
|
1022
1025
|
const textEditorController = createTextEditorController(
|
|
1023
1026
|
container,
|
|
1024
1027
|
schema,
|
|
1025
1028
|
options,
|
|
1026
|
-
|
|
1029
|
+
{
|
|
1030
|
+
mode,
|
|
1031
|
+
state,
|
|
1032
|
+
editor,
|
|
1033
|
+
defaultValue,
|
|
1034
|
+
updateDelay,
|
|
1035
|
+
placeholder
|
|
1036
|
+
}
|
|
1027
1037
|
);
|
|
1028
1038
|
controllerRef.current = textEditorController;
|
|
1029
1039
|
return textEditorController;
|
|
1030
1040
|
});
|
|
1031
1041
|
useEffect2(() => {
|
|
1032
|
-
const controller = controllerRef.current;
|
|
1033
|
-
if (!controller) {
|
|
1034
|
-
return;
|
|
1035
|
-
}
|
|
1036
1042
|
if (autoFocus) {
|
|
1037
|
-
|
|
1043
|
+
controllerRef.current?.view.focus();
|
|
1038
1044
|
}
|
|
1039
1045
|
}, []);
|
|
1040
1046
|
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", { ...props, ref: containerRef, className }), /* @__PURE__ */ React2.createElement(
|
|
@@ -1042,6 +1048,7 @@ function createTextEditor(options = {}) {
|
|
|
1042
1048
|
{
|
|
1043
1049
|
ref: controllerRef,
|
|
1044
1050
|
updateDelay,
|
|
1051
|
+
defaultValue,
|
|
1045
1052
|
onChange
|
|
1046
1053
|
}
|
|
1047
1054
|
));
|
|
@@ -384,7 +384,7 @@ var createCommands = (schema, view, options = {}) => {
|
|
|
384
384
|
var import_prosemirror_model2 = require("prosemirror-model");
|
|
385
385
|
var import_rxjs = require("rxjs");
|
|
386
386
|
function createTextEditorController(container, schema, options, {
|
|
387
|
-
mode,
|
|
387
|
+
mode = "html",
|
|
388
388
|
state,
|
|
389
389
|
editor,
|
|
390
390
|
defaultValue,
|
|
@@ -396,10 +396,10 @@ function createTextEditorController(container, schema, options, {
|
|
|
396
396
|
const prosemirrorSerializer = import_prosemirror_model2.DOMSerializer.fromSchema(schema);
|
|
397
397
|
const wrapper = document.createElement("div");
|
|
398
398
|
const toInnerHTML = (value) => {
|
|
399
|
-
if (mode === "
|
|
400
|
-
return value;
|
|
399
|
+
if (mode === "text") {
|
|
400
|
+
return value.split("\n").map((line) => `<p>${line}</p>`).join("");
|
|
401
401
|
}
|
|
402
|
-
return value
|
|
402
|
+
return value;
|
|
403
403
|
};
|
|
404
404
|
wrapper.innerHTML = toInnerHTML(defaultValue ? String(defaultValue) : "");
|
|
405
405
|
const attachFile = createAttachFile({
|
|
@@ -352,7 +352,7 @@ var createCommands = (schema, view, options = {}) => {
|
|
|
352
352
|
import { DOMParser, DOMSerializer } from "prosemirror-model";
|
|
353
353
|
import { Subject } from "rxjs";
|
|
354
354
|
function createTextEditorController(container, schema, options, {
|
|
355
|
-
mode,
|
|
355
|
+
mode = "html",
|
|
356
356
|
state,
|
|
357
357
|
editor,
|
|
358
358
|
defaultValue,
|
|
@@ -364,10 +364,10 @@ function createTextEditorController(container, schema, options, {
|
|
|
364
364
|
const prosemirrorSerializer = DOMSerializer.fromSchema(schema);
|
|
365
365
|
const wrapper = document.createElement("div");
|
|
366
366
|
const toInnerHTML = (value) => {
|
|
367
|
-
if (mode === "
|
|
368
|
-
return value;
|
|
367
|
+
if (mode === "text") {
|
|
368
|
+
return value.split("\n").map((line) => `<p>${line}</p>`).join("");
|
|
369
369
|
}
|
|
370
|
-
return value
|
|
370
|
+
return value;
|
|
371
371
|
};
|
|
372
372
|
wrapper.innerHTML = toInnerHTML(defaultValue ? String(defaultValue) : "");
|
|
373
373
|
const attachFile = createAttachFile({
|