@zero-library/common 3.0.5 → 3.0.7
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 +12 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +9 -2
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { EmptyProps } from 'antd';
|
|
3
|
+
export { default as microApp } from '@micro-zoe/micro-app';
|
|
3
4
|
import * as react from 'react';
|
|
4
5
|
import { ReactNode } from 'react';
|
|
5
6
|
import { Editor, FocusPosition, Content, InsertContentOptions, InsertContentAtOptions } from '@tiptap/core';
|
|
@@ -1545,7 +1546,7 @@ interface SafeParseJsonOptions {
|
|
|
1545
1546
|
* @param options - 解析配置
|
|
1546
1547
|
* @returns 解析成功时返回对象;失败时返回原字符串或 `null`
|
|
1547
1548
|
*/
|
|
1548
|
-
declare function safeParseJson<T = any>(raw
|
|
1549
|
+
declare function safeParseJson<T = any>(raw?: string, options?: SafeParseJsonOptions): T | string | null;
|
|
1549
1550
|
|
|
1550
1551
|
type DateType = string | number | Date | dayjs.Dayjs | null;
|
|
1551
1552
|
/** 默认日期时间格式:年-月-日 时:分:秒 */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { EmptyProps } from 'antd';
|
|
3
|
+
export { default as microApp } from '@micro-zoe/micro-app';
|
|
3
4
|
import * as react from 'react';
|
|
4
5
|
import { ReactNode } from 'react';
|
|
5
6
|
import { Editor, FocusPosition, Content, InsertContentOptions, InsertContentAtOptions } from '@tiptap/core';
|
|
@@ -1545,7 +1546,7 @@ interface SafeParseJsonOptions {
|
|
|
1545
1546
|
* @param options - 解析配置
|
|
1546
1547
|
* @returns 解析成功时返回对象;失败时返回原字符串或 `null`
|
|
1547
1548
|
*/
|
|
1548
|
-
declare function safeParseJson<T = any>(raw
|
|
1549
|
+
declare function safeParseJson<T = any>(raw?: string, options?: SafeParseJsonOptions): T | string | null;
|
|
1549
1550
|
|
|
1550
1551
|
type DateType = string | number | Date | dayjs.Dayjs | null;
|
|
1551
1552
|
/** 默认日期时间格式:年-月-日 时:分:秒 */
|
package/dist/index.esm.js
CHANGED
|
@@ -36,6 +36,7 @@ import Editor, { loader } from '@monaco-editor/react';
|
|
|
36
36
|
import * as monaco from 'monaco-editor';
|
|
37
37
|
import * as pdfjsLib from 'pdfjs-dist-v5/legacy/build/pdf.mjs';
|
|
38
38
|
import microApp from '@micro-zoe/micro-app';
|
|
39
|
+
export { default as microApp } from '@micro-zoe/micro-app';
|
|
39
40
|
import jsxCustomEvent from '@micro-zoe/micro-app/polyfill/jsx-custom-event';
|
|
40
41
|
import { mergeAttributes, useEditor, EditorContext, EditorContent, isNodeSelection, posToDOMRect, useCurrentEditor, useEditorState, isTextSelection } from '@tiptap/react';
|
|
41
42
|
import { Highlight } from '@tiptap/extension-highlight';
|
|
@@ -880,18 +881,24 @@ var findTreeNodesByIds = (tree, ids, formatFn, options = {}) => {
|
|
|
880
881
|
dfs(tree);
|
|
881
882
|
return result;
|
|
882
883
|
};
|
|
883
|
-
function
|
|
884
|
+
function looksLikeStructuredJson(raw) {
|
|
885
|
+
const normalized = raw.trim();
|
|
886
|
+
if (!normalized) return false;
|
|
887
|
+
return normalized.startsWith("{") || normalized.startsWith("[");
|
|
888
|
+
}
|
|
889
|
+
function safeParseJson(raw = "", options = {}) {
|
|
884
890
|
const shouldRepair = options.repair ?? false;
|
|
885
891
|
const fallbackMode = options.fallback ?? "raw";
|
|
886
892
|
const getFallbackValue = () => fallbackMode === "raw" ? raw : null;
|
|
887
893
|
try {
|
|
888
894
|
return JSON.parse(raw);
|
|
889
895
|
} catch {
|
|
890
|
-
if (!shouldRepair) return getFallbackValue();
|
|
896
|
+
if (!shouldRepair || !looksLikeStructuredJson(raw)) return getFallbackValue();
|
|
891
897
|
}
|
|
892
898
|
try {
|
|
893
899
|
return JSON.parse(jsonrepair(raw));
|
|
894
900
|
} catch {
|
|
901
|
+
console.error("jsonrepair error:", raw);
|
|
895
902
|
return getFallbackValue();
|
|
896
903
|
}
|
|
897
904
|
}
|