mardora 1.2.0 → 1.2.2
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-3OCUX4OO.js → chunk-SMHHXYOS.js} +53 -15
- package/dist/chunk-SMHHXYOS.js.map +1 -0
- package/dist/{chunk-7JOEPNEV.cjs → chunk-U3D2P2CM.cjs} +53 -14
- package/dist/chunk-U3D2P2CM.cjs.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 +50 -7
- 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,15 @@ var imageMarkDecorations = {
|
|
|
3795
3795
|
};
|
|
3796
3796
|
var imageWidthAttributePattern = /^(\s*)\{width=(\d+)\}/;
|
|
3797
3797
|
var minImageWidth = 120;
|
|
3798
|
+
var imageWidgetEditorSelectionEventTypes = /* @__PURE__ */ new Set([
|
|
3799
|
+
"mousedown",
|
|
3800
|
+
"mouseup",
|
|
3801
|
+
"mousemove",
|
|
3802
|
+
"pointerdown",
|
|
3803
|
+
"pointermove",
|
|
3804
|
+
"pointerup"
|
|
3805
|
+
]);
|
|
3806
|
+
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
3807
|
function parseImageMarkdown(content) {
|
|
3799
3808
|
const trimmed = content.trim();
|
|
3800
3809
|
const widthMatch = trimmed.match(/\{width=(\d+)\}$/);
|
|
@@ -3853,6 +3862,25 @@ function resolveImageDeleteChange(input) {
|
|
|
3853
3862
|
const range = readImageMarkdownRange(input.doc, input.from, input.to);
|
|
3854
3863
|
return { from: input.from, to: range.to, insert: "" };
|
|
3855
3864
|
}
|
|
3865
|
+
function bindImagePreviewButtons(root) {
|
|
3866
|
+
const onClick = (event) => {
|
|
3867
|
+
const target = event.target && typeof event.target.closest === "function" ? event.target : null;
|
|
3868
|
+
const previewButton = target?.closest(".cm-mardora-image-preview-button[data-src]");
|
|
3869
|
+
if (!previewButton || !root.contains(previewButton)) return;
|
|
3870
|
+
consumeMediaLightboxTrigger(event);
|
|
3871
|
+
openMediaLightbox(previewButton.ownerDocument, {
|
|
3872
|
+
content: {
|
|
3873
|
+
kind: "image",
|
|
3874
|
+
src: previewButton.dataset.src ?? "",
|
|
3875
|
+
alt: previewButton.dataset.alt ?? "",
|
|
3876
|
+
...previewButton.dataset.title ? { title: previewButton.dataset.title } : {}
|
|
3877
|
+
},
|
|
3878
|
+
returnFocus: previewButton
|
|
3879
|
+
});
|
|
3880
|
+
};
|
|
3881
|
+
root.addEventListener("click", onClick);
|
|
3882
|
+
return () => root.removeEventListener("click", onClick);
|
|
3883
|
+
}
|
|
3856
3884
|
var ImageWidget = class extends WidgetType {
|
|
3857
3885
|
constructor(url, alt, from, imageTo, to, width, title) {
|
|
3858
3886
|
super();
|
|
@@ -3937,9 +3965,8 @@ var ImageWidget = class extends WidgetType {
|
|
|
3937
3965
|
return figure;
|
|
3938
3966
|
}
|
|
3939
3967
|
ignoreEvent(event) {
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
);
|
|
3968
|
+
if (imageWidgetEditorSelectionEventTypes.has(event.type)) return true;
|
|
3969
|
+
return event.type !== "click";
|
|
3943
3970
|
}
|
|
3944
3971
|
createToolbar(view, figure) {
|
|
3945
3972
|
const toolbar = figure.ownerDocument.createElement("div");
|
|
@@ -4049,10 +4076,16 @@ function clampImageWidth(width, maxWidth) {
|
|
|
4049
4076
|
return Math.max(minImageWidth, Math.min(Math.round(width), maxWidth));
|
|
4050
4077
|
}
|
|
4051
4078
|
function resolveImageMaxWidth(view, figure) {
|
|
4052
|
-
const content = figure.closest(".cm-content") ?? view.contentDOM ?? view.dom;
|
|
4079
|
+
const content = figure.closest(".cm-line") ?? figure.closest(".cm-content") ?? view.contentDOM ?? view.dom;
|
|
4053
4080
|
const width = content.getBoundingClientRect().width;
|
|
4054
4081
|
return Math.max(minImageWidth, Math.round(width || figure.getBoundingClientRect().width || 800));
|
|
4055
4082
|
}
|
|
4083
|
+
function renderPreviewImageButton(parsed, ctx) {
|
|
4084
|
+
const titleDataAttr = parsed.title ? ` data-title="${ctx.sanitize(parsed.title)}"` : "";
|
|
4085
|
+
return `<div class="cm-mardora-image-toolbar">
|
|
4086
|
+
<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>
|
|
4087
|
+
</div>`;
|
|
4088
|
+
}
|
|
4056
4089
|
var ImagePlugin = class extends DecorationPlugin {
|
|
4057
4090
|
name = "image";
|
|
4058
4091
|
version = "1.0.0";
|
|
@@ -4212,9 +4245,11 @@ var ImagePlugin = class extends DecorationPlugin {
|
|
|
4212
4245
|
const altAttr = ctx.sanitize(parsed.alt);
|
|
4213
4246
|
const titleAttr = parsed.title ? ` title="${ctx.sanitize(parsed.title)}"` : "";
|
|
4214
4247
|
const ariaLabel = parsed.title ? ` aria-label="${ctx.sanitize(parsed.title)}"` : "";
|
|
4215
|
-
const
|
|
4216
|
-
|
|
4217
|
-
html
|
|
4248
|
+
const figureWidthStyle = parsed.width ? ` style="width: ${parsed.width}px;"` : "";
|
|
4249
|
+
const imageWidthStyle = parsed.width ? ` style="width: 100%;"` : "";
|
|
4250
|
+
let html = `<figure class="cm-mardora-image-figure" role="figure"${ariaLabel}${figureWidthStyle}>`;
|
|
4251
|
+
html += `<img class="cm-mardora-image" src="${ctx.sanitize(parsed.url)}" alt="${altAttr}"${titleAttr}${imageWidthStyle} loading="lazy" decoding="async" />`;
|
|
4252
|
+
html += renderPreviewImageButton(parsed, ctx);
|
|
4218
4253
|
if (parsed.title) {
|
|
4219
4254
|
html += `<figcaption class="cm-mardora-image-caption">${ctx.sanitize(parsed.title)}</figcaption>`;
|
|
4220
4255
|
}
|
|
@@ -4260,7 +4295,9 @@ var imageTheme = createTheme({
|
|
|
4260
4295
|
alignItems: "start",
|
|
4261
4296
|
width: "100%",
|
|
4262
4297
|
maxWidth: "100%",
|
|
4263
|
-
|
|
4298
|
+
margin: "0",
|
|
4299
|
+
padding: "0",
|
|
4300
|
+
position: "relative"
|
|
4264
4301
|
},
|
|
4265
4302
|
".cm-mardora-image-toolbar": {
|
|
4266
4303
|
position: "absolute",
|
|
@@ -5124,7 +5161,7 @@ var codePluginTheme = createTheme({
|
|
|
5124
5161
|
// Inline code
|
|
5125
5162
|
".cm-mardora-code-inline": {
|
|
5126
5163
|
fontFamily: "var(--font-jetbrains-mono, monospace)",
|
|
5127
|
-
fontSize: "0.
|
|
5164
|
+
fontSize: "0.9em",
|
|
5128
5165
|
backgroundColor: "rgba(0, 0, 0, 0.05)",
|
|
5129
5166
|
padding: "0.1rem 0.25rem",
|
|
5130
5167
|
border: "1px solid var(--color-border)",
|
|
@@ -5170,12 +5207,11 @@ var codePluginTheme = createTheme({
|
|
|
5170
5207
|
alignItems: "center",
|
|
5171
5208
|
gap: "0.2rem",
|
|
5172
5209
|
position: "absolute",
|
|
5173
|
-
top: "
|
|
5210
|
+
top: "0.5rem",
|
|
5174
5211
|
right: "0.45rem",
|
|
5175
5212
|
zIndex: "20",
|
|
5176
5213
|
opacity: "0",
|
|
5177
5214
|
pointerEvents: "none",
|
|
5178
|
-
transform: "translateY(-50%)",
|
|
5179
5215
|
transition: "opacity 0.12s ease",
|
|
5180
5216
|
color: "var(--color-text, inherit)",
|
|
5181
5217
|
fontFamily: "var(--font-sans, system-ui, sans-serif)",
|
|
@@ -5604,6 +5640,7 @@ var codeLanguageOptions = [
|
|
|
5604
5640
|
["JavaScript", "javascript"],
|
|
5605
5641
|
["JSON", "json"],
|
|
5606
5642
|
["Markdown", "markdown"],
|
|
5643
|
+
["Mermaid", "mermaid"],
|
|
5607
5644
|
["Python", "python"],
|
|
5608
5645
|
["Ruby", "ruby"],
|
|
5609
5646
|
["Rust", "rust"],
|
|
@@ -5630,6 +5667,7 @@ var codeLanguageAliases = {
|
|
|
5630
5667
|
js: "JavaScript",
|
|
5631
5668
|
json: "JSON",
|
|
5632
5669
|
markdown: "Markdown",
|
|
5670
|
+
mermaid: "Mermaid",
|
|
5633
5671
|
md: "Markdown",
|
|
5634
5672
|
python: "Python",
|
|
5635
5673
|
py: "Python",
|
|
@@ -7685,6 +7723,6 @@ var essentialPlugins = [
|
|
|
7685
7723
|
];
|
|
7686
7724
|
var allPlugins = [...essentialPlugins];
|
|
7687
7725
|
|
|
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-
|
|
7726
|
+
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 };
|
|
7727
|
+
//# sourceMappingURL=chunk-SMHHXYOS.js.map
|
|
7728
|
+
//# sourceMappingURL=chunk-SMHHXYOS.js.map
|