UNPKG

1.75 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = getField;
7
8function 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")); // array 默认使用list,array?enum 默认使用checkboxes,*?enum 默认使用select
22
23 list.push('*?enum');
24 }
25
26 if (format) {
27 list.push("".concat(type, ":").concat(format));
28 }
29
30 list.push(type); // 放在最后兜底,其他都不match时使用type默认的组件
31
32 var found = '';
33 list.some(function (item) {
34 found = map[item];
35 return !!found;
36 });
37 return found;
38}
39
40function 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']; // Field能否被重定义
50
51 var fieldCanRedefine = false;
52 var Field; // ui:widget 是字符串,从generated中查,不是的话,就是本身
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