chore: 项目基线(基于 WeKnora 定制版,整理文件忽略规则)
This commit is contained in:
commit
9097ee699d
5769 files changed
+1446466
No files matched your search
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Editors that can lose work register here, so whatever wants to move the
|
||||
* user elsewhere (the assistant opening a page) can check first.
|
||||
*/
|
||||
type UnsavedCheck = () => boolean
|
||||
|
||||
const checks = new Set<UnsavedCheck>()
|
||||
|
||||
/** Registers a check for unsaved changes; returns the unregister function. */
|
||||
export function registerUnsavedChanges(check: UnsavedCheck): () => void {
|
||||
checks.add(check)
|
||||
return () => {
|
||||
checks.delete(check)
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether any open editor has changes that leaving would lose. */
|
||||
export function hasUnsavedChanges(): boolean {
|
||||
for (const check of checks) {
|
||||
try {
|
||||
if (check()) return true
|
||||
} catch {
|
||||
// An editor tearing down cannot hold unsaved work.
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user