@king-design/intact 3.3.3 → 3.4.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ import ScrollToRowDemo from '~/components/table/demos/scrollToRow';
15
15
  import {mount, unmount, dispatchEvent, getElement, wait} from '../../test/utils';
16
16
  import {Component} from 'intact';
17
17
  import {Table, TableColumn} from './';
18
+ import { bind } from '../utils';
18
19
  import DraggableTable from '~/components/table/demos/draggable';
19
20
  import MergeCellDemo from '~/components/table/demos/mergeCell';
20
21
  import {Dropdown, DropdownMenu, DropdownItem} from '../dropdown';
@@ -186,6 +187,68 @@ describe('Table', () => {
186
187
  expect(table2.outerHTML).to.matchSnapshot();
187
188
  });
188
189
 
190
+ it('append a row in merged table', async () => {
191
+ let uniqueId = 0;
192
+ class Demo extends Component<{data: any[]}> {
193
+ static template = `
194
+ const {Table, TableColumn} = this;
195
+ const { data } = this.get();
196
+ <Table data={data} merge={this.merge} rowKey={data => data.uniqueId} animation={false}>
197
+ <TableColumn title="名称" key="Name" />
198
+ <TableColumn title="头衔" key="Title" />
199
+ <TableColumn title="uniqueId" key="uniqueId" />
200
+ </Table>
201
+ `
202
+
203
+ private Table = Table;
204
+ private TableColumn = TableColumn;
205
+
206
+ static defaults() {
207
+ return {
208
+ data: [
209
+ {
210
+ Name: '刘备',
211
+ Title: '大哥',
212
+ uniqueId: 0,
213
+ },
214
+ ]
215
+ }
216
+ }
217
+
218
+ @bind
219
+ merge(row: any, column: any, rowIndex: number, columnIndex: number) {
220
+ const { data } = this.get();
221
+ for (let i = 0; i < data.length; i++) {
222
+ const mergeIndex = data.findIndex((item: any, index: number) => {
223
+ return index > i && item.Name !== data[i]?.Name;
224
+ });
225
+ const allSame = data.every((item: any, index: number) => {
226
+ if (index > i) {
227
+ return item.Name === data[i].Name;
228
+ }
229
+ return true;
230
+ });
231
+ if ([0, 1, 2].includes(columnIndex) && rowIndex === i) {
232
+ if (mergeIndex === -1 && allSame) {
233
+ return { rowspan: data.length - i };
234
+ }
235
+ if (mergeIndex > -1) {
236
+ return { rowspan: mergeIndex - i };
237
+ }
238
+ }
239
+ }
240
+ }
241
+ }
242
+
243
+ const [instance, element] = mount(Demo);
244
+
245
+ const { data } = instance.get();
246
+ instance.set('data', [...data, { ...data[data.length - 1], uniqueId: ++uniqueId }]);
247
+
248
+ await wait();
249
+ expect(element.innerHTML).to.matchSnapshot();
250
+ });
251
+
189
252
  it('sort', async () => {
190
253
  const [instance, element] = mount(SortDemo);
191
254
 
@@ -210,7 +210,8 @@ export function useChecked(
210
210
  instance.trigger(isChecked ? 'checkRow' : 'uncheckRow', data.value![rowIndex], rowIndex, key);
211
211
  }
212
212
 
213
- instance.on('$receive:children', updateAllCheckedStatus);
213
+ // instance.on('$receive:children', updateAllCheckedStatus);
214
+ useReceive(['children'], updateAllCheckedStatus);
214
215
  instance.on('$change:checkedKeys', updateAllCheckedStatus);
215
216
  // for draggable
216
217
  watchState(data, updateAllCheckedStatus);
@@ -2,6 +2,7 @@ import {useInstance} from 'intact';
2
2
  import type {Table, TableRowKey, TableCheckType} from './table';
3
3
  import type {useTree} from './useTree';
4
4
  import { State, watchState } from '../../hooks/useState';
5
+ import { useReceive } from '../../hooks/useReceive';
5
6
 
6
7
  export function useDisableRow(
7
8
  loopData: ReturnType<typeof useTree>['loopData'],
@@ -48,7 +49,8 @@ export function useDisableRow(
48
49
  return allKeys;
49
50
  }
50
51
 
51
- instance.on('$receive:children', setDisabledKeys);
52
+ // instance.on('$receive:children', setDisabledKeys);
53
+ useReceive(['children'], setDisabledKeys);
52
54
  watchState(data, setDisabledKeys);
53
55
 
54
56
  return {isDisabled, getEnableKeys, isDisabledKey, getAllKeys};
@@ -2,6 +2,7 @@ import {useInstance, Props} from 'intact';
2
2
  import type {Table, TableRowKey, TableCheckType} from './table';
3
3
  import type {TableColumnProps} from './column';
4
4
  import { State, watchState } from '../../hooks/useState';
5
+ import { useReceive } from '../../hooks/useReceive';
5
6
 
6
7
  export type TableMerge<T = any, CheckType = 'checkbox'> = (
7
8
  row: T,
@@ -100,7 +101,11 @@ export function useMerge(
100
101
  return grid;
101
102
  }
102
103
 
103
- instance.on('$receive:children', handleSpans);
104
+ /**
105
+ * https://github.com/ksc-fe/kpc/issues/1008
106
+ */
107
+ // instance.on('$receive:children', handleSpans);
108
+ useReceive(['children'], handleSpans);
104
109
  watchState(data, handleSpans);
105
110
 
106
111
  return {getGrid};