@univerjs/sheets-table 0.7.0 → 0.8.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.
package/lib/facade.js CHANGED
@@ -1,7 +1,9 @@
1
- import { SheetTableService as o, AddSheetTableCommand as g, DeleteSheetTableCommand as u, SetSheetTableFilterCommand as b, TableManager as I } from "@univerjs/sheets-table";
2
- import { FWorkbook as m, FWorksheet as h } from "@univerjs/sheets/facade";
3
- import { LocaleService as S } from "@univerjs/core";
4
- class v extends m {
1
+ import { SheetTableService as o, AddSheetTableCommand as u, DeleteSheetTableCommand as T, SetSheetTableFilterCommand as d, SetSheetTableCommand as c, AddTableThemeCommand as C, TableColumnFilterTypeEnum as f, TableConditionTypeEnum as v, TableNumberCompareTypeEnum as k, TableStringCompareTypeEnum as p, TableDateCompareTypeEnum as _ } from "@univerjs/sheets-table";
2
+ import { FWorkbook as h, FWorksheet as g } from "@univerjs/sheets/facade";
3
+ import { cellToRange as x, Rectangle as y } from "@univerjs/core";
4
+ import { RangeThemeStyle as F } from "@univerjs/sheets";
5
+ import { FEnum as I } from "@univerjs/core/facade";
6
+ class W extends h {
5
7
  getTableInfo(e) {
6
8
  const t = this.getId();
7
9
  return this._injector.get(o).getTableInfo(t, e);
@@ -10,58 +12,137 @@ class v extends m {
10
12
  const e = this.getId();
11
13
  return this._injector.get(o).getTableList(e);
12
14
  }
13
- async addTable(e, t, i, a, d) {
14
- var r;
15
- const n = this._injector.get(o), s = {
15
+ async addTable(e, t, n, i, r) {
16
+ var b;
17
+ const s = this._injector.get(o), a = {
16
18
  unitId: this.getId(),
17
19
  name: t,
18
20
  subUnitId: e,
19
- range: i,
20
- options: d,
21
- tableId: a
21
+ range: n,
22
+ options: r,
23
+ id: i
22
24
  };
23
- if (await this._commandService.executeCommand(g.id, s))
24
- return (r = n.getTableList(this.getId()).find((c) => c.name === t)) == null ? void 0 : r.id;
25
+ if (await this._commandService.executeCommand(u.id, a))
26
+ return (b = s.getTableList(this.getId()).find((S) => S.name === t)) == null ? void 0 : b.id;
25
27
  }
26
28
  async removeTable(e) {
27
- var a;
28
- const t = (a = this.getTableInfo(e)) == null ? void 0 : a.subUnitId;
29
+ var i;
30
+ const t = (i = this.getTableInfo(e)) == null ? void 0 : i.subUnitId;
29
31
  if (!t)
30
32
  return !1;
31
- const i = {
33
+ const n = {
32
34
  unitId: this.getId(),
33
35
  subUnitId: t,
34
36
  tableId: e
35
37
  };
36
- return this._commandService.executeCommand(u.id, i);
38
+ return this._commandService.executeCommand(T.id, n);
37
39
  }
38
40
  getTableInfoByName(e) {
39
- return this.getTableList().find((i) => i.name === e);
41
+ return this.getTableList().find((n) => n.name === e);
40
42
  }
41
- setTableFilter(e, t, i) {
42
- const a = {
43
+ setTableFilter(e, t, n) {
44
+ const i = {
43
45
  unitId: this.getId(),
44
46
  tableId: e,
45
47
  column: t,
46
- tableFilter: i
48
+ tableFilter: n
47
49
  };
48
- return this._commandService.executeCommand(b.id, a);
50
+ return this._commandService.executeCommand(d.id, i);
49
51
  }
50
52
  }
51
- m.extend(v);
52
- class f extends h {
53
- addTable(e, t, i, a) {
54
- const d = this._injector.get(o), n = this.getSheetId(), s = this.getWorkbook().getUnitId(), l = this._injector.get(I), r = this._injector.get(S), c = l.getColumnHeader(s, n, t, r.t("sheets-table.columnPrefix"));
55
- return d.addTable(s, n, e, t, c, i, a);
56
- }
57
- addTableFilter(e, t, i) {
58
- const a = {
53
+ h.extend(W);
54
+ class E extends g {
55
+ addTable(e, t, n, i) {
56
+ const r = this.getSheetId(), a = {
57
+ unitId: this.getWorkbook().getUnitId(),
58
+ subUnitId: r,
59
+ name: e,
60
+ range: t,
61
+ id: n,
62
+ options: i
63
+ };
64
+ return this._commandService.executeCommand(u.id, a);
65
+ }
66
+ setTableFilter(e, t, n) {
67
+ const i = {
59
68
  unitId: this.getWorkbook().getUnitId(),
60
69
  tableId: e,
61
70
  column: t,
62
- tableFilter: i
71
+ tableFilter: n
72
+ };
73
+ return this._commandService.executeCommand(d.id, i);
74
+ }
75
+ removeTable(e) {
76
+ const t = {
77
+ unitId: this._fWorkbook.getId(),
78
+ subUnitId: this.getSheetId(),
79
+ tableId: e
80
+ };
81
+ return this._commandService.executeCommand(T.id, t);
82
+ }
83
+ setTableRange(e, t) {
84
+ const n = {
85
+ unitId: this.getWorkbook().getUnitId(),
86
+ tableId: e,
87
+ updateRange: {
88
+ newRange: t
89
+ }
63
90
  };
64
- return this._commandService.executeCommand(b.id, a);
91
+ return this._commandService.executeCommand(c.id, n);
92
+ }
93
+ setTableName(e, t) {
94
+ const n = {
95
+ unitId: this.getWorkbook().getUnitId(),
96
+ tableId: e,
97
+ name: t
98
+ };
99
+ return this._commandService.executeCommand(c.id, n);
100
+ }
101
+ getSubTableInfos() {
102
+ const e = this._fWorkbook.getId();
103
+ return this._injector.get(o).getTableList(e).filter((n) => n.subUnitId === this.getSheetId());
104
+ }
105
+ resetFilter(e, t) {
106
+ const n = {
107
+ unitId: this._fWorkbook.getId(),
108
+ tableId: e,
109
+ column: t,
110
+ tableFilter: void 0
111
+ };
112
+ return this._commandService.executeCommand(d.id, n);
113
+ }
114
+ getTableByCell(e, t) {
115
+ const n = this._fWorkbook.getId(), r = this._injector.get(o).getTableList(n).filter((a) => a.subUnitId === this.getSheetId()), s = x(e, t);
116
+ return r.find((a) => {
117
+ const l = a.range;
118
+ return y.intersects(l, s);
119
+ });
120
+ }
121
+ addTableTheme(e, t) {
122
+ const n = new F("table-style");
123
+ return n.fromJson(t), this._commandService.executeCommand(C.id, {
124
+ unitId: this._fWorkbook.getId(),
125
+ tableId: e,
126
+ themeStyle: n
127
+ });
128
+ }
129
+ }
130
+ g.extend(E);
131
+ class U extends I {
132
+ get TableColumnFilterTypeEnum() {
133
+ return f;
134
+ }
135
+ get TableConditionTypeEnum() {
136
+ return v;
137
+ }
138
+ get TableNumberCompareTypeEnum() {
139
+ return k;
140
+ }
141
+ get TableStringCompareTypeEnum() {
142
+ return p;
143
+ }
144
+ get TableDateCompareTypeEnum() {
145
+ return _;
65
146
  }
66
147
  }
67
- h.extend(f);
148
+ I.extend(U);
package/lib/index.js CHANGED
@@ -1530,8 +1530,8 @@ let W = class extends k {
1530
1530
  if (d) {
1531
1531
  const c = d.getRange(), m = a - c.startColumn;
1532
1532
  if (c.startRow === s) {
1533
- const w = d.getColumnNameByIndex(m), f = { ...e, v: w };
1534
- return r(f);
1533
+ const w = d.getColumnNameByIndex(m);
1534
+ return (!e || e === n.rawData) && (e = { ...n.rawData }), e.v = w, r(e);
1535
1535
  }
1536
1536
  }
1537
1537
  }
@@ -0,0 +1,23 @@
1
+ import { FEnum } from '@univerjs/core/facade';
2
+ import { TableColumnFilterTypeEnum, TableConditionTypeEnum, TableDateCompareTypeEnum, TableNumberCompareTypeEnum, TableStringCompareTypeEnum } from '@univerjs/sheets-table';
3
+ /**
4
+ * @ignore
5
+ */
6
+ export interface ITableEnumMixin {
7
+ TableColumnFilterTypeEnum: typeof TableColumnFilterTypeEnum;
8
+ TableConditionTypeEnum: typeof TableConditionTypeEnum;
9
+ TableNumberCompareTypeEnum: typeof TableNumberCompareTypeEnum;
10
+ TableStringCompareTypeEnum: typeof TableStringCompareTypeEnum;
11
+ TableDateCompareTypeEnum: typeof TableDateCompareTypeEnum;
12
+ }
13
+ export declare class TableEnum extends FEnum implements ITableEnumMixin {
14
+ get TableColumnFilterTypeEnum(): typeof TableColumnFilterTypeEnum;
15
+ get TableConditionTypeEnum(): typeof TableConditionTypeEnum;
16
+ get TableNumberCompareTypeEnum(): typeof TableNumberCompareTypeEnum;
17
+ get TableStringCompareTypeEnum(): typeof TableStringCompareTypeEnum;
18
+ get TableDateCompareTypeEnum(): typeof TableDateCompareTypeEnum;
19
+ }
20
+ declare module '@univerjs/core/facade' {
21
+ interface FEnum extends ITableEnumMixin {
22
+ }
23
+ }
@@ -11,21 +11,52 @@ export interface IFWorkbookSheetsTableMixin {
11
11
  * @example
12
12
  * ```typescript
13
13
  * const fWorkbook = univerAPI.getActiveWorkbook();
14
- * const fSheet = fWorkbook.getActiveSheet();
15
- * const id = fWorkbook.addTable('Table1', {
16
- * unitId: fWorkbook.getId(),
17
- * subUnitId:fSheet.getSheetId(),
18
- * range: {
19
- * startRow: 1,
20
- * startColumn: 1,
21
- * endRow: 10,
22
- * endColumn: 5,
23
- * },
24
- * }, { showHeader: true });
25
- * const tableInfo = fWorkbook.getTableInfo(fWorkbook.getId(), id);
14
+ * const fWorksheet = fWorkbook.getActiveSheet();
15
+ *
16
+ * // Insert a table in the range B2:F11
17
+ * const fRange = fWorksheet.getRange('B2:F11');
18
+ * const success = await fWorksheet.addTable(
19
+ * 'name-1',
20
+ * fRange.getRange(),
21
+ * 'id-1',
22
+ * {
23
+ * showHeader: true,
24
+ * }
25
+ * );
26
+ *
27
+ * if (success) {
28
+ * const tableInfo = fWorkbook.getTableInfo('id-1');
29
+ * console.log('debugger tableInfo', tableInfo);
30
+ * }
26
31
  * ```
27
32
  */
28
33
  getTableInfo(tableId: string): ITableInfoWithUnitId | undefined;
34
+ /**
35
+ * Get table information by name
36
+ * @param {string} tableName The table name
37
+ * @returns {ITableInfo} The table information
38
+ * @example
39
+ * ```typescript
40
+ * const fWorkbook = univerAPI.getActiveWorkbook();
41
+ * const fWorksheet = fWorkbook.getActiveSheet();
42
+ *
43
+ * // Insert a table in the range B2:F11
44
+ * const fRange = fWorksheet.getRange('B2:F11');
45
+ * const success = await fWorksheet.addTable(
46
+ * 'name-1',
47
+ * fRange.getRange(),
48
+ * 'id-1',
49
+ * {
50
+ * showHeader: true,
51
+ * }
52
+ * );
53
+ *
54
+ * if (success) {
55
+ * const tableInfo = fWorkbook.getTableInfoByName('name-1');
56
+ * console.log('debugger tableInfo', tableInfo);
57
+ * }
58
+ * ```
59
+ */
29
60
  getTableInfoByName(tableName: string): ITableInfoWithUnitId | undefined;
30
61
  /**
31
62
  * Get table list
@@ -33,45 +64,98 @@ export interface IFWorkbookSheetsTableMixin {
33
64
  * @example
34
65
  * ```typescript
35
66
  * const fWorkbook = univerAPI.getActiveWorkbook();
36
- * const fSheet = fWorkbook.getActiveSheet();
37
- * const id = fWorkbook.addTable('Table1', {
38
- * unitId: fWorkbook.getId(),
39
- * subUnitId:fSheet.getSheetId(),
40
- * range: {
41
- * startRow: 1,
42
- * startColumn: 1,
43
- * endRow: 10,
44
- * endColumn: 5,
45
- * },
46
- * }, { showHeader: true });
47
- * const tableList = fWorkbook.getTableList(fWorkbook.getId());
67
+ * const tables = fWorkbook.getTableList();
68
+ * console.log('debugger tables', tables);
48
69
  * ```
49
70
  */
50
71
  getTableList(): ITableInfo[];
51
72
  /**
52
73
  * Add table
74
+ * @param {string} subUnitId The sub unit id
53
75
  * @param {string} tableName The table name
54
76
  * @param {ITableRange} rangeInfo The table range information
55
- * @param {ITableOptions} options The table options
77
+ * @param {string} [tableId] The table id
78
+ * @param {ITableOptions} [options] The table options
56
79
  * @returns {string} The table id
57
80
  * @example
58
81
  * ```typescript
59
82
  * const fWorkbook = univerAPI.getActiveWorkbook();
60
- * const fSheet = fWorkbook.getActiveSheet();
61
- * const id = fWorkbook.addTable('Table1', {
62
- * unitId: fWorkbook.getId(),
63
- * subUnitId:fSheet.getSheetId(),
64
- * range: {
65
- * startRow: 1,
66
- * startColumn: 1,
67
- * endRow: 10,
68
- * endColumn: 5,
69
- * },
70
- * }, 'table1' ,{ showHeader: true });
83
+ * const fWorksheet = fWorkbook.getActiveSheet();
84
+ *
85
+ * // Insert a table in the range B2:F11
86
+ * const fRange = fWorksheet.getRange('B2:F11');
87
+ * const id = await fWorkbook.addTable(
88
+ * fWorksheet.getSheetId(),
89
+ * 'name-1',
90
+ * fRange.getRange(),
91
+ * 'id-1',
92
+ * {
93
+ * showHeader: true,
94
+ * }
95
+ * );
96
+ *
97
+ * if (id) {
98
+ * const tableInfo = fWorkbook.getTableInfo(id);
99
+ * console.log('debugger tableInfo', tableInfo);
100
+ * }
71
101
  * ```
72
102
  */
73
103
  addTable(subUnitId: string, tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise<string | undefined>;
104
+ /**
105
+ * set table filter
106
+ * @param {string} tableId The table id
107
+ * @param {number} column The column index, starting from 0.
108
+ * @param {ITableFilterItem} filter The filter item
109
+ * @returns {Promise<boolean>} The result of set table filter
110
+ * @example
111
+ * ```typescript
112
+ * const fWorkbook = univerAPI.getActiveWorkbook();
113
+ * const fWorksheet = fWorkbook.getActiveSheet();
114
+ *
115
+ * // Insert a table in the range B2:F11
116
+ * const fRange = fWorksheet.getRange('B2:F11');
117
+ * const success = await fWorksheet.addTable(
118
+ * 'name-1',
119
+ * fRange.getRange(),
120
+ * 'id-1',
121
+ * {
122
+ * showHeader: true,
123
+ * }
124
+ * );
125
+ *
126
+ * if (success) {
127
+ * // Set the filter for the second column
128
+ * await fWorkbook.setTableFilter('id-1', 1, {
129
+ * filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,
130
+ * filterInfo: {
131
+ * conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,
132
+ * compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,
133
+ * expectedValue: 10,
134
+ * },
135
+ * });
136
+ *
137
+ * const tableInfo = fWorkbook.getTableInfo('id-1');
138
+ * console.log('debugger tableInfo', tableInfo);
139
+ * }
140
+ * ```
141
+ */
74
142
  setTableFilter(tableId: string, column: number, filter: ITableFilterItem | undefined): void;
143
+ /**
144
+ * Remove table
145
+ * @param {string} tableId The table id
146
+ * @returns {boolean} The result of remove table
147
+ * @example
148
+ * ```typescript
149
+ * const fWorkbook = univerAPI.getActiveWorkbook();
150
+ * const tableInfo = fWorkbook.getTableInfo('id-1');
151
+ * console.log('debugger tableInfo', tableInfo);
152
+ *
153
+ * if (tableInfo) {
154
+ * // Remove the table with the specified id
155
+ * await fWorkbook.removeTable('id-1');
156
+ * }
157
+ * ```
158
+ */
75
159
  removeTable(tableId: string): Promise<boolean>;
76
160
  }
77
161
  export declare class FWorkbookSheetsTableMixin extends FWorkbook implements IFWorkbookSheetsTableMixin {