Skip to main content

registerEditorItem

Registers a custom Svelte component under a string name so the editor's items array can reference it via comp. With { readonly: true }, registers the component that renders that comp type when the editor is read-only. Call once at module scope.

The kanban editor pre-registers richselect, multicombo, datepicker, and slider. @svar-ui/svelte-editor exports Attachments, CodeMirror, and TinyMCE field components that aren't pre-registered and are typical candidates for registration.

Usage​

import { registerEditorItem } from "@svar-ui/svelte-kanban";
import type { Component } from "svelte";

registerEditorItem(
type: string,
handler: Component<any>,
config?: { readonly?: boolean } | null
): void;
ParameterTypeDescription
typestringIdentifier used as comp in editor item descriptors
handlerComponent<any>Svelte component receiving value, onchange, and promoted config fields
config{ readonly?: boolean } | nullOptional. { readonly: true } registers handler as the read-only renderer for type

When the editor is read-only, each item renders with the read-only handler registered for its comp. Without one, the editor falls back to its built-in read-only renderer.

The component must call onchange({ value }) on change. Fields in the item's config object are promoted to top-level props.

Example​

Registering a custom comments component:

<script>
import { Kanban, Editor, registerEditorItem } from "@svar-ui/svelte-kanban";
import Comments from "./Comments.svelte";

registerEditorItem("comments", Comments);

const items = [
{ comp: "text", key: "label", label: "Label" },
{ comp: "textarea", key: "description", label: "Description" },
{ comp: "comments", key: "comments", label: "Comments" },
];

let api;
</script>

<Kanban bind:this={api} {cards} {columns} />
<Editor {api} {items} />

Registering a bundled component from @svar-ui/svelte-editor:

<script>
import { registerEditorItem } from "@svar-ui/svelte-kanban";
import { Attachments } from "@svar-ui/svelte-editor";

registerEditorItem("files", Attachments);

const items = [
{ comp: "text", key: "label", label: "Label" },
{
comp: "files",
key: "attachments",
label: "Attachments",
uploadURL: "/api/files",
},
];
</script>

Registering a read-only renderer for a custom type:

<script>
import { registerEditorItem } from "@svar-ui/svelte-kanban";
import Comments from "./Comments.svelte";
import CommentsView from "./CommentsView.svelte";

registerEditorItem("comments", Comments);
registerEditorItem("comments", CommentsView, { readonly: true });
</script>

Registering multiple components:

<script>
import { registerEditorItem } from "@svar-ui/svelte-kanban";
import Comments from "./Comments.svelte";
import Tasklist from "./Tasklist.svelte";

registerEditorItem("comments", Comments);
registerEditorItem("tasks", Tasklist);

const items = [
{ comp: "text", key: "label", label: "Label" },
{ comp: "comments", key: "comments", label: "Comments" },
{ comp: "tasks", key: "tasks", label: "Checklist" },
];
</script>