@haklex/rich-plugin-floating-toolbar 0.62.2 → 0.63.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingToolbarPlugin.d.ts","sourceRoot":"","sources":["../src/FloatingToolbarPlugin.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FloatingToolbarPlugin.d.ts","sourceRoot":"","sources":["../src/FloatingToolbarPlugin.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAoBrD,MAAM,WAAW,0BAA0B;IACzC,OAAO,CAAC,EAAE,SAAS,CAAC;CACrB;AAOD,wBAAgB,qBAAqB,CAAC,EACpC,OAAO,GACR,GAAE,0BAA+B,GAAG,YAAY,GAAG,IAAI,CA0OvD"}
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { $createRubyNode, $isKaTeXInlineNode, $isRubyNode } from "@haklex/rich-e
|
|
|
4
4
|
import { ActionButton, ColorPicker, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, Kbd, TextInput, TooltipContent, TooltipProvider, TooltipRoot, TooltipTrigger, createTooltipHandle } from "@haklex/rich-editor-ui";
|
|
5
5
|
import { usePortalContainer, usePortalTheme, vars } from "@haklex/rich-style-token";
|
|
6
6
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
7
|
+
import { useLexicalEditable } from "@lexical/react/useLexicalEditable";
|
|
7
8
|
import { $getSelectionStyleValueForProperty, $patchStyleText } from "@lexical/selection";
|
|
8
9
|
import { $createTextNode, $getNearestNodeFromDOMNode, $getNodeByKey, $getSelection, $isRangeSelection, $isTextNode, $setSelection, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, KEY_DOWN_COMMAND, SELECTION_CHANGE_COMMAND } from "lexical";
|
|
9
10
|
import { Bold, Code, Ellipsis, EyeOff, Highlighter, Italic, Languages, Link, RemoveFormatting, Strikethrough, Subscript, Superscript, Trash2, Underline, Unlink, X } from "lucide-react";
|
|
@@ -433,7 +434,7 @@ function useEditorBindings({ editor, editRuby, modeRef, openLink, toolbarRef, up
|
|
|
433
434
|
useEffect(() => {
|
|
434
435
|
const onRootClick = (event) => {
|
|
435
436
|
const target = event.target;
|
|
436
|
-
if (!target) return;
|
|
437
|
+
if (!target || !editor.isEditable()) return;
|
|
437
438
|
if (window.getSelection()?.isCollapsed === false) return;
|
|
438
439
|
const ruby = editor.read(() => {
|
|
439
440
|
const node = findRubyAncestor($getNearestNodeFromDOMNode(target));
|
|
@@ -454,6 +455,7 @@ function useEditorBindings({ editor, editRuby, modeRef, openLink, toolbarRef, up
|
|
|
454
455
|
const isModK = event.key.toLowerCase() === "k" && (event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey;
|
|
455
456
|
const isAltF10 = event.key === "F10" && event.altKey;
|
|
456
457
|
if (!isModK && !isAltF10 || modeRef.current.kind !== "format") return false;
|
|
458
|
+
if (isModK && !editor.isEditable()) return false;
|
|
457
459
|
const selection = $getSelection();
|
|
458
460
|
if (!$isRangeSelection(selection) || selection.isCollapsed()) return false;
|
|
459
461
|
if (isAltF10 && !toolbarRef.current) return false;
|
|
@@ -807,6 +809,7 @@ function toBox(rect) {
|
|
|
807
809
|
}
|
|
808
810
|
function FloatingToolbarPlugin({ actions } = {}) {
|
|
809
811
|
const [editor] = useLexicalComposerContext();
|
|
812
|
+
const editable = useLexicalEditable();
|
|
810
813
|
const { className: portalClassName, theme: portalTheme } = usePortalTheme();
|
|
811
814
|
const portalContainer = usePortalContainer();
|
|
812
815
|
const selectionSnapshot = useTextSelectionSnapshot();
|
|
@@ -819,7 +822,7 @@ function FloatingToolbarPlugin({ actions } = {}) {
|
|
|
819
822
|
const modes = useInlineModes(editor, useCallback((target) => {
|
|
820
823
|
setPendingFocus(target ? { target } : null);
|
|
821
824
|
}, []));
|
|
822
|
-
const { mode, modeRef, openLink, openRuby, editRuby, commitOnOutsideClick } = modes;
|
|
825
|
+
const { mode, modeRef, openLink, openRuby, editRuby, commitOnOutsideClick, cancel } = modes;
|
|
823
826
|
useEditorBindings({
|
|
824
827
|
editor,
|
|
825
828
|
editRuby,
|
|
@@ -839,6 +842,9 @@ function FloatingToolbarPlugin({ actions } = {}) {
|
|
|
839
842
|
useEffect(() => {
|
|
840
843
|
if (!selectionSnapshot) setVisible(false);
|
|
841
844
|
}, [selectionSnapshot]);
|
|
845
|
+
useEffect(() => {
|
|
846
|
+
if (!editable) cancel(false);
|
|
847
|
+
}, [cancel, editable]);
|
|
842
848
|
useEffect(() => {
|
|
843
849
|
if (!pendingFocus) return;
|
|
844
850
|
const button = pendingFocus.target === "editor" ? null : toolbarRef.current?.querySelector(`[aria-label="${pendingFocus.target}"]`);
|
|
@@ -877,7 +883,7 @@ function FloatingToolbarPlugin({ actions } = {}) {
|
|
|
877
883
|
rubyKey,
|
|
878
884
|
selectionSnapshot
|
|
879
885
|
]);
|
|
880
|
-
const shown = visible || mode.kind !== "format";
|
|
886
|
+
const shown = editable ? visible || mode.kind !== "format" : visible && actions != null;
|
|
881
887
|
useToolbarPosition({
|
|
882
888
|
active: shown,
|
|
883
889
|
editor,
|
|
@@ -921,7 +927,6 @@ function FloatingToolbarPlugin({ actions } = {}) {
|
|
|
921
927
|
children: props.payload.label
|
|
922
928
|
}) : null)
|
|
923
929
|
}), createPortal(/* @__PURE__ */ jsxs("div", {
|
|
924
|
-
"aria-label": mode.kind === "format" ? "Text formatting" : void 0,
|
|
925
930
|
className: toolbarClassName,
|
|
926
931
|
"data-theme": portalClassName ? portalTheme : void 0,
|
|
927
932
|
ref: toolbarRef,
|
|
@@ -930,6 +935,7 @@ function FloatingToolbarPlugin({ actions } = {}) {
|
|
|
930
935
|
position: "fixed",
|
|
931
936
|
zIndex: 50
|
|
932
937
|
},
|
|
938
|
+
"aria-label": mode.kind !== "format" ? void 0 : editable ? "Text formatting" : "Selection actions",
|
|
933
939
|
onFocus: (e) => syncRovingTabIndex(e.currentTarget, e.target),
|
|
934
940
|
onKeyDown: (e) => {
|
|
935
941
|
if (mode.kind !== "format") return;
|
|
@@ -940,7 +946,8 @@ function FloatingToolbarPlugin({ actions } = {}) {
|
|
|
940
946
|
}
|
|
941
947
|
},
|
|
942
948
|
children: [
|
|
943
|
-
mode.kind === "format" &&
|
|
949
|
+
mode.kind === "format" && !editable && actions,
|
|
950
|
+
mode.kind === "format" && editable && /* @__PURE__ */ jsx(FormatBar, {
|
|
944
951
|
actions,
|
|
945
952
|
handle,
|
|
946
953
|
state,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-editor-bindings.d.ts","sourceRoot":"","sources":["../src/use-editor-bindings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAS7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEnE,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,UAAU,EACV,aAAa,GACd,EAAE;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,OAAO,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;IAChC,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;IACxC,UAAU,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC7C,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,
|
|
1
|
+
{"version":3,"file":"use-editor-bindings.d.ts","sourceRoot":"","sources":["../src/use-editor-bindings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAS7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEnE,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,UAAU,EACV,aAAa,GACd,EAAE;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,OAAO,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;IAChC,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;IACxC,UAAU,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC7C,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,QA0DA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haklex/rich-plugin-floating-toolbar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.1",
|
|
4
4
|
"description": "Floating toolbar plugin",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"vite": "^8.3.5"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@haklex/rich-editor": "^0.
|
|
41
|
-
"@haklex/rich-editor-ui": "^0.
|
|
42
|
-
"@haklex/rich-style-token": "^0.
|
|
40
|
+
"@haklex/rich-editor": "^0.63.1",
|
|
41
|
+
"@haklex/rich-editor-ui": "^0.63.1",
|
|
42
|
+
"@haklex/rich-style-token": "^0.63.1",
|
|
43
43
|
"@lexical/link": "^0.53.0",
|
|
44
44
|
"@lexical/react": "^0.53.0",
|
|
45
45
|
"@lexical/selection": "^0.53.0",
|