fan-standard-comp 4.1.49 → 4.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fan-standard-comp.min.js +1 -1
- package/es/ButtonGroup/index.js +8 -3
- package/es/ButtonGroup/styles/index.js +35 -2
- package/es/FormComp/FieldComponent/index.js +8 -0
- package/es/FormComp/JsonInput/index.d.ts +39 -0
- package/es/FormComp/JsonInput/index.js +279 -0
- package/es/FormComp/JsonInput/styles/index.d.ts +6 -0
- package/es/FormComp/JsonInput/styles/index.js +71 -0
- package/es/FormComp/Uploader/index.js +108 -98
- package/es/FormComp/index.d.ts +1 -0
- package/es/FormComp/index.js +2 -1
- package/es/StandardFilter/index.js +83 -96
- package/es/StandardFilter/index222.d.ts +29 -0
- package/es/StandardFilter/index222.js +571 -0
- package/es/StandardFilter/indexOld.d.ts +29 -0
- package/es/StandardFilter/indexOld.js +597 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/locales/bn-BD/settings.d.ts +7 -0
- package/es/locales/bn-BD/settings.js +7 -0
- package/es/locales/bn-BD.d.ts +7 -0
- package/es/locales/en-US/settings.d.ts +7 -0
- package/es/locales/en-US/settings.js +7 -0
- package/es/locales/en-US.d.ts +7 -0
- package/es/locales/fa-IR/settings.d.ts +7 -0
- package/es/locales/fa-IR/settings.js +7 -0
- package/es/locales/fa-IR.d.ts +7 -0
- package/es/locales/id-ID/settings.d.ts +7 -0
- package/es/locales/id-ID/settings.js +7 -0
- package/es/locales/id-ID.d.ts +7 -0
- package/es/locales/ja-JP/settings.d.ts +7 -0
- package/es/locales/ja-JP/settings.js +9 -2
- package/es/locales/ja-JP.d.ts +7 -0
- package/es/locales/pt-BR/settings.d.ts +7 -0
- package/es/locales/pt-BR/settings.js +7 -0
- package/es/locales/pt-BR.d.ts +7 -0
- package/es/locales/zh-CN/settings.d.ts +7 -0
- package/es/locales/zh-CN/settings.js +7 -0
- package/es/locales/zh-CN.d.ts +7 -0
- package/es/locales/zh-TW/settings.d.ts +7 -0
- package/es/locales/zh-TW/settings.js +8 -1
- package/es/locales/zh-TW.d.ts +7 -0
- package/lib/ButtonGroup/index.js +8 -3
- package/lib/ButtonGroup/styles/index.js +35 -2
- package/lib/FormComp/FieldComponent/index.js +8 -0
- package/lib/FormComp/JsonInput/index.d.ts +39 -0
- package/lib/FormComp/JsonInput/index.js +288 -0
- package/lib/FormComp/JsonInput/styles/index.d.ts +6 -0
- package/lib/FormComp/JsonInput/styles/index.js +77 -0
- package/lib/FormComp/Uploader/index.js +108 -98
- package/lib/FormComp/index.d.ts +1 -0
- package/lib/FormComp/index.js +7 -0
- package/lib/StandardFilter/index.js +83 -96
- package/lib/StandardFilter/index222.d.ts +29 -0
- package/lib/StandardFilter/index222.js +579 -0
- package/lib/StandardFilter/indexOld.d.ts +29 -0
- package/lib/StandardFilter/indexOld.js +605 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -0
- package/lib/locales/bn-BD/settings.d.ts +7 -0
- package/lib/locales/bn-BD/settings.js +7 -0
- package/lib/locales/bn-BD.d.ts +7 -0
- package/lib/locales/en-US/settings.d.ts +7 -0
- package/lib/locales/en-US/settings.js +7 -0
- package/lib/locales/en-US.d.ts +7 -0
- package/lib/locales/fa-IR/settings.d.ts +7 -0
- package/lib/locales/fa-IR/settings.js +7 -0
- package/lib/locales/fa-IR.d.ts +7 -0
- package/lib/locales/id-ID/settings.d.ts +7 -0
- package/lib/locales/id-ID/settings.js +7 -0
- package/lib/locales/id-ID.d.ts +7 -0
- package/lib/locales/ja-JP/settings.d.ts +7 -0
- package/lib/locales/ja-JP/settings.js +9 -2
- package/lib/locales/ja-JP.d.ts +7 -0
- package/lib/locales/pt-BR/settings.d.ts +7 -0
- package/lib/locales/pt-BR/settings.js +7 -0
- package/lib/locales/pt-BR.d.ts +7 -0
- package/lib/locales/zh-CN/settings.d.ts +7 -0
- package/lib/locales/zh-CN/settings.js +7 -0
- package/lib/locales/zh-CN.d.ts +7 -0
- package/lib/locales/zh-TW/settings.d.ts +7 -0
- package/lib/locales/zh-TW/settings.js +8 -1
- package/lib/locales/zh-TW.d.ts +7 -0
- package/package.json +1 -1
package/es/ButtonGroup/index.js
CHANGED
|
@@ -128,6 +128,7 @@ var ButtonGroup = function ButtonGroup(props) {
|
|
|
128
128
|
others = _objectWithoutProperties(vItem, _excluded);
|
|
129
129
|
var uniqueId = "".concat(Date.now(), "_").concat(Math.random().toString(36).substr(2, 9));
|
|
130
130
|
return _objectSpread(_objectSpread({}, others), {}, {
|
|
131
|
+
popupClassName: 'spec-button-group-dropdown-submenu button-menus',
|
|
131
132
|
key: code ? code + i + uniqueId : i + uniqueId,
|
|
132
133
|
// // 使用 useRef 保持 ID 的稳定性(只在组件挂载时生成一次)
|
|
133
134
|
// icon: icon ? <IconNode icon={icon} style={{ marginRight: '4px' }}/> : null,
|
|
@@ -198,6 +199,7 @@ var ButtonGroup = function ButtonGroup(props) {
|
|
|
198
199
|
others = _objectWithoutProperties(vItem, _excluded2);
|
|
199
200
|
var uniqueId = "".concat(Date.now(), "_").concat(Math.random().toString(36).substr(2, 9));
|
|
200
201
|
return {
|
|
202
|
+
popupClassName: 'spec-button-group-dropdown-submenu text-menus',
|
|
201
203
|
danger: others.danger,
|
|
202
204
|
disabled: btnIsDisabled(others.disabled, rowParams),
|
|
203
205
|
key: code ? code + i + uniqueId : i + uniqueId,
|
|
@@ -291,13 +293,14 @@ var ButtonGroup = function ButtonGroup(props) {
|
|
|
291
293
|
menu: {
|
|
292
294
|
items: type === 'button' ? deepTransButtonMenus(item.children) : deepTransTextMenus(item.children)
|
|
293
295
|
},
|
|
294
|
-
placement: "bottomRight"
|
|
296
|
+
placement: "bottomRight",
|
|
297
|
+
overlayClassName: 'spec-button-group-dropdown'
|
|
295
298
|
}, (item === null || item === void 0 ? void 0 : item.dropdownConfig) || dropdownConfig || {}), type === 'button' ? /*#__PURE__*/React.createElement(Button, {
|
|
296
299
|
type: "primary",
|
|
297
300
|
size: size,
|
|
298
301
|
onClick: function onClick(event) {
|
|
299
302
|
var _item$fn;
|
|
300
|
-
event.preventDefault()
|
|
303
|
+
// event.preventDefault()
|
|
301
304
|
item === null || item === void 0 || (_item$fn = item.fn) === null || _item$fn === void 0 || _item$fn.call(item, _objectSpread(_objectSpread({}, item), {}, {
|
|
302
305
|
event: event,
|
|
303
306
|
rowParams: rowParams
|
|
@@ -306,7 +309,7 @@ var ButtonGroup = function ButtonGroup(props) {
|
|
|
306
309
|
}, renderCustomLabel(item, false), " ", item.hasOwnProperty('moreIcon') ? item.moreIcon : /*#__PURE__*/React.createElement(DownOutlined, null)) : /*#__PURE__*/React.createElement("a", {
|
|
307
310
|
className: 'spec-button-group-text',
|
|
308
311
|
onClick: function onClick(event) {
|
|
309
|
-
event.preventDefault()
|
|
312
|
+
// event.preventDefault()
|
|
310
313
|
if (type === 'action') {
|
|
311
314
|
var _item$fn2;
|
|
312
315
|
item === null || item === void 0 || (_item$fn2 = item.fn) === null || _item$fn2 === void 0 || _item$fn2.call.apply(_item$fn2, [item].concat(_toConsumableArray(Object.keys(rowParams).map(function (pItem) {
|
|
@@ -533,6 +536,7 @@ var ButtonGroup = function ButtonGroup(props) {
|
|
|
533
536
|
menu: {
|
|
534
537
|
items: deepTransButtonMenus(forDrop)
|
|
535
538
|
},
|
|
539
|
+
overlayClassName: 'spec-button-group-dropdown',
|
|
536
540
|
placement: "bottomRight"
|
|
537
541
|
}, dropdownConfig), /*#__PURE__*/React.createElement(Button, {
|
|
538
542
|
type: "primary",
|
|
@@ -541,6 +545,7 @@ var ButtonGroup = function ButtonGroup(props) {
|
|
|
541
545
|
menu: {
|
|
542
546
|
items: deepTransTextMenus(forDrop)
|
|
543
547
|
},
|
|
548
|
+
overlayClassName: 'spec-button-group-dropdown',
|
|
544
549
|
placement: "bottomRight"
|
|
545
550
|
}, dropdownConfig), /*#__PURE__*/React.createElement("a", {
|
|
546
551
|
className: 'spec-button-group-text'
|
|
@@ -12,7 +12,7 @@ export var prepareComponentToken = function prepareComponentToken(token) {
|
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
var SpecButtonGroupTextStyle = function SpecButtonGroupTextStyle(prefixCls, token) {
|
|
15
|
-
return _defineProperty({}, ".".concat(prefixCls, "-text"), _defineProperty(_defineProperty({
|
|
15
|
+
return _defineProperty(_defineProperty({}, ".".concat(prefixCls, "-text"), _defineProperty(_defineProperty(_defineProperty({
|
|
16
16
|
position: 'relative',
|
|
17
17
|
display: 'inline-block',
|
|
18
18
|
cursor: 'pointer',
|
|
@@ -35,6 +35,8 @@ var SpecButtonGroupTextStyle = function SpecButtonGroupTextStyle(prefixCls, toke
|
|
|
35
35
|
// verticalAlign: 'middle',
|
|
36
36
|
// borderLeft: `1px solid ${token.colorBorder}`
|
|
37
37
|
// }
|
|
38
|
+
}), '.spec-button-group-label', {
|
|
39
|
+
display: 'block'
|
|
38
40
|
}), '& > .spec-button-group-label ', {
|
|
39
41
|
display: 'inline-flex !important',
|
|
40
42
|
alignItems: 'center',
|
|
@@ -42,7 +44,14 @@ var SpecButtonGroupTextStyle = function SpecButtonGroupTextStyle(prefixCls, toke
|
|
|
42
44
|
'.spec-icon': {
|
|
43
45
|
fontSize: '14px'
|
|
44
46
|
}
|
|
45
|
-
}))
|
|
47
|
+
})), '.spec-button-group-label', {
|
|
48
|
+
display: 'inline-flex !important',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
gap: '4px',
|
|
51
|
+
'.spec-icon': {
|
|
52
|
+
fontSize: '14px'
|
|
53
|
+
}
|
|
54
|
+
});
|
|
46
55
|
};
|
|
47
56
|
var SpecButtonGroupStyleFunc = function SpecButtonGroupStyleFunc(prefix) {
|
|
48
57
|
return createStyleHook(prefix, function (token) {
|
|
@@ -65,6 +74,30 @@ var SpecButtonGroupStyleFunc = function SpecButtonGroupStyleFunc(prefix) {
|
|
|
65
74
|
}
|
|
66
75
|
}
|
|
67
76
|
}, SpecButtonGroupTextStyle(prefixCls, SpecButtonGroupToken))), {
|
|
77
|
+
'.spec-button-group-dropdown, .spec-button-group-dropdown-submenu': {
|
|
78
|
+
// backgroundColor: token.colorPrimary,
|
|
79
|
+
'.ant-dropdown-menu-item': {
|
|
80
|
+
padding: '0 !important'
|
|
81
|
+
},
|
|
82
|
+
'.ant-dropdown-menu-submenu-title': {
|
|
83
|
+
alignItems: 'center',
|
|
84
|
+
paddingBlock: '0 !important',
|
|
85
|
+
paddingInlineStart: '0 !important'
|
|
86
|
+
},
|
|
87
|
+
'.spec-button-group-label ': {
|
|
88
|
+
// backgroundColor: 'rgba(255, 155, 155, 0.5)',
|
|
89
|
+
width: '100%',
|
|
90
|
+
padding: "5px ".concat(token.paddingSM, "px"),
|
|
91
|
+
boxSizing: 'border-box',
|
|
92
|
+
display: 'flex !important',
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
gap: '4px',
|
|
95
|
+
'.spec-icon': {
|
|
96
|
+
fontSize: '14px'
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
68
101
|
'.ant-dropdown-menu-item': {
|
|
69
102
|
background: '#f00',
|
|
70
103
|
'.spec-icon + .ant-dropdown-menu-title-content': {
|
|
@@ -13,6 +13,7 @@ import SpecIcon from "../../SpecIcon";
|
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
import RefactorTreeSelect from "./RefactorTreeSelect";
|
|
15
15
|
import DateTimeRangePicker from "../DateTimeRangePicker";
|
|
16
|
+
import JsonInput from "../JsonInput";
|
|
16
17
|
// @ts-ignore
|
|
17
18
|
import { setSelectValue, setDatePickerValue, setTimePickerValue, setCascaderValue, setInputValue } from "./setReadonlyValues";
|
|
18
19
|
import TitleNode from "./TitleNode";
|
|
@@ -161,6 +162,13 @@ var FieldComponent = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
161
162
|
style: _objectSpread(_objectSpread({}, defaultStyle), defaultProps.style)
|
|
162
163
|
}));
|
|
163
164
|
break;
|
|
165
|
+
case 'jsonInput':
|
|
166
|
+
compContent = /*#__PURE__*/React.createElement(JsonInput, _extends({}, defaultProps, {
|
|
167
|
+
fieldStatus: fieldStatus,
|
|
168
|
+
placeholder: defaultProps.placeholder || placeholder,
|
|
169
|
+
style: _objectSpread(_objectSpread({}, defaultStyle), defaultProps.style)
|
|
170
|
+
}));
|
|
171
|
+
break;
|
|
164
172
|
case 'inputNumber':
|
|
165
173
|
compContent = viewOnly ? setInputValue(value, _objectSpread(_objectSpread({}, defaultProps), {}, {
|
|
166
174
|
type: type
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JsonInput JSON 输入控件
|
|
3
|
+
* 支持 JSON 格式校验、格式化、折叠/展开
|
|
4
|
+
* 兼容 FieldComponent 的 fieldStatus(default / disabled / viewOnly)
|
|
5
|
+
* 样式使用 CSS-in-JS(createStyleHook)
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
export interface JsonInputProps {
|
|
9
|
+
/** 当前值,支持 JSON 字符串或对象 */
|
|
10
|
+
value?: string | Record<string, any> | any[];
|
|
11
|
+
/** 值变化回调,返回 JSON 字符串 */
|
|
12
|
+
onChange?: (value: string) => void;
|
|
13
|
+
/** 控件尺寸 */
|
|
14
|
+
size?: 'large' | 'middle' | 'small';
|
|
15
|
+
/** 控件状态 */
|
|
16
|
+
fieldStatus?: 'default' | 'disabled' | 'viewOnly' | string;
|
|
17
|
+
/** placeholder */
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
/** textarea 行数 */
|
|
20
|
+
rows?: number;
|
|
21
|
+
/** 是否自动格式化(失焦时自动 format) */
|
|
22
|
+
autoFormat?: boolean;
|
|
23
|
+
/** 是否显示操作按钮(格式化 / 折叠) */
|
|
24
|
+
showActions?: boolean;
|
|
25
|
+
/** 是否显示校验状态图标 */
|
|
26
|
+
showStatus?: boolean;
|
|
27
|
+
/** 自定义样式 */
|
|
28
|
+
style?: React.CSSProperties;
|
|
29
|
+
className?: string;
|
|
30
|
+
/** 禁用 */
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/** 只读 */
|
|
33
|
+
readOnly?: boolean;
|
|
34
|
+
/** 最大输入长度 */
|
|
35
|
+
maxLength?: number;
|
|
36
|
+
[k: string]: any;
|
|
37
|
+
}
|
|
38
|
+
declare const JsonInput: React.ForwardRefExoticComponent<Omit<JsonInputProps, "ref"> & React.RefAttributes<any>>;
|
|
39
|
+
export default JsonInput;
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
/**
|
|
8
|
+
* JsonInput JSON 输入控件
|
|
9
|
+
* 支持 JSON 格式校验、格式化、折叠/展开
|
|
10
|
+
* 兼容 FieldComponent 的 fieldStatus(default / disabled / viewOnly)
|
|
11
|
+
* 样式使用 CSS-in-JS(createStyleHook)
|
|
12
|
+
*/
|
|
13
|
+
import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
|
14
|
+
import { Input, Button, Tooltip, Space } from 'antd';
|
|
15
|
+
import { CheckCircleOutlined, CloseCircleOutlined, FormatPainterOutlined, ExpandOutlined, CompressOutlined } from '@ant-design/icons';
|
|
16
|
+
import classNames from 'classnames';
|
|
17
|
+
import { useLanguageObject } from "../../hooks/use-language";
|
|
18
|
+
import useStyle from "./styles";
|
|
19
|
+
var TextArea = Input.TextArea;
|
|
20
|
+
var componentName = 'spec-json-input';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 将 value 转为字符串显示
|
|
24
|
+
*/
|
|
25
|
+
var valueToString = function valueToString(val) {
|
|
26
|
+
if (val === undefined || val === null) return '';
|
|
27
|
+
if (typeof val === 'string') return val;
|
|
28
|
+
try {
|
|
29
|
+
return JSON.stringify(val, null, 2);
|
|
30
|
+
} catch (_unused) {
|
|
31
|
+
return String(val);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 根据语言包获取 JSON 解析错误信息
|
|
37
|
+
* 通过 error instanceof SyntaxError 判断,匹配常见 JSON 解析错误类型并返回本地化提示
|
|
38
|
+
*/
|
|
39
|
+
var getJsonErrorMessage = function getJsonErrorMessage(error, lang) {
|
|
40
|
+
var defaultMsg = (lang === null || lang === void 0 ? void 0 : lang['field.jsonInput.error.default']) || 'JSON 格式无效';
|
|
41
|
+
if (error instanceof SyntaxError) {
|
|
42
|
+
var msg = error.message || '';
|
|
43
|
+
// 提取位置号(V8: "at position N",SpiderMonkey/Firefox 无统一格式)
|
|
44
|
+
var posMatch = /at position (\d+)/i.exec(msg) || /position (\d+)/i.exec(msg);
|
|
45
|
+
var position = posMatch ? posMatch[1] : '';
|
|
46
|
+
|
|
47
|
+
// JSON 输入意外结束
|
|
48
|
+
if (/unexpected end of json/i.test(msg) || /end of data/i.test(msg)) {
|
|
49
|
+
return (lang === null || lang === void 0 ? void 0 : lang['field.jsonInput.error.unexpectedEnd']) || 'JSON 输入意外结束';
|
|
50
|
+
}
|
|
51
|
+
// 字符串未闭合
|
|
52
|
+
if (/unterminated string/i.test(msg) || /unterminated/i.test(msg)) {
|
|
53
|
+
var template = (lang === null || lang === void 0 ? void 0 : lang['field.jsonInput.error.unterminatedString']) || '在位置 {position} 处字符串未闭合';
|
|
54
|
+
return position ? template.replace('{position}', position) : defaultMsg;
|
|
55
|
+
}
|
|
56
|
+
// 意外的标记(最常见的错误)
|
|
57
|
+
if (/unexpected token/i.test(msg) || /unexpected/i.test(msg)) {
|
|
58
|
+
var _template = (lang === null || lang === void 0 ? void 0 : lang['field.jsonInput.error.unexpectedToken']) || '在位置 {position} 处发现意外的标记';
|
|
59
|
+
return position ? _template.replace('{position}', position) : defaultMsg;
|
|
60
|
+
}
|
|
61
|
+
// 其他未知 SyntaxError
|
|
62
|
+
return defaultMsg;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 非 SyntaxError 的异常
|
|
66
|
+
if (error instanceof Error && error.message) {
|
|
67
|
+
return error.message;
|
|
68
|
+
}
|
|
69
|
+
return defaultMsg;
|
|
70
|
+
};
|
|
71
|
+
var JsonInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
72
|
+
var lang = useLanguageObject();
|
|
73
|
+
var _useStyle = useStyle(componentName),
|
|
74
|
+
_useStyle2 = _slicedToArray(_useStyle, 2),
|
|
75
|
+
wrapSSR = _useStyle2[0],
|
|
76
|
+
hashId = _useStyle2[1];
|
|
77
|
+
var value = props.value,
|
|
78
|
+
onChange = props.onChange,
|
|
79
|
+
_props$size = props.size,
|
|
80
|
+
size = _props$size === void 0 ? 'middle' : _props$size,
|
|
81
|
+
_props$fieldStatus = props.fieldStatus,
|
|
82
|
+
fieldStatus = _props$fieldStatus === void 0 ? 'default' : _props$fieldStatus,
|
|
83
|
+
placeholder = props.placeholder,
|
|
84
|
+
_props$rows = props.rows,
|
|
85
|
+
rows = _props$rows === void 0 ? 6 : _props$rows,
|
|
86
|
+
_props$autoFormat = props.autoFormat,
|
|
87
|
+
autoFormat = _props$autoFormat === void 0 ? false : _props$autoFormat,
|
|
88
|
+
_props$showActions = props.showActions,
|
|
89
|
+
showActions = _props$showActions === void 0 ? true : _props$showActions,
|
|
90
|
+
_props$showStatus = props.showStatus,
|
|
91
|
+
showStatus = _props$showStatus === void 0 ? true : _props$showStatus,
|
|
92
|
+
style = props.style,
|
|
93
|
+
className = props.className,
|
|
94
|
+
_props$disabled = props.disabled,
|
|
95
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
96
|
+
_props$readOnly = props.readOnly,
|
|
97
|
+
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
98
|
+
maxLength = props.maxLength;
|
|
99
|
+
var isDisabled = disabled || fieldStatus === 'disabled';
|
|
100
|
+
var isViewOnly = fieldStatus === 'viewOnly' || readOnly;
|
|
101
|
+
var _useState = useState(''),
|
|
102
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
103
|
+
inputValue = _useState2[0],
|
|
104
|
+
setInputValue = _useState2[1];
|
|
105
|
+
var _useState3 = useState(true),
|
|
106
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
107
|
+
isValid = _useState4[0],
|
|
108
|
+
setIsValid = _useState4[1];
|
|
109
|
+
var _useState5 = useState(''),
|
|
110
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
111
|
+
errorMsg = _useState6[0],
|
|
112
|
+
setErrorMsg = _useState6[1];
|
|
113
|
+
var _useState7 = useState(false),
|
|
114
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
115
|
+
isFormatted = _useState8[0],
|
|
116
|
+
setIsFormatted = _useState8[1];
|
|
117
|
+
|
|
118
|
+
// 外部 value 变化时同步内部状态
|
|
119
|
+
useEffect(function () {
|
|
120
|
+
var str = valueToString(value);
|
|
121
|
+
setInputValue(str);
|
|
122
|
+
if (str.trim() === '') {
|
|
123
|
+
setIsValid(true);
|
|
124
|
+
setErrorMsg('');
|
|
125
|
+
} else {
|
|
126
|
+
try {
|
|
127
|
+
JSON.parse(str);
|
|
128
|
+
setIsValid(true);
|
|
129
|
+
setErrorMsg('');
|
|
130
|
+
} catch (e) {
|
|
131
|
+
setIsValid(false);
|
|
132
|
+
setErrorMsg(getJsonErrorMessage(e, lang));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}, [value, lang]);
|
|
136
|
+
|
|
137
|
+
// 校验 JSON
|
|
138
|
+
var validateJson = useCallback(function (str) {
|
|
139
|
+
if (!str || str.trim() === '') {
|
|
140
|
+
setIsValid(true);
|
|
141
|
+
setErrorMsg('');
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
JSON.parse(str);
|
|
146
|
+
setIsValid(true);
|
|
147
|
+
setErrorMsg('');
|
|
148
|
+
return true;
|
|
149
|
+
} catch (e) {
|
|
150
|
+
setIsValid(false);
|
|
151
|
+
setErrorMsg(getJsonErrorMessage(e, lang));
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}, [lang]);
|
|
155
|
+
|
|
156
|
+
// 输入变化
|
|
157
|
+
var handleChange = useCallback(function (e) {
|
|
158
|
+
var val = e.target.value;
|
|
159
|
+
setInputValue(val);
|
|
160
|
+
validateJson(val);
|
|
161
|
+
if (onChange) onChange(val);
|
|
162
|
+
}, [onChange, validateJson]);
|
|
163
|
+
|
|
164
|
+
// 格式化
|
|
165
|
+
var handleFormat = useCallback(function () {
|
|
166
|
+
if (!inputValue || !inputValue.trim()) return;
|
|
167
|
+
try {
|
|
168
|
+
var parsed = JSON.parse(inputValue);
|
|
169
|
+
var formatted = JSON.stringify(parsed, null, 2);
|
|
170
|
+
setInputValue(formatted);
|
|
171
|
+
setIsValid(true);
|
|
172
|
+
setErrorMsg('');
|
|
173
|
+
setIsFormatted(true);
|
|
174
|
+
if (onChange) onChange(formatted);
|
|
175
|
+
} catch (e) {
|
|
176
|
+
setIsValid(false);
|
|
177
|
+
setErrorMsg(getJsonErrorMessage(e, lang));
|
|
178
|
+
}
|
|
179
|
+
}, [inputValue, onChange, lang]);
|
|
180
|
+
|
|
181
|
+
// 压缩(单行)
|
|
182
|
+
var handleCompress = useCallback(function () {
|
|
183
|
+
if (!inputValue || !inputValue.trim()) return;
|
|
184
|
+
try {
|
|
185
|
+
var parsed = JSON.parse(inputValue);
|
|
186
|
+
var compressed = JSON.stringify(parsed);
|
|
187
|
+
setInputValue(compressed);
|
|
188
|
+
setIsValid(true);
|
|
189
|
+
setErrorMsg('');
|
|
190
|
+
setIsFormatted(false);
|
|
191
|
+
if (onChange) onChange(compressed);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
setIsValid(false);
|
|
194
|
+
setErrorMsg(getJsonErrorMessage(e, lang));
|
|
195
|
+
}
|
|
196
|
+
}, [inputValue, onChange, lang]);
|
|
197
|
+
|
|
198
|
+
// 失焦校验(autoFormat 时自动格式化)
|
|
199
|
+
var handleBlur = useCallback(function () {
|
|
200
|
+
if (autoFormat && inputValue && inputValue.trim()) {
|
|
201
|
+
handleFormat();
|
|
202
|
+
} else {
|
|
203
|
+
validateJson(inputValue);
|
|
204
|
+
}
|
|
205
|
+
}, [autoFormat, inputValue, handleFormat, validateJson]);
|
|
206
|
+
var inputPlaceholder = placeholder || (lang === null || lang === void 0 ? void 0 : lang['field.jsonInput.placeholder']) || '请输入 JSON,例如: {"name": "John"}';
|
|
207
|
+
|
|
208
|
+
// 状态图标
|
|
209
|
+
var statusIcon = useMemo(function () {
|
|
210
|
+
if (!showStatus) return null;
|
|
211
|
+
if (!inputValue || inputValue.trim() === '') return null;
|
|
212
|
+
return isValid ? /*#__PURE__*/React.createElement(CheckCircleOutlined, {
|
|
213
|
+
style: {
|
|
214
|
+
color: '#52c41a'
|
|
215
|
+
}
|
|
216
|
+
}) : /*#__PURE__*/React.createElement(Tooltip, {
|
|
217
|
+
title: errorMsg
|
|
218
|
+
}, /*#__PURE__*/React.createElement(CloseCircleOutlined, {
|
|
219
|
+
style: {
|
|
220
|
+
color: '#ff4d4f'
|
|
221
|
+
}
|
|
222
|
+
}));
|
|
223
|
+
}, [showStatus, inputValue, isValid, errorMsg]);
|
|
224
|
+
|
|
225
|
+
// 只读模式
|
|
226
|
+
if (isViewOnly) {
|
|
227
|
+
var displayValue = inputValue || '-';
|
|
228
|
+
return wrapSSR( /*#__PURE__*/React.createElement("pre", {
|
|
229
|
+
className: classNames(componentName, hashId, 'spec-json-input-viewonly', className),
|
|
230
|
+
style: style,
|
|
231
|
+
ref: ref
|
|
232
|
+
}, displayValue));
|
|
233
|
+
}
|
|
234
|
+
return wrapSSR( /*#__PURE__*/React.createElement("div", {
|
|
235
|
+
className: classNames(componentName, hashId, className, {
|
|
236
|
+
'spec-json-input-error': !isValid && inputValue,
|
|
237
|
+
'spec-json-input-disabled': isDisabled
|
|
238
|
+
}),
|
|
239
|
+
style: style,
|
|
240
|
+
ref: ref
|
|
241
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
242
|
+
className: "spec-json-input-wrap"
|
|
243
|
+
}, /*#__PURE__*/React.createElement(TextArea, {
|
|
244
|
+
value: inputValue,
|
|
245
|
+
onChange: handleChange,
|
|
246
|
+
onBlur: handleBlur,
|
|
247
|
+
rows: rows,
|
|
248
|
+
size: size,
|
|
249
|
+
disabled: isDisabled,
|
|
250
|
+
maxLength: maxLength,
|
|
251
|
+
placeholder: isDisabled ? '' : inputPlaceholder,
|
|
252
|
+
className: "spec-json-input-textarea",
|
|
253
|
+
style: {
|
|
254
|
+
fontFamily: 'monospace',
|
|
255
|
+
borderColor: !isValid && inputValue ? '#ff4d4f' : undefined
|
|
256
|
+
}
|
|
257
|
+
}), statusIcon && /*#__PURE__*/React.createElement("span", {
|
|
258
|
+
className: "spec-json-input-status"
|
|
259
|
+
}, statusIcon)), showActions && !isDisabled && /*#__PURE__*/React.createElement("div", {
|
|
260
|
+
className: "spec-json-input-actions"
|
|
261
|
+
}, /*#__PURE__*/React.createElement(Space, {
|
|
262
|
+
size: "small"
|
|
263
|
+
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
264
|
+
title: (lang === null || lang === void 0 ? void 0 : lang['field.jsonInput.format']) || '格式化'
|
|
265
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
266
|
+
size: "small",
|
|
267
|
+
icon: /*#__PURE__*/React.createElement(FormatPainterOutlined, null),
|
|
268
|
+
onClick: handleFormat
|
|
269
|
+
}, (lang === null || lang === void 0 ? void 0 : lang['field.jsonInput.format']) || '格式化')), /*#__PURE__*/React.createElement(Tooltip, {
|
|
270
|
+
title: (lang === null || lang === void 0 ? void 0 : lang['field.jsonInput.compress']) || '压缩'
|
|
271
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
272
|
+
size: "small",
|
|
273
|
+
icon: isFormatted ? /*#__PURE__*/React.createElement(CompressOutlined, null) : /*#__PURE__*/React.createElement(ExpandOutlined, null),
|
|
274
|
+
onClick: handleCompress
|
|
275
|
+
}, (lang === null || lang === void 0 ? void 0 : lang['field.jsonInput.compress']) || '压缩')))), !isValid && inputValue && errorMsg && /*#__PURE__*/React.createElement("div", {
|
|
276
|
+
className: "spec-json-input-error-msg"
|
|
277
|
+
}, errorMsg)));
|
|
278
|
+
});
|
|
279
|
+
export default JsonInput;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
3
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
4
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
5
|
+
import { createStyleHook } from "../../../theme/utils/genStyleHook";
|
|
6
|
+
var JsonInputStyleFunc = function JsonInputStyleFunc(prefix) {
|
|
7
|
+
var prepareComponentToken = function prepareComponentToken(token) {
|
|
8
|
+
return {};
|
|
9
|
+
};
|
|
10
|
+
return createStyleHook(prefix, function (token) {
|
|
11
|
+
var prefixCls = ".".concat(prefix);
|
|
12
|
+
return [_defineProperty({}, prefixCls, {
|
|
13
|
+
width: '100%',
|
|
14
|
+
'.spec-json-input-wrap': {
|
|
15
|
+
position: 'relative',
|
|
16
|
+
width: '100%',
|
|
17
|
+
'.spec-json-input-textarea': {
|
|
18
|
+
width: '100%',
|
|
19
|
+
fontFamily: 'Monaco, Menlo, Consolas, monospace',
|
|
20
|
+
resize: 'vertical'
|
|
21
|
+
},
|
|
22
|
+
'.spec-json-input-status': {
|
|
23
|
+
position: 'absolute',
|
|
24
|
+
top: '8px',
|
|
25
|
+
right: '8px',
|
|
26
|
+
fontSize: '16px',
|
|
27
|
+
lineHeight: 1,
|
|
28
|
+
pointerEvents: 'auto',
|
|
29
|
+
zIndex: 1
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
'.spec-json-input-actions': {
|
|
33
|
+
marginTop: '8px',
|
|
34
|
+
display: 'flex',
|
|
35
|
+
alignItems: 'center',
|
|
36
|
+
justifyContent: 'flex-start'
|
|
37
|
+
},
|
|
38
|
+
'.spec-json-input-error-msg': {
|
|
39
|
+
marginTop: '4px',
|
|
40
|
+
fontSize: token.fontSize,
|
|
41
|
+
color: token.colorError,
|
|
42
|
+
lineHeight: 1.5,
|
|
43
|
+
wordBreak: 'break-all'
|
|
44
|
+
}
|
|
45
|
+
}), _defineProperty({}, "".concat(prefixCls, ".spec-json-input-error"), {
|
|
46
|
+
'.spec-json-input-wrap': {
|
|
47
|
+
'.spec-json-input-textarea:focus': {
|
|
48
|
+
borderColor: token.colorError,
|
|
49
|
+
boxShadow: "0 0 0 2px ".concat(token.colorErrorBg)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}), _defineProperty({}, "".concat(prefixCls, ".spec-json-input-disabled"), {
|
|
53
|
+
opacity: 0.7
|
|
54
|
+
}), _defineProperty({}, "".concat(prefixCls, ".spec-json-input-viewonly"), {
|
|
55
|
+
margin: 0,
|
|
56
|
+
padding: '8px 12px',
|
|
57
|
+
fontFamily: 'Monaco, Menlo, Consolas, monospace',
|
|
58
|
+
fontSize: '13px',
|
|
59
|
+
lineHeight: 1.6,
|
|
60
|
+
background: token.colorFillQuaternary,
|
|
61
|
+
borderRadius: '6px',
|
|
62
|
+
border: "1px solid ".concat(token.colorBorderSecondary),
|
|
63
|
+
whiteSpace: 'pre-wrap',
|
|
64
|
+
wordBreak: 'break-all',
|
|
65
|
+
color: token.colorText,
|
|
66
|
+
maxHeight: '300px',
|
|
67
|
+
overflow: 'auto'
|
|
68
|
+
})];
|
|
69
|
+
}, prepareComponentToken);
|
|
70
|
+
};
|
|
71
|
+
export default JsonInputStyleFunc;
|