Files
plainleaf/Library/Std/Widget.md
T
Zef Hemel 45b767fd3c Lua widgets: html can now also be a DOM node
Encoding some more space lua priorities and documenting them
2025-03-28 17:38:32 +01:00

52 lines
966 B
Markdown

#meta
This implements the widget API. For a Lua Directive to be rendered as a widget, you need to return it via `widget.new`.
```space-lua
-- priority: 50
-- Widget APIs
widget = {}
-- Container for widgets
widgets = {}
-- Widget schema for validation
local widgetSchema = {
type = "object",
properties = {
markdown = { type = "string"},
html = {
anyOf = {
{ type = "object"},
{ type = "string" }
}
},
cssClasses = {
type = "array",
items = { type = "string" },
},
display = {
type = "string",
enum = {"block", "inline"}
},
events = {
type = "object",
additionalProperties = true
}
}
}
-- Creates a widget
function widget.new(spec)
-- Validate spec
local validationResult = jsonschema.validateObject(widgetSchema, spec)
if validationResult then
error(validationResult)
end
-- Mark as a widget
spec._isWidget = true
return spec
end
```