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