@nkzw/mdx-editor 0.1.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/LICENSE +21 -0
- package/README.md +86 -0
- package/UPSTREAM.md +21 -0
- package/dist/EditorIcon.js +75 -0
- package/dist/FormatConstants.js +20 -0
- package/dist/MDXEditor.js +189 -0
- package/dist/MarkdownEditor.js +281 -0
- package/dist/PersistentMarkdownEditor.js +358 -0
- package/dist/RealmWithPlugins.js +35 -0
- package/dist/core.d.ts +3232 -0
- package/dist/core.js +354 -0
- package/dist/defaultSvgIcons.js +371 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +28 -0
- package/dist/directive-editors/GenericDirectiveEditor.js +37 -0
- package/dist/exportMarkdownFromLexical.js +262 -0
- package/dist/horizontalRuleShortcut.js +37 -0
- package/dist/importMarkdownToLexical.js +172 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +8 -0
- package/dist/jsx-editors/GenericJsxEditor.js +84 -0
- package/dist/mdastUtilHtmlComment.js +125 -0
- package/dist/persistence.d.ts +128 -0
- package/dist/persistence.js +4 -0
- package/dist/plugins/codeblock/CodeBlockNode.js +183 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.js +23 -0
- package/dist/plugins/codeblock/findCodeBlockDescriptor.js +8 -0
- package/dist/plugins/codeblock/index.js +46 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.js +145 -0
- package/dist/plugins/codemirror/index.js +115 -0
- package/dist/plugins/codemirror/useCodeMirrorRef.js +101 -0
- package/dist/plugins/core/GenericHTMLNode.js +118 -0
- package/dist/plugins/core/LexicalGenericHTMLNodeVisitor.js +15 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
- package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
- package/dist/plugins/core/LexicalRootVisitor.js +10 -0
- package/dist/plugins/core/LexicalTextVisitor.js +160 -0
- package/dist/plugins/core/MdastBreakVisitor.js +10 -0
- package/dist/plugins/core/MdastFormattingVisitor.js +81 -0
- package/dist/plugins/core/MdastHTMLNode.js +120 -0
- package/dist/plugins/core/MdastHTMLVisitor.js +17 -0
- package/dist/plugins/core/MdastParagraphVisitor.js +23 -0
- package/dist/plugins/core/MdastRootVisitor.js +9 -0
- package/dist/plugins/core/MdastTextVisitor.js +16 -0
- package/dist/plugins/core/NestedLexicalEditor.js +221 -0
- package/dist/plugins/core/PropertyPopover.js +75 -0
- package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
- package/dist/plugins/core/index.js +692 -0
- package/dist/plugins/core/ui/DownshiftAutoComplete.js +89 -0
- package/dist/plugins/core/ui/PopoverUtils.js +22 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.js +24 -0
- package/dist/plugins/diff-source/DiffViewer.js +84 -0
- package/dist/plugins/diff-source/SourceEditor.js +60 -0
- package/dist/plugins/diff-source/index.js +27 -0
- package/dist/plugins/directives/DirectiveNode.js +107 -0
- package/dist/plugins/directives/DirectiveVisitor.js +10 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.js +30 -0
- package/dist/plugins/directives/index.js +45 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.js +137 -0
- package/dist/plugins/frontmatter/FrontmatterNode.js +70 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/index.js +113 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
- package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
- package/dist/plugins/headings/index.js +63 -0
- package/dist/plugins/image/EditImageToolbar.js +58 -0
- package/dist/plugins/image/ImageDialog.js +132 -0
- package/dist/plugins/image/ImageEditor.js +279 -0
- package/dist/plugins/image/ImageNode.js +187 -0
- package/dist/plugins/image/ImagePlaceholder.js +9 -0
- package/dist/plugins/image/ImageResizer.js +223 -0
- package/dist/plugins/image/LexicalImageVisitor.js +42 -0
- package/dist/plugins/image/MdastImageVisitor.js +91 -0
- package/dist/plugins/image/index.js +364 -0
- package/dist/plugins/jsx/LexicalJsxNode.js +103 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.js +27 -0
- package/dist/plugins/jsx/LexicalMdxExpressionNode.js +130 -0
- package/dist/plugins/jsx/LexicalMdxExpressionVisitor.js +14 -0
- package/dist/plugins/jsx/MdastMdxExpressionVisitor.js +11 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +28 -0
- package/dist/plugins/jsx/index.js +97 -0
- package/dist/plugins/jsx/jsxTagName.js +7 -0
- package/dist/plugins/link/AutoLinkPlugin.js +18 -0
- package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
- package/dist/plugins/link/MdastLinkVisitor.js +14 -0
- package/dist/plugins/link/index.js +34 -0
- package/dist/plugins/link-dialog/LinkDialog.js +262 -0
- package/dist/plugins/link-dialog/index.js +304 -0
- package/dist/plugins/lists/CheckListPlugin.js +270 -0
- package/dist/plugins/lists/LexicalListItemVisitor.js +41 -0
- package/dist/plugins/lists/LexicalListVisitor.js +13 -0
- package/dist/plugins/lists/MdastListItemVisitor.js +11 -0
- package/dist/plugins/lists/MdastListVisitor.js +19 -0
- package/dist/plugins/lists/NotesListItemNode.js +22 -0
- package/dist/plugins/lists/index.js +111 -0
- package/dist/plugins/markdown-shortcut/index.js +114 -0
- package/dist/plugins/maxlength/index.js +36 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.js +10 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
- package/dist/plugins/quote/index.js +18 -0
- package/dist/plugins/remote/index.js +52 -0
- package/dist/plugins/search/index.js +360 -0
- package/dist/plugins/table/LexicalTableVisitor.js +10 -0
- package/dist/plugins/table/MdastTableVisitor.js +10 -0
- package/dist/plugins/table/TableEditor.js +527 -0
- package/dist/plugins/table/TableNode.js +208 -0
- package/dist/plugins/table/index.js +66 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/index.js +27 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.js +62 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +98 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +43 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +42 -0
- package/dist/plugins/toolbar/components/CodeToggle.js +21 -0
- package/dist/plugins/toolbar/components/CreateLink.js +24 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +42 -0
- package/dist/plugins/toolbar/components/HighlightToggle.js +28 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.js +34 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.js +23 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.js +28 -0
- package/dist/plugins/toolbar/components/InsertImage.js +29 -0
- package/dist/plugins/toolbar/components/InsertTable.js +25 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.js +23 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +82 -0
- package/dist/plugins/toolbar/components/ListsToggle.js +29 -0
- package/dist/plugins/toolbar/components/UndoRedo.js +60 -0
- package/dist/plugins/toolbar/index.js +32 -0
- package/dist/plugins/toolbar/primitives/DialogButton.js +130 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.js +17 -0
- package/dist/plugins/toolbar/primitives/select.js +76 -0
- package/dist/plugins/toolbar/primitives/toolbar.js +144 -0
- package/dist/registerCodeBoundaryEscape.js +40 -0
- package/dist/styles/lexical-theme.module.css.js +62 -0
- package/dist/styles/lexicalTheme.js +32 -0
- package/dist/styles/ui.module.css.js +296 -0
- package/dist/styles.css +2838 -0
- package/dist/utils/detectMac.js +16 -0
- package/dist/utils/fp.js +44 -0
- package/dist/utils/isPartOftheEditorUI.js +12 -0
- package/dist/utils/lexicalHelpers.js +185 -0
- package/dist/utils/makeHslTransparent.js +6 -0
- package/dist/utils/mergeStyleAttributes.js +22 -0
- package/dist/utils/uuid4.js +10 -0
- package/dist/utils/voidEmitter.js +15 -0
- package/package.json +133 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const CAN_USE_DOM = typeof window !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
2
|
+
const IS_APPLE = CAN_USE_DOM && (() => {
|
|
3
|
+
const platform = navigator.userAgentData?.platform;
|
|
4
|
+
return platform ? /mac/i.test(platform) : /Mac|iPod|iPhone|iPad/.test(navigator.userAgent);
|
|
5
|
+
})();
|
|
6
|
+
function controlOrMeta(metaKey, ctrlKey) {
|
|
7
|
+
if (IS_APPLE) {
|
|
8
|
+
return metaKey;
|
|
9
|
+
}
|
|
10
|
+
return ctrlKey;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
CAN_USE_DOM,
|
|
14
|
+
IS_APPLE,
|
|
15
|
+
controlOrMeta
|
|
16
|
+
};
|
package/dist/utils/fp.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
function compose(a, b) {
|
|
2
|
+
return (arg) => a(b(arg));
|
|
3
|
+
}
|
|
4
|
+
function thrush(arg, proc) {
|
|
5
|
+
return proc(arg);
|
|
6
|
+
}
|
|
7
|
+
function curry2to1(proc, arg1) {
|
|
8
|
+
return (arg2) => proc(arg1, arg2);
|
|
9
|
+
}
|
|
10
|
+
function curry1to0(proc, arg) {
|
|
11
|
+
return () => proc(arg);
|
|
12
|
+
}
|
|
13
|
+
function prop(property) {
|
|
14
|
+
return (object) => object[property];
|
|
15
|
+
}
|
|
16
|
+
function tap(arg, proc) {
|
|
17
|
+
proc(arg);
|
|
18
|
+
return arg;
|
|
19
|
+
}
|
|
20
|
+
function call(proc) {
|
|
21
|
+
proc();
|
|
22
|
+
}
|
|
23
|
+
function always(value) {
|
|
24
|
+
return () => value;
|
|
25
|
+
}
|
|
26
|
+
function joinProc(...procs) {
|
|
27
|
+
return () => {
|
|
28
|
+
procs.map(call);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function noop() {
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
always,
|
|
35
|
+
call,
|
|
36
|
+
compose,
|
|
37
|
+
curry1to0,
|
|
38
|
+
curry2to1,
|
|
39
|
+
joinProc,
|
|
40
|
+
noop,
|
|
41
|
+
prop,
|
|
42
|
+
tap,
|
|
43
|
+
thrush
|
|
44
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function isPartOftheEditorUI(element, editorRoot) {
|
|
2
|
+
if (element === null || element === editorRoot) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
if (element.dataset.editorDialog !== void 0 || element.dataset.toolbarItem !== void 0 || element.dataset.editorDropdown) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return isPartOftheEditorUI(element.parentElement, editorRoot);
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
isPartOftheEditorUI
|
|
12
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { $getSelection, $isRangeSelection, $isElementNode, $getRoot, $isTextNode } from "lexical";
|
|
2
|
+
import { $isLinkNode } from "@lexical/link";
|
|
3
|
+
import { $isHeadingNode } from "@lexical/rich-text";
|
|
4
|
+
import { $isListItemNode, $isListNode } from "@lexical/list";
|
|
5
|
+
import { $isAtNodeEnd } from "@lexical/selection";
|
|
6
|
+
import { tap } from "./fp.js";
|
|
7
|
+
import { exportMarkdownFromLexical } from "../exportMarkdownFromLexical.js";
|
|
8
|
+
function fromWithinEditorRead(editor, fn) {
|
|
9
|
+
let result = null;
|
|
10
|
+
editor.getEditorState().read(() => {
|
|
11
|
+
result = fn();
|
|
12
|
+
});
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
function getSelectedNode(selection) {
|
|
16
|
+
try {
|
|
17
|
+
const anchor = selection.anchor;
|
|
18
|
+
const focus = selection.focus;
|
|
19
|
+
const anchorNode = selection.anchor.getNode();
|
|
20
|
+
const focusNode = selection.focus.getNode();
|
|
21
|
+
if (anchorNode === focusNode) {
|
|
22
|
+
return anchorNode;
|
|
23
|
+
}
|
|
24
|
+
const isBackward = selection.isBackward();
|
|
25
|
+
if (isBackward) {
|
|
26
|
+
return $isAtNodeEnd(focus) ? anchorNode : focusNode;
|
|
27
|
+
} else {
|
|
28
|
+
return $isAtNodeEnd(anchor) ? anchorNode : focusNode;
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const WILL_CHANGE_CONTAINING_BLOCK_PROPS = ["transform", "perspective", "filter", "backdrop-filter", "contain", "container-type"];
|
|
35
|
+
const CONTAIN_VALUES_CREATING_CONTAINING_BLOCK = ["layout", "paint", "strict", "content"];
|
|
36
|
+
function getFixedContainingBlock(element) {
|
|
37
|
+
let current = element?.parentElement;
|
|
38
|
+
while (current) {
|
|
39
|
+
const style = window.getComputedStyle(current);
|
|
40
|
+
const willChangeProps = style.willChange.split(",").map((v) => v.trim());
|
|
41
|
+
const hasRelevantWillChange = willChangeProps.some((prop) => WILL_CHANGE_CONTAINING_BLOCK_PROPS.includes(prop));
|
|
42
|
+
const createsContainingBlock = style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || style.backdropFilter !== "none" || CONTAIN_VALUES_CREATING_CONTAINING_BLOCK.includes(style.contain) || style.containerType !== "normal" || style.contentVisibility === "auto" || hasRelevantWillChange;
|
|
43
|
+
if (createsContainingBlock) {
|
|
44
|
+
return current;
|
|
45
|
+
}
|
|
46
|
+
current = current.parentElement;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function getSelectionRectangle(editor) {
|
|
51
|
+
const selection = $getSelection();
|
|
52
|
+
const nativeSelection = window.getSelection();
|
|
53
|
+
const activeElement = document.activeElement;
|
|
54
|
+
const rootElement = editor.getRootElement();
|
|
55
|
+
if (selection !== null && nativeSelection !== null && rootElement !== null && rootElement.contains(nativeSelection.anchorNode) && editor.isEditable()) {
|
|
56
|
+
const domRange = nativeSelection.getRangeAt(0);
|
|
57
|
+
let rect;
|
|
58
|
+
if (nativeSelection.isCollapsed) {
|
|
59
|
+
let node = nativeSelection.anchorNode;
|
|
60
|
+
if (node?.nodeType == 3) {
|
|
61
|
+
node = node.parentNode;
|
|
62
|
+
}
|
|
63
|
+
rect = node.getBoundingClientRect();
|
|
64
|
+
rect.width = 0;
|
|
65
|
+
} else {
|
|
66
|
+
if (nativeSelection.anchorNode === rootElement) {
|
|
67
|
+
let inner = rootElement;
|
|
68
|
+
while (inner.firstElementChild != null) {
|
|
69
|
+
inner = inner.firstElementChild;
|
|
70
|
+
}
|
|
71
|
+
rect = inner.getBoundingClientRect();
|
|
72
|
+
} else {
|
|
73
|
+
rect = domRange.getBoundingClientRect();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const fixedContainer = getFixedContainingBlock(rootElement);
|
|
77
|
+
if (fixedContainer) {
|
|
78
|
+
const containerRect = fixedContainer.getBoundingClientRect();
|
|
79
|
+
return {
|
|
80
|
+
top: Math.round(rect.top - containerRect.top),
|
|
81
|
+
left: Math.round(rect.left - containerRect.left),
|
|
82
|
+
width: Math.round(rect.width),
|
|
83
|
+
height: Math.round(rect.height)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
top: Math.round(rect.top),
|
|
88
|
+
left: Math.round(rect.left),
|
|
89
|
+
width: Math.round(rect.width),
|
|
90
|
+
height: Math.round(rect.height)
|
|
91
|
+
};
|
|
92
|
+
} else if (activeElement?.className !== "link-input") {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
function getStateAsMarkdown(editor, exportParams) {
|
|
98
|
+
return tap({ markdown: "" }, (result) => {
|
|
99
|
+
editor.getEditorState().read(() => {
|
|
100
|
+
result.markdown = exportMarkdownFromLexical({ root: $getRoot(), ...exportParams });
|
|
101
|
+
});
|
|
102
|
+
}).markdown;
|
|
103
|
+
}
|
|
104
|
+
function getSelectionAsMarkdown(editor, _exportParams) {
|
|
105
|
+
let markdown = "";
|
|
106
|
+
editor.getEditorState().read(() => {
|
|
107
|
+
const selection = $getSelection();
|
|
108
|
+
if (!selection || !$isRangeSelection(selection) || selection.isCollapsed()) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const nodes = selection.getNodes();
|
|
112
|
+
if (nodes.length === 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const parentNodes = /* @__PURE__ */ new Set();
|
|
116
|
+
nodes.forEach((node) => {
|
|
117
|
+
let current = node;
|
|
118
|
+
while (current) {
|
|
119
|
+
if ($isHeadingNode(current) || $isListItemNode(current) || current.getType() === "paragraph" || current.getType() === "quote") {
|
|
120
|
+
if ($isElementNode(current)) {
|
|
121
|
+
parentNodes.add(current);
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
current = current.getParent();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
const nodesToProcess = parentNodes.size > 0 ? Array.from(parentNodes) : nodes;
|
|
129
|
+
function nodeToMarkdown(node) {
|
|
130
|
+
if ($isHeadingNode(node)) {
|
|
131
|
+
const level = parseInt(node.getTag().replace("h", ""));
|
|
132
|
+
const children = node.getChildren();
|
|
133
|
+
const headingText = children.map((child) => nodeToMarkdown(child)).join("");
|
|
134
|
+
return "#".repeat(level) + " " + headingText + "\n\n";
|
|
135
|
+
} else if ($isListItemNode(node)) {
|
|
136
|
+
const parent = node.getParent();
|
|
137
|
+
const prefix = parent && $isListNode(parent) && parent.getListType() === "number" ? "1. " : "- ";
|
|
138
|
+
const children = node.getChildren();
|
|
139
|
+
const itemText = children.map((child) => nodeToMarkdown(child)).join("");
|
|
140
|
+
return prefix + itemText + "\n";
|
|
141
|
+
} else if ($isListNode(node)) {
|
|
142
|
+
const children = node.getChildren();
|
|
143
|
+
return children.map((child) => nodeToMarkdown(child)).join("") + "\n";
|
|
144
|
+
} else if ($isTextNode(node)) {
|
|
145
|
+
let text = node.getTextContent();
|
|
146
|
+
const format = node.getFormat();
|
|
147
|
+
if (format & 16) {
|
|
148
|
+
return `\`${text}\``;
|
|
149
|
+
}
|
|
150
|
+
if (format & 1) {
|
|
151
|
+
text = `**${text}**`;
|
|
152
|
+
}
|
|
153
|
+
if (format & 2) {
|
|
154
|
+
text = `*${text}*`;
|
|
155
|
+
}
|
|
156
|
+
if (format & 4) {
|
|
157
|
+
text = `~~${text}~~`;
|
|
158
|
+
}
|
|
159
|
+
return text;
|
|
160
|
+
} else if ($isLinkNode(node)) {
|
|
161
|
+
const url = node.getURL();
|
|
162
|
+
const title = node.getTitle();
|
|
163
|
+
const children = node.getChildren();
|
|
164
|
+
const linkText = children.map((child) => nodeToMarkdown(child)).join("");
|
|
165
|
+
if (title) {
|
|
166
|
+
return `[${linkText}](${url} "${title}")`;
|
|
167
|
+
}
|
|
168
|
+
return `[${linkText}](${url})`;
|
|
169
|
+
} else if ($isElementNode(node)) {
|
|
170
|
+
const children = node.getChildren();
|
|
171
|
+
return children.map((child) => nodeToMarkdown(child)).join("");
|
|
172
|
+
}
|
|
173
|
+
return node.getTextContent();
|
|
174
|
+
}
|
|
175
|
+
markdown = nodesToProcess.map((node) => nodeToMarkdown(node)).join("");
|
|
176
|
+
});
|
|
177
|
+
return markdown.trim();
|
|
178
|
+
}
|
|
179
|
+
export {
|
|
180
|
+
fromWithinEditorRead,
|
|
181
|
+
getSelectedNode,
|
|
182
|
+
getSelectionAsMarkdown,
|
|
183
|
+
getSelectionRectangle,
|
|
184
|
+
getStateAsMarkdown
|
|
185
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function mergeStyleAttributes(style1, style2) {
|
|
2
|
+
const styleObject1 = styleToObject(style1);
|
|
3
|
+
const styleObject2 = styleToObject(style2);
|
|
4
|
+
const mergedStyleObject = { ...styleObject1, ...styleObject2 };
|
|
5
|
+
const mergedStyleString = objectToStyle(mergedStyleObject);
|
|
6
|
+
return mergedStyleString;
|
|
7
|
+
}
|
|
8
|
+
function styleToObject(style) {
|
|
9
|
+
const styleObject = {};
|
|
10
|
+
const stylePairs = style.split(";").filter((pair) => pair.trim() !== "");
|
|
11
|
+
stylePairs.forEach((pair) => {
|
|
12
|
+
const [key, value] = pair.split(":").map((part) => part.trim());
|
|
13
|
+
styleObject[key] = value;
|
|
14
|
+
});
|
|
15
|
+
return styleObject;
|
|
16
|
+
}
|
|
17
|
+
function objectToStyle(styleObject) {
|
|
18
|
+
return Object.entries(styleObject).map(([key, value]) => `${key}: ${value}`).join("; ");
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
mergeStyleAttributes
|
|
22
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function uuidv4() {
|
|
2
|
+
const hex = [...Array(256).keys()].map((index) => index.toString(16).padStart(2, "0"));
|
|
3
|
+
const r = crypto.getRandomValues(new Uint8Array(16));
|
|
4
|
+
r[6] = r[6] & 15 | 64;
|
|
5
|
+
r[8] = r[8] & 63 | 128;
|
|
6
|
+
return [...r.entries()].map(([index, int]) => [4, 6, 8, 10].includes(index) ? `-${hex[int]}` : hex[int]).join("");
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
uuidv4
|
|
10
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nkzw/mdx-editor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A fast, polished inline Markdown editor for React.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/nkzw-tech/mdx-editor.git"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": [
|
|
12
|
+
"*.css"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./core": {
|
|
24
|
+
"types": "./dist/core.d.ts",
|
|
25
|
+
"import": "./dist/core.js",
|
|
26
|
+
"default": "./dist/core.js"
|
|
27
|
+
},
|
|
28
|
+
"./persistence": {
|
|
29
|
+
"types": "./dist/persistence.d.ts",
|
|
30
|
+
"import": "./dist/persistence.js",
|
|
31
|
+
"default": "./dist/persistence.js"
|
|
32
|
+
},
|
|
33
|
+
"./styles.css": "./dist/styles.css",
|
|
34
|
+
"./style.css": "./dist/styles.css",
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"LICENSE",
|
|
40
|
+
"README.md",
|
|
41
|
+
"UPSTREAM.md"
|
|
42
|
+
],
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@codemirror/commands": "^6.2.4",
|
|
45
|
+
"@codemirror/lang-markdown": "^6.2.3",
|
|
46
|
+
"@codemirror/language-data": "^6.5.1",
|
|
47
|
+
"@codemirror/merge": "^6.4.0",
|
|
48
|
+
"@codemirror/state": "^6.4.0",
|
|
49
|
+
"@codemirror/view": "^6.23.0",
|
|
50
|
+
"@lexical/clipboard": "0.45.0",
|
|
51
|
+
"@lexical/extension": "0.45.0",
|
|
52
|
+
"@lexical/link": "0.45.0",
|
|
53
|
+
"@lexical/list": "0.45.0",
|
|
54
|
+
"@lexical/markdown": "0.45.0",
|
|
55
|
+
"@lexical/plain-text": "0.45.0",
|
|
56
|
+
"@lexical/react": "0.45.0",
|
|
57
|
+
"@lexical/rich-text": "0.45.0",
|
|
58
|
+
"@lexical/selection": "0.45.0",
|
|
59
|
+
"@lexical/utils": "0.45.0",
|
|
60
|
+
"@mdxeditor/gurx": "^1.2.4",
|
|
61
|
+
"@radix-ui/colors": "^3.0.0",
|
|
62
|
+
"@radix-ui/react-dialog": "^1.1.11",
|
|
63
|
+
"@radix-ui/react-icons": "^1.3.2",
|
|
64
|
+
"@radix-ui/react-popover": "^1.1.11",
|
|
65
|
+
"@radix-ui/react-popper": "^1.2.4",
|
|
66
|
+
"@radix-ui/react-select": "^2.2.2",
|
|
67
|
+
"@radix-ui/react-toggle-group": "^1.1.7",
|
|
68
|
+
"@radix-ui/react-toolbar": "^1.1.7",
|
|
69
|
+
"@radix-ui/react-tooltip": "^1.2.4",
|
|
70
|
+
"classnames": "^2.3.2",
|
|
71
|
+
"cm6-theme-basic-light": "^0.2.0",
|
|
72
|
+
"codemirror": "^6.0.1",
|
|
73
|
+
"downshift": "^7.6.0",
|
|
74
|
+
"i18next": "^23.10.0",
|
|
75
|
+
"js-yaml": "4.2.0",
|
|
76
|
+
"lexical": "0.45.0",
|
|
77
|
+
"mdast-util-directive": "^3.0.0",
|
|
78
|
+
"mdast-util-from-markdown": "^2.0.0",
|
|
79
|
+
"mdast-util-frontmatter": "^2.0.1",
|
|
80
|
+
"mdast-util-gfm-strikethrough": "^2.0.0",
|
|
81
|
+
"mdast-util-gfm-table": "^2.0.0",
|
|
82
|
+
"mdast-util-gfm-task-list-item": "^2.0.0",
|
|
83
|
+
"mdast-util-highlight-mark": "^1.2.2",
|
|
84
|
+
"mdast-util-mdx": "^3.0.0",
|
|
85
|
+
"mdast-util-mdx-jsx": "3.0.0",
|
|
86
|
+
"mdast-util-to-markdown": "^2.1.0",
|
|
87
|
+
"micromark-extension-directive": "^3.0.0",
|
|
88
|
+
"micromark-extension-frontmatter": "^2.0.0",
|
|
89
|
+
"micromark-extension-gfm-strikethrough": "^2.0.0",
|
|
90
|
+
"micromark-extension-gfm-table": "^2.0.0",
|
|
91
|
+
"micromark-extension-gfm-task-list-item": "^2.0.1",
|
|
92
|
+
"micromark-extension-highlight-mark": "^1.2.0",
|
|
93
|
+
"micromark-extension-mdx-jsx": "^3.0.0",
|
|
94
|
+
"micromark-extension-mdx-md": "^2.0.0",
|
|
95
|
+
"micromark-extension-mdxjs": "^3.0.0",
|
|
96
|
+
"micromark-factory-space": "^2.0.0",
|
|
97
|
+
"micromark-util-character": "^2.0.1",
|
|
98
|
+
"micromark-util-symbol": "^2.0.0",
|
|
99
|
+
"react-hook-form": "7.56.1",
|
|
100
|
+
"unidiff": "^1.0.2"
|
|
101
|
+
},
|
|
102
|
+
"peerDependencies": {
|
|
103
|
+
"react": ">=18",
|
|
104
|
+
"react-dom": ">=18"
|
|
105
|
+
},
|
|
106
|
+
"devDependencies": {
|
|
107
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
108
|
+
"@testing-library/react": "^16.3.0",
|
|
109
|
+
"@types/js-yaml": "4.0.5",
|
|
110
|
+
"@types/mdast": "^4.0.4",
|
|
111
|
+
"@types/react": "^19.2.0",
|
|
112
|
+
"@types/react-dom": "^19.2.0",
|
|
113
|
+
"@types/unist": "^3.0.3",
|
|
114
|
+
"@vitejs/plugin-react": "^5.1.0",
|
|
115
|
+
"jsdom": "^27.0.0",
|
|
116
|
+
"micromark-util-types": "^2.0.2",
|
|
117
|
+
"postcss-mixins": "^12.1.2",
|
|
118
|
+
"typescript": "^5.9.0",
|
|
119
|
+
"typescript-plugin-css-modules": "^5.2.0",
|
|
120
|
+
"user-agent-data-types": "^0.4.2",
|
|
121
|
+
"vite": "^7.2.0",
|
|
122
|
+
"vite-plugin-dts": "^4.5.4",
|
|
123
|
+
"vite-plugin-svgr": "^4.5.0",
|
|
124
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
125
|
+
"vitest": "^4.1.9"
|
|
126
|
+
},
|
|
127
|
+
"scripts": {
|
|
128
|
+
"build": "vite build",
|
|
129
|
+
"check": "pnpm typecheck && pnpm test && pnpm build",
|
|
130
|
+
"test": "vitest run",
|
|
131
|
+
"typecheck": "tsc --noEmit"
|
|
132
|
+
}
|
|
133
|
+
}
|