@react-fabric/lexical 1.0.0-beta.23 → 1.0.0-beta.25

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.
@@ -11,6 +11,7 @@ var LexicalRichText = require('../../../../node_modules/@lexical/rich-text/Lexic
11
11
  var LexicalSelection = require('../../../../node_modules/@lexical/selection/LexicalSelection.js');
12
12
  var LexicalTable = require('../../../../node_modules/@lexical/table/LexicalTable.js');
13
13
  var LexicalUtils = require('../../../../node_modules/@lexical/utils/LexicalUtils.js');
14
+ var utilities = require('@react-fabric/utilities');
14
15
  var lexical = require('lexical');
15
16
  var react = require('react');
16
17
 
@@ -54,88 +55,92 @@ var useFormatWatcher = function useFormatWatcher() {
54
55
  _useState2 = _slicedToArray(_useState, 2),
55
56
  activeEditor = _useState2[0],
56
57
  setActiveEditor = _useState2[1];
57
- var _useState3 = react.useState("paragraph"),
58
+ var _useState3 = react.useState(),
58
59
  _useState4 = _slicedToArray(_useState3, 2),
59
- blockType = _useState4[0],
60
- setBlockType = _useState4[1];
61
- var _useState5 = react.useState("root"),
60
+ currentSelection = _useState4[0],
61
+ setCurrentSelection = _useState4[1];
62
+ var _useState5 = react.useState("paragraph"),
62
63
  _useState6 = _slicedToArray(_useState5, 2),
63
- rootType = _useState6[0],
64
- setRootType = _useState6[1];
65
- var _useState7 = react.useState(null),
64
+ blockType = _useState6[0],
65
+ setBlockType = _useState6[1];
66
+ var _useState7 = react.useState("root"),
66
67
  _useState8 = _slicedToArray(_useState7, 2),
67
- selectedElementKey = _useState8[0],
68
- setSelectedElementKey = _useState8[1];
69
- var _useState9 = react.useState("16"),
68
+ rootType = _useState8[0],
69
+ setRootType = _useState8[1];
70
+ var _useState9 = react.useState(null),
70
71
  _useState10 = _slicedToArray(_useState9, 2),
71
- fontSize = _useState10[0],
72
- setFontSize = _useState10[1];
73
- var _useState11 = react.useState("#000"),
72
+ selectedElementKey = _useState10[0],
73
+ setSelectedElementKey = _useState10[1];
74
+ var _useState11 = react.useState("16"),
74
75
  _useState12 = _slicedToArray(_useState11, 2),
75
- fontColor = _useState12[0],
76
- setFontColor = _useState12[1];
77
- var _useState13 = react.useState("#fff"),
76
+ fontSize = _useState12[0],
77
+ setFontSize = _useState12[1];
78
+ var _useState13 = react.useState("#000"),
78
79
  _useState14 = _slicedToArray(_useState13, 2),
79
- bgColor = _useState14[0],
80
- setBgColor = _useState14[1];
81
- var _useState15 = react.useState("Arial"),
80
+ fontColor = _useState14[0],
81
+ setFontColor = _useState14[1];
82
+ var _useState15 = react.useState("#fff"),
82
83
  _useState16 = _slicedToArray(_useState15, 2),
83
- fontFamily = _useState16[0],
84
- setFontFamily = _useState16[1];
85
- var _useState17 = react.useState(false),
84
+ bgColor = _useState16[0],
85
+ setBgColor = _useState16[1];
86
+ var _useState17 = react.useState("Arial"),
86
87
  _useState18 = _slicedToArray(_useState17, 2),
87
- isLink = _useState18[0],
88
- setIsLink = _useState18[1];
88
+ fontFamily = _useState18[0],
89
+ setFontFamily = _useState18[1];
89
90
  var _useState19 = react.useState(false),
90
91
  _useState20 = _slicedToArray(_useState19, 2),
91
- isBold = _useState20[0],
92
- setIsBold = _useState20[1];
92
+ isLink = _useState20[0],
93
+ setIsLink = _useState20[1];
93
94
  var _useState21 = react.useState(false),
94
95
  _useState22 = _slicedToArray(_useState21, 2),
95
- isItalic = _useState22[0],
96
- setIsItalic = _useState22[1];
96
+ isBold = _useState22[0],
97
+ setIsBold = _useState22[1];
97
98
  var _useState23 = react.useState(false),
98
99
  _useState24 = _slicedToArray(_useState23, 2),
99
- isUnderline = _useState24[0],
100
- setIsUnderline = _useState24[1];
100
+ isItalic = _useState24[0],
101
+ setIsItalic = _useState24[1];
101
102
  var _useState25 = react.useState(false),
102
103
  _useState26 = _slicedToArray(_useState25, 2),
103
- isStrikethrough = _useState26[0],
104
- setIsStrikethrough = _useState26[1];
104
+ isUnderline = _useState26[0],
105
+ setIsUnderline = _useState26[1];
105
106
  var _useState27 = react.useState(false),
106
107
  _useState28 = _slicedToArray(_useState27, 2),
107
- isSubscript = _useState28[0],
108
- setIsSubscript = _useState28[1];
108
+ isStrikethrough = _useState28[0],
109
+ setIsStrikethrough = _useState28[1];
109
110
  var _useState29 = react.useState(false),
110
111
  _useState30 = _slicedToArray(_useState29, 2),
111
- isSuperscript = _useState30[0],
112
- setIsSuperscript = _useState30[1];
112
+ isSubscript = _useState30[0],
113
+ setIsSubscript = _useState30[1];
113
114
  var _useState31 = react.useState(false),
114
115
  _useState32 = _slicedToArray(_useState31, 2),
115
- isCode = _useState32[0],
116
- setIsCode = _useState32[1];
116
+ isSuperscript = _useState32[0],
117
+ setIsSuperscript = _useState32[1];
117
118
  var _useState33 = react.useState(false),
118
119
  _useState34 = _slicedToArray(_useState33, 2),
119
- canUndo = _useState34[0],
120
- setCanUndo = _useState34[1];
120
+ isCode = _useState34[0],
121
+ setIsCode = _useState34[1];
121
122
  var _useState35 = react.useState(false),
122
123
  _useState36 = _slicedToArray(_useState35, 2),
123
- canRedo = _useState36[0],
124
- setCanRedo = _useState36[1];
124
+ canUndo = _useState36[0],
125
+ setCanUndo = _useState36[1];
125
126
  var _useState37 = react.useState(false),
126
127
  _useState38 = _slicedToArray(_useState37, 2),
127
- isRTL = _useState38[0],
128
- setIsRTL = _useState38[1];
129
- var _useState39 = react.useState(""),
128
+ canRedo = _useState38[0],
129
+ setCanRedo = _useState38[1];
130
+ var _useState39 = react.useState(false),
130
131
  _useState40 = _slicedToArray(_useState39, 2),
131
- codeLanguage = _useState40[0],
132
- setCodeLanguage = _useState40[1];
133
- var _useState41 = react.useState(function () {
132
+ isRTL = _useState40[0],
133
+ setIsRTL = _useState40[1];
134
+ var _useState41 = react.useState(""),
135
+ _useState42 = _slicedToArray(_useState41, 2),
136
+ codeLanguage = _useState42[0],
137
+ setCodeLanguage = _useState42[1];
138
+ var _useState43 = react.useState(function () {
134
139
  return editor.isEditable();
135
140
  }),
136
- _useState42 = _slicedToArray(_useState41, 2),
137
- isEditable = _useState42[0],
138
- setIsEditable = _useState42[1];
141
+ _useState44 = _slicedToArray(_useState43, 2),
142
+ isEditable = _useState44[0],
143
+ setIsEditable = _useState44[1];
139
144
  var $updateToolbar = react.useCallback(function () {
140
145
  var selection = lexical.$getSelection();
141
146
  if (lexical.$isRangeSelection(selection)) {
@@ -194,22 +199,29 @@ var useFormatWatcher = function useFormatWatcher() {
194
199
  }
195
200
  // Handle buttons
196
201
  setFontSize(parseInt(LexicalSelection.$getSelectionStyleValueForProperty(selection, "font-size", "16")) + "");
197
- setFontColor(LexicalSelection.$getSelectionStyleValueForProperty(selection, "color", "#000"));
198
- setBgColor(LexicalSelection.$getSelectionStyleValueForProperty(selection, "background-color", "#fff"));
202
+ setFontColor(LexicalSelection.$getSelectionStyleValueForProperty(selection, "color",
203
+ // @ts-expect-error ignore
204
+ // eslint-disable-next-line no-new-wrappers
205
+ new String("#000")));
206
+ setBgColor(LexicalSelection.$getSelectionStyleValueForProperty(selection, "background-color",
207
+ // @ts-expect-error ignore
208
+ // eslint-disable-next-line no-new-wrappers
209
+ new String("#fff")));
199
210
  setFontFamily(LexicalSelection.$getSelectionStyleValueForProperty(selection, "font-family", "inherit"));
200
211
  }
201
- }, [activeEditor]);
212
+ }, []);
202
213
  react.useEffect(function () {
203
- return editor.registerCommand(lexical.FOCUS_COMMAND, function (_payload, newEditor) {
214
+ return editor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
204
215
  setActiveEditor(newEditor);
216
+ setCurrentSelection(lexical.$getSelection());
217
+ $updateToolbar();
205
218
  return false;
206
219
  }, lexical.COMMAND_PRIORITY_CRITICAL);
207
- }, [editor]);
220
+ }, [editor, $updateToolbar]);
208
221
  react.useEffect(function () {
209
- return activeEditor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
222
+ activeEditor.getEditorState().read(function () {
210
223
  $updateToolbar();
211
- return false;
212
- }, lexical.COMMAND_PRIORITY_CRITICAL);
224
+ });
213
225
  }, [activeEditor, $updateToolbar]);
214
226
  react.useEffect(function () {
215
227
  return LexicalUtils.mergeRegister(editor.registerEditableListener(function (editable) {
@@ -228,15 +240,12 @@ var useFormatWatcher = function useFormatWatcher() {
228
240
  }, lexical.COMMAND_PRIORITY_CRITICAL));
229
241
  }, [$updateToolbar, activeEditor, editor]);
230
242
  var applyStyleText = react.useCallback(function (styles) {
231
- setTimeout(function () {
232
- editor.update(function () {
233
- var selection = lexical.$getSelection();
234
- if (lexical.$isRangeSelection(selection)) {
235
- LexicalSelection.$patchStyleText(selection, styles);
236
- }
237
- });
238
- }, 100);
239
- }, [editor]);
243
+ activeEditor.update(function () {
244
+ if (!utilities.isNil(currentSelection)) {
245
+ LexicalSelection.$patchStyleText(currentSelection, styles);
246
+ }
247
+ });
248
+ }, [activeEditor, currentSelection]);
240
249
  var formatBulletList = function formatBulletList() {
241
250
  setTimeout(function () {
242
251
  if (blockType !== "bullet") {
@@ -371,18 +380,14 @@ var useFormatWatcher = function useFormatWatcher() {
371
380
  "font-size": +value + "px"
372
381
  });
373
382
  }, [applyStyleText]);
374
- var onFontColorSelect = react.useCallback(function (value) {
375
- startTransition(function () {
376
- return setFontColor(value);
377
- });
383
+ var onFontColorSelect = react.useCallback(function () {
384
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#000000";
378
385
  applyStyleText({
379
386
  color: value
380
387
  });
381
388
  }, [applyStyleText]);
382
- var onBgColorSelect = react.useCallback(function (value) {
383
- startTransition(function () {
384
- return setBgColor(value);
385
- });
389
+ var onBgColorSelect = react.useCallback(function () {
390
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#ffffff";
386
391
  applyStyleText({
387
392
  "background-color": value
388
393
  });
@@ -220,20 +220,14 @@ var ToolbarPlugin = function ToolbarPlugin() {
220
220
  }), /*#__PURE__*/jsxRuntime.jsx(form.ColorInput, {
221
221
  noOutline: true,
222
222
  value: watch.fontColor,
223
- onChange: function onChange() {
224
- var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#000";
225
- return watch.onFontColorSelect(v);
226
- },
223
+ onChange: watch.onFontColorSelect,
227
224
  decorateStart: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
228
225
  icon: core.CoreIcons.formatText
229
226
  })
230
227
  }), /*#__PURE__*/jsxRuntime.jsx(form.ColorInput, {
231
228
  noOutline: true,
232
229
  value: watch.bgColor,
233
- onChange: function onChange() {
234
- var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#fff";
235
- return watch.onBgColorSelect(v);
236
- },
230
+ onChange: watch.onBgColorSelect,
237
231
  decorateStart: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
238
232
  icon: core.CoreIcons.formatFill
239
233
  })
@@ -11,7 +11,8 @@ import { $isHeadingNode, $createQuoteNode, $createHeadingNode, $isQuoteNode } fr
11
11
  import { $isParentElementRTL, $getSelectionStyleValueForProperty, $patchStyleText, $setBlocksType, $isAtNodeEnd } from '../../../../node_modules/@lexical/selection/LexicalSelection.js';
12
12
  import { $isTableNode } from '../../../../node_modules/@lexical/table/LexicalTable.js';
13
13
  import { $findMatchingParent, $getNearestNodeOfType, mergeRegister, $getNearestBlockElementAncestorOrThrow } from '../../../../node_modules/@lexical/utils/LexicalUtils.js';
14
- import { $getSelection, $isRangeSelection, $isRootOrShadowRoot, FOCUS_COMMAND, COMMAND_PRIORITY_CRITICAL, SELECTION_CHANGE_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND, $createParagraphNode, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, $isTextNode } from 'lexical';
14
+ import { isNil } from '@react-fabric/utilities';
15
+ import { $getSelection, $isRangeSelection, $isRootOrShadowRoot, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, CAN_UNDO_COMMAND, CAN_REDO_COMMAND, $createParagraphNode, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, $isTextNode } from 'lexical';
15
16
  import { useTransition, useState, useCallback, useEffect } from 'react';
16
17
 
17
18
  var blockTypeToBlockName = {
@@ -54,88 +55,92 @@ var useFormatWatcher = function useFormatWatcher() {
54
55
  _useState2 = _slicedToArray(_useState, 2),
55
56
  activeEditor = _useState2[0],
56
57
  setActiveEditor = _useState2[1];
57
- var _useState3 = useState("paragraph"),
58
+ var _useState3 = useState(),
58
59
  _useState4 = _slicedToArray(_useState3, 2),
59
- blockType = _useState4[0],
60
- setBlockType = _useState4[1];
61
- var _useState5 = useState("root"),
60
+ currentSelection = _useState4[0],
61
+ setCurrentSelection = _useState4[1];
62
+ var _useState5 = useState("paragraph"),
62
63
  _useState6 = _slicedToArray(_useState5, 2),
63
- rootType = _useState6[0],
64
- setRootType = _useState6[1];
65
- var _useState7 = useState(null),
64
+ blockType = _useState6[0],
65
+ setBlockType = _useState6[1];
66
+ var _useState7 = useState("root"),
66
67
  _useState8 = _slicedToArray(_useState7, 2),
67
- selectedElementKey = _useState8[0],
68
- setSelectedElementKey = _useState8[1];
69
- var _useState9 = useState("16"),
68
+ rootType = _useState8[0],
69
+ setRootType = _useState8[1];
70
+ var _useState9 = useState(null),
70
71
  _useState10 = _slicedToArray(_useState9, 2),
71
- fontSize = _useState10[0],
72
- setFontSize = _useState10[1];
73
- var _useState11 = useState("#000"),
72
+ selectedElementKey = _useState10[0],
73
+ setSelectedElementKey = _useState10[1];
74
+ var _useState11 = useState("16"),
74
75
  _useState12 = _slicedToArray(_useState11, 2),
75
- fontColor = _useState12[0],
76
- setFontColor = _useState12[1];
77
- var _useState13 = useState("#fff"),
76
+ fontSize = _useState12[0],
77
+ setFontSize = _useState12[1];
78
+ var _useState13 = useState("#000"),
78
79
  _useState14 = _slicedToArray(_useState13, 2),
79
- bgColor = _useState14[0],
80
- setBgColor = _useState14[1];
81
- var _useState15 = useState("Arial"),
80
+ fontColor = _useState14[0],
81
+ setFontColor = _useState14[1];
82
+ var _useState15 = useState("#fff"),
82
83
  _useState16 = _slicedToArray(_useState15, 2),
83
- fontFamily = _useState16[0],
84
- setFontFamily = _useState16[1];
85
- var _useState17 = useState(false),
84
+ bgColor = _useState16[0],
85
+ setBgColor = _useState16[1];
86
+ var _useState17 = useState("Arial"),
86
87
  _useState18 = _slicedToArray(_useState17, 2),
87
- isLink = _useState18[0],
88
- setIsLink = _useState18[1];
88
+ fontFamily = _useState18[0],
89
+ setFontFamily = _useState18[1];
89
90
  var _useState19 = useState(false),
90
91
  _useState20 = _slicedToArray(_useState19, 2),
91
- isBold = _useState20[0],
92
- setIsBold = _useState20[1];
92
+ isLink = _useState20[0],
93
+ setIsLink = _useState20[1];
93
94
  var _useState21 = useState(false),
94
95
  _useState22 = _slicedToArray(_useState21, 2),
95
- isItalic = _useState22[0],
96
- setIsItalic = _useState22[1];
96
+ isBold = _useState22[0],
97
+ setIsBold = _useState22[1];
97
98
  var _useState23 = useState(false),
98
99
  _useState24 = _slicedToArray(_useState23, 2),
99
- isUnderline = _useState24[0],
100
- setIsUnderline = _useState24[1];
100
+ isItalic = _useState24[0],
101
+ setIsItalic = _useState24[1];
101
102
  var _useState25 = useState(false),
102
103
  _useState26 = _slicedToArray(_useState25, 2),
103
- isStrikethrough = _useState26[0],
104
- setIsStrikethrough = _useState26[1];
104
+ isUnderline = _useState26[0],
105
+ setIsUnderline = _useState26[1];
105
106
  var _useState27 = useState(false),
106
107
  _useState28 = _slicedToArray(_useState27, 2),
107
- isSubscript = _useState28[0],
108
- setIsSubscript = _useState28[1];
108
+ isStrikethrough = _useState28[0],
109
+ setIsStrikethrough = _useState28[1];
109
110
  var _useState29 = useState(false),
110
111
  _useState30 = _slicedToArray(_useState29, 2),
111
- isSuperscript = _useState30[0],
112
- setIsSuperscript = _useState30[1];
112
+ isSubscript = _useState30[0],
113
+ setIsSubscript = _useState30[1];
113
114
  var _useState31 = useState(false),
114
115
  _useState32 = _slicedToArray(_useState31, 2),
115
- isCode = _useState32[0],
116
- setIsCode = _useState32[1];
116
+ isSuperscript = _useState32[0],
117
+ setIsSuperscript = _useState32[1];
117
118
  var _useState33 = useState(false),
118
119
  _useState34 = _slicedToArray(_useState33, 2),
119
- canUndo = _useState34[0],
120
- setCanUndo = _useState34[1];
120
+ isCode = _useState34[0],
121
+ setIsCode = _useState34[1];
121
122
  var _useState35 = useState(false),
122
123
  _useState36 = _slicedToArray(_useState35, 2),
123
- canRedo = _useState36[0],
124
- setCanRedo = _useState36[1];
124
+ canUndo = _useState36[0],
125
+ setCanUndo = _useState36[1];
125
126
  var _useState37 = useState(false),
126
127
  _useState38 = _slicedToArray(_useState37, 2),
127
- isRTL = _useState38[0],
128
- setIsRTL = _useState38[1];
129
- var _useState39 = useState(""),
128
+ canRedo = _useState38[0],
129
+ setCanRedo = _useState38[1];
130
+ var _useState39 = useState(false),
130
131
  _useState40 = _slicedToArray(_useState39, 2),
131
- codeLanguage = _useState40[0],
132
- setCodeLanguage = _useState40[1];
133
- var _useState41 = useState(function () {
132
+ isRTL = _useState40[0],
133
+ setIsRTL = _useState40[1];
134
+ var _useState41 = useState(""),
135
+ _useState42 = _slicedToArray(_useState41, 2),
136
+ codeLanguage = _useState42[0],
137
+ setCodeLanguage = _useState42[1];
138
+ var _useState43 = useState(function () {
134
139
  return editor.isEditable();
135
140
  }),
136
- _useState42 = _slicedToArray(_useState41, 2),
137
- isEditable = _useState42[0],
138
- setIsEditable = _useState42[1];
141
+ _useState44 = _slicedToArray(_useState43, 2),
142
+ isEditable = _useState44[0],
143
+ setIsEditable = _useState44[1];
139
144
  var $updateToolbar = useCallback(function () {
140
145
  var selection = $getSelection();
141
146
  if ($isRangeSelection(selection)) {
@@ -194,22 +199,29 @@ var useFormatWatcher = function useFormatWatcher() {
194
199
  }
195
200
  // Handle buttons
196
201
  setFontSize(parseInt($getSelectionStyleValueForProperty(selection, "font-size", "16")) + "");
197
- setFontColor($getSelectionStyleValueForProperty(selection, "color", "#000"));
198
- setBgColor($getSelectionStyleValueForProperty(selection, "background-color", "#fff"));
202
+ setFontColor($getSelectionStyleValueForProperty(selection, "color",
203
+ // @ts-expect-error ignore
204
+ // eslint-disable-next-line no-new-wrappers
205
+ new String("#000")));
206
+ setBgColor($getSelectionStyleValueForProperty(selection, "background-color",
207
+ // @ts-expect-error ignore
208
+ // eslint-disable-next-line no-new-wrappers
209
+ new String("#fff")));
199
210
  setFontFamily($getSelectionStyleValueForProperty(selection, "font-family", "inherit"));
200
211
  }
201
- }, [activeEditor]);
212
+ }, []);
202
213
  useEffect(function () {
203
- return editor.registerCommand(FOCUS_COMMAND, function (_payload, newEditor) {
214
+ return editor.registerCommand(SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
204
215
  setActiveEditor(newEditor);
216
+ setCurrentSelection($getSelection());
217
+ $updateToolbar();
205
218
  return false;
206
219
  }, COMMAND_PRIORITY_CRITICAL);
207
- }, [editor]);
220
+ }, [editor, $updateToolbar]);
208
221
  useEffect(function () {
209
- return activeEditor.registerCommand(SELECTION_CHANGE_COMMAND, function (_payload, newEditor) {
222
+ activeEditor.getEditorState().read(function () {
210
223
  $updateToolbar();
211
- return false;
212
- }, COMMAND_PRIORITY_CRITICAL);
224
+ });
213
225
  }, [activeEditor, $updateToolbar]);
214
226
  useEffect(function () {
215
227
  return mergeRegister(editor.registerEditableListener(function (editable) {
@@ -228,15 +240,12 @@ var useFormatWatcher = function useFormatWatcher() {
228
240
  }, COMMAND_PRIORITY_CRITICAL));
229
241
  }, [$updateToolbar, activeEditor, editor]);
230
242
  var applyStyleText = useCallback(function (styles) {
231
- setTimeout(function () {
232
- editor.update(function () {
233
- var selection = $getSelection();
234
- if ($isRangeSelection(selection)) {
235
- $patchStyleText(selection, styles);
236
- }
237
- });
238
- }, 100);
239
- }, [editor]);
243
+ activeEditor.update(function () {
244
+ if (!isNil(currentSelection)) {
245
+ $patchStyleText(currentSelection, styles);
246
+ }
247
+ });
248
+ }, [activeEditor, currentSelection]);
240
249
  var formatBulletList = function formatBulletList() {
241
250
  setTimeout(function () {
242
251
  if (blockType !== "bullet") {
@@ -371,18 +380,14 @@ var useFormatWatcher = function useFormatWatcher() {
371
380
  "font-size": +value + "px"
372
381
  });
373
382
  }, [applyStyleText]);
374
- var onFontColorSelect = useCallback(function (value) {
375
- startTransition(function () {
376
- return setFontColor(value);
377
- });
383
+ var onFontColorSelect = useCallback(function () {
384
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#000000";
378
385
  applyStyleText({
379
386
  color: value
380
387
  });
381
388
  }, [applyStyleText]);
382
- var onBgColorSelect = useCallback(function (value) {
383
- startTransition(function () {
384
- return setBgColor(value);
385
- });
389
+ var onBgColorSelect = useCallback(function () {
390
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#ffffff";
386
391
  applyStyleText({
387
392
  "background-color": value
388
393
  });
@@ -220,20 +220,14 @@ var ToolbarPlugin = function ToolbarPlugin() {
220
220
  }), /*#__PURE__*/jsx(ColorInput, {
221
221
  noOutline: true,
222
222
  value: watch.fontColor,
223
- onChange: function onChange() {
224
- var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#000";
225
- return watch.onFontColorSelect(v);
226
- },
223
+ onChange: watch.onFontColorSelect,
227
224
  decorateStart: /*#__PURE__*/jsx(Icon, {
228
225
  icon: CoreIcons.formatText
229
226
  })
230
227
  }), /*#__PURE__*/jsx(ColorInput, {
231
228
  noOutline: true,
232
229
  value: watch.bgColor,
233
- onChange: function onChange() {
234
- var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#fff";
235
- return watch.onBgColorSelect(v);
236
- },
230
+ onChange: watch.onBgColorSelect,
237
231
  decorateStart: /*#__PURE__*/jsx(Icon, {
238
232
  icon: CoreIcons.formatFill
239
233
  })
@@ -27,8 +27,8 @@ export declare const useFormatWatcher: () => {
27
27
  indent: () => void;
28
28
  outdent: () => void;
29
29
  clearFormatting: () => void;
30
- onFontColorSelect: (value: string) => void;
31
- onBgColorSelect: (value: string) => void;
30
+ onFontColorSelect: (value?: string) => void;
31
+ onBgColorSelect: (value?: string) => void;
32
32
  formatQuote: () => void;
33
33
  onSizeChange: (value: string) => void;
34
34
  formatBlock: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/lexical",
3
- "version": "1.0.0-beta.23",
3
+ "version": "1.0.0-beta.25",
4
4
  "description": "RUF: Lexical editor",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -35,9 +35,9 @@
35
35
  "dependencies": {
36
36
  "@lexical/headless": "^0.17.1",
37
37
  "@lexical/react": "^0.17.1",
38
- "@react-fabric/core": "^1.0.0-beta.23",
39
- "@react-fabric/form": "^1.0.0-beta.23",
40
- "@react-fabric/utilities": "^1.0.0-beta.23",
38
+ "@react-fabric/core": "^1.0.0-beta.25",
39
+ "@react-fabric/form": "^1.0.0-beta.25",
40
+ "@react-fabric/utilities": "^1.0.0-beta.25",
41
41
  "classnames": "^2.5.1",
42
42
  "lexical": "^0.17.1"
43
43
  },
@@ -51,5 +51,5 @@
51
51
  "node": ">=18.12.0",
52
52
  "npm": ">=8.19.0"
53
53
  },
54
- "gitHead": "96cac942a837ec03886660d398de74b8bcb2dbac"
54
+ "gitHead": "34640e2473c7823254e82aa7aed920c9c6f8f503"
55
55
  }
@@ -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],
@@ -252,13 +252,13 @@ export const ToolbarPlugin = () => {
252
252
  <ColorInput
253
253
  {...{ noOutline: true }}
254
254
  value={watch.fontColor}
255
- onChange={(v = "#000") => watch.onFontColorSelect(v)}
255
+ onChange={watch.onFontColorSelect}
256
256
  decorateStart={<Icon icon={CoreIcons.formatText} />}
257
257
  />
258
258
  <ColorInput
259
259
  {...{ noOutline: true }}
260
260
  value={watch.bgColor}
261
- onChange={(v = "#fff") => watch.onBgColorSelect(v)}
261
+ onChange={watch.onBgColorSelect}
262
262
  decorateStart={<Icon icon={CoreIcons.formatFill} />}
263
263
  />
264
264
  <ButtonWrapper