- Core: Schema (Codable), Store, EventBus, RPC, Engine, I18n - Controls: Text, Title1-6, Label, Input, Textarea, Number, Date, Button, Select VBox, HBox, ScrollPanel, DynamicColumn, Tabular, Form, InlineForm, TabView, Menu, PopupWindow, Html, Image, UrlWidget - Renderer: BricksView (main entry), ControlRenderer (recursive dispatch) - 30+ widget types, 9 bind actiontypes - Form validation (required/minlength/maxlength/min/max/email/number/pattern) - i18n with multi-language JSON files - 18 tests covering schema parsing, store, i18n, events
51 lines
1.6 KiB
Swift
51 lines
1.6 KiB
Swift
/// SwiftBricks — Bricks框架的Swift/SwiftUI原生实现
|
||
///
|
||
/// 核心架构:
|
||
/// - BricksEngine: 主引擎,管理schema加载、binds事件、状态
|
||
/// - BricksStore: 数据存储,widget值/表单/表格/弹窗状态
|
||
/// - BricksEventBus: 事件发布/订阅
|
||
/// - BricksRPC: 网络层(GET/POST/Form)
|
||
/// - BricksI18n: 国际化
|
||
/// - BricksView: 主入口视图
|
||
/// - ControlRenderer: 递归JSON→SwiftUI渲染器
|
||
///
|
||
/// 支持的Widget类型:
|
||
/// - 文本: Text, Title1-6, Label
|
||
/// - 输入: Input, Textarea, Select, UiCode, UiStr, UiNumber, UiDate, UiText
|
||
/// - 按钮: Button
|
||
/// - 布局: VBox, HBox, VScrollPanel, HScrollPanel, Filler, DynamicColumn, Card
|
||
/// - 数据: Tabular, DataViewer, Form, InlineForm
|
||
/// - 导航: TabView, Menu
|
||
/// - 弹窗: PopupWindow
|
||
/// - 其他: Html, Image, urlwidget
|
||
///
|
||
/// 支持的Bind ActionType (9种):
|
||
/// newwindow, iframe, urlwidget, urldata, bricks, registerfunction, method, script, event
|
||
///
|
||
/// 用法:
|
||
/// ```swift
|
||
/// // 1. 创建引擎
|
||
/// let engine = BricksEngine()
|
||
/// engine.rpc.baseURL = "https://api.example.com"
|
||
///
|
||
/// // 2. 渲染视图
|
||
/// BricksView(json: jsonString, engine: engine)
|
||
/// BricksView(url: "/api/page.ui", engine: engine)
|
||
///
|
||
/// // 3. 设置i18n
|
||
/// await engine.i18n.loadLocale("en")
|
||
/// ```
|
||
|
||
import SwiftUI
|
||
|
||
// 导出所有公开类型
|
||
public typealias Schema = ControlSchema
|
||
public typealias Options = ControlOptions
|
||
public typealias Bind = BindSchema
|
||
public typealias Field = FieldSchema
|
||
public typealias Store = BricksStore
|
||
public typealias EventBus = BricksEventBus
|
||
public typealias RPC = BricksRPC
|
||
public typealias I18n = BricksI18n
|
||
public typealias Engine = BricksEngine
|