@zero-library/common 2.1.10 → 2.1.11
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 +80 -60
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +231 -40
- package/dist/index.d.ts +231 -40
- package/dist/index.esm.js +83 -63
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
|
2
2
|
import { FileUnknownOutlined, FileZipOutlined, FileMarkdownOutlined, FileGifOutlined, FileImageOutlined, FileJpgOutlined, NotificationOutlined, VideoCameraOutlined, FilePptOutlined, FileExcelOutlined, FileWordOutlined, FilePdfOutlined, FileTextOutlined } from '@ant-design/icons';
|
|
3
3
|
import * as React16 from 'react';
|
|
4
4
|
import { forwardRef, useState, useMemo, useEffect, lazy, Suspense, useRef, createContext, useCallback, useContext } from 'react';
|
|
5
|
-
import { Spin, Result, Splitter, Empty, Image, Flex, Drawer, Tag, Avatar, Alert, notification, Modal, Form, Input, Button } from 'antd';
|
|
5
|
+
import { Spin, Result, message, Splitter, Empty, Image, Flex, Drawer, Tag, Avatar, Alert, notification, Modal, Form, Input, Button } from 'antd';
|
|
6
6
|
import parse from 'html-react-parser';
|
|
7
7
|
import { jsonrepair } from 'jsonrepair';
|
|
8
8
|
import markdownit from 'markdown-it';
|
|
@@ -19,7 +19,7 @@ import AES from 'crypto-js/aes';
|
|
|
19
19
|
import encUtf8 from 'crypto-js/enc-utf8';
|
|
20
20
|
import Decimal from 'decimal.js';
|
|
21
21
|
import axios from 'axios';
|
|
22
|
-
import { message } from 'antd/lib';
|
|
22
|
+
import { message as message$1 } from 'antd/lib';
|
|
23
23
|
import '@react-pdf-viewer/thumbnail/lib/styles/index.css';
|
|
24
24
|
import '@react-pdf-viewer/zoom/lib/styles/index.css';
|
|
25
25
|
import classNames2 from 'classnames';
|
|
@@ -59,24 +59,8 @@ var AudioPlayer_default = ({ fileUrl }) => {
|
|
|
59
59
|
"\u60A8\u7684\u6D4F\u89C8\u5668\u4E0D\u652F\u6301 audio \u6807\u7B7E\u3002"
|
|
60
60
|
] });
|
|
61
61
|
};
|
|
62
|
-
|
|
63
|
-
// src/utils/theme.ts
|
|
64
|
-
var getPrimaryColor = () => {
|
|
65
|
-
const searchParams = new URLSearchParams(location.search);
|
|
66
|
-
const mainSource = searchParams.get("mainSource") || "cube-uc";
|
|
67
|
-
if (mainSource === "cube-uc") {
|
|
68
|
-
return "#34AFBE";
|
|
69
|
-
} else if (mainSource === "uc") {
|
|
70
|
-
return "#FA541C";
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var LgPrimaryColor = getPrimaryColor();
|
|
74
|
-
var themeConfig = {
|
|
75
|
-
token: { colorPrimary: LgPrimaryColor, colorLink: LgPrimaryColor },
|
|
76
|
-
cssVar: true
|
|
77
|
-
};
|
|
78
62
|
var FileIcon_default = ({ suffix, fontSize = 22 }) => {
|
|
79
|
-
const styles = { fontSize, color:
|
|
63
|
+
const styles = { fontSize, color: "var(--ant-color-primary)" };
|
|
80
64
|
const Icon = useMemo(() => {
|
|
81
65
|
switch (suffix?.toUpperCase()) {
|
|
82
66
|
case "TXT":
|
|
@@ -171,7 +155,7 @@ function highlightKeywords(html, keywords) {
|
|
|
171
155
|
function makePlaceholder(id) {
|
|
172
156
|
return `__ALERT_DATA_${id}__`;
|
|
173
157
|
}
|
|
174
|
-
function
|
|
158
|
+
function alertMarkClean(src) {
|
|
175
159
|
let pos = 0;
|
|
176
160
|
let id = 0;
|
|
177
161
|
let out = "";
|
|
@@ -187,17 +171,13 @@ function extractAlertPlaceholders(src) {
|
|
|
187
171
|
const relAfter = afterStart.slice(":::alert".length);
|
|
188
172
|
const matchLineEnd = relAfter.search(/\s*:::\s*/);
|
|
189
173
|
let endIdx = -1;
|
|
174
|
+
let isNoEnd = 1;
|
|
190
175
|
if (matchLineEnd !== -1) {
|
|
191
|
-
endIdx = start + ":::alert".length + matchLineEnd
|
|
176
|
+
endIdx = start + ":::alert".length + matchLineEnd;
|
|
177
|
+
isNoEnd = 0;
|
|
192
178
|
} else {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
out += src.slice(start);
|
|
196
|
-
pos = src.length;
|
|
197
|
-
break;
|
|
198
|
-
} else {
|
|
199
|
-
endIdx = fallback;
|
|
200
|
-
}
|
|
179
|
+
endIdx = src.length;
|
|
180
|
+
isNoEnd = 1;
|
|
201
181
|
}
|
|
202
182
|
const inner = src.slice(start + ":::alert".length, endIdx).trim();
|
|
203
183
|
const typeMatch = inner.match(/type\s*=\s*(?:(['"])(.*?)\1|(\S+))/);
|
|
@@ -209,8 +189,8 @@ function extractAlertPlaceholders(src) {
|
|
|
209
189
|
}
|
|
210
190
|
const ph = makePlaceholder(id++);
|
|
211
191
|
placeholders.set(ph, rawData);
|
|
212
|
-
const typeText = type ? `
|
|
213
|
-
out += `:::alert${typeText} data="${ph}" :::`;
|
|
192
|
+
const typeText = type ? `type=${JSON.stringify(type)}` : "";
|
|
193
|
+
out += `:::alert ${typeText} data="${ph}" loading="${isNoEnd}" :::`;
|
|
214
194
|
const realClose = src.indexOf(":::", endIdx);
|
|
215
195
|
pos = realClose === -1 ? endIdx : realClose + 3;
|
|
216
196
|
}
|
|
@@ -239,33 +219,23 @@ try {
|
|
|
239
219
|
var RenderMarkdown_default = ({ content = "", searchValue, customComponents, onChange, onPartialChange }) => {
|
|
240
220
|
const reactContent = useMemo(() => {
|
|
241
221
|
if (!content) return null;
|
|
242
|
-
|
|
243
|
-
const openCount = (fixedContent.match(/:::alert\b/g) || []).length;
|
|
244
|
-
const closeCount = (fixedContent.match(/\s*:::\s*/gm) || []).length - openCount;
|
|
245
|
-
let incomplete = false;
|
|
246
|
-
if (openCount > closeCount) {
|
|
247
|
-
incomplete = true;
|
|
248
|
-
fixedContent += " :::";
|
|
249
|
-
}
|
|
250
|
-
const { text: preprocessed, placeholders } = extractAlertPlaceholders(fixedContent);
|
|
222
|
+
const { text: preprocessed, placeholders } = alertMarkClean(content);
|
|
251
223
|
let rawHtml = md.render(preprocessed);
|
|
252
224
|
rawHtml = searchValue ? highlightKeywords(rawHtml, [searchValue]) : rawHtml;
|
|
253
225
|
let lazyIndex = -1;
|
|
254
|
-
const allLazyMatches = [...rawHtml.matchAll(/<lazy-component/gi)];
|
|
255
|
-
const lastLazyIndex = allLazyMatches.length - 1;
|
|
256
226
|
return parse(rawHtml, {
|
|
257
227
|
replace: (domNode) => {
|
|
258
228
|
if (domNode.name === "lazy-component") {
|
|
259
229
|
lazyIndex++;
|
|
260
230
|
const el = domNode;
|
|
261
231
|
const type = el.attribs.type;
|
|
232
|
+
const loading = !!Number(el.attribs.loading);
|
|
262
233
|
const dataAttr = el.attribs.data || "";
|
|
263
234
|
let data = {};
|
|
264
235
|
if (/^__ALERT_DATA_\d+__$/.test(dataAttr)) {
|
|
265
236
|
const raw = placeholders.get(dataAttr) ?? "";
|
|
266
237
|
data = parseData(raw);
|
|
267
238
|
}
|
|
268
|
-
const loading = incomplete && lazyIndex === lastLazyIndex;
|
|
269
239
|
return /* @__PURE__ */ jsx(
|
|
270
240
|
LazyComponent_default,
|
|
271
241
|
{
|
|
@@ -462,8 +432,9 @@ function useCreateValtioContext() {
|
|
|
462
432
|
};
|
|
463
433
|
return {
|
|
464
434
|
ValtioProvider,
|
|
465
|
-
useValtioStore
|
|
466
|
-
// Context
|
|
435
|
+
useValtioStore,
|
|
436
|
+
// 导出 Context 以便外部使用
|
|
437
|
+
Context
|
|
467
438
|
};
|
|
468
439
|
}
|
|
469
440
|
function useDebounce(func, wait = 400) {
|
|
@@ -502,8 +473,6 @@ function useDebounce(func, wait = 400) {
|
|
|
502
473
|
debounce.cancel = cancel;
|
|
503
474
|
return useCallback(debounce, []);
|
|
504
475
|
}
|
|
505
|
-
|
|
506
|
-
// src/utils/common.ts
|
|
507
476
|
var deepCopy = (obj, isJson = true) => {
|
|
508
477
|
if (!isArray(obj) && !isObject(obj)) return obj;
|
|
509
478
|
if (isJson) return JSON.parse(JSON.stringify(obj));
|
|
@@ -606,9 +575,13 @@ var genNonDuplicateID = () => {
|
|
|
606
575
|
idStr += Math.random().toString(36).substr(2);
|
|
607
576
|
return idStr;
|
|
608
577
|
};
|
|
609
|
-
var copyText = (text) => {
|
|
578
|
+
var copyText = (text, prompt = "\u590D\u5236\u6210\u529F") => {
|
|
610
579
|
if (navigator.clipboard && window.isSecureContext) {
|
|
611
|
-
|
|
580
|
+
navigator.clipboard.writeText(text).then(() => {
|
|
581
|
+
if (prompt) {
|
|
582
|
+
message.success(prompt);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
612
585
|
} else {
|
|
613
586
|
const textArea = document.createElement("textarea");
|
|
614
587
|
textArea.value = text;
|
|
@@ -619,10 +592,11 @@ var copyText = (text) => {
|
|
|
619
592
|
document.body.appendChild(textArea);
|
|
620
593
|
textArea.focus();
|
|
621
594
|
textArea.select();
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}
|
|
595
|
+
const bol = document.execCommand("copy");
|
|
596
|
+
if (bol && prompt) {
|
|
597
|
+
message.success(prompt);
|
|
598
|
+
}
|
|
599
|
+
textArea.remove();
|
|
626
600
|
}
|
|
627
601
|
};
|
|
628
602
|
function formatNumberWithCommas(number) {
|
|
@@ -894,6 +868,24 @@ var isInteger = (num) => {
|
|
|
894
868
|
var isNegative = (num) => {
|
|
895
869
|
return new Decimal(num).isNegative();
|
|
896
870
|
};
|
|
871
|
+
|
|
872
|
+
// src/utils/theme.ts
|
|
873
|
+
var getPrimaryColor = () => {
|
|
874
|
+
const searchParams = new URLSearchParams(location.search);
|
|
875
|
+
const mainSource = searchParams.get("mainSource") || "cube-uc";
|
|
876
|
+
if (mainSource === "cube-uc") {
|
|
877
|
+
return "#34AFBE";
|
|
878
|
+
} else if (mainSource === "uc") {
|
|
879
|
+
return "#FA541C";
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
var LgPrimaryColor = getPrimaryColor();
|
|
883
|
+
var themeConfig = {
|
|
884
|
+
token: { colorPrimary: LgPrimaryColor, colorLink: LgPrimaryColor },
|
|
885
|
+
cssVar: true
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
// src/utils/message.ts
|
|
897
889
|
var cacheMessage = () => {
|
|
898
890
|
const contents = {};
|
|
899
891
|
return ({ title = "\u63D0\u793A", content, type = "warning", duration = 3, onClose, isCache = true, isOnly = false }) => {
|
|
@@ -917,7 +909,7 @@ var cacheMessage = () => {
|
|
|
917
909
|
onClose: onClose2
|
|
918
910
|
});
|
|
919
911
|
} else {
|
|
920
|
-
message[type]({
|
|
912
|
+
message$1[type]({
|
|
921
913
|
content,
|
|
922
914
|
duration,
|
|
923
915
|
onClose: onClose2
|
|
@@ -1024,18 +1016,46 @@ function createRequest(baseURL = "/api") {
|
|
|
1024
1016
|
}
|
|
1025
1017
|
);
|
|
1026
1018
|
return {
|
|
1019
|
+
/**
|
|
1020
|
+
* GET 请求方法
|
|
1021
|
+
* @param url - 请求地址
|
|
1022
|
+
* @param params - 查询参数
|
|
1023
|
+
* @param options - Axios 配置选项
|
|
1024
|
+
* @returns 响应数据
|
|
1025
|
+
*/
|
|
1027
1026
|
get: async (url, params, options) => {
|
|
1028
1027
|
const res = await instance({ method: "get", url, params, ...options });
|
|
1029
1028
|
return res.data;
|
|
1030
1029
|
},
|
|
1030
|
+
/**
|
|
1031
|
+
* POST 请求方法
|
|
1032
|
+
* @param url - 请求地址
|
|
1033
|
+
* @param data - 请求数据
|
|
1034
|
+
* @param options - Axios 配置选项
|
|
1035
|
+
* @returns 响应数据
|
|
1036
|
+
*/
|
|
1031
1037
|
post: async (url, data, options) => {
|
|
1032
1038
|
const res = await instance({ method: "post", url, data, ...options });
|
|
1033
1039
|
return res.data;
|
|
1034
1040
|
},
|
|
1041
|
+
/**
|
|
1042
|
+
* PUT 请求方法
|
|
1043
|
+
* @param url - 请求地址
|
|
1044
|
+
* @param data - 请求数据
|
|
1045
|
+
* @param options - Axios 配置选项
|
|
1046
|
+
* @returns 响应数据
|
|
1047
|
+
*/
|
|
1035
1048
|
put: async (url, data, options) => {
|
|
1036
1049
|
const res = await instance({ method: "put", url, data, ...options });
|
|
1037
1050
|
return res.data;
|
|
1038
1051
|
},
|
|
1052
|
+
/**
|
|
1053
|
+
* DELETE 请求方法
|
|
1054
|
+
* @param url - 请求地址
|
|
1055
|
+
* @param data - 请求数据
|
|
1056
|
+
* @param options - Axios 配置选项
|
|
1057
|
+
* @returns 响应数据
|
|
1058
|
+
*/
|
|
1039
1059
|
delete: async (url, data, options) => {
|
|
1040
1060
|
const res = await instance({ method: "delete", url, data, ...options });
|
|
1041
1061
|
return res.data;
|
|
@@ -1167,9 +1187,9 @@ var useWebSocket = ({
|
|
|
1167
1187
|
stopReconnectTimer();
|
|
1168
1188
|
};
|
|
1169
1189
|
}, [url]);
|
|
1170
|
-
const sendMessage = (
|
|
1190
|
+
const sendMessage = (message3) => {
|
|
1171
1191
|
if (socketRef.current?.readyState === WebSocket.OPEN) {
|
|
1172
|
-
socketRef.current.send(
|
|
1192
|
+
socketRef.current.send(message3);
|
|
1173
1193
|
stopHeartbeat();
|
|
1174
1194
|
startHeartbeat(socketRef.current);
|
|
1175
1195
|
}
|
|
@@ -1252,25 +1272,25 @@ var PdfPreview_default = ({ password, fileUrl, pageNo = 1, scale = 1, isHasThumb
|
|
|
1252
1272
|
}, 0);
|
|
1253
1273
|
}, [pageNo]);
|
|
1254
1274
|
const renderError = (error) => {
|
|
1255
|
-
let
|
|
1275
|
+
let message3 = "";
|
|
1256
1276
|
switch (error.name) {
|
|
1257
1277
|
case "InvalidPDFException":
|
|
1258
|
-
|
|
1278
|
+
message3 = "\u6587\u4EF6\u65E0\u6548\u6216\u5DF2\u635F\u574F";
|
|
1259
1279
|
break;
|
|
1260
1280
|
case "MissingPDFException":
|
|
1261
|
-
|
|
1281
|
+
message3 = "\u6587\u4EF6\u4E0D\u5B58\u5728";
|
|
1262
1282
|
break;
|
|
1263
1283
|
case "UnexpectedResponseException":
|
|
1264
|
-
|
|
1284
|
+
message3 = "\u610F\u5916\u7684\u670D\u52A1\u5668\u54CD\u5E94";
|
|
1265
1285
|
break;
|
|
1266
1286
|
// case 'CMapReaderFactory not initialized':
|
|
1267
1287
|
// message = '字体映射文件加载失败,请刷新页面重试'
|
|
1268
1288
|
// break
|
|
1269
1289
|
default:
|
|
1270
|
-
|
|
1290
|
+
message3 = "\u65E0\u6CD5\u52A0\u8F7D\u6587\u6863";
|
|
1271
1291
|
break;
|
|
1272
1292
|
}
|
|
1273
|
-
return /* @__PURE__ */ jsx(Flex, { className: "height-full", justify: "center", align: "center", children: /* @__PURE__ */ jsx(Alert, { message:
|
|
1293
|
+
return /* @__PURE__ */ jsx(Flex, { className: "height-full", justify: "center", align: "center", children: /* @__PURE__ */ jsx(Alert, { message: message3, type: "error", showIcon: true }) });
|
|
1274
1294
|
};
|
|
1275
1295
|
const onPageChange = (e) => {
|
|
1276
1296
|
let newCurrentPage = e.currentPage;
|
|
@@ -5231,7 +5251,7 @@ function propsMerge(control, props) {
|
|
|
5231
5251
|
return null;
|
|
5232
5252
|
}
|
|
5233
5253
|
var UserAvatar_default = ({ size, avatarSrc, userName }) => {
|
|
5234
|
-
return avatarSrc ? /* @__PURE__ */ jsx(Avatar, { size, src: avatarSrc }) : /* @__PURE__ */ jsx(Avatar, { size, className: "cursor-pointer", style: { backgroundColor:
|
|
5254
|
+
return avatarSrc ? /* @__PURE__ */ jsx(Avatar, { size, src: avatarSrc }) : /* @__PURE__ */ jsx(Avatar, { size, className: "cursor-pointer", style: { backgroundColor: "var(--ant-color-primary)" }, children: userName?.slice(0, 1)?.toLocaleUpperCase() });
|
|
5235
5255
|
};
|
|
5236
5256
|
|
|
5237
5257
|
export { AudioPlayer_default as AudioPlayer, DateFormatType, DateFormatType2, ERROR, FORBIDDEN, FileIcon_default as FileIcon, FilePreview_default as FilePreview, FilePreviewDrawer_default as FilePreviewDrawer, Iframe_default as Iframe, LazyComponent_default as LazyComponent, LgPrimaryColor, MISSING_PARAMETER, MarkdownEditor_default as MarkdownEditor, MarkdownPreview_default as MarkdownPreview, NOT_FOUND, OK, PERMISSION_DENIED, PdfPreview_default as PdfPreview, RenderMarkdown_default as RenderMarkdown, RenderWrapper, TOKEN_KEY, UNAUTHORIZED, UserAvatar_default as UserAvatar, VideoPlayer_default as VideoPlayer, absVal, addUrlLastSlash, arrToObj, buildUrlParams, calculate, clearCurrentUser, clearToken, compareNum, copyText, createRequest, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, formatDate, formatNumberWithCommas, genNonDuplicateID, generateRandomNumbers, getCurrentUser, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getSignPath, getStartOfTimestamp, getTimestamp, getToken, getUrlMainSource, getUrlToken, getWebSocketUrl, is, isArray, isBlob, isBoolean, isClient, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isRegExp, isServer, isString, isUnDef, isWindow, minus, nsSetInterval, objToOptions, plus, precision, propsMerge, setCurrentUser, setToken, shouldRender, textAreaView, themeConfig, times, toFixed, transform, transforms, useCreateValtioContext, useDebounce, useDeepEffect, useIframeRelayBridge, useRefState, useSyncInput, useThrottle, useWebSocket_default as useWebSocket };
|