@nectary/components 0.39.0 → 0.40.0

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.
Files changed (115) hide show
  1. package/accordion/index.js +47 -84
  2. package/accordion-item/index.js +26 -53
  3. package/action-menu/index.d.ts +0 -1
  4. package/action-menu/index.js +179 -223
  5. package/action-menu/types.d.ts +8 -18
  6. package/action-menu-option/index.d.ts +1 -0
  7. package/action-menu-option/index.js +51 -62
  8. package/action-menu-option/types.d.ts +9 -0
  9. package/action-menu-option/utils.d.ts +2 -0
  10. package/action-menu-option/utils.js +3 -0
  11. package/alert/index.js +6 -20
  12. package/avatar/index.js +12 -31
  13. package/avatar-badge/index.js +8 -22
  14. package/avatar-status/index.js +1 -1
  15. package/button/index.js +42 -92
  16. package/card/index.js +21 -59
  17. package/chat-avatar/index.js +8 -22
  18. package/chat-block/index.js +29 -69
  19. package/chat-bubble/index.js +6 -20
  20. package/checkbox/index.js +55 -107
  21. package/chip/index.d.ts +13 -0
  22. package/chip/index.js +137 -0
  23. package/chip/types.d.ts +38 -0
  24. package/color-menu/index.d.ts +13 -0
  25. package/color-menu/index.js +464 -0
  26. package/color-menu/types.d.ts +37 -0
  27. package/color-swatch/index.d.ts +13 -0
  28. package/color-swatch/index.js +59 -0
  29. package/color-swatch/types.d.ts +12 -0
  30. package/colors.json +57 -49
  31. package/date-picker/index.js +161 -292
  32. package/dialog/index.js +70 -142
  33. package/dropdown-checkbox-option/index.js +6 -20
  34. package/dropdown-radio-option/index.js +6 -20
  35. package/field/index.js +25 -63
  36. package/file-drop/index.js +123 -200
  37. package/file-picker/index.d.ts +0 -1
  38. package/file-picker/index.js +55 -108
  39. package/file-status/index.js +15 -39
  40. package/help-tooltip/index.js +1 -1
  41. package/horizontal-stepper/index.js +33 -59
  42. package/horizontal-stepper-item/index.js +13 -37
  43. package/icon-button/index.js +39 -84
  44. package/icons-channel/notify/index.d.ts +11 -0
  45. package/icons-channel/notify/index.js +4 -0
  46. package/illustrations/create-illustration-class.js +1 -1
  47. package/inline-alert/index.js +29 -81
  48. package/input/index.js +113 -222
  49. package/link/index.js +46 -96
  50. package/list-item/index.js +1 -1
  51. package/package.json +12 -14
  52. package/pagination/index.js +109 -163
  53. package/popover/index.js +224 -294
  54. package/progress/index.js +9 -28
  55. package/radio/index.js +103 -169
  56. package/radio-option/index.js +24 -48
  57. package/segment/index.js +49 -130
  58. package/segment-collapse/index.js +24 -49
  59. package/segmented-control/index.js +36 -73
  60. package/segmented-control-option/index.js +41 -87
  61. package/segmented-icon-control/index.js +47 -84
  62. package/segmented-icon-control-option/index.js +38 -79
  63. package/select-button/index.d.ts +13 -0
  64. package/select-button/index.js +153 -0
  65. package/select-button/types.d.ts +43 -0
  66. package/select-menu/index.d.ts +11 -0
  67. package/select-menu/index.js +346 -0
  68. package/select-menu/types.d.ts +29 -0
  69. package/select-menu/types.js +1 -0
  70. package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
  71. package/select-menu-option/index.js +76 -0
  72. package/{select-option → select-menu-option}/types.d.ts +8 -9
  73. package/stop-events/index.js +7 -20
  74. package/table-head-cell/index.js +7 -21
  75. package/tabs/index.js +103 -165
  76. package/tabs-option/index.js +20 -44
  77. package/tag/index.d.ts +0 -1
  78. package/tag/index.js +37 -38
  79. package/tag/types.d.ts +13 -7
  80. package/textarea/index.js +92 -167
  81. package/theme.css +80 -49
  82. package/tile-control/index.js +55 -96
  83. package/tile-control-option/index.js +40 -86
  84. package/time-picker/index.js +216 -368
  85. package/title/index.js +6 -20
  86. package/toast/index.js +32 -70
  87. package/toast-manager/index.js +141 -217
  88. package/toggle/index.js +54 -106
  89. package/types.d.ts +7 -0
  90. package/utils/colors.d.ts +10 -0
  91. package/utils/colors.js +121 -0
  92. package/{utils.d.ts → utils/index.d.ts} +17 -9
  93. package/{utils.js → utils/index.js} +96 -39
  94. package/vertical-stepper/index.js +29 -50
  95. package/vertical-stepper-item/index.js +13 -37
  96. package/dropdown/index.d.ts +0 -12
  97. package/dropdown/index.js +0 -415
  98. package/dropdown/types.d.ts +0 -32
  99. package/dropdown-text-option/index.js +0 -104
  100. package/dropdown-text-option/types.d.ts +0 -16
  101. package/select/index.d.ts +0 -13
  102. package/select/index.js +0 -316
  103. package/select/types.d.ts +0 -53
  104. package/select-option/index.d.ts +0 -11
  105. package/select-option/index.js +0 -8
  106. package/tag/utils.d.ts +0 -5
  107. package/tag/utils.js +0 -6
  108. package/tag-close/index.d.ts +0 -12
  109. package/tag-close/index.js +0 -42
  110. package/tag-close/types.d.ts +0 -5
  111. /package/{dropdown-text-option → chip}/types.js +0 -0
  112. /package/{dropdown → color-menu}/types.js +0 -0
  113. /package/{select-option → color-swatch}/types.js +0 -0
  114. /package/{select → select-button}/types.js +0 -0
  115. /package/{tag-close → select-menu-option}/types.js +0 -0
package/popover/index.js CHANGED
@@ -1,234 +1,77 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$target, _$dialog, _isConnected, _resizeThrottle, _originalOverflowValue, _$targetSlot, _$targetOpenSlot, _$targetOpenWrapper, _targetActiveElement, _onExpand, _onCollapse, _isOpen, _onResize, _updateOrientation, _onBackdropMouseDown, _onCancel, _onCloseReactHandler, _dispatchCloseEvent, _captureActiveElement, _stopPropagation;
5
-
6
- function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
7
-
8
- function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
9
-
10
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
11
-
12
- function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
13
-
14
1
  import dialogPolyfill from 'dialog-polyfill';
15
- import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, updateLiteralAttribute, getReactEventHandler, updateBooleanAttribute, NectaryElement, throttleAnimationFrame } from '../utils';
16
- const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative}dialog{position:fixed;top:0;left:0;margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:1;background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}dialog+.backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background-color:transparent}dialog.fixed{position:fixed;top:50%;transform:translate(0,-50%)}._dialog_overlay{position:fixed;top:0;right:0;bottom:0;left:0}#target{display:flex;flex-direction:column}#content{position:relative;font:var(--sinch-font-body);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-100);box-shadow:var(--sinch-elevation-level-2);border:1px solid var(--sinch-color-snow-500);border-radius:var(--sinch-popover-shape-radius,var(--sinch-shape-radius-l));outline:0}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0}</style><div id="wrapper"><div id="target" aria-haspopup="dialog" aria-expanded="false"><slot name="target"></slot></div><dialog id="dialog"><div id="target-open"><slot name="target-open"></slot></div><div id="content" tabindex="-1"><slot name="content"></slot></div></dialog></div>';
2
+ import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, updateLiteralAttribute, getReactEventHandler, updateBooleanAttribute, NectaryElement, throttleAnimationFrame, Context, getFirstSlotElement, isElementFocused } from '../utils';
3
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative}dialog{position:fixed;top:0;left:0;margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:1;background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}dialog+.backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background-color:transparent}dialog.fixed{position:fixed;top:50%;transform:translate(0,-50%)}._dialog_overlay{position:fixed;top:0;right:0;bottom:0;left:0}#target{display:flex;flex-direction:column}#content{position:relative;font:var(--sinch-font-body);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-100);box-shadow:var(--sinch-elevation-level-2);border:1px solid var(--sinch-color-snow-500);border-radius:var(--sinch-shape-radius-m);outline:0;overflow:hidden}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0}</style><div id="wrapper"><div id="target" aria-haspopup="dialog" aria-expanded="false"><slot name="target"></slot></div><dialog id="dialog"><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog></div>';
17
4
  import { orientationValues } from './utils';
18
5
  const template = document.createElement('template');
19
6
  template.innerHTML = templateHTML;
20
7
  const POPOVER_OFFSET = 4;
21
- defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new WeakMap(), _isConnected = new WeakMap(), _resizeThrottle = new WeakMap(), _originalOverflowValue = new WeakMap(), _$targetSlot = new WeakMap(), _$targetOpenSlot = new WeakMap(), _$targetOpenWrapper = new WeakMap(), _targetActiveElement = new WeakMap(), _onExpand = new WeakSet(), _onCollapse = new WeakSet(), _isOpen = new WeakSet(), _onResize = new WeakMap(), _updateOrientation = new WeakMap(), _onBackdropMouseDown = new WeakMap(), _onCancel = new WeakMap(), _onCloseReactHandler = new WeakMap(), _dispatchCloseEvent = new WeakSet(), _captureActiveElement = new WeakMap(), _stopPropagation = new WeakMap(), class extends NectaryElement {
8
+ defineCustomElement('sinch-popover', class extends NectaryElement {
9
+ #$target;
10
+ #$dialog;
11
+ #isConnected;
12
+ #resizeThrottle;
13
+ #originalOverflowValue = '';
14
+ #$targetSlot;
15
+ #$targetOpenSlot;
16
+ #$contentSlot;
17
+ #$targetOpenWrapper;
18
+ #targetActiveElement = null;
19
+ #controller = new AbortController();
20
+ #keydownContext;
21
+ #visibilityContext;
22
+
22
23
  constructor() {
23
24
  super();
24
-
25
- _classPrivateMethodInitSpec(this, _dispatchCloseEvent);
26
-
27
- _classPrivateMethodInitSpec(this, _isOpen);
28
-
29
- _classPrivateMethodInitSpec(this, _onCollapse);
30
-
31
- _classPrivateMethodInitSpec(this, _onExpand);
32
-
33
- _classPrivateFieldInitSpec(this, _$target, {
34
- writable: true,
35
- value: void 0
36
- });
37
-
38
- _classPrivateFieldInitSpec(this, _$dialog, {
39
- writable: true,
40
- value: void 0
41
- });
42
-
43
- _classPrivateFieldInitSpec(this, _isConnected, {
44
- writable: true,
45
- value: void 0
46
- });
47
-
48
- _classPrivateFieldInitSpec(this, _resizeThrottle, {
49
- writable: true,
50
- value: void 0
51
- });
52
-
53
- _classPrivateFieldInitSpec(this, _originalOverflowValue, {
54
- writable: true,
55
- value: ''
56
- });
57
-
58
- _classPrivateFieldInitSpec(this, _$targetSlot, {
59
- writable: true,
60
- value: void 0
61
- });
62
-
63
- _classPrivateFieldInitSpec(this, _$targetOpenSlot, {
64
- writable: true,
65
- value: void 0
66
- });
67
-
68
- _classPrivateFieldInitSpec(this, _$targetOpenWrapper, {
69
- writable: true,
70
- value: void 0
71
- });
72
-
73
- _classPrivateFieldInitSpec(this, _targetActiveElement, {
74
- writable: true,
75
- value: null
76
- });
77
-
78
- _classPrivateFieldInitSpec(this, _onResize, {
79
- writable: true,
80
- value: () => {
81
- _classPrivateFieldGet(this, _resizeThrottle).fn();
82
- }
83
- });
84
-
85
- _classPrivateFieldInitSpec(this, _updateOrientation, {
86
- writable: true,
87
- value: () => {
88
- _classPrivateFieldGet(this, _$dialog).style.width = 'max-content';
89
-
90
- const targetRect = _classPrivateFieldGet(this, _$target).getBoundingClientRect();
91
-
92
- const modalRect = _classPrivateFieldGet(this, _$dialog).getBoundingClientRect();
93
-
94
- let leftPos = 0;
95
- let topPos = 0;
96
- const orient = this.orientation;
97
- const shouldExpandWidthToTarget = orient === 'top' || orient === 'bottom';
98
- const resultWidth = shouldExpandWidthToTarget ? Math.max(modalRect.width, targetRect.width) : modalRect.width;
99
-
100
- if (orient === 'bottom-right' || orient === 'top-right' || orient === 'top' || orient === 'bottom') {
101
- leftPos = Math.max(POPOVER_OFFSET, Math.min(targetRect.x, window.innerWidth - resultWidth - POPOVER_OFFSET));
102
- }
103
-
104
- if (orient === 'bottom-left' || orient === 'top-left') {
105
- leftPos = Math.max(POPOVER_OFFSET, targetRect.right - resultWidth);
106
- }
107
-
108
- if (orient === 'bottom-left' || orient === 'bottom-right' || orient === 'bottom') {
109
- topPos = Math.max(POPOVER_OFFSET, Math.min(targetRect.bottom + POPOVER_OFFSET, window.innerHeight - modalRect.height - POPOVER_OFFSET));
110
- }
111
-
112
- if (orient === 'top-left' || orient === 'top-right' || orient === 'top') {
113
- topPos = Math.max(POPOVER_OFFSET, targetRect.top - POPOVER_OFFSET - modalRect.height);
114
- }
115
-
116
- _classPrivateFieldGet(this, _$dialog).style.left = `${leftPos}px`;
117
- _classPrivateFieldGet(this, _$dialog).style.top = `${topPos}px`;
118
- _classPrivateFieldGet(this, _$dialog).style.width = `${resultWidth}px`;
119
-
120
- if (!this.modal) {
121
- const targetLeftPos = targetRect.left - leftPos;
122
- const targetTopPos = targetRect.top - topPos;
123
- _classPrivateFieldGet(this, _$targetOpenWrapper).style.left = `${targetLeftPos}px`;
124
- _classPrivateFieldGet(this, _$targetOpenWrapper).style.top = `${targetTopPos}px`;
125
- }
126
- }
127
- });
128
-
129
- _classPrivateFieldInitSpec(this, _onBackdropMouseDown, {
130
- writable: true,
131
- value: e => {
132
- if (e.target !== _classPrivateFieldGet(this, _$dialog)) {
133
- return;
134
- }
135
-
136
- const rect = this.popoverRect;
137
- const isInside = e.x >= rect.x && e.x < rect.x + rect.width && e.y >= rect.y && e.y < rect.y + rect.height;
138
-
139
- if (!isInside) {
140
- _classPrivateMethodGet(this, _dispatchCloseEvent, _dispatchCloseEvent2).call(this);
141
- }
142
- }
143
- });
144
-
145
- _classPrivateFieldInitSpec(this, _onCancel, {
146
- writable: true,
147
- value: e => {
148
- e.preventDefault();
149
-
150
- _classPrivateMethodGet(this, _dispatchCloseEvent, _dispatchCloseEvent2).call(this);
151
- }
152
- });
153
-
154
- _classPrivateFieldInitSpec(this, _onCloseReactHandler, {
155
- writable: true,
156
- value: e => {
157
- getReactEventHandler(this, 'onClose')?.();
158
- getReactEventHandler(this, 'on-close')?.(e);
159
- }
160
- });
161
-
162
- _classPrivateFieldInitSpec(this, _captureActiveElement, {
163
- writable: true,
164
- value: e => {
165
- e.stopPropagation();
166
-
167
- _classPrivateFieldSet(this, _targetActiveElement, e.target);
168
- }
169
- });
170
-
171
- _classPrivateFieldInitSpec(this, _stopPropagation, {
172
- writable: true,
173
- value: e => {
174
- e.stopPropagation();
175
- }
176
- });
177
-
178
25
  const shadowRoot = this.attachShadow();
179
26
  shadowRoot.appendChild(template.content.cloneNode(true));
180
-
181
- _classPrivateFieldSet(this, _$target, shadowRoot.querySelector('#target'));
182
-
183
- _classPrivateFieldSet(this, _$dialog, shadowRoot.querySelector('#dialog'));
184
-
185
- _classPrivateFieldSet(this, _$targetSlot, shadowRoot.querySelector('slot[name="target"]'));
186
-
187
- _classPrivateFieldSet(this, _$targetOpenSlot, shadowRoot.querySelector('slot[name="target-open"]'));
188
-
189
- _classPrivateFieldSet(this, _$targetOpenWrapper, shadowRoot.querySelector('#target-open'));
190
-
191
- _classPrivateFieldSet(this, _isConnected, false);
192
-
193
- _classPrivateFieldSet(this, _resizeThrottle, throttleAnimationFrame(_classPrivateFieldGet(this, _updateOrientation)));
194
-
195
- dialogPolyfill.registerDialog(_classPrivateFieldGet(this, _$dialog));
27
+ this.#$target = shadowRoot.querySelector('#target');
28
+ this.#$dialog = shadowRoot.querySelector('#dialog');
29
+ this.#$targetSlot = shadowRoot.querySelector('slot[name="target"]');
30
+ this.#$targetOpenSlot = shadowRoot.querySelector('slot[name="target-open"]');
31
+ this.#$contentSlot = shadowRoot.querySelector('slot[name="content"]');
32
+ this.#$targetOpenWrapper = shadowRoot.querySelector('#target-open');
33
+ this.#isConnected = false;
34
+ this.#resizeThrottle = throttleAnimationFrame(this.#updateOrientation);
35
+ this.#keydownContext = new Context(this.#$contentSlot, 'keydown');
36
+ this.#visibilityContext = new Context(this.#$contentSlot, 'visibility');
37
+ dialogPolyfill.registerDialog(this.#$dialog);
196
38
 
197
39
  dialogPolyfill.dm.handleFocus_ = function () {};
198
40
  }
199
41
 
200
42
  connectedCallback() {
43
+ const {
44
+ signal
45
+ } = this.#controller;
201
46
  this.setAttribute('role', 'dialog');
202
-
203
- _classPrivateFieldGet(this, _$dialog).addEventListener('cancel', _classPrivateFieldGet(this, _onCancel));
204
-
205
- _classPrivateFieldGet(this, _$dialog).addEventListener('mousedown', _classPrivateFieldGet(this, _onBackdropMouseDown));
206
-
207
- this.addEventListener('-close', _classPrivateFieldGet(this, _onCloseReactHandler));
208
-
209
- _classPrivateFieldSet(this, _isConnected, true);
47
+ this.#$dialog.addEventListener('cancel', this.#onCancel, {
48
+ signal
49
+ });
50
+ this.#$dialog.addEventListener('mousedown', this.#onBackdropMouseDown, {
51
+ signal
52
+ });
53
+ this.addEventListener('-close', this.#onCloseReactHandler, {
54
+ signal
55
+ });
56
+ this.#isConnected = true;
57
+ this.#keydownContext.subscribe();
58
+ this.#visibilityContext.subscribe();
210
59
 
211
60
  if (getBooleanAttribute(this, 'open')) {
212
- _classPrivateMethodGet(this, _onExpand, _onExpand2).call(this);
213
- } else {
214
- _classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
61
+ this.#onExpand();
215
62
  }
216
63
  }
217
64
 
218
65
  disconnectedCallback() {
219
- _classPrivateFieldGet(this, _$dialog).removeEventListener('cancel', _classPrivateFieldGet(this, _onCancel));
220
-
221
- _classPrivateFieldGet(this, _$dialog).removeEventListener('mousedown', _classPrivateFieldGet(this, _onBackdropMouseDown));
222
-
223
- this.removeEventListener('-close', _classPrivateFieldGet(this, _onCloseReactHandler));
224
-
225
- _classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
226
-
227
- _classPrivateFieldSet(this, _isConnected, false);
66
+ this.#controller.abort();
67
+ this.#onCollapse();
68
+ this.#isConnected = false;
69
+ this.#keydownContext.unsubscribe();
70
+ this.#visibilityContext.unsubscribe();
228
71
  }
229
72
 
230
73
  static get observedAttributes() {
231
- return ['modal', 'orientation', 'open'];
74
+ return ['orientation', 'open'];
232
75
  }
233
76
 
234
77
  set modal(isModal) {
@@ -248,7 +91,7 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
248
91
  }
249
92
 
250
93
  get orientation() {
251
- return getLiteralAttribute(this, orientationValues, 'orientation', 'bottom');
94
+ return getLiteralAttribute(this, orientationValues, 'orientation', 'bottom-left');
252
95
  }
253
96
 
254
97
  set orientation(value) {
@@ -256,7 +99,7 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
256
99
  }
257
100
 
258
101
  get popoverRect() {
259
- return getRect(_classPrivateFieldGet(this, _$dialog));
102
+ return getRect(this.#$dialog);
260
103
  }
261
104
 
262
105
  attributeChangedCallback(name, oldVal, newVal) {
@@ -268,9 +111,11 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
268
111
  case 'open':
269
112
  {
270
113
  if (isAttrTrue(newVal)) {
271
- _classPrivateMethodGet(this, _onExpand, _onExpand2).call(this);
114
+ requestAnimationFrame(() => {
115
+ this.#onExpand();
116
+ });
272
117
  } else {
273
- _classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
118
+ this.#onCollapse();
274
119
  }
275
120
 
276
121
  updateBooleanAttribute(this, 'open', isAttrTrue(newVal));
@@ -279,115 +124,200 @@ defineCustomElement('sinch-popover', (_$target = new WeakMap(), _$dialog = new W
279
124
 
280
125
  case 'orientation':
281
126
  {
282
- if (_classPrivateMethodGet(this, _isOpen, _isOpen2).call(this)) {
283
- _classPrivateFieldGet(this, _updateOrientation).call(this);
127
+ if (this.#isOpen()) {
128
+ this.#updateOrientation();
284
129
  }
285
130
 
286
131
  break;
287
132
  }
288
-
289
- case 'modal':
290
- {
291
- if (_classPrivateMethodGet(this, _isOpen, _isOpen2).call(this)) {
292
- _classPrivateMethodGet(this, _onCollapse, _onCollapse2).call(this);
293
-
294
- _classPrivateMethodGet(this, _onExpand, _onExpand2).call(this);
295
- }
296
- }
297
133
  }
298
134
  }
299
135
 
300
- }));
136
+ #onExpand() {
137
+ if (!this.#isConnected || this.#isOpen()) {
138
+ return;
139
+ }
301
140
 
302
- function _onExpand2() {
303
- if (!_classPrivateFieldGet(this, _isConnected) || _classPrivateMethodGet(this, _isOpen, _isOpen2).call(this)) {
304
- return;
305
- }
141
+ const isNonModal = !this.modal;
142
+ this.#$targetSlot.addEventListener('blur', this.#captureActiveElement, true);
143
+
144
+ if (isNonModal) {
145
+ this.#$targetOpenSlot.addEventListener('blur', this.#captureActiveElement, true);
146
+ this.#$targetOpenSlot.addEventListener('focus', this.#stopPropagation, true);
147
+ const targetRect = this.#$target.getBoundingClientRect();
148
+ const widthPx = `${targetRect.width}px`;
149
+ const heightPx = `${targetRect.height}px`;
150
+ this.#$target.style.width = widthPx;
151
+ this.#$target.style.height = heightPx;
152
+ this.#$targetOpenWrapper.style.width = widthPx;
153
+ this.#$targetOpenWrapper.style.height = heightPx;
154
+ getFirstSlotElement(this.#$targetSlot)?.setAttribute('slot', 'target-open');
155
+ this.#$targetOpenSlot.addEventListener('keydown', this.#onTargetKeydown);
156
+ }
306
157
 
307
- const isNonModal = !this.modal;
158
+ this.#$dialog.showModal();
159
+ this.#updateOrientation();
160
+ this.#$target.setAttribute('aria-expanded', 'true');
161
+ this.#$targetSlot.removeEventListener('blur', this.#captureActiveElement, true);
162
+
163
+ if (isNonModal) {
164
+ this.#$targetOpenSlot.removeEventListener('blur', this.#captureActiveElement, true);
165
+ this.#$targetOpenSlot.removeEventListener('focus', this.#stopPropagation, true);
166
+
167
+ if (this.#targetActiveElement !== null) {
168
+ if (!isElementFocused(this.#targetActiveElement)) {
169
+ requestAnimationFrame(() => {
170
+ this.#$targetOpenSlot.addEventListener('focus', this.#stopPropagation, true);
171
+ this.#targetActiveElement?.focus();
172
+ this.#$targetOpenSlot.removeEventListener('focus', this.#stopPropagation, true);
173
+ });
174
+ }
175
+ }
176
+ } else {
177
+ if (document.activeElement === document.body) {
178
+ getFirstSlotElement(this.#$contentSlot)?.focus();
179
+ }
180
+ }
308
181
 
309
- _classPrivateFieldGet(this, _$targetSlot).addEventListener('blur', _classPrivateFieldGet(this, _stopPropagation), true);
182
+ this.#originalOverflowValue = document.body.style.overflow;
183
+ document.body.style.overflow = 'hidden';
184
+ window.addEventListener('resize', this.#onResize);
185
+ this.#dispatchContentVisibility(true);
186
+ }
310
187
 
311
- if (isNonModal) {
312
- _classPrivateFieldGet(this, _$targetOpenSlot).addEventListener('blur', _classPrivateFieldGet(this, _captureActiveElement), true);
188
+ #onCollapse() {
189
+ if (!this.#isOpen()) {
190
+ return;
191
+ }
313
192
 
314
- const targetRect = _classPrivateFieldGet(this, _$target).getBoundingClientRect();
193
+ this.#dispatchContentVisibility(false);
194
+ this.#$targetSlot.addEventListener('focus', this.#stopPropagation, true);
195
+ getFirstSlotElement(this.#$targetOpenSlot)?.setAttribute('slot', 'target');
196
+ this.#$target.style.width = 'unset';
197
+ this.#$target.style.height = 'unset';
198
+ this.#$dialog.close();
199
+ this.#$target.setAttribute('aria-expanded', 'false');
200
+
201
+ if (this.#targetActiveElement !== null) {
202
+ if (!isElementFocused(this.#targetActiveElement)) {
203
+ requestAnimationFrame(() => {
204
+ this.#$targetSlot.addEventListener('focus', this.#stopPropagation, true);
205
+ this.#targetActiveElement.focus();
206
+ this.#targetActiveElement = null;
207
+ this.#$targetSlot.removeEventListener('focus', this.#stopPropagation, true);
208
+ });
209
+ } else {
210
+ this.#targetActiveElement = null;
211
+ }
212
+ }
315
213
 
316
- const widthPx = `${targetRect.width}px`;
317
- const heightPx = `${targetRect.height}px`;
318
- _classPrivateFieldGet(this, _$target).style.width = widthPx;
319
- _classPrivateFieldGet(this, _$target).style.height = heightPx;
320
- _classPrivateFieldGet(this, _$targetOpenWrapper).style.width = widthPx;
321
- _classPrivateFieldGet(this, _$targetOpenWrapper).style.height = heightPx;
322
- _classPrivateFieldGet(this, _$targetSlot).assignedElements()[0]?.setAttribute('slot', 'target-open');
214
+ this.#$targetSlot.removeEventListener('focus', this.#stopPropagation, true);
215
+ this.#$targetOpenSlot.removeEventListener('keydown', this.#onTargetKeydown);
216
+ document.body.style.overflow = this.#originalOverflowValue;
217
+ this.#resizeThrottle.cancel();
218
+ window.removeEventListener('resize', this.#onResize);
323
219
  }
324
220
 
325
- _classPrivateFieldGet(this, _$dialog).showModal();
326
-
327
- _classPrivateFieldGet(this, _updateOrientation).call(this);
221
+ #isOpen() {
222
+ return getBooleanAttribute(this.#$dialog, 'open');
223
+ }
328
224
 
329
- _classPrivateFieldGet(this, _$target).setAttribute('aria-expanded', 'true');
225
+ #onResize = () => {
226
+ this.#resizeThrottle.fn();
227
+ };
228
+ #updateOrientation = () => {
229
+ this.#$dialog.style.width = 'max-content';
230
+ const targetRect = this.#$target.getBoundingClientRect();
231
+ const modalRect = this.#$dialog.getBoundingClientRect();
232
+ let leftPos = 0;
233
+ let topPos = 0;
234
+ const orient = this.orientation;
235
+ const shouldSetWidthToTarget = orient === 'top' || orient === 'bottom';
236
+ const resultWidth = shouldSetWidthToTarget ? targetRect.width : modalRect.width;
237
+
238
+ if (orient === 'bottom-right' || orient === 'top-right' || orient === 'top' || orient === 'bottom') {
239
+ leftPos = Math.max(POPOVER_OFFSET, Math.min(targetRect.x, window.innerWidth - resultWidth - POPOVER_OFFSET));
240
+ }
330
241
 
331
- _classPrivateFieldGet(this, _$targetSlot).removeEventListener('blur', _classPrivateFieldGet(this, _stopPropagation), true);
242
+ if (orient === 'bottom-left' || orient === 'top-left') {
243
+ leftPos = Math.max(POPOVER_OFFSET, targetRect.right - resultWidth);
244
+ }
332
245
 
333
- if (isNonModal) {
334
- _classPrivateFieldGet(this, _$targetOpenSlot).removeEventListener('blur', _classPrivateFieldGet(this, _captureActiveElement), true);
246
+ if (orient === 'bottom-left' || orient === 'bottom-right' || orient === 'bottom') {
247
+ topPos = Math.max(POPOVER_OFFSET, Math.min(targetRect.bottom + POPOVER_OFFSET, window.innerHeight - modalRect.height - POPOVER_OFFSET));
248
+ }
335
249
 
336
- if (_classPrivateFieldGet(this, _targetActiveElement) !== null) {
337
- requestAnimationFrame(() => {
338
- _classPrivateFieldGet(this, _$targetOpenSlot).addEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
250
+ if (orient === 'top-left' || orient === 'top-right' || orient === 'top') {
251
+ topPos = Math.max(POPOVER_OFFSET, targetRect.top - POPOVER_OFFSET - modalRect.height);
252
+ }
339
253
 
340
- _classPrivateFieldGet(this, _targetActiveElement)?.focus();
254
+ this.#$dialog.style.left = `${leftPos}px`;
255
+ this.#$dialog.style.top = `${topPos}px`;
256
+ this.#$dialog.style.width = `${resultWidth}px`;
341
257
 
342
- _classPrivateFieldGet(this, _$targetOpenSlot).removeEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
343
- });
258
+ if (!this.modal) {
259
+ const targetLeftPos = targetRect.left - leftPos;
260
+ const targetTopPos = targetRect.top - topPos;
261
+ this.#$targetOpenWrapper.style.left = `${targetLeftPos}px`;
262
+ this.#$targetOpenWrapper.style.top = `${targetTopPos}px`;
263
+ }
264
+ };
265
+ #onBackdropMouseDown = e => {
266
+ if (e.target !== this.#$dialog) {
267
+ return;
344
268
  }
345
- }
346
-
347
- _classPrivateFieldSet(this, _originalOverflowValue, document.body.style.overflow);
348
269
 
349
- document.body.style.overflow = 'hidden';
350
- window.addEventListener('resize', _classPrivateFieldGet(this, _onResize));
351
- }
270
+ const rect = this.popoverRect;
271
+ const isInside = e.x >= rect.x && e.x < rect.x + rect.width && e.y >= rect.y && e.y < rect.y + rect.height;
352
272
 
353
- function _onCollapse2() {
354
- if (!_classPrivateMethodGet(this, _isOpen, _isOpen2).call(this)) {
355
- return;
273
+ if (!isInside) {
274
+ this.#dispatchCloseEvent();
275
+ }
276
+ };
277
+ #onCancel = e => {
278
+ e.preventDefault();
279
+ this.#dispatchCloseEvent();
280
+ };
281
+ #onCloseReactHandler = e => {
282
+ getReactEventHandler(this, 'onClose')?.();
283
+ getReactEventHandler(this, 'on-close')?.(e);
284
+ };
285
+
286
+ #dispatchCloseEvent() {
287
+ this.dispatchEvent(new CustomEvent('-close'));
356
288
  }
357
289
 
358
- _classPrivateFieldGet(this, _$targetSlot).addEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
359
-
360
- if (_classPrivateFieldGet(this, _targetActiveElement) !== null) {
361
- _classPrivateFieldGet(this, _$targetOpenSlot).addEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
362
-
363
- _classPrivateFieldGet(this, _targetActiveElement).focus();
364
-
365
- _classPrivateFieldSet(this, _targetActiveElement, null);
366
-
367
- _classPrivateFieldGet(this, _$targetOpenSlot).removeEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
290
+ #captureActiveElement = e => {
291
+ e.stopPropagation();
292
+ this.#targetActiveElement = e.target;
293
+ };
294
+ #stopPropagation = e => {
295
+ e.stopPropagation();
296
+ };
297
+
298
+ #dispatchContentVisibility(isVisible) {
299
+ for (const $el of this.#visibilityContext.elements) {
300
+ $el.dispatchEvent(new CustomEvent('-visibility', {
301
+ detail: isVisible
302
+ }));
303
+ }
368
304
  }
369
305
 
370
- _classPrivateFieldGet(this, _$targetOpenSlot).assignedElements()[0]?.setAttribute('slot', 'target');
371
- _classPrivateFieldGet(this, _$target).style.width = 'unset';
372
- _classPrivateFieldGet(this, _$target).style.height = 'unset';
373
-
374
- _classPrivateFieldGet(this, _$dialog).close();
375
-
376
- _classPrivateFieldGet(this, _$target).setAttribute('aria-expanded', 'false');
377
-
378
- _classPrivateFieldGet(this, _$targetSlot).removeEventListener('focus', _classPrivateFieldGet(this, _stopPropagation), true);
379
-
380
- document.body.style.overflow = _classPrivateFieldGet(this, _originalOverflowValue);
381
-
382
- _classPrivateFieldGet(this, _resizeThrottle).cancel();
383
-
384
- window.removeEventListener('resize', _classPrivateFieldGet(this, _onResize));
385
- }
386
-
387
- function _isOpen2() {
388
- return getBooleanAttribute(_classPrivateFieldGet(this, _$dialog), 'open');
389
- }
306
+ #onTargetKeydown = e => {
307
+ for (const $el of this.#keydownContext.elements) {
308
+ let isPrevented = false;
309
+ $el.dispatchEvent(new CustomEvent('-keydown', {
310
+ detail: {
311
+ code: e.code,
312
+ preventDefault: () => {
313
+ isPrevented = true;
314
+ }
315
+ }
316
+ }));
390
317
 
391
- function _dispatchCloseEvent2() {
392
- this.dispatchEvent(new CustomEvent('-close'));
393
- }
318
+ if (isPrevented) {
319
+ e.preventDefault();
320
+ }
321
+ }
322
+ };
323
+ });
package/progress/index.js CHANGED
@@ -1,12 +1,3 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$bar, _$text;
5
-
6
- function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
7
-
8
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
9
-
10
1
  import '../spinner';
11
2
  import '../icons/check-circle';
12
3
  import '../icons/report';
@@ -17,26 +8,16 @@ import { defineCustomElement, updateAttribute, NectaryElement, updateBooleanAttr
17
8
  const templateHTML = '<style>:host{display:block}#wrapper{display:flex;align-items:center;height:24px}#bar,#progress{height:8px;border-radius:4px}#progress{background-color:var(--sinch-color-tropical-100);flex:1;min-width:0}#bar{background-color:var(--sinch-color-tropical-500);width:0}#text{display:none;width:46px}:host([detailed]:not([detailed=false])) #text{display:block}</style><div id="wrapper"><sinch-text id="text" type="m"></sinch-text><div id="progress"><div id="bar"></div></div></div>';
18
9
  const template = document.createElement('template');
19
10
  template.innerHTML = templateHTML;
20
- defineCustomElement('sinch-progress', (_$bar = new WeakMap(), _$text = new WeakMap(), class extends NectaryElement {
11
+ defineCustomElement('sinch-progress', class extends NectaryElement {
12
+ #$bar;
13
+ #$text;
14
+
21
15
  constructor() {
22
16
  super();
23
-
24
- _classPrivateFieldInitSpec(this, _$bar, {
25
- writable: true,
26
- value: void 0
27
- });
28
-
29
- _classPrivateFieldInitSpec(this, _$text, {
30
- writable: true,
31
- value: void 0
32
- });
33
-
34
17
  const shadowRoot = this.attachShadow();
35
18
  shadowRoot.appendChild(template.content.cloneNode(true));
36
-
37
- _classPrivateFieldSet(this, _$bar, shadowRoot.querySelector('#bar'));
38
-
39
- _classPrivateFieldSet(this, _$text, shadowRoot.querySelector('#text'));
19
+ this.#$bar = shadowRoot.querySelector('#bar');
20
+ this.#$text = shadowRoot.querySelector('#text');
40
21
  }
41
22
 
42
23
  connectedCallback() {
@@ -76,12 +57,12 @@ defineCustomElement('sinch-progress', (_$bar = new WeakMap(), _$text = new WeakM
76
57
  max: 100
77
58
  });
78
59
  const intCss = int === null ? '0%' : `${int}%`;
79
- _classPrivateFieldGet(this, _$bar).style.width = intCss;
80
- _classPrivateFieldGet(this, _$text).textContent = intCss;
60
+ this.#$bar.style.width = intCss;
61
+ this.#$text.textContent = intCss;
81
62
  this.setAttribute('valuenow', int !== null ? String(int) : '0');
82
63
  break;
83
64
  }
84
65
  }
85
66
  }
86
67
 
87
- }));
68
+ });