mardora 1.2.0 → 1.2.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/{chunk-7JOEPNEV.cjs → chunk-OHZKW7YE.cjs} +43 -11
- package/dist/chunk-OHZKW7YE.cjs.map +1 -0
- package/dist/{chunk-3OCUX4OO.js → chunk-PCXW2FUR.js} +43 -12
- package/dist/chunk-PCXW2FUR.js.map +1 -0
- package/dist/index.cjs +41 -37
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/plugins/index.cjs +28 -24
- package/dist/plugins/index.d.cts +2 -1
- package/dist/plugins/index.d.ts +2 -1
- package/dist/plugins/index.js +1 -1
- package/package.json +1 -1
- package/src/editor/media-lightbox.ts +1 -1
- package/src/plugins/code-plugin.theme.ts +2 -3
- package/src/plugins/code-plugin.ts +2 -0
- package/src/plugins/image-plugin.ts +40 -4
- package/src/plugins/index.ts +1 -1
- package/dist/chunk-3OCUX4OO.js.map +0 -1
- package/dist/chunk-7JOEPNEV.cjs.map +0 -1
|
@@ -3580,7 +3580,7 @@ function createMediaPreviewButton(ownerDocument, options) {
|
|
|
3580
3580
|
}
|
|
3581
3581
|
function openMediaLightbox(ownerDocument, options) {
|
|
3582
3582
|
ownerDocument.querySelector(".cm-mardora-media-lightbox")?.remove();
|
|
3583
|
-
const mountPoint = options.returnFocus?.closest(".cm-editor") ?? ownerDocument.body;
|
|
3583
|
+
const mountPoint = options.returnFocus?.closest(".cm-editor, .mardora-preview") ?? ownerDocument.body;
|
|
3584
3584
|
const root = ownerDocument.createElement("div");
|
|
3585
3585
|
root.className = "cm-mardora-media-lightbox";
|
|
3586
3586
|
root.setAttribute("role", "dialog");
|
|
@@ -3795,6 +3795,7 @@ var imageMarkDecorations = {
|
|
|
3795
3795
|
};
|
|
3796
3796
|
var imageWidthAttributePattern = /^(\s*)\{width=(\d+)\}/;
|
|
3797
3797
|
var minImageWidth = 120;
|
|
3798
|
+
var previewImageIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 3h6v6"></path><path d="m21 3-7 7"></path><path d="M9 21H3v-6"></path><path d="m3 21 7-7"></path></svg>';
|
|
3798
3799
|
function parseImageMarkdown(content) {
|
|
3799
3800
|
const trimmed = content.trim();
|
|
3800
3801
|
const widthMatch = trimmed.match(/\{width=(\d+)\}$/);
|
|
@@ -3853,6 +3854,25 @@ function resolveImageDeleteChange(input) {
|
|
|
3853
3854
|
const range = readImageMarkdownRange(input.doc, input.from, input.to);
|
|
3854
3855
|
return { from: input.from, to: range.to, insert: "" };
|
|
3855
3856
|
}
|
|
3857
|
+
function bindImagePreviewButtons(root) {
|
|
3858
|
+
const onClick = (event) => {
|
|
3859
|
+
const target = event.target && typeof event.target.closest === "function" ? event.target : null;
|
|
3860
|
+
const previewButton = target?.closest(".cm-mardora-image-preview-button[data-src]");
|
|
3861
|
+
if (!previewButton || !root.contains(previewButton)) return;
|
|
3862
|
+
consumeMediaLightboxTrigger(event);
|
|
3863
|
+
openMediaLightbox(previewButton.ownerDocument, {
|
|
3864
|
+
content: {
|
|
3865
|
+
kind: "image",
|
|
3866
|
+
src: previewButton.dataset.src ?? "",
|
|
3867
|
+
alt: previewButton.dataset.alt ?? "",
|
|
3868
|
+
...previewButton.dataset.title ? { title: previewButton.dataset.title } : {}
|
|
3869
|
+
},
|
|
3870
|
+
returnFocus: previewButton
|
|
3871
|
+
});
|
|
3872
|
+
};
|
|
3873
|
+
root.addEventListener("click", onClick);
|
|
3874
|
+
return () => root.removeEventListener("click", onClick);
|
|
3875
|
+
}
|
|
3856
3876
|
var ImageWidget = class extends WidgetType {
|
|
3857
3877
|
constructor(url, alt, from, imageTo, to, width, title) {
|
|
3858
3878
|
super();
|
|
@@ -4049,10 +4069,16 @@ function clampImageWidth(width, maxWidth) {
|
|
|
4049
4069
|
return Math.max(minImageWidth, Math.min(Math.round(width), maxWidth));
|
|
4050
4070
|
}
|
|
4051
4071
|
function resolveImageMaxWidth(view, figure) {
|
|
4052
|
-
const content = figure.closest(".cm-content") ?? view.contentDOM ?? view.dom;
|
|
4072
|
+
const content = figure.closest(".cm-line") ?? figure.closest(".cm-content") ?? view.contentDOM ?? view.dom;
|
|
4053
4073
|
const width = content.getBoundingClientRect().width;
|
|
4054
4074
|
return Math.max(minImageWidth, Math.round(width || figure.getBoundingClientRect().width || 800));
|
|
4055
4075
|
}
|
|
4076
|
+
function renderPreviewImageButton(parsed, ctx) {
|
|
4077
|
+
const titleDataAttr = parsed.title ? ` data-title="${ctx.sanitize(parsed.title)}"` : "";
|
|
4078
|
+
return `<div class="cm-mardora-image-toolbar">
|
|
4079
|
+
<button type="button" class="cm-mardora-image-tool-button cm-mardora-image-preview-button" aria-label="\u653E\u5927\u67E5\u770B\u56FE\u7247" title="\u653E\u5927\u67E5\u770B\u56FE\u7247" data-src="${ctx.sanitize(parsed.url)}" data-alt="${ctx.sanitize(parsed.alt)}"${titleDataAttr}>${previewImageIcon}</button>
|
|
4080
|
+
</div>`;
|
|
4081
|
+
}
|
|
4056
4082
|
var ImagePlugin = class extends DecorationPlugin {
|
|
4057
4083
|
name = "image";
|
|
4058
4084
|
version = "1.0.0";
|
|
@@ -4212,9 +4238,11 @@ var ImagePlugin = class extends DecorationPlugin {
|
|
|
4212
4238
|
const altAttr = ctx.sanitize(parsed.alt);
|
|
4213
4239
|
const titleAttr = parsed.title ? ` title="${ctx.sanitize(parsed.title)}"` : "";
|
|
4214
4240
|
const ariaLabel = parsed.title ? ` aria-label="${ctx.sanitize(parsed.title)}"` : "";
|
|
4215
|
-
const
|
|
4216
|
-
|
|
4217
|
-
html
|
|
4241
|
+
const figureWidthStyle = parsed.width ? ` style="width: ${parsed.width}px;"` : "";
|
|
4242
|
+
const imageWidthStyle = parsed.width ? ` style="width: 100%;"` : "";
|
|
4243
|
+
let html = `<figure class="cm-mardora-image-figure" role="figure"${ariaLabel}${figureWidthStyle}>`;
|
|
4244
|
+
html += `<img class="cm-mardora-image" src="${ctx.sanitize(parsed.url)}" alt="${altAttr}"${titleAttr}${imageWidthStyle} loading="lazy" decoding="async" />`;
|
|
4245
|
+
html += renderPreviewImageButton(parsed, ctx);
|
|
4218
4246
|
if (parsed.title) {
|
|
4219
4247
|
html += `<figcaption class="cm-mardora-image-caption">${ctx.sanitize(parsed.title)}</figcaption>`;
|
|
4220
4248
|
}
|
|
@@ -4260,7 +4288,9 @@ var imageTheme = createTheme({
|
|
|
4260
4288
|
alignItems: "start",
|
|
4261
4289
|
width: "100%",
|
|
4262
4290
|
maxWidth: "100%",
|
|
4263
|
-
|
|
4291
|
+
margin: "0",
|
|
4292
|
+
padding: "0",
|
|
4293
|
+
position: "relative"
|
|
4264
4294
|
},
|
|
4265
4295
|
".cm-mardora-image-toolbar": {
|
|
4266
4296
|
position: "absolute",
|
|
@@ -5124,7 +5154,7 @@ var codePluginTheme = createTheme({
|
|
|
5124
5154
|
// Inline code
|
|
5125
5155
|
".cm-mardora-code-inline": {
|
|
5126
5156
|
fontFamily: "var(--font-jetbrains-mono, monospace)",
|
|
5127
|
-
fontSize: "0.
|
|
5157
|
+
fontSize: "0.9em",
|
|
5128
5158
|
backgroundColor: "rgba(0, 0, 0, 0.05)",
|
|
5129
5159
|
padding: "0.1rem 0.25rem",
|
|
5130
5160
|
border: "1px solid var(--color-border)",
|
|
@@ -5170,12 +5200,11 @@ var codePluginTheme = createTheme({
|
|
|
5170
5200
|
alignItems: "center",
|
|
5171
5201
|
gap: "0.2rem",
|
|
5172
5202
|
position: "absolute",
|
|
5173
|
-
top: "
|
|
5203
|
+
top: "0.5rem",
|
|
5174
5204
|
right: "0.45rem",
|
|
5175
5205
|
zIndex: "20",
|
|
5176
5206
|
opacity: "0",
|
|
5177
5207
|
pointerEvents: "none",
|
|
5178
|
-
transform: "translateY(-50%)",
|
|
5179
5208
|
transition: "opacity 0.12s ease",
|
|
5180
5209
|
color: "var(--color-text, inherit)",
|
|
5181
5210
|
fontFamily: "var(--font-sans, system-ui, sans-serif)",
|
|
@@ -5604,6 +5633,7 @@ var codeLanguageOptions = [
|
|
|
5604
5633
|
["JavaScript", "javascript"],
|
|
5605
5634
|
["JSON", "json"],
|
|
5606
5635
|
["Markdown", "markdown"],
|
|
5636
|
+
["Mermaid", "mermaid"],
|
|
5607
5637
|
["Python", "python"],
|
|
5608
5638
|
["Ruby", "ruby"],
|
|
5609
5639
|
["Rust", "rust"],
|
|
@@ -5630,6 +5660,7 @@ var codeLanguageAliases = {
|
|
|
5630
5660
|
js: "JavaScript",
|
|
5631
5661
|
json: "JSON",
|
|
5632
5662
|
markdown: "Markdown",
|
|
5663
|
+
mermaid: "Mermaid",
|
|
5633
5664
|
md: "Markdown",
|
|
5634
5665
|
python: "Python",
|
|
5635
5666
|
py: "Python",
|
|
@@ -7685,6 +7716,6 @@ var essentialPlugins = [
|
|
|
7685
7716
|
];
|
|
7686
7717
|
var allPlugins = [...essentialPlugins];
|
|
7687
7718
|
|
|
7688
|
-
export { CODE_COPY_SUCCESS_ICON, CodePlugin, EmojiPlugin, HRPlugin, HTMLPlugin, HeadingPlugin, ImagePlugin, InlinePlugin, LinkPlugin, ListPlugin, MathPlugin, MermaidPlugin, ParagraphPlugin, QuotePlugin, TablePlugin, allPlugins, bindCodeCopyButtons, copyCodeTextToClipboard, decodeCodeCopyPayload, encodeCodeCopyPayload, essentialPlugins, resolveCalloutTitleInputTarget, resolveCalloutTypeChange };
|
|
7689
|
-
//# sourceMappingURL=chunk-
|
|
7690
|
-
//# sourceMappingURL=chunk-
|
|
7719
|
+
export { CODE_COPY_SUCCESS_ICON, CodePlugin, EmojiPlugin, HRPlugin, HTMLPlugin, HeadingPlugin, ImagePlugin, InlinePlugin, LinkPlugin, ListPlugin, MathPlugin, MermaidPlugin, ParagraphPlugin, QuotePlugin, TablePlugin, allPlugins, bindCodeCopyButtons, bindImagePreviewButtons, copyCodeTextToClipboard, decodeCodeCopyPayload, encodeCodeCopyPayload, essentialPlugins, resolveCalloutTitleInputTarget, resolveCalloutTypeChange };
|
|
7720
|
+
//# sourceMappingURL=chunk-PCXW2FUR.js.map
|
|
7721
|
+
//# sourceMappingURL=chunk-PCXW2FUR.js.map
|