diff options
Diffstat (limited to 'apps/web/src/editor/cancel-interaction.ts')
| -rw-r--r-- | apps/web/src/editor/cancel-interaction.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/apps/web/src/editor/cancel-interaction.ts b/apps/web/src/editor/cancel-interaction.ts new file mode 100644 index 00000000..297a2062 --- /dev/null +++ b/apps/web/src/editor/cancel-interaction.ts @@ -0,0 +1,24 @@ +type CancelFn = () => void;
+
+const cancellers = new Set<CancelFn>();
+
+export function registerCanceller({ fn }: { fn: CancelFn }): () => void {
+ cancellers.add(fn);
+
+ return () => {
+ cancellers.delete(fn);
+ };
+}
+
+export function cancelInteraction(): boolean {
+ if (cancellers.size === 0) return false;
+
+ const activeCancellers = Array.from(cancellers);
+ cancellers.clear();
+
+ for (const cancel of activeCancellers) {
+ cancel();
+ }
+
+ return true;
+}
|
