@mp-lb/mdkit 0.3.0 → 0.3.2
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,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEditorState } from "@tiptap/react";
|
|
3
3
|
import { BubbleMenu } from "@tiptap/react/menus";
|
|
4
|
-
import { Bold, Code2, Heading1, Heading2, Italic, Link2, List, ListOrdered, Quote, Strikethrough, } from "lucide-react";
|
|
4
|
+
import { Bold, Code2, Heading1, Heading2, Heading3, Italic, Link2, List, ListOrdered, Quote, Strikethrough, } from "lucide-react";
|
|
5
5
|
import { joinClassNames } from "../ui/joinClassNames.js";
|
|
6
6
|
const toolbarActiveStateIsEqual = (left, right) => {
|
|
7
7
|
if (!right) {
|
|
@@ -13,6 +13,7 @@ const toolbarActiveStateIsEqual = (left, right) => {
|
|
|
13
13
|
left.codeBlock === right.codeBlock &&
|
|
14
14
|
left.heading1 === right.heading1 &&
|
|
15
15
|
left.heading2 === right.heading2 &&
|
|
16
|
+
left.heading3 === right.heading3 &&
|
|
16
17
|
left.italic === right.italic &&
|
|
17
18
|
left.link === right.link &&
|
|
18
19
|
left.orderedList === right.orderedList &&
|
|
@@ -27,6 +28,7 @@ const useToolbarActiveState = (editor) => useEditorState({
|
|
|
27
28
|
codeBlock: currentEditor.isActive("codeBlock"),
|
|
28
29
|
heading1: currentEditor.isActive("heading", { level: 1 }),
|
|
29
30
|
heading2: currentEditor.isActive("heading", { level: 2 }),
|
|
31
|
+
heading3: currentEditor.isActive("heading", { level: 3 }),
|
|
30
32
|
italic: currentEditor.isActive("italic"),
|
|
31
33
|
link: currentEditor.isActive("link"),
|
|
32
34
|
orderedList: currentEditor.isActive("orderedList"),
|
|
@@ -80,5 +82,5 @@ export const MarkdownBubbleMenu = ({ editor }) => {
|
|
|
80
82
|
const activeState = useToolbarActiveState(editor);
|
|
81
83
|
return (_jsxs(BubbleMenu, { className: "mp-lb-mdkit-toolbar", editor: editor, options: {
|
|
82
84
|
placement: "top",
|
|
83
|
-
}, shouldShow: shouldShowMarkdownBubbleMenu, children: [_jsx(ToolbarButton, { ariaLabel: "Bold", isActive: activeState.bold, onAction: () => editor.chain().focus().toggleBold().run(), children: _jsx(Bold, {}) }), _jsx(ToolbarButton, { ariaLabel: "Italic", isActive: activeState.italic, onAction: () => editor.chain().focus().toggleItalic().run(), children: _jsx(Italic, {}) }), _jsx(ToolbarButton, { ariaLabel: "Strikethrough", isActive: activeState.strike, onAction: () => editor.chain().focus().toggleStrike().run(), children: _jsx(Strikethrough, {}) }), _jsx(ToolbarButton, { ariaLabel: "Code block", isActive: activeState.codeBlock, onAction: () => editor.chain().focus().toggleCodeBlock().run(), children: _jsx(Code2, {}) }), _jsx("div", { className: "mp-lb-mdkit-toolbar-divider" }), _jsx(ToolbarButton, { ariaLabel: "Heading 1", isActive: activeState.heading1, onAction: () => editor.chain().focus().toggleHeading({ level: 1 }).run(), children: _jsx(Heading1, {}) }), _jsx(ToolbarButton, { ariaLabel: "Heading 2", isActive: activeState.heading2, onAction: () => editor.chain().focus().toggleHeading({ level: 2 }).run(), children: _jsx(Heading2, {}) }), _jsx("div", { className: "mp-lb-mdkit-toolbar-divider" }), _jsx(ToolbarButton, { ariaLabel: "Bullet list", isActive: activeState.bulletList, onAction: () => editor.chain().focus().toggleBulletList().run(), children: _jsx(List, {}) }), _jsx(ToolbarButton, { ariaLabel: "Ordered list", isActive: activeState.orderedList, onAction: () => editor.chain().focus().toggleOrderedList().run(), children: _jsx(ListOrdered, {}) }), _jsx(ToolbarButton, { ariaLabel: "Blockquote", isActive: activeState.blockquote, onAction: () => editor.chain().focus().toggleBlockquote().run(), children: _jsx(Quote, {}) }), _jsx("div", { className: "mp-lb-mdkit-toolbar-divider" }), _jsx(ToolbarButton, { ariaLabel: "Link", isActive: activeState.link, onAction: () => setLink(editor), children: _jsx(Link2, {}) })] }));
|
|
85
|
+
}, shouldShow: shouldShowMarkdownBubbleMenu, children: [_jsx(ToolbarButton, { ariaLabel: "Bold", isActive: activeState.bold, onAction: () => editor.chain().focus().toggleBold().run(), children: _jsx(Bold, {}) }), _jsx(ToolbarButton, { ariaLabel: "Italic", isActive: activeState.italic, onAction: () => editor.chain().focus().toggleItalic().run(), children: _jsx(Italic, {}) }), _jsx(ToolbarButton, { ariaLabel: "Strikethrough", isActive: activeState.strike, onAction: () => editor.chain().focus().toggleStrike().run(), children: _jsx(Strikethrough, {}) }), _jsx(ToolbarButton, { ariaLabel: "Code block", isActive: activeState.codeBlock, onAction: () => editor.chain().focus().toggleCodeBlock().run(), children: _jsx(Code2, {}) }), _jsx("div", { className: "mp-lb-mdkit-toolbar-divider" }), _jsx(ToolbarButton, { ariaLabel: "Heading 1", isActive: activeState.heading1, onAction: () => editor.chain().focus().toggleHeading({ level: 1 }).run(), children: _jsx(Heading1, {}) }), _jsx(ToolbarButton, { ariaLabel: "Heading 2", isActive: activeState.heading2, onAction: () => editor.chain().focus().toggleHeading({ level: 2 }).run(), children: _jsx(Heading2, {}) }), _jsx(ToolbarButton, { ariaLabel: "Heading 3", isActive: activeState.heading3, onAction: () => editor.chain().focus().toggleHeading({ level: 3 }).run(), children: _jsx(Heading3, {}) }), _jsx("div", { className: "mp-lb-mdkit-toolbar-divider" }), _jsx(ToolbarButton, { ariaLabel: "Bullet list", isActive: activeState.bulletList, onAction: () => editor.chain().focus().toggleBulletList().run(), children: _jsx(List, {}) }), _jsx(ToolbarButton, { ariaLabel: "Ordered list", isActive: activeState.orderedList, onAction: () => editor.chain().focus().toggleOrderedList().run(), children: _jsx(ListOrdered, {}) }), _jsx(ToolbarButton, { ariaLabel: "Blockquote", isActive: activeState.blockquote, onAction: () => editor.chain().focus().toggleBlockquote().run(), children: _jsx(Quote, {}) }), _jsx("div", { className: "mp-lb-mdkit-toolbar-divider" }), _jsx(ToolbarButton, { ariaLabel: "Link", isActive: activeState.link, onAction: () => setLink(editor), children: _jsx(Link2, {}) })] }));
|
|
84
86
|
};
|
|
@@ -18,6 +18,7 @@ const describeElement = (element) => {
|
|
|
18
18
|
};
|
|
19
19
|
const describeEventTarget = (target) => target instanceof Element ? describeElement(target) : String(target);
|
|
20
20
|
const isInteractiveElement = (target) => !!target.closest("a,button,input,select,textarea,[contenteditable='false']");
|
|
21
|
+
const isNativeFocusTarget = (target) => !!target.closest("a[href],button,input,select,textarea,[contenteditable='true'],[tabindex]:not([tabindex='-1'])");
|
|
21
22
|
const createEditorDebugSnapshot = (editor, phase) => {
|
|
22
23
|
const activeElement = typeof document === "undefined" || !document.activeElement
|
|
23
24
|
? null
|
|
@@ -344,6 +345,9 @@ export const TiptapMarkdownSurface = (props) => {
|
|
|
344
345
|
if (editor.isDestroyed) {
|
|
345
346
|
return;
|
|
346
347
|
}
|
|
348
|
+
if (!editor.isFocused && !editor.view.hasFocus()) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
347
351
|
const target = event.target;
|
|
348
352
|
if (!(target instanceof Element)) {
|
|
349
353
|
return;
|
|
@@ -352,6 +356,9 @@ export const TiptapMarkdownSurface = (props) => {
|
|
|
352
356
|
target.closest(".mp-lb-mdkit-toolbar")) {
|
|
353
357
|
return;
|
|
354
358
|
}
|
|
359
|
+
if (isNativeFocusTarget(target)) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
355
362
|
editor.commands.blur();
|
|
356
363
|
};
|
|
357
364
|
document.addEventListener("pointerdown", blurEditorOnExternalPointerDown, {
|
|
@@ -6,7 +6,7 @@ import { MarkdownSearchExtension } from "./MarkdownSearchExtension.js";
|
|
|
6
6
|
export const defaultMdKitMarkdownPlaceholder = "Start writing...";
|
|
7
7
|
export const createMdKitTiptapExtensions = ({ placeholder = defaultMdKitMarkdownPlaceholder, undoRedo = true, } = {}) => [
|
|
8
8
|
StarterKit.configure({
|
|
9
|
-
heading: { levels: [1, 2] },
|
|
9
|
+
heading: { levels: [1, 2, 3, 4, 5, 6] },
|
|
10
10
|
link: {
|
|
11
11
|
HTMLAttributes: {
|
|
12
12
|
rel: "noopener noreferrer",
|