Options
All
  • Public
  • Public/Protected
  • All
Menu

Class default

Main component to build editors. Each editor should receive the editron, which carries all required services for editor initialization

Usage

Instantiate the editron

import Editron from "editron";
// jsonSchema = { type: "object", required: ["title"], properties: { title: { type: "string" } } }
const editron = new Editron(jsonSchema);

or, using all parameters

 import Editron from "editron";
 // jsonSchema = { type: "object", required: ["title"], properties: { title: { type: "string" } } }
 // data = { title: "Hello" } - or simply use {}
 // options = { editors: [ complete list of custom editors ] }
 const editron = new Editron(jsonSchema, data, options);

and start rendering editors

 const editor = editron.createEditor("#", document.querySelector("#editor"));
 // render from title only: editron.createEditor("#/title", document.querySelector("#title"));

to fetch the generated data use

 const data = editron.getData();

Hierarchy

  • default

Index

Constructors

constructor

  • Create a new editron instance, which will be used to create ui-forms for specific data-points via editron.createEditor(pointer, dom);

    Parameters

    Returns default

Properties

Private #proxy

#proxy: default

editron proxy instance

addDefaultEditors

addDefaultEditors: boolean

set to true,

core

core: any

destroyed

destroyed: boolean = false

internal helper. Set to true, if editron has been destroyed

disabled

disabled: boolean = false

active state of editor

editors

editors: EditorPlugin[] = ...

list of editor-widgets to generate form for this instance

options

options: Options

final options used by this editron instance

plugins

plugins: Plugin[] = ...

list of active plugins for this instance

services

services: Services

list instantiated services

store

store: default

current state of errors, ui and data

Methods

addFormatValidator

  • Parameters

    • format: string

      value of format

    • validator: FormatValidator

      validator function receiving (core, schema, value, pointer). Return undefined for a valid value and an object {type: "error", message: "err-msg", data: { pointer }} as error. May als return a promise

    Returns void

addItemTo

  • addItemTo(pointer: string, index?: number): void
  • Request to insert a child item (within the data) at the given pointer. If multiple options are present, a dialogue is opened to let the user select the appropriate type of child (oneof).

    Parameters

    • pointer: string

      to array on which to insert the child

    • index: number = 0

      index within array, where the child should be inserted (does not replace). Default: 0

    Returns void

addKeywordValidator

  • addKeywordValidator(datatype: string, keyword: string, validator: KeywordValidator): void
  • Parameters

    • datatype: string

      JSON-Schema datatype to register attribute, e.g. "string" or "object"

    • keyword: string

      custom keyword

    • validator: KeywordValidator

      validator function receiving (core, schema, value, pointer). Return undefined for a valid value and an object {type: "error", message: "err-msg", data: { pointer }} as error. May als return a promise

    Returns void

createEditor

  • createEditor(pointer: string, element: HTMLElement, options?: any): Editor
  • throws

    The only entry point to create editors. Use in application and from editors to create (delegate) child editors

    Parameters

    • pointer: string

      data pointer to editor in current state

    • element: HTMLElement

      parent element of create editor. Will be appended automatically

    • Optional options: any

    Returns Editor

    created editor-instance or undefined;

createElement

  • createElement(selector: string, attributes?: any): HTMLElement
  • Helper to create dom elements via mithril syntax

    Parameters

    • selector: string

      a css selector describing the desired element

    • Optional attributes: any

      a map of dom attribute:value of the element (reminder className = class)

    Returns HTMLElement

    the resulting dom-element (not attached)

destroy

  • destroy(): void

destroyEditor

  • destroyEditor(editor: Editor): void
  • Call this method, to destroy your editors, deregistering its instance on editron

    Parameters

    • editor: Editor

      editor instance to remove

    Returns void

getData

  • getData(pointer?: string): any
  • Parameters

    • pointer: string = "#"

    Returns any

    data at the given location

getParentEditor

getPlugin

  • getPlugin(pluginId: string): Plugin

getRootEditor

getSchema

getStates

  • getStates(): (ExtractRematchStateFromModels<{ data: { reducers: { clearHistory: any; redo: any; removeLastUndo: any; set: any; undo: any }; state: DataState }; errors: { reducers: { set: any }; state: any[] } }> | ExtractRematchStateFromModels<{ ui: { reducers: { setCurrentPage: any; setCurrentPointer: any; showOverlay: any }; state: UIState } }>)[]
  • debug

    return editron and global-state

    Returns (ExtractRematchStateFromModels<{ data: { reducers: { clearHistory: any; redo: any; removeLastUndo: any; set: any; undo: any }; state: DataState }; errors: { reducers: { set: any }; state: any[] } }> | ExtractRematchStateFromModels<{ ui: { reducers: { setCurrentPage: any; setCurrentPointer: any; showOverlay: any }; state: UIState } }>)[]

isActive

  • isActive(): boolean

notifyPlugins

  • notifyPlugins(method: string, ...args: any[]): void
  • Parameters

    • method: string
    • Rest ...args: any[]

    Returns void

proxy

  • proxy(): default

registerEditor

  • Add additional editors to available editors for json-schema rendering. Note, that order is important. First editor to register, will be selected first. Registered editors will be added to start of list.

    Parameters

    • Rest ...editors: EditorPlugin[]

      one or many editors to add to start of editor-list

    Returns void

resetUndoRedo

  • resetUndoRedo(): void

service

  • service<T>(serviceName: T): Services[T]
  • Type parameters

    • T: "instances" | "data" | "validation" | "schema" | "location"

    Parameters

    • serviceName: T

    Returns Services[T]

setActive

  • setActive(active?: boolean): void
  • enable or disable the editor input-interaction

    Parameters

    • active: boolean = true

      if false, deactivates editor

    Returns void

setData

  • setData(data: any, options?: any): void
  • Set the application data

    Parameters

    • data: any

      json data matching registered json-schema

    • Optional options: any

    Returns void

setSchema

validateAll

  • validateAll(): void

Generated using TypeDoc