Skip to content

Angular

Package: velo-circuit · Adapter: velo-circuit/angular · Overview · Editor Presets

Use createAngularCircuitEditorAdapter() — three mount methods:

LevelMethod
DSL onlyadapter.mountDsl(container, options)
Canvas onlyadapter.mount(container, options)
DSL + canvas syncedadapter.mountWorkbench(dslEl, editorEl, options)

Setup

ts
import { createAngularCircuitEditorAdapter } from 'velo-circuit/angular'

const adapter = createAngularCircuitEditorAdapter()

DSL only

ts
// ngAfterViewInit
@ViewChild('dslHost') dslHost!: ElementRef<HTMLDivElement>

ngAfterViewInit() {
  this.dslField = this.adapter.mountDsl(this.dslHost.nativeElement, {
    initialDsl: 'R0-p(R1,C1)',
    themeMode: 'dark',
    onChange: (dsl) => this.dsl = dsl,
  })
}

ngOnDestroy() {
  this.dslField?.destroy()
}

Lite canvas

ts
@ViewChild('editorHost') editorHost!: ElementRef<HTMLDivElement>

ngAfterViewInit() {
  this.editor = this.adapter.mount(this.editorHost.nativeElement, {
    preset: 'lite',
    initialDsl: this.dsl,
    themeMode: 'dark',
  })
  this.editor.on('ast-changed', () => {
    this.dsl = this.editor.getValue()
  })
}

Workbench (synced)

ts
@ViewChild('dslHost') dslHost!: ElementRef<HTMLDivElement>
@ViewChild('editorHost') editorHost!: ElementRef<HTMLDivElement>

ngAfterViewInit() {
  this.workbench = this.adapter.mountWorkbench(
    this.dslHost.nativeElement,
    this.editorHost.nativeElement,
    {
      initialDsl: this.dsl,
      editorPreset: 'lite',
      themeMode: 'dark',
      onChange: (dsl) => (this.dsl = dsl),
    },
  )
}

ngOnDestroy() {
  this.workbench?.destroy()
}

Component helper (createComponent)

ts
this.circuit = this.adapter.createComponent(this.host.nativeElement, {
  preset: 'extended',
  initialDsl: 'R0',
})

this.circuit.dslChange.subscribe((dsl) => (this.dsl = dsl))

Static SVG

ts
import { renderDslPreviewSvg } from 'velo-circuit'

const svg = renderDslPreviewSvg(dsl, { themeMode: 'dark' })

Options

mount / mountWorkbenchTypeDefault
preset / editorPreset'extended' | 'lite' | 'minimal''extended' / 'lite'
themeMode'light' | 'dark'system
initialDslstring
onChange(dsl) => voidworkbench only