@react-fabric/lexical 1.0.0-beta.5 → 1.0.0-beta.51

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 (73) hide show
  1. package/{src/editor/Lexical.module.css → css/_lexical.css} +4 -4
  2. package/css/styles.css +24 -0
  3. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
  4. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  5. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +9 -9
  6. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +142 -75
  7. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
  8. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +25 -21
  9. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +10 -3
  10. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
  11. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  12. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +147 -103
  13. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
  14. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +10 -10
  15. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +254 -178
  16. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
  17. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +19 -16
  18. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +53 -29
  19. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  20. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
  21. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +176 -194
  22. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +1 -1
  23. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +25 -18
  24. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +1925 -793
  25. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
  26. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +48 -40
  27. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +426 -144
  28. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +11 -1
  29. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +46 -32
  30. package/dist/cjs/node_modules/prismjs/prism.js +1 -1
  31. package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +4 -5
  32. package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +81 -76
  33. package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +4 -6
  34. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
  35. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  36. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
  37. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +139 -76
  38. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
  39. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
  40. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +11 -4
  41. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
  42. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  43. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +149 -105
  44. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
  45. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
  46. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +253 -180
  47. package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
  48. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +4 -4
  49. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -30
  50. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  51. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +3 -3
  52. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +171 -196
  53. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +1 -1
  54. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
  55. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +1920 -796
  56. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
  57. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
  58. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +413 -145
  59. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +7 -2
  60. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
  61. package/dist/esm/node_modules/prismjs/prism.js +1 -1
  62. package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +4 -5
  63. package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +82 -77
  64. package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +4 -6
  65. package/dist/types/hooks/useFormatWatcher.d.ts +2 -2
  66. package/dist/types/nodes/StickyNode.d.ts +0 -1
  67. package/package.json +13 -12
  68. package/src/components/StickyComponent.tsx +1 -1
  69. package/src/editor/LexicalEditor.tsx +28 -25
  70. package/src/hooks/useFormatWatcher.ts +28 -27
  71. package/src/plugins/ToolbarPlugin.tsx +22 -6
  72. package/dist/cjs/editor/Lexical.module.css +0 -1
  73. package/dist/esm/editor/Lexical.module.css +0 -1
@@ -53,6 +53,7 @@ import {
53
53
  $getNearestNodeOfType,
54
54
  mergeRegister,
55
55
  } from "@lexical/utils";
56
+ import { isNil } from "@react-fabric/utilities";
56
57
  import {
57
58
  $createParagraphNode,
58
59
  $getSelection,
@@ -62,7 +63,6 @@ import {
62
63
  CAN_REDO_COMMAND,
63
64
  CAN_UNDO_COMMAND,
64
65
  COMMAND_PRIORITY_CRITICAL,
65
- FOCUS_COMMAND,
66
66
  INDENT_CONTENT_COMMAND,
67
67
  OUTDENT_CONTENT_COMMAND,
68
68
  SELECTION_CHANGE_COMMAND,
@@ -114,6 +114,7 @@ export const useFormatWatcher = () => {
114
114
  const [, startTransition] = useTransition();
115
115
  const [editor] = useLexicalComposerContext();
116
116
  const [activeEditor, setActiveEditor] = useState(editor);
117
+ const [currentSelection, setCurrentSelection] = useState<AnyObject>();
117
118
  const [blockType, setBlockType] =
118
119
  useState<keyof typeof blockTypeToBlockName>("paragraph");
119
120
  const [rootType, setRootType] =
@@ -218,41 +219,46 @@ export const useFormatWatcher = () => {
218
219
  ) + "",
219
220
  );
220
221
  setFontColor(
221
- $getSelectionStyleValueForProperty(selection, "color", "#000"),
222
+ $getSelectionStyleValueForProperty(
223
+ selection,
224
+ "color",
225
+ // @ts-expect-error ignore
226
+ // eslint-disable-next-line no-new-wrappers
227
+ new String("#000"),
228
+ ),
222
229
  );
223
230
  setBgColor(
224
231
  $getSelectionStyleValueForProperty(
225
232
  selection,
226
233
  "background-color",
227
- "#fff",
234
+ // @ts-expect-error ignore
235
+ // eslint-disable-next-line no-new-wrappers
236
+ new String("#fff"),
228
237
  ),
229
238
  );
230
239
  setFontFamily(
231
240
  $getSelectionStyleValueForProperty(selection, "font-family", "inherit"),
232
241
  );
233
242
  }
234
- }, [activeEditor]);
243
+ }, []);
235
244
 
236
245
  useEffect(() => {
237
246
  return editor.registerCommand(
238
- FOCUS_COMMAND,
247
+ SELECTION_CHANGE_COMMAND,
239
248
  (_payload, newEditor) => {
240
249
  setActiveEditor(newEditor);
250
+ setCurrentSelection($getSelection());
251
+ $updateToolbar();
241
252
  return false;
242
253
  },
243
254
  COMMAND_PRIORITY_CRITICAL,
244
255
  );
245
- }, [editor]);
256
+ }, [editor, $updateToolbar]);
246
257
 
247
258
  useEffect(() => {
248
- return activeEditor.registerCommand(
249
- SELECTION_CHANGE_COMMAND,
250
- (_payload, newEditor) => {
251
- $updateToolbar();
252
- return false;
253
- },
254
- COMMAND_PRIORITY_CRITICAL,
255
- );
259
+ activeEditor.getEditorState().read(() => {
260
+ $updateToolbar();
261
+ });
256
262
  }, [activeEditor, $updateToolbar]);
257
263
 
258
264
  useEffect(() => {
@@ -286,16 +292,13 @@ export const useFormatWatcher = () => {
286
292
 
287
293
  const applyStyleText = useCallback(
288
294
  (styles: Record<string, string>) => {
289
- setTimeout(() => {
290
- editor.update(() => {
291
- const selection = $getSelection();
292
- if ($isRangeSelection(selection)) {
293
- $patchStyleText(selection, styles);
294
- }
295
- });
296
- }, 100);
295
+ activeEditor.update(() => {
296
+ if (!isNil(currentSelection)) {
297
+ $patchStyleText(currentSelection, styles);
298
+ }
299
+ });
297
300
  },
298
- [editor],
301
+ [activeEditor, currentSelection],
299
302
  );
300
303
 
301
304
  const formatBulletList = () => {
@@ -439,16 +442,14 @@ export const useFormatWatcher = () => {
439
442
  );
440
443
 
441
444
  const onFontColorSelect = useCallback(
442
- (value: string) => {
443
- startTransition(() => setFontColor(value));
445
+ (value: string = "#000000") => {
444
446
  applyStyleText({ color: value });
445
447
  },
446
448
  [applyStyleText],
447
449
  );
448
450
 
449
451
  const onBgColorSelect = useCallback(
450
- (value: string) => {
451
- startTransition(() => setBgColor(value));
452
+ (value: string = "#ffffff") => {
452
453
  applyStyleText({ "background-color": value });
453
454
  },
454
455
  [applyStyleText],
@@ -1,8 +1,24 @@
1
1
  /*
2
- * Marble NEXT
3
- * @version : 4.0.0
4
- * @copyright : 2023
5
- * @license : Presight.ai
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 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.
6
22
  */
7
23
 
8
24
  import {
@@ -252,13 +268,13 @@ export const ToolbarPlugin = () => {
252
268
  <ColorInput
253
269
  {...{ noOutline: true }}
254
270
  value={watch.fontColor}
255
- onChange={(v = "#000") => watch.onFontColorSelect(v)}
271
+ onChange={(v) => watch.onFontColorSelect(v ?? undefined)}
256
272
  decorateStart={<Icon icon={CoreIcons.formatText} />}
257
273
  />
258
274
  <ColorInput
259
275
  {...{ noOutline: true }}
260
276
  value={watch.bgColor}
261
- onChange={(v = "#fff") => watch.onBgColorSelect(v)}
277
+ onChange={(v) => watch.onBgColorSelect(v ?? undefined)}
262
278
  decorateStart={<Icon icon={CoreIcons.formatFill} />}
263
279
  />
264
280
  <ButtonWrapper
@@ -1 +0,0 @@
1
- @layer util{.lexicalEditor,.lexicalToolbar{margin:0 auto;width:21cm}.lexicalEditor :global{.editor-container.editor-container.editor-container{background-color:#fff;color:#0f172a;font-family:Sakkal Majalla;font-size:18px}.editor-heading-h1{font-size:1.5em;margin-bottom:1.5em;text-transform:capitalize}.editor-heading-h1,.editor-heading-h2{font-weight:600;line-height:1.5;margin-top:1.5em;padding:0 4px}.editor-heading-h2{font-size:1.25em;margin-bottom:1em}.editor-heading-h6{color:#b45309;font-size:.875em;font-weight:600;line-height:1.25;margin-bottom:1.5em;margin-top:1.5em}.editor-paragraph{font-size:1em}.editor-paragraph,.editor-quote{line-height:1.5;margin-bottom:1.5em;margin-top:1.5em}.editor-quote{border-color:#64748b;padding-inline-start:1em}.editor-code,.editor-quote{border-inline-start-width:4px;color:#1e293b;display:block;font-size:1.125em}.editor-code{background-color:#e2e8f0;line-height:1.5;margin-bottom:1.5em;margin-top:1.5em;padding:1em}.editor-textUnderline{text-decoration:underline}.editor-textStrikethrough{text-decoration:line-through}.editor-textUnderlineStrikethrough{text-decoration:underline line-through}.editor-page-break{page-break-after:always}.editor-no-break{page-break-inside:avoid}.editor-textSmall{font-size:.875em}.editor-textBold{font-weight:600}.editor-textItalic{font-style:italic}.editor-textMuted{color:#4b5563}.editor-list-ul{list-style:disc;padding-inline-start:.5em}.editor-list-ol{list-style:decimal;padding-inline-start:.5em}.editor-listItem{margin-inline-start:1em;text-align:start}@media print{body,html{margin:0;min-height:100vh}div,h1,h2,h3,h4,h5,h6,p,span{box-sizing:border-box}body.report-template{background-size:0;min-height:100vh}body:after{background-image:inherit;content:"";height:100vh;inset:0;margin:0 auto;max-width:21cm;position:fixed;-webkit-print-color-adjust:exact;print-color-adjust:exact;width:100vw;z-index:10}.editor-page-break>div,.sticky__container{display:none}.editor-container{position:relative}.editor-editor{box-sizing:border-box;padding:0 2cm}}}}
@@ -1 +0,0 @@
1
- @layer util{.lexicalEditor,.lexicalToolbar{margin:0 auto;width:21cm}.lexicalEditor :global{.editor-container.editor-container.editor-container{background-color:#fff;color:#0f172a;font-family:Sakkal Majalla;font-size:18px}.editor-heading-h1{font-size:1.5em;margin-bottom:1.5em;text-transform:capitalize}.editor-heading-h1,.editor-heading-h2{font-weight:600;line-height:1.5;margin-top:1.5em;padding:0 4px}.editor-heading-h2{font-size:1.25em;margin-bottom:1em}.editor-heading-h6{color:#b45309;font-size:.875em;font-weight:600;line-height:1.25;margin-bottom:1.5em;margin-top:1.5em}.editor-paragraph{font-size:1em}.editor-paragraph,.editor-quote{line-height:1.5;margin-bottom:1.5em;margin-top:1.5em}.editor-quote{border-color:#64748b;padding-inline-start:1em}.editor-code,.editor-quote{border-inline-start-width:4px;color:#1e293b;display:block;font-size:1.125em}.editor-code{background-color:#e2e8f0;line-height:1.5;margin-bottom:1.5em;margin-top:1.5em;padding:1em}.editor-textUnderline{text-decoration:underline}.editor-textStrikethrough{text-decoration:line-through}.editor-textUnderlineStrikethrough{text-decoration:underline line-through}.editor-page-break{page-break-after:always}.editor-no-break{page-break-inside:avoid}.editor-textSmall{font-size:.875em}.editor-textBold{font-weight:600}.editor-textItalic{font-style:italic}.editor-textMuted{color:#4b5563}.editor-list-ul{list-style:disc;padding-inline-start:.5em}.editor-list-ol{list-style:decimal;padding-inline-start:.5em}.editor-listItem{margin-inline-start:1em;text-align:start}@media print{body,html{margin:0;min-height:100vh}div,h1,h2,h3,h4,h5,h6,p,span{box-sizing:border-box}body.report-template{background-size:0;min-height:100vh}body:after{background-image:inherit;content:"";height:100vh;inset:0;margin:0 auto;max-width:21cm;position:fixed;-webkit-print-color-adjust:exact;print-color-adjust:exact;width:100vw;z-index:10}.editor-page-break>div,.sticky__container{display:none}.editor-container{position:relative}.editor-editor{box-sizing:border-box;padding:0 2cm}}}}