feat: enhance type definitions and add new classes for various components in code editor and notification center

This commit is contained in:
2025-12-30 10:21:46 +00:00
parent bf1401fe34
commit dc0336bb9e
10 changed files with 174 additions and 0 deletions

View File

@@ -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,

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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

View File

@@ -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",

View File

@@ -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",