@zero-library/common 2.4.0 → 2.4.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/index.d.mts CHANGED
@@ -126,20 +126,22 @@ interface FilePreviewDrawerProps extends FilePreviewProps {
126
126
  declare const _default$m: ({ open, title, onClose, ...props }: FilePreviewDrawerProps) => react_jsx_runtime.JSX.Element;
127
127
 
128
128
  /**
129
- * Markdown预览组件属性接口
129
+ * Markdown | txt 预览组件属性接口
130
130
  */
131
131
  interface MarkdownPreviewProps {
132
- /** Markdown文件URL地址 */
132
+ /** 文件URL地址 */
133
133
  fileUrl: string;
134
134
  /** 搜索关键字 */
135
135
  searchValue?: string;
136
+ /** 是否作为纯文本显示, 主要用于txt文件预览 */
137
+ asPlainText?: boolean;
136
138
  }
137
139
  /**
138
- * Markdown预览组件
139
- * 从指定URL获取Markdown内容并渲染显示
140
+ * Markdown | txt 预览组件
141
+ * 从指定URL获取Markdown或txt内容并渲染显示
140
142
  * @param props - 组件属性
141
143
  */
142
- declare const _default$l: ({ fileUrl, searchValue }: MarkdownPreviewProps) => react_jsx_runtime.JSX.Element;
144
+ declare const _default$l: ({ fileUrl, searchValue, asPlainText }: MarkdownPreviewProps) => react_jsx_runtime.JSX.Element;
143
145
 
144
146
  interface PdfImagePreviewProps {
145
147
  /** PDF文件URL地址 */
@@ -353,6 +355,16 @@ interface CollectionConfig extends CollectionsProps {
353
355
  */
354
356
  type ToolbarItem = 'undo-redo' | 'heading' | 'list' | 'block' | 'format' | 'script' | 'align';
355
357
 
358
+ /**
359
+ * 分页功能配置接口
360
+ */
361
+ interface PageNoConfig {
362
+ /** 是否启用分页功能,默认为false */
363
+ enabled: boolean;
364
+ /** 页面滚动回调 */
365
+ onScrollPage?: (pageIndex: number) => void;
366
+ }
367
+
356
368
  /**
357
369
  * Markdown编辑器组件属性接口
358
370
  */
@@ -379,12 +391,7 @@ interface MarkdownEditorProps {
379
391
  annotationConfig?: AnnotationConfig;
380
392
  /** 摘录功能专属配置,不与批注混淆 */
381
393
  collectionConfig?: CollectionConfig;
382
- pageNoConfig?: {
383
- /** 是否启用分页功能,默认为false */
384
- enabled: boolean;
385
- /** 页面滚动回调 */
386
- onScrollPage?: (pageIndex: number) => void;
387
- };
394
+ pageNoConfig?: PageNoConfig;
388
395
  }
389
396
  /**
390
397
  * Markdown编辑器组件
package/dist/index.d.ts CHANGED
@@ -126,20 +126,22 @@ interface FilePreviewDrawerProps extends FilePreviewProps {
126
126
  declare const _default$m: ({ open, title, onClose, ...props }: FilePreviewDrawerProps) => react_jsx_runtime.JSX.Element;
127
127
 
128
128
  /**
129
- * Markdown预览组件属性接口
129
+ * Markdown | txt 预览组件属性接口
130
130
  */
131
131
  interface MarkdownPreviewProps {
132
- /** Markdown文件URL地址 */
132
+ /** 文件URL地址 */
133
133
  fileUrl: string;
134
134
  /** 搜索关键字 */
135
135
  searchValue?: string;
136
+ /** 是否作为纯文本显示, 主要用于txt文件预览 */
137
+ asPlainText?: boolean;
136
138
  }
137
139
  /**
138
- * Markdown预览组件
139
- * 从指定URL获取Markdown内容并渲染显示
140
+ * Markdown | txt 预览组件
141
+ * 从指定URL获取Markdown或txt内容并渲染显示
140
142
  * @param props - 组件属性
141
143
  */
142
- declare const _default$l: ({ fileUrl, searchValue }: MarkdownPreviewProps) => react_jsx_runtime.JSX.Element;
144
+ declare const _default$l: ({ fileUrl, searchValue, asPlainText }: MarkdownPreviewProps) => react_jsx_runtime.JSX.Element;
143
145
 
144
146
  interface PdfImagePreviewProps {
145
147
  /** PDF文件URL地址 */
@@ -353,6 +355,16 @@ interface CollectionConfig extends CollectionsProps {
353
355
  */
354
356
  type ToolbarItem = 'undo-redo' | 'heading' | 'list' | 'block' | 'format' | 'script' | 'align';
355
357
 
358
+ /**
359
+ * 分页功能配置接口
360
+ */
361
+ interface PageNoConfig {
362
+ /** 是否启用分页功能,默认为false */
363
+ enabled: boolean;
364
+ /** 页面滚动回调 */
365
+ onScrollPage?: (pageIndex: number) => void;
366
+ }
367
+
356
368
  /**
357
369
  * Markdown编辑器组件属性接口
358
370
  */
@@ -379,12 +391,7 @@ interface MarkdownEditorProps {
379
391
  annotationConfig?: AnnotationConfig;
380
392
  /** 摘录功能专属配置,不与批注混淆 */
381
393
  collectionConfig?: CollectionConfig;
382
- pageNoConfig?: {
383
- /** 是否启用分页功能,默认为false */
384
- enabled: boolean;
385
- /** 页面滚动回调 */
386
- onScrollPage?: (pageIndex: number) => void;
387
- };
394
+ pageNoConfig?: PageNoConfig;
388
395
  }
389
396
  /**
390
397
  * Markdown编辑器组件
package/dist/index.esm.js CHANGED
@@ -1479,7 +1479,7 @@ var RenderMarkdown_default = ({ content = "", searchValue, customComponents, ...
1479
1479
  }, [content, searchValue]);
1480
1480
  return /* @__PURE__ */ jsx("div", { className: "ns-markdown", children: reactContent });
1481
1481
  };
1482
- var MarkdownPreview_default = ({ fileUrl, searchValue }) => {
1482
+ var MarkdownPreview_default = ({ fileUrl, searchValue, asPlainText }) => {
1483
1483
  const [content, setContent] = useState("");
1484
1484
  const [error, setError] = useState("");
1485
1485
  const fetchMarkdown = async () => {
@@ -1487,29 +1487,41 @@ var MarkdownPreview_default = ({ fileUrl, searchValue }) => {
1487
1487
  if (res.status !== 200) {
1488
1488
  throw new Error(`\u8BF7\u6C42\u5931\u8D25\uFF0C\u72B6\u6001\u7801: ${res.status}`);
1489
1489
  }
1490
- const markdownText = await res.text();
1491
- if (!markdownText) {
1490
+ const content2 = await res.text();
1491
+ if (!content2) {
1492
1492
  throw new Error("\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A");
1493
1493
  }
1494
- setContent(markdownText);
1494
+ return content2;
1495
1495
  };
1496
1496
  const init = async () => {
1497
1497
  setContent("");
1498
1498
  setError("");
1499
1499
  if (fileUrl) {
1500
1500
  try {
1501
- await fetchMarkdown();
1502
- } catch (error2) {
1503
- setError("\u52A0\u8F7D\u6216\u89E3\u6790 Markdown \u5931\u8D25");
1501
+ const content2 = await fetchMarkdown();
1502
+ setContent(content2);
1503
+ } catch {
1504
+ setError("\u52A0\u8F7D\u6216\u89E3\u6790\u6587\u4EF6\u5931\u8D25");
1504
1505
  }
1505
1506
  } else {
1506
- setError("Markdown\u5730\u5740\u9519\u8BEF");
1507
+ setError("\u6587\u4EF6\u5730\u5740\u9519\u8BEF");
1507
1508
  }
1508
1509
  };
1509
1510
  useEffect(() => {
1510
1511
  init();
1511
1512
  }, [fileUrl]);
1512
- return error ? /* @__PURE__ */ jsx(Result, { status: "error", title: error }) : /* @__PURE__ */ jsx("div", { className: "height-full width-full", children: /* @__PURE__ */ jsx(RenderMarkdown_default, { content, searchValue }) });
1513
+ const wrapInCodeFence = (text) => {
1514
+ const matches = text.match(/`+/g) ?? [];
1515
+ const maxRun = matches.reduce((max, run) => Math.max(max, run.length), 0);
1516
+ const fence = "`".repeat(Math.max(3, maxRun + 1));
1517
+ return `${fence}
1518
+ ${text}
1519
+ ${fence}`;
1520
+ };
1521
+ const newContent = useMemo(() => {
1522
+ return content ? asPlainText ? wrapInCodeFence(content) : content : "";
1523
+ }, [content, asPlainText]);
1524
+ return error ? /* @__PURE__ */ jsx(Result, { status: "error", title: error }) : /* @__PURE__ */ jsx("div", { className: "height-full width-full", children: /* @__PURE__ */ jsx(RenderMarkdown_default, { content: newContent, searchValue }) });
1513
1525
  };
1514
1526
 
1515
1527
  // src/hooks/iframe/iframeRelay.ts
@@ -2346,6 +2358,8 @@ var FilePreview_default = ({ suffix, fileUrl, pdfParams, password, searchValue,
2346
2358
  case "MD":
2347
2359
  case "MARKDOWN":
2348
2360
  return /* @__PURE__ */ jsx(MarkdownPreview_default, { fileUrl, searchValue });
2361
+ case "TXT":
2362
+ return /* @__PURE__ */ jsx(MarkdownPreview_default, { fileUrl, searchValue, asPlainText: true });
2349
2363
  case "DOCX":
2350
2364
  return /* @__PURE__ */ jsx(DocxPreview_default, { fileUrl });
2351
2365
  default: