Skip to main content

Creating Custom Spells

Spells in Cedar-OS are created using the useSpell hook, which provides a declarative API for binding gestures to behaviors. This guide will walk you through creating custom spells from simple to advanced.

Basic Spell Structure

Every spell requires three core elements:

The useSpell Hook

The useSpell hook is your primary interface for creating spells:

Parameters

Return Values

Activation Conditions

Activation conditions define how users trigger your spell:

Events

Spells can respond to multiple event types:

Activation Modes

Control how your spell’s lifecycle works:

Complete Examples

Example 1: Command Palette Spell

A command palette that appears with Cmd+K:

Example 2: Context Menu Spell

A context menu that appears on right-click:

Example 3: AI Assistant Spell

A spell that integrates with Cedar’s AI capabilities:

Advanced Patterns

Combining Multiple Spells

You can compose multiple spells for complex interactions:

Dynamic Activation Conditions

Activation conditions can be changed dynamically:

Accessing Cedar Store

Spells can interact with the Cedar store for AI operations:

Best Practices

1. Use Descriptive IDs

2. Handle Cleanup

3. Prevent Conflicts

4. Provide Visual Feedback

5. Consider Accessibility

API Reference

Available Hotkeys

All single keys (A-Z, 0-9) plus:
  • Function keys: F1 - F12
  • Special keys: ESCAPE, ENTER, SPACE, TAB, DELETE, BACKSPACE
  • Arrow keys: ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT
  • Modifiers: CTRL, CMD, META, ALT, SHIFT

Mouse Events

  • RIGHT_CLICK - Right mouse button
  • DOUBLE_CLICK - Double left click
  • MIDDLE_CLICK - Middle mouse button
  • SHIFT_CLICK - Shift + left click
  • CTRL_CLICK - Ctrl + left click
  • CMD_CLICK - Cmd + left click (Mac)
  • ALT_CLICK - Alt + left click

Selection Events

  • TEXT_SELECT - Text selection in document

Next Steps