@mp-lb/mdkit 0.2.0 → 0.2.1-main.15.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,6 +1,9 @@
1
1
  import { type Editor } from "@tiptap/react";
2
+ import { type BubbleMenuProps } from "@tiptap/react/menus";
2
3
  type MarkdownBubbleMenuProps = {
3
4
  editor: Editor;
4
5
  };
6
+ type BubbleMenuShouldShowProps = Parameters<NonNullable<BubbleMenuProps["shouldShow"]>>[0];
7
+ export declare const shouldShowMarkdownBubbleMenu: ({ editor, element, from, state, to, view, }: BubbleMenuShouldShowProps) => boolean;
5
8
  export declare const MarkdownBubbleMenu: ({ editor }: MarkdownBubbleMenuProps) => import("react/jsx-runtime").JSX.Element;
6
9
  export {};
@@ -34,6 +34,14 @@ const useToolbarActiveState = (editor) => useEditorState({
34
34
  }),
35
35
  equalityFn: toolbarActiveStateIsEqual,
36
36
  });
37
+ export const shouldShowMarkdownBubbleMenu = ({ editor, element, from, state, to, view, }) => {
38
+ const editorHasFocus = view.hasFocus() || element.contains(document.activeElement);
39
+ const selectedText = state.doc.textBetween(from, to);
40
+ return (editor.isEditable &&
41
+ editorHasFocus &&
42
+ !state.selection.empty &&
43
+ selectedText.length > 0);
44
+ };
37
45
  const setLink = (editor) => {
38
46
  const previousUrl = editor.getAttributes("link").href;
39
47
  const nextUrl = window.prompt("URL", previousUrl);
@@ -72,8 +80,5 @@ export const MarkdownBubbleMenu = ({ editor }) => {
72
80
  const activeState = useToolbarActiveState(editor);
73
81
  return (_jsxs(BubbleMenu, { className: "mp-lb-mdkit-toolbar", editor: editor, options: {
74
82
  placement: "top",
75
- }, shouldShow: ({ editor: currentEditor, state }) => {
76
- const { empty } = state.selection;
77
- return currentEditor.isEditable && !empty;
78
- }, 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, {}) })] }));
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, {}) })] }));
79
84
  };
package/docs/styling.md CHANGED
@@ -119,7 +119,8 @@ you need structural changes, component-specific spacing, or state styling.
119
119
  ### Editor
120
120
 
121
121
  `MdKitEditor` renders the markdown editing surface and the selection bubble
122
- toolbar.
122
+ toolbar. The toolbar appears for non-empty text selections while the editor or
123
+ toolbar has focus.
123
124
 
124
125
  - `.mp-lb-mdkit-markdown-editor`: root element rendered by `MdKitEditor`
125
126
  - `.mp-lb-mdkit-markdown-editor-fill-height`: added to the root when
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mp-lb/mdkit",
3
- "version": "0.2.0",
3
+ "version": "0.2.1-main.15.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/styles.css CHANGED
@@ -142,6 +142,26 @@
142
142
  flex: 1 1 auto;
143
143
  }
144
144
 
145
+ .mp-lb-mdkit-markdown-view.mp-lb-mdkit-markdown-editor-fill-height
146
+ .mp-lb-mdkit-editor-shell {
147
+ height: auto;
148
+ min-height: 100%;
149
+ overflow: visible;
150
+ }
151
+
152
+ .mp-lb-mdkit-markdown-view.mp-lb-mdkit-markdown-editor-fill-height
153
+ .mp-lb-mdkit-editor-surface {
154
+ overflow: visible;
155
+ }
156
+
157
+ .mp-lb-mdkit-markdown-view.mp-lb-mdkit-markdown-editor-fill-height
158
+ .mp-lb-mdkit-view-content {
159
+ display: block;
160
+ height: auto;
161
+ min-height: 100%;
162
+ flex: 0 0 auto;
163
+ }
164
+
145
165
  .mp-lb-mdkit-tiptap > * + * {
146
166
  margin-top: var(--mp-lb-mdkit-block-gap);
147
167
  }