@primer/view-components 0.28.0-rc.4d641547 → 0.28.0-rc.538292aa

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,7 +20,7 @@ export declare class SelectPanelElement extends HTMLElement {
20
20
  ariaLiveContainer: HTMLElement;
21
21
  noResults: HTMLElement;
22
22
  fragmentErrorElement: HTMLElement;
23
- bannerErrorElement: HTMLElement;
23
+ errorBannerElement: HTMLElement;
24
24
  bodySpinner: HTMLElement;
25
25
  filterFn?: FilterFn;
26
26
  get open(): boolean;
@@ -52,6 +52,8 @@ export declare class SelectPanelElement extends HTMLElement {
52
52
  disableItem(item: SelectPanelItem | null): void;
53
53
  enableItem(item: SelectPanelItem | null): void;
54
54
  isItemHidden(item: SelectPanelItem | null): boolean;
55
+ hideItem(item: SelectPanelItem | null): void;
56
+ showItem(item: SelectPanelItem | null): void;
55
57
  isItemChecked(item: SelectPanelItem | null): boolean;
56
58
  checkItem(item: SelectPanelItem | null): void;
57
59
  uncheckItem(item: SelectPanelItem | null): void;
@@ -15,7 +15,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
15
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");
16
16
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
17
17
  };
18
- var _SelectPanelElement_instances, _SelectPanelElement_dialogIntersectionObserver, _SelectPanelElement_abortController, _SelectPanelElement_originalLabel, _SelectPanelElement_inputName, _SelectPanelElement_selectedItems, _SelectPanelElement_loadingDelayTimeoutId, _SelectPanelElement_loadingAnnouncementTimeoutId, _SelectPanelElement_waitForCondition, _SelectPanelElement_softDisableItems, _SelectPanelElement_updateTabIndices, _SelectPanelElement_potentiallyDisallowActivation, _SelectPanelElement_isAnchorActivationViaSpace, _SelectPanelElement_isActivation, _SelectPanelElement_checkSelectedItems, _SelectPanelElement_addSelectedItem, _SelectPanelElement_removeSelectedItem, _SelectPanelElement_setTextFieldLoadingSpinnerTimer, _SelectPanelElement_handleIncludeFragmentEvent, _SelectPanelElement_toggleIncludeFragmentElements, _SelectPanelElement_handleRemoteInputEvent, _SelectPanelElement_defaultFilterFn, _SelectPanelElement_handleSearchFieldEvent, _SelectPanelElement_updateItemVisibility, _SelectPanelElement_inErrorState, _SelectPanelElement_setErrorState, _SelectPanelElement_clearErrorState, _SelectPanelElement_maybeAnnounce, _SelectPanelElement_fetchStrategy_get, _SelectPanelElement_filterInputTextFieldElement_get, _SelectPanelElement_performFilteringLocally, _SelectPanelElement_handleInvokerActivated, _SelectPanelElement_handleDialogItemActivated, _SelectPanelElement_handleItemActivated, _SelectPanelElement_setDynamicLabel, _SelectPanelElement_updateInput, _SelectPanelElement_firstItem_get, _SelectPanelElement_hideItem, _SelectPanelElement_showItem, _SelectPanelElement_getItemContent;
18
+ var _SelectPanelElement_instances, _SelectPanelElement_dialogIntersectionObserver, _SelectPanelElement_abortController, _SelectPanelElement_originalLabel, _SelectPanelElement_inputName, _SelectPanelElement_selectedItems, _SelectPanelElement_loadingDelayTimeoutId, _SelectPanelElement_loadingAnnouncementTimeoutId, _SelectPanelElement_softDisableItems, _SelectPanelElement_updateTabIndices, _SelectPanelElement_potentiallyDisallowActivation, _SelectPanelElement_isAnchorActivationViaSpace, _SelectPanelElement_isActivation, _SelectPanelElement_checkSelectedItems, _SelectPanelElement_addSelectedItem, _SelectPanelElement_removeSelectedItem, _SelectPanelElement_setTextFieldLoadingSpinnerTimer, _SelectPanelElement_handleIncludeFragmentEvent, _SelectPanelElement_toggleIncludeFragmentElements, _SelectPanelElement_handleRemoteInputEvent, _SelectPanelElement_defaultFilterFn, _SelectPanelElement_handleSearchFieldEvent, _SelectPanelElement_updateItemVisibility, _SelectPanelElement_inErrorState, _SelectPanelElement_setErrorState, _SelectPanelElement_clearErrorState, _SelectPanelElement_maybeAnnounce, _SelectPanelElement_fetchStrategy_get, _SelectPanelElement_filterInputTextFieldElement_get, _SelectPanelElement_performFilteringLocally, _SelectPanelElement_handleInvokerActivated, _SelectPanelElement_handleDialogItemActivated, _SelectPanelElement_handleItemActivated, _SelectPanelElement_setDynamicLabel, _SelectPanelElement_updateInput, _SelectPanelElement_firstItem_get, _SelectPanelElement_getItemContent;
19
19
  import { getAnchoredPosition } from '@primer/behaviors';
20
20
  import { controller, target } from '@github/catalyst';
21
21
  import { announceFromElement, announce } from '../aria_live';
@@ -170,35 +170,64 @@ let SelectPanelElement = class SelectPanelElement extends HTMLElement {
170
170
  __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
171
171
  __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_softDisableItems).call(this);
172
172
  updateWhenVisible(this);
173
- __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => Boolean(this.remoteInput), () => {
173
+ if (this.remoteInput) {
174
174
  this.remoteInput.addEventListener('loadstart', this, { signal });
175
175
  this.remoteInput.addEventListener('loadend', this, { signal });
176
- });
177
- __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => Boolean(this.includeFragment), () => {
176
+ }
177
+ else {
178
+ const mutationObserver = new MutationObserver(() => {
179
+ if (this.remoteInput) {
180
+ this.remoteInput.addEventListener('loadstart', this, { signal });
181
+ this.remoteInput.addEventListener('loadend', this, { signal });
182
+ mutationObserver.disconnect();
183
+ }
184
+ });
185
+ mutationObserver.observe(this, { childList: true, subtree: true });
186
+ }
187
+ if (this.includeFragment) {
178
188
  this.includeFragment.addEventListener('include-fragment-replaced', this, { signal });
179
189
  this.includeFragment.addEventListener('error', this, { signal });
180
190
  this.includeFragment.addEventListener('loadend', this, { signal });
181
- });
191
+ }
192
+ else {
193
+ const mutationObserver = new MutationObserver(() => {
194
+ if (this.includeFragment) {
195
+ this.includeFragment.addEventListener('include-fragment-replaced', this, { signal });
196
+ this.includeFragment.addEventListener('error', this, { signal });
197
+ this.includeFragment.addEventListener('loadend', this, { signal });
198
+ mutationObserver.disconnect();
199
+ }
200
+ });
201
+ mutationObserver.observe(this, { childList: true, subtree: true });
202
+ }
182
203
  __classPrivateFieldSet(this, _SelectPanelElement_dialogIntersectionObserver, new IntersectionObserver(entries => {
183
204
  for (const entry of entries) {
184
205
  const elem = entry.target;
185
206
  if (entry.isIntersecting && elem === this.dialog) {
186
207
  this.updateAnchorPosition();
208
+ if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL) {
209
+ __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
210
+ }
187
211
  }
188
212
  }
189
213
  }), "f");
190
- __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => Boolean(this.dialog), () => {
214
+ if (this.dialog) {
191
215
  if (this.getAttribute('data-open-on-load') === 'true') {
192
216
  this.show();
193
217
  }
194
218
  __classPrivateFieldGet(this, _SelectPanelElement_dialogIntersectionObserver, "f").observe(this.dialog);
195
- this.dialog.addEventListener('close', this, { signal });
196
- });
197
- if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL) {
198
- __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => this.items.length > 0, () => {
199
- __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
200
- __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
219
+ }
220
+ else {
221
+ const mutationObserver = new MutationObserver(() => {
222
+ if (this.dialog) {
223
+ if (this.getAttribute('data-open-on-load') === 'true') {
224
+ this.show();
225
+ }
226
+ __classPrivateFieldGet(this, _SelectPanelElement_dialogIntersectionObserver, "f").observe(this.dialog);
227
+ mutationObserver.disconnect();
228
+ }
201
229
  });
230
+ mutationObserver.observe(this, { childList: true, subtree: true });
202
231
  }
203
232
  }
204
233
  disconnectedCallback() {
@@ -233,14 +262,7 @@ let SelectPanelElement = class SelectPanelElement extends HTMLElement {
233
262
  return;
234
263
  }
235
264
  if (targetIsCloseButton && eventIsActivation) {
236
- // hide() will automatically be called by dialog event triggered from `data-close-dialog-id`
237
- return;
238
- }
239
- if (event.target === this.dialog && event.type === 'close') {
240
- this.dispatchEvent(new CustomEvent('panelClosed', {
241
- detail: { panel: this },
242
- bubbles: true,
243
- }));
265
+ // #hide will automatically be called by dialog event triggered from `data-close-dialog-id`
244
266
  return;
245
267
  }
246
268
  const item = event.target.closest(visibleMenuItemSelectors)?.parentElement;
@@ -293,6 +315,10 @@ let SelectPanelElement = class SelectPanelElement extends HTMLElement {
293
315
  }
294
316
  hide() {
295
317
  this.dialog.close();
318
+ this.dispatchEvent(new CustomEvent('panelClosed', {
319
+ detail: { panel: this },
320
+ bubbles: true,
321
+ }));
296
322
  }
297
323
  get visibleItems() {
298
324
  return Array.from(this.querySelectorAll(visibleMenuItemSelectors)).map(element => element.parentElement);
@@ -341,6 +367,16 @@ let SelectPanelElement = class SelectPanelElement extends HTMLElement {
341
367
  return false;
342
368
  }
343
369
  }
370
+ hideItem(item) {
371
+ if (item) {
372
+ item.setAttribute('hidden', 'hidden');
373
+ }
374
+ }
375
+ showItem(item) {
376
+ if (item) {
377
+ item.removeAttribute('hidden');
378
+ }
379
+ }
344
380
  isItemChecked(item) {
345
381
  if (item) {
346
382
  return __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item).getAttribute(this.ariaSelectionType) === 'true';
@@ -372,18 +408,6 @@ _SelectPanelElement_selectedItems = new WeakMap();
372
408
  _SelectPanelElement_loadingDelayTimeoutId = new WeakMap();
373
409
  _SelectPanelElement_loadingAnnouncementTimeoutId = new WeakMap();
374
410
  _SelectPanelElement_instances = new WeakSet();
375
- _SelectPanelElement_waitForCondition = function _SelectPanelElement_waitForCondition(condition, body) {
376
- if (condition()) {
377
- body();
378
- }
379
- else {
380
- const mutationObserver = new MutationObserver(() => {
381
- body();
382
- mutationObserver.disconnect();
383
- });
384
- mutationObserver.observe(this, { childList: true, subtree: true });
385
- }
386
- };
387
411
  _SelectPanelElement_softDisableItems = function _SelectPanelElement_softDisableItems() {
388
412
  const { signal } = __classPrivateFieldGet(this, _SelectPanelElement_abortController, "f");
389
413
  for (const item of this.querySelectorAll(validSelectors.join(','))) {
@@ -459,28 +483,23 @@ _SelectPanelElement_isActivation = function _SelectPanelElement_isActivation(eve
459
483
  };
460
484
  _SelectPanelElement_checkSelectedItems = function _SelectPanelElement_checkSelectedItems() {
461
485
  for (const item of this.items) {
462
- const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
463
- if (!itemContent)
464
- continue;
465
- const value = itemContent.getAttribute('data-value');
486
+ const value = item.getAttribute('data-value');
466
487
  if (value) {
467
488
  if (__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").has(value)) {
468
- itemContent.setAttribute(this.ariaSelectionType, 'true');
489
+ item.setAttribute(this.ariaSelectionType, 'true');
469
490
  }
470
491
  }
471
492
  }
472
493
  __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
473
494
  };
474
495
  _SelectPanelElement_addSelectedItem = function _SelectPanelElement_addSelectedItem(item) {
475
- const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
476
- if (!itemContent)
477
- return;
478
- const value = itemContent.getAttribute('data-value');
496
+ const button = item.querySelector('button');
497
+ const value = item.getAttribute('data-value');
479
498
  if (value) {
480
499
  __classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").set(value, {
481
500
  value,
482
- label: itemContent.querySelector('.ActionListItem-label')?.textContent?.trim(),
483
- inputName: itemContent.getAttribute('data-input-name'),
501
+ label: button.querySelector('.ActionListItem-label')?.textContent?.trim(),
502
+ inputName: button.getAttribute('data-input-name'),
484
503
  element: item,
485
504
  });
486
505
  }
@@ -614,11 +633,11 @@ _SelectPanelElement_updateItemVisibility = function _SelectPanelElement_updateIt
614
633
  const filter = this.filterFn || __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_defaultFilterFn);
615
634
  for (const item of this.items) {
616
635
  if (filter(item, query)) {
617
- __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_showItem).call(this, item);
636
+ this.showItem(item);
618
637
  atLeastOneResult = true;
619
638
  }
620
639
  else {
621
- __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_hideItem).call(this, item);
640
+ this.hideItem(item);
622
641
  }
623
642
  }
624
643
  }
@@ -628,10 +647,7 @@ _SelectPanelElement_updateItemVisibility = function _SelectPanelElement_updateIt
628
647
  __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateTabIndices).call(this);
629
648
  __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_maybeAnnounce).call(this);
630
649
  for (const item of this.items) {
631
- const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
632
- if (!itemContent)
633
- continue;
634
- const value = itemContent.getAttribute('data-value');
650
+ const value = item.getAttribute('data-value');
635
651
  if (value && !__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").has(value) && this.isItemChecked(item)) {
636
652
  __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_addSelectedItem).call(this, item);
637
653
  }
@@ -656,17 +672,17 @@ _SelectPanelElement_inErrorState = function _SelectPanelElement_inErrorState() {
656
672
  if (this.fragmentErrorElement && !this.fragmentErrorElement.hasAttribute('hidden')) {
657
673
  return true;
658
674
  }
659
- return !this.bannerErrorElement.hasAttribute('hidden');
675
+ return !this.errorBannerElement.hasAttribute('hidden');
660
676
  };
661
677
  _SelectPanelElement_setErrorState = function _SelectPanelElement_setErrorState(type) {
662
678
  let errorElement = this.fragmentErrorElement;
663
679
  if (type === ErrorStateType.BODY) {
664
680
  this.fragmentErrorElement?.removeAttribute('hidden');
665
- this.bannerErrorElement.setAttribute('hidden', '');
681
+ this.errorBannerElement.setAttribute('hidden', '');
666
682
  }
667
683
  else {
668
- errorElement = this.bannerErrorElement;
669
- this.bannerErrorElement?.removeAttribute('hidden');
684
+ errorElement = this.errorBannerElement;
685
+ this.errorBannerElement?.removeAttribute('hidden');
670
686
  this.fragmentErrorElement?.setAttribute('hidden', '');
671
687
  }
672
688
  // check if the errorElement is visible in the dom
@@ -677,7 +693,7 @@ _SelectPanelElement_setErrorState = function _SelectPanelElement_setErrorState(t
677
693
  };
678
694
  _SelectPanelElement_clearErrorState = function _SelectPanelElement_clearErrorState() {
679
695
  this.fragmentErrorElement?.setAttribute('hidden', '');
680
- this.bannerErrorElement.setAttribute('hidden', '');
696
+ this.errorBannerElement.setAttribute('hidden', '');
681
697
  };
682
698
  _SelectPanelElement_maybeAnnounce = function _SelectPanelElement_maybeAnnounce() {
683
699
  if (this.open && this.list) {
@@ -798,7 +814,6 @@ _SelectPanelElement_handleItemActivated = function _SelectPanelElement_handleIte
798
814
  }
799
815
  }
800
816
  __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
801
- __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateTabIndices).call(this);
802
817
  this.dispatchEvent(new CustomEvent('itemActivated', {
803
818
  bubbles: true,
804
819
  detail: { item, checked },
@@ -869,16 +884,6 @@ _SelectPanelElement_updateInput = function _SelectPanelElement_updateInput() {
869
884
  _SelectPanelElement_firstItem_get = function _SelectPanelElement_firstItem_get() {
870
885
  return (this.querySelector(visibleMenuItemSelectors)?.parentElement || null);
871
886
  };
872
- _SelectPanelElement_hideItem = function _SelectPanelElement_hideItem(item) {
873
- if (item) {
874
- item.setAttribute('hidden', 'hidden');
875
- }
876
- };
877
- _SelectPanelElement_showItem = function _SelectPanelElement_showItem(item) {
878
- if (item) {
879
- item.removeAttribute('hidden');
880
- }
881
- };
882
887
  _SelectPanelElement_getItemContent = function _SelectPanelElement_getItemContent(item) {
883
888
  return item.querySelector('.ActionListContent');
884
889
  };
@@ -908,7 +913,7 @@ __decorate([
908
913
  ], SelectPanelElement.prototype, "fragmentErrorElement", void 0);
909
914
  __decorate([
910
915
  target
911
- ], SelectPanelElement.prototype, "bannerErrorElement", void 0);
916
+ ], SelectPanelElement.prototype, "errorBannerElement", void 0);
912
917
  __decorate([
913
918
  target
914
919
  ], SelectPanelElement.prototype, "bodySpinner", void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/view-components",
3
- "version": "0.28.0-rc.4d641547",
3
+ "version": "0.28.0-rc.538292aa",
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",