@nectary/components 0.41.1 → 0.42.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.
- package/accordion/index.js +0 -16
- package/accordion/types.d.ts +9 -1
- package/accordion-item/index.js +0 -24
- package/accordion-item/types.d.ts +18 -3
- package/action-menu/index.js +1 -45
- package/action-menu-option/index.js +0 -18
- package/alert/index.js +0 -10
- package/alert/types.d.ts +6 -0
- package/avatar/index.js +57 -20
- package/avatar/types.d.ts +25 -7
- package/avatar/utils.d.ts +10 -2
- package/avatar/utils.js +23 -2
- package/badge/index.d.ts +11 -0
- package/badge/index.js +140 -0
- package/badge/types.d.ts +38 -0
- package/badge/utils.d.ts +11 -0
- package/badge/utils.js +23 -0
- package/button/index.js +0 -18
- package/card/index.js +0 -16
- package/card/types.d.ts +15 -3
- package/card-container/index.js +0 -1
- package/chat/index.js +0 -1
- package/chat-block/index.js +0 -19
- package/chat-block/types.d.ts +16 -4
- package/chat-bubble/index.js +0 -9
- package/chat-bubble/types.d.ts +6 -0
- package/checkbox/index.js +0 -23
- package/chip/index.js +16 -25
- package/chip/utils.d.ts +3 -0
- package/chip/utils.js +11 -0
- package/color-menu/index.js +8 -86
- package/color-menu/utils.js +0 -4
- package/color-swatch/index.js +17 -17
- package/color-swatch/types.d.ts +2 -2
- package/color-swatch/utils.d.ts +3 -0
- package/color-swatch/utils.js +11 -0
- package/date-picker/index.js +1 -50
- package/date-picker/utils.js +0 -7
- package/dialog/index.js +1 -17
- package/field/index.js +0 -19
- package/file-drop/index.js +0 -40
- package/file-drop/utils.js +0 -6
- package/file-picker/index.js +0 -17
- package/file-picker/utils.js +0 -1
- package/file-status/index.js +0 -12
- package/grid/index.js +0 -1
- package/grid-item/index.js +0 -9
- package/help-tooltip/index.js +0 -14
- package/horizontal-stepper/index.js +0 -12
- package/horizontal-stepper-item/index.js +0 -14
- package/icon-button/index.js +0 -15
- package/icons/create-icon-class.js +0 -2
- package/icons-branded/create-icon-class.js +0 -8
- package/icons-channel/create-icon-class.js +0 -6
- package/illustrations/create-illustration-class.js +0 -11
- package/inline-alert/index.js +0 -14
- package/input/index.js +0 -37
- package/link/index.js +0 -25
- package/list/index.js +0 -2
- package/list-item/index.js +0 -2
- package/logo/create-logo-class.js +0 -9
- package/package.json +1 -1
- package/pagination/index.js +0 -31
- package/pop/index.js +26 -68
- package/pop/utils.js +0 -1
- package/popover/index.js +0 -33
- package/popover/utils.js +0 -2
- package/progress/index.js +0 -10
- package/radio/index.js +0 -30
- package/radio-option/index.js +0 -20
- package/segment/index.js +0 -15
- package/segment-collapse/index.js +0 -13
- package/segmented-control/index.js +0 -12
- package/segmented-control-option/index.js +0 -18
- package/segmented-icon-control/index.js +0 -16
- package/segmented-icon-control-option/index.js +0 -14
- package/select-button/index.js +0 -23
- package/select-menu/index.js +1 -63
- package/select-menu-option/index.js +0 -14
- package/spinner/index.js +0 -4
- package/stop-events/index.js +0 -5
- package/table/index.js +0 -2
- package/table-body/index.js +0 -2
- package/table-cell/index.js +0 -4
- package/table-head/index.js +0 -2
- package/table-head-cell/index.js +0 -11
- package/table-row/index.js +0 -6
- package/tabs/index.js +0 -30
- package/tabs-option/index.js +0 -19
- package/tag/index.js +18 -21
- package/tag/utils.d.ts +3 -0
- package/tag/utils.js +11 -0
- package/text/index.js +1 -12
- package/textarea/index.js +0 -40
- package/{utils → theme}/colors.d.ts +0 -1
- package/{utils → theme}/colors.js +0 -1
- package/theme.css +13 -209
- package/tile-control/index.js +0 -24
- package/tile-control-option/index.js +0 -18
- package/time-picker/index.js +2 -51
- package/time-picker/utils.js +0 -18
- package/title/index.js +1 -12
- package/title/utils.js +0 -5
- package/toast/index.js +0 -19
- package/toast-manager/index.js +0 -27
- package/toggle/index.js +0 -23
- package/tooltip/index.js +0 -27
- package/tooltip/utils.js +0 -4
- package/utils/animation.js +0 -20
- package/utils/context.js +0 -6
- package/utils/index.d.ts +1 -0
- package/utils/index.js +11 -52
- package/vertical-stepper/index.js +0 -12
- package/vertical-stepper-item/index.js +0 -14
- package/avatar-badge/index.d.ts +0 -11
- package/avatar-badge/index.js +0 -38
- package/avatar-badge/types.d.ts +0 -8
- package/avatar-status/index.d.ts +0 -11
- package/avatar-status/index.js +0 -37
- package/avatar-status/types.d.ts +0 -9
- package/avatar-status/types.js +0 -1
- package/avatar-status/utils.d.ts +0 -5
- package/avatar-status/utils.js +0 -6
- package/chat-avatar/index.d.ts +0 -12
- package/chat-avatar/index.js +0 -52
- package/chat-avatar/types.d.ts +0 -12
- package/chat-avatar/types.js +0 -1
- /package/{avatar-badge → badge}/types.js +0 -0
package/pagination/index.js
CHANGED
|
@@ -15,7 +15,6 @@ defineCustomElement('sinch-pagination', class extends NectaryElement {
|
|
|
15
15
|
#$right;
|
|
16
16
|
#$buttons;
|
|
17
17
|
#$wrapper;
|
|
18
|
-
|
|
19
18
|
constructor() {
|
|
20
19
|
super();
|
|
21
20
|
const shadowRoot = this.attachShadow();
|
|
@@ -25,22 +24,18 @@ defineCustomElement('sinch-pagination', class extends NectaryElement {
|
|
|
25
24
|
this.#$buttons = shadowRoot.querySelectorAll('.page');
|
|
26
25
|
this.#$wrapper = shadowRoot.querySelector('#wrapper');
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
connectedCallback() {
|
|
30
28
|
this.#onValueChange();
|
|
31
29
|
this.#$wrapper.addEventListener('click', this.#onButtonClick);
|
|
32
30
|
this.addEventListener('-change', this.#onChangeReactHandler);
|
|
33
31
|
}
|
|
34
|
-
|
|
35
32
|
disconnectedCallback() {
|
|
36
33
|
this.#$wrapper.removeEventListener('click', this.#onButtonClick);
|
|
37
34
|
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
static get observedAttributes() {
|
|
41
37
|
return ['max', 'value'];
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
attributeChangedCallback(name, _) {
|
|
45
40
|
switch (name) {
|
|
46
41
|
case 'value':
|
|
@@ -48,7 +43,6 @@ defineCustomElement('sinch-pagination', class extends NectaryElement {
|
|
|
48
43
|
this.#onValueChange();
|
|
49
44
|
break;
|
|
50
45
|
}
|
|
51
|
-
|
|
52
46
|
case 'max':
|
|
53
47
|
{
|
|
54
48
|
this.#onValueChange();
|
|
@@ -56,35 +50,27 @@ defineCustomElement('sinch-pagination', class extends NectaryElement {
|
|
|
56
50
|
}
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
|
-
|
|
60
53
|
get nodeName() {
|
|
61
54
|
return 'select';
|
|
62
55
|
}
|
|
63
|
-
|
|
64
56
|
set value(val) {
|
|
65
57
|
updateAttribute(this, 'value', val);
|
|
66
58
|
}
|
|
67
|
-
|
|
68
59
|
get value() {
|
|
69
60
|
return getIntegerAttribute(this, 'value', 0);
|
|
70
61
|
}
|
|
71
|
-
|
|
72
62
|
set max(val) {
|
|
73
63
|
updateAttribute(this, 'max', val);
|
|
74
64
|
}
|
|
75
|
-
|
|
76
65
|
get max() {
|
|
77
66
|
return getIntegerAttribute(this, 'value', 0);
|
|
78
67
|
}
|
|
79
|
-
|
|
80
68
|
#onValueChange() {
|
|
81
69
|
const value = getIntegerAttribute(this, 'value', 0) - 1;
|
|
82
70
|
const max = Math.max(0, getIntegerAttribute(this, 'max', 0));
|
|
83
71
|
const valueOffset = Math.min(Math.max(0, value - MIDDLE_BTN_INDEX), Math.max(0, max - NUM_BUTTONS));
|
|
84
|
-
|
|
85
72
|
for (let i = 0; i < this.#$buttons.length; i++) {
|
|
86
73
|
const $b = this.#$buttons[i];
|
|
87
|
-
|
|
88
74
|
if (value < 3) {
|
|
89
75
|
setClass($b, 'active', value === i);
|
|
90
76
|
} else if (value >= max - MIDDLE_BTN_INDEX) {
|
|
@@ -92,24 +78,19 @@ defineCustomElement('sinch-pagination', class extends NectaryElement {
|
|
|
92
78
|
} else {
|
|
93
79
|
setClass($b, 'active', i === MIDDLE_BTN_INDEX);
|
|
94
80
|
}
|
|
95
|
-
|
|
96
81
|
if (max > NUM_BUTTONS) {
|
|
97
82
|
setClass($b, 'dots', i === DOTS_LEFT_INDEX && value > MIDDLE_BTN_INDEX || i === DOTS_RIGHT_INDEX && value <= max - DOTS_RIGHT_INDEX);
|
|
98
83
|
}
|
|
99
|
-
|
|
100
84
|
setClass($b, 'hidden', i >= max);
|
|
101
85
|
const btnText = $b.firstElementChild;
|
|
102
|
-
|
|
103
86
|
if (btnText != null) {
|
|
104
87
|
btnText.textContent = i === FIRST_BTN_INDEX ? '1' : i === LAST_BTN_INDEX ? String(max) : String(i + 1 + valueOffset);
|
|
105
88
|
}
|
|
106
89
|
}
|
|
107
|
-
|
|
108
90
|
const isValueBad = value < 0 || value >= max;
|
|
109
91
|
this.#$left.disabled = isValueBad || value === 0;
|
|
110
92
|
this.#$right.disabled = isValueBad || value === max - 1;
|
|
111
93
|
}
|
|
112
|
-
|
|
113
94
|
#onButtonClick = e => {
|
|
114
95
|
e.stopPropagation();
|
|
115
96
|
const value = getIntegerAttribute(this, 'value', 0) - 1;
|
|
@@ -122,9 +103,7 @@ defineCustomElement('sinch-pagination', class extends NectaryElement {
|
|
|
122
103
|
if (e.target === this.#$right) {
|
|
123
104
|
return this.#dispatchChangeEvent(value + 1);
|
|
124
105
|
}
|
|
125
|
-
|
|
126
106
|
const btnIndex = Array.prototype.indexOf.call(this.#$wrapper.children, e.target) - 1;
|
|
127
|
-
|
|
128
107
|
if (btnIndex >= 0 && btnIndex < this.#$buttons.length) {
|
|
129
108
|
if (btnIndex === FIRST_BTN_INDEX) {
|
|
130
109
|
return this.#dispatchChangeEvent(0);
|
|
@@ -145,12 +124,10 @@ defineCustomElement('sinch-pagination', class extends NectaryElement {
|
|
|
145
124
|
return this.#dispatchChangeEvent(btnIndex + Math.min(Math.max(0, value - MIDDLE_BTN_INDEX), Math.max(0, max - NUM_BUTTONS)));
|
|
146
125
|
}
|
|
147
126
|
};
|
|
148
|
-
|
|
149
127
|
#clamp(value) {
|
|
150
128
|
const max = getIntegerAttribute(this, 'max', 0);
|
|
151
129
|
return Math.max(0, Math.min(max - 1, value)) + 1;
|
|
152
130
|
}
|
|
153
|
-
|
|
154
131
|
#dispatchChangeEvent(value) {
|
|
155
132
|
const detail = this.#clamp(value);
|
|
156
133
|
this.dispatchEvent(new CustomEvent('change', {
|
|
@@ -161,36 +138,28 @@ defineCustomElement('sinch-pagination', class extends NectaryElement {
|
|
|
161
138
|
detail
|
|
162
139
|
}));
|
|
163
140
|
}
|
|
164
|
-
|
|
165
141
|
#onChangeReactHandler = e => {
|
|
166
142
|
getReactEventHandler(this, 'on-change')?.(e);
|
|
167
143
|
};
|
|
168
|
-
|
|
169
144
|
get focusable() {
|
|
170
145
|
return true;
|
|
171
146
|
}
|
|
172
|
-
|
|
173
147
|
focus() {
|
|
174
148
|
this.#$left.focus();
|
|
175
149
|
}
|
|
176
|
-
|
|
177
150
|
blur() {
|
|
178
151
|
this.#$left.blur();
|
|
179
152
|
this.#$right.blur();
|
|
180
153
|
this.#$buttons.forEach($b => $b.blur());
|
|
181
154
|
}
|
|
182
|
-
|
|
183
155
|
get prevButtonRect() {
|
|
184
156
|
return getRect(this.#$left);
|
|
185
157
|
}
|
|
186
|
-
|
|
187
158
|
get nextButtonRect() {
|
|
188
159
|
return getRect(this.#$right);
|
|
189
160
|
}
|
|
190
|
-
|
|
191
161
|
nthButtonRect(index) {
|
|
192
162
|
const btn = this.#$buttons[index];
|
|
193
163
|
return btn == null ? null : getRect(btn);
|
|
194
164
|
}
|
|
195
|
-
|
|
196
165
|
});
|
package/pop/index.js
CHANGED
|
@@ -20,7 +20,6 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
20
20
|
#keydownContext;
|
|
21
21
|
#visibilityContext;
|
|
22
22
|
#targetStyleValue = null;
|
|
23
|
-
|
|
24
23
|
constructor() {
|
|
25
24
|
super();
|
|
26
25
|
const shadowRoot = this.attachShadow();
|
|
@@ -40,7 +39,6 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
40
39
|
|
|
41
40
|
dialogPolyfill.dm.handleFocus_ = function () {};
|
|
42
41
|
}
|
|
43
|
-
|
|
44
42
|
connectedCallback() {
|
|
45
43
|
this.#controller = new AbortController();
|
|
46
44
|
const {
|
|
@@ -63,12 +61,10 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
63
61
|
});
|
|
64
62
|
dispatchContextConnectEvent(this, 'visibility');
|
|
65
63
|
this.#isConnected = true;
|
|
66
|
-
|
|
67
64
|
if (getBooleanAttribute(this, 'open')) {
|
|
68
65
|
this.#onExpand();
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
disconnectedCallback() {
|
|
73
69
|
this.#controller.abort();
|
|
74
70
|
this.#keydownContext.unsubscribe();
|
|
@@ -77,56 +73,43 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
77
73
|
this.#onCollapse();
|
|
78
74
|
this.#isConnected = false;
|
|
79
75
|
}
|
|
80
|
-
|
|
81
76
|
static get observedAttributes() {
|
|
82
77
|
return ['orientation', 'open'];
|
|
83
78
|
}
|
|
84
|
-
|
|
85
79
|
set modal(isModal) {
|
|
86
80
|
updateBooleanAttribute(this, 'modal', isModal);
|
|
87
81
|
}
|
|
88
|
-
|
|
89
82
|
get modal() {
|
|
90
83
|
return getBooleanAttribute(this, 'modal');
|
|
91
84
|
}
|
|
92
|
-
|
|
93
85
|
set open(isOpen) {
|
|
94
86
|
updateBooleanAttribute(this, 'open', isOpen);
|
|
95
87
|
}
|
|
96
|
-
|
|
97
88
|
get open() {
|
|
98
89
|
return getBooleanAttribute(this, 'open');
|
|
99
90
|
}
|
|
100
|
-
|
|
101
91
|
get orientation() {
|
|
102
92
|
return getLiteralAttribute(this, orientationValues, 'orientation');
|
|
103
93
|
}
|
|
104
|
-
|
|
105
94
|
set orientation(value) {
|
|
106
95
|
updateLiteralAttribute(this, orientationValues, 'orientation', value);
|
|
107
96
|
}
|
|
108
|
-
|
|
109
97
|
set inset(inset) {
|
|
110
98
|
updateIntegerAttribute(this, 'inset', inset);
|
|
111
99
|
}
|
|
112
|
-
|
|
113
100
|
get inset() {
|
|
114
101
|
return getIntegerAttribute(this, 'inset', 0);
|
|
115
102
|
}
|
|
116
|
-
|
|
117
103
|
get footprintRect() {
|
|
118
104
|
return this.#getTargetRect();
|
|
119
105
|
}
|
|
120
|
-
|
|
121
106
|
get popoverRect() {
|
|
122
107
|
return getRect(this.#$dialog);
|
|
123
108
|
}
|
|
124
|
-
|
|
125
109
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
126
110
|
if (oldVal === newVal) {
|
|
127
111
|
return;
|
|
128
112
|
}
|
|
129
|
-
|
|
130
113
|
switch (name) {
|
|
131
114
|
case 'open':
|
|
132
115
|
{
|
|
@@ -137,52 +120,39 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
137
120
|
} else {
|
|
138
121
|
this.#onCollapse();
|
|
139
122
|
}
|
|
140
|
-
|
|
141
123
|
updateBooleanAttribute(this, 'open', isAttrTrue(newVal));
|
|
142
124
|
break;
|
|
143
125
|
}
|
|
144
|
-
|
|
145
126
|
case 'orientation':
|
|
146
127
|
{
|
|
147
128
|
assertOrientation(newVal);
|
|
148
|
-
|
|
149
129
|
if (this.#isOpen()) {
|
|
150
130
|
this.#updateOrientation();
|
|
151
131
|
}
|
|
152
|
-
|
|
153
132
|
break;
|
|
154
133
|
}
|
|
155
134
|
}
|
|
156
135
|
}
|
|
157
|
-
|
|
158
136
|
#getTargetRect() {
|
|
159
137
|
let item = getFirstSlotElement(this.#$targetSlot, true);
|
|
160
|
-
|
|
161
138
|
if (item === null && this.#isOpen()) {
|
|
162
139
|
item = getFirstSlotElement(this.#$targetOpenSlot, true);
|
|
163
140
|
}
|
|
164
|
-
|
|
165
141
|
if (item === null) {
|
|
166
142
|
return getRect(this.#$target);
|
|
167
143
|
}
|
|
168
|
-
|
|
169
144
|
if (Reflect.has(item, 'footprintRect')) {
|
|
170
145
|
return item.footprintRect;
|
|
171
146
|
}
|
|
172
|
-
|
|
173
147
|
return getRect(item);
|
|
174
148
|
}
|
|
175
|
-
|
|
176
149
|
#getFirstTargetElement(slot) {
|
|
177
150
|
const item = getFirstSlotElement(slot, true);
|
|
178
|
-
|
|
179
151
|
if (item === null) {
|
|
180
152
|
return this.#$target;
|
|
181
153
|
}
|
|
182
|
-
|
|
183
154
|
return item;
|
|
184
155
|
}
|
|
185
|
-
|
|
186
156
|
#onExpand() {
|
|
187
157
|
if (!this.#isConnected || this.#isOpen()) {
|
|
188
158
|
return;
|
|
@@ -195,10 +165,10 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
195
165
|
this.#$focus.removeEventListener('focus', this.#captureRelatedActiveElement);
|
|
196
166
|
this.#$focus.style.removeProperty('display');
|
|
197
167
|
this.#$targetSlot.removeEventListener('blur', this.#stopEventPropagation, true);
|
|
168
|
+
|
|
198
169
|
this.#$dialog.showModal();
|
|
199
170
|
this.#$target.setAttribute('aria-expanded', 'true');
|
|
200
171
|
this.#updateOrientation();
|
|
201
|
-
|
|
202
172
|
if (this.modal) {
|
|
203
173
|
getFirstFocusableElement(this.#$contentSlot)?.focus();
|
|
204
174
|
} else {
|
|
@@ -217,41 +187,42 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
217
187
|
this.#targetStyleValue = $targetEl.getAttribute('style');
|
|
218
188
|
$targetEl.style.setProperty('margin', '0');
|
|
219
189
|
$targetEl.style.setProperty('position', 'static');
|
|
220
|
-
|
|
221
190
|
if (targetElComputedStyle.transform !== 'none') {
|
|
222
191
|
const matrix = new DOMMatrixReadOnly(targetElComputedStyle.transform);
|
|
223
192
|
$targetEl.style.setProperty('transform', matrix.translate(-matrix.e, -matrix.f).toString());
|
|
224
193
|
}
|
|
225
194
|
|
|
226
195
|
getFirstSlotElement(this.#$targetSlot)?.setAttribute('slot', 'target-open');
|
|
227
|
-
this.#$targetOpenSlot.addEventListener('keydown', this.#onTargetKeydown);
|
|
228
196
|
|
|
197
|
+
this.#$targetOpenSlot.addEventListener('keydown', this.#onTargetKeydown);
|
|
229
198
|
if (this.#targetActiveElement !== null) {
|
|
230
|
-
|
|
231
|
-
this.#
|
|
199
|
+
this.#$targetOpenSlot.addEventListener('focus', this.#stopEventPropagation, true);
|
|
200
|
+
this.#targetActiveElement.focus();
|
|
201
|
+
this.#$targetOpenSlot.removeEventListener('focus', this.#stopEventPropagation, true);
|
|
202
|
+
|
|
203
|
+
if (!isElementFocused(this.#targetActiveElement)) {
|
|
204
|
+
requestAnimationFrame(() => {
|
|
205
|
+
this.#$targetOpenSlot.addEventListener('focus', this.#stopEventPropagation, true);
|
|
206
|
+
this.#targetActiveElement.focus();
|
|
207
|
+
this.#$targetOpenSlot.removeEventListener('focus', this.#stopEventPropagation, true);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
232
210
|
}
|
|
233
211
|
}
|
|
234
212
|
|
|
235
213
|
disableScroll();
|
|
236
214
|
window.addEventListener('resize', this.#onResize);
|
|
215
|
+
|
|
237
216
|
this.#dispatchContentVisibility(true);
|
|
238
217
|
}
|
|
239
|
-
|
|
240
|
-
#focusTargetElementOnExpandNonModal = () => {
|
|
241
|
-
if (this.#targetActiveElement !== null) {
|
|
242
|
-
this.#$targetOpenSlot.addEventListener('focus', this.#stopEventPropagation, true);
|
|
243
|
-
this.#targetActiveElement.focus();
|
|
244
|
-
this.#$targetOpenSlot.removeEventListener('focus', this.#stopEventPropagation, true);
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
|
|
248
218
|
#onCollapse() {
|
|
249
219
|
if (!this.#isOpen()) {
|
|
250
220
|
return;
|
|
251
221
|
}
|
|
252
|
-
|
|
253
222
|
const isNonModal = !this.modal;
|
|
223
|
+
|
|
254
224
|
this.#dispatchContentVisibility(false);
|
|
225
|
+
|
|
255
226
|
this.#$targetOpenSlot.removeEventListener('keydown', this.#onTargetKeydown);
|
|
256
227
|
|
|
257
228
|
if (isNonModal) {
|
|
@@ -270,12 +241,10 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
270
241
|
targetEl.style.removeProperty('margin');
|
|
271
242
|
targetEl.style.removeProperty('position');
|
|
272
243
|
targetEl.style.removeProperty('transform');
|
|
273
|
-
|
|
274
244
|
if (this.#targetStyleValue !== null) {
|
|
275
245
|
targetEl.setAttribute('style', this.#targetStyleValue);
|
|
276
246
|
this.#targetStyleValue = null;
|
|
277
247
|
}
|
|
278
|
-
|
|
279
248
|
getFirstSlotElement(this.#$targetOpenSlot)?.setAttribute('slot', 'target');
|
|
280
249
|
this.#$target.style.removeProperty('display');
|
|
281
250
|
this.#$target.style.removeProperty('width');
|
|
@@ -286,20 +255,26 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
286
255
|
this.#$targetSlot.addEventListener('focus', this.#stopEventPropagation, true);
|
|
287
256
|
this.#targetActiveElement.focus();
|
|
288
257
|
this.#$targetSlot.removeEventListener('focus', this.#stopEventPropagation, true);
|
|
289
|
-
}
|
|
290
258
|
|
|
291
|
-
|
|
259
|
+
if (!isElementFocused(this.#targetActiveElement)) {
|
|
260
|
+
const $targetEl = this.#targetActiveElement;
|
|
261
|
+
requestAnimationFrame(() => {
|
|
262
|
+
this.#$targetSlot.addEventListener('focus', this.#stopEventPropagation, true);
|
|
263
|
+
$targetEl.focus();
|
|
264
|
+
this.#$targetSlot.removeEventListener('focus', this.#stopEventPropagation, true);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
this.#targetActiveElement = null;
|
|
268
|
+
}
|
|
292
269
|
}
|
|
293
270
|
|
|
294
271
|
enableScroll();
|
|
295
272
|
this.#resizeThrottle.cancel();
|
|
296
273
|
window.removeEventListener('resize', this.#onResize);
|
|
297
274
|
}
|
|
298
|
-
|
|
299
275
|
#isOpen() {
|
|
300
276
|
return getBooleanAttribute(this.#$dialog, 'open');
|
|
301
277
|
}
|
|
302
|
-
|
|
303
278
|
#onResize = () => {
|
|
304
279
|
this.#resizeThrottle.fn();
|
|
305
280
|
};
|
|
@@ -314,45 +289,35 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
314
289
|
const inset = this.inset;
|
|
315
290
|
let xPos = 0;
|
|
316
291
|
let yPos = 0;
|
|
317
|
-
|
|
318
292
|
if (orient === 'bottom-right' || orient === 'top-right' || orient === 'top-stretch' || orient === 'bottom-stretch') {
|
|
319
293
|
xPos = targetRect.x;
|
|
320
294
|
}
|
|
321
|
-
|
|
322
295
|
if (orient === 'bottom-left' || orient === 'top-left') {
|
|
323
296
|
xPos = targetRect.x + targetRect.width - modalWidth;
|
|
324
297
|
}
|
|
325
|
-
|
|
326
298
|
if (orient === 'bottom-center' || orient === 'top-center') {
|
|
327
299
|
xPos = targetRect.x + targetRect.width / 2 - modalWidth / 2;
|
|
328
300
|
}
|
|
329
|
-
|
|
330
301
|
if (orient === 'center-right') {
|
|
331
302
|
xPos = targetRect.x + targetRect.width;
|
|
332
303
|
}
|
|
333
|
-
|
|
334
304
|
if (orient === 'center-left') {
|
|
335
305
|
xPos = targetRect.x - modalWidth;
|
|
336
306
|
}
|
|
337
|
-
|
|
338
307
|
if (orient === 'bottom-left' || orient === 'bottom-right' || orient === 'bottom-stretch' || orient === 'bottom-center') {
|
|
339
308
|
yPos = targetRect.y + targetRect.height;
|
|
340
309
|
}
|
|
341
|
-
|
|
342
310
|
if (orient === 'top-left' || orient === 'top-right' || orient === 'top-stretch' || orient === 'top-center') {
|
|
343
311
|
yPos = targetRect.y - modalHeight;
|
|
344
312
|
}
|
|
345
|
-
|
|
346
313
|
if (orient === 'center-left' || orient === 'center-right') {
|
|
347
314
|
yPos = targetRect.y + targetRect.height / 2 - modalHeight / 2;
|
|
348
315
|
}
|
|
349
|
-
|
|
350
316
|
xPos = Math.round(Math.max(inset, Math.min(xPos, window.innerWidth - modalWidth - inset)));
|
|
351
317
|
yPos = Math.round(Math.max(inset, Math.min(yPos, window.innerHeight - modalHeight - inset)));
|
|
352
318
|
this.#$dialog.style.setProperty('left', `${xPos}px`);
|
|
353
319
|
this.#$dialog.style.setProperty('top', `${yPos}px`);
|
|
354
320
|
this.#$dialog.style.setProperty('width', `${modalWidth}px`);
|
|
355
|
-
|
|
356
321
|
if (!this.modal) {
|
|
357
322
|
const targetLeftPos = targetRect.x - xPos;
|
|
358
323
|
const targetTopPos = targetRect.y - yPos;
|
|
@@ -364,10 +329,8 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
364
329
|
if (e.target !== this.#$dialog) {
|
|
365
330
|
return;
|
|
366
331
|
}
|
|
367
|
-
|
|
368
332
|
const rect = this.popoverRect;
|
|
369
333
|
const isInside = e.x >= rect.x && e.x < rect.x + rect.width && e.y >= rect.y && e.y < rect.y + rect.height;
|
|
370
|
-
|
|
371
334
|
if (!isInside) {
|
|
372
335
|
this.#dispatchCloseEvent();
|
|
373
336
|
}
|
|
@@ -379,11 +342,9 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
379
342
|
#onCloseReactHandler = e => {
|
|
380
343
|
getReactEventHandler(this, 'on-close')?.(e);
|
|
381
344
|
};
|
|
382
|
-
|
|
383
345
|
#dispatchCloseEvent() {
|
|
384
346
|
this.dispatchEvent(new CustomEvent('-close'));
|
|
385
347
|
}
|
|
386
|
-
|
|
387
348
|
#captureRelatedActiveElement = e => {
|
|
388
349
|
e.stopPropagation();
|
|
389
350
|
this.#targetActiveElement = e.relatedTarget;
|
|
@@ -395,7 +356,6 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
395
356
|
#stopEventPropagation = e => {
|
|
396
357
|
e.stopPropagation();
|
|
397
358
|
};
|
|
398
|
-
|
|
399
359
|
#dispatchContentVisibility(isVisible) {
|
|
400
360
|
for (const $el of this.#visibilityContext.elements) {
|
|
401
361
|
$el.dispatchEvent(new CustomEvent('-visibility', {
|
|
@@ -403,7 +363,6 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
403
363
|
}));
|
|
404
364
|
}
|
|
405
365
|
}
|
|
406
|
-
|
|
407
366
|
#onTargetKeydown = e => {
|
|
408
367
|
for (const $el of this.#keydownContext.elements) {
|
|
409
368
|
let isPrevented = false;
|
|
@@ -415,7 +374,6 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
415
374
|
}
|
|
416
375
|
}
|
|
417
376
|
}));
|
|
418
|
-
|
|
419
377
|
if (isPrevented) {
|
|
420
378
|
e.preventDefault();
|
|
421
379
|
}
|
package/pop/utils.js
CHANGED
package/popover/index.js
CHANGED
|
@@ -11,7 +11,6 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
11
11
|
#$content;
|
|
12
12
|
#$tip;
|
|
13
13
|
#controller = null;
|
|
14
|
-
|
|
15
14
|
constructor() {
|
|
16
15
|
super();
|
|
17
16
|
const shadowRoot = this.attachShadow();
|
|
@@ -20,7 +19,6 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
20
19
|
this.#$content = shadowRoot.querySelector('#content');
|
|
21
20
|
this.#$tip = shadowRoot.querySelector('#tip');
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
connectedCallback() {
|
|
25
23
|
this.#controller = new AbortController();
|
|
26
24
|
const {
|
|
@@ -38,12 +36,10 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
38
36
|
dispatchContextConnectEvent(this.#$content, 'visibility');
|
|
39
37
|
updateAttribute(this.#$pop, 'orientation', getPopOrientation(this.orientation));
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
disconnectedCallback() {
|
|
43
40
|
dispatchContextDisconnectEvent(this.#$content, 'visibility');
|
|
44
41
|
this.#controller.abort();
|
|
45
42
|
}
|
|
46
|
-
|
|
47
43
|
#onPopClose = () => {
|
|
48
44
|
this.#dispatchCloseEvent();
|
|
49
45
|
};
|
|
@@ -51,84 +47,64 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
51
47
|
getReactEventHandler(this, 'onClose')?.();
|
|
52
48
|
getReactEventHandler(this, 'on-close')?.(e);
|
|
53
49
|
};
|
|
54
|
-
|
|
55
50
|
#dispatchCloseEvent() {
|
|
56
51
|
this.dispatchEvent(new CustomEvent('-close'));
|
|
57
52
|
}
|
|
58
|
-
|
|
59
53
|
static get observedAttributes() {
|
|
60
54
|
return ['orientation', 'open', 'modal', 'tip'];
|
|
61
55
|
}
|
|
62
|
-
|
|
63
56
|
set modal(isModal) {
|
|
64
57
|
updateBooleanAttribute(this, 'modal', isModal);
|
|
65
58
|
}
|
|
66
|
-
|
|
67
59
|
get modal() {
|
|
68
60
|
return getBooleanAttribute(this, 'modal');
|
|
69
61
|
}
|
|
70
|
-
|
|
71
62
|
set open(isOpen) {
|
|
72
63
|
updateBooleanAttribute(this, 'open', isOpen);
|
|
73
64
|
}
|
|
74
|
-
|
|
75
65
|
get open() {
|
|
76
66
|
return getBooleanAttribute(this, 'open');
|
|
77
67
|
}
|
|
78
|
-
|
|
79
68
|
set tip(hasTip) {
|
|
80
69
|
updateBooleanAttribute(this, 'tip', hasTip);
|
|
81
70
|
}
|
|
82
|
-
|
|
83
71
|
get tip() {
|
|
84
72
|
return getBooleanAttribute(this, 'tip');
|
|
85
73
|
}
|
|
86
|
-
|
|
87
74
|
get orientation() {
|
|
88
75
|
return getLiteralAttribute(this, orientationValues, 'orientation', 'bottom-left');
|
|
89
76
|
}
|
|
90
|
-
|
|
91
77
|
set orientation(value) {
|
|
92
78
|
updateLiteralAttribute(this, orientationValues, 'orientation', value);
|
|
93
79
|
}
|
|
94
|
-
|
|
95
80
|
get footprintRect() {
|
|
96
81
|
return this.#$pop.footprintRect;
|
|
97
82
|
}
|
|
98
|
-
|
|
99
83
|
get popoverRect() {
|
|
100
84
|
return this.#$pop.popoverRect;
|
|
101
85
|
}
|
|
102
|
-
|
|
103
86
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
104
87
|
if (oldVal === newVal) {
|
|
105
88
|
return;
|
|
106
89
|
}
|
|
107
|
-
|
|
108
90
|
switch (name) {
|
|
109
91
|
case 'orientation':
|
|
110
92
|
{
|
|
111
93
|
assertOrientation(newVal);
|
|
112
94
|
updateAttribute(this.#$pop, 'orientation', getPopOrientation(newVal));
|
|
113
|
-
|
|
114
95
|
if (this.#isOpen()) {
|
|
115
96
|
this.#updateTipOrientation();
|
|
116
97
|
}
|
|
117
|
-
|
|
118
98
|
break;
|
|
119
99
|
}
|
|
120
|
-
|
|
121
100
|
case 'tip':
|
|
122
101
|
{
|
|
123
102
|
updateBooleanAttribute(this, 'tip', isAttrTrue(newVal));
|
|
124
|
-
|
|
125
103
|
if (newVal === '' && this.#isOpen()) {
|
|
126
104
|
this.#updateTipOrientation();
|
|
127
105
|
}
|
|
128
|
-
|
|
129
106
|
break;
|
|
130
107
|
}
|
|
131
|
-
|
|
132
108
|
case 'open':
|
|
133
109
|
{
|
|
134
110
|
const isOpen = isAttrTrue(newVal);
|
|
@@ -136,14 +112,12 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
136
112
|
updateBooleanAttribute(this, name, isOpen);
|
|
137
113
|
break;
|
|
138
114
|
}
|
|
139
|
-
|
|
140
115
|
default:
|
|
141
116
|
{
|
|
142
117
|
updateAttribute(this.#$pop, name, newVal);
|
|
143
118
|
}
|
|
144
119
|
}
|
|
145
120
|
}
|
|
146
|
-
|
|
147
121
|
#onContextVisibility = e => {
|
|
148
122
|
if (e.detail) {
|
|
149
123
|
this.#updateTipOrientation();
|
|
@@ -151,34 +125,27 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
151
125
|
this.#resetTipOrientation();
|
|
152
126
|
}
|
|
153
127
|
};
|
|
154
|
-
|
|
155
128
|
#resetTipOrientation() {
|
|
156
129
|
this.#$tip.style.top = '';
|
|
157
130
|
this.#$tip.style.left = '';
|
|
158
131
|
}
|
|
159
|
-
|
|
160
132
|
#updateTipOrientation = () => {
|
|
161
133
|
const orientation = this.orientation;
|
|
162
134
|
const targetRect = this.#$pop.footprintRect;
|
|
163
135
|
const contentRect = this.#$content.getBoundingClientRect();
|
|
164
136
|
const diffX = targetRect.x - contentRect.x;
|
|
165
137
|
let desiredX = diffX + targetRect.width / 2;
|
|
166
|
-
|
|
167
138
|
if (orientation === 'bottom-left' || orientation === 'top-left') {
|
|
168
139
|
desiredX = Math.max(desiredX, contentRect.width * 0.75);
|
|
169
140
|
}
|
|
170
|
-
|
|
171
141
|
if (orientation === 'bottom-right' || orientation === 'top-right') {
|
|
172
142
|
desiredX = Math.min(desiredX, contentRect.width * 0.25);
|
|
173
143
|
}
|
|
174
|
-
|
|
175
144
|
const xPos = Math.max(TIP_SIZE, Math.min(desiredX, contentRect.width - TIP_SIZE));
|
|
176
145
|
this.#$tip.style.left = `${xPos}px`;
|
|
177
146
|
setClass(this.#$tip, 'hidden', rectOverlap(targetRect, contentRect));
|
|
178
147
|
};
|
|
179
|
-
|
|
180
148
|
#isOpen() {
|
|
181
149
|
return this.#$pop.open;
|
|
182
150
|
}
|
|
183
|
-
|
|
184
151
|
});
|
package/popover/utils.js
CHANGED