@mdxeditor/editor 3.0.8 → 3.1.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.
- package/dist/FormatConstants.js +10 -0
- package/dist/MDXEditor.js +1 -1
- package/dist/directive-editors/GenericDirectiveEditor.js +5 -7
- package/dist/exportMarkdownFromLexical.js +10 -7
- package/dist/icons/strikethrough_s.svg.js +5 -0
- package/dist/icons/subscript.svg.js +5 -0
- package/dist/icons/superscript.svg.js +5 -0
- package/dist/importMarkdownToLexical.js +3 -1
- package/dist/index.d.ts +62 -32
- package/dist/index.js +12 -1
- package/dist/jsx-editors/GenericJsxEditor.js +1 -1
- package/dist/mdastUtilHtmlComment.js +2 -2
- package/dist/node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js +114 -0
- package/dist/node_modules/micromark-util-chunked/index.js +29 -0
- package/dist/node_modules/micromark-util-classify-character/index.js +12 -0
- package/dist/node_modules/micromark-util-resolve-all/index.js +15 -0
- package/dist/plugins/codeblock/index.js +2 -2
- package/dist/plugins/codemirror/index.js +4 -4
- package/dist/plugins/core/Icon.js +6 -0
- package/dist/plugins/core/LexicalTextVisitor.js +49 -4
- package/dist/plugins/core/MdastFormattingVisitor.js +35 -59
- package/dist/plugins/core/MdastHTMLNode.js +1 -2
- package/dist/plugins/core/NestedLexicalEditor.js +1 -1
- package/dist/plugins/core/PropertyPopover.js +28 -18
- package/dist/plugins/core/index.js +34 -29
- package/dist/plugins/core/ui/DownshiftAutoComplete.js +1 -1
- package/dist/plugins/directives/index.js +2 -2
- package/dist/plugins/frontmatter/FrontmatterEditor.js +48 -31
- package/dist/plugins/frontmatter/FrontmatterNode.js +5 -3
- package/dist/plugins/image/ImageDialog.js +1 -1
- package/dist/plugins/image/ImageEditor.js +8 -6
- package/dist/plugins/image/ImageNode.js +2 -2
- package/dist/plugins/image/MdastImageVisitor.js +3 -3
- package/dist/plugins/image/index.js +20 -20
- package/dist/plugins/jsx/index.js +1 -1
- package/dist/plugins/link-dialog/LinkDialog.js +13 -5
- package/dist/plugins/link-dialog/index.js +7 -8
- package/dist/plugins/lists/MdastListVisitor.js +1 -2
- package/dist/plugins/lists/index.js +1 -1
- package/dist/plugins/markdown-shortcut/index.js +4 -2
- package/dist/plugins/sandpack/SandpackEditor.js +1 -1
- package/dist/plugins/sandpack/index.js +2 -2
- package/dist/plugins/sandpack/useCodeMirrorRef.js +8 -8
- package/dist/plugins/table/TableEditor.js +67 -50
- package/dist/plugins/table/TableNode.js +2 -2
- package/dist/plugins/toolbar/components/BlockTypeSelect.js +3 -3
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +79 -24
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +1 -1
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +1 -1
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +3 -1
- package/dist/plugins/toolbar/components/InsertFrontmatter.js +3 -1
- package/dist/plugins/toolbar/components/InsertImage.js +12 -1
- package/dist/plugins/toolbar/components/InsertThematicBreak.js +10 -1
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +2 -2
- package/dist/plugins/toolbar/primitives/DialogButton.js +1 -1
- package/dist/plugins/toolbar/primitives/select.js +3 -1
- package/dist/plugins/toolbar/primitives/toolbar.js +17 -3
- package/dist/utils/detectMac.js +1 -1
- package/dist/utils/isPartOftheEditorUI.js +1 -1
- package/package.json +3 -2
|
@@ -30,15 +30,15 @@ const codeMirrorPlugin = realmPlugin({
|
|
|
30
30
|
update(r, params) {
|
|
31
31
|
r.pubIn({
|
|
32
32
|
[codeBlockLanguages$]: params == null ? void 0 : params.codeBlockLanguages,
|
|
33
|
-
[codeMirrorExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions)
|
|
33
|
+
[codeMirrorExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions) ?? [],
|
|
34
34
|
[codeMirrorAutoLoadLanguageSupport$]: (params == null ? void 0 : params.autoLoadLanguageSupport) ?? true
|
|
35
35
|
});
|
|
36
36
|
},
|
|
37
37
|
init(r, params) {
|
|
38
38
|
r.pubIn({
|
|
39
39
|
[codeBlockLanguages$]: params == null ? void 0 : params.codeBlockLanguages,
|
|
40
|
-
[codeMirrorExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions)
|
|
41
|
-
[appendCodeBlockEditorDescriptor$]: buildCodeBlockDescriptor((params == null ? void 0 : params.codeBlockLanguages)
|
|
40
|
+
[codeMirrorExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions) ?? [],
|
|
41
|
+
[appendCodeBlockEditorDescriptor$]: buildCodeBlockDescriptor((params == null ? void 0 : params.codeBlockLanguages) ?? {}),
|
|
42
42
|
[codeMirrorAutoLoadLanguageSupport$]: (params == null ? void 0 : params.autoLoadLanguageSupport) ?? true
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -46,7 +46,7 @@ const codeMirrorPlugin = realmPlugin({
|
|
|
46
46
|
function buildCodeBlockDescriptor(codeBlockLanguages) {
|
|
47
47
|
return {
|
|
48
48
|
match(language, meta) {
|
|
49
|
-
return Boolean(
|
|
49
|
+
return Boolean(Object.hasOwn(codeBlockLanguages, language ?? "")) && !meta;
|
|
50
50
|
},
|
|
51
51
|
priority: 1,
|
|
52
52
|
Editor: CodeMirrorEditor
|
|
@@ -42,6 +42,9 @@ import SvgRichText from "../../icons/rich_text.svg.js";
|
|
|
42
42
|
import SvgSettings from "../../icons/settings.svg.js";
|
|
43
43
|
import SvgTable from "../../icons/table.svg.js";
|
|
44
44
|
import SvgUndo from "../../icons/undo.svg.js";
|
|
45
|
+
import SvgStrikethroughS from "../../icons/strikethrough_s.svg.js";
|
|
46
|
+
import SvgSuperscript from "../../icons/superscript.svg.js";
|
|
47
|
+
import SvgSubscript from "../../icons/subscript.svg.js";
|
|
45
48
|
const IconMap = {
|
|
46
49
|
add_column: SvgAddColumn,
|
|
47
50
|
add_photo: SvgAddPhoto,
|
|
@@ -84,6 +87,9 @@ const IconMap = {
|
|
|
84
87
|
redo: SvgRedo,
|
|
85
88
|
rich_text: SvgRichText,
|
|
86
89
|
settings: SvgSettings,
|
|
90
|
+
strikeThrough: SvgStrikethroughS,
|
|
91
|
+
subscript: SvgSubscript,
|
|
92
|
+
superscript: SvgSuperscript,
|
|
87
93
|
table: SvgTable,
|
|
88
94
|
undo: SvgUndo
|
|
89
95
|
};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { $isTextNode } from "lexical";
|
|
2
|
-
import { IS_ITALIC, IS_BOLD, IS_UNDERLINE, IS_CODE } from "../../FormatConstants.js";
|
|
2
|
+
import { IS_ITALIC, IS_BOLD, IS_UNDERLINE, IS_STRIKETHROUGH, IS_SUPERSCRIPT, IS_SUBSCRIPT, IS_CODE } from "../../FormatConstants.js";
|
|
3
3
|
function isMdastText(mdastNode) {
|
|
4
4
|
return mdastNode.type === "text";
|
|
5
5
|
}
|
|
6
|
-
const JOINABLE_TAGS = ["u", "span"];
|
|
6
|
+
const JOINABLE_TAGS = ["u", "span", "sub", "sup"];
|
|
7
7
|
const LexicalTextVisitor = {
|
|
8
8
|
shouldJoin: (prevNode, currentNode) => {
|
|
9
9
|
if (["text", "emphasis", "strong"].includes(prevNode.type)) {
|
|
10
10
|
return prevNode.type === currentNode.type;
|
|
11
11
|
}
|
|
12
|
-
if (prevNode.type === "mdxJsxTextElement" &&
|
|
12
|
+
if (prevNode.type === "mdxJsxTextElement" && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
13
|
+
currentNode.type === "mdxJsxTextElement" && JOINABLE_TAGS.includes(currentNode.name)) {
|
|
13
14
|
const currentMdxNode = currentNode;
|
|
14
15
|
return prevNode.name === currentMdxNode.name && JSON.stringify(prevNode.attributes) === JSON.stringify(currentMdxNode.attributes);
|
|
15
16
|
}
|
|
@@ -33,7 +34,7 @@ const LexicalTextVisitor = {
|
|
|
33
34
|
const previousSibling = lexicalNode.getPreviousSibling();
|
|
34
35
|
const prevFormat = $isTextNode(previousSibling) ? previousSibling.getFormat() : 0;
|
|
35
36
|
const textContent = lexicalNode.getTextContent();
|
|
36
|
-
const format = lexicalNode.getFormat()
|
|
37
|
+
const format = lexicalNode.getFormat();
|
|
37
38
|
const style = lexicalNode.getStyle();
|
|
38
39
|
let localParentNode = mdastParent;
|
|
39
40
|
if (style) {
|
|
@@ -64,6 +65,28 @@ const LexicalTextVisitor = {
|
|
|
64
65
|
attributes: []
|
|
65
66
|
});
|
|
66
67
|
}
|
|
68
|
+
if (prevFormat & format & IS_STRIKETHROUGH) {
|
|
69
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
70
|
+
type: "delete",
|
|
71
|
+
children: []
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (prevFormat & format & IS_SUPERSCRIPT) {
|
|
75
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
76
|
+
type: "mdxJsxTextElement",
|
|
77
|
+
name: "sup",
|
|
78
|
+
children: [],
|
|
79
|
+
attributes: []
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (prevFormat & format & IS_SUBSCRIPT) {
|
|
83
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
84
|
+
type: "mdxJsxTextElement",
|
|
85
|
+
name: "sub",
|
|
86
|
+
children: [],
|
|
87
|
+
attributes: []
|
|
88
|
+
});
|
|
89
|
+
}
|
|
67
90
|
if (format & IS_ITALIC && !(prevFormat & IS_ITALIC)) {
|
|
68
91
|
localParentNode = actions.appendToParent(localParentNode, {
|
|
69
92
|
type: "emphasis",
|
|
@@ -84,6 +107,28 @@ const LexicalTextVisitor = {
|
|
|
84
107
|
attributes: []
|
|
85
108
|
});
|
|
86
109
|
}
|
|
110
|
+
if (format & IS_STRIKETHROUGH && !(prevFormat & IS_STRIKETHROUGH)) {
|
|
111
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
112
|
+
type: "delete",
|
|
113
|
+
children: []
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (format & IS_SUPERSCRIPT && !(prevFormat & IS_SUPERSCRIPT)) {
|
|
117
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
118
|
+
type: "mdxJsxTextElement",
|
|
119
|
+
name: "sup",
|
|
120
|
+
children: [],
|
|
121
|
+
attributes: []
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (format & IS_SUBSCRIPT && !(prevFormat & IS_SUBSCRIPT)) {
|
|
125
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
126
|
+
type: "mdxJsxTextElement",
|
|
127
|
+
name: "sub",
|
|
128
|
+
children: [],
|
|
129
|
+
attributes: []
|
|
130
|
+
});
|
|
131
|
+
}
|
|
87
132
|
if (format & IS_CODE) {
|
|
88
133
|
actions.appendToParent(localParentNode, {
|
|
89
134
|
type: "inlineCode",
|
|
@@ -1,42 +1,35 @@
|
|
|
1
|
-
import { IS_CODE, IS_ITALIC, IS_BOLD, IS_UNDERLINE } from "../../FormatConstants.js";
|
|
1
|
+
import { IS_STRIKETHROUGH, IS_CODE, IS_ITALIC, IS_BOLD, IS_UNDERLINE, IS_SUPERSCRIPT, IS_SUBSCRIPT } from "../../FormatConstants.js";
|
|
2
2
|
import { $createTextNode } from "lexical";
|
|
3
|
-
function
|
|
4
|
-
return
|
|
3
|
+
function buildFormattingVisitors(tag, format) {
|
|
4
|
+
return [
|
|
5
|
+
{
|
|
6
|
+
testNode: (node) => node.type === "mdxJsxTextElement" && node.name === tag,
|
|
7
|
+
visitNode({ actions, mdastNode, lexicalParent }) {
|
|
8
|
+
actions.addFormatting(format);
|
|
9
|
+
actions.visitChildren(mdastNode, lexicalParent);
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
testNode: (node) => node.type === "html" && node.value === `<${tag}>`,
|
|
14
|
+
visitNode({ actions, mdastParent }) {
|
|
15
|
+
actions.addFormatting(format, mdastParent);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
testNode: (node) => node.type === "html" && node.value === `</${tag}>`,
|
|
20
|
+
visitNode({ actions, mdastParent }) {
|
|
21
|
+
actions.removeFormatting(format, mdastParent);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
];
|
|
5
25
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
function isJsxUnderlineNode(node) {
|
|
10
|
-
return node.type === "mdxJsxTextElement" && node.name === "u";
|
|
11
|
-
}
|
|
12
|
-
function isJsxCodeNode(node) {
|
|
13
|
-
return node.type === "mdxJsxTextElement" && node.name === "code";
|
|
14
|
-
}
|
|
15
|
-
function isOpeningCodeNode(node) {
|
|
16
|
-
return node.type === "html" && node.value === "<code>";
|
|
17
|
-
}
|
|
18
|
-
function isClosingCodeNode(node) {
|
|
19
|
-
return node.type === "html" && node.value === "</code>";
|
|
20
|
-
}
|
|
21
|
-
const JsxCodeVisitor = {
|
|
22
|
-
testNode: isJsxCodeNode,
|
|
26
|
+
const StrikeThroughVisitor = {
|
|
27
|
+
testNode: "delete",
|
|
23
28
|
visitNode({ mdastNode, actions, lexicalParent }) {
|
|
24
|
-
actions.addFormatting(
|
|
29
|
+
actions.addFormatting(IS_STRIKETHROUGH);
|
|
25
30
|
actions.visitChildren(mdastNode, lexicalParent);
|
|
26
31
|
}
|
|
27
32
|
};
|
|
28
|
-
const OpeningCodeVisitor = {
|
|
29
|
-
testNode: isOpeningCodeNode,
|
|
30
|
-
visitNode({ actions, mdastParent }) {
|
|
31
|
-
actions.addFormatting(IS_CODE, mdastParent);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const ClosingCodeVisitor = {
|
|
35
|
-
testNode: isClosingCodeNode,
|
|
36
|
-
visitNode({ actions, mdastParent }) {
|
|
37
|
-
actions.removeFormatting(IS_CODE, mdastParent);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
33
|
const MdCodeVisitor = {
|
|
41
34
|
testNode: "inlineCode",
|
|
42
35
|
visitNode({ mdastNode, actions }) {
|
|
@@ -57,39 +50,22 @@ const MdStrongVisitor = {
|
|
|
57
50
|
actions.visitChildren(mdastNode, lexicalParent);
|
|
58
51
|
}
|
|
59
52
|
};
|
|
60
|
-
const JsxUnderlineVisitor = {
|
|
61
|
-
testNode: isJsxUnderlineNode,
|
|
62
|
-
visitNode({ mdastNode, actions, lexicalParent }) {
|
|
63
|
-
actions.addFormatting(IS_UNDERLINE);
|
|
64
|
-
actions.visitChildren(mdastNode, lexicalParent);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const OpeningUnderlineVisitor = {
|
|
68
|
-
testNode: isOpeningUnderlineNode,
|
|
69
|
-
visitNode({ actions, mdastParent }) {
|
|
70
|
-
actions.addFormatting(IS_UNDERLINE, mdastParent);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const ClosingUnderlineVisitor = {
|
|
74
|
-
testNode: isClosingUnderlineNode,
|
|
75
|
-
visitNode({ actions, mdastParent }) {
|
|
76
|
-
actions.removeFormatting(IS_UNDERLINE, mdastParent);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
53
|
const formattingVisitors = [
|
|
80
54
|
// emphasis
|
|
81
55
|
MdEmphasisVisitor,
|
|
82
56
|
// strong
|
|
83
57
|
MdStrongVisitor,
|
|
84
58
|
// underline
|
|
85
|
-
|
|
86
|
-
OpeningUnderlineVisitor,
|
|
87
|
-
ClosingUnderlineVisitor,
|
|
59
|
+
...buildFormattingVisitors("u", IS_UNDERLINE),
|
|
88
60
|
// code
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
61
|
+
...buildFormattingVisitors("code", IS_CODE),
|
|
62
|
+
MdCodeVisitor,
|
|
63
|
+
// strikethrough
|
|
64
|
+
StrikeThroughVisitor,
|
|
65
|
+
// superscript
|
|
66
|
+
...buildFormattingVisitors("sup", IS_SUPERSCRIPT),
|
|
67
|
+
// subscript
|
|
68
|
+
...buildFormattingVisitors("sub", IS_SUBSCRIPT)
|
|
93
69
|
];
|
|
94
70
|
export {
|
|
95
71
|
formattingVisitors
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const MDX_NODE_TYPES = ["mdxJsxTextElement", "mdxJsxFlowElement"];
|
|
2
2
|
function isMdastHTMLNode(node) {
|
|
3
|
-
|
|
4
|
-
return MDX_NODE_TYPES.includes(node.type) && htmlTags.includes(((_a = node.name) == null ? void 0 : _a.toLowerCase()) ?? "");
|
|
3
|
+
return MDX_NODE_TYPES.includes(node.type) && htmlTags.includes(node.name.toLowerCase());
|
|
5
4
|
}
|
|
6
5
|
const htmlTags = [
|
|
7
6
|
"a",
|
|
@@ -84,7 +84,7 @@ const NestedLexicalEditor = function(props) {
|
|
|
84
84
|
return editor2;
|
|
85
85
|
});
|
|
86
86
|
React__default.useEffect(() => {
|
|
87
|
-
focusEmitter
|
|
87
|
+
focusEmitter.subscribe(() => {
|
|
88
88
|
editor.focus();
|
|
89
89
|
});
|
|
90
90
|
}, [editor, focusEmitter]);
|
|
@@ -9,31 +9,41 @@ const PropertyPopover = ({ title, properties, onChange }) => {
|
|
|
9
9
|
const [open, setOpen] = React__default.useState(false);
|
|
10
10
|
const iconComponentFor = useCellValue(iconComponentFor$);
|
|
11
11
|
const { register, handleSubmit, reset } = useForm({ defaultValues: properties });
|
|
12
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
13
|
-
|
|
12
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
13
|
+
RadixPopover.Root,
|
|
14
14
|
{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
setOpen(
|
|
18
|
-
e.preventDefault();
|
|
19
|
-
e.stopPropagation();
|
|
15
|
+
open,
|
|
16
|
+
onOpenChange: (v) => {
|
|
17
|
+
setOpen(v);
|
|
20
18
|
}
|
|
21
19
|
},
|
|
22
|
-
/* @__PURE__ */ React__default.createElement(
|
|
23
|
-
/* @__PURE__ */ React__default.createElement(
|
|
24
|
-
"
|
|
20
|
+
/* @__PURE__ */ React__default.createElement(RadixPopover.Trigger, { className: styles.iconButton }, /* @__PURE__ */ React__default.createElement("div", null, iconComponentFor("settings"))),
|
|
21
|
+
/* @__PURE__ */ React__default.createElement(PopoverPortal, null, /* @__PURE__ */ React__default.createElement(PopoverContent, null, /* @__PURE__ */ React__default.createElement(
|
|
22
|
+
"form",
|
|
25
23
|
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
onClick: (e) => {
|
|
29
|
-
e.preventDefault();
|
|
30
|
-
reset(properties);
|
|
24
|
+
onSubmit: (e) => {
|
|
25
|
+
void handleSubmit(onChange)(e);
|
|
31
26
|
setOpen(false);
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
e.stopPropagation();
|
|
32
29
|
}
|
|
33
30
|
},
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
/* @__PURE__ */ React__default.createElement("h3", { className: styles.propertyPanelTitle }, title, " Attributes"),
|
|
32
|
+
/* @__PURE__ */ React__default.createElement("table", { className: styles.propertyEditorTable }, /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.readOnlyColumnCell }, "Attribute"), /* @__PURE__ */ React__default.createElement("th", null, "Value"))), /* @__PURE__ */ React__default.createElement("tbody", null, Object.keys(properties).map((propName) => /* @__PURE__ */ React__default.createElement("tr", { key: propName }, /* @__PURE__ */ React__default.createElement("th", { className: styles.readOnlyColumnCell }, " ", propName, " "), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement("input", { ...register(propName), className: styles.propertyEditorInput }))))), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("td", { colSpan: 2 }, /* @__PURE__ */ React__default.createElement("div", { className: styles.buttonsFooter }, /* @__PURE__ */ React__default.createElement("button", { type: "submit", className: styles.primaryButton }, "Save"), /* @__PURE__ */ React__default.createElement(
|
|
33
|
+
"button",
|
|
34
|
+
{
|
|
35
|
+
type: "reset",
|
|
36
|
+
className: styles.secondaryButton,
|
|
37
|
+
onClick: (e) => {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
reset(properties);
|
|
40
|
+
setOpen(false);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"Cancel"
|
|
44
|
+
))))))
|
|
45
|
+
)))
|
|
46
|
+
);
|
|
37
47
|
};
|
|
38
48
|
export {
|
|
39
49
|
PropertyPopover
|
|
@@ -5,7 +5,8 @@ import { $setBlocksType } from "@lexical/selection";
|
|
|
5
5
|
import { $findMatchingParent, $wrapNodeInElement, $insertNodeToNearestRoot } from "@lexical/utils";
|
|
6
6
|
import { Cell, withLatestFrom, Signal, filter, map, useCellValue, scan } from "@mdxeditor/gurx";
|
|
7
7
|
import { createCommand, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getRoot, $setSelection, $getSelection, $insertNodes, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, DecoratorNode, $createParagraphNode, FOCUS_COMMAND, KEY_DOWN_COMMAND, $isDecoratorNode, BLUR_COMMAND, $isRangeSelection, ParagraphNode, TextNode, createEditor } from "lexical";
|
|
8
|
-
import {
|
|
8
|
+
import { gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown } from "mdast-util-gfm-strikethrough";
|
|
9
|
+
import { mdxJsxToMarkdown, mdxJsxFromMarkdown } from "mdast-util-mdx-jsx";
|
|
9
10
|
import { mdxJsx } from "micromark-extension-mdx-jsx";
|
|
10
11
|
import { mdxMd } from "micromark-extension-mdx-md";
|
|
11
12
|
import { exportMarkdownFromLexical } from "../../exportMarkdownFromLexical.js";
|
|
@@ -28,6 +29,7 @@ import { MdastTextVisitor } from "./MdastTextVisitor.js";
|
|
|
28
29
|
import { SharedHistoryPlugin } from "./SharedHistoryPlugin.js";
|
|
29
30
|
import { commentFromMarkdown, comment } from "../../mdastUtilHtmlComment.js";
|
|
30
31
|
import { lexicalTheme } from "../../styles/lexicalTheme.js";
|
|
32
|
+
import { gfmStrikethrough } from "../../node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js";
|
|
31
33
|
const NESTED_EDITOR_UPDATED_COMMAND = createCommand("NESTED_EDITOR_UPDATED_COMMAND");
|
|
32
34
|
const rootEditor$ = Cell(null);
|
|
33
35
|
const activeEditor$ = Cell(null);
|
|
@@ -135,7 +137,9 @@ const setMarkdown$ = Signal((r) => {
|
|
|
135
137
|
}
|
|
136
138
|
},
|
|
137
139
|
{
|
|
138
|
-
onUpdate: () =>
|
|
140
|
+
onUpdate: () => {
|
|
141
|
+
r.pub(muteChange$, false);
|
|
142
|
+
}
|
|
139
143
|
}
|
|
140
144
|
);
|
|
141
145
|
}
|
|
@@ -152,7 +156,7 @@ const insertMarkdown$ = Signal((r) => {
|
|
|
152
156
|
this.children.push(node);
|
|
153
157
|
},
|
|
154
158
|
getType() {
|
|
155
|
-
return selection
|
|
159
|
+
return selection.getNodes()[0].getType();
|
|
156
160
|
}
|
|
157
161
|
};
|
|
158
162
|
tryImportingMarkdown(r, importPoint, markdownToInsert);
|
|
@@ -402,28 +406,25 @@ const insertDecoratorNode$ = Signal((r) => {
|
|
|
402
406
|
theEditor.getEditorState().read(() => {
|
|
403
407
|
const selection = $getSelection();
|
|
404
408
|
if ($isRangeSelection(selection)) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
if (node.
|
|
410
|
-
$
|
|
411
|
-
if ($isRootOrShadowRoot(node.getParentOrThrow())) {
|
|
412
|
-
$wrapNodeInElement(node, $createParagraphNode).selectEnd();
|
|
413
|
-
}
|
|
414
|
-
} else {
|
|
415
|
-
$insertNodeToNearestRoot(node);
|
|
409
|
+
theEditor.update(() => {
|
|
410
|
+
const node = nodeFactory();
|
|
411
|
+
if (node.isInline()) {
|
|
412
|
+
$insertNodes([node]);
|
|
413
|
+
if ($isRootOrShadowRoot(node.getParentOrThrow())) {
|
|
414
|
+
$wrapNodeInElement(node, $createParagraphNode).selectEnd();
|
|
416
415
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
});
|
|
416
|
+
} else {
|
|
417
|
+
$insertNodeToNearestRoot(node);
|
|
418
|
+
}
|
|
423
419
|
setTimeout(() => {
|
|
424
|
-
|
|
420
|
+
if ("select" in node && typeof node.select === "function") {
|
|
421
|
+
node.select();
|
|
422
|
+
}
|
|
425
423
|
});
|
|
426
|
-
}
|
|
424
|
+
});
|
|
425
|
+
setTimeout(() => {
|
|
426
|
+
theEditor.dispatchCommand(NESTED_EDITOR_UPDATED_COMMAND, void 0);
|
|
427
|
+
});
|
|
427
428
|
}
|
|
428
429
|
});
|
|
429
430
|
},
|
|
@@ -492,13 +493,15 @@ const corePlugin = realmPlugin({
|
|
|
492
493
|
[autoFocus$]: params == null ? void 0 : params.autoFocus,
|
|
493
494
|
[placeholder$]: params == null ? void 0 : params.placeholder,
|
|
494
495
|
[readOnly$]: params == null ? void 0 : params.readOnly,
|
|
495
|
-
[translation$]: params == null ? void 0 : params.translation
|
|
496
|
+
[translation$]: params == null ? void 0 : params.translation,
|
|
497
|
+
[addMdastExtension$]: gfmStrikethroughFromMarkdown(),
|
|
498
|
+
[addSyntaxExtension$]: gfmStrikethrough(),
|
|
499
|
+
[addToMarkdownExtension$]: [mdxJsxToMarkdown(), gfmStrikethroughToMarkdown()]
|
|
496
500
|
});
|
|
497
501
|
if (!(params == null ? void 0 : params.suppressHtmlProcessing)) {
|
|
498
502
|
r.pubIn({
|
|
499
503
|
[addMdastExtension$]: [mdxJsxFromMarkdown(), commentFromMarkdown({ ast: false })],
|
|
500
504
|
[addSyntaxExtension$]: [mdxJsx(), mdxMd(), comment],
|
|
501
|
-
[addToMarkdownExtension$]: mdxJsxToMarkdown(),
|
|
502
505
|
[addImportVisitor$]: MdastHTMLVisitor
|
|
503
506
|
});
|
|
504
507
|
}
|
|
@@ -519,14 +522,16 @@ const corePlugin = realmPlugin({
|
|
|
519
522
|
const autoFocusValue = params == null ? void 0 : params.autoFocus;
|
|
520
523
|
if (autoFocusValue) {
|
|
521
524
|
if (autoFocusValue === true) {
|
|
522
|
-
setTimeout(() =>
|
|
525
|
+
setTimeout(() => {
|
|
526
|
+
newEditor.focus(noop, { defaultSelection: "rootStart" });
|
|
527
|
+
});
|
|
523
528
|
return;
|
|
524
529
|
}
|
|
525
|
-
setTimeout(
|
|
526
|
-
|
|
530
|
+
setTimeout(() => {
|
|
531
|
+
newEditor.focus(noop, {
|
|
527
532
|
defaultSelection: autoFocusValue.defaultSelection ?? "rootStart"
|
|
528
|
-
})
|
|
529
|
-
);
|
|
533
|
+
});
|
|
534
|
+
});
|
|
530
535
|
}
|
|
531
536
|
});
|
|
532
537
|
r.pub(rootEditor$, newEditor);
|
|
@@ -28,7 +28,7 @@ const DownshiftAutoCompleteWithSuggestions = ({
|
|
|
28
28
|
initialInputValue,
|
|
29
29
|
onInputValueChange({ inputValue = "" }) {
|
|
30
30
|
setValue(inputName, inputValue);
|
|
31
|
-
inputValue =
|
|
31
|
+
inputValue = inputValue.toLowerCase() || "";
|
|
32
32
|
const matchingItems = [];
|
|
33
33
|
for (const suggestion of suggestions) {
|
|
34
34
|
if (suggestion.toLowerCase().includes(inputValue)) {
|
|
@@ -20,11 +20,11 @@ const insertDirective$ = Signal((r) => {
|
|
|
20
20
|
});
|
|
21
21
|
const directivesPlugin = realmPlugin({
|
|
22
22
|
update: (realm, params) => {
|
|
23
|
-
realm.pub(directiveDescriptors$, (params == null ? void 0 : params.directiveDescriptors)
|
|
23
|
+
realm.pub(directiveDescriptors$, (params == null ? void 0 : params.directiveDescriptors) ?? []);
|
|
24
24
|
},
|
|
25
25
|
init: (realm, params) => {
|
|
26
26
|
realm.pubIn({
|
|
27
|
-
[directiveDescriptors$]: (params == null ? void 0 : params.directiveDescriptors)
|
|
27
|
+
[directiveDescriptors$]: (params == null ? void 0 : params.directiveDescriptors) ?? [],
|
|
28
28
|
// import
|
|
29
29
|
[addMdastExtension$]: directiveFromMarkdown(),
|
|
30
30
|
[addSyntaxExtension$]: directive(),
|
|
@@ -39,48 +39,65 @@ const FrontmatterEditor = ({ yaml, onChange }) => {
|
|
|
39
39
|
setFrontmatterDialogOpen(false);
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
const yaml2 = yamlConfig2.reduce(
|
|
43
|
-
(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
{}
|
|
50
|
-
);
|
|
42
|
+
const yaml2 = yamlConfig2.reduce((acc, { key, value }) => {
|
|
43
|
+
if (key && value) {
|
|
44
|
+
acc[key] = value;
|
|
45
|
+
}
|
|
46
|
+
return acc;
|
|
47
|
+
}, {});
|
|
51
48
|
onChange(YamlParser.dump(yaml2).trim());
|
|
52
49
|
setFrontmatterDialogOpen(false);
|
|
53
50
|
},
|
|
54
51
|
[onChange, setFrontmatterDialogOpen, removeFrontmatter]
|
|
55
52
|
);
|
|
56
|
-
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
|
|
57
|
-
|
|
53
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
|
|
54
|
+
Dialog.Root,
|
|
58
55
|
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
onReset: (e) => {
|
|
64
|
-
e.stopPropagation();
|
|
65
|
-
setFrontmatterDialogOpen(false);
|
|
56
|
+
open: frontmatterDialogOpen,
|
|
57
|
+
onOpenChange: (open) => {
|
|
58
|
+
setFrontmatterDialogOpen(open);
|
|
66
59
|
}
|
|
67
60
|
},
|
|
68
|
-
/* @__PURE__ */ React__default.createElement(
|
|
69
|
-
|
|
70
|
-
})), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(
|
|
71
|
-
"button",
|
|
61
|
+
/* @__PURE__ */ React__default.createElement(Dialog.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Dialog.Overlay, { className: styles.dialogOverlay }), /* @__PURE__ */ React__default.createElement(Dialog.Content, { className: styles.largeDialogContent, "data-editor-type": "frontmatter" }, /* @__PURE__ */ React__default.createElement(Dialog.Title, { className: styles.dialogTitle }, t("frontmatterEditor.title", "Edit document frontmatter")), /* @__PURE__ */ React__default.createElement(
|
|
62
|
+
"form",
|
|
72
63
|
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
64
|
+
onSubmit: (e) => {
|
|
65
|
+
void handleSubmit(onSubmit)(e);
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
},
|
|
68
|
+
onReset: (e) => {
|
|
69
|
+
e.stopPropagation();
|
|
70
|
+
setFrontmatterDialogOpen(false);
|
|
78
71
|
}
|
|
79
72
|
},
|
|
80
|
-
t("frontmatterEditor.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
/* @__PURE__ */ React__default.createElement("table", { className: styles.propertyEditorTable }, /* @__PURE__ */ React__default.createElement("colgroup", null, /* @__PURE__ */ React__default.createElement("col", null), /* @__PURE__ */ React__default.createElement("col", null), /* @__PURE__ */ React__default.createElement("col", null)), /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null, t("frontmatterEditor.key", "Key")), /* @__PURE__ */ React__default.createElement("th", null, t("frontmatterEditor.value", "Value")), /* @__PURE__ */ React__default.createElement("th", null))), /* @__PURE__ */ React__default.createElement("tbody", null, fields.map((item, index) => {
|
|
74
|
+
return /* @__PURE__ */ React__default.createElement("tr", { key: item.id }, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(TableInput, { ...register(`yamlConfig.${index}.key`, { required: true }), autofocusIfEmpty: true, readOnly })), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(TableInput, { ...register(`yamlConfig.${index}.value`, { required: true }), readOnly })), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(
|
|
75
|
+
"button",
|
|
76
|
+
{
|
|
77
|
+
type: "button",
|
|
78
|
+
onClick: () => {
|
|
79
|
+
remove(index);
|
|
80
|
+
},
|
|
81
|
+
className: styles.iconButton,
|
|
82
|
+
disabled: readOnly
|
|
83
|
+
},
|
|
84
|
+
iconComponentFor("delete_big")
|
|
85
|
+
)));
|
|
86
|
+
})), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(
|
|
87
|
+
"button",
|
|
88
|
+
{
|
|
89
|
+
disabled: readOnly,
|
|
90
|
+
className: classNames(styles.primaryButton, styles.smallButton),
|
|
91
|
+
type: "button",
|
|
92
|
+
onClick: () => {
|
|
93
|
+
append({ key: "", value: "" });
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
t("frontmatterEditor.addEntry", "Add entry")
|
|
97
|
+
))))),
|
|
98
|
+
/* @__PURE__ */ React__default.createElement("div", { style: { display: "flex", justifyContent: "flex-end", gap: "var(--spacing-2)" } }, /* @__PURE__ */ React__default.createElement("button", { type: "submit", className: styles.primaryButton }, t("dialogControls.save", "Save")), /* @__PURE__ */ React__default.createElement("button", { type: "reset", className: styles.secondaryButton }, t("dialogControls.cancel", "Cancel")))
|
|
99
|
+
), /* @__PURE__ */ React__default.createElement(Dialog.Close, { asChild: true }, /* @__PURE__ */ React__default.createElement("button", { className: styles.dialogCloseButton, "aria-label": t("dialogControls.cancel", "Cancel") }, iconComponentFor("close")))))
|
|
100
|
+
));
|
|
84
101
|
};
|
|
85
102
|
const TableInput = React__default.forwardRef(({ className, autofocusIfEmpty: _, ...props }, ref) => {
|
|
86
103
|
return /* @__PURE__ */ React__default.createElement("input", { className: classNames(styles.propertyEditorInput, className), ...props, ref });
|
|
@@ -51,9 +51,11 @@ class FrontmatterNode extends DecoratorNode {
|
|
|
51
51
|
FrontmatterEditor,
|
|
52
52
|
{
|
|
53
53
|
yaml: this.getYaml(),
|
|
54
|
-
onChange: (yaml) =>
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
onChange: (yaml) => {
|
|
55
|
+
editor.update(() => {
|
|
56
|
+
this.setYaml(yaml);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
57
59
|
}
|
|
58
60
|
);
|
|
59
61
|
}
|
|
@@ -55,7 +55,7 @@ const ImageDialog = () => {
|
|
|
55
55
|
DownshiftAutoComplete,
|
|
56
56
|
{
|
|
57
57
|
register,
|
|
58
|
-
initialInputValue: state.type === "editing" ? state.initialValues.src
|
|
58
|
+
initialInputValue: state.type === "editing" ? state.initialValues.src ?? "" : "",
|
|
59
59
|
inputName: "src",
|
|
60
60
|
suggestions: imageAutocompleteSuggestions,
|
|
61
61
|
setValue,
|