196 lines
6.2 KiB
Swift
196 lines
6.2 KiB
Swift
//
|
|
// Textarea.swift
|
|
// HTMLStandard
|
|
//
|
|
// Generated on 09/23/2025.
|
|
// THIS FILE IS GENERATED. DO NOT EDIT.
|
|
//
|
|
import Foundation
|
|
|
|
/// <textarea> Multiline text controls
|
|
public class Textarea : HTMLNode, IFlow, IFormAssociated, IInteractive, ILabelable, IListed, IPalpable, IPhrasing, IResettable, ISubmittable {
|
|
|
|
public enum Wrap : String, CaseIterable {
|
|
|
|
case hard
|
|
case soft
|
|
|
|
public init?(rawValue: Substring) {
|
|
guard
|
|
let value = Self.allCases.first(where: { $0.rawValue == rawValue })
|
|
else
|
|
{ return nil }
|
|
|
|
self = value
|
|
}
|
|
|
|
public init(expect: Substring) throws {
|
|
guard
|
|
let value = Self.allCases.first(where: { $0.rawValue == expect })
|
|
else
|
|
{ throw AppError("Unexpected value for Wrap: \(expect)") }
|
|
|
|
self = value
|
|
}
|
|
|
|
public init(expect: String) throws {
|
|
guard let result = Wrap(rawValue: expect) else {
|
|
throw AppError("Unexpected value for Wrap: \(expect)")
|
|
}
|
|
self = result
|
|
}
|
|
|
|
static func parseList(_ value:String?, _ separator:String = " ") throws -> [Wrap] {
|
|
guard let value = value else { return [] }
|
|
var iterator = value.componentsIterator(separatedBy: separator)
|
|
let result = try iterator.map { input in
|
|
return try expect(Wrap(rawValue: input), "unexpected value for Wrap: \(input)")
|
|
}
|
|
return result
|
|
}
|
|
}
|
|
|
|
/// Maximum number of characters per line. Valid non-negative integer greater than zero.
|
|
public var cols:UInt? = nil
|
|
|
|
/// Name of form control to use for sending the element's directionality in form submission. Text. The actual rules are more complicated than indicated.
|
|
public var dirname:String? = nil
|
|
|
|
/// Whether the form control is disabled.
|
|
public var disabled:Bool = false
|
|
|
|
/// Associates the element with a form element. ID. The actual rules are more complicated than indicated.
|
|
public var form:String? = nil
|
|
|
|
/// Maximum length of value. Valid non-negative integer.
|
|
public var maxlength:UInt? = nil
|
|
|
|
/// Minimum length of value. Valid non-negative integer.
|
|
public var minlength:UInt? = nil
|
|
|
|
/// Name of the element to use for form submission and in the form.elements API. Text. The actual rules are more complicated than indicated.
|
|
public var name:String? = nil
|
|
|
|
/// User-visible label to be placed within the form control. Text. The actual rules are more complicated than indicated.
|
|
public var placeholder:String? = nil
|
|
|
|
/// Whether to allow the value to be edited by the user.
|
|
public var readonly:Bool = false
|
|
|
|
/// Whether the control is required for form submission.
|
|
public var required:Bool = false
|
|
|
|
/// Number of lines to show. Valid non-negative integer greater than zero.
|
|
public var rows:UInt? = nil
|
|
|
|
/// How the value of the form control is to be wrapped for form submission.
|
|
public var wrap:Wrap? = nil
|
|
|
|
|
|
public init(_ attributes:[String:String], _ parser:XMLParser? = nil) throws {
|
|
var globalAttr = GlobalAttributesBuilder()
|
|
for (key, attValue) in attributes {
|
|
switch (key) {
|
|
case "cols":
|
|
cols = UInt(attValue)
|
|
continue
|
|
case "dirname":
|
|
dirname = attValue
|
|
continue
|
|
case "disabled":
|
|
disabled = true
|
|
continue
|
|
case "form":
|
|
form = attValue
|
|
continue
|
|
case "maxlength":
|
|
maxlength = UInt(attValue)
|
|
continue
|
|
case "minlength":
|
|
minlength = UInt(attValue)
|
|
continue
|
|
case "name":
|
|
name = attValue
|
|
continue
|
|
case "placeholder":
|
|
placeholder = attValue
|
|
continue
|
|
case "readonly":
|
|
readonly = true
|
|
continue
|
|
case "required":
|
|
required = true
|
|
continue
|
|
case "rows":
|
|
rows = UInt(attValue)
|
|
continue
|
|
case "wrap":
|
|
wrap = try Wrap(expect: attValue)
|
|
continue
|
|
|
|
default: break
|
|
}
|
|
if globalAttr.trySetGlobalAttribute(key, attValue) {
|
|
continue
|
|
}
|
|
throw AppError("Unexpected attribute: \(key)")
|
|
}
|
|
var allItems:[HTMLNode] = []
|
|
while let obj = try parser?.readObject(endTag: "textarea", xmlToHtmlMapper) {
|
|
allItems.append(obj)
|
|
}
|
|
super.init(globalAttr, allItems)
|
|
}
|
|
|
|
|
|
public override func renderAttributes() -> String {
|
|
var result = super.renderAttributes()
|
|
if let cols = cols {
|
|
result += " cols='\(cols)'"
|
|
}
|
|
if let dirname = dirname {
|
|
result += " dirname='\(dirname)'"
|
|
}
|
|
if disabled {
|
|
result += " disabled"
|
|
}
|
|
if let form = form {
|
|
result += " form='\(form)'"
|
|
}
|
|
if let maxlength = maxlength {
|
|
result += " maxlength='\(maxlength)'"
|
|
}
|
|
if let minlength = minlength {
|
|
result += " minlength='\(minlength)'"
|
|
}
|
|
if let name = name {
|
|
result += " name='\(name)'"
|
|
}
|
|
if let placeholder = placeholder {
|
|
result += " placeholder='\(placeholder)'"
|
|
}
|
|
if readonly {
|
|
result += " readonly"
|
|
}
|
|
if required {
|
|
result += " required"
|
|
}
|
|
if let rows = rows {
|
|
result += " rows='\(rows)'"
|
|
}
|
|
if let wrap = wrap {
|
|
result += " wrap='\(wrap.rawValue)'"
|
|
}
|
|
|
|
|
|
return result
|
|
}
|
|
|
|
override var nodeName: String {
|
|
return "textarea"
|
|
}
|
|
|
|
override var isVoidElement: Bool {
|
|
return false
|
|
}
|
|
} |