yumoqing 7bc06097b0 feat: add VideoPlayer widget with shared AVPlayer via Store
- New VideoPlayerControl.swift wrapping AVKit VideoPlayer
- Prefers shared AVPlayer from Store (e.g. PlayerBridge injection)
- Falls back to options.url for standalone use
- Schema.swift: add autoplay option for VideoPlayer
- ControlRenderer: register VideoPlayer widget type
- Add .gitignore to exclude .build/
2026-06-22 09:52:27 +08:00

346 lines
9.7 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
// MARK: - JSON Schema Models (Bricks JSON Codable)
/// Bricks JSON
public struct ControlSchema: Codable, Identifiable, Sendable {
public var id: String?
public let widgettype: String
public var options: ControlOptions
public var binds: [BindSchema]?
public var subwidgets: [ControlSchema]?
/// IDJSONid
public var runtimeId: String = UUID().uuidString.prefix(8).lowercased()
public var effectiveId: String {
id ?? runtimeId
}
public init(
id: String? = nil,
widgettype: String,
options: ControlOptions = .init(),
binds: [BindSchema]? = nil,
subwidgets: [ControlSchema]? = nil
) {
self.id = id
self.widgettype = widgettype
self.options = options
self.binds = binds
self.subwidgets = subwidgets
}
/// optionsFilleroptionswidget
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: .id)
self.widgettype = try container.decode(String.self, forKey: .widgettype)
self.options = try container.decodeIfPresent(ControlOptions.self, forKey: .options) ?? ControlOptions()
self.binds = try container.decodeIfPresent([BindSchema].self, forKey: .binds)
self.subwidgets = try container.decodeIfPresent([ControlSchema].self, forKey: .subwidgets)
}
private enum CodingKeys: String, CodingKey {
case id, widgettype, options, binds, subwidgets
}
}
/// 使+Codable
public struct ControlOptions: Codable, Sendable {
//
public var width: String?
public var height: String?
public var cwidth: Double?
public var cheight: Double?
public var bgcolor: String?
public var color: String?
public var css: String?
public var padding: String?
public var cursor: String?
public var spacing: Double?
public var alignItems: String?
// Text/Title
public var text: String?
public var otext: String?
public var i18n: Bool?
public var level: Int?
// Button
public var label: String?
public var actiontype: String?
public var url: String?
public var icon: String?
// Input/Textarea
public var name: String?
public var placeholder: String?
public var value: String?
public var defaultvalue: String?
public var required: Bool?
public var uitype: String?
public var title: String?
public var rules: [ValidationRule]?
public var codes: [CodeItem]?
// Select/Code
public var data: [CodeItem]?
public var dataurl: String?
public var valueField: String?
public var textField: String?
// Form
public var fields: [FieldSchema]?
public var submit_url: String?
public var submit_label: String?
public var show_label: Bool?
// Tabular
public var data_url: String?
public var data_method: String?
public var page_rows: Int?
public var row_options: RowOptions?
public var toolbar: ToolbarSchema?
// TabView
public var tabs: [TabItem]?
public var activeTab: Int?
// DynamicColumn
public var col_cwidth: Double?
public var col_cgap: Double?
public var col_width: Double?
// PopupWindow
public var popup_options: PopupOptions?
public var auto_open: Bool?
public var archor: String?
public var dismiss_events: [String]?
// Menu
public var items: [MenuItemSchema]?
public var target: String?
// HTML
public var html: String?
// Image
public var src: String?
public var alt: String?
// VideoPlayer
public var autoplay: Bool?
public var controls: Bool?
// Misc
public var fontsize: String?
public var cfontsize: Double?
public init() {}
}
/// eventaction
public struct BindSchema: Codable, Sendable {
public let wid: String // widget id
public let event: String //
public let actiontype: String // 9
public var target: String? // widget id
public var options: BindOptions?
public var mode: String? // replace/append
public var method: String? // methodactiontype=method
public var script: String? // actiontype=script
public var popup_options: PopupOptions?
public var datawidget: String? // widget
public var event_params: String?
}
///
public struct BindOptions: Codable, Sendable {
public var url: String?
public var params: [String: String]?
public init(url: String? = nil, params: [String: String]? = nil) {
self.url = url
self.params = params
}
}
///
public struct PopupOptions: Codable, Sendable {
public var title: String?
public var cwidth: Double?
public var cheight: Double?
public var width: String?
public var height: String?
public var archor: String?
public var eventpos: Bool?
public var dismiss_events: [String]?
public init() {}
}
///
public struct FieldSchema: Codable, Sendable {
public var name: String
public var label: String?
public var title: String?
public var type: String?
public var uitype: String?
public var required: Bool?
public var cwidth: Double?
public var placeholder: String?
public var value: String?
public var defaultvalue: String?
public var codes: [CodeItem]?
public var data: [CodeItem]?
public var dataurl: String?
public var valueField: String?
public var textField: String?
public var rules: [ValidationRule]?
public var effectiveLabel: String { label ?? title ?? name }
public var effectiveUitype: String { uitype ?? type ?? "str" }
}
///
public struct ValidationRule: Codable, Sendable {
public let type: String
public var value: String?
public var message: String?
}
///
public struct CodeItem: Codable, Sendable, Identifiable {
public var id: String { value }
public let value: String
public let text: String
}
/// Tabular
public struct RowOptions: Codable, Sendable {
public var fields: [FieldSchema]?
public var browserfields: BrowserFields?
}
///
public struct BrowserFields: Codable, Sendable {
public var exclouded: [String]?
public var cwidths: [String: Double]?
public var alters: [String: FieldSchema]?
}
///
public struct ToolbarSchema: Codable, Sendable {
public var tools: [ToolbarTool]?
}
///
public struct ToolbarTool: Codable, Sendable {
public var name: String
public var label: String?
public var icon: String?
public var selected_row: Bool?
public var css: String?
}
/// TabView
public struct TabItem: Codable, Sendable {
public var label: String
public var icon: String?
public var content: ControlSchema?
}
///
public struct MenuItemSchema: Codable, Sendable {
public var name: String
public var label: String
public var icon: String?
public var url: String?
public var submenu: [MenuItemSchema]?
public var binds: [BindSchema]?
}
// MARK: - WidgetType
public enum WidgetType: String, CaseIterable, Sendable {
//
case text = "Text"
case title1 = "Title1", title2 = "Title2", title3 = "Title3"
case title4 = "Title4", title5 = "Title5", title6 = "Title6"
case label = "Label"
//
case input = "Input"
case textarea = "Textarea"
case select = "Select"
case uiCode = "UiCode"
case uiStr = "UiStr"
case uiNumber = "UiNumber"
case uiDate = "UiDate"
case uiText = "UiText"
//
case button = "Button"
//
case vbox = "VBox"
case hbox = "HBox"
case vScrollPanel = "VScrollPanel"
case hScrollPanel = "HScrollPanel"
case filler = "Filler"
case dynamicColumn = "DynamicColumn"
//
case tabular = "Tabular"
case dataViewer = "DataViewer"
case form = "Form"
case inlineForm = "InlineForm"
//
case tabView = "TabView"
case menu = "Menu"
//
case popupWindow = "PopupWindow"
//
case card = "Card"
case html = "Html"
case image = "Image"
case urlwidget = "urlwidget"
//
case popup = "Popup"
public var isLayout: Bool {
[.vbox, .hbox, .vScrollPanel, .hScrollPanel, .dynamicColumn, .card].contains(self)
}
public var isText: Bool {
[.text, .title1, .title2, .title3, .title4, .title5, .title6, .label].contains(self)
}
public var isInput: Bool {
[.input, .textarea, .select, .uiCode, .uiStr, .uiNumber, .uiDate, .uiText].contains(self)
}
}
// MARK: - ActionType
public enum ActionType: String, CaseIterable, Sendable {
case newwindow //
case iframe // iframe
case urlwidget // UI
case urldata //
case bricks // widget
case registerfunction //
case method // widget
case script //
case event //
public static var validNames: [String] {
allCases.map { $0.rawValue }
}
}