@uiw/react-json-view 0.0.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/README.md +337 -0
- package/cjs/arrow/TriangleArrow.d.ts +4 -0
- package/cjs/arrow/TriangleArrow.js +30 -0
- package/cjs/arrow/TriangleSolidArrow.d.ts +4 -0
- package/cjs/arrow/TriangleSolidArrow.js +30 -0
- package/cjs/index.d.ts +26 -0
- package/cjs/index.js +62 -0
- package/cjs/node.d.ts +26 -0
- package/cjs/node.js +272 -0
- package/cjs/store.d.ts +5 -0
- package/cjs/store.js +55 -0
- package/cjs/theme/dark.d.ts +19 -0
- package/cjs/theme/dark.js +26 -0
- package/cjs/theme/light.d.ts +19 -0
- package/cjs/theme/light.js +26 -0
- package/cjs/value.d.ts +61 -0
- package/cjs/value.js +185 -0
- package/esm/arrow/TriangleArrow.d.ts +4 -0
- package/esm/arrow/TriangleArrow.js +25 -0
- package/esm/arrow/TriangleSolidArrow.d.ts +4 -0
- package/esm/arrow/TriangleSolidArrow.js +25 -0
- package/esm/index.d.ts +26 -0
- package/esm/index.js +34 -0
- package/esm/node.d.ts +26 -0
- package/esm/node.js +255 -0
- package/esm/store.d.ts +5 -0
- package/esm/store.js +36 -0
- package/esm/theme/dark.d.ts +19 -0
- package/esm/theme/dark.js +19 -0
- package/esm/theme/light.d.ts +19 -0
- package/esm/theme/light.js +19 -0
- package/esm/value.d.ts +61 -0
- package/esm/value.js +176 -0
- package/package.json +65 -0
- package/src/arrow/TriangleArrow.tsx +17 -0
- package/src/arrow/TriangleSolidArrow.tsx +17 -0
- package/src/index.tsx +43 -0
- package/src/node.tsx +201 -0
- package/src/store.tsx +37 -0
- package/src/theme/dark.ts +21 -0
- package/src/theme/light.ts +21 -0
- package/src/value.tsx +172 -0
package/cjs/node.js
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Line = exports.Ellipsis = exports.CountInfo = void 0;
|
|
8
|
+
exports.Meta = Meta;
|
|
9
|
+
exports.RooNode = RooNode;
|
|
10
|
+
exports.Semicolon = void 0;
|
|
11
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
12
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
14
|
+
var _react = require("react");
|
|
15
|
+
var _value = require("./value");
|
|
16
|
+
var _TriangleArrow = require("./arrow/TriangleArrow");
|
|
17
|
+
var _store = require("./store");
|
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
var _excluded = ["isArray", "start", "className", "render"],
|
|
20
|
+
_excluded2 = ["style", "render"],
|
|
21
|
+
_excluded3 = ["children", "render", "color", "value", "className", "show"],
|
|
22
|
+
_excluded4 = ["value", "keyName", "displayDataTypes", "components", "displayObjectSize", "indentWidth", "keyid"];
|
|
23
|
+
function Meta(props) {
|
|
24
|
+
var _props$isArray = props.isArray,
|
|
25
|
+
isArray = _props$isArray === void 0 ? false : _props$isArray,
|
|
26
|
+
_props$start = props.start,
|
|
27
|
+
start = _props$start === void 0 ? false : _props$start,
|
|
28
|
+
className = props.className,
|
|
29
|
+
render = props.render,
|
|
30
|
+
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
31
|
+
var mark = isArray ? '[]' : '{}';
|
|
32
|
+
var cls = "w-rjv-".concat(isArray ? 'brackets' : 'curlybraces', "-").concat(start ? 'start' : 'end', " ").concat(className || '');
|
|
33
|
+
var color = "var(--w-rjv-".concat(isArray ? 'brackets' : 'curlybraces', "-color, #236a7c)");
|
|
34
|
+
if (render) return render((0, _objectSpread2["default"])({
|
|
35
|
+
isArray: isArray,
|
|
36
|
+
className: cls,
|
|
37
|
+
style: {
|
|
38
|
+
color: color
|
|
39
|
+
},
|
|
40
|
+
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
41
|
+
}, reset));
|
|
42
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
43
|
+
color: color,
|
|
44
|
+
className: cls
|
|
45
|
+
}, reset), {}, {
|
|
46
|
+
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
var Line = function Line(props) {
|
|
50
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
|
|
51
|
+
};
|
|
52
|
+
exports.Line = Line;
|
|
53
|
+
var Ellipsis = function Ellipsis(_ref) {
|
|
54
|
+
var style = _ref.style,
|
|
55
|
+
render = _ref.render,
|
|
56
|
+
props = (0, _objectWithoutProperties2["default"])(_ref, _excluded2);
|
|
57
|
+
var styl = (0, _objectSpread2["default"])({
|
|
58
|
+
cursor: 'pointer'
|
|
59
|
+
}, style);
|
|
60
|
+
var className = "w-rjv-ellipsis ".concat(props.className || '');
|
|
61
|
+
if (render) return render((0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
62
|
+
style: styl
|
|
63
|
+
}, props), {}, {
|
|
64
|
+
className: className
|
|
65
|
+
}));
|
|
66
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
67
|
+
className: className,
|
|
68
|
+
style: styl
|
|
69
|
+
}, props), {}, {
|
|
70
|
+
children: "..."
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
exports.Ellipsis = Ellipsis;
|
|
74
|
+
var Semicolon = function Semicolon(_ref2) {
|
|
75
|
+
var children = _ref2.children,
|
|
76
|
+
render = _ref2.render,
|
|
77
|
+
color = _ref2.color,
|
|
78
|
+
value = _ref2.value,
|
|
79
|
+
_ref2$className = _ref2.className,
|
|
80
|
+
className = _ref2$className === void 0 ? 'w-rjv-object-key' : _ref2$className,
|
|
81
|
+
show = _ref2.show,
|
|
82
|
+
props = (0, _objectWithoutProperties2["default"])(_ref2, _excluded3);
|
|
83
|
+
var content = show ? "\"".concat(children, "\"") : children;
|
|
84
|
+
if (render) return render((0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
85
|
+
className: className
|
|
86
|
+
}, props), {}, {
|
|
87
|
+
value: value,
|
|
88
|
+
style: {
|
|
89
|
+
color: color
|
|
90
|
+
},
|
|
91
|
+
children: content
|
|
92
|
+
}));
|
|
93
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
94
|
+
className: className,
|
|
95
|
+
color: color
|
|
96
|
+
}, props), {}, {
|
|
97
|
+
children: content
|
|
98
|
+
}));
|
|
99
|
+
};
|
|
100
|
+
exports.Semicolon = Semicolon;
|
|
101
|
+
var CountInfo = function CountInfo(_ref3) {
|
|
102
|
+
var children = _ref3.children;
|
|
103
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, {
|
|
104
|
+
style: {
|
|
105
|
+
paddingLeft: 4,
|
|
106
|
+
fontStyle: 'italic'
|
|
107
|
+
},
|
|
108
|
+
color: "var(--w-rjv-info-color, #0000004d)",
|
|
109
|
+
className: "object-size",
|
|
110
|
+
children: children
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
exports.CountInfo = CountInfo;
|
|
114
|
+
function RooNode(props) {
|
|
115
|
+
var _expands$keyid;
|
|
116
|
+
var _props$value = props.value,
|
|
117
|
+
value = _props$value === void 0 ? {} : _props$value,
|
|
118
|
+
keyName = props.keyName,
|
|
119
|
+
_props$displayDataTyp = props.displayDataTypes,
|
|
120
|
+
displayDataTypes = _props$displayDataTyp === void 0 ? true : _props$displayDataTyp,
|
|
121
|
+
_props$components = props.components,
|
|
122
|
+
components = _props$components === void 0 ? {} : _props$components,
|
|
123
|
+
_props$displayObjectS = props.displayObjectSize,
|
|
124
|
+
displayObjectSize = _props$displayObjectS === void 0 ? true : _props$displayObjectS,
|
|
125
|
+
_props$indentWidth = props.indentWidth,
|
|
126
|
+
indentWidth = _props$indentWidth === void 0 ? 15 : _props$indentWidth,
|
|
127
|
+
_props$keyid = props.keyid,
|
|
128
|
+
keyid = _props$keyid === void 0 ? 'root' : _props$keyid,
|
|
129
|
+
reset = (0, _objectWithoutProperties2["default"])(props, _excluded4);
|
|
130
|
+
var isArray = Array.isArray(value);
|
|
131
|
+
var nameKeys = isArray ? Object.keys(value).map(function (m) {
|
|
132
|
+
return Number(m);
|
|
133
|
+
}) : Object.keys(value);
|
|
134
|
+
var subkeyid = (0, _react.useId)();
|
|
135
|
+
var expands = (0, _store.useExpandsStatus)();
|
|
136
|
+
var expand = (_expands$keyid = expands[keyid]) !== null && _expands$keyid !== void 0 ? _expands$keyid : true;
|
|
137
|
+
var arrowStyle = {
|
|
138
|
+
transform: "rotate(".concat(expand ? '0' : '-90', "deg)"),
|
|
139
|
+
transition: 'all 0.3s'
|
|
140
|
+
};
|
|
141
|
+
var handle = function handle() {
|
|
142
|
+
!expand ? _store.store.expand(keyid) : _store.store.collapse(keyid);
|
|
143
|
+
};
|
|
144
|
+
var subNodeProps = {
|
|
145
|
+
components: components,
|
|
146
|
+
indentWidth: indentWidth,
|
|
147
|
+
displayDataTypes: displayDataTypes,
|
|
148
|
+
displayObjectSize: displayObjectSize,
|
|
149
|
+
style: {
|
|
150
|
+
paddingLeft: indentWidth
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var valueViewProps = {
|
|
154
|
+
displayDataTypes: displayDataTypes,
|
|
155
|
+
renderValue: components.value
|
|
156
|
+
};
|
|
157
|
+
var arrowView = components.arrow ? /*#__PURE__*/(0, _react.cloneElement)(components.arrow, {
|
|
158
|
+
style: arrowStyle,
|
|
159
|
+
'data-expand': expand
|
|
160
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_TriangleArrow.TriangleArrow, {
|
|
161
|
+
style: arrowStyle
|
|
162
|
+
});
|
|
163
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
164
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
|
|
165
|
+
style: {
|
|
166
|
+
display: 'inline-flex',
|
|
167
|
+
alignItems: 'center'
|
|
168
|
+
},
|
|
169
|
+
onClick: handle,
|
|
170
|
+
children: [arrowView, (typeof keyName === 'string' || typeof keyName === 'number') && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
171
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Semicolon, {
|
|
172
|
+
value: value,
|
|
173
|
+
render: components.objectKey,
|
|
174
|
+
color: typeof keyName === 'number' ? _value.typeMap['number'].color : '',
|
|
175
|
+
show: typeof keyName === 'string',
|
|
176
|
+
children: keyName
|
|
177
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Colon, {})]
|
|
178
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
|
|
179
|
+
start: true,
|
|
180
|
+
isArray: isArray,
|
|
181
|
+
render: components.braces
|
|
182
|
+
}), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(Ellipsis, {
|
|
183
|
+
render: components.ellipsis
|
|
184
|
+
}), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
|
|
185
|
+
isArray: isArray,
|
|
186
|
+
render: components.braces
|
|
187
|
+
}), displayObjectSize && /*#__PURE__*/(0, _jsxRuntime.jsxs)(CountInfo, {
|
|
188
|
+
children: [nameKeys.length, " items"]
|
|
189
|
+
})]
|
|
190
|
+
}), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
191
|
+
style: {
|
|
192
|
+
borderLeft: 'var(--w-rjv-border-left, 1px solid #ebebeb)',
|
|
193
|
+
marginLeft: 6
|
|
194
|
+
},
|
|
195
|
+
children: nameKeys.length > 0 && nameKeys.map(function (key, idx) {
|
|
196
|
+
var item = value[key];
|
|
197
|
+
if (Array.isArray(item)) {
|
|
198
|
+
var label = isArray ? idx : key;
|
|
199
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
200
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
|
|
201
|
+
value: item,
|
|
202
|
+
keyid: keyid + subkeyid + label,
|
|
203
|
+
keyName: label
|
|
204
|
+
}, subNodeProps))
|
|
205
|
+
}, label + idx);
|
|
206
|
+
}
|
|
207
|
+
var renderKey = /*#__PURE__*/(0, _jsxRuntime.jsx)(Semicolon, {
|
|
208
|
+
value: item,
|
|
209
|
+
render: components.objectKey,
|
|
210
|
+
color: typeof key === 'number' ? _value.typeMap['number'].color : '',
|
|
211
|
+
show: typeof key === 'string',
|
|
212
|
+
children: key
|
|
213
|
+
});
|
|
214
|
+
if ((0, _typeof2["default"])(item) === 'object' && item && !(item instanceof Date)) {
|
|
215
|
+
if (Object.keys(item).length === 0) {
|
|
216
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
|
|
217
|
+
style: {
|
|
218
|
+
paddingLeft: indentWidth
|
|
219
|
+
},
|
|
220
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_value.ValueView, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, valueViewProps), {}, {
|
|
221
|
+
renderKey: renderKey,
|
|
222
|
+
keyName: key,
|
|
223
|
+
value: item
|
|
224
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
|
|
225
|
+
render: components.braces,
|
|
226
|
+
start: true,
|
|
227
|
+
isArray: isArray
|
|
228
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
|
|
229
|
+
render: components.braces,
|
|
230
|
+
isArray: isArray
|
|
231
|
+
}), displayObjectSize && /*#__PURE__*/(0, _jsxRuntime.jsxs)(CountInfo, {
|
|
232
|
+
children: [Object.keys(item).length, " items"]
|
|
233
|
+
})]
|
|
234
|
+
}, key + idx);
|
|
235
|
+
}
|
|
236
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
237
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
|
|
238
|
+
keyid: keyid + subkeyid + key,
|
|
239
|
+
value: item,
|
|
240
|
+
keyName: key
|
|
241
|
+
}, subNodeProps))
|
|
242
|
+
}, key + idx);
|
|
243
|
+
}
|
|
244
|
+
if (typeof item === 'function') {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
248
|
+
style: {
|
|
249
|
+
paddingLeft: indentWidth
|
|
250
|
+
},
|
|
251
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.ValueView, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, valueViewProps), {}, {
|
|
252
|
+
renderKey: renderKey,
|
|
253
|
+
keyName: key,
|
|
254
|
+
value: item
|
|
255
|
+
}))
|
|
256
|
+
}, idx);
|
|
257
|
+
})
|
|
258
|
+
}), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
259
|
+
style: {
|
|
260
|
+
paddingLeft: 2
|
|
261
|
+
},
|
|
262
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
|
|
263
|
+
render: components.braces,
|
|
264
|
+
isArray: isArray,
|
|
265
|
+
style: {
|
|
266
|
+
paddingLeft: 2,
|
|
267
|
+
display: 'inline-block'
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
})]
|
|
271
|
+
}));
|
|
272
|
+
}
|
package/cjs/store.d.ts
ADDED
package/cjs/store.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.store = void 0;
|
|
8
|
+
exports.useExpandsStatus = useExpandsStatus;
|
|
9
|
+
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
var _objectSpread4 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
|
+
var _react = require("react");
|
|
14
|
+
var expands = {};
|
|
15
|
+
var listeners = [];
|
|
16
|
+
var store = {
|
|
17
|
+
collapse: function collapse(id) {
|
|
18
|
+
expands = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, expands), {}, (0, _defineProperty2["default"])({}, id, false));
|
|
19
|
+
emitChange();
|
|
20
|
+
},
|
|
21
|
+
expand: function expand(id) {
|
|
22
|
+
expands = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, expands), {}, (0, _defineProperty2["default"])({}, id, true));
|
|
23
|
+
emitChange();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.store = store;
|
|
27
|
+
function getSnapshot() {
|
|
28
|
+
return expands;
|
|
29
|
+
}
|
|
30
|
+
function subscribe(listener) {
|
|
31
|
+
listeners = [].concat((0, _toConsumableArray2["default"])(listeners), [listener]);
|
|
32
|
+
return function () {
|
|
33
|
+
listeners = listeners.filter(function (l) {
|
|
34
|
+
return l !== listener;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function emitChange() {
|
|
39
|
+
var _iterator = (0, _createForOfIteratorHelper2["default"])(listeners),
|
|
40
|
+
_step;
|
|
41
|
+
try {
|
|
42
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
43
|
+
var listener = _step.value;
|
|
44
|
+
listener();
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
_iterator.e(err);
|
|
48
|
+
} finally {
|
|
49
|
+
_iterator.f();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function useExpandsStatus() {
|
|
53
|
+
var expands = (0, _react.useSyncExternalStore)(subscribe, getSnapshot);
|
|
54
|
+
return expands;
|
|
55
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const darkTheme: {
|
|
2
|
+
'--w-rjv-font-family': string;
|
|
3
|
+
'--w-rjv-color': string;
|
|
4
|
+
'--w-rjv-background-color': string;
|
|
5
|
+
'--w-rjv-border-left': string;
|
|
6
|
+
'--w-rjv-arrow-color': string;
|
|
7
|
+
'--w-rjv-info-color': string;
|
|
8
|
+
'--w-rjv-curlybraces-color': string;
|
|
9
|
+
'--w-rjv-brackets-color': string;
|
|
10
|
+
'--w-rjv-type-string-color': string;
|
|
11
|
+
'--w-rjv-type-int-color': string;
|
|
12
|
+
'--w-rjv-type-float-color': string;
|
|
13
|
+
'--w-rjv-type-bigint-color': string;
|
|
14
|
+
'--w-rjv-type-boolean-color': string;
|
|
15
|
+
'--w-rjv-type-date-color': string;
|
|
16
|
+
'--w-rjv-type-null-color': string;
|
|
17
|
+
'--w-rjv-type-nan-color': string;
|
|
18
|
+
'--w-rjv-type-undefined-color': string;
|
|
19
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.darkTheme = void 0;
|
|
7
|
+
var darkTheme = {
|
|
8
|
+
'--w-rjv-font-family': 'monospace',
|
|
9
|
+
'--w-rjv-color': '#0184a6',
|
|
10
|
+
'--w-rjv-background-color': '#202020',
|
|
11
|
+
'--w-rjv-border-left': '1px solid #323232',
|
|
12
|
+
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
13
|
+
'--w-rjv-info-color': '#656565',
|
|
14
|
+
'--w-rjv-curlybraces-color': '#1896b6',
|
|
15
|
+
'--w-rjv-brackets-color': '#1896b6',
|
|
16
|
+
'--w-rjv-type-string-color': '#cb4b16',
|
|
17
|
+
'--w-rjv-type-int-color': '#268bd2',
|
|
18
|
+
'--w-rjv-type-float-color': '#859900',
|
|
19
|
+
'--w-rjv-type-bigint-color': '#268bd2',
|
|
20
|
+
'--w-rjv-type-boolean-color': '#2aa198',
|
|
21
|
+
'--w-rjv-type-date-color': '#586e75',
|
|
22
|
+
'--w-rjv-type-null-color': '#d33682',
|
|
23
|
+
'--w-rjv-type-nan-color': '#859900',
|
|
24
|
+
'--w-rjv-type-undefined-color': '#586e75'
|
|
25
|
+
};
|
|
26
|
+
exports.darkTheme = darkTheme;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const lightTheme: {
|
|
2
|
+
'--w-rjv-font-family': string;
|
|
3
|
+
'--w-rjv-color': string;
|
|
4
|
+
'--w-rjv-background-color': string;
|
|
5
|
+
'--w-rjv-border-left': string;
|
|
6
|
+
'--w-rjv-arrow-color': string;
|
|
7
|
+
'--w-rjv-info-color': string;
|
|
8
|
+
'--w-rjv-curlybraces-color': string;
|
|
9
|
+
'--w-rjv-brackets-color': string;
|
|
10
|
+
'--w-rjv-type-string-color': string;
|
|
11
|
+
'--w-rjv-type-int-color': string;
|
|
12
|
+
'--w-rjv-type-float-color': string;
|
|
13
|
+
'--w-rjv-type-bigint-color': string;
|
|
14
|
+
'--w-rjv-type-boolean-color': string;
|
|
15
|
+
'--w-rjv-type-date-color': string;
|
|
16
|
+
'--w-rjv-type-null-color': string;
|
|
17
|
+
'--w-rjv-type-nan-color': string;
|
|
18
|
+
'--w-rjv-type-undefined-color': string;
|
|
19
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.lightTheme = void 0;
|
|
7
|
+
var lightTheme = {
|
|
8
|
+
'--w-rjv-font-family': 'monospace',
|
|
9
|
+
'--w-rjv-color': '#002b36',
|
|
10
|
+
'--w-rjv-background-color': '#ffffff',
|
|
11
|
+
'--w-rjv-border-left': '1px solid #ebebeb',
|
|
12
|
+
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
13
|
+
'--w-rjv-info-color': '#0000004d',
|
|
14
|
+
'--w-rjv-curlybraces-color': '#236a7c',
|
|
15
|
+
'--w-rjv-brackets-color': '#236a7c',
|
|
16
|
+
'--w-rjv-type-string-color': '#cb4b16',
|
|
17
|
+
'--w-rjv-type-int-color': '#268bd2',
|
|
18
|
+
'--w-rjv-type-float-color': '#859900',
|
|
19
|
+
'--w-rjv-type-bigint-color': '#268bd2',
|
|
20
|
+
'--w-rjv-type-boolean-color': '#2aa198',
|
|
21
|
+
'--w-rjv-type-date-color': '#586e75',
|
|
22
|
+
'--w-rjv-type-null-color': '#d33682',
|
|
23
|
+
'--w-rjv-type-nan-color': '#859900',
|
|
24
|
+
'--w-rjv-type-undefined-color': '#586e75'
|
|
25
|
+
};
|
|
26
|
+
exports.lightTheme = lightTheme;
|
package/cjs/value.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
export declare const typeMap: {
|
|
3
|
+
string: {
|
|
4
|
+
color: string;
|
|
5
|
+
label: string;
|
|
6
|
+
};
|
|
7
|
+
number: {
|
|
8
|
+
color: string;
|
|
9
|
+
label: string;
|
|
10
|
+
};
|
|
11
|
+
float: {
|
|
12
|
+
color: string;
|
|
13
|
+
label: string;
|
|
14
|
+
};
|
|
15
|
+
bigint: {
|
|
16
|
+
color: string;
|
|
17
|
+
label: string;
|
|
18
|
+
};
|
|
19
|
+
boolean: {
|
|
20
|
+
color: string;
|
|
21
|
+
label: string;
|
|
22
|
+
};
|
|
23
|
+
date: {
|
|
24
|
+
color: string;
|
|
25
|
+
label: string;
|
|
26
|
+
};
|
|
27
|
+
null: {
|
|
28
|
+
color: string;
|
|
29
|
+
label: string;
|
|
30
|
+
};
|
|
31
|
+
NaN: {
|
|
32
|
+
color: string;
|
|
33
|
+
label: string;
|
|
34
|
+
};
|
|
35
|
+
undefined: {
|
|
36
|
+
color: string;
|
|
37
|
+
label: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export declare const Colon: FC<PropsWithChildren<React.HTMLAttributes<HTMLSpanElement>>>;
|
|
41
|
+
export interface ValueViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
|
|
42
|
+
keyName?: string;
|
|
43
|
+
value: T;
|
|
44
|
+
displayDataTypes: boolean;
|
|
45
|
+
renderKey?: JSX.Element;
|
|
46
|
+
renderValue?: (props: React.HTMLAttributes<HTMLSpanElement> & {
|
|
47
|
+
type: TypeProps['type'];
|
|
48
|
+
}) => JSX.Element;
|
|
49
|
+
}
|
|
50
|
+
export declare function ValueView<T>(props: ValueViewProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
51
|
+
export interface LabelProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
52
|
+
color?: string;
|
|
53
|
+
fontSize?: number;
|
|
54
|
+
opacity?: number;
|
|
55
|
+
paddingRight?: number;
|
|
56
|
+
}
|
|
57
|
+
export declare const Label: FC<PropsWithChildren<LabelProps>>;
|
|
58
|
+
export interface TypeProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
|
|
59
|
+
type: keyof typeof typeMap;
|
|
60
|
+
}
|
|
61
|
+
export declare const Type: FC<PropsWithChildren<TypeProps>>;
|
package/cjs/value.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Type = exports.Label = exports.Colon = void 0;
|
|
8
|
+
exports.ValueView = ValueView;
|
|
9
|
+
exports.typeMap = void 0;
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
var _react = require("react");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
var _excluded = ["children", "style"],
|
|
16
|
+
_excluded2 = ["value", "keyName", "renderKey", "renderValue", "displayDataTypes"],
|
|
17
|
+
_excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
18
|
+
var isFloat = function isFloat(n) {
|
|
19
|
+
return Number(n) === n && n % 1 !== 0 || isNaN(n);
|
|
20
|
+
};
|
|
21
|
+
var typeMap = {
|
|
22
|
+
string: {
|
|
23
|
+
color: 'var(--w-rjv-type-string-color, #cb4b16)',
|
|
24
|
+
label: 'string'
|
|
25
|
+
},
|
|
26
|
+
number: {
|
|
27
|
+
color: 'var(--w-rjv-type-int-color, #268bd2)',
|
|
28
|
+
label: 'int'
|
|
29
|
+
},
|
|
30
|
+
"float": {
|
|
31
|
+
color: 'var(--w-rjv-type-float-color, #859900)',
|
|
32
|
+
label: 'float'
|
|
33
|
+
},
|
|
34
|
+
bigint: {
|
|
35
|
+
color: 'var(--w-rjv-type-bigint-color, #268bd2)',
|
|
36
|
+
label: 'bigint'
|
|
37
|
+
},
|
|
38
|
+
"boolean": {
|
|
39
|
+
color: 'var(--w-rjv-type-boolean-color, #2aa198)',
|
|
40
|
+
label: 'bool'
|
|
41
|
+
},
|
|
42
|
+
date: {
|
|
43
|
+
color: 'var(--w-rjv-type-date-color, #586e75)',
|
|
44
|
+
label: 'date'
|
|
45
|
+
},
|
|
46
|
+
"null": {
|
|
47
|
+
color: 'var(--w-rjv-type-null-color, #d33682)',
|
|
48
|
+
label: 'null'
|
|
49
|
+
},
|
|
50
|
+
NaN: {
|
|
51
|
+
color: 'var(--w-rjv-type-nan-color, #859900)',
|
|
52
|
+
label: 'NaN'
|
|
53
|
+
},
|
|
54
|
+
undefined: {
|
|
55
|
+
color: 'var(--w-rjv-type-undefined-color, #586e75)',
|
|
56
|
+
label: 'undefined'
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.typeMap = typeMap;
|
|
60
|
+
var Colon = function Colon(_ref) {
|
|
61
|
+
var _ref$children = _ref.children,
|
|
62
|
+
children = _ref$children === void 0 ? ':' : _ref$children,
|
|
63
|
+
style = _ref.style,
|
|
64
|
+
props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
65
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
66
|
+
className: "w-rjv-colon",
|
|
67
|
+
style: (0, _objectSpread2["default"])({
|
|
68
|
+
paddingRight: 3
|
|
69
|
+
}, style)
|
|
70
|
+
}, props), {}, {
|
|
71
|
+
children: children
|
|
72
|
+
}));
|
|
73
|
+
};
|
|
74
|
+
exports.Colon = Colon;
|
|
75
|
+
function ValueView(props) {
|
|
76
|
+
var _typeMap$type;
|
|
77
|
+
var value = props.value,
|
|
78
|
+
keyName = props.keyName,
|
|
79
|
+
renderKey = props.renderKey,
|
|
80
|
+
renderValue = props.renderValue,
|
|
81
|
+
displayDataTypes = props.displayDataTypes,
|
|
82
|
+
reset = (0, _objectWithoutProperties2["default"])(props, _excluded2);
|
|
83
|
+
var type = (0, _typeof2["default"])(value);
|
|
84
|
+
var content = '';
|
|
85
|
+
var color = '';
|
|
86
|
+
var style = {};
|
|
87
|
+
if (typeof value === 'number') {
|
|
88
|
+
type = isFloat(value) ? 'float' : 'number';
|
|
89
|
+
content = value.toString();
|
|
90
|
+
}
|
|
91
|
+
if (typeof value === 'boolean') {
|
|
92
|
+
type = 'boolean';
|
|
93
|
+
content = value.toString();
|
|
94
|
+
}
|
|
95
|
+
if ((0, _typeof2["default"])(value) === 'object' && value instanceof Date) {
|
|
96
|
+
type = 'date';
|
|
97
|
+
content = value.toString();
|
|
98
|
+
}
|
|
99
|
+
var typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
|
|
100
|
+
type: type
|
|
101
|
+
});
|
|
102
|
+
if (value === null) {
|
|
103
|
+
type = 'null';
|
|
104
|
+
content = "".concat(value).toLocaleUpperCase();
|
|
105
|
+
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
106
|
+
style = {
|
|
107
|
+
fontWeight: 'bold'
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (value === undefined) {
|
|
111
|
+
type = 'undefined';
|
|
112
|
+
content = String(value);
|
|
113
|
+
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
114
|
+
}
|
|
115
|
+
if (typeof value === 'bigint') {
|
|
116
|
+
type = 'bigint';
|
|
117
|
+
content = "".concat(value, "n");
|
|
118
|
+
}
|
|
119
|
+
if (typeof value === 'string') {
|
|
120
|
+
content = "\"".concat(value, "\"");
|
|
121
|
+
}
|
|
122
|
+
if (!displayDataTypes) {
|
|
123
|
+
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
124
|
+
}
|
|
125
|
+
color = ((_typeMap$type = typeMap[type]) === null || _typeMap$type === void 0 ? void 0 : _typeMap$type.color) || '';
|
|
126
|
+
if (content && typeof content === 'string') {
|
|
127
|
+
var valueView = renderValue ? renderValue({
|
|
128
|
+
className: 'w-rjv-value',
|
|
129
|
+
style: (0, _objectSpread2["default"])({
|
|
130
|
+
color: color
|
|
131
|
+
}, style),
|
|
132
|
+
type: type,
|
|
133
|
+
children: content
|
|
134
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(Label, {
|
|
135
|
+
color: color,
|
|
136
|
+
style: style,
|
|
137
|
+
className: "w-rjv-value",
|
|
138
|
+
children: content
|
|
139
|
+
});
|
|
140
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
141
|
+
children: [renderKey, /*#__PURE__*/(0, _jsxRuntime.jsx)(Colon, {}), typeView, valueView]
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
145
|
+
children: [renderKey, /*#__PURE__*/(0, _jsxRuntime.jsx)(Colon, {}), typeView]
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
var Label = function Label(_ref2) {
|
|
149
|
+
var children = _ref2.children,
|
|
150
|
+
color = _ref2.color,
|
|
151
|
+
fontSize = _ref2.fontSize,
|
|
152
|
+
opacity = _ref2.opacity,
|
|
153
|
+
paddingRight = _ref2.paddingRight,
|
|
154
|
+
style = _ref2.style,
|
|
155
|
+
reset = (0, _objectWithoutProperties2["default"])(_ref2, _excluded3);
|
|
156
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
157
|
+
style: (0, _objectSpread2["default"])({
|
|
158
|
+
color: color,
|
|
159
|
+
fontSize: fontSize,
|
|
160
|
+
opacity: opacity,
|
|
161
|
+
paddingRight: paddingRight
|
|
162
|
+
}, style)
|
|
163
|
+
}, reset), {}, {
|
|
164
|
+
children: children
|
|
165
|
+
}));
|
|
166
|
+
};
|
|
167
|
+
exports.Label = Label;
|
|
168
|
+
var Type = function Type(props) {
|
|
169
|
+
var _typeMap$type2, _typeMap$type3;
|
|
170
|
+
var type = props.type;
|
|
171
|
+
var color = (_typeMap$type2 = typeMap[type]) === null || _typeMap$type2 === void 0 ? void 0 : _typeMap$type2.color;
|
|
172
|
+
var label = (_typeMap$type3 = typeMap[type]) === null || _typeMap$type3 === void 0 ? void 0 : _typeMap$type3.label;
|
|
173
|
+
if (color && label) {
|
|
174
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Label, {
|
|
175
|
+
color: color,
|
|
176
|
+
fontSize: 11,
|
|
177
|
+
opacity: 0.8,
|
|
178
|
+
paddingRight: 4,
|
|
179
|
+
className: "w-rjv-type",
|
|
180
|
+
"data-type": type,
|
|
181
|
+
children: label
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
exports.Type = Type;
|