Skip to content

Commit

Permalink
Improved editor plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Apr 20, 2023
1 parent a6112b3 commit 4ae3696
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
12 changes: 8 additions & 4 deletions sources/table/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface ITableCell {
count: number;
color: string;
css: string;
update(): void;
update(quiet?: boolean): void;
}

export class TableCell extends Base implements ITableCell {
Expand Down Expand Up @@ -123,9 +123,13 @@ export class TableCell extends Base implements ITableCell {
}
this.isModified = false;
}
public update(): void {
this._isUpdating = true;
public update(quiet = true): void {
if(quiet) {
this._isUpdating = true;
}
this.data = this.rowData[this.name];
this._isUpdating = false;
if(quiet) {
this._isUpdating = false;
}
}
}
12 changes: 2 additions & 10 deletions sources/table/editor-inplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,16 @@ export class InplaceEditorPlugin extends EditorPlugin {
super.startEditRow(row);
this._activeEditors = {};
row.cells.forEach(cell => {
this._activeEditors[cell.name] = new Editor(cell.rowData, cell.name, (value: any, commit: boolean) => {
if(commit) {
cell.data = value;
}
});
this._activeEditors[cell.name] = new Editor(cell.rowData, cell.name);
});
row.mode = "edit-inplace";
}
protected endEditRow(commit: boolean) {
super.endEditRow(commit);
Object.keys(this._activeEditors || {}).forEach(name => {
this._activeEditors[name].complete(commit);
});
if(!!this._editedRow) {
this._editedRow.mode = "default";
this._editedRow = undefined;
}
this._activeEditors = undefined;
super.endEditRow(commit);
}
getActions(): IAction[] {
const actions = super.getActions();
Expand Down
7 changes: 1 addition & 6 deletions sources/table/editor-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ export class RowEditorPlugin extends EditorPlugin {
row.mode = "edit-row";
}
protected endEditRow(commit: boolean) {
super.endEditRow(commit);
if(!!this._form) {
this._form.complete(commit);
this._form = undefined;
}
if(!!this._editedRow) {
this._editedRow.mode = "default";
this._editedRow.update();
this._editedRow = undefined;
}
super.endEditRow(commit);
}
onRowCreated(row: ITableRow): void {
row.getRowComponent = () => {
Expand Down
7 changes: 7 additions & 0 deletions sources/table/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export class EditorPlugin implements ITablePlugin {
if(!commit && !!this._editedRow && this._editedRow.number === undefined) {
this._table.rows.splice(this._table.rows.indexOf(this._editedRow), 1);
}
if(!!this._editedRow) {
this._editedRow.mode = "default";
if(commit) {
this._editedRow.update(false);
}
this._editedRow = undefined;
}
this._saveAction.visible = false;
}
onSelectionChanged(): void {
Expand Down
6 changes: 3 additions & 3 deletions sources/table/row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import "./row.scss";
getRowComponentParams: (params: any) => any;
getCellComponent: (cell: ITableCell) => string;
getCellComponentParams: (params: any) => any;
update(): void;
update(quiet?: boolean): void;
}

export class TableRow extends Base implements ITableRow {
Expand Down Expand Up @@ -67,7 +67,7 @@ export class TableRow extends Base implements ITableRow {
}
return result;
}
public update() {
this.cells.forEach(cell => cell.update());
public update(quiet = true) {
this.cells.forEach(cell => cell.update(quiet));
}
}
3 changes: 1 addition & 2 deletions sources/widgets/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Editor extends Base {
bool: "table4js-checkbox-editor",
};

constructor(private _data: any, private name: string, private onComplete?: (value: any, commit: boolean) => void) {
constructor(private _data: any, private name: string) {
super();
this.value = _data[this.name];
}
Expand All @@ -46,7 +46,6 @@ export class Editor extends Base {
if(commit) {
this.data[this.name] = this.value;
}
!!this.onComplete && this.onComplete(this.value, commit);
}

// processKeyUp(event: KeyboardEvent) {
Expand Down

0 comments on commit 4ae3696

Please sign in to comment.