@react-fabric/lexical 1.0.0-beta.0
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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/cjs/_virtual/prism.js +5 -0
- package/dist/cjs/editor/Lexical.module.css +1 -0
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +432 -0
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +21 -0
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +27 -0
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +1139 -0
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +25 -0
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +50 -0
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +245 -0
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +19 -0
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +18 -0
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +471 -0
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +17 -0
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +24 -0
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +1275 -0
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +29 -0
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +29 -0
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +789 -0
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +29 -0
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +26 -0
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +976 -0
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +35 -0
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +35 -0
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +2792 -0
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +23 -0
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +55 -0
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +888 -0
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +35 -0
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +66 -0
- package/dist/cjs/node_modules/@mdi/js/mdi.js +8 -0
- package/dist/cjs/node_modules/prismjs/components/prism-c.js +82 -0
- package/dist/cjs/node_modules/prismjs/components/prism-clike.js +33 -0
- package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +101 -0
- package/dist/cjs/node_modules/prismjs/components/prism-css.js +66 -0
- package/dist/cjs/node_modules/prismjs/components/prism-java.js +126 -0
- package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +174 -0
- package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +417 -0
- package/dist/cjs/node_modules/prismjs/components/prism-markup.js +188 -0
- package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +14 -0
- package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +60 -0
- package/dist/cjs/node_modules/prismjs/components/prism-python.js +67 -0
- package/dist/cjs/node_modules/prismjs/components/prism-rust.js +130 -0
- package/dist/cjs/node_modules/prismjs/components/prism-sql.js +34 -0
- package/dist/cjs/node_modules/prismjs/components/prism-swift.js +150 -0
- package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +62 -0
- package/dist/cjs/node_modules/prismjs/prism.js +1951 -0
- package/dist/cjs/packages/lexical/src/components/StickyComponent.js +221 -0
- package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +156 -0
- package/dist/cjs/packages/lexical/src/editor/theme.js +97 -0
- package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +451 -0
- package/dist/cjs/packages/lexical/src/index.js +7 -0
- package/dist/cjs/packages/lexical/src/nodes/StickyNode.js +218 -0
- package/dist/cjs/packages/lexical/src/plugins/DraggableBlockPlugin.js +314 -0
- package/dist/cjs/packages/lexical/src/plugins/StickyPlugin.js +20 -0
- package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +258 -0
- package/dist/cjs/packages/lexical/src/utils/index.js +214 -0
- package/dist/esm/_virtual/prism.js +5 -0
- package/dist/esm/editor/Lexical.module.css +1 -0
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +423 -0
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +19 -0
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +18 -0
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +1121 -0
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +21 -0
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +32 -0
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +244 -0
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +18 -0
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +17 -0
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +463 -0
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +17 -0
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +16 -0
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +1262 -0
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +23 -0
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +16 -0
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +781 -0
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +23 -0
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +18 -0
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +957 -0
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +26 -0
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +16 -0
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +2754 -0
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +20 -0
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +17 -0
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +839 -0
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +26 -0
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +17 -0
- package/dist/esm/node_modules/@mdi/js/mdi.js +7 -0
- package/dist/esm/node_modules/prismjs/components/prism-c.js +82 -0
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +33 -0
- package/dist/esm/node_modules/prismjs/components/prism-cpp.js +101 -0
- package/dist/esm/node_modules/prismjs/components/prism-css.js +66 -0
- package/dist/esm/node_modules/prismjs/components/prism-java.js +126 -0
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +174 -0
- package/dist/esm/node_modules/prismjs/components/prism-markdown.js +417 -0
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +188 -0
- package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +14 -0
- package/dist/esm/node_modules/prismjs/components/prism-powershell.js +60 -0
- package/dist/esm/node_modules/prismjs/components/prism-python.js +67 -0
- package/dist/esm/node_modules/prismjs/components/prism-rust.js +130 -0
- package/dist/esm/node_modules/prismjs/components/prism-sql.js +34 -0
- package/dist/esm/node_modules/prismjs/components/prism-swift.js +150 -0
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +62 -0
- package/dist/esm/node_modules/prismjs/prism.js +1951 -0
- package/dist/esm/packages/lexical/src/components/StickyComponent.js +221 -0
- package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +156 -0
- package/dist/esm/packages/lexical/src/editor/theme.js +97 -0
- package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +450 -0
- package/dist/esm/packages/lexical/src/index.js +3 -0
- package/dist/esm/packages/lexical/src/nodes/StickyNode.js +216 -0
- package/dist/esm/packages/lexical/src/plugins/DraggableBlockPlugin.js +314 -0
- package/dist/esm/packages/lexical/src/plugins/StickyPlugin.js +20 -0
- package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +258 -0
- package/dist/esm/packages/lexical/src/utils/index.js +211 -0
- package/dist/types/components/StickyComponent.d.ts +9 -0
- package/dist/types/editor/LexicalEditor.d.ts +13 -0
- package/dist/types/editor/theme.d.ts +70 -0
- package/dist/types/hooks/useFormatWatcher.d.ts +40 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/nodes/StickyNode.d.ts +35 -0
- package/dist/types/plugins/DraggableBlockPlugin.d.ts +3 -0
- package/dist/types/plugins/StickyPlugin.d.ts +1 -0
- package/dist/types/plugins/ToolbarPlugin.d.ts +1 -0
- package/dist/types/utils/index.d.ts +57 -0
- package/package.json +55 -0
- package/src/components/StickyComponent.tsx +271 -0
- package/src/editor/Lexical.module.css +218 -0
- package/src/editor/LexicalEditor.tsx +222 -0
- package/src/editor/theme.ts +93 -0
- package/src/hooks/useFormatWatcher.ts +504 -0
- package/src/index.ts +24 -0
- package/src/nodes/StickyNode.tsx +249 -0
- package/src/plugins/DraggableBlockPlugin.tsx +418 -0
- package/src/plugins/StickyPlugin.ts +38 -0
- package/src/plugins/ToolbarPlugin.tsx +279 -0
- package/src/utils/index.ts +303 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
|
+
import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin';
|
|
5
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
6
|
+
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
7
|
+
import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
|
|
8
|
+
import { LexicalNestedComposer } from '@lexical/react/LexicalNestedComposer';
|
|
9
|
+
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
10
|
+
import { mdiFormatColorFill, mdiClose } from '../../../../node_modules/@mdi/js/mdi.js';
|
|
11
|
+
import { Icon } from '@react-fabric/core';
|
|
12
|
+
import { createEditor, $getNodeByKey } from 'lexical';
|
|
13
|
+
import { useRef, useEffect, useMemo } from 'react';
|
|
14
|
+
import { $isStickyNode } from '../nodes/StickyNode.js';
|
|
15
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
function positionSticky(stickyElem, positioning) {
|
|
18
|
+
var style = stickyElem.style;
|
|
19
|
+
style.top = "".concat(positioning.y, "px");
|
|
20
|
+
style.left = "".concat(positioning.x, "px");
|
|
21
|
+
}
|
|
22
|
+
var StickyComponent = function StickyComponent(_ref) {
|
|
23
|
+
var _ref$x = _ref.x,
|
|
24
|
+
x = _ref$x === void 0 ? 0 : _ref$x,
|
|
25
|
+
_ref$y = _ref.y,
|
|
26
|
+
y = _ref$y === void 0 ? 0 : _ref$y,
|
|
27
|
+
nodeKey = _ref.nodeKey,
|
|
28
|
+
color = _ref.color,
|
|
29
|
+
state = _ref.state,
|
|
30
|
+
user = _ref.user;
|
|
31
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
32
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
33
|
+
editor = _useLexicalComposerCo2[0];
|
|
34
|
+
var stickyContainerRef = useRef(null);
|
|
35
|
+
var positioningRef = useRef({
|
|
36
|
+
isDragging: false,
|
|
37
|
+
offsetX: 0,
|
|
38
|
+
offsetY: 0,
|
|
39
|
+
rootElementRect: {
|
|
40
|
+
left: 8,
|
|
41
|
+
top: 8
|
|
42
|
+
},
|
|
43
|
+
x: 8,
|
|
44
|
+
y: 8
|
|
45
|
+
});
|
|
46
|
+
useEffect(function () {
|
|
47
|
+
var position = positioningRef.current;
|
|
48
|
+
position.x = x;
|
|
49
|
+
position.y = y;
|
|
50
|
+
var stickyContainer = stickyContainerRef.current;
|
|
51
|
+
if (stickyContainer !== null) {
|
|
52
|
+
positioningRef.current.rootElementRect = {
|
|
53
|
+
left: x,
|
|
54
|
+
top: y
|
|
55
|
+
};
|
|
56
|
+
positionSticky(stickyContainer, position);
|
|
57
|
+
}
|
|
58
|
+
}, [x, y]);
|
|
59
|
+
useEffect(function () {
|
|
60
|
+
var stickyContainer = stickyContainerRef.current;
|
|
61
|
+
if (stickyContainer !== null) {
|
|
62
|
+
// Delay adding transition so we don't trigger the
|
|
63
|
+
// transition on load of the sticky.
|
|
64
|
+
setTimeout(function () {
|
|
65
|
+
stickyContainer.style.setProperty("transition", "top 300ms ease 0s, left 300ms ease 0s");
|
|
66
|
+
}, 500);
|
|
67
|
+
}
|
|
68
|
+
}, []);
|
|
69
|
+
var handlePointerMove = function handlePointerMove(event) {
|
|
70
|
+
var stickyContainer = stickyContainerRef.current;
|
|
71
|
+
var positioning = positioningRef.current;
|
|
72
|
+
var rootElementRect = positioning.rootElementRect;
|
|
73
|
+
if (stickyContainer !== null && positioning.isDragging && rootElementRect !== null) {
|
|
74
|
+
positioning.x = rootElementRect.left + (event.pageX - positioning.offsetX);
|
|
75
|
+
positioning.y = rootElementRect.top + (event.pageY - positioning.offsetY);
|
|
76
|
+
if (positioning.x < 0) positioning.x = 0;
|
|
77
|
+
if (positioning.x > 642) positioning.x = 642 - stickyContainer.offsetWidth;
|
|
78
|
+
if (positioning.y < 0) positioning.y = 0;
|
|
79
|
+
positionSticky(stickyContainer, positioning);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var handlePointerUp = function handlePointerUp(event) {
|
|
83
|
+
var stickyContainer = stickyContainerRef.current;
|
|
84
|
+
var positioning = positioningRef.current;
|
|
85
|
+
if (stickyContainer !== null) {
|
|
86
|
+
positioning.isDragging = false;
|
|
87
|
+
stickyContainer.classList.remove("dragging");
|
|
88
|
+
editor.update(function () {
|
|
89
|
+
var node = $getNodeByKey(nodeKey);
|
|
90
|
+
if ($isStickyNode(node)) {
|
|
91
|
+
node.setPosition(positioning.x, positioning.y);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
document.removeEventListener("pointermove", handlePointerMove);
|
|
96
|
+
document.removeEventListener("pointerup", handlePointerUp);
|
|
97
|
+
};
|
|
98
|
+
var handleDelete = function handleDelete() {
|
|
99
|
+
editor.update(function () {
|
|
100
|
+
var node = $getNodeByKey(nodeKey);
|
|
101
|
+
if ($isStickyNode(node)) {
|
|
102
|
+
node.remove();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
var handleColorChange = function handleColorChange() {
|
|
107
|
+
editor.update(function () {
|
|
108
|
+
var node = $getNodeByKey(nodeKey);
|
|
109
|
+
if ($isStickyNode(node)) {
|
|
110
|
+
node.toggleColor();
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
var innerEditor = useMemo(function () {
|
|
115
|
+
var editor = createEditor({
|
|
116
|
+
editable: true
|
|
117
|
+
});
|
|
118
|
+
if (state) {
|
|
119
|
+
var editorState = editor.parseEditorState(state);
|
|
120
|
+
editor.setEditorState(editorState);
|
|
121
|
+
}
|
|
122
|
+
return editor;
|
|
123
|
+
}, []);
|
|
124
|
+
useEffect(function () {
|
|
125
|
+
if (innerEditor._editable) {
|
|
126
|
+
var dispose = innerEditor.registerUpdateListener(function (_ref2) {
|
|
127
|
+
_ref2.editorState;
|
|
128
|
+
editor.update(function () {
|
|
129
|
+
var node = $getNodeByKey(nodeKey);
|
|
130
|
+
if ($isStickyNode(node)) {
|
|
131
|
+
node.updateState(innerEditor.getEditorState().toJSON());
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
return function () {
|
|
136
|
+
dispose();
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}, [innerEditor._editable]);
|
|
140
|
+
return /*#__PURE__*/jsxs("div", {
|
|
141
|
+
ref: stickyContainerRef,
|
|
142
|
+
className: "sticky__container",
|
|
143
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
144
|
+
className: "sticky__handle",
|
|
145
|
+
onPointerDown: function onPointerDown(event) {
|
|
146
|
+
var stickyContainer = stickyContainerRef.current;
|
|
147
|
+
if (stickyContainer == null || event.button === 2 || event.target !== stickyContainer.firstChild) {
|
|
148
|
+
// Right click or click on editor should not work
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
var stickContainer = stickyContainer;
|
|
152
|
+
var positioning = positioningRef.current;
|
|
153
|
+
if (stickContainer !== null) {
|
|
154
|
+
positioning.offsetX = event.clientX;
|
|
155
|
+
positioning.offsetY = event.clientY;
|
|
156
|
+
positioning.rootElementRect = {
|
|
157
|
+
left: positioning.x,
|
|
158
|
+
top: positioning.y
|
|
159
|
+
};
|
|
160
|
+
positioning.isDragging = true;
|
|
161
|
+
stickContainer.classList.add("dragging");
|
|
162
|
+
document.addEventListener("pointermove", handlePointerMove);
|
|
163
|
+
document.addEventListener("pointerup", handlePointerUp);
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
168
|
+
className: "sticky-note ".concat(color),
|
|
169
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
170
|
+
className: "sticky__tools",
|
|
171
|
+
children: [/*#__PURE__*/jsx("button", {
|
|
172
|
+
onClick: handleColorChange,
|
|
173
|
+
className: "sticky--color",
|
|
174
|
+
"aria-label": "Change sticky note color",
|
|
175
|
+
title: "Color",
|
|
176
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
177
|
+
icon: mdiFormatColorFill
|
|
178
|
+
})
|
|
179
|
+
}), /*#__PURE__*/jsx("button", {
|
|
180
|
+
onClick: handleDelete,
|
|
181
|
+
className: "sticky--delete",
|
|
182
|
+
"aria-label": "Delete sticky note",
|
|
183
|
+
title: "Delete",
|
|
184
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
185
|
+
icon: mdiClose
|
|
186
|
+
})
|
|
187
|
+
})]
|
|
188
|
+
}), /*#__PURE__*/jsx("div", {
|
|
189
|
+
className: "text-sm font-semibold",
|
|
190
|
+
children: user
|
|
191
|
+
}), /*#__PURE__*/jsxs(LexicalNestedComposer, {
|
|
192
|
+
initialEditor: innerEditor,
|
|
193
|
+
initialTheme: {
|
|
194
|
+
paragraph: "sticky__paragraph",
|
|
195
|
+
text: {
|
|
196
|
+
bold: "editor-textBold",
|
|
197
|
+
code: "editor-textCode",
|
|
198
|
+
italic: "editor-textItalic",
|
|
199
|
+
strikethrough: "editor-textStrikethrough",
|
|
200
|
+
subscript: "editor-textSubscript",
|
|
201
|
+
superscript: "editor-textSuperscript",
|
|
202
|
+
underline: "editor-textUnderline",
|
|
203
|
+
underlineStrikethrough: "editor-textUnderlineStrikethrough"
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
children: [/*#__PURE__*/jsx(RichTextPlugin, {
|
|
207
|
+
contentEditable: /*#__PURE__*/jsx(ContentEditable, {
|
|
208
|
+
className: "sticky__editor"
|
|
209
|
+
}),
|
|
210
|
+
placeholder: /*#__PURE__*/jsx("div", {
|
|
211
|
+
className: "sticky-placeholder",
|
|
212
|
+
children: "Sticky note..."
|
|
213
|
+
}),
|
|
214
|
+
ErrorBoundary: LexicalErrorBoundary
|
|
215
|
+
}), /*#__PURE__*/jsx(AutoFocusPlugin, {})]
|
|
216
|
+
})]
|
|
217
|
+
})]
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export { StickyComponent };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
|
+
import { CodeHighlightNode, CodeNode } from '../../../../node_modules/@lexical/code/LexicalCode.js';
|
|
5
|
+
import { ListItemNode, ListNode } from '../../../../node_modules/@lexical/list/LexicalList.js';
|
|
6
|
+
import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin';
|
|
7
|
+
import { CheckListPlugin } from '@lexical/react/LexicalCheckListPlugin';
|
|
8
|
+
import { LexicalComposer } from '@lexical/react/LexicalComposer';
|
|
9
|
+
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
10
|
+
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
|
11
|
+
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
|
|
12
|
+
import { ListPlugin } from '@lexical/react/LexicalListPlugin';
|
|
13
|
+
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
14
|
+
import { TablePlugin } from '@lexical/react/LexicalTablePlugin';
|
|
15
|
+
import { QuoteNode, HeadingNode } from '../../../../node_modules/@lexical/rich-text/LexicalRichText.js';
|
|
16
|
+
import { TableCellNode, TableNode, TableRowNode } from '../../../../node_modules/@lexical/table/LexicalTable.js';
|
|
17
|
+
import { Header, ErrorBoundary, ThemeProvider } from '@react-fabric/core';
|
|
18
|
+
import { debounce } from '@react-fabric/utilities';
|
|
19
|
+
import classNames from 'classnames';
|
|
20
|
+
import { useRef, useState, useCallback, useEffect, useMemo } from 'react';
|
|
21
|
+
import { StickyNode } from '../nodes/StickyNode.js';
|
|
22
|
+
import { DraggableBlockPlugin } from '../plugins/DraggableBlockPlugin.js';
|
|
23
|
+
import { StickyPlugin } from '../plugins/StickyPlugin.js';
|
|
24
|
+
import classes from './Lexical.module.css';
|
|
25
|
+
import { LexicalTheme } from './theme.js';
|
|
26
|
+
import { ToolbarPlugin } from '../plugins/ToolbarPlugin.js';
|
|
27
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
28
|
+
|
|
29
|
+
var LexicalEditor = function LexicalEditor(_ref) {
|
|
30
|
+
var value = _ref.value,
|
|
31
|
+
readOnly = _ref.readOnly,
|
|
32
|
+
publishMode = _ref.publishMode,
|
|
33
|
+
onChange = _ref.onChange,
|
|
34
|
+
onDirty = _ref.onDirty;
|
|
35
|
+
var editorRef = useRef();
|
|
36
|
+
var _useState = useState(null),
|
|
37
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
38
|
+
editorContainer = _useState2[0],
|
|
39
|
+
setEditorContainer = _useState2[1];
|
|
40
|
+
|
|
41
|
+
// Catch any errors that occur during Lexical updates and log them
|
|
42
|
+
// or throw them as needed. If you don't throw them, Lexical will
|
|
43
|
+
// try to recover gracefully without losing user data.
|
|
44
|
+
var onError = function onError(error) {
|
|
45
|
+
console.error("ERROR", error);
|
|
46
|
+
};
|
|
47
|
+
var initEditor = useCallback(function (editor) {
|
|
48
|
+
editorRef.current = editor;
|
|
49
|
+
var handler = debounce(function (_ref2) {
|
|
50
|
+
var editorState = _ref2.editorState,
|
|
51
|
+
dirtyElements = _ref2.dirtyElements;
|
|
52
|
+
_ref2.dirtyLeaves;
|
|
53
|
+
editorState.read(function () {
|
|
54
|
+
if (dirtyElements.size > 0) {
|
|
55
|
+
onDirty === null || onDirty === void 0 || onDirty(true);
|
|
56
|
+
}
|
|
57
|
+
onChange === null || onChange === void 0 || onChange(editorState.toJSON());
|
|
58
|
+
});
|
|
59
|
+
}, 500);
|
|
60
|
+
var handle = editor.registerUpdateListener(handler);
|
|
61
|
+
|
|
62
|
+
// const cb = mergeRegister(
|
|
63
|
+
// editor.registerCommand<DragEvent>(
|
|
64
|
+
// DRAGOVER_COMMAND,
|
|
65
|
+
// (event) => {
|
|
66
|
+
// return onDragover(event);
|
|
67
|
+
// },
|
|
68
|
+
// COMMAND_PRIORITY_LOW,
|
|
69
|
+
// ),
|
|
70
|
+
// editor.registerCommand<DragEvent>(
|
|
71
|
+
// DROP_COMMAND,
|
|
72
|
+
// (event) => {
|
|
73
|
+
// return onDrop(event, editor);
|
|
74
|
+
// },
|
|
75
|
+
// COMMAND_PRIORITY_HIGH,
|
|
76
|
+
// ),
|
|
77
|
+
// );
|
|
78
|
+
|
|
79
|
+
return function () {
|
|
80
|
+
handle === null || handle === void 0 || handle();
|
|
81
|
+
// cb?.();
|
|
82
|
+
};
|
|
83
|
+
}, []);
|
|
84
|
+
useEffect(function () {
|
|
85
|
+
var _editorRef$current, _editorRef$current2;
|
|
86
|
+
(_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || _editorRef$current.setEditorState((_editorRef$current2 = editorRef.current) === null || _editorRef$current2 === void 0 ? void 0 : _editorRef$current2.parseEditorState(value !== null && value !== void 0 ? value : ""));
|
|
87
|
+
}, [value]);
|
|
88
|
+
useEffect(function () {
|
|
89
|
+
var _editorRef$current3;
|
|
90
|
+
(_editorRef$current3 = editorRef.current) === null || _editorRef$current3 === void 0 || _editorRef$current3.registerRootListener(function (rootElement) {
|
|
91
|
+
rootElement && setTimeout(function () {
|
|
92
|
+
return rootElement.contentEditable = "".concat(!readOnly && !publishMode);
|
|
93
|
+
}, 100);
|
|
94
|
+
});
|
|
95
|
+
}, [readOnly, publishMode]);
|
|
96
|
+
var initialConfig = useMemo(function () {
|
|
97
|
+
return {
|
|
98
|
+
editorState: initEditor,
|
|
99
|
+
namespace: "MyEditor",
|
|
100
|
+
editable: !readOnly && !publishMode,
|
|
101
|
+
theme: LexicalTheme,
|
|
102
|
+
nodes: [QuoteNode, HeadingNode, CodeHighlightNode, CodeNode, ListItemNode, ListNode, TableCellNode, TableNode, TableRowNode, StickyNode],
|
|
103
|
+
onError: onError
|
|
104
|
+
};
|
|
105
|
+
}, []);
|
|
106
|
+
var Wrapper = useCallback(function (_ref3) {
|
|
107
|
+
var children = _ref3.children;
|
|
108
|
+
return !publishMode ? /*#__PURE__*/jsxs("div", {
|
|
109
|
+
className: "lexical-scroller area-content overflow-auto",
|
|
110
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
111
|
+
className: classNames(classes.lexicalToolbar, "sticky top-0 z-1"),
|
|
112
|
+
children: /*#__PURE__*/jsx(Header, {
|
|
113
|
+
className: "bg-base",
|
|
114
|
+
children: /*#__PURE__*/jsx(ToolbarPlugin, {})
|
|
115
|
+
})
|
|
116
|
+
}), children]
|
|
117
|
+
}) : children;
|
|
118
|
+
}, [publishMode]);
|
|
119
|
+
return /*#__PURE__*/jsx(ErrorBoundary, {
|
|
120
|
+
children: /*#__PURE__*/jsx(LexicalComposer, {
|
|
121
|
+
initialConfig: initialConfig,
|
|
122
|
+
children: /*#__PURE__*/jsx(Wrapper, {
|
|
123
|
+
children: /*#__PURE__*/jsx(ThemeProvider, {
|
|
124
|
+
colorScheme: "light",
|
|
125
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
126
|
+
role: "none",
|
|
127
|
+
className: classNames(classes.lexicalEditor, "lexical-container relative bg-white min-h-full mx-auto shadow-md print:shadow-none"),
|
|
128
|
+
onDragOver: function onDragOver(e) {
|
|
129
|
+
return e.stopPropagation();
|
|
130
|
+
},
|
|
131
|
+
onKeyDown: function onKeyDown(e) {
|
|
132
|
+
return e.stopPropagation();
|
|
133
|
+
},
|
|
134
|
+
ref: setEditorContainer,
|
|
135
|
+
children: [/*#__PURE__*/jsx(RichTextPlugin, {
|
|
136
|
+
contentEditable: /*#__PURE__*/jsx(ContentEditable, {
|
|
137
|
+
className: "lexical-editor px-[2cm] py-[1cm] min-h-screen"
|
|
138
|
+
}),
|
|
139
|
+
placeholder: /*#__PURE__*/jsx("div", {
|
|
140
|
+
className: "text-muted overflow-hidden absolute mt-6 top-[1cm] left-[2cm] select-none pointer-events-none",
|
|
141
|
+
children: "Enter some text..."
|
|
142
|
+
}),
|
|
143
|
+
ErrorBoundary: LexicalErrorBoundary
|
|
144
|
+
}), /*#__PURE__*/jsx(ListPlugin, {}), /*#__PURE__*/jsx(CheckListPlugin, {}), /*#__PURE__*/jsx(TablePlugin, {}), /*#__PURE__*/jsx(HistoryPlugin, {}), /*#__PURE__*/jsx(StickyPlugin, {}), /*#__PURE__*/jsx(AutoFocusPlugin, {
|
|
145
|
+
defaultSelection: "rootStart"
|
|
146
|
+
}), editorContainer && /*#__PURE__*/jsx(DraggableBlockPlugin, {
|
|
147
|
+
anchorElem: editorContainer
|
|
148
|
+
})]
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export { LexicalEditor };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* React Fabric
|
|
5
|
+
* @version: 1.0.0
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
12
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
13
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
14
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
* subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
18
|
+
* portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
21
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
22
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
var LexicalTheme = {
|
|
27
|
+
ltr: "ltr",
|
|
28
|
+
rtl: "rtl",
|
|
29
|
+
paragraph: "editor-paragraph",
|
|
30
|
+
quote: "editor-quote",
|
|
31
|
+
heading: {
|
|
32
|
+
h1: "editor-heading-h1",
|
|
33
|
+
h2: "editor-heading-h2",
|
|
34
|
+
h3: "editor-heading-h3",
|
|
35
|
+
h4: "editor-heading-h4",
|
|
36
|
+
h5: "editor-heading-h5",
|
|
37
|
+
h6: "editor-heading-h6"
|
|
38
|
+
},
|
|
39
|
+
list: {
|
|
40
|
+
nested: {
|
|
41
|
+
listitem: "editor-nested-listitem"
|
|
42
|
+
},
|
|
43
|
+
ol: "editor-list-ol",
|
|
44
|
+
ul: "editor-list-ul",
|
|
45
|
+
listitem: "editor-listItem",
|
|
46
|
+
listitemChecked: "editor-listItemChecked",
|
|
47
|
+
listitemUnchecked: "editor-listItemUnchecked"
|
|
48
|
+
},
|
|
49
|
+
hashtag: "editor-hashtag",
|
|
50
|
+
image: "editor-image",
|
|
51
|
+
link: "editor-link",
|
|
52
|
+
text: {
|
|
53
|
+
bold: "editor-textBold",
|
|
54
|
+
code: "editor-textCode",
|
|
55
|
+
italic: "editor-textItalic",
|
|
56
|
+
strikethrough: "editor-textStrikethrough",
|
|
57
|
+
subscript: "editor-textSubscript",
|
|
58
|
+
superscript: "editor-textSuperscript",
|
|
59
|
+
underline: "editor-textUnderline",
|
|
60
|
+
underlineStrikethrough: "editor-textUnderlineStrikethrough"
|
|
61
|
+
},
|
|
62
|
+
code: "editor-code",
|
|
63
|
+
codeHighlight: {
|
|
64
|
+
atrule: "editor-tokenAttr",
|
|
65
|
+
attr: "editor-tokenAttr",
|
|
66
|
+
"boolean": "editor-tokenProperty",
|
|
67
|
+
builtin: "editor-tokenSelector",
|
|
68
|
+
cdata: "editor-tokenComment",
|
|
69
|
+
"char": "editor-tokenSelector",
|
|
70
|
+
"class": "editor-tokenFunction",
|
|
71
|
+
"class-name": "editor-tokenFunction",
|
|
72
|
+
comment: "editor-tokenComment",
|
|
73
|
+
constant: "editor-tokenProperty",
|
|
74
|
+
deleted: "editor-tokenProperty",
|
|
75
|
+
doctype: "editor-tokenComment",
|
|
76
|
+
entity: "editor-tokenOperator",
|
|
77
|
+
"function": "editor-tokenFunction",
|
|
78
|
+
important: "editor-tokenVariable",
|
|
79
|
+
inserted: "editor-tokenSelector",
|
|
80
|
+
keyword: "editor-tokenAttr",
|
|
81
|
+
namespace: "editor-tokenVariable",
|
|
82
|
+
number: "editor-tokenProperty",
|
|
83
|
+
operator: "editor-tokenOperator",
|
|
84
|
+
prolog: "editor-tokenComment",
|
|
85
|
+
property: "editor-tokenProperty",
|
|
86
|
+
punctuation: "editor-tokenPunctuation",
|
|
87
|
+
regex: "editor-tokenVariable",
|
|
88
|
+
selector: "editor-tokenSelector",
|
|
89
|
+
string: "editor-tokenSelector",
|
|
90
|
+
symbol: "editor-tokenProperty",
|
|
91
|
+
tag: "editor-tokenProperty",
|
|
92
|
+
url: "editor-tokenOperator",
|
|
93
|
+
variable: "editor-tokenVariable"
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export { LexicalTheme };
|