API Reference
Spell Book works both in CEP and UXP platforms.
It consists of application and extension, which acts as a bridge between Spell Book app and your extension. Use npm modules, both for CEP and UXP, that provide interface for commands registration and handling command event.
Installation
Make sure that Spell Book is installed (both app and Spell Book extension).
Installation
npm install @knights-of-the-editing-table/spell-bookUsage
// code.js
import Spellbook from '@knights-of-the-editing-table/spell-book';
const commands = [
{
commandID: 'command.id',
// name: use localised name if needed
name: 'Command 1',
// group: optional
group: 'Group 1',
// action runs when command is triggered
action: () => {
console.log('command.id triggered!')
}
}
];
const spellbook = new Spellbook('Extension name', 'extension.id', commands);Make sure that Spell Book is installed (both app and Spell Book extension).
Installation
npm install @knights-of-the-editing-table/spell-book-uxpUsage
Add command entrypoint and enablePluginCommunication to manifest.json, for Inter Plugin Communication:
// manifest.json
{
"entrypoints": [
{
"type": "command",
"id": "spellbook.plugin",
"label": {
"default": "- spellbook plugin" // you can use your label
}
}
],
"requiredPermissions": {
"ipc": {
"enablePluginCommunication": true
}
}
}Add Spell Book plugin:
// code.js
import Spellbook from '@knights-of-the-editing-table/spell-book-uxp';
const commands = [
{
commandID: 'command.id',
// name: use localised name if needed
name: 'Command 1',
// group: optional
group: 'Group 1',
// action runs when command is triggered
action: () => {
console.log('command.id triggered!')
}
}
];
const spellbook = new Spellbook('Extension name', 'extension.id', commands);
// add spellbook.plugin to entry points
const { entrypoints } = require("uxp");
entrypoints.setup({
commands: {
'spellbook.plugin': {
run: (data, args) => spellbook.plugin(data, args),
},
},
});Spellbook constructor
const spellbook = new Spellbook(
pluginName: string,
pluginID: string,
commands?: Command[])Methods
// Add or update commands
spellbook.register(commands)
// Start listening for command events
spellbook.start()
// Stop listening for command events
spellbook.stop()Events
The plugin extends EventEmitter and emits events when commands are triggered:
spellbook.on('command.id', (commandID) => {
console.log('command.id triggered!')
});Last updated