This doc deals with building plugins for Wisk, a web-based note-taking app. Plugins are self-contained components that can be added to the editor to extend its functionality. The Wisk API provides a way to interact with the editor and the database, as well as to manage themes.
The Wisk API is accessible through the window.wisk
object, which serves as the host for the Wisk API. It contains the following main components:
The window.wisk.plugins
object provides the following methods and properties:
defaultPlugins
: An array of default pluginsloadedPlugins
: An array of loaded pluginsloadPlugin(plugin)
: Loads a plugin (internal method)pluginData
: An object containing plugin dataA plugin is a JavaScript object with the following properties:
name
: The name of the plugintitle
: The title of the pluginicon
: The icon of the plugintags
: An array of tags for the plugindescription
: A description of the plugincontents
: An array of componentsEach component in the contents
array is an object with the following properties:
title
: The title of the contenticon
: Displayed when installing the plugincategory
: Determines how the component will be shown (see details below)component
: Self-contained web componentnav
: Whether the icon should appear in the nav barmodule
: Whether the content should be loaded as a moduletextual
: Whether the content should be loaded as text (when true, the component shows a selector and the value is copied completely)The category
property determines how the component will be shown. It can be any one of the following:
mini-dialog
: A mini dialogfull-dialog
: A full dialogright-sidebar
: A right sidebarleft-sidebar
: A left sidebarelement
: An element in editorcontext-box
: Appears when text is selectedno-gui
: No GUI, just a function that runs in the background"example": {
"example": {
"name": "example",
"title": "Example",
"icon": "access-manager.svg",
"tags": ["example", "demo"],
"description": "An example plugin",
"contents": [
{
"title": "Example",
"icon": "example.svg",
"category": "mini-dialog",
"component": "example",
"nav": false,
"module": false,
"textual": true
}
]
}
}
Plugins can have the following optional methods:
installed
: Runs when the plugin is installed (should be in the first content of the plugin)uninstalled
: Runs when the plugin is uninstalled (should be in the first content of the plugin)load
: Runs when the component is loaded, initializes the component if neededunload
: Runs when the component is unloadedfocus
: Runs when the component is focusedblur
: Runs when the component is blurredfocusOnCaret
: Runs when the component should focus on the caret (only for textual components)Plugins can run these functions to interact with the editor and/or other plugins:
showSelector: function(elementId) {}
createNewBlock: function(elementId, blockType, value) {}
deleteBlock: function(elementId) {}
focusBlock: function(elementId, identifier) {}
updateBlock: function(elementId, path, value) {}
runBlockFunction: function(elementId, functionName, value) {}
justUpdates: function(elementId, value) {}
Wisk supports a key-value store database. The following methods are available: // change to getPages etc
getItems(pageId)
: Gets all items for a pagesetItem(pageId, value)
: Sets an item for a pageremoveItem(pageId)
: Removes an item for a pagegetAllItems()
: Gets all itemsTheme data is stored locally in the browser. The window.wisk.theme
object supports the following methods:
setTheme(theme)
: Sets the themegetTheme()
: Gets the current themegetThemes()
: Gets all themesgetThemeData()
: Gets the data for a themeThe window.wisk.editor
object supports these properties and methods:
showSelector(elementId)
: Shows the selector for element typenewElement
: TODOchangeElement
: TODOpageId
: The current page idelementIds
: An array of element ids