@tarviks/lexical-rich-editor 1.0.6 → 1.0.7
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/dist/index.js +244 -240
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mergeRegister, $wrapNodeInElement, $insertNodeToNearestRoot, $getNearestNodeOfType, $findMatchingParent as $findMatchingParent$1, calculateZoomLevel } from '@lexical/utils';
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
2
|
+
import * as React9 from 'react';
|
|
3
|
+
import React9__default, { forwardRef, useState, useCallback, useRef, useEffect, useMemo, useImperativeHandle, Suspense } from 'react';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
6
6
|
import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
|
|
@@ -647,7 +647,7 @@ function parseDimFromStyleOrAttr(img3) {
|
|
|
647
647
|
var ImageComponent2, isGoogleDocCheckboxImg, $convertImageElement, ImageNode, $createImageNode, $isImageNode;
|
|
648
648
|
var init_ImageNode = __esm({
|
|
649
649
|
"src/Nodes/ImageNode.tsx"() {
|
|
650
|
-
ImageComponent2 =
|
|
650
|
+
ImageComponent2 = React9.lazy(() => Promise.resolve().then(() => (init_ImageComponent(), ImageComponent_exports)));
|
|
651
651
|
isGoogleDocCheckboxImg = (img3) => {
|
|
652
652
|
return img3.parentElement != null && img3.parentElement.tagName === "LI" && img3.previousSibling === null && img3.getAttribute("aria-roledescription") === "checkbox";
|
|
653
653
|
};
|
|
@@ -1048,7 +1048,7 @@ var init_InlineImageComponent = __esm({
|
|
|
1048
1048
|
var InlineImageComponent2, $convertInlineImageElement, InlineImageNode, $createInlineImageNode, $isInlineImageNode;
|
|
1049
1049
|
var init_InlineImageNode = __esm({
|
|
1050
1050
|
"src/Nodes/InlineImageNode.tsx"() {
|
|
1051
|
-
InlineImageComponent2 =
|
|
1051
|
+
InlineImageComponent2 = React9.lazy(() => Promise.resolve().then(() => (init_InlineImageComponent(), InlineImageComponent_exports)));
|
|
1052
1052
|
$convertInlineImageElement = (domNode) => {
|
|
1053
1053
|
if (isHTMLElement(domNode) && domNode.nodeName === "IMG") {
|
|
1054
1054
|
const { alt: altText, src, width, height } = domNode;
|
|
@@ -1529,7 +1529,7 @@ function VideoResizer({
|
|
|
1529
1529
|
onResizeStart,
|
|
1530
1530
|
onResizeEnd
|
|
1531
1531
|
}) {
|
|
1532
|
-
const resizeState =
|
|
1532
|
+
const resizeState = React9.useRef(null);
|
|
1533
1533
|
const startResize = (e, dir) => {
|
|
1534
1534
|
e.preventDefault();
|
|
1535
1535
|
e.stopPropagation();
|
|
@@ -1622,9 +1622,9 @@ function YouTubeComponent({
|
|
|
1622
1622
|
height,
|
|
1623
1623
|
editor
|
|
1624
1624
|
}) {
|
|
1625
|
-
const containerRef =
|
|
1626
|
-
const [isHovered, setIsHovered] =
|
|
1627
|
-
const [isResizing, setIsResizing] =
|
|
1625
|
+
const containerRef = React9.useRef(null);
|
|
1626
|
+
const [isHovered, setIsHovered] = React9.useState(false);
|
|
1627
|
+
const [isResizing, setIsResizing] = React9.useState(false);
|
|
1628
1628
|
const handleDelete = (e) => {
|
|
1629
1629
|
e.preventDefault();
|
|
1630
1630
|
e.stopPropagation();
|
|
@@ -1884,13 +1884,13 @@ function AutocompletePlugin({
|
|
|
1884
1884
|
prefixWindow = 300
|
|
1885
1885
|
}) {
|
|
1886
1886
|
const [editor] = useLexicalComposerContext();
|
|
1887
|
-
const ghostKeyRef =
|
|
1888
|
-
const idleTimerRef =
|
|
1889
|
-
const inflightRef =
|
|
1890
|
-
const reqCounterRef =
|
|
1891
|
-
const lastTriggerRef =
|
|
1892
|
-
const lastShownCtxRef =
|
|
1893
|
-
const clearGhost =
|
|
1887
|
+
const ghostKeyRef = React9.useRef(null);
|
|
1888
|
+
const idleTimerRef = React9.useRef(null);
|
|
1889
|
+
const inflightRef = React9.useRef(null);
|
|
1890
|
+
const reqCounterRef = React9.useRef(0);
|
|
1891
|
+
const lastTriggerRef = React9.useRef("");
|
|
1892
|
+
const lastShownCtxRef = React9.useRef("");
|
|
1893
|
+
const clearGhost = React9.useCallback(() => {
|
|
1894
1894
|
editor.update(
|
|
1895
1895
|
() => {
|
|
1896
1896
|
const key = ghostKeyRef.current;
|
|
@@ -1902,7 +1902,7 @@ function AutocompletePlugin({
|
|
|
1902
1902
|
{ tag: "autocomplete-ghost" }
|
|
1903
1903
|
);
|
|
1904
1904
|
}, [editor]);
|
|
1905
|
-
const upsertGhost =
|
|
1905
|
+
const upsertGhost = React9.useCallback(
|
|
1906
1906
|
(text, insertAtCharOffset) => {
|
|
1907
1907
|
editor.update(
|
|
1908
1908
|
() => {
|
|
@@ -1966,12 +1966,12 @@ function AutocompletePlugin({
|
|
|
1966
1966
|
},
|
|
1967
1967
|
[editor]
|
|
1968
1968
|
);
|
|
1969
|
-
const cancelInflight =
|
|
1969
|
+
const cancelInflight = React9.useCallback(() => {
|
|
1970
1970
|
if (!inflightRef.current) return;
|
|
1971
1971
|
inflightRef.current.dismiss();
|
|
1972
1972
|
inflightRef.current = null;
|
|
1973
1973
|
}, []);
|
|
1974
|
-
const resetIdleTimer =
|
|
1974
|
+
const resetIdleTimer = React9.useCallback(
|
|
1975
1975
|
(callback) => {
|
|
1976
1976
|
if (idleTimerRef.current) {
|
|
1977
1977
|
clearTimeout(idleTimerRef.current);
|
|
@@ -1986,7 +1986,7 @@ function AutocompletePlugin({
|
|
|
1986
1986
|
},
|
|
1987
1987
|
[idleMs, cancelInflight, clearGhost]
|
|
1988
1988
|
);
|
|
1989
|
-
const fireQuery =
|
|
1989
|
+
const fireQuery = React9.useCallback(() => {
|
|
1990
1990
|
if (!useQuery || isReadOnly) return;
|
|
1991
1991
|
let context = "";
|
|
1992
1992
|
let prefix = "";
|
|
@@ -2058,7 +2058,7 @@ function AutocompletePlugin({
|
|
|
2058
2058
|
upsertGhost,
|
|
2059
2059
|
onSuggestionShown
|
|
2060
2060
|
]);
|
|
2061
|
-
|
|
2061
|
+
React9.useEffect(() => {
|
|
2062
2062
|
if (!useQuery || isReadOnly) return;
|
|
2063
2063
|
return editor.registerUpdateListener(({ tags }) => {
|
|
2064
2064
|
if (tags.has("history-merge") || tags.has("collaboration")) return;
|
|
@@ -2067,7 +2067,7 @@ function AutocompletePlugin({
|
|
|
2067
2067
|
resetIdleTimer(fireQuery);
|
|
2068
2068
|
});
|
|
2069
2069
|
}, [editor, useQuery, isReadOnly, resetIdleTimer, fireQuery]);
|
|
2070
|
-
|
|
2070
|
+
React9.useEffect(() => {
|
|
2071
2071
|
if (!useQuery || isReadOnly) return;
|
|
2072
2072
|
return editor.registerCommand(
|
|
2073
2073
|
SELECTION_CHANGE_COMMAND,
|
|
@@ -2091,7 +2091,7 @@ function AutocompletePlugin({
|
|
|
2091
2091
|
COMMAND_PRIORITY_LOW
|
|
2092
2092
|
);
|
|
2093
2093
|
}, [editor, useQuery, isReadOnly, resetIdleTimer, fireQuery]);
|
|
2094
|
-
|
|
2094
|
+
React9.useEffect(() => {
|
|
2095
2095
|
return editor.registerCommand(
|
|
2096
2096
|
KEY_DOWN_COMMAND,
|
|
2097
2097
|
(e) => {
|
|
@@ -2132,7 +2132,7 @@ function AutocompletePlugin({
|
|
|
2132
2132
|
COMMAND_PRIORITY_HIGH
|
|
2133
2133
|
);
|
|
2134
2134
|
}, [editor, clearGhost, onSuggestionAccept, prefixWindow]);
|
|
2135
|
-
|
|
2135
|
+
React9.useEffect(() => {
|
|
2136
2136
|
return () => {
|
|
2137
2137
|
cancelInflight();
|
|
2138
2138
|
if (idleTimerRef.current) clearTimeout(idleTimerRef.current);
|
|
@@ -4010,28 +4010,28 @@ function SpellPopover({
|
|
|
4010
4010
|
onImprove,
|
|
4011
4011
|
onAcceptGrammar
|
|
4012
4012
|
}) {
|
|
4013
|
-
const ref =
|
|
4013
|
+
const ref = React9.useRef(null);
|
|
4014
4014
|
const type = state.issue.type ?? "spelling";
|
|
4015
|
-
const [pos, setPos] =
|
|
4016
|
-
|
|
4015
|
+
const [pos, setPos] = React9.useState({ left: state.x, top: state.y });
|
|
4016
|
+
React9.useEffect(() => {
|
|
4017
4017
|
if (!ref.current) return;
|
|
4018
4018
|
const { offsetHeight: h, offsetWidth: w } = ref.current;
|
|
4019
4019
|
const top = state.y + h > window.innerHeight - 8 ? state.y - h - 32 : state.y;
|
|
4020
4020
|
setPos({ left: Math.min(state.x, window.innerWidth - w - 8), top });
|
|
4021
4021
|
}, [state.x, state.y]);
|
|
4022
|
-
|
|
4022
|
+
React9.useEffect(() => {
|
|
4023
4023
|
const h = (e) => {
|
|
4024
4024
|
if (ref.current && !ref.current.contains(e.target)) onClose();
|
|
4025
4025
|
};
|
|
4026
4026
|
document.addEventListener("mousedown", h, true);
|
|
4027
4027
|
return () => document.removeEventListener("mousedown", h, true);
|
|
4028
4028
|
}, [onClose]);
|
|
4029
|
-
|
|
4029
|
+
React9.useEffect(() => {
|
|
4030
4030
|
const h = () => onClose();
|
|
4031
4031
|
window.addEventListener("scroll", h, { capture: true, passive: true });
|
|
4032
4032
|
return () => window.removeEventListener("scroll", h, true);
|
|
4033
4033
|
}, [onClose]);
|
|
4034
|
-
|
|
4034
|
+
React9.useEffect(() => {
|
|
4035
4035
|
const h = (e) => {
|
|
4036
4036
|
if (e.key === "Escape") onClose();
|
|
4037
4037
|
};
|
|
@@ -4148,17 +4148,17 @@ function SpellCheckPlugin({
|
|
|
4148
4148
|
enabled = true
|
|
4149
4149
|
}) {
|
|
4150
4150
|
const [editor] = useLexicalComposerContext();
|
|
4151
|
-
const timerRef =
|
|
4152
|
-
const dismissRef =
|
|
4153
|
-
const reqIdRef =
|
|
4154
|
-
const lastTextRef =
|
|
4155
|
-
const applyingRef =
|
|
4156
|
-
const grammarCorrectionRef =
|
|
4157
|
-
const [popover, setPopover] =
|
|
4158
|
-
|
|
4151
|
+
const timerRef = React9.useRef(null);
|
|
4152
|
+
const dismissRef = React9.useRef(null);
|
|
4153
|
+
const reqIdRef = React9.useRef(0);
|
|
4154
|
+
const lastTextRef = React9.useRef("");
|
|
4155
|
+
const applyingRef = React9.useRef(false);
|
|
4156
|
+
const grammarCorrectionRef = React9.useRef(void 0);
|
|
4157
|
+
const [popover, setPopover] = React9.useState(null);
|
|
4158
|
+
React9.useEffect(() => {
|
|
4159
4159
|
injectCSS();
|
|
4160
4160
|
}, []);
|
|
4161
|
-
const clearErrors =
|
|
4161
|
+
const clearErrors = React9.useCallback(() => {
|
|
4162
4162
|
setPopover(null);
|
|
4163
4163
|
grammarCorrectionRef.current = void 0;
|
|
4164
4164
|
applyingRef.current = true;
|
|
@@ -4174,7 +4174,7 @@ function SpellCheckPlugin({
|
|
|
4174
4174
|
}
|
|
4175
4175
|
);
|
|
4176
4176
|
}, [editor]);
|
|
4177
|
-
const applyIssues =
|
|
4177
|
+
const applyIssues = React9.useCallback(
|
|
4178
4178
|
(issues, improvedText, trimOffset = 0) => {
|
|
4179
4179
|
let savedCharOffset = -1;
|
|
4180
4180
|
editor.getEditorState().read(() => {
|
|
@@ -4317,7 +4317,7 @@ function SpellCheckPlugin({
|
|
|
4317
4317
|
},
|
|
4318
4318
|
[editor]
|
|
4319
4319
|
);
|
|
4320
|
-
|
|
4320
|
+
React9.useEffect(() => {
|
|
4321
4321
|
let currentRoot = null;
|
|
4322
4322
|
const onClick = (e) => {
|
|
4323
4323
|
const span = e.target.closest("[data-spell-offset]");
|
|
@@ -4361,7 +4361,7 @@ function SpellCheckPlugin({
|
|
|
4361
4361
|
if (currentRoot) currentRoot.removeEventListener("click", onClick);
|
|
4362
4362
|
};
|
|
4363
4363
|
}, [editor]);
|
|
4364
|
-
const handleAccept =
|
|
4364
|
+
const handleAccept = React9.useCallback(
|
|
4365
4365
|
(replacement, nodeKey) => {
|
|
4366
4366
|
let original = "";
|
|
4367
4367
|
editor.getEditorState().read(() => {
|
|
@@ -4387,7 +4387,7 @@ function SpellCheckPlugin({
|
|
|
4387
4387
|
},
|
|
4388
4388
|
[editor, onSpellCheckAccept, popover]
|
|
4389
4389
|
);
|
|
4390
|
-
const handleDismiss =
|
|
4390
|
+
const handleDismiss = React9.useCallback(
|
|
4391
4391
|
(nodeKey) => {
|
|
4392
4392
|
editor.update(
|
|
4393
4393
|
() => {
|
|
@@ -4401,7 +4401,7 @@ function SpellCheckPlugin({
|
|
|
4401
4401
|
},
|
|
4402
4402
|
[editor]
|
|
4403
4403
|
);
|
|
4404
|
-
const handleImprove =
|
|
4404
|
+
const handleImprove = React9.useCallback(
|
|
4405
4405
|
(text) => {
|
|
4406
4406
|
const original = lastTextRef.current;
|
|
4407
4407
|
applyingRef.current = true;
|
|
@@ -4421,7 +4421,7 @@ function SpellCheckPlugin({
|
|
|
4421
4421
|
},
|
|
4422
4422
|
[editor, onSpellCheckAccept]
|
|
4423
4423
|
);
|
|
4424
|
-
const handleAcceptGrammar =
|
|
4424
|
+
const handleAcceptGrammar = React9.useCallback(
|
|
4425
4425
|
(corrected) => {
|
|
4426
4426
|
const original = lastTextRef.current;
|
|
4427
4427
|
applyingRef.current = true;
|
|
@@ -4441,7 +4441,7 @@ function SpellCheckPlugin({
|
|
|
4441
4441
|
},
|
|
4442
4442
|
[editor, onSpellCheckAccept]
|
|
4443
4443
|
);
|
|
4444
|
-
|
|
4444
|
+
React9.useEffect(() => {
|
|
4445
4445
|
if (!enabled || !useSpellCheck) return;
|
|
4446
4446
|
return editor.registerUpdateListener(({ tags }) => {
|
|
4447
4447
|
if (applyingRef.current) return;
|
|
@@ -4479,13 +4479,13 @@ function SpellCheckPlugin({
|
|
|
4479
4479
|
}, idleMs);
|
|
4480
4480
|
});
|
|
4481
4481
|
}, [editor, useSpellCheck, enabled, idleMs, applyIssues, clearErrors]);
|
|
4482
|
-
|
|
4482
|
+
React9.useEffect(() => {
|
|
4483
4483
|
if (!enabled) {
|
|
4484
4484
|
clearErrors();
|
|
4485
4485
|
lastTextRef.current = "";
|
|
4486
4486
|
}
|
|
4487
4487
|
}, [enabled, clearErrors]);
|
|
4488
|
-
|
|
4488
|
+
React9.useEffect(
|
|
4489
4489
|
() => () => {
|
|
4490
4490
|
dismissRef.current?.();
|
|
4491
4491
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
@@ -4506,10 +4506,10 @@ function SpellCheckPlugin({
|
|
|
4506
4506
|
}
|
|
4507
4507
|
function TableActionMenuPlugin({ disabled = false }) {
|
|
4508
4508
|
const [editor] = useLexicalComposerContext();
|
|
4509
|
-
const [isInTable, setIsInTable] =
|
|
4510
|
-
const [anchorRect, setAnchorRect] =
|
|
4511
|
-
const [open, setOpen] =
|
|
4512
|
-
const updateFromSelection =
|
|
4509
|
+
const [isInTable, setIsInTable] = React9.useState(false);
|
|
4510
|
+
const [anchorRect, setAnchorRect] = React9.useState(null);
|
|
4511
|
+
const [open, setOpen] = React9.useState(false);
|
|
4512
|
+
const updateFromSelection = React9.useCallback(() => {
|
|
4513
4513
|
const root = editor.getRootElement();
|
|
4514
4514
|
if (!root) return;
|
|
4515
4515
|
editor.getEditorState().read(() => {
|
|
@@ -4547,7 +4547,7 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
4547
4547
|
setAnchorRect(cellDom.getBoundingClientRect());
|
|
4548
4548
|
});
|
|
4549
4549
|
}, [editor]);
|
|
4550
|
-
|
|
4550
|
+
React9.useEffect(() => {
|
|
4551
4551
|
return mergeRegister(
|
|
4552
4552
|
editor.registerCommand(
|
|
4553
4553
|
SELECTION_CHANGE_COMMAND,
|
|
@@ -4562,7 +4562,7 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
4562
4562
|
})
|
|
4563
4563
|
);
|
|
4564
4564
|
}, [editor, updateFromSelection]);
|
|
4565
|
-
|
|
4565
|
+
React9.useEffect(() => {
|
|
4566
4566
|
return editor.registerCommand(
|
|
4567
4567
|
KEY_DOWN_COMMAND,
|
|
4568
4568
|
(event) => {
|
|
@@ -4603,11 +4603,11 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
4603
4603
|
COMMAND_PRIORITY_HIGH
|
|
4604
4604
|
);
|
|
4605
4605
|
}, [editor, disabled]);
|
|
4606
|
-
|
|
4606
|
+
React9.useEffect(() => {
|
|
4607
4607
|
if (!isInTable && open) setOpen(false);
|
|
4608
4608
|
}, [isInTable, open]);
|
|
4609
4609
|
const canShow = isInTable && !!anchorRect && !disabled;
|
|
4610
|
-
const handleStyle =
|
|
4610
|
+
const handleStyle = React9.useMemo(() => {
|
|
4611
4611
|
if (!anchorRect) return void 0;
|
|
4612
4612
|
const top = Math.max(8, anchorRect.top + 6);
|
|
4613
4613
|
const left = Math.max(8, anchorRect.right - 34);
|
|
@@ -4621,7 +4621,7 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
4621
4621
|
const dangerStyle = {
|
|
4622
4622
|
color: "var(--colorPaletteRedForeground1)"
|
|
4623
4623
|
};
|
|
4624
|
-
const run =
|
|
4624
|
+
const run = React9.useCallback(
|
|
4625
4625
|
(fn) => {
|
|
4626
4626
|
if (disabled) return;
|
|
4627
4627
|
editor.focus();
|
|
@@ -5086,8 +5086,8 @@ var hsvToRgb = (h, s, v) => {
|
|
|
5086
5086
|
};
|
|
5087
5087
|
};
|
|
5088
5088
|
function useDrag(onMove, onEnd, interactingRef) {
|
|
5089
|
-
const draggingRef =
|
|
5090
|
-
const start =
|
|
5089
|
+
const draggingRef = React9.useRef(false);
|
|
5090
|
+
const start = React9.useCallback(
|
|
5091
5091
|
(e) => {
|
|
5092
5092
|
draggingRef.current = true;
|
|
5093
5093
|
if (interactingRef) interactingRef.current = true;
|
|
@@ -5119,19 +5119,19 @@ function useDrag(onMove, onEnd, interactingRef) {
|
|
|
5119
5119
|
return start;
|
|
5120
5120
|
}
|
|
5121
5121
|
var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
5122
|
-
const [open, setOpen] =
|
|
5123
|
-
const btnRef =
|
|
5124
|
-
const interactingRef =
|
|
5125
|
-
const handleDismiss =
|
|
5126
|
-
const preventDismissOnEvent =
|
|
5122
|
+
const [open, setOpen] = React9.useState(false);
|
|
5123
|
+
const btnRef = React9.useRef(null);
|
|
5124
|
+
const interactingRef = React9.useRef(false);
|
|
5125
|
+
const handleDismiss = React9.useCallback(() => setOpen(false), []);
|
|
5126
|
+
const preventDismissOnEvent = React9.useCallback(
|
|
5127
5127
|
(ev) => {
|
|
5128
5128
|
if (interactingRef.current) return true;
|
|
5129
5129
|
return ev.type !== "click";
|
|
5130
5130
|
},
|
|
5131
5131
|
[]
|
|
5132
5132
|
);
|
|
5133
|
-
const [, forceReposition] =
|
|
5134
|
-
|
|
5133
|
+
const [, forceReposition] = React9.useState(0);
|
|
5134
|
+
React9.useEffect(() => {
|
|
5135
5135
|
if (!open) return;
|
|
5136
5136
|
let rafId = null;
|
|
5137
5137
|
const reposition = () => {
|
|
@@ -5149,13 +5149,17 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5149
5149
|
window.removeEventListener("resize", reposition);
|
|
5150
5150
|
};
|
|
5151
5151
|
}, [open]);
|
|
5152
|
-
const [hex, setHex] =
|
|
5153
|
-
const { r, g, b } =
|
|
5154
|
-
const hsv =
|
|
5155
|
-
const [h, setH] =
|
|
5156
|
-
const [s, setS] =
|
|
5157
|
-
const [v, setV] =
|
|
5158
|
-
|
|
5152
|
+
const [hex, setHex] = React9.useState(normalizeHex(value || "#000000"));
|
|
5153
|
+
const { r, g, b } = React9.useMemo(() => hexToRgb(hex), [hex]);
|
|
5154
|
+
const hsv = React9.useMemo(() => rgbToHsv(r, g, b), [r, g, b]);
|
|
5155
|
+
const [h, setH] = React9.useState(hsv.h);
|
|
5156
|
+
const [s, setS] = React9.useState(hsv.s);
|
|
5157
|
+
const [v, setV] = React9.useState(hsv.v);
|
|
5158
|
+
const wasOpenRef = React9.useRef(open);
|
|
5159
|
+
React9.useEffect(() => {
|
|
5160
|
+
const justOpened = open && !wasOpenRef.current;
|
|
5161
|
+
wasOpenRef.current = open;
|
|
5162
|
+
if (!justOpened) return;
|
|
5159
5163
|
const n = normalizeHex(value || "#000000");
|
|
5160
5164
|
setHex(n);
|
|
5161
5165
|
const rgb = hexToRgb(n);
|
|
@@ -5163,8 +5167,8 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5163
5167
|
setH(next.h);
|
|
5164
5168
|
setS(next.s);
|
|
5165
5169
|
setV(next.v);
|
|
5166
|
-
}, [value]);
|
|
5167
|
-
const commitHsv =
|
|
5170
|
+
}, [value, open]);
|
|
5171
|
+
const commitHsv = React9.useCallback(
|
|
5168
5172
|
(hh, ss, vv, close) => {
|
|
5169
5173
|
const rgb = hsvToRgb(hh, ss, vv);
|
|
5170
5174
|
const nextHex = rgbToHex(rgb.r, rgb.g, rgb.b);
|
|
@@ -5174,8 +5178,8 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5174
5178
|
},
|
|
5175
5179
|
[onChange]
|
|
5176
5180
|
);
|
|
5177
|
-
const svRef =
|
|
5178
|
-
const onSVMove =
|
|
5181
|
+
const svRef = React9.useRef(null);
|
|
5182
|
+
const onSVMove = React9.useCallback(
|
|
5179
5183
|
(clientX, clientY) => {
|
|
5180
5184
|
if (!svRef.current) return;
|
|
5181
5185
|
const rect = svRef.current.getBoundingClientRect();
|
|
@@ -5190,8 +5194,8 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5190
5194
|
[h, commitHsv]
|
|
5191
5195
|
);
|
|
5192
5196
|
const startSV = useDrag(onSVMove, void 0, interactingRef);
|
|
5193
|
-
const hueRef =
|
|
5194
|
-
const onHueMove =
|
|
5197
|
+
const hueRef = React9.useRef(null);
|
|
5198
|
+
const onHueMove = React9.useCallback(
|
|
5195
5199
|
(clientX) => {
|
|
5196
5200
|
if (!hueRef.current) return;
|
|
5197
5201
|
const rect = hueRef.current.getBoundingClientRect();
|
|
@@ -5203,9 +5207,9 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5203
5207
|
[s, v, commitHsv]
|
|
5204
5208
|
);
|
|
5205
5209
|
const startHue = useDrag((x) => onHueMove(x), void 0, interactingRef);
|
|
5206
|
-
const svThumb =
|
|
5207
|
-
const hueThumb =
|
|
5208
|
-
const hueColor =
|
|
5210
|
+
const svThumb = React9.useMemo(() => ({ left: `${s * 100}%`, top: `${(1 - v) * 100}%` }), [s, v]);
|
|
5211
|
+
const hueThumb = React9.useMemo(() => ({ left: `${h / 360 * 100}%` }), [h]);
|
|
5212
|
+
const hueColor = React9.useMemo(() => {
|
|
5209
5213
|
const { r: r2, g: g2, b: b2 } = hsvToRgb(h, 1, 1);
|
|
5210
5214
|
return rgbToHex(r2, g2, b2);
|
|
5211
5215
|
}, [h]);
|
|
@@ -5327,8 +5331,8 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5327
5331
|
};
|
|
5328
5332
|
var ColorPickerPlugin = ({ disabled }) => {
|
|
5329
5333
|
const [editor] = useLexicalComposerContext();
|
|
5330
|
-
const [{ color, bgColor }, setColors] =
|
|
5331
|
-
const lastRangeSelectionRef =
|
|
5334
|
+
const [{ color, bgColor }, setColors] = React9__default.useState({ color: "#000000", bgColor: "#ffffff" });
|
|
5335
|
+
const lastRangeSelectionRef = React9__default.useRef(null);
|
|
5332
5336
|
const updateToolbar = () => {
|
|
5333
5337
|
const selection = $getSelection();
|
|
5334
5338
|
if ($isRangeSelection(selection)) {
|
|
@@ -5338,7 +5342,7 @@ var ColorPickerPlugin = ({ disabled }) => {
|
|
|
5338
5342
|
setColors({ color: c, bgColor: bg });
|
|
5339
5343
|
}
|
|
5340
5344
|
};
|
|
5341
|
-
|
|
5345
|
+
React9__default.useEffect(() => {
|
|
5342
5346
|
return mergeRegister(
|
|
5343
5347
|
editor.registerUpdateListener(({ editorState }) => {
|
|
5344
5348
|
editorState.read(() => updateToolbar());
|
|
@@ -5554,9 +5558,9 @@ var useStyles3 = makeStyles({
|
|
|
5554
5558
|
var FontSizePlugin = ({ disabled }) => {
|
|
5555
5559
|
const [editor] = useLexicalComposerContext();
|
|
5556
5560
|
const styles = useStyles3();
|
|
5557
|
-
const [fontSize2, setFontSize] =
|
|
5561
|
+
const [fontSize2, setFontSize] = React9.useState(String(DEFAULT_FONT_SIZE));
|
|
5558
5562
|
const fg = disabled ? "var(--colorNeutralForegroundDisabled, #A6A6A6)" : "#333333";
|
|
5559
|
-
|
|
5563
|
+
React9.useEffect(() => {
|
|
5560
5564
|
const readFontSize = () => {
|
|
5561
5565
|
const selection = $getSelection();
|
|
5562
5566
|
if ($isRangeSelection(selection)) {
|
|
@@ -5974,7 +5978,7 @@ var ToolBarPlugins = (props) => {
|
|
|
5974
5978
|
const [isLowercase, setIsLowercase] = useState(false);
|
|
5975
5979
|
const [isCapitalize, setIsCapitalize] = useState(false);
|
|
5976
5980
|
const [alignment, setAlignment] = useState("left");
|
|
5977
|
-
const lastSelectionRef =
|
|
5981
|
+
const lastSelectionRef = React9__default.useRef(null);
|
|
5978
5982
|
const presetGroups = getToolbarGroupsByLevel(props.level);
|
|
5979
5983
|
const pluginGroups = useMemo(() => sanitizePluginGroups(presetGroups), [presetGroups]);
|
|
5980
5984
|
const updateToolbarPlugins = () => {
|
|
@@ -6028,7 +6032,7 @@ var ToolBarPlugins = (props) => {
|
|
|
6028
6032
|
["paragraph", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "quote", "code"].includes(type) ? type : "paragraph"
|
|
6029
6033
|
);
|
|
6030
6034
|
};
|
|
6031
|
-
const applyToBlock =
|
|
6035
|
+
const applyToBlock = React9__default.useCallback(
|
|
6032
6036
|
(fn) => {
|
|
6033
6037
|
editor.update(() => {
|
|
6034
6038
|
const saved = lastSelectionRef.current;
|
|
@@ -6048,7 +6052,7 @@ var ToolBarPlugins = (props) => {
|
|
|
6048
6052
|
}
|
|
6049
6053
|
});
|
|
6050
6054
|
};
|
|
6051
|
-
|
|
6055
|
+
React9__default.useEffect(() => {
|
|
6052
6056
|
return mergeRegister(
|
|
6053
6057
|
editor.registerEditableListener((editable) => {
|
|
6054
6058
|
setIsEditable(editable);
|
|
@@ -6509,7 +6513,7 @@ var ToolBarPlugins = (props) => {
|
|
|
6509
6513
|
padding: "0px",
|
|
6510
6514
|
minHeight: 36
|
|
6511
6515
|
},
|
|
6512
|
-
children: pluginGroups.map((group, groupIndex) => /* @__PURE__ */ jsx(
|
|
6516
|
+
children: pluginGroups.map((group, groupIndex) => /* @__PURE__ */ jsx(React9__default.Fragment, { children: group.map((token, tokenIndex) => {
|
|
6513
6517
|
try {
|
|
6514
6518
|
return renderToken(token, groupIndex, tokenIndex);
|
|
6515
6519
|
} catch {
|
|
@@ -6822,12 +6826,12 @@ function _makeQueryFn(fn) {
|
|
|
6822
6826
|
var ContentEditorComponent = forwardRef(
|
|
6823
6827
|
(props, ref) => {
|
|
6824
6828
|
const isReadOnly = !!props.readOnly;
|
|
6825
|
-
const resolvedSpellCheck =
|
|
6829
|
+
const resolvedSpellCheck = React9__default.useMemo(
|
|
6826
6830
|
() => props.spellCheckFn ? _makeSpellCheckFn(props.spellCheckFn) : props.useSpellCheck,
|
|
6827
6831
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6828
6832
|
[props.spellCheckFn, props.useSpellCheck]
|
|
6829
6833
|
);
|
|
6830
|
-
const resolvedQuery =
|
|
6834
|
+
const resolvedQuery = React9__default.useMemo(
|
|
6831
6835
|
() => props.suggestFn ? _makeQueryFn(props.suggestFn) : props.useQuery,
|
|
6832
6836
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6833
6837
|
[props.suggestFn, props.useQuery]
|