ProtoCalendar

Day, week and infinite month calendar with drag to create, move and resize, an inline event form, quick natural-language events, and Y.js CRDT persistence.

Overview

ProtoCalendar is a self-contained calendar backed by useProtoCalendar. It is built from the Nuxt UI calendar template (MIT) and provides:

  • Three views: day, week, and an infinitely scrolling month (virtualized ±5 years) whose month labels ride the rows as you scroll
  • Drag on empty grid to draw a new event; double-click for a one-hour one
  • Inline form: clicking an event opens a popover form that saves as you type; right-click for edit / delete
  • Move and resize: drag a timed block across days and times (15-minute snap), drag its bottom edge to resize, drag a chip in the month view or the all-day row to another day
  • Quick events: type "Lunch with Sam at 1pm tomorrow" into the + menu; the phrase is parsed in the browser by gpu-time, downloaded on first use
  • Overlap layout: Google Calendar–style columns for overlapping timed events, lane packing for all-day bars
  • External drops: accept HTML5 drag payloads from outside the calendar (e.g. a task panel)
  • Y.js CRDT persistence: IndexedDB storage and BroadcastChannel cross-tab sync

Requires @nuxt/ui 4.5 or later.

Click an event to edit it in place:

The week view lays timed events out by the hour, with all-day events in the band above:

Quick Start

<template>
  <ProtoCalendar doc-key="my-calendar" class="h-screen" />
</template>

That's it. The component manages its own data layer internally. The calendar fills its container, so give the container a height.

ProtoCalendar Props

PropTypeDefaultDescription
docKeystring'proto-calendar'IDB document key
namespacestring—Optional namespace prefix for multi-tenant isolation
existingDocY.Doc—Pass a shared Y.Doc to co-locate with other tools
initialView'month' | 'week' | 'day''month'Starting view
initialDatestringtodayYYYY-MM-DD date to open on
disableSyncbooleanfalseDisable server sync (use local IDB only)

Every ProtoCalendarView prop and listener below passes through, e.g. <ProtoCalendar doc-key="cal" :week-starts-on="0" sidebar @event-click="…" />.

ProtoCalendarView — bring your own data

ProtoCalendar is ProtoCalendarView bound to a Y.Doc. Use the view directly to drive the calendar from anything else: an API, a collection, a store. It owns no persistence: events comes in and every change goes back out as an emit. A change is shown straight away and held until you hand back a new events array, so a drop does not snap back while your request is in flight.

<script setup lang="ts">
import type { CalendarViewEvent } from '#protokit/calendar'

const events = ref<CalendarViewEvent[]>([])

function onCreate(event: CalendarViewEvent) {
  events.value = [...events.value, event]
}
function onUpdate(event: CalendarViewEvent) {
  events.value = events.value.map(e => (e.id === event.id ? event : e))
}
function onRemove(id: string) {
  events.value = events.value.filter(e => e.id !== id)
}
</script>

<template>
  <ProtoCalendarView
    :events="events"
    @create="onCreate"
    @update="onUpdate"
    @remove="onRemove"
  />
</template>

Props

PropTypeDefaultDescription
eventsCalendarViewEvent[][]The events to draw
calendarsCalendarSource[][]Sources events belong to via calendarId; they colour events and fill the sidebar list
weekStartsOn0–61First day of the week (0 = Sunday)
localestring'en-US'Locale for day, month and time labels
viewsCalendarView[]all threeWhich views the switcher offers
editablebooleantrueDrag to move and resize. Off, the calendar only displays and emits event-click
creatablebooleantrueDraw new events on the grid, the + menu and n. Needs editable
popoverbooleantrueClicking an editable event opens the inline form. Off, the click is only event-click
droppablebooleanfalseAccept HTML5 drops from outside (see External Drops)
loadingbooleanfalseShow placeholders where the visible range has no events yet
toolbarbooleantrueTitle, view switcher, previous / today / next, and the + menu
sidebarbooleanfalseMini month and the calendar list, from lg up
quickEventsbooleantrueThe "Movie at 7pm on Friday" input in the + menu
shortcutsbooleanfalset today · d / w / m view · n new · ← / → previous / next. Off by default because they listen page-wide

Models

ModelTypeDescription
v-model:viewCalendarViewThe current view (default 'week'). Bind it when you offer more than one view and want to keep it
v-model:dateCalendarDate (@internationalized/date)The date the calendar is on
v-model:hidden-calendarsstring[]Calendar ids unchecked in the sidebar list

A prop passed without v-model pins the value: view="month" with :views="['month']" is a month-only calendar.

Emits

EmitPayloadWhen
createCalendarViewEventA drawn or quick event is saved (closing its form saves it; Escape discards it)
updateCalendarViewEventAn event is moved, resized, or edited in the form (debounced while typing)
removeid: stringDeleted from the form or the right-click menu
event-clickCalendarViewEventAny click on an event, with or without the form
external-dropCalendarExternalDropSomething from outside was dropped on the grid (needs droppable)
range-changeDateRangeThe range on screen changed, and in the month view every 6-week chunk scrolled near; use it to fetch by range

CalendarViewEvent

interface CalendarViewEvent {
  id: string
  title: string
  start: string          // floating local datetime "YYYY-MM-DDTHH:mm:ss"
  end: string            // exclusive: an all-day event on the 3rd ends at "…-04T00:00:00"
  allDay?: boolean
  calendarId?: string
  color?: CalendarColor  // overrides the calendar's colour
  description?: string
  location?: string
  icon?: string          // drawn in place of the dot, e.g. "i-lucide-video": says what KIND of thing it is
  editable?: boolean     // false locks this one event: no drag, no form; clicks still emit
}

Dates are floating local times (no timezone designator): new Date() reads them in the viewer's own zone, so a 09:15 stand-up is 09:15 wherever it is viewed.

useProtoCalendar Composable

Use the composable directly when you need programmatic control over the stored events.

const {
  events,       // Ref<CalendarEvent[]> — the stored shape below
  addEvent,     // (event: Omit<CalendarEvent, 'id'>) => void
  updateEvent,  // (id: string, patch: Partial<CalendarEvent>) => void
  removeEvent,  // (id: string) => void
  moveEvent,    // (id: string, newStartAt: string, newEndAt: string) => void
  isReady,      // Ref<boolean>
  doc,          // Y.Doc
} = useProtoCalendar({
  docKey: 'my-calendar',
  disableSync: false,
})

Options

OptionTypeDefaultDescription
docKeystring'proto-calendar'IDB document key
namespacestring—Namespace prefix
existingDocY.Doc—Bypass IDB by providing an existing document
encryptionEncryptionConfig—AES-GCM encryption config
disableSyncbooleanfalseDisable server sync

Stored CalendarEvent type

interface CalendarEvent {
  id: string           // auto-generated UUID
  title: string
  startAt: string      // local ISO datetime: "YYYY-MM-DDTHH:mm:ss"
  endAt: string        // for all-day events, the LAST day (inclusive)
  allDay: boolean
  color: CalendarColor
  description: string
  location: string
  linkedTaskId: string // optional: ID of an external item linked to this event
}

The stored shape predates the view and is kept so existing documents keep opening. Convert between the two with fromStoredEvent and toStoredPatch from #protokit/calendar, which is what ProtoCalendar does internally:

import { fromStoredEvent, toStoredPatch } from '#protokit/calendar'

const viewEvents = computed(() => events.value.map(fromStoredEvent))
const onUpdate = (event: CalendarViewEvent) => updateEvent(event.id, toStoredPatch(event))

linkedTaskId is an opaque string your app controls. The calendar stores it but does not interpret it. Use it to prevent the same external item from being scheduled more than once (see External Drops below).

Integration with Other Proto Tools

Share a single Y.Doc between a calendar and other tools using existingDoc:

const { doc } = useProtoDoc('shared-workspace')

// Both tools store their data in the same Y.Doc
const calendar = useProtoCalendar({ existingDoc: doc })
const collection = useProtoCollection(schema, { existingDoc: doc })

External Drops

With droppable, the view emits external-drop when an HTML5 drag from outside the calendar lands on the grid. Where it lands decides the range: an hour at the pointer in the time grid, the whole day on the all-day row or in the month view.

interface CalendarExternalDrop {
  start: string
  end: string
  allDay: boolean
  data: string    // application/x-calendar-item, then application/x-task, then text/plain
  event: DragEvent
}
<ProtoCalendarView
  :events="viewEvents"
  droppable
  @external-drop="onExternalDrop"
/>
function onExternalDrop({ start, end, allDay, data }: CalendarExternalDrop) {
  const task = JSON.parse(data)
  addEvent({
    ...toStoredPatch({ id: '', title: task.title, start, end, allDay, color: task.color ?? 'blue' }),
    linkedTaskId: task.id, // prevents the task from being scheduled twice
  })
}

To prevent duplicate scheduling, check linkedTaskId before allowing a task to be dragged:

const scheduledTaskIds = computed(() =>
  new Set(events.value.map(e => e.linkedTaskId).filter(Boolean))
)

// In template: disable dragging for scheduled tasks
:draggable="!scheduledTaskIds.has(task.id)"

See apps/playground/pages/calendar-tasks.vue for the full example.

Colours

color (or a calendar's colour) takes either a Nuxt UI semantic colour, which follows the app theme:

primary · secondary · success · info · warning · error · neutral

or a Tailwind palette hue:

red · orange · amber · yellow · lime · green · emerald · teal · cyan · sky · blue · indigo · violet · purple · fuchsia · pink · rose

Palette hues are painted from fixed hex values, so they render whether or not the app's Tailwind build includes that colour. Without calendars, the event form offers a colour picker instead of a calendar select.

Need a Landing Page?

Modern landing pages with optional modules (blog, docs, forms, i18n). Let's discuss your project.

Build Your MVP

Full-stack SaaS development. Expert in database design, multi-tenancy, and scalable architecture.

Deployment Help

Dockerize your backend, set up CI/CD pipelines, deploy to Cloudflare or Hetzner. Early-stage setup.

Suggest a SaaS Tool

Missing a calculator or tool? Suggest what you'd like to see on our site.