💥 Agrupa componentes en packs en lugar de bundles
This commit is contained in:
parent
f1f6f495bb
commit
9a63cacd8f
11 changed files with 67 additions and 67 deletions
|
|
@ -162,7 +162,7 @@ pub struct MegaMenu {
|
|||
renderable: Renderable,
|
||||
id : IdentifierValue,
|
||||
classes : Classes,
|
||||
items : ComponentsBundle,
|
||||
items : PackComponents,
|
||||
template : String,
|
||||
}
|
||||
|
||||
|
|
@ -255,12 +255,12 @@ impl MegaMenu {
|
|||
}
|
||||
|
||||
pub fn with_item(mut self, item: MegaMenuItem) -> Self {
|
||||
self.items.alter_bundle(BundleOp::Add, item);
|
||||
self.items.alter_pack(PackOp::Add, item);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_items(&mut self, op: BundleOp, item: MegaMenuItem) -> &mut Self {
|
||||
self.items.alter_bundle(op, item);
|
||||
pub fn alter_items(&mut self, op: PackOp, item: MegaMenuItem) -> &mut Self {
|
||||
self.items.alter_pack(op, item);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +276,7 @@ impl MegaMenu {
|
|||
&self.classes
|
||||
}
|
||||
|
||||
pub fn items(&self) -> &ComponentsBundle {
|
||||
pub fn items(&self) -> &PackComponents {
|
||||
&self.items
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub struct Container {
|
|||
classes : Classes,
|
||||
inner_classes : Classes,
|
||||
container_type: ContainerType,
|
||||
components : ComponentsBundle,
|
||||
components : PackComponents,
|
||||
template : String,
|
||||
}
|
||||
|
||||
|
|
@ -159,12 +159,12 @@ impl Container {
|
|||
}
|
||||
|
||||
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
self.components.alter_bundle(BundleOp::Add, component);
|
||||
self.components.alter_pack(PackOp::Add, component);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_components(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_bundle(op, component);
|
||||
pub fn alter_components(&mut self, op: PackOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_pack(op, component);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ impl Container {
|
|||
&self.container_type
|
||||
}
|
||||
|
||||
pub fn components(&self) -> &ComponentsBundle {
|
||||
pub fn components(&self) -> &PackComponents {
|
||||
&self.components
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ pub struct Form {
|
|||
action : AttributeValue,
|
||||
charset : AttributeValue,
|
||||
method : FormMethod,
|
||||
elements : ComponentsBundle,
|
||||
elements : PackComponents,
|
||||
template : String,
|
||||
}
|
||||
|
||||
|
|
@ -125,12 +125,12 @@ impl Form {
|
|||
}
|
||||
|
||||
pub fn with_element(mut self, element: impl ComponentTrait) -> Self {
|
||||
self.elements.alter_bundle(BundleOp::Add, element);
|
||||
self.elements.alter_pack(PackOp::Add, element);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_elements(&mut self, op: BundleOp, element: impl ComponentTrait) -> &mut Self {
|
||||
self.elements.alter_bundle(op, element);
|
||||
pub fn alter_elements(&mut self, op: PackOp, element: impl ComponentTrait) -> &mut Self {
|
||||
self.elements.alter_pack(op, element);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ impl Form {
|
|||
&self.method
|
||||
}
|
||||
|
||||
pub fn elements(&self) -> &ComponentsBundle {
|
||||
pub fn elements(&self) -> &PackComponents {
|
||||
&self.elements
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ pub struct Column {
|
|||
id : IdentifierValue,
|
||||
classes : Classes,
|
||||
size : ColumnSize,
|
||||
components: ComponentsBundle,
|
||||
components: PackComponents,
|
||||
template : String,
|
||||
}
|
||||
|
||||
|
|
@ -140,12 +140,12 @@ impl Column {
|
|||
}
|
||||
|
||||
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
self.components.alter_bundle(BundleOp::Add, component);
|
||||
self.components.alter_pack(PackOp::Add, component);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_components(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_bundle(op, component);
|
||||
pub fn alter_components(&mut self, op: PackOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_pack(op, component);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +165,7 @@ impl Column {
|
|||
&self.size
|
||||
}
|
||||
|
||||
pub fn components(&self) -> &ComponentsBundle {
|
||||
pub fn components(&self) -> &PackComponents {
|
||||
&self.components
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub struct Row {
|
|||
renderable: Renderable,
|
||||
id : IdentifierValue,
|
||||
classes : Classes,
|
||||
columns : ComponentsBundle,
|
||||
columns : PackComponents,
|
||||
template : String,
|
||||
}
|
||||
|
||||
|
|
@ -87,12 +87,12 @@ impl Row {
|
|||
}
|
||||
|
||||
pub fn with_column(mut self, column: grid::Column) -> Self {
|
||||
self.columns.alter_bundle(BundleOp::Add, column);
|
||||
self.columns.alter_pack(PackOp::Add, column);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_columns(&mut self, op: BundleOp, column: grid::Column) -> &mut Self {
|
||||
self.columns.alter_bundle(op, column);
|
||||
pub fn alter_columns(&mut self, op: PackOp, column: grid::Column) -> &mut Self {
|
||||
self.columns.alter_pack(op, column);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ impl Row {
|
|||
&self.classes
|
||||
}
|
||||
|
||||
pub fn columns(&self) -> &ComponentsBundle {
|
||||
pub fn columns(&self) -> &PackComponents {
|
||||
&self.columns
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ pub struct Paragraph {
|
|||
renderable: Renderable,
|
||||
id : IdentifierValue,
|
||||
classes : Classes,
|
||||
components: ComponentsBundle,
|
||||
components: PackComponents,
|
||||
display : ParagraphDisplay,
|
||||
template : String,
|
||||
}
|
||||
|
|
@ -98,12 +98,12 @@ impl Paragraph {
|
|||
}
|
||||
|
||||
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
self.components.alter_bundle(BundleOp::Add, component);
|
||||
self.components.alter_pack(PackOp::Add, component);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_components(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_bundle(op, component);
|
||||
pub fn alter_components(&mut self, op: PackOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_pack(op, component);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ impl Paragraph {
|
|||
&self.classes
|
||||
}
|
||||
|
||||
pub fn components(&self) -> &ComponentsBundle {
|
||||
pub fn components(&self) -> &PackComponents {
|
||||
&self.components
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub struct Block {
|
|||
id : IdentifierValue,
|
||||
classes : Classes,
|
||||
title : AttributeValue,
|
||||
components: ComponentsBundle,
|
||||
components: PackComponents,
|
||||
template : String,
|
||||
}
|
||||
|
||||
|
|
@ -98,12 +98,12 @@ impl Block {
|
|||
}
|
||||
|
||||
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
self.components.alter_bundle(BundleOp::Add, component);
|
||||
self.components.alter_pack(PackOp::Add, component);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_components(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_bundle(op, component);
|
||||
pub fn alter_components(&mut self, op: PackOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_pack(op, component);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ impl Block {
|
|||
&self.title
|
||||
}
|
||||
|
||||
pub fn components(&self) -> &ComponentsBundle {
|
||||
pub fn components(&self) -> &PackComponents {
|
||||
&self.components
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ pub use definition::{component_mut, component_ref, AnyComponent, BaseComponent,
|
|||
mod one;
|
||||
pub use one::OneComponent;
|
||||
|
||||
mod bundle;
|
||||
pub use bundle::{BundleOp, ComponentsBundle};
|
||||
mod pack;
|
||||
pub use pack::{PackComponents, PackOp};
|
||||
|
||||
mod renderable;
|
||||
pub use renderable::{IsRenderable, Renderable};
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::{fn_builder, Handle};
|
|||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
pub enum BundleOp {
|
||||
pub enum PackOp {
|
||||
Add,
|
||||
AddAfterId(&'static str),
|
||||
AddBeforeId(&'static str),
|
||||
|
|
@ -17,41 +17,41 @@ pub enum BundleOp {
|
|||
pub type ArcLockComponent = Arc<RwLock<dyn ComponentTrait>>;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct ComponentsBundle(Vec<ArcLockComponent>);
|
||||
pub struct PackComponents(Vec<ArcLockComponent>);
|
||||
|
||||
impl ComponentsBundle {
|
||||
impl PackComponents {
|
||||
pub fn new() -> Self {
|
||||
ComponentsBundle::default()
|
||||
PackComponents::default()
|
||||
}
|
||||
|
||||
pub fn new_with(component: impl ComponentTrait) -> Self {
|
||||
let mut bundle = ComponentsBundle::new();
|
||||
bundle.alter_bundle(BundleOp::Add, component);
|
||||
let mut bundle = PackComponents::new();
|
||||
bundle.alter_pack(PackOp::Add, component);
|
||||
bundle
|
||||
}
|
||||
|
||||
pub(crate) fn merge(one: Option<&ComponentsBundle>, other: Option<&ComponentsBundle>) -> Self {
|
||||
pub(crate) fn merge(one: Option<&PackComponents>, other: Option<&PackComponents>) -> Self {
|
||||
if let Some(one) = one {
|
||||
let mut components = one.0.clone();
|
||||
if let Some(other) = other {
|
||||
components.append(&mut other.0.clone());
|
||||
}
|
||||
ComponentsBundle(components)
|
||||
PackComponents(components)
|
||||
} else if let Some(other) = other {
|
||||
ComponentsBundle(other.0.clone())
|
||||
PackComponents(other.0.clone())
|
||||
} else {
|
||||
ComponentsBundle::default()
|
||||
PackComponents::default()
|
||||
}
|
||||
}
|
||||
|
||||
// ComponentsBundle BUILDER.
|
||||
// PackComponents BUILDER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_bundle(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
pub fn alter_pack(&mut self, op: PackOp, component: impl ComponentTrait) -> &mut Self {
|
||||
let arc = Arc::new(RwLock::new(component));
|
||||
match op {
|
||||
BundleOp::Add => self.0.push(arc),
|
||||
BundleOp::AddAfterId(id) => {
|
||||
PackOp::Add => self.0.push(arc),
|
||||
PackOp::AddAfterId(id) => {
|
||||
match self
|
||||
.0
|
||||
.iter()
|
||||
|
|
@ -61,7 +61,7 @@ impl ComponentsBundle {
|
|||
_ => self.0.push(arc),
|
||||
}
|
||||
}
|
||||
BundleOp::AddBeforeId(id) => {
|
||||
PackOp::AddBeforeId(id) => {
|
||||
match self
|
||||
.0
|
||||
.iter()
|
||||
|
|
@ -71,8 +71,8 @@ impl ComponentsBundle {
|
|||
_ => self.0.insert(0, arc),
|
||||
}
|
||||
}
|
||||
BundleOp::AddFirst => self.0.insert(0, arc),
|
||||
BundleOp::RemoveById(id) => {
|
||||
PackOp::AddFirst => self.0.insert(0, arc),
|
||||
PackOp::RemoveById(id) => {
|
||||
if let Some(index) = self
|
||||
.0
|
||||
.iter()
|
||||
|
|
@ -81,7 +81,7 @@ impl ComponentsBundle {
|
|||
self.0.remove(index);
|
||||
}
|
||||
}
|
||||
BundleOp::ReplaceById(id) => {
|
||||
PackOp::ReplaceById(id) => {
|
||||
for c in self.0.iter_mut() {
|
||||
if c.read().unwrap().id().as_deref() == Some(id) {
|
||||
*c = arc;
|
||||
|
|
@ -89,12 +89,12 @@ impl ComponentsBundle {
|
|||
}
|
||||
}
|
||||
}
|
||||
BundleOp::Reset => self.0.clear(),
|
||||
PackOp::Reset => self.0.clear(),
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
// ComponentsBundle GETTERS.
|
||||
// PackComponents GETTERS.
|
||||
|
||||
pub fn get_by_id(&self, id: &'static str) -> Option<&ArcLockComponent> {
|
||||
self.0
|
||||
|
|
@ -114,7 +114,7 @@ impl ComponentsBundle {
|
|||
.filter(move |&c| c.read().unwrap().handle() == handle)
|
||||
}
|
||||
|
||||
// ComponentsBundle PREPARE.
|
||||
// PackComponents PREPARE.
|
||||
|
||||
pub fn prepare(&self, rcx: &mut RenderContext) -> Markup {
|
||||
let mut components = self.0.clone();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::component::{BundleOp, ComponentTrait, ComponentsBundle};
|
||||
use crate::core::component::{ComponentTrait, PackComponents, PackOp};
|
||||
use crate::LazyStatic;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -8,7 +8,7 @@ static THEME_REGIONS: LazyStatic<RwLock<HashMap<&'static str, ComponentsRegions>
|
|||
LazyStatic::new(|| RwLock::new(HashMap::new()));
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ComponentsRegions(HashMap<&'static str, ComponentsBundle>);
|
||||
pub struct ComponentsRegions(HashMap<&'static str, PackComponents>);
|
||||
|
||||
impl ComponentsRegions {
|
||||
pub fn new() -> Self {
|
||||
|
|
@ -17,17 +17,17 @@ impl ComponentsRegions {
|
|||
|
||||
pub fn add_to(&mut self, region: &'static str, component: impl ComponentTrait) {
|
||||
if let Some(region) = self.0.get_mut(region) {
|
||||
region.alter_bundle(BundleOp::Add, component);
|
||||
region.alter_pack(PackOp::Add, component);
|
||||
} else {
|
||||
self.0.insert(region, ComponentsBundle::new_with(component));
|
||||
self.0.insert(region, PackComponents::new_with(component));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_extended_bundle(&self, theme: &str, region: &str) -> ComponentsBundle {
|
||||
pub fn get_extended_pack(&self, theme: &str, region: &str) -> PackComponents {
|
||||
if let Some(hm_theme) = THEME_REGIONS.read().unwrap().get(theme) {
|
||||
ComponentsBundle::merge(self.0.get(region), hm_theme.0.get(region))
|
||||
PackComponents::merge(self.0.get(region), hm_theme.0.get(region))
|
||||
} else {
|
||||
ComponentsBundle::merge(self.0.get(region), None)
|
||||
PackComponents::merge(self.0.get(region), None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ impl Page {
|
|||
// Acciones del tema después de preparar la página.
|
||||
self.context.theme().after_prepare_page(self);
|
||||
|
||||
// Finalmente, renderizar la página.
|
||||
// Finalmente, renderiza la página.
|
||||
let lang = self.langid().language.as_str();
|
||||
let dir = match self.langid().character_direction() {
|
||||
CharacterDirection::LTR => "ltr",
|
||||
|
|
@ -195,7 +195,7 @@ impl Page {
|
|||
pub fn prepare_region(&mut self, region: &str) -> Option<Markup> {
|
||||
let render = self
|
||||
.regions
|
||||
.get_extended_bundle(self.context.theme().single_name(), region)
|
||||
.get_extended_pack(self.context.theme().single_name(), region)
|
||||
.prepare(self.context());
|
||||
if render.is_empty() {
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue