@react-email/editor 0.0.0-experimental.35 → 0.0.0-experimental.38
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/core/index.cjs +8 -7
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.mts +3 -2
- package/dist/core/index.mjs +3 -3
- package/dist/create-paste-handler-B8BtjBk3.d.cts +14 -0
- package/dist/create-paste-handler-B8BtjBk3.d.cts.map +1 -0
- package/dist/create-paste-handler-CGR738bC.d.mts +14 -0
- package/dist/create-paste-handler-CGR738bC.d.mts.map +1 -0
- package/dist/{columns-Cos2lqfu.mjs → event-bus-CHEzOS_O.mjs} +45 -45
- package/dist/event-bus-CHEzOS_O.mjs.map +1 -0
- package/dist/{columns-BXN-NNd4.cjs → event-bus-fb8U7hrl.cjs} +42 -42
- package/dist/extension-CnC8y63H.mjs +1119 -0
- package/dist/extension-CnC8y63H.mjs.map +1 -0
- package/dist/extension-dGpPpEvD.cjs +1244 -0
- package/dist/extensions/index.cjs +45 -45
- package/dist/extensions/index.d.cts +2 -41
- package/dist/extensions/index.d.cts.map +1 -1
- package/dist/extensions/index.d.mts +3 -41
- package/dist/extensions/index.d.mts.map +1 -1
- package/dist/extensions/index.mjs +3 -3
- package/dist/{core-mUMTkab3.mjs → extensions-DWsu9kwZ.mjs} +221 -221
- package/dist/extensions-DWsu9kwZ.mjs.map +1 -0
- package/dist/{core-DVox_fis.cjs → extensions-aMMnHcs9.cjs} +298 -280
- package/dist/{global-content-kdUzYcsA.mjs → global-content-5rAU84QT.mjs} +1 -1
- package/dist/{global-content-kdUzYcsA.mjs.map → global-content-5rAU84QT.mjs.map} +1 -1
- package/dist/{global-content-BRvA4PRG.cjs → global-content-62RO9uoQ.cjs} +1 -1
- package/dist/{index-CVRlPqX_.d.cts → index-C4KcMQ0R.d.cts} +43 -13
- package/dist/index-C4KcMQ0R.d.cts.map +1 -0
- package/dist/{index-BrSAA0dn.d.mts → index-CxX7W63O.d.mts} +43 -13
- package/dist/index-CxX7W63O.d.mts.map +1 -0
- package/dist/index.cjs +74 -0
- package/dist/index.css +859 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +33 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +33 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +74 -0
- package/dist/index.mjs.map +1 -0
- package/dist/plugins/index.cjs +22 -1138
- package/dist/plugins/index.d.cts.map +1 -1
- package/dist/plugins/index.d.mts +1 -1
- package/dist/plugins/index.d.mts.map +1 -1
- package/dist/plugins/index.mjs +2 -1118
- package/dist/root-BMxsq1NF.mjs +2401 -0
- package/dist/root-BMxsq1NF.mjs.map +1 -0
- package/dist/root-CNVO39XG.cjs +2941 -0
- package/dist/{set-text-alignment-BO24ieeE.mjs → set-text-alignment-GMXOPMlJ.mjs} +1 -1
- package/dist/{set-text-alignment-BO24ieeE.mjs.map → set-text-alignment-GMXOPMlJ.mjs.map} +1 -1
- package/dist/{styles-DLviD0JK.mjs → styles-_TMw3YxC.mjs} +1 -1
- package/dist/{styles-DLviD0JK.mjs.map → styles-_TMw3YxC.mjs.map} +1 -1
- package/dist/ui/index.cjs +128 -2515
- package/dist/ui/index.d.cts +97 -102
- package/dist/ui/index.d.cts.map +1 -1
- package/dist/ui/index.d.mts +98 -103
- package/dist/ui/index.d.mts.map +1 -1
- package/dist/ui/index.mjs +2 -2388
- package/dist/ui/index.mjs.map +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.mjs +1 -1
- package/package.json +12 -2
- package/dist/columns-Cos2lqfu.mjs.map +0 -1
- package/dist/core-mUMTkab3.mjs.map +0 -1
- package/dist/index-BrSAA0dn.d.mts.map +0 -1
- package/dist/index-CVRlPqX_.d.cts.map +0 -1
- package/dist/plugins/index.mjs.map +0 -1
- /package/dist/{set-text-alignment-CbECklB4.cjs → set-text-alignment-aNb7Ml9N.cjs} +0 -0
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as GlobalContent } from "./global-content-
|
|
1
|
+
import { n as inlineCssToJs, r as resolveConflictingStyles } from "./styles-_TMw3YxC.mjs";
|
|
2
|
+
import { d as TABLE_ATTRIBUTES, f as TABLE_CELL_ATTRIBUTES, h as EmailNode, i as FourColumns, l as COMMON_HTML_ATTRIBUTES, m as createStandardAttributes, o as ThreeColumns, p as TABLE_HEADER_ATTRIBUTES, r as ColumnsColumn, s as TwoColumns, t as editorEventBus, u as LAYOUT_ATTRIBUTES } from "./event-bus-CHEzOS_O.mjs";
|
|
3
|
+
import { t as GlobalContent } from "./global-content-5rAU84QT.mjs";
|
|
4
|
+
import { UndoRedo } from "@tiptap/extensions";
|
|
5
|
+
import { NodeViewContent, NodeViewWrapper, ReactNodeViewRenderer, useEditor, useEditorState } from "@tiptap/react";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { generateJSON } from "@tiptap/html";
|
|
4
8
|
import * as ReactEmailComponents from "@react-email/components";
|
|
5
9
|
import { Body, Button, CodeBlock, Column, Head, Heading, Hr, Html, Link, Preview, Row, Section, pretty, render, toPlainText } from "@react-email/components";
|
|
6
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
11
|
import { Extension, InputRule, Mark, Node as Node$1, findChildren, mergeAttributes } from "@tiptap/core";
|
|
8
|
-
import { UndoRedo } from "@tiptap/extensions";
|
|
9
|
-
import { NodeViewContent, NodeViewWrapper, ReactNodeViewRenderer, useEditor, useEditorState } from "@tiptap/react";
|
|
10
|
-
import * as React from "react";
|
|
11
12
|
import TipTapStarterKit from "@tiptap/starter-kit";
|
|
12
13
|
import BlockquoteBase from "@tiptap/extension-blockquote";
|
|
13
14
|
import BoldBase from "@tiptap/extension-bold";
|
|
@@ -31,25 +32,131 @@ import StrikeBase from "@tiptap/extension-strike";
|
|
|
31
32
|
import SuperscriptBase from "@tiptap/extension-superscript";
|
|
32
33
|
import { Text } from "@tiptap/extension-text";
|
|
33
34
|
import UnderlineBase from "@tiptap/extension-underline";
|
|
34
|
-
import { generateJSON } from "@tiptap/html";
|
|
35
35
|
|
|
36
|
-
//#region src/core/
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
//#region src/core/create-drop-handler.ts
|
|
37
|
+
function createDropHandler({ onPaste, onUploadImage }) {
|
|
38
|
+
return (view, event, _slice, moved) => {
|
|
39
|
+
if (!moved && event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
const file = event.dataTransfer.files[0];
|
|
42
|
+
if (onPaste?.(file, view)) return true;
|
|
43
|
+
if (file.type.includes("image/") && onUploadImage) {
|
|
44
|
+
onUploadImage(file, view, (view.posAtCoords({
|
|
45
|
+
left: event.clientX,
|
|
46
|
+
top: event.clientY
|
|
47
|
+
})?.pos || 0) - 1);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/utils/paste-sanitizer.ts
|
|
57
|
+
/**
|
|
58
|
+
* Sanitizes pasted HTML.
|
|
59
|
+
* - From editor (has node-* classes): pass through as-is
|
|
60
|
+
* - From external: strip all styles/classes, keep only semantic HTML
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* Detects content from the Resend editor by checking for node-* class names.
|
|
64
|
+
*/
|
|
65
|
+
const EDITOR_CLASS_PATTERN = /class="[^"]*node-/;
|
|
66
|
+
/**
|
|
67
|
+
* Attributes to preserve on specific elements for EXTERNAL content.
|
|
68
|
+
* Only functional attributes - NO style or class.
|
|
69
|
+
*/
|
|
70
|
+
const PRESERVED_ATTRIBUTES = {
|
|
71
|
+
a: [
|
|
72
|
+
"href",
|
|
73
|
+
"target",
|
|
74
|
+
"rel"
|
|
75
|
+
],
|
|
76
|
+
img: [
|
|
77
|
+
"src",
|
|
78
|
+
"alt",
|
|
79
|
+
"width",
|
|
80
|
+
"height"
|
|
81
|
+
],
|
|
82
|
+
td: ["colspan", "rowspan"],
|
|
83
|
+
th: [
|
|
84
|
+
"colspan",
|
|
85
|
+
"rowspan",
|
|
86
|
+
"scope"
|
|
87
|
+
],
|
|
88
|
+
table: [
|
|
89
|
+
"border",
|
|
90
|
+
"cellpadding",
|
|
91
|
+
"cellspacing"
|
|
92
|
+
],
|
|
93
|
+
"*": ["id"]
|
|
94
|
+
};
|
|
95
|
+
function isFromEditor(html) {
|
|
96
|
+
return EDITOR_CLASS_PATTERN.test(html);
|
|
97
|
+
}
|
|
98
|
+
function sanitizePastedHtml(html) {
|
|
99
|
+
if (isFromEditor(html)) return html;
|
|
100
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
101
|
+
sanitizeNode(doc.body);
|
|
102
|
+
return doc.body.innerHTML;
|
|
103
|
+
}
|
|
104
|
+
function sanitizeNode(node) {
|
|
105
|
+
if (node.nodeType === Node.ELEMENT_NODE) sanitizeElement(node);
|
|
106
|
+
for (const child of Array.from(node.childNodes)) sanitizeNode(child);
|
|
107
|
+
}
|
|
108
|
+
function sanitizeElement(el) {
|
|
109
|
+
const allowedForTag = PRESERVED_ATTRIBUTES[el.tagName.toLowerCase()] || [];
|
|
110
|
+
const allowedGlobal = PRESERVED_ATTRIBUTES["*"] || [];
|
|
111
|
+
const allowed = new Set([...allowedForTag, ...allowedGlobal]);
|
|
112
|
+
const attributesToRemove = [];
|
|
113
|
+
for (const attr of Array.from(el.attributes)) {
|
|
114
|
+
if (attr.name.startsWith("data-")) {
|
|
115
|
+
attributesToRemove.push(attr.name);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (!allowed.has(attr.name)) attributesToRemove.push(attr.name);
|
|
49
119
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
120
|
+
for (const attr of attributesToRemove) el.removeAttribute(attr);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/core/create-paste-handler.ts
|
|
125
|
+
function createPasteHandler({ onPaste, onUploadImage, extensions }) {
|
|
126
|
+
return (view, event, slice) => {
|
|
127
|
+
const text = event.clipboardData?.getData("text/plain");
|
|
128
|
+
if (text && onPaste?.(text, view)) {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
if (event.clipboardData?.files?.[0]) {
|
|
133
|
+
const file = event.clipboardData.files[0];
|
|
134
|
+
if (onPaste?.(file, view)) {
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
if (file.type.includes("image/") && onUploadImage) {
|
|
139
|
+
const pos = view.state.selection.from;
|
|
140
|
+
onUploadImage(file, view, pos);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* If the coming content has a single child, we can assume
|
|
146
|
+
* it's a plain text and doesn't need to be parsed and
|
|
147
|
+
* be introduced in a new line
|
|
148
|
+
*/
|
|
149
|
+
if (slice.content.childCount === 1) return false;
|
|
150
|
+
if (event.clipboardData?.getData?.("text/html")) {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
const jsonContent = generateJSON(sanitizePastedHtml(event.clipboardData.getData("text/html")), extensions);
|
|
153
|
+
const node = view.state.schema.nodeFromJSON(jsonContent);
|
|
154
|
+
const transaction = view.state.tr.replaceSelectionWith(node, false);
|
|
155
|
+
view.dispatch(transaction);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
};
|
|
53
160
|
}
|
|
54
161
|
|
|
55
162
|
//#endregion
|
|
@@ -738,6 +845,95 @@ const Div = EmailNode.create({
|
|
|
738
845
|
}
|
|
739
846
|
});
|
|
740
847
|
|
|
848
|
+
//#endregion
|
|
849
|
+
//#region src/core/is-document-visually-empty.ts
|
|
850
|
+
function isDocumentVisuallyEmpty(doc) {
|
|
851
|
+
let nonGlobalNodeCount = 0;
|
|
852
|
+
let firstNonGlobalNode = null;
|
|
853
|
+
for (let index = 0; index < doc.childCount; index += 1) {
|
|
854
|
+
const node = doc.child(index);
|
|
855
|
+
if (node.type.name === "globalContent") continue;
|
|
856
|
+
nonGlobalNodeCount += 1;
|
|
857
|
+
if (firstNonGlobalNode === null) firstNonGlobalNode = {
|
|
858
|
+
type: node.type,
|
|
859
|
+
textContent: node.textContent,
|
|
860
|
+
childCount: node.content.childCount
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
if (nonGlobalNodeCount === 0) return true;
|
|
864
|
+
if (nonGlobalNodeCount !== 1) return false;
|
|
865
|
+
return firstNonGlobalNode?.type.name === "paragraph" && firstNonGlobalNode.textContent.trim().length === 0 && firstNonGlobalNode.childCount === 0;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
//#endregion
|
|
869
|
+
//#region src/core/use-editor.ts
|
|
870
|
+
const COLLABORATION_EXTENSION_NAMES = new Set(["liveblocksExtension", "collaboration"]);
|
|
871
|
+
function hasCollaborationExtension(exts) {
|
|
872
|
+
return exts.some((ext) => COLLABORATION_EXTENSION_NAMES.has(ext.name));
|
|
873
|
+
}
|
|
874
|
+
function useEditor$1({ content, extensions = [], onUpdate, onPaste, onUploadImage, onReady, editable = true, ...rest }) {
|
|
875
|
+
const [contentError, setContentError] = React.useState(null);
|
|
876
|
+
const isCollaborative = hasCollaborationExtension(extensions);
|
|
877
|
+
const effectiveExtensions = React.useMemo(() => [
|
|
878
|
+
StarterKit,
|
|
879
|
+
...isCollaborative ? [] : [UndoRedo],
|
|
880
|
+
...extensions
|
|
881
|
+
], [extensions, isCollaborative]);
|
|
882
|
+
const editor = useEditor({
|
|
883
|
+
content: isCollaborative ? void 0 : content,
|
|
884
|
+
extensions: effectiveExtensions,
|
|
885
|
+
editable,
|
|
886
|
+
immediatelyRender: false,
|
|
887
|
+
enableContentCheck: true,
|
|
888
|
+
onContentError({ editor: editor$1, error, disableCollaboration }) {
|
|
889
|
+
disableCollaboration();
|
|
890
|
+
setContentError(error);
|
|
891
|
+
console.error(error);
|
|
892
|
+
editor$1.setEditable(false);
|
|
893
|
+
},
|
|
894
|
+
onCreate({ editor: editor$1 }) {
|
|
895
|
+
onReady?.(editor$1);
|
|
896
|
+
},
|
|
897
|
+
onUpdate({ editor: editor$1, transaction }) {
|
|
898
|
+
onUpdate?.(editor$1, transaction);
|
|
899
|
+
},
|
|
900
|
+
editorProps: {
|
|
901
|
+
handleDOMEvents: { click: (view, event) => {
|
|
902
|
+
if (!view.editable) {
|
|
903
|
+
if (event.target.closest("a")) {
|
|
904
|
+
event.preventDefault();
|
|
905
|
+
return true;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return false;
|
|
909
|
+
} },
|
|
910
|
+
handlePaste: createPasteHandler({
|
|
911
|
+
onPaste,
|
|
912
|
+
onUploadImage,
|
|
913
|
+
extensions: effectiveExtensions
|
|
914
|
+
}),
|
|
915
|
+
handleDrop: createDropHandler({
|
|
916
|
+
onPaste,
|
|
917
|
+
onUploadImage
|
|
918
|
+
})
|
|
919
|
+
},
|
|
920
|
+
...rest
|
|
921
|
+
});
|
|
922
|
+
return {
|
|
923
|
+
editor,
|
|
924
|
+
isEditorEmpty: useEditorState({
|
|
925
|
+
editor,
|
|
926
|
+
selector: (context) => {
|
|
927
|
+
if (!context.editor) return true;
|
|
928
|
+
return isDocumentVisuallyEmpty(context.editor.state.doc);
|
|
929
|
+
}
|
|
930
|
+
}) ?? true,
|
|
931
|
+
extensions: effectiveExtensions,
|
|
932
|
+
contentError,
|
|
933
|
+
isCollaborative
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
|
|
741
937
|
//#endregion
|
|
742
938
|
//#region src/extensions/divider.tsx
|
|
743
939
|
const Divider = EmailNode.from(HorizontalRule.extend({
|
|
@@ -1714,201 +1910,5 @@ const StarterKit = Extension.create({
|
|
|
1714
1910
|
});
|
|
1715
1911
|
|
|
1716
1912
|
//#endregion
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
return (view, event, _slice, moved) => {
|
|
1720
|
-
if (!moved && event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {
|
|
1721
|
-
event.preventDefault();
|
|
1722
|
-
const file = event.dataTransfer.files[0];
|
|
1723
|
-
if (onPaste?.(file, view)) return true;
|
|
1724
|
-
if (file.type.includes("image/") && onUploadImage) {
|
|
1725
|
-
onUploadImage(file, view, (view.posAtCoords({
|
|
1726
|
-
left: event.clientX,
|
|
1727
|
-
top: event.clientY
|
|
1728
|
-
})?.pos || 0) - 1);
|
|
1729
|
-
return true;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
return false;
|
|
1733
|
-
};
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
//#endregion
|
|
1737
|
-
//#region src/utils/paste-sanitizer.ts
|
|
1738
|
-
/**
|
|
1739
|
-
* Sanitizes pasted HTML.
|
|
1740
|
-
* - From editor (has node-* classes): pass through as-is
|
|
1741
|
-
* - From external: strip all styles/classes, keep only semantic HTML
|
|
1742
|
-
*/
|
|
1743
|
-
/**
|
|
1744
|
-
* Detects content from the Resend editor by checking for node-* class names.
|
|
1745
|
-
*/
|
|
1746
|
-
const EDITOR_CLASS_PATTERN = /class="[^"]*node-/;
|
|
1747
|
-
/**
|
|
1748
|
-
* Attributes to preserve on specific elements for EXTERNAL content.
|
|
1749
|
-
* Only functional attributes - NO style or class.
|
|
1750
|
-
*/
|
|
1751
|
-
const PRESERVED_ATTRIBUTES = {
|
|
1752
|
-
a: [
|
|
1753
|
-
"href",
|
|
1754
|
-
"target",
|
|
1755
|
-
"rel"
|
|
1756
|
-
],
|
|
1757
|
-
img: [
|
|
1758
|
-
"src",
|
|
1759
|
-
"alt",
|
|
1760
|
-
"width",
|
|
1761
|
-
"height"
|
|
1762
|
-
],
|
|
1763
|
-
td: ["colspan", "rowspan"],
|
|
1764
|
-
th: [
|
|
1765
|
-
"colspan",
|
|
1766
|
-
"rowspan",
|
|
1767
|
-
"scope"
|
|
1768
|
-
],
|
|
1769
|
-
table: [
|
|
1770
|
-
"border",
|
|
1771
|
-
"cellpadding",
|
|
1772
|
-
"cellspacing"
|
|
1773
|
-
],
|
|
1774
|
-
"*": ["id"]
|
|
1775
|
-
};
|
|
1776
|
-
function isFromEditor(html) {
|
|
1777
|
-
return EDITOR_CLASS_PATTERN.test(html);
|
|
1778
|
-
}
|
|
1779
|
-
function sanitizePastedHtml(html) {
|
|
1780
|
-
if (isFromEditor(html)) return html;
|
|
1781
|
-
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
1782
|
-
sanitizeNode(doc.body);
|
|
1783
|
-
return doc.body.innerHTML;
|
|
1784
|
-
}
|
|
1785
|
-
function sanitizeNode(node) {
|
|
1786
|
-
if (node.nodeType === Node.ELEMENT_NODE) sanitizeElement(node);
|
|
1787
|
-
for (const child of Array.from(node.childNodes)) sanitizeNode(child);
|
|
1788
|
-
}
|
|
1789
|
-
function sanitizeElement(el) {
|
|
1790
|
-
const allowedForTag = PRESERVED_ATTRIBUTES[el.tagName.toLowerCase()] || [];
|
|
1791
|
-
const allowedGlobal = PRESERVED_ATTRIBUTES["*"] || [];
|
|
1792
|
-
const allowed = new Set([...allowedForTag, ...allowedGlobal]);
|
|
1793
|
-
const attributesToRemove = [];
|
|
1794
|
-
for (const attr of Array.from(el.attributes)) {
|
|
1795
|
-
if (attr.name.startsWith("data-")) {
|
|
1796
|
-
attributesToRemove.push(attr.name);
|
|
1797
|
-
continue;
|
|
1798
|
-
}
|
|
1799
|
-
if (!allowed.has(attr.name)) attributesToRemove.push(attr.name);
|
|
1800
|
-
}
|
|
1801
|
-
for (const attr of attributesToRemove) el.removeAttribute(attr);
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
//#endregion
|
|
1805
|
-
//#region src/core/create-paste-handler.ts
|
|
1806
|
-
function createPasteHandler({ onPaste, onUploadImage, extensions }) {
|
|
1807
|
-
return (view, event, slice) => {
|
|
1808
|
-
const text = event.clipboardData?.getData("text/plain");
|
|
1809
|
-
if (text && onPaste?.(text, view)) {
|
|
1810
|
-
event.preventDefault();
|
|
1811
|
-
return true;
|
|
1812
|
-
}
|
|
1813
|
-
if (event.clipboardData?.files?.[0]) {
|
|
1814
|
-
const file = event.clipboardData.files[0];
|
|
1815
|
-
if (onPaste?.(file, view)) {
|
|
1816
|
-
event.preventDefault();
|
|
1817
|
-
return true;
|
|
1818
|
-
}
|
|
1819
|
-
if (file.type.includes("image/") && onUploadImage) {
|
|
1820
|
-
const pos = view.state.selection.from;
|
|
1821
|
-
onUploadImage(file, view, pos);
|
|
1822
|
-
return true;
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
/**
|
|
1826
|
-
* If the coming content has a single child, we can assume
|
|
1827
|
-
* it's a plain text and doesn't need to be parsed and
|
|
1828
|
-
* be introduced in a new line
|
|
1829
|
-
*/
|
|
1830
|
-
if (slice.content.childCount === 1) return false;
|
|
1831
|
-
if (event.clipboardData?.getData?.("text/html")) {
|
|
1832
|
-
event.preventDefault();
|
|
1833
|
-
const jsonContent = generateJSON(sanitizePastedHtml(event.clipboardData.getData("text/html")), extensions);
|
|
1834
|
-
const node = view.state.schema.nodeFromJSON(jsonContent);
|
|
1835
|
-
const transaction = view.state.tr.replaceSelectionWith(node, false);
|
|
1836
|
-
view.dispatch(transaction);
|
|
1837
|
-
return true;
|
|
1838
|
-
}
|
|
1839
|
-
return false;
|
|
1840
|
-
};
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
//#endregion
|
|
1844
|
-
//#region src/core/use-editor.ts
|
|
1845
|
-
const COLLABORATION_EXTENSION_NAMES = new Set(["liveblocksExtension", "collaboration"]);
|
|
1846
|
-
function hasCollaborationExtension(exts) {
|
|
1847
|
-
return exts.some((ext) => COLLABORATION_EXTENSION_NAMES.has(ext.name));
|
|
1848
|
-
}
|
|
1849
|
-
function useEditor$1({ content, extensions = [], onUpdate, onPaste, onUploadImage, onReady, editable = true, ...rest }) {
|
|
1850
|
-
const [contentError, setContentError] = React.useState(null);
|
|
1851
|
-
const isCollaborative = hasCollaborationExtension(extensions);
|
|
1852
|
-
const effectiveExtensions = React.useMemo(() => [
|
|
1853
|
-
StarterKit,
|
|
1854
|
-
...isCollaborative ? [] : [UndoRedo],
|
|
1855
|
-
...extensions
|
|
1856
|
-
], [extensions, isCollaborative]);
|
|
1857
|
-
const editor = useEditor({
|
|
1858
|
-
content: isCollaborative ? void 0 : content,
|
|
1859
|
-
extensions: effectiveExtensions,
|
|
1860
|
-
editable,
|
|
1861
|
-
immediatelyRender: false,
|
|
1862
|
-
enableContentCheck: true,
|
|
1863
|
-
onContentError({ editor: editor$1, error, disableCollaboration }) {
|
|
1864
|
-
disableCollaboration();
|
|
1865
|
-
setContentError(error);
|
|
1866
|
-
console.error(error);
|
|
1867
|
-
editor$1.setEditable(false);
|
|
1868
|
-
},
|
|
1869
|
-
onCreate({ editor: editor$1 }) {
|
|
1870
|
-
onReady?.(editor$1);
|
|
1871
|
-
},
|
|
1872
|
-
onUpdate({ editor: editor$1, transaction }) {
|
|
1873
|
-
onUpdate?.(editor$1, transaction);
|
|
1874
|
-
},
|
|
1875
|
-
editorProps: {
|
|
1876
|
-
handleDOMEvents: { click: (view, event) => {
|
|
1877
|
-
if (!view.editable) {
|
|
1878
|
-
if (event.target.closest("a")) {
|
|
1879
|
-
event.preventDefault();
|
|
1880
|
-
return true;
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
return false;
|
|
1884
|
-
} },
|
|
1885
|
-
handlePaste: createPasteHandler({
|
|
1886
|
-
onPaste,
|
|
1887
|
-
onUploadImage,
|
|
1888
|
-
extensions: effectiveExtensions
|
|
1889
|
-
}),
|
|
1890
|
-
handleDrop: createDropHandler({
|
|
1891
|
-
onPaste,
|
|
1892
|
-
onUploadImage
|
|
1893
|
-
})
|
|
1894
|
-
},
|
|
1895
|
-
...rest
|
|
1896
|
-
});
|
|
1897
|
-
return {
|
|
1898
|
-
editor,
|
|
1899
|
-
isEditorEmpty: useEditorState({
|
|
1900
|
-
editor,
|
|
1901
|
-
selector: (context) => {
|
|
1902
|
-
if (!context.editor) return true;
|
|
1903
|
-
return isDocumentVisuallyEmpty(context.editor.state.doc);
|
|
1904
|
-
}
|
|
1905
|
-
}) ?? true,
|
|
1906
|
-
extensions: effectiveExtensions,
|
|
1907
|
-
contentError,
|
|
1908
|
-
isCollaborative
|
|
1909
|
-
};
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
//#endregion
|
|
1913
|
-
export { ClassAttribute as A, Italic as C, Div as D, Divider as E, Blockquote as F, AlignmentAttribute as I, composeReactEmail as L, BulletList as M, Bold as N, CodeBlockPrism as O, Body$1 as P, isDocumentVisuallyEmpty as R, processStylesForUnlink as S, HardBreak as T, OrderedList as _, Text$1 as a, Link$1 as b, TableHeader as c, StyleAttribute as d, Strike as f, Paragraph as g, Placeholder as h, Underline as i, Button$1 as j, Code as k, TableRow as l, PreviewText as m, StarterKit as n, Table as o, Section$1 as p, Uppercase as r, TableCell as s, useEditor$1 as t, Sup as u, MaxNesting as v, Heading$2 as w, PreservedStyle as x, ListItem as y };
|
|
1914
|
-
//# sourceMappingURL=core-mUMTkab3.mjs.map
|
|
1913
|
+
export { Code as A, createPasteHandler as B, Heading$2 as C, isDocumentVisuallyEmpty as D, useEditor$1 as E, Body$1 as F, Blockquote as I, AlignmentAttribute as L, Button$1 as M, BulletList as N, Div as O, Bold as P, composeReactEmail as R, Italic as S, Divider as T, createDropHandler as V, MaxNesting as _, Table as a, PreservedStyle as b, TableRow as c, Strike as d, Section$1 as f, OrderedList as g, Paragraph as h, Text$1 as i, ClassAttribute as j, CodeBlockPrism as k, Sup as l, Placeholder as m, Uppercase as n, TableCell as o, PreviewText as p, Underline as r, TableHeader as s, StarterKit as t, StyleAttribute as u, ListItem as v, HardBreak as w, processStylesForUnlink as x, Link$1 as y, EmailMark as z };
|
|
1914
|
+
//# sourceMappingURL=extensions-DWsu9kwZ.mjs.map
|