Skip to content

An open source design system that's fully customizable and agent ready

TypeScript
3.6 KB
Raw Blame
// Generated by @astryxdesign/native. Do not edit.
import Foundation

#if os(iOS) || os(macOS)
/// One Astryx component in a tree a TypeScript core sends, by its `component` name.
/// A node this binding cannot read decodes as `unsupported`: an unknown component,
/// or a known one with a value its enums lack or a required prop missing. An older
/// app then keeps drawing the rest of a newer core's tree.
public enum AstryxNode: Decodable, Equatable, Sendable {
  case avatar(AvatarNode)
  case avatarStatusDot(AvatarStatusDotNode)
  case badge(BadgeNode)
  case button(ButtonNode)
  case card(CardNode)
  case divider(DividerNode)
  case heading(HeadingNode)
  case hStack(HStackNode)
  case icon(IconNode)
  case item(ItemNode)
  case listItem(ListItemNode)
  case progressBar(ProgressBarNode)
  case selector(SelectorNode)
  case `switch`(SwitchNode)
  case text(TextNode)
  case thumbnail(ThumbnailNode)
  case textInput(TextInputNode)
  case vStack(VStackNode)
  case unsupported(component: String, key: String)

  public var key: String {
    switch self {
    case .avatar(let node): return node.key
    case .avatarStatusDot(let node): return node.key
    case .badge(let node): return node.key
    case .button(let node): return node.key
    case .card(let node): return node.key
    case .divider(let node): return node.key
    case .heading(let node): return node.key
    case .hStack(let node): return node.key
    case .icon(let node): return node.key
    case .item(let node): return node.key
    case .listItem(let node): return node.key
    case .progressBar(let node): return node.key
    case .selector(let node): return node.key
    case .`switch`(let node): return node.key
    case .text(let node): return node.key
    case .thumbnail(let node): return node.key
    case .textInput(let node): return node.key
    case .vStack(let node): return node.key
    case .unsupported(_, let key): return key
    }
  }

  private enum Keys: String, CodingKey { case component, key }

  public init(from decoder: any Decoder) throws {
    let container = try decoder.container(keyedBy: Keys.self)
    let component = try container.decode(String.self, forKey: .component)
    let key = try container.decode(String.self, forKey: .key)
    do {
      switch component {
      case "Avatar": self = .avatar(try AvatarNode(from: decoder))
      case "AvatarStatusDot": self = .avatarStatusDot(try AvatarStatusDotNode(from: decoder))
      case "Badge": self = .badge(try BadgeNode(from: decoder))
      case "Button": self = .button(try ButtonNode(from: decoder))
      case "Card": self = .card(try CardNode(from: decoder))
      case "Divider": self = .divider(try DividerNode(from: decoder))
      case "Heading": self = .heading(try HeadingNode(from: decoder))
      case "HStack": self = .hStack(try HStackNode(from: decoder))
      case "Icon": self = .icon(try IconNode(from: decoder))
      case "Item": self = .item(try ItemNode(from: decoder))
      case "ListItem": self = .listItem(try ListItemNode(from: decoder))
      case "ProgressBar": self = .progressBar(try ProgressBarNode(from: decoder))
      case "Selector": self = .selector(try SelectorNode(from: decoder))
      case "Switch": self = .`switch`(try SwitchNode(from: decoder))
      case "Text": self = .text(try TextNode(from: decoder))
      case "Thumbnail": self = .thumbnail(try ThumbnailNode(from: decoder))
      case "TextInput": self = .textInput(try TextInputNode(from: decoder))
      case "VStack": self = .vStack(try VStackNode(from: decoder))
      default: self = .unsupported(component: component, key: key)
      }
    } catch {
      self = .unsupported(component: component, key: key)
    }
  }
}
#endif