@hi-ui/schema-fields 4.0.0-experimental.1

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.
Files changed (139) hide show
  1. package/README.md +11 -0
  2. package/lib/cjs/base.js +125 -0
  3. package/lib/cjs/components/image-preview/index.js +63 -0
  4. package/lib/cjs/components/span/index.js +33 -0
  5. package/lib/cjs/components/upload-bridge/index.js +227 -0
  6. package/lib/cjs/components/upload-bridge/utils.js +73 -0
  7. package/lib/cjs/ctx.js +70 -0
  8. package/lib/cjs/editable/ctx.js +45 -0
  9. package/lib/cjs/editable/editable.js +141 -0
  10. package/lib/cjs/editable/index.js +62 -0
  11. package/lib/cjs/editable/readonly.js +36 -0
  12. package/lib/cjs/editable/simple.js +61 -0
  13. package/lib/cjs/editable/use-readonly.js +200 -0
  14. package/lib/cjs/extensible/selectable/index.js +114 -0
  15. package/lib/cjs/extensible/selectable/match-cascader.js +184 -0
  16. package/lib/cjs/fields/basic/cascader/index.js +98 -0
  17. package/lib/cjs/fields/basic/check-cascader/index.js +58 -0
  18. package/lib/cjs/fields/basic/check-select/index.js +89 -0
  19. package/lib/cjs/fields/basic/check-tree-select/index.js +61 -0
  20. package/lib/cjs/fields/basic/checkbox/index.js +84 -0
  21. package/lib/cjs/fields/basic/counter/index.js +40 -0
  22. package/lib/cjs/fields/basic/radio/index.js +44 -0
  23. package/lib/cjs/fields/basic/rating/index.js +40 -0
  24. package/lib/cjs/fields/basic/select/index.js +98 -0
  25. package/lib/cjs/fields/basic/slider/index.js +40 -0
  26. package/lib/cjs/fields/basic/switch/index.js +47 -0
  27. package/lib/cjs/fields/basic/textarea/index.js +40 -0
  28. package/lib/cjs/fields/basic/time-picker/index.js +45 -0
  29. package/lib/cjs/fields/basic/time-picker/index.scss.js +18 -0
  30. package/lib/cjs/fields/basic/tree-select/index.js +61 -0
  31. package/lib/cjs/fields/basic/upload/custom.js +29 -0
  32. package/lib/cjs/fields/basic/upload/index.js +48 -0
  33. package/lib/cjs/fields/enhance/number-range/index.js +39 -0
  34. package/lib/cjs/fields/semantic/date/index.js +82 -0
  35. package/lib/cjs/fields/semantic/image/index.js +65 -0
  36. package/lib/cjs/fields/semantic/image/upload.js +32 -0
  37. package/lib/cjs/fields/semantic/link/index.js +96 -0
  38. package/lib/cjs/fields/semantic/number/index.js +106 -0
  39. package/lib/cjs/fields/semantic/tag/index.js +164 -0
  40. package/lib/cjs/fields/semantic/tag/index.scss.js +18 -0
  41. package/lib/cjs/fields/semantic/text/index.js +61 -0
  42. package/lib/cjs/index.js +145 -0
  43. package/lib/cjs/utils/batch-dep-update.js +40 -0
  44. package/lib/cjs/utils/form-binding.js +40 -0
  45. package/lib/cjs/utils/label.js +34 -0
  46. package/lib/cjs/utils.js +35 -0
  47. package/lib/esm/base.js +111 -0
  48. package/lib/esm/components/image-preview/index.js +49 -0
  49. package/lib/esm/components/span/index.js +20 -0
  50. package/lib/esm/components/upload-bridge/index.js +214 -0
  51. package/lib/esm/components/upload-bridge/utils.js +66 -0
  52. package/lib/esm/ctx.js +55 -0
  53. package/lib/esm/editable/ctx.js +32 -0
  54. package/lib/esm/editable/editable.js +129 -0
  55. package/lib/esm/editable/index.js +44 -0
  56. package/lib/esm/editable/readonly.js +24 -0
  57. package/lib/esm/editable/simple.js +49 -0
  58. package/lib/esm/editable/use-readonly.js +193 -0
  59. package/lib/esm/extensible/selectable/index.js +101 -0
  60. package/lib/esm/extensible/selectable/match-cascader.js +179 -0
  61. package/lib/esm/fields/basic/cascader/index.js +83 -0
  62. package/lib/esm/fields/basic/check-cascader/index.js +44 -0
  63. package/lib/esm/fields/basic/check-select/index.js +75 -0
  64. package/lib/esm/fields/basic/check-tree-select/index.js +47 -0
  65. package/lib/esm/fields/basic/checkbox/index.js +70 -0
  66. package/lib/esm/fields/basic/counter/index.js +26 -0
  67. package/lib/esm/fields/basic/radio/index.js +30 -0
  68. package/lib/esm/fields/basic/rating/index.js +26 -0
  69. package/lib/esm/fields/basic/select/index.js +83 -0
  70. package/lib/esm/fields/basic/slider/index.js +26 -0
  71. package/lib/esm/fields/basic/switch/index.js +33 -0
  72. package/lib/esm/fields/basic/textarea/index.js +26 -0
  73. package/lib/esm/fields/basic/time-picker/index.js +31 -0
  74. package/lib/esm/fields/basic/time-picker/index.scss.js +13 -0
  75. package/lib/esm/fields/basic/tree-select/index.js +47 -0
  76. package/lib/esm/fields/basic/upload/custom.js +16 -0
  77. package/lib/esm/fields/basic/upload/index.js +34 -0
  78. package/lib/esm/fields/enhance/number-range/index.js +26 -0
  79. package/lib/esm/fields/semantic/date/index.js +67 -0
  80. package/lib/esm/fields/semantic/image/index.js +51 -0
  81. package/lib/esm/fields/semantic/image/upload.js +20 -0
  82. package/lib/esm/fields/semantic/link/index.js +82 -0
  83. package/lib/esm/fields/semantic/number/index.js +91 -0
  84. package/lib/esm/fields/semantic/tag/index.js +149 -0
  85. package/lib/esm/fields/semantic/tag/index.scss.js +13 -0
  86. package/lib/esm/fields/semantic/text/index.js +47 -0
  87. package/lib/esm/index.js +85 -0
  88. package/lib/esm/utils/batch-dep-update.js +35 -0
  89. package/lib/esm/utils/form-binding.js +34 -0
  90. package/lib/esm/utils/label.js +21 -0
  91. package/lib/esm/utils.js +27 -0
  92. package/lib/types/base.d.ts +44 -0
  93. package/lib/types/components/async-refill-placeholder/index.d.ts +7 -0
  94. package/lib/types/components/image-preview/index.d.ts +5 -0
  95. package/lib/types/components/span/index.d.ts +8 -0
  96. package/lib/types/components/upload-bridge/index.d.ts +5 -0
  97. package/lib/types/components/upload-bridge/type.d.ts +26 -0
  98. package/lib/types/components/upload-bridge/utils.d.ts +11 -0
  99. package/lib/types/ctx.d.ts +21 -0
  100. package/lib/types/editable/ctx.d.ts +5 -0
  101. package/lib/types/editable/editable.d.ts +18 -0
  102. package/lib/types/editable/index.d.ts +14 -0
  103. package/lib/types/editable/readonly.d.ts +8 -0
  104. package/lib/types/editable/simple.d.ts +8 -0
  105. package/lib/types/editable/type.d.ts +9 -0
  106. package/lib/types/editable/use-readonly.d.ts +26 -0
  107. package/lib/types/extensible/selectable/index.d.ts +31 -0
  108. package/lib/types/extensible/selectable/match-cascader.d.ts +19 -0
  109. package/lib/types/extensible/selectable/type.d.ts +16 -0
  110. package/lib/types/fields/basic/cascader/index.d.ts +10 -0
  111. package/lib/types/fields/basic/check-cascader/index.d.ts +11 -0
  112. package/lib/types/fields/basic/check-select/index.d.ts +34 -0
  113. package/lib/types/fields/basic/check-tree-select/index.d.ts +10 -0
  114. package/lib/types/fields/basic/checkbox/index.d.ts +19 -0
  115. package/lib/types/fields/basic/counter/index.d.ts +7 -0
  116. package/lib/types/fields/basic/radio/index.d.ts +7 -0
  117. package/lib/types/fields/basic/rating/index.d.ts +7 -0
  118. package/lib/types/fields/basic/select/index.d.ts +12 -0
  119. package/lib/types/fields/basic/slider/index.d.ts +7 -0
  120. package/lib/types/fields/basic/switch/index.d.ts +7 -0
  121. package/lib/types/fields/basic/textarea/index.d.ts +7 -0
  122. package/lib/types/fields/basic/time-picker/index.d.ts +8 -0
  123. package/lib/types/fields/basic/tree-select/index.d.ts +11 -0
  124. package/lib/types/fields/basic/upload/custom.d.ts +3 -0
  125. package/lib/types/fields/basic/upload/index.d.ts +8 -0
  126. package/lib/types/fields/enhance/number-range/index.d.ts +7 -0
  127. package/lib/types/fields/semantic/date/index.d.ts +15 -0
  128. package/lib/types/fields/semantic/image/index.d.ts +11 -0
  129. package/lib/types/fields/semantic/image/upload.d.ts +3 -0
  130. package/lib/types/fields/semantic/link/index.d.ts +31 -0
  131. package/lib/types/fields/semantic/number/index.d.ts +21 -0
  132. package/lib/types/fields/semantic/tag/index.d.ts +78 -0
  133. package/lib/types/fields/semantic/text/index.d.ts +13 -0
  134. package/lib/types/index.d.ts +108 -0
  135. package/lib/types/utils/batch-dep-update.d.ts +13 -0
  136. package/lib/types/utils/form-binding.d.ts +11 -0
  137. package/lib/types/utils/label.d.ts +11 -0
  138. package/lib/types/utils.d.ts +15 -0
  139. package/package.json +98 -0
@@ -0,0 +1,179 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
11
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
12
+ if (it) return (it = it.call(o)).next.bind(it);
13
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
14
+ if (it) o = it;
15
+ var i = 0;
16
+ return function () {
17
+ if (i >= o.length) return {
18
+ done: true
19
+ };
20
+ return {
21
+ done: false,
22
+ value: o[i++]
23
+ };
24
+ };
25
+ }
26
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
27
+ }
28
+ function _unsupportedIterableToArray(o, minLen) {
29
+ if (!o) return;
30
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
31
+ var n = Object.prototype.toString.call(o).slice(8, -1);
32
+ if (n === "Object" && o.constructor) n = o.constructor.name;
33
+ if (n === "Map" || n === "Set") return Array.from(o);
34
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
35
+ }
36
+ function _arrayLikeToArray(arr, len) {
37
+ if (len == null || len > arr.length) len = arr.length;
38
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
39
+ arr2[i] = arr[i];
40
+ }
41
+ return arr2;
42
+ }
43
+ /**
44
+ * 在嵌套选项数据中匹配多个路径
45
+ * @param values 二维数组,包含多个级联路径,例如 [['hubei', 'wuhan'], ['guangdong', 'shenzhen']]
46
+ * @param options 嵌套选项数据,包含 children 的树形结构
47
+ * @param extra 配置选项
48
+ * @returns 二维数组,保持输入的结构,每个路径对应一个匹配的选项链数组
49
+ *
50
+ * 边界条件处理:
51
+ * - 部分匹配:如果路径中某一层找不到,返回已匹配的部分(而不是空数组)
52
+ * - 缺失title:如果选项的title字段不存在,自动使用id字段作为默认值
53
+ * - 完全不匹配:如果第一层就找不到,返回空数组
54
+ */
55
+ function matchCascaderOpts(values, options, extra) {
56
+ if (extra === void 0) {
57
+ extra = {};
58
+ }
59
+ var _extra = extra,
60
+ _extra$fieldNames = _extra.fieldNames,
61
+ fieldNames = _extra$fieldNames === void 0 ? {} : _extra$fieldNames;
62
+ var _fieldNames$id = fieldNames.id,
63
+ idFieldKey = _fieldNames$id === void 0 ? 'id' : _fieldNames$id,
64
+ _fieldNames$title = fieldNames.title,
65
+ titleFieldKey = _fieldNames$title === void 0 ? 'title' : _fieldNames$title;
66
+ /**
67
+ * 根据单个路径查找对应的选项链
68
+ * @param path 单个路径数组,例如 ['hubei', 'wuhan']
69
+ * @param opts 当前层级的选项数据
70
+ * @returns 匹配的选项数组
71
+ */
72
+ function findPathOptions(path, opts) {
73
+ var result = [];
74
+ var currentOptions = opts;
75
+ var _loop = function _loop() {
76
+ var valueId = _step.value;
77
+ var found = currentOptions.find(function (item) {
78
+ return String(item[idFieldKey]) === String(valueId);
79
+ });
80
+ if (found) {
81
+ result.push(found);
82
+ // 如果还有下一层,继续在 children 中查找
83
+ currentOptions = found.children || [];
84
+ } else {
85
+ // 如果某一层找不到对应的选项,就停止查找
86
+ return "break";
87
+ }
88
+ };
89
+ for (var _iterator = _createForOfIteratorHelperLoose(path), _step; !(_step = _iterator()).done;) {
90
+ var _ret = _loop();
91
+ if (_ret === "break") break;
92
+ }
93
+ // 返回部分匹配的结果,即使路径不完整也返回已匹配的部分
94
+ return result;
95
+ }
96
+ try {
97
+ // 转换函数:将原始选项转换为 MatchedNestOptsType 格式
98
+ // const convertToMatchedType =
99
+ // 处理每个路径,保持二维数组结构
100
+ return values.map(function (path) {
101
+ if (!Array.isArray(path)) return [];
102
+ var pathOptions = findPathOptions(path, options);
103
+ return pathOptions.map(function (option) {
104
+ var id = option[idFieldKey];
105
+ var title = option[titleFieldKey] || String(id); // 如果 title 不存在,使用 id 作为默认值
106
+ return {
107
+ id: id,
108
+ title: title
109
+ };
110
+ });
111
+ });
112
+ } catch (error) {
113
+ console.error('matchCascaderOpts', error);
114
+ return [];
115
+ }
116
+ }
117
+ // 测试用例示例(可取消注释运行)
118
+ /*
119
+ const testOpts = [
120
+ {
121
+ id: 'hubei',
122
+ title: '湖北',
123
+ children: [
124
+ { id: 'wuhan', title: '武汉' },
125
+ { id: 'xiangyang', title: '襄阳' },
126
+ { id: 'noTitle' }, // 测试没有 title 的情况
127
+ ],
128
+ },
129
+ {
130
+ id: 'beijing',
131
+ title: '北京',
132
+ children: [
133
+ { id: 'haidian', title: '海淀' },
134
+ { id: 'chaoyang', title: '朝阳' },
135
+ ],
136
+ },
137
+ {
138
+ id: 'guangdong',
139
+ // 测试第一层没有 title 的情况
140
+ children: [{ id: 'shenzhen', title: '深圳' }],
141
+ },
142
+ ]
143
+
144
+ // 边界条件测试用例
145
+ console.log('=== 正常匹配 ===')
146
+ console.log(matchCascaderOpts([['hubei', 'wuhan']], testOpts))
147
+ // 预期输出: [[{ id: 'hubei', title: '湖北' }, { id: 'wuhan', title: '武汉' }]]
148
+
149
+ console.log('\n=== 第一层查到,第二层没查到(部分匹配) ===')
150
+ console.log(matchCascaderOpts([['hubei', 'nonexistent']], testOpts))
151
+ // 预期输出: [[{ id: 'hubei', title: '湖北' }]]
152
+
153
+ console.log('\n=== ID查到了,title没查到(使用ID作为默认值) ===')
154
+ console.log(matchCascaderOpts([['hubei', 'noTitle']], testOpts))
155
+ // 预期输出: [[{ id: 'hubei', title: '湖北' }, { id: 'noTitle', title: 'noTitle' }]]
156
+
157
+ console.log('\n=== 第一层没有title(使用ID作为默认值) ===')
158
+ console.log(matchCascaderOpts([['guangdong', 'shenzhen']], testOpts))
159
+ // 预期输出: [[{ id: 'guangdong', title: 'guangdong' }, { id: 'shenzhen', title: '深圳' }]]
160
+
161
+ console.log('\n=== 完全匹配不到 ===')
162
+ console.log(matchCascaderOpts([['nonexistent', 'city']], testOpts))
163
+ // 预期输出: [[]]
164
+
165
+ console.log('\n=== 多路径混合测试 ===')
166
+ console.log(
167
+ matchCascaderOpts(
168
+ [
169
+ ['hubei', 'wuhan'], // 正常匹配
170
+ ['hubei', 'nonexistent'], // 部分匹配
171
+ ['guangdong', 'shenzhen'], // 第一层无title
172
+ ['nonexistent'], // 完全不匹配
173
+ ],
174
+ testOpts
175
+ )
176
+ )
177
+ */
178
+
179
+ export { matchCascaderOpts };
@@ -0,0 +1,83 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
11
+ import React from 'react';
12
+ import Cascader from '@hi-ui/cascader';
13
+ import { AsyncOptsDataInjector } from '@hi-ui/schema-option-injector';
14
+ import { InterruptInjector } from '@hi-ui/schema-interrupt-injector';
15
+ import { ProSelectableField } from '../../../extensible/selectable/index.js';
16
+ import { matchCascaderOpts } from '../../../extensible/selectable/match-cascader.js';
17
+ var ProCascader = /*#__PURE__*/function (_ProSelectableField) {
18
+ _inheritsLoose(ProCascader, _ProSelectableField);
19
+ function ProCascader() {
20
+ return _ProSelectableField.apply(this, arguments) || this;
21
+ }
22
+ var _proto = ProCascader.prototype;
23
+ _proto.renderFormItem = function renderFormItem(_, ctx) {
24
+ var _a, _b;
25
+ var fieldProps = this.getFieldProps({
26
+ overlay: (_a = ctx.field.extra) === null || _a === void 0 ? void 0 : _a.popperProps
27
+ }, ctx);
28
+ // 过滤掉原始参数中的自引用属性,防止 immer 在处理数据时出现崩溃
29
+ var hookedSetSelectedRawOption = this.hookedSetSelectedRawOption.bind(this, ctx);
30
+ return /*#__PURE__*/React.createElement(AsyncOptsDataInjector
31
+ // options
32
+ , Object.assign({}, fieldProps, {
33
+ renderCtx: ctx,
34
+ setSelectedRawOption: hookedSetSelectedRawOption
35
+ }), /*#__PURE__*/React.createElement(InterruptInjector, {
36
+ config: (_b = ctx.field.control) === null || _b === void 0 ? void 0 : _b.interrupt
37
+ }, /*#__PURE__*/React.createElement(Cascader, null)));
38
+ };
39
+ _proto.renderEditable = function renderEditable(data, ctx) {
40
+ // 首先尝试渲染已选中元素的标题
41
+ var selectedEl = this.renderEditableForStringSelected(data, ctx);
42
+ if (selectedEl) return selectedEl;
43
+ // 随后尝试渲染首次回显元素
44
+ var firstRefillEl = this.renderEditableForStringFirstRefill(data, ctx, {
45
+ dftRender: _ProSelectableField.prototype.renderEditable.bind(this),
46
+ RefillComponent: CascaderRefillPlaceholder
47
+ });
48
+ if (firstRefillEl) return firstRefillEl;
49
+ return _ProSelectableField.prototype.renderEditable.call(this, data, ctx, {
50
+ suffix: this.suffixEl
51
+ });
52
+ };
53
+ return ProCascader;
54
+ }(ProSelectableField);
55
+ function CascaderRefillPlaceholder(props) {
56
+ var _a, _b, _c, _d;
57
+ var _props$data = props.data,
58
+ options = _props$data === void 0 ? [] : _props$data,
59
+ ctx = props.ctx,
60
+ fieldNames = props.fieldNames,
61
+ instance = props.instance;
62
+ try {
63
+ var _hereValue = (_a = props.value) !== null && _a !== void 0 ? _a : [];
64
+ // 使用公用的 matchCascaderOpts 函数 // 注意这里取了0
65
+ var matchedOptions = (_b = matchCascaderOpts([_hereValue], options, {
66
+ fieldNames: fieldNames
67
+ })[0]) !== null && _b !== void 0 ? _b : [];
68
+ // 显示所有匹配到的标题
69
+ var displayTitle = matchedOptions.map(function (item) {
70
+ return item.title;
71
+ }).join('/');
72
+ // 最终是显示字符串,所以直接使用 dftRender 渲染
73
+ return /*#__PURE__*/React.createElement(React.Fragment, null, (_c = props.dftRender) === null || _c === void 0 ? void 0 : _c.call(props, displayTitle, ctx, {
74
+ suffix: instance.suffixEl
75
+ }));
76
+ } catch (error) {
77
+ console.error('CascaderRefillPlaceholder', error);
78
+ return /*#__PURE__*/React.createElement(React.Fragment, null, (_d = props.dftRender) === null || _d === void 0 ? void 0 : _d.call(props, props.value, ctx, {
79
+ suffix: instance.suffixEl
80
+ }));
81
+ }
82
+ }
83
+ export { CascaderRefillPlaceholder, ProCascader };
@@ -0,0 +1,44 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
11
+ import React from 'react';
12
+ import CheckCascader from '@hi-ui/check-cascader';
13
+ import { AsyncOptsDataInjector } from '@hi-ui/schema-option-injector';
14
+ import { ProSelectableField } from '../../../extensible/selectable/index.js';
15
+ var ProCheckCascader = /*#__PURE__*/function (_ProSelectableField) {
16
+ _inheritsLoose(ProCheckCascader, _ProSelectableField);
17
+ function ProCheckCascader() {
18
+ var _this;
19
+ _this = _ProSelectableField.apply(this, arguments) || this;
20
+ _this.dftFieldProps = {
21
+ changeOnSelect: true
22
+ };
23
+ return _this;
24
+ }
25
+ var _proto = ProCheckCascader.prototype;
26
+ _proto.renderFormItem = function renderFormItem(_, ctx) {
27
+ var _a;
28
+ var fieldProps = this.getFieldProps(Object.assign(Object.assign({}, this.dftFieldProps), {
29
+ overlay: (_a = ctx.field.extra) === null || _a === void 0 ? void 0 : _a.popperProps
30
+ }), ctx);
31
+ // 过滤掉原始参数中的自引用属性,防止 immer 在处理数据时出现崩溃
32
+ var hookedSetSelectedRawOption = this.hookedSetSelectedRawOption.bind(this, ctx);
33
+ return /*#__PURE__*/React.createElement(AsyncOptsDataInjector
34
+ // options
35
+ , Object.assign({}, fieldProps, {
36
+ renderCtx: ctx,
37
+ setSelectedRawOption: hookedSetSelectedRawOption
38
+ }), /*#__PURE__*/React.createElement(CheckCascader, {
39
+ data: []
40
+ }));
41
+ };
42
+ return ProCheckCascader;
43
+ }(ProSelectableField);
44
+ export { ProCheckCascader };
@@ -0,0 +1,75 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
11
+ import { __rest } from 'tslib';
12
+ import React from 'react';
13
+ import CheckSelect from '@hi-ui/check-select';
14
+ import { AsyncOptsDataInjector } from '@hi-ui/schema-option-injector';
15
+ import { ProSelectableField } from '../../../extensible/selectable/index.js';
16
+ import { ProTag } from '../../semantic/tag/index.js';
17
+ var ProCheckSelect = /*#__PURE__*/function (_ProSelectableField) {
18
+ _inheritsLoose(ProCheckSelect, _ProSelectableField);
19
+ function ProCheckSelect() {
20
+ return _ProSelectableField.apply(this, arguments) || this;
21
+ }
22
+ var _proto = ProCheckSelect.prototype;
23
+ _proto.render = function render(data, ctx) {
24
+ var title = this.getOptionTitle(ctx) || data;
25
+ var tagRef = this.tagRef || new ProTag();
26
+ this.tagRef = tagRef;
27
+ var _this$getSelfFieldPro = this.getSelfFieldProps(ctx),
28
+ tagProps = _this$getSelfFieldPro.tagProps;
29
+ return tagRef.render(title, Object.assign(Object.assign({}, ctx), {
30
+ field: {
31
+ fieldProps: tagProps
32
+ }
33
+ }));
34
+ };
35
+ _proto.getSelfFieldProps = function getSelfFieldProps(ctx) {
36
+ var _a;
37
+ var _b = this.getFieldProps({
38
+ placeholder: this.getDftPlaceholder(ctx),
39
+ overlay: (_a = ctx.field.extra) === null || _a === void 0 ? void 0 : _a.popperProps
40
+ }, ctx),
41
+ bordered = _b.bordered,
42
+ colorPreset = _b.colorPreset,
43
+ tagProps = _b.tagProps,
44
+ fieldProps = __rest(_b, ["bordered", "colorPreset", "tagProps"]);
45
+ return {
46
+ fieldProps: fieldProps,
47
+ tagProps: Object.assign({
48
+ bordered: bordered,
49
+ colorPreset: colorPreset
50
+ }, tagProps)
51
+ };
52
+ };
53
+ _proto.renderFormItem = function renderFormItem(_, ctx) {
54
+ var _a;
55
+ var _this$getSelfFieldPro2 = this.getSelfFieldProps(ctx),
56
+ fieldProps = _this$getSelfFieldPro2.fieldProps;
57
+ return /*#__PURE__*/React.createElement(AsyncOptsDataInjector, Object.assign({}, fieldProps, {
58
+ renderCtx: ctx,
59
+ setSelectedRawOption: (_a = ctx.field.payload) === null || _a === void 0 ? void 0 : _a.setSelectedRawOption
60
+ }), /*#__PURE__*/React.createElement(CheckSelect, null));
61
+ };
62
+ _proto.getDftPlaceholder = function getDftPlaceholder(ctx) {
63
+ var titleText = ctx.field._titleText;
64
+ if (titleText) return "\u8BF7\u9009\u62E9" + titleText;
65
+ };
66
+ _proto.renderEditable = function renderEditable(data, ctx) {
67
+ var dataKey = ctx.dataKey;
68
+ var title = this.getOptionTitle(ctx, dataKey);
69
+ return _ProSelectableField.prototype.renderEditable.call(this, title, ctx, {
70
+ suffix: this.suffixEl
71
+ });
72
+ };
73
+ return ProCheckSelect;
74
+ }(ProSelectableField);
75
+ export { ProCheckSelect };
@@ -0,0 +1,47 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
11
+ import React from 'react';
12
+ import CheckTreeSelect from '@hi-ui/check-tree-select';
13
+ import { AsyncOptsDataInjector } from '@hi-ui/schema-option-injector';
14
+ import { ProSelectableField } from '../../../extensible/selectable/index.js';
15
+ var ProCheckTreeSelect = /*#__PURE__*/function (_ProSelectableField) {
16
+ _inheritsLoose(ProCheckTreeSelect, _ProSelectableField);
17
+ function ProCheckTreeSelect() {
18
+ return _ProSelectableField.apply(this, arguments) || this;
19
+ }
20
+ var _proto = ProCheckTreeSelect.prototype;
21
+ _proto.render = function render(data, ctx) {
22
+ var title = this.getOptionTitle(ctx) || data;
23
+ return _ProSelectableField.prototype.render.call(this, title, ctx);
24
+ };
25
+ _proto.renderFormItem = function renderFormItem(_, ctx) {
26
+ var _a, _b;
27
+ var fieldProps = this.getFieldProps({
28
+ overlay: (_a = ctx.field.extra) === null || _a === void 0 ? void 0 : _a.popperProps
29
+ }, ctx);
30
+ // NOTE 实测 searchMode 不传时,无法开启搜索
31
+ // 考虑到是有接口搜索时,会按照关键字过滤,因此默认采用 filter 模式
32
+ if (fieldProps.request) fieldProps.searchMode = 'filter';
33
+ return /*#__PURE__*/React.createElement(AsyncOptsDataInjector, Object.assign({}, fieldProps, {
34
+ renderCtx: ctx,
35
+ setSelectedRawOption: (_b = ctx.field.payload) === null || _b === void 0 ? void 0 : _b.setSelectedRawOption
36
+ }), /*#__PURE__*/React.createElement(CheckTreeSelect, null));
37
+ };
38
+ _proto.renderEditable = function renderEditable(data, ctx) {
39
+ var dataKey = ctx.dataKey;
40
+ var title = this.getOptionTitle(ctx, dataKey);
41
+ return _ProSelectableField.prototype.renderEditable.call(this, title, ctx, {
42
+ suffix: this.suffixEl
43
+ });
44
+ };
45
+ return ProCheckTreeSelect;
46
+ }(ProSelectableField);
47
+ export { ProCheckTreeSelect };
@@ -0,0 +1,70 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
11
+ import { __rest } from 'tslib';
12
+ import React from 'react';
13
+ import Checkbox from '@hi-ui/checkbox';
14
+ import { getPrefixCls } from '@hi-ui/classname';
15
+ import { GridHelper } from '@hi-ui/schema-auto-grid';
16
+ import { getBoolConfig } from '@hi-ui/schema-utils';
17
+ import { ProField } from '../../../base.js';
18
+ var ProCheckbox = /*#__PURE__*/function (_ProField) {
19
+ _inheritsLoose(ProCheckbox, _ProField);
20
+ function ProCheckbox() {
21
+ return _ProField.apply(this, arguments) || this;
22
+ }
23
+ var _proto = ProCheckbox.prototype;
24
+ _proto.renderFormItem = function renderFormItem(_, ctx) {
25
+ var _a = this.getFieldProps({}, ctx),
26
+ gridProps = _a.grid,
27
+ fieldProps = __rest(_a, ["grid"]);
28
+ // gridProps 为 true 或者对象时,使用网格布局
29
+ if (gridProps) {
30
+ return this.renderGridFormItem(_, ctx, {
31
+ gridProps: gridProps,
32
+ fieldProps: fieldProps
33
+ });
34
+ }
35
+ return this.renderNormalFormItem(_, ctx, {
36
+ fieldProps: fieldProps
37
+ });
38
+ };
39
+ _proto.renderNormalFormItem = function renderNormalFormItem(_, ctx, extra) {
40
+ var fieldProps = extra.fieldProps;
41
+ return /*#__PURE__*/React.createElement(Checkbox.Group, Object.assign({}, fieldProps));
42
+ };
43
+ _proto.renderGridFormItem = function renderGridFormItem(_, ctx, extra) {
44
+ var _a, _b;
45
+ var _c = extra.fieldProps,
46
+ _c$data = _c.data,
47
+ data = _c$data === void 0 ? [] : _c$data,
48
+ restFieldProps = __rest(_c, ["data"]);
49
+ var value = (_a = ctx.formBinding.value) !== null && _a !== void 0 ? _a : [];
50
+ var gridProps = (_b = getBoolConfig(extra.gridProps, {})) !== null && _b !== void 0 ? _b : {};
51
+ return /*#__PURE__*/React.createElement(Checkbox.Group, Object.assign({}, restFieldProps), /*#__PURE__*/React.createElement(GridHelper, Object.assign({}, gridProps),
52
+ // fork from hiui Checkbox.Group
53
+ // https://github.com/XiaoMi/hiui/blob/0180764ef5deb334f70404cabd3d715708d41b06/packages/ui/checkbox/src/CheckboxGroup.tsx#L65-L76
54
+ data.map(function (_ref) {
55
+ var id = _ref.id,
56
+ disabled = _ref.disabled,
57
+ title = _ref.title;
58
+ return /*#__PURE__*/React.createElement(Checkbox, {
59
+ key: id,
60
+ value: id,
61
+ name: restFieldProps.name,
62
+ disabled: disabled,
63
+ checked: value.includes(id),
64
+ className: getPrefixCls('checkbox-group') + "__item"
65
+ }, title);
66
+ })));
67
+ };
68
+ return ProCheckbox;
69
+ }(ProField);
70
+ export { ProCheckbox };
@@ -0,0 +1,26 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
11
+ import React from 'react';
12
+ import Counter from '@hi-ui/counter';
13
+ import { ProField } from '../../../base.js';
14
+ var ProCounter = /*#__PURE__*/function (_ProField) {
15
+ _inheritsLoose(ProCounter, _ProField);
16
+ function ProCounter() {
17
+ return _ProField.apply(this, arguments) || this;
18
+ }
19
+ var _proto = ProCounter.prototype;
20
+ _proto.renderFormItem = function renderFormItem(_, ctx) {
21
+ var fieldProps = this.getFieldProps({}, ctx);
22
+ return /*#__PURE__*/React.createElement(Counter, Object.assign({}, fieldProps));
23
+ };
24
+ return ProCounter;
25
+ }(ProField);
26
+ export { ProCounter };
@@ -0,0 +1,30 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
11
+ import React from 'react';
12
+ import Radio from '@hi-ui/radio';
13
+ import { InterruptInjector } from '@hi-ui/schema-interrupt-injector';
14
+ import { ProField } from '../../../base.js';
15
+ var ProRadio = /*#__PURE__*/function (_ProField) {
16
+ _inheritsLoose(ProRadio, _ProField);
17
+ function ProRadio() {
18
+ return _ProField.apply(this, arguments) || this;
19
+ }
20
+ var _proto = ProRadio.prototype;
21
+ _proto.renderFormItem = function renderFormItem(_, ctx) {
22
+ var _a;
23
+ var fieldProps = this.getFieldProps({}, ctx);
24
+ return /*#__PURE__*/React.createElement(InterruptInjector, {
25
+ config: (_a = ctx.field.control) === null || _a === void 0 ? void 0 : _a.interrupt
26
+ }, /*#__PURE__*/React.createElement(Radio.Group, Object.assign({}, fieldProps)));
27
+ };
28
+ return ProRadio;
29
+ }(ProField);
30
+ export { ProRadio };
@@ -0,0 +1,26 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
11
+ import React from 'react';
12
+ import Rating from '@hi-ui/rating';
13
+ import { ProField } from '../../../base.js';
14
+ var ProRating = /*#__PURE__*/function (_ProField) {
15
+ _inheritsLoose(ProRating, _ProField);
16
+ function ProRating() {
17
+ return _ProField.apply(this, arguments) || this;
18
+ }
19
+ var _proto = ProRating.prototype;
20
+ _proto.renderFormItem = function renderFormItem(_, ctx) {
21
+ var fieldProps = this.getFieldProps({}, ctx);
22
+ return /*#__PURE__*/React.createElement(Rating, Object.assign({}, fieldProps));
23
+ };
24
+ return ProRating;
25
+ }(ProField);
26
+ export { ProRating };
@@ -0,0 +1,83 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
11
+ import React from 'react';
12
+ import Select from '@hi-ui/select';
13
+ import { AsyncOptsDataInjector } from '@hi-ui/schema-option-injector';
14
+ import { InterruptInjector } from '@hi-ui/schema-interrupt-injector';
15
+ import { ProSelectableField } from '../../../extensible/selectable/index.js';
16
+ var ProSelect = /*#__PURE__*/function (_ProSelectableField) {
17
+ _inheritsLoose(ProSelect, _ProSelectableField);
18
+ function ProSelect() {
19
+ return _ProSelectableField.apply(this, arguments) || this;
20
+ }
21
+ var _proto = ProSelect.prototype;
22
+ _proto.render = function render(data, ctx) {
23
+ var title = this.getOptionTitle(ctx) || data;
24
+ return _ProSelectableField.prototype.render.call(this, title, ctx);
25
+ };
26
+ _proto.renderFormItem = function renderFormItem(_, ctx) {
27
+ var _a, _b, _c;
28
+ var fieldProps = this.getFieldProps({
29
+ placeholder: this.getDftPlaceholder(ctx),
30
+ overlay: (_a = ctx.field.extra) === null || _a === void 0 ? void 0 : _a.popperProps
31
+ }, ctx);
32
+ return /*#__PURE__*/React.createElement(AsyncOptsDataInjector, Object.assign({}, fieldProps, {
33
+ renderCtx: ctx,
34
+ setSelectedRawOption: (_b = ctx.field.payload) === null || _b === void 0 ? void 0 : _b.setSelectedRawOption
35
+ }), /*#__PURE__*/React.createElement(InterruptInjector, {
36
+ config: (_c = ctx.field.control) === null || _c === void 0 ? void 0 : _c.interrupt
37
+ }, /*#__PURE__*/React.createElement(Select, null)));
38
+ };
39
+ _proto.renderEditable = function renderEditable(data, ctx) {
40
+ // 首先尝试渲染已选中元素的标题
41
+ var selectedEl = this.renderEditableForStringSelected(data, ctx);
42
+ if (selectedEl) return selectedEl;
43
+ // 随后尝试渲染首次回显元素
44
+ var firstRefillEl = this.renderEditableForStringFirstRefill(data, ctx, {
45
+ dftRender: _ProSelectableField.prototype.renderEditable.bind(this),
46
+ RefillComponent: SelectRefillPlaceholder
47
+ });
48
+ if (firstRefillEl) return firstRefillEl;
49
+ return _ProSelectableField.prototype.renderEditable.call(this, data, ctx, {
50
+ suffix: this.suffixEl
51
+ });
52
+ };
53
+ return ProSelect;
54
+ }(ProSelectableField);
55
+ function SelectRefillPlaceholder(props) {
56
+ var _a, _b, _c;
57
+ var _props$data = props.data,
58
+ options = _props$data === void 0 ? [] : _props$data,
59
+ ctx = props.ctx,
60
+ fieldNames = props.fieldNames,
61
+ instance = props.instance;
62
+ var _ref = fieldNames || {},
63
+ _ref$id = _ref.id,
64
+ idFieldKey = _ref$id === void 0 ? 'id' : _ref$id,
65
+ _ref$title = _ref.title,
66
+ titleFieldKey = _ref$title === void 0 ? 'title' : _ref$title;
67
+ try {
68
+ var matchedOpts = options.filter(function (item) {
69
+ return item[idFieldKey] === props.value;
70
+ });
71
+ var displayTitle = (_a = matchedOpts[0]) === null || _a === void 0 ? void 0 : _a[titleFieldKey];
72
+ // 最终是显示字符串,所以直接使用 dftRender 渲染
73
+ return /*#__PURE__*/React.createElement(React.Fragment, null, (_b = props.dftRender) === null || _b === void 0 ? void 0 : _b.call(props, displayTitle, ctx, {
74
+ suffix: instance.suffixEl
75
+ }));
76
+ } catch (error) {
77
+ console.error('SelectRefillPlaceholder', error);
78
+ return /*#__PURE__*/React.createElement(React.Fragment, null, (_c = props.dftRender) === null || _c === void 0 ? void 0 : _c.call(props, props.value, ctx, {
79
+ suffix: instance.suffixEl
80
+ }));
81
+ }
82
+ }
83
+ export { ProSelect, SelectRefillPlaceholder };