yy-forms 1.0.0
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/.fatherrc.js +37 -0
- package/CHANGELOG.md +254 -0
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/index.d.ts +145 -0
- package/dist/index.esm.js +4006 -0
- package/dist/index.js +4041 -0
- package/es/Provider.js +248 -0
- package/es/index.d.ts +145 -0
- package/es/index.js +44 -0
- package/es/settings/index.js +975 -0
- package/es/styles/atom.less +1134 -0
- package/es/styles/index.less +358 -0
- package/es/transformer/form-render.js +75 -0
- package/es/utils/context.js +3 -0
- package/es/utils/hooks.js +48 -0
- package/es/utils/index.js +706 -0
- package/es/utils/mapping.js +31 -0
- package/es/utils/serialize.js +276 -0
- package/es/widgets/htmlInput.js +20 -0
- package/es/widgets/idInput.js +23 -0
- package/es/widgets/index.js +5 -0
- package/es/widgets/jsonInput.js +24 -0
- package/es/widgets/list.js +24 -0
- package/es/widgets/percentSlider.js +89 -0
- package/package.json +53 -0
- package/src/Provider.jsx +239 -0
- package/src/components/Canvas/core/RenderChildren.jsx +18 -0
- package/src/components/Canvas/core/RenderField.jsx +129 -0
- package/src/components/Canvas/core/Wrapper.jsx +298 -0
- package/src/components/Canvas/core/Wrapper.less +57 -0
- package/src/components/Canvas/core/index.jsx +171 -0
- package/src/components/Canvas/index.jsx +178 -0
- package/src/components/Settings/GlobalSettings.jsx +48 -0
- package/src/components/Settings/ItemSettings.jsx +143 -0
- package/src/components/Settings/index.jsx +75 -0
- package/src/components/Settings/index.less +25 -0
- package/src/components/Sidebar/Element.jsx +80 -0
- package/src/components/Sidebar/Element.less +18 -0
- package/src/components/Sidebar/index.jsx +47 -0
- package/src/components/Sidebar/index.less +23 -0
- package/src/i18next/index.ts +14 -0
- package/src/i18next/locales/enUS.json +60 -0
- package/src/i18next/locales/resources.ts +7 -0
- package/src/i18next/locales/zhCN.json +3 -0
- package/src/index.d.ts +145 -0
- package/src/index.js +45 -0
- package/src/settings/index.js +1058 -0
- package/src/styles/atom.less +1134 -0
- package/src/styles/index.less +358 -0
- package/src/transformer/form-render.js +65 -0
- package/src/utils/context.js +4 -0
- package/src/utils/hooks.js +35 -0
- package/src/utils/index.js +678 -0
- package/src/utils/mapping.js +29 -0
- package/src/utils/serialize.js +368 -0
- package/src/widgets/htmlInput.jsx +24 -0
- package/src/widgets/idInput.jsx +27 -0
- package/src/widgets/index.js +6 -0
- package/src/widgets/jsonInput.jsx +29 -0
- package/src/widgets/list.jsx +28 -0
- package/src/widgets/percentSlider.jsx +74 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function getWidgetName(schema, _mapping) {
|
|
2
|
+
var type = schema.type,
|
|
3
|
+
format = schema.format,
|
|
4
|
+
enums = schema.enum,
|
|
5
|
+
readonly = schema.readonly;
|
|
6
|
+
|
|
7
|
+
// 如果已经注明了渲染widget,那最好
|
|
8
|
+
if (schema['widget']) {
|
|
9
|
+
return schema['widget'];
|
|
10
|
+
}
|
|
11
|
+
var list = [];
|
|
12
|
+
if (readonly) {
|
|
13
|
+
list.push("".concat(type, "?readonly"));
|
|
14
|
+
list.push('*?readonly');
|
|
15
|
+
}
|
|
16
|
+
if (enums) {
|
|
17
|
+
list.push("".concat(type, "?enum"));
|
|
18
|
+
// array 默认使用list,array?enum 默认使用checkboxes,*?enum 默认使用select
|
|
19
|
+
list.push('*?enum');
|
|
20
|
+
}
|
|
21
|
+
if (format) {
|
|
22
|
+
list.push("".concat(type, ":").concat(format));
|
|
23
|
+
}
|
|
24
|
+
list.push(type); // 放在最后兜底,其他都不match时使用type默认的组件
|
|
25
|
+
var found = '';
|
|
26
|
+
list.some(function (item) {
|
|
27
|
+
found = _mapping[item];
|
|
28
|
+
return !!found;
|
|
29
|
+
});
|
|
30
|
+
return found;
|
|
31
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
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
|
+
/*
|
|
3
|
+
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
|
|
4
|
+
Copyrights licensed under the New BSD License.
|
|
5
|
+
See the accompanying LICENSE file for terms.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// fork自https://github.com/yahoo/serialize-javascript.git,新增 ignoreUndefined 参数的支持
|
|
9
|
+
|
|
10
|
+
import { customAlphabet } from 'nanoid';
|
|
11
|
+
var nanoid = customAlphabet('1234567890abcdef');
|
|
12
|
+
|
|
13
|
+
// Generate an internal UID to make the regexp pattern harder to guess.
|
|
14
|
+
var UID = nanoid(32);
|
|
15
|
+
var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-' + UID + '-(\\d+)__@"', 'g');
|
|
16
|
+
var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
|
|
17
|
+
var IS_PURE_FUNCTION = /function.*?\(/;
|
|
18
|
+
var IS_ARROW_FUNCTION = /.*?=>.*?/;
|
|
19
|
+
var UNSAFE_CHARS_REGEXP = /[<>\/\u2028\u2029]/g;
|
|
20
|
+
var RESERVED_SYMBOLS = ['*', 'async'];
|
|
21
|
+
|
|
22
|
+
// Mapping of unsafe HTML and invalid JavaScript line terminator chars to their
|
|
23
|
+
// Unicode char counterparts which are safe to use in JavaScript strings.
|
|
24
|
+
var ESCAPED_CHARS = {
|
|
25
|
+
'<': "\\u003C",
|
|
26
|
+
'>': "\\u003E",
|
|
27
|
+
'/': "\\u002F",
|
|
28
|
+
"\u2028": "\\u2028",
|
|
29
|
+
"\u2029": "\\u2029"
|
|
30
|
+
};
|
|
31
|
+
function escapeUnsafeChars(unsafeChar) {
|
|
32
|
+
return ESCAPED_CHARS[unsafeChar];
|
|
33
|
+
}
|
|
34
|
+
function deleteFunctions(obj) {
|
|
35
|
+
var functionKeys = [];
|
|
36
|
+
for (var key in obj) {
|
|
37
|
+
if (typeof obj[key] === 'function') {
|
|
38
|
+
functionKeys.push(key);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (var i = 0; i < functionKeys.length; i++) {
|
|
42
|
+
delete obj[functionKeys[i]];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function deleteUndefined(obj) {
|
|
46
|
+
var undefinedKeys = [];
|
|
47
|
+
for (var key in obj) {
|
|
48
|
+
if (typeof obj[key] === 'undefined') {
|
|
49
|
+
undefinedKeys.push(key);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (var i = 0; i < undefinedKeys.length; i++) {
|
|
53
|
+
delete obj[undefinedKeys[i]];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function serializeUtil(obj, options) {
|
|
57
|
+
options || (options = {});
|
|
58
|
+
|
|
59
|
+
// Backwards-compatibility for `space` as the second argument.
|
|
60
|
+
if (typeof options === 'number' || typeof options === 'string') {
|
|
61
|
+
options = {
|
|
62
|
+
space: options
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
var functions = [];
|
|
66
|
+
var regexps = [];
|
|
67
|
+
var dates = [];
|
|
68
|
+
var maps = [];
|
|
69
|
+
var sets = [];
|
|
70
|
+
var arrays = [];
|
|
71
|
+
var undefs = [];
|
|
72
|
+
var infinities = [];
|
|
73
|
+
var bigInts = [];
|
|
74
|
+
var urls = [];
|
|
75
|
+
|
|
76
|
+
// Returns placeholders for functions and regexps (identified by index)
|
|
77
|
+
// which are later replaced by their string representation.
|
|
78
|
+
function replacer(key, value) {
|
|
79
|
+
// For nested function
|
|
80
|
+
if (options.ignoreFunction) {
|
|
81
|
+
deleteFunctions(value);
|
|
82
|
+
}
|
|
83
|
+
if (options.ignoreUndefined) {
|
|
84
|
+
deleteUndefined(value);
|
|
85
|
+
}
|
|
86
|
+
if (!value && value !== undefined) {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// If the value is an object w/ a toJSON method, toJSON is called before
|
|
91
|
+
// the replacer runs, so we use this[key] to get the non-toJSONed value.
|
|
92
|
+
var origValue = this[key];
|
|
93
|
+
var type = _typeof(origValue);
|
|
94
|
+
if (type === 'object') {
|
|
95
|
+
if (origValue instanceof RegExp) {
|
|
96
|
+
return '@__R-' + UID + '-' + (regexps.push(origValue) - 1) + '__@';
|
|
97
|
+
}
|
|
98
|
+
if (origValue instanceof Date) {
|
|
99
|
+
return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
|
|
100
|
+
}
|
|
101
|
+
if (origValue instanceof Map) {
|
|
102
|
+
return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
|
|
103
|
+
}
|
|
104
|
+
if (origValue instanceof Set) {
|
|
105
|
+
return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
|
|
106
|
+
}
|
|
107
|
+
if (origValue instanceof Array) {
|
|
108
|
+
var isSparse = origValue.filter(function () {
|
|
109
|
+
return true;
|
|
110
|
+
}).length !== origValue.length;
|
|
111
|
+
if (isSparse) {
|
|
112
|
+
return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (origValue instanceof URL) {
|
|
116
|
+
return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (type === 'function') {
|
|
120
|
+
return '@__F-' + UID + '-' + (functions.push(origValue) - 1) + '__@';
|
|
121
|
+
}
|
|
122
|
+
if (type === 'undefined') {
|
|
123
|
+
return '@__U-' + UID + '-' + (undefs.push(origValue) - 1) + '__@';
|
|
124
|
+
}
|
|
125
|
+
if (type === 'number' && !isNaN(origValue) && !isFinite(origValue)) {
|
|
126
|
+
return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
|
|
127
|
+
}
|
|
128
|
+
if (type === 'bigint') {
|
|
129
|
+
return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
|
|
130
|
+
}
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
function serializeFunc(fn) {
|
|
134
|
+
var serializedFn = fn.toString();
|
|
135
|
+
if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) {
|
|
136
|
+
throw new TypeError('Serializing native function: ' + fn.name);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// pure functions, example: {key: function() {}}
|
|
140
|
+
if (IS_PURE_FUNCTION.test(serializedFn)) {
|
|
141
|
+
return serializedFn;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// arrow functions, example: arg1 => arg1+5
|
|
145
|
+
if (IS_ARROW_FUNCTION.test(serializedFn)) {
|
|
146
|
+
return serializedFn;
|
|
147
|
+
}
|
|
148
|
+
var argsStartsAt = serializedFn.indexOf('(');
|
|
149
|
+
var def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter(function (val) {
|
|
150
|
+
return val.length > 0;
|
|
151
|
+
});
|
|
152
|
+
var nonReservedSymbols = def.filter(function (val) {
|
|
153
|
+
return RESERVED_SYMBOLS.indexOf(val) === -1;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// enhanced literal objects, example: {key() {}}
|
|
157
|
+
if (nonReservedSymbols.length > 0) {
|
|
158
|
+
return (def.indexOf('async') > -1 ? 'async ' : '') + 'function' + (def.join('').indexOf('*') > -1 ? '*' : '') + serializedFn.substr(argsStartsAt);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// arrow functions
|
|
162
|
+
return serializedFn;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Check if the parameter is function
|
|
166
|
+
if (options.ignoreFunction && typeof obj === 'function') {
|
|
167
|
+
obj = undefined;
|
|
168
|
+
}
|
|
169
|
+
// Protects against `JSON.stringify()` returning `undefined`, by serializing
|
|
170
|
+
// to the literal string: "undefined".
|
|
171
|
+
if (obj === undefined) {
|
|
172
|
+
return String(obj);
|
|
173
|
+
}
|
|
174
|
+
var str;
|
|
175
|
+
|
|
176
|
+
// Creates a JSON string representation of the value.
|
|
177
|
+
// NOTE: Node 0.12 goes into slow mode with extra JSON.stringify() args.
|
|
178
|
+
if (options.isJSON && !options.space) {
|
|
179
|
+
str = JSON.stringify(obj);
|
|
180
|
+
} else {
|
|
181
|
+
str = JSON.stringify(obj, options.isJSON ? null : replacer, options.space);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Protects against `JSON.stringify()` returning `undefined`, by serializing
|
|
185
|
+
// to the literal string: "undefined".
|
|
186
|
+
if (typeof str !== 'string') {
|
|
187
|
+
return String(str);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Replace unsafe HTML and invalid JavaScript line terminator chars with
|
|
191
|
+
// their safe Unicode char counterpart. This _must_ happen before the
|
|
192
|
+
// regexps and functions are serialized and added back to the string.
|
|
193
|
+
if (options.unsafe !== true) {
|
|
194
|
+
str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
|
|
195
|
+
}
|
|
196
|
+
if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && arrays.length === 0 && undefs.length === 0 && infinities.length === 0 && bigInts.length === 0 && urls.length === 0) {
|
|
197
|
+
return str;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Replaces all occurrences of function, regexp, date, map and set placeholders in the
|
|
201
|
+
// JSON string with their string representations. If the original value can
|
|
202
|
+
// not be found, then `undefined` is used.
|
|
203
|
+
return str.replace(PLACE_HOLDER_REGEXP, function (match, backSlash, type, valueIndex) {
|
|
204
|
+
// The placeholder may not be preceded by a backslash. This is to prevent
|
|
205
|
+
// replacing things like `"a\"@__R-<UID>-0__@"` and thus outputting
|
|
206
|
+
// invalid JS.
|
|
207
|
+
if (backSlash) {
|
|
208
|
+
return match;
|
|
209
|
+
}
|
|
210
|
+
if (type === 'D') {
|
|
211
|
+
return 'new Date("' + dates[valueIndex].toISOString() + '")';
|
|
212
|
+
}
|
|
213
|
+
if (type === 'R') {
|
|
214
|
+
return 'new RegExp(' + serialize(regexps[valueIndex].source) + ', "' + regexps[valueIndex].flags + '")';
|
|
215
|
+
}
|
|
216
|
+
if (type === 'M') {
|
|
217
|
+
return 'new Map(' + serialize(Array.from(maps[valueIndex].entries()), options) + ')';
|
|
218
|
+
}
|
|
219
|
+
if (type === 'S') {
|
|
220
|
+
return 'new Set(' + serialize(Array.from(sets[valueIndex].values()), options) + ')';
|
|
221
|
+
}
|
|
222
|
+
if (type === 'A') {
|
|
223
|
+
return 'Array.prototype.slice.call(' + serialize(Object.assign({
|
|
224
|
+
length: arrays[valueIndex].length
|
|
225
|
+
}, arrays[valueIndex]), options) + ')';
|
|
226
|
+
}
|
|
227
|
+
if (type === 'U') {
|
|
228
|
+
return 'undefined';
|
|
229
|
+
}
|
|
230
|
+
if (type === 'I') {
|
|
231
|
+
return infinities[valueIndex];
|
|
232
|
+
}
|
|
233
|
+
if (type === 'B') {
|
|
234
|
+
return 'BigInt("' + bigInts[valueIndex] + '")';
|
|
235
|
+
}
|
|
236
|
+
if (type === 'L') {
|
|
237
|
+
return 'new URL("' + urls[valueIndex].toString() + '")';
|
|
238
|
+
}
|
|
239
|
+
var fn = functions[valueIndex];
|
|
240
|
+
return serializeFunc(fn);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @description 使用serialize-javascript进行序列化,替代JSON.stringify()
|
|
246
|
+
* @description 组件rules里面会存储一些validator函数,如果用JSON.stringify提交给接口会丢失
|
|
247
|
+
* @param {*} obj 传入需要序列化的值
|
|
248
|
+
* @returns 序列化后的值
|
|
249
|
+
*/
|
|
250
|
+
function serialize(obj) {
|
|
251
|
+
return serializeUtil(obj, {
|
|
252
|
+
ignoreUndefined: true
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @description 序列化成编辑器需要的展示格式
|
|
258
|
+
* @param {*} obj 传入需要序列化的值
|
|
259
|
+
* @return {*} 序列化后的值
|
|
260
|
+
*/
|
|
261
|
+
function serializeToDraft(obj) {
|
|
262
|
+
return serializeUtil(obj, {
|
|
263
|
+
space: 2,
|
|
264
|
+
ignoreUndefined: true
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @description 对serialize-javascript序列化后的值进行反序列化化
|
|
270
|
+
* @param {*} serializedJavascript 反序列化后的值
|
|
271
|
+
* @returns
|
|
272
|
+
*/
|
|
273
|
+
function deserialize(serializedJavascript) {
|
|
274
|
+
return new Function('return ' + serializedJavascript)();
|
|
275
|
+
}
|
|
276
|
+
export { deserialize, serialize, serializeToDraft, serializeUtil };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import { Input } from 'antd';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export default function HtmlInput(_ref) {
|
|
5
|
+
var value = _ref.value,
|
|
6
|
+
disabled = _ref.disabled,
|
|
7
|
+
readonly = _ref.readonly,
|
|
8
|
+
options = _ref.options,
|
|
9
|
+
onChange = _ref.onChange;
|
|
10
|
+
var handleChange = function handleChange(e) {
|
|
11
|
+
var newVal = e.target.value;
|
|
12
|
+
onChange(newVal && newVal.replace(/on(.*?=)/g, 'no$1'));
|
|
13
|
+
};
|
|
14
|
+
return /*#__PURE__*/React.createElement(Input, _extends({
|
|
15
|
+
disabled: disabled || readonly
|
|
16
|
+
}, options, {
|
|
17
|
+
onChange: handleChange,
|
|
18
|
+
value: value && value.replace(/no(.*?=)/g, 'on$1')
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import { Input } from 'antd';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { changeKeyFromUniqueId, getKeyFromUniqueId } from '../utils';
|
|
5
|
+
export default function IdInput(_ref) {
|
|
6
|
+
var onChange = _ref.onChange,
|
|
7
|
+
value = _ref.value,
|
|
8
|
+
disabled = _ref.disabled,
|
|
9
|
+
readonly = _ref.readonly,
|
|
10
|
+
options = _ref.options;
|
|
11
|
+
var handleChange = function handleChange(e) {
|
|
12
|
+
try {
|
|
13
|
+
var newId = changeKeyFromUniqueId(value, e.target.value);
|
|
14
|
+
onChange(newId);
|
|
15
|
+
} catch (error) {}
|
|
16
|
+
};
|
|
17
|
+
return /*#__PURE__*/React.createElement(Input, _extends({
|
|
18
|
+
disabled: disabled || readonly
|
|
19
|
+
}, options, {
|
|
20
|
+
onChange: handleChange,
|
|
21
|
+
value: getKeyFromUniqueId(value)
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import { Input } from 'antd';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export default function jsonInput(_ref) {
|
|
5
|
+
var onChange = _ref.onChange,
|
|
6
|
+
value = _ref.value,
|
|
7
|
+
disabled = _ref.disabled,
|
|
8
|
+
readonly = _ref.readonly,
|
|
9
|
+
options = _ref.options;
|
|
10
|
+
var handleChange = function handleChange(e) {
|
|
11
|
+
try {
|
|
12
|
+
onChange(JSON.parse(e.target.value));
|
|
13
|
+
} catch (_unused) {
|
|
14
|
+
onChange(e.target.value);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var inputValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
18
|
+
return /*#__PURE__*/React.createElement(Input, _extends({
|
|
19
|
+
disabled: disabled || readonly
|
|
20
|
+
}, options, {
|
|
21
|
+
onChange: handleChange,
|
|
22
|
+
value: inputValue
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DeleteOutlined, PlusCircleOutlined } from '@ant-design/icons';
|
|
2
|
+
import { Button } from 'antd';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export default function list(props) {
|
|
5
|
+
if (!/^#/.test(props.schema.$id)) {
|
|
6
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
7
|
+
className: "w-100"
|
|
8
|
+
}, props.children);
|
|
9
|
+
}
|
|
10
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
11
|
+
className: "flex flex-column"
|
|
12
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
13
|
+
className: "fr-set w-100 flex flex-column ba pt4 pb2 ph2 relative b--black-10"
|
|
14
|
+
}, props.children, /*#__PURE__*/React.createElement(Button, {
|
|
15
|
+
size: "small",
|
|
16
|
+
className: "self-end",
|
|
17
|
+
type: "dashed",
|
|
18
|
+
icon: /*#__PURE__*/React.createElement(DeleteOutlined, null)
|
|
19
|
+
}, "\u5220\u9664")), /*#__PURE__*/React.createElement(Button, {
|
|
20
|
+
size: "small",
|
|
21
|
+
className: "self-end",
|
|
22
|
+
icon: /*#__PURE__*/React.createElement(PlusCircleOutlined, null)
|
|
23
|
+
}, "\u6DFB\u52A0"));
|
|
24
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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 _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
7
|
+
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); }
|
|
8
|
+
import { InputNumber, Slider } from 'antd';
|
|
9
|
+
import React from 'react';
|
|
10
|
+
var PercentSlider = function PercentSlider(p) {
|
|
11
|
+
var style = p.invalid ? {
|
|
12
|
+
borderColor: '#f5222d'
|
|
13
|
+
} : {};
|
|
14
|
+
var _p$schema = p.schema,
|
|
15
|
+
max = _p$schema.max,
|
|
16
|
+
min = _p$schema.min,
|
|
17
|
+
step = _p$schema.step;
|
|
18
|
+
var setting = {};
|
|
19
|
+
if (max || max === 0) {
|
|
20
|
+
setting = {
|
|
21
|
+
max: max
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (min || min === 0) {
|
|
25
|
+
setting = _objectSpread(_objectSpread({}, setting), {}, {
|
|
26
|
+
min: min
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (step) {
|
|
30
|
+
setting = _objectSpread(_objectSpread({}, setting), {}, {
|
|
31
|
+
step: step
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
var hideNumber = false;
|
|
35
|
+
if (p.options && p.options.hideNumber) {
|
|
36
|
+
hideNumber = true;
|
|
37
|
+
}
|
|
38
|
+
var isPercent = function isPercent(string) {
|
|
39
|
+
return typeof string === 'string' && string.endsWith('%');
|
|
40
|
+
};
|
|
41
|
+
var numberValue = 100;
|
|
42
|
+
if (isPercent(p.value)) {
|
|
43
|
+
try {
|
|
44
|
+
numberValue = Number(p.value.split('%')[0]);
|
|
45
|
+
if (Number.isNaN(numberValue)) numberValue = 100;
|
|
46
|
+
} catch (error) {}
|
|
47
|
+
}
|
|
48
|
+
var handleChange = function handleChange(newNumber) {
|
|
49
|
+
var a = newNumber + '%';
|
|
50
|
+
p.onChange(a);
|
|
51
|
+
};
|
|
52
|
+
var renderNumber = p.readonly ? /*#__PURE__*/React.createElement("span", {
|
|
53
|
+
style: {
|
|
54
|
+
width: '80px'
|
|
55
|
+
}
|
|
56
|
+
}, p.value === (undefined || '') ? '-' : p.value + '%') : /*#__PURE__*/React.createElement(InputNumber, _extends({}, p.options, setting, {
|
|
57
|
+
style: _objectSpread({
|
|
58
|
+
width: '80px'
|
|
59
|
+
}, style),
|
|
60
|
+
value: numberValue,
|
|
61
|
+
disabled: p.disabled,
|
|
62
|
+
onChange: handleChange,
|
|
63
|
+
formatter: function formatter(value) {
|
|
64
|
+
return "".concat(value, "%");
|
|
65
|
+
},
|
|
66
|
+
parser: function parser(value) {
|
|
67
|
+
return value.replace('%', '');
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
71
|
+
className: "fr-slider"
|
|
72
|
+
}, /*#__PURE__*/React.createElement(Slider, _extends({
|
|
73
|
+
style: {
|
|
74
|
+
flexGrow: 1,
|
|
75
|
+
marginRight: hideNumber ? 0 : 12
|
|
76
|
+
}
|
|
77
|
+
}, setting, {
|
|
78
|
+
onChange: handleChange,
|
|
79
|
+
max: 100,
|
|
80
|
+
tooltip: {
|
|
81
|
+
formatter: function formatter(v) {
|
|
82
|
+
return v + '%';
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
value: numberValue || 100,
|
|
86
|
+
disabled: p.disabled || p.readonly
|
|
87
|
+
})), hideNumber ? null : renderNumber);
|
|
88
|
+
};
|
|
89
|
+
export default PercentSlider;
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "yy-forms",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.esm.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"beta": "npm publish --tag beta",
|
|
10
|
+
"build": "father-build",
|
|
11
|
+
"prepare": "yarn build",
|
|
12
|
+
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
|
|
13
|
+
"postpublish": "git push --tags",
|
|
14
|
+
"test": "umi-test",
|
|
15
|
+
"test:coverage": "umi-test --coverage"
|
|
16
|
+
},
|
|
17
|
+
"lint-staged": {
|
|
18
|
+
"*.{js,jsx,less,md,json}": [
|
|
19
|
+
"prettier --write"
|
|
20
|
+
],
|
|
21
|
+
"*.ts?(x)": [
|
|
22
|
+
"prettier --parser=typescript --write"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"babel-plugin-import": "^1.13.8",
|
|
27
|
+
"clone": "^2.1.2",
|
|
28
|
+
"copy-text-to-clipboard": "^2.2.0",
|
|
29
|
+
"father-build": "^1.22.5",
|
|
30
|
+
"form-render": "^1.0.0",
|
|
31
|
+
"i18next": "^21.8.11",
|
|
32
|
+
"moment": "^2.27.0",
|
|
33
|
+
"nanoid": "^3.1.22",
|
|
34
|
+
"randombytes": "2.1.0",
|
|
35
|
+
"rc-color-picker": "^1.2.6",
|
|
36
|
+
"react-dnd": "^14.0.2",
|
|
37
|
+
"react-dnd-html5-backend": "^14.0.0",
|
|
38
|
+
"react-i18next": "^11.17.2",
|
|
39
|
+
"react-sortable-hoc": "^2.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"rollup-plugin-commonjs": "^10.1.0",
|
|
43
|
+
"rollup-plugin-copy": "^3.4.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"antd": "4.x",
|
|
47
|
+
"react": ">=16.14.0",
|
|
48
|
+
"react-dom": ">=16.14.0"
|
|
49
|
+
},
|
|
50
|
+
"gitHooks": {
|
|
51
|
+
"pre-commit": "lint-staged"
|
|
52
|
+
}
|
|
53
|
+
}
|