Skip to content

TypeScript definitions

Ezyreka ships with TypeScript definitions at types/index.d.ts (the types field in package.json), so everything is typed out of the box.

ts
import { Editor, DesignDocument, EditorOptions } from 'ezyreka'

const options: EditorOptions = {
  target: '#app',
  width: 1080,
  height: 1080,
  name: 'Typed design'
}

const editor = new Editor(options)

editor.on('ready', () => {
  const el = editor.addElement({ type: 'rect', w: 200, h: 100 })
  editor.select([el.id])
})

Key exports

ExportDescription
EditorThe editor class
EditorOptionsConstructor options
DesignDocument / DesignPage / DesignElementDocument schema
PageBackgroundBackground union type
ChartConfig / ChartData / ChartSeries / ChartTypeChart types
GradientFill / GradientStopGradient fills
PaletteEntrystring | { label, colors }
EditorTemplateTemplate shape
ImageSourceImage provider contract
PanelDefinitionSidebar panel contract
HistoryLikeCustom history strategy contract
autoInitProgrammatic auto-init of data-ezr-editor elements
versionLibrary version

Typing a custom history

ts
import type { HistoryLike } from 'ezyreka'

const serverHistory: HistoryLike = {
  push(snapshot) { /* send to server */ },
  undo(current) { return previousSnapshot(current) },
  redo(current) { return nextSnapshot(current) },
  reset() { /* clear */ },
  canUndo() { return hasPrevious() },
  canRedo() { return hasNext() }
}

new Editor({ target: '#app', history: serverHistory })

Typing an image source

ts
import type { ImageSource } from 'ezyreka'

const provider: ImageSource = {
  id: 'brand',
  label: 'Brand assets',
  async search(query) {
    return [{ src: '/assets/logo.png', name: 'Logo', thumb: '/thumbs/logo.png' }]
  }
}

Typing a custom panel

ts
import type { PanelDefinition } from 'ezyreka'

const brandPanel: PanelDefinition = {
  id: 'brand',
  label: 'Brand kit',
  icon: '<svg viewBox="0 0 24 24">…</svg>',
  render(contentEl, editor) {
    const button = document.createElement('button')
    button.textContent = 'Add logo'
    button.onclick = () => editor.addElement({ type: 'image', src: '/assets/logo.png', w: 200, h: 60 })
    contentEl.append(button)
  }
}

editor.registerPanel(brandPanel)

Released under the MIT License.