@react-fabric/lexical 1.0.0-beta.9 → 1.0.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/{src/editor/Lexical.module.css → css/_lexical.css} +79 -13
- package/css/styles.css +24 -0
- package/dist/cjs/{packages/lexical/src/editor → editor}/LexicalEditor.js +98 -45
- package/dist/cjs/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +147 -140
- package/dist/cjs/i18n/ar/lexical.json.js +30 -0
- package/dist/cjs/i18n/en/lexical.json.js +30 -0
- package/{src/plugins/StickyPlugin.ts → dist/cjs/i18n/index.js} +10 -15
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/plugins/CommentPlugin.js +481 -0
- package/dist/cjs/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +17 -20
- package/dist/cjs/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +58 -37
- package/dist/esm/{packages/lexical/src/editor → editor}/LexicalEditor.js +101 -48
- package/dist/esm/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +95 -88
- package/dist/esm/i18n/ar/lexical.json.js +25 -0
- package/dist/esm/i18n/en/lexical.json.js +25 -0
- package/dist/esm/i18n/index.js +33 -0
- package/dist/esm/index.js +34 -0
- package/dist/esm/plugins/CommentPlugin.js +481 -0
- package/dist/esm/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +15 -18
- package/dist/esm/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +59 -38
- package/dist/types/editor/LexicalEditor.d.ts +33 -4
- package/dist/types/hooks/useFormatWatcher.d.ts +7 -4
- package/dist/types/i18n/index.d.ts +1 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/types/plugins/CommentPlugin.d.ts +5 -0
- package/dist/types/plugins/DraggableBlockPlugin.d.ts +3 -2
- package/dist/types/plugins/ToolbarPlugin.d.ts +1 -1
- package/dist/types/utils/index.d.ts +3 -6
- package/package.json +18 -18
- package/src/editor/LexicalEditor.tsx +95 -55
- package/src/hooks/useFormatWatcher.ts +50 -74
- package/src/i18n/ar/lexical.json +18 -0
- package/src/i18n/en/lexical.json +18 -0
- package/src/i18n/index.ts +28 -0
- package/src/index.ts +24 -17
- package/src/plugins/CommentPlugin.tsx +523 -0
- package/src/plugins/DraggableBlockPlugin.tsx +23 -68
- package/src/plugins/ToolbarPlugin.tsx +83 -131
- package/src/utils/index.ts +12 -108
- package/dist/cjs/_virtual/prism.js +0 -5
- package/dist/cjs/editor/Lexical.module.css +0 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -432
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -21
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -27
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +0 -1139
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +0 -25
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +0 -50
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +0 -245
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +0 -19
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +0 -18
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +0 -471
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +0 -17
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +0 -24
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +0 -1275
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +0 -29
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +0 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -789
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +0 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -26
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -976
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +0 -35
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -35
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +0 -2792
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +0 -23
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +0 -55
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -888
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +0 -35
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -66
- package/dist/cjs/node_modules/@mdi/js/mdi.js +0 -8
- package/dist/cjs/node_modules/prismjs/components/prism-c.js +0 -82
- package/dist/cjs/node_modules/prismjs/components/prism-clike.js +0 -33
- package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +0 -101
- package/dist/cjs/node_modules/prismjs/components/prism-css.js +0 -66
- package/dist/cjs/node_modules/prismjs/components/prism-java.js +0 -126
- package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +0 -174
- package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +0 -417
- package/dist/cjs/node_modules/prismjs/components/prism-markup.js +0 -188
- package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +0 -14
- package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +0 -60
- package/dist/cjs/node_modules/prismjs/components/prism-python.js +0 -67
- package/dist/cjs/node_modules/prismjs/components/prism-rust.js +0 -130
- package/dist/cjs/node_modules/prismjs/components/prism-sql.js +0 -34
- package/dist/cjs/node_modules/prismjs/components/prism-swift.js +0 -150
- package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +0 -62
- package/dist/cjs/node_modules/prismjs/prism.js +0 -1951
- package/dist/cjs/packages/lexical/src/components/StickyComponent.js +0 -221
- package/dist/cjs/packages/lexical/src/index.js +0 -7
- package/dist/cjs/packages/lexical/src/nodes/StickyNode.js +0 -218
- package/dist/cjs/packages/lexical/src/plugins/StickyPlugin.js +0 -20
- package/dist/esm/_virtual/prism.js +0 -5
- package/dist/esm/editor/Lexical.module.css +0 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -423
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -19
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -18
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +0 -1121
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +0 -21
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +0 -32
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +0 -244
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +0 -18
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +0 -463
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +0 -17
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +0 -1262
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +0 -23
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -781
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +0 -23
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -18
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -957
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +0 -26
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +0 -2754
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +0 -20
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -839
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +0 -26
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -17
- package/dist/esm/node_modules/@mdi/js/mdi.js +0 -7
- package/dist/esm/node_modules/prismjs/components/prism-c.js +0 -82
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -33
- package/dist/esm/node_modules/prismjs/components/prism-cpp.js +0 -101
- package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -66
- package/dist/esm/node_modules/prismjs/components/prism-java.js +0 -126
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -174
- package/dist/esm/node_modules/prismjs/components/prism-markdown.js +0 -417
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -188
- package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +0 -14
- package/dist/esm/node_modules/prismjs/components/prism-powershell.js +0 -60
- package/dist/esm/node_modules/prismjs/components/prism-python.js +0 -67
- package/dist/esm/node_modules/prismjs/components/prism-rust.js +0 -130
- package/dist/esm/node_modules/prismjs/components/prism-sql.js +0 -34
- package/dist/esm/node_modules/prismjs/components/prism-swift.js +0 -150
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -62
- package/dist/esm/node_modules/prismjs/prism.js +0 -1951
- package/dist/esm/packages/lexical/src/components/StickyComponent.js +0 -221
- package/dist/esm/packages/lexical/src/index.js +0 -3
- package/dist/esm/packages/lexical/src/nodes/StickyNode.js +0 -216
- package/dist/esm/packages/lexical/src/plugins/StickyPlugin.js +0 -20
- package/dist/types/components/StickyComponent.d.ts +0 -9
- package/dist/types/nodes/StickyNode.d.ts +0 -35
- package/dist/types/plugins/StickyPlugin.d.ts +0 -1
- package/src/components/StickyComponent.tsx +0 -271
- package/src/nodes/StickyNode.tsx +0 -249
- /package/dist/cjs/{packages/lexical/src/editor → editor}/theme.js +0 -0
- /package/dist/cjs/{packages/lexical/src/utils → utils}/index.js +0 -0
- /package/dist/esm/{packages/lexical/src/editor → editor}/theme.js +0 -0
- /package/dist/esm/{packages/lexical/src/utils → utils}/index.js +0 -0
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
6
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
7
|
+
import { useOverlayService, Badge, Icon, Flyout, Content, Modal, Button, Card, Footer } from '@react-fabric/core';
|
|
8
|
+
import { DateDuration } from '@react-fabric/date';
|
|
9
|
+
import { Textarea } from '@react-fabric/form';
|
|
10
|
+
import { compareValues, cn } from '@react-fabric/utilities';
|
|
11
|
+
import { createState, $getRoot, $getState, $getNodeByKey, $setState, $getNearestNodeFromDOMNode, $isElementNode } from 'lexical';
|
|
12
|
+
import { useState, useEffectEvent, useEffect, useRef } from 'react';
|
|
13
|
+
import { createPortal } from 'react-dom';
|
|
14
|
+
import { useTranslation } from 'react-i18next';
|
|
15
|
+
import { isHTMLElement, Point, Rect } from '../utils/index.js';
|
|
16
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
17
|
+
|
|
18
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
20
|
+
var SPACE = 4;
|
|
21
|
+
var Downward = 1;
|
|
22
|
+
var Upward = -1;
|
|
23
|
+
var Indeterminate = 0;
|
|
24
|
+
var prevIndex = Infinity;
|
|
25
|
+
function getCurrentIndex(keysLength) {
|
|
26
|
+
if (keysLength === 0) {
|
|
27
|
+
return Infinity;
|
|
28
|
+
}
|
|
29
|
+
if (prevIndex >= 0 && prevIndex < keysLength) {
|
|
30
|
+
return prevIndex;
|
|
31
|
+
}
|
|
32
|
+
return Math.floor(keysLength / 2);
|
|
33
|
+
}
|
|
34
|
+
function getTopLevelNodeKeys(editor) {
|
|
35
|
+
return editor.getEditorState().read(function () {
|
|
36
|
+
return $getRoot().getChildrenKeys();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function getBlockElement(anchorElem, editor, event) {
|
|
40
|
+
var anchorElementRect = anchorElem.getBoundingClientRect();
|
|
41
|
+
var topLevelNodeKeys = getTopLevelNodeKeys(editor);
|
|
42
|
+
var blockElem = null;
|
|
43
|
+
editor.getEditorState().read(function () {
|
|
44
|
+
var index = getCurrentIndex(topLevelNodeKeys.length);
|
|
45
|
+
var direction = Indeterminate;
|
|
46
|
+
while (index >= 0 && index < topLevelNodeKeys.length) {
|
|
47
|
+
var key = topLevelNodeKeys[index];
|
|
48
|
+
var elem = editor.getElementByKey(key);
|
|
49
|
+
if (elem === null) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
var point = new Point(event.x, event.y);
|
|
53
|
+
var domRect = Rect.fromDOM(elem);
|
|
54
|
+
var _window$getComputedSt = window.getComputedStyle(elem),
|
|
55
|
+
marginTop = _window$getComputedSt.marginTop,
|
|
56
|
+
marginBottom = _window$getComputedSt.marginBottom;
|
|
57
|
+
var rect = domRect.generateNewRect({
|
|
58
|
+
bottom: domRect.bottom + parseFloat(marginBottom),
|
|
59
|
+
left: anchorElementRect.left,
|
|
60
|
+
right: anchorElementRect.right,
|
|
61
|
+
top: domRect.top - parseFloat(marginTop)
|
|
62
|
+
});
|
|
63
|
+
var _rect$contains = rect.contains(point),
|
|
64
|
+
result = _rect$contains.result,
|
|
65
|
+
_rect$contains$reason = _rect$contains.reason,
|
|
66
|
+
isOnTopSide = _rect$contains$reason.isOnTopSide,
|
|
67
|
+
isOnBottomSide = _rect$contains$reason.isOnBottomSide;
|
|
68
|
+
if (result) {
|
|
69
|
+
blockElem = elem;
|
|
70
|
+
prevIndex = index;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (direction === Indeterminate) {
|
|
74
|
+
if (isOnTopSide) {
|
|
75
|
+
direction = Upward;
|
|
76
|
+
} else if (isOnBottomSide) {
|
|
77
|
+
direction = Downward;
|
|
78
|
+
} else {
|
|
79
|
+
// stop search block element
|
|
80
|
+
direction = Infinity;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
index += direction;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return blockElem;
|
|
87
|
+
}
|
|
88
|
+
var commentState = createState("comment", {
|
|
89
|
+
parse: function parse(v) {
|
|
90
|
+
return typeof v === "string" ? JSON.parse(v) : _typeof(v) === "object" ? v : null;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
function setMenuPosition(targetElem, floatingElem, anchorElem) {
|
|
94
|
+
if (!targetElem) {
|
|
95
|
+
floatingElem.style.opacity = "0";
|
|
96
|
+
floatingElem.style.transform = "translate(-10000px, -10000px)";
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
var targetRect = targetElem.getBoundingClientRect();
|
|
100
|
+
var targetStyle = window.getComputedStyle(targetElem);
|
|
101
|
+
var floatingElemRect = floatingElem.getBoundingClientRect();
|
|
102
|
+
var anchorElementRect = anchorElem.getBoundingClientRect();
|
|
103
|
+
var top = targetRect.top + (parseInt(targetStyle.lineHeight, 10) - floatingElemRect.height) / 2 - anchorElementRect.top;
|
|
104
|
+
var left = SPACE;
|
|
105
|
+
floatingElem.style.opacity = "1";
|
|
106
|
+
floatingElem.style.transform = "translate(-".concat(left, "px, ").concat(top, "px)");
|
|
107
|
+
}
|
|
108
|
+
function useCommentMenu(editor, anchorElem, username, openForm) {
|
|
109
|
+
var scrollerElem = anchorElem.parentElement;
|
|
110
|
+
var menuRef = useRef(null);
|
|
111
|
+
var _useState = useState(null),
|
|
112
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
113
|
+
draggableBlockElem = _useState2[0],
|
|
114
|
+
setDraggableBlockElem = _useState2[1];
|
|
115
|
+
useEffect(function () {
|
|
116
|
+
function onMouseMove(event) {
|
|
117
|
+
var target = event.target;
|
|
118
|
+
if (!isHTMLElement(target)) {
|
|
119
|
+
setDraggableBlockElem(null);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
var _draggableBlockElem = getBlockElement(anchorElem, editor, event);
|
|
123
|
+
editor.update(function () {
|
|
124
|
+
var node = _draggableBlockElem && $getNearestNodeFromDOMNode(_draggableBlockElem);
|
|
125
|
+
if (node) {
|
|
126
|
+
var comment = $getState(node, commentState);
|
|
127
|
+
setDraggableBlockElem(comment === null ? _draggableBlockElem : null);
|
|
128
|
+
} else {
|
|
129
|
+
setDraggableBlockElem(null);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function onMouseLeave() {
|
|
134
|
+
setDraggableBlockElem(null);
|
|
135
|
+
}
|
|
136
|
+
scrollerElem === null || scrollerElem === void 0 || scrollerElem.addEventListener("mousemove", onMouseMove);
|
|
137
|
+
scrollerElem === null || scrollerElem === void 0 || scrollerElem.addEventListener("mouseleave", onMouseLeave);
|
|
138
|
+
return function () {
|
|
139
|
+
scrollerElem === null || scrollerElem === void 0 || scrollerElem.removeEventListener("mousemove", onMouseMove);
|
|
140
|
+
scrollerElem === null || scrollerElem === void 0 || scrollerElem.removeEventListener("mouseleave", onMouseLeave);
|
|
141
|
+
};
|
|
142
|
+
}, [scrollerElem, anchorElem, editor]);
|
|
143
|
+
useEffect(function () {
|
|
144
|
+
if (menuRef.current) {
|
|
145
|
+
setMenuPosition(draggableBlockElem, menuRef.current, anchorElem);
|
|
146
|
+
}
|
|
147
|
+
}, [anchorElem, draggableBlockElem]);
|
|
148
|
+
var addComment = function addComment() {
|
|
149
|
+
editor.update(function () {
|
|
150
|
+
var node = draggableBlockElem && $getNearestNodeFromDOMNode(draggableBlockElem);
|
|
151
|
+
if (node && $isElementNode(node)) {
|
|
152
|
+
draggableBlockElem.scrollIntoView({
|
|
153
|
+
behavior: "smooth",
|
|
154
|
+
block: "center"
|
|
155
|
+
});
|
|
156
|
+
void openForm({
|
|
157
|
+
sample: node.getTextContent().substring(0, 128)
|
|
158
|
+
}).then(function (comment) {
|
|
159
|
+
editor.update(function () {
|
|
160
|
+
if (comment) $setState(node, commentState, {
|
|
161
|
+
username: username,
|
|
162
|
+
comment: comment,
|
|
163
|
+
timestamp: new Date().toISOString(),
|
|
164
|
+
lastUpdate: new Date().toISOString(),
|
|
165
|
+
replies: []
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
return true;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
return /*#__PURE__*/createPortal(/*#__PURE__*/jsx(Fragment, {
|
|
174
|
+
children: /*#__PURE__*/jsx("div", {
|
|
175
|
+
role: "none",
|
|
176
|
+
ref: menuRef,
|
|
177
|
+
onClick: addComment,
|
|
178
|
+
className: "rounded px-0.5 py-px select-none opacity-0 absolute right-0 top-0 will-change-transform cursor-pointer hover:bg-primary-50",
|
|
179
|
+
children: /*#__PURE__*/jsxs("svg", {
|
|
180
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
181
|
+
viewBox: "0 0 24 24",
|
|
182
|
+
className: "w-4 h-4 opacity-30 pointer-events-none",
|
|
183
|
+
children: [/*#__PURE__*/jsx("title", {
|
|
184
|
+
children: "comment-plus-outline"
|
|
185
|
+
}), /*#__PURE__*/jsx("path", {
|
|
186
|
+
d: "M9,22A1,1 0 0,1 8,21V18H4A2,2 0 0,1 2,16V4C2,2.89 2.9,2 4,2H20A2,2 0 0,1 22,4V16A2,2 0 0,1 20,18H13.9L10.2,21.71C10,21.9 9.75,22 9.5,22V22H9M10,16V19.08L13.08,16H20V4H4V16H10M11,6H13V9H16V11H13V14H11V11H8V9H11V6Z"
|
|
187
|
+
})]
|
|
188
|
+
})
|
|
189
|
+
})
|
|
190
|
+
}), anchorElem);
|
|
191
|
+
}
|
|
192
|
+
function CommentCard(_ref) {
|
|
193
|
+
var _comment$replies;
|
|
194
|
+
var sample = _ref.sample,
|
|
195
|
+
nodeKey = _ref.nodeKey,
|
|
196
|
+
comment = _ref.comment,
|
|
197
|
+
active = _ref.active,
|
|
198
|
+
onSelect = _ref.onSelect,
|
|
199
|
+
onReply = _ref.onReply;
|
|
200
|
+
var _useTranslation = useTranslation("lexical"),
|
|
201
|
+
t = _useTranslation.t;
|
|
202
|
+
var _useState3 = useState(),
|
|
203
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
204
|
+
reply = _useState4[0],
|
|
205
|
+
setReply = _useState4[1];
|
|
206
|
+
return /*#__PURE__*/jsxs(Card, {
|
|
207
|
+
"data-key": nodeKey,
|
|
208
|
+
selected: active,
|
|
209
|
+
className: "mb-2",
|
|
210
|
+
onClick: function onClick() {
|
|
211
|
+
return onSelect(nodeKey);
|
|
212
|
+
},
|
|
213
|
+
children: [/*#__PURE__*/jsxs(Content, {
|
|
214
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
215
|
+
className: "line-clamp-2 mb-4",
|
|
216
|
+
children: sample
|
|
217
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
218
|
+
className: "text-xs truncate mb-2 text-tint-500",
|
|
219
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
220
|
+
className: "font-medium",
|
|
221
|
+
children: comment.username
|
|
222
|
+
}), /*#__PURE__*/jsx(DateDuration, {
|
|
223
|
+
date: comment.timestamp
|
|
224
|
+
})]
|
|
225
|
+
}), /*#__PURE__*/jsx("div", {
|
|
226
|
+
className: "text-sm",
|
|
227
|
+
children: comment.comment
|
|
228
|
+
}), ((_comment$replies = comment.replies) === null || _comment$replies === void 0 ? void 0 : _comment$replies.length) > 0 && /*#__PURE__*/jsx("div", {
|
|
229
|
+
className: "bg-alternate ps-2 border-s-2 border-s-tint-200",
|
|
230
|
+
children: comment.replies.map(function (reply, idx) {
|
|
231
|
+
return (
|
|
232
|
+
/*#__PURE__*/
|
|
233
|
+
// eslint-disable-next-line @eslint-react/no-array-index-key
|
|
234
|
+
jsxs("div", {
|
|
235
|
+
className: "px-2 py-1",
|
|
236
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
237
|
+
className: "text-xs truncate mb-2 text-tint-500",
|
|
238
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
239
|
+
className: "font-medium",
|
|
240
|
+
children: reply.username
|
|
241
|
+
}), /*#__PURE__*/jsx(DateDuration, {
|
|
242
|
+
date: reply.timestamp
|
|
243
|
+
})]
|
|
244
|
+
}), /*#__PURE__*/jsx("div", {
|
|
245
|
+
className: "text-sm",
|
|
246
|
+
children: reply.comment
|
|
247
|
+
})]
|
|
248
|
+
}, idx)
|
|
249
|
+
);
|
|
250
|
+
})
|
|
251
|
+
})]
|
|
252
|
+
}), /*#__PURE__*/jsx(Footer, {
|
|
253
|
+
children: /*#__PURE__*/jsx("div", {
|
|
254
|
+
className: "p-px text-xs bg-default",
|
|
255
|
+
children: /*#__PURE__*/jsx(Textarea, {
|
|
256
|
+
placeholder: t("reply") + "...",
|
|
257
|
+
rows: 1,
|
|
258
|
+
value: reply !== null && reply !== void 0 ? reply : "",
|
|
259
|
+
onChange: setReply,
|
|
260
|
+
onEnterPressed: function onEnterPressed() {
|
|
261
|
+
return reply && (onReply(nodeKey, reply), setReply(undefined));
|
|
262
|
+
},
|
|
263
|
+
decorateEnd: /*#__PURE__*/jsx(Button, {
|
|
264
|
+
size: "sm",
|
|
265
|
+
variant: "link",
|
|
266
|
+
icon: "icon-[mdi--send]",
|
|
267
|
+
"aria-label": "reply",
|
|
268
|
+
onClick: function onClick() {
|
|
269
|
+
return reply && (onReply(nodeKey, reply), setReply(undefined));
|
|
270
|
+
}
|
|
271
|
+
})
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
})]
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
var CommentFlyout = function CommentFlyout(_ref2) {
|
|
278
|
+
var comments = _ref2.comments,
|
|
279
|
+
activeKey = _ref2.activeKey,
|
|
280
|
+
onClose = _ref2.onClose,
|
|
281
|
+
onSelect = _ref2.onSelect,
|
|
282
|
+
onReply = _ref2.onReply;
|
|
283
|
+
var contentRef = useRef(null);
|
|
284
|
+
useEffect(function () {
|
|
285
|
+
if (activeKey) {
|
|
286
|
+
var tmr = setTimeout(function () {
|
|
287
|
+
var _contentRef$current;
|
|
288
|
+
(_contentRef$current = contentRef.current) === null || _contentRef$current === void 0 || (_contentRef$current = _contentRef$current.querySelector("[data-key=\"".concat(activeKey, "\"]"))) === null || _contentRef$current === void 0 || _contentRef$current.scrollIntoView({
|
|
289
|
+
behavior: "smooth",
|
|
290
|
+
block: "center"
|
|
291
|
+
});
|
|
292
|
+
}, 100);
|
|
293
|
+
return function () {
|
|
294
|
+
clearTimeout(tmr);
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}, [activeKey]);
|
|
298
|
+
return /*#__PURE__*/jsx(Flyout, {
|
|
299
|
+
onClose: onClose,
|
|
300
|
+
title: "Comments",
|
|
301
|
+
icon: "icon-[mdi--comment-text-multiple]",
|
|
302
|
+
hideMask: true,
|
|
303
|
+
align: "end",
|
|
304
|
+
size: "sm",
|
|
305
|
+
classNames: {
|
|
306
|
+
titlebar: "border-b border-primary-500 text-sm font-medium"
|
|
307
|
+
},
|
|
308
|
+
children: /*#__PURE__*/jsx(Content, {
|
|
309
|
+
ref: contentRef,
|
|
310
|
+
children: comments.map(function (props) {
|
|
311
|
+
return /*#__PURE__*/jsx(CommentCard, _objectSpread(_objectSpread({}, props), {}, {
|
|
312
|
+
active: activeKey === props.nodeKey,
|
|
313
|
+
onSelect: onSelect,
|
|
314
|
+
onReply: onReply
|
|
315
|
+
}), props.nodeKey);
|
|
316
|
+
})
|
|
317
|
+
})
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
function CommentForm(_ref3) {
|
|
321
|
+
var onClose = _ref3.onClose,
|
|
322
|
+
sample = _ref3.sample;
|
|
323
|
+
var _useTranslation2 = useTranslation("lexical"),
|
|
324
|
+
t = _useTranslation2.t;
|
|
325
|
+
var _useState5 = useState(),
|
|
326
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
327
|
+
comment = _useState6[0],
|
|
328
|
+
setComment = _useState6[1];
|
|
329
|
+
return /*#__PURE__*/jsx(Modal, {
|
|
330
|
+
onClose: onClose,
|
|
331
|
+
size: "sm",
|
|
332
|
+
title: t("addComment"),
|
|
333
|
+
children: /*#__PURE__*/jsxs(Content, {
|
|
334
|
+
className: "grid text-sm",
|
|
335
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
336
|
+
className: "px-2 py-1 line-clamp-2",
|
|
337
|
+
children: sample
|
|
338
|
+
}), /*#__PURE__*/jsx(Textarea, {
|
|
339
|
+
placeholder: t("addComment") + "...",
|
|
340
|
+
rows: 4,
|
|
341
|
+
autoFocus: true,
|
|
342
|
+
value: comment,
|
|
343
|
+
onChange: setComment,
|
|
344
|
+
onEnterPressed: function onEnterPressed() {
|
|
345
|
+
return comment && (onClose === null || onClose === void 0 ? void 0 : onClose(comment));
|
|
346
|
+
},
|
|
347
|
+
decorateEnd: /*#__PURE__*/jsx(Button, {
|
|
348
|
+
size: "sm",
|
|
349
|
+
variant: "link",
|
|
350
|
+
icon: "icon-[mdi--send]",
|
|
351
|
+
"aria-label": "add comment",
|
|
352
|
+
onClick: function onClick() {
|
|
353
|
+
return comment && (onClose === null || onClose === void 0 ? void 0 : onClose(comment));
|
|
354
|
+
}
|
|
355
|
+
})
|
|
356
|
+
})]
|
|
357
|
+
})
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
function CommentHandler(editor, anchorElem, username) {
|
|
361
|
+
var _useState7 = useState(function () {
|
|
362
|
+
return [];
|
|
363
|
+
}),
|
|
364
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
365
|
+
comments = _useState8[0],
|
|
366
|
+
setComments = _useState8[1];
|
|
367
|
+
var _useOverlayService = useOverlayService(CommentFlyout),
|
|
368
|
+
_useOverlayService2 = _slicedToArray(_useOverlayService, 3),
|
|
369
|
+
renderFlyout = _useOverlayService2[0],
|
|
370
|
+
openFlyout = _useOverlayService2[1],
|
|
371
|
+
closeFlyout = _useOverlayService2[2];
|
|
372
|
+
var _useOverlayService3 = useOverlayService(CommentForm),
|
|
373
|
+
_useOverlayService4 = _slicedToArray(_useOverlayService3, 2),
|
|
374
|
+
renderModal = _useOverlayService4[0],
|
|
375
|
+
openModal = _useOverlayService4[1];
|
|
376
|
+
var scrollIntoView = function scrollIntoView(key) {
|
|
377
|
+
var el = editor.getElementByKey(key);
|
|
378
|
+
if (el) {
|
|
379
|
+
el.scrollIntoView({
|
|
380
|
+
behavior: "smooth",
|
|
381
|
+
block: "center"
|
|
382
|
+
});
|
|
383
|
+
el.classList.add("editor-comment-hilight");
|
|
384
|
+
setTimeout(function () {
|
|
385
|
+
el.classList.remove("editor-comment-hilight");
|
|
386
|
+
}, 1000);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
var addReply = function addReply(key, reply) {
|
|
390
|
+
editor.update(function () {
|
|
391
|
+
var node = $getNodeByKey(key);
|
|
392
|
+
if (node) {
|
|
393
|
+
var comment = $getState(node, commentState);
|
|
394
|
+
if (comment) {
|
|
395
|
+
comment.lastUpdate = new Date().toISOString();
|
|
396
|
+
comment.replies.unshift({
|
|
397
|
+
username: username,
|
|
398
|
+
comment: reply,
|
|
399
|
+
timestamp: new Date().toISOString()
|
|
400
|
+
});
|
|
401
|
+
$setState(node, commentState, comment);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
var handleOpenFlyout = useEffectEvent(function (activeKey) {
|
|
407
|
+
if (!activeKey && closeFlyout) {
|
|
408
|
+
closeFlyout(null);
|
|
409
|
+
}
|
|
410
|
+
void openFlyout({
|
|
411
|
+
activeKey: activeKey
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
useEffect(function () {
|
|
415
|
+
return editor.registerUpdateListener(function (_ref4) {
|
|
416
|
+
var editorState = _ref4.editorState;
|
|
417
|
+
var comments = [];
|
|
418
|
+
editorState.read(function () {
|
|
419
|
+
$getRoot().getChildren().forEach(function (node) {
|
|
420
|
+
var comment = $getState(node, commentState);
|
|
421
|
+
var element = editor.getElementByKey(node.getKey());
|
|
422
|
+
element === null || element === void 0 || element.classList.remove("editor-has-comment");
|
|
423
|
+
if (comment !== null && element) {
|
|
424
|
+
element.classList.add("editor-has-comment");
|
|
425
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
426
|
+
element.addEventListener("click", function (e) {
|
|
427
|
+
if (e.offsetX < 0) {
|
|
428
|
+
handleOpenFlyout(node.getKey());
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
comments.push({
|
|
432
|
+
nodeKey: node.getKey(),
|
|
433
|
+
sample: node.getTextContent().substring(0, 128),
|
|
434
|
+
comment: comment
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
setComments(comments.sort(compareValues("desc", "comment.lastUpdate")));
|
|
440
|
+
});
|
|
441
|
+
}, [editor]);
|
|
442
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
443
|
+
children: [useCommentMenu(editor, anchorElem, username, openModal), /*#__PURE__*/jsx("div", {
|
|
444
|
+
className: "fixed inset-x-0 bottom-0 max-w-[21cm] mx-auto flex justify-end",
|
|
445
|
+
children: comments.length > 0 && /*#__PURE__*/jsx(Badge, {
|
|
446
|
+
value: comments.length,
|
|
447
|
+
placement: "top-start",
|
|
448
|
+
children: /*#__PURE__*/jsx("button", {
|
|
449
|
+
type: "button",
|
|
450
|
+
className: "size-fit cursor-pointer",
|
|
451
|
+
onClick: function onClick() {
|
|
452
|
+
void openFlyout();
|
|
453
|
+
},
|
|
454
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
455
|
+
rounded: true,
|
|
456
|
+
icon: "icon-[mdi--comment-text-multiple]",
|
|
457
|
+
className: cn("text-2xl outline p-2 -me-4", closeFlyout ? "bg-primary-50 text-primary-500" : "bg-dimmed text-muted hover:text-dimmed")
|
|
458
|
+
})
|
|
459
|
+
})
|
|
460
|
+
})
|
|
461
|
+
}), renderFlyout({
|
|
462
|
+
onSelect: scrollIntoView,
|
|
463
|
+
onReply: addReply,
|
|
464
|
+
comments: comments
|
|
465
|
+
}), renderModal()]
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
var CommentPlugin = function CommentPlugin(_ref5) {
|
|
469
|
+
var _ref5$anchorElem = _ref5.anchorElem,
|
|
470
|
+
anchorElem = _ref5$anchorElem === void 0 ? document.body : _ref5$anchorElem,
|
|
471
|
+
_ref5$isPublishMode = _ref5.isPublishMode,
|
|
472
|
+
isPublishMode = _ref5$isPublishMode === void 0 ? true : _ref5$isPublishMode,
|
|
473
|
+
username = _ref5.username;
|
|
474
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
475
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
476
|
+
editor = _useLexicalComposerCo2[0];
|
|
477
|
+
if (isPublishMode) return /*#__PURE__*/jsx(Fragment, {});
|
|
478
|
+
return CommentHandler(editor, anchorElem, username);
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
export { CommentPlugin };
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
4
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
5
|
-
import { eventFiles } from '
|
|
6
|
-
import { mergeRegister } from '
|
|
5
|
+
import { eventFiles } from '@lexical/rich-text';
|
|
6
|
+
import { mergeRegister } from '@lexical/utils';
|
|
7
7
|
import { DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, COMMAND_PRIORITY_HIGH, $getNodeByKey, $getNearestNodeFromDOMNode, $getRoot } from 'lexical';
|
|
8
8
|
import { useRef, useState, useEffect } from 'react';
|
|
9
9
|
import { createPortal } from 'react-dom';
|
|
10
10
|
import { isHTMLElement, Point, Rect } from '../utils/index.js';
|
|
11
|
-
import { jsx,
|
|
11
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
12
12
|
|
|
13
13
|
var SPACE = 4;
|
|
14
14
|
var TARGET_LINE_HALF_HEIGHT = 2;
|
|
@@ -86,18 +86,16 @@ function isOnMenu(element) {
|
|
|
86
86
|
return !!element.closest(".".concat(DRAGGABLE_BLOCK_MENU_CLASSNAME));
|
|
87
87
|
}
|
|
88
88
|
function setMenuPosition(targetElem, floatingElem, anchorElem) {
|
|
89
|
-
var _targetElem$closest$s, _targetElem$closest;
|
|
90
89
|
if (!targetElem) {
|
|
91
90
|
floatingElem.style.opacity = "0";
|
|
92
91
|
floatingElem.style.transform = "translate(-10000px, -10000px)";
|
|
93
92
|
return;
|
|
94
93
|
}
|
|
95
|
-
var scrollTop = (_targetElem$closest$s = (_targetElem$closest = targetElem.closest(".lexical-scroller")) === null || _targetElem$closest === void 0 ? void 0 : _targetElem$closest.scrollTop) !== null && _targetElem$closest$s !== void 0 ? _targetElem$closest$s : 0;
|
|
96
94
|
var targetRect = targetElem.getBoundingClientRect();
|
|
97
95
|
var targetStyle = window.getComputedStyle(targetElem);
|
|
98
96
|
var floatingElemRect = floatingElem.getBoundingClientRect();
|
|
99
97
|
var anchorElementRect = anchorElem.getBoundingClientRect();
|
|
100
|
-
var top =
|
|
98
|
+
var top = targetRect.top + (parseInt(targetStyle.lineHeight, 10) - floatingElemRect.height) / 2 - anchorElementRect.top;
|
|
101
99
|
var left = SPACE;
|
|
102
100
|
floatingElem.style.opacity = "1";
|
|
103
101
|
floatingElem.style.transform = "translate(".concat(left, "px, ").concat(top, "px)");
|
|
@@ -141,8 +139,7 @@ function hideTargetLine(targetLineElem) {
|
|
|
141
139
|
targetLineElem.style.transform = "translate(-10000px, -10000px)";
|
|
142
140
|
}
|
|
143
141
|
}
|
|
144
|
-
function
|
|
145
|
-
var _draggableBlockElem$c;
|
|
142
|
+
function RenderDraggableBlockMenu(editor, anchorElem) {
|
|
146
143
|
var scrollerElem = anchorElem.parentElement;
|
|
147
144
|
var menuRef = useRef(null);
|
|
148
145
|
var targetLineRef = useRef(null);
|
|
@@ -276,12 +273,9 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
276
273
|
isDraggingBlockRef.current = false;
|
|
277
274
|
hideTargetLine(targetLineRef.current);
|
|
278
275
|
}
|
|
279
|
-
|
|
280
|
-
return /*#__PURE__*/jsx("div", {});
|
|
281
|
-
}
|
|
282
|
-
return /*#__PURE__*/createPortal( /*#__PURE__*/jsxs(Fragment, {
|
|
276
|
+
return /*#__PURE__*/createPortal(/*#__PURE__*/jsxs(Fragment, {
|
|
283
277
|
children: [/*#__PURE__*/jsx("div", {
|
|
284
|
-
className: "rounded px-0.5 py-px select-none cursor-grab opacity-0 absolute left-0 top-0 will-change-transform active:cursor-grabbing hover:bg-
|
|
278
|
+
className: "rounded px-0.5 py-px select-none cursor-grab opacity-0 absolute left-0 top-0 will-change-transform active:cursor-grabbing hover:bg-default",
|
|
285
279
|
ref: menuRef,
|
|
286
280
|
draggable: true,
|
|
287
281
|
onDragStart: onDragStart,
|
|
@@ -297,18 +291,21 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
297
291
|
})]
|
|
298
292
|
})
|
|
299
293
|
}), /*#__PURE__*/jsx("div", {
|
|
300
|
-
className: "pointer-events-none bg-primary h-1 absolute top-0 left-0 opacity-0 will-change-transform",
|
|
294
|
+
className: "pointer-events-none bg-primary-200 h-1 absolute top-0 left-0 opacity-0 will-change-transform",
|
|
301
295
|
ref: targetLineRef
|
|
302
296
|
})]
|
|
303
297
|
}), anchorElem);
|
|
304
298
|
}
|
|
305
|
-
|
|
299
|
+
function DraggableBlockPlugin(_ref) {
|
|
306
300
|
var _ref$anchorElem = _ref.anchorElem,
|
|
307
|
-
anchorElem = _ref$anchorElem === void 0 ? document.body : _ref$anchorElem
|
|
301
|
+
anchorElem = _ref$anchorElem === void 0 ? document.body : _ref$anchorElem,
|
|
302
|
+
_ref$isEditable = _ref.isEditable,
|
|
303
|
+
isEditable = _ref$isEditable === void 0 ? true : _ref$isEditable;
|
|
308
304
|
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
309
305
|
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
310
306
|
editor = _useLexicalComposerCo2[0];
|
|
311
|
-
return
|
|
312
|
-
|
|
307
|
+
if (!isEditable) return /*#__PURE__*/jsx(Fragment, {});
|
|
308
|
+
return RenderDraggableBlockMenu(editor, anchorElem);
|
|
309
|
+
}
|
|
313
310
|
|
|
314
311
|
export { DraggableBlockPlugin };
|