stk-table-vue 0.8.2 → 0.8.3

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.
@@ -347,7 +347,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
347
347
  * en: Set expanded rows
348
348
  * @see {@link setRowExpand}
349
349
  */
350
- setRowExpand: (rowKeyOrRow: string | undefined | PrivateRowDT, expand?: boolean, data?: {
350
+ setRowExpand: (rowKeyOrRow: string | undefined | PrivateRowDT, expand?: boolean | null, data?: {
351
351
  col?: StkTableColumn<PrivateRowDT>;
352
352
  silent?: boolean;
353
353
  }) => void;
@@ -9,7 +9,7 @@ type Option<DT extends Record<string, any>> = {
9
9
  };
10
10
  export declare function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>): {
11
11
  toggleExpandRow: (row: DT, col: StkTableColumn<DT>) => void;
12
- setRowExpand: (rowKeyOrRow: string | undefined | DT, expand?: boolean, data?: {
12
+ setRowExpand: (rowKeyOrRow: string | undefined | DT, expand?: boolean | null, data?: {
13
13
  col?: StkTableColumn<DT>;
14
14
  silent?: boolean;
15
15
  }) => void;
@@ -854,8 +854,12 @@ function useKeyboardArrowScroll(targetElement, { props, scrollTo, virtualScroll,
854
854
  }
855
855
  }
856
856
  function useRowExpand({ dataSourceCopy, rowKeyGen, emits }) {
857
+ const expandedKey = "__EXPANDED__";
858
+ function isExpanded(row, col) {
859
+ return (row == null ? void 0 : row[expandedKey]) === col ? !(row == null ? void 0 : row[expandedKey]) : true;
860
+ }
857
861
  function toggleExpandRow(row, col) {
858
- const isExpand = (row == null ? void 0 : row.__EXPANDED__) === col ? !(row == null ? void 0 : row.__EXPANDED__) : true;
862
+ const isExpand = isExpanded(row, col);
859
863
  setRowExpand(row, isExpand, { col });
860
864
  }
861
865
  function setRowExpand(rowKeyOrRow, expand, data) {
@@ -883,6 +887,9 @@ function useRowExpand({ dataSourceCopy, rowKeyGen, emits }) {
883
887
  }
884
888
  const row = tempData[index];
885
889
  const col = (data == null ? void 0 : data.col) || null;
890
+ if (expand == null) {
891
+ expand = isExpanded(row, col);
892
+ }
886
893
  if (expand) {
887
894
  const newExpandRow = {
888
895
  __ROW_KEY__: EXPANDED_ROW_KEY_PREFIX + rowKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stk-table-vue",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Simple realtime virtual table for vue3 and vue2.7",
5
5
  "main": "./lib/stk-table-vue.js",
6
6
  "types": "./lib/src/StkTable/index.d.ts",
@@ -9,26 +9,32 @@ type Option<DT extends Record<string, any>> = {
9
9
  };
10
10
 
11
11
  export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
12
+ const expandedKey = '__EXPANDED__';
13
+
14
+ function isExpanded(row: DT, col?: StkTableColumn<DT> | null) {
15
+ return row?.[expandedKey] === col ? !row?.[expandedKey] : true;
16
+ }
12
17
  /** click expended icon to toggle expand row */
13
18
  function toggleExpandRow(row: DT, col: StkTableColumn<DT>) {
14
- const isExpand = row?.__EXPANDED__ === col ? !row?.__EXPANDED__ : true;
19
+ const isExpand = isExpanded(row, col);
15
20
  setRowExpand(row, isExpand, { col });
16
21
  }
17
22
 
18
23
  /**
19
24
  *
20
25
  * @param rowKeyOrRow rowKey or row
21
- * @param expand expand or collapse
26
+ * @param expand expand or collapse, if set null, toggle expand
22
27
  * @param data { col?: StkTableColumn<DT> }
23
28
  * @param data.silent if set true, not emit `toggle-row-expand`, default:false
24
29
  */
25
- function setRowExpand(rowKeyOrRow: string | undefined | DT, expand?: boolean, data?: { col?: StkTableColumn<DT>; silent?: boolean }) {
30
+ function setRowExpand(rowKeyOrRow: string | undefined | DT, expand?: boolean | null, data?: { col?: StkTableColumn<DT>; silent?: boolean }) {
26
31
  let rowKey: UniqKey;
27
32
  if (typeof rowKeyOrRow === 'string') {
28
33
  rowKey = rowKeyOrRow;
29
34
  } else {
30
35
  rowKey = rowKeyGen(rowKeyOrRow);
31
36
  }
37
+
32
38
  const tempData = dataSourceCopy.value.slice();
33
39
  const index = tempData.findIndex(it => rowKeyGen(it) === rowKey);
34
40
  if (index === -1) {
@@ -51,6 +57,10 @@ export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
51
57
  const row = tempData[index];
52
58
  const col = data?.col || null;
53
59
 
60
+ if (expand == null) {
61
+ expand = isExpanded(row, col);
62
+ }
63
+
54
64
  if (expand) {
55
65
  // insert new expanded row
56
66
  const newExpandRow: ExpandedRow = {