Skip to content

Commit dca8897

Browse files
committed
v2.5.1
1 parent e528e35 commit dca8897

21 files changed

Lines changed: 1179 additions & 1109 deletions

locales/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@svar-ui/grid-locales",
3-
"version": "2.5.0",
3+
"version": "2.5.1",
44
"description": "Locales for SVAR DataGrid widget",
55
"type": "module",
66
"main": "index.js",

provider/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@svar-ui/grid-data-provider",
3-
"version": "2.5.0",
3+
"version": "2.5.1",
44
"type": "module",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

site/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@svar-ui/site-svelte-grid",
3-
"version": "2.5.0",
3+
"version": "2.5.1",
44
"type": "module",
55
"scripts": {
66
"build": "vite build",
@@ -9,7 +9,7 @@
99
},
1010
"license": "MIT",
1111
"dependencies": {
12-
"@svar-ui/svelte-grid": "2.5.0",
13-
"@svar-ui/svelte-core": "2.4.0"
12+
"@svar-ui/svelte-grid": "2.5.1",
13+
"@svar-ui/svelte-core": "2.4.1"
1414
}
1515
}

store/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@svar-ui/grid-store",
3-
"version": "2.5.0",
3+
"version": "2.5.1",
44
"type": "module",
55
"main": "dist/index.js",
66
"module": "dist/index.js",
@@ -19,6 +19,6 @@
1919
],
2020
"dependencies": {
2121
"@svar-ui/lib-state": "1.9.6",
22-
"@svar-ui/lib-dom": "0.11.1"
22+
"@svar-ui/lib-dom": "0.12.0"
2323
}
2424
}

store/src/DataStore.ts

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { getFilterHandler } from "./filters";
3737
export default class DataStore extends Store<IData> {
3838
public in: EventBus<TMethodsConfig, keyof TMethodsConfig>;
3939
private _router: DataRouter<IData, IDataConfig, TMethodsConfig>;
40-
private _branches: { [key: TID]: IRow };
40+
private _branches: Record<string | number, IRow>;
4141
private _xlsxWorker: any;
4242
private _historyManager: HistoryManager;
4343

@@ -234,7 +234,7 @@ export default class DataStore extends Store<IData> {
234234
if (this.isSelected(id)) {
235235
update.selectedRows = selectedRows.filter(a => a !== id);
236236
}
237-
if (editor?.id == id) {
237+
if (editor?.id === id) {
238238
update.editor = null;
239239
}
240240

@@ -263,7 +263,7 @@ export default class DataStore extends Store<IData> {
263263
data = update;
264264
}
265265
} else {
266-
const index = data.findIndex(a => a.id == id);
266+
const index = data.findIndex(a => a.id === id);
267267
const obj = { ...data[index] };
268268
setValue(obj, col, value);
269269

@@ -276,7 +276,7 @@ export default class DataStore extends Store<IData> {
276276
let { data } = this.getState();
277277
const { id, row } = ev;
278278

279-
const index = data.findIndex(a => a.id == id);
279+
const index = data.findIndex(a => a.id === id);
280280
data = [...data];
281281
data[index] = { ...data[index], ...row };
282282
this.setState({ data });
@@ -301,14 +301,13 @@ export default class DataStore extends Store<IData> {
301301
const { data } = this.getState();
302302

303303
let sindex = data.findIndex(
304-
a => a.id == selectedRows[selectedRows.length - 1]
304+
a => a.id === selectedRows[selectedRows.length - 1]
305305
);
306-
let eindex = data.findIndex(a => a.id == id);
306+
let eindex = data.findIndex(a => a.id === id);
307307
if (sindex > eindex) [sindex, eindex] = [eindex, sindex];
308308

309309
data.slice(sindex, eindex + 1).forEach(a => {
310-
if (selectedRows.indexOf(a.id) === -1)
311-
selectedRows.push(a.id);
310+
if (!this.isSelected(a.id)) selectedRows.push(a.id);
312311
});
313312
} else if (toggle && this.isSelected(id)) {
314313
if (mode === true) return;
@@ -337,10 +336,10 @@ export default class DataStore extends Store<IData> {
337336
if (eventSource !== "click") {
338337
if (
339338
(!split.left ||
340-
_columns.findIndex(a => a.id == ev.column) >=
339+
_columns.findIndex(a => a.id === ev.column) >=
341340
split.left) &&
342341
(!split.right ||
343-
_columns.findIndex(a => a.id == ev.column) <
342+
_columns.findIndex(a => a.id === ev.column) <
344343
_columns.length - split.right)
345344
) {
346345
this.in.exec("scroll", { row, column });
@@ -356,10 +355,10 @@ export default class DataStore extends Store<IData> {
356355
}
357356
let width = ev.width || 0;
358357
const columns = [...this.getState().columns];
359-
const column = columns.find(a => a.id == id);
358+
const column = this.getColumn(id);
360359

361360
if (auto) {
362-
if (auto == "data" || auto === true) {
361+
if (auto === "data" || auto === true) {
363362
const { flatData, _skin } = this.getState();
364363
let max = flatData.length;
365364

@@ -369,7 +368,7 @@ export default class DataStore extends Store<IData> {
369368
width = getColumnWidth(column, curData, _skin);
370369
}
371370

372-
if (auto == "header" || auto === true) {
371+
if (auto === "header" || auto === true) {
373372
const { _skin } = this.getState();
374373

375374
width = Math.max(getHeaderColWidth(column, _skin), width);
@@ -383,7 +382,7 @@ export default class DataStore extends Store<IData> {
383382
inBus.on("hide-column", (ev: IDataMethodsConfig["hide-column"]) => {
384383
const { id, mode } = ev;
385384
const columns = [...this.getState().columns];
386-
const column = columns.find(a => a.id == id);
385+
const column = this.getColumn(id);
387386
const visibleColumns = columns.reduce(
388387
(p, v) => p + (v.hidden ? 0 : 1),
389388
0
@@ -506,7 +505,7 @@ export default class DataStore extends Store<IData> {
506505
let { target, mode = "after" } = ev;
507506
const { data, flatData, tree } = this.getState();
508507

509-
const sourceIndex = flatData.findIndex(a => a.id == id);
508+
const sourceIndex = flatData.findIndex(a => a.id === id);
510509
let targetIndex;
511510

512511
if (mode === "up" || mode === "down") {
@@ -524,7 +523,7 @@ export default class DataStore extends Store<IData> {
524523

525524
target = flatData[targetIndex] && flatData[targetIndex].id;
526525
} else {
527-
targetIndex = flatData.findIndex(a => a.id == target);
526+
targetIndex = flatData.findIndex(a => a.id === target);
528527
}
529528

530529
if (
@@ -560,7 +559,7 @@ export default class DataStore extends Store<IData> {
560559
const copiedRow: IRow = { ...sourceRow, id: uid() };
561560
ev.id = copiedRow.id;
562561

563-
const targetIndex = flatData.findIndex(a => a.id == target);
562+
const targetIndex = flatData.findIndex(a => a.id === target);
564563
if (targetIndex === -1) return;
565564

566565
data.splice(targetIndex + (mode === "after" ? 1 : 0), 0, copiedRow);
@@ -588,7 +587,7 @@ export default class DataStore extends Store<IData> {
588587

589588
const filename = `${ev.fileName || "data"}.${format}`;
590589

591-
if (format == "csv") {
590+
if (format === "csv") {
592591
const csv = getCsvData(this.getState(), ev.csv || {});
593592
if (ev.download !== false)
594593
download(
@@ -912,7 +911,7 @@ export default class DataStore extends Store<IData> {
912911
height = 0;
913912
if (ev.column) {
914913
left = 0;
915-
const ind = _columns.findIndex(a => a.id == ev.column);
914+
const ind = _columns.findIndex(a => a.id === ev.column);
916915
width = _columns[ind].width;
917916
for (let i = split.left ?? 0; i < ind; i++) {
918917
const col = _columns[i];
@@ -921,7 +920,7 @@ export default class DataStore extends Store<IData> {
921920
}
922921
}
923922
if (ev.row && !dynamic) {
924-
const index = data.findIndex(a => a.id == ev.row);
923+
const index = data.findIndex(a => a.id === ev.row);
925924
if (index >= 0) {
926925
if (_rowHeightFromData) {
927926
top = data
@@ -1012,7 +1011,6 @@ export default class DataStore extends Store<IData> {
10121011
// perform these changes only if data was reset
10131012
if (!isSame(this.getState().data, state.data)) {
10141013
if (state.tree) {
1015-
this._branches = { 0: { data: state.data } };
10161014
state.data = this.normalizeTreeRows(state.data);
10171015
} else state.data = this.normalizeRows(state.data);
10181016

@@ -1057,12 +1055,12 @@ export default class DataStore extends Store<IData> {
10571055
getRow(id: TID): IRow {
10581056
const { tree } = this.getState();
10591057
if (tree) return this._branches[id];
1060-
return this.getState().data.find(a => a.id == id);
1058+
return this.getState().data.find(a => a.id === id);
10611059
}
10621060

10631061
getRowIndex(id: TID, data?: any[]): number {
10641062
if (!data) data = this.getState().flatData;
1065-
return data.findIndex(a => a.id == id);
1063+
return data.findIndex(a => a.id === id);
10661064
}
10671065

10681066
getNextRow(id: TID): IRow {
@@ -1078,12 +1076,12 @@ export default class DataStore extends Store<IData> {
10781076
}
10791077

10801078
getColumn(id: TID): IColumn {
1081-
return this.getState().columns.find(a => a.id == id);
1079+
return this.getState().columns.find(a => a.id === id);
10821080
}
10831081

10841082
getNextColumn(id: TID, visible?: boolean): IRenderColumn {
10851083
const columns = this.getState()._columns;
1086-
const index = columns.findIndex((c: IRenderColumn) => c.id == id);
1084+
const index = columns.findIndex((c: IRenderColumn) => c.id === id);
10871085

10881086
if (visible) {
10891087
return this._getFirstVisibleColumn(index + 1);
@@ -1094,7 +1092,7 @@ export default class DataStore extends Store<IData> {
10941092

10951093
getPrevColumn(id: TID, visible?: boolean): IRenderColumn {
10961094
const columns = this.getState()._columns;
1097-
const index = columns.findIndex((c: IRenderColumn) => c.id == id);
1095+
const index = columns.findIndex((c: IRenderColumn) => c.id === id);
10981096

10991097
if (visible) {
11001098
return this._getLastVisibleColumn(index - 1);
@@ -1142,7 +1140,7 @@ export default class DataStore extends Store<IData> {
11421140
getNextEditor(row: IRow, column?: IColumn): IColumn {
11431141
let columns = this.getState().columns;
11441142
if (column) {
1145-
const index = columns.findIndex(c => c.id == column.id);
1143+
const index = columns.findIndex(c => c.id === column.id);
11461144
columns = columns.slice(index + 1);
11471145
}
11481146
return columns.find(c => this.isCellEditable(row, c));
@@ -1151,7 +1149,7 @@ export default class DataStore extends Store<IData> {
11511149
getPrevEditor(row: IRow, column?: IColumn): IColumn {
11521150
let columns = this.getState().columns;
11531151
if (column) {
1154-
const index = columns.findLastIndex(c => c.id == column.id);
1152+
const index = columns.findLastIndex(c => c.id === column.id);
11551153
columns = columns.slice(0, index);
11561154
}
11571155
return columns.findLast(c => this.isCellEditable(row, c));
@@ -1197,21 +1195,21 @@ export default class DataStore extends Store<IData> {
11971195
this._branches[id] = item;
11981196

11991197
const parentRow = this._branches[item.$parent];
1200-
const parentIndex = parentRow.data.findIndex((a: IRow) => a.id == id);
1198+
const parentIndex = parentRow.data.findIndex((a: IRow) => a.id === id);
12011199

12021200
parentRow.data = [...parentRow.data];
12031201
parentRow.data[parentIndex] = item;
12041202

12051203
return parentRow.data;
12061204
}
12071205

1208-
private isSelected(id: TID): boolean {
1206+
isSelected(id: TID): boolean {
12091207
return this.getState().selectedRows.indexOf(id) !== -1;
12101208
}
12111209

12121210
private findAndRemove(items: any[], id: TID): any {
12131211
for (let i = 0; i < items.length; i++) {
1214-
if (items[i].id == id) {
1212+
if (items[i].id === id) {
12151213
return items.splice(i, 1)[0];
12161214
}
12171215
if (items[i].data) {
@@ -1236,7 +1234,7 @@ export default class DataStore extends Store<IData> {
12361234
mode: IDataMethodsConfig["move-item"]["mode"]
12371235
): boolean {
12381236
for (let i = 0; i < items.length; i++) {
1239-
if (items[i].id == targetId) {
1237+
if (items[i].id === targetId) {
12401238
const targetItem = items[i];
12411239
const insertIndex = mode === "before" ? i : i + 1;
12421240

@@ -1457,6 +1455,7 @@ export default class DataStore extends Store<IData> {
14571455
}
14581456

14591457
normalizeTreeRows(data: IRow[], level?: number, parent?: TID): IRow[] {
1458+
if (!level && !parent) this._branches = { 0: { data } };
14601459
data.forEach(row => {
14611460
if (!row.id) row.id = uid();
14621461

@@ -1516,17 +1515,17 @@ export default class DataStore extends Store<IData> {
15161515
const filters: ((obj: any) => boolean)[] = [];
15171516

15181517
for (const field in filterValues) {
1519-
const { config, type } = columns
1520-
.find(c => c.id == field)
1521-
.header.find(h => h.filter).filter;
1518+
const column = columns.find(c => c.id == field); // the non-strict comparison, since field is always a string
1519+
const { config, type } = column.header.find(h => h.filter).filter;
15221520
const value = filterValues[field];
15231521

15241522
filters.push((obj: any) => {
1523+
const oValue = getValue(obj, column);
15251524
if (config?.handler) {
1526-
return config.handler(obj[field], value);
1525+
return config.handler(oValue, value);
15271526
}
15281527

1529-
return getFilterHandler(type)(obj[field], value);
1528+
return getFilterHandler(type)(oValue, value);
15301529
});
15311530
}
15321531

@@ -1540,7 +1539,7 @@ export default class DataStore extends Store<IData> {
15401539
};
15411540
}
15421541

1543-
searchRows(search: string, columns?: { [key: TID]: boolean }) {
1542+
searchRows(search: string, columns?: Record<string | number, boolean>) {
15441543
search = search.trim().toLowerCase();
15451544
const rows: ISearchValue["rows"] = {};
15461545

@@ -1553,7 +1552,7 @@ export default class DataStore extends Store<IData> {
15531552
: allColumns;
15541553

15551554
flatData.forEach(row => {
1556-
const columnsMatches: { [key: TID]: boolean } = {};
1555+
const columnsMatches: Record<string | number, boolean> = {};
15571556

15581557
columnsToSearch.forEach(column => {
15591558
const cellValue = getRenderValue(row, column);
@@ -1663,16 +1662,14 @@ export type IDataMethodsConfig = CombineTypes<
16631662
eventSource?: string;
16641663
} & ISkipUndoAction;
16651664
["sort-rows"]: {
1666-
key: string;
1665+
key: TID;
16671666
order?: "asc" | "desc";
16681667
add?: boolean | number;
16691668
sort?: (a: IRow, b: IRow) => 1 | -1 | 0;
16701669
};
16711670
["search-rows"]: {
16721671
search: string;
1673-
columns?: {
1674-
[key: TID]: boolean;
1675-
};
1672+
columns?: Record<string | number, boolean>;
16761673
};
16771674
["open-editor"]: {
16781675
id: TID;
@@ -1686,7 +1683,7 @@ export type IDataMethodsConfig = CombineTypes<
16861683
};
16871684
["filter-rows"]: {
16881685
filter?: any;
1689-
key?: string;
1686+
key?: TID;
16901687
value?: any;
16911688
};
16921689
["collapse-column"]: {

0 commit comments

Comments
 (0)