1import { 2 AlertController 3} from "./chunk-RLZ522BW.js"; 4import { 5 Injectable, 6 inject, 7 setClassMetadata, 8 ɵɵdefineInjectable 9} from "./chunk-UQ6LLOJ6.js"; 10import { 11 __async 12} from "./chunk-CO64IJQE.js"; 13 14// src/app/services/guards/unsaved-changes.guard.ts 15var _UnsavedChangesService = class _UnsavedChangesService { 16 constructor() { 17 this.checkFn = null; 18 this.discardFn = null; 19 } 20 /** 21 * Register functions to check for and discard unsaved changes. 22 * The discard function can be synchronous or asynchronous. 23 */ 24 register(checkFn, discardFn) { 25 this.checkFn = checkFn; 26 this.discardFn = discardFn; 27 } 28 /** 29 * Unregister when component is destroyed. 30 */ 31 unregister() { 32 this.checkFn = null; 33 this.discardFn = null; 34 } 35 /** 36 * Check if there are unsaved changes. 37 */ 38 hasUnsavedChanges() { 39 return this.checkFn ? this.checkFn() : false; 40 } 41 /** 42 * Discard unsaved changes. 43 * Returns a promise if the discard function is async. 44 */ 45 discardChanges() { 46 return __async(this, null, function* () { 47 if (this.discardFn) { 48 yield this.discardFn(); 49 } 50 }); 51 } 52}; 53_UnsavedChangesService.\u0275fac = function UnsavedChangesService_Factory(__ngFactoryType__) { 54 return new (__ngFactoryType__ || _UnsavedChangesService)(); 55}; 56_UnsavedChangesService.\u0275prov = /* @__PURE__ */ \u0275\u0275defineInjectable({ token: _UnsavedChangesService, factory: _UnsavedChangesService.\u0275fac, providedIn: "root" }); 57var UnsavedChangesService = _UnsavedChangesService; 58(() => { 59 (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(UnsavedChangesService, [{ 60 type: Injectable, 61 args: [{ 62 providedIn: "root" 63 }] 64 }], null, null); 65})(); 66var unsavedChangesGuard = (component) => __async(void 0, null, function* () { 67 const service = inject(UnsavedChangesService); 68 const alertController = inject(AlertController); 69 if (service.hasUnsavedChanges()) { 70 const alert = yield alertController.create({ 71 header: "Unsaved Changes", 72 message: "You have unsaved changes. Discard them?", 73 buttons: [ 74 { text: "Stay", role: "cancel" }, 75 { text: "Discard", role: "destructive", cssClass: "danger" } 76 ] 77 }); 78 yield alert.present(); 79 const { role } = yield alert.onDidDismiss(); 80 if (role === "destructive") { 81 yield service.discardChanges(); 82 return true; 83 } 84 return false; 85 } 86 if (component == null ? void 0 : component.canDeactivate) { 87 return component.canDeactivate(); 88 } 89 return true; 90}); 91 92export { 93 UnsavedChangesService, 94 unsavedChangesGuard 95};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.