Missing API docs
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
# Step 1: Lua APIs
|
||||
The `common/space_lua/stdlib` folder contains implementations of the standard Lua library functions in TypeScript. These APIs should all be documented in a markdown format under `website/API` folder. The markdown files should be named after the Lua module they represent. For example, the `string` module should be documented in `website/API/string.md`.
|
||||
|
||||
Ignore the `printf` module, as it is not part of the standard Lua library.
|
||||
|
||||
Please compare the APIs implemented in TypeScript and make sure they appear in the API documentation. Add documentation for any missing APIs, follow the same format as the existing documentation.
|
||||
Please compare the APIs implemented in TypeScript and make sure they appear in the API documentation. Add documentation for any missing APIs, follow the same format as the existing documentation.
|
||||
|
||||
# Step 2: Syscall documentation
|
||||
Also in the `website/API` are markdown files for syscalls exposed in SilverBullet. Interfaces for all of theses are implemented under the `plug-api/syscalls/` folder. Each .ts file there should have a matching .md file under `website/API` documenting the APIs using the format similar to `website/API/editor.md`.
|
||||
|
||||
Check if all the syscalls defined in the .ts files are present under the API docs, and if not, add them.
|
||||
|
||||
For exising API documentation, verify if it is complete and no syscalls are missing. If it is missing, add it.
|
||||
@@ -0,0 +1,54 @@
|
||||
The Asset API provides functions for reading and managing assets embedded in plugs.
|
||||
|
||||
### asset.readAsset(plugName, name, encoding?)
|
||||
Reads an asset embedded in a plug.
|
||||
|
||||
Parameters:
|
||||
- `plugName`: Name of the plug to read asset from
|
||||
- `name`: Name of the asset to read
|
||||
- `encoding`: Optional encoding type, either "utf8" (default) or "dataurl"
|
||||
|
||||
Returns the content of the asset in the requested encoding.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
-- Read a text file as UTF-8
|
||||
local text = asset.readAsset("myplug", "data.txt")
|
||||
print(text)
|
||||
|
||||
-- Read an image as data URL
|
||||
local imageData = asset.readAsset("myplug", "image.png", "dataurl")
|
||||
print(imageData)
|
||||
```
|
||||
|
||||
### asset.listFiles(plugName)
|
||||
Lists all files in a plug.
|
||||
|
||||
Parameters:
|
||||
- `plugName`: Name of the plug to list files from
|
||||
|
||||
Returns an array of FileMeta objects containing information about each file.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local files = asset.listFiles("myplug")
|
||||
for _, file in ipairs(files) do
|
||||
print(file.name, file.size)
|
||||
end
|
||||
```
|
||||
|
||||
### asset.getFileMeta(plugName, name)
|
||||
Gets metadata about a specific file in a plug.
|
||||
|
||||
Parameters:
|
||||
- `plugName`: Name of the plug
|
||||
- `name`: Name of the file to get metadata for
|
||||
|
||||
Returns a FileMeta object containing information about the file.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local meta = asset.getFileMeta("myplug", "data.txt")
|
||||
print("File size:", meta.size)
|
||||
print("Last modified:", meta.lastModified)
|
||||
```
|
||||
@@ -0,0 +1,9 @@
|
||||
The Code Widget API provides functions for managing code widgets in the editor.
|
||||
|
||||
### codeWidget.refreshAll()
|
||||
Refreshes all code widgets on the current page that support refreshing.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
codeWidget.refreshAll() -- Refresh all code widgets on the page
|
||||
```
|
||||
+65
-7
@@ -1,10 +1,68 @@
|
||||
Can be configured anywhere, but preferred in [[CONFIG]].
|
||||
The Config API provides functions for managing configuration values.
|
||||
|
||||
## config.set(key, value)
|
||||
Set a config value
|
||||
### config.get(path, defaultValue)
|
||||
Gets a config value by path, with support for dot notation.
|
||||
|
||||
## config.get(key)
|
||||
Get a config value
|
||||
Parameters:
|
||||
- `path`: The path to get the value from
|
||||
- `defaultValue`: The default value to return if the path doesn't exist
|
||||
|
||||
## config.define(key, jsonSchema)
|
||||
Defines a JSON schema for a config key
|
||||
Example:
|
||||
```lua
|
||||
local theme = config.get("theme", "light")
|
||||
print("Current theme: " .. theme)
|
||||
```
|
||||
|
||||
### config.set(path, value)
|
||||
Sets a config value by path, with support for dot notation.
|
||||
|
||||
Parameters:
|
||||
- `path`: The path to set the value at
|
||||
- `value`: The value to set
|
||||
|
||||
Example:
|
||||
```lua
|
||||
config.set("theme", "dark")
|
||||
```
|
||||
|
||||
### config.set(values)
|
||||
Sets multiple config values at once.
|
||||
|
||||
Parameters:
|
||||
- `values`: An object containing key-value pairs to set
|
||||
|
||||
Example:
|
||||
```lua
|
||||
config.set({
|
||||
theme = "dark",
|
||||
fontSize = 14
|
||||
})
|
||||
```
|
||||
|
||||
### config.has(path)
|
||||
Checks if a config path exists.
|
||||
|
||||
Parameters:
|
||||
- `path`: The path to check
|
||||
|
||||
Example:
|
||||
```lua
|
||||
if config.has("theme") then
|
||||
print("Theme is configured")
|
||||
end
|
||||
```
|
||||
|
||||
### config.define(key, schema)
|
||||
Defines a JSON schema for a configuration key. The schema will be used to validate values when setting this key.
|
||||
|
||||
Parameters:
|
||||
- `key`: The configuration key to define a schema for
|
||||
- `schema`: The JSON schema to validate against
|
||||
|
||||
Example:
|
||||
```lua
|
||||
config.define("theme", {
|
||||
type = "string",
|
||||
enum = {"light", "dark"}
|
||||
})
|
||||
```
|
||||
@@ -11,6 +11,27 @@ Returns the meta data of the page currently open in the editor.
|
||||
Example:
|
||||
${editor.getCurrentPageMeta()}
|
||||
|
||||
### editor.getCurrentPath(extension?)
|
||||
Returns the name of the page or document currently open in the editor.
|
||||
|
||||
Parameters:
|
||||
- `extension`: If true, returns page paths with their `.md` extension
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local path = editor.getCurrentPath(true)
|
||||
print(path) -- prints: page.md
|
||||
```
|
||||
|
||||
### editor.getCurrentEditor()
|
||||
Returns the name of the currently open editor.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local editorName = editor.getCurrentEditor()
|
||||
print(editorName)
|
||||
```
|
||||
|
||||
### editor.getText()
|
||||
Returns the full text of the currently open page.
|
||||
|
||||
@@ -95,6 +116,27 @@ Example:
|
||||
editor.moveCursorToLine(1, 1, true) -- Move to start of first line
|
||||
```
|
||||
|
||||
### editor.save()
|
||||
Force saves the current page.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.save()
|
||||
```
|
||||
|
||||
### editor.navigate(ref, replaceState?, newWindow?)
|
||||
Navigates to the specified page reference.
|
||||
|
||||
Parameters:
|
||||
- `ref`: The page reference to navigate to
|
||||
- `replaceState`: Whether to replace the current history state
|
||||
- `newWindow`: Whether to open in a new window
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.navigate({ page: "other-page" })
|
||||
```
|
||||
|
||||
### editor.openPageNavigator(mode)
|
||||
Opens the page navigator.
|
||||
|
||||
@@ -111,6 +153,62 @@ Example:
|
||||
editor.openCommandPalette()
|
||||
```
|
||||
|
||||
### editor.reloadPage()
|
||||
Force reloads the current page.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.reloadPage()
|
||||
```
|
||||
|
||||
### editor.reloadUI()
|
||||
Force reloads the browser UI.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.reloadUI()
|
||||
```
|
||||
|
||||
### editor.rebuildEditorState()
|
||||
Rebuilds the editor state to ensure the dispatch updates the state.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.rebuildEditorState()
|
||||
```
|
||||
|
||||
### editor.reloadConfigAndCommands()
|
||||
Reloads the config and commands, also in the server.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.reloadConfigAndCommands()
|
||||
```
|
||||
|
||||
### editor.openUrl(url, existingWindow?)
|
||||
Opens the specified URL in the browser.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.openUrl("https://example.com")
|
||||
```
|
||||
|
||||
### editor.newWindow()
|
||||
Opens a new window.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.newWindow()
|
||||
```
|
||||
|
||||
### editor.goHistory(delta)
|
||||
Moves in the browser history.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.goHistory(-1) -- Go back
|
||||
```
|
||||
|
||||
### editor.showPanel(id, mode, html, script)
|
||||
Shows a panel in the editor.
|
||||
|
||||
@@ -160,6 +258,17 @@ Example:
|
||||
editor.copyToClipboard("Copied text")
|
||||
```
|
||||
|
||||
### editor.filterBox(label, options, helpText?, placeHolder?)
|
||||
Shows a filter box UI.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local result = editor.filterBox("Select:", {
|
||||
{ name: "Option 1", value: "1" },
|
||||
{ name: "Option 2", value: "2" }
|
||||
})
|
||||
```
|
||||
|
||||
### editor.toggleFold()
|
||||
Toggles code folding at the current position.
|
||||
|
||||
@@ -184,9 +293,106 @@ Example:
|
||||
editor.unfoldAll()
|
||||
```
|
||||
|
||||
### editor.undo()
|
||||
Undoes the last change.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.undo()
|
||||
```
|
||||
|
||||
### editor.redo()
|
||||
Redoes the last undone change.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.redo()
|
||||
```
|
||||
|
||||
### editor.openSearchPanel()
|
||||
Opens the editor's search panel.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.openSearchPanel()
|
||||
```
|
||||
|
||||
### editor.deleteLine()
|
||||
Deletes the current line.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.deleteLine()
|
||||
```
|
||||
|
||||
### editor.moveLineUp()
|
||||
Moves the current line up.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.moveLineUp()
|
||||
```
|
||||
|
||||
### editor.moveLineDown()
|
||||
Moves the current line down.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.moveLineDown()
|
||||
```
|
||||
|
||||
### editor.vimEx(exCommand)
|
||||
Executes a Vim ex command.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.vimEx(":w")
|
||||
```
|
||||
|
||||
### editor.sendMessage(type, data?)
|
||||
Sends a message to the editor.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.sendMessage("custom-event", { data: "value" })
|
||||
```
|
||||
|
||||
### editor.prompt(message, defaultValue?)
|
||||
Shows a prompt dialog.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local result = editor.prompt("Enter your name:", "John")
|
||||
```
|
||||
|
||||
### editor.confirm(message)
|
||||
Shows a confirmation dialog.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local confirmed = editor.confirm("Are you sure?")
|
||||
```
|
||||
|
||||
### editor.alert(message)
|
||||
Shows an alert dialog.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.alert("Operation completed")
|
||||
```
|
||||
|
||||
### editor.getUiOption(key)
|
||||
Gets a UI option value.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local theme = editor.getUiOption("theme")
|
||||
```
|
||||
|
||||
### editor.setUiOption(key, value)
|
||||
Sets a UI option value.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
editor.setUiOption("theme", "dark")
|
||||
```
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
The Lua API provides functions for parsing and evaluating Lua code.
|
||||
|
||||
### lua.parse(code)
|
||||
Parses a string of Lua code into an abstract syntax tree (AST).
|
||||
|
||||
Parameters:
|
||||
- `code`: The Lua code to parse
|
||||
|
||||
Returns a LuaBlock object representing the parsed code.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local ast = lua.parse("print('Hello')")
|
||||
-- ast contains the parsed syntax tree
|
||||
```
|
||||
|
||||
### lua.parseExpression(expression)
|
||||
Parses a Lua expression into an abstract syntax tree (AST).
|
||||
|
||||
Parameters:
|
||||
- `expression`: The Lua expression to parse
|
||||
|
||||
Returns a LuaExpression object representing the parsed expression.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local expr = lua.parseExpression("1 + 2 * 3")
|
||||
-- expr contains the parsed expression tree
|
||||
```
|
||||
|
||||
### lua.evalExpression(expression)
|
||||
Evaluates a Lua expression and returns its result.
|
||||
|
||||
Parameters:
|
||||
- `expression`: The Lua expression to evaluate
|
||||
|
||||
Returns the result of evaluating the expression.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local result = lua.evalExpression("1 + 2 * 3")
|
||||
print(result) -- prints: 7
|
||||
```
|
||||
@@ -0,0 +1,40 @@
|
||||
The Shell API provides functions for running shell commands and interacting with processes.
|
||||
|
||||
### shell.run(cmd, args)
|
||||
Runs a shell command and returns its output.
|
||||
|
||||
Parameters:
|
||||
- `cmd`: The command to run
|
||||
- `args`: Array of arguments to pass to the command
|
||||
|
||||
Returns an object with:
|
||||
- `stdout`: The standard output of the command
|
||||
- `stderr`: The standard error of the command
|
||||
- `code`: The exit code of the command
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local result = shell.run("ls", {"-l"})
|
||||
print("Output:", result.stdout)
|
||||
print("Error:", result.stderr)
|
||||
print("Exit code:", result.code)
|
||||
```
|
||||
|
||||
### shell.spawn(cmd, args)
|
||||
Runs a shell command with streaming I/O, allowing interaction with the process.
|
||||
|
||||
Parameters:
|
||||
- `cmd`: The command to run
|
||||
- `args`: Array of arguments to pass to the command
|
||||
|
||||
Returns a ShellStream object with methods:
|
||||
- `send(data)`: Send data to the process stdin
|
||||
- `kill(signal)`: Send a signal to the process
|
||||
- `close()`: Close the connection
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local stream = shell.spawn("cat", {})
|
||||
stream.send("Hello\n")
|
||||
stream.close()
|
||||
```
|
||||
+19
-3
@@ -83,6 +83,19 @@ print("SilverBullet version: " .. version)
|
||||
|
||||
## Configuration
|
||||
|
||||
### system.getConfig(key, defaultValue?)
|
||||
Gets a configuration value.
|
||||
|
||||
Parameters:
|
||||
- `key`: The configuration key to get
|
||||
- `defaultValue`: Optional default value if the key is not set
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local theme = system.getConfig("theme", "light")
|
||||
print("Current theme: " .. theme)
|
||||
```
|
||||
|
||||
### system.reloadConfig()
|
||||
Triggers an explicit reload of the configuration.
|
||||
|
||||
@@ -99,13 +112,16 @@ Example:
|
||||
```lua
|
||||
system.reloadPlugs()
|
||||
print("All plugs reloaded")
|
||||
```
|
||||
|
||||
|
||||
## system.wipeClient()
|
||||
### system.wipeClient(logout?)
|
||||
Completely wipes the client state, including cached files, service worker and databases.
|
||||
|
||||
Parameters:
|
||||
- `logout`: Optional boolean to also log out the user
|
||||
|
||||
Example:
|
||||
```lua
|
||||
system.wipeClient()
|
||||
system.wipeClient(true) -- Wipe client and log out
|
||||
print("Client state has been reset")
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user