@m4l/components 9.3.10-BE220825-beta.2 → 9.3.10-BE250825-beta.1
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/commonjs/index.js +6 -0
- package/components/ObjectLogs/slots/ObjectLogsSlots.js +2 -2
- package/components/ObjectLogs/subcomponents/DetailDialog/index.js +2 -4
- package/components/extended/React-Json-Viewer/ReactJsonViewer.js +2 -3
- package/components/extended/React-Json-Viewer/helpers/getReactJsonViewerTheme/getReactJsonViewerTheme.d.ts +2 -2
- package/components/extended/React-Json-Viewer/helpers/getReactJsonViewerTheme/getReactJsonViewerTheme.js +16 -16
- package/components/extended/React-Json-Viewer/types.d.ts +2 -2
- package/not_recognized/index.js +1942 -0
- package/package.json +2 -1
- package/components/extended/React-Json-Viewer/helpers/getReactJsonViewerTheme/index.js +0 -1
|
@@ -0,0 +1,1942 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createTheme, ThemeProvider, Paper, Box, SvgIcon, NoSsr, InputBase } from "@mui/material";
|
|
3
|
+
import { useMemo, createContext, useState, useEffect, useContext, useRef, useCallback, memo } from "react";
|
|
4
|
+
import { create, createStore, useStore } from "zustand";
|
|
5
|
+
import { g as getDefaultExportFromCjs } from "../commonjs/index.js";
|
|
6
|
+
var toggleSelection;
|
|
7
|
+
var hasRequiredToggleSelection;
|
|
8
|
+
function requireToggleSelection() {
|
|
9
|
+
if (hasRequiredToggleSelection) return toggleSelection;
|
|
10
|
+
hasRequiredToggleSelection = 1;
|
|
11
|
+
toggleSelection = function() {
|
|
12
|
+
var selection = document.getSelection();
|
|
13
|
+
if (!selection.rangeCount) {
|
|
14
|
+
return function() {
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
var active = document.activeElement;
|
|
18
|
+
var ranges = [];
|
|
19
|
+
for (var i = 0; i < selection.rangeCount; i++) {
|
|
20
|
+
ranges.push(selection.getRangeAt(i));
|
|
21
|
+
}
|
|
22
|
+
switch (active.tagName.toUpperCase()) {
|
|
23
|
+
// .toUpperCase handles XHTML
|
|
24
|
+
case "INPUT":
|
|
25
|
+
case "TEXTAREA":
|
|
26
|
+
active.blur();
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
active = null;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
selection.removeAllRanges();
|
|
33
|
+
return function() {
|
|
34
|
+
selection.type === "Caret" && selection.removeAllRanges();
|
|
35
|
+
if (!selection.rangeCount) {
|
|
36
|
+
ranges.forEach(function(range) {
|
|
37
|
+
selection.addRange(range);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
active && active.focus();
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
return toggleSelection;
|
|
44
|
+
}
|
|
45
|
+
var copyToClipboard$1;
|
|
46
|
+
var hasRequiredCopyToClipboard;
|
|
47
|
+
function requireCopyToClipboard() {
|
|
48
|
+
if (hasRequiredCopyToClipboard) return copyToClipboard$1;
|
|
49
|
+
hasRequiredCopyToClipboard = 1;
|
|
50
|
+
var deselectCurrent = requireToggleSelection();
|
|
51
|
+
var clipboardToIE11Formatting = {
|
|
52
|
+
"text/plain": "Text",
|
|
53
|
+
"text/html": "Url",
|
|
54
|
+
"default": "Text"
|
|
55
|
+
};
|
|
56
|
+
var defaultMessage = "Copy to clipboard: #{key}, Enter";
|
|
57
|
+
function format(message) {
|
|
58
|
+
var copyKey = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C";
|
|
59
|
+
return message.replace(/#{\s*key\s*}/g, copyKey);
|
|
60
|
+
}
|
|
61
|
+
function copy(text, options) {
|
|
62
|
+
var debug, message, reselectPrevious, range, selection, mark, success = false;
|
|
63
|
+
if (!options) {
|
|
64
|
+
options = {};
|
|
65
|
+
}
|
|
66
|
+
debug = options.debug || false;
|
|
67
|
+
try {
|
|
68
|
+
reselectPrevious = deselectCurrent();
|
|
69
|
+
range = document.createRange();
|
|
70
|
+
selection = document.getSelection();
|
|
71
|
+
mark = document.createElement("span");
|
|
72
|
+
mark.textContent = text;
|
|
73
|
+
mark.ariaHidden = "true";
|
|
74
|
+
mark.style.all = "unset";
|
|
75
|
+
mark.style.position = "fixed";
|
|
76
|
+
mark.style.top = 0;
|
|
77
|
+
mark.style.clip = "rect(0, 0, 0, 0)";
|
|
78
|
+
mark.style.whiteSpace = "pre";
|
|
79
|
+
mark.style.webkitUserSelect = "text";
|
|
80
|
+
mark.style.MozUserSelect = "text";
|
|
81
|
+
mark.style.msUserSelect = "text";
|
|
82
|
+
mark.style.userSelect = "text";
|
|
83
|
+
mark.addEventListener("copy", function(e) {
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
if (options.format) {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
if (typeof e.clipboardData === "undefined") {
|
|
88
|
+
debug && console.warn("unable to use e.clipboardData");
|
|
89
|
+
debug && console.warn("trying IE specific stuff");
|
|
90
|
+
window.clipboardData.clearData();
|
|
91
|
+
var format2 = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting["default"];
|
|
92
|
+
window.clipboardData.setData(format2, text);
|
|
93
|
+
} else {
|
|
94
|
+
e.clipboardData.clearData();
|
|
95
|
+
e.clipboardData.setData(options.format, text);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (options.onCopy) {
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
options.onCopy(e.clipboardData);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
document.body.appendChild(mark);
|
|
104
|
+
range.selectNodeContents(mark);
|
|
105
|
+
selection.addRange(range);
|
|
106
|
+
var successful = document.execCommand("copy");
|
|
107
|
+
if (!successful) {
|
|
108
|
+
throw new Error("copy command was unsuccessful");
|
|
109
|
+
}
|
|
110
|
+
success = true;
|
|
111
|
+
} catch (err) {
|
|
112
|
+
debug && console.error("unable to copy using execCommand: ", err);
|
|
113
|
+
debug && console.warn("trying IE specific stuff");
|
|
114
|
+
try {
|
|
115
|
+
window.clipboardData.setData(options.format || "text", text);
|
|
116
|
+
options.onCopy && options.onCopy(window.clipboardData);
|
|
117
|
+
success = true;
|
|
118
|
+
} catch (err2) {
|
|
119
|
+
debug && console.error("unable to copy using clipboardData: ", err2);
|
|
120
|
+
debug && console.error("falling back to prompt");
|
|
121
|
+
message = format("message" in options ? options.message : defaultMessage);
|
|
122
|
+
window.prompt(message, text);
|
|
123
|
+
}
|
|
124
|
+
} finally {
|
|
125
|
+
if (selection) {
|
|
126
|
+
if (typeof selection.removeRange == "function") {
|
|
127
|
+
selection.removeRange(range);
|
|
128
|
+
} else {
|
|
129
|
+
selection.removeAllRanges();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (mark) {
|
|
133
|
+
document.body.removeChild(mark);
|
|
134
|
+
}
|
|
135
|
+
reselectPrevious();
|
|
136
|
+
}
|
|
137
|
+
return success;
|
|
138
|
+
}
|
|
139
|
+
copyToClipboard$1 = copy;
|
|
140
|
+
return copyToClipboard$1;
|
|
141
|
+
}
|
|
142
|
+
var copyToClipboardExports = requireCopyToClipboard();
|
|
143
|
+
const copyToClipboard = /* @__PURE__ */ getDefaultExportFromCjs(copyToClipboardExports);
|
|
144
|
+
function r(e) {
|
|
145
|
+
var t, f, n = "";
|
|
146
|
+
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
147
|
+
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
148
|
+
var o = e.length;
|
|
149
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
150
|
+
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
151
|
+
return n;
|
|
152
|
+
}
|
|
153
|
+
function clsx() {
|
|
154
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
155
|
+
return n;
|
|
156
|
+
}
|
|
157
|
+
const lightColorspace = {
|
|
158
|
+
scheme: "Light Theme",
|
|
159
|
+
author: "mac gainor (https://github.com/mac-s-g)",
|
|
160
|
+
base00: "rgba(0, 0, 0, 0)",
|
|
161
|
+
base01: "rgb(245, 245, 245)",
|
|
162
|
+
base02: "rgb(235, 235, 235)",
|
|
163
|
+
base03: "#93a1a1",
|
|
164
|
+
base04: "rgba(0, 0, 0, 0.3)",
|
|
165
|
+
base05: "#586e75",
|
|
166
|
+
base06: "#073642",
|
|
167
|
+
base07: "#002b36",
|
|
168
|
+
base08: "#d33682",
|
|
169
|
+
base09: "#cb4b16",
|
|
170
|
+
base0A: "#ffd500",
|
|
171
|
+
base0B: "#859900",
|
|
172
|
+
base0C: "#6c71c4",
|
|
173
|
+
base0D: "#586e75",
|
|
174
|
+
base0E: "#2aa198",
|
|
175
|
+
base0F: "#268bd2"
|
|
176
|
+
};
|
|
177
|
+
const darkColorspace = {
|
|
178
|
+
scheme: "Dark Theme",
|
|
179
|
+
author: "Chris Kempson (http://chriskempson.com)",
|
|
180
|
+
base00: "#181818",
|
|
181
|
+
base01: "#282828",
|
|
182
|
+
base02: "#383838",
|
|
183
|
+
base03: "#585858",
|
|
184
|
+
base04: "#b8b8b8",
|
|
185
|
+
base05: "#d8d8d8",
|
|
186
|
+
base06: "#e8e8e8",
|
|
187
|
+
base07: "#f8f8f8",
|
|
188
|
+
base08: "#ab4642",
|
|
189
|
+
base09: "#dc9656",
|
|
190
|
+
base0A: "#f7ca88",
|
|
191
|
+
base0B: "#a1b56c",
|
|
192
|
+
base0C: "#86c1b9",
|
|
193
|
+
base0D: "#7cafc2",
|
|
194
|
+
base0E: "#ba8baf",
|
|
195
|
+
base0F: "#a16946"
|
|
196
|
+
};
|
|
197
|
+
const DefaultKeyRenderer = () => null;
|
|
198
|
+
DefaultKeyRenderer.when = () => false;
|
|
199
|
+
const createJsonViewerStore = (props) => {
|
|
200
|
+
return create()((set, get) => {
|
|
201
|
+
var _props_rootName, _props_indentWidth, _props_keyRenderer, _props_enableAdd, _props_enableDelete, _props_enableClipboard, _props_editable, _props_onChange, _props_onCopy, _props_onSelect, _props_onAdd, _props_onDelete, _props_defaultInspectDepth, _props_defaultInspectControl, _props_maxDisplayLength, _props_groupArraysAfterLength, _props_collapseStringsAfterLength, _props_objectSortKeys, _props_quotesOnKeys, _props_displayDataTypes, _props_displaySize, _props_displayComma, _props_highlightUpdates;
|
|
202
|
+
return {
|
|
203
|
+
// provided by user
|
|
204
|
+
rootName: (_props_rootName = props.rootName) !== null && _props_rootName !== void 0 ? _props_rootName : "root",
|
|
205
|
+
indentWidth: (_props_indentWidth = props.indentWidth) !== null && _props_indentWidth !== void 0 ? _props_indentWidth : 3,
|
|
206
|
+
keyRenderer: (_props_keyRenderer = props.keyRenderer) !== null && _props_keyRenderer !== void 0 ? _props_keyRenderer : DefaultKeyRenderer,
|
|
207
|
+
enableAdd: (_props_enableAdd = props.enableAdd) !== null && _props_enableAdd !== void 0 ? _props_enableAdd : false,
|
|
208
|
+
enableDelete: (_props_enableDelete = props.enableDelete) !== null && _props_enableDelete !== void 0 ? _props_enableDelete : false,
|
|
209
|
+
enableClipboard: (_props_enableClipboard = props.enableClipboard) !== null && _props_enableClipboard !== void 0 ? _props_enableClipboard : true,
|
|
210
|
+
editable: (_props_editable = props.editable) !== null && _props_editable !== void 0 ? _props_editable : false,
|
|
211
|
+
onChange: (_props_onChange = props.onChange) !== null && _props_onChange !== void 0 ? _props_onChange : () => {
|
|
212
|
+
},
|
|
213
|
+
onCopy: (_props_onCopy = props.onCopy) !== null && _props_onCopy !== void 0 ? _props_onCopy : void 0,
|
|
214
|
+
onSelect: (_props_onSelect = props.onSelect) !== null && _props_onSelect !== void 0 ? _props_onSelect : void 0,
|
|
215
|
+
onAdd: (_props_onAdd = props.onAdd) !== null && _props_onAdd !== void 0 ? _props_onAdd : void 0,
|
|
216
|
+
onDelete: (_props_onDelete = props.onDelete) !== null && _props_onDelete !== void 0 ? _props_onDelete : void 0,
|
|
217
|
+
defaultInspectDepth: (_props_defaultInspectDepth = props.defaultInspectDepth) !== null && _props_defaultInspectDepth !== void 0 ? _props_defaultInspectDepth : 5,
|
|
218
|
+
defaultInspectControl: (_props_defaultInspectControl = props.defaultInspectControl) !== null && _props_defaultInspectControl !== void 0 ? _props_defaultInspectControl : void 0,
|
|
219
|
+
maxDisplayLength: (_props_maxDisplayLength = props.maxDisplayLength) !== null && _props_maxDisplayLength !== void 0 ? _props_maxDisplayLength : 30,
|
|
220
|
+
groupArraysAfterLength: (_props_groupArraysAfterLength = props.groupArraysAfterLength) !== null && _props_groupArraysAfterLength !== void 0 ? _props_groupArraysAfterLength : 100,
|
|
221
|
+
collapseStringsAfterLength: props.collapseStringsAfterLength === false ? Number.MAX_VALUE : (_props_collapseStringsAfterLength = props.collapseStringsAfterLength) !== null && _props_collapseStringsAfterLength !== void 0 ? _props_collapseStringsAfterLength : 50,
|
|
222
|
+
objectSortKeys: (_props_objectSortKeys = props.objectSortKeys) !== null && _props_objectSortKeys !== void 0 ? _props_objectSortKeys : false,
|
|
223
|
+
quotesOnKeys: (_props_quotesOnKeys = props.quotesOnKeys) !== null && _props_quotesOnKeys !== void 0 ? _props_quotesOnKeys : true,
|
|
224
|
+
displayDataTypes: (_props_displayDataTypes = props.displayDataTypes) !== null && _props_displayDataTypes !== void 0 ? _props_displayDataTypes : true,
|
|
225
|
+
displaySize: (_props_displaySize = props.displaySize) !== null && _props_displaySize !== void 0 ? _props_displaySize : true,
|
|
226
|
+
displayComma: (_props_displayComma = props.displayComma) !== null && _props_displayComma !== void 0 ? _props_displayComma : false,
|
|
227
|
+
highlightUpdates: (_props_highlightUpdates = props.highlightUpdates) !== null && _props_highlightUpdates !== void 0 ? _props_highlightUpdates : false,
|
|
228
|
+
// internal state
|
|
229
|
+
inspectCache: {},
|
|
230
|
+
hoverPath: null,
|
|
231
|
+
colorspace: lightColorspace,
|
|
232
|
+
value: props.value,
|
|
233
|
+
prevValue: void 0,
|
|
234
|
+
getInspectCache: (path, nestedIndex) => {
|
|
235
|
+
const target = nestedIndex !== void 0 ? path.join(".") + "[".concat(nestedIndex, "]nt") : path.join(".");
|
|
236
|
+
return get().inspectCache[target];
|
|
237
|
+
},
|
|
238
|
+
setInspectCache: (path, action, nestedIndex) => {
|
|
239
|
+
const target = nestedIndex !== void 0 ? path.join(".") + "[".concat(nestedIndex, "]nt") : path.join(".");
|
|
240
|
+
set((state) => ({
|
|
241
|
+
inspectCache: {
|
|
242
|
+
...state.inspectCache,
|
|
243
|
+
[target]: typeof action === "function" ? action(state.inspectCache[target]) : action
|
|
244
|
+
}
|
|
245
|
+
}));
|
|
246
|
+
},
|
|
247
|
+
setHover: (path, nestedIndex) => {
|
|
248
|
+
set({
|
|
249
|
+
hoverPath: path ? {
|
|
250
|
+
path,
|
|
251
|
+
nestedIndex
|
|
252
|
+
} : null
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
const JsonViewerStoreContext = createContext(void 0);
|
|
259
|
+
JsonViewerStoreContext.Provider;
|
|
260
|
+
const useJsonViewerStore = (selector, equalityFn) => {
|
|
261
|
+
const store = useContext(JsonViewerStoreContext);
|
|
262
|
+
return useStore(store, selector, equalityFn);
|
|
263
|
+
};
|
|
264
|
+
const useTextColor = () => {
|
|
265
|
+
return useJsonViewerStore((store) => store.colorspace.base07);
|
|
266
|
+
};
|
|
267
|
+
const objectCtorString = Object.prototype.constructor.toString();
|
|
268
|
+
function isPlainObject(value) {
|
|
269
|
+
if (!value || typeof value !== "object") return false;
|
|
270
|
+
const proto = Object.getPrototypeOf(value);
|
|
271
|
+
if (proto === null) return true;
|
|
272
|
+
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
273
|
+
if (Ctor === Object) return true;
|
|
274
|
+
return typeof Ctor === "function" && Function.toString.call(Ctor) === objectCtorString;
|
|
275
|
+
}
|
|
276
|
+
const isCycleReference = (root, path, value) => {
|
|
277
|
+
if (root === null || value === null) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
if (typeof root !== "object") {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
if (typeof value !== "object") {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
if (Object.is(root, value) && path.length !== 0) {
|
|
287
|
+
return "";
|
|
288
|
+
}
|
|
289
|
+
const currentPath = [];
|
|
290
|
+
const arr = [
|
|
291
|
+
...path
|
|
292
|
+
];
|
|
293
|
+
let currentRoot = root;
|
|
294
|
+
while (currentRoot !== value || arr.length !== 0) {
|
|
295
|
+
if (typeof currentRoot !== "object" || currentRoot === null) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
if (Object.is(currentRoot, value)) {
|
|
299
|
+
return currentPath.reduce((path2, value2, currentIndex) => {
|
|
300
|
+
if (typeof value2 === "number") {
|
|
301
|
+
return path2 + "[".concat(value2, "]");
|
|
302
|
+
}
|
|
303
|
+
return path2 + "".concat(currentIndex === 0 ? "" : ".").concat(value2);
|
|
304
|
+
}, "");
|
|
305
|
+
}
|
|
306
|
+
const target = arr.shift();
|
|
307
|
+
currentPath.push(target);
|
|
308
|
+
currentRoot = currentRoot[target];
|
|
309
|
+
}
|
|
310
|
+
return false;
|
|
311
|
+
};
|
|
312
|
+
function getValueSize(value) {
|
|
313
|
+
if (value === null || void 0) {
|
|
314
|
+
return 0;
|
|
315
|
+
} else if (Array.isArray(value)) {
|
|
316
|
+
return value.length;
|
|
317
|
+
} else if (value instanceof Map || value instanceof Set) {
|
|
318
|
+
return value.size;
|
|
319
|
+
} else if (value instanceof Date) {
|
|
320
|
+
return 1;
|
|
321
|
+
} else if (typeof value === "object") {
|
|
322
|
+
return Object.keys(value).length;
|
|
323
|
+
} else if (typeof value === "string") {
|
|
324
|
+
return value.length;
|
|
325
|
+
}
|
|
326
|
+
return 1;
|
|
327
|
+
}
|
|
328
|
+
function segmentArray(arr, size) {
|
|
329
|
+
const result = [];
|
|
330
|
+
let index = 0;
|
|
331
|
+
while (index < arr.length) {
|
|
332
|
+
result.push(arr.slice(index, index + size));
|
|
333
|
+
index += size;
|
|
334
|
+
}
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
function safeStringify(obj, space) {
|
|
338
|
+
const seenValues = [];
|
|
339
|
+
function replacer(key, value) {
|
|
340
|
+
if (typeof value === "bigint") return value.toString();
|
|
341
|
+
if (value instanceof Map) {
|
|
342
|
+
if ("toJSON" in value && typeof value.toJSON === "function") return value.toJSON();
|
|
343
|
+
if (value.size === 0) return {};
|
|
344
|
+
if (seenValues.includes(value)) return "[Circular]";
|
|
345
|
+
seenValues.push(value);
|
|
346
|
+
const entries = Array.from(value.entries());
|
|
347
|
+
if (entries.every((param) => {
|
|
348
|
+
let [key2] = param;
|
|
349
|
+
return typeof key2 === "string" || typeof key2 === "number";
|
|
350
|
+
})) {
|
|
351
|
+
return Object.fromEntries(entries);
|
|
352
|
+
}
|
|
353
|
+
return {};
|
|
354
|
+
}
|
|
355
|
+
if (value instanceof Set) {
|
|
356
|
+
if ("toJSON" in value && typeof value.toJSON === "function") return value.toJSON();
|
|
357
|
+
if (seenValues.includes(value)) return "[Circular]";
|
|
358
|
+
seenValues.push(value);
|
|
359
|
+
return Array.from(value.values());
|
|
360
|
+
}
|
|
361
|
+
if (typeof value === "object" && value !== null && Object.keys(value).length) {
|
|
362
|
+
const stackSize = seenValues.length;
|
|
363
|
+
if (stackSize) {
|
|
364
|
+
for (let n = stackSize - 1; n >= 0 && seenValues[n][key] !== value; --n) {
|
|
365
|
+
seenValues.pop();
|
|
366
|
+
}
|
|
367
|
+
if (seenValues.includes(value)) return "[Circular]";
|
|
368
|
+
}
|
|
369
|
+
seenValues.push(value);
|
|
370
|
+
}
|
|
371
|
+
return value;
|
|
372
|
+
}
|
|
373
|
+
return JSON.stringify(obj, replacer, space);
|
|
374
|
+
}
|
|
375
|
+
async function copyString(value) {
|
|
376
|
+
if ("clipboard" in navigator) {
|
|
377
|
+
try {
|
|
378
|
+
await navigator.clipboard.writeText(value);
|
|
379
|
+
} catch {
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
copyToClipboard(value);
|
|
383
|
+
}
|
|
384
|
+
function useClipboard() {
|
|
385
|
+
let { timeout = 2e3 } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
386
|
+
const [copied, setCopied] = useState(false);
|
|
387
|
+
const copyTimeout = useRef(null);
|
|
388
|
+
const handleCopyResult = useCallback((value) => {
|
|
389
|
+
const current = copyTimeout.current;
|
|
390
|
+
if (current) {
|
|
391
|
+
window.clearTimeout(current);
|
|
392
|
+
}
|
|
393
|
+
copyTimeout.current = window.setTimeout(() => setCopied(false), timeout);
|
|
394
|
+
setCopied(value);
|
|
395
|
+
}, [
|
|
396
|
+
timeout
|
|
397
|
+
]);
|
|
398
|
+
const onCopy = useJsonViewerStore((store) => store.onCopy);
|
|
399
|
+
const copy = useCallback(async (path, value) => {
|
|
400
|
+
if (typeof onCopy === "function") {
|
|
401
|
+
try {
|
|
402
|
+
await onCopy(path, value, copyString);
|
|
403
|
+
handleCopyResult(true);
|
|
404
|
+
} catch (error) {
|
|
405
|
+
console.error("error when copy ".concat(path.length === 0 ? "src" : "src[".concat(path.join(".")), "]"), error);
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
try {
|
|
409
|
+
const valueToCopy = safeStringify(typeof value === "function" ? value.toString() : value, " ");
|
|
410
|
+
await copyString(valueToCopy);
|
|
411
|
+
handleCopyResult(true);
|
|
412
|
+
} catch (error) {
|
|
413
|
+
console.error("error when copy ".concat(path.length === 0 ? "src" : "src[".concat(path.join(".")), "]"), error);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}, [
|
|
417
|
+
handleCopyResult,
|
|
418
|
+
onCopy
|
|
419
|
+
]);
|
|
420
|
+
const reset = useCallback(() => {
|
|
421
|
+
setCopied(false);
|
|
422
|
+
if (copyTimeout.current) {
|
|
423
|
+
clearTimeout(copyTimeout.current);
|
|
424
|
+
}
|
|
425
|
+
}, []);
|
|
426
|
+
return {
|
|
427
|
+
copy,
|
|
428
|
+
reset,
|
|
429
|
+
copied
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
function useIsCycleReference(path, value) {
|
|
433
|
+
const rootValue = useJsonViewerStore((store) => store.value);
|
|
434
|
+
return useMemo(() => isCycleReference(rootValue, path, value), [
|
|
435
|
+
path,
|
|
436
|
+
value,
|
|
437
|
+
rootValue
|
|
438
|
+
]);
|
|
439
|
+
}
|
|
440
|
+
function useInspect(path, value, nestedIndex) {
|
|
441
|
+
const depth = path.length;
|
|
442
|
+
const isTrap = useIsCycleReference(path, value);
|
|
443
|
+
const getInspectCache = useJsonViewerStore((store) => store.getInspectCache);
|
|
444
|
+
const setInspectCache = useJsonViewerStore((store) => store.setInspectCache);
|
|
445
|
+
const defaultInspectDepth = useJsonViewerStore((store) => store.defaultInspectDepth);
|
|
446
|
+
const defaultInspectControl = useJsonViewerStore((store) => store.defaultInspectControl);
|
|
447
|
+
useEffect(() => {
|
|
448
|
+
const inspect2 = getInspectCache(path, nestedIndex);
|
|
449
|
+
if (inspect2 !== void 0) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
if (nestedIndex !== void 0) {
|
|
453
|
+
setInspectCache(path, false, nestedIndex);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const shouldInspect = isTrap ? false : typeof defaultInspectControl === "function" ? defaultInspectControl(path, value) : depth < defaultInspectDepth;
|
|
457
|
+
setInspectCache(path, shouldInspect);
|
|
458
|
+
}, [
|
|
459
|
+
defaultInspectDepth,
|
|
460
|
+
defaultInspectControl,
|
|
461
|
+
depth,
|
|
462
|
+
getInspectCache,
|
|
463
|
+
isTrap,
|
|
464
|
+
nestedIndex,
|
|
465
|
+
path,
|
|
466
|
+
value,
|
|
467
|
+
setInspectCache
|
|
468
|
+
]);
|
|
469
|
+
const [inspect, set] = useState(() => {
|
|
470
|
+
const shouldInspect = getInspectCache(path, nestedIndex);
|
|
471
|
+
if (shouldInspect !== void 0) {
|
|
472
|
+
return shouldInspect;
|
|
473
|
+
}
|
|
474
|
+
if (nestedIndex !== void 0) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
return isTrap ? false : typeof defaultInspectControl === "function" ? defaultInspectControl(path, value) : depth < defaultInspectDepth;
|
|
478
|
+
});
|
|
479
|
+
const setInspect = useCallback((apply) => {
|
|
480
|
+
set((oldState) => {
|
|
481
|
+
const newState = typeof apply === "boolean" ? apply : apply(oldState);
|
|
482
|
+
setInspectCache(path, newState, nestedIndex);
|
|
483
|
+
return newState;
|
|
484
|
+
});
|
|
485
|
+
}, [
|
|
486
|
+
nestedIndex,
|
|
487
|
+
path,
|
|
488
|
+
setInspectCache
|
|
489
|
+
]);
|
|
490
|
+
return [
|
|
491
|
+
inspect,
|
|
492
|
+
setInspect
|
|
493
|
+
];
|
|
494
|
+
}
|
|
495
|
+
const DataBox = (props) => /* @__PURE__ */ jsx(Box, {
|
|
496
|
+
component: "div",
|
|
497
|
+
...props,
|
|
498
|
+
sx: {
|
|
499
|
+
display: "inline-block",
|
|
500
|
+
...props.sx
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
const DataTypeLabel = (param) => {
|
|
504
|
+
let { dataType, enable = true } = param;
|
|
505
|
+
if (!enable) return null;
|
|
506
|
+
return /* @__PURE__ */ jsx(DataBox, {
|
|
507
|
+
className: "data-type-label",
|
|
508
|
+
sx: {
|
|
509
|
+
mx: 0.5,
|
|
510
|
+
fontSize: "0.7rem",
|
|
511
|
+
opacity: 0.8,
|
|
512
|
+
userSelect: "none"
|
|
513
|
+
},
|
|
514
|
+
children: dataType
|
|
515
|
+
});
|
|
516
|
+
};
|
|
517
|
+
function defineEasyType(param) {
|
|
518
|
+
let { is, serialize, deserialize, type, colorKey, displayTypeLabel = true, Renderer } = param;
|
|
519
|
+
const Render = /* @__PURE__ */ memo(Renderer);
|
|
520
|
+
const EasyType = (props) => {
|
|
521
|
+
const storeDisplayDataTypes = useJsonViewerStore((store) => store.displayDataTypes);
|
|
522
|
+
const color = useJsonViewerStore((store) => store.colorspace[colorKey]);
|
|
523
|
+
const onSelect = useJsonViewerStore((store) => store.onSelect);
|
|
524
|
+
return /* @__PURE__ */ jsxs(DataBox, {
|
|
525
|
+
onClick: () => onSelect === null || onSelect === void 0 ? void 0 : onSelect(props.path, props.value),
|
|
526
|
+
sx: {
|
|
527
|
+
color
|
|
528
|
+
},
|
|
529
|
+
children: [
|
|
530
|
+
displayTypeLabel && storeDisplayDataTypes && /* @__PURE__ */ jsx(DataTypeLabel, {
|
|
531
|
+
dataType: type
|
|
532
|
+
}),
|
|
533
|
+
/* @__PURE__ */ jsx(DataBox, {
|
|
534
|
+
className: "".concat(type, "-value"),
|
|
535
|
+
children: /* @__PURE__ */ jsx(Render, {
|
|
536
|
+
path: props.path,
|
|
537
|
+
inspect: props.inspect,
|
|
538
|
+
setInspect: props.setInspect,
|
|
539
|
+
value: props.value,
|
|
540
|
+
prevValue: props.prevValue
|
|
541
|
+
})
|
|
542
|
+
})
|
|
543
|
+
]
|
|
544
|
+
});
|
|
545
|
+
};
|
|
546
|
+
EasyType.displayName = "easy-".concat(type, "-type");
|
|
547
|
+
if (!serialize || !deserialize) {
|
|
548
|
+
return {
|
|
549
|
+
is,
|
|
550
|
+
Component: EasyType
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
const EasyTypeEditor = (param2) => {
|
|
554
|
+
let { value, setValue, abortEditing, commitEditing } = param2;
|
|
555
|
+
const color = useJsonViewerStore((store) => store.colorspace[colorKey]);
|
|
556
|
+
const handleKeyDown = useCallback((event) => {
|
|
557
|
+
if (event.key === "Enter") {
|
|
558
|
+
event.preventDefault();
|
|
559
|
+
commitEditing(value);
|
|
560
|
+
}
|
|
561
|
+
if (event.key === "Escape") {
|
|
562
|
+
event.preventDefault();
|
|
563
|
+
abortEditing();
|
|
564
|
+
}
|
|
565
|
+
}, [
|
|
566
|
+
abortEditing,
|
|
567
|
+
commitEditing,
|
|
568
|
+
value
|
|
569
|
+
]);
|
|
570
|
+
const handleChange = useCallback((event) => {
|
|
571
|
+
setValue(event.target.value);
|
|
572
|
+
}, [
|
|
573
|
+
setValue
|
|
574
|
+
]);
|
|
575
|
+
return /* @__PURE__ */ jsx(InputBase, {
|
|
576
|
+
autoFocus: true,
|
|
577
|
+
value,
|
|
578
|
+
onChange: handleChange,
|
|
579
|
+
onKeyDown: handleKeyDown,
|
|
580
|
+
size: "small",
|
|
581
|
+
multiline: true,
|
|
582
|
+
sx: {
|
|
583
|
+
color,
|
|
584
|
+
padding: 0.5,
|
|
585
|
+
borderStyle: "solid",
|
|
586
|
+
borderColor: "black",
|
|
587
|
+
borderWidth: 1,
|
|
588
|
+
fontSize: "0.8rem",
|
|
589
|
+
fontFamily: "monospace",
|
|
590
|
+
display: "inline-flex"
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
};
|
|
594
|
+
EasyTypeEditor.displayName = "easy-".concat(type, "-type-editor");
|
|
595
|
+
return {
|
|
596
|
+
is,
|
|
597
|
+
serialize,
|
|
598
|
+
deserialize,
|
|
599
|
+
Component: EasyType,
|
|
600
|
+
Editor: EasyTypeEditor
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
const booleanType = defineEasyType({
|
|
604
|
+
is: (value) => typeof value === "boolean",
|
|
605
|
+
type: "bool",
|
|
606
|
+
colorKey: "base0E",
|
|
607
|
+
serialize: (value) => value.toString(),
|
|
608
|
+
deserialize: (value) => {
|
|
609
|
+
if (value === "true") return true;
|
|
610
|
+
if (value === "false") return false;
|
|
611
|
+
throw new Error("Invalid boolean value");
|
|
612
|
+
},
|
|
613
|
+
Renderer: (param) => {
|
|
614
|
+
let { value } = param;
|
|
615
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
616
|
+
children: value ? "true" : "false"
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
const displayOptions = {
|
|
621
|
+
weekday: "short",
|
|
622
|
+
year: "numeric",
|
|
623
|
+
month: "short",
|
|
624
|
+
day: "numeric",
|
|
625
|
+
hour: "2-digit",
|
|
626
|
+
minute: "2-digit"
|
|
627
|
+
};
|
|
628
|
+
const dateType = defineEasyType({
|
|
629
|
+
is: (value) => value instanceof Date,
|
|
630
|
+
type: "date",
|
|
631
|
+
colorKey: "base0D",
|
|
632
|
+
Renderer: (param) => {
|
|
633
|
+
let { value } = param;
|
|
634
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
635
|
+
children: value.toLocaleTimeString("en-us", displayOptions)
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
const functionBody = (func) => {
|
|
640
|
+
const funcString = func.toString();
|
|
641
|
+
let isUsualFunction = true;
|
|
642
|
+
const parenthesisPos = funcString.indexOf(")");
|
|
643
|
+
const arrowPos = funcString.indexOf("=>");
|
|
644
|
+
if (arrowPos !== -1 && arrowPos > parenthesisPos) {
|
|
645
|
+
isUsualFunction = false;
|
|
646
|
+
}
|
|
647
|
+
if (isUsualFunction) {
|
|
648
|
+
return funcString.substring(funcString.indexOf("{", parenthesisPos) + 1, funcString.lastIndexOf("}"));
|
|
649
|
+
}
|
|
650
|
+
return funcString.substring(funcString.indexOf("=>") + 2);
|
|
651
|
+
};
|
|
652
|
+
const functionName = (func) => {
|
|
653
|
+
const funcString = func.toString();
|
|
654
|
+
const isUsualFunction = funcString.indexOf("function") !== -1;
|
|
655
|
+
if (isUsualFunction) {
|
|
656
|
+
return funcString.substring(8, funcString.indexOf("{")).trim();
|
|
657
|
+
}
|
|
658
|
+
return funcString.substring(0, funcString.indexOf("=>") + 2).trim();
|
|
659
|
+
};
|
|
660
|
+
const lb = "{";
|
|
661
|
+
const rb = "}";
|
|
662
|
+
const PreFunctionType = (props) => {
|
|
663
|
+
return /* @__PURE__ */ jsxs(NoSsr, {
|
|
664
|
+
children: [
|
|
665
|
+
/* @__PURE__ */ jsx(DataTypeLabel, {
|
|
666
|
+
dataType: "function"
|
|
667
|
+
}),
|
|
668
|
+
/* @__PURE__ */ jsxs(Box, {
|
|
669
|
+
component: "span",
|
|
670
|
+
className: "data-function-start",
|
|
671
|
+
sx: {
|
|
672
|
+
letterSpacing: 0.5
|
|
673
|
+
},
|
|
674
|
+
children: [
|
|
675
|
+
functionName(props.value),
|
|
676
|
+
" ",
|
|
677
|
+
lb
|
|
678
|
+
]
|
|
679
|
+
})
|
|
680
|
+
]
|
|
681
|
+
});
|
|
682
|
+
};
|
|
683
|
+
const PostFunctionType = () => {
|
|
684
|
+
return /* @__PURE__ */ jsx(NoSsr, {
|
|
685
|
+
children: /* @__PURE__ */ jsx(Box, {
|
|
686
|
+
component: "span",
|
|
687
|
+
className: "data-function-end",
|
|
688
|
+
children: rb
|
|
689
|
+
})
|
|
690
|
+
});
|
|
691
|
+
};
|
|
692
|
+
const FunctionType = (props) => {
|
|
693
|
+
const functionColor = useJsonViewerStore((store) => store.colorspace.base05);
|
|
694
|
+
return /* @__PURE__ */ jsx(NoSsr, {
|
|
695
|
+
children: /* @__PURE__ */ jsx(Box, {
|
|
696
|
+
className: "data-function",
|
|
697
|
+
sx: {
|
|
698
|
+
display: props.inspect ? "block" : "inline-block",
|
|
699
|
+
pl: props.inspect ? 2 : 0,
|
|
700
|
+
color: functionColor
|
|
701
|
+
},
|
|
702
|
+
children: props.inspect ? functionBody(props.value) : /* @__PURE__ */ jsx(Box, {
|
|
703
|
+
component: "span",
|
|
704
|
+
className: "data-function-body",
|
|
705
|
+
onClick: () => props.setInspect(true),
|
|
706
|
+
sx: {
|
|
707
|
+
"&:hover": {
|
|
708
|
+
cursor: "pointer"
|
|
709
|
+
},
|
|
710
|
+
padding: 0.5
|
|
711
|
+
},
|
|
712
|
+
children: "…"
|
|
713
|
+
})
|
|
714
|
+
})
|
|
715
|
+
});
|
|
716
|
+
};
|
|
717
|
+
const functionType = {
|
|
718
|
+
is: (value) => typeof value === "function",
|
|
719
|
+
Component: FunctionType,
|
|
720
|
+
PreComponent: PreFunctionType,
|
|
721
|
+
PostComponent: PostFunctionType
|
|
722
|
+
};
|
|
723
|
+
const nullType = defineEasyType({
|
|
724
|
+
is: (value) => value === null,
|
|
725
|
+
type: "null",
|
|
726
|
+
colorKey: "base08",
|
|
727
|
+
displayTypeLabel: false,
|
|
728
|
+
Renderer: () => {
|
|
729
|
+
const backgroundColor = useJsonViewerStore((store) => store.colorspace.base02);
|
|
730
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
731
|
+
sx: {
|
|
732
|
+
fontSize: "0.8rem",
|
|
733
|
+
backgroundColor,
|
|
734
|
+
fontWeight: "bold",
|
|
735
|
+
borderRadius: "3px",
|
|
736
|
+
padding: "0.5px 2px"
|
|
737
|
+
},
|
|
738
|
+
children: "NULL"
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
const isInt = (n) => n % 1 === 0;
|
|
743
|
+
const nanType = defineEasyType({
|
|
744
|
+
is: (value) => typeof value === "number" && isNaN(value),
|
|
745
|
+
type: "NaN",
|
|
746
|
+
colorKey: "base08",
|
|
747
|
+
displayTypeLabel: false,
|
|
748
|
+
serialize: () => "NaN",
|
|
749
|
+
// allow deserialize the value back to number
|
|
750
|
+
deserialize: (value) => parseFloat(value),
|
|
751
|
+
Renderer: () => {
|
|
752
|
+
const backgroundColor = useJsonViewerStore((store) => store.colorspace.base02);
|
|
753
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
754
|
+
sx: {
|
|
755
|
+
backgroundColor,
|
|
756
|
+
fontSize: "0.8rem",
|
|
757
|
+
fontWeight: "bold",
|
|
758
|
+
borderRadius: "3px",
|
|
759
|
+
padding: "0.5px 2px"
|
|
760
|
+
},
|
|
761
|
+
children: "NaN"
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
const floatType = defineEasyType({
|
|
766
|
+
is: (value) => typeof value === "number" && !isInt(value) && !isNaN(value),
|
|
767
|
+
type: "float",
|
|
768
|
+
colorKey: "base0B",
|
|
769
|
+
serialize: (value) => value.toString(),
|
|
770
|
+
deserialize: (value) => parseFloat(value),
|
|
771
|
+
Renderer: (param) => {
|
|
772
|
+
let { value } = param;
|
|
773
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
774
|
+
children: value
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
const intType = defineEasyType({
|
|
779
|
+
is: (value) => typeof value === "number" && isInt(value),
|
|
780
|
+
type: "int",
|
|
781
|
+
colorKey: "base0F",
|
|
782
|
+
serialize: (value) => value.toString(),
|
|
783
|
+
// allow deserialize the value to float
|
|
784
|
+
deserialize: (value) => parseFloat(value),
|
|
785
|
+
Renderer: (param) => {
|
|
786
|
+
let { value } = param;
|
|
787
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
788
|
+
children: value
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
const bigIntType = defineEasyType({
|
|
793
|
+
is: (value) => typeof value === "bigint",
|
|
794
|
+
type: "bigint",
|
|
795
|
+
colorKey: "base0F",
|
|
796
|
+
serialize: (value) => value.toString(),
|
|
797
|
+
deserialize: (value) => BigInt(value.replace(/\D/g, "")),
|
|
798
|
+
Renderer: (param) => {
|
|
799
|
+
let { value } = param;
|
|
800
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
801
|
+
children: "".concat(value, "n")
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
const BaseIcon = (param) => {
|
|
806
|
+
let { d, ...props } = param;
|
|
807
|
+
return /* @__PURE__ */ jsx(SvgIcon, {
|
|
808
|
+
...props,
|
|
809
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
810
|
+
d
|
|
811
|
+
})
|
|
812
|
+
});
|
|
813
|
+
};
|
|
814
|
+
const AddBox = "M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2m0 16H5V5h14zm-8-2h2v-4h4v-2h-4V7h-2v4H7v2h4z";
|
|
815
|
+
const Check = "M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z";
|
|
816
|
+
const ChevronRight = "M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z";
|
|
817
|
+
const CircularArrows = "M 12 2 C 10.615 1.998 9.214625 2.2867656 7.890625 2.8847656 L 8.9003906 4.6328125 C 9.9043906 4.2098125 10.957 3.998 12 4 C 15.080783 4 17.738521 5.7633175 19.074219 8.3222656 L 17.125 9 L 21.25 11 L 22.875 7 L 20.998047 7.6523438 C 19.377701 4.3110398 15.95585 2 12 2 z M 6.5097656 4.4882812 L 2.2324219 5.0820312 L 3.734375 6.3808594 C 1.6515335 9.4550558 1.3615962 13.574578 3.3398438 17 C 4.0308437 18.201 4.9801562 19.268234 6.1601562 20.115234 L 7.1699219 18.367188 C 6.3019219 17.710187 5.5922656 16.904 5.0722656 16 C 3.5320014 13.332354 3.729203 10.148679 5.2773438 7.7128906 L 6.8398438 9.0625 L 6.5097656 4.4882812 z M 19.929688 13 C 19.794687 14.08 19.450734 15.098 18.927734 16 C 17.386985 18.668487 14.531361 20.090637 11.646484 19.966797 L 12.035156 17.9375 L 8.2402344 20.511719 L 10.892578 23.917969 L 11.265625 21.966797 C 14.968963 22.233766 18.681899 20.426323 20.660156 17 C 21.355156 15.801 21.805219 14.445 21.949219 13 L 19.929688 13 z";
|
|
818
|
+
const Close = "M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z";
|
|
819
|
+
const ContentCopy = "M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z";
|
|
820
|
+
const Edit = "M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34a.9959.9959 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z";
|
|
821
|
+
const ExpandMore = "M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z";
|
|
822
|
+
const Delete = "M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6zM8 9h8v10H8zm7.5-5l-1-1h-5l-1 1H5v2h14V4z";
|
|
823
|
+
const AddBoxIcon = (props) => {
|
|
824
|
+
return /* @__PURE__ */ jsx(BaseIcon, {
|
|
825
|
+
d: AddBox,
|
|
826
|
+
...props
|
|
827
|
+
});
|
|
828
|
+
};
|
|
829
|
+
const CheckIcon = (props) => {
|
|
830
|
+
return /* @__PURE__ */ jsx(BaseIcon, {
|
|
831
|
+
d: Check,
|
|
832
|
+
...props
|
|
833
|
+
});
|
|
834
|
+
};
|
|
835
|
+
const ChevronRightIcon = (props) => {
|
|
836
|
+
return /* @__PURE__ */ jsx(BaseIcon, {
|
|
837
|
+
d: ChevronRight,
|
|
838
|
+
...props
|
|
839
|
+
});
|
|
840
|
+
};
|
|
841
|
+
const CircularArrowsIcon = (props) => {
|
|
842
|
+
return /* @__PURE__ */ jsx(BaseIcon, {
|
|
843
|
+
d: CircularArrows,
|
|
844
|
+
...props
|
|
845
|
+
});
|
|
846
|
+
};
|
|
847
|
+
const CloseIcon = (props) => {
|
|
848
|
+
return /* @__PURE__ */ jsx(BaseIcon, {
|
|
849
|
+
d: Close,
|
|
850
|
+
...props
|
|
851
|
+
});
|
|
852
|
+
};
|
|
853
|
+
const ContentCopyIcon = (props) => {
|
|
854
|
+
return /* @__PURE__ */ jsx(BaseIcon, {
|
|
855
|
+
d: ContentCopy,
|
|
856
|
+
...props
|
|
857
|
+
});
|
|
858
|
+
};
|
|
859
|
+
const EditIcon = (props) => {
|
|
860
|
+
return /* @__PURE__ */ jsx(BaseIcon, {
|
|
861
|
+
d: Edit,
|
|
862
|
+
...props
|
|
863
|
+
});
|
|
864
|
+
};
|
|
865
|
+
const ExpandMoreIcon = (props) => {
|
|
866
|
+
return /* @__PURE__ */ jsx(BaseIcon, {
|
|
867
|
+
d: ExpandMore,
|
|
868
|
+
...props
|
|
869
|
+
});
|
|
870
|
+
};
|
|
871
|
+
const DeleteIcon = (props) => {
|
|
872
|
+
return /* @__PURE__ */ jsx(BaseIcon, {
|
|
873
|
+
d: Delete,
|
|
874
|
+
...props
|
|
875
|
+
});
|
|
876
|
+
};
|
|
877
|
+
const objectLb = "{";
|
|
878
|
+
const arrayLb = "[";
|
|
879
|
+
const objectRb = "}";
|
|
880
|
+
const arrayRb = "]";
|
|
881
|
+
function inspectMetadata(value) {
|
|
882
|
+
const length = getValueSize(value);
|
|
883
|
+
let name = "";
|
|
884
|
+
if (value instanceof Map || value instanceof Set) {
|
|
885
|
+
name = value[Symbol.toStringTag];
|
|
886
|
+
}
|
|
887
|
+
if (Object.prototype.hasOwnProperty.call(value, Symbol.toStringTag)) {
|
|
888
|
+
name = value[Symbol.toStringTag];
|
|
889
|
+
}
|
|
890
|
+
const itemsPluralized = length === 1 ? "Item" : "Items";
|
|
891
|
+
return "".concat(length, " ").concat(itemsPluralized).concat(name ? " (".concat(name, ")") : "");
|
|
892
|
+
}
|
|
893
|
+
const PreObjectType = (props) => {
|
|
894
|
+
const metadataColor = useJsonViewerStore((store) => store.colorspace.base04);
|
|
895
|
+
const textColor = useTextColor();
|
|
896
|
+
const isArrayLike = useMemo(() => Array.isArray(props.value) || props.value instanceof Set, [
|
|
897
|
+
props.value
|
|
898
|
+
]);
|
|
899
|
+
const isEmptyValue = useMemo(() => getValueSize(props.value) === 0, [
|
|
900
|
+
props.value
|
|
901
|
+
]);
|
|
902
|
+
const sizeOfValue = useMemo(() => inspectMetadata(props.value), [
|
|
903
|
+
props.value
|
|
904
|
+
]);
|
|
905
|
+
const displaySize = useJsonViewerStore((store) => store.displaySize);
|
|
906
|
+
const shouldDisplaySize = useMemo(() => typeof displaySize === "function" ? displaySize(props.path, props.value) : displaySize, [
|
|
907
|
+
displaySize,
|
|
908
|
+
props.path,
|
|
909
|
+
props.value
|
|
910
|
+
]);
|
|
911
|
+
const isTrap = useIsCycleReference(props.path, props.value);
|
|
912
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
913
|
+
component: "span",
|
|
914
|
+
className: "data-object-start",
|
|
915
|
+
sx: {
|
|
916
|
+
letterSpacing: 0.5
|
|
917
|
+
},
|
|
918
|
+
children: [
|
|
919
|
+
isArrayLike ? arrayLb : objectLb,
|
|
920
|
+
shouldDisplaySize && props.inspect && !isEmptyValue && /* @__PURE__ */ jsx(Box, {
|
|
921
|
+
component: "span",
|
|
922
|
+
sx: {
|
|
923
|
+
pl: 0.5,
|
|
924
|
+
fontStyle: "italic",
|
|
925
|
+
color: metadataColor,
|
|
926
|
+
userSelect: "none"
|
|
927
|
+
},
|
|
928
|
+
children: sizeOfValue
|
|
929
|
+
}),
|
|
930
|
+
isTrap && !props.inspect && /* @__PURE__ */ jsxs(Fragment, {
|
|
931
|
+
children: [
|
|
932
|
+
/* @__PURE__ */ jsx(CircularArrowsIcon, {
|
|
933
|
+
sx: {
|
|
934
|
+
fontSize: 12,
|
|
935
|
+
color: textColor,
|
|
936
|
+
mx: 0.5
|
|
937
|
+
}
|
|
938
|
+
}),
|
|
939
|
+
/* @__PURE__ */ jsx(DataBox, {
|
|
940
|
+
sx: {
|
|
941
|
+
cursor: "pointer",
|
|
942
|
+
userSelect: "none"
|
|
943
|
+
},
|
|
944
|
+
children: isTrap
|
|
945
|
+
})
|
|
946
|
+
]
|
|
947
|
+
})
|
|
948
|
+
]
|
|
949
|
+
});
|
|
950
|
+
};
|
|
951
|
+
const PostObjectType = (props) => {
|
|
952
|
+
const metadataColor = useJsonViewerStore((store) => store.colorspace.base04);
|
|
953
|
+
const textColor = useTextColor();
|
|
954
|
+
const isArrayLike = useMemo(() => Array.isArray(props.value) || props.value instanceof Set, [
|
|
955
|
+
props.value
|
|
956
|
+
]);
|
|
957
|
+
const isEmptyValue = useMemo(() => getValueSize(props.value) === 0, [
|
|
958
|
+
props.value
|
|
959
|
+
]);
|
|
960
|
+
const sizeOfValue = useMemo(() => inspectMetadata(props.value), [
|
|
961
|
+
props.value
|
|
962
|
+
]);
|
|
963
|
+
const displaySize = useJsonViewerStore((store) => store.displaySize);
|
|
964
|
+
const shouldDisplaySize = useMemo(() => typeof displaySize === "function" ? displaySize(props.path, props.value) : displaySize, [
|
|
965
|
+
displaySize,
|
|
966
|
+
props.path,
|
|
967
|
+
props.value
|
|
968
|
+
]);
|
|
969
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
970
|
+
component: "span",
|
|
971
|
+
className: "data-object-end",
|
|
972
|
+
sx: {
|
|
973
|
+
lineHeight: 1.5,
|
|
974
|
+
color: textColor,
|
|
975
|
+
letterSpacing: 0.5,
|
|
976
|
+
opacity: 0.8
|
|
977
|
+
},
|
|
978
|
+
children: [
|
|
979
|
+
isArrayLike ? arrayRb : objectRb,
|
|
980
|
+
shouldDisplaySize && (isEmptyValue || !props.inspect) ? /* @__PURE__ */ jsx(Box, {
|
|
981
|
+
component: "span",
|
|
982
|
+
sx: {
|
|
983
|
+
pl: 0.5,
|
|
984
|
+
fontStyle: "italic",
|
|
985
|
+
color: metadataColor,
|
|
986
|
+
userSelect: "none"
|
|
987
|
+
},
|
|
988
|
+
children: sizeOfValue
|
|
989
|
+
}) : null
|
|
990
|
+
]
|
|
991
|
+
});
|
|
992
|
+
};
|
|
993
|
+
function getIterator(value) {
|
|
994
|
+
return typeof (value === null || value === void 0 ? void 0 : value[Symbol.iterator]) === "function";
|
|
995
|
+
}
|
|
996
|
+
const ObjectType = (props) => {
|
|
997
|
+
const keyColor = useTextColor();
|
|
998
|
+
const borderColor = useJsonViewerStore((store) => store.colorspace.base02);
|
|
999
|
+
const groupArraysAfterLength = useJsonViewerStore((store) => store.groupArraysAfterLength);
|
|
1000
|
+
const isTrap = useIsCycleReference(props.path, props.value);
|
|
1001
|
+
const [displayLength, setDisplayLength] = useState(useJsonViewerStore((store) => store.maxDisplayLength));
|
|
1002
|
+
const objectSortKeys = useJsonViewerStore((store) => store.objectSortKeys);
|
|
1003
|
+
const elements = useMemo(() => {
|
|
1004
|
+
if (!props.inspect) {
|
|
1005
|
+
return null;
|
|
1006
|
+
}
|
|
1007
|
+
const value = props.value;
|
|
1008
|
+
const iterator = getIterator(value);
|
|
1009
|
+
if (iterator && !Array.isArray(value)) {
|
|
1010
|
+
const elements3 = [];
|
|
1011
|
+
if (value instanceof Map) {
|
|
1012
|
+
const lastIndex2 = value.size - 1;
|
|
1013
|
+
let index = 0;
|
|
1014
|
+
value.forEach((value2, k) => {
|
|
1015
|
+
const key = k.toString();
|
|
1016
|
+
const path = [
|
|
1017
|
+
...props.path,
|
|
1018
|
+
key
|
|
1019
|
+
];
|
|
1020
|
+
elements3.push(/* @__PURE__ */ jsx(DataKeyPair, {
|
|
1021
|
+
path,
|
|
1022
|
+
value: value2,
|
|
1023
|
+
prevValue: props.prevValue instanceof Map ? props.prevValue.get(k) : void 0,
|
|
1024
|
+
editable: false,
|
|
1025
|
+
last: index === lastIndex2
|
|
1026
|
+
}, key));
|
|
1027
|
+
index++;
|
|
1028
|
+
});
|
|
1029
|
+
} else {
|
|
1030
|
+
const iterator2 = value[Symbol.iterator]();
|
|
1031
|
+
let result = iterator2.next();
|
|
1032
|
+
let count = 0;
|
|
1033
|
+
while (true) {
|
|
1034
|
+
const nextResult = iterator2.next();
|
|
1035
|
+
var _nextResult_done;
|
|
1036
|
+
elements3.push(/* @__PURE__ */ jsx(DataKeyPair, {
|
|
1037
|
+
path: [
|
|
1038
|
+
...props.path,
|
|
1039
|
+
"iterator:".concat(count)
|
|
1040
|
+
],
|
|
1041
|
+
value: result.value,
|
|
1042
|
+
nestedIndex: count,
|
|
1043
|
+
editable: false,
|
|
1044
|
+
last: (_nextResult_done = nextResult.done) !== null && _nextResult_done !== void 0 ? _nextResult_done : false
|
|
1045
|
+
}, count));
|
|
1046
|
+
if (nextResult.done) {
|
|
1047
|
+
break;
|
|
1048
|
+
}
|
|
1049
|
+
count++;
|
|
1050
|
+
result = nextResult;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
return elements3;
|
|
1054
|
+
}
|
|
1055
|
+
if (Array.isArray(value)) {
|
|
1056
|
+
const lastIndex2 = value.length - 1;
|
|
1057
|
+
if (value.length <= groupArraysAfterLength) {
|
|
1058
|
+
const elements4 = value.slice(0, displayLength).map((value2, _index) => {
|
|
1059
|
+
const index = props.nestedIndex ? props.nestedIndex * groupArraysAfterLength + _index : _index;
|
|
1060
|
+
const path = [
|
|
1061
|
+
...props.path,
|
|
1062
|
+
index
|
|
1063
|
+
];
|
|
1064
|
+
return /* @__PURE__ */ jsx(DataKeyPair, {
|
|
1065
|
+
path,
|
|
1066
|
+
value: value2,
|
|
1067
|
+
prevValue: Array.isArray(props.prevValue) ? props.prevValue[index] : void 0,
|
|
1068
|
+
last: _index === lastIndex2
|
|
1069
|
+
}, index);
|
|
1070
|
+
});
|
|
1071
|
+
if (value.length > displayLength) {
|
|
1072
|
+
const rest = value.length - displayLength;
|
|
1073
|
+
elements4.push(/* @__PURE__ */ jsxs(DataBox, {
|
|
1074
|
+
sx: {
|
|
1075
|
+
cursor: "pointer",
|
|
1076
|
+
lineHeight: 1.5,
|
|
1077
|
+
color: keyColor,
|
|
1078
|
+
letterSpacing: 0.5,
|
|
1079
|
+
opacity: 0.8,
|
|
1080
|
+
userSelect: "none"
|
|
1081
|
+
},
|
|
1082
|
+
onClick: () => setDisplayLength((length) => length * 2),
|
|
1083
|
+
children: [
|
|
1084
|
+
"hidden ",
|
|
1085
|
+
rest,
|
|
1086
|
+
" items…"
|
|
1087
|
+
]
|
|
1088
|
+
}, "last"));
|
|
1089
|
+
}
|
|
1090
|
+
return elements4;
|
|
1091
|
+
}
|
|
1092
|
+
const elements3 = segmentArray(value, groupArraysAfterLength);
|
|
1093
|
+
const prevElements = Array.isArray(props.prevValue) ? segmentArray(props.prevValue, groupArraysAfterLength) : void 0;
|
|
1094
|
+
const elementsLastIndex = elements3.length - 1;
|
|
1095
|
+
return elements3.map((list, index) => {
|
|
1096
|
+
return /* @__PURE__ */ jsx(DataKeyPair, {
|
|
1097
|
+
path: props.path,
|
|
1098
|
+
value: list,
|
|
1099
|
+
nestedIndex: index,
|
|
1100
|
+
prevValue: prevElements === null || prevElements === void 0 ? void 0 : prevElements[index],
|
|
1101
|
+
last: index === elementsLastIndex
|
|
1102
|
+
}, index);
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
let entries = Object.entries(value);
|
|
1106
|
+
if (objectSortKeys) {
|
|
1107
|
+
entries = objectSortKeys === true ? entries.sort((param, param1) => {
|
|
1108
|
+
let [a] = param, [b] = param1;
|
|
1109
|
+
return a.localeCompare(b);
|
|
1110
|
+
}) : entries.sort((param, param1) => {
|
|
1111
|
+
let [a] = param, [b] = param1;
|
|
1112
|
+
return objectSortKeys(a, b);
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
const lastIndex = entries.length - 1;
|
|
1116
|
+
const elements2 = entries.slice(0, displayLength).map((param, index) => {
|
|
1117
|
+
let [key, value2] = param;
|
|
1118
|
+
var _props_prevValue;
|
|
1119
|
+
const path = [
|
|
1120
|
+
...props.path,
|
|
1121
|
+
key
|
|
1122
|
+
];
|
|
1123
|
+
return /* @__PURE__ */ jsx(DataKeyPair, {
|
|
1124
|
+
path,
|
|
1125
|
+
value: value2,
|
|
1126
|
+
prevValue: (_props_prevValue = props.prevValue) === null || _props_prevValue === void 0 ? void 0 : _props_prevValue[key],
|
|
1127
|
+
last: index === lastIndex
|
|
1128
|
+
}, key);
|
|
1129
|
+
});
|
|
1130
|
+
if (entries.length > displayLength) {
|
|
1131
|
+
const rest = entries.length - displayLength;
|
|
1132
|
+
elements2.push(/* @__PURE__ */ jsxs(DataBox, {
|
|
1133
|
+
sx: {
|
|
1134
|
+
cursor: "pointer",
|
|
1135
|
+
lineHeight: 1.5,
|
|
1136
|
+
color: keyColor,
|
|
1137
|
+
letterSpacing: 0.5,
|
|
1138
|
+
opacity: 0.8,
|
|
1139
|
+
userSelect: "none"
|
|
1140
|
+
},
|
|
1141
|
+
onClick: () => setDisplayLength((length) => length * 2),
|
|
1142
|
+
children: [
|
|
1143
|
+
"hidden ",
|
|
1144
|
+
rest,
|
|
1145
|
+
" items…"
|
|
1146
|
+
]
|
|
1147
|
+
}, "last"));
|
|
1148
|
+
}
|
|
1149
|
+
return elements2;
|
|
1150
|
+
}, [
|
|
1151
|
+
props.inspect,
|
|
1152
|
+
props.value,
|
|
1153
|
+
props.prevValue,
|
|
1154
|
+
props.path,
|
|
1155
|
+
props.nestedIndex,
|
|
1156
|
+
groupArraysAfterLength,
|
|
1157
|
+
displayLength,
|
|
1158
|
+
keyColor,
|
|
1159
|
+
objectSortKeys
|
|
1160
|
+
]);
|
|
1161
|
+
const marginLeft = props.inspect ? 0.6 : 0;
|
|
1162
|
+
const width = useJsonViewerStore((store) => store.indentWidth);
|
|
1163
|
+
const indentWidth = props.inspect ? width - marginLeft : width;
|
|
1164
|
+
const isEmptyValue = useMemo(() => getValueSize(props.value) === 0, [
|
|
1165
|
+
props.value
|
|
1166
|
+
]);
|
|
1167
|
+
if (isEmptyValue) {
|
|
1168
|
+
return null;
|
|
1169
|
+
}
|
|
1170
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1171
|
+
className: "data-object",
|
|
1172
|
+
sx: {
|
|
1173
|
+
display: props.inspect ? "block" : "inline-block",
|
|
1174
|
+
pl: props.inspect ? indentWidth - 0.6 : 0,
|
|
1175
|
+
marginLeft,
|
|
1176
|
+
color: keyColor,
|
|
1177
|
+
borderLeft: props.inspect ? "1px solid ".concat(borderColor) : "none"
|
|
1178
|
+
},
|
|
1179
|
+
children: props.inspect ? elements : !isTrap && /* @__PURE__ */ jsx(Box, {
|
|
1180
|
+
component: "span",
|
|
1181
|
+
className: "data-object-body",
|
|
1182
|
+
onClick: () => props.setInspect(true),
|
|
1183
|
+
sx: {
|
|
1184
|
+
"&:hover": {
|
|
1185
|
+
cursor: "pointer"
|
|
1186
|
+
},
|
|
1187
|
+
padding: 0.5,
|
|
1188
|
+
userSelect: "none"
|
|
1189
|
+
},
|
|
1190
|
+
children: "…"
|
|
1191
|
+
})
|
|
1192
|
+
});
|
|
1193
|
+
};
|
|
1194
|
+
const objectType = {
|
|
1195
|
+
is: (value) => typeof value === "object",
|
|
1196
|
+
Component: ObjectType,
|
|
1197
|
+
PreComponent: PreObjectType,
|
|
1198
|
+
PostComponent: PostObjectType
|
|
1199
|
+
};
|
|
1200
|
+
const stringType = defineEasyType({
|
|
1201
|
+
is: (value) => typeof value === "string",
|
|
1202
|
+
type: "string",
|
|
1203
|
+
colorKey: "base09",
|
|
1204
|
+
serialize: (value) => value,
|
|
1205
|
+
deserialize: (value) => value,
|
|
1206
|
+
Renderer: (props) => {
|
|
1207
|
+
const [showRest, setShowRest] = useState(false);
|
|
1208
|
+
const collapseStringsAfterLength = useJsonViewerStore((store) => store.collapseStringsAfterLength);
|
|
1209
|
+
const value = showRest ? props.value : props.value.slice(0, collapseStringsAfterLength);
|
|
1210
|
+
const hasRest = props.value.length > collapseStringsAfterLength;
|
|
1211
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
1212
|
+
component: "span",
|
|
1213
|
+
sx: {
|
|
1214
|
+
overflowWrap: "anywhere",
|
|
1215
|
+
cursor: hasRest ? "pointer" : "inherit"
|
|
1216
|
+
},
|
|
1217
|
+
onClick: () => {
|
|
1218
|
+
var _window_getSelection;
|
|
1219
|
+
if (((_window_getSelection = window.getSelection()) === null || _window_getSelection === void 0 ? void 0 : _window_getSelection.type) === "Range") {
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
if (hasRest) {
|
|
1223
|
+
setShowRest((value2) => !value2);
|
|
1224
|
+
}
|
|
1225
|
+
},
|
|
1226
|
+
children: [
|
|
1227
|
+
'"',
|
|
1228
|
+
value,
|
|
1229
|
+
hasRest && !showRest && /* @__PURE__ */ jsx(Box, {
|
|
1230
|
+
component: "span",
|
|
1231
|
+
sx: {
|
|
1232
|
+
padding: 0.5
|
|
1233
|
+
},
|
|
1234
|
+
children: "…"
|
|
1235
|
+
}),
|
|
1236
|
+
'"'
|
|
1237
|
+
]
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
const undefinedType = defineEasyType({
|
|
1242
|
+
is: (value) => value === void 0,
|
|
1243
|
+
type: "undefined",
|
|
1244
|
+
colorKey: "base05",
|
|
1245
|
+
displayTypeLabel: false,
|
|
1246
|
+
Renderer: () => {
|
|
1247
|
+
const backgroundColor = useJsonViewerStore((store) => store.colorspace.base02);
|
|
1248
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1249
|
+
sx: {
|
|
1250
|
+
fontSize: "0.7rem",
|
|
1251
|
+
backgroundColor,
|
|
1252
|
+
borderRadius: "3px",
|
|
1253
|
+
padding: "0.5px 2px"
|
|
1254
|
+
},
|
|
1255
|
+
children: "undefined"
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
function memorizeDataType(dataType) {
|
|
1260
|
+
function compare(prevProps, nextProps) {
|
|
1261
|
+
var _prevProps_path, _nextProps_path;
|
|
1262
|
+
return Object.is(prevProps.value, nextProps.value) && prevProps.inspect && nextProps.inspect && ((_prevProps_path = prevProps.path) === null || _prevProps_path === void 0 ? void 0 : _prevProps_path.join(".")) === ((_nextProps_path = nextProps.path) === null || _nextProps_path === void 0 ? void 0 : _nextProps_path.join("."));
|
|
1263
|
+
}
|
|
1264
|
+
dataType.Component = /* @__PURE__ */ memo(dataType.Component, compare);
|
|
1265
|
+
if (dataType.Editor) {
|
|
1266
|
+
dataType.Editor = /* @__PURE__ */ memo(dataType.Editor, function compare2(prevProps, nextProps) {
|
|
1267
|
+
return Object.is(prevProps.value, nextProps.value);
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
if (dataType.PreComponent) {
|
|
1271
|
+
dataType.PreComponent = /* @__PURE__ */ memo(dataType.PreComponent, compare);
|
|
1272
|
+
}
|
|
1273
|
+
if (dataType.PostComponent) {
|
|
1274
|
+
dataType.PostComponent = /* @__PURE__ */ memo(dataType.PostComponent, compare);
|
|
1275
|
+
}
|
|
1276
|
+
return dataType;
|
|
1277
|
+
}
|
|
1278
|
+
const predefinedTypes = [
|
|
1279
|
+
memorizeDataType(booleanType),
|
|
1280
|
+
memorizeDataType(dateType),
|
|
1281
|
+
memorizeDataType(nullType),
|
|
1282
|
+
memorizeDataType(undefinedType),
|
|
1283
|
+
memorizeDataType(stringType),
|
|
1284
|
+
memorizeDataType(functionType),
|
|
1285
|
+
memorizeDataType(nanType),
|
|
1286
|
+
memorizeDataType(intType),
|
|
1287
|
+
memorizeDataType(floatType),
|
|
1288
|
+
memorizeDataType(bigIntType)
|
|
1289
|
+
];
|
|
1290
|
+
const createTypeRegistryStore = () => {
|
|
1291
|
+
return createStore()((set) => ({
|
|
1292
|
+
registry: predefinedTypes,
|
|
1293
|
+
registerTypes: (setState) => {
|
|
1294
|
+
set((state) => ({
|
|
1295
|
+
registry: typeof setState === "function" ? setState(state.registry) : setState
|
|
1296
|
+
}));
|
|
1297
|
+
}
|
|
1298
|
+
}));
|
|
1299
|
+
};
|
|
1300
|
+
const TypeRegistryStoreContext = /* @__PURE__ */ createContext(void 0);
|
|
1301
|
+
TypeRegistryStoreContext.Provider;
|
|
1302
|
+
const useTypeRegistryStore = (selector, equalityFn) => {
|
|
1303
|
+
const store = useContext(TypeRegistryStoreContext);
|
|
1304
|
+
return useStore(store, selector, equalityFn);
|
|
1305
|
+
};
|
|
1306
|
+
function matchTypeComponents(value, path, registry) {
|
|
1307
|
+
let potential;
|
|
1308
|
+
for (const T of registry) {
|
|
1309
|
+
if (T.is(value, path)) {
|
|
1310
|
+
potential = T;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
if (potential === void 0) {
|
|
1314
|
+
if (typeof value === "object") {
|
|
1315
|
+
return objectType;
|
|
1316
|
+
}
|
|
1317
|
+
throw new Error("No type matched for value: ".concat(value));
|
|
1318
|
+
}
|
|
1319
|
+
return potential;
|
|
1320
|
+
}
|
|
1321
|
+
function useTypeComponents(value, path) {
|
|
1322
|
+
const registry = useTypeRegistryStore((store) => store.registry);
|
|
1323
|
+
return useMemo(() => matchTypeComponents(value, path, registry), [
|
|
1324
|
+
value,
|
|
1325
|
+
path,
|
|
1326
|
+
registry
|
|
1327
|
+
]);
|
|
1328
|
+
}
|
|
1329
|
+
const IconBox = (props) => /* @__PURE__ */ jsx(Box, {
|
|
1330
|
+
component: "span",
|
|
1331
|
+
...props,
|
|
1332
|
+
sx: {
|
|
1333
|
+
cursor: "pointer",
|
|
1334
|
+
paddingLeft: "0.7rem",
|
|
1335
|
+
...props.sx
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1338
|
+
const DataKeyPair = (props) => {
|
|
1339
|
+
const { value, prevValue, path, nestedIndex, last } = props;
|
|
1340
|
+
const { Component, PreComponent, PostComponent, Editor, serialize, deserialize } = useTypeComponents(value, path);
|
|
1341
|
+
var _props_editable;
|
|
1342
|
+
const propsEditable = (_props_editable = props.editable) !== null && _props_editable !== void 0 ? _props_editable : void 0;
|
|
1343
|
+
const storeEditable = useJsonViewerStore((store) => store.editable);
|
|
1344
|
+
const editable = useMemo(() => {
|
|
1345
|
+
if (storeEditable === false) {
|
|
1346
|
+
return false;
|
|
1347
|
+
}
|
|
1348
|
+
if (propsEditable === false) {
|
|
1349
|
+
return false;
|
|
1350
|
+
}
|
|
1351
|
+
if (typeof storeEditable === "function") {
|
|
1352
|
+
return !!storeEditable(path, value);
|
|
1353
|
+
}
|
|
1354
|
+
return storeEditable;
|
|
1355
|
+
}, [
|
|
1356
|
+
path,
|
|
1357
|
+
propsEditable,
|
|
1358
|
+
storeEditable,
|
|
1359
|
+
value
|
|
1360
|
+
]);
|
|
1361
|
+
const [tempValue, setTempValue] = useState("");
|
|
1362
|
+
const depth = path.length;
|
|
1363
|
+
const key = path[depth - 1];
|
|
1364
|
+
const hoverPath = useJsonViewerStore((store) => store.hoverPath);
|
|
1365
|
+
const isHover = useMemo(() => {
|
|
1366
|
+
return hoverPath && path.every((value2, index) => value2 === hoverPath.path[index] && nestedIndex === hoverPath.nestedIndex);
|
|
1367
|
+
}, [
|
|
1368
|
+
hoverPath,
|
|
1369
|
+
path,
|
|
1370
|
+
nestedIndex
|
|
1371
|
+
]);
|
|
1372
|
+
const setHover = useJsonViewerStore((store) => store.setHover);
|
|
1373
|
+
const root = useJsonViewerStore((store) => store.value);
|
|
1374
|
+
const [inspect, setInspect] = useInspect(path, value, nestedIndex);
|
|
1375
|
+
const [editing, setEditing] = useState(false);
|
|
1376
|
+
const onChange = useJsonViewerStore((store) => store.onChange);
|
|
1377
|
+
const keyColor = useTextColor();
|
|
1378
|
+
const numberKeyColor = useJsonViewerStore((store) => store.colorspace.base0C);
|
|
1379
|
+
const highlightColor = useJsonViewerStore((store) => store.colorspace.base0A);
|
|
1380
|
+
const displayComma = useJsonViewerStore((store) => store.displayComma);
|
|
1381
|
+
const quotesOnKeys = useJsonViewerStore((store) => store.quotesOnKeys);
|
|
1382
|
+
const rootName = useJsonViewerStore((store) => store.rootName);
|
|
1383
|
+
const isRoot = root === value;
|
|
1384
|
+
const isNumberKey = Number.isInteger(Number(key));
|
|
1385
|
+
const storeEnableAdd = useJsonViewerStore((store) => store.enableAdd);
|
|
1386
|
+
const onAdd = useJsonViewerStore((store) => store.onAdd);
|
|
1387
|
+
const enableAdd = useMemo(() => {
|
|
1388
|
+
if (!onAdd || nestedIndex !== void 0) return false;
|
|
1389
|
+
if (storeEnableAdd === false) {
|
|
1390
|
+
return false;
|
|
1391
|
+
}
|
|
1392
|
+
if (propsEditable === false) {
|
|
1393
|
+
return false;
|
|
1394
|
+
}
|
|
1395
|
+
if (typeof storeEnableAdd === "function") {
|
|
1396
|
+
return !!storeEnableAdd(path, value);
|
|
1397
|
+
}
|
|
1398
|
+
if (Array.isArray(value) || isPlainObject(value)) {
|
|
1399
|
+
return true;
|
|
1400
|
+
}
|
|
1401
|
+
return false;
|
|
1402
|
+
}, [
|
|
1403
|
+
onAdd,
|
|
1404
|
+
nestedIndex,
|
|
1405
|
+
path,
|
|
1406
|
+
storeEnableAdd,
|
|
1407
|
+
propsEditable,
|
|
1408
|
+
value
|
|
1409
|
+
]);
|
|
1410
|
+
const storeEnableDelete = useJsonViewerStore((store) => store.enableDelete);
|
|
1411
|
+
const onDelete = useJsonViewerStore((store) => store.onDelete);
|
|
1412
|
+
const enableDelete = useMemo(() => {
|
|
1413
|
+
if (!onDelete || nestedIndex !== void 0) return false;
|
|
1414
|
+
if (isRoot) {
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
if (storeEnableDelete === false) {
|
|
1418
|
+
return false;
|
|
1419
|
+
}
|
|
1420
|
+
if (propsEditable === false) {
|
|
1421
|
+
return false;
|
|
1422
|
+
}
|
|
1423
|
+
if (typeof storeEnableDelete === "function") {
|
|
1424
|
+
return !!storeEnableDelete(path, value);
|
|
1425
|
+
}
|
|
1426
|
+
return storeEnableDelete;
|
|
1427
|
+
}, [
|
|
1428
|
+
onDelete,
|
|
1429
|
+
nestedIndex,
|
|
1430
|
+
isRoot,
|
|
1431
|
+
path,
|
|
1432
|
+
storeEnableDelete,
|
|
1433
|
+
propsEditable,
|
|
1434
|
+
value
|
|
1435
|
+
]);
|
|
1436
|
+
const enableClipboard = useJsonViewerStore((store) => store.enableClipboard);
|
|
1437
|
+
const { copy, copied } = useClipboard();
|
|
1438
|
+
const highlightUpdates = useJsonViewerStore((store) => store.highlightUpdates);
|
|
1439
|
+
const isHighlight = useMemo(() => {
|
|
1440
|
+
if (!highlightUpdates || prevValue === void 0) return false;
|
|
1441
|
+
if (typeof value !== typeof prevValue) {
|
|
1442
|
+
return true;
|
|
1443
|
+
}
|
|
1444
|
+
if (typeof value === "number") {
|
|
1445
|
+
if (isNaN(value) && isNaN(prevValue)) return false;
|
|
1446
|
+
return value !== prevValue;
|
|
1447
|
+
}
|
|
1448
|
+
if (Array.isArray(value) !== Array.isArray(prevValue)) {
|
|
1449
|
+
return true;
|
|
1450
|
+
}
|
|
1451
|
+
if (typeof value === "object" || typeof value === "function") {
|
|
1452
|
+
return false;
|
|
1453
|
+
}
|
|
1454
|
+
if (value !== prevValue) {
|
|
1455
|
+
return true;
|
|
1456
|
+
}
|
|
1457
|
+
return false;
|
|
1458
|
+
}, [
|
|
1459
|
+
highlightUpdates,
|
|
1460
|
+
prevValue,
|
|
1461
|
+
value
|
|
1462
|
+
]);
|
|
1463
|
+
const highlightContainer = useRef();
|
|
1464
|
+
useEffect(() => {
|
|
1465
|
+
if (highlightContainer.current && isHighlight && "animate" in highlightContainer.current) {
|
|
1466
|
+
highlightContainer.current.animate([
|
|
1467
|
+
{
|
|
1468
|
+
backgroundColor: highlightColor
|
|
1469
|
+
},
|
|
1470
|
+
{
|
|
1471
|
+
backgroundColor: ""
|
|
1472
|
+
}
|
|
1473
|
+
], {
|
|
1474
|
+
duration: 1e3,
|
|
1475
|
+
easing: "ease-in"
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
}, [
|
|
1479
|
+
highlightColor,
|
|
1480
|
+
isHighlight,
|
|
1481
|
+
prevValue,
|
|
1482
|
+
value
|
|
1483
|
+
]);
|
|
1484
|
+
const startEditing = useCallback((event) => {
|
|
1485
|
+
event.preventDefault();
|
|
1486
|
+
if (serialize) setTempValue(serialize(value));
|
|
1487
|
+
setEditing(true);
|
|
1488
|
+
}, [
|
|
1489
|
+
serialize,
|
|
1490
|
+
value
|
|
1491
|
+
]);
|
|
1492
|
+
const abortEditing = useCallback(() => {
|
|
1493
|
+
setEditing(false);
|
|
1494
|
+
setTempValue("");
|
|
1495
|
+
}, [
|
|
1496
|
+
setEditing,
|
|
1497
|
+
setTempValue
|
|
1498
|
+
]);
|
|
1499
|
+
const commitEditing = useCallback((newValue) => {
|
|
1500
|
+
setEditing(false);
|
|
1501
|
+
if (!deserialize) return;
|
|
1502
|
+
try {
|
|
1503
|
+
onChange(path, value, deserialize(newValue));
|
|
1504
|
+
} catch {
|
|
1505
|
+
}
|
|
1506
|
+
}, [
|
|
1507
|
+
setEditing,
|
|
1508
|
+
deserialize,
|
|
1509
|
+
onChange,
|
|
1510
|
+
path,
|
|
1511
|
+
value
|
|
1512
|
+
]);
|
|
1513
|
+
const actionIcons = useMemo(() => {
|
|
1514
|
+
if (editing) {
|
|
1515
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
1516
|
+
children: [
|
|
1517
|
+
/* @__PURE__ */ jsx(IconBox, {
|
|
1518
|
+
children: /* @__PURE__ */ jsx(CloseIcon, {
|
|
1519
|
+
sx: {
|
|
1520
|
+
fontSize: ".8rem"
|
|
1521
|
+
},
|
|
1522
|
+
onClick: abortEditing
|
|
1523
|
+
})
|
|
1524
|
+
}),
|
|
1525
|
+
/* @__PURE__ */ jsx(IconBox, {
|
|
1526
|
+
children: /* @__PURE__ */ jsx(CheckIcon, {
|
|
1527
|
+
sx: {
|
|
1528
|
+
fontSize: ".8rem"
|
|
1529
|
+
},
|
|
1530
|
+
onClick: () => commitEditing(tempValue)
|
|
1531
|
+
})
|
|
1532
|
+
})
|
|
1533
|
+
]
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
1537
|
+
children: [
|
|
1538
|
+
enableClipboard && /* @__PURE__ */ jsx(IconBox, {
|
|
1539
|
+
onClick: (event) => {
|
|
1540
|
+
event.preventDefault();
|
|
1541
|
+
try {
|
|
1542
|
+
copy(path, value, copyString);
|
|
1543
|
+
} catch (e) {
|
|
1544
|
+
console.error(e);
|
|
1545
|
+
}
|
|
1546
|
+
},
|
|
1547
|
+
children: copied ? /* @__PURE__ */ jsx(CheckIcon, {
|
|
1548
|
+
sx: {
|
|
1549
|
+
fontSize: ".8rem"
|
|
1550
|
+
}
|
|
1551
|
+
}) : /* @__PURE__ */ jsx(ContentCopyIcon, {
|
|
1552
|
+
sx: {
|
|
1553
|
+
fontSize: ".8rem"
|
|
1554
|
+
}
|
|
1555
|
+
})
|
|
1556
|
+
}),
|
|
1557
|
+
Editor && editable && serialize && deserialize && /* @__PURE__ */ jsx(IconBox, {
|
|
1558
|
+
onClick: startEditing,
|
|
1559
|
+
children: /* @__PURE__ */ jsx(EditIcon, {
|
|
1560
|
+
sx: {
|
|
1561
|
+
fontSize: ".8rem"
|
|
1562
|
+
}
|
|
1563
|
+
})
|
|
1564
|
+
}),
|
|
1565
|
+
enableAdd && /* @__PURE__ */ jsx(IconBox, {
|
|
1566
|
+
onClick: (event) => {
|
|
1567
|
+
event.preventDefault();
|
|
1568
|
+
onAdd === null || onAdd === void 0 ? void 0 : onAdd(path);
|
|
1569
|
+
},
|
|
1570
|
+
children: /* @__PURE__ */ jsx(AddBoxIcon, {
|
|
1571
|
+
sx: {
|
|
1572
|
+
fontSize: ".8rem"
|
|
1573
|
+
}
|
|
1574
|
+
})
|
|
1575
|
+
}),
|
|
1576
|
+
enableDelete && /* @__PURE__ */ jsx(IconBox, {
|
|
1577
|
+
onClick: (event) => {
|
|
1578
|
+
event.preventDefault();
|
|
1579
|
+
onDelete === null || onDelete === void 0 ? void 0 : onDelete(path, value);
|
|
1580
|
+
},
|
|
1581
|
+
children: /* @__PURE__ */ jsx(DeleteIcon, {
|
|
1582
|
+
sx: {
|
|
1583
|
+
fontSize: ".9rem"
|
|
1584
|
+
}
|
|
1585
|
+
})
|
|
1586
|
+
})
|
|
1587
|
+
]
|
|
1588
|
+
});
|
|
1589
|
+
}, [
|
|
1590
|
+
Editor,
|
|
1591
|
+
serialize,
|
|
1592
|
+
deserialize,
|
|
1593
|
+
copied,
|
|
1594
|
+
copy,
|
|
1595
|
+
editable,
|
|
1596
|
+
editing,
|
|
1597
|
+
enableClipboard,
|
|
1598
|
+
enableAdd,
|
|
1599
|
+
enableDelete,
|
|
1600
|
+
tempValue,
|
|
1601
|
+
path,
|
|
1602
|
+
value,
|
|
1603
|
+
onAdd,
|
|
1604
|
+
onDelete,
|
|
1605
|
+
startEditing,
|
|
1606
|
+
abortEditing,
|
|
1607
|
+
commitEditing
|
|
1608
|
+
]);
|
|
1609
|
+
const isEmptyValue = useMemo(() => getValueSize(value) === 0, [
|
|
1610
|
+
value
|
|
1611
|
+
]);
|
|
1612
|
+
const expandable = !isEmptyValue && !!(PreComponent && PostComponent);
|
|
1613
|
+
const KeyRenderer = useJsonViewerStore((store) => store.keyRenderer);
|
|
1614
|
+
const downstreamProps = useMemo(() => ({
|
|
1615
|
+
path,
|
|
1616
|
+
inspect,
|
|
1617
|
+
setInspect,
|
|
1618
|
+
value,
|
|
1619
|
+
prevValue,
|
|
1620
|
+
nestedIndex
|
|
1621
|
+
}), [
|
|
1622
|
+
inspect,
|
|
1623
|
+
path,
|
|
1624
|
+
setInspect,
|
|
1625
|
+
value,
|
|
1626
|
+
prevValue,
|
|
1627
|
+
nestedIndex
|
|
1628
|
+
]);
|
|
1629
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
1630
|
+
className: "data-key-pair",
|
|
1631
|
+
"data-testid": "data-key-pair" + path.join("."),
|
|
1632
|
+
sx: {
|
|
1633
|
+
userSelect: "text"
|
|
1634
|
+
},
|
|
1635
|
+
onMouseEnter: useCallback(() => setHover(path, nestedIndex), [
|
|
1636
|
+
setHover,
|
|
1637
|
+
path,
|
|
1638
|
+
nestedIndex
|
|
1639
|
+
]),
|
|
1640
|
+
children: [
|
|
1641
|
+
/* @__PURE__ */ jsxs(DataBox, {
|
|
1642
|
+
component: "span",
|
|
1643
|
+
className: "data-key",
|
|
1644
|
+
sx: {
|
|
1645
|
+
lineHeight: 1.5,
|
|
1646
|
+
color: keyColor,
|
|
1647
|
+
letterSpacing: 0.5,
|
|
1648
|
+
opacity: 0.8
|
|
1649
|
+
},
|
|
1650
|
+
onClick: useCallback((event) => {
|
|
1651
|
+
if (event.isDefaultPrevented()) {
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
if (!isEmptyValue) {
|
|
1655
|
+
setInspect((state) => !state);
|
|
1656
|
+
}
|
|
1657
|
+
}, [
|
|
1658
|
+
isEmptyValue,
|
|
1659
|
+
setInspect
|
|
1660
|
+
]),
|
|
1661
|
+
children: [
|
|
1662
|
+
expandable ? inspect ? /* @__PURE__ */ jsx(ExpandMoreIcon, {
|
|
1663
|
+
className: "data-key-toggle-expanded",
|
|
1664
|
+
sx: {
|
|
1665
|
+
fontSize: ".8rem",
|
|
1666
|
+
"&:hover": {
|
|
1667
|
+
cursor: "pointer"
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
}) : /* @__PURE__ */ jsx(ChevronRightIcon, {
|
|
1671
|
+
className: "data-key-toggle-collapsed",
|
|
1672
|
+
sx: {
|
|
1673
|
+
fontSize: ".8rem",
|
|
1674
|
+
"&:hover": {
|
|
1675
|
+
cursor: "pointer"
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
}) : null,
|
|
1679
|
+
/* @__PURE__ */ jsx(Box, {
|
|
1680
|
+
ref: highlightContainer,
|
|
1681
|
+
className: "data-key-key",
|
|
1682
|
+
component: "span",
|
|
1683
|
+
children: isRoot && depth === 0 ? rootName !== false ? quotesOnKeys ? /* @__PURE__ */ jsxs(Fragment, {
|
|
1684
|
+
children: [
|
|
1685
|
+
'"',
|
|
1686
|
+
rootName,
|
|
1687
|
+
'"'
|
|
1688
|
+
]
|
|
1689
|
+
}) : /* @__PURE__ */ jsx(Fragment, {
|
|
1690
|
+
children: rootName
|
|
1691
|
+
}) : null : KeyRenderer.when(downstreamProps) ? /* @__PURE__ */ jsx(KeyRenderer, {
|
|
1692
|
+
...downstreamProps
|
|
1693
|
+
}) : nestedIndex === void 0 && (isNumberKey ? /* @__PURE__ */ jsx(Box, {
|
|
1694
|
+
component: "span",
|
|
1695
|
+
style: {
|
|
1696
|
+
color: numberKeyColor,
|
|
1697
|
+
userSelect: isNumberKey ? "none" : "auto"
|
|
1698
|
+
},
|
|
1699
|
+
children: key
|
|
1700
|
+
}) : quotesOnKeys ? /* @__PURE__ */ jsxs(Fragment, {
|
|
1701
|
+
children: [
|
|
1702
|
+
'"',
|
|
1703
|
+
key,
|
|
1704
|
+
'"'
|
|
1705
|
+
]
|
|
1706
|
+
}) : /* @__PURE__ */ jsx(Fragment, {
|
|
1707
|
+
children: key
|
|
1708
|
+
}))
|
|
1709
|
+
}),
|
|
1710
|
+
isRoot ? rootName !== false && /* @__PURE__ */ jsx(DataBox, {
|
|
1711
|
+
className: "data-key-colon",
|
|
1712
|
+
sx: {
|
|
1713
|
+
mr: 0.5
|
|
1714
|
+
},
|
|
1715
|
+
children: ":"
|
|
1716
|
+
}) : nestedIndex === void 0 && /* @__PURE__ */ jsx(DataBox, {
|
|
1717
|
+
className: "data-key-colon",
|
|
1718
|
+
sx: {
|
|
1719
|
+
mr: 0.5,
|
|
1720
|
+
".data-key-key:empty + &": {
|
|
1721
|
+
display: "none"
|
|
1722
|
+
},
|
|
1723
|
+
userSelect: isNumberKey ? "none" : "auto"
|
|
1724
|
+
},
|
|
1725
|
+
children: ":"
|
|
1726
|
+
}),
|
|
1727
|
+
PreComponent && /* @__PURE__ */ jsx(PreComponent, {
|
|
1728
|
+
...downstreamProps
|
|
1729
|
+
}),
|
|
1730
|
+
isHover && expandable && inspect && actionIcons
|
|
1731
|
+
]
|
|
1732
|
+
}),
|
|
1733
|
+
editing && editable ? Editor && /* @__PURE__ */ jsx(Editor, {
|
|
1734
|
+
path,
|
|
1735
|
+
value: tempValue,
|
|
1736
|
+
setValue: setTempValue,
|
|
1737
|
+
abortEditing,
|
|
1738
|
+
commitEditing
|
|
1739
|
+
}) : Component ? /* @__PURE__ */ jsx(Component, {
|
|
1740
|
+
...downstreamProps
|
|
1741
|
+
}) : /* @__PURE__ */ jsx(Box, {
|
|
1742
|
+
component: "span",
|
|
1743
|
+
className: "data-value-fallback",
|
|
1744
|
+
children: "fallback: ".concat(value)
|
|
1745
|
+
}),
|
|
1746
|
+
PostComponent && /* @__PURE__ */ jsx(PostComponent, {
|
|
1747
|
+
...downstreamProps
|
|
1748
|
+
}),
|
|
1749
|
+
!last && displayComma && /* @__PURE__ */ jsx(DataBox, {
|
|
1750
|
+
children: ","
|
|
1751
|
+
}),
|
|
1752
|
+
isHover && expandable && !inspect && actionIcons,
|
|
1753
|
+
isHover && !expandable && actionIcons,
|
|
1754
|
+
!isHover && editing && actionIcons
|
|
1755
|
+
]
|
|
1756
|
+
});
|
|
1757
|
+
};
|
|
1758
|
+
const query = "(prefers-color-scheme: dark)";
|
|
1759
|
+
function useThemeDetector() {
|
|
1760
|
+
const [isDark, setIsDark] = useState(false);
|
|
1761
|
+
useEffect(() => {
|
|
1762
|
+
const listener = (e) => setIsDark(e.matches);
|
|
1763
|
+
setIsDark(window.matchMedia(query).matches);
|
|
1764
|
+
const queryMedia = window.matchMedia(query);
|
|
1765
|
+
queryMedia.addEventListener("change", listener);
|
|
1766
|
+
return () => queryMedia.removeEventListener("change", listener);
|
|
1767
|
+
}, []);
|
|
1768
|
+
return isDark;
|
|
1769
|
+
}
|
|
1770
|
+
function useSetIfNotUndefinedEffect(key, value) {
|
|
1771
|
+
const { setState } = useContext(JsonViewerStoreContext);
|
|
1772
|
+
useEffect(() => {
|
|
1773
|
+
if (value !== void 0) {
|
|
1774
|
+
setState({
|
|
1775
|
+
[key]: value
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
}, [
|
|
1779
|
+
key,
|
|
1780
|
+
value,
|
|
1781
|
+
setState
|
|
1782
|
+
]);
|
|
1783
|
+
}
|
|
1784
|
+
const JsonViewerInner = (props) => {
|
|
1785
|
+
const { setState } = useContext(JsonViewerStoreContext);
|
|
1786
|
+
useEffect(() => {
|
|
1787
|
+
setState((state) => ({
|
|
1788
|
+
prevValue: state.value,
|
|
1789
|
+
value: props.value
|
|
1790
|
+
}));
|
|
1791
|
+
}, [
|
|
1792
|
+
props.value,
|
|
1793
|
+
setState
|
|
1794
|
+
]);
|
|
1795
|
+
useSetIfNotUndefinedEffect("rootName", props.rootName);
|
|
1796
|
+
useSetIfNotUndefinedEffect("indentWidth", props.indentWidth);
|
|
1797
|
+
useSetIfNotUndefinedEffect("keyRenderer", props.keyRenderer);
|
|
1798
|
+
useSetIfNotUndefinedEffect("enableAdd", props.enableAdd);
|
|
1799
|
+
useSetIfNotUndefinedEffect("enableDelete", props.enableDelete);
|
|
1800
|
+
useSetIfNotUndefinedEffect("enableClipboard", props.enableClipboard);
|
|
1801
|
+
useSetIfNotUndefinedEffect("editable", props.editable);
|
|
1802
|
+
useSetIfNotUndefinedEffect("onChange", props.onChange);
|
|
1803
|
+
useSetIfNotUndefinedEffect("onCopy", props.onCopy);
|
|
1804
|
+
useSetIfNotUndefinedEffect("onSelect", props.onSelect);
|
|
1805
|
+
useSetIfNotUndefinedEffect("onAdd", props.onAdd);
|
|
1806
|
+
useSetIfNotUndefinedEffect("onDelete", props.onDelete);
|
|
1807
|
+
useSetIfNotUndefinedEffect("maxDisplayLength", props.maxDisplayLength);
|
|
1808
|
+
useSetIfNotUndefinedEffect("groupArraysAfterLength", props.groupArraysAfterLength);
|
|
1809
|
+
useSetIfNotUndefinedEffect("quotesOnKeys", props.quotesOnKeys);
|
|
1810
|
+
useSetIfNotUndefinedEffect("displayDataTypes", props.displayDataTypes);
|
|
1811
|
+
useSetIfNotUndefinedEffect("displaySize", props.displaySize);
|
|
1812
|
+
useSetIfNotUndefinedEffect("displayComma", props.displayComma);
|
|
1813
|
+
useSetIfNotUndefinedEffect("highlightUpdates", props.highlightUpdates);
|
|
1814
|
+
useEffect(() => {
|
|
1815
|
+
if (props.theme === "light") {
|
|
1816
|
+
setState({
|
|
1817
|
+
colorspace: lightColorspace
|
|
1818
|
+
});
|
|
1819
|
+
} else if (props.theme === "dark") {
|
|
1820
|
+
setState({
|
|
1821
|
+
colorspace: darkColorspace
|
|
1822
|
+
});
|
|
1823
|
+
} else if (typeof props.theme === "object") {
|
|
1824
|
+
setState({
|
|
1825
|
+
colorspace: props.theme
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
}, [
|
|
1829
|
+
setState,
|
|
1830
|
+
props.theme
|
|
1831
|
+
]);
|
|
1832
|
+
const themeCls = useMemo(() => {
|
|
1833
|
+
if (typeof props.theme === "object") return "json-viewer-theme-custom";
|
|
1834
|
+
return props.theme === "dark" ? "json-viewer-theme-dark" : "json-viewer-theme-light";
|
|
1835
|
+
}, [
|
|
1836
|
+
props.theme
|
|
1837
|
+
]);
|
|
1838
|
+
const onceRef = useRef(true);
|
|
1839
|
+
const registerTypes = useTypeRegistryStore((store) => store.registerTypes);
|
|
1840
|
+
if (onceRef.current) {
|
|
1841
|
+
const allTypes = props.valueTypes ? [
|
|
1842
|
+
...predefinedTypes,
|
|
1843
|
+
...props.valueTypes
|
|
1844
|
+
] : [
|
|
1845
|
+
...predefinedTypes
|
|
1846
|
+
];
|
|
1847
|
+
registerTypes(allTypes);
|
|
1848
|
+
onceRef.current = false;
|
|
1849
|
+
}
|
|
1850
|
+
useEffect(() => {
|
|
1851
|
+
const allTypes = props.valueTypes ? [
|
|
1852
|
+
...predefinedTypes,
|
|
1853
|
+
...props.valueTypes
|
|
1854
|
+
] : [
|
|
1855
|
+
...predefinedTypes
|
|
1856
|
+
];
|
|
1857
|
+
registerTypes(allTypes);
|
|
1858
|
+
}, [
|
|
1859
|
+
props.valueTypes,
|
|
1860
|
+
registerTypes
|
|
1861
|
+
]);
|
|
1862
|
+
const value = useJsonViewerStore((store) => store.value);
|
|
1863
|
+
const prevValue = useJsonViewerStore((store) => store.prevValue);
|
|
1864
|
+
const emptyPath = useMemo(() => [], []);
|
|
1865
|
+
const setHover = useJsonViewerStore((store) => store.setHover);
|
|
1866
|
+
const onMouseLeave = useCallback(() => setHover(null), [
|
|
1867
|
+
setHover
|
|
1868
|
+
]);
|
|
1869
|
+
return /* @__PURE__ */ jsx(Paper, {
|
|
1870
|
+
elevation: 0,
|
|
1871
|
+
className: clsx(themeCls, props.className),
|
|
1872
|
+
style: props.style,
|
|
1873
|
+
sx: {
|
|
1874
|
+
fontFamily: "monospace",
|
|
1875
|
+
userSelect: "none",
|
|
1876
|
+
contentVisibility: "auto",
|
|
1877
|
+
...props.sx
|
|
1878
|
+
},
|
|
1879
|
+
onMouseLeave,
|
|
1880
|
+
children: /* @__PURE__ */ jsx(DataKeyPair, {
|
|
1881
|
+
value,
|
|
1882
|
+
prevValue,
|
|
1883
|
+
path: emptyPath,
|
|
1884
|
+
last: true
|
|
1885
|
+
})
|
|
1886
|
+
});
|
|
1887
|
+
};
|
|
1888
|
+
const JsonViewer = function JsonViewer2(props) {
|
|
1889
|
+
const isAutoDarkTheme = useThemeDetector();
|
|
1890
|
+
const themeType = useMemo(() => {
|
|
1891
|
+
var _props_theme;
|
|
1892
|
+
return props.theme === "auto" ? isAutoDarkTheme ? "dark" : "light" : (_props_theme = props.theme) !== null && _props_theme !== void 0 ? _props_theme : "light";
|
|
1893
|
+
}, [
|
|
1894
|
+
isAutoDarkTheme,
|
|
1895
|
+
props.theme
|
|
1896
|
+
]);
|
|
1897
|
+
const theme = useMemo(() => {
|
|
1898
|
+
const backgroundColor = typeof themeType === "object" ? themeType.base00 : themeType === "dark" ? darkColorspace.base00 : lightColorspace.base00;
|
|
1899
|
+
const foregroundColor = typeof themeType === "object" ? themeType.base07 : themeType === "dark" ? darkColorspace.base07 : lightColorspace.base07;
|
|
1900
|
+
return createTheme({
|
|
1901
|
+
components: {
|
|
1902
|
+
MuiPaper: {
|
|
1903
|
+
styleOverrides: {
|
|
1904
|
+
root: {
|
|
1905
|
+
backgroundColor,
|
|
1906
|
+
color: foregroundColor
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
},
|
|
1911
|
+
palette: {
|
|
1912
|
+
mode: themeType === "dark" ? "dark" : "light",
|
|
1913
|
+
background: {
|
|
1914
|
+
default: backgroundColor
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
});
|
|
1918
|
+
}, [
|
|
1919
|
+
themeType
|
|
1920
|
+
]);
|
|
1921
|
+
const mixedProps = {
|
|
1922
|
+
...props,
|
|
1923
|
+
theme: themeType
|
|
1924
|
+
};
|
|
1925
|
+
const jsonViewerStore = useMemo(() => createJsonViewerStore(props), []);
|
|
1926
|
+
const typeRegistryStore = useMemo(() => createTypeRegistryStore(), []);
|
|
1927
|
+
return /* @__PURE__ */ jsx(ThemeProvider, {
|
|
1928
|
+
theme,
|
|
1929
|
+
children: /* @__PURE__ */ jsx(TypeRegistryStoreContext.Provider, {
|
|
1930
|
+
value: typeRegistryStore,
|
|
1931
|
+
children: /* @__PURE__ */ jsx(JsonViewerStoreContext.Provider, {
|
|
1932
|
+
value: jsonViewerStore,
|
|
1933
|
+
children: /* @__PURE__ */ jsx(JsonViewerInner, {
|
|
1934
|
+
...mixedProps
|
|
1935
|
+
})
|
|
1936
|
+
})
|
|
1937
|
+
})
|
|
1938
|
+
});
|
|
1939
|
+
};
|
|
1940
|
+
export {
|
|
1941
|
+
JsonViewer as J
|
|
1942
|
+
};
|