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
|
@@ -3608,7 +3608,7 @@ function createMediaPreviewButton(ownerDocument, options) {
|
|
|
3608
3608
|
}
|
|
3609
3609
|
function openMediaLightbox(ownerDocument, options) {
|
|
3610
3610
|
ownerDocument.querySelector(".cm-mardora-media-lightbox")?.remove();
|
|
3611
|
-
const mountPoint = options.returnFocus?.closest(".cm-editor") ?? ownerDocument.body;
|
|
3611
|
+
const mountPoint = options.returnFocus?.closest(".cm-editor, .mardora-preview") ?? ownerDocument.body;
|
|
3612
3612
|
const root = ownerDocument.createElement("div");
|
|
3613
3613
|
root.className = "cm-mardora-media-lightbox";
|
|
3614
3614
|
root.setAttribute("role", "dialog");
|
|
@@ -3823,6 +3823,7 @@ var imageMarkDecorations = {
|
|
|
3823
3823
|
};
|
|
3824
3824
|
var imageWidthAttributePattern = /^(\s*)\{width=(\d+)\}/;
|
|
3825
3825
|
var minImageWidth = 120;
|
|
3826
|
+
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>';
|
|
3826
3827
|
function parseImageMarkdown(content) {
|
|
3827
3828
|
const trimmed = content.trim();
|
|
3828
3829
|
const widthMatch = trimmed.match(/\{width=(\d+)\}$/);
|
|
@@ -3881,6 +3882,25 @@ function resolveImageDeleteChange(input) {
|
|
|
3881
3882
|
const range = readImageMarkdownRange(input.doc, input.from, input.to);
|
|
3882
3883
|
return { from: input.from, to: range.to, insert: "" };
|
|
3883
3884
|
}
|
|
3885
|
+
function bindImagePreviewButtons(root) {
|
|
3886
|
+
const onClick = (event) => {
|
|
3887
|
+
const target = event.target && typeof event.target.closest === "function" ? event.target : null;
|
|
3888
|
+
const previewButton = target?.closest(".cm-mardora-image-preview-button[data-src]");
|
|
3889
|
+
if (!previewButton || !root.contains(previewButton)) return;
|
|
3890
|
+
consumeMediaLightboxTrigger(event);
|
|
3891
|
+
openMediaLightbox(previewButton.ownerDocument, {
|
|
3892
|
+
content: {
|
|
3893
|
+
kind: "image",
|
|
3894
|
+
src: previewButton.dataset.src ?? "",
|
|
3895
|
+
alt: previewButton.dataset.alt ?? "",
|
|
3896
|
+
...previewButton.dataset.title ? { title: previewButton.dataset.title } : {}
|
|
3897
|
+
},
|
|
3898
|
+
returnFocus: previewButton
|
|
3899
|
+
});
|
|
3900
|
+
};
|
|
3901
|
+
root.addEventListener("click", onClick);
|
|
3902
|
+
return () => root.removeEventListener("click", onClick);
|
|
3903
|
+
}
|
|
3884
3904
|
var ImageWidget = class extends view.WidgetType {
|
|
3885
3905
|
constructor(url, alt, from, imageTo, to, width, title) {
|
|
3886
3906
|
super();
|
|
@@ -4077,10 +4097,16 @@ function clampImageWidth(width, maxWidth) {
|
|
|
4077
4097
|
return Math.max(minImageWidth, Math.min(Math.round(width), maxWidth));
|
|
4078
4098
|
}
|
|
4079
4099
|
function resolveImageMaxWidth(view, figure) {
|
|
4080
|
-
const content = figure.closest(".cm-content") ?? view.contentDOM ?? view.dom;
|
|
4100
|
+
const content = figure.closest(".cm-line") ?? figure.closest(".cm-content") ?? view.contentDOM ?? view.dom;
|
|
4081
4101
|
const width = content.getBoundingClientRect().width;
|
|
4082
4102
|
return Math.max(minImageWidth, Math.round(width || figure.getBoundingClientRect().width || 800));
|
|
4083
4103
|
}
|
|
4104
|
+
function renderPreviewImageButton(parsed, ctx) {
|
|
4105
|
+
const titleDataAttr = parsed.title ? ` data-title="${ctx.sanitize(parsed.title)}"` : "";
|
|
4106
|
+
return `<div class="cm-mardora-image-toolbar">
|
|
4107
|
+
<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>
|
|
4108
|
+
</div>`;
|
|
4109
|
+
}
|
|
4084
4110
|
var ImagePlugin = class extends chunkMLBEBFHB_cjs.DecorationPlugin {
|
|
4085
4111
|
name = "image";
|
|
4086
4112
|
version = "1.0.0";
|
|
@@ -4240,9 +4266,11 @@ var ImagePlugin = class extends chunkMLBEBFHB_cjs.DecorationPlugin {
|
|
|
4240
4266
|
const altAttr = ctx.sanitize(parsed.alt);
|
|
4241
4267
|
const titleAttr = parsed.title ? ` title="${ctx.sanitize(parsed.title)}"` : "";
|
|
4242
4268
|
const ariaLabel = parsed.title ? ` aria-label="${ctx.sanitize(parsed.title)}"` : "";
|
|
4243
|
-
const
|
|
4244
|
-
|
|
4245
|
-
html
|
|
4269
|
+
const figureWidthStyle = parsed.width ? ` style="width: ${parsed.width}px;"` : "";
|
|
4270
|
+
const imageWidthStyle = parsed.width ? ` style="width: 100%;"` : "";
|
|
4271
|
+
let html = `<figure class="cm-mardora-image-figure" role="figure"${ariaLabel}${figureWidthStyle}>`;
|
|
4272
|
+
html += `<img class="cm-mardora-image" src="${ctx.sanitize(parsed.url)}" alt="${altAttr}"${titleAttr}${imageWidthStyle} loading="lazy" decoding="async" />`;
|
|
4273
|
+
html += renderPreviewImageButton(parsed, ctx);
|
|
4246
4274
|
if (parsed.title) {
|
|
4247
4275
|
html += `<figcaption class="cm-mardora-image-caption">${ctx.sanitize(parsed.title)}</figcaption>`;
|
|
4248
4276
|
}
|
|
@@ -4288,7 +4316,9 @@ var imageTheme = chunkWFVCG4LD_cjs.createTheme({
|
|
|
4288
4316
|
alignItems: "start",
|
|
4289
4317
|
width: "100%",
|
|
4290
4318
|
maxWidth: "100%",
|
|
4291
|
-
|
|
4319
|
+
margin: "0",
|
|
4320
|
+
padding: "0",
|
|
4321
|
+
position: "relative"
|
|
4292
4322
|
},
|
|
4293
4323
|
".cm-mardora-image-toolbar": {
|
|
4294
4324
|
position: "absolute",
|
|
@@ -5152,7 +5182,7 @@ var codePluginTheme = chunkWFVCG4LD_cjs.createTheme({
|
|
|
5152
5182
|
// Inline code
|
|
5153
5183
|
".cm-mardora-code-inline": {
|
|
5154
5184
|
fontFamily: "var(--font-jetbrains-mono, monospace)",
|
|
5155
|
-
fontSize: "0.
|
|
5185
|
+
fontSize: "0.9em",
|
|
5156
5186
|
backgroundColor: "rgba(0, 0, 0, 0.05)",
|
|
5157
5187
|
padding: "0.1rem 0.25rem",
|
|
5158
5188
|
border: "1px solid var(--color-border)",
|
|
@@ -5198,12 +5228,11 @@ var codePluginTheme = chunkWFVCG4LD_cjs.createTheme({
|
|
|
5198
5228
|
alignItems: "center",
|
|
5199
5229
|
gap: "0.2rem",
|
|
5200
5230
|
position: "absolute",
|
|
5201
|
-
top: "
|
|
5231
|
+
top: "0.5rem",
|
|
5202
5232
|
right: "0.45rem",
|
|
5203
5233
|
zIndex: "20",
|
|
5204
5234
|
opacity: "0",
|
|
5205
5235
|
pointerEvents: "none",
|
|
5206
|
-
transform: "translateY(-50%)",
|
|
5207
5236
|
transition: "opacity 0.12s ease",
|
|
5208
5237
|
color: "var(--color-text, inherit)",
|
|
5209
5238
|
fontFamily: "var(--font-sans, system-ui, sans-serif)",
|
|
@@ -5632,6 +5661,7 @@ var codeLanguageOptions = [
|
|
|
5632
5661
|
["JavaScript", "javascript"],
|
|
5633
5662
|
["JSON", "json"],
|
|
5634
5663
|
["Markdown", "markdown"],
|
|
5664
|
+
["Mermaid", "mermaid"],
|
|
5635
5665
|
["Python", "python"],
|
|
5636
5666
|
["Ruby", "ruby"],
|
|
5637
5667
|
["Rust", "rust"],
|
|
@@ -5658,6 +5688,7 @@ var codeLanguageAliases = {
|
|
|
5658
5688
|
js: "JavaScript",
|
|
5659
5689
|
json: "JSON",
|
|
5660
5690
|
markdown: "Markdown",
|
|
5691
|
+
mermaid: "Mermaid",
|
|
5661
5692
|
md: "Markdown",
|
|
5662
5693
|
python: "Python",
|
|
5663
5694
|
py: "Python",
|
|
@@ -7730,11 +7761,12 @@ exports.QuotePlugin = QuotePlugin;
|
|
|
7730
7761
|
exports.TablePlugin = TablePlugin;
|
|
7731
7762
|
exports.allPlugins = allPlugins;
|
|
7732
7763
|
exports.bindCodeCopyButtons = bindCodeCopyButtons;
|
|
7764
|
+
exports.bindImagePreviewButtons = bindImagePreviewButtons;
|
|
7733
7765
|
exports.copyCodeTextToClipboard = copyCodeTextToClipboard;
|
|
7734
7766
|
exports.decodeCodeCopyPayload = decodeCodeCopyPayload;
|
|
7735
7767
|
exports.encodeCodeCopyPayload = encodeCodeCopyPayload;
|
|
7736
7768
|
exports.essentialPlugins = essentialPlugins;
|
|
7737
7769
|
exports.resolveCalloutTitleInputTarget = resolveCalloutTitleInputTarget;
|
|
7738
7770
|
exports.resolveCalloutTypeChange = resolveCalloutTypeChange;
|
|
7739
|
-
//# sourceMappingURL=chunk-
|
|
7740
|
-
//# sourceMappingURL=chunk-
|
|
7771
|
+
//# sourceMappingURL=chunk-OHZKW7YE.cjs.map
|
|
7772
|
+
//# sourceMappingURL=chunk-OHZKW7YE.cjs.map
|