Skip to main content

native/guppy_nif/src/ir_allowed.rs

pub(crate) fn allowed_node_fields(kind: &str) -> Option<&'static [&'static str]> {
    Some(match kind {
        "text" => &["kind", "content", "id", "style", "runs", "events"],
        "div" => &[
            "kind",
            "children",
            "id",
            "style",
            "hover_style",
            "focus_style",
            "focus_visible_style",
            "in_focus_style",
            "active_style",
            "disabled_style",
            "animation",
            "disabled",
            "stack_priority",
            "occlude",
            "focusable",
            "tab_stop",
            "tab_index",
            "track_scroll",
            "anchor_scroll",
            "scroll_to",
            "tooltip",
            "actions",
            "shortcuts",
            "events",
        ],
        "scroll" => &["kind", "children", "id", "axis", "style"],
        "popover" => &[
            "kind",
            "label",
            "open",
            "children",
            "id",
            "style",
            "popover_style",
            "anchor",
            "anchor_position",
            "anchor_offset",
            "anchor_position_mode",
            "anchor_fit",
            "snap_margin",
            "close_on_click_outside",
            "stack_priority",
            "disabled",
            "events",
        ],
        "uniform_list" => &["kind", "items", "id", "style", "item_style", "events"],
        "list" => &["kind", "items", "id", "style", "item_style", "events"],
        "data_table" => &[
            "kind",
            "columns",
            "rows",
            "id",
            "style",
            "header_style",
            "row_style",
            "cell_style",
            "selected_row_id",
            "selected_cell",
            "sort",
            "events",
        ],
        "tree" => &[
            "kind",
            "nodes",
            "id",
            "style",
            "row_style",
            "selected_id",
            "events",
        ],
        "canvas" => &["kind", "commands", "id", "style", "events"],
        "select" => &[
            "kind",
            "options",
            "id",
            "value",
            "open",
            "placeholder",
            "style",
            "list_style",
            "option_style",
            "anchor",
            "anchor_offset",
            "anchor_fit",
            "snap_margin",
            "disabled",
            "tab_index",
            "events",
        ],
        "image" => &["kind", "source", "id", "style", "object_fit", "grayscale"],
        "icon" => &["kind", "source", "id", "style"],
        "spacer" => &["kind", "id", "style"],
        "checkbox" => &[
            "kind",
            "label",
            "checked",
            "id",
            "style",
            "hover_style",
            "focus_style",
            "focus_visible_style",
            "in_focus_style",
            "active_style",
            "disabled_style",
            "disabled",
            "tab_index",
            "events",
        ],
        "radio" => &[
            "kind",
            "label",
            "value",
            "checked",
            "id",
            "style",
            "hover_style",
            "focus_style",
            "focus_visible_style",
            "in_focus_style",
            "active_style",
            "disabled_style",
            "disabled",
            "tab_index",
            "events",
        ],
        "button" => &[
            "kind",
            "label",
            "id",
            "style",
            "hover_style",
            "focus_style",
            "focus_visible_style",
            "in_focus_style",
            "active_style",
            "disabled_style",
            "animation",
            "disabled",
            "tab_index",
            "actions",
            "shortcuts",
            "events",
        ],
        "text_input" => &[
            "kind",
            "value",
            "id",
            "placeholder",
            "style",
            "disabled",
            "tab_index",
            "actions",
            "shortcuts",
            "events",
        ],
        "textarea" => &[
            "kind",
            "value",
            "id",
            "placeholder",
            "style",
            "disabled",
            "tab_index",
            "actions",
            "shortcuts",
            "events",
        ],
        _ => return None,
    })
}

pub(crate) fn allowed_node_event_fields(
    kind: &str,
) -> Option<(&'static [&'static str], &'static str)> {
    Some(match kind {
        "text" => (&["click"], "text events"),
        "div" => (
            &[
                "click",
                "hover",
                "focus",
                "blur",
                "key_down",
                "key_up",
                "context_menu",
                "drag_start",
                "drag_move",
                "drop",
                "mouse_down",
                "mouse_up",
                "mouse_move",
                "scroll_wheel",
            ],
            "div events",
        ),
        "popover" => (&["click", "close"], "popover events"),
        "uniform_list" => (&["click", "context_menu"], "uniform_list events"),
        "list" => (&["click", "context_menu"], "list events"),
        "data_table" => (
            &[
                "row_click",
                "cell_click",
                "sort",
                "column_reorder",
                "column_resize",
                "row_context_menu",
                "cell_context_menu",
            ],
            "data_table events",
        ),
        "tree" => (&["select", "toggle", "context_menu"], "tree events"),
        "canvas" => (&["click", "context_menu"], "canvas events"),
        "select" => (
            &["click", "change", "close", "focus", "blur"],
            "select events",
        ),
        "checkbox" => (&["change", "focus", "blur"], "checkbox events"),
        "radio" => (&["change", "focus", "blur"], "radio events"),
        "button" => (
            &[
                "click",
                "hover",
                "focus",
                "blur",
                "key_down",
                "key_up",
                "context_menu",
                "mouse_down",
                "mouse_up",
                "mouse_move",
            ],
            "button events",
        ),
        "text_input" => (
            &["change", "focus", "blur", "context_menu"],
            "text_input events",
        ),
        "textarea" => (
            &["change", "focus", "blur", "context_menu"],
            "textarea events",
        ),
        _ => return None,
    })
}