From 57899773cb36dc76151487424f3ff82a7e13d4b7 Mon Sep 17 00:00:00 2001 From: BearToCode Date: Sat, 21 Sep 2024 09:47:18 +0200 Subject: [PATCH] style: format code --- packages/plugin-attachment/src/lib/index.ts | 35 +++++++++++-------- .../plugin-attachment/src/routes/+page.svelte | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/plugin-attachment/src/lib/index.ts b/packages/plugin-attachment/src/lib/index.ts index 4dbccafe..907c2d4d 100644 --- a/packages/plugin-attachment/src/lib/index.ts +++ b/packages/plugin-attachment/src/lib/index.ts @@ -35,7 +35,14 @@ export interface AttachmentExtensionOptions { loadingOverlay?: false | typeof SvelteComponent<{ uploadingFiles: Writable }>; } -const ImageMimeTypes = ['image/png', 'image/jpeg', 'image/gif', 'image/svg+xml', 'image/webp', 'image/avif']; +const ImageMimeTypes = [ + 'image/png', + 'image/jpeg', + 'image/gif', + 'image/svg+xml', + 'image/webp', + 'image/avif' +]; /** * Carta attachment plugin. @@ -64,27 +71,27 @@ export const attachment = (options: AttachmentExtensionOptions): Plugin => { async function handleFile(file: File) { if (!allowedMimeTypes.includes(file.type)) return; if (!carta?.input) return; - const input = carta.input + const input = carta.input; const textarea = input.textarea; let pos = input.textarea.selectionStart; const loadingStr = `[Uploading ${file.name}](loading)`; - const isImage = ImageMimeTypes.includes(file.type) + const isImage = ImageMimeTypes.includes(file.type); if (isImage) { // assume images are being inserted as blocks const line = carta.input.getLine(); - pos = line.end + pos = line.end; if (line.value) { - input.insertAt(pos, '\n\n') - pos +=2 + input.insertAt(pos, '\n\n'); + pos += 2; } - input.insertAt(pos, loadingStr + '\n') + input.insertAt(pos, loadingStr + '\n'); pos += loadingStr.length + 1; } else { // non image attachments are inline (could make multiple into comma separated list or bullets) carta.input.insertAt(pos, loadingStr + ' '); - pos += loadingStr.length + 1 + pos += loadingStr.length + 1; } carta.input.update(); @@ -103,9 +110,7 @@ export const attachment = (options: AttachmentExtensionOptions): Plugin => { if (!path) return; - const str = isImage - ? `![${file.name}](${path})` - : `[${file.name}](${path})`; + const str = isImage ? `![${file.name}](${path})` : `[${file.name}](${path})`; carta.input.insertAt(loadingStrIndex, str); carta.input.update(); @@ -113,19 +118,19 @@ export const attachment = (options: AttachmentExtensionOptions): Plugin => { // update cursor position to account for the string replacement if (input.textarea.selectionStart < loadingStrIndex) { // caret is before the loading string, no change required - pos = input.textarea.selectionStart + pos = input.textarea.selectionStart; } else if (input.textarea.selectionStart >= loadingStrIndex + str.length) { // caret is after the loading string, adjust position by the difference - pos = input.textarea.selectionStart - loadingStr.length + str.length + pos = input.textarea.selectionStart - loadingStr.length + str.length; } else if (input.textarea.selectionStart >= loadingStrIndex) { // caret is within the loading string, position it just after - pos = loadingStrIndex + str.length + 1 + pos = loadingStrIndex + str.length + 1; } textarea.setSelectionRange(pos, pos); carta.input.history.saveState(textarea.value, textarea.selectionStart); - return + return; } function handleDrop(this: HTMLTextAreaElement, e: DragEvent) { diff --git a/packages/plugin-attachment/src/routes/+page.svelte b/packages/plugin-attachment/src/routes/+page.svelte index 4cc10d2c..f3b0ae7a 100644 --- a/packages/plugin-attachment/src/routes/+page.svelte +++ b/packages/plugin-attachment/src/routes/+page.svelte @@ -11,7 +11,7 @@ attachment({ async upload(file) { await new Promise((resolve) => setTimeout(resolve, 1_000)); - return URL.createObjectURL(file) + return URL.createObjectURL(file); } }) ]