carta/packages/plugin-attachment
2023-11-07 11:50:02 +01:00
..
src style: fix linting issues 2023-11-07 11:50:02 +01:00
static feat: add plugin-attachment 2023-10-26 19:32:50 +02:00
.gitignore feat: add plugin-attachment 2023-10-26 19:32:50 +02:00
.npmrc feat: add plugin-attachment 2023-10-26 19:32:50 +02:00
package.json v2.8.0 2023-11-06 20:57:07 +01:00
README.md style: fix linting issues 2023-11-07 11:50:02 +01:00
svelte.config.js feat: add plugin-attachment 2023-10-26 19:32:50 +02:00
tsconfig.json feat: add plugin-attachment 2023-10-26 19:32:50 +02:00
vite.config.ts feat: add plugin-attachment 2023-10-26 19:32:50 +02:00

Carta Attachment Plugin

This plugin adds support for attachments. Install it using:

npm i @cartamd/plugin-attachment

Setup

Styles

Import the default theme, or create you own:

import '@cartamd/plugin-attachment/default.css';

Extension

<script lang="ts">
	import { Carta, CartaEditor } from 'carta-md';
	import { attachment } from '@cartamd/plugin-attachment';

	const carta = new Carta({
		extensions: [
			attachment({
				upload(file) {
					/* ... */
				}
			})
		]
	});
</script>

<CartaEditor {carta} />

Options

Here are the options you can pass to attachment():

export interface AttachmentExtensionOptions {
	/**
	 * Upload a file to the server. Return the url of the uploaded file.
	 * If an error occurs, return null. This function does **not** handle errors.
	 * @param file The file to upload
	 * @returns The uploaded file url, or null if it failed
	 */
	upload: (file: File) => Promise<string | null>;
	/**
	 * Supported mime types.
	 *
	 * @default ['image/png', 'image/jpeg', 'image/gif', 'image/svg+xml'].
	 */
	supportedMimeTypes?: string[];
	/**
	 * Whether to disable the attach icon.
	 *
	 * @default false
	 */
	disableIcon?: boolean;
	/**
	 * Custom drop overlay component. Use `false` to disable the overlay.
	 */
	dropOverlay?: false | typeof SvelteComponent;
	/**
	 * Custom loading overlay component. Use `false` to disable the overlay.
	 */
	loadingOverlay?: false | typeof SvelteComponent<{ uploadingFiles: Writable<File[]> }>;
}