@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.
- package/css/_lexical.css +67 -9
- package/dist/cjs/editor/LexicalEditor.js +34 -11
- package/dist/cjs/hooks/useFormatWatcher.js +54 -56
- package/dist/cjs/i18n/{ar.json.js → ar/lexical.json.js} +10 -4
- package/dist/cjs/i18n/{en.json.js → en/lexical.json.js} +7 -1
- package/dist/cjs/i18n/index.js +4 -4
- package/dist/cjs/plugins/CommentPlugin.js +471 -0
- package/dist/cjs/plugins/DraggableBlockPlugin.js +10 -13
- package/dist/esm/editor/LexicalEditor.js +35 -12
- package/dist/esm/hooks/useFormatWatcher.js +54 -56
- package/dist/esm/i18n/{ar.json.js → ar/lexical.json.js} +9 -5
- package/dist/esm/i18n/{en.json.js → en/lexical.json.js} +6 -2
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/plugins/CommentPlugin.js +471 -0
- package/dist/esm/plugins/DraggableBlockPlugin.js +11 -14
- package/dist/types/editor/LexicalEditor.d.ts +13 -4
- package/dist/types/hooks/useFormatWatcher.d.ts +1 -1
- package/dist/types/plugins/CommentPlugin.d.ts +5 -0
- package/dist/types/plugins/DraggableBlockPlugin.d.ts +3 -2
- package/package.json +14 -13
- package/src/editor/LexicalEditor.tsx +66 -19
- package/src/hooks/useFormatWatcher.ts +0 -2
- package/src/i18n/{ar.json → ar/lexical.json} +6 -4
- package/src/i18n/{en.json → en/lexical.json} +3 -1
- package/src/i18n/index.ts +2 -2
- package/src/plugins/CommentPlugin.tsx +554 -0
- package/src/plugins/DraggableBlockPlugin.tsx +8 -13
- package/dist/cjs/components/StickyComponent.js +0 -220
- package/dist/cjs/nodes/StickyNode.js +0 -218
- package/dist/cjs/plugins/StickyPlugin.js +0 -20
- package/dist/esm/components/StickyComponent.js +0 -220
- package/dist/esm/nodes/StickyNode.js +0 -216
- package/dist/esm/plugins/StickyPlugin.js +0 -20
- package/dist/types/components/StickyComponent.d.ts +0 -9
- package/dist/types/nodes/StickyNode.d.ts +0 -34
- package/dist/types/plugins/StickyPlugin.d.ts +0 -1
- package/src/components/StickyComponent.tsx +0 -270
- package/src/nodes/StickyNode.tsx +0 -249
- package/src/plugins/StickyPlugin.ts +0 -38
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
4
|
-
import _createClass from '@babel/runtime/helpers/createClass';
|
|
5
|
-
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
6
|
-
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
7
|
-
import _inherits from '@babel/runtime/helpers/inherits';
|
|
8
|
-
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
9
|
-
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
10
|
-
import { DecoratorNode, $applyNodeReplacement } from 'lexical';
|
|
11
|
-
import { Suspense, lazy } from 'react';
|
|
12
|
-
import { createPortal } from 'react-dom';
|
|
13
|
-
import { jsx } from '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__*/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 import('../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__*/createPortal( /*#__PURE__*/jsx(Suspense, {
|
|
141
|
-
fallback: null,
|
|
142
|
-
children: /*#__PURE__*/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
|
-
}(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 $applyNodeReplacement(node);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export { $createStickyNode, $isStickyNode, StickyNode };
|
|
@@ -1,20 +0,0 @@
|
|
|
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 };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type NodeKey } from "lexical";
|
|
2
|
-
export declare const StickyComponent: ({ x, y, nodeKey, color, state, user, }: {
|
|
3
|
-
user: string;
|
|
4
|
-
state?: AnyObject;
|
|
5
|
-
color: "pink" | "yellow";
|
|
6
|
-
nodeKey: NodeKey;
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { DecoratorNode, type DOMConversionMap, type DOMExportOutput, type EditorConfig, type LexicalEditor, type LexicalNode, type NodeKey, type SerializedLexicalNode, type Spread } from "lexical";
|
|
2
|
-
type StickyNoteColor = "pink" | "yellow" | "green" | "blue";
|
|
3
|
-
interface StickyNodeType {
|
|
4
|
-
xOffset: number;
|
|
5
|
-
yOffset: number;
|
|
6
|
-
user?: string;
|
|
7
|
-
color?: StickyNoteColor;
|
|
8
|
-
state?: AnyObject;
|
|
9
|
-
}
|
|
10
|
-
export type SerializedStickyNode = Spread<StickyNodeType, SerializedLexicalNode>;
|
|
11
|
-
export declare class StickyNode extends DecoratorNode<JSX.Element> {
|
|
12
|
-
__x: number;
|
|
13
|
-
__y: number;
|
|
14
|
-
__user: string;
|
|
15
|
-
__state?: AnyObject;
|
|
16
|
-
__color: StickyNoteColor;
|
|
17
|
-
static getType(): string;
|
|
18
|
-
static clone(node: StickyNode): StickyNode;
|
|
19
|
-
static importJSON(serializedNode: SerializedStickyNode): StickyNode;
|
|
20
|
-
static importDOM(): DOMConversionMap | null;
|
|
21
|
-
constructor(x: number, y: number, user?: string, color?: StickyNoteColor, state?: KeyValue, key?: NodeKey);
|
|
22
|
-
exportJSON(): SerializedStickyNode;
|
|
23
|
-
createDOM(config: EditorConfig): HTMLElement;
|
|
24
|
-
updateDOM(): false;
|
|
25
|
-
exportDOM(): DOMExportOutput;
|
|
26
|
-
setPosition(x: number, y: number): void;
|
|
27
|
-
toggleColor(): void;
|
|
28
|
-
updateState(text: KeyValue): void;
|
|
29
|
-
decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element;
|
|
30
|
-
isIsolated(): true;
|
|
31
|
-
}
|
|
32
|
-
export declare function $isStickyNode(node: LexicalNode | null | undefined): node is StickyNode;
|
|
33
|
-
export declare function $createStickyNode({ xOffset, yOffset, user, color, state, }: StickyNodeType): StickyNode;
|
|
34
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const StickyPlugin: () => JSX.Element | null;
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* React Fabric
|
|
3
|
-
* @version: 1.0.0
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* The MIT License (MIT)
|
|
7
|
-
* Copyright (c) 2024 Adarsh Pastakia
|
|
8
|
-
*
|
|
9
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
-
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
-
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
-
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
-
* subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
-
* portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
-
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
// REF: https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/nodes/StickyComponent.tsx
|
|
25
|
-
|
|
26
|
-
import { AutoFocusPlugin } from "@lexical/react/LexicalAutoFocusPlugin";
|
|
27
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
28
|
-
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
29
|
-
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
|
|
30
|
-
import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
|
|
31
|
-
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
32
|
-
import { Icon } from "@react-fabric/core";
|
|
33
|
-
import { $getNodeByKey, createEditor, type NodeKey } from "lexical";
|
|
34
|
-
import { useEffect, useMemo, useRef } from "react";
|
|
35
|
-
import { $isStickyNode } from "../nodes/StickyNode";
|
|
36
|
-
|
|
37
|
-
interface Positioning {
|
|
38
|
-
isDragging: boolean;
|
|
39
|
-
offsetX: number;
|
|
40
|
-
offsetY: number;
|
|
41
|
-
rootElementRect: null | { left: number; top: number };
|
|
42
|
-
x: number;
|
|
43
|
-
y: number;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function positionSticky(
|
|
47
|
-
stickyElem: HTMLElement,
|
|
48
|
-
positioning: Positioning,
|
|
49
|
-
): void {
|
|
50
|
-
const style = stickyElem.style;
|
|
51
|
-
style.top = `${positioning.y}px`;
|
|
52
|
-
style.left = `${positioning.x}px`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const StickyComponent = ({
|
|
56
|
-
x = 0,
|
|
57
|
-
y = 0,
|
|
58
|
-
nodeKey,
|
|
59
|
-
color,
|
|
60
|
-
state,
|
|
61
|
-
user,
|
|
62
|
-
}: {
|
|
63
|
-
user: string;
|
|
64
|
-
state?: AnyObject;
|
|
65
|
-
color: "pink" | "yellow";
|
|
66
|
-
nodeKey: NodeKey;
|
|
67
|
-
x: number;
|
|
68
|
-
y: number;
|
|
69
|
-
}) => {
|
|
70
|
-
const [editor] = useLexicalComposerContext();
|
|
71
|
-
const stickyContainerRef = useRef<null | HTMLDivElement>(null);
|
|
72
|
-
const positioningRef = useRef<Positioning>({
|
|
73
|
-
isDragging: false,
|
|
74
|
-
offsetX: 0,
|
|
75
|
-
offsetY: 0,
|
|
76
|
-
rootElementRect: { left: 8, top: 8 },
|
|
77
|
-
x: 8,
|
|
78
|
-
y: 8,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
const position = positioningRef.current;
|
|
83
|
-
position.x = x;
|
|
84
|
-
position.y = y;
|
|
85
|
-
|
|
86
|
-
const stickyContainer = stickyContainerRef.current;
|
|
87
|
-
if (stickyContainer !== null) {
|
|
88
|
-
positioningRef.current.rootElementRect = {
|
|
89
|
-
left: x,
|
|
90
|
-
top: y,
|
|
91
|
-
};
|
|
92
|
-
positionSticky(stickyContainer, position);
|
|
93
|
-
}
|
|
94
|
-
}, [x, y]);
|
|
95
|
-
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
const stickyContainer = stickyContainerRef.current;
|
|
98
|
-
if (stickyContainer !== null) {
|
|
99
|
-
// Delay adding transition so we don't trigger the
|
|
100
|
-
// transition on load of the sticky.
|
|
101
|
-
setTimeout(() => {
|
|
102
|
-
stickyContainer.style.setProperty(
|
|
103
|
-
"transition",
|
|
104
|
-
"top 300ms ease 0s, left 300ms ease 0s",
|
|
105
|
-
);
|
|
106
|
-
}, 500);
|
|
107
|
-
}
|
|
108
|
-
}, []);
|
|
109
|
-
|
|
110
|
-
const handlePointerMove = (event: PointerEvent) => {
|
|
111
|
-
const stickyContainer = stickyContainerRef.current;
|
|
112
|
-
const positioning = positioningRef.current;
|
|
113
|
-
const rootElementRect = positioning.rootElementRect;
|
|
114
|
-
if (
|
|
115
|
-
stickyContainer !== null &&
|
|
116
|
-
positioning.isDragging &&
|
|
117
|
-
rootElementRect !== null
|
|
118
|
-
) {
|
|
119
|
-
positioning.x =
|
|
120
|
-
rootElementRect.left + (event.pageX - positioning.offsetX);
|
|
121
|
-
positioning.y = rootElementRect.top + (event.pageY - positioning.offsetY);
|
|
122
|
-
if (positioning.x < 0) positioning.x = 0;
|
|
123
|
-
if (positioning.x > 642)
|
|
124
|
-
positioning.x = 642 - stickyContainer.offsetWidth;
|
|
125
|
-
if (positioning.y < 0) positioning.y = 0;
|
|
126
|
-
positionSticky(stickyContainer, positioning);
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const handlePointerUp = (event: PointerEvent) => {
|
|
131
|
-
const stickyContainer = stickyContainerRef.current;
|
|
132
|
-
const positioning = positioningRef.current;
|
|
133
|
-
if (stickyContainer !== null) {
|
|
134
|
-
positioning.isDragging = false;
|
|
135
|
-
stickyContainer.classList.remove("dragging");
|
|
136
|
-
editor.update(() => {
|
|
137
|
-
const node = $getNodeByKey(nodeKey);
|
|
138
|
-
if ($isStickyNode(node)) {
|
|
139
|
-
node.setPosition(positioning.x, positioning.y);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
document.removeEventListener("pointermove", handlePointerMove);
|
|
144
|
-
document.removeEventListener("pointerup", handlePointerUp);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const handleDelete = () => {
|
|
148
|
-
editor.update(() => {
|
|
149
|
-
const node = $getNodeByKey(nodeKey);
|
|
150
|
-
if ($isStickyNode(node)) {
|
|
151
|
-
node.remove();
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const handleColorChange = () => {
|
|
157
|
-
editor.update(() => {
|
|
158
|
-
const node = $getNodeByKey(nodeKey);
|
|
159
|
-
if ($isStickyNode(node)) {
|
|
160
|
-
node.toggleColor();
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const innerEditor = useMemo(() => {
|
|
166
|
-
const editor = createEditor({ editable: true });
|
|
167
|
-
if (state) {
|
|
168
|
-
const editorState = editor.parseEditorState(state);
|
|
169
|
-
editor.setEditorState(editorState);
|
|
170
|
-
}
|
|
171
|
-
return editor;
|
|
172
|
-
}, []);
|
|
173
|
-
|
|
174
|
-
useEffect(() => {
|
|
175
|
-
if (innerEditor._editable) {
|
|
176
|
-
const dispose = innerEditor.registerUpdateListener(({ editorState }) => {
|
|
177
|
-
editor.update(() => {
|
|
178
|
-
const node = $getNodeByKey(nodeKey);
|
|
179
|
-
if ($isStickyNode(node)) {
|
|
180
|
-
node.updateState(innerEditor.getEditorState().toJSON());
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
return () => {
|
|
186
|
-
dispose();
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
}, [innerEditor._editable]);
|
|
190
|
-
|
|
191
|
-
return (
|
|
192
|
-
<div ref={stickyContainerRef} className="sticky__container">
|
|
193
|
-
<div
|
|
194
|
-
className="sticky__handle"
|
|
195
|
-
onPointerDown={(event) => {
|
|
196
|
-
const stickyContainer = stickyContainerRef.current;
|
|
197
|
-
if (
|
|
198
|
-
stickyContainer == null ||
|
|
199
|
-
event.button === 2 ||
|
|
200
|
-
event.target !== stickyContainer.firstChild
|
|
201
|
-
) {
|
|
202
|
-
// Right click or click on editor should not work
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
const stickContainer = stickyContainer;
|
|
206
|
-
const positioning = positioningRef.current;
|
|
207
|
-
if (stickContainer !== null) {
|
|
208
|
-
positioning.offsetX = event.clientX;
|
|
209
|
-
positioning.offsetY = event.clientY;
|
|
210
|
-
positioning.rootElementRect = {
|
|
211
|
-
left: positioning.x,
|
|
212
|
-
top: positioning.y,
|
|
213
|
-
};
|
|
214
|
-
positioning.isDragging = true;
|
|
215
|
-
stickContainer.classList.add("dragging");
|
|
216
|
-
document.addEventListener("pointermove", handlePointerMove);
|
|
217
|
-
document.addEventListener("pointerup", handlePointerUp);
|
|
218
|
-
event.preventDefault();
|
|
219
|
-
}
|
|
220
|
-
}}
|
|
221
|
-
/>
|
|
222
|
-
<div className={`sticky-note ${color}`}>
|
|
223
|
-
<div className="sticky__tools">
|
|
224
|
-
<button
|
|
225
|
-
onClick={handleColorChange}
|
|
226
|
-
className="sticky--color"
|
|
227
|
-
aria-label="Change sticky note color"
|
|
228
|
-
title="Color"
|
|
229
|
-
>
|
|
230
|
-
<Icon icon="icon-[mdi--format-color-fill]" />
|
|
231
|
-
</button>
|
|
232
|
-
<button
|
|
233
|
-
onClick={handleDelete}
|
|
234
|
-
className="sticky--delete"
|
|
235
|
-
aria-label="Delete sticky note"
|
|
236
|
-
title="Delete"
|
|
237
|
-
>
|
|
238
|
-
<Icon icon="icon-[mdi--close]" />
|
|
239
|
-
</button>
|
|
240
|
-
</div>
|
|
241
|
-
<div className="text-sm font-semibold">{user}</div>
|
|
242
|
-
<LexicalNestedComposer
|
|
243
|
-
initialEditor={innerEditor}
|
|
244
|
-
initialTheme={{
|
|
245
|
-
paragraph: "sticky__paragraph",
|
|
246
|
-
text: {
|
|
247
|
-
bold: "editor-textBold",
|
|
248
|
-
code: "editor-textCode",
|
|
249
|
-
italic: "editor-textItalic",
|
|
250
|
-
strikethrough: "editor-textStrikethrough",
|
|
251
|
-
subscript: "editor-textSubscript",
|
|
252
|
-
superscript: "editor-textSuperscript",
|
|
253
|
-
underline: "editor-textUnderline",
|
|
254
|
-
underlineStrikethrough: "editor-textUnderlineStrikethrough",
|
|
255
|
-
},
|
|
256
|
-
}}
|
|
257
|
-
>
|
|
258
|
-
<RichTextPlugin
|
|
259
|
-
contentEditable={<ContentEditable className="sticky__editor" />}
|
|
260
|
-
placeholder={
|
|
261
|
-
<div className="sticky-placeholder">Sticky note...</div>
|
|
262
|
-
}
|
|
263
|
-
ErrorBoundary={LexicalErrorBoundary as any}
|
|
264
|
-
/>
|
|
265
|
-
<AutoFocusPlugin />
|
|
266
|
-
</LexicalNestedComposer>
|
|
267
|
-
</div>
|
|
268
|
-
</div>
|
|
269
|
-
);
|
|
270
|
-
};
|