@jvs-milkdown/crepe 1.2.26 → 1.2.28

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.
Files changed (34) hide show
  1. package/lib/cjs/feature/block-edit/index.js +3 -3
  2. package/lib/cjs/feature/block-edit/index.js.map +1 -1
  3. package/lib/cjs/feature/code-mirror/index.js +63 -1
  4. package/lib/cjs/feature/code-mirror/index.js.map +1 -1
  5. package/lib/cjs/feature/toolbar/index.js +1 -1
  6. package/lib/cjs/feature/toolbar/index.js.map +1 -1
  7. package/lib/cjs/index.js +79 -5
  8. package/lib/cjs/index.js.map +1 -1
  9. package/lib/esm/feature/block-edit/index.js +3 -3
  10. package/lib/esm/feature/block-edit/index.js.map +1 -1
  11. package/lib/esm/feature/code-mirror/index.js +63 -1
  12. package/lib/esm/feature/code-mirror/index.js.map +1 -1
  13. package/lib/esm/feature/toolbar/index.js +1 -1
  14. package/lib/esm/feature/toolbar/index.js.map +1 -1
  15. package/lib/esm/index.js +79 -5
  16. package/lib/esm/index.js.map +1 -1
  17. package/lib/theme/common/block-edit.css +5 -3
  18. package/lib/theme/common/code-mirror.css +19 -0
  19. package/lib/theme/common/link-tooltip.css +2 -2
  20. package/lib/theme/common/toolbar.css +1 -1
  21. package/lib/tsconfig.tsbuildinfo +1 -1
  22. package/lib/types/default-config/index.d.ts.map +1 -1
  23. package/lib/types/feature/block-edit/handle/index.d.ts.map +1 -1
  24. package/lib/types/feature/block-edit/menu/component.d.ts.map +1 -1
  25. package/lib/types/feature/code-mirror/index.d.ts.map +1 -1
  26. package/package.json +5 -4
  27. package/src/default-config/index.ts +17 -1
  28. package/src/feature/block-edit/handle/index.ts +8 -2
  29. package/src/feature/block-edit/menu/component.tsx +4 -1
  30. package/src/feature/code-mirror/index.ts +72 -1
  31. package/src/theme/common/block-edit.css +5 -3
  32. package/src/theme/common/code-mirror.css +19 -0
  33. package/src/theme/common/link-tooltip.css +2 -2
  34. package/src/theme/common/toolbar.css +1 -1
package/lib/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { replaceAll, $prose as $prose$1, getHTML } from '@jvs-milkdown/utils';
2
2
  import { defaultsDeep } from 'lodash-es';
3
+ import { LanguageDescription } from '@codemirror/language';
3
4
  import { languages } from '@codemirror/language-data';
4
5
  import { oneDark } from '@codemirror/theme-one-dark';
5
6
  import { createSlice } from '@jvs-milkdown/kit/ctx';
@@ -675,10 +676,21 @@ const importIcon = `
675
676
  </svg>
676
677
  `;
677
678
 
679
+ const mermaidLanguage = LanguageDescription.of({
680
+ name: "Mermaid",
681
+ alias: ["mermaid"],
682
+ load: () => {
683
+ const fallback = languages.find((l) => l.name === "YAML") || languages.find((l) => l.name === "Markdown");
684
+ return fallback ? fallback.load() : Promise.resolve(null);
685
+ }
686
+ });
687
+ const allLanguages = [mermaidLanguage, ...languages].sort(
688
+ (a, b) => a.name.localeCompare(b.name)
689
+ );
678
690
  const defaultConfig = {
679
691
  [CrepeFeature.CodeMirror]: {
680
692
  theme: oneDark,
681
- languages,
693
+ languages: allLanguages,
682
694
  expandIcon: chevronDownIcon,
683
695
  searchIcon,
684
696
  clearSearchIcon: clearIcon,
@@ -3064,7 +3076,7 @@ const Menu = defineComponent({
3064
3076
  const isTableBlock = (node == null ? void 0 : node.type.name) === "table";
3065
3077
  const isMedia = ((_a = node == null ? void 0 : node.type.name) == null ? void 0 : _a.includes("image")) || isAttachmentBlock || isImageParagraph || (node == null ? void 0 : node.type.name) === "hr" || isTableBlock;
3066
3078
  const showAlign = !isMedia || isImageBlock;
3067
- const isEmpty = node ? node.textContent.length === 0 && node.content.size <= 2 && !isMedia : false;
3079
+ const isEmpty = node ? node.type.name === "paragraph" && node.textContent.length === 0 && node.content.size <= 2 && !isMedia : false;
3068
3080
  const currentAlign = ((_b = node == null ? void 0 : node.attrs) == null ? void 0 : _b.align) || "left";
3069
3081
  const currentIndent = ((_c = node == null ? void 0 : node.attrs) == null ? void 0 : _c.indent) || 0;
3070
3082
  const setAlign = (alignValue) => {
@@ -4020,7 +4032,7 @@ class BlockHandleView {
4020
4032
  });
4021
4033
  }
4022
4034
  const isMedia = node.type.name.includes("image") || node.type.name.includes("attachment") || node.type.name === "hr" || node.type.name.includes("math") || hasMediaChild;
4023
- const isEmpty = node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
4035
+ const isEmpty = node.type.name === "paragraph" && node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
4024
4036
  if (isEmpty) {
4025
4037
  __privateGet$5(this, _content$3).classList.add("empty-block");
4026
4038
  } else {
@@ -4171,7 +4183,7 @@ class BlockHandleView {
4171
4183
  });
4172
4184
  }
4173
4185
  const isMedia = node.type.name.includes("image") || node.type.name.includes("attachment") || node.type.name === "hr" || node.type.name.includes("math") || hasMediaChild;
4174
- const isEmpty = node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
4186
+ const isEmpty = node.type.name === "paragraph" && node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
4175
4187
  if (isEmpty) {
4176
4188
  __privateGet$5(this, _content$3).classList.add("empty-block");
4177
4189
  } else {
@@ -4276,7 +4288,69 @@ const codeMirror = (editor, config = {}) => {
4276
4288
  }),
4277
4289
  noResultText: config.noResultText || i18n(ctx, "codeMirror.noResultText"),
4278
4290
  renderLanguage: config.renderLanguage || defaultConfig.renderLanguage,
4279
- renderPreview: config.renderPreview || defaultConfig.renderPreview,
4291
+ renderPreview: config.renderPreview || ((language, content, applyPreview) => {
4292
+ if (language.toLowerCase() === "mermaid" && content.trim().length > 0) {
4293
+ import('mermaid').then(({ default: mermaid }) => {
4294
+ mermaid.initialize({
4295
+ startOnLoad: false,
4296
+ theme: "default",
4297
+ themeVariables: {
4298
+ fontFamily: '"trebuchet ms", verdana, arial, sans-serif'
4299
+ }
4300
+ });
4301
+ if (typeof document !== "undefined") {
4302
+ const styleId = "mermaid-global-measurement-styles";
4303
+ if (!document.getElementById(styleId)) {
4304
+ const styleEl = document.createElement("style");
4305
+ styleEl.id = styleId;
4306
+ styleEl.textContent = `
4307
+ body,
4308
+ .mermaid,
4309
+ .relationshipLabel,
4310
+ .edgeLabel,
4311
+ .edgeLabelText,
4312
+ .label,
4313
+ .nodeLabel,
4314
+ svg * {
4315
+ font-family: "trebuchet ms", verdana, arial, sans-serif !important;
4316
+ line-height: normal !important;
4317
+ }
4318
+ .relationshipLabel,
4319
+ .relationshipLabel *,
4320
+ .edgeLabel,
4321
+ .edgeLabel *,
4322
+ .edgeLabelText,
4323
+ .edgeLabelText * {
4324
+ font-size: 11px !important;
4325
+ }
4326
+ svg foreignObject {
4327
+ overflow: visible !important;
4328
+ }
4329
+ `;
4330
+ document.head.appendChild(styleEl);
4331
+ }
4332
+ }
4333
+ const id = `mermaid-${Math.random().toString(36).substring(2, 9)}`;
4334
+ mermaid.render(id, content).then(({ svg }) => {
4335
+ applyPreview(svg);
4336
+ }).catch((e) => {
4337
+ const errorEl = document.getElementById(`d${id}`);
4338
+ if (errorEl) {
4339
+ errorEl.remove();
4340
+ }
4341
+ applyPreview(
4342
+ `<div class="mermaid-error" style="color: red; padding: 10px; font-family: monospace;">${e instanceof Error ? e.message : String(e)}</div>`
4343
+ );
4344
+ });
4345
+ }).catch((err) => {
4346
+ applyPreview(
4347
+ `<div class="mermaid-error" style="color: red; padding: 10px; font-family: monospace;">Failed to load mermaid: ${err.message}</div>`
4348
+ );
4349
+ });
4350
+ return;
4351
+ }
4352
+ return defaultConfig.renderPreview(language, content, applyPreview);
4353
+ }),
4280
4354
  previewToggleButton: (previewOnlyMode) => {
4281
4355
  var _a2, _b;
4282
4356
  const icon = ((_a2 = config.previewToggleIcon) == null ? void 0 : _a2.call(config, previewOnlyMode)) || (previewOnlyMode ? editIcon : visibilityOffIcon);