@heikeson/md-engine 0.5.3 → 0.6.0
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/README.en.md +267 -0
- package/README.md +154 -271
- package/dist/{chunk-YJGGJP2V.js → chunk-BMAGJMFB.js} +1 -2
- package/dist/{chunk-OG47YL3H.js → chunk-JUWL5RG7.js} +1 -2
- package/dist/{chunk-EJGRPSVC.js → chunk-OKP7VFRV.js} +234 -143
- package/dist/{chunk-OJQDOFGL.js → chunk-W463Q7LK.js} +2 -4
- package/dist/{chunk-ONVXIYKH.js → chunk-Y3B7I6LZ.js} +140 -19
- package/dist/components/index.d.ts +72 -6
- package/dist/components/index.js +4 -6
- package/dist/editor/index.d.ts +17 -7
- package/dist/editor/index.js +72 -25
- package/dist/index.d.ts +19 -18
- package/dist/index.js +14 -10
- package/dist/locales/en-US.d.ts +1 -0
- package/dist/locales/en-US.js +1 -3
- package/dist/locales/zh-CN.d.ts +1 -0
- package/dist/locales/zh-CN.js +1 -3
- package/dist/mermaid/index.d.ts +1 -15
- package/dist/mermaid/index.js +3 -5
- package/dist/{mermaid-placeholder-DYfFG3_f.d.ts → mermaid-placeholder-D97goALt.d.ts} +0 -3
- package/dist/{render-BxUxfxMc.d.ts → render-Dv1LAIvk.d.ts} +3 -4
- package/dist/styles.css +1 -1
- package/package.json +6 -1
- package/styles/cards.css +0 -1
- package/styles/columns.css +41 -0
- package/styles/files.css +0 -1
- package/styles/image.css +45 -3
- package/styles/index.css +4 -3
- package/styles/mermaid.css +0 -6
- package/styles/timeline.css +89 -0
- package/styles/video.css +28 -0
- package//345/257/271/346/216/245/345/245/221/347/272/246.en.md +765 -0
- package//345/257/271/346/216/245/345/245/221/347/272/246.md +411 -235
- package/dist/chunk-EJGRPSVC.js.map +0 -1
- package/dist/chunk-OG47YL3H.js.map +0 -1
- package/dist/chunk-OJQDOFGL.js.map +0 -1
- package/dist/chunk-ONVXIYKH.js.map +0 -1
- package/dist/chunk-YJGGJP2V.js.map +0 -1
- package/dist/components/index.js.map +0 -1
- package/dist/editor/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/locales/en-US.js.map +0 -1
- package/dist/locales/zh-CN.js.map +0 -1
- package/dist/mermaid/index.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useUIText } from './chunk-
|
|
1
|
+
import { useUIText } from './chunk-W463Q7LK.js';
|
|
2
2
|
import { useState, Children, isValidElement, useEffect, useRef, useId } from 'react';
|
|
3
3
|
import { ChevronDown, Lightbulb, XCircle, AlertTriangle, AlertCircle, Info, FileType, FileKey, FileLock, FileTerminal, FileSpreadsheet, FileArchive, FileMusic, FilePlay, FileImage, FileBraces, FileText, FileCode } from 'lucide-react';
|
|
4
4
|
import { clsx } from 'clsx';
|
|
@@ -131,6 +131,28 @@ function Cards({ children }) {
|
|
|
131
131
|
return safeHref ? /* @__PURE__ */ jsx("a", { href: safeHref, className: cls, children: inner }, i) : /* @__PURE__ */ jsx("div", { className: cls, children: inner }, i);
|
|
132
132
|
}) });
|
|
133
133
|
}
|
|
134
|
+
function Column(props) {
|
|
135
|
+
return /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
136
|
+
}
|
|
137
|
+
var WIDTH_RE = /^\d+(?:\.\d+)?(?:px|%|rem|em|ch|vw)?$/;
|
|
138
|
+
var RATIO_RE = /^\d+(?:\.\d+)?$/;
|
|
139
|
+
function columnVars(width) {
|
|
140
|
+
if (!width) return void 0;
|
|
141
|
+
const value = width.trim();
|
|
142
|
+
if (!WIDTH_RE.test(value)) return void 0;
|
|
143
|
+
if (RATIO_RE.test(value)) {
|
|
144
|
+
const ratio = Number(value);
|
|
145
|
+
return ratio > 0 ? { "--lkes-col-grow": ratio } : void 0;
|
|
146
|
+
}
|
|
147
|
+
return { "--lkes-col-basis": value };
|
|
148
|
+
}
|
|
149
|
+
function Columns({ children }) {
|
|
150
|
+
const items = Children.toArray(children).filter(isValidElement);
|
|
151
|
+
return /* @__PURE__ */ jsx("div", { className: "columns", children: items.map((el, i) => {
|
|
152
|
+
const { width, children: body } = el.props;
|
|
153
|
+
return /* @__PURE__ */ jsx("div", { className: "column", style: columnVars(width), children: body }, i);
|
|
154
|
+
}) });
|
|
155
|
+
}
|
|
134
156
|
var OPEN_LID_PATH = "M1 12.3L2.5 9.95A1.4 1.4 0 013.7 9.3h10.05a1.25 1.25 0 011.2 1.6l-1.13 3.3a1.4 1.4 0 01-1.32.93H2.4A1.4 1.4 0 011 13.73V12.3z";
|
|
135
157
|
function FileIcon() {
|
|
136
158
|
return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", className: "files-icon", children: [
|
|
@@ -355,10 +377,40 @@ function Folder({ name, defaultOpen, children }) {
|
|
|
355
377
|
/* @__PURE__ */ jsx("div", { className: "files-children", children })
|
|
356
378
|
] });
|
|
357
379
|
}
|
|
380
|
+
|
|
381
|
+
// src/internal/width.ts
|
|
382
|
+
var LENGTH_RE = /^\d+(?:\.\d+)?(?:px|%|rem|em|ch|vw)?$/;
|
|
383
|
+
var BARE_NUMBER_RE = /^\d+(?:\.\d+)?$/;
|
|
384
|
+
var FRACTION_RE = /^(\d+(?:\.\d+)?)\s*\/\s*(\d+(?:\.\d+)?)$/;
|
|
385
|
+
var MAX_PERCENT = 100;
|
|
386
|
+
function parseWidth(value) {
|
|
387
|
+
if (value === void 0 || value === null) return void 0;
|
|
388
|
+
const text = typeof value === "number" ? String(value) : value.trim();
|
|
389
|
+
if (text === "" || text === "auto") return void 0;
|
|
390
|
+
const fraction = FRACTION_RE.exec(text);
|
|
391
|
+
if (fraction) {
|
|
392
|
+
const numerator = Number(fraction[1]);
|
|
393
|
+
const denominator = Number(fraction[2]);
|
|
394
|
+
if (!(numerator > 0) || !(denominator > 0)) return void 0;
|
|
395
|
+
const percent = Math.min(MAX_PERCENT, numerator / denominator * MAX_PERCENT);
|
|
396
|
+
return `${Number(percent.toFixed(2))}%`;
|
|
397
|
+
}
|
|
398
|
+
if (!LENGTH_RE.test(text)) return void 0;
|
|
399
|
+
if (text.endsWith("%")) {
|
|
400
|
+
const percent = Number(text.slice(0, -1));
|
|
401
|
+
if (!Number.isFinite(percent)) return void 0;
|
|
402
|
+
return `${Number(Math.min(MAX_PERCENT, percent).toFixed(2))}%`;
|
|
403
|
+
}
|
|
404
|
+
return BARE_NUMBER_RE.test(text) ? `${text}px` : text;
|
|
405
|
+
}
|
|
406
|
+
var ALIGNS = ["left", "center", "right"];
|
|
407
|
+
function alignOf(value) {
|
|
408
|
+
return value && ALIGNS.includes(value) ? value : "center";
|
|
409
|
+
}
|
|
358
410
|
function Image({
|
|
359
411
|
src,
|
|
360
412
|
alt,
|
|
361
|
-
align
|
|
413
|
+
align: alignProp,
|
|
362
414
|
width,
|
|
363
415
|
caption,
|
|
364
416
|
zoom,
|
|
@@ -366,33 +418,58 @@ function Image({
|
|
|
366
418
|
}) {
|
|
367
419
|
const [open, setOpen] = useState(false);
|
|
368
420
|
const maskRef = useRef(null);
|
|
421
|
+
const triggerRef = useRef(null);
|
|
422
|
+
const wasOpen = useRef(false);
|
|
369
423
|
const text = useUIText();
|
|
370
424
|
const safeSrc = src && isSafeHref(src) ? src : void 0;
|
|
371
|
-
const
|
|
372
|
-
const
|
|
373
|
-
if (align === "center" && !width) figStyle.marginInline = "auto";
|
|
425
|
+
const align = alignOf(alignProp);
|
|
426
|
+
const w = parseWidth(width);
|
|
374
427
|
useEffect(() => {
|
|
375
|
-
if (!open)
|
|
428
|
+
if (!open) {
|
|
429
|
+
if (wasOpen.current) {
|
|
430
|
+
wasOpen.current = false;
|
|
431
|
+
triggerRef.current?.focus();
|
|
432
|
+
}
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
wasOpen.current = true;
|
|
436
|
+
maskRef.current?.focus();
|
|
376
437
|
const onKey = (event) => {
|
|
377
438
|
if (event.key === "Escape") setOpen(false);
|
|
378
439
|
};
|
|
440
|
+
const previousOverflow = document.body.style.overflow;
|
|
441
|
+
document.body.style.overflow = "hidden";
|
|
379
442
|
window.addEventListener("keydown", onKey);
|
|
380
|
-
return () =>
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
443
|
+
return () => {
|
|
444
|
+
document.body.style.overflow = previousOverflow;
|
|
445
|
+
window.removeEventListener("keydown", onKey);
|
|
446
|
+
};
|
|
384
447
|
}, [open]);
|
|
385
|
-
|
|
448
|
+
if (!safeSrc && !caption && !children) return null;
|
|
449
|
+
return /* @__PURE__ */ jsxs("figure", { className: cn("image", `align-${align}`), style: w ? { width: w } : void 0, children: [
|
|
386
450
|
safeSrc ? (
|
|
387
451
|
// eslint-disable-next-line @next/next/no-img-element
|
|
388
452
|
/* @__PURE__ */ jsx(
|
|
389
453
|
"img",
|
|
390
454
|
{
|
|
455
|
+
ref: triggerRef,
|
|
391
456
|
src: safeSrc,
|
|
392
457
|
alt: alt ?? "",
|
|
393
|
-
|
|
458
|
+
loading: "lazy",
|
|
459
|
+
decoding: "async",
|
|
460
|
+
style: w ? { width: "100%" } : void 0,
|
|
394
461
|
className: cn("image-img", zoom && "image-img-zoomable"),
|
|
395
|
-
|
|
462
|
+
role: zoom ? "button" : void 0,
|
|
463
|
+
tabIndex: zoom ? 0 : void 0,
|
|
464
|
+
"aria-label": zoom ? text.imageZoomOpen : void 0,
|
|
465
|
+
"aria-haspopup": zoom ? "dialog" : void 0,
|
|
466
|
+
onClick: zoom ? () => setOpen(true) : void 0,
|
|
467
|
+
onKeyDown: zoom ? (event) => {
|
|
468
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
469
|
+
event.preventDefault();
|
|
470
|
+
setOpen(true);
|
|
471
|
+
}
|
|
472
|
+
} : void 0
|
|
396
473
|
}
|
|
397
474
|
)
|
|
398
475
|
) : null,
|
|
@@ -402,9 +479,10 @@ function Image({
|
|
|
402
479
|
{
|
|
403
480
|
ref: maskRef,
|
|
404
481
|
className: "image-zoom-mask",
|
|
405
|
-
role: "
|
|
406
|
-
|
|
482
|
+
role: "dialog",
|
|
483
|
+
"aria-modal": "true",
|
|
407
484
|
"aria-label": text.imageZoomClose,
|
|
485
|
+
tabIndex: -1,
|
|
408
486
|
onClick: () => setOpen(false),
|
|
409
487
|
onKeyDown: (event) => {
|
|
410
488
|
if (event.key === "Enter" || event.key === " ") {
|
|
@@ -412,7 +490,7 @@ function Image({
|
|
|
412
490
|
setOpen(false);
|
|
413
491
|
}
|
|
414
492
|
},
|
|
415
|
-
children: /* @__PURE__ */ jsx("img", { src, alt: alt ?? "", className: "image-zoom-img" })
|
|
493
|
+
children: /* @__PURE__ */ jsx("img", { src: safeSrc, alt: alt ?? "", className: "image-zoom-img" })
|
|
416
494
|
}
|
|
417
495
|
) : null
|
|
418
496
|
] });
|
|
@@ -546,6 +624,27 @@ function Tabs({ children }) {
|
|
|
546
624
|
}) })
|
|
547
625
|
] });
|
|
548
626
|
}
|
|
627
|
+
var TONES = /* @__PURE__ */ new Set(["note", "tip", "warning", "danger"]);
|
|
628
|
+
function Timeline({ children }) {
|
|
629
|
+
const items = Children.toArray(children).filter(isValidElement);
|
|
630
|
+
return /* @__PURE__ */ jsx("div", { className: "timeline", children: items.map((el, i) => {
|
|
631
|
+
const { date, title, type, children: body } = el.props;
|
|
632
|
+
const tone = type && TONES.has(type) ? type : "note";
|
|
633
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("timeline-item", `is-${tone}`), children: [
|
|
634
|
+
/* @__PURE__ */ jsx("span", { className: "timeline-marker", "aria-hidden": "true" }),
|
|
635
|
+
/* @__PURE__ */ jsxs("div", { className: "timeline-body", children: [
|
|
636
|
+
date || title ? /* @__PURE__ */ jsxs("div", { className: "timeline-head", children: [
|
|
637
|
+
date ? /* @__PURE__ */ jsx("span", { className: "timeline-date", children: date }) : null,
|
|
638
|
+
title ? /* @__PURE__ */ jsx("span", { className: "timeline-title", children: title }) : null
|
|
639
|
+
] }) : null,
|
|
640
|
+
/* @__PURE__ */ jsx("div", { className: "timeline-content", children: body })
|
|
641
|
+
] })
|
|
642
|
+
] }, i);
|
|
643
|
+
}) });
|
|
644
|
+
}
|
|
645
|
+
function TimelineItem(props) {
|
|
646
|
+
return /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
647
|
+
}
|
|
549
648
|
function TypeItem({ name, type, default: defaultValue, required, children }) {
|
|
550
649
|
const text = useUIText();
|
|
551
650
|
const empty = text.typeItemEmpty;
|
|
@@ -572,6 +671,25 @@ function TypeTable({ children }) {
|
|
|
572
671
|
/* @__PURE__ */ jsx("tbody", { children: items })
|
|
573
672
|
] }) });
|
|
574
673
|
}
|
|
674
|
+
function Video({ src, poster, caption, width, children }) {
|
|
675
|
+
const safeSrc = src && isSafeHref(src) ? src : void 0;
|
|
676
|
+
const safePoster = poster && isSafeHref(poster) ? poster : void 0;
|
|
677
|
+
const w = parseWidth(width);
|
|
678
|
+
return /* @__PURE__ */ jsxs("figure", { className: "video", style: w ? { width: w } : void 0, children: [
|
|
679
|
+
safeSrc ? /* @__PURE__ */ jsx(
|
|
680
|
+
"video",
|
|
681
|
+
{
|
|
682
|
+
className: "video-el",
|
|
683
|
+
src: safeSrc,
|
|
684
|
+
poster: safePoster,
|
|
685
|
+
controls: true,
|
|
686
|
+
preload: "metadata",
|
|
687
|
+
playsInline: true
|
|
688
|
+
}
|
|
689
|
+
) : null,
|
|
690
|
+
caption ? /* @__PURE__ */ jsx("figcaption", { children: caption }) : children ? /* @__PURE__ */ jsx("figcaption", { children }) : null
|
|
691
|
+
] });
|
|
692
|
+
}
|
|
575
693
|
|
|
576
694
|
// src/components/index.ts
|
|
577
695
|
var mdxComponents = {
|
|
@@ -589,11 +707,14 @@ var mdxComponents = {
|
|
|
589
707
|
File,
|
|
590
708
|
TypeTable,
|
|
591
709
|
TypeItem,
|
|
710
|
+
Columns,
|
|
711
|
+
Column,
|
|
712
|
+
Timeline,
|
|
713
|
+
TimelineItem,
|
|
714
|
+
Video,
|
|
592
715
|
Image,
|
|
593
716
|
// 图表:主入口只出源码骨架;交互由 `/mermaid` 入口通过 components 覆写替换
|
|
594
717
|
Mermaid: MermaidPlaceholder
|
|
595
718
|
};
|
|
596
719
|
|
|
597
|
-
export { AccItem, Accordion, Callout, Card, Cards, File, Files, Folder, Image, MermaidPlaceholder, Step, Steps, Tab, Tabs, TypeItem, TypeTable, isSafeHref, mdxComponents };
|
|
598
|
-
//# sourceMappingURL=chunk-ONVXIYKH.js.map
|
|
599
|
-
//# sourceMappingURL=chunk-ONVXIYKH.js.map
|
|
720
|
+
export { AccItem, Accordion, Callout, Card, Cards, Column, Columns, File, Files, Folder, Image, MermaidPlaceholder, Step, Steps, Tab, Tabs, Timeline, TimelineItem, TypeItem, TypeTable, Video, isSafeHref, mdxComponents };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { M as MermaidPlaceholder } from '../mermaid-placeholder-
|
|
4
|
-
export { a as MermaidProps } from '../mermaid-placeholder-
|
|
3
|
+
import { M as MermaidPlaceholder } from '../mermaid-placeholder-D97goALt.js';
|
|
4
|
+
export { a as MermaidProps } from '../mermaid-placeholder-D97goALt.js';
|
|
5
5
|
|
|
6
6
|
/** 子项参数 */
|
|
7
7
|
interface AccItemProps {
|
|
@@ -60,6 +60,25 @@ declare function Cards({ children }: {
|
|
|
60
60
|
children?: ReactNode;
|
|
61
61
|
}): react.JSX.Element;
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* 列子项
|
|
65
|
+
* @param props 含 children 及透传属性(width 等)
|
|
66
|
+
* @returns 子元素
|
|
67
|
+
*/
|
|
68
|
+
declare function Column(props: {
|
|
69
|
+
children?: ReactNode;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}): react.JSX.Element;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 多列布局
|
|
75
|
+
* @param children 内层 `<Column>` 元素集合
|
|
76
|
+
* @returns 列布局节点
|
|
77
|
+
*/
|
|
78
|
+
declare function Columns({ children }: {
|
|
79
|
+
children?: ReactNode;
|
|
80
|
+
}): react.JSX.Element;
|
|
81
|
+
|
|
63
82
|
/** 文件参数 */
|
|
64
83
|
interface FileProps {
|
|
65
84
|
/** 文件名 */
|
|
@@ -104,6 +123,11 @@ interface ImageProps {
|
|
|
104
123
|
src?: string;
|
|
105
124
|
alt?: string;
|
|
106
125
|
align?: "left" | "center" | "right";
|
|
126
|
+
/**
|
|
127
|
+
* 宽度
|
|
128
|
+
* @description `auto`(缺省)原始尺寸;`50%` / `1/2` 按正文宽度占比;`360` 按像素;
|
|
129
|
+
* `20rem` 等按 CSS 长度。写法不合法的值忽略(等同 auto)。
|
|
130
|
+
*/
|
|
107
131
|
width?: string | number;
|
|
108
132
|
caption?: string;
|
|
109
133
|
/** 点击放大(布尔属性,写 `zoom` 即为真) */
|
|
@@ -115,7 +139,7 @@ interface ImageProps {
|
|
|
115
139
|
* @param props 图片来源、对齐、宽度、题注与缩放开关
|
|
116
140
|
* @returns 图片元素
|
|
117
141
|
*/
|
|
118
|
-
declare function Image({ src, alt, align, width, caption, zoom, children, }: ImageProps): react.JSX.Element;
|
|
142
|
+
declare function Image({ src, alt, align: alignProp, width, caption, zoom, children, }: ImageProps): react.JSX.Element | null;
|
|
119
143
|
|
|
120
144
|
/**
|
|
121
145
|
* 步骤子项
|
|
@@ -154,6 +178,25 @@ declare function Tabs({ children }: {
|
|
|
154
178
|
children?: ReactNode;
|
|
155
179
|
}): react.JSX.Element | null;
|
|
156
180
|
|
|
181
|
+
/**
|
|
182
|
+
* 时间线
|
|
183
|
+
* @param children 内层 `<TimelineItem>` 元素集合
|
|
184
|
+
* @returns 时间线节点
|
|
185
|
+
*/
|
|
186
|
+
declare function Timeline({ children }: {
|
|
187
|
+
children?: ReactNode;
|
|
188
|
+
}): react.JSX.Element;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 时间线子项
|
|
192
|
+
* @param props 含 children 及透传属性(date / title / type)
|
|
193
|
+
* @returns 子元素
|
|
194
|
+
*/
|
|
195
|
+
declare function TimelineItem(props: {
|
|
196
|
+
children?: ReactNode;
|
|
197
|
+
[key: string]: unknown;
|
|
198
|
+
}): react.JSX.Element;
|
|
199
|
+
|
|
157
200
|
/** 行参数 */
|
|
158
201
|
interface TypeItemProps {
|
|
159
202
|
/** 属性名 */
|
|
@@ -183,13 +226,31 @@ declare function TypeTable({ children }: {
|
|
|
183
226
|
children?: ReactNode;
|
|
184
227
|
}): react.JSX.Element;
|
|
185
228
|
|
|
229
|
+
/** 视频参数 */
|
|
230
|
+
interface VideoProps {
|
|
231
|
+
/** 视频地址 */
|
|
232
|
+
src?: string;
|
|
233
|
+
/** 封面图地址 */
|
|
234
|
+
poster?: string;
|
|
235
|
+
/** 题注;也可用正文补充说明 */
|
|
236
|
+
caption?: string;
|
|
237
|
+
/** 宽度:写法同 `Image`(`auto` / 占比 / 像素 / 长度) */
|
|
238
|
+
width?: string | number;
|
|
239
|
+
children?: ReactNode;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* 视频(含题注)
|
|
243
|
+
* @param props 视频来源、封面、题注与宽度
|
|
244
|
+
* @returns 视频元素
|
|
245
|
+
*/
|
|
246
|
+
declare function Video({ src, poster, caption, width, children }: VideoProps): react.JSX.Element;
|
|
247
|
+
|
|
186
248
|
/**
|
|
187
249
|
* @file 内容组件集合与渲染映射
|
|
188
250
|
* @description 映射键与 mdast 节点名完全一致(首字母大写),由渲染层的 hast tagName 直接查表。
|
|
189
251
|
* 新增组件时:先在 registry 声明,再在此登记组件实现。
|
|
190
252
|
* @created 2026-10-24 20:10
|
|
191
|
-
* @updated 2026-
|
|
192
|
-
* @updated 2026-11-01 21:47 登记 Mermaid 占位组件
|
|
253
|
+
* @updated 2026-11-27 10:20 登记 Columns / Column、Timeline / TimelineItem、Video
|
|
193
254
|
*/
|
|
194
255
|
|
|
195
256
|
/**
|
|
@@ -211,8 +272,13 @@ declare const mdxComponents: {
|
|
|
211
272
|
File: typeof File;
|
|
212
273
|
TypeTable: typeof TypeTable;
|
|
213
274
|
TypeItem: typeof TypeItem;
|
|
275
|
+
Columns: typeof Columns;
|
|
276
|
+
Column: typeof Column;
|
|
277
|
+
Timeline: typeof Timeline;
|
|
278
|
+
TimelineItem: typeof TimelineItem;
|
|
279
|
+
Video: typeof Video;
|
|
214
280
|
Image: typeof Image;
|
|
215
281
|
Mermaid: typeof MermaidPlaceholder;
|
|
216
282
|
};
|
|
217
283
|
|
|
218
|
-
export { AccItem, Accordion, Callout, Card, Cards, File, Files, Folder, Image as MdImage, MermaidPlaceholder, Step, Steps, Tab, Tabs, TypeItem, TypeTable, mdxComponents };
|
|
284
|
+
export { AccItem, Accordion, Callout, Card, Cards, Column, Columns, File, Files, Folder, Image as MdImage, MermaidPlaceholder, Step, Steps, Tab, Tabs, Timeline, TimelineItem, TypeItem, TypeTable, Video, type VideoProps, mdxComponents };
|
package/dist/components/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export { AccItem, Accordion, Callout, Card, Cards, File, Files, Folder, Image as MdImage, MermaidPlaceholder, Step, Steps, Tab, Tabs, TypeItem, TypeTable, mdxComponents } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
5
|
-
//# sourceMappingURL=index.js.map
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { AccItem, Accordion, Callout, Card, Cards, Column, Columns, File, Files, Folder, Image as MdImage, MermaidPlaceholder, Step, Steps, Tab, Tabs, Timeline, TimelineItem, TypeItem, TypeTable, Video, mdxComponents } from '../chunk-Y3B7I6LZ.js';
|
|
2
|
+
import '../chunk-W463Q7LK.js';
|
|
3
|
+
import '../chunk-JUWL5RG7.js';
|
|
4
|
+
import '../chunk-BMAGJMFB.js';
|
package/dist/editor/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { R as RenderConfig, U as UITextPatch } from '../render-
|
|
3
|
-
export { a as UIText } from '../render-
|
|
2
|
+
import { R as RenderConfig, U as UITextPatch } from '../render-Dv1LAIvk.js';
|
|
3
|
+
export { a as UIText } from '../render-Dv1LAIvk.js';
|
|
4
4
|
import 'unified';
|
|
5
5
|
|
|
6
6
|
/** 编辑器配置(只增不改) */
|
|
@@ -59,8 +59,7 @@ declare function MarkdownEditor(props: MarkdownEditorProps): react.JSX.Element;
|
|
|
59
59
|
* @description 组件名一律取自 `registry`,模板只描述"骨架"(标签 + 子项 + 空行),
|
|
60
60
|
* 禁止在别处硬编码 `<Callout` 之类的字符串。
|
|
61
61
|
* @created 2026-10-24 21:12
|
|
62
|
-
* @updated 2026-
|
|
63
|
-
* @updated 2026-11-01 21:47 图表片段:rawBody 容器给流程图骨架,可插入列表加 Mermaid
|
|
62
|
+
* @updated 2026-11-27 10:20 补 Columns / Timeline / Video 骨架
|
|
64
63
|
*/
|
|
65
64
|
/**
|
|
66
65
|
* 生成容器的插入骨架
|
|
@@ -69,14 +68,14 @@ declare function MarkdownEditor(props: MarkdownEditorProps): react.JSX.Element;
|
|
|
69
68
|
*/
|
|
70
69
|
declare function blockSnippet(name: string): string;
|
|
71
70
|
/** 工具栏里可一键插入的容器顺序 */
|
|
72
|
-
declare const INSERTABLE_BLOCKS: readonly ["Callout", "Tabs", "Steps", "Cards", "Accordion", "Files", "TypeTable", "Image", "Mermaid"];
|
|
71
|
+
declare const INSERTABLE_BLOCKS: readonly ["Callout", "Tabs", "Steps", "Cards", "Accordion", "Files", "TypeTable", "Columns", "Timeline", "Image", "Video", "Mermaid"];
|
|
73
72
|
|
|
74
73
|
/**
|
|
75
74
|
* @file 编辑器文本动作(纯函数,无 DOM)
|
|
76
75
|
* @description 编辑器只改 Markdown 文本,不维护第二份文档模型。这里提供三个基础动作:
|
|
77
76
|
* 选区包裹、行首前缀切换、光标处插入。全部返回新文本与新选区,由调用方写回。
|
|
78
77
|
* @created 2026-10-24 21:12
|
|
79
|
-
* @updated 2026-
|
|
78
|
+
* @updated 2026-11-09 12:40 块级插入沿用当前行缩进,光标落到内容占位处(正文占位文字选中),不再停在闭标签之后
|
|
80
79
|
*/
|
|
81
80
|
/** 选区(全文 offset,end 不含) */
|
|
82
81
|
interface Selection {
|
|
@@ -115,5 +114,16 @@ declare function toggleLinePrefix(value: string, selection: Selection, prefix: s
|
|
|
115
114
|
* @returns 新文本与光标位置(落在片段之后)
|
|
116
115
|
*/
|
|
117
116
|
declare function insertAtCursor(value: string, position: number, snippet: string): EditResult;
|
|
117
|
+
/**
|
|
118
|
+
* 在光标所在行插入块级片段(容器组件专用)
|
|
119
|
+
* @description 容器是块级构造:与前后内容隔开空行、并按当前行缩进对齐。
|
|
120
|
+
* 按字符插入会把 `<Callout>` 塞进行中间,导致整块解析失败或落到错误的层级;
|
|
121
|
+
* 缩进同理——在列表项或容器内部插入时不带缩进会把整块提到列 0,容器直接被截断。
|
|
122
|
+
* @param value 全文
|
|
123
|
+
* @param position 光标位置(取其所在行的行首作为插入点)
|
|
124
|
+
* @param snippet 片段文本(通常以换行结尾)
|
|
125
|
+
* @returns 新文本与新选区(落在内容占位处,正文占位文字会被选中)
|
|
126
|
+
*/
|
|
127
|
+
declare function insertBlockAt(value: string, position: number, snippet: string): EditResult;
|
|
118
128
|
|
|
119
|
-
export { type EditResult, type EditorConfig, type EditorView, INSERTABLE_BLOCKS, MarkdownEditor, type MarkdownEditorProps, type Selection, UITextPatch, blockSnippet, insertAtCursor, toggleLinePrefix, wrapSelection };
|
|
129
|
+
export { type EditResult, type EditorConfig, type EditorView, INSERTABLE_BLOCKS, MarkdownEditor, type MarkdownEditorProps, type Selection, UITextPatch, blockSnippet, insertAtCursor, insertBlockAt, toggleLinePrefix, wrapSelection };
|
package/dist/editor/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { COMPONENTS,
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import { useShallowStable, MdEngineProvider, useUIText, useMessage } from '../chunk-
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
1
|
+
import { COMPONENTS, parse, MarkdownTreeRenderer, formatDiagnostic } from '../chunk-OKP7VFRV.js';
|
|
2
|
+
import '../chunk-Y3B7I6LZ.js';
|
|
3
|
+
import { useShallowStable, MdEngineProvider, useUIText, useMessage } from '../chunk-W463Q7LK.js';
|
|
4
|
+
import '../chunk-JUWL5RG7.js';
|
|
5
|
+
import '../chunk-BMAGJMFB.js';
|
|
6
6
|
import { useMemo, useState, useRef, useDeferredValue, useEffect, useCallback } from 'react';
|
|
7
7
|
import { Compartment, EditorState } from '@codemirror/state';
|
|
8
8
|
import { EditorView, keymap, lineNumbers, drawSelection, placeholder } from '@codemirror/view';
|
|
@@ -32,19 +32,53 @@ function insertAtCursor(value, position, snippet) {
|
|
|
32
32
|
const cursor = position + snippet.length;
|
|
33
33
|
return { value: next, selection: { start: cursor, end: cursor } };
|
|
34
34
|
}
|
|
35
|
+
function leadingIndent(line) {
|
|
36
|
+
return /^[ \t]*/.exec(line)?.[0] ?? "";
|
|
37
|
+
}
|
|
38
|
+
function indentSnippet(snippet, indent) {
|
|
39
|
+
if (indent === "") return snippet;
|
|
40
|
+
return snippet.split("\n").map((line) => line === "" ? "" : indent + line).join("\n");
|
|
41
|
+
}
|
|
42
|
+
function contentSelection(body) {
|
|
43
|
+
const lines = body.split("\n");
|
|
44
|
+
const starts = [];
|
|
45
|
+
let offset = 0;
|
|
46
|
+
for (const line of lines) {
|
|
47
|
+
starts.push(offset);
|
|
48
|
+
offset += line.length + 1;
|
|
49
|
+
}
|
|
50
|
+
if (lines.length <= 2) {
|
|
51
|
+
const end2 = starts[0] + (lines[0] ?? "").length;
|
|
52
|
+
return { start: end2, end: end2 };
|
|
53
|
+
}
|
|
54
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
55
|
+
const text = lines[index] ?? "";
|
|
56
|
+
const trimmed = text.trim();
|
|
57
|
+
const at = starts[index] + leadingIndent(text).length;
|
|
58
|
+
if (trimmed === "" || trimmed.startsWith("</") || trimmed.endsWith("/>")) {
|
|
59
|
+
return { start: at, end: at };
|
|
60
|
+
}
|
|
61
|
+
if (trimmed.startsWith("<")) continue;
|
|
62
|
+
const next = (lines[index + 1] ?? "").trim();
|
|
63
|
+
return { start: at, end: next.startsWith("</") ? starts[index] + text.trimEnd().length : at };
|
|
64
|
+
}
|
|
65
|
+
const end = Math.max(0, body.length - 1);
|
|
66
|
+
return { start: end, end };
|
|
67
|
+
}
|
|
35
68
|
function insertBlockAt(value, position, snippet) {
|
|
36
69
|
const lineStart = value.lastIndexOf("\n", position - 1) + 1;
|
|
37
70
|
const before = value.slice(0, lineStart);
|
|
38
71
|
const after = value.slice(lineStart);
|
|
72
|
+
const indent = leadingIndent(after);
|
|
39
73
|
const lead = before === "" || before.endsWith("\n\n") ? "" : before.endsWith("\n") ? "\n" : "\n\n";
|
|
40
|
-
const body = snippet.endsWith("\n") ? snippet : `${snippet}
|
|
41
|
-
|
|
74
|
+
const body = indentSnippet(snippet.endsWith("\n") ? snippet : `${snippet}
|
|
75
|
+
`, indent);
|
|
42
76
|
const tail = after === "" || after.startsWith("\n") ? "" : "\n";
|
|
43
77
|
const inserted = lead + body + tail;
|
|
44
78
|
const next = before + inserted + after;
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
return { value: next, selection: { start:
|
|
79
|
+
const caret = contentSelection(body);
|
|
80
|
+
const base = before.length + lead.length;
|
|
81
|
+
return { value: next, selection: { start: base + caret.start, end: base + caret.end } };
|
|
48
82
|
}
|
|
49
83
|
function buildShortcuts(wrapPlaceholder) {
|
|
50
84
|
return [
|
|
@@ -368,6 +402,22 @@ var FILES_SNIPPET = `<Files>
|
|
|
368
402
|
<File name="package.json" />
|
|
369
403
|
</Files>
|
|
370
404
|
`;
|
|
405
|
+
var COLUMNS_SNIPPET = `<Columns>
|
|
406
|
+
<Column width="1">
|
|
407
|
+
\u5185\u5BB9
|
|
408
|
+
</Column>
|
|
409
|
+
<Column width="1">
|
|
410
|
+
\u5185\u5BB9
|
|
411
|
+
</Column>
|
|
412
|
+
</Columns>
|
|
413
|
+
`;
|
|
414
|
+
var TIMELINE_SNIPPET = `<Timeline>
|
|
415
|
+
<TimelineItem date="2026-01" title="\u6807\u9898">
|
|
416
|
+
\u5185\u5BB9
|
|
417
|
+
</TimelineItem>
|
|
418
|
+
</Timeline>
|
|
419
|
+
`;
|
|
420
|
+
var VIDEO_SNIPPET = '<Video src="" caption="" />\n';
|
|
371
421
|
function blockSnippet(name) {
|
|
372
422
|
const spec = COMPONENTS[name];
|
|
373
423
|
if (!spec) return "";
|
|
@@ -380,10 +430,12 @@ graph TD
|
|
|
380
430
|
`;
|
|
381
431
|
}
|
|
382
432
|
if (spec.selfClosing) {
|
|
383
|
-
return `<${name} src="" alt="" />
|
|
433
|
+
return name === "Video" ? VIDEO_SNIPPET : `<${name} src="" alt="" />
|
|
384
434
|
`;
|
|
385
435
|
}
|
|
386
436
|
if (name === "Files") return FILES_SNIPPET;
|
|
437
|
+
if (name === "Columns") return COLUMNS_SNIPPET;
|
|
438
|
+
if (name === "Timeline") return TIMELINE_SNIPPET;
|
|
387
439
|
if (name === "TypeTable") {
|
|
388
440
|
return `<TypeTable>
|
|
389
441
|
<TypeItem name="id" type="string" required>
|
|
@@ -420,7 +472,10 @@ var INSERTABLE_BLOCKS = [
|
|
|
420
472
|
"Accordion",
|
|
421
473
|
"Files",
|
|
422
474
|
"TypeTable",
|
|
475
|
+
"Columns",
|
|
476
|
+
"Timeline",
|
|
423
477
|
"Image",
|
|
478
|
+
"Video",
|
|
424
479
|
"Mermaid"
|
|
425
480
|
];
|
|
426
481
|
var VIEW_OPTIONS = [
|
|
@@ -545,14 +600,8 @@ function EditorShell({ value, onChange, view = "split", config, fullscreen, onTo
|
|
|
545
600
|
useEffect(() => {
|
|
546
601
|
handleRef.current?.setDoc(value);
|
|
547
602
|
}, [value]);
|
|
548
|
-
const
|
|
549
|
-
const
|
|
550
|
-
const current = valueRef.current;
|
|
551
|
-
const normalized = normalizeMarkdown(current);
|
|
552
|
-
if (normalized === current) return;
|
|
553
|
-
onChangeRef.current(normalized);
|
|
554
|
-
handleRef.current?.setDoc(normalized);
|
|
555
|
-
}, []);
|
|
603
|
+
const parsed = useMemo(() => parse(deferredValue, { blocks: false }), [deferredValue]);
|
|
604
|
+
const diagnostics = parsed.diagnostics;
|
|
556
605
|
return /* @__PURE__ */ jsxs("div", { className: "md-editor", children: [
|
|
557
606
|
/* @__PURE__ */ jsxs("div", { className: "md-editor-toolbar", children: [
|
|
558
607
|
WRAP_ITEMS.map((item) => /* @__PURE__ */ jsx(
|
|
@@ -604,12 +653,12 @@ function EditorShell({ value, onChange, view = "split", config, fullscreen, onTo
|
|
|
604
653
|
)) }),
|
|
605
654
|
onToggleFullscreen ? /* @__PURE__ */ jsx("button", { type: "button", onClick: onToggleFullscreen, children: fullscreen ? text.editorExitFullscreen : text.editorFullscreen }) : null
|
|
606
655
|
] }),
|
|
607
|
-
/* @__PURE__ */ jsxs("div", { className: "md-editor-body",
|
|
656
|
+
/* @__PURE__ */ jsxs("div", { className: "md-editor-body", children: [
|
|
608
657
|
viewMode !== "preview" && /* @__PURE__ */ jsx("div", { ref: hostRef, className: "md-editor-source" }),
|
|
609
658
|
viewMode !== "source" && /* @__PURE__ */ jsx("div", { ref: previewRef, className: "md-editor-preview", children: /* @__PURE__ */ jsx(
|
|
610
|
-
|
|
659
|
+
MarkdownTreeRenderer,
|
|
611
660
|
{
|
|
612
|
-
|
|
661
|
+
tree: parsed.tree,
|
|
613
662
|
className: "prose-site",
|
|
614
663
|
config: { ...config?.rendererConfig, sourcePositions: true }
|
|
615
664
|
}
|
|
@@ -625,6 +674,4 @@ function EditorShell({ value, onChange, view = "split", config, fullscreen, onTo
|
|
|
625
674
|
] });
|
|
626
675
|
}
|
|
627
676
|
|
|
628
|
-
export { INSERTABLE_BLOCKS, MarkdownEditor, blockSnippet, insertAtCursor, toggleLinePrefix, wrapSelection };
|
|
629
|
-
//# sourceMappingURL=index.js.map
|
|
630
|
-
//# sourceMappingURL=index.js.map
|
|
677
|
+
export { INSERTABLE_BLOCKS, MarkdownEditor, blockSnippet, insertAtCursor, insertBlockAt, toggleLinePrefix, wrapSelection };
|