diff --git a/website/API/clientStore.md b/website/API/clientStore.md new file mode 100644 index 00000000..0c824f0c --- /dev/null +++ b/website/API/clientStore.md @@ -0,0 +1,28 @@ +The Client Store API provides a simple key-value store for client-specific states and preferences. + +# Client Store API + +## clientStore.set(key, value) +Sets a value in the client store. + +Example: +```lua +clientStore.set("theme", "dark") +``` + +## clientStore.get(key) +Gets a value from the client store. + +Example: +```lua +local theme = clientStore.get("theme") +print("Current theme: " .. theme) +``` + +## clientStore.del(key) +Deletes a value from the client store. + +Example: +```lua +clientStore.del("theme") +``` \ No newline at end of file diff --git a/website/API/datastore.md b/website/API/datastore.md new file mode 100644 index 00000000..09b25b78 --- /dev/null +++ b/website/API/datastore.md @@ -0,0 +1,66 @@ +# Datastore API + +The Datastore API provides functions for interacting with a key-value store that has query capabilities. + +## Key-Value Operations + +### datastore.set(key, value) +Sets a value in the key-value store. + +Example: +```lua +datastore.set("user:123", {name = "John", age = 30}) +``` + +### datastore.get(key) +Gets a value from the key-value store. + +Example: +```lua +local user = datastore.get("user:123") +print(user.name) -- prints "John" +``` + +### datastore.del(key) +Deletes a value from the key-value store. + +Example: +```lua +datastore.del("user:123") +``` + +## Batch Operations + +### datastore.batch_set(kvs) +Sets multiple key-value pairs in a single operation. + +Example: +```lua +local kvs = { + {key = "user:1", value = {name = "Alice"}}, + {key = "user:2", value = {name = "Bob"}} +} +datastore.batch_set(kvs) +``` + +### datastore.batch_get(keys) +Gets multiple values in a single operation. + +Example: +```lua +local keys = {"user:1", "user:2"} +local values = datastore.batch_get(keys) +for _, value in ipairs(values) do + print(value.name) +end +``` + +### datastore.batch_del(keys) +Deletes multiple values in a single operation. + +Example: +```lua +local keys = {"user:1", "user:2"} +datastore.batch_del(keys) +``` + diff --git a/website/API/debug.md b/website/API/debug.md new file mode 100644 index 00000000..52d36775 --- /dev/null +++ b/website/API/debug.md @@ -0,0 +1,21 @@ +# Debug API + +The Debug API provides functions for debugging and resetting the application state. + +## debug.reset_client() +Completely wipes the client state, including cached files and databases. + +Example: +```lua +debug.reset_client() +print("Client state has been reset") +``` + +## debug.cleanup() +Wipes the entire state KV store and the entire space KV store. + +Example: +```lua +debug.cleanup() +print("All KV stores have been wiped") +``` \ No newline at end of file diff --git a/website/API/editor.md b/website/API/editor.md new file mode 100644 index 00000000..5d18e21f --- /dev/null +++ b/website/API/editor.md @@ -0,0 +1,282 @@ +# Editor API + +The Editor API provides functions for interacting with the editor interface, including text manipulation, cursor control, and UI operations. + +## Page Operations + +### editor.get_current_page() +Returns the name of the page currently open in the editor. + +Example: +```lua +local page = editor.get_current_page() +print("Current page: " .. page) +``` + +### editor.get_current_page_meta() +Returns the meta data of the page currently open in the editor. + +Example: +```lua +local meta = editor.get_current_page_meta() +print("Last modified: " .. meta.last_modified) +``` + +## Text Operations + +### editor.get_text() +Returns the full text of the currently open page. + +Example: +```lua +local text = editor.get_text() +print("Document length: " .. #text) +``` + +### editor.set_text(text, isolate_history) +Updates the editor text while preserving cursor location. + +Example: +```lua +local text = editor.get_text() +editor.set_text(text:upper(), false) -- Convert to uppercase +``` + +### editor.insert_at_pos(text, pos) +Insert text at the specified position. + +Example: +```lua +editor.insert_at_pos("Hello!", 0) -- Insert at beginning +``` + +### editor.replace_range(from, to, text) +Replace text in the specified range. + +Example: +```lua +editor.replace_range(0, 5, "New text") +``` + +### editor.insert_at_cursor(text) +Insert text at the current cursor position. + +Example: +```lua +editor.insert_at_cursor("Inserted at cursor") +``` + +## Cursor Control + +### editor.get_cursor() +Returns the cursor position as character offset. + +Example: +```lua +local pos = editor.get_cursor() +print("Cursor at position: " .. pos) +``` + +### editor.get_selection() +Returns the current selection range. + +Example: +```lua +local sel = editor.get_selection() +print("Selection from " .. sel.from .. " to " .. sel.to) +``` + +### editor.set_selection(from, to) +Sets the current selection range. + +Example: +```lua +editor.set_selection(0, 10) -- Select first 10 characters +``` + +### editor.move_cursor(pos, center) +Move the cursor to a specific position. + +Example: +```lua +editor.move_cursor(0, true) -- Move to start and center +``` + +### editor.move_cursor_to_line(line, column, center) +Move the cursor to a specific line and column. + +Example: +```lua +editor.move_cursor_to_line(1, 1, true) -- Move to start of first line +``` + +## Navigation + +### editor.navigate(page_ref, replace_state, new_window) +Navigates to the specified page. + +Example: +```lua +editor.navigate({page = "welcome"}, false, false) +``` + +### editor.open_page_navigator(mode) +Opens the page navigator. + +Example: +```lua +editor.open_page_navigator("page") +``` + +### editor.open_command_palette() +Opens the command palette. + +Example: +```lua +editor.open_command_palette() +``` + +## UI Operations + +### editor.show_panel(id, mode, html, script) +Shows a panel in the editor. + +Example: +```lua +editor.show_panel("rhs", 1, "

Hello

") +``` + +### editor.hide_panel(id) +Hides a panel in the editor. + +Example: +```lua +editor.hide_panel("rhs") +``` + +### editor.flash_notification(message, type) +Shows a flash notification. + +Example: +```lua +editor.flash_notification("Operation completed", "info") +``` + +### editor.prompt(message, default_value) +Prompts the user for input. + +Example: +```lua +local name = editor.prompt("Enter your name:", "") +print("Hello, " .. name) +``` + +### editor.confirm(message) +Shows a confirmation dialog. + +Example: +```lua +if editor.confirm("Are you sure?") then + print("User confirmed") +end +``` + +## File Operations + +### editor.download_file(filename, data_url) +Triggers a file download in the browser. + +Example: +```lua +editor.download_file("test.txt", "data:text/plain;base64,SGVsbG8=") +``` + +### editor.upload_file(accept, capture) +Opens a file upload dialog. + +Example: +```lua +local file = editor.upload_file(".txt", nil) +print("Uploaded: " .. file.name) +``` + +## Clipboard Operations + +### editor.copy_to_clipboard(data) +Copies data to the clipboard. + +Example: +```lua +editor.copy_to_clipboard("Copied text") +``` + +## Code Folding + +### editor.fold() +Folds code at the current cursor position. + +Example: +```lua +editor.fold() +``` + +### editor.unfold() +Unfolds code at the current cursor position. + +Example: +```lua +editor.unfold() +``` + +### editor.toggle_fold() +Toggles code folding at the current position. + +Example: +```lua +editor.toggle_fold() +``` + +### editor.fold_all() +Folds all foldable regions. + +Example: +```lua +editor.fold_all() +``` + +### editor.unfold_all() +Unfolds all folded regions. + +Example: +```lua +editor.unfold_all() +``` + +## History Operations + +### editor.undo() +Undoes the last edit operation. + +Example: +```lua +editor.undo() +``` + +### editor.redo() +Redoes the last undone operation. + +Example: +```lua +editor.redo() +``` + +## Search Operations + +### editor.open_search_panel() +Opens the editor's search panel. + +Example: +```lua +editor.open_search_panel() +``` + diff --git a/website/API/event.md b/website/API/event.md new file mode 100644 index 00000000..9b6dc45e --- /dev/null +++ b/website/API/event.md @@ -0,0 +1,31 @@ +# Event API + +The Event API provides functions for working with SilverBullet's event bus system, allowing communication between different parts of the application. + +## Event Operations + +### event.dispatch_event(event_name, data, timeout) +Triggers an event on the SilverBullet event bus. Event handlers can return values, which are accumulated and returned to the caller. + +Example: +```lua +-- Simple event dispatch +event.dispatch_event("custom.event", {message = "Hello"}) + +-- Event dispatch with timeout and response handling +local responses = event.dispatch_event("data.request", {id = 123}, 5000) +for _, response in ipairs(responses) do + print(response) +end +``` + +### event.list_events() +Lists all events currently registered (listened to) on the SilverBullet event bus. + +Example: +```lua +local events = event.list_events() +for _, event_name in ipairs(events) do + print("Registered event: " .. event_name) +end +``` \ No newline at end of file diff --git a/website/API/jsonschema.md b/website/API/jsonschema.md new file mode 100644 index 00000000..09091c06 --- /dev/null +++ b/website/API/jsonschema.md @@ -0,0 +1,48 @@ +# JSON Schema API + +The JSON Schema API provides functions for validating JSON objects against JSON schemas. + +## Validation Operations + +### jsonschema.validate_object(schema, object) +Validates a JSON object against a JSON schema. + +Example: +```lua +local schema = { + type = "object", + properties = { + name = {type = "string"}, + age = {type = "number", minimum = 0} + }, + required = {"name"} +} + +local object = {name = "John", age = 30} +local error = jsonschema.validate_object(schema, object) +if error then + print("Validation error: " .. error) +else + print("Object is valid") +end +``` + +### jsonschema.validate_schema(schema) +Validates a JSON schema itself to ensure it's well-formed. + +Example: +```lua +local schema = { + type = "object", + properties = { + name = {type = "string"} + } +} + +local error = jsonschema.validate_schema(schema) +if error then + print("Schema error: " .. error) +else + print("Schema is valid") +end +``` \ No newline at end of file diff --git a/website/API/language.md b/website/API/language.md new file mode 100644 index 00000000..c16e1214 --- /dev/null +++ b/website/API/language.md @@ -0,0 +1,28 @@ +The Language API provides functions for parsing code in various programming languages and listing supported languages. + +## Language Operations + +### language.parse_language(language, code) +Parses a piece of code using any of the supported SilverBullet languages. + +Example: +```lua +local code = [[ +function hello() { + console.log("Hello, world!"); +} +]] + +local tree = language.parse_language("javascript", [[ +function hello() { + console.log("Hello, world!"); +} +]]) +print("Parsed syntax tree:", tree) +``` + +### language.list_languages() +Lists all supported languages in fenced code blocks. + +Example: +${language.list_languages()} \ No newline at end of file diff --git a/website/API/markdown.md b/website/API/markdown.md new file mode 100644 index 00000000..579e91a9 --- /dev/null +++ b/website/API/markdown.md @@ -0,0 +1,32 @@ +# Markdown API + +The Markdown API provides functions for parsing and rendering Markdown content. + +## Markdown Operations + +### markdown.parse_markdown(text) +Parses a piece of markdown text into a ParseTree. + +Example: +```lua +local text = [[ +# Hello World + +This is a **bold** statement. +]] + +local tree = markdown.parse_markdown(text) +print("Parsed markdown tree:", tree) +``` + +### markdown.render_parse_tree(tree) +Renders a ParseTree back to markdown text. + +Example: +```lua +local text = "# Title\n\nSome text" +local tree = markdown.parse_markdown(text) +-- Modify tree if needed +local rendered = markdown.render_parse_tree(tree) +print("Rendered markdown:", rendered) +``` \ No newline at end of file diff --git a/website/API/mq.md b/website/API/mq.md new file mode 100644 index 00000000..75f6d235 --- /dev/null +++ b/website/API/mq.md @@ -0,0 +1,54 @@ +# Message Queue API + +The Message Queue API provides functions for implementing a simple message queue system. + +## Message Operations + +### mq.send(queue, body) +Sends a message to a queue. + +Example: +```lua +mq.send("tasks", {type = "process", data = "sample"}) +``` + +### mq.batch_send(queue, bodies) +Sends multiple messages to a queue in a single operation. + +Example: +```lua +local messages = { + {type = "task1", data = "sample1"}, + {type = "task2", data = "sample2"} +} +mq.batch_send("tasks", messages) +``` + +### mq.ack(queue, id) +Acknowledges a message from a queue, marking it as processed. + +Example: +```lua +mq.ack("tasks", "message-123") +``` + +### mq.batch_ack(queue, ids) +Acknowledges multiple messages from a queue in a single operation. + +Example: +```lua +local messageIds = {"msg1", "msg2", "msg3"} +mq.batch_ack("tasks", messageIds) +``` + +## Queue Management + +### mq.get_queue_stats(queue) +Retrieves statistics about a particular queue. + +Example: +```lua +local stats = mq.get_queue_stats("tasks") +print("Queue size: " .. stats.size) +print("Processing: " .. stats.processing) +``` \ No newline at end of file diff --git a/website/API/shell.md b/website/API/shell.md new file mode 100644 index 00000000..39184a9d --- /dev/null +++ b/website/API/shell.md @@ -0,0 +1,12 @@ +The Shell API provides functions for running shell commands. + +### shell.run(cmd, args) +Runs a shell command with the specified arguments. + +Example: +```lua +local result = shell.run("ls", {"-la"}) +print("Output: " .. result.stdout) +print("Errors: " .. result.stderr) +print("Exit code: " .. result.code) +``` \ No newline at end of file diff --git a/website/API/space.md b/website/API/space.md new file mode 100644 index 00000000..9afb7f37 --- /dev/null +++ b/website/API/space.md @@ -0,0 +1,152 @@ +# Space API + +The Space API provides functions for interacting with pages, attachments, and files in the space. + +## Page Operations + +### space.list_pages() +Returns a list of all pages in the space. + +Example: +```lua +local pages = space.list_pages() +for page in each(pages) do + print(page.name) +end +``` + +### space.read_page(name) +Reads the content of a page. + +Example: +```lua +local content = space.read_page("welcome") +print(content) -- prints the content of the "welcome" page +``` + +### space.get_page_meta(name) +Gets metadata for a specific page. + +Example: +```lua +local meta = space.get_page_meta("welcome") +print(meta.name, meta.lastModified) -- prints page name and last modified date +``` + +### space.write_page(name, text) +Writes content to a page. + +Example: +```lua +local meta = space.write_page("notes", "My new note content") +print("Page updated at: " .. meta.lastModified) +``` + +### space.delete_page(name) +Deletes a page from the space. + +Example: +```lua +space.delete_page("old-notes") +``` + +## Attachment Operations + +### space.list_attachments() +Returns a list of all attachments in the space. + +Example: +```lua +local attachments = space.list_attachments() +for att in each(attachments) do + print(att.name, att.size) +end +``` + +### space.read_attachment(name) +Reads the content of an attachment. + +Example: +```lua +local data = space.read_attachment("image.png") +print("Attachment size: " .. #data .. " bytes") +``` + +### space.write_attachment(name, data) +Writes binary data to an attachment. + +Example: +```lua +local binary_data = string.char(72, 69, 76, 76, 79) -- "HELLO" in binary +local meta = space.write_attachment("test.bin", binary_data) +print("Attachment saved with size: " .. meta.size) +``` + +### space.delete_attachment(name) +Deletes an attachment from the space. + +Example: +```lua +space.delete_attachment("old-image.png") +``` + +## File Operations + +### space.list_files() +Returns a list of all files in the space. + +Example: +```lua +local files = space.list_files() +for _, file in ipairs(files) do + print(file.name, file.size) +end +``` + +### space.get_file_meta(name) +Gets metadata for a specific file. + +Example: +```lua +local meta = space.get_file_meta("document.txt") +print(meta.name, meta.modified, meta.size) +``` + +### space.read_file(name) +Reads the content of a file. + +Example: +```lua +local content = space.read_file("document.txt") +print("File size: " .. #content .. " bytes") +``` + +### space.write_file(name, data) +Writes binary data to a file. + +Example: +```lua +local text = "Hello, World!" +local meta = space.write_file("greeting.txt", text) +print("File written with size: " .. meta.size) +``` + +### space.delete_file(name) +Deletes a file from the space. + +Example: +```lua +space.delete_file("old-document.txt") +``` + +### space.file_exists(name) +Checks if a file exists in the space. + +Example: +```lua +if space.file_exists("config.json") then + print("Config file exists!") +else + print("Config file not found") +end +``` diff --git a/website/API/sync.md b/website/API/sync.md new file mode 100644 index 00000000..2421ee7b --- /dev/null +++ b/website/API/sync.md @@ -0,0 +1,44 @@ +# Sync API + +The Sync API provides functions for interacting with the sync engine when the client runs in Sync mode. + +## Sync Operations + +### sync.is_syncing() +Checks if a sync is currently in progress. + +Example: +```lua +if sync.is_syncing() then + print("Sync in progress...") +end +``` + +### sync.has_initial_sync_completed() +Checks if an initial sync has completed. + +Example: +```lua +if sync.has_initial_sync_completed() then + print("Initial sync completed") +else + print("Waiting for initial sync...") +end +``` + +### sync.schedule_file_sync(path) +Actively schedules a file to be synced. Sync will happen by default too, but this prioritizes the file. + +Example: +```lua +sync.schedule_file_sync("notes/important.md") +``` + +### sync.schedule_space_sync() +Schedules a sync without waiting for the usual sync interval. + +Example: +```lua +local changes = sync.schedule_space_sync() +print("Number of changes synced: " .. changes) +``` \ No newline at end of file diff --git a/website/API/system.md b/website/API/system.md new file mode 100644 index 00000000..5a2b5c6b --- /dev/null +++ b/website/API/system.md @@ -0,0 +1,117 @@ +# System API + +The System API provides system-level functions for interacting with the SilverBullet environment. + +## Function Operations + +### system.invoke_function(name, ...) +Invokes a plug function by name. + +Example: +```lua +-- Invoke a function from a plug +system.invoke_function("myplug.process_data", "input", 123) +``` + +### system.invoke_command(name, args) +Invokes a client command by name. + +Example: +```lua +system.invoke_command("editor.save", {}) +``` + +### system.invoke_space_function(name, ...) +Invokes a space function by name. + +Example: +```lua +local result = system.invoke_space_function("custom_function", "arg1", "arg2") +print("Function result:", result) +``` + +## System Information + +### system.list_commands() +Lists all available commands. + +Example: +```lua +local commands = system.list_commands() +for name, def in pairs(commands) do + print(name .. ": " .. def.description) +end +``` + +### system.list_syscalls() +Lists all available syscalls. + +Example: +```lua +local syscalls = system.list_syscalls() +for _, syscall in ipairs(syscalls) do + print(syscall.name) +end +``` + +### system.get_env() +Returns the runtime environment ("server", "client", or undefined for hybrid). + +Example: +```lua +local env = system.get_env() +print("Running in environment: " .. (env or "hybrid")) +``` + +### system.get_mode() +Returns the current mode of the system ("ro" or "rw"). + +Example: +```lua +local mode = system.get_mode() +print("System mode: " .. mode) +``` + +### system.get_version() +Returns the SilverBullet version. + +Example: +```lua +local version = system.get_version() +print("SilverBullet version: " .. version) +``` + +## Configuration + +### system.get_space_config(key, default_value) +Loads space configuration values. + +Example: +```lua +-- Get specific config value +local value = system.get_space_config("theme", "light") + +-- Get all config values +local config = system.get_space_config() +for key, value in pairs(config) do + print(key .. ": " .. value) +end +``` + +### system.reload_config() +Triggers an explicit reload of the configuration. + +Example: +```lua +local new_config = system.reload_config() +print("Configuration reloaded") +``` + +### system.reload_plugs() +Triggers a reload of all plugs. + +Example: +```lua +system.reload_plugs() +print("All plugs reloaded") +``` \ No newline at end of file diff --git a/website/API/yaml.md b/website/API/yaml.md new file mode 100644 index 00000000..1a6155ed --- /dev/null +++ b/website/API/yaml.md @@ -0,0 +1,38 @@ +# YAML API + +The YAML API provides functions for parsing and stringifying YAML content. + +## YAML Operations + +### yaml.parse(text) +Parses a YAML string into a Lua table. + +Example: +```lua +local text = [[ +name: John +age: 30 +hobbies: + - reading + - hiking +]] + +local data = yaml.parse(text) +print(data.name) -- prints: John +print(data.hobbies[1]) -- prints: reading +``` + +### yaml.stringify(obj) +Converts a Lua table into a YAML string. + +Example: +```lua +local data = { + name = "John", + age = 30, + hobbies = {"reading", "hiking"} +} + +local yaml_text = yaml.stringify(data) +print(yaml_text) +``` \ No newline at end of file