@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 client';
2
+
3
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
4
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
5
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
+ import _typeof from '@babel/runtime/helpers/typeof';
7
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
8
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
9
+ import { useOverlayService, Badge, Icon, Flyout, Content, Modal, Button, Card, Footer } from '@react-fabric/core';
10
+ import { DateDuration } from '@react-fabric/date';
11
+ import { Textarea } from '@react-fabric/form';
12
+ import { compareValues } from '@react-fabric/utilities';
13
+ import classNames from 'classnames';
14
+ import { createState, $getNodeByKey, $getState, $setState, $getRoot, $getNearestNodeFromDOMNode, $isElementNode } from 'lexical';
15
+ import { useState, useEffectEvent, useEffect, useRef } from 'react';
16
+ import { createPortal } from 'react-dom';
17
+ import { useTranslation } from 'react-i18next';
18
+ import { isHTMLElement, Point, Rect } from '../utils/index.js';
19
+ import { jsx, Fragment, jsxs } from '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 $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 = getCurrentIndex(topLevelNodeKeys.length);
48
+ var direction = Indeterminate;
49
+ while (index >= 0 && index < topLevelNodeKeys.length) {
50
+ var key = topLevelNodeKeys[index];
51
+ var elem = editor.getElementByKey(key);
52
+ if (elem === null) {
53
+ break;
54
+ }
55
+ var point = new Point(event.x, event.y);
56
+ var domRect = 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;
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 += direction;
87
+ }
88
+ });
89
+ return blockElem;
90
+ }
91
+ var commentState = 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 = useRef(null);
114
+ var _useState = useState(null),
115
+ _useState2 = _slicedToArray(_useState, 2),
116
+ draggableBlockElem = _useState2[0],
117
+ setDraggableBlockElem = _useState2[1];
118
+ useEffect(function () {
119
+ function onMouseMove(event) {
120
+ var target = event.target;
121
+ if (!isHTMLElement(target)) {
122
+ setDraggableBlockElem(null);
123
+ return;
124
+ }
125
+ var _draggableBlockElem = getBlockElement(anchorElem, editor, event);
126
+ editor.update(function () {
127
+ var node = _draggableBlockElem && $getNearestNodeFromDOMNode(_draggableBlockElem);
128
+ if (node) {
129
+ var comment = $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
+ 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 && $getNearestNodeFromDOMNode(draggableBlockElem);
154
+ if (node && $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 && $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__*/createPortal(/*#__PURE__*/jsx(Fragment, {
177
+ children: /*#__PURE__*/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__*/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__*/jsx("title", {
187
+ children: "comment-plus-outline"
188
+ }), /*#__PURE__*/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 = useTranslation("lexical"),
203
+ t = _useTranslation.t;
204
+ var _useState3 = useState(null),
205
+ _useState4 = _slicedToArray(_useState3, 2),
206
+ reply = _useState4[0],
207
+ setReply = _useState4[1];
208
+ return /*#__PURE__*/jsxs(Card, {
209
+ "data-key": nodeKey,
210
+ className: "mb-2",
211
+ onClick: function onClick() {
212
+ return onSelect(nodeKey);
213
+ },
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 /*#__PURE__*/jsxs("div", {
232
+ className: "px-2 py-1",
233
+ children: [/*#__PURE__*/jsxs("div", {
234
+ className: "text-xs truncate mb-2 text-tint-500",
235
+ children: [/*#__PURE__*/jsx("div", {
236
+ className: "font-medium",
237
+ children: reply.username
238
+ }), /*#__PURE__*/jsx(DateDuration, {
239
+ date: reply.timestamp
240
+ })]
241
+ }), /*#__PURE__*/jsx("div", {
242
+ className: "text-sm",
243
+ children: reply.comment
244
+ })]
245
+ }, idx);
246
+ })
247
+ }), /*#__PURE__*/jsx(Footer, {
248
+ children: /*#__PURE__*/jsx("div", {
249
+ className: "p-px text-xs bg-default",
250
+ children: /*#__PURE__*/jsx(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__*/jsx(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 = useRef(null);
279
+ 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__*/jsx(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__*/jsx(Content, {
297
+ ref: contentRef,
298
+ children: comments.map(function (props) {
299
+ return /*#__PURE__*/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 = useTranslation("lexical"),
311
+ t = _useTranslation2.t;
312
+ var _useState5 = useState(null),
313
+ _useState6 = _slicedToArray(_useState5, 2),
314
+ comment = _useState6[0],
315
+ setComment = _useState6[1];
316
+ return /*#__PURE__*/jsx(Modal, {
317
+ onClose: onClose,
318
+ size: "sm",
319
+ title: t("addComment"),
320
+ children: /*#__PURE__*/jsxs(Content, {
321
+ className: "p-px grid text-sm",
322
+ children: [/*#__PURE__*/jsx("div", {
323
+ className: "px-2 py-1 line-clamp-2",
324
+ children: sample
325
+ }), /*#__PURE__*/jsx(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__*/jsx(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 = useState([]),
349
+ _useState8 = _slicedToArray(_useState7, 2),
350
+ comments = _useState8[0],
351
+ setComments = _useState8[1];
352
+ var _useOverlayService = useOverlayService(CommentFlyout),
353
+ _useOverlayService2 = _slicedToArray(_useOverlayService, 3),
354
+ FlyoutEl = _useOverlayService2[0],
355
+ openFlyout = _useOverlayService2[1],
356
+ closeFlyout = _useOverlayService2[2];
357
+ var _useOverlayService3 = useOverlayService(CommentForm),
358
+ _useOverlayService4 = _slicedToArray(_useOverlayService3, 2),
359
+ ModalEl = _useOverlayService4[0],
360
+ openModal = _useOverlayService4[1];
361
+ var scrollIntoView = 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 = useEffectEvent(function (key, reply) {
375
+ editor.update(function () {
376
+ var node = $getNodeByKey(key);
377
+ if (node) {
378
+ var comment = $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
+ $setState(node, commentState, comment);
387
+ }
388
+ }
389
+ });
390
+ });
391
+ var handleOpenFlyout = useEffectEvent(function (activeKey) {
392
+ if (!activeKey && closeFlyout) {
393
+ closeFlyout();
394
+ }
395
+ void openFlyout({
396
+ activeKey: activeKey
397
+ });
398
+ });
399
+ useEffect(function () {
400
+ return editor.registerUpdateListener(function (_ref4) {
401
+ var editorState = _ref4.editorState;
402
+ var comments = [];
403
+ editorState.read(function () {
404
+ $getRoot().getChildren().forEach(function (node) {
405
+ var comment = $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(compareValues("desc", "comment.lastUpdate")));
424
+ });
425
+ }, [editor]);
426
+ return /*#__PURE__*/jsxs(Fragment, {
427
+ children: [useCommentMenu(editor, anchorElem, username, openModal), /*#__PURE__*/jsx("div", {
428
+ className: "fixed inset-x-0 bottom-0 max-w-[21cm] mx-auto text-end",
429
+ children: comments.length > 0 && /*#__PURE__*/jsx(Badge, {
430
+ value: comments.length,
431
+ max: 99,
432
+ placement: "top-end",
433
+ className: "-me-4",
434
+ children: /*#__PURE__*/jsx(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__*/jsx(FlyoutEl, {
452
+ comments: comments,
453
+ onSelect: scrollIntoView,
454
+ onReply: addReply
455
+ }), /*#__PURE__*/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 = useLexicalComposerContext(),
465
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
466
+ editor = _useLexicalComposerCo2[0];
467
+ if (isPublishMode) return /*#__PURE__*/jsx(Fragment, {});
468
+ return commentHandler(editor, anchorElem, username);
469
+ };
470
+
471
+ export { CommentPlugin };
@@ -8,7 +8,7 @@ import { DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, COMMAND_PRIORITY_
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, jsxs, Fragment } from 'react/jsx-runtime';
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 = 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 = 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
- if (draggableBlockElem !== null && draggableBlockElem !== void 0 && (_draggableBlockElem$c = draggableBlockElem.classList) !== null && _draggableBlockElem$c !== void 0 && _draggableBlockElem$c.contains("editor-cover-page")) {
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-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__*/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 = useLexicalComposerContext(),
309
305
  _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
310
306
  editor = _useLexicalComposerCo2[0];
311
- return useDraggableBlockMenu(editor, anchorElem, editor._editable);
307
+ if (!isEditable) return /*#__PURE__*/jsx(Fragment, {});
308
+ return useDraggableBlockMenu(editor, anchorElem);
312
309
  };
313
310
 
314
311
  export { DraggableBlockPlugin };
@@ -1,12 +1,21 @@
1
+ import { type ReactElement } from "@react-fabric/core/dist/types/types";
2
+ import { type Klass, type LexicalNode, type LexicalNodeReplacement } from "lexical";
1
3
  export interface EditorProps {
2
4
  value?: string | AnyObject;
5
+ isRtl?: boolean;
3
6
  readOnly?: boolean;
4
7
  /**
5
8
  * publish mode removes all wrapping and renders plain lexical view for exporting to pdf using puppeteer
6
9
  */
7
10
  publishMode?: boolean;
8
- header?: string;
9
- footer?: string;
11
+ header?: ReactElement;
12
+ footer?: ReactElement;
13
+ coverPage?: ReactElement;
14
+ /**
15
+ * Username is used for comment plugin to identify the comment author. It can be used to conditionally render delete option for comments.
16
+ */
17
+ username?: string;
18
+ nodes?: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>;
10
19
  onChange?: (value: KeyValue) => void;
11
20
  onDirty?: (isDirty: boolean) => void;
12
21
  }
@@ -19,7 +28,7 @@ export interface EditorProps {
19
28
  * It uses a custom theme and provides error handling for Lexical updates.
20
29
  *
21
30
  * @param {EditorProps} props - The properties for the LexicalEditor component.
22
- * @returns {JSX.Element} The rendered LexicalEditor component.
31
+ * @returns {React.ReactElement} The rendered LexicalEditor component.
23
32
  *
24
33
  * @example
25
34
  * ```jsx
@@ -35,4 +44,4 @@ export interface EditorProps {
35
44
  * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/lexical-playground--playground}
36
45
  * @see {@link https://lexical.dev/docs/}
37
46
  */
38
- export declare const LexicalEditor: ({ value, readOnly, publishMode, onChange, onDirty, }: EditorProps) => import("react/jsx-runtime").JSX.Element;
47
+ export declare const LexicalEditor: ({ value, readOnly, publishMode, header, footer, coverPage, isRtl, username, nodes, onChange, onDirty, }: EditorProps) => import("react/jsx-runtime").JSX.Element;
@@ -3,7 +3,7 @@ import { type ElementNode, type RangeSelection, type TextNode } from "lexical";
3
3
  export declare function getSelectedNode(selection: RangeSelection): TextNode | ElementNode;
4
4
  export declare const useFormatWatcher: () => {
5
5
  editor: import("lexical").LexicalEditor;
6
- blockType: "number" | "paragraph" | "code" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "bullet" | "check" | "quote";
6
+ blockType: "number" | "code" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "bullet" | "check" | "paragraph" | "quote";
7
7
  rootType: "table" | "root";
8
8
  selectedElementKey: string | null;
9
9
  fontSize: string;
@@ -0,0 +1,5 @@
1
+ export declare const CommentPlugin: ({ anchorElem, isPublishMode, username, }: {
2
+ anchorElem?: HTMLElement;
3
+ isPublishMode: boolean;
4
+ username: string;
5
+ }) => React.ReactElement;
@@ -1,3 +1,4 @@
1
- export declare const DraggableBlockPlugin: ({ anchorElem, }: {
1
+ export declare const DraggableBlockPlugin: ({ anchorElem, isEditable, }: {
2
2
  anchorElem?: HTMLElement;
3
- }) => JSX.Element;
3
+ isEditable: boolean;
4
+ }) => React.ReactElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/lexical",
3
- "version": "1.0.0-beta.61",
3
+ "version": "1.0.0-beta.63",
4
4
  "description": "RUF: Lexical editor",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -35,22 +35,23 @@
35
35
  "watch": "npm-run-all -p watch:rollup watch:dts"
36
36
  },
37
37
  "dependencies": {
38
- "@lexical/react": "~0.35.0",
39
- "@react-fabric/core": "^1.0.0-beta.61",
40
- "@react-fabric/form": "^1.0.0-beta.61",
41
- "@react-fabric/utilities": "^1.0.0-beta.61",
38
+ "@lexical/react": "0.41.0",
39
+ "@react-fabric/core": "^1.0.0-beta.63",
40
+ "@react-fabric/date": "^1.0.0-beta.63",
41
+ "@react-fabric/form": "^1.0.0-beta.63",
42
+ "@react-fabric/utilities": "^1.0.0-beta.63",
42
43
  "classnames": "~2.5.1",
43
- "lexical": "~0.35.0"
44
+ "lexical": "0.41.0"
44
45
  },
45
46
  "peerDependencies": {
46
- "i18next": "~25.6.0",
47
- "react": "~19.2.0",
48
- "react-dom": "~19.2.0",
49
- "react-i18next": "~16.2.1"
47
+ "i18next": "~25.8.18",
48
+ "react": "~19.2.4",
49
+ "react-dom": "~19.2.4",
50
+ "react-i18next": "~16.5.8"
50
51
  },
51
52
  "engines": {
52
- "node": ">=18.12.0",
53
- "npm": ">=8.19.0"
53
+ "node": ">=22.18.0",
54
+ "npm": ">=10.8.0"
54
55
  },
55
- "gitHead": "a0b0c571bf9c189fa3355bbc3b896ecc4b9d6a04"
56
+ "gitHead": "6e0652b15c6384fbc316842862572e21299a5466"
56
57
  }