Skip to content

Commit

Permalink
fix: set to unsaved after edit actions other than cell editing
Browse files Browse the repository at this point in the history
- Introduce type `TableEvent`
- Add `initChangeListener`

Resolves: #50
  • Loading branch information
yinanazhou committed Jul 2, 2024
1 parent 2ce9258 commit bc21c71
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/Editor/CressTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import { ColumnTools } from './ColumnTools';
import { updateAttachment } from '../Dashboard/Storage';
import { setSavedStatus } from '../utils/Unsaved';
import * as Notification from '../utils/Notification';
import { TableEvent } from '../Types';

const changeHooks: TableEvent[] = [
'afterChange',
'afterColumnMove',
'afterColumnSequenceChange',
'afterCreateCol',
'afterCreateRow',
'afterCut',
'afterRemoveCol',
'afterRemoveRow',
'afterRowMove',
'afterRowSequenceChange',
];

export class CressTable {
private table: Handsontable;
Expand Down Expand Up @@ -65,15 +79,15 @@ export class CressTable {
dropdownMenu: true,
className: 'table-menu-btn',
licenseKey: 'non-commercial-and-evaluation',
afterChange(changes, source) {
if (source != 'loadData') setSavedStatus(false);
afterChange() {
this.validateCells();
},
beforeValidate: (value) => this.setProcessStatus(value),
afterValidate: (isValid) => this.setResultStatus(isValid),
});

this.initFileListener(id, inputHeader, body, headers);
this.initChangeListener();
}

private initFileListener(
Expand Down Expand Up @@ -141,4 +155,12 @@ export class CressTable {
this.ColumnTools.hasInvalid = false;
}
}

private initChangeListener() {
changeHooks.forEach((hook) => {
this.table.addHook(hook, (source) => {
if (source != 'loadData') setSavedStatus(false);
});
});
}
}
13 changes: 13 additions & 0 deletions src/Types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import PouchDB from 'pouchdb';

interface Glyph {
imagePath: string | null;
imageBinary: string | null;
Expand Down Expand Up @@ -61,3 +62,15 @@ export type validationStatus = 'unknown' | 'processing' | 'done';
export type HTMLSVGElement = HTMLElement & SVGSVGElement;

export type NotificationType = 'default' | 'error' | 'warning' | 'success';

export type TableEvent =
| 'afterChange'
| 'afterColumnMove'
| 'afterColumnSequenceChange'
| 'afterCreateCol'
| 'afterCreateRow'
| 'afterCut'
| 'afterRemoveCol'
| 'afterRemoveRow'
| 'afterRowMove'
| 'afterRowSequenceChange';

0 comments on commit bc21c71

Please sign in to comment.