@react-fabric/lexical 1.0.0-beta.61 → 1.0.0-beta.63

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.
Files changed (39) hide show
  1. package/css/_lexical.css +67 -9
  2. package/dist/cjs/editor/LexicalEditor.js +34 -11
  3. package/dist/cjs/hooks/useFormatWatcher.js +54 -56
  4. package/dist/cjs/i18n/{ar.json.js → ar/lexical.json.js} +10 -4
  5. package/dist/cjs/i18n/{en.json.js → en/lexical.json.js} +7 -1
  6. package/dist/cjs/i18n/index.js +4 -4
  7. package/dist/cjs/plugins/CommentPlugin.js +471 -0
  8. package/dist/cjs/plugins/DraggableBlockPlugin.js +10 -13
  9. package/dist/esm/editor/LexicalEditor.js +35 -12
  10. package/dist/esm/hooks/useFormatWatcher.js +54 -56
  11. package/dist/esm/i18n/{ar.json.js → ar/lexical.json.js} +9 -5
  12. package/dist/esm/i18n/{en.json.js → en/lexical.json.js} +6 -2
  13. package/dist/esm/i18n/index.js +2 -2
  14. package/dist/esm/plugins/CommentPlugin.js +471 -0
  15. package/dist/esm/plugins/DraggableBlockPlugin.js +11 -14
  16. package/dist/types/editor/LexicalEditor.d.ts +13 -4
  17. package/dist/types/hooks/useFormatWatcher.d.ts +1 -1
  18. package/dist/types/plugins/CommentPlugin.d.ts +5 -0
  19. package/dist/types/plugins/DraggableBlockPlugin.d.ts +3 -2
  20. package/package.json +14 -13
  21. package/src/editor/LexicalEditor.tsx +66 -19
  22. package/src/hooks/useFormatWatcher.ts +0 -2
  23. package/src/i18n/{ar.json → ar/lexical.json} +6 -4
  24. package/src/i18n/{en.json → en/lexical.json} +3 -1
  25. package/src/i18n/index.ts +2 -2
  26. package/src/plugins/CommentPlugin.tsx +554 -0
  27. package/src/plugins/DraggableBlockPlugin.tsx +8 -13
  28. package/dist/cjs/components/StickyComponent.js +0 -220
  29. package/dist/cjs/nodes/StickyNode.js +0 -218
  30. package/dist/cjs/plugins/StickyPlugin.js +0 -20
  31. package/dist/esm/components/StickyComponent.js +0 -220
  32. package/dist/esm/nodes/StickyNode.js +0 -216
  33. package/dist/esm/plugins/StickyPlugin.js +0 -20
  34. package/dist/types/components/StickyComponent.d.ts +0 -9
  35. package/dist/types/nodes/StickyNode.d.ts +0 -34
  36. package/dist/types/plugins/StickyPlugin.d.ts +0 -1
  37. package/src/components/StickyComponent.tsx +0 -270
  38. package/src/nodes/StickyNode.tsx +0 -249
  39. package/src/plugins/StickyPlugin.ts +0 -38
@@ -0,0 +1,471 @@
1
+ 'use strict';
2
+
3
+ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
4
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
6
+ var _typeof = require('@babel/runtime/helpers/typeof');
7
+ var _regeneratorRuntime = require('@babel/runtime/regenerator');
8
+ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
9
+ var core = require('@react-fabric/core');
10
+ var date = require('@react-fabric/date');
11
+ var form = require('@react-fabric/form');
12
+ var utilities = require('@react-fabric/utilities');
13
+ var classNames = require('classnames');
14
+ var lexical = require('lexical');
15
+ var react = require('react');
16
+ var reactDom = require('react-dom');
17
+ var reactI18next = require('react-i18next');
18
+ var index = require('../utils/index.js');
19
+ var jsxRuntime = require('react/jsx-runtime');
20
+
21
+ 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; }
22
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).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; }
23
+ var SPACE = 4;
24
+ var Downward = 1;
25
+ var Upward = -1;
26
+ var Indeterminate = 0;
27
+ var prevIndex = Infinity;
28
+ function getCurrentIndex(keysLength) {
29
+ if (keysLength === 0) {
30
+ return Infinity;
31
+ }
32
+ if (prevIndex >= 0 && prevIndex < keysLength) {
33
+ return prevIndex;
34
+ }
35
+ return Math.floor(keysLength / 2);
36
+ }
37
+ function getTopLevelNodeKeys(editor) {
38
+ return editor.getEditorState().read(function () {
39
+ return lexical.$getRoot().getChildrenKeys();
40
+ });
41
+ }
42
+ function getBlockElement(anchorElem, editor, event) {
43
+ var anchorElementRect = anchorElem.getBoundingClientRect();
44
+ var topLevelNodeKeys = getTopLevelNodeKeys(editor);
45
+ var blockElem = null;
46
+ editor.getEditorState().read(function () {
47
+ var index$1 = getCurrentIndex(topLevelNodeKeys.length);
48
+ var direction = Indeterminate;
49
+ while (index$1 >= 0 && index$1 < topLevelNodeKeys.length) {
50
+ var key = topLevelNodeKeys[index$1];
51
+ var elem = editor.getElementByKey(key);
52
+ if (elem === null) {
53
+ break;
54
+ }
55
+ var point = new index.Point(event.x, event.y);
56
+ var domRect = index.Rect.fromDOM(elem);
57
+ var _window$getComputedSt = window.getComputedStyle(elem),
58
+ marginTop = _window$getComputedSt.marginTop,
59
+ marginBottom = _window$getComputedSt.marginBottom;
60
+ var rect = domRect.generateNewRect({
61
+ bottom: domRect.bottom + parseFloat(marginBottom),
62
+ left: anchorElementRect.left,
63
+ right: anchorElementRect.right,
64
+ top: domRect.top - parseFloat(marginTop)
65
+ });
66
+ var _rect$contains = rect.contains(point),
67
+ result = _rect$contains.result,
68
+ _rect$contains$reason = _rect$contains.reason,
69
+ isOnTopSide = _rect$contains$reason.isOnTopSide,
70
+ isOnBottomSide = _rect$contains$reason.isOnBottomSide;
71
+ if (result) {
72
+ blockElem = elem;
73
+ prevIndex = index$1;
74
+ break;
75
+ }
76
+ if (direction === Indeterminate) {
77
+ if (isOnTopSide) {
78
+ direction = Upward;
79
+ } else if (isOnBottomSide) {
80
+ direction = Downward;
81
+ } else {
82
+ // stop search block element
83
+ direction = Infinity;
84
+ }
85
+ }
86
+ index$1 += direction;
87
+ }
88
+ });
89
+ return blockElem;
90
+ }
91
+ var commentState = lexical.createState("comment", {
92
+ parse: function parse(v) {
93
+ return typeof v === "string" ? JSON.parse(v) : _typeof(v) === "object" ? v : null;
94
+ }
95
+ });
96
+ function setMenuPosition(targetElem, floatingElem, anchorElem) {
97
+ if (!targetElem) {
98
+ floatingElem.style.opacity = "0";
99
+ floatingElem.style.transform = "translate(-10000px, -10000px)";
100
+ return;
101
+ }
102
+ var targetRect = targetElem.getBoundingClientRect();
103
+ var targetStyle = window.getComputedStyle(targetElem);
104
+ var floatingElemRect = floatingElem.getBoundingClientRect();
105
+ var anchorElementRect = anchorElem.getBoundingClientRect();
106
+ var top = targetRect.top + (parseInt(targetStyle.lineHeight, 10) - floatingElemRect.height) / 2 - anchorElementRect.top;
107
+ var left = SPACE;
108
+ floatingElem.style.opacity = "1";
109
+ floatingElem.style.transform = "translate(-".concat(left, "px, ").concat(top, "px)");
110
+ }
111
+ function useCommentMenu(editor, anchorElem, username, openForm) {
112
+ var scrollerElem = anchorElem.parentElement;
113
+ var menuRef = react.useRef(null);
114
+ var _useState = react.useState(null),
115
+ _useState2 = _slicedToArray(_useState, 2),
116
+ draggableBlockElem = _useState2[0],
117
+ setDraggableBlockElem = _useState2[1];
118
+ react.useEffect(function () {
119
+ function onMouseMove(event) {
120
+ var target = event.target;
121
+ if (!index.isHTMLElement(target)) {
122
+ setDraggableBlockElem(null);
123
+ return;
124
+ }
125
+ var _draggableBlockElem = getBlockElement(anchorElem, editor, event);
126
+ editor.update(function () {
127
+ var node = _draggableBlockElem && lexical.$getNearestNodeFromDOMNode(_draggableBlockElem);
128
+ if (node) {
129
+ var comment = lexical.$getState(node, commentState);
130
+ setDraggableBlockElem(comment === null ? _draggableBlockElem : null);
131
+ } else {
132
+ setDraggableBlockElem(null);
133
+ }
134
+ });
135
+ }
136
+ function onMouseLeave() {
137
+ setDraggableBlockElem(null);
138
+ }
139
+ scrollerElem === null || scrollerElem === void 0 || scrollerElem.addEventListener("mousemove", onMouseMove);
140
+ scrollerElem === null || scrollerElem === void 0 || scrollerElem.addEventListener("mouseleave", onMouseLeave);
141
+ return function () {
142
+ scrollerElem === null || scrollerElem === void 0 || scrollerElem.removeEventListener("mousemove", onMouseMove);
143
+ scrollerElem === null || scrollerElem === void 0 || scrollerElem.removeEventListener("mouseleave", onMouseLeave);
144
+ };
145
+ }, [scrollerElem, anchorElem, editor]);
146
+ react.useEffect(function () {
147
+ if (menuRef.current) {
148
+ setMenuPosition(draggableBlockElem, menuRef.current, anchorElem);
149
+ }
150
+ }, [anchorElem, draggableBlockElem]);
151
+ var addComment = function addComment() {
152
+ editor.update(function () {
153
+ var node = draggableBlockElem && lexical.$getNearestNodeFromDOMNode(draggableBlockElem);
154
+ if (node && lexical.$isElementNode(node)) {
155
+ draggableBlockElem.scrollIntoView({
156
+ behavior: "smooth",
157
+ block: "center"
158
+ });
159
+ void openForm({
160
+ sample: node.getTextContent().substring(0, 128)
161
+ }).then(function (comment) {
162
+ editor.update(function () {
163
+ comment && lexical.$setState(node, commentState, {
164
+ username: username,
165
+ comment: comment,
166
+ timestamp: new Date().toISOString(),
167
+ lastUpdate: new Date().toISOString(),
168
+ replies: []
169
+ });
170
+ });
171
+ return true;
172
+ });
173
+ }
174
+ });
175
+ };
176
+ return /*#__PURE__*/reactDom.createPortal(/*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
177
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
178
+ role: "none",
179
+ ref: menuRef,
180
+ onClick: addComment,
181
+ 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",
182
+ children: /*#__PURE__*/jsxRuntime.jsxs("svg", {
183
+ xmlns: "http://www.w3.org/2000/svg",
184
+ viewBox: "0 0 24 24",
185
+ className: "w-4 h-4 opacity-30 pointer-events-none",
186
+ children: [/*#__PURE__*/jsxRuntime.jsx("title", {
187
+ children: "comment-plus-outline"
188
+ }), /*#__PURE__*/jsxRuntime.jsx("path", {
189
+ 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"
190
+ })]
191
+ })
192
+ })
193
+ }), anchorElem);
194
+ }
195
+ var CommentCard = function CommentCard(_ref) {
196
+ var _comment$replies;
197
+ var sample = _ref.sample,
198
+ nodeKey = _ref.nodeKey,
199
+ comment = _ref.comment,
200
+ onSelect = _ref.onSelect,
201
+ onReply = _ref.onReply;
202
+ var _useTranslation = reactI18next.useTranslation("lexical"),
203
+ t = _useTranslation.t;
204
+ var _useState3 = react.useState(null),
205
+ _useState4 = _slicedToArray(_useState3, 2),
206
+ reply = _useState4[0],
207
+ setReply = _useState4[1];
208
+ return /*#__PURE__*/jsxRuntime.jsxs(core.Card, {
209
+ "data-key": nodeKey,
210
+ className: "mb-2",
211
+ onClick: function onClick() {
212
+ return onSelect(nodeKey);
213
+ },
214
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
215
+ className: "line-clamp-2 mb-4",
216
+ children: sample
217
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
218
+ className: "text-xs truncate mb-2 text-tint-500",
219
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
220
+ className: "font-medium",
221
+ children: comment.username
222
+ }), /*#__PURE__*/jsxRuntime.jsx(date.DateDuration, {
223
+ date: comment.timestamp
224
+ })]
225
+ }), /*#__PURE__*/jsxRuntime.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__*/jsxRuntime.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 /*#__PURE__*/jsxRuntime.jsxs("div", {
232
+ className: "px-2 py-1",
233
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
234
+ className: "text-xs truncate mb-2 text-tint-500",
235
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
236
+ className: "font-medium",
237
+ children: reply.username
238
+ }), /*#__PURE__*/jsxRuntime.jsx(date.DateDuration, {
239
+ date: reply.timestamp
240
+ })]
241
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
242
+ className: "text-sm",
243
+ children: reply.comment
244
+ })]
245
+ }, idx);
246
+ })
247
+ }), /*#__PURE__*/jsxRuntime.jsx(core.Footer, {
248
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
249
+ className: "p-px text-xs bg-default",
250
+ children: /*#__PURE__*/jsxRuntime.jsx(form.Textarea, {
251
+ placeholder: t("reply") + "...",
252
+ rows: 1,
253
+ value: reply,
254
+ onChange: setReply,
255
+ onEnterPressed: function onEnterPressed() {
256
+ return reply && (onReply(nodeKey, reply), setReply(null));
257
+ },
258
+ decorateEnd: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
259
+ size: "sm",
260
+ variant: "link",
261
+ icon: "icon-[mdi--send]",
262
+ "aria-label": "reply",
263
+ onClick: function onClick() {
264
+ return reply && (onReply(nodeKey, reply), setReply(null));
265
+ }
266
+ })
267
+ })
268
+ })
269
+ })]
270
+ });
271
+ };
272
+ var CommentFlyout = function CommentFlyout(_ref2) {
273
+ var comments = _ref2.comments,
274
+ activeKey = _ref2.activeKey,
275
+ onClose = _ref2.onClose,
276
+ onSelect = _ref2.onSelect,
277
+ onReply = _ref2.onReply;
278
+ var contentRef = react.useRef(null);
279
+ react.useEffect(function () {
280
+ activeKey && setTimeout(function () {
281
+ var _contentRef$current;
282
+ (_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({
283
+ behavior: "smooth",
284
+ block: "center"
285
+ });
286
+ }, 100);
287
+ }, [activeKey]);
288
+ return /*#__PURE__*/jsxRuntime.jsx(core.Flyout, {
289
+ onClose: onClose,
290
+ title: "Comments",
291
+ icon: "icon-[mdi--comment-text-multiple]",
292
+ hideMask: true,
293
+ align: "end",
294
+ size: "sm",
295
+ headerClassName: "border-b border-primary-500 text-sm font-medium",
296
+ children: /*#__PURE__*/jsxRuntime.jsx(core.Content, {
297
+ ref: contentRef,
298
+ children: comments.map(function (props) {
299
+ return /*#__PURE__*/jsxRuntime.jsx(CommentCard, _objectSpread(_objectSpread({}, props), {}, {
300
+ onSelect: onSelect,
301
+ onReply: onReply
302
+ }), props.nodeKey);
303
+ })
304
+ })
305
+ });
306
+ };
307
+ var CommentForm = function CommentForm(_ref3) {
308
+ var onClose = _ref3.onClose,
309
+ sample = _ref3.sample;
310
+ var _useTranslation2 = reactI18next.useTranslation("lexical"),
311
+ t = _useTranslation2.t;
312
+ var _useState5 = react.useState(null),
313
+ _useState6 = _slicedToArray(_useState5, 2),
314
+ comment = _useState6[0],
315
+ setComment = _useState6[1];
316
+ return /*#__PURE__*/jsxRuntime.jsx(core.Modal, {
317
+ onClose: onClose,
318
+ size: "sm",
319
+ title: t("addComment"),
320
+ children: /*#__PURE__*/jsxRuntime.jsxs(core.Content, {
321
+ className: "p-px grid text-sm",
322
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
323
+ className: "px-2 py-1 line-clamp-2",
324
+ children: sample
325
+ }), /*#__PURE__*/jsxRuntime.jsx(form.Textarea, {
326
+ placeholder: t("addComment") + "...",
327
+ rows: 4,
328
+ autoFocus: true,
329
+ value: comment,
330
+ onChange: setComment,
331
+ onEnterPressed: function onEnterPressed() {
332
+ return comment && onClose(comment);
333
+ },
334
+ decorateEnd: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
335
+ size: "sm",
336
+ variant: "link",
337
+ icon: "icon-[mdi--send]",
338
+ "aria-label": "add comment",
339
+ onClick: function onClick() {
340
+ return comment && onClose(comment);
341
+ }
342
+ })
343
+ })]
344
+ })
345
+ });
346
+ };
347
+ var commentHandler = function commentHandler(editor, anchorElem, username) {
348
+ var _useState7 = react.useState([]),
349
+ _useState8 = _slicedToArray(_useState7, 2),
350
+ comments = _useState8[0],
351
+ setComments = _useState8[1];
352
+ var _useOverlayService = core.useOverlayService(CommentFlyout),
353
+ _useOverlayService2 = _slicedToArray(_useOverlayService, 3),
354
+ FlyoutEl = _useOverlayService2[0],
355
+ openFlyout = _useOverlayService2[1],
356
+ closeFlyout = _useOverlayService2[2];
357
+ var _useOverlayService3 = core.useOverlayService(CommentForm),
358
+ _useOverlayService4 = _slicedToArray(_useOverlayService3, 2),
359
+ ModalEl = _useOverlayService4[0],
360
+ openModal = _useOverlayService4[1];
361
+ var scrollIntoView = react.useEffectEvent(function (key) {
362
+ var el = editor.getElementByKey(key);
363
+ if (el) {
364
+ el.scrollIntoView({
365
+ behavior: "smooth",
366
+ block: "center"
367
+ });
368
+ el.classList.add("editor-comment-hilight");
369
+ setTimeout(function () {
370
+ el.classList.remove("editor-comment-hilight");
371
+ }, 1000);
372
+ }
373
+ });
374
+ var addReply = react.useEffectEvent(function (key, reply) {
375
+ editor.update(function () {
376
+ var node = lexical.$getNodeByKey(key);
377
+ if (node) {
378
+ var comment = lexical.$getState(node, commentState);
379
+ if (comment) {
380
+ comment.lastUpdate = new Date().toISOString();
381
+ comment.replies.unshift({
382
+ username: username,
383
+ comment: reply,
384
+ timestamp: new Date().toISOString()
385
+ });
386
+ lexical.$setState(node, commentState, comment);
387
+ }
388
+ }
389
+ });
390
+ });
391
+ var handleOpenFlyout = react.useEffectEvent(function (activeKey) {
392
+ if (!activeKey && closeFlyout) {
393
+ closeFlyout();
394
+ }
395
+ void openFlyout({
396
+ activeKey: activeKey
397
+ });
398
+ });
399
+ react.useEffect(function () {
400
+ return editor.registerUpdateListener(function (_ref4) {
401
+ var editorState = _ref4.editorState;
402
+ var comments = [];
403
+ editorState.read(function () {
404
+ lexical.$getRoot().getChildren().forEach(function (node) {
405
+ var comment = lexical.$getState(node, commentState);
406
+ var element = editor.getElementByKey(node.getKey());
407
+ element === null || element === void 0 || element.classList.remove("editor-has-comment");
408
+ if (comment !== null) {
409
+ element === null || element === void 0 || element.classList.add("editor-has-comment");
410
+ element === null || element === void 0 || element.addEventListener("click", function (e) {
411
+ if (e.offsetX < 0) {
412
+ handleOpenFlyout(node.getKey());
413
+ }
414
+ });
415
+ comments.push({
416
+ nodeKey: node.getKey(),
417
+ sample: node.getTextContent().substring(0, 128),
418
+ comment: comment
419
+ });
420
+ }
421
+ });
422
+ });
423
+ setComments(comments.sort(utilities.compareValues("desc", "comment.lastUpdate")));
424
+ });
425
+ }, [editor]);
426
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
427
+ children: [useCommentMenu(editor, anchorElem, username, openModal), /*#__PURE__*/jsxRuntime.jsx("div", {
428
+ className: "fixed inset-x-0 bottom-0 max-w-[21cm] mx-auto text-end",
429
+ children: comments.length > 0 && /*#__PURE__*/jsxRuntime.jsx(core.Badge, {
430
+ value: comments.length,
431
+ max: 99,
432
+ placement: "top-end",
433
+ className: "-me-4",
434
+ children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
435
+ rounded: true,
436
+ onClick: /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
437
+ return _regeneratorRuntime.wrap(function (_context) {
438
+ while (1) switch (_context.prev = _context.next) {
439
+ case 0:
440
+ return _context.abrupt("return", handleOpenFlyout());
441
+ case 1:
442
+ case "end":
443
+ return _context.stop();
444
+ }
445
+ }, _callee);
446
+ })),
447
+ icon: "icon-[mdi--comment-text-multiple]",
448
+ className: classNames("text-2xl outline p-2 -me-4", closeFlyout ? "bg-primary-50 text-primary-500" : "bg-dimmed text-muted hover:text-dimmed")
449
+ })
450
+ })
451
+ }), /*#__PURE__*/jsxRuntime.jsx(FlyoutEl, {
452
+ comments: comments,
453
+ onSelect: scrollIntoView,
454
+ onReply: addReply
455
+ }), /*#__PURE__*/jsxRuntime.jsx(ModalEl, {})]
456
+ });
457
+ };
458
+ var CommentPlugin = function CommentPlugin(_ref6) {
459
+ var _ref6$anchorElem = _ref6.anchorElem,
460
+ anchorElem = _ref6$anchorElem === void 0 ? document.body : _ref6$anchorElem,
461
+ _ref6$isPublishMode = _ref6.isPublishMode,
462
+ isPublishMode = _ref6$isPublishMode === void 0 ? true : _ref6$isPublishMode,
463
+ username = _ref6.username;
464
+ var _useLexicalComposerCo = LexicalComposerContext.useLexicalComposerContext(),
465
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
466
+ editor = _useLexicalComposerCo2[0];
467
+ if (isPublishMode) return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {});
468
+ return commentHandler(editor, anchorElem, username);
469
+ };
470
+
471
+ exports.CommentPlugin = CommentPlugin;
@@ -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 = scrollTop + targetRect.top + (parseInt(targetStyle.lineHeight, 10) - floatingElemRect.height) / 2 - anchorElementRect.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 useDraggableBlockMenu(editor, anchorElem, isEditable) {
145
- var _draggableBlockElem$c;
142
+ function useDraggableBlockMenu(editor, anchorElem) {
146
143
  var scrollerElem = anchorElem.parentElement;
147
144
  var menuRef = react.useRef(null);
148
145
  var targetLineRef = react.useRef(null);
@@ -276,12 +273,9 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
276
273
  isDraggingBlockRef.current = false;
277
274
  hideTargetLine(targetLineRef.current);
278
275
  }
279
- if (draggableBlockElem !== null && draggableBlockElem !== void 0 && (_draggableBlockElem$c = draggableBlockElem.classList) !== null && _draggableBlockElem$c !== void 0 && _draggableBlockElem$c.contains("editor-cover-page")) {
280
- return /*#__PURE__*/jsxRuntime.jsx("div", {});
281
- }
282
- return /*#__PURE__*/reactDom.createPortal( /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
276
+ return /*#__PURE__*/reactDom.createPortal(/*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
283
277
  children: [/*#__PURE__*/jsxRuntime.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-base",
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__*/jsxRuntime.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
  var DraggableBlockPlugin = 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 = LexicalComposerContext.useLexicalComposerContext(),
309
305
  _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
310
306
  editor = _useLexicalComposerCo2[0];
311
- return useDraggableBlockMenu(editor, anchorElem, editor._editable);
307
+ if (!isEditable) return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {});
308
+ return useDraggableBlockMenu(editor, anchorElem);
312
309
  };
313
310
 
314
311
  exports.DraggableBlockPlugin = DraggableBlockPlugin;
@@ -1,5 +1,6 @@
1
1
  'use client';
2
2
 
3
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
3
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
5
  import { CodeHighlightNode, CodeNode } from '@lexical/code';
5
6
  import { ListItemNode, ListNode } from '@lexical/list';
@@ -15,12 +16,11 @@ import { TablePlugin } from '@lexical/react/LexicalTablePlugin';
15
16
  import { QuoteNode, HeadingNode } from '@lexical/rich-text';
16
17
  import { TableCellNode, TableNode, TableRowNode } from '@lexical/table';
17
18
  import { Header, ErrorBoundary, ThemeProvider } from '@react-fabric/core';
18
- import { debounce } from '@react-fabric/utilities';
19
+ import { debounce, EMPTY_ARRAY } from '@react-fabric/utilities';
19
20
  import classNames from 'classnames';
20
21
  import { useRef, useState, useCallback, useEffect, useMemo } from 'react';
21
- import { StickyNode } from '../nodes/StickyNode.js';
22
+ import { CommentPlugin } from '../plugins/CommentPlugin.js';
22
23
  import { DraggableBlockPlugin } from '../plugins/DraggableBlockPlugin.js';
23
- import { StickyPlugin } from '../plugins/StickyPlugin.js';
24
24
  import { ToolbarPlugin } from '../plugins/ToolbarPlugin.js';
25
25
  import { LexicalTheme } from './theme.js';
26
26
  import { jsxs, jsx } from 'react/jsx-runtime';
@@ -34,7 +34,7 @@ import { jsxs, jsx } from 'react/jsx-runtime';
34
34
  * It uses a custom theme and provides error handling for Lexical updates.
35
35
  *
36
36
  * @param {EditorProps} props - The properties for the LexicalEditor component.
37
- * @returns {JSX.Element} The rendered LexicalEditor component.
37
+ * @returns {React.ReactElement} The rendered LexicalEditor component.
38
38
  *
39
39
  * @example
40
40
  * ```jsx
@@ -54,6 +54,14 @@ var LexicalEditor = function LexicalEditor(_ref) {
54
54
  var value = _ref.value,
55
55
  readOnly = _ref.readOnly,
56
56
  publishMode = _ref.publishMode,
57
+ header = _ref.header,
58
+ footer = _ref.footer,
59
+ coverPage = _ref.coverPage,
60
+ isRtl = _ref.isRtl,
61
+ _ref$username = _ref.username,
62
+ username = _ref$username === void 0 ? "Guest" : _ref$username,
63
+ _ref$nodes = _ref.nodes,
64
+ nodes = _ref$nodes === void 0 ? EMPTY_ARRAY : _ref$nodes,
57
65
  onChange = _ref.onChange,
58
66
  onDirty = _ref.onDirty;
59
67
  var editorRef = useRef(null);
@@ -123,7 +131,7 @@ var LexicalEditor = function LexicalEditor(_ref) {
123
131
  namespace: "MyEditor",
124
132
  editable: !readOnly && !publishMode,
125
133
  theme: LexicalTheme,
126
- nodes: [QuoteNode, HeadingNode, CodeHighlightNode, CodeNode, ListItemNode, ListNode, TableCellNode, TableNode, TableRowNode, StickyNode],
134
+ nodes: [QuoteNode, HeadingNode, CodeHighlightNode, CodeNode, ListItemNode, ListNode, TableCellNode, TableNode, TableRowNode].concat(_toConsumableArray(nodes)),
127
135
  onError: onError
128
136
  };
129
137
  }, []);
@@ -131,15 +139,15 @@ var LexicalEditor = function LexicalEditor(_ref) {
131
139
  var children = _ref3.children;
132
140
  return !publishMode ? /*#__PURE__*/jsxs("div", {
133
141
  className: "lexical-scroller area-content overflow-auto",
134
- children: [/*#__PURE__*/jsx("div", {
142
+ children: [!readOnly && /*#__PURE__*/jsx("div", {
135
143
  className: classNames("fabric-lexicalToolbar", "sticky top-0 z-1"),
136
144
  children: /*#__PURE__*/jsx(Header, {
137
- className: "bg-base",
145
+ className: "bg-default",
138
146
  children: /*#__PURE__*/jsx(ToolbarPlugin, {})
139
147
  })
140
148
  }), children]
141
149
  }) : children;
142
- }, [publishMode]);
150
+ }, [publishMode, readOnly]);
143
151
  return /*#__PURE__*/jsx(ErrorBoundary, {
144
152
  children: /*#__PURE__*/jsx(LexicalComposer, {
145
153
  initialConfig: initialConfig,
@@ -149,6 +157,7 @@ var LexicalEditor = function LexicalEditor(_ref) {
149
157
  children: /*#__PURE__*/jsxs("div", {
150
158
  role: "none",
151
159
  className: classNames("fabric-lexicalEditor", "lexical-container relative bg-white min-h-full mx-auto shadow-md print:shadow-none"),
160
+ dir: isRtl ? "rtl" : "ltr",
152
161
  onDragOver: function onDragOver(e) {
153
162
  return e.stopPropagation();
154
163
  },
@@ -156,20 +165,34 @@ var LexicalEditor = function LexicalEditor(_ref) {
156
165
  return e.stopPropagation();
157
166
  },
158
167
  ref: setEditorContainer,
159
- children: [/*#__PURE__*/jsx(RichTextPlugin, {
168
+ children: [!publishMode && header && /*#__PURE__*/jsx("div", {
169
+ className: "editor-header",
170
+ children: header
171
+ }), coverPage && /*#__PURE__*/jsx("div", {
172
+ className: "editor-cover px-[2cm] py-[1cm]",
173
+ children: coverPage
174
+ }), /*#__PURE__*/jsx(RichTextPlugin, {
160
175
  contentEditable: /*#__PURE__*/jsx(ContentEditable, {
161
176
  readOnly: !!readOnly || publishMode,
162
- className: "lexical-editor px-[2cm] py-[1cm] min-h-screen"
177
+ className: "lexical-editor min-h-screen px-[2cm] py-[1cm]"
163
178
  }),
164
179
  placeholder: /*#__PURE__*/jsx("div", {
165
180
  className: "text-muted overflow-hidden absolute mt-6 top-[1cm] left-[2cm] select-none pointer-events-none",
166
181
  children: "Enter some text..."
167
182
  }),
168
183
  ErrorBoundary: LexicalErrorBoundary
169
- }), /*#__PURE__*/jsx(ListPlugin, {}), /*#__PURE__*/jsx(CheckListPlugin, {}), /*#__PURE__*/jsx(TablePlugin, {}), /*#__PURE__*/jsx(HistoryPlugin, {}), /*#__PURE__*/jsx(StickyPlugin, {}), /*#__PURE__*/jsx(AutoFocusPlugin, {
184
+ }), /*#__PURE__*/jsx(ListPlugin, {}), /*#__PURE__*/jsx(CheckListPlugin, {}), /*#__PURE__*/jsx(TablePlugin, {}), /*#__PURE__*/jsx(HistoryPlugin, {}), /*#__PURE__*/jsx(AutoFocusPlugin, {
170
185
  defaultSelection: "rootStart"
171
186
  }), editorContainer && /*#__PURE__*/jsx(DraggableBlockPlugin, {
172
- anchorElem: editorContainer
187
+ anchorElem: editorContainer,
188
+ isEditable: !readOnly && !publishMode
189
+ }), editorContainer && /*#__PURE__*/jsx(CommentPlugin, {
190
+ username: username,
191
+ anchorElem: editorContainer,
192
+ isPublishMode: !!publishMode
193
+ }), !publishMode && footer && /*#__PURE__*/jsx("div", {
194
+ className: "editor-footer",
195
+ children: footer
173
196
  })]
174
197
  })
175
198
  })