react-schema-form 1.0.4 → 1.0.6
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/react-schema-form.css +1 -0
- package/dist/react-schema-form.js +24405 -0
- package/dist/react-schema-form.js.map +1 -0
- package/dist/react-schema-form.umd.cjs +228 -0
- package/dist/react-schema-form.umd.cjs.map +1 -0
- package/package.json +66 -60
- package/dist/index.js +0 -2134
- package/dist/index.js.map +0 -1
- package/dist/index.modern.js +0 -2128
- package/dist/index.modern.js.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,2134 +0,0 @@
|
|
|
1
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var React__default = _interopDefault(React);
|
|
5
|
-
var merge$1 = _interopDefault(require('lodash/merge'));
|
|
6
|
-
var isNil = _interopDefault(require('lodash/isNil'));
|
|
7
|
-
var isObject = _interopDefault(require('lodash/isObject'));
|
|
8
|
-
var cloneDeep = _interopDefault(require('lodash/cloneDeep'));
|
|
9
|
-
var extend = _interopDefault(require('lodash/extend'));
|
|
10
|
-
var isUndefined = _interopDefault(require('lodash/isUndefined'));
|
|
11
|
-
var ObjectPath = _interopDefault(require('objectpath'));
|
|
12
|
-
var tv4 = _interopDefault(require('tv4'));
|
|
13
|
-
var notevil = _interopDefault(require('notevil'));
|
|
14
|
-
var TextField = _interopDefault(require('@mui/material/TextField'));
|
|
15
|
-
var FormLabel = _interopDefault(require('@mui/material/FormLabel'));
|
|
16
|
-
var FormHelperText = _interopDefault(require('@mui/material/FormHelperText'));
|
|
17
|
-
var ReactMde = _interopDefault(require('react-mde'));
|
|
18
|
-
var Showdown = require('showdown');
|
|
19
|
-
require('react-mde/lib/styles/css/react-mde-all.css');
|
|
20
|
-
var MenuItem = _interopDefault(require('@mui/material/MenuItem'));
|
|
21
|
-
var MuiSelect = _interopDefault(require('@mui/material/Select'));
|
|
22
|
-
var InputLabel = _interopDefault(require('@mui/material/InputLabel'));
|
|
23
|
-
var FormControl = _interopDefault(require('@mui/material/FormControl'));
|
|
24
|
-
var withStyles = _interopDefault(require('@mui/styles/withStyles'));
|
|
25
|
-
var Chip = _interopDefault(require('@mui/material/Chip'));
|
|
26
|
-
var FormControlLabel = _interopDefault(require('@mui/material/FormControlLabel'));
|
|
27
|
-
var RadioGroup = _interopDefault(require('@mui/material/RadioGroup'));
|
|
28
|
-
var Radio = _interopDefault(require('@mui/material/Radio'));
|
|
29
|
-
var Checkbox$1 = _interopDefault(require('@mui/material/Checkbox'));
|
|
30
|
-
var FormGroup = _interopDefault(require('@mui/material/FormGroup'));
|
|
31
|
-
var Typography = _interopDefault(require('@mui/material/Typography'));
|
|
32
|
-
var Button = _interopDefault(require('@mui/material/Button'));
|
|
33
|
-
var Card = _interopDefault(require('@mui/material/Card'));
|
|
34
|
-
var IconButton = _interopDefault(require('@mui/material/IconButton'));
|
|
35
|
-
var DeleteIcon = _interopDefault(require('@mui/icons-material/Close'));
|
|
36
|
-
var classNames = _interopDefault(require('classnames'));
|
|
37
|
-
var material = require('@mui/material');
|
|
38
|
-
var CheckboxTree = _interopDefault(require('react-checkbox-tree'));
|
|
39
|
-
require('react-checkbox-tree/lib/react-checkbox-tree.css');
|
|
40
|
-
var CheckBoxIcon = _interopDefault(require('@mui/icons-material/CheckBox'));
|
|
41
|
-
var CheckBoxOutlineBlankIcon = _interopDefault(require('@mui/icons-material/CheckBoxOutlineBlank'));
|
|
42
|
-
var IndeterminateCheckBoxIcon = _interopDefault(require('@mui/icons-material/IndeterminateCheckBox'));
|
|
43
|
-
var ChevronRightIcon = _interopDefault(require('@mui/icons-material/ChevronRight'));
|
|
44
|
-
var KeyboardArrowDownIcon = _interopDefault(require('@mui/icons-material/KeyboardArrowDown'));
|
|
45
|
-
var AddBoxIcon = _interopDefault(require('@mui/icons-material/AddBox'));
|
|
46
|
-
var FolderIcon = _interopDefault(require('@mui/icons-material/Folder'));
|
|
47
|
-
var FolderOpenIcon = _interopDefault(require('@mui/icons-material/FolderOpen'));
|
|
48
|
-
var InsertDriveFileIcon = _interopDefault(require('@mui/icons-material/InsertDriveFile'));
|
|
49
|
-
var Cookies = _interopDefault(require('universal-cookie'));
|
|
50
|
-
|
|
51
|
-
function _extends() {
|
|
52
|
-
_extends = Object.assign || function (target) {
|
|
53
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
54
|
-
var source = arguments[i];
|
|
55
|
-
|
|
56
|
-
for (var key in source) {
|
|
57
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
58
|
-
target[key] = source[key];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return target;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
return _extends.apply(this, arguments);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function _inheritsLoose(subClass, superClass) {
|
|
70
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
71
|
-
subClass.prototype.constructor = subClass;
|
|
72
|
-
|
|
73
|
-
_setPrototypeOf(subClass, superClass);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function _setPrototypeOf(o, p) {
|
|
77
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
78
|
-
o.__proto__ = p;
|
|
79
|
-
return o;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
return _setPrototypeOf(o, p);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function _assertThisInitialized(self) {
|
|
86
|
-
if (self === void 0) {
|
|
87
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return self;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
var safeEval = function safeEval(condition, scope) {
|
|
94
|
-
try {
|
|
95
|
-
var scopeSafe = cloneDeep(scope);
|
|
96
|
-
return notevil(condition, scopeSafe);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
var stripNullType = function stripNullType(type) {
|
|
103
|
-
if (Array.isArray(type) && type.length === 2) {
|
|
104
|
-
if (type[0] === 'null') return type[1];
|
|
105
|
-
if (type[1] === 'null') return type[0];
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return type;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
var enumToTitleMap = function enumToTitleMap(enm) {
|
|
112
|
-
var titleMap = [];
|
|
113
|
-
enm.forEach(function (name) {
|
|
114
|
-
titleMap.push({
|
|
115
|
-
name: name,
|
|
116
|
-
value: name
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
return titleMap;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
var canonicalTitleMap = function canonicalTitleMap(titleMap, originalEnum) {
|
|
123
|
-
if (!originalEnum) return titleMap;
|
|
124
|
-
var canonical = [];
|
|
125
|
-
var enumValues = Object.keys(titleMap).length === 0 ? originalEnum : titleMap;
|
|
126
|
-
originalEnum.forEach(function (value, idx) {
|
|
127
|
-
canonical.push({
|
|
128
|
-
name: enumValues[idx],
|
|
129
|
-
value: value
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
return canonical;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
var stdFormObj = function stdFormObj(name, schema, options) {
|
|
136
|
-
options = options || {};
|
|
137
|
-
var f = options.global && options.global.formDefaults ? cloneDeep(options.global.formDefaults) : {};
|
|
138
|
-
|
|
139
|
-
if (options.global && options.global.supressPropertyTitles === true) {
|
|
140
|
-
f.title = schema.title;
|
|
141
|
-
} else {
|
|
142
|
-
f.title = schema.title || name;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (schema.description) {
|
|
146
|
-
f.description = schema.description;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (options.required === true || schema.required === true) {
|
|
150
|
-
f.required = true;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (schema.maxLength) {
|
|
154
|
-
f.maxlength = schema.maxLength;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (schema.minLength) {
|
|
158
|
-
f.minlength = schema.minLength;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (schema.readOnly || schema.readonly) {
|
|
162
|
-
f.readonly = true;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (schema.minimum) {
|
|
166
|
-
f.minimum = schema.minimum + (schema.exclusiveMinimum ? 1 : 0);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (schema.maximum) {
|
|
170
|
-
f.maximum = schema.maximum - (schema.exclusiveMaximum ? 1 : 0);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (schema.validationMessage) {
|
|
174
|
-
f.validationMessage = schema.validationMessage;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (schema.enumNames) {
|
|
178
|
-
f.titleMap = canonicalTitleMap(schema.enumNames, schema["enum"]);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
f.schema = schema;
|
|
182
|
-
return f;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
var tBoolean = function tBoolean(name, schema, options) {
|
|
186
|
-
if (stripNullType(schema.type) === 'tBoolean' && !schema["enum"]) {
|
|
187
|
-
var f = stdFormObj(name, schema, options);
|
|
188
|
-
f.key = options.path;
|
|
189
|
-
f.type = 'tBoolean';
|
|
190
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
191
|
-
return f;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return undefined;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
var text = function text(name, schema, options) {
|
|
198
|
-
if (stripNullType(schema.type) === 'string' && !schema["enum"]) {
|
|
199
|
-
var f = stdFormObj(name, schema, options);
|
|
200
|
-
f.key = options.path;
|
|
201
|
-
f.type = 'text';
|
|
202
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
203
|
-
return f;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return undefined;
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
var number = function number(name, schema, options) {
|
|
210
|
-
if (stripNullType(schema.type) === 'number') {
|
|
211
|
-
var f = stdFormObj(name, schema, options);
|
|
212
|
-
f.key = options.path;
|
|
213
|
-
f.type = 'number';
|
|
214
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
215
|
-
return f;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return undefined;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
var integer = function integer(name, schema, options) {
|
|
222
|
-
if (stripNullType(schema.type) === 'integer') {
|
|
223
|
-
var f = stdFormObj(name, schema, options);
|
|
224
|
-
f.key = options.path;
|
|
225
|
-
f.type = 'number';
|
|
226
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
227
|
-
return f;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return undefined;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
var date = function date(name, schema, options) {
|
|
234
|
-
if (stripNullType(schema.type) === 'date') {
|
|
235
|
-
var f = stdFormObj(name, schema, options);
|
|
236
|
-
f.key = options.path;
|
|
237
|
-
f.type = 'date';
|
|
238
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
239
|
-
return f;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return undefined;
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
var checkbox = function checkbox(name, schema, options) {
|
|
246
|
-
if (stripNullType(schema.type) === 'boolean') {
|
|
247
|
-
var f = stdFormObj(name, schema, options);
|
|
248
|
-
f.key = options.path;
|
|
249
|
-
f.type = 'checkbox';
|
|
250
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
251
|
-
return f;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return undefined;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
var select = function select(name, schema, options) {
|
|
258
|
-
if (stripNullType(schema.type) === 'string' && schema["enum"]) {
|
|
259
|
-
var f = stdFormObj(name, schema, options);
|
|
260
|
-
f.key = options.path;
|
|
261
|
-
f.type = 'select';
|
|
262
|
-
|
|
263
|
-
if (!f.titleMap && !schema.isObject) {
|
|
264
|
-
f.titleMap = enumToTitleMap(schema["enum"]);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
268
|
-
return f;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return undefined;
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
var removeEmpty = function removeEmpty(obj) {
|
|
275
|
-
return Object.entries(obj).forEach(function (_ref) {
|
|
276
|
-
var key = _ref[0],
|
|
277
|
-
val = _ref[1];
|
|
278
|
-
if (val && typeof val === 'object') removeEmpty(val);else if (val === undefined || val === null || val === '') delete obj[key];
|
|
279
|
-
});
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
var checkboxes = function checkboxes(name, schema, options) {
|
|
283
|
-
if (stripNullType(schema.type) === 'array' && schema.items && schema.items["enum"]) {
|
|
284
|
-
var f = stdFormObj(name, schema, options);
|
|
285
|
-
f.key = options.path;
|
|
286
|
-
f.type = 'checkboxes';
|
|
287
|
-
|
|
288
|
-
if (!f.titleMap) {
|
|
289
|
-
f.titleMap = enumToTitleMap(schema.items["enum"]);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
293
|
-
return f;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return undefined;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
var defaultFormDefinition = function defaultFormDefinition(name, schema, options) {
|
|
300
|
-
var rules = defaults[stripNullType(schema.type)];
|
|
301
|
-
|
|
302
|
-
if (rules) {
|
|
303
|
-
var def;
|
|
304
|
-
|
|
305
|
-
for (var i = 0; i < rules.length; i += 1) {
|
|
306
|
-
def = rules[i](name, schema, options);
|
|
307
|
-
|
|
308
|
-
if (def) {
|
|
309
|
-
if (def.schema['x-schema-form'] && isObject(def.schema['x-schema-form'])) {
|
|
310
|
-
def = extend(def, def.schema['x-schema-form']);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return def;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return undefined;
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
var fieldset = function fieldset(name, schema, options) {
|
|
322
|
-
if (stripNullType(schema.type) === 'object') {
|
|
323
|
-
var f = stdFormObj(name, schema, options);
|
|
324
|
-
f.type = 'fieldset';
|
|
325
|
-
f.items = [];
|
|
326
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
327
|
-
|
|
328
|
-
if (schema.properties) {
|
|
329
|
-
Object.keys(schema.properties).forEach(function (key) {
|
|
330
|
-
if (Object.prototype.hasOwnProperty.call(schema.properties, key)) {
|
|
331
|
-
var path = options.path.slice();
|
|
332
|
-
path.push(key);
|
|
333
|
-
|
|
334
|
-
if (options.ignore[ObjectPath.stringify(path)] !== true) {
|
|
335
|
-
var required = schema.required && schema.required.indexOf(key) !== -1;
|
|
336
|
-
var def = defaultFormDefinition(key, schema.properties[key], {
|
|
337
|
-
path: path,
|
|
338
|
-
required: required || false,
|
|
339
|
-
lookup: options.lookup,
|
|
340
|
-
ignore: options.ignore,
|
|
341
|
-
global: options.global
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
if (def) {
|
|
345
|
-
f.items.push(def);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return f;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return undefined;
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
var tuple = function tuple(name, schema, options) {
|
|
359
|
-
if (stripNullType(schema.type) === 'array') {
|
|
360
|
-
var f = stdFormObj(name, schema, options);
|
|
361
|
-
f.type = 'tuple';
|
|
362
|
-
f.key = options.path;
|
|
363
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
364
|
-
|
|
365
|
-
if (Array.isArray(schema.items)) {
|
|
366
|
-
var required = schema.required && schema.required.indexOf(options.path[options.path.length - 1]);
|
|
367
|
-
f.items = schema.items.reduce(function (items, item, index) {
|
|
368
|
-
var arrPath = options.path.slice();
|
|
369
|
-
arrPath.push(index);
|
|
370
|
-
var def = defaultFormDefinition(name, item, {
|
|
371
|
-
path: arrPath,
|
|
372
|
-
required: required || false,
|
|
373
|
-
lookup: options.lookup,
|
|
374
|
-
ignore: options.ignore,
|
|
375
|
-
global: options.global
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
if (def) {
|
|
379
|
-
items.push(def);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
return items;
|
|
383
|
-
}, []);
|
|
384
|
-
return f;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return undefined;
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
var array = function array(name, schema, options) {
|
|
392
|
-
if (stripNullType(schema.type) === 'array') {
|
|
393
|
-
var f = stdFormObj(name, schema, options);
|
|
394
|
-
f.type = 'array';
|
|
395
|
-
f.key = options.path;
|
|
396
|
-
options.lookup[ObjectPath.stringify(options.path)] = f;
|
|
397
|
-
|
|
398
|
-
if (typeof schema.items !== 'undefined') {
|
|
399
|
-
var required = schema.required && schema.required.indexOf(options.path[options.path.length - 1]) !== -1;
|
|
400
|
-
var arrPath = options.path.slice();
|
|
401
|
-
arrPath.push('');
|
|
402
|
-
var def = defaultFormDefinition(name, schema.items, {
|
|
403
|
-
path: arrPath,
|
|
404
|
-
required: required || false,
|
|
405
|
-
lookup: options.lookup,
|
|
406
|
-
ignore: options.ignore,
|
|
407
|
-
global: options.global
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
if (def) {
|
|
411
|
-
f.items = [def];
|
|
412
|
-
} else {
|
|
413
|
-
f.items = schema.items;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
return f;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
return undefined;
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
var defaults = {
|
|
424
|
-
string: [select, text],
|
|
425
|
-
object: [fieldset],
|
|
426
|
-
number: [number],
|
|
427
|
-
integer: [integer],
|
|
428
|
-
"boolean": [checkbox],
|
|
429
|
-
array: [checkboxes, tuple, array],
|
|
430
|
-
date: [date],
|
|
431
|
-
tBoolean: [tBoolean]
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
var getDefaults = function getDefaults(schema, ignore, globalOptions) {
|
|
435
|
-
var form = [];
|
|
436
|
-
var lookup = {};
|
|
437
|
-
ignore = ignore || {};
|
|
438
|
-
globalOptions = globalOptions || {};
|
|
439
|
-
|
|
440
|
-
if (stripNullType(schema.type) === 'object') {
|
|
441
|
-
if (schema.properties) {
|
|
442
|
-
Object.keys(schema.properties).forEach(function (key) {
|
|
443
|
-
if (Object.prototype.hasOwnProperty.call(schema.properties, key)) {
|
|
444
|
-
if (ignore[key] !== true) {
|
|
445
|
-
var required = schema.required && schema.required.indexOf(key) !== -1;
|
|
446
|
-
var def = defaultFormDefinition(key, schema.properties[key], {
|
|
447
|
-
path: [key],
|
|
448
|
-
lookup: lookup,
|
|
449
|
-
ignore: ignore,
|
|
450
|
-
required: required,
|
|
451
|
-
global: globalOptions
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
if (def) {
|
|
455
|
-
form.push(def);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
} else {
|
|
462
|
-
throw new Error('Not implemented. Only type "object" allowed at root level of schema.');
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return {
|
|
466
|
-
form: form,
|
|
467
|
-
lookup: lookup
|
|
468
|
-
};
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
var postProcessFn = function postProcessFn(form) {
|
|
472
|
-
return form;
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
var appendRule = function appendRule(type, rule) {
|
|
476
|
-
if (!defaults[type]) {
|
|
477
|
-
defaults[type] = [];
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
defaults[type].push(rule);
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
var prependRule = function prependRule(type, rule) {
|
|
484
|
-
if (!defaults[type]) {
|
|
485
|
-
defaults[type] = [];
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
defaults[type].unshift(rule);
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
var traverseSchema = function traverseSchema(schema, fn, path, ignoreArrays) {
|
|
492
|
-
ignoreArrays = typeof ignoreArrays !== 'undefined' ? ignoreArrays : true;
|
|
493
|
-
path = path || [];
|
|
494
|
-
|
|
495
|
-
var traverse = function traverse(innerSchema, innerFunc, innerPath) {
|
|
496
|
-
innerFunc(innerSchema, innerPath);
|
|
497
|
-
|
|
498
|
-
if (innerSchema.properties) {
|
|
499
|
-
Object.keys(innerSchema.properties).forEach(function (key) {
|
|
500
|
-
if (Object.prototype.hasOwnProperty.call(innerSchema.properties, key)) {
|
|
501
|
-
var currentPath = innerPath.slice();
|
|
502
|
-
currentPath.push(key);
|
|
503
|
-
traverse(innerSchema.properties[key], innerFunc, currentPath);
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
if (!ignoreArrays && innerSchema.items) {
|
|
509
|
-
var arrPath = innerPath.slice();
|
|
510
|
-
arrPath.push('');
|
|
511
|
-
traverse(innerSchema.items, innerFunc, arrPath);
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
traverse(schema, fn, path || []);
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
var traverseForm = function traverseForm(form, fn) {
|
|
519
|
-
fn(form);
|
|
520
|
-
|
|
521
|
-
if (form.items) {
|
|
522
|
-
form.items.forEach(function (f) {
|
|
523
|
-
traverseForm(f, fn);
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
if (form.tabs) {
|
|
528
|
-
form.tabs.forEach(function (tab) {
|
|
529
|
-
tab.items.forEach(function (f) {
|
|
530
|
-
traverseForm(f, fn);
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
var merge = function merge(schema, form, ignore, options, readonly) {
|
|
537
|
-
form = form || ['*'];
|
|
538
|
-
options = options || {};
|
|
539
|
-
readonly = readonly || schema.readonly || schema.readOnly;
|
|
540
|
-
var stdForm = getDefaults(schema, ignore, options);
|
|
541
|
-
var idx = form.indexOf('*');
|
|
542
|
-
|
|
543
|
-
if (idx !== -1) {
|
|
544
|
-
form = form.slice(0, idx).concat(stdForm.form).concat(form.slice(idx + 1));
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
var lookup = stdForm.lookup;
|
|
548
|
-
return postProcessFn(form.map(function (obj) {
|
|
549
|
-
if (typeof obj === 'string') {
|
|
550
|
-
obj = {
|
|
551
|
-
key: obj
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
if (obj && obj.key) {
|
|
556
|
-
if (typeof obj.key === 'string') {
|
|
557
|
-
obj.key = ObjectPath.parse(obj.key);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
if (obj && obj.itemForm) {
|
|
562
|
-
obj.items = [];
|
|
563
|
-
var str = ObjectPath.stringify(obj.key);
|
|
564
|
-
var foundForm = lookup[str];
|
|
565
|
-
foundForm.items.forEach(function (item) {
|
|
566
|
-
var o = cloneDeep(obj.itemForm);
|
|
567
|
-
o.key = item.key;
|
|
568
|
-
obj.items.push(o);
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
if (obj && obj.key) {
|
|
573
|
-
var strid = ObjectPath.stringify(obj.key);
|
|
574
|
-
|
|
575
|
-
if (lookup[strid]) {
|
|
576
|
-
var schemaDefaults = lookup[strid];
|
|
577
|
-
Object.keys(schemaDefaults).forEach(function (key) {
|
|
578
|
-
if (Object.prototype.hasOwnProperty.call(schemaDefaults, key)) {
|
|
579
|
-
if (obj[key] === undefined) {
|
|
580
|
-
obj[key] = schemaDefaults[key];
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
if (readonly === true) {
|
|
588
|
-
obj.readonly = true;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
if (obj && obj.items && obj.items.length > 0) {
|
|
592
|
-
obj.items = merge(schema, obj.items, ignore, options, obj.readonly);
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
if (obj && obj.tabs) {
|
|
596
|
-
obj.tabs.forEach(function (tab) {
|
|
597
|
-
tab.items = merge(schema, tab.items, ignore, options, obj.readonly);
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
if (obj && obj.type === 'checkbox' && isUndefined(obj.schema["default"])) {
|
|
602
|
-
obj.schema["default"] = false;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
return obj;
|
|
606
|
-
}));
|
|
607
|
-
};
|
|
608
|
-
|
|
609
|
-
function selectOrSet(projection, obj, valueToSet, type) {
|
|
610
|
-
var numRe = /^\d+$/;
|
|
611
|
-
|
|
612
|
-
if (!obj) {
|
|
613
|
-
obj = this;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
var parts = typeof projection === 'string' ? ObjectPath.parse(projection) : projection;
|
|
617
|
-
|
|
618
|
-
if (typeof valueToSet !== 'undefined' && parts.length === 1) {
|
|
619
|
-
obj[parts[0]] = valueToSet;
|
|
620
|
-
return obj;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
if (typeof valueToSet !== 'undefined' && typeof obj[parts[0]] === 'undefined') {
|
|
624
|
-
obj[parts[0]] = parts.length >= 2 && numRe.test(parts[1]) ? [] : {};
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
if (typeof type !== 'undefined' && ['number', 'integer'].indexOf(type) > -1 && typeof valueToSet === 'undefined') {
|
|
628
|
-
obj[parts[0]] = valueToSet;
|
|
629
|
-
return obj;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
var value = obj[parts[0]];
|
|
633
|
-
|
|
634
|
-
for (var i = 1; i < parts.length; i += 1) {
|
|
635
|
-
if (parts[i] === '') {
|
|
636
|
-
return undefined;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
if (typeof valueToSet !== 'undefined') {
|
|
640
|
-
if (i === parts.length - 1) {
|
|
641
|
-
value[parts[i]] = valueToSet;
|
|
642
|
-
return valueToSet;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
var tmp = value[parts[i]];
|
|
646
|
-
|
|
647
|
-
if (typeof tmp === 'undefined' || tmp === null) {
|
|
648
|
-
tmp = numRe.test(parts[i + 1]) ? [] : {};
|
|
649
|
-
value[parts[i]] = tmp;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
value = tmp;
|
|
653
|
-
} else if (value) {
|
|
654
|
-
value = value[parts[i]];
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
return value;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
var validateBySchema = function validateBySchema(schema, value) {
|
|
662
|
-
return tv4.validateResult(value, schema);
|
|
663
|
-
};
|
|
664
|
-
|
|
665
|
-
var validate = function validate(form, value, getLocalizedString) {
|
|
666
|
-
if (!form) {
|
|
667
|
-
return {
|
|
668
|
-
valid: true
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
var schema = form.schema;
|
|
673
|
-
|
|
674
|
-
if (!schema) {
|
|
675
|
-
return {
|
|
676
|
-
valid: true
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
if (value === '') {
|
|
681
|
-
value = undefined;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
if (form.type === 'number' && value === null) {
|
|
685
|
-
value = undefined;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
if (form.type === 'number' && Number.isNaN(parseFloat(value))) {
|
|
689
|
-
value = undefined;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
var wrap = {
|
|
693
|
-
type: 'object',
|
|
694
|
-
properties: {}
|
|
695
|
-
};
|
|
696
|
-
var propName = form.key[form.key.length - 1];
|
|
697
|
-
wrap.properties[propName] = schema;
|
|
698
|
-
|
|
699
|
-
if (form.required) {
|
|
700
|
-
wrap.required = [propName];
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
var valueWrap = {};
|
|
704
|
-
|
|
705
|
-
if (typeof value !== 'undefined') {
|
|
706
|
-
valueWrap[propName] = value;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
var tv4Result = tv4.validateResult(valueWrap, wrap);
|
|
710
|
-
|
|
711
|
-
if (tv4Result != null && !tv4Result.valid && form.validationMessage != null && typeof value !== 'undefined') {
|
|
712
|
-
tv4Result.error.message = getLocalizedString ? getLocalizedString(form.validationMessage) : form.validationMessage;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
return tv4Result;
|
|
716
|
-
};
|
|
717
|
-
|
|
718
|
-
var getValueFromModel = function getValueFromModel(model, key) {
|
|
719
|
-
var result;
|
|
720
|
-
|
|
721
|
-
if (Array.isArray(key)) {
|
|
722
|
-
key.reduce(function (cur, nxt) {
|
|
723
|
-
return cur && cur[nxt];
|
|
724
|
-
}, model);
|
|
725
|
-
result = key.reduce(function (cur, nxt) {
|
|
726
|
-
return cur && cur[nxt];
|
|
727
|
-
}, model);
|
|
728
|
-
} else {
|
|
729
|
-
result = model[key];
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
return result;
|
|
733
|
-
};
|
|
734
|
-
|
|
735
|
-
var getTitleByValue = function getTitleByValue(titleMap, value) {
|
|
736
|
-
for (var i = 0; i < titleMap.length; i += 1) {
|
|
737
|
-
var item = titleMap[i];
|
|
738
|
-
if (item.value === value) return item.name;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
return undefined;
|
|
742
|
-
};
|
|
743
|
-
|
|
744
|
-
var utils = {
|
|
745
|
-
traverseForm: traverseForm,
|
|
746
|
-
traverseSchema: traverseSchema,
|
|
747
|
-
prependRule: prependRule,
|
|
748
|
-
appendRule: appendRule,
|
|
749
|
-
postProcessFn: postProcessFn,
|
|
750
|
-
getDefaults: getDefaults,
|
|
751
|
-
defaultFormDefinition: defaultFormDefinition,
|
|
752
|
-
defaults: defaults,
|
|
753
|
-
array: array,
|
|
754
|
-
fieldset: fieldset,
|
|
755
|
-
checkboxes: checkboxes,
|
|
756
|
-
select: select,
|
|
757
|
-
checkbox: checkbox,
|
|
758
|
-
integer: integer,
|
|
759
|
-
number: number,
|
|
760
|
-
text: text,
|
|
761
|
-
stdFormObj: stdFormObj,
|
|
762
|
-
canonicalTitleMap: canonicalTitleMap,
|
|
763
|
-
enumToTitleMap: enumToTitleMap,
|
|
764
|
-
stripNullType: stripNullType,
|
|
765
|
-
merge: merge,
|
|
766
|
-
validate: validate,
|
|
767
|
-
validateBySchema: validateBySchema,
|
|
768
|
-
safeEval: safeEval,
|
|
769
|
-
selectOrSet: selectOrSet,
|
|
770
|
-
getValueFromModel: getValueFromModel,
|
|
771
|
-
getTitleByValue: getTitleByValue,
|
|
772
|
-
removeEmpty: removeEmpty
|
|
773
|
-
};
|
|
774
|
-
|
|
775
|
-
var defaultValue = function defaultValue(props) {
|
|
776
|
-
var value;
|
|
777
|
-
if (props.form && props.form.key) value = utils.selectOrSet(props.form.key, props.model);
|
|
778
|
-
|
|
779
|
-
if (value === null || value === undefined) {
|
|
780
|
-
if (props.form["default"]) {
|
|
781
|
-
value = props.form["default"];
|
|
782
|
-
} else if (props.form.schema && props.form.schema["default"]) {
|
|
783
|
-
value = props.form.schema["default"];
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
return value;
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
var getDisplayName = function getDisplayName(WrappedComponent) {
|
|
791
|
-
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
792
|
-
};
|
|
793
|
-
|
|
794
|
-
var ComposedComponent = (function (ComposedComponent, defaultProps) {
|
|
795
|
-
if (defaultProps === void 0) {
|
|
796
|
-
defaultProps = {};
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
return /*#__PURE__*/function (_React$Component) {
|
|
800
|
-
_inheritsLoose(Composed, _React$Component);
|
|
801
|
-
|
|
802
|
-
function Composed(props) {
|
|
803
|
-
var _this;
|
|
804
|
-
|
|
805
|
-
_this = _React$Component.call(this, props) || this;
|
|
806
|
-
_this.displayName = "ComposedComponent(" + getDisplayName(ComposedComponent) + ")";
|
|
807
|
-
_this.onChangeValidate = _this.onChangeValidate.bind(_assertThisInitialized(_this));
|
|
808
|
-
_this.state = _this.constructor.getDerivedStateFromProps(_this.props);
|
|
809
|
-
return _this;
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
Composed.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps) {
|
|
813
|
-
var errorText = nextProps.errorText,
|
|
814
|
-
form = nextProps.form,
|
|
815
|
-
showErrors = nextProps.showErrors,
|
|
816
|
-
localization = nextProps.localization;
|
|
817
|
-
var getLocalizedString = localization && localization.getLocalizedString;
|
|
818
|
-
var value = defaultValue(nextProps);
|
|
819
|
-
|
|
820
|
-
if (!showErrors) {
|
|
821
|
-
return {
|
|
822
|
-
value: value,
|
|
823
|
-
valid: true,
|
|
824
|
-
error: ''
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
var validationResult = utils.validate(form, value || undefined, getLocalizedString);
|
|
829
|
-
var error = !validationResult.valid ? validationResult.error : undefined;
|
|
830
|
-
return {
|
|
831
|
-
value: value,
|
|
832
|
-
valid: validationResult.valid,
|
|
833
|
-
error: (!validationResult.valid ? error.message : null) || errorText
|
|
834
|
-
};
|
|
835
|
-
};
|
|
836
|
-
|
|
837
|
-
var _proto = Composed.prototype;
|
|
838
|
-
|
|
839
|
-
_proto.onChangeValidate = function onChangeValidate(e, v) {
|
|
840
|
-
var _this$props = this.props,
|
|
841
|
-
form = _this$props.form,
|
|
842
|
-
onChange = _this$props.onChange,
|
|
843
|
-
localization = _this$props.localization;
|
|
844
|
-
var getLocalizedString = localization && localization.getLocalizedString;
|
|
845
|
-
var value = null;
|
|
846
|
-
var type = form.schema ? form.schema.type : form.type;
|
|
847
|
-
|
|
848
|
-
switch (type) {
|
|
849
|
-
case 'integer':
|
|
850
|
-
case 'number':
|
|
851
|
-
{
|
|
852
|
-
value = e;
|
|
853
|
-
break;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
case 'boolean':
|
|
857
|
-
value = e.target.checked;
|
|
858
|
-
break;
|
|
859
|
-
|
|
860
|
-
case 'array':
|
|
861
|
-
value = e;
|
|
862
|
-
break;
|
|
863
|
-
|
|
864
|
-
case 'object':
|
|
865
|
-
if (form.type === 'date') {
|
|
866
|
-
if (e.target.value.length > 0) {
|
|
867
|
-
value = new Date(e.target.value);
|
|
868
|
-
} else {
|
|
869
|
-
value = '';
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
break;
|
|
873
|
-
}
|
|
874
|
-
value = e.target.value;
|
|
875
|
-
break;
|
|
876
|
-
|
|
877
|
-
default:
|
|
878
|
-
value = e.target.value;
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
var validationResult = utils.validate(form, value, getLocalizedString);
|
|
882
|
-
this.setState({
|
|
883
|
-
value: value,
|
|
884
|
-
valid: validationResult.valid,
|
|
885
|
-
error: validationResult.valid ? null : validationResult.error.message
|
|
886
|
-
});
|
|
887
|
-
onChange(form.key, value);
|
|
888
|
-
};
|
|
889
|
-
|
|
890
|
-
_proto.render = function render() {
|
|
891
|
-
return /*#__PURE__*/React__default.createElement(ComposedComponent, _extends({}, defaultProps, this.props, this.state, {
|
|
892
|
-
onChangeValidate: this.onChangeValidate
|
|
893
|
-
}));
|
|
894
|
-
};
|
|
895
|
-
|
|
896
|
-
return Composed;
|
|
897
|
-
}(React__default.Component);
|
|
898
|
-
});
|
|
899
|
-
|
|
900
|
-
var Text = /*#__PURE__*/function (_React$Component) {
|
|
901
|
-
_inheritsLoose(Text, _React$Component);
|
|
902
|
-
|
|
903
|
-
function Text(props) {
|
|
904
|
-
var _this;
|
|
905
|
-
|
|
906
|
-
_this = _React$Component.call(this, props) || this;
|
|
907
|
-
var _this$props = _this.props,
|
|
908
|
-
model = _this$props.model,
|
|
909
|
-
form = _this$props.form,
|
|
910
|
-
value = _this$props.value,
|
|
911
|
-
setDefault = _this$props.setDefault;
|
|
912
|
-
var key = form.key;
|
|
913
|
-
setDefault(key, model, form, value);
|
|
914
|
-
return _this;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
var _proto = Text.prototype;
|
|
918
|
-
|
|
919
|
-
_proto.render = function render() {
|
|
920
|
-
var _this$props2 = this.props,
|
|
921
|
-
form = _this$props2.form,
|
|
922
|
-
error = _this$props2.error,
|
|
923
|
-
value = _this$props2.value,
|
|
924
|
-
onChangeValidate = _this$props2.onChangeValidate,
|
|
925
|
-
getLocalizedString = _this$props2.localization.getLocalizedString,
|
|
926
|
-
otherProps = _this$props2.otherProps;
|
|
927
|
-
return /*#__PURE__*/React__default.createElement(TextField, _extends({
|
|
928
|
-
type: form.type,
|
|
929
|
-
label: form.title && getLocalizedString(form.title),
|
|
930
|
-
placeholder: form.placeholder && getLocalizedString(form.placeholder),
|
|
931
|
-
helperText: (error || form.description) && getLocalizedString(error || form.description),
|
|
932
|
-
error: !!error,
|
|
933
|
-
onChange: onChangeValidate,
|
|
934
|
-
value: value || '',
|
|
935
|
-
disabled: form.readonly,
|
|
936
|
-
fullWidth: true,
|
|
937
|
-
required: form.required,
|
|
938
|
-
style: form.style
|
|
939
|
-
}, otherProps, form.otherProps));
|
|
940
|
-
};
|
|
941
|
-
|
|
942
|
-
return Text;
|
|
943
|
-
}(React__default.Component);
|
|
944
|
-
|
|
945
|
-
Text.defaultProps = {
|
|
946
|
-
otherProps: undefined
|
|
947
|
-
};
|
|
948
|
-
var Text$1 = ComposedComponent(Text);
|
|
949
|
-
|
|
950
|
-
var NumberComponent = function NumberComponent(props) {
|
|
951
|
-
var form = props.form,
|
|
952
|
-
value = props.value,
|
|
953
|
-
getLocalizedNumber = props.localization.getLocalizedNumber,
|
|
954
|
-
onChangeValidate = props.onChangeValidate;
|
|
955
|
-
var inputValue = value || value === 0 ? value : '';
|
|
956
|
-
if (form.useLocalizer) inputValue = getLocalizedNumber(inputValue);
|
|
957
|
-
|
|
958
|
-
var onChange = function onChange(e) {
|
|
959
|
-
var type = form.schema ? form.schema.type : form.type;
|
|
960
|
-
var enteredValue = null;
|
|
961
|
-
|
|
962
|
-
if (type === 'integer') {
|
|
963
|
-
enteredValue = parseInt(e.target.value, 10);
|
|
964
|
-
} else if (type === 'number') {
|
|
965
|
-
var values = e.target.value.split('.');
|
|
966
|
-
|
|
967
|
-
if (values.length < 2) {
|
|
968
|
-
enteredValue = parseInt(e.target.value, 10);
|
|
969
|
-
} else if (values.length > 1) {
|
|
970
|
-
if (values[1].length > 0) enteredValue = parseFloat(e.target.value);else enteredValue = parseInt(values[0], 10) + ".";
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
onChangeValidate(enteredValue);
|
|
975
|
-
};
|
|
976
|
-
|
|
977
|
-
return /*#__PURE__*/React__default.createElement(Text$1, _extends({}, props, {
|
|
978
|
-
form: _extends({}, form, {
|
|
979
|
-
type: 'string'
|
|
980
|
-
}),
|
|
981
|
-
value: inputValue,
|
|
982
|
-
otherProps: {
|
|
983
|
-
onChange: onChange
|
|
984
|
-
}
|
|
985
|
-
}));
|
|
986
|
-
};
|
|
987
|
-
|
|
988
|
-
var Number$1 = ComposedComponent(NumberComponent);
|
|
989
|
-
|
|
990
|
-
var TextArea = function TextArea(props) {
|
|
991
|
-
var form = props.form;
|
|
992
|
-
return /*#__PURE__*/React__default.createElement(Text$1, _extends({}, props, {
|
|
993
|
-
otherProps: {
|
|
994
|
-
multiline: true,
|
|
995
|
-
rows: form.rows,
|
|
996
|
-
maxRows: form.maxRows
|
|
997
|
-
}
|
|
998
|
-
}));
|
|
999
|
-
};
|
|
1000
|
-
|
|
1001
|
-
var TextArea$1 = ComposedComponent(TextArea);
|
|
1002
|
-
|
|
1003
|
-
var converter = new Showdown.Converter({
|
|
1004
|
-
tables: true,
|
|
1005
|
-
simplifiedAutoLink: true,
|
|
1006
|
-
strikethrough: true,
|
|
1007
|
-
tasklists: true
|
|
1008
|
-
});
|
|
1009
|
-
|
|
1010
|
-
var Markdown = function Markdown(props) {
|
|
1011
|
-
var model = props.model,
|
|
1012
|
-
form = props.form,
|
|
1013
|
-
value = props.value,
|
|
1014
|
-
error = props.error,
|
|
1015
|
-
setDefault = props.setDefault,
|
|
1016
|
-
onChangeValidate = props.onChangeValidate;
|
|
1017
|
-
var key = form.key,
|
|
1018
|
-
title = form.title;
|
|
1019
|
-
setDefault(key, model, form, value);
|
|
1020
|
-
|
|
1021
|
-
var _useState = React.useState('write'),
|
|
1022
|
-
selectedTab = _useState[0],
|
|
1023
|
-
setSelectedTab = _useState[1];
|
|
1024
|
-
|
|
1025
|
-
var _useState2 = React.useState(value),
|
|
1026
|
-
text = _useState2[0],
|
|
1027
|
-
setText = _useState2[1];
|
|
1028
|
-
|
|
1029
|
-
React.useEffect(function () {
|
|
1030
|
-
onChangeValidate({
|
|
1031
|
-
target: {
|
|
1032
|
-
value: text
|
|
1033
|
-
}
|
|
1034
|
-
});
|
|
1035
|
-
}, [text]);
|
|
1036
|
-
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(FormLabel, {
|
|
1037
|
-
required: form.required
|
|
1038
|
-
}, title), /*#__PURE__*/React__default.createElement(ReactMde, {
|
|
1039
|
-
value: value,
|
|
1040
|
-
onChange: setText,
|
|
1041
|
-
readOnly: form.readonly,
|
|
1042
|
-
selectedTab: selectedTab,
|
|
1043
|
-
onTabChange: setSelectedTab,
|
|
1044
|
-
generateMarkdownPreview: function generateMarkdownPreview(markdown) {
|
|
1045
|
-
return Promise.resolve(converter.makeHtml(markdown));
|
|
1046
|
-
}
|
|
1047
|
-
}), error ? /*#__PURE__*/React__default.createElement(FormHelperText, {
|
|
1048
|
-
error: true
|
|
1049
|
-
}, error) : null);
|
|
1050
|
-
};
|
|
1051
|
-
|
|
1052
|
-
var Markdown$1 = ComposedComponent(Markdown);
|
|
1053
|
-
|
|
1054
|
-
var dataSourceConfig = {
|
|
1055
|
-
text: "name",
|
|
1056
|
-
value: "value"
|
|
1057
|
-
};
|
|
1058
|
-
|
|
1059
|
-
var TextSuggest = /*#__PURE__*/function (_React$Component) {
|
|
1060
|
-
_inheritsLoose(TextSuggest, _React$Component);
|
|
1061
|
-
|
|
1062
|
-
function TextSuggest() {
|
|
1063
|
-
var _this;
|
|
1064
|
-
|
|
1065
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1066
|
-
args[_key] = arguments[_key];
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
1070
|
-
|
|
1071
|
-
_this.handleUpdate = function (newValue, index) {
|
|
1072
|
-
var key = _this.props.form.key;
|
|
1073
|
-
var type = _this.props.form.schema.type;
|
|
1074
|
-
return _this.props.onChange(key, newValue[dataSourceConfig.value], type, _this.props.form);
|
|
1075
|
-
};
|
|
1076
|
-
|
|
1077
|
-
_this.handleInit = function (init_value) {
|
|
1078
|
-
if (!_this.props.form.schema || !_this.props.form.schema["enum"]) return init_value.toString();
|
|
1079
|
-
var names = _this.props.form.schema.enumNames || _this.props.form.schema["enum"];
|
|
1080
|
-
var values = _this.props.form.schema["enum"];
|
|
1081
|
-
var init_value_name = names[values.indexOf(init_value)];
|
|
1082
|
-
return init_value_name || init_value.toString();
|
|
1083
|
-
};
|
|
1084
|
-
|
|
1085
|
-
return _this;
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
var _proto = TextSuggest.prototype;
|
|
1089
|
-
|
|
1090
|
-
_proto.render = function render() {
|
|
1091
|
-
var filter = function (filter) {
|
|
1092
|
-
switch (filter) {
|
|
1093
|
-
case "fuzzy":
|
|
1094
|
-
return AutoComplete.fuzzyFilter;
|
|
1095
|
-
|
|
1096
|
-
default:
|
|
1097
|
-
return AutoComplete.caseInsensitiveFilter;
|
|
1098
|
-
}
|
|
1099
|
-
}(this.props.form.filter);
|
|
1100
|
-
|
|
1101
|
-
var value = this.props.value && this.handleInit(this.props.value);
|
|
1102
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
1103
|
-
className: this.props.form.htmlClass
|
|
1104
|
-
}, /*#__PURE__*/React__default.createElement(AutoComplete, {
|
|
1105
|
-
type: this.props.form.type,
|
|
1106
|
-
floatingLabelText: this.props.form.title,
|
|
1107
|
-
hintText: this.props.form.placeholder,
|
|
1108
|
-
errorText: this.props.error,
|
|
1109
|
-
onNewRequest: this.handleUpdate,
|
|
1110
|
-
disabled: this.props.form.readonly,
|
|
1111
|
-
style: this.props.form.style || {
|
|
1112
|
-
width: "100%"
|
|
1113
|
-
},
|
|
1114
|
-
openOnFocus: true,
|
|
1115
|
-
searchText: value,
|
|
1116
|
-
dataSource: this.props.form.titleMap || ["Loading..."],
|
|
1117
|
-
filter: filter,
|
|
1118
|
-
maxSearchResults: this.props.form.maxSearchResults || 5,
|
|
1119
|
-
dataSourceConfig: dataSourceConfig
|
|
1120
|
-
}));
|
|
1121
|
-
};
|
|
1122
|
-
|
|
1123
|
-
return TextSuggest;
|
|
1124
|
-
}(React__default.Component);
|
|
1125
|
-
|
|
1126
|
-
var TextSuggest$1 = ComposedComponent(TextSuggest);
|
|
1127
|
-
|
|
1128
|
-
function Select(props) {
|
|
1129
|
-
var model = props.model,
|
|
1130
|
-
form = props.form,
|
|
1131
|
-
error = props.error,
|
|
1132
|
-
setDefault = props.setDefault,
|
|
1133
|
-
onChange = props.onChange,
|
|
1134
|
-
onChangeValidate = props.onChangeValidate,
|
|
1135
|
-
getLocalizedString = props.localization.getLocalizedString,
|
|
1136
|
-
_props$form = props.form,
|
|
1137
|
-
key = _props$form.key,
|
|
1138
|
-
_props$form$schema = _props$form.schema,
|
|
1139
|
-
isObject = _props$form$schema.isObject,
|
|
1140
|
-
values = _props$form$schema["enum"],
|
|
1141
|
-
findFn = _props$form$schema.findFn,
|
|
1142
|
-
displayFn = _props$form$schema.displayFn,
|
|
1143
|
-
noLocalization = _props$form$schema.noLocalization;
|
|
1144
|
-
var defaultValue = form && form.selectProps && form.selectProps.multiple ? [] : '';
|
|
1145
|
-
|
|
1146
|
-
if (props.form["default"]) {
|
|
1147
|
-
defaultValue = props.form["default"];
|
|
1148
|
-
} else if (props.form.schema && props.form.schema["default"]) {
|
|
1149
|
-
defaultValue = props.form.schema["default"];
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
var _useState = React.useState(utils.getValueFromModel(model, form.key) || defaultValue),
|
|
1153
|
-
currentValue = _useState[0],
|
|
1154
|
-
setCurrentValue = _useState[1];
|
|
1155
|
-
|
|
1156
|
-
React.useEffect(function () {
|
|
1157
|
-
setDefault(key, model, form, currentValue);
|
|
1158
|
-
}, []);
|
|
1159
|
-
|
|
1160
|
-
var onSelected = function onSelected(event) {
|
|
1161
|
-
var selectedValue = event.target.value;
|
|
1162
|
-
setCurrentValue(selectedValue);
|
|
1163
|
-
|
|
1164
|
-
if (isObject) {
|
|
1165
|
-
var item = values.find(function (each) {
|
|
1166
|
-
return findFn ? findFn(each, selectedValue) : each === selectedValue;
|
|
1167
|
-
});
|
|
1168
|
-
onChange(key, item);
|
|
1169
|
-
} else {
|
|
1170
|
-
onChangeValidate(event);
|
|
1171
|
-
}
|
|
1172
|
-
};
|
|
1173
|
-
|
|
1174
|
-
var getLabel = function getLabel(each) {
|
|
1175
|
-
if (displayFn) {
|
|
1176
|
-
return displayFn(each);
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
if (noLocalization) return each.name;
|
|
1180
|
-
return getLocalizedString(each.name);
|
|
1181
|
-
};
|
|
1182
|
-
|
|
1183
|
-
var menuItems = [];
|
|
1184
|
-
|
|
1185
|
-
if (isObject) {
|
|
1186
|
-
menuItems = form.schema["enum"].map(function (item, idx) {
|
|
1187
|
-
return (
|
|
1188
|
-
/*#__PURE__*/
|
|
1189
|
-
React__default.createElement(MenuItem, {
|
|
1190
|
-
key: idx,
|
|
1191
|
-
value: item
|
|
1192
|
-
}, getLabel(item))
|
|
1193
|
-
);
|
|
1194
|
-
});
|
|
1195
|
-
} else {
|
|
1196
|
-
menuItems = form.titleMap.map(function (item, idx) {
|
|
1197
|
-
return (
|
|
1198
|
-
/*#__PURE__*/
|
|
1199
|
-
React__default.createElement(MenuItem, {
|
|
1200
|
-
key: idx,
|
|
1201
|
-
value: item.value
|
|
1202
|
-
}, getLabel(item))
|
|
1203
|
-
);
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
return /*#__PURE__*/React__default.createElement(FormControl, _extends({
|
|
1208
|
-
fullWidth: true,
|
|
1209
|
-
error: !!error
|
|
1210
|
-
}, form.otherProps), /*#__PURE__*/React__default.createElement(InputLabel, _extends({
|
|
1211
|
-
required: form.required
|
|
1212
|
-
}, form.labelProps), form.title && getLocalizedString(form.title)), /*#__PURE__*/React__default.createElement(MuiSelect, _extends({
|
|
1213
|
-
value: currentValue,
|
|
1214
|
-
placeholder: form.placeholder && getLocalizedString(form.placeholder),
|
|
1215
|
-
disabled: form.readonly,
|
|
1216
|
-
onChange: onSelected
|
|
1217
|
-
}, form.selectProps), menuItems), /*#__PURE__*/React__default.createElement(FormHelperText, form.helperTextProps, (error || form.description) && getLocalizedString(error || form.description)));
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
var Select$1 = ComposedComponent(Select);
|
|
1221
|
-
|
|
1222
|
-
var styles = function styles(theme) {
|
|
1223
|
-
return {
|
|
1224
|
-
root: {
|
|
1225
|
-
display: 'flex',
|
|
1226
|
-
flexWrap: 'wrap'
|
|
1227
|
-
},
|
|
1228
|
-
chips: {
|
|
1229
|
-
display: 'flex',
|
|
1230
|
-
flexWrap: 'wrap'
|
|
1231
|
-
},
|
|
1232
|
-
chip: {
|
|
1233
|
-
margin: theme.spacing(0.25)
|
|
1234
|
-
},
|
|
1235
|
-
menuItem: {
|
|
1236
|
-
fontWeight: theme.typography.fontWeightRegular
|
|
1237
|
-
},
|
|
1238
|
-
selectedMenuItem: {
|
|
1239
|
-
fontWeight: theme.typography.fontWeightMedium
|
|
1240
|
-
}
|
|
1241
|
-
};
|
|
1242
|
-
};
|
|
1243
|
-
|
|
1244
|
-
var ITEM_HEIGHT = 48;
|
|
1245
|
-
var ITEM_PADDING_TOP = 8;
|
|
1246
|
-
var MenuProps = {
|
|
1247
|
-
PaperProps: {
|
|
1248
|
-
style: {
|
|
1249
|
-
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
|
|
1250
|
-
width: 250
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
};
|
|
1254
|
-
|
|
1255
|
-
var MultiSelect = /*#__PURE__*/function (_Component) {
|
|
1256
|
-
_inheritsLoose(MultiSelect, _Component);
|
|
1257
|
-
|
|
1258
|
-
function MultiSelect(props) {
|
|
1259
|
-
var _this;
|
|
1260
|
-
|
|
1261
|
-
_this = _Component.call(this, props) || this;
|
|
1262
|
-
|
|
1263
|
-
_this.onSelected = function (event) {
|
|
1264
|
-
var onChangeValidate = _this.props.onChangeValidate;
|
|
1265
|
-
var currentValue = event.target.value;
|
|
1266
|
-
|
|
1267
|
-
_this.setState({
|
|
1268
|
-
currentValue: currentValue
|
|
1269
|
-
});
|
|
1270
|
-
|
|
1271
|
-
onChangeValidate(currentValue);
|
|
1272
|
-
};
|
|
1273
|
-
|
|
1274
|
-
var _this$props = _this.props,
|
|
1275
|
-
model = _this$props.model,
|
|
1276
|
-
form = _this$props.form;
|
|
1277
|
-
_this.state = {
|
|
1278
|
-
currentValue: utils.getValueFromModel(model, form.key) || []
|
|
1279
|
-
};
|
|
1280
|
-
return _this;
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
MultiSelect.getDerivedStateFromProps = function getDerivedStateFromProps(props) {
|
|
1284
|
-
var model = props.model,
|
|
1285
|
-
form = props.form;
|
|
1286
|
-
|
|
1287
|
-
if (model && form.key) {
|
|
1288
|
-
return {
|
|
1289
|
-
currentValue: utils.getValueFromModel(model, form.key) || []
|
|
1290
|
-
};
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
return null;
|
|
1294
|
-
};
|
|
1295
|
-
|
|
1296
|
-
var _proto = MultiSelect.prototype;
|
|
1297
|
-
|
|
1298
|
-
_proto.render = function render() {
|
|
1299
|
-
var _this$props2 = this.props,
|
|
1300
|
-
form = _this$props2.form,
|
|
1301
|
-
classes = _this$props2.classes,
|
|
1302
|
-
getLocalizedString = _this$props2.localization.getLocalizedString;
|
|
1303
|
-
var currentValue = this.state.currentValue;
|
|
1304
|
-
var getTitle = utils.getTitleByValue.bind(this, form.titleMap);
|
|
1305
|
-
var menuItems = form.titleMap.map(function (item) {
|
|
1306
|
-
return /*#__PURE__*/React__default.createElement(MenuItem, {
|
|
1307
|
-
key: item.value,
|
|
1308
|
-
value: item.value,
|
|
1309
|
-
className: currentValue.indexOf(item.value) === -1 ? classes.menuItem : classes.selectedMenuItem
|
|
1310
|
-
}, item.name && getLocalizedString(item.name));
|
|
1311
|
-
});
|
|
1312
|
-
return /*#__PURE__*/React__default.createElement(FormControl, _extends({
|
|
1313
|
-
fullWidth: true
|
|
1314
|
-
}, form.otherProps), /*#__PURE__*/React__default.createElement(InputLabel, {
|
|
1315
|
-
required: form.required
|
|
1316
|
-
}, form.title && getLocalizedString(form.title)), /*#__PURE__*/React__default.createElement(MuiSelect, {
|
|
1317
|
-
multiple: true,
|
|
1318
|
-
value: currentValue || '',
|
|
1319
|
-
placeholder: form.placeholder && getLocalizedString(form.placeholder),
|
|
1320
|
-
disabled: form.readonly,
|
|
1321
|
-
onChange: this.onSelected,
|
|
1322
|
-
MenuProps: MenuProps,
|
|
1323
|
-
renderValue: function renderValue(selected) {
|
|
1324
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
1325
|
-
className: classes.chips
|
|
1326
|
-
}, selected.map(function (value) {
|
|
1327
|
-
return /*#__PURE__*/React__default.createElement(Chip, {
|
|
1328
|
-
key: value,
|
|
1329
|
-
label: getTitle(value) && getLocalizedString(getTitle(value)),
|
|
1330
|
-
className: classes.chip
|
|
1331
|
-
});
|
|
1332
|
-
}));
|
|
1333
|
-
}
|
|
1334
|
-
}, menuItems));
|
|
1335
|
-
};
|
|
1336
|
-
|
|
1337
|
-
return MultiSelect;
|
|
1338
|
-
}(React.Component);
|
|
1339
|
-
|
|
1340
|
-
var MultiSelect$1 = ComposedComponent(withStyles(styles)(MultiSelect));
|
|
1341
|
-
|
|
1342
|
-
var styles$1 = function styles(theme) {
|
|
1343
|
-
return {
|
|
1344
|
-
formControl: {
|
|
1345
|
-
marginTop: theme.spacing(1)
|
|
1346
|
-
},
|
|
1347
|
-
group: {
|
|
1348
|
-
margin: theme.spacing(1, 0)
|
|
1349
|
-
}
|
|
1350
|
-
};
|
|
1351
|
-
};
|
|
1352
|
-
|
|
1353
|
-
var Radios = /*#__PURE__*/function (_Component) {
|
|
1354
|
-
_inheritsLoose(Radios, _Component);
|
|
1355
|
-
|
|
1356
|
-
function Radios() {
|
|
1357
|
-
var _this;
|
|
1358
|
-
|
|
1359
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1360
|
-
args[_key] = arguments[_key];
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
|
1364
|
-
|
|
1365
|
-
_this.renderItems = function (form) {
|
|
1366
|
-
var getLocalizedString = _this.props.localization.getLocalizedString;
|
|
1367
|
-
return form.titleMap.map(function (item, index) {
|
|
1368
|
-
return /*#__PURE__*/React__default.createElement(FormControlLabel, {
|
|
1369
|
-
key: index,
|
|
1370
|
-
control: /*#__PURE__*/React__default.createElement(Radio, null),
|
|
1371
|
-
label: item.name && getLocalizedString(item.name),
|
|
1372
|
-
value: item.value,
|
|
1373
|
-
disabled: form.readonly
|
|
1374
|
-
});
|
|
1375
|
-
});
|
|
1376
|
-
};
|
|
1377
|
-
|
|
1378
|
-
return _this;
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
var _proto = Radios.prototype;
|
|
1382
|
-
|
|
1383
|
-
_proto.render = function render() {
|
|
1384
|
-
var _this$props = this.props,
|
|
1385
|
-
classes = _this$props.classes,
|
|
1386
|
-
form = _this$props.form,
|
|
1387
|
-
value = _this$props.value,
|
|
1388
|
-
onChangeValidate = _this$props.onChangeValidate,
|
|
1389
|
-
getLocalizedString = _this$props.localization.getLocalizedString;
|
|
1390
|
-
return /*#__PURE__*/React__default.createElement(FormControl, _extends({
|
|
1391
|
-
component: "fieldset",
|
|
1392
|
-
className: classes.formControl
|
|
1393
|
-
}, form.otherProps), /*#__PURE__*/React__default.createElement(FormLabel, {
|
|
1394
|
-
component: "legend",
|
|
1395
|
-
required: form.required
|
|
1396
|
-
}, form.title && getLocalizedString(form.title)), /*#__PURE__*/React__default.createElement(RadioGroup, {
|
|
1397
|
-
value: value,
|
|
1398
|
-
name: form.title,
|
|
1399
|
-
onChange: onChangeValidate,
|
|
1400
|
-
className: classes.group
|
|
1401
|
-
}, this.renderItems(form)));
|
|
1402
|
-
};
|
|
1403
|
-
|
|
1404
|
-
return Radios;
|
|
1405
|
-
}(React.Component);
|
|
1406
|
-
|
|
1407
|
-
var Radios$1 = ComposedComponent(withStyles(styles$1)(Radios));
|
|
1408
|
-
|
|
1409
|
-
var NativeDateField = function NativeDateField(props) {
|
|
1410
|
-
var value = props.value,
|
|
1411
|
-
getLocalizedDate = props.localization.getLocalizedDate,
|
|
1412
|
-
form = props.form,
|
|
1413
|
-
type = props.type;
|
|
1414
|
-
return /*#__PURE__*/React__default.createElement(Text$1, _extends({}, props, {
|
|
1415
|
-
form: _extends({}, form, {
|
|
1416
|
-
type: type
|
|
1417
|
-
}),
|
|
1418
|
-
value: getLocalizedDate(value),
|
|
1419
|
-
otherProps: {
|
|
1420
|
-
InputLabelProps: {
|
|
1421
|
-
shrink: true
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
}, form.otherProps));
|
|
1425
|
-
};
|
|
1426
|
-
|
|
1427
|
-
var DateComponent = ComposedComponent(NativeDateField, {
|
|
1428
|
-
type: 'date'
|
|
1429
|
-
});
|
|
1430
|
-
|
|
1431
|
-
var Timestamp = /*#__PURE__*/function (_React$Component) {
|
|
1432
|
-
_inheritsLoose(Timestamp, _React$Component);
|
|
1433
|
-
|
|
1434
|
-
function Timestamp(props) {
|
|
1435
|
-
var _this;
|
|
1436
|
-
|
|
1437
|
-
_this = _React$Component.call(this, props) || this;
|
|
1438
|
-
var _this$props = _this.props,
|
|
1439
|
-
model = _this$props.model,
|
|
1440
|
-
form = _this$props.form,
|
|
1441
|
-
value = _this$props.value,
|
|
1442
|
-
setDefault = _this$props.setDefault;
|
|
1443
|
-
var key = form.key;
|
|
1444
|
-
var d = new Date();
|
|
1445
|
-
var currentTimestamp = d.toISOString().substring(0, 16);
|
|
1446
|
-
setDefault(key, model, form, value || currentTimestamp);
|
|
1447
|
-
return _this;
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
var _proto = Timestamp.prototype;
|
|
1451
|
-
|
|
1452
|
-
_proto.render = function render() {
|
|
1453
|
-
var _this$props2 = this.props,
|
|
1454
|
-
form = _this$props2.form,
|
|
1455
|
-
error = _this$props2.error,
|
|
1456
|
-
value = _this$props2.value,
|
|
1457
|
-
onChangeValidate = _this$props2.onChangeValidate,
|
|
1458
|
-
getLocalizedString = _this$props2.localization.getLocalizedString;
|
|
1459
|
-
return /*#__PURE__*/React__default.createElement(TextField, _extends({
|
|
1460
|
-
type: "datetime-local",
|
|
1461
|
-
label: form.title && getLocalizedString(form.title),
|
|
1462
|
-
placeholder: form.placeholder && getLocalizedString(form.placeholder),
|
|
1463
|
-
helperText: (error || form.description) && getLocalizedString(error || form.description),
|
|
1464
|
-
error: !!error,
|
|
1465
|
-
onChange: onChangeValidate,
|
|
1466
|
-
value: value || '',
|
|
1467
|
-
disabled: form.readonly,
|
|
1468
|
-
fullWidth: true,
|
|
1469
|
-
required: form.required,
|
|
1470
|
-
style: form.style
|
|
1471
|
-
}, form.otherProps));
|
|
1472
|
-
};
|
|
1473
|
-
|
|
1474
|
-
return Timestamp;
|
|
1475
|
-
}(React__default.Component);
|
|
1476
|
-
|
|
1477
|
-
var Timestamp$1 = ComposedComponent(Timestamp);
|
|
1478
|
-
|
|
1479
|
-
function FormCheckbox(props) {
|
|
1480
|
-
var model = props.model,
|
|
1481
|
-
form = props.form,
|
|
1482
|
-
value = props.value,
|
|
1483
|
-
setDefault = props.setDefault,
|
|
1484
|
-
getLocalizedString = props.localization.getLocalizedString,
|
|
1485
|
-
onChangeValidate = props.onChangeValidate;
|
|
1486
|
-
var key = form.key;
|
|
1487
|
-
setDefault(key, model, form, value);
|
|
1488
|
-
return /*#__PURE__*/React__default.createElement(FormGroup, {
|
|
1489
|
-
row: true
|
|
1490
|
-
}, /*#__PURE__*/React__default.createElement(FormControlLabel, _extends({
|
|
1491
|
-
className: form.className,
|
|
1492
|
-
label: form.title && getLocalizedString(form.title),
|
|
1493
|
-
control: /*#__PURE__*/React__default.createElement(Checkbox$1, {
|
|
1494
|
-
name: form.key.slice(-1)[0],
|
|
1495
|
-
value: form.key.slice(-1)[0],
|
|
1496
|
-
checked: value || false,
|
|
1497
|
-
disabled: form.readonly,
|
|
1498
|
-
onChange: onChangeValidate
|
|
1499
|
-
})
|
|
1500
|
-
}, form.otherProps)));
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
var Checkbox = ComposedComponent(FormCheckbox);
|
|
1504
|
-
|
|
1505
|
-
var Help = function Help(_ref) {
|
|
1506
|
-
var _ref$form = _ref.form,
|
|
1507
|
-
description = _ref$form.description,
|
|
1508
|
-
variant = _ref$form.variant,
|
|
1509
|
-
align = _ref$form.align,
|
|
1510
|
-
color = _ref$form.color,
|
|
1511
|
-
noWrap = _ref$form.noWrap,
|
|
1512
|
-
paragraph = _ref$form.paragraph,
|
|
1513
|
-
otherProps = _ref$form.otherProps;
|
|
1514
|
-
return /*#__PURE__*/React__default.createElement(Typography, _extends({
|
|
1515
|
-
variant: variant,
|
|
1516
|
-
align: align,
|
|
1517
|
-
color: color,
|
|
1518
|
-
noWrap: noWrap,
|
|
1519
|
-
paragraph: paragraph
|
|
1520
|
-
}, otherProps), description);
|
|
1521
|
-
};
|
|
1522
|
-
|
|
1523
|
-
var styles$2 = function styles(theme) {
|
|
1524
|
-
return {
|
|
1525
|
-
arrayItem: {
|
|
1526
|
-
position: 'relative',
|
|
1527
|
-
padding: theme.spacing(),
|
|
1528
|
-
marginTop: theme.spacing(),
|
|
1529
|
-
display: 'flex'
|
|
1530
|
-
},
|
|
1531
|
-
deleteItemButton: {
|
|
1532
|
-
margin: [[theme.spacing(-1), theme.spacing(-1), 'auto', 'auto']]
|
|
1533
|
-
},
|
|
1534
|
-
addButton: {
|
|
1535
|
-
marginLeft: theme.spacing()
|
|
1536
|
-
},
|
|
1537
|
-
elementsContainer: {
|
|
1538
|
-
display: 'flex',
|
|
1539
|
-
flexWrap: 'wrap'
|
|
1540
|
-
},
|
|
1541
|
-
title: {
|
|
1542
|
-
margin: 'auto 0'
|
|
1543
|
-
}
|
|
1544
|
-
};
|
|
1545
|
-
};
|
|
1546
|
-
|
|
1547
|
-
var ArrayComponent = /*#__PURE__*/function (_Component) {
|
|
1548
|
-
_inheritsLoose(ArrayComponent, _Component);
|
|
1549
|
-
|
|
1550
|
-
ArrayComponent.assignItemId = function assignItemId(item) {
|
|
1551
|
-
var newItem = null;
|
|
1552
|
-
|
|
1553
|
-
if (item && typeof item === 'object' && Array.isArray(item)) {
|
|
1554
|
-
newItem = [].concat(item);
|
|
1555
|
-
} else if (item && typeof item === 'object' && !item[ArrayComponent.ITEM_ID]) {
|
|
1556
|
-
newItem = _extends({}, item);
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1559
|
-
if (newItem) {
|
|
1560
|
-
Object.defineProperty(newItem, ArrayComponent.ITEM_ID, {
|
|
1561
|
-
enumerable: false,
|
|
1562
|
-
writable: true
|
|
1563
|
-
});
|
|
1564
|
-
ArrayComponent.SEQUENCE += 1;
|
|
1565
|
-
newItem[ArrayComponent.ITEM_ID] = ArrayComponent.SEQUENCE;
|
|
1566
|
-
return newItem;
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
return item;
|
|
1570
|
-
};
|
|
1571
|
-
|
|
1572
|
-
function ArrayComponent(_props) {
|
|
1573
|
-
var _this;
|
|
1574
|
-
|
|
1575
|
-
_this = _Component.call(this, _props) || this;
|
|
1576
|
-
_this.SEQUENCE = 1;
|
|
1577
|
-
|
|
1578
|
-
_this.onAppend = function () {
|
|
1579
|
-
var _this$props = _this.props,
|
|
1580
|
-
form = _this$props.form,
|
|
1581
|
-
options = _this$props.options,
|
|
1582
|
-
onChangeValidate = _this$props.onChangeValidate;
|
|
1583
|
-
var model = _this.state.model;
|
|
1584
|
-
var empty;
|
|
1585
|
-
|
|
1586
|
-
if (form && form.schema && form.schema.items) {
|
|
1587
|
-
var items = form.schema.items;
|
|
1588
|
-
|
|
1589
|
-
if (items.type && items.type.indexOf('object') !== -1) {
|
|
1590
|
-
empty = {};
|
|
1591
|
-
|
|
1592
|
-
if (!options || options.setSchemaDefaults !== false) {
|
|
1593
|
-
empty = typeof items["default"] !== 'undefined' ? items["default"] : empty;
|
|
1594
|
-
|
|
1595
|
-
if (empty) {
|
|
1596
|
-
utils.traverseSchema(items, function (prop, path) {
|
|
1597
|
-
if (typeof prop["default"] !== 'undefined') {
|
|
1598
|
-
utils.selectOrSet(path, empty, prop["default"]);
|
|
1599
|
-
}
|
|
1600
|
-
});
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
} else if (items.type && items.type.indexOf('array') !== -1) {
|
|
1604
|
-
empty = [];
|
|
1605
|
-
|
|
1606
|
-
if (!options || options.setSchemaDefaults !== false) {
|
|
1607
|
-
empty = items["default"] || empty;
|
|
1608
|
-
}
|
|
1609
|
-
} else if (!options || options.setSchemaDefaults !== false) {
|
|
1610
|
-
empty = items["default"] || empty;
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
var newModel = model;
|
|
1615
|
-
ArrayComponent.assignItemId(empty);
|
|
1616
|
-
newModel.push(empty);
|
|
1617
|
-
|
|
1618
|
-
_this.setState({
|
|
1619
|
-
model: newModel
|
|
1620
|
-
});
|
|
1621
|
-
|
|
1622
|
-
onChangeValidate(model);
|
|
1623
|
-
};
|
|
1624
|
-
|
|
1625
|
-
_this.onDelete = function (index) {
|
|
1626
|
-
return function () {
|
|
1627
|
-
var model = _this.state.model;
|
|
1628
|
-
var onChangeValidate = _this.props.onChangeValidate;
|
|
1629
|
-
var newModel = model;
|
|
1630
|
-
newModel.splice(index, 1);
|
|
1631
|
-
|
|
1632
|
-
_this.setState({
|
|
1633
|
-
model: newModel
|
|
1634
|
-
});
|
|
1635
|
-
|
|
1636
|
-
onChangeValidate(model);
|
|
1637
|
-
};
|
|
1638
|
-
};
|
|
1639
|
-
|
|
1640
|
-
_this.getAddButton = function () {
|
|
1641
|
-
var _this$props2 = _this.props,
|
|
1642
|
-
form = _this$props2.form,
|
|
1643
|
-
classes = _this$props2.classes;
|
|
1644
|
-
|
|
1645
|
-
var AddButton = form.AddButton || function (props) {
|
|
1646
|
-
return /*#__PURE__*/React__default.createElement(Button, _extends({
|
|
1647
|
-
className: classes.addButton,
|
|
1648
|
-
variant: "contained",
|
|
1649
|
-
color: "primary"
|
|
1650
|
-
}, props));
|
|
1651
|
-
};
|
|
1652
|
-
|
|
1653
|
-
return /*#__PURE__*/React__default.createElement(AddButton, {
|
|
1654
|
-
onClick: _this.onAppend
|
|
1655
|
-
}, form.add || 'Add');
|
|
1656
|
-
};
|
|
1657
|
-
|
|
1658
|
-
var _this$props3 = _this.props,
|
|
1659
|
-
_form = _this$props3.form,
|
|
1660
|
-
_model = _this$props3.model;
|
|
1661
|
-
_this.state = {
|
|
1662
|
-
model: utils.selectOrSet(_form.key, _model) || []
|
|
1663
|
-
};
|
|
1664
|
-
return _this;
|
|
1665
|
-
}
|
|
1666
|
-
|
|
1667
|
-
ArrayComponent.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
|
|
1668
|
-
var form = props.form;
|
|
1669
|
-
var propsKey = form.key;
|
|
1670
|
-
|
|
1671
|
-
if (props.form && propsKey === state.formKey && props.model && props.model[propsKey] === state.model) {
|
|
1672
|
-
return null;
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
var model = utils.selectOrSet(propsKey, props.model) || [];
|
|
1676
|
-
return {
|
|
1677
|
-
formKey: propsKey,
|
|
1678
|
-
model: model.map(ArrayComponent.assignItemId)
|
|
1679
|
-
};
|
|
1680
|
-
};
|
|
1681
|
-
|
|
1682
|
-
var _proto = ArrayComponent.prototype;
|
|
1683
|
-
|
|
1684
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
1685
|
-
var _this$props4 = this.props,
|
|
1686
|
-
form = _this$props4.form,
|
|
1687
|
-
model = _this$props4.model;
|
|
1688
|
-
|
|
1689
|
-
if (form.startEmpty !== true && model.length === 0) {
|
|
1690
|
-
this.onAppend();
|
|
1691
|
-
}
|
|
1692
|
-
};
|
|
1693
|
-
|
|
1694
|
-
_proto.render = function render() {
|
|
1695
|
-
var _this2 = this;
|
|
1696
|
-
|
|
1697
|
-
var _this$props5 = this.props,
|
|
1698
|
-
classes = _this$props5.classes,
|
|
1699
|
-
form = _this$props5.form,
|
|
1700
|
-
builder = _this$props5.builder,
|
|
1701
|
-
model = _this$props5.model,
|
|
1702
|
-
mapper = _this$props5.mapper,
|
|
1703
|
-
onChange = _this$props5.onChange,
|
|
1704
|
-
getLocalizedString = _this$props5.localization.getLocalizedString;
|
|
1705
|
-
var stateModel = this.state.model;
|
|
1706
|
-
var arrays = [];
|
|
1707
|
-
|
|
1708
|
-
var _loop = function _loop(i) {
|
|
1709
|
-
var item = stateModel[i];
|
|
1710
|
-
var forms = form.items.map(function (eachForm, index) {
|
|
1711
|
-
var copy = ArrayComponent.copyWithIndex(eachForm, i);
|
|
1712
|
-
return builder(copy, model, index, mapper, onChange, builder, {
|
|
1713
|
-
arrayIndex: i
|
|
1714
|
-
});
|
|
1715
|
-
});
|
|
1716
|
-
arrays.push( /*#__PURE__*/React__default.createElement(Card, {
|
|
1717
|
-
className: classes.arrayItem,
|
|
1718
|
-
key: item && item[ArrayComponent.ITEM_ID] || i
|
|
1719
|
-
}, /*#__PURE__*/React__default.createElement("div", {
|
|
1720
|
-
className: classes.elementsContainer
|
|
1721
|
-
}, forms), /*#__PURE__*/React__default.createElement(IconButton, {
|
|
1722
|
-
onClick: _this2.onDelete(i),
|
|
1723
|
-
className: classes.deleteItemButton,
|
|
1724
|
-
size: "large"
|
|
1725
|
-
}, /*#__PURE__*/React__default.createElement(DeleteIcon, {
|
|
1726
|
-
fontSize: "small"
|
|
1727
|
-
}))));
|
|
1728
|
-
};
|
|
1729
|
-
|
|
1730
|
-
for (var i = 0; i < stateModel.length; i += 1) {
|
|
1731
|
-
_loop(i);
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
1735
|
-
className: classes.root
|
|
1736
|
-
}, /*#__PURE__*/React__default.createElement("div", {
|
|
1737
|
-
style: {
|
|
1738
|
-
display: 'flex'
|
|
1739
|
-
}
|
|
1740
|
-
}, /*#__PURE__*/React__default.createElement(FormLabel, {
|
|
1741
|
-
required: form.required,
|
|
1742
|
-
className: classes.title
|
|
1743
|
-
}, form.title && getLocalizedString(form.title)), this.getAddButton()), /*#__PURE__*/React__default.createElement("div", null, arrays));
|
|
1744
|
-
};
|
|
1745
|
-
|
|
1746
|
-
return ArrayComponent;
|
|
1747
|
-
}(React.Component);
|
|
1748
|
-
|
|
1749
|
-
ArrayComponent.setIndex = function (index) {
|
|
1750
|
-
return function (form) {
|
|
1751
|
-
if (form.key) {
|
|
1752
|
-
form.key[form.key.indexOf('')] = index;
|
|
1753
|
-
}
|
|
1754
|
-
};
|
|
1755
|
-
};
|
|
1756
|
-
|
|
1757
|
-
ArrayComponent.copyWithIndex = function (form, index) {
|
|
1758
|
-
var copy = cloneDeep(form);
|
|
1759
|
-
copy.arrayIndex = index;
|
|
1760
|
-
utils.traverseForm(copy, ArrayComponent.setIndex(index));
|
|
1761
|
-
return copy;
|
|
1762
|
-
};
|
|
1763
|
-
|
|
1764
|
-
ArrayComponent.ITEM_ID = Symbol('_SCHEMAFORM_ITEM_ID');
|
|
1765
|
-
var Array$1 = ComposedComponent(withStyles(styles$2)(ArrayComponent));
|
|
1766
|
-
|
|
1767
|
-
var styles$3 = function styles(theme) {
|
|
1768
|
-
return {
|
|
1769
|
-
root: {
|
|
1770
|
-
marginTop: theme.spacing(1)
|
|
1771
|
-
},
|
|
1772
|
-
fields: {
|
|
1773
|
-
marginLeft: theme.spacing(1)
|
|
1774
|
-
}
|
|
1775
|
-
};
|
|
1776
|
-
};
|
|
1777
|
-
|
|
1778
|
-
var FieldSet = function FieldSet(_ref) {
|
|
1779
|
-
var form = _ref.form,
|
|
1780
|
-
mapper = _ref.mapper,
|
|
1781
|
-
builder = _ref.builder,
|
|
1782
|
-
model = _ref.model,
|
|
1783
|
-
onChange = _ref.onChange,
|
|
1784
|
-
classes = _ref.classes,
|
|
1785
|
-
getLocalizedString = _ref.localization.getLocalizedString;
|
|
1786
|
-
var forms = form.items.map(function (f, index) {
|
|
1787
|
-
return builder(f, model, index, mapper, onChange, builder);
|
|
1788
|
-
});
|
|
1789
|
-
var className = classNames(classes.root, form.htmlClass);
|
|
1790
|
-
return /*#__PURE__*/React__default.createElement(FormControl, _extends({
|
|
1791
|
-
component: "fieldset",
|
|
1792
|
-
className: className,
|
|
1793
|
-
style: form.style
|
|
1794
|
-
}, form.otherProps), /*#__PURE__*/React__default.createElement(FormLabel, {
|
|
1795
|
-
component: "legend",
|
|
1796
|
-
required: form.required
|
|
1797
|
-
}, form.title && getLocalizedString(form.title)), /*#__PURE__*/React__default.createElement("div", {
|
|
1798
|
-
className: classes.fields
|
|
1799
|
-
}, forms));
|
|
1800
|
-
};
|
|
1801
|
-
|
|
1802
|
-
var FieldSet$1 = withStyles(styles$3)(FieldSet);
|
|
1803
|
-
|
|
1804
|
-
var TripleBoolean = /*#__PURE__*/function (_Component) {
|
|
1805
|
-
_inheritsLoose(TripleBoolean, _Component);
|
|
1806
|
-
|
|
1807
|
-
TripleBoolean.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps) {
|
|
1808
|
-
return {
|
|
1809
|
-
yesChecked: nextProps.value === 'yes',
|
|
1810
|
-
noChecked: nextProps.value === 'no'
|
|
1811
|
-
};
|
|
1812
|
-
};
|
|
1813
|
-
|
|
1814
|
-
function TripleBoolean(props) {
|
|
1815
|
-
var _this;
|
|
1816
|
-
|
|
1817
|
-
_this = _Component.call(this, props) || this;
|
|
1818
|
-
_this.divStyle = {
|
|
1819
|
-
padding: '20px'
|
|
1820
|
-
};
|
|
1821
|
-
_this.state = {
|
|
1822
|
-
yesChecked: false,
|
|
1823
|
-
noChecked: false
|
|
1824
|
-
};
|
|
1825
|
-
var _this$props = _this.props,
|
|
1826
|
-
model = _this$props.model,
|
|
1827
|
-
form = _this$props.form,
|
|
1828
|
-
value = _this$props.value,
|
|
1829
|
-
setDefault = _this$props.setDefault;
|
|
1830
|
-
var key = form.key;
|
|
1831
|
-
setDefault(key, model, form, value);
|
|
1832
|
-
return _this;
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
var _proto = TripleBoolean.prototype;
|
|
1836
|
-
|
|
1837
|
-
_proto.displaySwitch = function displaySwitch() {
|
|
1838
|
-
var _this$props2 = this.props,
|
|
1839
|
-
_this$props2$form = _this$props2.form,
|
|
1840
|
-
title = _this$props2$form.title,
|
|
1841
|
-
yesLabel = _this$props2$form.yesLabel,
|
|
1842
|
-
noLabel = _this$props2$form.noLabel,
|
|
1843
|
-
clearButtonLabel = _this$props2$form.clearButtonLabel,
|
|
1844
|
-
required = _this$props2$form.required,
|
|
1845
|
-
onChangeValidate = _this$props2.onChangeValidate,
|
|
1846
|
-
value = _this$props2.value,
|
|
1847
|
-
getLocalizedString = _this$props2.localization.getLocalizedString;
|
|
1848
|
-
var _this$state = this.state,
|
|
1849
|
-
yesChecked = _this$state.yesChecked,
|
|
1850
|
-
noChecked = _this$state.noChecked;
|
|
1851
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
1852
|
-
style: this.divStyle
|
|
1853
|
-
}, /*#__PURE__*/React__default.createElement(FormLabel, {
|
|
1854
|
-
required: required
|
|
1855
|
-
}, title && getLocalizedString(title)), /*#__PURE__*/React__default.createElement("br", null), /*#__PURE__*/React__default.createElement(material.FormGroup, null, /*#__PURE__*/React__default.createElement(material.FormControlLabel, {
|
|
1856
|
-
control: /*#__PURE__*/React__default.createElement(material.Checkbox, {
|
|
1857
|
-
onClick: function onClick(e) {
|
|
1858
|
-
onChangeValidate(e, 'yes');
|
|
1859
|
-
},
|
|
1860
|
-
checked: yesChecked
|
|
1861
|
-
}),
|
|
1862
|
-
label: yesLabel ? getLocalizedString(yesLabel) : 'Yes'
|
|
1863
|
-
}), /*#__PURE__*/React__default.createElement(material.FormControlLabel, {
|
|
1864
|
-
control: /*#__PURE__*/React__default.createElement(material.Checkbox, {
|
|
1865
|
-
onClick: function onClick(e) {
|
|
1866
|
-
onChangeValidate(e, 'no');
|
|
1867
|
-
},
|
|
1868
|
-
checked: noChecked
|
|
1869
|
-
}),
|
|
1870
|
-
label: noLabel ? getLocalizedString(noLabel) : 'No'
|
|
1871
|
-
})), value === 'yes' || value === 'no' ? /*#__PURE__*/React__default.createElement(material.Button, {
|
|
1872
|
-
id: "temp",
|
|
1873
|
-
variant: "text",
|
|
1874
|
-
color: "primary",
|
|
1875
|
-
onClick: function onClick(e) {
|
|
1876
|
-
return onChangeValidate(e, 'unanswered');
|
|
1877
|
-
}
|
|
1878
|
-
}, clearButtonLabel ? getLocalizedString(clearButtonLabel) : 'clear response') : '');
|
|
1879
|
-
};
|
|
1880
|
-
|
|
1881
|
-
_proto.render = function render() {
|
|
1882
|
-
return /*#__PURE__*/React__default.createElement(material.Card, null, this.displaySwitch());
|
|
1883
|
-
};
|
|
1884
|
-
|
|
1885
|
-
return TripleBoolean;
|
|
1886
|
-
}(React.Component);
|
|
1887
|
-
|
|
1888
|
-
var TripleBoolean$1 = ComposedComponent(TripleBoolean);
|
|
1889
|
-
|
|
1890
|
-
function Taxonomy(props) {
|
|
1891
|
-
var model = props.model,
|
|
1892
|
-
form = props.form,
|
|
1893
|
-
value = props.value,
|
|
1894
|
-
error = props.error,
|
|
1895
|
-
setDefault = props.setDefault,
|
|
1896
|
-
onChangeValidate = props.onChangeValidate;
|
|
1897
|
-
var key = form.key,
|
|
1898
|
-
title = form.title,
|
|
1899
|
-
action = form.action;
|
|
1900
|
-
setDefault(key, model, form, value);
|
|
1901
|
-
|
|
1902
|
-
var _useState = React.useState(value || []),
|
|
1903
|
-
taxonomies = _useState[0],
|
|
1904
|
-
setTaxonomies = _useState[1];
|
|
1905
|
-
|
|
1906
|
-
var _useState2 = React.useState([]),
|
|
1907
|
-
expanded = _useState2[0],
|
|
1908
|
-
setExpended = _useState2[1];
|
|
1909
|
-
|
|
1910
|
-
var _useState3 = React.useState([]),
|
|
1911
|
-
terms = _useState3[0],
|
|
1912
|
-
setTerms = _useState3[1];
|
|
1913
|
-
|
|
1914
|
-
React.useEffect(function () {
|
|
1915
|
-
onChangeValidate(taxonomies);
|
|
1916
|
-
}, [taxonomies]);
|
|
1917
|
-
|
|
1918
|
-
var fetchCateogry = function fetchCateogry(url) {
|
|
1919
|
-
var cookies = new Cookies();
|
|
1920
|
-
var headers = {
|
|
1921
|
-
'Content-Type': 'application/json'
|
|
1922
|
-
};
|
|
1923
|
-
if (cookies.get('csrf')) Object.assign(headers, {
|
|
1924
|
-
'X-CSRF-TOKEN': cookies.get('csrf')
|
|
1925
|
-
});
|
|
1926
|
-
fetch(url, {
|
|
1927
|
-
headers: headers,
|
|
1928
|
-
credentials: 'include'
|
|
1929
|
-
}).then(function (res) {
|
|
1930
|
-
if (res.ok) {
|
|
1931
|
-
return res.json();
|
|
1932
|
-
}
|
|
1933
|
-
|
|
1934
|
-
return res.text().then(function (text) {
|
|
1935
|
-
throw new Error(text);
|
|
1936
|
-
});
|
|
1937
|
-
}).then(function (res) {
|
|
1938
|
-
setTerms(res);
|
|
1939
|
-
})["catch"](function (error) {
|
|
1940
|
-
console.error(error);
|
|
1941
|
-
});
|
|
1942
|
-
};
|
|
1943
|
-
|
|
1944
|
-
React.useEffect(function () {
|
|
1945
|
-
var url = action.url;
|
|
1946
|
-
fetchCateogry(url);
|
|
1947
|
-
}, []);
|
|
1948
|
-
var icons = {
|
|
1949
|
-
check: /*#__PURE__*/React__default.createElement(CheckBoxIcon, {
|
|
1950
|
-
className: "rct-icon rct-icon-check"
|
|
1951
|
-
}),
|
|
1952
|
-
uncheck: /*#__PURE__*/React__default.createElement(CheckBoxOutlineBlankIcon, {
|
|
1953
|
-
className: "rct-icon rct-icon-uncheck"
|
|
1954
|
-
}),
|
|
1955
|
-
halfCheck: /*#__PURE__*/React__default.createElement(IndeterminateCheckBoxIcon, {
|
|
1956
|
-
className: "rct-icon rct-icon-half-check"
|
|
1957
|
-
}),
|
|
1958
|
-
expandClose: /*#__PURE__*/React__default.createElement(ChevronRightIcon, {
|
|
1959
|
-
className: "rct-icon rct-icon-expand-close"
|
|
1960
|
-
}),
|
|
1961
|
-
expandOpen: /*#__PURE__*/React__default.createElement(KeyboardArrowDownIcon, {
|
|
1962
|
-
className: "rct-icon rct-icon-expand-open"
|
|
1963
|
-
}),
|
|
1964
|
-
expandAll: /*#__PURE__*/React__default.createElement(AddBoxIcon, {
|
|
1965
|
-
className: "rct-icon rct-icon-expand-all"
|
|
1966
|
-
}),
|
|
1967
|
-
collapseAll: /*#__PURE__*/React__default.createElement(IndeterminateCheckBoxIcon, {
|
|
1968
|
-
className: "rct-icon rct-icon-collapse-all"
|
|
1969
|
-
}),
|
|
1970
|
-
parentClose: /*#__PURE__*/React__default.createElement(FolderIcon, {
|
|
1971
|
-
className: "rct-icon rct-icon-parent-close"
|
|
1972
|
-
}),
|
|
1973
|
-
parentOpen: /*#__PURE__*/React__default.createElement(FolderOpenIcon, {
|
|
1974
|
-
className: "rct-icon rct-icon-parent-open"
|
|
1975
|
-
}),
|
|
1976
|
-
leaf: /*#__PURE__*/React__default.createElement(InsertDriveFileIcon, {
|
|
1977
|
-
className: "rct-icon rct-icon-leaf-close"
|
|
1978
|
-
})
|
|
1979
|
-
};
|
|
1980
|
-
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(FormLabel, {
|
|
1981
|
-
required: form.required
|
|
1982
|
-
}, title), /*#__PURE__*/React__default.createElement(CheckboxTree, {
|
|
1983
|
-
nodes: terms,
|
|
1984
|
-
checked: taxonomies,
|
|
1985
|
-
expanded: expanded,
|
|
1986
|
-
onCheck: function onCheck(checked) {
|
|
1987
|
-
return setTaxonomies(checked);
|
|
1988
|
-
},
|
|
1989
|
-
onExpand: function onExpand(expanded) {
|
|
1990
|
-
return setExpended(expanded);
|
|
1991
|
-
},
|
|
1992
|
-
icons: icons,
|
|
1993
|
-
noCascade: true
|
|
1994
|
-
}), error ? /*#__PURE__*/React__default.createElement(FormHelperText, {
|
|
1995
|
-
error: true
|
|
1996
|
-
}, error) : null);
|
|
1997
|
-
}
|
|
1998
|
-
|
|
1999
|
-
var Taxonomy$1 = ComposedComponent(Taxonomy);
|
|
2000
|
-
|
|
2001
|
-
var formatDate = function formatDate(date) {
|
|
2002
|
-
var value = date && typeof date === 'object' && date.toISOString().slice(0, 10) || date;
|
|
2003
|
-
if (!value) value = '';
|
|
2004
|
-
if (value.length > 0) value = new Date(value).toISOString().slice(0, 10);
|
|
2005
|
-
return value;
|
|
2006
|
-
};
|
|
2007
|
-
|
|
2008
|
-
var SchemaForm = /*#__PURE__*/function (_Component) {
|
|
2009
|
-
_inheritsLoose(SchemaForm, _Component);
|
|
2010
|
-
|
|
2011
|
-
function SchemaForm(props) {
|
|
2012
|
-
var _this;
|
|
2013
|
-
|
|
2014
|
-
_this = _Component.call(this, props) || this;
|
|
2015
|
-
_this.mapper = {
|
|
2016
|
-
number: Number$1,
|
|
2017
|
-
text: Text$1,
|
|
2018
|
-
password: Text$1,
|
|
2019
|
-
textarea: TextArea$1,
|
|
2020
|
-
markdown: Markdown$1,
|
|
2021
|
-
textsuggest: TextSuggest$1,
|
|
2022
|
-
select: Select$1,
|
|
2023
|
-
taxonomy: Taxonomy$1,
|
|
2024
|
-
radios: Radios$1,
|
|
2025
|
-
date: DateComponent,
|
|
2026
|
-
timestamp: Timestamp$1,
|
|
2027
|
-
checkbox: Checkbox,
|
|
2028
|
-
help: Help,
|
|
2029
|
-
array: Array$1,
|
|
2030
|
-
tBoolean: TripleBoolean$1,
|
|
2031
|
-
fieldset: FieldSet$1,
|
|
2032
|
-
tuple: FieldSet$1,
|
|
2033
|
-
multiselect: MultiSelect$1
|
|
2034
|
-
};
|
|
2035
|
-
|
|
2036
|
-
_this.setDefault = function (key, model, form, value) {
|
|
2037
|
-
var onModelChange = _this.props.onModelChange;
|
|
2038
|
-
var currentValue = utils.selectOrSet(key, model);
|
|
2039
|
-
if (isNil(currentValue) && !isNil(value)) onModelChange(key, value, form.type, form);
|
|
2040
|
-
};
|
|
2041
|
-
|
|
2042
|
-
_this.getLocalization = function () {
|
|
2043
|
-
var localization = _this.props.localization;
|
|
2044
|
-
return {
|
|
2045
|
-
getLocalizedString: localization && localization.getLocalizedString ? localization.getLocalizedString : function (value) {
|
|
2046
|
-
return value;
|
|
2047
|
-
},
|
|
2048
|
-
getLocalizedNumber: localization && localization.getLocalizedNumber ? localization.getLocalizedNumber : function (value) {
|
|
2049
|
-
return value;
|
|
2050
|
-
},
|
|
2051
|
-
getLocalizedDate: localization && localization.getLocalizedDate ? localization.getLocalizedDate : formatDate
|
|
2052
|
-
};
|
|
2053
|
-
};
|
|
2054
|
-
|
|
2055
|
-
_this.builder = _this.builder.bind(_assertThisInitialized(_this));
|
|
2056
|
-
return _this;
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
var _proto = SchemaForm.prototype;
|
|
2060
|
-
|
|
2061
|
-
_proto.builder = function builder(form, model, index, mapper, onChange, _builder) {
|
|
2062
|
-
var _this$props = this.props,
|
|
2063
|
-
errors = _this$props.errors,
|
|
2064
|
-
showErrors = _this$props.showErrors,
|
|
2065
|
-
evalContext = _this$props.evalContext;
|
|
2066
|
-
var Field = this.mapper[form.type];
|
|
2067
|
-
|
|
2068
|
-
if (!Field) {
|
|
2069
|
-
return null;
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
|
-
if (form.condition && !utils.safeEval(form.condition, _extends({
|
|
2073
|
-
model: model,
|
|
2074
|
-
form: form
|
|
2075
|
-
}, evalContext))) {
|
|
2076
|
-
return null;
|
|
2077
|
-
}
|
|
2078
|
-
|
|
2079
|
-
var key = form.key && form.key.join('.') || index;
|
|
2080
|
-
var error = errors && key in errors ? errors[key] : null;
|
|
2081
|
-
return /*#__PURE__*/React__default.createElement(Field, {
|
|
2082
|
-
model: model,
|
|
2083
|
-
form: form,
|
|
2084
|
-
key: key,
|
|
2085
|
-
onChange: onChange,
|
|
2086
|
-
setDefault: this.setDefault,
|
|
2087
|
-
mapper: mapper,
|
|
2088
|
-
builder: _builder,
|
|
2089
|
-
errorText: error,
|
|
2090
|
-
localization: this.getLocalization(),
|
|
2091
|
-
showErrors: showErrors
|
|
2092
|
-
});
|
|
2093
|
-
};
|
|
2094
|
-
|
|
2095
|
-
_proto.render = function render() {
|
|
2096
|
-
var _this2 = this;
|
|
2097
|
-
|
|
2098
|
-
var _this$props2 = this.props,
|
|
2099
|
-
schema = _this$props2.schema,
|
|
2100
|
-
form = _this$props2.form,
|
|
2101
|
-
ignore = _this$props2.ignore,
|
|
2102
|
-
option = _this$props2.option,
|
|
2103
|
-
model = _this$props2.model,
|
|
2104
|
-
className = _this$props2.className,
|
|
2105
|
-
onModelChange = _this$props2.onModelChange,
|
|
2106
|
-
mapper = _this$props2.mapper;
|
|
2107
|
-
var merged = utils.merge(schema, form, ignore, option);
|
|
2108
|
-
var mergedMapper = this.mapper;
|
|
2109
|
-
|
|
2110
|
-
if (mapper) {
|
|
2111
|
-
mergedMapper = merge$1(this.mapper, mapper);
|
|
2112
|
-
}
|
|
2113
|
-
|
|
2114
|
-
var forms = merged.map(function (formPart, index) {
|
|
2115
|
-
return _this2.builder(formPart, model, index, mergedMapper, onModelChange, _this2.builder);
|
|
2116
|
-
});
|
|
2117
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
2118
|
-
className: className
|
|
2119
|
-
}, forms);
|
|
2120
|
-
};
|
|
2121
|
-
|
|
2122
|
-
return SchemaForm;
|
|
2123
|
-
}(React.Component);
|
|
2124
|
-
|
|
2125
|
-
SchemaForm.defaultProps = {
|
|
2126
|
-
localization: undefined,
|
|
2127
|
-
showErrors: false
|
|
2128
|
-
};
|
|
2129
|
-
|
|
2130
|
-
exports.Array = Array$1;
|
|
2131
|
-
exports.ComposedComponent = ComposedComponent;
|
|
2132
|
-
exports.SchemaForm = SchemaForm;
|
|
2133
|
-
exports.utils = utils;
|
|
2134
|
-
//# sourceMappingURL=index.js.map
|