@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
package/src/nodes/StickyNode.tsx
DELETED
|
@@ -1,249 +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/StickyNode.tsx
|
|
25
|
-
|
|
26
|
-
import {
|
|
27
|
-
$applyNodeReplacement,
|
|
28
|
-
DecoratorNode,
|
|
29
|
-
type DOMConversionMap,
|
|
30
|
-
type DOMConversionOutput,
|
|
31
|
-
type DOMExportOutput,
|
|
32
|
-
type EditorConfig,
|
|
33
|
-
type LexicalEditor,
|
|
34
|
-
type LexicalNode,
|
|
35
|
-
type NodeKey,
|
|
36
|
-
type SerializedLexicalNode,
|
|
37
|
-
type Spread,
|
|
38
|
-
} from "lexical";
|
|
39
|
-
import { lazy, Suspense } from "react";
|
|
40
|
-
import { createPortal } from "react-dom";
|
|
41
|
-
|
|
42
|
-
const StickyComponent = lazy(
|
|
43
|
-
async () =>
|
|
44
|
-
await import("../components/StickyComponent").then(
|
|
45
|
-
({ StickyComponent }) => ({
|
|
46
|
-
default: StickyComponent,
|
|
47
|
-
}),
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
type StickyNoteColor = "pink" | "yellow" | "green" | "blue";
|
|
52
|
-
|
|
53
|
-
interface StickyNodeType {
|
|
54
|
-
xOffset: number;
|
|
55
|
-
yOffset: number;
|
|
56
|
-
user?: string;
|
|
57
|
-
color?: StickyNoteColor;
|
|
58
|
-
state?: AnyObject;
|
|
59
|
-
}
|
|
60
|
-
export type SerializedStickyNode = Spread<
|
|
61
|
-
StickyNodeType,
|
|
62
|
-
SerializedLexicalNode
|
|
63
|
-
>;
|
|
64
|
-
|
|
65
|
-
const convertStickyElement = (
|
|
66
|
-
domNode: HTMLElement,
|
|
67
|
-
): null | DOMConversionOutput => {
|
|
68
|
-
const sticky = domNode.getAttribute("data-lexical-sticky") === "true";
|
|
69
|
-
if (sticky) {
|
|
70
|
-
const node = $createStickyNode({
|
|
71
|
-
xOffset: +(domNode.getAttribute("data-x") ?? "8"),
|
|
72
|
-
yOffset: +(domNode.getAttribute("data-y") ?? "8"),
|
|
73
|
-
user: domNode.getAttribute("data-user") ?? "",
|
|
74
|
-
color: domNode.getAttribute("data-color") as AnyObject,
|
|
75
|
-
state: domNode.getAttribute("data-state") ?? "",
|
|
76
|
-
});
|
|
77
|
-
return { node };
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return null;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const colors: AnyObject = {
|
|
84
|
-
yellow: "green",
|
|
85
|
-
green: "blue",
|
|
86
|
-
blue: "pink",
|
|
87
|
-
pink: "yellow",
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export class StickyNode extends DecoratorNode<JSX.Element> {
|
|
91
|
-
__x: number;
|
|
92
|
-
__y: number;
|
|
93
|
-
__user: string;
|
|
94
|
-
__state?: AnyObject;
|
|
95
|
-
__color: StickyNoteColor;
|
|
96
|
-
|
|
97
|
-
static getType(): string {
|
|
98
|
-
return "sticky";
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
static clone(node: StickyNode): StickyNode {
|
|
102
|
-
return new StickyNode(
|
|
103
|
-
node.__x,
|
|
104
|
-
node.__y,
|
|
105
|
-
node.__user,
|
|
106
|
-
node.__color,
|
|
107
|
-
node.__state,
|
|
108
|
-
node.__key,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
static importJSON(serializedNode: SerializedStickyNode): StickyNode {
|
|
113
|
-
const stickyNode = new StickyNode(
|
|
114
|
-
serializedNode.xOffset,
|
|
115
|
-
serializedNode.yOffset,
|
|
116
|
-
serializedNode.user,
|
|
117
|
-
serializedNode.color,
|
|
118
|
-
serializedNode.state,
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
return stickyNode;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
static importDOM(): DOMConversionMap | null {
|
|
125
|
-
return {
|
|
126
|
-
div: (domNode: HTMLElement) => {
|
|
127
|
-
if (!domNode.hasAttribute("data-lexical-sticky")) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
conversion: convertStickyElement,
|
|
132
|
-
priority: 2,
|
|
133
|
-
};
|
|
134
|
-
},
|
|
135
|
-
span: (domNode: HTMLElement) => {
|
|
136
|
-
if (!domNode.hasAttribute("data-lexical-sticky")) {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
conversion: convertStickyElement,
|
|
141
|
-
priority: 1,
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
constructor(
|
|
148
|
-
x: number,
|
|
149
|
-
y: number,
|
|
150
|
-
user = "",
|
|
151
|
-
color: StickyNoteColor = "yellow",
|
|
152
|
-
state?: KeyValue,
|
|
153
|
-
key?: NodeKey,
|
|
154
|
-
) {
|
|
155
|
-
super(key);
|
|
156
|
-
this.__x = x;
|
|
157
|
-
this.__y = y;
|
|
158
|
-
this.__user = user;
|
|
159
|
-
this.__state = state;
|
|
160
|
-
this.__color = color;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
exportJSON(): SerializedStickyNode {
|
|
164
|
-
return {
|
|
165
|
-
state: this.__state,
|
|
166
|
-
color: this.__color,
|
|
167
|
-
user: this.__user,
|
|
168
|
-
type: "sticky",
|
|
169
|
-
version: 1,
|
|
170
|
-
xOffset: this.__x,
|
|
171
|
-
yOffset: this.__y,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
createDOM(config: EditorConfig): HTMLElement {
|
|
176
|
-
const div = document.createElement("div");
|
|
177
|
-
div.style.display = "contents";
|
|
178
|
-
return div;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
updateDOM(): false {
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
exportDOM(): DOMExportOutput {
|
|
186
|
-
const writable = this.getWritable();
|
|
187
|
-
const element = document.createElement("div");
|
|
188
|
-
element.setAttribute("data-lexical-sticky", "true");
|
|
189
|
-
element.setAttribute("data-x", `${writable.__x}`);
|
|
190
|
-
element.setAttribute("data-y", `${writable.__y}`);
|
|
191
|
-
element.setAttribute("data-user", `${writable.__user}`);
|
|
192
|
-
element.setAttribute("data-color", `${writable.__color}`);
|
|
193
|
-
element.setAttribute("data-state", `${writable.__state}`);
|
|
194
|
-
return { element };
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
setPosition(x: number, y: number): void {
|
|
198
|
-
const writable = this.getWritable();
|
|
199
|
-
writable.__x = x;
|
|
200
|
-
writable.__y = y;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
toggleColor(): void {
|
|
204
|
-
const writable = this.getWritable();
|
|
205
|
-
writable.__color = colors[writable.__color ?? "yellow"];
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
updateState(text: KeyValue): void {
|
|
209
|
-
const writable = this.getWritable();
|
|
210
|
-
writable.__state = text;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element {
|
|
214
|
-
return createPortal(
|
|
215
|
-
<Suspense fallback={null}>
|
|
216
|
-
<StickyComponent
|
|
217
|
-
x={this.__x}
|
|
218
|
-
y={this.__y}
|
|
219
|
-
user={this.__user}
|
|
220
|
-
state={this.__state}
|
|
221
|
-
nodeKey={this.getKey()}
|
|
222
|
-
color={this.__color as AnyObject}
|
|
223
|
-
/>
|
|
224
|
-
</Suspense>,
|
|
225
|
-
document.querySelector(".lexical-container") ?? document.body,
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
isIsolated(): true {
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export function $isStickyNode(
|
|
235
|
-
node: LexicalNode | null | undefined,
|
|
236
|
-
): node is StickyNode {
|
|
237
|
-
return node instanceof StickyNode;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export function $createStickyNode({
|
|
241
|
-
xOffset = 650,
|
|
242
|
-
yOffset = 32,
|
|
243
|
-
user = "",
|
|
244
|
-
color = "yellow",
|
|
245
|
-
state,
|
|
246
|
-
}: StickyNodeType): StickyNode {
|
|
247
|
-
const node = new StickyNode(xOffset, yOffset, user, color, state);
|
|
248
|
-
return $applyNodeReplacement(node);
|
|
249
|
-
}
|
|
@@ -1,38 +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/plugins/StickyPlugin/index.ts
|
|
25
|
-
|
|
26
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
27
|
-
import { useEffect } from "react";
|
|
28
|
-
import { StickyNode } from "../nodes/StickyNode";
|
|
29
|
-
|
|
30
|
-
export const StickyPlugin = (): JSX.Element | null => {
|
|
31
|
-
const [editor] = useLexicalComposerContext();
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (!editor.hasNodes([StickyNode])) {
|
|
34
|
-
throw new Error("StickyPlugin: StickyNode not registered on editor");
|
|
35
|
-
}
|
|
36
|
-
}, [editor]);
|
|
37
|
-
return null;
|
|
38
|
-
};
|