@primer/view-components 0.15.1-rc.6d3176b2 → 0.15.2-rc.ab78bcfc

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.
@@ -1 +1 @@
1
- .ActionBar{display:flex!important;flex-grow:1;flex-shrink:1;justify-content:flex-end;min-width:calc(var(--control-medium-size,2rem)*3);overflow:hidden;position:relative}.ActionBar,.ActionBar-item-container{align-items:center;box-sizing:initial}.ActionBar-item-container{display:flex;flex-grow:0;flex-shrink:0}.ActionBar-item{flex-shrink:0;position:relative}.ActionBar-more-menu{flex-shrink:0}.ActionBar--small{min-width:calc(var(--control-small-size,1.75rem)*3)}.ActionBar--large{min-width:calc(var(--control-large-size,2.5rem)*3)}.ActionBar-divider{border-left:var(--borderWidth-thin,max(1px,.0625rem)) solid var(--borderColor-muted,var(--color-border-muted));height:calc(var(--control-medium-size,2rem)/2);margin:0 var(--controlStack-medium-gap-condensed,.5rem)}.ActionBar--small .ActionBar-divider{margin:0 var(--controlStack-small-gap-condensed,.5rem)}.ActionBar--large .ActionBar-divider{margin:0 var(--controlStack-large-gap-condensed,.5rem)}
1
+ .ActionBar{align-items:center;box-sizing:initial;display:flex!important;flex-grow:1;flex-shrink:1;justify-content:flex-end;min-width:calc(var(--control-medium-size,2rem)*3);overflow:hidden;position:relative}.ActionBar-item-container{box-sizing:initial;height:var(--control-medium-size,2rem);overflow:hidden}.ActionBar-item{float:left;position:relative}.ActionBar-more-menu{float:left}.ActionBar--small{min-width:calc(var(--control-small-size,1.75rem)*3)}.ActionBar--large{min-width:calc(var(--control-large-size,2.5rem)*3)}.ActionBar-divider{border-left:var(--borderWidth-thin,max(1px,.0625rem)) solid var(--borderColor-muted,var(--color-border-muted));bottom:50%;float:left;height:calc(var(--control-medium-size,2rem)/2);margin:0 var(--controlStack-medium-gap-condensed,.5rem);top:50%;transform:translateY(-50%)}.ActionBar--small .ActionBar-divider{margin:0 var(--controlStack-small-gap-condensed,.5rem)}.ActionBar--large .ActionBar-divider{margin:0 var(--controlStack-large-gap-condensed,.5rem)}
@@ -1,12 +1,13 @@
1
+ import { ActionMenuElement } from './action_menu/action_menu_element';
1
2
  declare class ActionBarElement extends HTMLElement {
2
3
  #private;
3
4
  items: HTMLElement[];
4
5
  itemContainer: HTMLElement;
5
- moreMenu: HTMLElement;
6
+ moreMenu: ActionMenuElement;
6
7
  connectedCallback(): void;
7
8
  disconnectedCallback(): void;
8
9
  menuItemClick(event: Event): void;
9
- update(rect?: DOMRect): void;
10
+ update(): void;
10
11
  }
11
12
  declare global {
12
13
  interface Window {
@@ -4,18 +4,18 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
7
12
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
13
  if (kind === "m") throw new TypeError("Private method is not writable");
9
14
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
15
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
16
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
17
  };
13
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
14
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
15
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
16
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
17
- };
18
- var _ActionBarElement_instances, _ActionBarElement_initialBarWidth, _ActionBarElement_previousBarWidth, _ActionBarElement_focusZoneAbortController, _ActionBarElement_isVisible, _ActionBarElement_itemGap, _ActionBarElement_availableSpace, _ActionBarElement_menuSpace, _ActionBarElement_shrink, _ActionBarElement_grow, _ActionBarElement_showItem, _ActionBarElement_hideItem, _ActionBarElement_menuItems_get;
18
+ var _ActionBarElement_instances, _ActionBarElement_focusZoneAbortController, _ActionBarElement_firstItem_get, _ActionBarElement_showItem, _ActionBarElement_hideItem, _ActionBarElement_menuItems_get, _ActionBarElement_eachItem;
19
19
  import { controller, targets, target } from '@github/catalyst';
20
20
  import { focusZone, FocusKeys } from '@primer/behaviors';
21
21
  const instersectionObserver = new IntersectionObserver(entries => {
@@ -30,35 +30,37 @@ const resizeObserver = new ResizeObserver(entries => {
30
30
  for (const entry of entries) {
31
31
  const action = entry.target;
32
32
  if (action instanceof ActionBarElement) {
33
- action.update(entry.contentRect);
33
+ action.update();
34
34
  }
35
35
  }
36
36
  });
37
+ // These are definitely used, but eslint is dumb apparently
38
+ // eslint-disable-next-line no-unused-vars
39
+ var ItemType;
40
+ (function (ItemType) {
41
+ // eslint-disable-next-line no-unused-vars
42
+ ItemType[ItemType["Item"] = 0] = "Item";
43
+ // eslint-disable-next-line no-unused-vars
44
+ ItemType[ItemType["Divider"] = 1] = "Divider";
45
+ })(ItemType || (ItemType = {}));
37
46
  let ActionBarElement = class ActionBarElement extends HTMLElement {
38
47
  constructor() {
39
48
  super(...arguments);
40
49
  _ActionBarElement_instances.add(this);
41
- _ActionBarElement_initialBarWidth.set(this, void 0);
42
- _ActionBarElement_previousBarWidth.set(this, void 0);
43
50
  _ActionBarElement_focusZoneAbortController.set(this, null);
44
51
  }
45
52
  connectedCallback() {
46
- var _a, _b, _c, _d;
47
- __classPrivateFieldSet(this, _ActionBarElement_previousBarWidth, (_a = this.offsetWidth) !== null && _a !== void 0 ? _a : Infinity, "f");
48
- __classPrivateFieldSet(this, _ActionBarElement_initialBarWidth, (_b = this.itemContainer.offsetWidth) !== null && _b !== void 0 ? _b : Infinity, "f");
53
+ var _a, _b;
49
54
  // Calculate the width of all the items before hiding anything
50
55
  for (const item of this.items) {
51
56
  const width = item.getBoundingClientRect().width;
52
- const marginLeft = parseInt((_c = window.getComputedStyle(item)) === null || _c === void 0 ? void 0 : _c.marginLeft, 10);
53
- const marginRight = parseInt((_d = window.getComputedStyle(item)) === null || _d === void 0 ? void 0 : _d.marginRight, 10);
57
+ const marginLeft = parseInt((_a = window.getComputedStyle(item)) === null || _a === void 0 ? void 0 : _a.marginLeft, 10);
58
+ const marginRight = parseInt((_b = window.getComputedStyle(item)) === null || _b === void 0 ? void 0 : _b.marginRight, 10);
54
59
  item.setAttribute('data-offset-width', `${width + marginLeft + marginRight}`);
55
60
  }
56
61
  resizeObserver.observe(this);
57
62
  instersectionObserver.observe(this);
58
- setTimeout(() => {
59
- this.style.overflow = 'visible';
60
- this.update();
61
- }, 20); // Wait for the items to be rendered, making this really short to avoid a flash of unstyled content
63
+ requestAnimationFrame(() => this.update());
62
64
  }
63
65
  disconnectedCallback() {
64
66
  resizeObserver.unobserve(this);
@@ -72,21 +74,37 @@ let ActionBarElement = class ActionBarElement extends HTMLElement {
72
74
  (_a = document.getElementById(id)) === null || _a === void 0 ? void 0 : _a.click();
73
75
  }
74
76
  }
75
- update(rect = this.getBoundingClientRect()) {
76
- // Only recalculate if the bar width changed
77
- if (rect.width <= __classPrivateFieldGet(this, _ActionBarElement_previousBarWidth, "f") || __classPrivateFieldGet(this, _ActionBarElement_previousBarWidth, "f") === 0) {
78
- __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_shrink).call(this);
79
- }
80
- else if (rect.width > __classPrivateFieldGet(this, _ActionBarElement_previousBarWidth, "f")) {
81
- __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_grow).call(this);
82
- }
83
- __classPrivateFieldSet(this, _ActionBarElement_previousBarWidth, rect.width, "f");
84
- if (rect.width <= __classPrivateFieldGet(this, _ActionBarElement_initialBarWidth, "f")) {
85
- this.style.justifyContent = 'space-between';
86
- }
87
- else {
88
- this.style.justifyContent = 'flex-end';
89
- }
77
+ update() {
78
+ const firstItem = __classPrivateFieldGet(this, _ActionBarElement_instances, "a", _ActionBarElement_firstItem_get);
79
+ if (!firstItem)
80
+ return;
81
+ const firstItemTop = firstItem.getBoundingClientRect().top;
82
+ let previousItemType = null;
83
+ __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_eachItem).call(this, (item, index, type) => {
84
+ const itemTop = item.getBoundingClientRect().top;
85
+ if (type === ItemType.Item) {
86
+ if (itemTop > firstItemTop) {
87
+ __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_hideItem).call(this, index);
88
+ if (this.moreMenu.hidden) {
89
+ this.moreMenu.hidden = false;
90
+ }
91
+ if (previousItemType === ItemType.Divider) {
92
+ __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_hideItem).call(this, index - 1);
93
+ }
94
+ }
95
+ else {
96
+ __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_showItem).call(this, index);
97
+ if (index === this.items.length - 1) {
98
+ this.moreMenu.hidden = true;
99
+ }
100
+ if (previousItemType === ItemType.Divider) {
101
+ __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_showItem).call(this, index - 1);
102
+ }
103
+ }
104
+ }
105
+ previousItemType = type;
106
+ return true;
107
+ });
90
108
  if (__classPrivateFieldGet(this, _ActionBarElement_focusZoneAbortController, "f")) {
91
109
  __classPrivateFieldGet(this, _ActionBarElement_focusZoneAbortController, "f").abort();
92
110
  }
@@ -94,88 +112,47 @@ let ActionBarElement = class ActionBarElement extends HTMLElement {
94
112
  bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
95
113
  focusOutBehavior: 'wrap',
96
114
  focusableElementFilter: element => {
97
- return __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_isVisible).call(this, element);
98
- }
115
+ const idx = this.items.indexOf(element.parentElement);
116
+ const elementIsVisibleItem = idx > -1 && this.items[idx].style.visibility === 'visible';
117
+ const elementIsVisibleActionMenuInvoker = element === this.moreMenu.invokerElement && !this.moreMenu.hidden;
118
+ return elementIsVisibleItem || elementIsVisibleActionMenuInvoker;
119
+ },
99
120
  }), "f");
100
121
  }
101
122
  };
102
- _ActionBarElement_initialBarWidth = new WeakMap();
103
- _ActionBarElement_previousBarWidth = new WeakMap();
104
123
  _ActionBarElement_focusZoneAbortController = new WeakMap();
105
124
  _ActionBarElement_instances = new WeakSet();
106
- _ActionBarElement_isVisible = function _ActionBarElement_isVisible(element) {
107
- // Safari doesn't support `checkVisibility` yet.
108
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
109
- // @ts-ignore
110
- if (typeof element.checkVisibility === 'function')
111
- return element.checkVisibility();
112
- return Boolean(element.offsetParent || element.offsetWidth || element.offsetHeight);
113
- };
114
- _ActionBarElement_itemGap = function _ActionBarElement_itemGap() {
115
- var _a;
116
- return parseInt((_a = window.getComputedStyle(this.itemContainer)) === null || _a === void 0 ? void 0 : _a.columnGap, 10) || 0;
117
- };
118
- _ActionBarElement_availableSpace = function _ActionBarElement_availableSpace() {
119
- // Get the offset of the item container from the container edge
120
- return this.offsetWidth - this.itemContainer.offsetWidth;
121
- };
122
- _ActionBarElement_menuSpace = function _ActionBarElement_menuSpace() {
123
- if (this.moreMenu.hidden) {
124
- return 0;
125
- }
126
- return this.moreMenu.offsetWidth + __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_itemGap).call(this);
127
- };
128
- _ActionBarElement_shrink = function _ActionBarElement_shrink() {
129
- if (this.items[0].hidden) {
130
- return;
131
- }
132
- let index = this.items.length - 1;
133
- for (const item of this.items.reverse()) {
134
- if (!item.hidden && __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_availableSpace).call(this) < __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_menuSpace).call(this)) {
135
- __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_hideItem).call(this, index);
125
+ _ActionBarElement_firstItem_get = function _ActionBarElement_firstItem_get() {
126
+ let foundItem = null;
127
+ __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_eachItem).call(this, (item, _index, type) => {
128
+ if (type === ItemType.Item) {
129
+ foundItem = item;
130
+ return false;
136
131
  }
137
- else if (__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_availableSpace).call(this) >= __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_menuSpace).call(this)) {
138
- return;
139
- }
140
- index--;
141
- }
142
- };
143
- _ActionBarElement_grow = function _ActionBarElement_grow() {
144
- // If last item is visible, there is no need to grow
145
- if (!this.items[this.items.length - 1].hidden) {
146
- return;
147
- }
148
- let index = 0;
149
- for (const item of this.items) {
150
- if (item.hidden) {
151
- const offsetWidth = Number(item.getAttribute('data-offset-width'));
152
- if (__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_availableSpace).call(this) >= __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_menuSpace).call(this) + offsetWidth || index === this.items.length - 1) {
153
- __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_showItem).call(this, index);
154
- }
155
- else {
156
- return;
157
- }
158
- }
159
- index++;
160
- }
161
- if (!this.items[this.items.length - 1].hidden) {
162
- this.moreMenu.hidden = true;
163
- }
132
+ return true;
133
+ });
134
+ return foundItem;
164
135
  };
165
136
  _ActionBarElement_showItem = function _ActionBarElement_showItem(index) {
166
- this.items[index].hidden = false;
137
+ this.items[index].style.setProperty('visibility', 'visible');
167
138
  __classPrivateFieldGet(this, _ActionBarElement_instances, "a", _ActionBarElement_menuItems_get)[index].hidden = true;
168
139
  };
169
140
  _ActionBarElement_hideItem = function _ActionBarElement_hideItem(index) {
170
- this.items[index].hidden = true;
141
+ this.items[index].style.setProperty('visibility', 'hidden');
171
142
  __classPrivateFieldGet(this, _ActionBarElement_instances, "a", _ActionBarElement_menuItems_get)[index].hidden = false;
172
- if (this.moreMenu.hidden) {
173
- this.moreMenu.hidden = false;
174
- }
175
143
  };
176
144
  _ActionBarElement_menuItems_get = function _ActionBarElement_menuItems_get() {
177
145
  return this.moreMenu.querySelectorAll('[role="menu"] > li');
178
146
  };
147
+ _ActionBarElement_eachItem = function _ActionBarElement_eachItem(callback) {
148
+ for (let i = 0; i < this.items.length; i++) {
149
+ const item = this.items[i];
150
+ const type = item.classList.contains('ActionBar-divider') ? ItemType.Divider : ItemType.Item;
151
+ if (!callback(item, i, type)) {
152
+ break;
153
+ }
154
+ }
155
+ };
179
156
  __decorate([
180
157
  targets
181
158
  ], ActionBarElement.prototype, "items", void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/view-components",
3
- "version": "0.15.1-rc.6d3176b2",
3
+ "version": "0.15.2-rc.ab78bcfc",
4
4
  "description": "ViewComponents for the Primer Design System",
5
5
  "main": "app/assets/javascripts/primer_view_components.js",
6
6
  "module": "app/components/primer/primer.js",