wcl_wdoc 0.11.2-alpha

WCL documentation format — build structured docs with WCL, render to HTML
    export let terminal_widget_dropdown_item = (item) => {
        kind = "menu_item",
        id = item.id,
        label = attr_or(item, "label", "Item"),
        target = attr_or(item, "target", ""),
        close_targets = attr_or(item, "close_targets", ""),
        disabled = attr_or(item, "disabled", "false") == "true"
    }

    export let terminal_widget_dropdown = (b) => {
        let row = attr_or(b, "row", 0)
        let col = attr_or(b, "col", 0)
        let item_blocks = children(b, "wdoc::draw::menu_item")
        let value = attr_or(b, "value", "")
        let placeholder = attr_or(b, "placeholder", "Select")
        let selected_index = attr_or(b, "selected_index", -1)
        let selected = value != "" ? value : (selected_index >= 0 && len(item_blocks) > selected_index ? attr_or(item_blocks[selected_index], "label", placeholder) : placeholder)
        let cols = attr_or(b, "cols", 12)
        let disabled = attr_or(b, "disabled", "false") == "true"
        let menu_id = to_string(b.id) + "_menu"
        let fg = attr_or(b, "foreground_fill", "#d7e0ff")
        let muted = attr_or(b, "muted_fill", "#94a3b8")
        let bg = attr_or(b, "background_fill", "#111827")
        let hover_bg = attr_or(b, "hover_background_fill", "#38bdf8")
        let hover_fg = attr_or(b, "hover_foreground_fill", "#06121f")
        let shown_fill = value == "" && selected_index < 0 ? muted : fg
        let base_class = attr_or(b, "class", "wdoc-widget-terminal_dropdown")
        let control_class = disabled ? "wdoc-terminal-control wdoc-terminal-control-disabled" : "wdoc-terminal-control"
        let events = disabled ? [] : [
            { trigger = "hover", state = "hovered", mode = "while" },
            { trigger = "click", target = menu_id, state = "shown", mode = "toggle" }
        ]
        let menu_class = attr_or(b, "open", "false") == "true" ? "wdoc-terminal-dropdown-menu wdoc-state-shown" : "wdoc-terminal-dropdown-menu"
        let items = map(item_blocks, item => wdoc::terminal_widget_dropdown_item(item))
        let item_shapes = map(range(0, len(items)), i => wdoc::terminal_menu_item_shape(b, items[i], i, row + 1, col, cols, fg, bg, hover_fg, hover_bg, [], [], [menu_id]))
        [
            {
                kind = "group",
                id = to_string(b.id),
                row = row,
                col = col,
                rows = 1,
                cols = cols,
                class = base_class + " " + control_class,
                cursor = disabled ? "default" : "pointer",
                pointer_events = disabled ? "none" : "all",
                _wdoc_runtime = "true",
                _wdoc_terminal_grid_group = "true",
                events = events,
                children = [
                    {
                        kind = "terminal_surface",
                        id = to_string(b.id) + "_surface",
                        row = row,
                        col = col,
                        cols = cols,
                        background_fill = bg,
                        hover_background_fill = hover_bg,
                        _wdoc_runtime = "true"
                    },
                    {
                        kind = "terminal_text",
                        id = to_string(b.id) + "_label",
                        row = row,
                        col = col,
                        cols = cols,
                        content = " " + selected + " v",
                        foreground_fill = shown_fill,
                        _wdoc_runtime = "true",
                        pointer_events = "none"
                    }
                ]
            },
            {
                kind = "group",
                id = menu_id,
                row = row + 1,
                col = col,
                rows = len(item_blocks) > 0 ? len(item_blocks) : 1,
                cols = cols,
                class = menu_class,
                _wdoc_runtime = "true",
                _wdoc_terminal_grid_group = "true",
                children = concat([
                    { kind = "terminal_surface", id = menu_id + "_surface", row = row + 1, col = col, rows = len(item_blocks) > 0 ? len(item_blocks) : 1, cols = cols, background_fill = bg, _wdoc_runtime = "true" }
                ], item_shapes)
            }
        ]
    }