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