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.
@@ -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,15 @@ var imageMarkDecorations = {
3823
3823
  };
3824
3824
  var imageWidthAttributePattern = /^(\s*)\{width=(\d+)\}/;
3825
3825
  var minImageWidth = 120;
3826
+ var imageWidgetEditorSelectionEventTypes = /* @__PURE__ */ new Set([
3827
+ "mousedown",
3828
+ "mouseup",
3829
+ "mousemove",
3830
+ "pointerdown",
3831
+ "pointermove",
3832
+ "pointerup"
3833
+ ]);
3834
+ 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
3835
  function parseImageMarkdown(content) {
3827
3836
  const trimmed = content.trim();
3828
3837
  const widthMatch = trimmed.match(/\{width=(\d+)\}$/);
@@ -3881,6 +3890,25 @@ function resolveImageDeleteChange(input) {
3881
3890
  const range = readImageMarkdownRange(input.doc, input.from, input.to);
3882
3891
  return { from: input.from, to: range.to, insert: "" };
3883
3892
  }
3893
+ function bindImagePreviewButtons(root) {
3894
+ const onClick = (event) => {
3895
+ const target = event.target && typeof event.target.closest === "function" ? event.target : null;
3896
+ const previewButton = target?.closest(".cm-mardora-image-preview-button[data-src]");
3897
+ if (!previewButton || !root.contains(previewButton)) return;
3898
+ consumeMediaLightboxTrigger(event);
3899
+ openMediaLightbox(previewButton.ownerDocument, {
3900
+ content: {
3901
+ kind: "image",
3902
+ src: previewButton.dataset.src ?? "",
3903
+ alt: previewButton.dataset.alt ?? "",
3904
+ ...previewButton.dataset.title ? { title: previewButton.dataset.title } : {}
3905
+ },
3906
+ returnFocus: previewButton
3907
+ });
3908
+ };
3909
+ root.addEventListener("click", onClick);
3910
+ return () => root.removeEventListener("click", onClick);
3911
+ }
3884
3912
  var ImageWidget = class extends view.WidgetType {
3885
3913
  constructor(url, alt, from, imageTo, to, width, title) {
3886
3914
  super();
@@ -3965,9 +3993,8 @@ var ImageWidget = class extends view.WidgetType {
3965
3993
  return figure;
3966
3994
  }
3967
3995
  ignoreEvent(event) {
3968
- return !["click", "mousedown", "mouseup", "mousemove", "pointerdown", "pointermove", "pointerup"].includes(
3969
- event.type
3970
- );
3996
+ if (imageWidgetEditorSelectionEventTypes.has(event.type)) return true;
3997
+ return event.type !== "click";
3971
3998
  }
3972
3999
  createToolbar(view, figure) {
3973
4000
  const toolbar = figure.ownerDocument.createElement("div");
@@ -4077,10 +4104,16 @@ function clampImageWidth(width, maxWidth) {
4077
4104
  return Math.max(minImageWidth, Math.min(Math.round(width), maxWidth));
4078
4105
  }
4079
4106
  function resolveImageMaxWidth(view, figure) {
4080
- const content = figure.closest(".cm-content") ?? view.contentDOM ?? view.dom;
4107
+ const content = figure.closest(".cm-line") ?? figure.closest(".cm-content") ?? view.contentDOM ?? view.dom;
4081
4108
  const width = content.getBoundingClientRect().width;
4082
4109
  return Math.max(minImageWidth, Math.round(width || figure.getBoundingClientRect().width || 800));
4083
4110
  }
4111
+ function renderPreviewImageButton(parsed, ctx) {
4112
+ const titleDataAttr = parsed.title ? ` data-title="${ctx.sanitize(parsed.title)}"` : "";
4113
+ return `<div class="cm-mardora-image-toolbar">
4114
+ <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>
4115
+ </div>`;
4116
+ }
4084
4117
  var ImagePlugin = class extends chunkMLBEBFHB_cjs.DecorationPlugin {
4085
4118
  name = "image";
4086
4119
  version = "1.0.0";
@@ -4240,9 +4273,11 @@ var ImagePlugin = class extends chunkMLBEBFHB_cjs.DecorationPlugin {
4240
4273
  const altAttr = ctx.sanitize(parsed.alt);
4241
4274
  const titleAttr = parsed.title ? ` title="${ctx.sanitize(parsed.title)}"` : "";
4242
4275
  const ariaLabel = parsed.title ? ` aria-label="${ctx.sanitize(parsed.title)}"` : "";
4243
- const widthStyle = parsed.width ? ` style="width: ${parsed.width}px;"` : "";
4244
- let html = `<figure class="cm-mardora-image-figure" role="figure"${ariaLabel}>`;
4245
- html += `<img class="cm-mardora-image" src="${ctx.sanitize(parsed.url)}" alt="${altAttr}"${titleAttr}${widthStyle} loading="lazy" decoding="async" />`;
4276
+ const figureWidthStyle = parsed.width ? ` style="width: ${parsed.width}px;"` : "";
4277
+ const imageWidthStyle = parsed.width ? ` style="width: 100%;"` : "";
4278
+ let html = `<figure class="cm-mardora-image-figure" role="figure"${ariaLabel}${figureWidthStyle}>`;
4279
+ html += `<img class="cm-mardora-image" src="${ctx.sanitize(parsed.url)}" alt="${altAttr}"${titleAttr}${imageWidthStyle} loading="lazy" decoding="async" />`;
4280
+ html += renderPreviewImageButton(parsed, ctx);
4246
4281
  if (parsed.title) {
4247
4282
  html += `<figcaption class="cm-mardora-image-caption">${ctx.sanitize(parsed.title)}</figcaption>`;
4248
4283
  }
@@ -4288,7 +4323,9 @@ var imageTheme = chunkWFVCG4LD_cjs.createTheme({
4288
4323
  alignItems: "start",
4289
4324
  width: "100%",
4290
4325
  maxWidth: "100%",
4291
- padding: "0"
4326
+ margin: "0",
4327
+ padding: "0",
4328
+ position: "relative"
4292
4329
  },
4293
4330
  ".cm-mardora-image-toolbar": {
4294
4331
  position: "absolute",
@@ -5152,7 +5189,7 @@ var codePluginTheme = chunkWFVCG4LD_cjs.createTheme({
5152
5189
  // Inline code
5153
5190
  ".cm-mardora-code-inline": {
5154
5191
  fontFamily: "var(--font-jetbrains-mono, monospace)",
5155
- fontSize: "0.9rem",
5192
+ fontSize: "0.9em",
5156
5193
  backgroundColor: "rgba(0, 0, 0, 0.05)",
5157
5194
  padding: "0.1rem 0.25rem",
5158
5195
  border: "1px solid var(--color-border)",
@@ -5198,12 +5235,11 @@ var codePluginTheme = chunkWFVCG4LD_cjs.createTheme({
5198
5235
  alignItems: "center",
5199
5236
  gap: "0.2rem",
5200
5237
  position: "absolute",
5201
- top: "50%",
5238
+ top: "0.5rem",
5202
5239
  right: "0.45rem",
5203
5240
  zIndex: "20",
5204
5241
  opacity: "0",
5205
5242
  pointerEvents: "none",
5206
- transform: "translateY(-50%)",
5207
5243
  transition: "opacity 0.12s ease",
5208
5244
  color: "var(--color-text, inherit)",
5209
5245
  fontFamily: "var(--font-sans, system-ui, sans-serif)",
@@ -5632,6 +5668,7 @@ var codeLanguageOptions = [
5632
5668
  ["JavaScript", "javascript"],
5633
5669
  ["JSON", "json"],
5634
5670
  ["Markdown", "markdown"],
5671
+ ["Mermaid", "mermaid"],
5635
5672
  ["Python", "python"],
5636
5673
  ["Ruby", "ruby"],
5637
5674
  ["Rust", "rust"],
@@ -5658,6 +5695,7 @@ var codeLanguageAliases = {
5658
5695
  js: "JavaScript",
5659
5696
  json: "JSON",
5660
5697
  markdown: "Markdown",
5698
+ mermaid: "Mermaid",
5661
5699
  md: "Markdown",
5662
5700
  python: "Python",
5663
5701
  py: "Python",
@@ -7730,11 +7768,12 @@ exports.QuotePlugin = QuotePlugin;
7730
7768
  exports.TablePlugin = TablePlugin;
7731
7769
  exports.allPlugins = allPlugins;
7732
7770
  exports.bindCodeCopyButtons = bindCodeCopyButtons;
7771
+ exports.bindImagePreviewButtons = bindImagePreviewButtons;
7733
7772
  exports.copyCodeTextToClipboard = copyCodeTextToClipboard;
7734
7773
  exports.decodeCodeCopyPayload = decodeCodeCopyPayload;
7735
7774
  exports.encodeCodeCopyPayload = encodeCodeCopyPayload;
7736
7775
  exports.essentialPlugins = essentialPlugins;
7737
7776
  exports.resolveCalloutTitleInputTarget = resolveCalloutTitleInputTarget;
7738
7777
  exports.resolveCalloutTypeChange = resolveCalloutTypeChange;
7739
- //# sourceMappingURL=chunk-7JOEPNEV.cjs.map
7740
- //# sourceMappingURL=chunk-7JOEPNEV.cjs.map
7778
+ //# sourceMappingURL=chunk-U3D2P2CM.cjs.map
7779
+ //# sourceMappingURL=chunk-U3D2P2CM.cjs.map