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