@zero-library/common 2.4.1 → 2.4.3
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.cjs.js +74 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.esm.js +74 -12
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
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
|
-
/**
|
|
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地址 */
|
|
@@ -357,10 +359,12 @@ type ToolbarItem = 'undo-redo' | 'heading' | 'list' | 'block' | 'format' | 'scri
|
|
|
357
359
|
* 分页功能配置接口
|
|
358
360
|
*/
|
|
359
361
|
interface PageNoConfig {
|
|
362
|
+
/** 当前页码,默认为1 */
|
|
363
|
+
pageNo?: number;
|
|
360
364
|
/** 是否启用分页功能,默认为false */
|
|
361
365
|
enabled: boolean;
|
|
362
366
|
/** 页面滚动回调 */
|
|
363
|
-
onScrollPage?: (
|
|
367
|
+
onScrollPage?: (pageNo: number) => void;
|
|
364
368
|
}
|
|
365
369
|
|
|
366
370
|
/**
|
|
@@ -2499,4 +2503,4 @@ declare function createTokenManager({ key, storage }: TokenManagerProps): {
|
|
|
2499
2503
|
clear: () => void;
|
|
2500
2504
|
};
|
|
2501
2505
|
|
|
2502
|
-
export { type AnnotationConfig, type AnnotationType, _default$q as AudioPlayer, type AudioPlayerProps, BusinessCode, type CacheMessage, type CollectionConfig, type CollectionType, type ComponentMapType, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, _default$p as DocxPreview, type DocxPreviewProps, _default$o as FileIcon, type FileIconProps, _default$n as FilePreview, _default$m as FilePreviewDrawer, type FilePreviewDrawerProps, type FilePreviewProps, type FindTreeNodesOptions, type FormatSizeOptions, HttpStatus, _default$h as Iframe, type IframeProps, _default$g as LazyComponent, type LazyComponentProps, _default$e as MarkDrawing, type MarkDrawingProps, _default$f as MarkdownEditor, type MarkdownEditorProps, _default$l as MarkdownPreview, type MarkdownPreviewProps, MultiEmailValidator, _default$k as PdfImagePreview, type PdfImagePreviewProps, _default$j as PdfPreview, type PdfPreviewProps, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegPassword, RegSmsCode, RegTaxNo, RegTelePhone, type RenderControl, _default$d as RenderMarkdown, type RenderMarkdownProps, _default$c as RenderWrapper, type RenderWrapperProps, type RequestConfig, type SecureManagerProps, type SetIntervalType, type SizeUnit, ThanNumLengthValidator, ThanNumValidator, type TokenManagerProps, _default$b as UserAvatar, type UserAvatarProps, _default$i as VideoPlayer, type VideoPlayerProps, type WebSocketProps, type WebSocketType, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, findTreeNodesByIds, formatDate, formatNumberWithCommas, formatSize, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, htmlToMarkdown, htmlToText, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, markdownToText, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, _default$9 as useAsyncQueue, _default$8 as useAutoRefresh, _default$7 as useCountDown, _default$6 as useCreateValtioContext, _default$5 as useDebounce, _default$4 as useDeepEffect, _default$a as useIframeRelayBridge, _default$3 as useRefState, _default$2 as useSyncInput, _default$1 as useThrottle, _default as useWebSocket };
|
|
2506
|
+
export { type AnnotationConfig, type AnnotationType, _default$q as AudioPlayer, type AudioPlayerProps, BusinessCode, type CacheMessage, type CollectionConfig, type CollectionType, type ComponentMapType, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, _default$p as DocxPreview, type DocxPreviewProps, _default$o as FileIcon, type FileIconProps, _default$n as FilePreview, _default$m as FilePreviewDrawer, type FilePreviewDrawerProps, type FilePreviewProps, type FindTreeNodesOptions, type FormatSizeOptions, HttpStatus, _default$h as Iframe, type IframeProps, _default$g as LazyComponent, type LazyComponentProps, _default$e as MarkDrawing, type MarkDrawingProps, _default$f as MarkdownEditor, type MarkdownEditorProps, _default$l as MarkdownPreview, type MarkdownPreviewProps, MultiEmailValidator, type PageNoConfig, _default$k as PdfImagePreview, type PdfImagePreviewProps, _default$j as PdfPreview, type PdfPreviewProps, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegPassword, RegSmsCode, RegTaxNo, RegTelePhone, type RenderControl, _default$d as RenderMarkdown, type RenderMarkdownProps, _default$c as RenderWrapper, type RenderWrapperProps, type RequestConfig, type SecureManagerProps, type SetIntervalType, type SizeUnit, ThanNumLengthValidator, ThanNumValidator, type TokenManagerProps, _default$b as UserAvatar, type UserAvatarProps, _default$i as VideoPlayer, type VideoPlayerProps, type WebSocketProps, type WebSocketType, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, findTreeNodesByIds, formatDate, formatNumberWithCommas, formatSize, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, htmlToMarkdown, htmlToText, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, markdownToText, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, _default$9 as useAsyncQueue, _default$8 as useAutoRefresh, _default$7 as useCountDown, _default$6 as useCreateValtioContext, _default$5 as useDebounce, _default$4 as useDeepEffect, _default$a as useIframeRelayBridge, _default$3 as useRefState, _default$2 as useSyncInput, _default$1 as useThrottle, _default as useWebSocket };
|
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
|
-
/**
|
|
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地址 */
|
|
@@ -357,10 +359,12 @@ type ToolbarItem = 'undo-redo' | 'heading' | 'list' | 'block' | 'format' | 'scri
|
|
|
357
359
|
* 分页功能配置接口
|
|
358
360
|
*/
|
|
359
361
|
interface PageNoConfig {
|
|
362
|
+
/** 当前页码,默认为1 */
|
|
363
|
+
pageNo?: number;
|
|
360
364
|
/** 是否启用分页功能,默认为false */
|
|
361
365
|
enabled: boolean;
|
|
362
366
|
/** 页面滚动回调 */
|
|
363
|
-
onScrollPage?: (
|
|
367
|
+
onScrollPage?: (pageNo: number) => void;
|
|
364
368
|
}
|
|
365
369
|
|
|
366
370
|
/**
|
|
@@ -2499,4 +2503,4 @@ declare function createTokenManager({ key, storage }: TokenManagerProps): {
|
|
|
2499
2503
|
clear: () => void;
|
|
2500
2504
|
};
|
|
2501
2505
|
|
|
2502
|
-
export { type AnnotationConfig, type AnnotationType, _default$q as AudioPlayer, type AudioPlayerProps, BusinessCode, type CacheMessage, type CollectionConfig, type CollectionType, type ComponentMapType, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, _default$p as DocxPreview, type DocxPreviewProps, _default$o as FileIcon, type FileIconProps, _default$n as FilePreview, _default$m as FilePreviewDrawer, type FilePreviewDrawerProps, type FilePreviewProps, type FindTreeNodesOptions, type FormatSizeOptions, HttpStatus, _default$h as Iframe, type IframeProps, _default$g as LazyComponent, type LazyComponentProps, _default$e as MarkDrawing, type MarkDrawingProps, _default$f as MarkdownEditor, type MarkdownEditorProps, _default$l as MarkdownPreview, type MarkdownPreviewProps, MultiEmailValidator, _default$k as PdfImagePreview, type PdfImagePreviewProps, _default$j as PdfPreview, type PdfPreviewProps, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegPassword, RegSmsCode, RegTaxNo, RegTelePhone, type RenderControl, _default$d as RenderMarkdown, type RenderMarkdownProps, _default$c as RenderWrapper, type RenderWrapperProps, type RequestConfig, type SecureManagerProps, type SetIntervalType, type SizeUnit, ThanNumLengthValidator, ThanNumValidator, type TokenManagerProps, _default$b as UserAvatar, type UserAvatarProps, _default$i as VideoPlayer, type VideoPlayerProps, type WebSocketProps, type WebSocketType, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, findTreeNodesByIds, formatDate, formatNumberWithCommas, formatSize, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, htmlToMarkdown, htmlToText, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, markdownToText, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, _default$9 as useAsyncQueue, _default$8 as useAutoRefresh, _default$7 as useCountDown, _default$6 as useCreateValtioContext, _default$5 as useDebounce, _default$4 as useDeepEffect, _default$a as useIframeRelayBridge, _default$3 as useRefState, _default$2 as useSyncInput, _default$1 as useThrottle, _default as useWebSocket };
|
|
2506
|
+
export { type AnnotationConfig, type AnnotationType, _default$q as AudioPlayer, type AudioPlayerProps, BusinessCode, type CacheMessage, type CollectionConfig, type CollectionType, type ComponentMapType, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, _default$p as DocxPreview, type DocxPreviewProps, _default$o as FileIcon, type FileIconProps, _default$n as FilePreview, _default$m as FilePreviewDrawer, type FilePreviewDrawerProps, type FilePreviewProps, type FindTreeNodesOptions, type FormatSizeOptions, HttpStatus, _default$h as Iframe, type IframeProps, _default$g as LazyComponent, type LazyComponentProps, _default$e as MarkDrawing, type MarkDrawingProps, _default$f as MarkdownEditor, type MarkdownEditorProps, _default$l as MarkdownPreview, type MarkdownPreviewProps, MultiEmailValidator, type PageNoConfig, _default$k as PdfImagePreview, type PdfImagePreviewProps, _default$j as PdfPreview, type PdfPreviewProps, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegPassword, RegSmsCode, RegTaxNo, RegTelePhone, type RenderControl, _default$d as RenderMarkdown, type RenderMarkdownProps, _default$c as RenderWrapper, type RenderWrapperProps, type RequestConfig, type SecureManagerProps, type SetIntervalType, type SizeUnit, ThanNumLengthValidator, ThanNumValidator, type TokenManagerProps, _default$b as UserAvatar, type UserAvatarProps, _default$i as VideoPlayer, type VideoPlayerProps, type WebSocketProps, type WebSocketType, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, findTreeNodesByIds, formatDate, formatNumberWithCommas, formatSize, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, htmlToMarkdown, htmlToText, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, markdownToText, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, _default$9 as useAsyncQueue, _default$8 as useAutoRefresh, _default$7 as useCountDown, _default$6 as useCreateValtioContext, _default$5 as useDebounce, _default$4 as useDeepEffect, _default$a as useIframeRelayBridge, _default$3 as useRefState, _default$2 as useSyncInput, _default$1 as useThrottle, _default as useWebSocket };
|
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
|
|
1491
|
-
if (!
|
|
1490
|
+
const content2 = await res.text();
|
|
1491
|
+
if (!content2) {
|
|
1492
1492
|
throw new Error("\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A");
|
|
1493
1493
|
}
|
|
1494
|
-
|
|
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
|
-
|
|
1503
|
-
|
|
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("
|
|
1507
|
+
setError("\u6587\u4EF6\u5730\u5740\u9519\u8BEF");
|
|
1507
1508
|
}
|
|
1508
1509
|
};
|
|
1509
1510
|
useEffect(() => {
|
|
1510
1511
|
init();
|
|
1511
1512
|
}, [fileUrl]);
|
|
1512
|
-
|
|
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:
|
|
@@ -8470,6 +8484,55 @@ var SearchAndReplace = Extension.create({
|
|
|
8470
8484
|
}
|
|
8471
8485
|
});
|
|
8472
8486
|
var searchAndReplace_default = SearchAndReplace;
|
|
8487
|
+
var usePageNo = (pageNoConfig) => {
|
|
8488
|
+
const [editor, setEditor] = useState(null);
|
|
8489
|
+
const lastScrollToPageNoRef = useRef(void 0);
|
|
8490
|
+
const setPageNoEditor = (newEditor) => {
|
|
8491
|
+
setEditor(newEditor);
|
|
8492
|
+
};
|
|
8493
|
+
const onPageChange = useDebounce_default((pageNo = 0) => {
|
|
8494
|
+
lastScrollToPageNoRef.current = pageNo;
|
|
8495
|
+
pageNoConfig?.onScrollPage?.(pageNo);
|
|
8496
|
+
}, 300);
|
|
8497
|
+
useEffect(() => {
|
|
8498
|
+
if (!editor) return;
|
|
8499
|
+
if (!pageNoConfig?.enabled) return;
|
|
8500
|
+
const targetPageNo = pageNoConfig?.pageNo;
|
|
8501
|
+
if (isNullOrUnDef(targetPageNo)) return;
|
|
8502
|
+
if (lastScrollToPageNoRef.current === targetPageNo) return;
|
|
8503
|
+
let rafId = 0;
|
|
8504
|
+
const targetPageNoStr = String(targetPageNo);
|
|
8505
|
+
const findTargetPos = () => {
|
|
8506
|
+
let foundPos = null;
|
|
8507
|
+
editor.state.doc.descendants((node, pos) => {
|
|
8508
|
+
if (!isNullOrUnDef(foundPos)) return false;
|
|
8509
|
+
if (node.type.name !== PAGE_NO_KEY) return true;
|
|
8510
|
+
if (String(node.attrs?.[PAGE_NO_TAG]) === targetPageNoStr) {
|
|
8511
|
+
foundPos = pos;
|
|
8512
|
+
return false;
|
|
8513
|
+
}
|
|
8514
|
+
return true;
|
|
8515
|
+
});
|
|
8516
|
+
return foundPos;
|
|
8517
|
+
};
|
|
8518
|
+
let tries = 0;
|
|
8519
|
+
const tryScroll = () => {
|
|
8520
|
+
const foundPos = findTargetPos();
|
|
8521
|
+
if (!isNullOrUnDef(foundPos)) {
|
|
8522
|
+
scrollEditorViewToPosInNextFrame(editor.view, foundPos, { align: "start", behavior: "smooth" });
|
|
8523
|
+
return;
|
|
8524
|
+
}
|
|
8525
|
+
tries += 1;
|
|
8526
|
+
if (tries < 10) rafId = requestAnimationFrame(tryScroll);
|
|
8527
|
+
};
|
|
8528
|
+
rafId = requestAnimationFrame(tryScroll);
|
|
8529
|
+
return () => cancelAnimationFrame(rafId);
|
|
8530
|
+
}, [editor, pageNoConfig?.enabled, pageNoConfig?.pageNo]);
|
|
8531
|
+
return {
|
|
8532
|
+
setPageNoEditor,
|
|
8533
|
+
onPageChange
|
|
8534
|
+
};
|
|
8535
|
+
};
|
|
8473
8536
|
var MarkdownEditor_default = ({
|
|
8474
8537
|
value = ``,
|
|
8475
8538
|
onChange,
|
|
@@ -8486,9 +8549,7 @@ var MarkdownEditor_default = ({
|
|
|
8486
8549
|
}) => {
|
|
8487
8550
|
const isMobile = useIsBreakpoint();
|
|
8488
8551
|
const lastContentRef = useRef("");
|
|
8489
|
-
const onPageChange =
|
|
8490
|
-
pageNoConfig?.onScrollPage?.(pageIndex ?? 0);
|
|
8491
|
-
}, 300);
|
|
8552
|
+
const { setPageNoEditor, onPageChange } = usePageNo(pageNoConfig);
|
|
8492
8553
|
const {
|
|
8493
8554
|
setAnnotationEditor,
|
|
8494
8555
|
annotations,
|
|
@@ -8624,6 +8685,7 @@ var MarkdownEditor_default = ({
|
|
|
8624
8685
|
if (!editor) return;
|
|
8625
8686
|
setAnnotationEditor(editor);
|
|
8626
8687
|
setCollectionEditor(editor);
|
|
8688
|
+
setPageNoEditor(editor);
|
|
8627
8689
|
}, [editor]);
|
|
8628
8690
|
useEffect(() => {
|
|
8629
8691
|
if (!editor) return;
|