mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 12:36:24 +08:00
refactor(editor): enable the noUncheckedIndexedAccess rule for the data-view package (#9351)
close: BS-2230
This commit is contained in:
@@ -197,7 +197,7 @@ function getSelectedArea(
|
||||
const { rowsSelection, columnsSelection, groupKey } = selection;
|
||||
const data: SelectedArea = [];
|
||||
const rows = groupKey
|
||||
? view.groupTrait.groupDataMap$.value?.[groupKey].rows
|
||||
? view.groupTrait.groupDataMap$.value?.[groupKey]?.rows
|
||||
: view.rows$.value;
|
||||
const columns = view.propertyIds$.value;
|
||||
if (!rows) {
|
||||
@@ -208,8 +208,14 @@ function getSelectedArea(
|
||||
cells: [],
|
||||
};
|
||||
const rowId = rows[i];
|
||||
if (rowId == null) {
|
||||
continue;
|
||||
}
|
||||
for (let j = columnsSelection.start; j <= columnsSelection.end; j++) {
|
||||
const columnId = columns[j];
|
||||
if (columnId == null) {
|
||||
continue;
|
||||
}
|
||||
const cell = view.cellGet(rowId, columnId);
|
||||
row.cells.push(cell);
|
||||
}
|
||||
@@ -237,7 +243,7 @@ function getTargetRangeFromSelection(
|
||||
},
|
||||
column: {
|
||||
start: focus.columnIndex,
|
||||
length: data[0].length,
|
||||
length: data[0]?.length ?? 0,
|
||||
},
|
||||
}
|
||||
: {
|
||||
@@ -258,7 +264,7 @@ function pasteToCells(
|
||||
selection: TableAreaSelection
|
||||
) {
|
||||
const srcRowLength = rows.length;
|
||||
const srcColumnLength = rows[0].length;
|
||||
const srcColumnLength = rows[0]?.length ?? 0;
|
||||
const targetRange = getTargetRangeFromSelection(selection, rows);
|
||||
for (let i = 0; i < targetRange.row.length; i++) {
|
||||
for (let j = 0; j < targetRange.column.length; j++) {
|
||||
@@ -267,7 +273,7 @@ function pasteToCells(
|
||||
|
||||
const srcRowIndex = i % srcRowLength;
|
||||
const srcColumnIndex = j % srcColumnLength;
|
||||
const dataString = rows[srcRowIndex][srcColumnIndex];
|
||||
const dataString = rows[srcRowIndex]?.[srcColumnIndex];
|
||||
|
||||
const targetContainer = table.selectionController.getCellContainer(
|
||||
selection.groupKey,
|
||||
@@ -278,7 +284,7 @@ function pasteToCells(
|
||||
const columnId = targetContainer?.dataset.columnId;
|
||||
|
||||
if (rowId && columnId) {
|
||||
targetContainer?.column.valueSetFromString(rowId, dataString);
|
||||
targetContainer?.column.valueSetFromString(rowId, dataString ?? '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +333,8 @@ export class TableHotkeysController implements ReactiveController {
|
||||
this.selectionController.selection = TableRowSelection.create({
|
||||
rows:
|
||||
this.host.props.view.groupTrait.groupsDataList$.value?.flatMap(
|
||||
group => group.rows.map(id => ({ groupKey: group.key, id }))
|
||||
group =>
|
||||
group?.rows.map(id => ({ groupKey: group.key, id })) ?? []
|
||||
) ??
|
||||
this.host.props.view.rows$.value.map(id => ({
|
||||
groupKey: undefined,
|
||||
|
||||
@@ -234,7 +234,7 @@ export class TableSelectionController implements ReactiveController {
|
||||
}
|
||||
const rows =
|
||||
groupKey != null
|
||||
? this.view.groupTrait.groupDataMap$.value?.[groupKey].rows
|
||||
? this.view.groupTrait.groupDataMap$.value?.[groupKey]?.rows
|
||||
: this.view.rows$.value;
|
||||
requestAnimationFrame(() => {
|
||||
const index = this.host.props.view.properties$.value.findIndex(
|
||||
@@ -285,7 +285,8 @@ export class TableSelectionController implements ReactiveController {
|
||||
length: selection.rowsSelection.end - selection.rowsSelection.start + 1,
|
||||
})
|
||||
.map((_, index) => index + selection.rowsSelection.start)
|
||||
.map(row => rows[row]?.rowId);
|
||||
.map(row => rows[row]?.rowId)
|
||||
.filter((id): id is string => id != null);
|
||||
return ids.map(id => ({ id, groupKey: selection.groupKey }));
|
||||
}
|
||||
|
||||
@@ -314,6 +315,7 @@ export class TableSelectionController implements ReactiveController {
|
||||
};
|
||||
for (let i = 0; i < rowOffsets.length; i++) {
|
||||
const offset = rowOffsets[i];
|
||||
if (offset == null) continue;
|
||||
if (offset < startY) {
|
||||
row.start = i;
|
||||
}
|
||||
@@ -323,6 +325,7 @@ export class TableSelectionController implements ReactiveController {
|
||||
}
|
||||
for (let i = 0; i < columnOffsets.length; i++) {
|
||||
const offset = columnOffsets[i];
|
||||
if (offset == null) continue;
|
||||
if (offset < startX) {
|
||||
column.start = i;
|
||||
}
|
||||
@@ -544,20 +547,21 @@ export class TableSelectionController implements ReactiveController {
|
||||
if (!TableRowSelection.is(this.selection)) return;
|
||||
const rows = this.selection.rows;
|
||||
const lastRow = rows[rows.length - 1];
|
||||
if (!lastRow) return;
|
||||
const lastRowIndex =
|
||||
(
|
||||
this.getGroup(lastRow.groupKey)?.querySelector(
|
||||
`data-view-table-row[data-row-id='${lastRow.id}']`
|
||||
this.getGroup(lastRow?.groupKey)?.querySelector(
|
||||
`data-view-table-row[data-row-id='${lastRow?.id}']`
|
||||
) as TableRow | null
|
||||
)?.rowIndex ?? 0;
|
||||
const getRowByIndex = (index: number) => {
|
||||
const tableRow = this.rows(lastRow.groupKey)?.item(index);
|
||||
const tableRow = this.rows(lastRow?.groupKey)?.item(index);
|
||||
if (!tableRow) {
|
||||
return;
|
||||
}
|
||||
return {
|
||||
id: tableRow.rowId,
|
||||
groupKey: lastRow.groupKey,
|
||||
groupKey: lastRow?.groupKey,
|
||||
};
|
||||
};
|
||||
const prevRow = getRowByIndex(lastRowIndex - 1);
|
||||
@@ -621,10 +625,15 @@ export class TableSelectionController implements ReactiveController {
|
||||
add.forEach(row => rows.add(key(row)));
|
||||
const result = [...rows]
|
||||
.map(r => r.split('.'))
|
||||
.map(([id, groupKey]) => ({
|
||||
id,
|
||||
groupKey: groupKey ? groupKey : undefined,
|
||||
}));
|
||||
.flatMap(([id, groupKey]) => {
|
||||
if (id == null) return [];
|
||||
return [
|
||||
{
|
||||
id,
|
||||
groupKey: groupKey ? groupKey : undefined,
|
||||
},
|
||||
];
|
||||
});
|
||||
this.selection = TableRowSelection.create({
|
||||
rows: result,
|
||||
});
|
||||
|
||||
@@ -79,6 +79,7 @@ export const popRowMenu = (
|
||||
return;
|
||||
}
|
||||
const row = selection.rows[0];
|
||||
if (!row) return;
|
||||
popFilterableSimpleMenu(ele, [
|
||||
menu.action({
|
||||
name: 'Expand Row',
|
||||
|
||||
@@ -94,12 +94,15 @@ export class DatabaseColumnStatsCell extends SignalWatcher(
|
||||
if (!groups[func.group]) {
|
||||
groups[func.group] = {};
|
||||
}
|
||||
const oldFunc = groups[func.group][func.type];
|
||||
const oldFunc = groups[func.group]?.[func.type];
|
||||
if (!oldFunc || typeSystem.unify(func.dataType, oldFunc.dataType)) {
|
||||
if (!func.impl) {
|
||||
delete groups[func.group][func.type];
|
||||
delete groups[func.group]?.[func.type];
|
||||
} else {
|
||||
groups[func.group][func.type] = func;
|
||||
const group = groups[func.group];
|
||||
if (group) {
|
||||
group[func.type] = func;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -306,6 +306,7 @@ export class TableSingleView extends SingleViewBase<TableViewData> {
|
||||
}
|
||||
const columns = [...this.computedColumns$.value];
|
||||
const [column] = columns.splice(columnIndex, 1);
|
||||
if (!column) return {};
|
||||
const index = insertPositionToIndex(toAfterOfColumn, columns);
|
||||
columns.splice(index, 0, column);
|
||||
return {
|
||||
@@ -356,12 +357,12 @@ export class TableSingleView extends SingleViewBase<TableViewData> {
|
||||
this.groupTrait.moveCardTo(rowId, fromGroup, toGroup, position);
|
||||
}
|
||||
|
||||
override rowNextGet(rowId: string): string {
|
||||
override rowNextGet(rowId: string): string | undefined {
|
||||
const index = this.rows$.value.indexOf(rowId);
|
||||
return this.rows$.value[index + 1];
|
||||
}
|
||||
|
||||
override rowPrevGet(rowId: string): string {
|
||||
override rowPrevGet(rowId: string): string | undefined {
|
||||
const index = this.rows$.value.indexOf(rowId);
|
||||
return this.rows$.value[index - 1];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user