@primer/behaviors 0.0.0-202223113012 → 0.0.0-2022312101859

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.
@@ -5,7 +5,7 @@ declare class ModalDialogElement extends HTMLElement {
5
5
  connectedCallback(): void;
6
6
  disconnectedCallback(): void;
7
7
  show(): void;
8
- close(): void;
8
+ close(cancelled?: boolean): void;
9
9
  }
10
10
  declare global {
11
11
  interface Window {
@@ -10,7 +10,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
10
10
  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
11
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
12
  };
13
- var _ModalDialogElement_instances, _ModalDialogElement_focusAbortController, _ModalDialogElement_abortController, _ModalDialogElement_isComposing, _ModalDialogElement_openButton, _ModalDialogElement_overlayBackdrop_get, _ModalDialogElement_keydown;
13
+ var _ModalDialogElement_instances, _ModalDialogElement_focusAbortController, _ModalDialogElement_abortController, _ModalDialogElement_openButton, _ModalDialogElement_overlayBackdrop_get, _ModalDialogElement_keydown;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const iterate_focusable_elements_js_1 = require("../utils/iterate-focusable-elements.js");
16
16
  const focus_trap_js_1 = require("../focus-trap.js");
@@ -19,8 +19,7 @@ class ModalDialogElement extends HTMLElement {
19
19
  super(...arguments);
20
20
  _ModalDialogElement_instances.add(this);
21
21
  _ModalDialogElement_focusAbortController.set(this, new AbortController());
22
- _ModalDialogElement_abortController.set(this, new AbortController());
23
- _ModalDialogElement_isComposing.set(this, false);
22
+ _ModalDialogElement_abortController.set(this, null);
24
23
  _ModalDialogElement_openButton.set(this, void 0);
25
24
  }
26
25
  get open() {
@@ -53,7 +52,7 @@ class ModalDialogElement extends HTMLElement {
53
52
  connectedCallback() {
54
53
  if (!this.hasAttribute('role'))
55
54
  this.setAttribute('role', 'dialog');
56
- const signal = __classPrivateFieldGet(this, _ModalDialogElement_abortController, "f").signal;
55
+ const { signal } = (__classPrivateFieldSet(this, _ModalDialogElement_abortController, new AbortController(), "f"));
57
56
  this.ownerDocument.addEventListener('click', event => {
58
57
  const target = event.target;
59
58
  const clickOutsideDialog = target.closest(this.tagName) !== this;
@@ -68,6 +67,10 @@ class ModalDialogElement extends HTMLElement {
68
67
  if (dialogId === this.id) {
69
68
  this.close();
70
69
  }
70
+ dialogId = button.getAttribute('data-submit-dialog-id');
71
+ if (dialogId === this.id) {
72
+ this.close(true);
73
+ }
71
74
  dialogId = button.getAttribute('data-show-dialog-id');
72
75
  if (dialogId === this.id) {
73
76
  event.stopPropagation();
@@ -75,21 +78,23 @@ class ModalDialogElement extends HTMLElement {
75
78
  this.show();
76
79
  }
77
80
  }, { signal });
78
- this.addEventListener('compositionstart', () => (__classPrivateFieldSet(this, _ModalDialogElement_isComposing, true, "f")));
79
- this.addEventListener('compositionend', () => (__classPrivateFieldSet(this, _ModalDialogElement_isComposing, false, "f")));
80
81
  this.addEventListener('keydown', e => __classPrivateFieldGet(this, _ModalDialogElement_instances, "m", _ModalDialogElement_keydown).call(this, e));
81
82
  }
82
83
  disconnectedCallback() {
83
- __classPrivateFieldGet(this, _ModalDialogElement_abortController, "f").abort();
84
+ var _a;
85
+ (_a = __classPrivateFieldGet(this, _ModalDialogElement_abortController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
84
86
  }
85
87
  show() {
86
88
  this.open = true;
87
89
  }
88
- close() {
90
+ close(cancelled = true) {
91
+ const eventType = cancelled ? 'cancel' : 'close';
92
+ const dialogEvent = new Event(eventType);
93
+ this.dispatchEvent(dialogEvent);
89
94
  this.open = false;
90
95
  }
91
96
  }
92
- _ModalDialogElement_focusAbortController = new WeakMap(), _ModalDialogElement_abortController = new WeakMap(), _ModalDialogElement_isComposing = new WeakMap(), _ModalDialogElement_openButton = new WeakMap(), _ModalDialogElement_instances = new WeakSet(), _ModalDialogElement_overlayBackdrop_get = function _ModalDialogElement_overlayBackdrop_get() {
97
+ _ModalDialogElement_focusAbortController = new WeakMap(), _ModalDialogElement_abortController = new WeakMap(), _ModalDialogElement_openButton = new WeakMap(), _ModalDialogElement_instances = new WeakSet(), _ModalDialogElement_overlayBackdrop_get = function _ModalDialogElement_overlayBackdrop_get() {
93
98
  var _a;
94
99
  if ((_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains('Overlay-backdrop')) {
95
100
  return this.parentElement;
@@ -98,7 +103,7 @@ _ModalDialogElement_focusAbortController = new WeakMap(), _ModalDialogElement_ab
98
103
  }, _ModalDialogElement_keydown = function _ModalDialogElement_keydown(event) {
99
104
  if (!(event instanceof KeyboardEvent))
100
105
  return;
101
- if (__classPrivateFieldGet(this, _ModalDialogElement_isComposing, "f"))
106
+ if (event.isComposing)
102
107
  return;
103
108
  switch (event.key) {
104
109
  case 'Escape':
@@ -5,7 +5,7 @@ declare class ModalDialogElement extends HTMLElement {
5
5
  connectedCallback(): void;
6
6
  disconnectedCallback(): void;
7
7
  show(): void;
8
- close(): void;
8
+ close(cancelled?: boolean): void;
9
9
  }
10
10
  declare global {
11
11
  interface Window {
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  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");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- var _ModalDialogElement_instances, _ModalDialogElement_focusAbortController, _ModalDialogElement_abortController, _ModalDialogElement_isComposing, _ModalDialogElement_openButton, _ModalDialogElement_overlayBackdrop_get, _ModalDialogElement_keydown;
12
+ var _ModalDialogElement_instances, _ModalDialogElement_focusAbortController, _ModalDialogElement_abortController, _ModalDialogElement_openButton, _ModalDialogElement_overlayBackdrop_get, _ModalDialogElement_keydown;
13
13
  import { focusIfNeeded } from '../utils/iterate-focusable-elements.js';
14
14
  import { focusTrap } from '../focus-trap.js';
15
15
  class ModalDialogElement extends HTMLElement {
@@ -17,8 +17,7 @@ class ModalDialogElement extends HTMLElement {
17
17
  super(...arguments);
18
18
  _ModalDialogElement_instances.add(this);
19
19
  _ModalDialogElement_focusAbortController.set(this, new AbortController());
20
- _ModalDialogElement_abortController.set(this, new AbortController());
21
- _ModalDialogElement_isComposing.set(this, false);
20
+ _ModalDialogElement_abortController.set(this, null);
22
21
  _ModalDialogElement_openButton.set(this, void 0);
23
22
  }
24
23
  get open() {
@@ -51,7 +50,7 @@ class ModalDialogElement extends HTMLElement {
51
50
  connectedCallback() {
52
51
  if (!this.hasAttribute('role'))
53
52
  this.setAttribute('role', 'dialog');
54
- const signal = __classPrivateFieldGet(this, _ModalDialogElement_abortController, "f").signal;
53
+ const { signal } = (__classPrivateFieldSet(this, _ModalDialogElement_abortController, new AbortController(), "f"));
55
54
  this.ownerDocument.addEventListener('click', event => {
56
55
  const target = event.target;
57
56
  const clickOutsideDialog = target.closest(this.tagName) !== this;
@@ -66,6 +65,10 @@ class ModalDialogElement extends HTMLElement {
66
65
  if (dialogId === this.id) {
67
66
  this.close();
68
67
  }
68
+ dialogId = button.getAttribute('data-submit-dialog-id');
69
+ if (dialogId === this.id) {
70
+ this.close(true);
71
+ }
69
72
  dialogId = button.getAttribute('data-show-dialog-id');
70
73
  if (dialogId === this.id) {
71
74
  event.stopPropagation();
@@ -73,21 +76,23 @@ class ModalDialogElement extends HTMLElement {
73
76
  this.show();
74
77
  }
75
78
  }, { signal });
76
- this.addEventListener('compositionstart', () => (__classPrivateFieldSet(this, _ModalDialogElement_isComposing, true, "f")));
77
- this.addEventListener('compositionend', () => (__classPrivateFieldSet(this, _ModalDialogElement_isComposing, false, "f")));
78
79
  this.addEventListener('keydown', e => __classPrivateFieldGet(this, _ModalDialogElement_instances, "m", _ModalDialogElement_keydown).call(this, e));
79
80
  }
80
81
  disconnectedCallback() {
81
- __classPrivateFieldGet(this, _ModalDialogElement_abortController, "f").abort();
82
+ var _a;
83
+ (_a = __classPrivateFieldGet(this, _ModalDialogElement_abortController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
82
84
  }
83
85
  show() {
84
86
  this.open = true;
85
87
  }
86
- close() {
88
+ close(cancelled = true) {
89
+ const eventType = cancelled ? 'cancel' : 'close';
90
+ const dialogEvent = new Event(eventType);
91
+ this.dispatchEvent(dialogEvent);
87
92
  this.open = false;
88
93
  }
89
94
  }
90
- _ModalDialogElement_focusAbortController = new WeakMap(), _ModalDialogElement_abortController = new WeakMap(), _ModalDialogElement_isComposing = new WeakMap(), _ModalDialogElement_openButton = new WeakMap(), _ModalDialogElement_instances = new WeakSet(), _ModalDialogElement_overlayBackdrop_get = function _ModalDialogElement_overlayBackdrop_get() {
95
+ _ModalDialogElement_focusAbortController = new WeakMap(), _ModalDialogElement_abortController = new WeakMap(), _ModalDialogElement_openButton = new WeakMap(), _ModalDialogElement_instances = new WeakSet(), _ModalDialogElement_overlayBackdrop_get = function _ModalDialogElement_overlayBackdrop_get() {
91
96
  var _a;
92
97
  if ((_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains('Overlay-backdrop')) {
93
98
  return this.parentElement;
@@ -96,7 +101,7 @@ _ModalDialogElement_focusAbortController = new WeakMap(), _ModalDialogElement_ab
96
101
  }, _ModalDialogElement_keydown = function _ModalDialogElement_keydown(event) {
97
102
  if (!(event instanceof KeyboardEvent))
98
103
  return;
99
- if (__classPrivateFieldGet(this, _ModalDialogElement_isComposing, "f"))
104
+ if (event.isComposing)
100
105
  return;
101
106
  switch (event.key) {
102
107
  case 'Escape':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "0.0.0-202223113012",
3
+ "version": "0.0.0-2022312101859",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",