1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = getField;
|
7 |
|
8 | function getWidgetName(schema, map) {
|
9 | var type = schema.type,
|
10 | format = schema.format,
|
11 | enums = schema.enum,
|
12 | readonly = schema.readonly;
|
13 | var list = [];
|
14 |
|
15 | if (readonly) {
|
16 | list.push("".concat(type, "?readonly"));
|
17 | list.push('*?readonly');
|
18 | }
|
19 |
|
20 | if (enums) {
|
21 | list.push("".concat(type, "?enum"));
|
22 |
|
23 | list.push('*?enum');
|
24 | }
|
25 |
|
26 | if (format) {
|
27 | list.push("".concat(type, ":").concat(format));
|
28 | }
|
29 |
|
30 | list.push(type);
|
31 |
|
32 | var found = '';
|
33 | list.some(function (item) {
|
34 | found = map[item];
|
35 | return !!found;
|
36 | });
|
37 | return found;
|
38 | }
|
39 |
|
40 | function getField() {
|
41 | var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
42 |
|
43 | var _ref = arguments.length > 1 ? arguments[1] : undefined,
|
44 | customized = _ref.customized,
|
45 | generated = _ref.generated,
|
46 | mapping = _ref.mapping;
|
47 |
|
48 | var widget = schema['ui:widget'],
|
49 | field = schema['ui:field'];
|
50 |
|
51 | var fieldCanRedefine = false;
|
52 | var Field;
|
53 |
|
54 | var _widget = typeof widget === 'string' ? generated[widget] : widget;
|
55 |
|
56 | if (field && !Field) {
|
57 | Field = typeof field === 'string' ? customized[field] : field;
|
58 | }
|
59 |
|
60 | if (!Field && _widget) {
|
61 | Field = _widget;
|
62 | }
|
63 |
|
64 | if (!Field && !_widget) {
|
65 | Field = generated[getWidgetName(schema, mapping)];
|
66 | fieldCanRedefine = !!Field;
|
67 | }
|
68 |
|
69 | return {
|
70 | fieldCanRedefine: fieldCanRedefine,
|
71 | Field: Field || null
|
72 | };
|
73 | } |
\ | No newline at end of file |