@mdxeditor/editor 3.41.0 → 3.42.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/dist/defaultSvgIcons.js +19 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +2 -0
- package/dist/plugins/core/LexicalTextVisitor.js +14 -2
- package/dist/plugins/core/MdastFormattingVisitor.js +10 -1
- package/dist/plugins/core/index.js +5 -3
- package/dist/plugins/toolbar/components/HighlightToggle.js +28 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +2 -1
- package/package.json +3 -1
package/dist/defaultSvgIcons.js
CHANGED
|
@@ -35,6 +35,25 @@ const defaultSvgIcons = {
|
|
|
35
35
|
fill: "currentColor"
|
|
36
36
|
}
|
|
37
37
|
)),
|
|
38
|
+
format_highlight: (
|
|
39
|
+
/* taken from from https://lucide.dev/icons/highlighter */
|
|
40
|
+
/* @__PURE__ */ React__default.createElement(
|
|
41
|
+
"svg",
|
|
42
|
+
{
|
|
43
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
44
|
+
width: "24",
|
|
45
|
+
height: "24",
|
|
46
|
+
viewBox: "0 0 24 24",
|
|
47
|
+
fill: "none",
|
|
48
|
+
stroke: "currentColor",
|
|
49
|
+
strokeWidth: "1.75",
|
|
50
|
+
strokeLinecap: "round",
|
|
51
|
+
strokeLinejoin: "round"
|
|
52
|
+
},
|
|
53
|
+
/* @__PURE__ */ React__default.createElement("path", { d: "m9 11-6 6v3h9l3-3" }),
|
|
54
|
+
/* @__PURE__ */ React__default.createElement("path", { d: "m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4" })
|
|
55
|
+
)
|
|
56
|
+
),
|
|
38
57
|
code: /* @__PURE__ */ React__default.createElement("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React__default.createElement(
|
|
39
58
|
"path",
|
|
40
59
|
{
|
package/dist/index.d.ts
CHANGED
|
@@ -822,6 +822,7 @@ export declare const defaultSvgIcons: {
|
|
|
822
822
|
format_bold: default_2.JSX.Element;
|
|
823
823
|
format_italic: default_2.JSX.Element;
|
|
824
824
|
format_underlined: default_2.JSX.Element;
|
|
825
|
+
format_highlight: default_2.JSX.Element;
|
|
825
826
|
code: default_2.JSX.Element;
|
|
826
827
|
strikeThrough: default_2.JSX.Element;
|
|
827
828
|
superscript: default_2.JSX.Element;
|
|
@@ -1342,6 +1343,12 @@ export declare const headingsPlugin: (params?: {
|
|
|
1342
1343
|
allowedHeadingLevels?: readonly HEADING_LEVEL[] | undefined;
|
|
1343
1344
|
} | undefined) => RealmPlugin;
|
|
1344
1345
|
|
|
1346
|
+
/**
|
|
1347
|
+
* A toolbar component that lets the user toggle highlight formatting.
|
|
1348
|
+
* @group Toolbar Components
|
|
1349
|
+
*/
|
|
1350
|
+
export declare const HighlightToggle: default_2.FC;
|
|
1351
|
+
|
|
1345
1352
|
/* Excluded from this release type: historyState$ */
|
|
1346
1353
|
|
|
1347
1354
|
/**
|
|
@@ -1356,7 +1363,7 @@ export declare const htmlTags: string[];
|
|
|
1356
1363
|
*/
|
|
1357
1364
|
export declare const iconComponentFor$: NodeRef<(name: IconKey) => default_2.ReactNode>;
|
|
1358
1365
|
|
|
1359
|
-
export declare type IconKey = 'undo' | 'redo' | 'format_bold' | 'format_italic' | 'format_underlined' | 'code' | 'strikeThrough' | 'superscript' | 'subscript' | 'format_list_bulleted' | 'format_list_numbered' | 'format_list_checked' | 'link' | 'add_photo' | 'table' | 'horizontal_rule' | 'frontmatter' | 'frame_source' | 'arrow_drop_down' | 'admonition' | 'sandpack' | 'rich_text' | 'difference' | 'markdown' | 'open_in_new' | 'link_off' | 'edit' | 'content_copy' | 'more_horiz' | 'more_vert' | 'close' | 'settings' | 'delete_big' | 'delete_small' | 'format_align_center' | 'format_align_left' | 'format_align_right' | 'add_row' | 'add_column' | 'insert_col_left' | 'insert_row_above' | 'insert_row_below' | 'insert_col_right' | 'check';
|
|
1366
|
+
export declare type IconKey = 'undo' | 'redo' | 'format_bold' | 'format_italic' | 'format_underlined' | 'code' | 'strikeThrough' | 'superscript' | 'subscript' | 'format_list_bulleted' | 'format_list_numbered' | 'format_list_checked' | 'format_highlight' | 'link' | 'add_photo' | 'table' | 'horizontal_rule' | 'frontmatter' | 'frame_source' | 'arrow_drop_down' | 'admonition' | 'sandpack' | 'rich_text' | 'difference' | 'markdown' | 'open_in_new' | 'link_off' | 'edit' | 'content_copy' | 'more_horiz' | 'more_vert' | 'close' | 'settings' | 'delete_big' | 'delete_small' | 'format_align_center' | 'format_align_left' | 'format_align_right' | 'add_row' | 'add_column' | 'insert_col_left' | 'insert_row_above' | 'insert_row_below' | 'insert_col_right' | 'check';
|
|
1360
1367
|
|
|
1361
1368
|
/**
|
|
1362
1369
|
* Holds the autocomplete suggestions for image sources.
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ import { BoldItalicUnderlineToggles, StrikeThroughSupSubToggles } from "./plugin
|
|
|
34
34
|
import { ChangeAdmonitionType, admonitionLabelsMap } from "./plugins/toolbar/components/ChangeAdmonitionType.js";
|
|
35
35
|
import { ChangeCodeMirrorLanguage } from "./plugins/toolbar/components/ChangeCodeMirrorLanguage.js";
|
|
36
36
|
import { CodeToggle } from "./plugins/toolbar/components/CodeToggle.js";
|
|
37
|
+
import { HighlightToggle } from "./plugins/toolbar/components/HighlightToggle.js";
|
|
37
38
|
import { CreateLink } from "./plugins/toolbar/components/CreateLink.js";
|
|
38
39
|
import { DiffSourceToggleWrapper } from "./plugins/toolbar/components/DiffSourceToggleWrapper.js";
|
|
39
40
|
import { InsertAdmonition } from "./plugins/toolbar/components/InsertAdmonition.js";
|
|
@@ -114,6 +115,7 @@ export {
|
|
|
114
115
|
GenericDirectiveEditor,
|
|
115
116
|
GenericHTMLNode,
|
|
116
117
|
GenericJsxEditor,
|
|
118
|
+
HighlightToggle,
|
|
117
119
|
INSERT_IMAGE_COMMAND,
|
|
118
120
|
IS_APPLE,
|
|
119
121
|
IS_BOLD,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { $isTextNode } from "lexical";
|
|
2
|
-
import { IS_UNDERLINE, IS_SUPERSCRIPT, IS_SUBSCRIPT, IS_ITALIC, IS_BOLD, IS_STRIKETHROUGH, IS_CODE } from "../../FormatConstants.js";
|
|
2
|
+
import { IS_UNDERLINE, IS_SUPERSCRIPT, IS_SUBSCRIPT, IS_ITALIC, IS_BOLD, IS_STRIKETHROUGH, IS_HIGHLIGHT, IS_CODE } from "../../FormatConstants.js";
|
|
3
3
|
function isMdastText(mdastNode) {
|
|
4
4
|
return mdastNode.type === "text";
|
|
5
5
|
}
|
|
6
6
|
const JOINABLE_TAGS = ["u", "span", "sub", "sup"];
|
|
7
7
|
const LexicalTextVisitor = {
|
|
8
8
|
shouldJoin: (prevNode, currentNode) => {
|
|
9
|
-
if (["text", "emphasis", "strong"].includes(prevNode.type)) {
|
|
9
|
+
if (["text", "emphasis", "strong", "highlight"].includes(prevNode.type)) {
|
|
10
10
|
return prevNode.type === currentNode.type;
|
|
11
11
|
}
|
|
12
12
|
if (prevNode.type === "mdxJsxTextElement" && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -87,6 +87,12 @@ const LexicalTextVisitor = {
|
|
|
87
87
|
children: []
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
+
if (prevFormat & format & IS_HIGHLIGHT) {
|
|
91
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
92
|
+
type: "highlight",
|
|
93
|
+
children: []
|
|
94
|
+
});
|
|
95
|
+
}
|
|
90
96
|
if (format & IS_UNDERLINE && !(prevFormat & IS_UNDERLINE)) {
|
|
91
97
|
localParentNode = actions.appendToParent(localParentNode, {
|
|
92
98
|
type: "mdxJsxTextElement",
|
|
@@ -129,6 +135,12 @@ const LexicalTextVisitor = {
|
|
|
129
135
|
children: []
|
|
130
136
|
});
|
|
131
137
|
}
|
|
138
|
+
if (format & IS_HIGHLIGHT && !(prevFormat & IS_HIGHLIGHT)) {
|
|
139
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
140
|
+
type: "highlight",
|
|
141
|
+
children: []
|
|
142
|
+
});
|
|
143
|
+
}
|
|
132
144
|
if (format & IS_CODE) {
|
|
133
145
|
actions.appendToParent(localParentNode, {
|
|
134
146
|
type: "inlineCode",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IS_ITALIC, IS_BOLD, IS_CODE, IS_STRIKETHROUGH, IS_UNDERLINE, IS_SUPERSCRIPT, IS_SUBSCRIPT } from "../../FormatConstants.js";
|
|
1
|
+
import { IS_ITALIC, IS_BOLD, IS_CODE, IS_STRIKETHROUGH, IS_HIGHLIGHT, IS_UNDERLINE, IS_SUPERSCRIPT, IS_SUBSCRIPT } from "../../FormatConstants.js";
|
|
2
2
|
import { $createTextNode } from "lexical";
|
|
3
3
|
function buildFormattingVisitors(tag, format) {
|
|
4
4
|
return [
|
|
@@ -30,6 +30,13 @@ const StrikeThroughVisitor = {
|
|
|
30
30
|
actions.visitChildren(mdastNode, lexicalParent);
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
+
const HighlightVisitor = {
|
|
34
|
+
testNode: "highlight",
|
|
35
|
+
visitNode({ mdastNode, actions, lexicalParent }) {
|
|
36
|
+
actions.addFormatting(IS_HIGHLIGHT);
|
|
37
|
+
actions.visitChildren(mdastNode, lexicalParent);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
33
40
|
const MdCodeVisitor = {
|
|
34
41
|
testNode: "inlineCode",
|
|
35
42
|
visitNode({ mdastNode, actions }) {
|
|
@@ -62,6 +69,8 @@ const formattingVisitors = [
|
|
|
62
69
|
MdCodeVisitor,
|
|
63
70
|
// strikethrough
|
|
64
71
|
StrikeThroughVisitor,
|
|
72
|
+
// highlight
|
|
73
|
+
HighlightVisitor,
|
|
65
74
|
// superscript
|
|
66
75
|
...buildFormattingVisitors("sup", IS_SUPERSCRIPT),
|
|
67
76
|
// subscript
|
|
@@ -7,7 +7,9 @@ import { Cell, Signal, withLatestFrom, filter, useCellValue, scan, map } from "@
|
|
|
7
7
|
import { createCommand, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getRoot, $setSelection, $getSelection, $insertNodes, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, DecoratorNode, $createParagraphNode, FOCUS_COMMAND, BLUR_COMMAND, $isRangeSelection, createEditor, ParagraphNode, TextNode } from "lexical";
|
|
8
8
|
import { gfmStrikethrough } from "micromark-extension-gfm-strikethrough";
|
|
9
9
|
import { gfmStrikethroughToMarkdown, gfmStrikethroughFromMarkdown } from "mdast-util-gfm-strikethrough";
|
|
10
|
+
import { highlightMarkToMarkdown, highlightMarkFromMarkdown } from "mdast-util-highlight-mark";
|
|
10
11
|
import { mdxJsxToMarkdown, mdxJsxFromMarkdown } from "mdast-util-mdx-jsx";
|
|
12
|
+
import { highlightMark } from "micromark-extension-highlight-mark";
|
|
11
13
|
import { mdxJsx } from "micromark-extension-mdx-jsx";
|
|
12
14
|
import { mdxMd } from "micromark-extension-mdx-md";
|
|
13
15
|
import { exportMarkdownFromLexical } from "../../exportMarkdownFromLexical.js";
|
|
@@ -516,9 +518,9 @@ const corePlugin = realmPlugin({
|
|
|
516
518
|
[placeholder$]: params == null ? void 0 : params.placeholder,
|
|
517
519
|
[readOnly$]: params == null ? void 0 : params.readOnly,
|
|
518
520
|
[translation$]: params == null ? void 0 : params.translation,
|
|
519
|
-
[addMdastExtension$]: gfmStrikethroughFromMarkdown(),
|
|
520
|
-
[addSyntaxExtension$]: gfmStrikethrough(),
|
|
521
|
-
[addToMarkdownExtension$]: [mdxJsxToMarkdown(), gfmStrikethroughToMarkdown()],
|
|
521
|
+
[addMdastExtension$]: [gfmStrikethroughFromMarkdown(), highlightMarkFromMarkdown],
|
|
522
|
+
[addSyntaxExtension$]: [gfmStrikethrough(), highlightMark()],
|
|
523
|
+
[addToMarkdownExtension$]: [mdxJsxToMarkdown(), gfmStrikethroughToMarkdown(), highlightMarkToMarkdown],
|
|
522
524
|
[lexicalTheme$]: (params == null ? void 0 : params.lexicalTheme) ?? lexicalTheme
|
|
523
525
|
});
|
|
524
526
|
r.singletonSub(markdownErrorSignal$, params == null ? void 0 : params.onError);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import { IS_HIGHLIGHT } from "../../../FormatConstants.js";
|
|
3
|
+
import { currentFormat$, iconComponentFor$, applyFormat$, useTranslation } from "../../core/index.js";
|
|
4
|
+
import { MultipleChoiceToggleGroup } from "../primitives/toolbar.js";
|
|
5
|
+
import { useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
6
|
+
const HighlightToggle = () => {
|
|
7
|
+
const [currentFormat, iconComponentFor] = useCellValues(currentFormat$, iconComponentFor$);
|
|
8
|
+
const applyFormat = usePublisher(applyFormat$);
|
|
9
|
+
const t = useTranslation();
|
|
10
|
+
const highlightIsOn = (currentFormat & IS_HIGHLIGHT) !== 0;
|
|
11
|
+
const title = highlightIsOn ? t("toolbar.removeHighlight", "Remove highlight") : t("toolbar.highlight", "Highlight");
|
|
12
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
13
|
+
MultipleChoiceToggleGroup,
|
|
14
|
+
{
|
|
15
|
+
items: [
|
|
16
|
+
{
|
|
17
|
+
title,
|
|
18
|
+
contents: iconComponentFor("format_highlight"),
|
|
19
|
+
active: highlightIsOn,
|
|
20
|
+
onChange: applyFormat.bind(null, "highlight")
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
HighlightToggle
|
|
28
|
+
};
|
|
@@ -17,6 +17,7 @@ import { ListsToggle } from "./ListsToggle.js";
|
|
|
17
17
|
import { ShowSandpackInfo } from "./ShowSandpackInfo.js";
|
|
18
18
|
import { UndoRedo } from "./UndoRedo.js";
|
|
19
19
|
import { CreateLink } from "./CreateLink.js";
|
|
20
|
+
import { HighlightToggle } from "./HighlightToggle.js";
|
|
20
21
|
function whenInAdmonition(editorInFocus) {
|
|
21
22
|
const node = editorInFocus == null ? void 0 : editorInFocus.rootNode;
|
|
22
23
|
if (!node || node.getType() !== "directive") {
|
|
@@ -32,7 +33,7 @@ const KitchenSinkToolbar = () => {
|
|
|
32
33
|
{ when: (editor) => (editor == null ? void 0 : editor.editorType) === "codeblock", contents: () => /* @__PURE__ */ React__default.createElement(ChangeCodeMirrorLanguage, null) },
|
|
33
34
|
{ when: (editor) => (editor == null ? void 0 : editor.editorType) === "sandpack", contents: () => /* @__PURE__ */ React__default.createElement(ShowSandpackInfo, null) },
|
|
34
35
|
{
|
|
35
|
-
fallback: () => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(UndoRedo, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(BoldItalicUnderlineToggles, null), /* @__PURE__ */ React__default.createElement(CodeToggle, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(StrikeThroughSupSubToggles, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(ListsToggle, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(
|
|
36
|
+
fallback: () => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(UndoRedo, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(BoldItalicUnderlineToggles, null), /* @__PURE__ */ React__default.createElement(CodeToggle, null), /* @__PURE__ */ React__default.createElement(HighlightToggle, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(StrikeThroughSupSubToggles, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(ListsToggle, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(
|
|
36
37
|
ConditionalContents,
|
|
37
38
|
{
|
|
38
39
|
options: [{ when: whenInAdmonition, contents: () => /* @__PURE__ */ React__default.createElement(ChangeAdmonitionType, null) }, { fallback: () => /* @__PURE__ */ React__default.createElement(BlockTypeSelect, null) }]
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"*.css"
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
|
-
"version": "3.
|
|
14
|
+
"version": "3.42.0",
|
|
15
15
|
"description": "React component for rich text markdown editing",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "vite build",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"mdast-util-gfm-strikethrough": "^2.0.0",
|
|
76
76
|
"mdast-util-gfm-table": "^2.0.0",
|
|
77
77
|
"mdast-util-gfm-task-list-item": "^2.0.0",
|
|
78
|
+
"mdast-util-highlight-mark": "^1.2.2",
|
|
78
79
|
"mdast-util-mdx": "^3.0.0",
|
|
79
80
|
"mdast-util-mdx-jsx": "^3.0.0",
|
|
80
81
|
"mdast-util-to-markdown": "^2.1.0",
|
|
@@ -83,6 +84,7 @@
|
|
|
83
84
|
"micromark-extension-gfm-strikethrough": "^2.0.0",
|
|
84
85
|
"micromark-extension-gfm-table": "^2.0.0",
|
|
85
86
|
"micromark-extension-gfm-task-list-item": "^2.0.1",
|
|
87
|
+
"micromark-extension-highlight-mark": "^1.2.0",
|
|
86
88
|
"micromark-extension-mdx-jsx": "^3.0.0",
|
|
87
89
|
"micromark-extension-mdx-md": "^2.0.0",
|
|
88
90
|
"micromark-extension-mdxjs": "^3.0.0",
|