@meowdown/react 0.21.1 → 0.22.0

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/README.md CHANGED
@@ -43,8 +43,9 @@ The Markdown editor component. Renders inside a `div.meowdown` wrapper that fill
43
43
  - `onDocChange?: VoidFunction`: called on every user-driven document change. Programmatic `setMarkdown` / `setState` on the handle do not fire it.
44
44
  - `onTagSearch?: (query: string) => TagItem[] | Promise<TagItem[]>`: enables the tag menu, which opens when typing `#` followed by text in a rich mode. Returns ranked rows `{ tag, label?, detail?, onSelect? }` (the menu does not re-sort). Selecting a row inserts `#tag ` then runs its `onSelect`. Omit to disable.
45
45
  - `onWikilinkSearch?: (query: string) => WikilinkItem[] | Promise<WikilinkItem[]>`: enables the wikilink menu, which opens as soon as `[[` or `@` is typed, or `Mod-Shift-k` is pressed, in a rich mode; the shortcut seeds the query from any selected text. Returns ranked rows `{ target, label?, detail?, onSelect? }` (the menu does not re-sort). Selecting a row inserts `[[target]]` then runs its `onSelect`. Omit to disable.
46
- - `onWikilinkClick?: (payload: { target: string; event: MouseEvent }) => void`: called when a rendered wiki link is clicked. A plain click inside a link the caret already sits in just places the caret; `Mod`-click always fires. Pass a stable function (e.g. from `useCallback`). Ignored in source mode.
47
- - `onLinkClick?: (payload: { href: string; event: MouseEvent }) => void`: called with its `href` when a rendered Markdown link (`[text](url)`) is clicked. A plain click inside a link the caret already sits in just places the caret; `Mod`-click always fires. Pass a stable function (e.g. from `useCallback`). Ignored in source mode.
46
+ - `onWikilinkClick?: (payload: { target: string; event: MouseEvent }) => void`: called when a rendered wiki link is clicked. Pass a stable function (e.g. from `useCallback`). Ignored in source mode.
47
+ - `onLinkClick?: (payload: { href: string; event: MouseEvent }) => void`: called with its `href` when a rendered Markdown link (`[text](url)`) is clicked. Pass a stable function (e.g. from `useCallback`). Ignored in source mode.
48
+ - `onTagClick?: (payload: { tag: string; event: MouseEvent }) => void`: called with the tag name (without the leading `#`) when a rendered `#tag` is clicked. Pass a stable function (e.g. from `useCallback`). Ignored in source mode.
48
49
  - `resolveImageUrl?: (src: string) => string | undefined`: maps an image `src` to a displayable URL (or `undefined` to skip). Enables inline image rendering: `![alt](src)` stays literal text and the image renders beneath its line. Pass a stable function. Ignored in source mode.
49
50
  - `onImagePaste?: (file: File) => string | undefined | Promise<string | undefined>`: persists a pasted or dropped image file and returns its markdown `src` (or `undefined` to decline), synchronously or as a promise. Pass a stable function. Ignored in source mode.
50
51
  - `onImageSaveError?: (error: unknown, file: File) => void`: called when `onImagePaste` throws. Defaults to `console.error`. Ignored in source mode.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactElement, ReactNode, Ref } from "react";
2
- import { ImageClickHandler, ImageOptions, LinkClickHandler, MarkMode, PlaceholderOptions, TypedEditor, WikilinkClickHandler } from "@meowdown/core";
2
+ import { ImageClickHandler, ImageOptions, LinkClickHandler, MarkMode, PlaceholderOptions, TagClickHandler, TypedEditor, WikilinkClickHandler } from "@meowdown/core";
3
3
  import { SelectionJSON, SelectionJSON as SelectionJSON$1 } from "@prosekit/core";
4
4
  import { useEditor, useExtension, useKeymap } from "@prosekit/react";
5
5
 
@@ -120,11 +120,16 @@ interface EditorProps {
120
120
  onWikilinkClick?: WikilinkClickHandler;
121
121
  /**
122
122
  * Called with the link `href` on click of a rendered Markdown link
123
- * (`[text](url)`). A plain click inside a link the caret already sits in just
124
- * places the caret; `Mod`-click always fires. Pass a stable function (e.g.
125
- * from `useCallback`). Ignored in source mode.
123
+ * (`[text](url)`). Pass a stable function (e.g. from `useCallback`). Ignored
124
+ * in source mode.
126
125
  */
127
126
  onLinkClick?: LinkClickHandler;
127
+ /**
128
+ * Called with the tag name (without the leading `#`) on click of a rendered
129
+ * `#tag`. Pass a stable function (e.g. from `useCallback`). Ignored in source
130
+ * mode.
131
+ */
132
+ onTagClick?: TagClickHandler;
128
133
  /**
129
134
  * Maps an image `src` to a displayable URL, or `undefined` to skip that image.
130
135
  * Defaults to showing http(s) URLs as-is. Pass a stable function (e.g. from
@@ -194,6 +199,7 @@ declare function MeowdownEditor({
194
199
  onWikilinkSearch,
195
200
  onWikilinkClick,
196
201
  onLinkClick,
202
+ onTagClick,
197
203
  resolveImageUrl,
198
204
  onImagePaste,
199
205
  onImageSaveError,
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { Compartment, EditorSelection, EditorState } from "@codemirror/state";
7
7
  import { EditorView, keymap } from "@codemirror/view";
8
8
  import { clamp } from "@ocavue/utils";
9
9
  import { jsx, jsxs } from "react/jsx-runtime";
10
- import { codeBlockLanguages, defaultResolveImageUrl, defineBulletAfterHeading, defineEditorExtension, defineEmbedPaste, defineHTMLPaste, defineImage, defineImageClickHandler, defineLinkClickHandler, defineMarkMode, defineMarkdownCopy, definePlaceholder, defineReadonly, defineWikilinkClickHandler, defineWikilinkTrigger, docToMarkdown, getCodeTokens, getMarkBuilders, inlineTextToMarkChunks, listenForTweetHeight, markdownToDoc, matchEmbed } from "@meowdown/core";
10
+ import { codeBlockLanguages, defaultResolveImageUrl, defineBulletAfterHeading, defineEditorExtension, defineEmbedPaste, defineHTMLPaste, defineImage, defineImageClickHandler, defineLinkClickHandler, defineMarkMode, defineMarkdownCopy, definePlaceholder, defineReadonly, defineTagClickHandler, defineWikilinkClickHandler, defineWikilinkTrigger, docToMarkdown, getCodeTokens, getMarkBuilders, inlineTextToMarkChunks, listenForTweetHeight, markdownToDoc, matchEmbed } from "@meowdown/core";
11
11
  import { canUseRegexLookbehind, createEditor, defineDocChangeHandler, union } from "@prosekit/core";
12
12
  import { Selection, TextSelection } from "@prosekit/pm/state";
13
13
  import { ProseKit, defineReactNodeView, useEditor, useEditor as useEditor$1, useEditorDerivedValue, useExtension, useExtension as useExtension$1, useKeymap } from "@prosekit/react";
@@ -320,7 +320,7 @@ function DropIndicator$1() {
320
320
 
321
321
  //#endregion
322
322
  //#region src/components/editor-extensions.tsx
323
- function EditorExtensions({ markMode, onDocChange, onWikilinkClick, onLinkClick, resolveImageUrl, onImagePaste, onImageSaveError, onImageClick, embedPaste, bulletAfterHeading, placeholder, readOnly, wikilinkEnabled }) {
323
+ function EditorExtensions({ markMode, onDocChange, onWikilinkClick, onLinkClick, onTagClick, resolveImageUrl, onImagePaste, onImageSaveError, onImageClick, embedPaste, bulletAfterHeading, placeholder, readOnly, wikilinkEnabled }) {
324
324
  useExtension$1(useMemo(() => {
325
325
  return defineMarkMode(markMode);
326
326
  }, [markMode]));
@@ -336,6 +336,9 @@ function EditorExtensions({ markMode, onDocChange, onWikilinkClick, onLinkClick,
336
336
  useExtension$1(useMemo(() => {
337
337
  return onLinkClick ? defineLinkClickHandler(onLinkClick) : null;
338
338
  }, [onLinkClick]));
339
+ useExtension$1(useMemo(() => {
340
+ return onTagClick ? defineTagClickHandler(onTagClick) : null;
341
+ }, [onTagClick]));
339
342
  useExtension$1(useMemo(() => {
340
343
  return defineImage({
341
344
  resolveImageUrl,
@@ -774,7 +777,7 @@ function resolveSelection(doc, selection) {
774
777
  return TextSelection.between(doc.resolve(anchor), doc.resolve(head));
775
778
  }
776
779
  }
777
- function ProseKitEditor({ markMode = "focus", initialMarkdown, onDocChange, onTagSearch, onWikilinkSearch, onWikilinkClick, onLinkClick, resolveImageUrl, onImagePaste, onImageSaveError, onImageClick, embedPaste, bulletAfterHeading, frontmatter = false, blockHandle = true, placeholder, readOnly, spellCheck, editorClassName, ref, children }) {
780
+ function ProseKitEditor({ markMode = "focus", initialMarkdown, onDocChange, onTagSearch, onWikilinkSearch, onWikilinkClick, onLinkClick, onTagClick, resolveImageUrl, onImagePaste, onImageSaveError, onImageClick, embedPaste, bulletAfterHeading, frontmatter = false, blockHandle = true, placeholder, readOnly, spellCheck, editorClassName, ref, children }) {
778
781
  const [editor] = useState(() => {
779
782
  const editor = createEditor({ extension: union(defineEditorExtension(), defineCodeBlockView()) });
780
783
  if (initialMarkdown) editor.setContent(markdownToDoc(initialMarkdown, {
@@ -856,6 +859,7 @@ function ProseKitEditor({ markMode = "focus", initialMarkdown, onDocChange, onTa
856
859
  onDocChange: handleDocChange,
857
860
  onWikilinkClick,
858
861
  onLinkClick,
862
+ onTagClick,
859
863
  resolveImageUrl,
860
864
  onImagePaste,
861
865
  onImageSaveError,
@@ -879,7 +883,7 @@ function ProseKitEditor({ markMode = "focus", initialMarkdown, onDocChange, onTa
879
883
 
880
884
  //#endregion
881
885
  //#region src/components/editor.tsx
882
- function MeowdownEditor({ mode = "focus", initialMarkdown, onDocChange, onTagSearch, onWikilinkSearch, onWikilinkClick, onLinkClick, resolveImageUrl, onImagePaste, onImageSaveError, onImageClick, embedPaste = true, bulletAfterHeading = false, frontmatter = false, blockHandle = true, placeholder, readOnly, spellCheck, editorClassName, wrapperClassName, handleRef, children }) {
886
+ function MeowdownEditor({ mode = "focus", initialMarkdown, onDocChange, onTagSearch, onWikilinkSearch, onWikilinkClick, onLinkClick, onTagClick, resolveImageUrl, onImagePaste, onImageSaveError, onImageClick, embedPaste = true, bulletAfterHeading = false, frontmatter = false, blockHandle = true, placeholder, readOnly, spellCheck, editorClassName, wrapperClassName, handleRef, children }) {
883
887
  const childRef = useRef(null);
884
888
  useImperativeHandle(handleRef, () => {
885
889
  function getMarkdown() {
@@ -945,6 +949,7 @@ function MeowdownEditor({ mode = "focus", initialMarkdown, onDocChange, onTagSea
945
949
  onWikilinkSearch,
946
950
  onWikilinkClick,
947
951
  onLinkClick,
952
+ onTagClick,
948
953
  resolveImageUrl,
949
954
  onImagePaste,
950
955
  onImageSaveError,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meowdown/react",
3
3
  "type": "module",
4
- "version": "0.21.1",
4
+ "version": "0.22.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -30,7 +30,7 @@
30
30
  "@prosekit/react": "^0.8.0-beta.11",
31
31
  "clsx": "^2.1.1",
32
32
  "lucide-react": "^1.21.0",
33
- "@meowdown/core": "0.21.1"
33
+ "@meowdown/core": "0.22.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": "^19.0.0",