@tarviks/lexical-rich-editor 1.0.6 → 1.0.8
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 +256 -244
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -96
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -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();
|
|
@@ -5032,10 +5032,16 @@ var PRESET = [
|
|
|
5032
5032
|
];
|
|
5033
5033
|
var clamp3 = (v, min, max) => Math.min(max, Math.max(min, v));
|
|
5034
5034
|
var normalizeHex = (v) => {
|
|
5035
|
-
|
|
5035
|
+
const s = (v ?? "").trim();
|
|
5036
5036
|
if (!s) return "#000000";
|
|
5037
|
-
|
|
5038
|
-
if (
|
|
5037
|
+
const rgbMatch = s.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)$/i);
|
|
5038
|
+
if (rgbMatch) {
|
|
5039
|
+
const [, r, g, b] = rgbMatch;
|
|
5040
|
+
return rgbToHex(clamp3(+r, 0, 255), clamp3(+g, 0, 255), clamp3(+b, 0, 255));
|
|
5041
|
+
}
|
|
5042
|
+
let hex = s.startsWith("#") ? s : `#${s}`;
|
|
5043
|
+
if (hex.length === 9) hex = hex.slice(0, 7);
|
|
5044
|
+
if (hex.length === 4 || hex.length === 7) return hex.toLowerCase();
|
|
5039
5045
|
return "#000000";
|
|
5040
5046
|
};
|
|
5041
5047
|
var hexToRgb = (hex) => {
|
|
@@ -5086,8 +5092,8 @@ var hsvToRgb = (h, s, v) => {
|
|
|
5086
5092
|
};
|
|
5087
5093
|
};
|
|
5088
5094
|
function useDrag(onMove, onEnd, interactingRef) {
|
|
5089
|
-
const draggingRef =
|
|
5090
|
-
const start =
|
|
5095
|
+
const draggingRef = React9.useRef(false);
|
|
5096
|
+
const start = React9.useCallback(
|
|
5091
5097
|
(e) => {
|
|
5092
5098
|
draggingRef.current = true;
|
|
5093
5099
|
if (interactingRef) interactingRef.current = true;
|
|
@@ -5119,19 +5125,19 @@ function useDrag(onMove, onEnd, interactingRef) {
|
|
|
5119
5125
|
return start;
|
|
5120
5126
|
}
|
|
5121
5127
|
var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
5122
|
-
const [open, setOpen] =
|
|
5123
|
-
const btnRef =
|
|
5124
|
-
const interactingRef =
|
|
5125
|
-
const handleDismiss =
|
|
5126
|
-
const preventDismissOnEvent =
|
|
5128
|
+
const [open, setOpen] = React9.useState(false);
|
|
5129
|
+
const btnRef = React9.useRef(null);
|
|
5130
|
+
const interactingRef = React9.useRef(false);
|
|
5131
|
+
const handleDismiss = React9.useCallback(() => setOpen(false), []);
|
|
5132
|
+
const preventDismissOnEvent = React9.useCallback(
|
|
5127
5133
|
(ev) => {
|
|
5128
5134
|
if (interactingRef.current) return true;
|
|
5129
5135
|
return ev.type !== "click";
|
|
5130
5136
|
},
|
|
5131
5137
|
[]
|
|
5132
5138
|
);
|
|
5133
|
-
const [, forceReposition] =
|
|
5134
|
-
|
|
5139
|
+
const [, forceReposition] = React9.useState(0);
|
|
5140
|
+
React9.useEffect(() => {
|
|
5135
5141
|
if (!open) return;
|
|
5136
5142
|
let rafId = null;
|
|
5137
5143
|
const reposition = () => {
|
|
@@ -5149,13 +5155,17 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5149
5155
|
window.removeEventListener("resize", reposition);
|
|
5150
5156
|
};
|
|
5151
5157
|
}, [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
|
-
|
|
5158
|
+
const [hex, setHex] = React9.useState(normalizeHex(value || "#000000"));
|
|
5159
|
+
const { r, g, b } = React9.useMemo(() => hexToRgb(hex), [hex]);
|
|
5160
|
+
const hsv = React9.useMemo(() => rgbToHsv(r, g, b), [r, g, b]);
|
|
5161
|
+
const [h, setH] = React9.useState(hsv.h);
|
|
5162
|
+
const [s, setS] = React9.useState(hsv.s);
|
|
5163
|
+
const [v, setV] = React9.useState(hsv.v);
|
|
5164
|
+
const wasOpenRef = React9.useRef(open);
|
|
5165
|
+
React9.useEffect(() => {
|
|
5166
|
+
const justOpened = open && !wasOpenRef.current;
|
|
5167
|
+
wasOpenRef.current = open;
|
|
5168
|
+
if (!justOpened) return;
|
|
5159
5169
|
const n = normalizeHex(value || "#000000");
|
|
5160
5170
|
setHex(n);
|
|
5161
5171
|
const rgb = hexToRgb(n);
|
|
@@ -5163,8 +5173,8 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5163
5173
|
setH(next.h);
|
|
5164
5174
|
setS(next.s);
|
|
5165
5175
|
setV(next.v);
|
|
5166
|
-
}, [value]);
|
|
5167
|
-
const commitHsv =
|
|
5176
|
+
}, [value, open]);
|
|
5177
|
+
const commitHsv = React9.useCallback(
|
|
5168
5178
|
(hh, ss, vv, close) => {
|
|
5169
5179
|
const rgb = hsvToRgb(hh, ss, vv);
|
|
5170
5180
|
const nextHex = rgbToHex(rgb.r, rgb.g, rgb.b);
|
|
@@ -5174,8 +5184,8 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5174
5184
|
},
|
|
5175
5185
|
[onChange]
|
|
5176
5186
|
);
|
|
5177
|
-
const svRef =
|
|
5178
|
-
const onSVMove =
|
|
5187
|
+
const svRef = React9.useRef(null);
|
|
5188
|
+
const onSVMove = React9.useCallback(
|
|
5179
5189
|
(clientX, clientY) => {
|
|
5180
5190
|
if (!svRef.current) return;
|
|
5181
5191
|
const rect = svRef.current.getBoundingClientRect();
|
|
@@ -5190,8 +5200,8 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5190
5200
|
[h, commitHsv]
|
|
5191
5201
|
);
|
|
5192
5202
|
const startSV = useDrag(onSVMove, void 0, interactingRef);
|
|
5193
|
-
const hueRef =
|
|
5194
|
-
const onHueMove =
|
|
5203
|
+
const hueRef = React9.useRef(null);
|
|
5204
|
+
const onHueMove = React9.useCallback(
|
|
5195
5205
|
(clientX) => {
|
|
5196
5206
|
if (!hueRef.current) return;
|
|
5197
5207
|
const rect = hueRef.current.getBoundingClientRect();
|
|
@@ -5203,9 +5213,9 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5203
5213
|
[s, v, commitHsv]
|
|
5204
5214
|
);
|
|
5205
5215
|
const startHue = useDrag((x) => onHueMove(x), void 0, interactingRef);
|
|
5206
|
-
const svThumb =
|
|
5207
|
-
const hueThumb =
|
|
5208
|
-
const hueColor =
|
|
5216
|
+
const svThumb = React9.useMemo(() => ({ left: `${s * 100}%`, top: `${(1 - v) * 100}%` }), [s, v]);
|
|
5217
|
+
const hueThumb = React9.useMemo(() => ({ left: `${h / 360 * 100}%` }), [h]);
|
|
5218
|
+
const hueColor = React9.useMemo(() => {
|
|
5209
5219
|
const { r: r2, g: g2, b: b2 } = hsvToRgb(h, 1, 1);
|
|
5210
5220
|
return rgbToHex(r2, g2, b2);
|
|
5211
5221
|
}, [h]);
|
|
@@ -5213,6 +5223,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5213
5223
|
/* @__PURE__ */ jsx(
|
|
5214
5224
|
Button,
|
|
5215
5225
|
{
|
|
5226
|
+
type: "button",
|
|
5216
5227
|
size: "small",
|
|
5217
5228
|
icon,
|
|
5218
5229
|
value: title,
|
|
@@ -5312,13 +5323,14 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5312
5323
|
/* @__PURE__ */ jsx(
|
|
5313
5324
|
DefaultButton,
|
|
5314
5325
|
{
|
|
5326
|
+
type: "button",
|
|
5315
5327
|
text: "Apply",
|
|
5316
5328
|
onClick: () => {
|
|
5317
5329
|
commitHsv(h, s, v, true);
|
|
5318
5330
|
}
|
|
5319
5331
|
}
|
|
5320
5332
|
),
|
|
5321
|
-
/* @__PURE__ */ jsx(DefaultButton, { text: "Close", onClick: () => setOpen(false) })
|
|
5333
|
+
/* @__PURE__ */ jsx(DefaultButton, { type: "button", text: "Close", onClick: () => setOpen(false) })
|
|
5322
5334
|
] })
|
|
5323
5335
|
] })
|
|
5324
5336
|
}
|
|
@@ -5327,8 +5339,8 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5327
5339
|
};
|
|
5328
5340
|
var ColorPickerPlugin = ({ disabled }) => {
|
|
5329
5341
|
const [editor] = useLexicalComposerContext();
|
|
5330
|
-
const [{ color, bgColor }, setColors] =
|
|
5331
|
-
const lastRangeSelectionRef =
|
|
5342
|
+
const [{ color, bgColor }, setColors] = React9__default.useState({ color: "#000000", bgColor: "#ffffff" });
|
|
5343
|
+
const lastRangeSelectionRef = React9__default.useRef(null);
|
|
5332
5344
|
const updateToolbar = () => {
|
|
5333
5345
|
const selection = $getSelection();
|
|
5334
5346
|
if ($isRangeSelection(selection)) {
|
|
@@ -5338,7 +5350,7 @@ var ColorPickerPlugin = ({ disabled }) => {
|
|
|
5338
5350
|
setColors({ color: c, bgColor: bg });
|
|
5339
5351
|
}
|
|
5340
5352
|
};
|
|
5341
|
-
|
|
5353
|
+
React9__default.useEffect(() => {
|
|
5342
5354
|
return mergeRegister(
|
|
5343
5355
|
editor.registerUpdateListener(({ editorState }) => {
|
|
5344
5356
|
editorState.read(() => updateToolbar());
|
|
@@ -5554,9 +5566,9 @@ var useStyles3 = makeStyles({
|
|
|
5554
5566
|
var FontSizePlugin = ({ disabled }) => {
|
|
5555
5567
|
const [editor] = useLexicalComposerContext();
|
|
5556
5568
|
const styles = useStyles3();
|
|
5557
|
-
const [fontSize2, setFontSize] =
|
|
5569
|
+
const [fontSize2, setFontSize] = React9.useState(String(DEFAULT_FONT_SIZE));
|
|
5558
5570
|
const fg = disabled ? "var(--colorNeutralForegroundDisabled, #A6A6A6)" : "#333333";
|
|
5559
|
-
|
|
5571
|
+
React9.useEffect(() => {
|
|
5560
5572
|
const readFontSize = () => {
|
|
5561
5573
|
const selection = $getSelection();
|
|
5562
5574
|
if ($isRangeSelection(selection)) {
|
|
@@ -5974,7 +5986,7 @@ var ToolBarPlugins = (props) => {
|
|
|
5974
5986
|
const [isLowercase, setIsLowercase] = useState(false);
|
|
5975
5987
|
const [isCapitalize, setIsCapitalize] = useState(false);
|
|
5976
5988
|
const [alignment, setAlignment] = useState("left");
|
|
5977
|
-
const lastSelectionRef =
|
|
5989
|
+
const lastSelectionRef = React9__default.useRef(null);
|
|
5978
5990
|
const presetGroups = getToolbarGroupsByLevel(props.level);
|
|
5979
5991
|
const pluginGroups = useMemo(() => sanitizePluginGroups(presetGroups), [presetGroups]);
|
|
5980
5992
|
const updateToolbarPlugins = () => {
|
|
@@ -6028,7 +6040,7 @@ var ToolBarPlugins = (props) => {
|
|
|
6028
6040
|
["paragraph", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "quote", "code"].includes(type) ? type : "paragraph"
|
|
6029
6041
|
);
|
|
6030
6042
|
};
|
|
6031
|
-
const applyToBlock =
|
|
6043
|
+
const applyToBlock = React9__default.useCallback(
|
|
6032
6044
|
(fn) => {
|
|
6033
6045
|
editor.update(() => {
|
|
6034
6046
|
const saved = lastSelectionRef.current;
|
|
@@ -6048,7 +6060,7 @@ var ToolBarPlugins = (props) => {
|
|
|
6048
6060
|
}
|
|
6049
6061
|
});
|
|
6050
6062
|
};
|
|
6051
|
-
|
|
6063
|
+
React9__default.useEffect(() => {
|
|
6052
6064
|
return mergeRegister(
|
|
6053
6065
|
editor.registerEditableListener((editable) => {
|
|
6054
6066
|
setIsEditable(editable);
|
|
@@ -6509,7 +6521,7 @@ var ToolBarPlugins = (props) => {
|
|
|
6509
6521
|
padding: "0px",
|
|
6510
6522
|
minHeight: 36
|
|
6511
6523
|
},
|
|
6512
|
-
children: pluginGroups.map((group, groupIndex) => /* @__PURE__ */ jsx(
|
|
6524
|
+
children: pluginGroups.map((group, groupIndex) => /* @__PURE__ */ jsx(React9__default.Fragment, { children: group.map((token, tokenIndex) => {
|
|
6513
6525
|
try {
|
|
6514
6526
|
return renderToken(token, groupIndex, tokenIndex);
|
|
6515
6527
|
} catch {
|
|
@@ -6822,12 +6834,12 @@ function _makeQueryFn(fn) {
|
|
|
6822
6834
|
var ContentEditorComponent = forwardRef(
|
|
6823
6835
|
(props, ref) => {
|
|
6824
6836
|
const isReadOnly = !!props.readOnly;
|
|
6825
|
-
const resolvedSpellCheck =
|
|
6837
|
+
const resolvedSpellCheck = React9__default.useMemo(
|
|
6826
6838
|
() => props.spellCheckFn ? _makeSpellCheckFn(props.spellCheckFn) : props.useSpellCheck,
|
|
6827
6839
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6828
6840
|
[props.spellCheckFn, props.useSpellCheck]
|
|
6829
6841
|
);
|
|
6830
|
-
const resolvedQuery =
|
|
6842
|
+
const resolvedQuery = React9__default.useMemo(
|
|
6831
6843
|
() => props.suggestFn ? _makeQueryFn(props.suggestFn) : props.useQuery,
|
|
6832
6844
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6833
6845
|
[props.suggestFn, props.useQuery]
|