amis 1.6.5-beta.3 → 1.8.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/lib/Schema.d.ts +3 -2
  2. package/lib/Schema.js +0 -1
  3. package/lib/Schema.js.map +2 -2
  4. package/lib/components/Alert2.js +4 -2
  5. package/lib/components/Alert2.js.map +2 -2
  6. package/lib/components/AssociatedSelection.d.ts +84 -84
  7. package/lib/components/Avatar.d.ts +20 -20
  8. package/lib/components/Breadcrumb.d.ts +130 -0
  9. package/lib/components/Breadcrumb.js +161 -0
  10. package/lib/components/Breadcrumb.js.map +13 -0
  11. package/lib/components/Card.d.ts +20 -20
  12. package/lib/components/ChainedSelection.d.ts +84 -84
  13. package/lib/components/CityArea.js +3 -0
  14. package/lib/components/CityArea.js.map +2 -2
  15. package/lib/components/Collapse.d.ts +20 -20
  16. package/lib/components/CollapseGroup.d.ts +20 -20
  17. package/lib/components/DatePicker.d.ts +84 -84
  18. package/lib/components/DateRangePicker.d.ts +2 -2
  19. package/lib/components/DateRangePicker.js +36 -45
  20. package/lib/components/DateRangePicker.js.map +2 -2
  21. package/lib/components/GroupedSelection.d.ts +84 -84
  22. package/lib/components/Layout.d.ts +21 -21
  23. package/lib/components/ListGroup.d.ts +21 -21
  24. package/lib/components/PopUp.js +2 -1
  25. package/lib/components/PopUp.js.map +2 -2
  26. package/lib/components/Radios.d.ts +21 -21
  27. package/lib/components/Range.js.map +2 -2
  28. package/lib/components/Selection.d.ts +84 -84
  29. package/lib/components/TableSelection.d.ts +84 -84
  30. package/lib/components/Tabs.d.ts +52 -23
  31. package/lib/components/Tabs.js +198 -46
  32. package/lib/components/Tabs.js.map +2 -2
  33. package/lib/components/TooltipWrapper.d.ts +21 -20
  34. package/lib/components/TooltipWrapper.js +2 -2
  35. package/lib/components/TooltipWrapper.js.map +2 -2
  36. package/lib/components/Transfer.d.ts +84 -84
  37. package/lib/components/TransferDropDown.d.ts +84 -84
  38. package/lib/components/Tree.d.ts +84 -84
  39. package/lib/components/TreeSelection.d.ts +84 -84
  40. package/lib/components/calendar/Calendar.js +5 -0
  41. package/lib/components/calendar/Calendar.js.map +2 -2
  42. package/lib/components/calendar/DaysView.js.map +1 -1
  43. package/lib/components/icons.js +8 -0
  44. package/lib/components/icons.js.map +2 -2
  45. package/lib/components/index.d.ts +2 -1
  46. package/lib/components/index.js +4 -2
  47. package/lib/components/index.js.map +2 -2
  48. package/lib/icons/cloud-upload.js +17 -0
  49. package/lib/icons/image.js +7 -0
  50. package/lib/icons/refresh.js +9 -0
  51. package/lib/icons/trash.js +10 -0
  52. package/lib/icons/upload.js +3 -8
  53. package/lib/index.d.ts +1 -0
  54. package/lib/index.js +2 -1
  55. package/lib/index.js.map +2 -2
  56. package/lib/locale/en-US.js +3 -1
  57. package/lib/locale/en-US.js.map +2 -2
  58. package/lib/locale/zh-CN.js +4 -2
  59. package/lib/locale/zh-CN.js.map +2 -2
  60. package/lib/renderers/Action.d.ts +1 -1
  61. package/lib/renderers/Action.js.map +2 -2
  62. package/lib/renderers/Breadcrumb.d.ts +41 -6
  63. package/lib/renderers/Breadcrumb.js +23 -19
  64. package/lib/renderers/Breadcrumb.js.map +2 -2
  65. package/lib/renderers/ButtonGroup.d.ts +2 -2
  66. package/lib/renderers/ButtonGroup.js.map +1 -1
  67. package/lib/renderers/Form/ChainedSelect.d.ts +4 -1
  68. package/lib/renderers/Form/ChainedSelect.js +83 -34
  69. package/lib/renderers/Form/ChainedSelect.js.map +2 -2
  70. package/lib/renderers/Form/Checkbox.d.ts +3 -0
  71. package/lib/renderers/Form/Checkbox.js +38 -1
  72. package/lib/renderers/Form/Checkbox.js.map +2 -2
  73. package/lib/renderers/Form/Combo.d.ts +4 -3
  74. package/lib/renderers/Form/Combo.js +81 -32
  75. package/lib/renderers/Form/Combo.js.map +2 -2
  76. package/lib/renderers/Form/DiffEditor.d.ts +1 -1
  77. package/lib/renderers/Form/InputCity.d.ts +84 -84
  78. package/lib/renderers/Form/InputCity.js +4 -1
  79. package/lib/renderers/Form/InputCity.js.map +2 -2
  80. package/lib/renderers/Form/InputColor.js +3 -1
  81. package/lib/renderers/Form/InputColor.js.map +2 -2
  82. package/lib/renderers/Form/InputDate.js +3 -1
  83. package/lib/renderers/Form/InputDate.js.map +2 -2
  84. package/lib/renderers/Form/InputDateRange.js +3 -1
  85. package/lib/renderers/Form/InputDateRange.js.map +2 -2
  86. package/lib/renderers/Form/InputExcel.d.ts +4 -0
  87. package/lib/renderers/Form/InputExcel.js +33 -6
  88. package/lib/renderers/Form/InputExcel.js.map +2 -2
  89. package/lib/renderers/Form/InputFile.d.ts +8 -1
  90. package/lib/renderers/Form/InputFile.js +71 -42
  91. package/lib/renderers/Form/InputFile.js.map +2 -2
  92. package/lib/renderers/Form/InputImage.d.ts +4 -1
  93. package/lib/renderers/Form/InputImage.js +21 -9
  94. package/lib/renderers/Form/InputImage.js.map +2 -2
  95. package/lib/renderers/Form/InputRange.d.ts +27 -9
  96. package/lib/renderers/Form/InputRange.js +88 -23
  97. package/lib/renderers/Form/InputRange.js.map +2 -2
  98. package/lib/renderers/Form/InputSubForm.js +2 -1
  99. package/lib/renderers/Form/InputSubForm.js.map +2 -2
  100. package/lib/renderers/Form/InputTag.js +2 -1
  101. package/lib/renderers/Form/InputTag.js.map +2 -2
  102. package/lib/renderers/Form/MatrixCheckboxes.js +2 -1
  103. package/lib/renderers/Form/MatrixCheckboxes.js.map +2 -2
  104. package/lib/renderers/Form/NestedSelect.d.ts +9 -6
  105. package/lib/renderers/Form/NestedSelect.js +247 -130
  106. package/lib/renderers/Form/NestedSelect.js.map +2 -2
  107. package/lib/renderers/Form/Options.js +2 -1
  108. package/lib/renderers/Form/Options.js.map +2 -2
  109. package/lib/renderers/Form/Radios.js +2 -1
  110. package/lib/renderers/Form/Radios.js.map +2 -2
  111. package/lib/renderers/Form/Select.js +6 -3
  112. package/lib/renderers/Form/Select.js.map +2 -2
  113. package/lib/renderers/Form/Switch.d.ts +7 -6
  114. package/lib/renderers/Form/Switch.js +4 -1
  115. package/lib/renderers/Form/Switch.js.map +2 -2
  116. package/lib/renderers/Log.js +2 -1
  117. package/lib/renderers/Log.js.map +2 -2
  118. package/lib/renderers/PopOver.js +1 -1
  119. package/lib/renderers/PopOver.js.map +2 -2
  120. package/lib/renderers/Tabs.d.ts +58 -5
  121. package/lib/renderers/Tabs.js +170 -58
  122. package/lib/renderers/Tabs.js.map +2 -2
  123. package/lib/renderers/TooltipWrapper.d.ts +104 -0
  124. package/lib/renderers/TooltipWrapper.js +59 -0
  125. package/lib/renderers/TooltipWrapper.js.map +13 -0
  126. package/lib/renderers/Video.d.ts +6 -0
  127. package/lib/renderers/Video.js +13 -6
  128. package/lib/renderers/Video.js.map +2 -2
  129. package/lib/store/form.js +4 -13
  130. package/lib/store/form.js.map +2 -2
  131. package/lib/store/table.js +1 -1
  132. package/lib/store/table.js.map +2 -2
  133. package/lib/themes/ang-ie11.css +742 -160
  134. package/lib/themes/ang.css +793 -163
  135. package/lib/themes/ang.css.map +1 -1
  136. package/lib/themes/antd-ie11.css +757 -175
  137. package/lib/themes/antd.css +793 -163
  138. package/lib/themes/antd.css.map +1 -1
  139. package/lib/themes/cxd-ie11.css +1249 -667
  140. package/lib/themes/cxd.css +970 -321
  141. package/lib/themes/cxd.css.map +1 -1
  142. package/lib/themes/dark-ie11.css +742 -160
  143. package/lib/themes/dark.css +793 -163
  144. package/lib/themes/dark.css.map +1 -1
  145. package/lib/themes/default-ie11.css +1249 -667
  146. package/lib/themes/default.css +970 -321
  147. package/lib/themes/default.css.map +1 -1
  148. package/package.json +1 -1
  149. package/schema.json +16012 -736
  150. package/scss/_properties.scss +56 -2
  151. package/scss/components/_alert.scss +1 -1
  152. package/scss/components/_breadcrumb.scss +90 -1
  153. package/scss/components/_button-group.scss +15 -0
  154. package/scss/components/_city-area.scss +2 -0
  155. package/scss/components/_popup.scss +13 -3
  156. package/scss/components/_tabs.scss +629 -132
  157. package/scss/components/_tooltip.scss +72 -0
  158. package/scss/components/form/_file.scss +82 -24
  159. package/scss/components/form/_image.scss +30 -25
  160. package/scss/components/form/_number.scss +2 -0
  161. package/scss/components/form/_switch.scss +1 -3
  162. package/scss/themes/_cxd-colors.scss +47 -47
  163. package/scss/themes/_cxd-variables.scss +20 -0
  164. package/sdk/ang-ie11.css +879 -196
  165. package/sdk/ang.css +931 -200
  166. package/sdk/antd-ie11.css +951 -268
  167. package/sdk/antd.css +931 -200
  168. package/sdk/barcode.js +51 -51
  169. package/sdk/charts.js +14 -14
  170. package/sdk/codemirror.js +7 -7
  171. package/sdk/color-picker.js +65 -65
  172. package/sdk/cropperjs.js +2 -2
  173. package/sdk/cxd-ie11.css +1386 -703
  174. package/sdk/cxd.css +1107 -357
  175. package/sdk/dark-ie11.css +879 -196
  176. package/sdk/dark.css +931 -200
  177. package/sdk/exceljs.js +1 -1
  178. package/sdk/markdown.js +69 -69
  179. package/sdk/papaparse.js +1 -1
  180. package/sdk/renderers/Form/CityDB.js +1 -1
  181. package/sdk/rest.js +17 -17
  182. package/sdk/rich-text.js +62 -62
  183. package/sdk/sdk-ie11.css +1386 -703
  184. package/sdk/sdk.css +1107 -357
  185. package/sdk/sdk.js +1260 -1248
  186. package/sdk/thirds/hls.js/hls.js +1 -1
  187. package/sdk/thirds/mpegts.js/mpegts.js +1 -1
  188. package/sdk/tinymce.js +57 -57
  189. package/src/Schema.ts +5 -2
  190. package/src/components/Alert2.tsx +9 -3
  191. package/src/components/Breadcrumb.tsx +294 -0
  192. package/src/components/CityArea.tsx +3 -0
  193. package/src/components/DateRangePicker.tsx +40 -68
  194. package/src/components/PopUp.tsx +6 -5
  195. package/src/components/Range.tsx +7 -1
  196. package/src/components/Tabs.tsx +300 -54
  197. package/src/components/TooltipWrapper.tsx +4 -1
  198. package/src/components/calendar/Calendar.tsx +5 -0
  199. package/src/components/calendar/DaysView.tsx +2 -2
  200. package/src/components/icons.tsx +8 -0
  201. package/src/components/index.tsx +2 -0
  202. package/src/icons/cloud-upload.svg +22 -0
  203. package/src/icons/image.svg +1 -0
  204. package/src/icons/refresh.svg +7 -0
  205. package/src/icons/trash.svg +8 -0
  206. package/src/icons/upload.svg +4 -9
  207. package/src/index.tsx +1 -0
  208. package/src/locale/en-US.ts +3 -1
  209. package/src/locale/zh-CN.ts +4 -2
  210. package/src/renderers/Action.tsx +2 -1
  211. package/src/renderers/Breadcrumb.tsx +89 -45
  212. package/src/renderers/ButtonGroup.tsx +2 -2
  213. package/src/renderers/Form/ChainedSelect.tsx +56 -12
  214. package/src/renderers/Form/Checkbox.tsx +30 -1
  215. package/src/renderers/Form/Combo.tsx +84 -26
  216. package/src/renderers/Form/InputCity.tsx +13 -1
  217. package/src/renderers/Form/InputColor.tsx +2 -0
  218. package/src/renderers/Form/InputDate.tsx +2 -0
  219. package/src/renderers/Form/InputDateRange.tsx +2 -0
  220. package/src/renderers/Form/InputExcel.tsx +27 -5
  221. package/src/renderers/Form/InputFile.tsx +167 -115
  222. package/src/renderers/Form/InputImage.tsx +61 -35
  223. package/src/renderers/Form/InputRange.tsx +95 -40
  224. package/src/renderers/Form/InputSubForm.tsx +2 -1
  225. package/src/renderers/Form/InputTag.tsx +3 -1
  226. package/src/renderers/Form/MatrixCheckboxes.tsx +3 -1
  227. package/src/renderers/Form/NestedSelect.tsx +75 -26
  228. package/src/renderers/Form/Options.tsx +3 -1
  229. package/src/renderers/Form/Radios.tsx +3 -1
  230. package/src/renderers/Form/Select.tsx +6 -2
  231. package/src/renderers/Form/Switch.tsx +16 -9
  232. package/src/renderers/Log.tsx +2 -1
  233. package/src/renderers/PopOver.tsx +1 -1
  234. package/src/renderers/Tabs.tsx +254 -93
  235. package/src/renderers/TooltipWrapper.tsx +219 -0
  236. package/src/renderers/Video.tsx +21 -6
  237. package/src/store/form.ts +0 -9
  238. package/src/store/table.ts +1 -1
@@ -8,10 +8,11 @@ import {
8
8
  isDisabled,
9
9
  isObject,
10
10
  createObject,
11
- getVariable
11
+ getVariable,
12
+ isObjectShallowModified
12
13
  } from '../utils/helper';
13
14
  import findIndex from 'lodash/findIndex';
14
- import {Tabs as CTabs, Tab} from '../components/Tabs';
15
+ import {Tabs as CTabs, Tab, TabsMode} from '../components/Tabs';
15
16
  import {ClassNamesFn} from '../theme';
16
17
  import {
17
18
  BaseSchema,
@@ -87,6 +88,14 @@ export interface TabSchema extends Omit<BaseSchema, 'type'> {
87
88
  * 如果是水平排版,这个属性可以细化水平排版的左右宽度占比。
88
89
  */
89
90
  horizontal?: FormSchemaHorizontal;
91
+ /**
92
+ * 是否可关闭,优先级高于 tabs 的 closable
93
+ */
94
+ closable?: boolean;
95
+ /**
96
+ * 是否禁用
97
+ */
98
+ disabled?: boolean;
90
99
  }
91
100
 
92
101
  /**
@@ -114,7 +123,7 @@ export interface TabsSchema extends BaseSchema {
114
123
  /**
115
124
  * 展示形式
116
125
  */
117
- tabsMode?: '' | 'line' | 'card' | 'radio' | 'vertical' | 'tiled';
126
+ tabsMode?: TabsMode;
118
127
 
119
128
  /**
120
129
  * 内容类名
@@ -150,9 +159,41 @@ export interface TabsSchema extends BaseSchema {
150
159
  */
151
160
  subFormHorizontal?: FormSchemaHorizontal;
152
161
  /**
153
- * 是否支持溢出滚动
162
+ * 是否支持新增
163
+ */
164
+ addable?: boolean;
165
+ /**
166
+ * 是否支持删除
167
+ */
168
+ closable?: boolean;
169
+ /**
170
+ * 是否支持拖拽
171
+ */
172
+ draggable?: boolean;
173
+ /**
174
+ * 是否显示提示
175
+ */
176
+ showTip?: boolean;
177
+ /**
178
+ * tooltip 提示的类名
179
+ */
180
+ showTipClassName?: string;
181
+ /**
182
+ * 是否可编辑标签名
183
+ */
184
+ editable?: boolean;
185
+ /**
186
+ * 是否导航支持内容溢出滚动。属性废弃,为了兼容暂且保留
154
187
  */
155
188
  scrollable?: boolean;
189
+ /**
190
+ * 编辑器模式,侧边的位置
191
+ */
192
+ sidePosition?: 'left' | 'right';
193
+ /**
194
+ * 自定义增加按钮文案
195
+ */
196
+ addBtnText?: string;
156
197
  }
157
198
 
158
199
  export interface TabsProps
@@ -163,9 +204,15 @@ export interface TabsProps
163
204
  tabRender?: (tab: TabSchema, props: TabsProps, index: number) => JSX.Element;
164
205
  }
165
206
 
207
+ interface TabSource extends TabSchema {
208
+ ctx?: any;
209
+ }
210
+
166
211
  export interface TabsState {
167
212
  activeKey: any;
168
213
  prevKey: any;
214
+ localTabs: Array<TabSource>;
215
+ isFromSource: boolean;
169
216
  }
170
217
 
171
218
  export type TabsRendererEvent = 'change';
@@ -181,19 +228,20 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
181
228
 
182
229
  renderTab?: (tab: TabSchema, props: TabsProps, index: number) => JSX.Element;
183
230
  activeKey: any;
231
+ newTabDefaultId: number = 3;
184
232
 
185
233
  constructor(props: TabsProps) {
186
234
  super(props);
187
235
 
188
236
  const location = props.location || window.location;
189
- const tabs = props.tabs;
237
+ const {tabs, source, data} = props;
190
238
  let activeKey: any = 0;
191
239
 
192
240
  if (typeof props.activeKey !== 'undefined') {
193
241
  activeKey = props.activeKey;
194
242
  } else if (location && Array.isArray(tabs)) {
195
243
  const hash = location.hash.substring(1);
196
- const tab: TabSchema = find(tabs, tab => tab.hash === hash) as TabSchema;
244
+ const tab: TabSource = find(tabs, tab => tab.hash === hash) as TabSource;
197
245
 
198
246
  if (tab) {
199
247
  activeKey = tab.hash;
@@ -204,17 +252,50 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
204
252
  activeKey = activeKey || (tabs[0] && tabs[0].hash) || 0;
205
253
  }
206
254
 
255
+ const [localTabs, isFromSource] = this.initTabArray(tabs, source, data);
256
+
207
257
  this.state = {
208
258
  prevKey: undefined,
209
- activeKey: (this.activeKey = activeKey)
259
+ activeKey: (this.activeKey = activeKey),
260
+ localTabs,
261
+ isFromSource
210
262
  };
211
263
  }
212
264
 
265
+ // 初始化 tabs 数组,当从 source 获取数据源时
266
+ @autobind
267
+ initTabArray(tabs: Array<TabSource>, source?: string, data?: any): [Array<TabSource>, boolean] {
268
+ if (!tabs) {
269
+ return [[], false];
270
+ }
271
+
272
+ const arr = resolveVariableAndFilter(source, data, '| raw');
273
+ if (!Array.isArray(arr)) {
274
+ return [tabs, false];
275
+ }
276
+
277
+ tabs = Array.isArray(tabs) ? tabs : [tabs];
278
+
279
+ const sourceTabs: Array<TabSource> = [];
280
+ arr.forEach((value, index) => {
281
+ const ctx = createObject(
282
+ data,
283
+ isObject(value) ? {index, ...value} : {item: value, index}
284
+ );
285
+
286
+ sourceTabs.push(...tabs.map((tab: TabSource) => ({...tab, ctx})));
287
+ });
288
+
289
+ return [sourceTabs, true];
290
+ }
291
+
213
292
  componentDidMount() {
214
293
  this.autoJumpToNeighbour(this.activeKey);
215
294
 
216
295
  let {name, value, onChange, source, tabs, data} = this.props;
217
296
 
297
+ const localTabs = this.state.localTabs;
298
+
218
299
  // 如果没有配置 name ,说明不需要同步表单值
219
300
  if (
220
301
  !name ||
@@ -228,7 +309,7 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
228
309
  value = value ?? getVariable(data, name);
229
310
 
230
311
  // 如果有值,切到对应的 tab
231
- if (value && Array.isArray(tabs)) {
312
+ if (value && Array.isArray(localTabs)) {
232
313
  const key = this.resolveKeyByValue(value);
233
314
  key !== undefined && this.handleSelect(key);
234
315
  } else {
@@ -241,17 +322,37 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
241
322
 
242
323
  componentDidUpdate(preProps: TabsProps, prevState: any) {
243
324
  const props = this.props;
325
+ let localTabs = this.state.localTabs;
244
326
 
245
- if (props.location && props.location.hash !== preProps.location.hash) {
327
+ // 响应外部修改 tabs
328
+ const isTabsModified = isObjectShallowModified({
329
+ tabs: props.tabs,
330
+ source: resolveVariableAndFilter(props.source, props.data, '| raw')
331
+ }, {
332
+ tabs: preProps.tabs,
333
+ source: resolveVariableAndFilter(preProps.source, preProps.data, '| raw')
334
+ }, false);
335
+
336
+ if (isTabsModified) {
337
+ const [newLocalTabs, isFromSource] = this.initTabArray(props.tabs, props.source, props.data);
338
+
339
+ this.setState({
340
+ localTabs: newLocalTabs,
341
+ isFromSource
342
+ });
343
+ localTabs = newLocalTabs;
344
+ }
345
+
346
+ if (props.location && preProps.location && props.location.hash !== preProps.location.hash) {
246
347
  const hash = props.location.hash.substring(1);
247
348
  if (!hash) {
248
349
  return;
249
350
  }
250
351
 
251
- const tab: TabSchema = find(
252
- props.tabs,
352
+ const tab: TabSource = find(
353
+ localTabs,
253
354
  tab => tab.hash === hash
254
- ) as TabSchema;
355
+ ) as TabSource;
255
356
  if (tab && tab.hash && tab.hash !== this.state.activeKey) {
256
357
  this.setState({
257
358
  activeKey: (this.activeKey = tab.hash),
@@ -259,29 +360,29 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
259
360
  });
260
361
  }
261
362
  } else if (
262
- Array.isArray(props.tabs) &&
263
- Array.isArray(preProps.tabs) &&
264
- JSON.stringify(props.tabs.map(item => item.hash)) !==
265
- JSON.stringify(preProps.tabs.map(item => item.hash))
363
+ Array.isArray(localTabs) &&
364
+ Array.isArray(prevState.localTabs) &&
365
+ JSON.stringify(localTabs.map(item => item.hash)) !==
366
+ JSON.stringify(prevState.localTabs.map((item: TabSource) => item.hash))
266
367
  ) {
267
368
  let activeKey: any = this.state.activeKey;
268
369
  const location = props.location;
269
- let tab: TabSchema | null = null;
370
+ let tab: TabSource | null = null;
270
371
 
271
- if (location && Array.isArray(props.tabs)) {
372
+ if (location && Array.isArray(localTabs)) {
272
373
  const hash = location.hash.substring(1);
273
- tab = find(props.tabs, tab => tab.hash === hash) as TabSchema;
374
+ tab = find(localTabs, tab => tab.hash === hash) as TabSource;
274
375
  }
275
376
 
276
377
  if (tab) {
277
378
  activeKey = tab.hash;
278
379
  } else if (
279
- !props.tabs ||
280
- !props.tabs.some((item, index) =>
380
+ !localTabs ||
381
+ !localTabs.some((item, index) =>
281
382
  item.hash ? item.hash === activeKey : index === activeKey
282
383
  )
283
384
  ) {
284
- activeKey = (props.tabs && props.tabs[0] && props.tabs[0].hash) || 0;
385
+ activeKey = (localTabs && localTabs[0] && localTabs[0].hash) || 0;
285
386
  }
286
387
 
287
388
  this.setState({
@@ -323,54 +424,55 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
323
424
  }
324
425
 
325
426
  resolveTabByKey(key: any) {
326
- const tabs = this.props.tabs;
427
+ const localTabs = this.state.localTabs;
327
428
 
328
- if (!Array.isArray(tabs)) {
429
+ if (!Array.isArray(localTabs)) {
329
430
  return;
330
431
  }
331
432
 
332
- return find(tabs, (tab: TabSchema, index) =>
433
+ return find(localTabs, (tab: TabSource, index) =>
333
434
  tab.hash ? tab.hash === key : index === key
334
435
  );
335
436
  }
336
437
 
337
438
  resolveKeyByValue(value: any) {
338
- const tabs = this.props.tabs;
439
+ const localTabs = this.state.localTabs;
339
440
 
340
- if (!Array.isArray(tabs)) {
441
+ if (!Array.isArray(localTabs)) {
341
442
  return;
342
443
  }
343
444
 
344
- const tab: TabSchema = find(
345
- tabs,
445
+ const tab: TabSource = find(
446
+ localTabs,
346
447
  tab => ((tab as any).value ?? tab.title) === value
347
- ) as TabSchema;
448
+ ) as TabSource;
348
449
 
349
- return tab && tab.hash ? tab.hash : tabs.indexOf(tab);
450
+ return tab && tab.hash ? tab.hash : localTabs.indexOf(tab);
350
451
  }
351
452
 
352
453
  @autobind
353
454
  autoJumpToNeighbour(key: any) {
354
455
  const {tabs, data} = this.props;
456
+ const localTabs = this.state.localTabs;
355
457
 
356
- if (!Array.isArray(tabs)) {
458
+ if (!Array.isArray(localTabs)) {
357
459
  return;
358
460
  }
359
461
 
360
462
  // 当前 tab 可能不可见,所以需要自动切到一个可见的 tab, 向前找,找一圈
361
- const tabIndex = findIndex(tabs, (tab: TabSchema, index) =>
463
+ const tabIndex = findIndex(localTabs, (tab: TabSource, index) =>
362
464
  tab.hash ? tab.hash === key : index === key
363
465
  );
364
466
 
365
- if (tabs[tabIndex] && !isVisible(tabs[tabIndex], this.props.data)) {
366
- let len = tabs.length;
467
+ if (localTabs[tabIndex] && !isVisible(localTabs[tabIndex], this.props.data)) {
468
+ let len = localTabs.length;
367
469
  let i = tabIndex - 1 + len;
368
470
  let tries = len - 1;
369
471
 
370
472
  while (tries--) {
371
473
  const index = i-- % len;
372
- if (isVisible(tabs[index], data)) {
373
- let activeKey = tabs[index].hash || index;
474
+ if (isVisible(localTabs[index], data)) {
475
+ let activeKey = localTabs[index].hash || index;
374
476
  this.setState({
375
477
  activeKey: (this.activeKey = activeKey)
376
478
  });
@@ -380,6 +482,60 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
380
482
  }
381
483
  }
382
484
 
485
+ @autobind
486
+ handleAdd() {
487
+ const localTabs = this.state.localTabs.concat();
488
+
489
+ localTabs.push({
490
+ title: `新增tab${this.newTabDefaultId++}`,
491
+ body: '新增tab 内容'
492
+ } as TabSource);
493
+
494
+ this.setState({
495
+ localTabs: localTabs
496
+ }, () => {
497
+ this.switchTo(this.state.localTabs.length - 1);
498
+ });
499
+ }
500
+
501
+ @autobind
502
+ handleClose(index: number, key: string | number) {
503
+ const originTabs = this.state.localTabs.concat();
504
+
505
+ originTabs.splice(index, 1);
506
+
507
+ this.setState({
508
+ localTabs: originTabs
509
+ });
510
+ }
511
+
512
+ @autobind
513
+ handleEdit(index: number, text: string) {
514
+ const originTabs = this.state.localTabs.concat();
515
+ originTabs[index].title = text;
516
+
517
+ this.setState({
518
+ localTabs: originTabs
519
+ });
520
+ }
521
+
522
+ @autobind
523
+ async handleDragChange(e: any){
524
+ const activeTab = this.resolveTabByKey(this.activeKey);
525
+ const originTabs: TabSource[] = this.state.localTabs.concat();
526
+
527
+ originTabs.splice(e.newIndex, 0, originTabs.splice(e.oldIndex, 1)[0]);
528
+
529
+ this.setState({
530
+ localTabs: originTabs
531
+ }, () => {
532
+ if (activeTab) {
533
+ const newActiveTabIndex = originTabs.indexOf(activeTab);
534
+ this.switchTo(newActiveTabIndex);
535
+ }
536
+ });
537
+ }
538
+
383
539
  @autobind
384
540
  handleSelect(key: any) {
385
541
  const {env, onSelect, id} = this.props;
@@ -438,21 +594,22 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
438
594
 
439
595
  @autobind
440
596
  switchTo(index: number) {
441
- const {tabs} = this.props;
597
+ const localTabs = this.state.localTabs;
442
598
 
443
- Array.isArray(tabs) &&
444
- tabs[index] &&
599
+ Array.isArray(localTabs) &&
600
+ localTabs[index] &&
445
601
  this.setState({
446
- activeKey: (this.activeKey = tabs[index].hash || index)
602
+ activeKey: (this.activeKey = localTabs[index].hash || index)
447
603
  });
448
604
  }
449
605
 
450
606
  @autobind
451
607
  currentIndex(): number {
452
- const {tabs} = this.props;
608
+ // const {tabs} = this.props;
609
+ const localTabs = this.state.localTabs;
453
610
 
454
- return Array.isArray(tabs)
455
- ? findIndex(tabs, (tab: TabSchema, index) =>
611
+ return Array.isArray(localTabs)
612
+ ? findIndex(localTabs, (tab: TabSource, index) =>
456
613
  tab.hash
457
614
  ? tab.hash === this.state.activeKey
458
615
  : index === this.state.activeKey
@@ -489,11 +646,17 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
489
646
  formHorizontal,
490
647
  subFormMode,
491
648
  subFormHorizontal,
492
- scrollable
649
+ addable,
650
+ closable,
651
+ draggable,
652
+ showTip,
653
+ showTipClassName,
654
+ editable,
655
+ sidePosition,
656
+ addBtnText
493
657
  } = this.props;
494
658
 
495
659
  const mode = tabsMode || dMode;
496
- const arr = resolveVariableAndFilter(source, data, '| raw');
497
660
  let mountOnEnter = this.props.mountOnEnter;
498
661
 
499
662
  // 如果在form下面,其他tabs默认需要渲染出来
@@ -502,54 +665,41 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
502
665
  mountOnEnter = false;
503
666
  }
504
667
 
505
- let tabs = this.props.tabs;
506
- if (!tabs) {
507
- return null;
508
- }
509
-
510
- tabs = Array.isArray(tabs) ? tabs : [tabs];
668
+ const {localTabs: tabs, isFromSource} = this.state;
511
669
  let children: Array<JSX.Element | null> = [];
512
670
 
513
- if (Array.isArray(arr)) {
514
- arr.forEach((value, index) => {
515
- const ctx = createObject(
516
- data,
517
- isObject(value) ? {index, ...value} : {item: value, index}
518
- );
519
-
520
- children.push(
521
- ...tabs.map((tab, tabIndex) =>
522
- isVisible(tab, ctx) ? (
523
- <Tab
524
- {...(tab as any)}
525
- title={filter(tab.title, ctx)}
526
- disabled={isDisabled(tab, ctx)}
527
- key={`${index * 1000 + tabIndex}`}
528
- eventKey={index * 1000 + tabIndex}
529
- mountOnEnter={mountOnEnter}
530
- unmountOnExit={
531
- typeof tab.reload === 'boolean'
532
- ? tab.reload
533
- : typeof tab.unmountOnExit === 'boolean'
534
- ? tab.unmountOnExit
535
- : unmountOnExit
536
- }
537
- >
538
- {render(
539
- `item/${index}/${tabIndex}`,
540
- (tab as any)?.type ? (tab as any) : tab.tab || tab.body,
541
- {
542
- data: ctx,
543
- formMode: tab.mode || subFormMode || formMode,
544
- formHorizontal:
545
- tab.horizontal || subFormHorizontal || formHorizontal
546
- }
547
- )}
548
- </Tab>
549
- ) : null
550
- )
551
- );
552
- });
671
+ // 是否从 source 数据中生成
672
+ if (isFromSource) {
673
+ children = tabs.map((tab: TabSource, index: number) =>
674
+ isVisible(tab, tab.ctx) ? (
675
+ <Tab
676
+ {...(tab as any)}
677
+ title={filter(tab.title, tab.ctx)}
678
+ disabled={isDisabled(tab, tab.ctx)}
679
+ key={index}
680
+ eventKey={index}
681
+ mountOnEnter={mountOnEnter}
682
+ unmountOnExit={
683
+ typeof tab.reload === 'boolean'
684
+ ? tab.reload
685
+ : typeof tab.unmountOnExit === 'boolean'
686
+ ? tab.unmountOnExit
687
+ : unmountOnExit
688
+ }
689
+ >
690
+ {render(
691
+ `item/${index}`,
692
+ (tab as any)?.type ? (tab as any) : tab.tab || tab.body,
693
+ {
694
+ data: tab.ctx,
695
+ formMode: tab.mode || subFormMode || formMode,
696
+ formHorizontal:
697
+ tab.horizontal || subFormHorizontal || formHorizontal
698
+ }
699
+ )}
700
+ </Tab>
701
+ ) : null
702
+ );
553
703
  } else {
554
704
  children = tabs.map((tab, index) =>
555
705
  isVisible(tab, data) ? (
@@ -591,13 +741,24 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
591
741
  classPrefix={ns}
592
742
  classnames={cx}
593
743
  mode={mode}
744
+ closable={closable}
594
745
  className={className}
595
746
  contentClassName={contentClassName}
596
747
  linksClassName={linksClassName}
597
748
  onSelect={this.handleSelect}
598
749
  activeKey={this.state.activeKey}
599
750
  toolbar={this.renderToolbar()}
600
- scrollable={scrollable}
751
+ addable={addable}
752
+ onAdd={this.handleAdd}
753
+ onClose={this.handleClose}
754
+ draggable={draggable}
755
+ onDragChange={this.handleDragChange}
756
+ showTip={showTip}
757
+ showTipClassName={showTipClassName}
758
+ editable={editable}
759
+ onEdit={this.handleEdit}
760
+ sidePosition={sidePosition}
761
+ addBtnText={addBtnText}
601
762
  >
602
763
  {children}
603
764
  </CTabs>