mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
feat: enhance type definitions and add new classes for various components in code editor and notification center
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
-- Code Editor initialization
|
||||
|
||||
---@class CodeEditor
|
||||
---@field name string
|
||||
---@field version string
|
||||
local M = {}
|
||||
|
||||
M.name = "code_editor"
|
||||
M.version = "1.0.0"
|
||||
|
||||
---@class InitResult
|
||||
---@field name string
|
||||
---@field version string
|
||||
---@field loaded boolean
|
||||
|
||||
---@return InitResult
|
||||
function M.init()
|
||||
return {
|
||||
name = M.name,
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
-- JSON Editor utilities
|
||||
|
||||
---@class JsonEditor
|
||||
local M = {}
|
||||
|
||||
---@class EditorOptions
|
||||
---@field read_only? boolean
|
||||
|
||||
---@class UIComponent
|
||||
---@field type string
|
||||
---@field props? table
|
||||
---@field children? table
|
||||
|
||||
---@class ValidationResult
|
||||
---@field valid boolean
|
||||
---@field errors table
|
||||
|
||||
---@class FormatAction
|
||||
---@field action string
|
||||
---@field language string
|
||||
|
||||
---@param value? string
|
||||
---@param options? EditorOptions
|
||||
---@return UIComponent
|
||||
function M.render(value, options)
|
||||
return {
|
||||
type = "code_editor",
|
||||
@@ -14,6 +35,8 @@ function M.render(value, options)
|
||||
}
|
||||
end
|
||||
|
||||
---@param json_string string
|
||||
---@return ValidationResult
|
||||
function M.validate(json_string)
|
||||
-- JSON validation placeholder
|
||||
return {
|
||||
@@ -22,6 +45,8 @@ function M.validate(json_string)
|
||||
}
|
||||
end
|
||||
|
||||
---@param json_string string
|
||||
---@return FormatAction
|
||||
function M.format(json_string)
|
||||
return {
|
||||
action = "format",
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
-- Lua Editor utilities
|
||||
|
||||
---@class LuaEditor
|
||||
local M = {}
|
||||
|
||||
---@class EditorOptions
|
||||
---@field read_only? boolean
|
||||
|
||||
---@class UIComponent
|
||||
---@field type string
|
||||
---@field props? table
|
||||
---@field children? table
|
||||
|
||||
---@class ValidationResult
|
||||
---@field valid boolean
|
||||
---@field errors table
|
||||
|
||||
---@class SandboxAction
|
||||
---@field action string
|
||||
---@field sandbox boolean
|
||||
---@field context table
|
||||
|
||||
---@param value? string
|
||||
---@param options? EditorOptions
|
||||
---@return UIComponent
|
||||
function M.render(value, options)
|
||||
return {
|
||||
type = "code_editor",
|
||||
@@ -14,6 +36,8 @@ function M.render(value, options)
|
||||
}
|
||||
end
|
||||
|
||||
---@param lua_code string
|
||||
---@return ValidationResult
|
||||
function M.validate(lua_code)
|
||||
-- Lua syntax validation placeholder
|
||||
return {
|
||||
@@ -22,6 +46,9 @@ function M.validate(lua_code)
|
||||
}
|
||||
end
|
||||
|
||||
---@param lua_code string
|
||||
---@param context? table
|
||||
---@return SandboxAction
|
||||
function M.run_sandbox(lua_code, context)
|
||||
return {
|
||||
action = "execute",
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
-- Theme Editor utilities
|
||||
|
||||
---@class ThemeEditor
|
||||
local M = {}
|
||||
|
||||
---@class Theme
|
||||
---@field primary? string
|
||||
---@field secondary? string
|
||||
---@field mode? string
|
||||
|
||||
---@class UIComponent
|
||||
---@field type string
|
||||
---@field props? table
|
||||
---@field children? table
|
||||
|
||||
---@param theme? Theme
|
||||
---@return UIComponent
|
||||
function M.render(theme)
|
||||
return {
|
||||
type = "theme_editor",
|
||||
@@ -12,6 +26,9 @@ function M.render(theme)
|
||||
}
|
||||
end
|
||||
|
||||
---@param name string
|
||||
---@param value string
|
||||
---@return UIComponent
|
||||
function M.color_picker(name, value)
|
||||
return {
|
||||
type = "color_picker",
|
||||
@@ -23,6 +40,7 @@ function M.color_picker(name, value)
|
||||
}
|
||||
end
|
||||
|
||||
---@return UIComponent
|
||||
function M.mode_toggle()
|
||||
return {
|
||||
type = "switch",
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
-- Dashboard stat trend indicator
|
||||
|
||||
---@class TrendIndicatorConfig
|
||||
---@field type string
|
||||
---@field direction string
|
||||
---@field value string
|
||||
---@field color string
|
||||
|
||||
---@param direction string Direction of trend: "up" or "down"
|
||||
---@param value string Trend value to display
|
||||
---@return TrendIndicatorConfig
|
||||
local function trend_indicator(direction, value)
|
||||
return {
|
||||
type = "trend",
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
-- Date column definition
|
||||
|
||||
---@class DateColumn
|
||||
---@field type "date"
|
||||
---@field id string Column identifier
|
||||
---@field label string Column header label
|
||||
---@field format string Date format string (e.g., "YYYY-MM-DD")
|
||||
---@field sortable boolean Whether the column is sortable
|
||||
|
||||
---Create a date column definition
|
||||
---@param id string Column identifier
|
||||
---@param label string Column header label
|
||||
---@param format? string Date format string (default: "YYYY-MM-DD")
|
||||
---@return DateColumn
|
||||
local function date_column(id, label, format)
|
||||
return {
|
||||
type = "date",
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
-- Number column definition
|
||||
|
||||
---@class NumberColumn
|
||||
---@field type "number"
|
||||
---@field id string Column identifier
|
||||
---@field label string Column header label
|
||||
---@field width string Column width (e.g., "100px")
|
||||
---@field sortable boolean Whether the column is sortable
|
||||
---@field align "right" Text alignment
|
||||
|
||||
---Create a number column definition
|
||||
---@param id string Column identifier
|
||||
---@param label string Column header label
|
||||
---@param width? string Column width (default: "100px")
|
||||
---@return NumberColumn
|
||||
local function number_column(id, label, width)
|
||||
return {
|
||||
type = "number",
|
||||
|
||||
@@ -1,35 +1,69 @@
|
||||
---@class Validate
|
||||
local M = {}
|
||||
|
||||
---@class ValidationRule
|
||||
---@field type string
|
||||
---@field message? string
|
||||
---@field min? number
|
||||
---@field max? number
|
||||
---@field value? any
|
||||
|
||||
---@class ValidationResult
|
||||
---@field valid boolean
|
||||
---@field errors string[]
|
||||
|
||||
---@param value string|number|nil
|
||||
---@return boolean
|
||||
function M.required(value)
|
||||
return value ~= nil and value ~= ""
|
||||
end
|
||||
|
||||
---@param value string|nil
|
||||
---@return boolean
|
||||
function M.email(value)
|
||||
if not value then return false end
|
||||
return string.match(value, "^[^@]+@[^@]+%.[^@]+$") ~= nil
|
||||
end
|
||||
|
||||
---@param value string|nil
|
||||
---@param min number
|
||||
---@return boolean
|
||||
function M.minLength(value, min)
|
||||
return value and #value >= min
|
||||
end
|
||||
|
||||
---@param value string|nil
|
||||
---@param max number
|
||||
---@return boolean
|
||||
function M.maxLength(value, max)
|
||||
return not value or #value <= max
|
||||
end
|
||||
|
||||
---@param value string|nil
|
||||
---@param pat string
|
||||
---@return boolean
|
||||
function M.pattern(value, pat)
|
||||
return value and string.match(value, pat) ~= nil
|
||||
end
|
||||
|
||||
---@param value any
|
||||
---@return boolean
|
||||
function M.number(value)
|
||||
return tonumber(value) ~= nil
|
||||
end
|
||||
|
||||
---@param value any
|
||||
---@param min number
|
||||
---@param max number
|
||||
---@return boolean
|
||||
function M.range(value, min, max)
|
||||
local n = tonumber(value)
|
||||
return n and n >= min and n <= max
|
||||
end
|
||||
|
||||
---@param value string|number|nil
|
||||
---@param rules ValidationRule[]
|
||||
---@return ValidationResult
|
||||
function M.validate_field(value, rules)
|
||||
local errors = {}
|
||||
for _, rule in ipairs(rules) do
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
-- Notification list container
|
||||
|
||||
---@class UIComponent
|
||||
---@field type string
|
||||
---@field children? table[]
|
||||
---@field emptyMessage? string
|
||||
|
||||
---@param notifications? table[]
|
||||
---@return UIComponent
|
||||
local function list_container(notifications)
|
||||
return {
|
||||
type = "notification_list",
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
-- Notification list item component
|
||||
|
||||
---@class UIComponent
|
||||
---@field type string
|
||||
---@field id string|number
|
||||
---@field title string
|
||||
---@field message string
|
||||
---@field timestamp string|number
|
||||
---@field read boolean
|
||||
|
||||
---@param id string|number
|
||||
---@param title string
|
||||
---@param message string
|
||||
---@param timestamp string|number
|
||||
---@param read? boolean
|
||||
---@return UIComponent
|
||||
local function list_item(id, title, message, timestamp, read)
|
||||
return {
|
||||
type = "notification_item",
|
||||
|
||||
Reference in New Issue
Block a user