From ab649f125d4efa0f83a90c0f912d38b368b721a9 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Tue, 26 Oct 2021 16:05:06 +0000 Subject: [PATCH] feat: add support for AbortSignal --- src/index.ts | 10 +++++----- src/paste-markdown-image-link.ts | 8 ++++---- src/paste-markdown-link.ts | 4 ++-- src/paste-markdown-table.ts | 8 ++++---- src/paste-markdown-text.ts | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index b961e50..de0d0c3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,11 +7,11 @@ interface Subscription { unsubscribe: () => void } -function subscribe(el: HTMLElement): Subscription { - installTable(el) - installImageLink(el) - installLink(el) - installText(el) +function subscribe(el: HTMLElement, {signal}: {signal?: AbortSignal} = {}): Subscription { + installTable(el, {signal}) + installImageLink(el, {signal}) + installLink(el, {signal}) + installText(el, {signal}) return { unsubscribe: () => { diff --git a/src/paste-markdown-image-link.ts b/src/paste-markdown-image-link.ts index defdcb2..cf33f5d 100644 --- a/src/paste-markdown-image-link.ts +++ b/src/paste-markdown-image-link.ts @@ -2,10 +2,10 @@ import {insertText} from './text' -export function install(el: HTMLElement): void { - el.addEventListener('dragover', onDragover) - el.addEventListener('drop', onDrop) - el.addEventListener('paste', onPaste) +export function install(el: HTMLElement, {signal}: {signal?: AbortSignal} = {}): void { + el.addEventListener('dragover', onDragover, {signal}) + el.addEventListener('drop', onDrop, {signal}) + el.addEventListener('paste', onPaste, {signal}) } export function uninstall(el: HTMLElement): void { diff --git a/src/paste-markdown-link.ts b/src/paste-markdown-link.ts index f9cb264..15b851e 100644 --- a/src/paste-markdown-link.ts +++ b/src/paste-markdown-link.ts @@ -1,7 +1,7 @@ import {insertText} from './text' -export function install(el: HTMLElement): void { - el.addEventListener('paste', onPaste) +export function install(el: HTMLElement, {signal}: {signal?: AbortSignal} = {}): void { + el.addEventListener('paste', onPaste, {signal}) } export function uninstall(el: HTMLElement): void { diff --git a/src/paste-markdown-table.ts b/src/paste-markdown-table.ts index e2784b7..6ecbdc1 100644 --- a/src/paste-markdown-table.ts +++ b/src/paste-markdown-table.ts @@ -1,9 +1,9 @@ import {insertText} from './text' -export function install(el: HTMLElement): void { - el.addEventListener('dragover', onDragover) - el.addEventListener('drop', onDrop) - el.addEventListener('paste', onPaste) +export function install(el: HTMLElement, {signal}: {signal?: AbortSignal} = {}): void { + el.addEventListener('dragover', onDragover, {signal}) + el.addEventListener('drop', onDrop, {signal}) + el.addEventListener('paste', onPaste, {signal}) } export function uninstall(el: HTMLElement): void { diff --git a/src/paste-markdown-text.ts b/src/paste-markdown-text.ts index b02fa6d..bc5fba8 100644 --- a/src/paste-markdown-text.ts +++ b/src/paste-markdown-text.ts @@ -1,7 +1,7 @@ import {insertText} from './text' -export function install(el: HTMLElement): void { - el.addEventListener('paste', onPaste) +export function install(el: HTMLElement, {signal}: {signal?: AbortSignal} = {}): void { + el.addEventListener('paste', onPaste, {signal}) } export function uninstall(el: HTMLElement): void {