@uiw/react-json-view 1.7.0 → 1.7.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 +21 -5
- package/cjs/editor/countInfoExtra.d.ts +3 -3
- package/cjs/editor/countInfoExtra.js +2 -0
- package/cjs/editor/icon/add.js +1 -1
- package/cjs/editor/index.d.ts +5 -2
- package/cjs/editor/value.js +99 -63
- package/esm/editor/countInfoExtra.d.ts +3 -3
- package/esm/editor/countInfoExtra.js +2 -0
- package/esm/editor/icon/add.js +1 -1
- package/esm/editor/index.d.ts +5 -2
- package/esm/editor/value.js +74 -58
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -123,6 +123,7 @@ const customTheme = {
|
|
|
123
123
|
'--w-rjv-line-color': '#323232',
|
|
124
124
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
125
125
|
'--w-rjv-edit-color': 'var(--w-rjv-color)',
|
|
126
|
+
'--w-rjv-add-color': 'var(--w-rjv-color)',
|
|
126
127
|
'--w-rjv-info-color': '#656565',
|
|
127
128
|
'--w-rjv-update-color': '#ebcb8b',
|
|
128
129
|
'--w-rjv-copied-color': '#9cdcfe',
|
|
@@ -187,7 +188,8 @@ const customTheme = {
|
|
|
187
188
|
'--w-rjv-background-color': '#1e1e1e',
|
|
188
189
|
'--w-rjv-line-color': '#323232',
|
|
189
190
|
'--w-rjv-arrow-color': '#9cdcfe',
|
|
190
|
-
'--w-rjv-edit-color': '#
|
|
191
|
+
'--w-rjv-edit-color': '#0184a6',
|
|
192
|
+
'--w-rjv-add-color': '#0184a6',
|
|
191
193
|
'--w-rjv-info-color': '#656565',
|
|
192
194
|
'--w-rjv-update-color': '#ebcb8b',
|
|
193
195
|
'--w-rjv-copied-color': '#0184a6',
|
|
@@ -237,7 +239,18 @@ export default function Demo() {
|
|
|
237
239
|
<input type="checkbox" checked={editable} onChange={changeEditable} /> Editable
|
|
238
240
|
</label>
|
|
239
241
|
<div style={{ display: 'flex', gap: '1rem', alignItems: 'flex-start' }}>
|
|
240
|
-
<JsonView
|
|
242
|
+
<JsonView
|
|
243
|
+
editable={editable}
|
|
244
|
+
value={src}
|
|
245
|
+
keyName="root"
|
|
246
|
+
onAdd={(keyOrValue, newValue, value, isAdd) => {
|
|
247
|
+
return isAdd;
|
|
248
|
+
}}
|
|
249
|
+
onEdit={(opts) => {
|
|
250
|
+
return true;
|
|
251
|
+
}}
|
|
252
|
+
style={{ flex: 1, overflow: 'auto', ...theme }}
|
|
253
|
+
/>
|
|
241
254
|
<div>
|
|
242
255
|
<Colorful color={hex} onChange={onChange} />
|
|
243
256
|
<div style={{ display: 'flex', gap: '0.4rem', flexDirection: 'column' }}>
|
|
@@ -247,7 +260,7 @@ export default function Demo() {
|
|
|
247
260
|
setHex(customTheme[varname]);
|
|
248
261
|
};
|
|
249
262
|
const active = cssvar === varname ? '#a8a8a8' : '';
|
|
250
|
-
return <button key={idx} style={{ background: active }} onClick={click}>{varname}</button>
|
|
263
|
+
return <button key={idx} style={{ background: active, border: 0,boxShadow: 'inset 0px 0px 1px #000' }} onClick={click}>{varname}</button>
|
|
251
264
|
})}
|
|
252
265
|
</div>
|
|
253
266
|
</div>
|
|
@@ -730,14 +743,17 @@ export interface CountInfoProps {
|
|
|
730
743
|
import { JsonViewProps } from '@uiw/react-json-view';
|
|
731
744
|
import type { CountInfoExtraProps } from '@uiw/react-json-view/cjs/editor/countInfoExtra';
|
|
732
745
|
export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
|
|
733
|
-
/**
|
|
746
|
+
/**
|
|
747
|
+
* When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
|
|
748
|
+
* @returns {boolean} Returning false from onEdit will prevent the change from being made.
|
|
749
|
+
*/
|
|
734
750
|
onEdit?: (option: {
|
|
735
751
|
value: unknown;
|
|
736
752
|
oldValue: unknown;
|
|
737
753
|
keyName?: string | number;
|
|
738
754
|
parentName?: string | number;
|
|
739
755
|
type?: 'value' | 'key';
|
|
740
|
-
}) =>
|
|
756
|
+
}) => boolean;
|
|
741
757
|
/**
|
|
742
758
|
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
743
759
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { CountInfoProps } from '../';
|
|
3
|
-
export interface CountInfoExtraProps<T> extends CountInfoProps {
|
|
3
|
+
export interface CountInfoExtraProps<T> extends Partial<CountInfoProps> {
|
|
4
4
|
editable: boolean;
|
|
5
5
|
showTools: boolean;
|
|
6
6
|
value: T;
|
|
7
|
-
setValue
|
|
7
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
8
8
|
/**
|
|
9
9
|
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
10
10
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
11
11
|
*/
|
|
12
12
|
onAdd?: (keyOrValue: string, newValue: T, value: T, isAdd: boolean) => boolean;
|
|
13
13
|
}
|
|
14
|
-
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
@@ -15,6 +15,7 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
15
15
|
function CountInfoExtra(props) {
|
|
16
16
|
var visible = props.visible,
|
|
17
17
|
showTools = props.showTools,
|
|
18
|
+
editable = props.editable,
|
|
18
19
|
value = props.value,
|
|
19
20
|
setValue = props.setValue,
|
|
20
21
|
onAdd = props.onAdd;
|
|
@@ -54,5 +55,6 @@ function CountInfoExtra(props) {
|
|
|
54
55
|
var svgProps = {
|
|
55
56
|
onClick: click
|
|
56
57
|
};
|
|
58
|
+
if (!editable || !onAdd) return;
|
|
57
59
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_add.AddIcon, (0, _objectSpread3["default"])({}, svgProps));
|
|
58
60
|
}
|
package/cjs/editor/icon/add.js
CHANGED
|
@@ -19,7 +19,7 @@ var AddIcon = function AddIcon(props) {
|
|
|
19
19
|
};
|
|
20
20
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
21
21
|
viewBox: "0 0 20 20",
|
|
22
|
-
fill: "var(--w-rjv-
|
|
22
|
+
fill: "var(--w-rjv-add-color, currentColor)"
|
|
23
23
|
}, props), {}, {
|
|
24
24
|
style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), defaultStyle),
|
|
25
25
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
|
package/cjs/editor/index.d.ts
CHANGED
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
import type { JsonViewProps } from '../';
|
|
3
3
|
import type { CountInfoExtraProps } from './countInfoExtra';
|
|
4
4
|
export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
|
|
7
|
+
* @returns {boolean} Returning false from onEdit will prevent the change from being made.
|
|
8
|
+
*/
|
|
6
9
|
onEdit?: (option: {
|
|
7
10
|
value: unknown;
|
|
8
11
|
oldValue: unknown;
|
|
9
12
|
keyName?: string | number;
|
|
10
13
|
parentName?: string | number;
|
|
11
14
|
type?: 'value' | 'key';
|
|
12
|
-
}) =>
|
|
15
|
+
}) => boolean;
|
|
13
16
|
/**
|
|
14
17
|
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
15
18
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
package/cjs/editor/value.js
CHANGED
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.ReValue = ReValue;
|
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
9
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
13
|
var _react = require("react");
|
|
@@ -71,60 +73,96 @@ function ReValue(props) {
|
|
|
71
73
|
$edit.current.contentEditable = 'false';
|
|
72
74
|
}
|
|
73
75
|
};
|
|
74
|
-
var blur = function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
76
|
+
var blur = /*#__PURE__*/function () {
|
|
77
|
+
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
|
|
78
|
+
var text, _typeStr, dt, result, _getValueString, oldChildStr;
|
|
79
|
+
return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
|
|
80
|
+
while (1) switch (_context.prev = _context.next) {
|
|
81
|
+
case 0:
|
|
82
|
+
if (editableValue) {
|
|
83
|
+
_context.next = 2;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
return _context.abrupt("return");
|
|
87
|
+
case 2:
|
|
88
|
+
setEditable(false);
|
|
89
|
+
if (!$edit.current) {
|
|
90
|
+
_context.next = 16;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
$edit.current.contentEditable = 'false';
|
|
94
|
+
text = $edit.current.innerText;
|
|
95
|
+
_typeStr = curentType;
|
|
96
|
+
if (curentType === 'number' || curentType === 'float') {
|
|
97
|
+
text = Number(text);
|
|
98
|
+
_typeStr = (0, _value.isFloat)(text) ? 'float' : 'number';
|
|
99
|
+
}
|
|
100
|
+
if (curentType === 'url' && typeof text === 'string') {
|
|
101
|
+
text = new URL(text);
|
|
102
|
+
_typeStr = 'url';
|
|
103
|
+
}
|
|
104
|
+
if (Number.isNaN(text)) {
|
|
105
|
+
_typeStr = 'number';
|
|
106
|
+
}
|
|
107
|
+
if (typeof text === 'string' && /^(true|false)$/ig.test(text)) {
|
|
108
|
+
text = /^(true)$/ig.test(text) ? true : false;
|
|
109
|
+
_typeStr = 'boolean';
|
|
110
|
+
} else if (typeof text === 'string' && /^[\d]+n$/ig.test(text)) {
|
|
111
|
+
text = BigInt(text.replace(/n$/ig, ''));
|
|
112
|
+
_typeStr = 'bigint';
|
|
113
|
+
} else if (typeof text === 'string' && /^(null)$/ig.test(text)) {
|
|
114
|
+
text = null;
|
|
115
|
+
_typeStr = 'null';
|
|
116
|
+
} else if (typeof text === 'string' && /^(undefined)$/ig.test(text)) {
|
|
117
|
+
text = undefined;
|
|
118
|
+
_typeStr = 'undefined';
|
|
119
|
+
} else if (typeof text === 'string') {
|
|
120
|
+
try {
|
|
121
|
+
if (text && text.length > 10 && !isNaN(Date.parse(text))) {
|
|
122
|
+
dt = new Date(text);
|
|
123
|
+
text = dt;
|
|
124
|
+
_typeStr = 'date';
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {}
|
|
127
|
+
}
|
|
128
|
+
if (!onEdit) {
|
|
129
|
+
_context.next = 16;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
_context.next = 14;
|
|
133
|
+
return onEdit({
|
|
134
|
+
type: 'value',
|
|
135
|
+
value: text,
|
|
136
|
+
oldValue: curentChild
|
|
137
|
+
});
|
|
138
|
+
case 14:
|
|
139
|
+
result = _context.sent;
|
|
140
|
+
if (result) {
|
|
141
|
+
setCurentType(_typeStr);
|
|
142
|
+
setCurentChild(text);
|
|
143
|
+
} else {
|
|
144
|
+
_getValueString = (0, _value.getValueString)(curentChild), oldChildStr = _getValueString.content;
|
|
145
|
+
$edit.current.innerHTML = String(oldChildStr);
|
|
146
|
+
}
|
|
147
|
+
case 16:
|
|
148
|
+
case "end":
|
|
149
|
+
return _context.stop();
|
|
150
|
+
}
|
|
151
|
+
}, _callee);
|
|
152
|
+
}));
|
|
153
|
+
return function blur() {
|
|
154
|
+
return _ref2.apply(this, arguments);
|
|
155
|
+
};
|
|
156
|
+
}();
|
|
119
157
|
var defaultStyle = {
|
|
120
158
|
minWidth: 34,
|
|
121
159
|
minHeight: 18,
|
|
122
160
|
paddingInline: 3,
|
|
123
161
|
display: 'inline-block'
|
|
124
162
|
};
|
|
125
|
-
var
|
|
126
|
-
typeStr =
|
|
127
|
-
childStr =
|
|
163
|
+
var _getValueString2 = (0, _value.getValueString)(curentChild),
|
|
164
|
+
typeStr = _getValueString2.type,
|
|
165
|
+
childStr = _getValueString2.content;
|
|
128
166
|
var color = ((_typeMap$typeStr = _value.typeMap[typeStr]) === null || _typeMap$typeStr === void 0 ? void 0 : _typeMap$typeStr.color) || '';
|
|
129
167
|
var spanProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
130
168
|
onBlur: blur,
|
|
@@ -143,21 +181,19 @@ function ReValue(props) {
|
|
|
143
181
|
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
144
182
|
}
|
|
145
183
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
146
|
-
children: [displayDataTypes && typeView, /*#__PURE__*/(0, _jsxRuntime.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
})]
|
|
160
|
-
}), visible && editableValue && /*#__PURE__*/(0, _jsxRuntime.jsx)(_edit.EditIcon, {
|
|
184
|
+
children: [displayDataTypes && typeView, /*#__PURE__*/(0, _jsxRuntime.jsx)(Quotes, {
|
|
185
|
+
style: style,
|
|
186
|
+
quotes: quotes,
|
|
187
|
+
show: typeStr === 'string'
|
|
188
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, spanProps), {}, {
|
|
189
|
+
ref: $edit,
|
|
190
|
+
"data-value": childStr,
|
|
191
|
+
children: typeof curentChild === 'string' ? curentChild : childStr
|
|
192
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(Quotes, {
|
|
193
|
+
style: style,
|
|
194
|
+
quotes: quotes,
|
|
195
|
+
show: typeStr === 'string'
|
|
196
|
+
}), visible && editableValue && onEdit && /*#__PURE__*/(0, _jsxRuntime.jsx)(_edit.EditIcon, {
|
|
161
197
|
onClick: click
|
|
162
198
|
})]
|
|
163
199
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { CountInfoProps } from '../';
|
|
3
|
-
export interface CountInfoExtraProps<T> extends CountInfoProps {
|
|
3
|
+
export interface CountInfoExtraProps<T> extends Partial<CountInfoProps> {
|
|
4
4
|
editable: boolean;
|
|
5
5
|
showTools: boolean;
|
|
6
6
|
value: T;
|
|
7
|
-
setValue
|
|
7
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
8
8
|
/**
|
|
9
9
|
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
10
10
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
11
11
|
*/
|
|
12
12
|
onAdd?: (keyOrValue: string, newValue: T, value: T, isAdd: boolean) => boolean;
|
|
13
13
|
}
|
|
14
|
-
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
@@ -6,6 +6,7 @@ export function CountInfoExtra(props) {
|
|
|
6
6
|
var {
|
|
7
7
|
visible,
|
|
8
8
|
showTools,
|
|
9
|
+
editable,
|
|
9
10
|
value,
|
|
10
11
|
setValue,
|
|
11
12
|
onAdd
|
|
@@ -34,5 +35,6 @@ export function CountInfoExtra(props) {
|
|
|
34
35
|
var svgProps = {
|
|
35
36
|
onClick: click
|
|
36
37
|
};
|
|
38
|
+
if (!editable || !onAdd) return;
|
|
37
39
|
return /*#__PURE__*/_jsx(AddIcon, _extends({}, svgProps));
|
|
38
40
|
}
|
package/esm/editor/icon/add.js
CHANGED
|
@@ -14,7 +14,7 @@ export var AddIcon = props => {
|
|
|
14
14
|
};
|
|
15
15
|
return /*#__PURE__*/_jsx("svg", _extends({
|
|
16
16
|
viewBox: "0 0 20 20",
|
|
17
|
-
fill: "var(--w-rjv-
|
|
17
|
+
fill: "var(--w-rjv-add-color, currentColor)"
|
|
18
18
|
}, props, {
|
|
19
19
|
style: _extends({}, style, defaultStyle),
|
|
20
20
|
children: /*#__PURE__*/_jsx("path", {
|
package/esm/editor/index.d.ts
CHANGED
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
import type { JsonViewProps } from '../';
|
|
3
3
|
import type { CountInfoExtraProps } from './countInfoExtra';
|
|
4
4
|
export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
|
|
7
|
+
* @returns {boolean} Returning false from onEdit will prevent the change from being made.
|
|
8
|
+
*/
|
|
6
9
|
onEdit?: (option: {
|
|
7
10
|
value: unknown;
|
|
8
11
|
oldValue: unknown;
|
|
9
12
|
keyName?: string | number;
|
|
10
13
|
parentName?: string | number;
|
|
11
14
|
type?: 'value' | 'key';
|
|
12
|
-
}) =>
|
|
15
|
+
}) => boolean;
|
|
13
16
|
/**
|
|
14
17
|
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
15
18
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
package/esm/editor/value.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
4
|
var _excluded = ["type", "value", "keyName", "visible", "quotes", "style", "children", "displayDataTypes", "editableValue", "onEdit"];
|
|
4
5
|
import { Fragment, useEffect, useRef, useState } from 'react';
|
|
@@ -55,51 +56,68 @@ export function ReValue(props) {
|
|
|
55
56
|
$edit.current.contentEditable = 'false';
|
|
56
57
|
}
|
|
57
58
|
};
|
|
58
|
-
var blur = ()
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
$edit.current
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
59
|
+
var blur = /*#__PURE__*/function () {
|
|
60
|
+
var _ref2 = _asyncToGenerator(function* () {
|
|
61
|
+
if (!editableValue) return;
|
|
62
|
+
setEditable(false);
|
|
63
|
+
if ($edit.current) {
|
|
64
|
+
$edit.current.contentEditable = 'false';
|
|
65
|
+
var text = $edit.current.innerText;
|
|
66
|
+
var _typeStr = curentType;
|
|
67
|
+
if (curentType === 'number' || curentType === 'float') {
|
|
68
|
+
text = Number(text);
|
|
69
|
+
_typeStr = isFloat(text) ? 'float' : 'number';
|
|
70
|
+
}
|
|
71
|
+
if (curentType === 'url' && typeof text === 'string') {
|
|
72
|
+
text = new URL(text);
|
|
73
|
+
_typeStr = 'url';
|
|
74
|
+
}
|
|
75
|
+
if (Number.isNaN(text)) {
|
|
76
|
+
_typeStr = 'number';
|
|
77
|
+
}
|
|
78
|
+
if (typeof text === 'string' && /^(true|false)$/ig.test(text)) {
|
|
79
|
+
text = /^(true)$/ig.test(text) ? true : false;
|
|
80
|
+
_typeStr = 'boolean';
|
|
81
|
+
} else if (typeof text === 'string' && /^[\d]+n$/ig.test(text)) {
|
|
82
|
+
text = BigInt(text.replace(/n$/ig, ''));
|
|
83
|
+
_typeStr = 'bigint';
|
|
84
|
+
} else if (typeof text === 'string' && /^(null)$/ig.test(text)) {
|
|
85
|
+
text = null;
|
|
86
|
+
_typeStr = 'null';
|
|
87
|
+
} else if (typeof text === 'string' && /^(undefined)$/ig.test(text)) {
|
|
88
|
+
text = undefined;
|
|
89
|
+
_typeStr = 'undefined';
|
|
90
|
+
} else if (typeof text === 'string') {
|
|
91
|
+
try {
|
|
92
|
+
if (text && text.length > 10 && !isNaN(Date.parse(text))) {
|
|
93
|
+
var dt = new Date(text);
|
|
94
|
+
text = dt;
|
|
95
|
+
_typeStr = 'date';
|
|
96
|
+
}
|
|
97
|
+
} catch (error) {}
|
|
98
|
+
}
|
|
99
|
+
if (onEdit) {
|
|
100
|
+
var result = yield onEdit({
|
|
101
|
+
type: 'value',
|
|
102
|
+
value: text,
|
|
103
|
+
oldValue: curentChild
|
|
104
|
+
});
|
|
105
|
+
if (result) {
|
|
106
|
+
setCurentType(_typeStr);
|
|
107
|
+
setCurentChild(text);
|
|
108
|
+
} else {
|
|
109
|
+
var {
|
|
110
|
+
content: oldChildStr
|
|
111
|
+
} = getValueString(curentChild);
|
|
112
|
+
$edit.current.innerHTML = String(oldChildStr);
|
|
92
113
|
}
|
|
93
|
-
}
|
|
114
|
+
}
|
|
94
115
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
};
|
|
116
|
+
});
|
|
117
|
+
return function blur() {
|
|
118
|
+
return _ref2.apply(this, arguments);
|
|
119
|
+
};
|
|
120
|
+
}();
|
|
103
121
|
var defaultStyle = {
|
|
104
122
|
minWidth: 34,
|
|
105
123
|
minHeight: 18,
|
|
@@ -128,21 +146,19 @@ export function ReValue(props) {
|
|
|
128
146
|
typeView = /*#__PURE__*/_jsx(Fragment, {});
|
|
129
147
|
}
|
|
130
148
|
return /*#__PURE__*/_jsxs(Fragment, {
|
|
131
|
-
children: [displayDataTypes && typeView, /*#__PURE__*/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
})]
|
|
145
|
-
}), visible && editableValue && /*#__PURE__*/_jsx(EditIcon, {
|
|
149
|
+
children: [displayDataTypes && typeView, /*#__PURE__*/_jsx(Quotes, {
|
|
150
|
+
style: style,
|
|
151
|
+
quotes: quotes,
|
|
152
|
+
show: typeStr === 'string'
|
|
153
|
+
}), /*#__PURE__*/_jsx("span", _extends({}, spanProps, {
|
|
154
|
+
ref: $edit,
|
|
155
|
+
"data-value": childStr,
|
|
156
|
+
children: typeof curentChild === 'string' ? curentChild : childStr
|
|
157
|
+
})), /*#__PURE__*/_jsx(Quotes, {
|
|
158
|
+
style: style,
|
|
159
|
+
quotes: quotes,
|
|
160
|
+
show: typeStr === 'string'
|
|
161
|
+
}), visible && editableValue && onEdit && /*#__PURE__*/_jsx(EditIcon, {
|
|
146
162
|
onClick: click
|
|
147
163
|
})]
|
|
148
164
|
});
|