Skip to main content

Editor

A Svelte component that renders an event editor bound to the Calendar instance. It mounts when api.getReactiveState().editorData carries a selected event and forwards form changes back to the calendar through update-event, delete-event, and select-event.

Signature

import { Editor } from "@svar-ui/svelte-calendar";

type EditorProps = {
api: CalendarInstanceApi;
items?: EditorItem[];
placement?: "sidebar" | "modal";
layout?: "columns" | "default";
focus?: boolean;
css?: string;
topBar?: any;
autoSave?: boolean;
onchange?: (ev: {
key: string;
value: any;
update: Record<string, any>;
}) => void;
onsave?: (ev: { values: Record<string, any> }) => void;
onaction?: (ev: {
item: { id: string; comp?: string };
changes?: any;
}) => void;
};

Other props are forwarded to the underlying Editor from @wx/svelte-editor. The values prop is reserved - the wrapper always binds the form to editorData.

Props

PropTypeDefaultDescription
apiCalendarInstanceApirequiredCalendar instance from bind:this or init. Used to read editorData and dispatch actions.
itemsEditorItem[]getEditorItems()Field config passed to @wx/svelte-editor.
placement"sidebar" | "modal""sidebar"Where the editor is rendered.
layout"columns" | "default""default"Layout preset for the underlying editor.
focusbooleantrueForwarded to @wx/svelte-editor.
cssstring""Extra class appended to the editor's CSS class list.
topBaranydefault top barOverride the injected top bar; pass null to remove it.
autoSavebooleantruePushes field changes through update-event immediately.
onchange(ev) => voidundefinedFires after the wrapper's same-day end-date adjustment runs.
onsave(ev) => voidundefinedFires before update-event is dispatched (manual-save flow).
onaction(ev) => voidundefinedFires before built-in close handling on top/bottom-bar buttons.

The wrapper applies two classes on every instance: wx-editor-calendar, plus wx-editor-all-day when the selected event has allDay: true. The all-day class hides the time inputs of the built-in date-time-picker fields via CSS.

Built-in top bar

When topBar is left undefined, the wrapper renders a close icon and a Delete button:

ControlAction
Close iconselect-event({ id: null })
Delete buttondelete-event({ id }), then select-event({ id: null })

Pass topBar={null} to remove it, or pass a custom { items: [...] } to replace it.

Example

<script>
import { Calendar, Editor } from "@svar-ui/svelte-calendar";

let api = $state();
</script>

<Calendar bind:this={api} {events} {date} />
{#if api}
<Editor {api} />
{/if}