capibara 1.3.60 → 1.3.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capibara",
3
- "version": "1.3.60",
3
+ "version": "1.3.62",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,6 +60,44 @@
60
60
  margin: 0.3em 1em;
61
61
  }
62
62
 
63
+ &.is-section-label {
64
+ cursor: unset;
65
+ font-size: 0.7em;
66
+ padding: 0.3em 1em 0.1em;
67
+ text-transform: uppercase;
68
+ letter-spacing: 0.06em;
69
+ &:hover {
70
+ background: none;
71
+ }
72
+ }
73
+
74
+ &.has-children {
75
+ position: relative;
76
+
77
+ .cap-context-menu--submenu {
78
+ display: none;
79
+ position: absolute;
80
+ left: 100%;
81
+ top: 0;
82
+ min-width: 180px;
83
+ z-index: 3;
84
+ font-size: 1em;
85
+ }
86
+
87
+ &:hover {
88
+ > .cap-context-menu--submenu {
89
+ display: block;
90
+ }
91
+ }
92
+ }
93
+
94
+ &_chevron {
95
+ margin-left: auto;
96
+ padding-left: 0.5em;
97
+ font-size: 1.1em;
98
+ opacity: 0.7;
99
+ }
100
+
63
101
  &_icon {
64
102
  display: inline-block;
65
103
  flex: 0 0 auto;
@@ -84,6 +122,17 @@
84
122
  fill: mapGet($theme, color);
85
123
  }
86
124
  }
125
+ .cap-context-menu--submenu {
126
+ color: mapGet($theme, color);
127
+ border-color: mapGet($theme, detailDay, border);
128
+ background: mapGet($theme, detailDay, background);
129
+ }
130
+ .cap-context-menu_item.is-section-label {
131
+ color: rgba(mapGet($theme, color), 0.6);
132
+ }
133
+ .cap-context-menu_item.is-divider {
134
+ border-bottom-color: rgba(mapGet($theme, color), 0.2);
135
+ }
87
136
  }
88
137
  }
89
138
  }
@@ -4631,22 +4631,28 @@ export default {
4631
4631
  let $contextMenu = $contextMenuContainer.querySelector(".cap-context-menu");
4632
4632
  let hasSomeoption = false;
4633
4633
 
4634
- config.timeline.contextMenu.options.forEach((option) => {
4634
+ var ctx = { config: config, date: date, item: item, selected: selected, tabSelected: tabSelected, target: target, name: name };
4635
+
4636
+ function renderContextMenuItem(option, $menu) {
4635
4637
  if (option.showIf) {
4636
- let show = option.showIf({ item, date, selected, name, tabSelected });
4638
+ let show = option.showIf({ item: ctx.item, date: ctx.date, selected: ctx.selected, name: ctx.name, tabSelected: ctx.tabSelected });
4637
4639
  if (!show) return;
4638
4640
  }
4639
4641
 
4642
+ // isGroup: llama getItems() e inserta cada resultado como item independiente
4643
+ if (option.isGroup && option.getItems) {
4644
+ var groupItems = option.getItems({ config: ctx.config, date: ctx.date, item: ctx.item, selected: ctx.selected, tabSelected: ctx.tabSelected, target: ctx.target });
4645
+ if (groupItems && groupItems.length > 0) {
4646
+ groupItems.forEach(function(gItem) { renderContextMenuItem(gItem, $menu); });
4647
+ hasSomeoption = true;
4648
+ }
4649
+ return;
4650
+ }
4651
+
4640
4652
  let isEnabled = true;
4641
4653
  let isClickeable = true;
4642
4654
  if (option.enableIf) {
4643
- isEnabled = option.enableIf({
4644
- item,
4645
- date,
4646
- selected,
4647
- name,
4648
- tabSelected,
4649
- });
4655
+ isEnabled = option.enableIf({ item: ctx.item, date: ctx.date, selected: ctx.selected, name: ctx.name, tabSelected: ctx.tabSelected });
4650
4656
  }
4651
4657
 
4652
4658
  let optionClassName = "";
@@ -4662,47 +4668,168 @@ export default {
4662
4668
  optionClassName += "is-divider ";
4663
4669
  }
4664
4670
 
4671
+ if (option.isSectionLabel) {
4672
+ isClickeable = false;
4673
+ optionClassName += "is-section-label ";
4674
+ }
4675
+
4665
4676
  if (option.label) {
4666
- label = `<span>${option.label}</span>`;
4677
+ var resolvedLabel = typeof option.label === "function"
4678
+ ? option.label({ config: ctx.config, date: ctx.date, item: ctx.item, selected: ctx.selected, tabSelected: ctx.tabSelected, target: ctx.target })
4679
+ : option.label;
4680
+ label = "<span>" + resolvedLabel + "</span>";
4667
4681
  }
4668
4682
 
4669
4683
  if (option.icon) {
4670
- strIcon = `<div class="cap-context-menu_item_icon">
4671
- <svg viewBox="0 0 24 24">
4672
- <path d="${option.icon}" />
4673
- </svg>
4674
- </div>`;
4684
+ strIcon = "<div class=\"cap-context-menu_item_icon\"><svg viewBox=\"0 0 24 24\"><path d=\"" + option.icon + "\" /></svg></div>";
4675
4685
  }
4676
4686
 
4677
- let optionStrHtml = `
4678
- <div class="cap-context-menu_item ${optionClassName}">
4679
- ${strIcon}
4680
- ${label}
4681
- </div>`;
4687
+ var resolvedChildren = null;
4688
+ if (option.children) {
4689
+ resolvedChildren = typeof option.children === "function"
4690
+ ? option.children({ config: ctx.config, date: ctx.date, item: ctx.item, selected: ctx.selected, tabSelected: ctx.tabSelected, target: ctx.target })
4691
+ : option.children;
4692
+ }
4693
+
4694
+ var chevron = resolvedChildren && resolvedChildren.length > 0
4695
+ ? "<span class=\"cap-context-menu_item_chevron\">&#8250;</span>"
4696
+ : "";
4697
+
4698
+ var hasChildrenClass = resolvedChildren && resolvedChildren.length > 0 ? "has-children" : "";
4699
+
4700
+ let optionStrHtml = "<div class=\"cap-context-menu_item " + hasChildrenClass + " " + optionClassName + "\">" + strIcon + label + chevron + "</div>";
4682
4701
 
4683
4702
  let $option = dom.createElementFromHTML(optionStrHtml);
4684
4703
 
4685
- if (isEnabled && isClickeable) {
4704
+ if (resolvedChildren && resolvedChildren.length > 0) {
4705
+ var $submenu = document.createElement("div");
4706
+ $submenu.className = "cap-context-menu cap-context-menu--submenu";
4707
+
4708
+ resolvedChildren.forEach(function(child) {
4709
+ var childEnabled = true;
4710
+ if (child.enableIf) {
4711
+ childEnabled = child.enableIf({ config: ctx.config, date: ctx.date, item: ctx.item, selected: ctx.selected, tabSelected: ctx.tabSelected });
4712
+ }
4713
+ var childClassName = childEnabled ? "" : "is-disabled ";
4714
+ var childIcon = "";
4715
+ var childLabel = child.label
4716
+ ? "<span>" + (typeof child.label === "function" ? child.label({ config: ctx.config, date: ctx.date, item: ctx.item, selected: ctx.selected, tabSelected: ctx.tabSelected, target: ctx.target }) : child.label) + "</span>"
4717
+ : "";
4718
+ if (child.icon) {
4719
+ childIcon = "<div class=\"cap-context-menu_item_icon\"><svg viewBox=\"0 0 24 24\"><path d=\"" + child.icon + "\" /></svg></div>";
4720
+ }
4721
+
4722
+ var childResolvedChildren = null;
4723
+ if (child.children) {
4724
+ childResolvedChildren = typeof child.children === "function"
4725
+ ? child.children({ config: ctx.config, date: ctx.date, item: ctx.item, selected: ctx.selected, tabSelected: ctx.tabSelected, target: ctx.target })
4726
+ : child.children;
4727
+ }
4728
+ var childChevron = childResolvedChildren && childResolvedChildren.length > 0
4729
+ ? "<span class=\"cap-context-menu_item_chevron\">&#8250;</span>"
4730
+ : "";
4731
+ var childHasChildrenClass = childResolvedChildren && childResolvedChildren.length > 0 ? "has-children" : "";
4732
+
4733
+ var childHtml = "<div class=\"cap-context-menu_item " + childHasChildrenClass + " " + childClassName + "\">" + childIcon + childLabel + childChevron + "</div>";
4734
+ var $child = dom.createElementFromHTML(childHtml);
4735
+
4736
+ if (childResolvedChildren && childResolvedChildren.length > 0) {
4737
+ var $childSubmenu = document.createElement("div");
4738
+ $childSubmenu.className = "cap-context-menu cap-context-menu--submenu";
4739
+ childResolvedChildren.forEach(function(grandchild) {
4740
+ var gcEnabled = !grandchild.enableIf || grandchild.enableIf({ config: ctx.config, date: ctx.date, item: ctx.item, selected: ctx.selected, tabSelected: ctx.tabSelected });
4741
+ var gcLabel = grandchild.label
4742
+ ? "<span>" + (typeof grandchild.label === "function" ? grandchild.label({ config: ctx.config, date: ctx.date, item: ctx.item, selected: ctx.selected, tabSelected: ctx.tabSelected, target: ctx.target }) : grandchild.label) + "</span>"
4743
+ : "";
4744
+ var gcIcon = grandchild.icon
4745
+ ? "<div class=\"cap-context-menu_item_icon\"><svg viewBox=\"0 0 24 24\"><path d=\"" + grandchild.icon + "\" /></svg></div>"
4746
+ : "";
4747
+ var $gc = dom.createElementFromHTML("<div class=\"cap-context-menu_item " + (gcEnabled ? "" : "is-disabled ") + "\">" + gcIcon + gcLabel + "</div>");
4748
+ if (gcEnabled && grandchild.onClick) {
4749
+ (function(gc) {
4750
+ $gc.addEventListener("click", function(evtClick) {
4751
+ gc.onClick({ config: ctx.config, evt: evtClick, date: ctx.date, item: ctx.item, selected: ctx.selected, tabSelected: ctx.tabSelected, target: ctx.target });
4752
+ });
4753
+ })(grandchild);
4754
+ }
4755
+ $childSubmenu.appendChild($gc);
4756
+ });
4757
+ $child.appendChild($childSubmenu);
4758
+ (function(el, sub) {
4759
+ el.addEventListener("mouseenter", function() {
4760
+ var elRect = el.getBoundingClientRect();
4761
+ var vh = window.innerHeight;
4762
+ sub.style.transform = "";
4763
+ sub.style.top = "0";
4764
+ sub.style.bottom = "auto";
4765
+ if (elRect.top > vh * 4 / 6) {
4766
+ sub.style.top = "auto";
4767
+ sub.style.bottom = "0";
4768
+ } else if (elRect.top > vh * 2 / 6) {
4769
+ sub.style.transform = "translateY(-50%)";
4770
+ }
4771
+ });
4772
+ })($child, $childSubmenu);
4773
+ }
4774
+
4775
+ if (childEnabled && child.onClick) {
4776
+ (function(c) {
4777
+ $child.addEventListener("click", function(evtClick) {
4778
+ c.onClick({ config: ctx.config, evt: evtClick, date: ctx.date, item: ctx.item, selected: ctx.selected, tabSelected: ctx.tabSelected, target: ctx.target });
4779
+ });
4780
+ })(child);
4781
+ } else if (!(childResolvedChildren && childResolvedChildren.length > 0)) {
4782
+ $child.addEventListener("click", function(evtClick) {
4783
+ evtClick.preventDefault();
4784
+ evtClick.stopPropagation();
4785
+ });
4786
+ }
4787
+ $submenu.appendChild($child);
4788
+ });
4789
+
4790
+ $option.appendChild($submenu);
4791
+ (function(el, sub) {
4792
+ el.addEventListener("mouseenter", function() {
4793
+ var elRect = el.getBoundingClientRect();
4794
+ var vh = window.innerHeight;
4795
+ sub.style.transform = "";
4796
+ sub.style.top = "0";
4797
+ sub.style.bottom = "auto";
4798
+ if (elRect.top > vh * 4 / 6) {
4799
+ sub.style.top = "auto";
4800
+ sub.style.bottom = "0";
4801
+ } else if (elRect.top > vh * 2 / 6) {
4802
+ sub.style.transform = "translateY(-50%)";
4803
+ }
4804
+ });
4805
+ })($option, $submenu);
4806
+ }
4807
+
4808
+ if (isEnabled && isClickeable && !(resolvedChildren && resolvedChildren.length > 0)) {
4686
4809
  $option.addEventListener("click", (evtClick) =>
4687
4810
  option.onClick({
4688
- config,
4811
+ config: ctx.config,
4689
4812
  evt: evtClick,
4690
- date,
4691
- item,
4692
- selected,
4693
- tabSelected,
4694
- target,
4813
+ date: ctx.date,
4814
+ item: ctx.item,
4815
+ selected: ctx.selected,
4816
+ tabSelected: ctx.tabSelected,
4817
+ target: ctx.target,
4695
4818
  })
4696
4819
  );
4697
- } else {
4820
+ } else if (!(resolvedChildren && resolvedChildren.length > 0)) {
4698
4821
  $option.addEventListener("click", (evtClick) => {
4699
4822
  evtClick.preventDefault();
4700
4823
  evtClick.stopPropagation();
4701
4824
  });
4702
4825
  }
4703
4826
 
4704
- $contextMenu.append($option);
4827
+ $menu.append($option);
4705
4828
  hasSomeoption = true;
4829
+ }
4830
+
4831
+ config.timeline.contextMenu.options.forEach((option) => {
4832
+ renderContextMenuItem(option, $contextMenu);
4706
4833
  });
4707
4834
 
4708
4835
  return {