@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.
- package/lib/cjs/feature/block-edit/index.js +3 -3
- package/lib/cjs/feature/block-edit/index.js.map +1 -1
- package/lib/cjs/feature/code-mirror/index.js +63 -1
- package/lib/cjs/feature/code-mirror/index.js.map +1 -1
- package/lib/cjs/feature/toolbar/index.js +1 -1
- package/lib/cjs/feature/toolbar/index.js.map +1 -1
- package/lib/cjs/index.js +79 -5
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/feature/block-edit/index.js +3 -3
- package/lib/esm/feature/block-edit/index.js.map +1 -1
- package/lib/esm/feature/code-mirror/index.js +63 -1
- package/lib/esm/feature/code-mirror/index.js.map +1 -1
- package/lib/esm/feature/toolbar/index.js +1 -1
- package/lib/esm/feature/toolbar/index.js.map +1 -1
- package/lib/esm/index.js +79 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/theme/common/block-edit.css +5 -3
- package/lib/theme/common/code-mirror.css +19 -0
- package/lib/theme/common/link-tooltip.css +2 -2
- package/lib/theme/common/toolbar.css +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/default-config/index.d.ts.map +1 -1
- package/lib/types/feature/block-edit/handle/index.d.ts.map +1 -1
- package/lib/types/feature/block-edit/menu/component.d.ts.map +1 -1
- package/lib/types/feature/code-mirror/index.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/default-config/index.ts +17 -1
- package/src/feature/block-edit/handle/index.ts +8 -2
- package/src/feature/block-edit/menu/component.tsx +4 -1
- package/src/feature/code-mirror/index.ts +72 -1
- package/src/theme/common/block-edit.css +5 -3
- package/src/theme/common/code-mirror.css +19 -0
- package/src/theme/common/link-tooltip.css +2 -2
- package/src/theme/common/toolbar.css +1 -1
package/lib/cjs/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var utils$1 = require('@jvs-milkdown/utils');
|
|
4
4
|
var lodashEs = require('lodash-es');
|
|
5
|
+
var language = require('@codemirror/language');
|
|
5
6
|
var languageData = require('@codemirror/language-data');
|
|
6
7
|
var themeOneDark = require('@codemirror/theme-one-dark');
|
|
7
8
|
var ctx = require('@jvs-milkdown/kit/ctx');
|
|
@@ -696,10 +697,21 @@ const importIcon = `
|
|
|
696
697
|
</svg>
|
|
697
698
|
`;
|
|
698
699
|
|
|
700
|
+
const mermaidLanguage = language.LanguageDescription.of({
|
|
701
|
+
name: "Mermaid",
|
|
702
|
+
alias: ["mermaid"],
|
|
703
|
+
load: () => {
|
|
704
|
+
const fallback = languageData.languages.find((l) => l.name === "YAML") || languageData.languages.find((l) => l.name === "Markdown");
|
|
705
|
+
return fallback ? fallback.load() : Promise.resolve(null);
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
const allLanguages = [mermaidLanguage, ...languageData.languages].sort(
|
|
709
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
710
|
+
);
|
|
699
711
|
const defaultConfig = {
|
|
700
712
|
[CrepeFeature.CodeMirror]: {
|
|
701
713
|
theme: themeOneDark.oneDark,
|
|
702
|
-
languages:
|
|
714
|
+
languages: allLanguages,
|
|
703
715
|
expandIcon: chevronDownIcon,
|
|
704
716
|
searchIcon,
|
|
705
717
|
clearSearchIcon: clearIcon,
|
|
@@ -3085,7 +3097,7 @@ const Menu = vue.defineComponent({
|
|
|
3085
3097
|
const isTableBlock = (node == null ? void 0 : node.type.name) === "table";
|
|
3086
3098
|
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;
|
|
3087
3099
|
const showAlign = !isMedia || isImageBlock;
|
|
3088
|
-
const isEmpty = node ? node.textContent.length === 0 && node.content.size <= 2 && !isMedia : false;
|
|
3100
|
+
const isEmpty = node ? node.type.name === "paragraph" && node.textContent.length === 0 && node.content.size <= 2 && !isMedia : false;
|
|
3089
3101
|
const currentAlign = ((_b = node == null ? void 0 : node.attrs) == null ? void 0 : _b.align) || "left";
|
|
3090
3102
|
const currentIndent = ((_c = node == null ? void 0 : node.attrs) == null ? void 0 : _c.indent) || 0;
|
|
3091
3103
|
const setAlign = (alignValue) => {
|
|
@@ -4041,7 +4053,7 @@ class BlockHandleView {
|
|
|
4041
4053
|
});
|
|
4042
4054
|
}
|
|
4043
4055
|
const isMedia = node.type.name.includes("image") || node.type.name.includes("attachment") || node.type.name === "hr" || node.type.name.includes("math") || hasMediaChild;
|
|
4044
|
-
const isEmpty = node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
|
|
4056
|
+
const isEmpty = node.type.name === "paragraph" && node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
|
|
4045
4057
|
if (isEmpty) {
|
|
4046
4058
|
__privateGet$5(this, _content$3).classList.add("empty-block");
|
|
4047
4059
|
} else {
|
|
@@ -4192,7 +4204,7 @@ class BlockHandleView {
|
|
|
4192
4204
|
});
|
|
4193
4205
|
}
|
|
4194
4206
|
const isMedia = node.type.name.includes("image") || node.type.name.includes("attachment") || node.type.name === "hr" || node.type.name.includes("math") || hasMediaChild;
|
|
4195
|
-
const isEmpty = node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
|
|
4207
|
+
const isEmpty = node.type.name === "paragraph" && node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
|
|
4196
4208
|
if (isEmpty) {
|
|
4197
4209
|
__privateGet$5(this, _content$3).classList.add("empty-block");
|
|
4198
4210
|
} else {
|
|
@@ -4297,7 +4309,69 @@ const codeMirror = (editor, config = {}) => {
|
|
|
4297
4309
|
}),
|
|
4298
4310
|
noResultText: config.noResultText || i18n(ctx, "codeMirror.noResultText"),
|
|
4299
4311
|
renderLanguage: config.renderLanguage || defaultConfig.renderLanguage,
|
|
4300
|
-
renderPreview: config.renderPreview ||
|
|
4312
|
+
renderPreview: config.renderPreview || ((language, content, applyPreview) => {
|
|
4313
|
+
if (language.toLowerCase() === "mermaid" && content.trim().length > 0) {
|
|
4314
|
+
import('mermaid').then(({ default: mermaid }) => {
|
|
4315
|
+
mermaid.initialize({
|
|
4316
|
+
startOnLoad: false,
|
|
4317
|
+
theme: "default",
|
|
4318
|
+
themeVariables: {
|
|
4319
|
+
fontFamily: '"trebuchet ms", verdana, arial, sans-serif'
|
|
4320
|
+
}
|
|
4321
|
+
});
|
|
4322
|
+
if (typeof document !== "undefined") {
|
|
4323
|
+
const styleId = "mermaid-global-measurement-styles";
|
|
4324
|
+
if (!document.getElementById(styleId)) {
|
|
4325
|
+
const styleEl = document.createElement("style");
|
|
4326
|
+
styleEl.id = styleId;
|
|
4327
|
+
styleEl.textContent = `
|
|
4328
|
+
body,
|
|
4329
|
+
.mermaid,
|
|
4330
|
+
.relationshipLabel,
|
|
4331
|
+
.edgeLabel,
|
|
4332
|
+
.edgeLabelText,
|
|
4333
|
+
.label,
|
|
4334
|
+
.nodeLabel,
|
|
4335
|
+
svg * {
|
|
4336
|
+
font-family: "trebuchet ms", verdana, arial, sans-serif !important;
|
|
4337
|
+
line-height: normal !important;
|
|
4338
|
+
}
|
|
4339
|
+
.relationshipLabel,
|
|
4340
|
+
.relationshipLabel *,
|
|
4341
|
+
.edgeLabel,
|
|
4342
|
+
.edgeLabel *,
|
|
4343
|
+
.edgeLabelText,
|
|
4344
|
+
.edgeLabelText * {
|
|
4345
|
+
font-size: 11px !important;
|
|
4346
|
+
}
|
|
4347
|
+
svg foreignObject {
|
|
4348
|
+
overflow: visible !important;
|
|
4349
|
+
}
|
|
4350
|
+
`;
|
|
4351
|
+
document.head.appendChild(styleEl);
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
const id = `mermaid-${Math.random().toString(36).substring(2, 9)}`;
|
|
4355
|
+
mermaid.render(id, content).then(({ svg }) => {
|
|
4356
|
+
applyPreview(svg);
|
|
4357
|
+
}).catch((e) => {
|
|
4358
|
+
const errorEl = document.getElementById(`d${id}`);
|
|
4359
|
+
if (errorEl) {
|
|
4360
|
+
errorEl.remove();
|
|
4361
|
+
}
|
|
4362
|
+
applyPreview(
|
|
4363
|
+
`<div class="mermaid-error" style="color: red; padding: 10px; font-family: monospace;">${e instanceof Error ? e.message : String(e)}</div>`
|
|
4364
|
+
);
|
|
4365
|
+
});
|
|
4366
|
+
}).catch((err) => {
|
|
4367
|
+
applyPreview(
|
|
4368
|
+
`<div class="mermaid-error" style="color: red; padding: 10px; font-family: monospace;">Failed to load mermaid: ${err.message}</div>`
|
|
4369
|
+
);
|
|
4370
|
+
});
|
|
4371
|
+
return;
|
|
4372
|
+
}
|
|
4373
|
+
return defaultConfig.renderPreview(language, content, applyPreview);
|
|
4374
|
+
}),
|
|
4301
4375
|
previewToggleButton: (previewOnlyMode) => {
|
|
4302
4376
|
var _a2, _b;
|
|
4303
4377
|
const icon = ((_a2 = config.previewToggleIcon) == null ? void 0 : _a2.call(config, previewOnlyMode)) || (previewOnlyMode ? editIcon : visibilityOffIcon);
|