@react-fabric/lexical 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/dist/cjs/_virtual/prism.js +5 -0
  4. package/dist/cjs/editor/Lexical.module.css +1 -0
  5. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +432 -0
  6. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +21 -0
  7. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +27 -0
  8. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +1139 -0
  9. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +25 -0
  10. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +50 -0
  11. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +245 -0
  12. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +19 -0
  13. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +18 -0
  14. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +471 -0
  15. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +17 -0
  16. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +24 -0
  17. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +1275 -0
  18. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +29 -0
  19. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +29 -0
  20. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +789 -0
  21. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +29 -0
  22. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +26 -0
  23. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +976 -0
  24. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +35 -0
  25. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +35 -0
  26. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +2792 -0
  27. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +23 -0
  28. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +55 -0
  29. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +888 -0
  30. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +35 -0
  31. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +66 -0
  32. package/dist/cjs/node_modules/@mdi/js/mdi.js +8 -0
  33. package/dist/cjs/node_modules/prismjs/components/prism-c.js +82 -0
  34. package/dist/cjs/node_modules/prismjs/components/prism-clike.js +33 -0
  35. package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +101 -0
  36. package/dist/cjs/node_modules/prismjs/components/prism-css.js +66 -0
  37. package/dist/cjs/node_modules/prismjs/components/prism-java.js +126 -0
  38. package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +174 -0
  39. package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +417 -0
  40. package/dist/cjs/node_modules/prismjs/components/prism-markup.js +188 -0
  41. package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +14 -0
  42. package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +60 -0
  43. package/dist/cjs/node_modules/prismjs/components/prism-python.js +67 -0
  44. package/dist/cjs/node_modules/prismjs/components/prism-rust.js +130 -0
  45. package/dist/cjs/node_modules/prismjs/components/prism-sql.js +34 -0
  46. package/dist/cjs/node_modules/prismjs/components/prism-swift.js +150 -0
  47. package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +62 -0
  48. package/dist/cjs/node_modules/prismjs/prism.js +1951 -0
  49. package/dist/cjs/packages/lexical/src/components/StickyComponent.js +221 -0
  50. package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +156 -0
  51. package/dist/cjs/packages/lexical/src/editor/theme.js +97 -0
  52. package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +451 -0
  53. package/dist/cjs/packages/lexical/src/index.js +7 -0
  54. package/dist/cjs/packages/lexical/src/nodes/StickyNode.js +218 -0
  55. package/dist/cjs/packages/lexical/src/plugins/DraggableBlockPlugin.js +314 -0
  56. package/dist/cjs/packages/lexical/src/plugins/StickyPlugin.js +20 -0
  57. package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +258 -0
  58. package/dist/cjs/packages/lexical/src/utils/index.js +214 -0
  59. package/dist/esm/_virtual/prism.js +5 -0
  60. package/dist/esm/editor/Lexical.module.css +1 -0
  61. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +423 -0
  62. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +19 -0
  63. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +18 -0
  64. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +1121 -0
  65. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +21 -0
  66. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +32 -0
  67. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +244 -0
  68. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +18 -0
  69. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +17 -0
  70. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +463 -0
  71. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +17 -0
  72. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +16 -0
  73. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +1262 -0
  74. package/dist/esm/node_modules/@lexical/list/LexicalList.js +23 -0
  75. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +16 -0
  76. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +781 -0
  77. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +23 -0
  78. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +18 -0
  79. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +957 -0
  80. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +26 -0
  81. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +16 -0
  82. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +2754 -0
  83. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +20 -0
  84. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +17 -0
  85. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +839 -0
  86. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +26 -0
  87. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +17 -0
  88. package/dist/esm/node_modules/@mdi/js/mdi.js +7 -0
  89. package/dist/esm/node_modules/prismjs/components/prism-c.js +82 -0
  90. package/dist/esm/node_modules/prismjs/components/prism-clike.js +33 -0
  91. package/dist/esm/node_modules/prismjs/components/prism-cpp.js +101 -0
  92. package/dist/esm/node_modules/prismjs/components/prism-css.js +66 -0
  93. package/dist/esm/node_modules/prismjs/components/prism-java.js +126 -0
  94. package/dist/esm/node_modules/prismjs/components/prism-javascript.js +174 -0
  95. package/dist/esm/node_modules/prismjs/components/prism-markdown.js +417 -0
  96. package/dist/esm/node_modules/prismjs/components/prism-markup.js +188 -0
  97. package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +14 -0
  98. package/dist/esm/node_modules/prismjs/components/prism-powershell.js +60 -0
  99. package/dist/esm/node_modules/prismjs/components/prism-python.js +67 -0
  100. package/dist/esm/node_modules/prismjs/components/prism-rust.js +130 -0
  101. package/dist/esm/node_modules/prismjs/components/prism-sql.js +34 -0
  102. package/dist/esm/node_modules/prismjs/components/prism-swift.js +150 -0
  103. package/dist/esm/node_modules/prismjs/components/prism-typescript.js +62 -0
  104. package/dist/esm/node_modules/prismjs/prism.js +1951 -0
  105. package/dist/esm/packages/lexical/src/components/StickyComponent.js +221 -0
  106. package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +156 -0
  107. package/dist/esm/packages/lexical/src/editor/theme.js +97 -0
  108. package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +450 -0
  109. package/dist/esm/packages/lexical/src/index.js +3 -0
  110. package/dist/esm/packages/lexical/src/nodes/StickyNode.js +216 -0
  111. package/dist/esm/packages/lexical/src/plugins/DraggableBlockPlugin.js +314 -0
  112. package/dist/esm/packages/lexical/src/plugins/StickyPlugin.js +20 -0
  113. package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +258 -0
  114. package/dist/esm/packages/lexical/src/utils/index.js +211 -0
  115. package/dist/types/components/StickyComponent.d.ts +9 -0
  116. package/dist/types/editor/LexicalEditor.d.ts +13 -0
  117. package/dist/types/editor/theme.d.ts +70 -0
  118. package/dist/types/hooks/useFormatWatcher.d.ts +40 -0
  119. package/dist/types/index.d.ts +1 -0
  120. package/dist/types/nodes/StickyNode.d.ts +35 -0
  121. package/dist/types/plugins/DraggableBlockPlugin.d.ts +3 -0
  122. package/dist/types/plugins/StickyPlugin.d.ts +1 -0
  123. package/dist/types/plugins/ToolbarPlugin.d.ts +1 -0
  124. package/dist/types/utils/index.d.ts +57 -0
  125. package/package.json +55 -0
  126. package/src/components/StickyComponent.tsx +271 -0
  127. package/src/editor/Lexical.module.css +218 -0
  128. package/src/editor/LexicalEditor.tsx +222 -0
  129. package/src/editor/theme.ts +93 -0
  130. package/src/hooks/useFormatWatcher.ts +504 -0
  131. package/src/index.ts +24 -0
  132. package/src/nodes/StickyNode.tsx +249 -0
  133. package/src/plugins/DraggableBlockPlugin.tsx +418 -0
  134. package/src/plugins/StickyPlugin.ts +38 -0
  135. package/src/plugins/ToolbarPlugin.tsx +279 -0
  136. package/src/utils/index.ts +303 -0
@@ -0,0 +1,314 @@
1
+ 'use client';
2
+
3
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
5
+ import { eventFiles } from '../../../../node_modules/@lexical/rich-text/LexicalRichText.js';
6
+ import { mergeRegister } from '../../../../node_modules/@lexical/utils/LexicalUtils.js';
7
+ import { DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, COMMAND_PRIORITY_HIGH, $getNodeByKey, $getNearestNodeFromDOMNode, $getRoot } from 'lexical';
8
+ import { useRef, useState, useEffect } from 'react';
9
+ import { createPortal } from 'react-dom';
10
+ import { isHTMLElement, Point, Rect } from '../utils/index.js';
11
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
12
+
13
+ var SPACE = 4;
14
+ var TARGET_LINE_HALF_HEIGHT = 2;
15
+ var DRAGGABLE_BLOCK_MENU_CLASSNAME = "draggable-block-menu";
16
+ var DRAG_DATA_FORMAT = "application/x-lexical-drag-block";
17
+ var TEXT_BOX_HORIZONTAL_PADDING = 28;
18
+ var Downward = 1;
19
+ var Upward = -1;
20
+ var Indeterminate = 0;
21
+ var prevIndex = Infinity;
22
+ function getCurrentIndex(keysLength) {
23
+ if (keysLength === 0) {
24
+ return Infinity;
25
+ }
26
+ if (prevIndex >= 0 && prevIndex < keysLength) {
27
+ return prevIndex;
28
+ }
29
+ return Math.floor(keysLength / 2);
30
+ }
31
+ function getTopLevelNodeKeys(editor) {
32
+ return editor.getEditorState().read(function () {
33
+ return $getRoot().getChildrenKeys();
34
+ });
35
+ }
36
+ function getBlockElement(anchorElem, editor, event) {
37
+ var anchorElementRect = anchorElem.getBoundingClientRect();
38
+ var topLevelNodeKeys = getTopLevelNodeKeys(editor);
39
+ var blockElem = null;
40
+ editor.getEditorState().read(function () {
41
+ var index = getCurrentIndex(topLevelNodeKeys.length);
42
+ var direction = Indeterminate;
43
+ while (index >= 0 && index < topLevelNodeKeys.length) {
44
+ var key = topLevelNodeKeys[index];
45
+ var elem = editor.getElementByKey(key);
46
+ if (elem === null) {
47
+ break;
48
+ }
49
+ var point = new Point(event.x, event.y);
50
+ var domRect = Rect.fromDOM(elem);
51
+ var _window$getComputedSt = window.getComputedStyle(elem),
52
+ marginTop = _window$getComputedSt.marginTop,
53
+ marginBottom = _window$getComputedSt.marginBottom;
54
+ var rect = domRect.generateNewRect({
55
+ bottom: domRect.bottom + parseFloat(marginBottom),
56
+ left: anchorElementRect.left,
57
+ right: anchorElementRect.right,
58
+ top: domRect.top - parseFloat(marginTop)
59
+ });
60
+ var _rect$contains = rect.contains(point),
61
+ result = _rect$contains.result,
62
+ _rect$contains$reason = _rect$contains.reason,
63
+ isOnTopSide = _rect$contains$reason.isOnTopSide,
64
+ isOnBottomSide = _rect$contains$reason.isOnBottomSide;
65
+ if (result) {
66
+ blockElem = elem;
67
+ prevIndex = index;
68
+ break;
69
+ }
70
+ if (direction === Indeterminate) {
71
+ if (isOnTopSide) {
72
+ direction = Upward;
73
+ } else if (isOnBottomSide) {
74
+ direction = Downward;
75
+ } else {
76
+ // stop search block element
77
+ direction = Infinity;
78
+ }
79
+ }
80
+ index += direction;
81
+ }
82
+ });
83
+ return blockElem;
84
+ }
85
+ function isOnMenu(element) {
86
+ return !!element.closest(".".concat(DRAGGABLE_BLOCK_MENU_CLASSNAME));
87
+ }
88
+ function setMenuPosition(targetElem, floatingElem, anchorElem) {
89
+ var _targetElem$closest$s, _targetElem$closest;
90
+ if (!targetElem) {
91
+ floatingElem.style.opacity = "0";
92
+ floatingElem.style.transform = "translate(-10000px, -10000px)";
93
+ return;
94
+ }
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
+ var targetRect = targetElem.getBoundingClientRect();
97
+ var targetStyle = window.getComputedStyle(targetElem);
98
+ var floatingElemRect = floatingElem.getBoundingClientRect();
99
+ var anchorElementRect = anchorElem.getBoundingClientRect();
100
+ var top = scrollTop + targetRect.top + (parseInt(targetStyle.lineHeight, 10) - floatingElemRect.height) / 2 - anchorElementRect.top;
101
+ var left = SPACE;
102
+ floatingElem.style.opacity = "1";
103
+ floatingElem.style.transform = "translate(".concat(left, "px, ").concat(top, "px)");
104
+ }
105
+ function setDragImage(dataTransfer, draggableBlockElem) {
106
+ var transform = draggableBlockElem.style.transform;
107
+
108
+ // Remove dragImage borders
109
+ draggableBlockElem.style.transform = "translateZ(0)";
110
+ dataTransfer.setDragImage(draggableBlockElem, 0, 0);
111
+ setTimeout(function () {
112
+ draggableBlockElem.style.transform = transform;
113
+ });
114
+ }
115
+ function setTargetLine(targetLineElem, targetBlockElem, mouseY, anchorElem) {
116
+ var _targetBlockElem$clos, _targetBlockElem$clos2;
117
+ var targetStyle = window.getComputedStyle(targetBlockElem);
118
+ var _targetBlockElem$getB = targetBlockElem.getBoundingClientRect(),
119
+ targetBlockElemTop = _targetBlockElem$getB.top,
120
+ targetBlockElemHeight = _targetBlockElem$getB.height;
121
+ var _anchorElem$getBoundi = anchorElem.getBoundingClientRect(),
122
+ anchorTop = _anchorElem$getBoundi.top,
123
+ anchorWidth = _anchorElem$getBoundi.width;
124
+ var scrollTop = (_targetBlockElem$clos = (_targetBlockElem$clos2 = targetBlockElem.closest(".editor-container")) === null || _targetBlockElem$clos2 === void 0 ? void 0 : _targetBlockElem$clos2.scrollTop) !== null && _targetBlockElem$clos !== void 0 ? _targetBlockElem$clos : 0;
125
+ var lineTop = targetBlockElemTop;
126
+ // At the bottom of the target
127
+ if (mouseY - targetBlockElemTop > targetBlockElemHeight / 2) {
128
+ lineTop += targetBlockElemHeight + parseFloat(targetStyle.marginBottom);
129
+ } else {
130
+ lineTop -= parseFloat(targetStyle.marginTop);
131
+ }
132
+ var top = lineTop - anchorTop - TARGET_LINE_HALF_HEIGHT + scrollTop;
133
+ var left = TEXT_BOX_HORIZONTAL_PADDING - SPACE;
134
+ targetLineElem.style.transform = "translate(".concat(left, "px, ").concat(top, "px)");
135
+ targetLineElem.style.width = "".concat(anchorWidth - (TEXT_BOX_HORIZONTAL_PADDING - SPACE) * 2, "px");
136
+ targetLineElem.style.opacity = ".4";
137
+ }
138
+ function hideTargetLine(targetLineElem) {
139
+ if (targetLineElem) {
140
+ targetLineElem.style.opacity = "0";
141
+ targetLineElem.style.transform = "translate(-10000px, -10000px)";
142
+ }
143
+ }
144
+ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
145
+ var _draggableBlockElem$c;
146
+ var scrollerElem = anchorElem.parentElement;
147
+ var menuRef = useRef(null);
148
+ var targetLineRef = useRef(null);
149
+ var isDraggingBlockRef = useRef(false);
150
+ var _useState = useState(null),
151
+ _useState2 = _slicedToArray(_useState, 2),
152
+ draggableBlockElem = _useState2[0],
153
+ setDraggableBlockElem = _useState2[1];
154
+ useEffect(function () {
155
+ function onMouseMove(event) {
156
+ var target = event.target;
157
+ if (!isHTMLElement(target)) {
158
+ setDraggableBlockElem(null);
159
+ return;
160
+ }
161
+ if (target && isOnMenu(target)) {
162
+ return;
163
+ }
164
+ var _draggableBlockElem = getBlockElement(anchorElem, editor, event);
165
+ setDraggableBlockElem(_draggableBlockElem);
166
+ }
167
+ function onMouseLeave() {
168
+ setDraggableBlockElem(null);
169
+ }
170
+ scrollerElem === null || scrollerElem === void 0 || scrollerElem.addEventListener("mousemove", onMouseMove);
171
+ scrollerElem === null || scrollerElem === void 0 || scrollerElem.addEventListener("mouseleave", onMouseLeave);
172
+ return function () {
173
+ scrollerElem === null || scrollerElem === void 0 || scrollerElem.removeEventListener("mousemove", onMouseMove);
174
+ scrollerElem === null || scrollerElem === void 0 || scrollerElem.removeEventListener("mouseleave", onMouseLeave);
175
+ };
176
+ }, [scrollerElem, anchorElem, editor]);
177
+ useEffect(function () {
178
+ if (menuRef.current) {
179
+ setMenuPosition(draggableBlockElem, menuRef.current, anchorElem);
180
+ }
181
+ }, [anchorElem, draggableBlockElem]);
182
+ useEffect(function () {
183
+ function onDragover(event) {
184
+ if (!isDraggingBlockRef.current) {
185
+ return false;
186
+ }
187
+ var _eventFiles = eventFiles(event),
188
+ _eventFiles2 = _slicedToArray(_eventFiles, 1),
189
+ isFileTransfer = _eventFiles2[0];
190
+ if (isFileTransfer) {
191
+ return false;
192
+ }
193
+ var pageY = event.pageY,
194
+ target = event.target;
195
+ if (!isHTMLElement(target)) {
196
+ return false;
197
+ }
198
+ var targetBlockElem = getBlockElement(anchorElem, editor, event);
199
+ var targetLineElem = targetLineRef.current;
200
+ if (targetBlockElem === null || targetLineElem === null) {
201
+ return false;
202
+ }
203
+ setTargetLine(targetLineElem, targetBlockElem, pageY, anchorElem);
204
+ // Prevent default event to be able to trigger onDrop events
205
+ event.preventDefault();
206
+ return true;
207
+ }
208
+ function onDrop(event) {
209
+ var _dataTransfer$getData;
210
+ if (!isDraggingBlockRef.current) {
211
+ return false;
212
+ }
213
+ var _eventFiles3 = eventFiles(event),
214
+ _eventFiles4 = _slicedToArray(_eventFiles3, 1),
215
+ isFileTransfer = _eventFiles4[0];
216
+ if (isFileTransfer) {
217
+ return false;
218
+ }
219
+ var target = event.target,
220
+ dataTransfer = event.dataTransfer,
221
+ pageY = event.pageY;
222
+ var dragData = (_dataTransfer$getData = dataTransfer === null || dataTransfer === void 0 ? void 0 : dataTransfer.getData(DRAG_DATA_FORMAT)) !== null && _dataTransfer$getData !== void 0 ? _dataTransfer$getData : "";
223
+ var draggedNode = $getNodeByKey(dragData);
224
+ if (!draggedNode) {
225
+ return false;
226
+ }
227
+ if (!isHTMLElement(target)) {
228
+ return false;
229
+ }
230
+ var targetBlockElem = getBlockElement(anchorElem, editor, event);
231
+ if (!targetBlockElem) {
232
+ return false;
233
+ }
234
+ var targetNode = $getNearestNodeFromDOMNode(targetBlockElem);
235
+ if (!targetNode) {
236
+ return false;
237
+ }
238
+ if (targetNode === draggedNode) {
239
+ return true;
240
+ }
241
+ var _targetBlockElem$getB2 = targetBlockElem.getBoundingClientRect(),
242
+ top = _targetBlockElem$getB2.top,
243
+ height = _targetBlockElem$getB2.height;
244
+ var shouldInsertAfter = pageY - top > height / 2;
245
+ if (shouldInsertAfter || targetBlockElem.classList.contains("editor-cover-page")) {
246
+ targetNode.insertAfter(draggedNode);
247
+ } else {
248
+ targetNode.insertBefore(draggedNode);
249
+ }
250
+ setDraggableBlockElem(null);
251
+ return true;
252
+ }
253
+ return mergeRegister(editor.registerCommand(DRAGOVER_COMMAND, function (event) {
254
+ return onDragover(event);
255
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(DROP_COMMAND, function (event) {
256
+ return onDrop(event);
257
+ }, COMMAND_PRIORITY_HIGH));
258
+ }, [anchorElem, editor]);
259
+ function onDragStart(event) {
260
+ var dataTransfer = event.dataTransfer;
261
+ if (!dataTransfer || !draggableBlockElem) {
262
+ return;
263
+ }
264
+ setDragImage(dataTransfer, draggableBlockElem);
265
+ var nodeKey = "";
266
+ editor.update(function () {
267
+ var node = $getNearestNodeFromDOMNode(draggableBlockElem);
268
+ if (node) {
269
+ nodeKey = node.getKey();
270
+ }
271
+ });
272
+ isDraggingBlockRef.current = true;
273
+ dataTransfer.setData(DRAG_DATA_FORMAT, nodeKey);
274
+ }
275
+ function onDragEnd() {
276
+ isDraggingBlockRef.current = false;
277
+ hideTargetLine(targetLineRef.current);
278
+ }
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, {
283
+ 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",
285
+ ref: menuRef,
286
+ draggable: true,
287
+ onDragStart: onDragStart,
288
+ onDragEnd: onDragEnd,
289
+ children: /*#__PURE__*/jsxs("svg", {
290
+ xmlns: "http://www.w3.org/2000/svg",
291
+ viewBox: "0 0 24 24",
292
+ className: "w-4 h-4 opacity-30 pointer-events-none",
293
+ children: [/*#__PURE__*/jsx("title", {
294
+ children: "dots-grid"
295
+ }), /*#__PURE__*/jsx("path", {
296
+ d: "M12 16C13.1 16 14 16.9 14 18S13.1 20 12 20 10 19.1 10 18 10.9 16 12 16M12 10C13.1 10 14 10.9 14 12S13.1 14 12 14 10 13.1 10 12 10.9 10 12 10M12 4C13.1 4 14 4.9 14 6S13.1 8 12 8 10 7.1 10 6 10.9 4 12 4M6 16C7.1 16 8 16.9 8 18S7.1 20 6 20 4 19.1 4 18 4.9 16 6 16M6 10C7.1 10 8 10.9 8 12S7.1 14 6 14 4 13.1 4 12 4.9 10 6 10M6 4C7.1 4 8 4.9 8 6S7.1 8 6 8 4 7.1 4 6 4.9 4 6 4M18 16C19.1 16 20 16.9 20 18S19.1 20 18 20 16 19.1 16 18 16.9 16 18 16M18 10C19.1 10 20 10.9 20 12S19.1 14 18 14 16 13.1 16 12 16.9 10 18 10M18 4C19.1 4 20 4.9 20 6S19.1 8 18 8 16 7.1 16 6 16.9 4 18 4Z"
297
+ })]
298
+ })
299
+ }), /*#__PURE__*/jsx("div", {
300
+ className: "pointer-events-none bg-primary h-1 absolute top-0 left-0 opacity-0 will-change-transform",
301
+ ref: targetLineRef
302
+ })]
303
+ }), anchorElem);
304
+ }
305
+ var DraggableBlockPlugin = function DraggableBlockPlugin(_ref) {
306
+ var _ref$anchorElem = _ref.anchorElem,
307
+ anchorElem = _ref$anchorElem === void 0 ? document.body : _ref$anchorElem;
308
+ var _useLexicalComposerCo = useLexicalComposerContext(),
309
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
310
+ editor = _useLexicalComposerCo2[0];
311
+ return useDraggableBlockMenu(editor, anchorElem, editor._editable);
312
+ };
313
+
314
+ export { DraggableBlockPlugin };
@@ -0,0 +1,20 @@
1
+ 'use client';
2
+
3
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
5
+ import { useEffect } from 'react';
6
+ import { StickyNode } from '../nodes/StickyNode.js';
7
+
8
+ var StickyPlugin = function StickyPlugin() {
9
+ var _useLexicalComposerCo = useLexicalComposerContext(),
10
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
11
+ editor = _useLexicalComposerCo2[0];
12
+ useEffect(function () {
13
+ if (!editor.hasNodes([StickyNode])) {
14
+ throw new Error("StickyPlugin: StickyNode not registered on editor");
15
+ }
16
+ }, [editor]);
17
+ return null;
18
+ };
19
+
20
+ export { StickyPlugin };
@@ -0,0 +1,258 @@
1
+ 'use client';
2
+
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
+ import { CoreIcons, Dropdown, Button, Menu, MenuItem, Divider, ButtonGroup, ToggleButtonGroup, Icon, Tooltip } from '@react-fabric/core';
6
+ import { ColorInput } from '@react-fabric/form';
7
+ import { getValue } from '@react-fabric/utilities';
8
+ import { FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND } from 'lexical';
9
+ import { useMemo } from 'react';
10
+ import { useTranslation } from 'react-i18next';
11
+ import { useFormatWatcher } from '../hooks/useFormatWatcher.js';
12
+ import { jsxs, jsx } from 'react/jsx-runtime';
13
+
14
+ var _excluded = ["label"];
15
+ 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; }
16
+ 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; }
17
+ var blockTypeToBlockName = {
18
+ bullet: "Bulleted List",
19
+ code: "Block",
20
+ h1: "Heading",
21
+ h2: "Sub Heading",
22
+ h6: "Comment",
23
+ number: "Numbered List",
24
+ paragraph: "Normal",
25
+ quote: "Quote"
26
+ };
27
+ var blockTypeToBlockIcon = {
28
+ bullet: CoreIcons.formatListBullet,
29
+ code: CoreIcons.formatCodeBlock,
30
+ h1: " ",
31
+ h2: " ",
32
+ paragraph: "",
33
+ h6: CoreIcons.formatCommentBlock,
34
+ number: CoreIcons.formatListNumber,
35
+ quote: CoreIcons.formatQuoteBlock
36
+ };
37
+ var SIZES = Object.freeze(["8", "9", "10", "11", "12", "13", "14", "16", "18", "20", "24", "28", "32", "36", "48", "64", "72"]);
38
+ var ButtonWrapper = function ButtonWrapper(_ref) {
39
+ var label = _ref.label,
40
+ rest = _objectWithoutProperties(_ref, _excluded);
41
+ return /*#__PURE__*/jsx(Tooltip, {
42
+ content: label,
43
+ children: /*#__PURE__*/jsx(Button, _objectSpread({
44
+ "aria-label": label,
45
+ tabIndex: -1,
46
+ variant: "link"
47
+ }, rest))
48
+ });
49
+ };
50
+ var ToolbarPlugin = function ToolbarPlugin() {
51
+ var watch = useFormatWatcher();
52
+ var _useTranslation = useTranslation("lexical"),
53
+ t = _useTranslation.t;
54
+ var textFormat = useMemo(function () {
55
+ var ret = [];
56
+ if (watch.isBold) ret.push("bold");
57
+ if (watch.isItalic) ret.push("italic");
58
+ if (watch.isUnderline) ret.push("underline");
59
+ return ret;
60
+ }, [watch]);
61
+ return /*#__PURE__*/jsxs("div", {
62
+ className: "border-b flex px-1 py-px",
63
+ children: [/*#__PURE__*/jsxs(Dropdown, {
64
+ children: [/*#__PURE__*/jsx(Button, {
65
+ variant: "link",
66
+ tabIndex: -1,
67
+ altIcon: CoreIcons.caretDown,
68
+ icon: blockTypeToBlockIcon[watch.blockType],
69
+ children: blockTypeToBlockName[watch.blockType]
70
+ }), /*#__PURE__*/jsxs(Menu, {
71
+ children: [/*#__PURE__*/jsx(MenuItem, {
72
+ icon: blockTypeToBlockIcon.h1,
73
+ label: blockTypeToBlockName.h1,
74
+ onClick: function onClick() {
75
+ return watch.formatHeading("h1");
76
+ }
77
+ }), /*#__PURE__*/jsx(MenuItem, {
78
+ icon: blockTypeToBlockIcon.h2,
79
+ label: blockTypeToBlockName.h2,
80
+ onClick: function onClick() {
81
+ return watch.formatHeading("h2");
82
+ }
83
+ }), /*#__PURE__*/jsx(MenuItem, {
84
+ icon: blockTypeToBlockIcon.paragraph,
85
+ label: blockTypeToBlockName.paragraph,
86
+ onClick: watch.formatNormal
87
+ }), /*#__PURE__*/jsx(MenuItem, {
88
+ icon: blockTypeToBlockIcon.quote,
89
+ label: blockTypeToBlockName.quote,
90
+ onClick: watch.formatQuote
91
+ }), /*#__PURE__*/jsx(MenuItem, {
92
+ icon: blockTypeToBlockIcon.code,
93
+ label: blockTypeToBlockName.code,
94
+ onClick: watch.formatBlock
95
+ }), /*#__PURE__*/jsx(MenuItem, {
96
+ icon: blockTypeToBlockIcon.h6,
97
+ label: blockTypeToBlockName.h6,
98
+ onClick: function onClick() {
99
+ return watch.formatHeading("h6");
100
+ }
101
+ }), /*#__PURE__*/jsx(MenuItem, {
102
+ icon: blockTypeToBlockIcon.bullet,
103
+ label: blockTypeToBlockName.bullet,
104
+ onClick: watch.formatBulletList
105
+ }), /*#__PURE__*/jsx(MenuItem, {
106
+ icon: blockTypeToBlockIcon.number,
107
+ label: blockTypeToBlockName.number,
108
+ onClick: watch.formatNumberedList
109
+ })]
110
+ })]
111
+ }), /*#__PURE__*/jsx(Divider, {
112
+ vertical: true
113
+ }), /*#__PURE__*/jsx("div", {
114
+ children: /*#__PURE__*/jsxs(Dropdown, {
115
+ children: [/*#__PURE__*/jsx(Button, {
116
+ variant: "link",
117
+ altIcon: CoreIcons.caretDown,
118
+ children: getValue(watch.fontSize + "", "16")
119
+ }), /*#__PURE__*/jsx(Menu, {
120
+ className: "hide-icons",
121
+ children: SIZES.map(function (size) {
122
+ return /*#__PURE__*/jsx(MenuItem, {
123
+ label: size,
124
+ active: watch.fontSize === size,
125
+ onClick: function onClick() {
126
+ return watch.onSizeChange(size);
127
+ }
128
+ }, size);
129
+ })
130
+ })]
131
+ })
132
+ }), /*#__PURE__*/jsx(Divider, {
133
+ vertical: true
134
+ }), /*#__PURE__*/jsxs(ButtonGroup, {
135
+ variant: "link",
136
+ children: [/*#__PURE__*/jsx(ButtonWrapper, {
137
+ value: "start",
138
+ rtlFlip: true,
139
+ label: t("tool.alignStart"),
140
+ icon: CoreIcons.alignLeft,
141
+ onClick: function onClick() {
142
+ return watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "start");
143
+ }
144
+ }), /*#__PURE__*/jsx(ButtonWrapper, {
145
+ value: "center",
146
+ label: t("tool.alignCenter"),
147
+ icon: CoreIcons.alignCenter,
148
+ onClick: function onClick() {
149
+ return watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "center");
150
+ }
151
+ }), /*#__PURE__*/jsx(ButtonWrapper, {
152
+ value: "end",
153
+ rtlFlip: true,
154
+ label: t("tool.alignEnd"),
155
+ icon: CoreIcons.alignRight,
156
+ onClick: function onClick() {
157
+ return watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "end");
158
+ }
159
+ }), /*#__PURE__*/jsx(ButtonWrapper, {
160
+ value: "justify",
161
+ rtlFlip: true,
162
+ label: t("tool.alignJustify"),
163
+ icon: CoreIcons.alignJustify,
164
+ onClick: function onClick() {
165
+ return watch.activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, "justify");
166
+ }
167
+ }), /*#__PURE__*/jsx(ButtonWrapper, {
168
+ value: "justify",
169
+ rtlFlip: true,
170
+ label: t("tool.indentOut"),
171
+ icon: CoreIcons.formatIndentDecrease,
172
+ onClick: function onClick() {
173
+ return watch.outdent();
174
+ }
175
+ }), /*#__PURE__*/jsx(ButtonWrapper, {
176
+ value: "justify",
177
+ rtlFlip: true,
178
+ label: t("tool.identIn"),
179
+ icon: CoreIcons.formatIndentIncrease,
180
+ onClick: function onClick() {
181
+ return watch.indent();
182
+ }
183
+ })]
184
+ }), /*#__PURE__*/jsx(Divider, {
185
+ vertical: true
186
+ }), /*#__PURE__*/jsxs(ToggleButtonGroup, {
187
+ variant: "link",
188
+ value: textFormat,
189
+ children: [/*#__PURE__*/jsx(ButtonWrapper, {
190
+ value: "bold",
191
+ label: t("tool.bold"),
192
+ icon: CoreIcons.formatBold,
193
+ onClick: function onClick() {
194
+ return watch.activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "bold");
195
+ }
196
+ }), /*#__PURE__*/jsx(ButtonWrapper, {
197
+ value: "italic",
198
+ label: t("tool.italic"),
199
+ icon: CoreIcons.formatItalic,
200
+ onClick: function onClick() {
201
+ return watch.activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "italic");
202
+ }
203
+ }), /*#__PURE__*/jsx(ButtonWrapper, {
204
+ value: "underline",
205
+ label: t("tool.underline"),
206
+ icon: CoreIcons.formatUnderline,
207
+ onClick: function onClick() {
208
+ return watch.activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "underline");
209
+ }
210
+ }), /*#__PURE__*/jsx(ButtonWrapper, {
211
+ value: "strikethrough",
212
+ label: t("tool.strikethrough"),
213
+ icon: CoreIcons.formatStrikethrough,
214
+ onClick: function onClick() {
215
+ return watch.activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "strikethrough");
216
+ }
217
+ })]
218
+ }), /*#__PURE__*/jsx(Divider, {
219
+ vertical: true
220
+ }), /*#__PURE__*/jsx(ColorInput, {
221
+ noOutline: true,
222
+ value: watch.fontColor,
223
+ onChange: function onChange() {
224
+ var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#000";
225
+ return watch.onFontColorSelect(v);
226
+ },
227
+ decorateStart: /*#__PURE__*/jsx(Icon, {
228
+ icon: CoreIcons.formatText
229
+ })
230
+ }), /*#__PURE__*/jsx(ColorInput, {
231
+ noOutline: true,
232
+ value: watch.bgColor,
233
+ onChange: function onChange() {
234
+ var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#fff";
235
+ return watch.onBgColorSelect(v);
236
+ },
237
+ decorateStart: /*#__PURE__*/jsx(Icon, {
238
+ icon: CoreIcons.formatFill
239
+ })
240
+ }), /*#__PURE__*/jsx(ButtonWrapper, {
241
+ value: "hilight",
242
+ label: t("tool.hilight"),
243
+ icon: CoreIcons.formatHilight,
244
+ onClick: function onClick() {
245
+ return watch.onBgColorSelect("#fde68a");
246
+ }
247
+ }), /*#__PURE__*/jsx(ButtonWrapper, {
248
+ value: "hilight",
249
+ label: t("tool.clear"),
250
+ icon: CoreIcons.formatClear,
251
+ onClick: function onClick() {
252
+ return watch.clearFormatting();
253
+ }
254
+ }), /*#__PURE__*/jsx(Divider, {})]
255
+ });
256
+ };
257
+
258
+ export { ToolbarPlugin };