SDK 0.1.1 is tagged v0.1.1 in the public SDK repository. It adds the action icons duplicate, template, and tab, and the optional URL of the browser contribution's newTab.
RuneStone Plugin SDK
@runestone/plugin-sdk gives TypeScript types and small helpers for RuneStone plugins.
RuneStone is a desktop workspace for Markdown notes, code, and project work. Plugins add views, commands, and document editors to it.
The SDK contains:
- The types of the plugin API:
PluginApiand its members, theplugin.jsonmanifest, commands, views, document types, menus, and contributions API_VERSION, the plugin API version that the SDK describes- Feature checks for API members that older RuneStone versions do not have
- The RuneStone action icons and the tooltip helper, as DOM functions
The SDK does not run plugins and does not call RuneStone. RuneStone gives the api object to your plugin at activation.
Install
Install the SDK from a release tag of its Git repository. The SDK is not on the npm registry.
pnpm add -D "git+https://git.knottywyvern.com/kwyvern/RuneStone_Plugin_SDK.git#v0.1.1"
The result in package.json:
{
"devDependencies": {
"@runestone/plugin-sdk": "git+https://git.knottywyvern.com/kwyvern/RuneStone_Plugin_SDK.git#v0.1.1"
}
}
The repository is public, so you need no access token and no .npmrc file. npm and Yarn accept the same URL.
Always give a tag. Without a tag, the package manager uses the latest commit, and your build can change without notice.
The package contains compiled JavaScript and declaration files, so the installation runs no build step.
Use TypeScript 5.0 or later, with moduleResolution set to bundler, node16, or nodenext. Include the DOM library.
Write a plugin
A plugin is one JavaScript module that exports activate(api). This example adds a view and a command that opens it.
import type { PluginApi } from "@runestone/plugin-sdk";
export function activate(api: PluginApi) {
api.registerView({
id: "hello",
title: "Hello",
mount(container) {
const text = document.createElement("p");
text.textContent = "Hello from a RuneStone plugin.";
container.append(text);
return () => text.remove();
},
});
api.registerCommand({ id: "show-hello", title: "Show hello", icon: "puzzle", run: () => api.openView("hello") });
}
Compile the module with a bundler, so the entry file contains the SDK helpers that it uses. RuneStone loads the entry from a Blob URL, so imports from node_modules do not resolve at run time.
Then make the plugin ZIP. See Build and package a plugin.
A type-only import, such as import type { PluginApi }, adds no code to the bundle.
Check for features
Members marked optional in PluginApi can be absent on older RuneStone versions. Examples are api.pty, api.files, and api.workspace.readBytes.
Make sure that a member exists before you use it.
import { hasFeature, requireFeature, requireFeatures, type PluginApi } from "@runestone/plugin-sdk";
export function activate(api: PluginApi) {
// Stop the activation with one message that names each missing feature.
requireFeatures(api, ["pty", "workspace.readOptional"]);
const pty = requireFeature(api, "pty");
// Hide a control when the feature is absent.
if (hasFeature(api, "ui.showActionMenu")) showMenuButton();
}
| Function | Result |
|---|---|
hasFeature(api, feature) |
true when RuneStone gives the member |
missingFeatures(api, features) |
The features of the list that RuneStone does not give |
requireFeature(api, feature) |
The member, with its type. A function stays bound to its object. |
requireFeatures(api, features) |
Nothing. Throws one error for all missing features. |
When a feature is missing, requireFeature and requireFeatures throw a MissingFeatureError. Its features property lists the feature names.
Its message names each feature and its API path, and tells the user to update RuneStone. For example:
This plugin needs the terminal API (api.pty). Update RuneStone to a version that has this feature.
pluginFeatures lists all the feature names. The checks examine only whether the member exists.
Icons and tooltips
RuneStone has no API for icons or tooltips. The SDK gives the host code as DOM functions, so your controls look and behave like the RuneStone controls.
import { actionIcon } from "@runestone/plugin-sdk/icons";
import { attachTooltip } from "@runestone/plugin-sdk/tooltip";
const button = document.createElement("button");
button.setAttribute("aria-label", "Refresh");
button.append(actionIcon("refresh"));
const removeTooltip = attachTooltip(button, () => "Refresh");
| Import | Contents |
|---|---|
@runestone/plugin-sdk/icons |
actionIcons, the SVG markup of each icon. actionIcon(name) makes an SVG element with the action-icon class. |
@runestone/plugin-sdk/tooltip |
attachTooltip(element, label) shows a tooltip on hover and keyboard focus. It returns a cleanup function. |
RuneStone styles the action-icon and rs-tooltip classes. Call the cleanup function of each tooltip when your view closes.
For menus, call api.ui.showActionMenu. RuneStone draws the menu, so the SDK contains only its types: ActionMenuItem and ActionMenuOptions.
Versions
The SDK has its own version number in the form zz.yy.xx, for example 0.1.0. Each release has the tag v<version>.
A hotfix adds a lowercase letter to the version, for example 0.1.0a.
API_VERSION is the apiVersion value of plugin.json. The SDK version and the RuneStone version are different numbers.
A new SDK release can add types for new RuneStone features. Use the feature checks for features that older RuneStone versions do not have.
Documentation and help
- Plugin development reference: the package format, the API, and the build procedure
- Completion API
- Install and manage plugins
- Release policy
The SDK source is in the packages/plugin-sdk folder of the RuneStone repository. Report problems there.
This repository holds only the released files.
Knotty Wyvern maintains RuneStone and the SDK.