@haklex/rich-plugin-floating-toolbar 0.0.44 → 0.0.46
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":"AAuCA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAkMzC,wBAAgB,qBAAqB,IAAI,YAAY,GAAG,IAAI,CAghB3D"}
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { $createRubyNode, $isRubyNode } from "@haklex/rich-editor";
|
|
3
3
|
import { ColorPicker } from "@haklex/rich-editor-ui";
|
|
4
4
|
import { usePortalTheme, vars } from "@haklex/rich-style-token";
|
|
5
|
-
import { $isLinkNode,
|
|
5
|
+
import { TOGGLE_LINK_COMMAND, $isLinkNode, $isAutoLinkNode } from "@lexical/link";
|
|
6
6
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
7
7
|
import { $patchStyleText, $getSelectionStyleValueForProperty } from "@lexical/selection";
|
|
8
8
|
import { $getSelection, $isRangeSelection, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, $createTextNode, $getNodeByKey } from "lexical";
|
|
@@ -22,6 +22,26 @@ var rubyInput = "_1m6axz7a";
|
|
|
22
22
|
var rubyActionBtn = "_1m6axz7b";
|
|
23
23
|
var rubyHint = "_1m6axz7c";
|
|
24
24
|
var separator = "_1m6axz7d";
|
|
25
|
+
function isEffectiveLinkNode(node) {
|
|
26
|
+
if (!$isLinkNode(node)) return false;
|
|
27
|
+
return !$isAutoLinkNode(node) || !node.getIsUnlinked();
|
|
28
|
+
}
|
|
29
|
+
function isRegularLinkNode(node) {
|
|
30
|
+
return $isLinkNode(node) && !$isAutoLinkNode(node);
|
|
31
|
+
}
|
|
32
|
+
function collectSelectedActiveAutoLinkNodes(selection) {
|
|
33
|
+
const autoLinkNodes = /* @__PURE__ */ new Map();
|
|
34
|
+
for (const node of selection.getNodes()) {
|
|
35
|
+
if ($isAutoLinkNode(node) && !node.getIsUnlinked()) {
|
|
36
|
+
autoLinkNodes.set(node.getKey(), node);
|
|
37
|
+
}
|
|
38
|
+
const parent = node.getParent();
|
|
39
|
+
if ($isAutoLinkNode(parent) && !parent.getIsUnlinked()) {
|
|
40
|
+
autoLinkNodes.set(parent.getKey(), parent);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return Array.from(autoLinkNodes.values());
|
|
44
|
+
}
|
|
25
45
|
const INITIAL_STATE = {
|
|
26
46
|
isBold: false,
|
|
27
47
|
isItalic: false,
|
|
@@ -59,7 +79,7 @@ function getSelectionState(selection) {
|
|
|
59
79
|
const nodes = selection.getNodes();
|
|
60
80
|
const hasLink = nodes.some((node) => {
|
|
61
81
|
const parent = node.getParent();
|
|
62
|
-
return
|
|
82
|
+
return isEffectiveLinkNode(parent) || isEffectiveLinkNode(node);
|
|
63
83
|
});
|
|
64
84
|
const hasRuby = getSelectedRubyNodes(nodes).length > 0;
|
|
65
85
|
return {
|
|
@@ -234,16 +254,28 @@ function FloatingToolbarPlugin() {
|
|
|
234
254
|
[editor]
|
|
235
255
|
);
|
|
236
256
|
const handleLink = useCallback(() => {
|
|
237
|
-
editor.
|
|
257
|
+
editor.update(() => {
|
|
238
258
|
const selection = $getSelection();
|
|
239
259
|
if (!$isRangeSelection(selection)) return;
|
|
240
260
|
const nodes = selection.getNodes();
|
|
241
261
|
const hasLink = nodes.some((node) => {
|
|
242
262
|
const parent = node.getParent();
|
|
243
|
-
return
|
|
263
|
+
return isEffectiveLinkNode(parent) || isEffectiveLinkNode(node);
|
|
244
264
|
});
|
|
245
265
|
if (hasLink) {
|
|
246
|
-
|
|
266
|
+
for (const autoLinkNode of collectSelectedActiveAutoLinkNodes(
|
|
267
|
+
selection
|
|
268
|
+
)) {
|
|
269
|
+
autoLinkNode.setIsUnlinked(true);
|
|
270
|
+
autoLinkNode.markDirty();
|
|
271
|
+
}
|
|
272
|
+
const hasRegularLink = nodes.some((node) => {
|
|
273
|
+
const parent = node.getParent();
|
|
274
|
+
return isRegularLinkNode(parent) || isRegularLinkNode(node);
|
|
275
|
+
});
|
|
276
|
+
if (hasRegularLink) {
|
|
277
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
278
|
+
}
|
|
247
279
|
} else {
|
|
248
280
|
const text = selection.getTextContent();
|
|
249
281
|
const url = /^https?:\/\//.test(text) ? text : "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haklex/rich-plugin-floating-toolbar",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.46",
|
|
4
4
|
"description": "Floating toolbar plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@haklex/rich-editor": "0.0.
|
|
20
|
-
"@haklex/rich-editor
|
|
21
|
-
"@haklex/rich-style-token": "0.0.
|
|
19
|
+
"@haklex/rich-editor-ui": "0.0.46",
|
|
20
|
+
"@haklex/rich-editor": "0.0.46",
|
|
21
|
+
"@haklex/rich-style-token": "0.0.46"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@lexical/link": "^0.41.0",
|