Configurator
Class defined in util/Configurator.js#55

Default Configurator for Substance editors. It provides an API for adding nodes to the schema, components, commands and tools etc.

Example
let configurator = new Configurator()

configurator.addNode(Heading)
configurator.addComponent('heading', HeadingComponent)

To modularize configuration, package definitions can be imported.

configurator.import(ParagraphPackage)

You can create your own extensions that way.


const AlienPackage = {
  name: 'alien'
  configure: function(config) {
    config.addNode(AlienNode)
    config.addComponent('alien', AlienComponent)
    config.addCommand('add-alien', AddAlienCommand)
    config.addTool('add-alien', AddAlienTool)
  }
}

From within a package, another package can be imported. This provides a simple mechanism to model dependencies between packages. Just make sure you don't run into cyclic dependencies as there is no checking for that at the moment.

Defines the document schema for this configuration.

Parameters
schemaDocumentSchema

A schema to be used for articles created from this configuration.

Adds a node to this configuration. Later, when you use Configurator#getSchema(), this node will be added to that schema. Usually, used within a package to add its own nodes to the schema.

Parameters
NodeClassNode

Adds a converter for a conversion format.

Parameters
typestring

a conversion format type, eg. 'html', 'xml', 'json'

converterObject

a converter for that format.

Add importer for a conversion format.

Parameters
typestring

a conversion format type. eg. 'html', 'xml'

ImporterClassObject

an importer for the conversion format.

Add exporter for a conversion format.

Parameters
typestring

a conversion format type. eg. 'html', 'xml'

ExporterClassObject

an exporter for the conversion format.

Add a component for a node type. Components (Component) are the ui representation of a node for rendering and manipulation. This is usually used within a package to add representations for nodes added by that package.

A component can be added once per nodeType. If you provide two components for the same node type, Substance can't figure out which one to use.

Parameters
nodeTypeString

the type attribute of the node for which this component is to be used.

ComponentClassClass

A subclass of {@link Component} for nodes of nodeType.

Adds an icon to the configuration which can be later retrieved via the iconProvider.

Parameters
iconNamestring

name or key for retrieving the icon

optionsObject

your custom method of representing the icon as a JSON object. Enables plugging in your own IconProvider.

Define a new label Label is either a string or a hash with translations. If string is provided 'en' is used as the language.

Parameters
labelNameString

name of label.

labelString

label.

Example
// Using english only.
config.addLabel('paragraph.content', 'Paragraph')

// Using multiple languages
config.addLabel('superscript', {
  en: 'Superscript',
  de: 'Hochgestellt'
})

.
.
// Usage within other code
let labels = this.context.labelProvider
$$('span').append(labels.getLabel('superscript'))

Replaces the seed function for this configuration.

Use a seed function to create the empty state for your document. This should be used only once per configuration. You shouldn't call this within package config methods.

You can use Configurator#getSeed method to get this seed and apply it on your document Document class.

Parameters
seedfunction

A transaction function that creates the seed document from an empty document.

Example
var seedFn = function(tx) {
  var body = tx.get('body')

  tx.create({
    id: 'p1',
    type: 'paragraph',
    content: 'This is your new paragraph!'
  })
  body.show('p1')
}

config.addSeed(seedFn)

Adds an editing behavior to this configuration. EditingBehavior for more.

Parameters
editingBehavior.EditingBehavior

Configure this instance of configuration for provided package.

Parameters
pkgObject

Object should contain a configure method that takes a Configurator instance as the first method.

optionsObject

Additional options to pass to the package.configure method

Returns
configurator

returns the configurator instance to make it easy to chain calls to import.