@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
@@ -38,27 +38,42 @@ import { TablePlugin } from "@lexical/react/LexicalTablePlugin";
38
38
  import { HeadingNode, QuoteNode } from "@lexical/rich-text";
39
39
  import { TableCellNode, TableNode, TableRowNode } from "@lexical/table";
40
40
  import { ErrorBoundary, Header, ThemeProvider } from "@react-fabric/core";
41
- import { debounce } from "@react-fabric/utilities";
41
+ import { type ReactElement } from "@react-fabric/core/dist/types/types";
42
+ import { debounce, EMPTY_ARRAY } from "@react-fabric/utilities";
42
43
  import classNames from "classnames";
43
- import { type LexicalEditor as LXE } from "lexical";
44
+ import {
45
+ type Klass,
46
+ type LexicalNode,
47
+ type LexicalNodeReplacement,
48
+ type LexicalEditor as LXE,
49
+ } from "lexical";
44
50
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
45
- import { StickyNode } from "../nodes/StickyNode";
51
+ import { CommentPlugin } from "../plugins/CommentPlugin";
46
52
  import { DraggableBlockPlugin } from "../plugins/DraggableBlockPlugin";
47
- import { StickyPlugin } from "../plugins/StickyPlugin";
48
53
  import { ToolbarPlugin } from "../plugins/ToolbarPlugin";
49
54
  import { LexicalTheme } from "./theme";
50
55
 
51
56
  export interface EditorProps {
52
57
  value?: string | AnyObject;
53
58
 
59
+ isRtl?: boolean;
60
+
54
61
  readOnly?: boolean;
55
62
  /**
56
63
  * publish mode removes all wrapping and renders plain lexical view for exporting to pdf using puppeteer
57
64
  */
58
65
  publishMode?: boolean;
59
66
 
60
- header?: string;
61
- footer?: string;
67
+ header?: ReactElement;
68
+ footer?: ReactElement;
69
+ coverPage?: ReactElement;
70
+
71
+ /**
72
+ * Username is used for comment plugin to identify the comment author. It can be used to conditionally render delete option for comments.
73
+ */
74
+ username?: string;
75
+
76
+ nodes?: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>;
62
77
 
63
78
  onChange?: (value: KeyValue) => void;
64
79
  onDirty?: (isDirty: boolean) => void;
@@ -73,7 +88,7 @@ export interface EditorProps {
73
88
  * It uses a custom theme and provides error handling for Lexical updates.
74
89
  *
75
90
  * @param {EditorProps} props - The properties for the LexicalEditor component.
76
- * @returns {JSX.Element} The rendered LexicalEditor component.
91
+ * @returns {React.ReactElement} The rendered LexicalEditor component.
77
92
  *
78
93
  * @example
79
94
  * ```jsx
@@ -93,6 +108,12 @@ export const LexicalEditor = ({
93
108
  value,
94
109
  readOnly,
95
110
  publishMode,
111
+ header,
112
+ footer,
113
+ coverPage,
114
+ isRtl,
115
+ username = "Guest",
116
+ nodes = EMPTY_ARRAY,
96
117
  onChange,
97
118
  onDirty,
98
119
  }: EditorProps) => {
@@ -178,7 +199,7 @@ export const LexicalEditor = ({
178
199
  TableCellNode,
179
200
  TableNode,
180
201
  TableRowNode,
181
- StickyNode,
202
+ ...nodes,
182
203
  ],
183
204
  onError,
184
205
  }) as InitialConfigType,
@@ -189,20 +210,25 @@ export const LexicalEditor = ({
189
210
  ({ children }: KeyValue) => {
190
211
  return !publishMode ? (
191
212
  <div className="lexical-scroller area-content overflow-auto">
192
- <div
193
- className={classNames("fabric-lexicalToolbar", "sticky top-0 z-1")}
194
- >
195
- <Header className="bg-base">
196
- <ToolbarPlugin />
197
- </Header>
198
- </div>
213
+ {!readOnly && (
214
+ <div
215
+ className={classNames(
216
+ "fabric-lexicalToolbar",
217
+ "sticky top-0 z-1",
218
+ )}
219
+ >
220
+ <Header className="bg-default">
221
+ <ToolbarPlugin />
222
+ </Header>
223
+ </div>
224
+ )}
199
225
  {children}
200
226
  </div>
201
227
  ) : (
202
228
  children
203
229
  );
204
230
  },
205
- [publishMode],
231
+ [publishMode, readOnly],
206
232
  );
207
233
 
208
234
  return (
@@ -216,15 +242,24 @@ export const LexicalEditor = ({
216
242
  "fabric-lexicalEditor",
217
243
  "lexical-container relative bg-white min-h-full mx-auto shadow-md print:shadow-none",
218
244
  )}
245
+ dir={isRtl ? "rtl" : "ltr"}
219
246
  onDragOver={(e) => e.stopPropagation()}
220
247
  onKeyDown={(e) => e.stopPropagation()}
221
248
  ref={setEditorContainer}
222
249
  >
250
+ {!publishMode && header && (
251
+ <div className="editor-header">{header}</div>
252
+ )}
253
+ {coverPage && (
254
+ <div className="editor-cover px-[2cm] py-[1cm]">
255
+ {coverPage}
256
+ </div>
257
+ )}
223
258
  <RichTextPlugin
224
259
  contentEditable={
225
260
  <ContentEditable
226
261
  readOnly={!!readOnly || publishMode}
227
- className="lexical-editor px-[2cm] py-[1cm] min-h-screen"
262
+ className="lexical-editor min-h-screen px-[2cm] py-[1cm]"
228
263
  />
229
264
  }
230
265
  placeholder={
@@ -238,11 +273,23 @@ export const LexicalEditor = ({
238
273
  <CheckListPlugin />
239
274
  <TablePlugin />
240
275
  <HistoryPlugin />
241
- <StickyPlugin />
242
276
  <AutoFocusPlugin defaultSelection="rootStart" />
243
277
  {/** Custom plugins **/}
244
278
  {editorContainer && (
245
- <DraggableBlockPlugin anchorElem={editorContainer} />
279
+ <DraggableBlockPlugin
280
+ anchorElem={editorContainer}
281
+ isEditable={!readOnly && !publishMode}
282
+ />
283
+ )}
284
+ {editorContainer && (
285
+ <CommentPlugin
286
+ username={username}
287
+ anchorElem={editorContainer}
288
+ isPublishMode={!!publishMode}
289
+ />
290
+ )}
291
+ {!publishMode && footer && (
292
+ <div className="editor-footer">{footer}</div>
246
293
  )}
247
294
  </div>
248
295
  </ThemeProvider>
@@ -227,7 +227,6 @@ export const useFormatWatcher = () => {
227
227
  selection,
228
228
  "color",
229
229
  // @ts-expect-error ignore
230
- // eslint-disable-next-line no-new-wrappers
231
230
  new String("#000"),
232
231
  ),
233
232
  );
@@ -236,7 +235,6 @@ export const useFormatWatcher = () => {
236
235
  selection,
237
236
  "background-color",
238
237
  // @ts-expect-error ignore
239
- // eslint-disable-next-line no-new-wrappers
240
238
  new String("#fff"),
241
239
  ),
242
240
  );
@@ -1,16 +1,18 @@
1
1
  {
2
+ "addComment": "أضف تعليقا",
3
+ "reply": "رد",
2
4
  "tool": {
3
5
  "alignCenter": "محاذاة المركز",
4
- "alignJustify": "محاذاة وضبط",
5
6
  "alignEnd": "محاذاة النهاية",
7
+ "alignJustify": "محاذاة وضبط",
6
8
  "alignStart": "محاذاة البداية",
7
9
  "bold": "عريض",
8
10
  "clear": "مسح التنسيق",
9
11
  "hilight": "تسليط الضوء",
10
12
  "indentIn": "المسافة البادئة في",
11
- "underline": "تسطير",
12
- "strikethrough": "يتوسطه خط",
13
+ "indentOut": "مسافة بادئة للخارج",
13
14
  "italic": "مائل",
14
- "indentOut": "مسافة بادئة للخارج"
15
+ "strikethrough": "يتوسطه خط",
16
+ "underline": "تسطير"
15
17
  }
16
18
  }
@@ -12,5 +12,7 @@
12
12
  "indentIn": "Indent In",
13
13
  "hilight": "Highlight",
14
14
  "clear": "Clear Formatting"
15
- }
15
+ },
16
+ "addComment": "Add comment",
17
+ "reply": "Reply"
16
18
  }
package/src/i18n/index.ts CHANGED
@@ -22,7 +22,7 @@
22
22
  */
23
23
 
24
24
  import { addTranslationBundle } from "@react-fabric/core";
25
- import ar from "./ar.json";
26
- import en from "./en.json";
25
+ import ar from "./ar/lexical.json";
26
+ import en from "./en/lexical.json";
27
27
 
28
28
  addTranslationBundle("lexical", { en, ar });