@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
@@ -1,220 +0,0 @@
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 core = require('@react-fabric/core');
11
- var lexical = require('lexical');
12
- var react = require('react');
13
- var StickyNode = require('../nodes/StickyNode.js');
14
- var jsxRuntime = require('react/jsx-runtime');
15
-
16
- function positionSticky(stickyElem, positioning) {
17
- var style = stickyElem.style;
18
- style.top = "".concat(positioning.y, "px");
19
- style.left = "".concat(positioning.x, "px");
20
- }
21
- var StickyComponent = function StickyComponent(_ref) {
22
- var _ref$x = _ref.x,
23
- x = _ref$x === void 0 ? 0 : _ref$x,
24
- _ref$y = _ref.y,
25
- y = _ref$y === void 0 ? 0 : _ref$y,
26
- nodeKey = _ref.nodeKey,
27
- color = _ref.color,
28
- state = _ref.state,
29
- user = _ref.user;
30
- var _useLexicalComposerCo = LexicalComposerContext.useLexicalComposerContext(),
31
- _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
32
- editor = _useLexicalComposerCo2[0];
33
- var stickyContainerRef = react.useRef(null);
34
- var positioningRef = react.useRef({
35
- isDragging: false,
36
- offsetX: 0,
37
- offsetY: 0,
38
- rootElementRect: {
39
- left: 8,
40
- top: 8
41
- },
42
- x: 8,
43
- y: 8
44
- });
45
- react.useEffect(function () {
46
- var position = positioningRef.current;
47
- position.x = x;
48
- position.y = y;
49
- var stickyContainer = stickyContainerRef.current;
50
- if (stickyContainer !== null) {
51
- positioningRef.current.rootElementRect = {
52
- left: x,
53
- top: y
54
- };
55
- positionSticky(stickyContainer, position);
56
- }
57
- }, [x, y]);
58
- react.useEffect(function () {
59
- var stickyContainer = stickyContainerRef.current;
60
- if (stickyContainer !== null) {
61
- // Delay adding transition so we don't trigger the
62
- // transition on load of the sticky.
63
- setTimeout(function () {
64
- stickyContainer.style.setProperty("transition", "top 300ms ease 0s, left 300ms ease 0s");
65
- }, 500);
66
- }
67
- }, []);
68
- var handlePointerMove = function handlePointerMove(event) {
69
- var stickyContainer = stickyContainerRef.current;
70
- var positioning = positioningRef.current;
71
- var rootElementRect = positioning.rootElementRect;
72
- if (stickyContainer !== null && positioning.isDragging && rootElementRect !== null) {
73
- positioning.x = rootElementRect.left + (event.pageX - positioning.offsetX);
74
- positioning.y = rootElementRect.top + (event.pageY - positioning.offsetY);
75
- if (positioning.x < 0) positioning.x = 0;
76
- if (positioning.x > 642) positioning.x = 642 - stickyContainer.offsetWidth;
77
- if (positioning.y < 0) positioning.y = 0;
78
- positionSticky(stickyContainer, positioning);
79
- }
80
- };
81
- var handlePointerUp = function handlePointerUp(event) {
82
- var stickyContainer = stickyContainerRef.current;
83
- var positioning = positioningRef.current;
84
- if (stickyContainer !== null) {
85
- positioning.isDragging = false;
86
- stickyContainer.classList.remove("dragging");
87
- editor.update(function () {
88
- var node = lexical.$getNodeByKey(nodeKey);
89
- if (StickyNode.$isStickyNode(node)) {
90
- node.setPosition(positioning.x, positioning.y);
91
- }
92
- });
93
- }
94
- document.removeEventListener("pointermove", handlePointerMove);
95
- document.removeEventListener("pointerup", handlePointerUp);
96
- };
97
- var handleDelete = function handleDelete() {
98
- editor.update(function () {
99
- var node = lexical.$getNodeByKey(nodeKey);
100
- if (StickyNode.$isStickyNode(node)) {
101
- node.remove();
102
- }
103
- });
104
- };
105
- var handleColorChange = function handleColorChange() {
106
- editor.update(function () {
107
- var node = lexical.$getNodeByKey(nodeKey);
108
- if (StickyNode.$isStickyNode(node)) {
109
- node.toggleColor();
110
- }
111
- });
112
- };
113
- var innerEditor = react.useMemo(function () {
114
- var editor = lexical.createEditor({
115
- editable: true
116
- });
117
- if (state) {
118
- var editorState = editor.parseEditorState(state);
119
- editor.setEditorState(editorState);
120
- }
121
- return editor;
122
- }, []);
123
- react.useEffect(function () {
124
- if (innerEditor._editable) {
125
- var dispose = innerEditor.registerUpdateListener(function (_ref2) {
126
- _ref2.editorState;
127
- editor.update(function () {
128
- var node = lexical.$getNodeByKey(nodeKey);
129
- if (StickyNode.$isStickyNode(node)) {
130
- node.updateState(innerEditor.getEditorState().toJSON());
131
- }
132
- });
133
- });
134
- return function () {
135
- dispose();
136
- };
137
- }
138
- }, [innerEditor._editable]);
139
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
140
- ref: stickyContainerRef,
141
- className: "sticky__container",
142
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
143
- className: "sticky__handle",
144
- onPointerDown: function onPointerDown(event) {
145
- var stickyContainer = stickyContainerRef.current;
146
- if (stickyContainer == null || event.button === 2 || event.target !== stickyContainer.firstChild) {
147
- // Right click or click on editor should not work
148
- return;
149
- }
150
- var stickContainer = stickyContainer;
151
- var positioning = positioningRef.current;
152
- if (stickContainer !== null) {
153
- positioning.offsetX = event.clientX;
154
- positioning.offsetY = event.clientY;
155
- positioning.rootElementRect = {
156
- left: positioning.x,
157
- top: positioning.y
158
- };
159
- positioning.isDragging = true;
160
- stickContainer.classList.add("dragging");
161
- document.addEventListener("pointermove", handlePointerMove);
162
- document.addEventListener("pointerup", handlePointerUp);
163
- event.preventDefault();
164
- }
165
- }
166
- }), /*#__PURE__*/jsxRuntime.jsxs("div", {
167
- className: "sticky-note ".concat(color),
168
- children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
169
- className: "sticky__tools",
170
- children: [/*#__PURE__*/jsxRuntime.jsx("button", {
171
- onClick: handleColorChange,
172
- className: "sticky--color",
173
- "aria-label": "Change sticky note color",
174
- title: "Color",
175
- children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
176
- icon: "icon-[mdi--format-color-fill]"
177
- })
178
- }), /*#__PURE__*/jsxRuntime.jsx("button", {
179
- onClick: handleDelete,
180
- className: "sticky--delete",
181
- "aria-label": "Delete sticky note",
182
- title: "Delete",
183
- children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
184
- icon: "icon-[mdi--close]"
185
- })
186
- })]
187
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
188
- className: "text-sm font-semibold",
189
- children: user
190
- }), /*#__PURE__*/jsxRuntime.jsxs(LexicalNestedComposer.LexicalNestedComposer, {
191
- initialEditor: innerEditor,
192
- initialTheme: {
193
- paragraph: "sticky__paragraph",
194
- text: {
195
- bold: "editor-textBold",
196
- code: "editor-textCode",
197
- italic: "editor-textItalic",
198
- strikethrough: "editor-textStrikethrough",
199
- subscript: "editor-textSubscript",
200
- superscript: "editor-textSuperscript",
201
- underline: "editor-textUnderline",
202
- underlineStrikethrough: "editor-textUnderlineStrikethrough"
203
- }
204
- },
205
- children: [/*#__PURE__*/jsxRuntime.jsx(LexicalRichTextPlugin.RichTextPlugin, {
206
- contentEditable: /*#__PURE__*/jsxRuntime.jsx(LexicalContentEditable.ContentEditable, {
207
- className: "sticky__editor"
208
- }),
209
- placeholder: /*#__PURE__*/jsxRuntime.jsx("div", {
210
- className: "sticky-placeholder",
211
- children: "Sticky note..."
212
- }),
213
- ErrorBoundary: LexicalErrorBoundary.LexicalErrorBoundary
214
- }), /*#__PURE__*/jsxRuntime.jsx(LexicalAutoFocusPlugin.AutoFocusPlugin, {})]
215
- })]
216
- })]
217
- });
218
- };
219
-
220
- exports.StickyComponent = StickyComponent;
@@ -1,218 +0,0 @@
1
- 'use strict';
2
-
3
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
4
- var _createClass = require('@babel/runtime/helpers/createClass');
5
- var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
6
- var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
7
- var _inherits = require('@babel/runtime/helpers/inherits');
8
- var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
9
- var _regeneratorRuntime = require('@babel/runtime/regenerator');
10
- var lexical = require('lexical');
11
- var react = require('react');
12
- var reactDom = require('react-dom');
13
- var jsxRuntime = require('react/jsx-runtime');
14
-
15
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
16
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
17
- var StickyComponent = /*#__PURE__*/react.lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
18
- return _regeneratorRuntime.wrap(function _callee$(_context) {
19
- while (1) switch (_context.prev = _context.next) {
20
- case 0:
21
- _context.next = 2;
22
- return Promise.resolve().then(function () { return require('../components/StickyComponent.js'); }).then(function (_ref2) {
23
- var StickyComponent = _ref2.StickyComponent;
24
- return {
25
- "default": StickyComponent
26
- };
27
- });
28
- case 2:
29
- return _context.abrupt("return", _context.sent);
30
- case 3:
31
- case "end":
32
- return _context.stop();
33
- }
34
- }, _callee);
35
- })));
36
- var convertStickyElement = function convertStickyElement(domNode) {
37
- var sticky = domNode.getAttribute("data-lexical-sticky") === "true";
38
- if (sticky) {
39
- var _domNode$getAttribute, _domNode$getAttribute2, _domNode$getAttribute3, _domNode$getAttribute4;
40
- var node = $createStickyNode({
41
- xOffset: +((_domNode$getAttribute = domNode.getAttribute("data-x")) !== null && _domNode$getAttribute !== void 0 ? _domNode$getAttribute : "8"),
42
- yOffset: +((_domNode$getAttribute2 = domNode.getAttribute("data-y")) !== null && _domNode$getAttribute2 !== void 0 ? _domNode$getAttribute2 : "8"),
43
- user: (_domNode$getAttribute3 = domNode.getAttribute("data-user")) !== null && _domNode$getAttribute3 !== void 0 ? _domNode$getAttribute3 : "",
44
- color: domNode.getAttribute("data-color"),
45
- state: (_domNode$getAttribute4 = domNode.getAttribute("data-state")) !== null && _domNode$getAttribute4 !== void 0 ? _domNode$getAttribute4 : ""
46
- });
47
- return {
48
- node: node
49
- };
50
- }
51
- return null;
52
- };
53
- var colors = {
54
- yellow: "green",
55
- green: "blue",
56
- blue: "pink",
57
- pink: "yellow"
58
- };
59
- var StickyNode = /*#__PURE__*/function (_DecoratorNode) {
60
- function StickyNode(x, y) {
61
- var _this;
62
- var user = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
63
- var color = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "yellow";
64
- var state = arguments.length > 4 ? arguments[4] : undefined;
65
- var key = arguments.length > 5 ? arguments[5] : undefined;
66
- _classCallCheck(this, StickyNode);
67
- _this = _callSuper(this, StickyNode, [key]);
68
- _this.__x = x;
69
- _this.__y = y;
70
- _this.__user = user;
71
- _this.__state = state;
72
- _this.__color = color;
73
- return _this;
74
- }
75
- _inherits(StickyNode, _DecoratorNode);
76
- return _createClass(StickyNode, [{
77
- key: "exportJSON",
78
- value: function exportJSON() {
79
- return {
80
- state: this.__state,
81
- color: this.__color,
82
- user: this.__user,
83
- type: "sticky",
84
- version: 1,
85
- xOffset: this.__x,
86
- yOffset: this.__y
87
- };
88
- }
89
- }, {
90
- key: "createDOM",
91
- value: function createDOM(config) {
92
- var div = document.createElement("div");
93
- div.style.display = "contents";
94
- return div;
95
- }
96
- }, {
97
- key: "updateDOM",
98
- value: function updateDOM() {
99
- return false;
100
- }
101
- }, {
102
- key: "exportDOM",
103
- value: function exportDOM() {
104
- var writable = this.getWritable();
105
- var element = document.createElement("div");
106
- element.setAttribute("data-lexical-sticky", "true");
107
- element.setAttribute("data-x", "".concat(writable.__x));
108
- element.setAttribute("data-y", "".concat(writable.__y));
109
- element.setAttribute("data-user", "".concat(writable.__user));
110
- element.setAttribute("data-color", "".concat(writable.__color));
111
- element.setAttribute("data-state", "".concat(writable.__state));
112
- return {
113
- element: element
114
- };
115
- }
116
- }, {
117
- key: "setPosition",
118
- value: function setPosition(x, y) {
119
- var writable = this.getWritable();
120
- writable.__x = x;
121
- writable.__y = y;
122
- }
123
- }, {
124
- key: "toggleColor",
125
- value: function toggleColor() {
126
- var _writable$__color;
127
- var writable = this.getWritable();
128
- writable.__color = colors[(_writable$__color = writable.__color) !== null && _writable$__color !== void 0 ? _writable$__color : "yellow"];
129
- }
130
- }, {
131
- key: "updateState",
132
- value: function updateState(text) {
133
- var writable = this.getWritable();
134
- writable.__state = text;
135
- }
136
- }, {
137
- key: "decorate",
138
- value: function decorate(editor, config) {
139
- var _document$querySelect;
140
- return /*#__PURE__*/reactDom.createPortal( /*#__PURE__*/jsxRuntime.jsx(react.Suspense, {
141
- fallback: null,
142
- children: /*#__PURE__*/jsxRuntime.jsx(StickyComponent, {
143
- x: this.__x,
144
- y: this.__y,
145
- user: this.__user,
146
- state: this.__state,
147
- nodeKey: this.getKey(),
148
- color: this.__color
149
- })
150
- }), (_document$querySelect = document.querySelector(".lexical-container")) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.body);
151
- }
152
- }, {
153
- key: "isIsolated",
154
- value: function isIsolated() {
155
- return true;
156
- }
157
- }], [{
158
- key: "getType",
159
- value: function getType() {
160
- return "sticky";
161
- }
162
- }, {
163
- key: "clone",
164
- value: function clone(node) {
165
- return new StickyNode(node.__x, node.__y, node.__user, node.__color, node.__state, node.__key);
166
- }
167
- }, {
168
- key: "importJSON",
169
- value: function importJSON(serializedNode) {
170
- var stickyNode = new StickyNode(serializedNode.xOffset, serializedNode.yOffset, serializedNode.user, serializedNode.color, serializedNode.state);
171
- return stickyNode;
172
- }
173
- }, {
174
- key: "importDOM",
175
- value: function importDOM() {
176
- return {
177
- div: function div(domNode) {
178
- if (!domNode.hasAttribute("data-lexical-sticky")) {
179
- return null;
180
- }
181
- return {
182
- conversion: convertStickyElement,
183
- priority: 2
184
- };
185
- },
186
- span: function span(domNode) {
187
- if (!domNode.hasAttribute("data-lexical-sticky")) {
188
- return null;
189
- }
190
- return {
191
- conversion: convertStickyElement,
192
- priority: 1
193
- };
194
- }
195
- };
196
- }
197
- }]);
198
- }(lexical.DecoratorNode);
199
- function $isStickyNode(node) {
200
- return node instanceof StickyNode;
201
- }
202
- function $createStickyNode(_ref3) {
203
- var _ref3$xOffset = _ref3.xOffset,
204
- xOffset = _ref3$xOffset === void 0 ? 650 : _ref3$xOffset,
205
- _ref3$yOffset = _ref3.yOffset,
206
- yOffset = _ref3$yOffset === void 0 ? 32 : _ref3$yOffset,
207
- _ref3$user = _ref3.user,
208
- user = _ref3$user === void 0 ? "" : _ref3$user,
209
- _ref3$color = _ref3.color,
210
- color = _ref3$color === void 0 ? "yellow" : _ref3$color,
211
- state = _ref3.state;
212
- var node = new StickyNode(xOffset, yOffset, user, color, state);
213
- return lexical.$applyNodeReplacement(node);
214
- }
215
-
216
- exports.$createStickyNode = $createStickyNode;
217
- exports.$isStickyNode = $isStickyNode;
218
- exports.StickyNode = StickyNode;
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
- var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
5
- var react = require('react');
6
- var StickyNode = require('../nodes/StickyNode.js');
7
-
8
- var StickyPlugin = function StickyPlugin() {
9
- var _useLexicalComposerCo = LexicalComposerContext.useLexicalComposerContext(),
10
- _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
11
- editor = _useLexicalComposerCo2[0];
12
- react.useEffect(function () {
13
- if (!editor.hasNodes([StickyNode.StickyNode])) {
14
- throw new Error("StickyPlugin: StickyNode not registered on editor");
15
- }
16
- }, [editor]);
17
- return null;
18
- };
19
-
20
- exports.StickyPlugin = StickyPlugin;
@@ -1,220 +0,0 @@
1
- 'use client';
2
-
3
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
- import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin';
5
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
6
- import { ContentEditable } from '@lexical/react/LexicalContentEditable';
7
- import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
8
- import { LexicalNestedComposer } from '@lexical/react/LexicalNestedComposer';
9
- import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
10
- import { Icon } from '@react-fabric/core';
11
- import { createEditor, $getNodeByKey } from 'lexical';
12
- import { useRef, useEffect, useMemo } from 'react';
13
- import { $isStickyNode } from '../nodes/StickyNode.js';
14
- import { jsxs, jsx } from 'react/jsx-runtime';
15
-
16
- function positionSticky(stickyElem, positioning) {
17
- var style = stickyElem.style;
18
- style.top = "".concat(positioning.y, "px");
19
- style.left = "".concat(positioning.x, "px");
20
- }
21
- var StickyComponent = function StickyComponent(_ref) {
22
- var _ref$x = _ref.x,
23
- x = _ref$x === void 0 ? 0 : _ref$x,
24
- _ref$y = _ref.y,
25
- y = _ref$y === void 0 ? 0 : _ref$y,
26
- nodeKey = _ref.nodeKey,
27
- color = _ref.color,
28
- state = _ref.state,
29
- user = _ref.user;
30
- var _useLexicalComposerCo = useLexicalComposerContext(),
31
- _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
32
- editor = _useLexicalComposerCo2[0];
33
- var stickyContainerRef = useRef(null);
34
- var positioningRef = useRef({
35
- isDragging: false,
36
- offsetX: 0,
37
- offsetY: 0,
38
- rootElementRect: {
39
- left: 8,
40
- top: 8
41
- },
42
- x: 8,
43
- y: 8
44
- });
45
- useEffect(function () {
46
- var position = positioningRef.current;
47
- position.x = x;
48
- position.y = y;
49
- var stickyContainer = stickyContainerRef.current;
50
- if (stickyContainer !== null) {
51
- positioningRef.current.rootElementRect = {
52
- left: x,
53
- top: y
54
- };
55
- positionSticky(stickyContainer, position);
56
- }
57
- }, [x, y]);
58
- useEffect(function () {
59
- var stickyContainer = stickyContainerRef.current;
60
- if (stickyContainer !== null) {
61
- // Delay adding transition so we don't trigger the
62
- // transition on load of the sticky.
63
- setTimeout(function () {
64
- stickyContainer.style.setProperty("transition", "top 300ms ease 0s, left 300ms ease 0s");
65
- }, 500);
66
- }
67
- }, []);
68
- var handlePointerMove = function handlePointerMove(event) {
69
- var stickyContainer = stickyContainerRef.current;
70
- var positioning = positioningRef.current;
71
- var rootElementRect = positioning.rootElementRect;
72
- if (stickyContainer !== null && positioning.isDragging && rootElementRect !== null) {
73
- positioning.x = rootElementRect.left + (event.pageX - positioning.offsetX);
74
- positioning.y = rootElementRect.top + (event.pageY - positioning.offsetY);
75
- if (positioning.x < 0) positioning.x = 0;
76
- if (positioning.x > 642) positioning.x = 642 - stickyContainer.offsetWidth;
77
- if (positioning.y < 0) positioning.y = 0;
78
- positionSticky(stickyContainer, positioning);
79
- }
80
- };
81
- var handlePointerUp = function handlePointerUp(event) {
82
- var stickyContainer = stickyContainerRef.current;
83
- var positioning = positioningRef.current;
84
- if (stickyContainer !== null) {
85
- positioning.isDragging = false;
86
- stickyContainer.classList.remove("dragging");
87
- editor.update(function () {
88
- var node = $getNodeByKey(nodeKey);
89
- if ($isStickyNode(node)) {
90
- node.setPosition(positioning.x, positioning.y);
91
- }
92
- });
93
- }
94
- document.removeEventListener("pointermove", handlePointerMove);
95
- document.removeEventListener("pointerup", handlePointerUp);
96
- };
97
- var handleDelete = function handleDelete() {
98
- editor.update(function () {
99
- var node = $getNodeByKey(nodeKey);
100
- if ($isStickyNode(node)) {
101
- node.remove();
102
- }
103
- });
104
- };
105
- var handleColorChange = function handleColorChange() {
106
- editor.update(function () {
107
- var node = $getNodeByKey(nodeKey);
108
- if ($isStickyNode(node)) {
109
- node.toggleColor();
110
- }
111
- });
112
- };
113
- var innerEditor = useMemo(function () {
114
- var editor = createEditor({
115
- editable: true
116
- });
117
- if (state) {
118
- var editorState = editor.parseEditorState(state);
119
- editor.setEditorState(editorState);
120
- }
121
- return editor;
122
- }, []);
123
- useEffect(function () {
124
- if (innerEditor._editable) {
125
- var dispose = innerEditor.registerUpdateListener(function (_ref2) {
126
- _ref2.editorState;
127
- editor.update(function () {
128
- var node = $getNodeByKey(nodeKey);
129
- if ($isStickyNode(node)) {
130
- node.updateState(innerEditor.getEditorState().toJSON());
131
- }
132
- });
133
- });
134
- return function () {
135
- dispose();
136
- };
137
- }
138
- }, [innerEditor._editable]);
139
- return /*#__PURE__*/jsxs("div", {
140
- ref: stickyContainerRef,
141
- className: "sticky__container",
142
- children: [/*#__PURE__*/jsx("div", {
143
- className: "sticky__handle",
144
- onPointerDown: function onPointerDown(event) {
145
- var stickyContainer = stickyContainerRef.current;
146
- if (stickyContainer == null || event.button === 2 || event.target !== stickyContainer.firstChild) {
147
- // Right click or click on editor should not work
148
- return;
149
- }
150
- var stickContainer = stickyContainer;
151
- var positioning = positioningRef.current;
152
- if (stickContainer !== null) {
153
- positioning.offsetX = event.clientX;
154
- positioning.offsetY = event.clientY;
155
- positioning.rootElementRect = {
156
- left: positioning.x,
157
- top: positioning.y
158
- };
159
- positioning.isDragging = true;
160
- stickContainer.classList.add("dragging");
161
- document.addEventListener("pointermove", handlePointerMove);
162
- document.addEventListener("pointerup", handlePointerUp);
163
- event.preventDefault();
164
- }
165
- }
166
- }), /*#__PURE__*/jsxs("div", {
167
- className: "sticky-note ".concat(color),
168
- children: [/*#__PURE__*/jsxs("div", {
169
- className: "sticky__tools",
170
- children: [/*#__PURE__*/jsx("button", {
171
- onClick: handleColorChange,
172
- className: "sticky--color",
173
- "aria-label": "Change sticky note color",
174
- title: "Color",
175
- children: /*#__PURE__*/jsx(Icon, {
176
- icon: "icon-[mdi--format-color-fill]"
177
- })
178
- }), /*#__PURE__*/jsx("button", {
179
- onClick: handleDelete,
180
- className: "sticky--delete",
181
- "aria-label": "Delete sticky note",
182
- title: "Delete",
183
- children: /*#__PURE__*/jsx(Icon, {
184
- icon: "icon-[mdi--close]"
185
- })
186
- })]
187
- }), /*#__PURE__*/jsx("div", {
188
- className: "text-sm font-semibold",
189
- children: user
190
- }), /*#__PURE__*/jsxs(LexicalNestedComposer, {
191
- initialEditor: innerEditor,
192
- initialTheme: {
193
- paragraph: "sticky__paragraph",
194
- text: {
195
- bold: "editor-textBold",
196
- code: "editor-textCode",
197
- italic: "editor-textItalic",
198
- strikethrough: "editor-textStrikethrough",
199
- subscript: "editor-textSubscript",
200
- superscript: "editor-textSuperscript",
201
- underline: "editor-textUnderline",
202
- underlineStrikethrough: "editor-textUnderlineStrikethrough"
203
- }
204
- },
205
- children: [/*#__PURE__*/jsx(RichTextPlugin, {
206
- contentEditable: /*#__PURE__*/jsx(ContentEditable, {
207
- className: "sticky__editor"
208
- }),
209
- placeholder: /*#__PURE__*/jsx("div", {
210
- className: "sticky-placeholder",
211
- children: "Sticky note..."
212
- }),
213
- ErrorBoundary: LexicalErrorBoundary
214
- }), /*#__PURE__*/jsx(AutoFocusPlugin, {})]
215
- })]
216
- })]
217
- });
218
- };
219
-
220
- export { StickyComponent };