amis-core 6.9.0 → 6.10.0-beta.0

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 (307) hide show
  1. package/esm/Root.js +1 -1
  2. package/esm/RootRenderer.js +4 -2
  3. package/esm/SchemaRenderer.d.ts +1 -0
  4. package/esm/SchemaRenderer.js +8 -4
  5. package/esm/Scoped.d.ts +1 -1
  6. package/esm/Scoped.js +1 -1
  7. package/esm/StatusScoped.js +1 -1
  8. package/esm/StyleManager.js +1 -1
  9. package/esm/WithRootStore.js +1 -1
  10. package/esm/WithStore.js +1 -1
  11. package/esm/actions/Action.js +4 -1
  12. package/esm/actions/AjaxAction.js +1 -1
  13. package/esm/actions/BreakAction.js +1 -1
  14. package/esm/actions/BroadcastAction.d.ts +1 -1
  15. package/esm/actions/BroadcastAction.js +6 -6
  16. package/esm/actions/CmptAction.d.ts +1 -0
  17. package/esm/actions/CmptAction.js +51 -51
  18. package/esm/actions/ContinueAction.js +1 -1
  19. package/esm/actions/CopyAction.js +1 -1
  20. package/esm/actions/CustomAction.js +1 -1
  21. package/esm/actions/DialogAction.js +1 -1
  22. package/esm/actions/DrawerAction.js +1 -1
  23. package/esm/actions/EmailAction.js +1 -1
  24. package/esm/actions/EventAction.js +1 -1
  25. package/esm/actions/LinkAction.js +1 -1
  26. package/esm/actions/LoopAction.js +1 -1
  27. package/esm/actions/PageAction.js +1 -1
  28. package/esm/actions/ParallelAction.js +1 -1
  29. package/esm/actions/PrintAction.js +1 -1
  30. package/esm/actions/StatusAction.js +1 -1
  31. package/esm/actions/SwitchAction.js +1 -1
  32. package/esm/actions/ToastAction.js +1 -1
  33. package/esm/actions/WaitAction.js +1 -1
  34. package/esm/components/CustomStyle.js +1 -1
  35. package/esm/components/ErrorBoundary.js +1 -1
  36. package/esm/components/LazyComponent.js +1 -1
  37. package/esm/components/Overlay.js +13 -16
  38. package/esm/components/PopOver.js +2 -2
  39. package/esm/env.js +1 -1
  40. package/esm/envOverwrite.js +1 -1
  41. package/esm/factory.d.ts +1 -1
  42. package/esm/factory.js +5 -3
  43. package/esm/index.d.ts +4 -3
  44. package/esm/index.js +10 -9
  45. package/esm/locale.js +1 -1
  46. package/esm/polyfills.js +1 -1
  47. package/esm/renderers/Form.js +1 -1
  48. package/esm/renderers/Item.d.ts +1 -0
  49. package/esm/renderers/Item.js +2 -2
  50. package/esm/renderers/Options.d.ts +46 -1
  51. package/esm/renderers/Options.js +921 -914
  52. package/esm/renderers/Placeholder.js +1 -1
  53. package/esm/renderers/builtin.js +1 -1
  54. package/esm/renderers/register.js +1 -1
  55. package/esm/renderers/wrapControl.d.ts +2 -1
  56. package/esm/renderers/wrapControl.js +3 -3
  57. package/esm/store/app.js +1 -1
  58. package/esm/store/combo.js +1 -1
  59. package/esm/store/crud.d.ts +4 -2
  60. package/esm/store/crud.js +39 -141
  61. package/esm/store/form.js +1 -1
  62. package/esm/store/formItem.js +2 -2
  63. package/esm/store/iRenderer.js +1 -1
  64. package/esm/store/index.js +1 -1
  65. package/esm/store/list.js +1 -1
  66. package/esm/store/manager.js +1 -1
  67. package/esm/store/modal.js +1 -1
  68. package/esm/store/node.js +1 -1
  69. package/esm/store/pagination.js +1 -1
  70. package/esm/store/root.js +1 -1
  71. package/esm/store/service.js +1 -1
  72. package/esm/store/status.js +1 -1
  73. package/esm/store/table.js +1 -1
  74. package/esm/store/table2.js +1 -1
  75. package/esm/theme.js +1 -1
  76. package/esm/utils/Animation.js +1 -1
  77. package/esm/utils/ColorScale.js +1 -1
  78. package/esm/utils/DataSchema.js +1 -1
  79. package/esm/utils/DataScope.js +1 -1
  80. package/esm/utils/RootClose.js +1 -1
  81. package/esm/utils/SimpleMap.js +1 -1
  82. package/esm/utils/animations.js +1 -1
  83. package/esm/utils/api.d.ts +2 -1
  84. package/esm/utils/api.js +6 -4
  85. package/esm/utils/arraySlice.js +1 -1
  86. package/esm/utils/attachmentAdpator.js +4 -1
  87. package/esm/utils/autobind.js +1 -1
  88. package/esm/utils/browser.js +1 -1
  89. package/esm/utils/columnsSplit.js +1 -1
  90. package/esm/utils/concatData.js +1 -1
  91. package/esm/utils/dataMapping.js +1 -1
  92. package/esm/utils/date.js +1 -1
  93. package/esm/utils/debug.d.ts +3 -3
  94. package/esm/utils/debug.js +104 -37
  95. package/esm/utils/decodeEntity.js +1 -1
  96. package/esm/utils/dom.js +1 -1
  97. package/esm/utils/errors.js +1 -1
  98. package/esm/utils/escapeHtml.js +1 -1
  99. package/esm/utils/filter-schema.js +1 -1
  100. package/esm/utils/filter.js +1 -1
  101. package/esm/utils/formatDuration.js +1 -1
  102. package/esm/utils/formula.js +1 -1
  103. package/esm/utils/getVariable.js +1 -1
  104. package/esm/utils/grammar.js +1 -1
  105. package/esm/utils/handleAction.js +1 -1
  106. package/esm/utils/helper.d.ts +7 -0
  107. package/esm/utils/helper.js +87 -2
  108. package/esm/utils/highlight.js +1 -1
  109. package/esm/utils/icon.js +1 -1
  110. package/esm/utils/image.js +1 -1
  111. package/esm/utils/index.d.ts +1 -0
  112. package/esm/utils/isPureVariable.js +1 -1
  113. package/esm/utils/json-schema-2-amis-schema.js +1 -1
  114. package/esm/utils/keyToPath.js +1 -1
  115. package/esm/utils/labelToString.js +1 -1
  116. package/esm/utils/loopTooMuch.d.ts +1 -0
  117. package/esm/utils/loopTooMuch.js +27 -0
  118. package/esm/utils/makeSorter.js +1 -1
  119. package/esm/utils/math.js +1 -1
  120. package/esm/utils/memoryParse.js +1 -1
  121. package/esm/utils/normalizeLink.js +1 -1
  122. package/esm/utils/normalizeOptions.js +1 -1
  123. package/esm/utils/object.js +1 -1
  124. package/esm/utils/offset.js +1 -1
  125. package/esm/utils/offsetParent.js +1 -1
  126. package/esm/utils/optionValueCompare.js +1 -1
  127. package/esm/utils/position.js +11 -6
  128. package/esm/utils/prettyBytes.js +1 -1
  129. package/esm/utils/printElement.js +1 -1
  130. package/esm/utils/renderer-event.d.ts +4 -0
  131. package/esm/utils/renderer-event.js +97 -11
  132. package/esm/utils/replaceText.js +1 -1
  133. package/esm/utils/resize-sensor.js +1 -1
  134. package/esm/utils/resolveCondition.js +1 -1
  135. package/esm/utils/resolveVariable.js +1 -1
  136. package/esm/utils/resolveVariableAndFilter.js +1 -1
  137. package/esm/utils/resolveVariableAndFilterForAsync.js +1 -1
  138. package/esm/utils/scrollPosition.js +1 -1
  139. package/esm/utils/string2regExp.js +1 -1
  140. package/esm/utils/stripNumber.js +1 -1
  141. package/esm/utils/style-helper.js +1 -1
  142. package/esm/utils/style.js +1 -1
  143. package/esm/utils/toNumber.js +1 -1
  144. package/esm/utils/tokenize.js +1 -1
  145. package/esm/utils/tpl-builtin.js +1 -1
  146. package/esm/utils/tpl-lodash.js +1 -1
  147. package/esm/utils/tpl.js +1 -1
  148. package/esm/utils/uncontrollable.js +1 -1
  149. package/esm/utils/validateId.js +1 -1
  150. package/esm/utils/validations.js +5 -3
  151. package/esm/utils/visitedCache.js +1 -1
  152. package/lib/Root.js +1 -1
  153. package/lib/RootRenderer.d.ts +1 -1
  154. package/lib/RootRenderer.js +4 -2
  155. package/lib/SchemaRenderer.d.ts +1 -0
  156. package/lib/SchemaRenderer.js +7 -3
  157. package/lib/Scoped.d.ts +1 -1
  158. package/lib/Scoped.js +1 -1
  159. package/lib/StatusScoped.js +1 -1
  160. package/lib/StyleManager.js +1 -1
  161. package/lib/WithRootStore.js +1 -1
  162. package/lib/WithStore.js +1 -1
  163. package/lib/actions/Action.js +4 -1
  164. package/lib/actions/AjaxAction.js +1 -1
  165. package/lib/actions/BreakAction.js +1 -1
  166. package/lib/actions/BroadcastAction.d.ts +1 -1
  167. package/lib/actions/BroadcastAction.js +5 -5
  168. package/lib/actions/CmptAction.d.ts +1 -0
  169. package/lib/actions/CmptAction.js +50 -50
  170. package/lib/actions/ContinueAction.js +1 -1
  171. package/lib/actions/CopyAction.js +1 -1
  172. package/lib/actions/CustomAction.js +1 -1
  173. package/lib/actions/DialogAction.js +1 -1
  174. package/lib/actions/DrawerAction.js +1 -1
  175. package/lib/actions/EmailAction.js +1 -1
  176. package/lib/actions/EventAction.js +1 -1
  177. package/lib/actions/LinkAction.js +1 -1
  178. package/lib/actions/LoopAction.js +1 -1
  179. package/lib/actions/PageAction.js +1 -1
  180. package/lib/actions/ParallelAction.js +1 -1
  181. package/lib/actions/PrintAction.js +1 -1
  182. package/lib/actions/StatusAction.js +1 -1
  183. package/lib/actions/SwitchAction.js +1 -1
  184. package/lib/actions/ToastAction.js +1 -1
  185. package/lib/actions/WaitAction.js +1 -1
  186. package/lib/components/CustomStyle.js +1 -1
  187. package/lib/components/ErrorBoundary.js +1 -1
  188. package/lib/components/LazyComponent.js +1 -1
  189. package/lib/components/Overlay.js +11 -14
  190. package/lib/components/PopOver.js +2 -2
  191. package/lib/env.js +1 -1
  192. package/lib/envOverwrite.js +1 -1
  193. package/lib/factory.d.ts +1 -1
  194. package/lib/factory.js +5 -3
  195. package/lib/index.d.ts +4 -3
  196. package/lib/index.js +14 -5
  197. package/lib/locale.js +1 -1
  198. package/lib/polyfills.js +1 -1
  199. package/lib/renderers/Form.js +1 -1
  200. package/lib/renderers/Item.d.ts +1 -0
  201. package/lib/renderers/Item.js +2 -2
  202. package/lib/renderers/Options.d.ts +46 -1
  203. package/lib/renderers/Options.js +920 -912
  204. package/lib/renderers/Placeholder.js +1 -1
  205. package/lib/renderers/builtin.js +1 -1
  206. package/lib/renderers/register.js +1 -1
  207. package/lib/renderers/wrapControl.d.ts +2 -1
  208. package/lib/renderers/wrapControl.js +3 -3
  209. package/lib/store/app.js +1 -1
  210. package/lib/store/combo.d.ts +25 -24
  211. package/lib/store/combo.js +1 -1
  212. package/lib/store/crud.d.ts +4 -2
  213. package/lib/store/crud.js +37 -139
  214. package/lib/store/form.d.ts +11 -10
  215. package/lib/store/form.js +1 -1
  216. package/lib/store/formItem.js +2 -2
  217. package/lib/store/iRenderer.js +1 -1
  218. package/lib/store/index.js +1 -1
  219. package/lib/store/list.js +1 -1
  220. package/lib/store/manager.js +1 -1
  221. package/lib/store/modal.js +1 -1
  222. package/lib/store/node.js +1 -1
  223. package/lib/store/pagination.js +1 -1
  224. package/lib/store/root.js +1 -1
  225. package/lib/store/service.js +1 -1
  226. package/lib/store/status.js +1 -1
  227. package/lib/store/table.d.ts +21 -20
  228. package/lib/store/table.js +1 -1
  229. package/lib/store/table2.js +1 -1
  230. package/lib/theme.js +1 -1
  231. package/lib/utils/Animation.js +1 -1
  232. package/lib/utils/ColorScale.js +1 -1
  233. package/lib/utils/DataSchema.js +1 -1
  234. package/lib/utils/DataScope.js +1 -1
  235. package/lib/utils/RootClose.js +1 -1
  236. package/lib/utils/SimpleMap.js +1 -1
  237. package/lib/utils/animations.js +1 -1
  238. package/lib/utils/api.d.ts +2 -1
  239. package/lib/utils/api.js +5 -2
  240. package/lib/utils/arraySlice.js +1 -1
  241. package/lib/utils/attachmentAdpator.js +4 -1
  242. package/lib/utils/autobind.js +1 -1
  243. package/lib/utils/browser.js +1 -1
  244. package/lib/utils/columnsSplit.js +1 -1
  245. package/lib/utils/concatData.js +1 -1
  246. package/lib/utils/dataMapping.js +1 -1
  247. package/lib/utils/date.js +1 -1
  248. package/lib/utils/debug.d.ts +3 -3
  249. package/lib/utils/debug.js +103 -36
  250. package/lib/utils/decodeEntity.js +1 -1
  251. package/lib/utils/dom.js +1 -1
  252. package/lib/utils/errors.js +1 -1
  253. package/lib/utils/escapeHtml.js +1 -1
  254. package/lib/utils/filter-schema.js +1 -1
  255. package/lib/utils/filter.js +1 -1
  256. package/lib/utils/formatDuration.js +1 -1
  257. package/lib/utils/formula.js +1 -1
  258. package/lib/utils/getVariable.js +1 -1
  259. package/lib/utils/grammar.js +1 -1
  260. package/lib/utils/handleAction.js +1 -1
  261. package/lib/utils/helper.d.ts +7 -0
  262. package/lib/utils/helper.js +87 -1
  263. package/lib/utils/highlight.js +1 -1
  264. package/lib/utils/icon.js +1 -1
  265. package/lib/utils/image.js +1 -1
  266. package/lib/utils/index.d.ts +1 -0
  267. package/lib/utils/isPureVariable.js +1 -1
  268. package/lib/utils/json-schema-2-amis-schema.js +1 -1
  269. package/lib/utils/keyToPath.js +1 -1
  270. package/lib/utils/labelToString.js +1 -1
  271. package/lib/utils/loopTooMuch.d.ts +1 -0
  272. package/lib/utils/loopTooMuch.js +31 -0
  273. package/lib/utils/makeSorter.js +1 -1
  274. package/lib/utils/math.js +1 -1
  275. package/lib/utils/memoryParse.js +1 -1
  276. package/lib/utils/normalizeLink.js +1 -1
  277. package/lib/utils/normalizeOptions.js +1 -1
  278. package/lib/utils/object.js +1 -1
  279. package/lib/utils/offset.js +1 -1
  280. package/lib/utils/offsetParent.js +1 -1
  281. package/lib/utils/optionValueCompare.js +1 -1
  282. package/lib/utils/position.js +11 -6
  283. package/lib/utils/prettyBytes.js +1 -1
  284. package/lib/utils/printElement.js +1 -1
  285. package/lib/utils/renderer-event.d.ts +4 -0
  286. package/lib/utils/renderer-event.js +99 -10
  287. package/lib/utils/replaceText.js +1 -1
  288. package/lib/utils/resize-sensor.js +1 -1
  289. package/lib/utils/resolveCondition.js +1 -1
  290. package/lib/utils/resolveVariable.js +1 -1
  291. package/lib/utils/resolveVariableAndFilter.js +1 -1
  292. package/lib/utils/resolveVariableAndFilterForAsync.js +1 -1
  293. package/lib/utils/scrollPosition.js +1 -1
  294. package/lib/utils/string2regExp.js +1 -1
  295. package/lib/utils/stripNumber.js +1 -1
  296. package/lib/utils/style-helper.js +1 -1
  297. package/lib/utils/style.js +1 -1
  298. package/lib/utils/toNumber.js +1 -1
  299. package/lib/utils/tokenize.js +1 -1
  300. package/lib/utils/tpl-builtin.js +1 -1
  301. package/lib/utils/tpl-lodash.js +1 -1
  302. package/lib/utils/tpl.js +1 -1
  303. package/lib/utils/uncontrollable.js +1 -1
  304. package/lib/utils/validateId.js +1 -1
  305. package/lib/utils/validations.js +5 -3
  306. package/lib/utils/visitedCache.js +1 -1
  307. package/package.json +5 -4
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v6.9.0
2
+ * amis-core v6.10.0-beta.0
3
3
  * Copyright 2018-2024 fex
4
4
  */
5
5
 
@@ -8,7 +8,7 @@ import { isEffectiveApi, isApiOutdated } from '../utils/api.js';
8
8
  import { isAlive } from 'mobx-state-tree';
9
9
  import { anyChanged, getTreeDepth, flattenTree, spliceTree, getTree, findTreeIndex, normalizeNodePath, autobind } from '../utils/helper.js';
10
10
  import { reaction } from 'mobx';
11
- import { registerFormItem, detectProps as detectProps$1 } from './Item.js';
11
+ import { detectProps as detectProps$1, registerFormItem } from './Item.js';
12
12
  import React from 'react';
13
13
  import 'amis-formula';
14
14
  import 'moment';
@@ -69,962 +69,969 @@ var detectProps = detectProps$1.concat([
69
69
  'borderMode',
70
70
  'hideSelected'
71
71
  ]);
72
- function registerOptionsControl(config) {
73
- var Control = config.component;
74
- var FormOptionsItem = /** @class */ (function (_super) {
75
- __extends(FormOptionsItem, _super);
76
- function FormOptionsItem(props) {
77
- var _this = this;
78
- var _a;
79
- _this = _super.call(this, props) || this;
80
- _this.toDispose = [];
81
- _this.mounted = false;
82
- var initFetch = props.initFetch, formItem = props.formItem, source = props.source, data = props.data, setPrinstineValue = props.setPrinstineValue, defaultValue = props.defaultValue, multiple = props.multiple, joinValues = props.joinValues, extractValue = props.extractValue, addHook = props.addHook, formInited = props.formInited, valueField = props.valueField, options = props.options, value = props.value, defaultCheckAll = props.defaultCheckAll;
83
- if (!formItem) {
84
- return _this;
85
- }
86
- formItem.setOptions(normalizeOptions(options, undefined, valueField), _this.changeOptionValue, data);
87
- _this.toDispose.push(reaction(function () { return JSON.stringify([formItem.loading, formItem.filteredOptions]); }, function () { return _this.mounted && _this.forceUpdate(); }));
88
- // 默认全选。这里会和默认值\回填值逻辑冲突,所以如果有配置source则不执行默认全选
89
- if (multiple &&
90
- defaultCheckAll &&
91
- ((_a = formItem.filteredOptions) === null || _a === void 0 ? void 0 : _a.length) &&
92
- !source) {
93
- _this.defaultCheckAll();
94
- }
95
- var loadOptions = initFetch !== false;
96
- var setInitValue = null;
97
- if (joinValues === false && defaultValue) {
98
- setInitValue = function () {
99
- var selectedOptions = extractValue
100
- ? formItem
101
- .getSelectedOptions(value)
102
- .map(function (selectedOption) {
103
- return selectedOption[valueField || 'value'];
104
- })
105
- : formItem.getSelectedOptions(value);
106
- setPrinstineValue(multiple ? selectedOptions.concat() : selectedOptions[0]);
107
- };
108
- }
109
- if (loadOptions && config.autoLoadOptionsFromSource !== false) {
110
- _this.toDispose.push(formInited || !addHook
111
- ? formItem.addInitHook(function () { return __awaiter(_this, void 0, void 0, function () {
112
- return __generator(this, function (_a) {
113
- switch (_a.label) {
114
- case 0: return [4 /*yield*/, this.reload()];
115
- case 1:
116
- _a.sent();
117
- setInitValue === null || setInitValue === void 0 ? void 0 : setInitValue();
118
- return [2 /*return*/];
119
- }
120
- });
121
- }); })
122
- : addHook(function (data) { return __awaiter(_this, void 0, void 0, function () {
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
125
- case 0: return [4 /*yield*/, this.initOptions(data)];
126
- case 1:
127
- _a.sent();
128
- setInitValue === null || setInitValue === void 0 ? void 0 : setInitValue();
129
- return [2 /*return*/];
130
- }
131
- });
132
- }); }, 'init'));
133
- }
134
- else {
135
- setInitValue === null || setInitValue === void 0 ? void 0 : setInitValue();
136
- }
72
+ var OptionsControlBase = /** @class */ (function (_super) {
73
+ __extends(OptionsControlBase, _super);
74
+ function OptionsControlBase(props, config) {
75
+ var _this = this;
76
+ var _a;
77
+ _this = _super.call(this, props) || this;
78
+ _this.config = config;
79
+ _this.toDispose = [];
80
+ _this.mounted = false;
81
+ var initFetch = props.initFetch, formItem = props.formItem, source = props.source, data = props.data, setPrinstineValue = props.setPrinstineValue, defaultValue = props.defaultValue, multiple = props.multiple, joinValues = props.joinValues, extractValue = props.extractValue, addHook = props.addHook, formInited = props.formInited, valueField = props.valueField, options = props.options, value = props.value, defaultCheckAll = props.defaultCheckAll;
82
+ if (!formItem) {
137
83
  return _this;
138
84
  }
139
- FormOptionsItem.prototype.componentDidMount = function () {
140
- this.mounted = true;
85
+ formItem.setOptions(normalizeOptions(options, undefined, valueField), _this.changeOptionValue, data);
86
+ _this.toDispose.push(reaction(function () { return JSON.stringify([formItem.loading, formItem.filteredOptions]); }, function () { return _this.mounted && _this.forceUpdate(); }));
87
+ // 默认全选。这里会和默认值\回填值逻辑冲突,所以如果有配置source则不执行默认全选
88
+ if (multiple &&
89
+ defaultCheckAll &&
90
+ ((_a = formItem.filteredOptions) === null || _a === void 0 ? void 0 : _a.length) &&
91
+ !source) {
92
+ _this.defaultCheckAll();
93
+ }
94
+ var loadOptions = initFetch !== false;
95
+ var setInitValue = null;
96
+ if (joinValues === false && defaultValue) {
97
+ setInitValue = function () {
98
+ var selectedOptions = extractValue
99
+ ? formItem
100
+ .getSelectedOptions(value)
101
+ .map(function (selectedOption) {
102
+ return selectedOption[valueField || 'value'];
103
+ })
104
+ : formItem.getSelectedOptions(value);
105
+ setPrinstineValue(multiple ? selectedOptions.concat() : selectedOptions[0]);
106
+ };
107
+ }
108
+ if (loadOptions && config.autoLoadOptionsFromSource !== false) {
109
+ _this.toDispose.push(formInited || !addHook
110
+ ? formItem.addInitHook(function () { return __awaiter(_this, void 0, void 0, function () {
111
+ return __generator(this, function (_a) {
112
+ switch (_a.label) {
113
+ case 0: return [4 /*yield*/, this.reload()];
114
+ case 1:
115
+ _a.sent();
116
+ setInitValue === null || setInitValue === void 0 ? void 0 : setInitValue();
117
+ return [2 /*return*/];
118
+ }
119
+ });
120
+ }); })
121
+ : addHook(function (data) { return __awaiter(_this, void 0, void 0, function () {
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
124
+ case 0: return [4 /*yield*/, this.initOptions(data)];
125
+ case 1:
126
+ _a.sent();
127
+ setInitValue === null || setInitValue === void 0 ? void 0 : setInitValue();
128
+ return [2 /*return*/];
129
+ }
130
+ });
131
+ }); }, 'init'));
132
+ }
133
+ else {
134
+ setInitValue === null || setInitValue === void 0 ? void 0 : setInitValue();
135
+ }
136
+ return _this;
137
+ }
138
+ OptionsControlBase.prototype.componentDidMount = function () {
139
+ this.mounted = true;
140
+ this.normalizeValue();
141
+ };
142
+ OptionsControlBase.prototype.shouldComponentUpdate = function (nextProps) {
143
+ var _a;
144
+ if (this.config.strictMode === false || nextProps.strictMode === false) {
145
+ return true;
146
+ }
147
+ else if (nextProps.source || nextProps.autoComplete) {
148
+ return true;
149
+ }
150
+ else if ((_a = nextProps.formItem) === null || _a === void 0 ? void 0 : _a.expressionsInOptions) {
151
+ return true;
152
+ }
153
+ else if (anyChanged(detectProps, this.props, nextProps)) {
154
+ return true;
155
+ }
156
+ return false;
157
+ };
158
+ OptionsControlBase.prototype.componentDidUpdate = function (prevProps) {
159
+ var _this = this;
160
+ var props = this.props;
161
+ var formItem = props.formItem;
162
+ if (!props.source && prevProps.options !== props.options && formItem) {
163
+ formItem.setOptions(normalizeOptions(props.options || [], undefined, props.valueField), this.changeOptionValue, props.data);
141
164
  this.normalizeValue();
142
- };
143
- FormOptionsItem.prototype.shouldComponentUpdate = function (nextProps) {
144
- var _a;
145
- if (config.strictMode === false || nextProps.strictMode === false) {
146
- return true;
147
- }
148
- else if (nextProps.source || nextProps.autoComplete) {
149
- return true;
150
- }
151
- else if ((_a = nextProps.formItem) === null || _a === void 0 ? void 0 : _a.expressionsInOptions) {
152
- return true;
153
- }
154
- else if (anyChanged(detectProps, this.props, nextProps)) {
155
- return true;
165
+ }
166
+ else if (this.config.autoLoadOptionsFromSource !== false &&
167
+ (props.formInited || typeof props.formInited === 'undefined') &&
168
+ props.source &&
169
+ formItem &&
170
+ (prevProps.source !== props.source || prevProps.data !== props.data)) {
171
+ if (isPureVariable(props.source)) {
172
+ var prevOptions = resolveVariableAndFilter(prevProps.source, prevProps.data, '| raw');
173
+ var options = resolveVariableAndFilter(props.source, props.data, '| raw');
174
+ if (prevOptions !== options) {
175
+ formItem.loadOptionsFromDataScope(props.source, props.data, this.changeOptionValue);
176
+ this.normalizeValue();
177
+ }
156
178
  }
157
- return false;
158
- };
159
- FormOptionsItem.prototype.componentDidUpdate = function (prevProps) {
160
- var _this = this;
161
- var props = this.props;
162
- var formItem = props.formItem;
163
- if (!props.source && prevProps.options !== props.options && formItem) {
164
- formItem.setOptions(normalizeOptions(props.options || [], undefined, props.valueField), this.changeOptionValue, props.data);
165
- this.normalizeValue();
179
+ else if (isEffectiveApi(props.source, props.data) &&
180
+ isApiOutdated(prevProps.source, props.source, prevProps.data, props.data)) {
181
+ formItem
182
+ .loadOptions(props.source, props.data, undefined, true, this.changeOptionValue)
183
+ .then(function () { return _this.normalizeValue(); });
166
184
  }
167
- else if (config.autoLoadOptionsFromSource !== false &&
168
- (props.formInited || typeof props.formInited === 'undefined') &&
169
- props.source &&
170
- formItem &&
171
- (prevProps.source !== props.source || prevProps.data !== props.data)) {
172
- if (isPureVariable(props.source)) {
173
- var prevOptions = resolveVariableAndFilter(prevProps.source, prevProps.data, '| raw');
174
- var options = resolveVariableAndFilter(props.source, props.data, '| raw');
175
- if (prevOptions !== options) {
176
- formItem.loadOptionsFromDataScope(props.source, props.data, this.changeOptionValue);
177
- this.normalizeValue();
178
- }
185
+ }
186
+ if (prevProps.value !== props.value || (formItem === null || formItem === void 0 ? void 0 : formItem.expressionsInOptions)) {
187
+ formItem === null || formItem === void 0 ? void 0 : formItem.syncOptions(undefined, props.data);
188
+ }
189
+ };
190
+ OptionsControlBase.prototype.componentWillUnmount = function () {
191
+ var _a, _b;
192
+ (_b = (_a = this.props).removeHook) === null || _b === void 0 ? void 0 : _b.call(_a, this.reload, 'init');
193
+ this.mounted = false;
194
+ this.toDispose.forEach(function (fn) { return fn(); });
195
+ this.toDispose = [];
196
+ };
197
+ // 不推荐使用,缺少组件值
198
+ OptionsControlBase.prototype.oldDispatchOptionEvent = function (eventName, eventData) {
199
+ if (eventData === void 0) { eventData = ''; }
200
+ return __awaiter(this, void 0, void 0, function () {
201
+ var _a, dispatchEvent, options, rendererEvent;
202
+ return __generator(this, function (_b) {
203
+ switch (_b.label) {
204
+ case 0:
205
+ _a = this.props, dispatchEvent = _a.dispatchEvent, options = _a.options;
206
+ return [4 /*yield*/, dispatchEvent(eventName, resolveEventData(this.props, { value: eventData, options: options, items: options } // 为了保持名字统一
207
+ ))];
208
+ case 1:
209
+ rendererEvent = _b.sent();
210
+ // 返回阻塞标识
211
+ return [2 /*return*/, !!(rendererEvent === null || rendererEvent === void 0 ? void 0 : rendererEvent.prevented)];
179
212
  }
180
- else if (isEffectiveApi(props.source, props.data) &&
181
- isApiOutdated(prevProps.source, props.source, prevProps.data, props.data)) {
182
- formItem
183
- .loadOptions(props.source, props.data, undefined, true, this.changeOptionValue)
184
- .then(function () { return _this.normalizeValue(); });
213
+ });
214
+ });
215
+ };
216
+ OptionsControlBase.prototype.dispatchOptionEvent = function (eventName, eventData) {
217
+ if (eventData === void 0) { eventData = ''; }
218
+ return __awaiter(this, void 0, void 0, function () {
219
+ var _a, dispatchEvent, options, value, rendererEvent;
220
+ return __generator(this, function (_b) {
221
+ switch (_b.label) {
222
+ case 0:
223
+ _a = this.props, dispatchEvent = _a.dispatchEvent, options = _a.options, value = _a.value;
224
+ return [4 /*yield*/, dispatchEvent(eventName, resolveEventData(this.props, __assign({ value: value, options: options, items: options }, eventData)))];
225
+ case 1:
226
+ rendererEvent = _b.sent();
227
+ // 返回阻塞标识
228
+ return [2 /*return*/, !!(rendererEvent === null || rendererEvent === void 0 ? void 0 : rendererEvent.prevented)];
185
229
  }
186
- }
187
- if (prevProps.value !== props.value || (formItem === null || formItem === void 0 ? void 0 : formItem.expressionsInOptions)) {
188
- formItem === null || formItem === void 0 ? void 0 : formItem.syncOptions(undefined, props.data);
189
- }
190
- };
191
- FormOptionsItem.prototype.componentWillUnmount = function () {
192
- var _a, _b;
193
- (_b = (_a = this.props).removeHook) === null || _b === void 0 ? void 0 : _b.call(_a, this.reload, 'init');
194
- this.mounted = false;
195
- this.toDispose.forEach(function (fn) { return fn(); });
196
- this.toDispose = [];
197
- };
198
- // 不推荐使用,缺少组件值
199
- FormOptionsItem.prototype.oldDispatchOptionEvent = function (eventName, eventData) {
200
- if (eventData === void 0) { eventData = ''; }
201
- return __awaiter(this, void 0, void 0, function () {
202
- var _a, dispatchEvent, options, rendererEvent;
203
- return __generator(this, function (_b) {
204
- switch (_b.label) {
205
- case 0:
206
- _a = this.props, dispatchEvent = _a.dispatchEvent, options = _a.options;
207
- return [4 /*yield*/, dispatchEvent(eventName, resolveEventData(this.props, { value: eventData, options: options, items: options } // 为了保持名字统一
208
- ))];
209
- case 1:
210
- rendererEvent = _b.sent();
211
- // 返回阻塞标识
212
- return [2 /*return*/, !!(rendererEvent === null || rendererEvent === void 0 ? void 0 : rendererEvent.prevented)];
213
- }
214
- });
215
230
  });
216
- };
217
- FormOptionsItem.prototype.dispatchOptionEvent = function (eventName, eventData) {
218
- if (eventData === void 0) { eventData = ''; }
219
- return __awaiter(this, void 0, void 0, function () {
220
- var _a, dispatchEvent, options, value, rendererEvent;
221
- return __generator(this, function (_b) {
222
- switch (_b.label) {
223
- case 0:
224
- _a = this.props, dispatchEvent = _a.dispatchEvent, options = _a.options, value = _a.value;
225
- return [4 /*yield*/, dispatchEvent(eventName, resolveEventData(this.props, __assign({ value: value, options: options, items: options }, eventData)))];
226
- case 1:
227
- rendererEvent = _b.sent();
228
- // 返回阻塞标识
229
- return [2 /*return*/, !!(rendererEvent === null || rendererEvent === void 0 ? void 0 : rendererEvent.prevented)];
230
- }
231
- });
231
+ });
232
+ };
233
+ OptionsControlBase.prototype.doAction = function (action, data, throwErrors) {
234
+ var _a = this.props, resetValue = _a.resetValue, onChange = _a.onChange;
235
+ var actionType = action === null || action === void 0 ? void 0 : action.actionType;
236
+ if (actionType === 'clear') {
237
+ onChange === null || onChange === void 0 ? void 0 : onChange('');
238
+ }
239
+ else if (actionType === 'reset') {
240
+ onChange === null || onChange === void 0 ? void 0 : onChange(resetValue !== null && resetValue !== void 0 ? resetValue : '');
241
+ }
242
+ };
243
+ // 当前值,跟设置预期的值格式不一致时自动转换。
244
+ OptionsControlBase.prototype.normalizeValue = function () {
245
+ var _a = this.props, joinValues = _a.joinValues, extractValue = _a.extractValue, value = _a.value, multiple = _a.multiple, formItem = _a.formItem, valueField = _a.valueField; _a.enableNodePath; _a.pathSeparator; var onChange = _a.onChange;
246
+ if (!formItem || joinValues !== false || !formItem.options.length) {
247
+ return;
248
+ }
249
+ if (extractValue === false &&
250
+ (typeof value === 'string' || typeof value === 'number')) {
251
+ var selectedOptions = formItem.getSelectedOptions(value);
252
+ onChange === null || onChange === void 0 ? void 0 : onChange(multiple ? selectedOptions.concat() : selectedOptions[0]);
253
+ }
254
+ else if (extractValue === true &&
255
+ value &&
256
+ !((Array.isArray(value) &&
257
+ value.every(function (val) { return typeof val === 'string' || typeof val === 'number'; })) ||
258
+ typeof value === 'string' ||
259
+ typeof value === 'number')) {
260
+ var selectedOptions = formItem
261
+ .getSelectedOptions(value)
262
+ .map(function (selectedOption) { return selectedOption[valueField || 'value']; });
263
+ onChange === null || onChange === void 0 ? void 0 : onChange(multiple ? selectedOptions.concat() : selectedOptions[0]);
264
+ }
265
+ };
266
+ OptionsControlBase.prototype.getWrappedInstance = function () {
267
+ return this.input;
268
+ };
269
+ OptionsControlBase.prototype.inputRef = function (ref) {
270
+ this.input = ref;
271
+ };
272
+ OptionsControlBase.prototype.handleToggle = function (option, submitOnChange, changeImmediately) {
273
+ return __awaiter(this, void 0, void 0, function () {
274
+ var _a, onChange, formItem, value, newValue, isPrevented;
275
+ return __generator(this, function (_b) {
276
+ switch (_b.label) {
277
+ case 0:
278
+ _a = this.props, onChange = _a.onChange, formItem = _a.formItem, value = _a.value;
279
+ if (!formItem) {
280
+ return [2 /*return*/];
281
+ }
282
+ newValue = this.toggleValue(option, value);
283
+ return [4 /*yield*/, this.dispatchOptionEvent('change', {
284
+ value: newValue
285
+ })];
286
+ case 1:
287
+ isPrevented = _b.sent();
288
+ isPrevented ||
289
+ (onChange && onChange(newValue, submitOnChange, changeImmediately));
290
+ return [2 /*return*/];
291
+ }
232
292
  });
233
- };
234
- FormOptionsItem.prototype.doAction = function (action, data, throwErrors) {
235
- var _a = this.props, resetValue = _a.resetValue, onChange = _a.onChange;
236
- var actionType = action === null || action === void 0 ? void 0 : action.actionType;
237
- if (actionType === 'clear') {
238
- onChange === null || onChange === void 0 ? void 0 : onChange('');
239
- }
240
- else if (actionType === 'reset') {
241
- onChange === null || onChange === void 0 ? void 0 : onChange(resetValue !== null && resetValue !== void 0 ? resetValue : '');
242
- }
243
- };
244
- // 当前值,跟设置预期的值格式不一致时自动转换。
245
- FormOptionsItem.prototype.normalizeValue = function () {
246
- var _a = this.props, joinValues = _a.joinValues, extractValue = _a.extractValue, value = _a.value, multiple = _a.multiple, formItem = _a.formItem, valueField = _a.valueField; _a.enableNodePath; _a.pathSeparator; var onChange = _a.onChange;
247
- if (!formItem || joinValues !== false || !formItem.options.length) {
248
- return;
293
+ });
294
+ };
295
+ /**
296
+ * 初始化时处理默认全选逻辑
297
+ */
298
+ OptionsControlBase.prototype.defaultCheckAll = function () {
299
+ var _a = this.props, value = _a.value, formItem = _a.formItem, setPrinstineValue = _a.setPrinstineValue;
300
+ // 如果有默认值\回填值直接返回
301
+ if (!formItem || formItem.getSelectedOptions(value).length) {
302
+ return;
303
+ }
304
+ var valueArray = formItem.filteredOptions.concat();
305
+ var newValue = this.formatValueArray(valueArray);
306
+ setPrinstineValue === null || setPrinstineValue === void 0 ? void 0 : setPrinstineValue(newValue);
307
+ };
308
+ /**
309
+ * 选中的值经过joinValues和delimiter等规则处理输出规定格式的值
310
+ * @param valueArray 选中值的数组
311
+ * @returns 通过joinValues和delimiter等规则输出规定格式的值
312
+ */
313
+ OptionsControlBase.prototype.formatValueArray = function (valueArray) {
314
+ var _a = this.props, joinValues = _a.joinValues, extractValue = _a.extractValue, valueField = _a.valueField, delimiter = _a.delimiter, resetValue = _a.resetValue, multiple = _a.multiple;
315
+ var newValue = '';
316
+ if (multiple) {
317
+ /** 兼容tree数据结构 */
318
+ newValue =
319
+ getTreeDepth(valueArray) > 1 ? flattenTree(valueArray) : valueArray;
320
+ if (joinValues) {
321
+ newValue = newValue
322
+ .map(function (item) { return item[valueField || 'value']; })
323
+ .filter(function (item) { return item != null; }) /** tree的父节点可能没有value值 */
324
+ .join(delimiter);
249
325
  }
250
- if (extractValue === false &&
251
- (typeof value === 'string' || typeof value === 'number')) {
252
- var selectedOptions = formItem.getSelectedOptions(value);
253
- onChange === null || onChange === void 0 ? void 0 : onChange(multiple ? selectedOptions.concat() : selectedOptions[0]);
326
+ else if (extractValue) {
327
+ newValue = newValue
328
+ .map(function (item) { return item[valueField || 'value']; })
329
+ .filter(function (item) { return item != null; });
254
330
  }
255
- else if (extractValue === true &&
256
- value &&
257
- !((Array.isArray(value) &&
258
- value.every(function (val) { return typeof val === 'string' || typeof val === 'number'; })) ||
259
- typeof value === 'string' ||
260
- typeof value === 'number')) {
261
- var selectedOptions = formItem
262
- .getSelectedOptions(value)
263
- .map(function (selectedOption) { return selectedOption[valueField || 'value']; });
264
- onChange === null || onChange === void 0 ? void 0 : onChange(multiple ? selectedOptions.concat() : selectedOptions[0]);
331
+ }
332
+ else {
333
+ newValue = valueArray[0] || resetValue;
334
+ if (joinValues && newValue) {
335
+ newValue = newValue[valueField || 'value'];
265
336
  }
266
- };
267
- FormOptionsItem.prototype.getWrappedInstance = function () {
268
- return this.input;
269
- };
270
- FormOptionsItem.prototype.inputRef = function (ref) {
271
- this.input = ref;
272
- };
273
- FormOptionsItem.prototype.handleToggle = function (option, submitOnChange, changeImmediately) {
274
- return __awaiter(this, void 0, void 0, function () {
275
- var _a, onChange, formItem, value, newValue, isPrevented;
276
- return __generator(this, function (_b) {
277
- switch (_b.label) {
278
- case 0:
279
- _a = this.props, onChange = _a.onChange, formItem = _a.formItem, value = _a.value;
280
- if (!formItem) {
281
- return [2 /*return*/];
282
- }
283
- newValue = this.toggleValue(option, value);
284
- return [4 /*yield*/, this.dispatchOptionEvent('change', {
285
- value: newValue
286
- })];
287
- case 1:
288
- isPrevented = _b.sent();
289
- isPrevented ||
290
- (onChange && onChange(newValue, submitOnChange, changeImmediately));
337
+ }
338
+ return newValue;
339
+ };
340
+ OptionsControlBase.prototype.handleToggleAll = function () {
341
+ return __awaiter(this, void 0, void 0, function () {
342
+ var _a, value, onChange, formItem, valueField, selectedOptions, filteredOptions, valueArray, newValue, isPrevented;
343
+ return __generator(this, function (_b) {
344
+ switch (_b.label) {
345
+ case 0:
346
+ _a = this.props, value = _a.value, onChange = _a.onChange, formItem = _a.formItem, valueField = _a.valueField;
347
+ if (!formItem) {
291
348
  return [2 /*return*/];
292
- }
293
- });
294
- });
295
- };
296
- /**
297
- * 初始化时处理默认全选逻辑
298
- */
299
- FormOptionsItem.prototype.defaultCheckAll = function () {
300
- var _a = this.props, value = _a.value, formItem = _a.formItem, setPrinstineValue = _a.setPrinstineValue;
301
- // 如果有默认值\回填值直接返回
302
- if (!formItem || formItem.getSelectedOptions(value).length) {
303
- return;
304
- }
305
- var valueArray = formItem.filteredOptions.concat();
306
- var newValue = this.formatValueArray(valueArray);
307
- setPrinstineValue === null || setPrinstineValue === void 0 ? void 0 : setPrinstineValue(newValue);
308
- };
309
- /**
310
- * 选中的值经过joinValues和delimiter等规则处理输出规定格式的值
311
- * @param valueArray 选中值的数组
312
- * @returns 通过joinValues和delimiter等规则输出规定格式的值
313
- */
314
- FormOptionsItem.prototype.formatValueArray = function (valueArray) {
315
- var _a = this.props, joinValues = _a.joinValues, extractValue = _a.extractValue, valueField = _a.valueField, delimiter = _a.delimiter, resetValue = _a.resetValue, multiple = _a.multiple;
316
- var newValue = '';
317
- if (multiple) {
318
- /** 兼容tree数据结构 */
319
- newValue =
320
- getTreeDepth(valueArray) > 1 ? flattenTree(valueArray) : valueArray;
321
- if (joinValues) {
322
- newValue = newValue
323
- .map(function (item) { return item[valueField || 'value']; })
324
- .filter(function (item) { return item != null; }) /** tree的父节点可能没有value值 */
325
- .join(delimiter);
326
- }
327
- else if (extractValue) {
328
- newValue = newValue
329
- .map(function (item) { return item[valueField || 'value']; })
330
- .filter(function (item) { return item != null; });
349
+ }
350
+ selectedOptions = formItem.getSelectedOptions(value);
351
+ filteredOptions = flattenTree(formItem.filteredOptions.concat()).filter(function (item) { return item != null && item[valueField || 'value'] != null; });
352
+ valueArray = selectedOptions.length === filteredOptions.length
353
+ ? []
354
+ : formItem.filteredOptions.concat();
355
+ newValue = this.formatValueArray(valueArray);
356
+ return [4 /*yield*/, this.dispatchOptionEvent('change', {
357
+ value: newValue
358
+ })];
359
+ case 1:
360
+ isPrevented = _b.sent();
361
+ isPrevented || (onChange && onChange(newValue));
362
+ return [2 /*return*/];
331
363
  }
364
+ });
365
+ });
366
+ };
367
+ OptionsControlBase.prototype.toggleValue = function (option, originValue) {
368
+ var _a = this.props, joinValues = _a.joinValues, extractValue = _a.extractValue, valueField = _a.valueField, delimiter = _a.delimiter, clearable = _a.clearable, resetValue = _a.resetValue, multiple = _a.multiple, formItem = _a.formItem;
369
+ var valueArray = originValue !== undefined
370
+ ? formItem.getSelectedOptions(originValue).concat()
371
+ : [];
372
+ var idx = findIndex(valueArray, optionValueCompare(option[valueField || 'value'], valueField || 'value'));
373
+ var newValue = '';
374
+ if (multiple) {
375
+ if (~idx) {
376
+ valueArray.splice(idx, 1);
332
377
  }
333
378
  else {
334
- newValue = valueArray[0] || resetValue;
335
- if (joinValues && newValue) {
336
- newValue = newValue[valueField || 'value'];
337
- }
379
+ valueArray.push(option);
338
380
  }
339
- return newValue;
340
- };
341
- FormOptionsItem.prototype.handleToggleAll = function () {
342
- return __awaiter(this, void 0, void 0, function () {
343
- var _a, value, onChange, formItem, valueField, selectedOptions, filteredOptions, valueArray, newValue, isPrevented;
344
- return __generator(this, function (_b) {
345
- switch (_b.label) {
346
- case 0:
347
- _a = this.props, value = _a.value, onChange = _a.onChange, formItem = _a.formItem, valueField = _a.valueField;
348
- if (!formItem) {
349
- return [2 /*return*/];
350
- }
351
- selectedOptions = formItem.getSelectedOptions(value);
352
- filteredOptions = flattenTree(formItem.filteredOptions.concat()).filter(function (item) { return item != null && item[valueField || 'value'] != null; });
353
- valueArray = selectedOptions.length === filteredOptions.length
354
- ? []
355
- : formItem.filteredOptions.concat();
356
- newValue = this.formatValueArray(valueArray);
357
- return [4 /*yield*/, this.dispatchOptionEvent('change', {
358
- value: newValue
359
- })];
360
- case 1:
361
- isPrevented = _b.sent();
362
- isPrevented || (onChange && onChange(newValue));
363
- return [2 /*return*/];
364
- }
365
- });
366
- });
367
- };
368
- FormOptionsItem.prototype.toggleValue = function (option, originValue) {
369
- var _a = this.props, joinValues = _a.joinValues, extractValue = _a.extractValue, valueField = _a.valueField, delimiter = _a.delimiter, clearable = _a.clearable, resetValue = _a.resetValue, multiple = _a.multiple, formItem = _a.formItem;
370
- var valueArray = originValue !== undefined
371
- ? formItem.getSelectedOptions(originValue).concat()
372
- : [];
373
- var idx = findIndex(valueArray, optionValueCompare(option[valueField || 'value'], valueField || 'value'));
374
- var newValue = '';
375
- if (multiple) {
376
- if (~idx) {
377
- valueArray.splice(idx, 1);
378
- }
379
- else {
380
- valueArray.push(option);
381
- }
382
- newValue = valueArray;
383
- if (joinValues) {
384
- newValue = newValue
385
- .map(function (item) { return item[valueField || 'value']; })
386
- .join(delimiter);
387
- }
388
- else if (extractValue) {
389
- newValue = newValue.map(function (item) { return item[valueField || 'value']; });
390
- }
381
+ newValue = valueArray;
382
+ if (joinValues) {
383
+ newValue = newValue
384
+ .map(function (item) { return item[valueField || 'value']; })
385
+ .join(delimiter);
391
386
  }
392
- else {
393
- if (~idx && clearable) {
394
- valueArray.splice(idx, 1);
395
- }
396
- else {
397
- valueArray = [option];
398
- }
399
- newValue = valueArray[0] || resetValue;
400
- if ((joinValues || extractValue) && newValue) {
401
- newValue = newValue[valueField || 'value'];
402
- }
387
+ else if (extractValue) {
388
+ newValue = newValue.map(function (item) { return item[valueField || 'value']; });
403
389
  }
404
- return newValue;
405
- };
406
- // 当有 action 触发,如果指定了 reload 目标组件,有可能会来到这里面来
407
- FormOptionsItem.prototype.reload = function () {
408
- return this.reloadOptions();
409
- };
410
- FormOptionsItem.prototype.reloadOptions = function (setError, isInit, data) {
411
- if (isInit === void 0) { isInit = false; }
412
- if (data === void 0) { data = this.props.data; }
413
- var _a = this.props, source = _a.source, formItem = _a.formItem, onChange = _a.onChange, setPrinstineValue = _a.setPrinstineValue; _a.valueField;
414
- if (formItem && isPureVariable(source)) {
415
- isAlive(formItem) &&
416
- formItem.loadOptionsFromDataScope(source, data, this.changeOptionValue);
417
- return;
390
+ }
391
+ else {
392
+ if (~idx && clearable) {
393
+ valueArray.splice(idx, 1);
418
394
  }
419
- else if (!formItem || !isEffectiveApi(source, data)) {
420
- return;
395
+ else {
396
+ valueArray = [option];
421
397
  }
422
- return isAlive(formItem)
423
- ? formItem.loadOptions(source, data, undefined, false, isInit ? setPrinstineValue : onChange, setError)
424
- : undefined;
425
- };
426
- FormOptionsItem.prototype.deferLoad = function (option) {
427
- return __awaiter(this, void 0, void 0, function () {
428
- var _a, deferApi, source, env, formItem, data, api, json;
429
- return __generator(this, function (_b) {
430
- switch (_b.label) {
431
- case 0:
432
- _a = this.props, deferApi = _a.deferApi, source = _a.source, env = _a.env, formItem = _a.formItem, data = _a.data;
433
- api = option.deferApi || deferApi || source;
434
- if (!api) {
435
- env.notify('error', '请在选项中设置 `deferApi` 或者表单项中设置 `deferApi`,用来加载子选项。');
436
- return [2 /*return*/];
437
- }
438
- return [4 /*yield*/, (formItem === null || formItem === void 0 ? void 0 : formItem.deferLoadOptions(option, api, createObject(data, option)))];
439
- case 1:
440
- json = _b.sent();
441
- // 触发事件通知,加载完成
442
- // 废弃,不推荐使用
443
- this.oldDispatchOptionEvent('loadFinished', json);
444
- // 避免产生breakchange,增加新事件名,用来更正之前的设计问题
445
- this.dispatchOptionEvent('deferLoadFinished', { result: json });
398
+ newValue = valueArray[0] || resetValue;
399
+ if ((joinValues || extractValue) && newValue) {
400
+ newValue = newValue[valueField || 'value'];
401
+ }
402
+ }
403
+ return newValue;
404
+ };
405
+ // 当有 action 触发,如果指定了 reload 目标组件,有可能会来到这里面来
406
+ OptionsControlBase.prototype.reload = function () {
407
+ return this.reloadOptions();
408
+ };
409
+ OptionsControlBase.prototype.reloadOptions = function (setError, isInit, data) {
410
+ if (isInit === void 0) { isInit = false; }
411
+ if (data === void 0) { data = this.props.data; }
412
+ var _a = this.props, source = _a.source, formItem = _a.formItem, onChange = _a.onChange, setPrinstineValue = _a.setPrinstineValue; _a.valueField;
413
+ if (formItem && isPureVariable(source)) {
414
+ isAlive(formItem) &&
415
+ formItem.loadOptionsFromDataScope(source, data, this.changeOptionValue);
416
+ return;
417
+ }
418
+ else if (!formItem || !isEffectiveApi(source, data)) {
419
+ return;
420
+ }
421
+ return isAlive(formItem)
422
+ ? formItem.loadOptions(source, data, undefined, false, isInit ? setPrinstineValue : onChange, setError)
423
+ : undefined;
424
+ };
425
+ OptionsControlBase.prototype.deferLoad = function (option) {
426
+ return __awaiter(this, void 0, void 0, function () {
427
+ var _a, deferApi, source, env, formItem, data, api, json;
428
+ return __generator(this, function (_b) {
429
+ switch (_b.label) {
430
+ case 0:
431
+ _a = this.props, deferApi = _a.deferApi, source = _a.source, env = _a.env, formItem = _a.formItem, data = _a.data;
432
+ api = option.deferApi || deferApi || source;
433
+ if (!api) {
434
+ env.notify('error', '请在选项中设置 `deferApi` 或者表单项中设置 `deferApi`,用来加载子选项。');
446
435
  return [2 /*return*/];
447
- }
448
- });
436
+ }
437
+ return [4 /*yield*/, (formItem === null || formItem === void 0 ? void 0 : formItem.deferLoadOptions(option, api, createObject(data, option)))];
438
+ case 1:
439
+ json = _b.sent();
440
+ // 触发事件通知,加载完成
441
+ // 废弃,不推荐使用
442
+ this.oldDispatchOptionEvent('loadFinished', json);
443
+ // 避免产生breakchange,增加新事件名,用来更正之前的设计问题
444
+ this.dispatchOptionEvent('deferLoadFinished', { result: json });
445
+ return [2 /*return*/];
446
+ }
449
447
  });
450
- };
451
- FormOptionsItem.prototype.leftDeferLoad = function (option, leftOptions) {
452
- var _a = this.props, deferApi = _a.deferApi, source = _a.source, env = _a.env, formItem = _a.formItem, data = _a.data;
453
- var api = option.deferApi || deferApi || source;
454
- if (!api) {
455
- env.notify('error', '请在选项中设置 `deferApi` 或者表单项中设置 `deferApi`,用来加载子选项。');
456
- return;
457
- }
458
- formItem === null || formItem === void 0 ? void 0 : formItem.deferLoadLeftOptions(option, leftOptions, api, createObject(data, option));
459
- };
460
- FormOptionsItem.prototype.expandTreeOptions = function (nodePathArr) {
461
- var _a = this.props, deferApi = _a.deferApi, source = _a.source, env = _a.env, formItem = _a.formItem, data = _a.data;
462
- var api = deferApi || source;
463
- if (!api) {
464
- env.notify('error', '请在选项中设置 `deferApi` 或者表单项中设置 `deferApi`,用来加载子选项。');
465
- return;
466
- }
467
- formItem === null || formItem === void 0 ? void 0 : formItem.expandTreeOptions(nodePathArr, api, createObject(data));
468
- };
469
- FormOptionsItem.prototype.initOptions = function (data) {
470
- var _a;
471
- return __awaiter(this, void 0, void 0, function () {
472
- var _b, formItem, name, multiple, defaultCheckAll;
473
- return __generator(this, function (_c) {
474
- switch (_c.label) {
475
- case 0: return [4 /*yield*/, this.reloadOptions(false, true)];
476
- case 1:
477
- _c.sent();
478
- _b = this.props, formItem = _b.formItem, name = _b.name, multiple = _b.multiple, defaultCheckAll = _b.defaultCheckAll;
479
- if (!formItem) {
480
- return [2 /*return*/];
481
- }
482
- if (isAlive(formItem) && formItem.value) {
483
- setVariable(data, name, formItem.value);
484
- }
485
- // 默认全选
486
- if (multiple && defaultCheckAll && ((_a = formItem.filteredOptions) === null || _a === void 0 ? void 0 : _a.length)) {
487
- this.defaultCheckAll();
488
- }
448
+ });
449
+ };
450
+ OptionsControlBase.prototype.leftDeferLoad = function (option, leftOptions) {
451
+ var _a = this.props, deferApi = _a.deferApi, source = _a.source, env = _a.env, formItem = _a.formItem, data = _a.data;
452
+ var api = option.deferApi || deferApi || source;
453
+ if (!api) {
454
+ env.notify('error', '请在选项中设置 `deferApi` 或者表单项中设置 `deferApi`,用来加载子选项。');
455
+ return;
456
+ }
457
+ formItem === null || formItem === void 0 ? void 0 : formItem.deferLoadLeftOptions(option, leftOptions, api, createObject(data, option));
458
+ };
459
+ OptionsControlBase.prototype.expandTreeOptions = function (nodePathArr) {
460
+ var _a = this.props, deferApi = _a.deferApi, source = _a.source, env = _a.env, formItem = _a.formItem, data = _a.data;
461
+ var api = deferApi || source;
462
+ if (!api) {
463
+ env.notify('error', '请在选项中设置 `deferApi` 或者表单项中设置 `deferApi`,用来加载子选项。');
464
+ return;
465
+ }
466
+ formItem === null || formItem === void 0 ? void 0 : formItem.expandTreeOptions(nodePathArr, api, createObject(data));
467
+ };
468
+ OptionsControlBase.prototype.initOptions = function (data) {
469
+ var _a;
470
+ return __awaiter(this, void 0, void 0, function () {
471
+ var _b, formItem, name, multiple, defaultCheckAll;
472
+ return __generator(this, function (_c) {
473
+ switch (_c.label) {
474
+ case 0: return [4 /*yield*/, this.reloadOptions(false, true)];
475
+ case 1:
476
+ _c.sent();
477
+ _b = this.props, formItem = _b.formItem, name = _b.name, multiple = _b.multiple, defaultCheckAll = _b.defaultCheckAll;
478
+ if (!formItem) {
489
479
  return [2 /*return*/];
490
- }
491
- });
480
+ }
481
+ if (isAlive(formItem) && formItem.value) {
482
+ setVariable(data, name, formItem.value);
483
+ }
484
+ // 默认全选
485
+ if (multiple && defaultCheckAll && ((_a = formItem.filteredOptions) === null || _a === void 0 ? void 0 : _a.length)) {
486
+ this.defaultCheckAll();
487
+ }
488
+ return [2 /*return*/];
489
+ }
492
490
  });
493
- };
494
- FormOptionsItem.prototype.focus = function () {
495
- this.input && this.input.focus && this.input.focus();
496
- };
497
- FormOptionsItem.prototype.changeOptionValue = function (value) {
498
- var _a = this.props, onChange = _a.onChange, formInited = _a.formInited, setPrinstineValue = _a.setPrinstineValue, originValue = _a.value;
499
- if (formInited === false) {
500
- originValue === undefined && (setPrinstineValue === null || setPrinstineValue === void 0 ? void 0 : setPrinstineValue(value));
501
- }
502
- else {
503
- onChange === null || onChange === void 0 ? void 0 : onChange(value);
504
- }
505
- };
506
- FormOptionsItem.prototype.setOptions = function (options, skipNormalize) {
507
- if (skipNormalize === void 0) { skipNormalize = false; }
508
- var formItem = this.props.formItem;
509
- formItem &&
510
- formItem.setOptions(skipNormalize
511
- ? options
512
- : normalizeOptions(options || [], undefined, this.props.valueField), this.changeOptionValue, this.props.data);
513
- };
514
- FormOptionsItem.prototype.syncOptions = function () {
515
- var formItem = this.props.formItem;
516
- formItem && formItem.syncOptions(undefined, this.props.data);
517
- };
518
- FormOptionsItem.prototype.setLoading = function (value) {
519
- var formItem = this.props.formItem;
520
- formItem && formItem.setLoading(value);
521
- };
522
- FormOptionsItem.prototype.handleOptionAdd = function (idx, value, skipForm, callback) {
523
- var _a, _b;
524
- if (idx === void 0) { idx = -1; }
525
- if (skipForm === void 0) { skipForm = false; }
526
- return __awaiter(this, void 0, void 0, function () {
527
- var _c, addControls, addDialog, disabled, labelField, onOpenDialog, optionLabel, addApi, source, data, valueField, deferField, model, createBtnLabel, env, __, parent, ctx, customAddPrevent, result, _d, prevent, payload, e_1, isPrevented, ret, options;
528
- var _e;
529
- var _this = this;
530
- return __generator(this, function (_f) {
531
- switch (_f.label) {
532
- case 0:
533
- _c = this.props, addControls = _c.addControls, addDialog = _c.addDialog, disabled = _c.disabled, labelField = _c.labelField, onOpenDialog = _c.onOpenDialog, optionLabel = _c.optionLabel, addApi = _c.addApi, source = _c.source, data = _c.data, valueField = _c.valueField, deferField = _c.deferField, model = _c.formItem, createBtnLabel = _c.createBtnLabel, env = _c.env, __ = _c.translate;
534
- // 禁用或者没有配置 name
535
- if (disabled || !model) {
536
- return [2 /*return*/];
537
- }
538
- // 用户没有配置表单项,则自动创建一个 label 输入
539
- if (!skipForm && (!Array.isArray(addControls) || !addControls.length)) {
540
- addControls = [
491
+ });
492
+ };
493
+ OptionsControlBase.prototype.focus = function () {
494
+ this.input && this.input.focus && this.input.focus();
495
+ };
496
+ OptionsControlBase.prototype.changeOptionValue = function (value) {
497
+ var _a = this.props, onChange = _a.onChange, formInited = _a.formInited, setPrinstineValue = _a.setPrinstineValue, originValue = _a.value;
498
+ if (formInited === false) {
499
+ originValue === undefined && (setPrinstineValue === null || setPrinstineValue === void 0 ? void 0 : setPrinstineValue(value));
500
+ }
501
+ else {
502
+ onChange === null || onChange === void 0 ? void 0 : onChange(value);
503
+ }
504
+ };
505
+ OptionsControlBase.prototype.setOptions = function (options, skipNormalize) {
506
+ if (skipNormalize === void 0) { skipNormalize = false; }
507
+ var formItem = this.props.formItem;
508
+ formItem &&
509
+ formItem.setOptions(skipNormalize
510
+ ? options
511
+ : normalizeOptions(options || [], undefined, this.props.valueField), this.changeOptionValue, this.props.data);
512
+ };
513
+ OptionsControlBase.prototype.syncOptions = function () {
514
+ var formItem = this.props.formItem;
515
+ formItem && formItem.syncOptions(undefined, this.props.data);
516
+ };
517
+ OptionsControlBase.prototype.setLoading = function (value) {
518
+ var formItem = this.props.formItem;
519
+ formItem && formItem.setLoading(value);
520
+ };
521
+ OptionsControlBase.prototype.handleOptionAdd = function (idx, value, skipForm, callback) {
522
+ var _a, _b;
523
+ if (idx === void 0) { idx = -1; }
524
+ if (skipForm === void 0) { skipForm = false; }
525
+ return __awaiter(this, void 0, void 0, function () {
526
+ var _c, addControls, addDialog, disabled, labelField, onOpenDialog, optionLabel, addApi, source, data, valueField, deferField, model, createBtnLabel, env, __, parent, ctx, customAddPrevent, result, _d, prevent, payload, e_1, isPrevented, ret, options;
527
+ var _e;
528
+ var _this = this;
529
+ return __generator(this, function (_f) {
530
+ switch (_f.label) {
531
+ case 0:
532
+ _c = this.props, addControls = _c.addControls, addDialog = _c.addDialog, disabled = _c.disabled, labelField = _c.labelField, onOpenDialog = _c.onOpenDialog, optionLabel = _c.optionLabel, addApi = _c.addApi, source = _c.source, data = _c.data, valueField = _c.valueField, deferField = _c.deferField, model = _c.formItem, createBtnLabel = _c.createBtnLabel, env = _c.env, __ = _c.translate;
533
+ // 禁用或者没有配置 name
534
+ if (disabled || !model) {
535
+ return [2 /*return*/];
536
+ }
537
+ // 用户没有配置表单项,则自动创建一个 label 输入
538
+ if (!skipForm && (!Array.isArray(addControls) || !addControls.length)) {
539
+ addControls = [
540
+ {
541
+ type: 'text',
542
+ name: labelField || 'label',
543
+ label: false,
544
+ required: true,
545
+ placeholder: __('Options.addPlaceholder')
546
+ }
547
+ ];
548
+ }
549
+ parent = Array.isArray(idx)
550
+ ? getTree(model.options, idx.slice(0, -1))
551
+ : undefined;
552
+ ctx = createObject(data, Array.isArray(idx)
553
+ ? __assign({ parent: parent }, value) : value);
554
+ customAddPrevent = false;
555
+ if (!skipForm) return [3 /*break*/, 1];
556
+ _d = ctx;
557
+ return [3 /*break*/, 3];
558
+ case 1: return [4 /*yield*/, onOpenDialog(__assign(__assign({ type: 'dialog', title: createBtnLabel || "\u65B0\u589E".concat(optionLabel || '选项') }, addDialog), { body: {
559
+ type: 'form',
560
+ api: addApi,
561
+ controls: __spreadArray([
562
+ {
563
+ type: 'hidden',
564
+ name: 'idx',
565
+ value: idx
566
+ },
541
567
  {
542
- type: 'text',
543
- name: labelField || 'label',
544
- label: false,
545
- required: true,
546
- placeholder: __('Options.addPlaceholder')
568
+ type: 'hidden',
569
+ name: 'parent',
570
+ value: parent
547
571
  }
548
- ];
549
- }
550
- parent = Array.isArray(idx)
551
- ? getTree(model.options, idx.slice(0, -1))
552
- : undefined;
553
- ctx = createObject(data, Array.isArray(idx)
554
- ? __assign({ parent: parent }, value) : value);
555
- customAddPrevent = false;
556
- if (!skipForm) return [3 /*break*/, 1];
557
- _d = ctx;
558
- return [3 /*break*/, 3];
559
- case 1: return [4 /*yield*/, onOpenDialog(__assign(__assign({ type: 'dialog', title: createBtnLabel || "\u65B0\u589E".concat(optionLabel || '选项') }, addDialog), { body: {
560
- type: 'form',
561
- api: addApi,
562
- controls: __spreadArray([
563
- {
564
- type: 'hidden',
565
- name: 'idx',
566
- value: idx
567
- },
568
- {
569
- type: 'hidden',
570
- name: 'parent',
571
- value: parent
572
+ ], __read((addControls || [])), false),
573
+ onSubmit: function (payload) { return __awaiter(_this, void 0, void 0, function () {
574
+ var labelKey, valueKey;
575
+ var _a;
576
+ var _b;
577
+ return __generator(this, function (_c) {
578
+ switch (_c.label) {
579
+ case 0:
580
+ labelKey = labelField || 'label';
581
+ valueKey = valueField || 'value';
582
+ return [4 /*yield*/, this.dispatchOptionEvent('addConfirm', {
583
+ item: (_a = {},
584
+ _a[labelKey] = payload[labelKey],
585
+ _a[valueKey] = (_b = payload[valueKey]) !== null && _b !== void 0 ? _b : payload[labelKey],
586
+ _a)
587
+ })];
588
+ case 1:
589
+ // 派发确认添加事件
590
+ customAddPrevent = _c.sent();
591
+ return [2 /*return*/, !customAddPrevent];
572
592
  }
573
- ], __read((addControls || [])), false),
574
- onSubmit: function (payload) { return __awaiter(_this, void 0, void 0, function () {
575
- var labelKey, valueKey;
576
- var _a;
577
- var _b;
578
- return __generator(this, function (_c) {
579
- switch (_c.label) {
580
- case 0:
581
- labelKey = labelField || 'label';
582
- valueKey = valueField || 'value';
583
- return [4 /*yield*/, this.dispatchOptionEvent('addConfirm', {
584
- item: (_a = {},
585
- _a[labelKey] = payload[labelKey],
586
- _a[valueKey] = (_b = payload[valueKey]) !== null && _b !== void 0 ? _b : payload[labelKey],
587
- _a)
588
- })];
589
- case 1:
590
- // 派发确认添加事件
591
- customAddPrevent = _c.sent();
592
- return [2 /*return*/, !customAddPrevent];
593
- }
594
- });
595
- }); }
596
- } }), ctx)];
597
- case 2:
598
- _d = _f.sent();
599
- _f.label = 3;
600
- case 3:
601
- result = _d;
602
- if (!skipForm) return [3 /*break*/, 5];
603
- return [4 /*yield*/, this.dispatchOptionEvent('addConfirm', {
604
- item: result
605
- })];
606
- case 4:
607
- prevent = _f.sent();
608
- if (prevent) {
609
- return [2 /*return*/];
610
- }
611
- return [3 /*break*/, 6];
612
- case 5:
613
- if (customAddPrevent) {
614
- return [2 /*return*/];
615
- }
616
- _f.label = 6;
617
- case 6:
618
- if (!(skipForm && addApi)) return [3 /*break*/, 10];
619
- _f.label = 7;
620
- case 7:
621
- _f.trys.push([7, 9, , 10]);
622
- return [4 /*yield*/, env.fetcher(addApi, result, {
623
- method: 'post'
624
- })];
625
- case 8:
626
- payload = _f.sent();
627
- if (!payload.ok) {
628
- !addApi.silent &&
629
- env.notify('error', (_b = (_a = addApi === null || addApi === void 0 ? void 0 : addApi.messages) === null || _a === void 0 ? void 0 : _a.failed) !== null && _b !== void 0 ? _b : (payload.msg || __('Options.createFailed')));
630
- result = null;
631
- }
632
- else {
633
- result = payload.data || result;
634
- }
635
- return [3 /*break*/, 10];
636
- case 9:
637
- e_1 = _f.sent();
593
+ });
594
+ }); }
595
+ } }), ctx)];
596
+ case 2:
597
+ _d = _f.sent();
598
+ _f.label = 3;
599
+ case 3:
600
+ result = _d;
601
+ if (!skipForm) return [3 /*break*/, 5];
602
+ return [4 /*yield*/, this.dispatchOptionEvent('addConfirm', {
603
+ item: result
604
+ })];
605
+ case 4:
606
+ prevent = _f.sent();
607
+ if (prevent) {
608
+ return [2 /*return*/];
609
+ }
610
+ return [3 /*break*/, 6];
611
+ case 5:
612
+ if (customAddPrevent) {
613
+ return [2 /*return*/];
614
+ }
615
+ _f.label = 6;
616
+ case 6:
617
+ if (!(skipForm && addApi)) return [3 /*break*/, 10];
618
+ _f.label = 7;
619
+ case 7:
620
+ _f.trys.push([7, 9, , 10]);
621
+ return [4 /*yield*/, env.fetcher(addApi, result, {
622
+ method: 'post'
623
+ })];
624
+ case 8:
625
+ payload = _f.sent();
626
+ if (!payload.ok) {
627
+ !addApi.silent &&
628
+ env.notify('error', (_b = (_a = addApi === null || addApi === void 0 ? void 0 : addApi.messages) === null || _a === void 0 ? void 0 : _a.failed) !== null && _b !== void 0 ? _b : (payload.msg || __('Options.createFailed')));
638
629
  result = null;
639
- console.error(e_1);
640
- !addApi.silent && env.notify('error', e_1.message);
641
- return [3 /*break*/, 10];
642
- case 10:
643
- // result 说明弹框点了确认。否则就是取消了。
644
- if (!result) {
645
- return [2 /*return*/];
646
- }
647
- // 没走服务端的。
648
- if (!result.hasOwnProperty(valueField || 'value')) {
649
- result = __assign(__assign({}, result), (_e = {}, _e[valueField || 'value'] = result[labelField || 'label'], _e));
650
- }
651
- return [4 /*yield*/, this.oldDispatchOptionEvent('add', __assign(__assign({}, result), { idx: idx }))];
652
- case 11:
653
- isPrevented = _f.sent();
654
- if (isPrevented) {
655
- return [2 /*return*/];
656
- }
657
- return [4 /*yield*/, (callback === null || callback === void 0 ? void 0 : callback(result))];
658
- case 12:
659
- ret = _f.sent();
660
- if (!(ret === false)) return [3 /*break*/, 13];
661
- // 如果回调里面返回 false,就不继续了。
630
+ }
631
+ else {
632
+ result = payload.data || result;
633
+ }
634
+ return [3 /*break*/, 10];
635
+ case 9:
636
+ e_1 = _f.sent();
637
+ result = null;
638
+ console.error(e_1);
639
+ !addApi.silent && env.notify('error', e_1.message);
640
+ return [3 /*break*/, 10];
641
+ case 10:
642
+ // result 说明弹框点了确认。否则就是取消了。
643
+ if (!result) {
662
644
  return [2 /*return*/];
663
- case 13:
664
- if (!
665
- // 如果是懒加载的,只懒加载当前节点。
666
- (((parent === null || parent === void 0 ? void 0 : parent.hasOwnProperty(deferField)) && parent[deferField]) ||
667
- (parent === null || parent === void 0 ? void 0 : parent.defer)))
668
- // 如果是懒加载的,只懒加载当前节点。
669
- return [3 /*break*/, 15];
670
- return [4 /*yield*/, this.deferLoad(parent)];
671
- case 14:
672
- _f.sent();
673
- return [3 /*break*/, 16];
674
- case 15:
675
- if (source && addApi) {
676
- // 如果配置了 source 且配置了 addApi 直接重新拉取接口就够了
677
- // 不能不判断 addApi 就刷新,因为有些场景就是临时添加的。
678
- this.reload();
645
+ }
646
+ // 没走服务端的。
647
+ if (!result.hasOwnProperty(valueField || 'value')) {
648
+ result = __assign(__assign({}, result), (_e = {}, _e[valueField || 'value'] = result[labelField || 'label'], _e));
649
+ }
650
+ return [4 /*yield*/, this.oldDispatchOptionEvent('add', __assign(__assign({}, result), { idx: idx }))];
651
+ case 11:
652
+ isPrevented = _f.sent();
653
+ if (isPrevented) {
654
+ return [2 /*return*/];
655
+ }
656
+ return [4 /*yield*/, (callback === null || callback === void 0 ? void 0 : callback(result))];
657
+ case 12:
658
+ ret = _f.sent();
659
+ if (!(ret === false)) return [3 /*break*/, 13];
660
+ // 如果回调里面返回 false,就不继续了。
661
+ return [2 /*return*/];
662
+ case 13:
663
+ if (!
664
+ // 如果是懒加载的,只懒加载当前节点。
665
+ (((parent === null || parent === void 0 ? void 0 : parent.hasOwnProperty(deferField)) && parent[deferField]) ||
666
+ (parent === null || parent === void 0 ? void 0 : parent.defer)))
667
+ // 如果是懒加载的,只懒加载当前节点。
668
+ return [3 /*break*/, 15];
669
+ return [4 /*yield*/, this.deferLoad(parent)];
670
+ case 14:
671
+ _f.sent();
672
+ return [3 /*break*/, 16];
673
+ case 15:
674
+ if (source && addApi) {
675
+ // 如果配置了 source 且配置了 addApi 直接重新拉取接口就够了
676
+ // 不能不判断 addApi 就刷新,因为有些场景就是临时添加的。
677
+ this.reload();
678
+ }
679
+ else {
680
+ options = model.options.concat();
681
+ if (Array.isArray(idx)) {
682
+ options = spliceTree(options, idx, 0, __assign({}, result));
679
683
  }
680
684
  else {
681
- options = model.options.concat();
682
- if (Array.isArray(idx)) {
683
- options = spliceTree(options, idx, 0, __assign({}, result));
684
- }
685
- else {
686
- ~idx
687
- ? options.splice(idx, 0, __assign({}, result))
688
- : options.push(__assign({}, result));
689
- }
690
- model.setOptions(options, this.changeOptionValue, data);
685
+ ~idx ? options.splice(idx, 0, __assign({}, result)) : options.push(__assign({}, result));
691
686
  }
692
- _f.label = 16;
693
- case 16: return [2 /*return*/];
694
- }
695
- });
687
+ model.setOptions(options, this.changeOptionValue, data);
688
+ }
689
+ _f.label = 16;
690
+ case 16: return [2 /*return*/];
691
+ }
696
692
  });
697
- };
698
- FormOptionsItem.prototype.handleOptionEdit = function (value, origin, skipForm, callback) {
699
- var _a, _b;
700
- if (origin === void 0) { origin = value; }
701
- if (skipForm === void 0) { skipForm = false; }
702
- return __awaiter(this, void 0, void 0, function () {
703
- var _c, editControls, editDialog, disabled, labelField, valueField, onOpenDialog, editApi, editInitApi, env, source, data, model, optionLabel, __, customEditPrevent, result, _d, prevent, payload, e_2, isPrevented, ret, indexes;
704
- var _this = this;
705
- return __generator(this, function (_e) {
706
- switch (_e.label) {
707
- case 0:
708
- _c = this.props, editControls = _c.editControls, editDialog = _c.editDialog, disabled = _c.disabled, labelField = _c.labelField, valueField = _c.valueField, onOpenDialog = _c.onOpenDialog, editApi = _c.editApi, editInitApi = _c.editInitApi, env = _c.env, source = _c.source, data = _c.data, model = _c.formItem, optionLabel = _c.optionLabel, __ = _c.translate;
709
- if (disabled || !model) {
710
- return [2 /*return*/];
711
- }
712
- if (!skipForm && (!Array.isArray(editControls) || !editControls.length)) {
713
- editControls = [
714
- {
715
- type: 'text',
716
- name: labelField || 'label',
717
- label: false,
718
- placeholder: __('Options.addPlaceholder')
719
- }
720
- ];
721
- }
722
- customEditPrevent = false;
723
- if (!skipForm) return [3 /*break*/, 1];
724
- _d = value;
725
- return [3 /*break*/, 3];
726
- case 1: return [4 /*yield*/, onOpenDialog(__assign(__assign({ type: 'dialog', title: __('Options.editLabel', {
727
- label: optionLabel || __('Options.label')
728
- }) }, editDialog), { body: {
729
- type: 'form',
730
- initApi: editInitApi,
731
- api: editApi,
732
- controls: editControls,
733
- onSubmit: function (payload) { return __awaiter(_this, void 0, void 0, function () {
734
- var labelKey, valueKey;
735
- var _a;
736
- var _b;
737
- return __generator(this, function (_c) {
738
- switch (_c.label) {
739
- case 0:
740
- labelKey = labelField || 'label';
741
- valueKey = valueField || 'value';
742
- return [4 /*yield*/, this.dispatchOptionEvent('editConfirm', {
743
- item: (_a = {},
744
- _a[labelKey] = payload[labelKey],
745
- _a[valueKey] = (_b = payload[valueKey]) !== null && _b !== void 0 ? _b : payload[labelKey],
746
- _a)
747
- })];
748
- case 1:
749
- // 避免产生breakchange,增加新事件名,用来更正之前的设计问题
750
- customEditPrevent = _c.sent();
751
- return [2 /*return*/, !customEditPrevent];
752
- }
753
- });
754
- }); }
755
- } }), createObject(data, value))];
756
- case 2:
757
- _d = _e.sent();
758
- _e.label = 3;
759
- case 3:
760
- result = _d;
761
- if (!skipForm) return [3 /*break*/, 5];
762
- return [4 /*yield*/, this.dispatchOptionEvent('editConfirm', {
763
- item: result
764
- })];
765
- case 4:
766
- prevent = _e.sent();
767
- if (prevent) {
768
- return [2 /*return*/];
769
- }
770
- return [3 /*break*/, 6];
771
- case 5:
772
- if (customEditPrevent) {
773
- return [2 /*return*/];
774
- }
775
- _e.label = 6;
776
- case 6:
777
- if (!(skipForm && editApi)) return [3 /*break*/, 10];
778
- _e.label = 7;
779
- case 7:
780
- _e.trys.push([7, 9, , 10]);
781
- return [4 /*yield*/, env.fetcher(editApi, createObject(data, result), {
782
- method: 'post'
783
- })];
784
- case 8:
785
- payload = _e.sent();
786
- if (!payload.ok) {
787
- !editApi.silent &&
788
- env.notify('error', (_b = (_a = editApi === null || editApi === void 0 ? void 0 : editApi.messages) === null || _a === void 0 ? void 0 : _a.failed) !== null && _b !== void 0 ? _b : (payload.msg || __('saveFailed')));
789
- result = null;
790
- }
791
- else {
792
- result = payload.data || result;
793
- }
794
- return [3 /*break*/, 10];
795
- case 9:
796
- e_2 = _e.sent();
797
- result = null;
798
- console.error(e_2);
799
- !editApi.silent && env.notify('error', e_2.message);
800
- return [3 /*break*/, 10];
801
- case 10:
802
- // 没有结果,说明取消了。
803
- if (!result) {
804
- return [2 /*return*/];
805
- }
806
- return [4 /*yield*/, this.oldDispatchOptionEvent('edit', result)];
807
- case 11:
808
- isPrevented = _e.sent();
809
- if (isPrevented) {
810
- return [2 /*return*/];
811
- }
812
- return [4 /*yield*/, (callback === null || callback === void 0 ? void 0 : callback(result))];
813
- case 12:
814
- ret = _e.sent();
815
- if (ret === false) {
816
- // 如果回调里面返回 false,就不继续了。
817
- return [2 /*return*/];
818
- }
819
- else if (source && editApi) {
820
- this.reload();
821
- }
822
- else {
823
- indexes = findTreeIndex(model.options, function (item) { return item === origin; });
824
- if (indexes) {
825
- model.setOptions(spliceTree(model.options, indexes, 1, __assign(__assign({}, origin), result)), this.changeOptionValue, data);
693
+ });
694
+ };
695
+ OptionsControlBase.prototype.handleOptionEdit = function (value, origin, skipForm, callback) {
696
+ var _a, _b;
697
+ if (origin === void 0) { origin = value; }
698
+ if (skipForm === void 0) { skipForm = false; }
699
+ return __awaiter(this, void 0, void 0, function () {
700
+ var _c, editControls, editDialog, disabled, labelField, valueField, onOpenDialog, editApi, editInitApi, env, source, data, model, optionLabel, __, customEditPrevent, result, _d, prevent, payload, e_2, isPrevented, ret, indexes;
701
+ var _this = this;
702
+ return __generator(this, function (_e) {
703
+ switch (_e.label) {
704
+ case 0:
705
+ _c = this.props, editControls = _c.editControls, editDialog = _c.editDialog, disabled = _c.disabled, labelField = _c.labelField, valueField = _c.valueField, onOpenDialog = _c.onOpenDialog, editApi = _c.editApi, editInitApi = _c.editInitApi, env = _c.env, source = _c.source, data = _c.data, model = _c.formItem, optionLabel = _c.optionLabel, __ = _c.translate;
706
+ if (disabled || !model) {
707
+ return [2 /*return*/];
708
+ }
709
+ if (!skipForm && (!Array.isArray(editControls) || !editControls.length)) {
710
+ editControls = [
711
+ {
712
+ type: 'text',
713
+ name: labelField || 'label',
714
+ label: false,
715
+ placeholder: __('Options.addPlaceholder')
826
716
  }
827
- }
717
+ ];
718
+ }
719
+ customEditPrevent = false;
720
+ if (!skipForm) return [3 /*break*/, 1];
721
+ _d = value;
722
+ return [3 /*break*/, 3];
723
+ case 1: return [4 /*yield*/, onOpenDialog(__assign(__assign({ type: 'dialog', title: __('Options.editLabel', {
724
+ label: optionLabel || __('Options.label')
725
+ }) }, editDialog), { body: {
726
+ type: 'form',
727
+ initApi: editInitApi,
728
+ api: editApi,
729
+ controls: editControls,
730
+ onSubmit: function (payload) { return __awaiter(_this, void 0, void 0, function () {
731
+ var labelKey, valueKey;
732
+ var _a;
733
+ var _b;
734
+ return __generator(this, function (_c) {
735
+ switch (_c.label) {
736
+ case 0:
737
+ labelKey = labelField || 'label';
738
+ valueKey = valueField || 'value';
739
+ return [4 /*yield*/, this.dispatchOptionEvent('editConfirm', {
740
+ item: (_a = {},
741
+ _a[labelKey] = payload[labelKey],
742
+ _a[valueKey] = (_b = payload[valueKey]) !== null && _b !== void 0 ? _b : payload[labelKey],
743
+ _a)
744
+ })];
745
+ case 1:
746
+ // 避免产生breakchange,增加新事件名,用来更正之前的设计问题
747
+ customEditPrevent = _c.sent();
748
+ return [2 /*return*/, !customEditPrevent];
749
+ }
750
+ });
751
+ }); }
752
+ } }), createObject(data, value))];
753
+ case 2:
754
+ _d = _e.sent();
755
+ _e.label = 3;
756
+ case 3:
757
+ result = _d;
758
+ if (!skipForm) return [3 /*break*/, 5];
759
+ return [4 /*yield*/, this.dispatchOptionEvent('editConfirm', {
760
+ item: result
761
+ })];
762
+ case 4:
763
+ prevent = _e.sent();
764
+ if (prevent) {
828
765
  return [2 /*return*/];
829
- }
830
- });
831
- });
832
- };
833
- FormOptionsItem.prototype.handleOptionDelete = function (value, callback) {
834
- var _a, _b;
835
- return __awaiter(this, void 0, void 0, function () {
836
- var _c, deleteConfirmText, disabled, data, deleteApi, onDelete, env, model, source, valueField, __, ctx, confirmed, _d, isPrevented, delConfirmPrevent, result, ret, options, indexes, e_3;
837
- return __generator(this, function (_e) {
838
- switch (_e.label) {
839
- case 0:
840
- _c = this.props, deleteConfirmText = _c.deleteConfirmText, disabled = _c.disabled, data = _c.data, deleteApi = _c.deleteApi, onDelete = _c.onDelete, env = _c.env, model = _c.formItem, source = _c.source, valueField = _c.valueField, __ = _c.translate;
841
- if (disabled || !model) {
842
- return [2 /*return*/];
843
- }
844
- ctx = createObject(data, value);
845
- if (!deleteConfirmText) return [3 /*break*/, 2];
846
- return [4 /*yield*/, env.confirm(filter(__(deleteConfirmText), ctx))];
847
- case 1:
848
- _d = _e.sent();
849
- return [3 /*break*/, 3];
850
- case 2:
851
- _d = true;
852
- _e.label = 3;
853
- case 3:
854
- confirmed = _d;
855
- if (!confirmed) {
856
- return [2 /*return*/];
857
- }
858
- return [4 /*yield*/, this.oldDispatchOptionEvent('delete', ctx)];
859
- case 4:
860
- isPrevented = _e.sent();
861
- if (isPrevented) {
862
- return [2 /*return*/];
863
- }
864
- return [4 /*yield*/, this.dispatchOptionEvent('deleteConfirm', {
865
- item: value
866
- })];
867
- case 5:
868
- delConfirmPrevent = _e.sent();
869
- if (delConfirmPrevent) {
870
- return [2 /*return*/];
871
- }
872
- _e.label = 6;
873
- case 6:
874
- _e.trys.push([6, 9, , 10]);
875
- if (!deleteApi) return [3 /*break*/, 8];
876
- return [4 /*yield*/, env.fetcher(deleteApi, ctx, {
877
- method: 'delete'
878
- })];
879
- case 7:
880
- result = _e.sent();
881
- if (!result.ok) {
882
- !deleteApi.silent &&
883
- env.notify('error', (_b = (_a = deleteApi === null || deleteApi === void 0 ? void 0 : deleteApi.messages) === null || _a === void 0 ? void 0 : _a.failed) !== null && _b !== void 0 ? _b : (result.msg || __('deleteFailed')));
884
- return [2 /*return*/];
885
- }
886
- _e.label = 8;
887
- case 8:
888
- // 由外部代码实现删除逻辑
889
- if (onDelete) {
890
- onDelete(ctx);
891
- }
892
- ret = callback === null || callback === void 0 ? void 0 : callback(ctx);
893
- if (ret === false) {
894
- // 如果回调里面返回 false,就不继续了。
895
- return [2 /*return*/];
896
- }
897
- else if (source) {
898
- this.reload();
766
+ }
767
+ return [3 /*break*/, 6];
768
+ case 5:
769
+ if (customEditPrevent) {
770
+ return [2 /*return*/];
771
+ }
772
+ _e.label = 6;
773
+ case 6:
774
+ if (!(skipForm && editApi)) return [3 /*break*/, 10];
775
+ _e.label = 7;
776
+ case 7:
777
+ _e.trys.push([7, 9, , 10]);
778
+ return [4 /*yield*/, env.fetcher(editApi, createObject(data, result), {
779
+ method: 'post'
780
+ })];
781
+ case 8:
782
+ payload = _e.sent();
783
+ if (!payload.ok) {
784
+ !editApi.silent &&
785
+ env.notify('error', (_b = (_a = editApi === null || editApi === void 0 ? void 0 : editApi.messages) === null || _a === void 0 ? void 0 : _a.failed) !== null && _b !== void 0 ? _b : (payload.msg || __('saveFailed')));
786
+ result = null;
787
+ }
788
+ else {
789
+ result = payload.data || result;
790
+ }
791
+ return [3 /*break*/, 10];
792
+ case 9:
793
+ e_2 = _e.sent();
794
+ result = null;
795
+ console.error(e_2);
796
+ !editApi.silent && env.notify('error', e_2.message);
797
+ return [3 /*break*/, 10];
798
+ case 10:
799
+ // 没有结果,说明取消了。
800
+ if (!result) {
801
+ return [2 /*return*/];
802
+ }
803
+ return [4 /*yield*/, this.oldDispatchOptionEvent('edit', result)];
804
+ case 11:
805
+ isPrevented = _e.sent();
806
+ if (isPrevented) {
807
+ return [2 /*return*/];
808
+ }
809
+ return [4 /*yield*/, (callback === null || callback === void 0 ? void 0 : callback(result))];
810
+ case 12:
811
+ ret = _e.sent();
812
+ if (ret === false) {
813
+ // 如果回调里面返回 false,就不继续了。
814
+ return [2 /*return*/];
815
+ }
816
+ else if (source && editApi) {
817
+ this.reload();
818
+ }
819
+ else {
820
+ indexes = findTreeIndex(model.options, function (item) { return item === origin; });
821
+ if (indexes) {
822
+ model.setOptions(spliceTree(model.options, indexes, 1, __assign(__assign({}, origin), result)), this.changeOptionValue, data);
899
823
  }
900
- else {
901
- options = model.options.concat();
902
- indexes = findTreeIndex(options, function (item) { return item[valueField || 'value'] == value[valueField || 'value']; });
903
- if (indexes) {
904
- model.setOptions(spliceTree(options, indexes, 1), this.changeOptionValue, data);
905
- }
824
+ }
825
+ return [2 /*return*/];
826
+ }
827
+ });
828
+ });
829
+ };
830
+ OptionsControlBase.prototype.handleOptionDelete = function (value, callback) {
831
+ var _a, _b;
832
+ return __awaiter(this, void 0, void 0, function () {
833
+ var _c, deleteConfirmText, disabled, data, deleteApi, onDelete, env, model, source, valueField, __, ctx, confirmed, _d, isPrevented, delConfirmPrevent, result, ret, options, indexes, e_3;
834
+ return __generator(this, function (_e) {
835
+ switch (_e.label) {
836
+ case 0:
837
+ _c = this.props, deleteConfirmText = _c.deleteConfirmText, disabled = _c.disabled, data = _c.data, deleteApi = _c.deleteApi, onDelete = _c.onDelete, env = _c.env, model = _c.formItem, source = _c.source, valueField = _c.valueField, __ = _c.translate;
838
+ if (disabled || !model) {
839
+ return [2 /*return*/];
840
+ }
841
+ ctx = createObject(data, value);
842
+ if (!deleteConfirmText) return [3 /*break*/, 2];
843
+ return [4 /*yield*/, env.confirm(filter(__(deleteConfirmText), ctx))];
844
+ case 1:
845
+ _d = _e.sent();
846
+ return [3 /*break*/, 3];
847
+ case 2:
848
+ _d = true;
849
+ _e.label = 3;
850
+ case 3:
851
+ confirmed = _d;
852
+ if (!confirmed) {
853
+ return [2 /*return*/];
854
+ }
855
+ return [4 /*yield*/, this.oldDispatchOptionEvent('delete', ctx)];
856
+ case 4:
857
+ isPrevented = _e.sent();
858
+ if (isPrevented) {
859
+ return [2 /*return*/];
860
+ }
861
+ return [4 /*yield*/, this.dispatchOptionEvent('deleteConfirm', {
862
+ item: value
863
+ })];
864
+ case 5:
865
+ delConfirmPrevent = _e.sent();
866
+ if (delConfirmPrevent) {
867
+ return [2 /*return*/];
868
+ }
869
+ _e.label = 6;
870
+ case 6:
871
+ _e.trys.push([6, 9, , 10]);
872
+ if (!deleteApi) return [3 /*break*/, 8];
873
+ return [4 /*yield*/, env.fetcher(deleteApi, ctx, {
874
+ method: 'delete'
875
+ })];
876
+ case 7:
877
+ result = _e.sent();
878
+ if (!result.ok) {
879
+ !deleteApi.silent &&
880
+ env.notify('error', (_b = (_a = deleteApi === null || deleteApi === void 0 ? void 0 : deleteApi.messages) === null || _a === void 0 ? void 0 : _a.failed) !== null && _b !== void 0 ? _b : (result.msg || __('deleteFailed')));
881
+ return [2 /*return*/];
882
+ }
883
+ _e.label = 8;
884
+ case 8:
885
+ // 由外部代码实现删除逻辑
886
+ if (onDelete) {
887
+ onDelete(ctx);
888
+ }
889
+ ret = callback === null || callback === void 0 ? void 0 : callback(ctx);
890
+ if (ret === false) {
891
+ // 如果回调里面返回 false,就不继续了。
892
+ return [2 /*return*/];
893
+ }
894
+ else if (source) {
895
+ this.reload();
896
+ }
897
+ else {
898
+ options = model.options.concat();
899
+ indexes = findTreeIndex(options, function (item) { return item[valueField || 'value'] == value[valueField || 'value']; });
900
+ if (indexes) {
901
+ model.setOptions(spliceTree(options, indexes, 1), this.changeOptionValue, data);
906
902
  }
907
- return [3 /*break*/, 10];
908
- case 9:
909
- e_3 = _e.sent();
910
- console.error(e_3);
911
- !deleteApi.silent && env.notify('error', e_3.message);
912
- return [3 /*break*/, 10];
913
- case 10: return [2 /*return*/];
914
- }
915
- });
903
+ }
904
+ return [3 /*break*/, 10];
905
+ case 9:
906
+ e_3 = _e.sent();
907
+ console.error(e_3);
908
+ !deleteApi.silent && env.notify('error', e_3.message);
909
+ return [3 /*break*/, 10];
910
+ case 10: return [2 /*return*/];
911
+ }
916
912
  });
917
- };
918
- FormOptionsItem.prototype.render = function () {
919
- var _a = this.props, value = _a.value, formItem = _a.formItem, addApi = _a.addApi, editApi = _a.editApi, deleteApi = _a.deleteApi, creatable = _a.creatable, editable = _a.editable, removable = _a.removable, enableNodePath = _a.enableNodePath, pathSeparator = _a.pathSeparator, _b = _a.delimiter, delimiter = _b === void 0 ? ',' : _b, _c = _a.labelField, labelField = _c === void 0 ? 'label' : _c, _d = _a.valueField, valueField = _d === void 0 ? 'value' : _d, __ = _a.translate;
920
- var _e = normalizeNodePath(value, enableNodePath, labelField, valueField, pathSeparator, delimiter), nodePathArray = _e.nodePathArray, nodeValueArray = _e.nodeValueArray;
921
- return (React.createElement(Control, __assign({}, this.props, { placeholder: __(this.props.placeholder), ref: this.inputRef, options: formItem ? formItem.filteredOptions : [], onToggle: this.handleToggle, onToggleAll: this.handleToggleAll, selectedOptions: formItem
922
- ? formItem.getSelectedOptions(value, enableNodePath ? nodeValueArray : undefined)
923
- : [], nodePath: nodePathArray, loading: formItem ? formItem.loading : false, setLoading: this.setLoading, setOptions: this.setOptions, syncOptions: this.syncOptions, reloadOptions: this.reload, deferLoad: this.deferLoad, leftDeferLoad: this.leftDeferLoad, expandTreeOptions: this.expandTreeOptions, creatable: creatable !== false && isEffectiveApi(addApi) ? true : creatable, editable: editable || (editable !== false && isEffectiveApi(editApi)), removable: removable || (removable !== false && isEffectiveApi(deleteApi)), onAdd: this.handleOptionAdd, onEdit: this.handleOptionEdit, onDelete: this.handleOptionDelete })));
924
- };
913
+ });
914
+ };
915
+ OptionsControlBase.prototype.render = function () {
916
+ var _a = this.props, value = _a.value, formItem = _a.formItem, addApi = _a.addApi, editApi = _a.editApi, deleteApi = _a.deleteApi, creatable = _a.creatable, editable = _a.editable, removable = _a.removable, enableNodePath = _a.enableNodePath, pathSeparator = _a.pathSeparator, _b = _a.delimiter, delimiter = _b === void 0 ? ',' : _b, _c = _a.labelField, labelField = _c === void 0 ? 'label' : _c, _d = _a.valueField, valueField = _d === void 0 ? 'value' : _d, __ = _a.translate;
917
+ var _e = normalizeNodePath(value, enableNodePath, labelField, valueField, pathSeparator, delimiter), nodePathArray = _e.nodePathArray, nodeValueArray = _e.nodeValueArray;
918
+ var Control = this.config.component;
919
+ return (React.createElement(Control, __assign({}, this.props, { placeholder: __(this.props.placeholder), ref: this.inputRef, options: formItem ? formItem.filteredOptions : [], onToggle: this.handleToggle, onToggleAll: this.handleToggleAll, selectedOptions: formItem
920
+ ? formItem.getSelectedOptions(value, enableNodePath ? nodeValueArray : undefined)
921
+ : [], nodePath: nodePathArray, loading: formItem ? formItem.loading : false, setLoading: this.setLoading, setOptions: this.setOptions, syncOptions: this.syncOptions, reloadOptions: this.reload, deferLoad: this.deferLoad, leftDeferLoad: this.leftDeferLoad, expandTreeOptions: this.expandTreeOptions, creatable: creatable !== false && isEffectiveApi(addApi) ? true : creatable, editable: editable || (editable !== false && isEffectiveApi(editApi)), removable: removable || (removable !== false && isEffectiveApi(deleteApi)), onAdd: this.handleOptionAdd, onEdit: this.handleOptionEdit, onDelete: this.handleOptionDelete })));
922
+ };
923
+ __decorate([
924
+ autobind,
925
+ __metadata("design:type", Function),
926
+ __metadata("design:paramtypes", [Object]),
927
+ __metadata("design:returntype", void 0)
928
+ ], OptionsControlBase.prototype, "inputRef", null);
929
+ __decorate([
930
+ autobind,
931
+ __metadata("design:type", Function),
932
+ __metadata("design:paramtypes", [Object, Boolean, Boolean]),
933
+ __metadata("design:returntype", Promise)
934
+ ], OptionsControlBase.prototype, "handleToggle", null);
935
+ __decorate([
936
+ autobind,
937
+ __metadata("design:type", Function),
938
+ __metadata("design:paramtypes", []),
939
+ __metadata("design:returntype", Promise)
940
+ ], OptionsControlBase.prototype, "handleToggleAll", null);
941
+ __decorate([
942
+ autobind,
943
+ __metadata("design:type", Function),
944
+ __metadata("design:paramtypes", []),
945
+ __metadata("design:returntype", void 0)
946
+ ], OptionsControlBase.prototype, "reload", null);
947
+ __decorate([
948
+ autobind,
949
+ __metadata("design:type", Function),
950
+ __metadata("design:paramtypes", [Boolean, Object, Object]),
951
+ __metadata("design:returntype", void 0)
952
+ ], OptionsControlBase.prototype, "reloadOptions", null);
953
+ __decorate([
954
+ autobind,
955
+ __metadata("design:type", Function),
956
+ __metadata("design:paramtypes", [Object]),
957
+ __metadata("design:returntype", Promise)
958
+ ], OptionsControlBase.prototype, "deferLoad", null);
959
+ __decorate([
960
+ autobind,
961
+ __metadata("design:type", Function),
962
+ __metadata("design:paramtypes", [Object, Object]),
963
+ __metadata("design:returntype", void 0)
964
+ ], OptionsControlBase.prototype, "leftDeferLoad", null);
965
+ __decorate([
966
+ autobind,
967
+ __metadata("design:type", Function),
968
+ __metadata("design:paramtypes", [Array]),
969
+ __metadata("design:returntype", void 0)
970
+ ], OptionsControlBase.prototype, "expandTreeOptions", null);
971
+ __decorate([
972
+ autobind,
973
+ __metadata("design:type", Function),
974
+ __metadata("design:paramtypes", [Object]),
975
+ __metadata("design:returntype", Promise)
976
+ ], OptionsControlBase.prototype, "initOptions", null);
977
+ __decorate([
978
+ autobind,
979
+ __metadata("design:type", Function),
980
+ __metadata("design:paramtypes", [Object]),
981
+ __metadata("design:returntype", void 0)
982
+ ], OptionsControlBase.prototype, "changeOptionValue", null);
983
+ __decorate([
984
+ autobind,
985
+ __metadata("design:type", Function),
986
+ __metadata("design:paramtypes", [Array, Object]),
987
+ __metadata("design:returntype", void 0)
988
+ ], OptionsControlBase.prototype, "setOptions", null);
989
+ __decorate([
990
+ autobind,
991
+ __metadata("design:type", Function),
992
+ __metadata("design:paramtypes", []),
993
+ __metadata("design:returntype", void 0)
994
+ ], OptionsControlBase.prototype, "syncOptions", null);
995
+ __decorate([
996
+ autobind,
997
+ __metadata("design:type", Function),
998
+ __metadata("design:paramtypes", [Boolean]),
999
+ __metadata("design:returntype", void 0)
1000
+ ], OptionsControlBase.prototype, "setLoading", null);
1001
+ __decorate([
1002
+ autobind,
1003
+ __metadata("design:type", Function),
1004
+ __metadata("design:paramtypes", [Object, Object, Boolean, Function]),
1005
+ __metadata("design:returntype", Promise)
1006
+ ], OptionsControlBase.prototype, "handleOptionAdd", null);
1007
+ __decorate([
1008
+ autobind,
1009
+ __metadata("design:type", Function),
1010
+ __metadata("design:paramtypes", [Object, Object, Boolean, Function]),
1011
+ __metadata("design:returntype", Promise)
1012
+ ], OptionsControlBase.prototype, "handleOptionEdit", null);
1013
+ __decorate([
1014
+ autobind,
1015
+ __metadata("design:type", Function),
1016
+ __metadata("design:paramtypes", [Object, Function]),
1017
+ __metadata("design:returntype", Promise)
1018
+ ], OptionsControlBase.prototype, "handleOptionDelete", null);
1019
+ return OptionsControlBase;
1020
+ }(React.Component));
1021
+ function registerOptionsControl(config) {
1022
+ var Control = config.component;
1023
+ var FormOptionsItem = /** @class */ (function (_super) {
1024
+ __extends(FormOptionsItem, _super);
1025
+ function FormOptionsItem(props) {
1026
+ return _super.call(this, props, config) || this;
1027
+ }
925
1028
  FormOptionsItem.displayName = "OptionsControl(".concat(config.type, ")");
926
1029
  FormOptionsItem.defaultProps = __assign({ delimiter: ',', labelField: 'label', valueField: 'value', joinValues: true, extractValue: false, multiple: false, placeholder: 'Select.placeholder', resetValue: '', deleteConfirmText: 'deleteConfirm' }, Control.defaultProps);
927
1030
  FormOptionsItem.propsList = Control.propsList
928
1031
  ? __spreadArray([], __read(Control.propsList), false) : [];
929
1032
  FormOptionsItem.ComposedComponent = Control;
930
- __decorate([
931
- autobind,
932
- __metadata("design:type", Function),
933
- __metadata("design:paramtypes", [Object]),
934
- __metadata("design:returntype", void 0)
935
- ], FormOptionsItem.prototype, "inputRef", null);
936
- __decorate([
937
- autobind,
938
- __metadata("design:type", Function),
939
- __metadata("design:paramtypes", [Object, Boolean, Boolean]),
940
- __metadata("design:returntype", Promise)
941
- ], FormOptionsItem.prototype, "handleToggle", null);
942
- __decorate([
943
- autobind,
944
- __metadata("design:type", Function),
945
- __metadata("design:paramtypes", []),
946
- __metadata("design:returntype", Promise)
947
- ], FormOptionsItem.prototype, "handleToggleAll", null);
948
- __decorate([
949
- autobind,
950
- __metadata("design:type", Function),
951
- __metadata("design:paramtypes", []),
952
- __metadata("design:returntype", void 0)
953
- ], FormOptionsItem.prototype, "reload", null);
954
- __decorate([
955
- autobind,
956
- __metadata("design:type", Function),
957
- __metadata("design:paramtypes", [Boolean, Object, Object]),
958
- __metadata("design:returntype", void 0)
959
- ], FormOptionsItem.prototype, "reloadOptions", null);
960
- __decorate([
961
- autobind,
962
- __metadata("design:type", Function),
963
- __metadata("design:paramtypes", [Object]),
964
- __metadata("design:returntype", Promise)
965
- ], FormOptionsItem.prototype, "deferLoad", null);
966
- __decorate([
967
- autobind,
968
- __metadata("design:type", Function),
969
- __metadata("design:paramtypes", [Object, Object]),
970
- __metadata("design:returntype", void 0)
971
- ], FormOptionsItem.prototype, "leftDeferLoad", null);
972
- __decorate([
973
- autobind,
974
- __metadata("design:type", Function),
975
- __metadata("design:paramtypes", [Array]),
976
- __metadata("design:returntype", void 0)
977
- ], FormOptionsItem.prototype, "expandTreeOptions", null);
978
- __decorate([
979
- autobind,
980
- __metadata("design:type", Function),
981
- __metadata("design:paramtypes", [Object]),
982
- __metadata("design:returntype", Promise)
983
- ], FormOptionsItem.prototype, "initOptions", null);
984
- __decorate([
985
- autobind,
986
- __metadata("design:type", Function),
987
- __metadata("design:paramtypes", [Object]),
988
- __metadata("design:returntype", void 0)
989
- ], FormOptionsItem.prototype, "changeOptionValue", null);
990
- __decorate([
991
- autobind,
992
- __metadata("design:type", Function),
993
- __metadata("design:paramtypes", [Array, Object]),
994
- __metadata("design:returntype", void 0)
995
- ], FormOptionsItem.prototype, "setOptions", null);
996
- __decorate([
997
- autobind,
998
- __metadata("design:type", Function),
999
- __metadata("design:paramtypes", []),
1000
- __metadata("design:returntype", void 0)
1001
- ], FormOptionsItem.prototype, "syncOptions", null);
1002
- __decorate([
1003
- autobind,
1004
- __metadata("design:type", Function),
1005
- __metadata("design:paramtypes", [Boolean]),
1006
- __metadata("design:returntype", void 0)
1007
- ], FormOptionsItem.prototype, "setLoading", null);
1008
- __decorate([
1009
- autobind,
1010
- __metadata("design:type", Function),
1011
- __metadata("design:paramtypes", [Object, Object, Boolean, Function]),
1012
- __metadata("design:returntype", Promise)
1013
- ], FormOptionsItem.prototype, "handleOptionAdd", null);
1014
- __decorate([
1015
- autobind,
1016
- __metadata("design:type", Function),
1017
- __metadata("design:paramtypes", [Object, Object, Boolean, Function]),
1018
- __metadata("design:returntype", Promise)
1019
- ], FormOptionsItem.prototype, "handleOptionEdit", null);
1020
- __decorate([
1021
- autobind,
1022
- __metadata("design:type", Function),
1023
- __metadata("design:paramtypes", [Object, Function]),
1024
- __metadata("design:returntype", Promise)
1025
- ], FormOptionsItem.prototype, "handleOptionDelete", null);
1026
1033
  return FormOptionsItem;
1027
- }(React.Component));
1034
+ }(OptionsControlBase));
1028
1035
  return registerFormItem(__assign(__assign({}, config), { strictMode: false, component: FormOptionsItem }));
1029
1036
  }
1030
1037
  function OptionsControl(config) {
@@ -1034,4 +1041,4 @@ function OptionsControl(config) {
1034
1041
  };
1035
1042
  }
1036
1043
 
1037
- export { OptionsControl, detectProps, registerOptionsControl };
1044
+ export { OptionsControl, OptionsControlBase, detectProps, registerOptionsControl };