Default Configurator for Substance editors. It provides an API for adding nodes to the schema, components, commands and tools etc.
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.
schema | DocumentSchema | 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.
NodeClass | Node |
Adds a converter for a conversion format.
type | string | a conversion format type, eg. 'html', 'xml', 'json' |
converter | Object | a converter for that format. |
Add importer for a conversion format.
type | string | a conversion format type. eg. 'html', 'xml' |
ImporterClass | Object | an importer for the conversion format. |
Add exporter for a conversion format.
type | string | a conversion format type. eg. 'html', 'xml' |
ExporterClass | Object | 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.
nodeType | String | the type attribute of the node for which this component is to be used. |
ComponentClass | Class | A subclass of {@link Component} for nodes of nodeType. |
Adds an icon to the configuration which can be later retrieved via the iconProvider.
iconName | string | name or key for retrieving the icon |
options | Object | 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.
labelName | String | name of label. |
label | String | label. |
// 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.
seed | function | A transaction function that creates the seed document from an empty document. |
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.
editingBehavior. | EditingBehavior |
Configure this instance of configuration for provided package.
pkg | Object | Object should contain a |
options | Object | Additional options to pass to the package. |
configurator | returns the configurator instance to make it easy to chain calls to import. |