550c98f275
Reorganización física de crates/: - core/ (mezclaba 6 propósitos) se divide en protocol/, init/, runtime/, compat/ - shared/ (3 crates) se redistribuye en protocol/ e init/ - lapaloma (sub-módulo de ui_engine) se promueve a modules/pineal/ Renames de proyectos: - shipote → shuma (runtime de sandboxes) - nouser → akasha (explorador de Mónadas) - yahweh → nahual (motor GPUI, antes ui_engine/) - lapaloma → pineal (data-viz agnóstica) Fraccionamiento UI → core agnóstico: - vista-core (DeckState + snap, 175 LOC, 5 tests verdes) - barra-core (Task + render_html + sanitize, 90 LOC, 5 tests verdes) - vista-web y barra-web ahora son thin DOM bindings Documentación nueva: - 16 SDDs por subdirectorio (≤80 LOC c/u): protocol/init/runtime/compat + 10 módulos + apps/ - docs/STATUS.md con cifras reales por proyecto - docs/ROADMAP.md con plan a finalización (6 hitos, ~6-8 semanas) - CHANGELOG.md particionado en docs/changelog/<proyecto>.md (7 buckets) Automatización: - scripts/reorg.py — script idempotente que: git mv directorios, renombra package names, recomputa path = refs, reescribe imports rust, actualiza workspace Cargo.toml. Soporta --dry-run. - scripts/split-changelog.py — particiona CHANGELOG por componente. Validación: - cargo check --workspace pasa (124 crates + 2 nuevos cores). - 10 tests adicionales (5 en vista-core + 5 en barra-core) verdes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
73 lines
2.7 KiB
Rust
73 lines
2.7 KiB
Rust
//! Barra-web — binding DOM de la taskbar. Re-exporta `Task` desde
|
|
//! `barra-core` y delega el render-to-html al core. Aquí sólo viven el
|
|
//! mount sobre un `<ul>`, el listener de click delegado y los lookups
|
|
//! de posición (bounding rects) que son intrínsecos al DOM.
|
|
//!
|
|
//! Contrato HTML mínimo:
|
|
//! ```html
|
|
//! <ul id="my-tasks" class="taskbar-list" role="presentation"></ul>
|
|
//! ```
|
|
//!
|
|
//! Convenciones de clase generadas:
|
|
//! - `.taskbar-item` — cada cajita
|
|
//! - `.taskbar-item.active` — la cajita visible/foreground
|
|
//! - `.taskbar-item-dot` — punto decorativo
|
|
//! - `data-task="<id>"` — identificador único usable por CSS para theming
|
|
|
|
use std::cell::RefCell;
|
|
use std::rc::Rc;
|
|
|
|
pub use barra_core::Task;
|
|
use barra_core::{render_html, sanitize_attr};
|
|
use wasm_bindgen::prelude::*;
|
|
use wasm_bindgen::JsCast;
|
|
use web_sys::{Element, HtmlElement, MouseEvent};
|
|
|
|
#[derive(Clone)]
|
|
pub struct TaskList {
|
|
list: HtmlElement,
|
|
on_click: Rc<RefCell<Option<Box<dyn FnMut(&str, f64, f64)>>>>,
|
|
}
|
|
|
|
impl TaskList {
|
|
pub fn mount(list: HtmlElement) -> Result<Self, JsValue> {
|
|
let on_click: Rc<RefCell<Option<Box<dyn FnMut(&str, f64, f64)>>>> =
|
|
Rc::new(RefCell::new(None));
|
|
let on_click2 = on_click.clone();
|
|
let cb = Closure::<dyn FnMut(MouseEvent)>::new(move |e: MouseEvent| {
|
|
let Some(target) = e.target() else { return };
|
|
let Ok(target_el): Result<Element, _> = target.dyn_into() else { return };
|
|
let Ok(Some(item)) = target_el.closest(".taskbar-item") else { return };
|
|
let Some(id) = item.get_attribute("data-task") else { return };
|
|
let rect = item.get_bounding_client_rect();
|
|
let cx = rect.left() + rect.width() / 2.0;
|
|
let cy = rect.top() + rect.height() / 2.0;
|
|
if let Some(cb) = on_click2.borrow_mut().as_mut() {
|
|
cb(&id, cx, cy);
|
|
}
|
|
});
|
|
list.add_event_listener_with_callback("click", cb.as_ref().unchecked_ref())?;
|
|
cb.forget();
|
|
Ok(Self { list, on_click })
|
|
}
|
|
|
|
pub fn set_tasks(&self, tasks: &[Task]) {
|
|
self.list.set_inner_html(&render_html(tasks));
|
|
}
|
|
|
|
pub fn on_click<F: FnMut(&str, f64, f64) + 'static>(&self, cb: F) {
|
|
*self.on_click.borrow_mut() = Some(Box::new(cb));
|
|
}
|
|
|
|
pub fn task_center(&self, id: &str) -> Option<(f64, f64)> {
|
|
let sel = format!(".taskbar-item[data-task=\"{}\"]", sanitize_attr(id));
|
|
let el = self.list.query_selector(&sel).ok().flatten()?;
|
|
let rect = el.get_bounding_client_rect();
|
|
Some((rect.left() + rect.width() / 2.0, rect.top() + rect.height() / 2.0))
|
|
}
|
|
|
|
pub fn list_el(&self) -> &HtmlElement {
|
|
&self.list
|
|
}
|
|
}
|