SPB Git

Repository Public License

Catalog.swift 41.7 KB 458 lines swift

1import Foundation2import PrismComponentSDK3import PrismCore45/// The V1 component catalog (spec §7). Each entry is a contract the renderer implements and the tests exercise.6public enum Catalog {7    public static let tones = ["neutral", "info", "success", "warning", "danger", "accent"]89    /// The registry with every manifest whose hash matches `CatalogLock`.10    public static let registry = ComponentRegistry(manifests: manifests, lock: CatalogLock.hashes)1112    // MARK: Builders1314    static func fixture(_ type: String, _ props: JSONValue, state: JSONValue = [:], extra: [JSONValue] = [], children: [String] = [], permissions: [String] = []) -> JSONValue {15        var root: [String: JSONValue] = ["id": "fx", "type": .string(type), "name": "Preview", "props": props]16        if !children.isEmpty { root["children"] = .array(children.map(JSONValue.string)) }17        return ["root": "fx", "objects": .array([.object(root)] + extra), "state": state, "permissions": .array(permissions.map(JSONValue.string))]18    }1920    static func text(_ id: String, _ text: String) -> JSONValue {21        ["id": .string(id), "type": "prism.text", "name": .string(text), "props": ["text": .string(text)]]22    }2324    /// A small table with sample rows, shared by the data and chart fixtures.25    static let sampleTable: JSONValue = [26        "id": "fx_items", "type": "prism.data.table", "name": "Items",27        "props": [28            "columns": [29                ["name": "date", "type": "date", "label": "Date"], ["name": "title", "type": "text", "label": "Title", "required": true],30                ["name": "category", "type": "text", "label": "Category", "options": ["Food", "Housing", "Fun"]],31                ["name": "amount", "type": "currency", "label": "Amount"],32            ],33            "seed": [34                ["date": "2026-01-05", "title": "Groceries", "category": "Food", "amount": 82.4],35                ["date": "2026-01-12", "title": "Rent", "category": "Housing", "amount": 1200],36                ["date": "2026-02-03", "title": "Cinema", "category": "Fun", "amount": 24],37                ["date": "2026-02-18", "title": "Restaurant", "category": "Food", "amount": 61.5],38                ["date": "2026-03-02", "title": "Rent", "category": "Housing", "amount": 1200],39            ],40        ],41    ]4243    static let byMonth: JSONValue = [44        "table": "fx_items", "groupBy": ["column": "date", "bucket": "month", "as": "month"],45        "aggregates": [["fn": "sum", "column": "amount", "as": "total"]],46    ]47    static let byCategory: JSONValue = [48        "table": "fx_items", "groupBy": ["column": "category", "as": "category"],49        "aggregates": [["fn": "sum", "column": "amount", "as": "total"]],50    ]5152    static let storage = [Permission.storageLocal]53    static let toneProp = PropSpec("tone", .enum, "Semantic color.", default: "neutral", values: tones, dynamic: true)5455    // MARK: Manifests5657    public static let manifests: [ComponentManifest] = foundation + forms + data + charts + navigation + logic + familyA + familyB + familyC5859    static let foundation: [ComponentManifest] = [60        ComponentManifest(61            type: "prism.text", name: "Text", category: "foundation", summary: "A line or paragraph of text, fixed or computed.",62            props: [63                PropSpec("text", .string, "The text to show.", required: true),64                PropSpec("style", .enum, "Typography role.", default: "body", values: ["body", "caption", "footnote", "callout", "headline", "title", "largeTitle", "monospaced"], dynamic: false),65                toneProp,66                PropSpec("align", .enum, "Horizontal alignment.", default: "leading", values: ["leading", "center", "trailing"], dynamic: false),67            ],68            keywords: ["label", "paragraph", "caption", "value"], accessibilityRole: "staticText", accessibilityLabelProp: "text",69            examples: [["id": "total_label", "type": "prism.text", "props": ["text": ["$expr": "concat('Total: ', formatCurrency(sum(queries.totals, 'total')))"], "style": "headline"]]],70            fixture: fixture("prism.text", ["text": "Describe it. Build it. Use it. Evolve it.", "style": "headline"])71        ),72        ComponentManifest(73            type: "prism.heading", name: "Heading", category: "foundation", summary: "A section or page title.",74            props: [PropSpec("text", .string, "The heading text.", required: true), PropSpec("level", .number, "1 (largest) to 3.", default: 2, dynamic: false)],75            keywords: ["title", "header", "section"], accessibilityRole: "heading", accessibilityLabelProp: "text",76            examples: [["id": "page_title", "type": "prism.heading", "props": ["text": "Transactions", "level": 1]]],77            fixture: fixture("prism.heading", ["text": "Monthly overview", "level": 1])78        ),79        ComponentManifest(80            type: "prism.icon", name: "Icon", category: "foundation", summary: "An SF Symbol.",81            props: [PropSpec("symbol", .string, "SF Symbol name, e.g. `chart.bar`.", required: true), PropSpec("size", .number, "Point size.", default: 18, dynamic: false), toneProp],82            keywords: ["symbol", "glyph", "image"], accessibilityRole: "image",83            examples: [["id": "warn_icon", "type": "prism.icon", "props": ["symbol": "exclamationmark.triangle", "tone": "warning", "accessibilityLabel": "Warning"]]],84            fixture: fixture("prism.icon", ["symbol": "sparkles", "size": 28, "tone": "accent", "accessibilityLabel": "Sparkles"])85        ),86        ComponentManifest(87            type: "prism.button", name: "Button", category: "foundation", summary: "Runs actions when clicked.",88            props: [89                PropSpec("title", .string, "Button label."), PropSpec("icon", .string, "SF Symbol shown before the title."),90                PropSpec("style", .enum, "Visual weight.", default: "secondary", values: ["primary", "secondary", "destructive", "plain"], dynamic: false),91                PropSpec("disabled", .boolean, "Whether the button is inactive.", default: false),92            ],93            events: ["click"], keywords: ["action", "submit", "press", "add", "save"], accessibilityRole: "button", accessibilityLabelProp: "title",94            examples: [["id": "add_button", "type": "prism.button", "props": ["title": "Add", "icon": "plus", "style": "primary"], "events": ["click": [["type": "setState", "key": "showEditor", "value": true]]]]],95            fixture: fixture("prism.button", ["title": "Count up", "icon": "plus", "style": "primary"], state: ["count": 0])96        ),97        ComponentManifest(98            type: "prism.badge", name: "Badge", category: "foundation", summary: "A small colored status label.",99            props: [PropSpec("text", .string, "Badge text.", required: true), toneProp],100            keywords: ["tag", "status", "pill", "chip"], accessibilityRole: "staticText", accessibilityLabelProp: "text",101            examples: [["id": "status", "type": "prism.badge", "props": ["text": "Over budget", "tone": "danger"]]],102            fixture: fixture("prism.badge", ["text": "Verified", "tone": "success"])103        ),104        ComponentManifest(105            type: "prism.card", name: "Card", category: "foundation", summary: "A titled surface that groups content.",106            props: [PropSpec("title", .string, "Optional title above the content.")],107            acceptsChildren: true, keywords: ["panel", "group", "box", "surface", "tile"], accessibilityRole: "group", accessibilityLabelProp: "title",108            examples: [["id": "summary_card", "type": "prism.card", "props": ["title": "This month"], "children": ["total_label"]]],109            fixture: fixture("prism.card", ["title": "This month"], extra: [text("fx_a", "Card content goes here.")], children: ["fx_a"])110        ),111        ComponentManifest(112            type: "prism.divider", name: "Divider", category: "foundation", summary: "A thin separating line.",113            keywords: ["separator", "rule", "line"], accessibilityRole: "separator",114            examples: [["id": "sep", "type": "prism.divider"]],115            fixture: fixture("prism.divider", [:])116        ),117        ComponentManifest(118            type: "prism.progress", name: "Progress", category: "foundation", summary: "A bar showing a fraction from 0 to 1, e.g. budget used.",119            props: [120                PropSpec("value", .number, "Fraction complete, 0 to 1.", required: true), PropSpec("label", .string, "Text above the bar."),121                PropSpec("showPercent", .boolean, "Show the percentage.", default: true, dynamic: false), toneProp,122            ],123            keywords: ["bar", "budget", "completion", "meter", "gauge"], accessibilityRole: "progressIndicator", accessibilityLabelProp: "label",124            examples: [["id": "budget_bar", "type": "prism.progress", "props": ["label": "Budget used", "value": ["$expr": "sum(queries.month_total, 'total') / state.budget"]]]],125            fixture: fixture("prism.progress", ["label": "Budget used", "value": 0.62])126        ),127        ComponentManifest(128            type: "prism.toggle", name: "Toggle", category: "foundation", summary: "An on/off switch bound to state.",129            props: [PropSpec("label", .string, "Switch label.", required: true), PropSpec("value", .boolean, "State key holding true/false.", required: true, dynamic: false, binding: .required)],130            events: ["change"], keywords: ["switch", "checkbox", "boolean", "option"], accessibilityRole: "switch", accessibilityLabelProp: "label",131            examples: [["id": "only_big", "type": "prism.toggle", "props": ["label": "Only large amounts", "value": ["$bind": "onlyLarge"]]]],132            fixture: fixture("prism.toggle", ["label": "Show archived", "value": ["$bind": "archived"]], state: ["archived": false])133        ),134        ComponentManifest(135            type: "prism.stack", name: "Stack", category: "foundation", summary: "Lays children out in a column or a row.",136            props: [137                PropSpec("direction", .enum, "Column or row.", default: "vertical", values: ["vertical", "horizontal"], dynamic: false),138                PropSpec("spacing", .number, "Gap between children, in points.", default: 12, dynamic: false),139                PropSpec("align", .enum, "Cross-axis alignment.", default: "leading", values: ["leading", "center", "trailing", "stretch"], dynamic: false),140            ],141            acceptsChildren: true, keywords: ["layout", "row", "column", "vstack", "hstack", "container"], accessibilityRole: "group",142            examples: [["id": "filters_row", "type": "prism.stack", "props": ["direction": "horizontal", "spacing": 8], "children": ["search", "category_filter"]]],143            fixture: fixture("prism.stack", ["direction": "horizontal", "spacing": 16], extra: [text("fx_a", "First"), text("fx_b", "Second"), text("fx_c", "Third")], children: ["fx_a", "fx_b", "fx_c"])144        ),145        ComponentManifest(146            type: "prism.grid", name: "Grid", category: "foundation", summary: "Lays children out in equal columns.",147            props: [PropSpec("columns", .number, "Number of columns.", default: 2, dynamic: false), PropSpec("spacing", .number, "Gap in points.", default: 12, dynamic: false)],148            acceptsChildren: true, keywords: ["layout", "dashboard", "tiles", "columns"], accessibilityRole: "group",149            examples: [["id": "stats", "type": "prism.grid", "props": ["columns": 3], "children": ["stat_total", "stat_count", "stat_avg"]]],150            fixture: fixture("prism.grid", ["columns": 2], extra: [text("fx_a", "A"), text("fx_b", "B"), text("fx_c", "C"), text("fx_d", "D")], children: ["fx_a", "fx_b", "fx_c", "fx_d"])151        ),152        ComponentManifest(153            type: "prism.scroll", name: "Scroll view", category: "foundation", summary: "Makes tall content scrollable.",154            props: [PropSpec("axis", .enum, "Scroll direction.", default: "vertical", values: ["vertical", "horizontal"], dynamic: false)],155            acceptsChildren: true, keywords: ["scroll", "overflow", "long"], accessibilityRole: "scrollArea",156            examples: [["id": "page_scroll", "type": "prism.scroll", "children": ["content"]]],157            fixture: fixture("prism.scroll", [:], extra: [text("fx_a", "Scrollable content")], children: ["fx_a"])158        ),159        ComponentManifest(160            type: "prism.split", name: "Split view", category: "foundation", summary: "Two resizable panes side by side or stacked.",161            props: [PropSpec("direction", .enum, "Pane arrangement.", default: "horizontal", values: ["horizontal", "vertical"], dynamic: false)],162            acceptsChildren: true, maxChildren: 2, keywords: ["panes", "resizable", "master", "detail", "two column"], accessibilityRole: "splitGroup",163            examples: [["id": "main_split", "type": "prism.split", "children": ["list_pane", "detail_pane"]]],164            fixture: fixture("prism.split", [:], extra: [text("fx_a", "Left pane"), text("fx_b", "Right pane")], children: ["fx_a", "fx_b"])165        ),166        ComponentManifest(167            type: "prism.tabs", name: "Tab bar", category: "foundation", summary: "Switches between children; each child's `name` is its tab title.",168            props: [PropSpec("selection", .string, "State key holding the selected child's id.", dynamic: false, binding: .optional)],169            events: ["change"], acceptsChildren: true, keywords: ["tabs", "sections", "switcher", "views"], accessibilityRole: "tabGroup",170            examples: [["id": "main_tabs", "type": "prism.tabs", "children": ["transactions_tab", "charts_tab"]]],171            fixture: fixture("prism.tabs", [:], extra: [text("fx_a", "Overview"), text("fx_b", "Details")], children: ["fx_a", "fx_b"])172        ),173        ComponentManifest(174            type: "prism.toolbar", name: "Toolbar", category: "foundation", summary: "A bar of controls along the top of a page.",175            acceptsChildren: true, keywords: ["bar", "actions", "header", "controls"], accessibilityRole: "toolbar",176            examples: [["id": "top_bar", "type": "prism.toolbar", "children": ["search", "add_button"]]],177            fixture: fixture("prism.toolbar", [:], extra: [text("fx_a", "Transactions"), ["id": "fx_b", "type": "prism.button", "props": ["title": "Add", "icon": "plus"]]], children: ["fx_a", "fx_b"])178        ),179        ComponentManifest(180            type: "prism.modal", name: "Modal", category: "foundation", summary: "A sheet shown while a state key is true.",181            props: [182                PropSpec("title", .string, "Sheet title."),183                PropSpec("presented", .boolean, "State key that is true while the sheet is open.", required: true, dynamic: false, binding: .required),184                PropSpec("minWidth", .number, "Minimum width in points.", default: 420, dynamic: false),185            ],186            acceptsChildren: true, keywords: ["sheet", "dialog", "popup", "overlay"], accessibilityRole: "sheet", accessibilityLabelProp: "title",187            examples: [["id": "editor_sheet", "type": "prism.modal", "props": ["title": "New transaction", "presented": ["$bind": "showEditor"]], "children": ["editor"]]],188            fixture: fixture("prism.modal", ["title": "Details", "presented": ["$bind": "open"]], state: ["open": false], extra: [text("fx_a", "Inside the sheet")], children: ["fx_a"])189        ),190        ComponentManifest(191            type: "prism.alert", name: "Alert", category: "foundation", summary: "An inline banner; combine with `visible` to warn when a condition holds (e.g. over budget).",192            props: [PropSpec("title", .string, "Headline.", required: true), PropSpec("message", .string, "Supporting text."), PropSpec("tone", .enum, "Severity.", default: "warning", values: tones)],193            keywords: ["banner", "warning", "budget alert", "notice", "error", "threshold"], accessibilityRole: "alert", accessibilityLabelProp: "title",194            examples: [["id": "budget_alert", "type": "prism.alert", "props": [195                "title": "Over budget", "tone": "danger", "visible": ["$expr": "sum(queries.month_total, 'total') > state.budget"],196                "message": ["$expr": "concat('Spent ', formatCurrency(sum(queries.month_total, 'total')), ' of ', formatCurrency(state.budget))"],197            ]]],198            fixture: fixture("prism.alert", ["title": "Over budget", "message": "You spent more than planned this month.", "tone": "danger"])199        ),200        ComponentManifest(201            type: "prism.notification", name: "Notification area", category: "foundation", summary: "Shows the messages raised by `showNotification` actions.",202            props: [PropSpec("emptyText", .string, "Text when there is nothing to show.")],203            keywords: ["toast", "message", "feedback", "status"], accessibilityRole: "status",204            examples: [["id": "notices", "type": "prism.notification"]],205            fixture: fixture("prism.notification", ["emptyText": "No messages yet."])206        ),207        ComponentManifest(208            type: "prism.menu", name: "Menu", category: "foundation", summary: "A pull-down button with a list of actions.",209            props: [210                PropSpec("title", .string, "Button label."), PropSpec("icon", .string, "SF Symbol."),211                PropSpec("items", .list, "Entries: `{title, icon?, actions:[…]}`.", required: true, dynamic: false),212            ],213            keywords: ["dropdown", "actions", "more", "pull down", "options"], accessibilityRole: "menuButton", accessibilityLabelProp: "title",214            examples: [["id": "more_menu", "type": "prism.menu", "props": ["title": "More", "icon": "ellipsis.circle", "items": [["title": "Clear filter", "actions": [["type": "setState", "key": "category", "value": "All"]]]]]]],215            fixture: fixture("prism.menu", ["title": "Actions", "icon": "ellipsis.circle", "items": [["title": "Reset counter", "icon": "arrow.counterclockwise", "actions": [["type": "setState", "key": "count", "value": 0]]]]], state: ["count": 3])216        ),217    ]218219    static let forms: [ComponentManifest] = [220        ComponentManifest(221            type: "prism.textField", name: "Text field", category: "forms", summary: "Single-line text input bound to state.",222            props: [PropSpec("label", .string, "Field label."), PropSpec("placeholder", .string, "Hint shown when empty."), PropSpec("value", .string, "State key holding the text.", required: true, dynamic: false, binding: .required)],223            events: ["change", "submit"], keywords: ["input", "text", "name", "entry"], accessibilityRole: "textField", accessibilityLabelProp: "label",224            examples: [["id": "name_field", "type": "prism.textField", "props": ["label": "Description", "value": ["$bind": "form.description"]]]],225            fixture: fixture("prism.textField", ["label": "Name", "placeholder": "Type a name", "value": ["$bind": "name"]], state: ["name": ""])226        ),227        ComponentManifest(228            type: "prism.numberField", name: "Numeric input", category: "forms", summary: "Number input with optional bounds, bound to state.",229            props: [230                PropSpec("label", .string, "Field label."), PropSpec("value", .number, "State key holding the number.", required: true, dynamic: false, binding: .required),231                PropSpec("min", .number, "Lowest allowed value.", dynamic: false), PropSpec("max", .number, "Highest allowed value.", dynamic: false),232                PropSpec("step", .number, "Stepper increment.", default: 1, dynamic: false),233            ],234            events: ["change"], keywords: ["number", "quantity", "stepper", "integer"], accessibilityRole: "textField", accessibilityLabelProp: "label",235            examples: [["id": "qty", "type": "prism.numberField", "props": ["label": "Quantity", "value": ["$bind": "quantity"], "min": 0]]],236            fixture: fixture("prism.numberField", ["label": "Quantity", "value": ["$bind": "qty"], "min": 0, "max": 99], state: ["qty": 3])237        ),238        ComponentManifest(239            type: "prism.currencyField", name: "Currency input", category: "forms", summary: "Money amount input bound to state.",240            props: [PropSpec("label", .string, "Field label."), PropSpec("value", .number, "State key holding the amount.", required: true, dynamic: false, binding: .required), PropSpec("currencyCode", .string, "ISO code such as USD or CAD.", dynamic: false)],241            events: ["change"], keywords: ["money", "amount", "price", "budget", "dollars"], accessibilityRole: "textField", accessibilityLabelProp: "label",242            examples: [["id": "budget_field", "type": "prism.currencyField", "props": ["label": "Monthly budget", "value": ["$bind": "budget"]]]],243            fixture: fixture("prism.currencyField", ["label": "Monthly budget", "value": ["$bind": "budget"]], state: ["budget": 1500])244        ),245        ComponentManifest(246            type: "prism.datePicker", name: "Date picker", category: "forms", summary: "Calendar date input (stored as YYYY-MM-DD) bound to state.",247            props: [PropSpec("label", .string, "Field label."), PropSpec("value", .string, "State key holding the date.", required: true, dynamic: false, binding: .required)],248            events: ["change"], keywords: ["date", "calendar", "day", "when"], accessibilityRole: "dateField", accessibilityLabelProp: "label",249            examples: [["id": "date_field", "type": "prism.datePicker", "props": ["label": "Date", "value": ["$bind": "form.date"]]]],250            fixture: fixture("prism.datePicker", ["label": "Date", "value": ["$bind": "day"]], state: ["day": "2026-03-14"])251        ),252        ComponentManifest(253            type: "prism.dropdown", name: "Dropdown", category: "forms", summary: "Pick one value from fixed options or from the distinct values of a table column.",254            props: [255                PropSpec("label", .string, "Field label."), PropSpec("value", .string, "State key holding the choice.", required: true, dynamic: false, binding: .required),256                PropSpec("options", .list, "Fixed choices."), PropSpec("optionsFrom", .object, "`{table, column}`: use that column's distinct values.", dynamic: false),257                PropSpec("includeAll", .string, "Adds this entry first (e.g. \"All\") for filters.", dynamic: false),258            ],259            events: ["change"], keywords: ["select", "picker", "category filter", "choice", "popup"], accessibilityRole: "popUpButton", accessibilityLabelProp: "label",260            examples: [["id": "category_filter", "type": "prism.dropdown", "props": ["label": "Category", "value": ["$bind": "category"], "optionsFrom": ["table": "transactions", "column": "category"], "includeAll": "All"]]],261            fixture: fixture("prism.dropdown", ["label": "Category", "value": ["$bind": "category"], "options": ["Food", "Housing", "Fun"], "includeAll": "All"], state: ["category": "All"])262        ),263        ComponentManifest(264            type: "prism.search", name: "Search field", category: "forms", summary: "Search box bound to state; pair it with a query `search`.",265            props: [PropSpec("placeholder", .string, "Hint text.", default: "Search"), PropSpec("value", .string, "State key holding the search text.", required: true, dynamic: false, binding: .required)],266            events: ["change", "submit"], keywords: ["find", "filter", "query", "lookup"], accessibilityRole: "searchField", accessibilityLabelProp: "placeholder",267            examples: [["id": "search", "type": "prism.search", "props": ["placeholder": "Search transactions", "value": ["$bind": "search"]]]],268            fixture: fixture("prism.search", ["placeholder": "Search", "value": ["$bind": "q"]], state: ["q": ""])269        ),270        ComponentManifest(271            type: "prism.segmented", name: "Segmented control", category: "forms", summary: "Pick one of a few options shown side by side.",272            props: [PropSpec("label", .string, "Accessible label."), PropSpec("value", .string, "State key holding the choice.", required: true, dynamic: false, binding: .required), PropSpec("options", .list, "The choices.", required: true)],273            events: ["change"], keywords: ["switcher", "mode", "period", "tabs", "choice"], accessibilityRole: "radioGroup", accessibilityLabelProp: "label",274            examples: [["id": "period", "type": "prism.segmented", "props": ["label": "Period", "value": ["$bind": "period"], "options": ["Month", "Year"]]]],275            fixture: fixture("prism.segmented", ["label": "Period", "value": ["$bind": "period"], "options": ["Week", "Month", "Year"]], state: ["period": "Month"])276        ),277        ComponentManifest(278            type: "prism.formSection", name: "Form section", category: "forms", summary: "Groups form fields under a title.",279            props: [PropSpec("title", .string, "Section title.")],280            acceptsChildren: true, keywords: ["form", "group", "fieldset", "settings"], accessibilityRole: "group", accessibilityLabelProp: "title",281            examples: [["id": "details_section", "type": "prism.formSection", "props": ["title": "Details"], "children": ["name_field", "date_field"]]],282            fixture: fixture("prism.formSection", ["title": "Details"], extra: [text("fx_a", "Fields go here")], children: ["fx_a"])283        ),284        ComponentManifest(285            type: "prism.validationSummary", name: "Validation summary", category: "forms", summary: "Lists the messages of the rules whose `when` is true.",286            props: [PropSpec("title", .string, "Heading above the messages."), PropSpec("rules", .list, "Rules: `{when: {$expr}, message}`.", required: true, dynamic: false)],287            keywords: ["errors", "validation", "form check", "required"], accessibilityRole: "alert", accessibilityLabelProp: "title",288            examples: [["id": "form_errors", "type": "prism.validationSummary", "props": ["title": "Please fix", "rules": [["when": ["$expr": "state.amount <= 0"], "message": "Amount must be greater than zero."]]]]],289            fixture: fixture("prism.validationSummary", ["title": "Please fix", "rules": [["when": ["$expr": "state.amount <= 0"], "message": "Amount must be greater than zero."]]], state: ["amount": 0])290        ),291        ComponentManifest(292            type: "prism.filePicker", name: "File picker", category: "forms", summary: "Lets the user choose a file in an Open dialog; stores its name in state.",293            props: [294                PropSpec("label", .string, "Field label."), PropSpec("buttonTitle", .string, "Button text.", default: "Choose File…"),295                PropSpec("allowedExtensions", .list, "File extensions without dots, e.g. [\"csv\"].", dynamic: false),296                PropSpec("value", .string, "State key that receives the chosen file's name.", required: true, dynamic: false, binding: .required),297            ],298            events: ["select"], permissions: [Permission.filesImport], keywords: ["open", "upload", "attach", "browse", "document"], accessibilityRole: "button", accessibilityLabelProp: "label",299            examples: [["id": "attachment", "type": "prism.filePicker", "props": ["label": "Receipt", "allowedExtensions": ["pdf", "png"], "value": ["$bind": "receiptName"]]]],300            fixture: fixture("prism.filePicker", ["label": "Attachment", "value": ["$bind": "file"]], state: ["file": ""], permissions: [Permission.filesImport])301        ),302    ]303304    static let data: [ComponentManifest] = [305        ComponentManifest(306            type: "prism.table", name: "Table", category: "data", summary: "Sortable table over a query; filter it with the query's `filters` and `search`.",307            props: [308                PropSpec("query", .query, "What to show: `{table, filters?, search?, sort?, limit?}` or `{$ref: queryId}`.", required: true, dynamic: false),309                PropSpec("columns", .list, "Columns: `{column, title?, format?: text|number|currency|date|badge, align?, width?}`. Defaults to every column.", dynamic: false),310                PropSpec("selection", .any, "State key that receives the selected record's id.", dynamic: false, binding: .optional),311                PropSpec("sortable", .boolean, "Allow sorting by clicking headers.", default: true, dynamic: false),312                PropSpec("emptyTitle", .string, "Title of the empty state."), PropSpec("emptyMessage", .string, "Message of the empty state."),313            ],314            events: ["select"], permissions: storage, keywords: ["list", "rows", "records", "grid", "sortable", "filterable", "transactions"], accessibilityRole: "table",315            examples: [["id": "transactions_table", "type": "prism.table", "props": [316                "query": ["table": "transactions", "filters": [["column": "category", "op": "eq", "value": ["$bind": "category"], "unless": ["$expr": "state.category == 'All'"]]],317                          "search": ["columns": ["description"], "text": ["$bind": "search"]], "sort": [["column": "date", "descending": true]]],318                "columns": [["column": "date", "format": "date"], ["column": "description"], ["column": "category", "format": "badge"], ["column": "amount", "format": "currency", "align": "trailing"]],319                "selection": ["$bind": "selectedId"],320            ]]],321            fixture: fixture("prism.table", [322                "query": ["table": "fx_items", "sort": [["column": "date", "descending": true]]],323                "columns": [["column": "date", "format": "date"], ["column": "title"], ["column": "category", "format": "badge"], ["column": "amount", "format": "currency", "align": "trailing"]],324                "selection": ["$bind": "selected"],325            ], state: ["selected": nil], extra: [sampleTable], permissions: storage)326        ),327        ComponentManifest(328            type: "prism.csvImport", name: "CSV import", category: "data", summary: "A button that imports a CSV file into a table, matching columns by name and reporting skipped rows.",329            props: [PropSpec("table", .string, "Table that receives the rows.", required: true, dynamic: false), PropSpec("title", .string, "Button text.", default: "Import CSV…")],330            events: ["imported"], permissions: [Permission.storageLocal, Permission.filesImport], keywords: ["csv", "import", "upload", "bank export", "spreadsheet"], accessibilityRole: "button", accessibilityLabelProp: "title",331            examples: [["id": "import_button", "type": "prism.csvImport", "props": ["table": "transactions", "title": "Import CSV…"]]],332            fixture: fixture("prism.csvImport", ["table": "fx_items"], extra: [sampleTable], permissions: [Permission.storageLocal, Permission.filesImport])333        ),334        ComponentManifest(335            type: "prism.csvExport", name: "CSV export", category: "data", summary: "A button that saves the rows of a query as a CSV file.",336            props: [337                PropSpec("query", .query, "Rows to export.", required: true, dynamic: false), PropSpec("title", .string, "Button text.", default: "Export CSV…"),338                PropSpec("filename", .string, "Suggested file name.", default: "export.csv", dynamic: false),339            ],340            events: ["exported"], permissions: [Permission.storageLocal, Permission.filesExport], keywords: ["csv", "export", "download", "save", "spreadsheet"], accessibilityRole: "button", accessibilityLabelProp: "title",341            examples: [["id": "export_button", "type": "prism.csvExport", "props": ["query": ["table": "transactions"], "filename": "transactions.csv"]]],342            fixture: fixture("prism.csvExport", ["query": ["table": "fx_items"], "filename": "items.csv"], extra: [sampleTable], permissions: [Permission.storageLocal, Permission.filesExport])343        ),344        ComponentManifest(345            type: "prism.crud", name: "Record manager", category: "data", summary: "A complete list for one table with add, edit and delete built in (SQLite CRUD).",346            props: [347                PropSpec("table", .string, "The table to manage.", required: true, dynamic: false), PropSpec("title", .string, "Heading."),348                PropSpec("columns", .list, "Column names to show; defaults to all.", dynamic: false),349                PropSpec("allowAdd", .boolean, "Show Add.", default: true, dynamic: false), PropSpec("allowEdit", .boolean, "Allow editing.", default: true, dynamic: false),350                PropSpec("allowDelete", .boolean, "Allow deleting.", default: true, dynamic: false),351            ],352            events: ["saved", "deleted"], permissions: storage, keywords: ["crud", "manage", "edit records", "list editor", "database", "sqlite", "tasks", "contacts", "inventory"], accessibilityRole: "group", accessibilityLabelProp: "title",353            examples: [["id": "budgets_manager", "type": "prism.crud", "props": ["table": "budgets", "title": "Budgets"]]],354            fixture: fixture("prism.crud", ["table": "fx_items", "title": "Items"], extra: [sampleTable], permissions: storage)355        ),356        ComponentManifest(357            type: "prism.recordEditor", name: "Record editor", category: "data", summary: "A form for one record of a table: creates a new record, or edits the one whose id is given.",358            props: [359                PropSpec("table", .string, "The record's table.", required: true, dynamic: false),360                PropSpec("recordId", .any, "Id of the record to edit; empty creates a new one.", binding: .optional),361                PropSpec("fields", .list, "Column names to show; defaults to all.", dynamic: false),362                PropSpec("submitTitle", .string, "Save button text.", default: "Save"), PropSpec("allowDelete", .boolean, "Show Delete when editing.", default: true, dynamic: false),363            ],364            events: ["saved", "deleted", "cancelled"], permissions: storage, keywords: ["form", "edit", "new record", "detail", "add entry"], accessibilityRole: "group",365            examples: [["id": "editor", "type": "prism.recordEditor", "props": ["table": "transactions", "recordId": ["$bind": "selectedId"]],366                        "events": ["saved": [["type": "setState", "key": "showEditor", "value": false]], "cancelled": [["type": "setState", "key": "showEditor", "value": false]]]]],367            fixture: fixture("prism.recordEditor", ["table": "fx_items", "recordId": 1], extra: [sampleTable], permissions: storage)368        ),369        ComponentManifest(370            type: "prism.aggregation", name: "Statistic", category: "data", summary: "A tile showing one number: a query aggregate or a computed value.",371            props: [372                PropSpec("label", .string, "What the number means.", required: true),373                PropSpec("query", .query, "An aggregate query; the first row is used.", dynamic: false), PropSpec("valueColumn", .string, "Result column to show.", dynamic: false),374                PropSpec("value", .any, "Alternative to `query`: a computed value."),375                PropSpec("format", .enum, "Number format.", default: "number", values: ["number", "currency", "percent", "text"], dynamic: false),376                PropSpec("icon", .string, "SF Symbol."), toneProp,377            ],378            permissions: [], keywords: ["total", "sum", "count", "average", "kpi", "metric", "stat", "number"], accessibilityRole: "staticText", accessibilityLabelProp: "label",379            examples: [["id": "stat_total", "type": "prism.aggregation", "props": ["label": "Total spent", "format": "currency", "icon": "creditcard",380                        "query": ["table": "transactions", "aggregates": [["fn": "sum", "column": "amount", "as": "total"]]], "valueColumn": "total"]]],381            fixture: fixture("prism.aggregation", ["label": "Total", "format": "currency", "icon": "sum", "query": ["table": "fx_items", "aggregates": [["fn": "sum", "column": "amount", "as": "total"]]], "valueColumn": "total"], extra: [sampleTable], permissions: storage)382        ),383    ]384385    private static func chart(_ type: String, _ name: String, _ summary: String, _ keywords: [String], _ exampleTitle: String) -> ComponentManifest {386        ComponentManifest(387            type: type, name: name, category: "charts", summary: summary,388            props: [389                PropSpec("query", .query, "A grouped query, e.g. totals by month.", required: true, dynamic: false),390                PropSpec("x", .string, "Result column for the horizontal axis.", required: true, dynamic: false),391                PropSpec("y", .string, "Result column for the values.", required: true, dynamic: false),392                PropSpec("title", .string, "Chart title."),393                PropSpec("format", .enum, "Value format.", default: "number", values: ["number", "currency"], dynamic: false), toneProp,394            ],395            permissions: storage, keywords: keywords, accessibilityRole: "chart", accessibilityLabelProp: "title",396            examples: [["id": "monthly_chart", "type": .string(type), "props": ["title": .string(exampleTitle), "x": "month", "y": "total", "format": "currency",397                        "query": ["table": "transactions", "groupBy": ["column": "date", "bucket": "month", "as": "month"], "aggregates": [["fn": "sum", "column": "amount", "as": "total"]]]]]],398            fixture: fixture(type, ["title": .string(exampleTitle), "x": "month", "y": "total", "format": "currency", "query": byMonth], extra: [sampleTable], permissions: storage)399        )400    }401402    static let charts: [ComponentManifest] = [403        chart("prism.chart.line", "Line chart", "A line over an ordered axis, e.g. spending per month.", ["trend", "time series", "monthly", "line", "graph", "evolution"], "Spending per month"),404        chart("prism.chart.bar", "Bar chart", "Bars comparing a value across groups or periods.", ["bars", "compare", "monthly", "histogram", "graph", "columns"], "Monthly totals"),405        ComponentManifest(406            type: "prism.chart.pie", name: "Pie / donut chart", category: "charts", summary: "Shares of a whole, e.g. spending by category.",407            props: [408                PropSpec("query", .query, "A grouped query, e.g. totals by category.", required: true, dynamic: false),409                PropSpec("label", .string, "Result column naming each slice.", required: true, dynamic: false),410                PropSpec("value", .string, "Result column with each slice's value.", required: true, dynamic: false),411                PropSpec("title", .string, "Chart title."), PropSpec("donut", .boolean, "Draw as a ring.", default: true, dynamic: false),412                PropSpec("format", .enum, "Value format.", default: "number", values: ["number", "currency"], dynamic: false),413            ],414            permissions: storage, keywords: ["pie", "donut", "share", "breakdown", "category", "proportion", "graph"], accessibilityRole: "chart", accessibilityLabelProp: "title",415            examples: [["id": "category_chart", "type": "prism.chart.pie", "props": ["title": "By category", "label": "category", "value": "total", "format": "currency",416                        "query": ["table": "transactions", "groupBy": ["column": "category", "as": "category"], "aggregates": [["fn": "sum", "column": "amount", "as": "total"]]]]]],417            fixture: fixture("prism.chart.pie", ["title": "By category", "label": "category", "value": "total", "format": "currency", "query": byCategory], extra: [sampleTable], permissions: storage)418        ),419    ]420421    static let navigation: [ComponentManifest] = [422        ComponentManifest(423            type: "prism.sidebar", name: "Sidebar", category: "navigation", summary: "A source list on the left that switches between its children; each child's `name` is its entry.",424            props: [425                PropSpec("selection", .string, "State key holding the selected child's id.", dynamic: false, binding: .optional),426                PropSpec("icons", .object, "Optional SF Symbol per child id.", dynamic: false),427            ],428            events: ["change"], acceptsChildren: true, keywords: ["navigation", "source list", "sections", "menu", "master detail"], accessibilityRole: "outline",429            examples: [["id": "nav", "type": "prism.sidebar", "props": ["icons": ["transactions_view": "list.bullet", "charts_view": "chart.pie"]], "children": ["transactions_view", "charts_view"]]],430            fixture: fixture("prism.sidebar", ["icons": ["fx_a": "list.bullet", "fx_b": "chart.pie"]], extra: [text("fx_a", "Transactions"), text("fx_b", "Charts")], children: ["fx_a", "fx_b"])431        ),432        ComponentManifest(433            type: "prism.inspector", name: "Inspector", category: "navigation", summary: "A trailing panel for the details of the current selection.",434            props: [435                PropSpec("title", .string, "Panel title."), PropSpec("presented", .boolean, "State key controlling whether the panel is shown; shown when omitted.", binding: .optional),436                PropSpec("panelWidth", .number, "Width in points.", default: 280, dynamic: false),437            ],438            acceptsChildren: true, keywords: ["details", "side panel", "properties", "trailing"], accessibilityRole: "group", accessibilityLabelProp: "title",439            examples: [["id": "details_panel", "type": "prism.inspector", "props": ["title": "Details", "presented": ["$expr": "state.selectedId != null"]], "children": ["editor"]]],440            fixture: fixture("prism.inspector", ["title": "Details"], extra: [text("fx_a", "Selection details")], children: ["fx_a"])441        ),442    ]443444    static let logic: [ComponentManifest] = [445        ComponentManifest(446            type: "prism.timer", name: "Timer", category: "logic", summary: "Invisible: runs its `tick` actions at a fixed interval while `running` is true (clocks, countdowns, auto-refresh, games).",447            props: [448                PropSpec("interval", .number, "Seconds between ticks (0.05 or more).", required: true, dynamic: false),449                PropSpec("running", .boolean, "Ticks only while true.", default: true),450            ],451            events: ["tick"], keywords: ["interval", "clock", "countdown", "stopwatch", "auto refresh", "every second", "schedule", "animation"], accessibilityRole: "none",452            examples: [["id": "second_timer", "type": "prism.timer", "props": ["interval": 1, "running": ["$expr": "state.running"]],453                        "events": ["tick": [["type": "setState", "key": "seconds", "value": ["$expr": "state.seconds + 1"]]]]]],454            fixture: fixture("prism.timer", ["interval": 1, "running": ["$expr": "state.running"]], state: ["running": false, "seconds": 0])455        ),456    ]457}458
Files main
Menu

Theme