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