@nectary/components 0.38.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.
- package/accordion/index.js +47 -84
- package/accordion/types.d.ts +1 -0
- package/accordion-item/index.js +26 -53
- package/action-menu/index.d.ts +0 -1
- package/action-menu/index.js +179 -223
- package/action-menu/types.d.ts +8 -18
- package/action-menu-option/index.d.ts +1 -0
- package/action-menu-option/index.js +51 -62
- package/action-menu-option/types.d.ts +9 -0
- package/action-menu-option/utils.d.ts +2 -0
- package/action-menu-option/utils.js +3 -0
- package/alert/index.js +6 -20
- package/avatar/index.js +12 -31
- package/avatar-badge/index.js +8 -22
- package/avatar-status/index.js +1 -1
- package/button/index.js +42 -92
- package/card/index.d.ts +2 -0
- package/card/index.js +24 -87
- package/chat-avatar/index.js +8 -22
- package/chat-block/index.js +29 -69
- package/chat-bubble/index.js +6 -20
- package/checkbox/index.js +55 -107
- package/chip/index.d.ts +13 -0
- package/chip/index.js +137 -0
- package/chip/types.d.ts +38 -0
- package/color-menu/index.d.ts +13 -0
- package/color-menu/index.js +464 -0
- package/color-menu/types.d.ts +37 -0
- package/color-swatch/index.d.ts +13 -0
- package/color-swatch/index.js +59 -0
- package/color-swatch/types.d.ts +12 -0
- package/colors.json +57 -49
- package/date-picker/index.js +196 -287
- package/date-picker/types.d.ts +25 -1
- package/dialog/index.d.ts +1 -0
- package/dialog/index.js +72 -143
- package/dropdown-checkbox-option/index.js +6 -20
- package/dropdown-radio-option/index.js +6 -20
- package/field/index.js +25 -63
- package/file-drop/index.js +123 -200
- package/file-picker/index.d.ts +0 -1
- package/file-picker/index.js +55 -108
- package/file-status/index.js +15 -39
- package/help-tooltip/index.js +1 -1
- package/horizontal-stepper/index.js +33 -59
- package/horizontal-stepper-item/index.js +13 -37
- package/icon-button/index.js +39 -84
- package/icons-channel/notify/index.d.ts +11 -0
- package/icons-channel/notify/index.js +4 -0
- package/illustrations/create-illustration-class.js +1 -1
- package/inline-alert/index.js +30 -82
- package/input/index.js +113 -222
- package/link/index.js +46 -96
- package/list-item/index.js +1 -1
- package/package.json +12 -14
- package/pagination/index.js +109 -163
- package/pagination/types.d.ts +1 -0
- package/popover/index.js +224 -294
- package/progress/index.js +9 -28
- package/radio/index.js +103 -169
- package/radio/types.d.ts +1 -0
- package/radio-option/index.js +24 -48
- package/segment/index.js +50 -131
- package/segment-collapse/index.js +24 -49
- package/segment-collapse/types.d.ts +1 -0
- package/segmented-control/index.js +36 -73
- package/segmented-control/types.d.ts +1 -0
- package/segmented-control-option/index.js +41 -87
- package/segmented-icon-control/index.js +47 -84
- package/segmented-icon-control/types.d.ts +1 -0
- package/segmented-icon-control-option/index.js +38 -79
- package/select-button/index.d.ts +13 -0
- package/select-button/index.js +153 -0
- package/select-button/types.d.ts +43 -0
- package/select-menu/index.d.ts +11 -0
- package/select-menu/index.js +346 -0
- package/select-menu/types.d.ts +29 -0
- package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
- package/select-menu-option/index.js +76 -0
- package/{select-option → select-menu-option}/types.d.ts +8 -9
- package/stop-events/index.js +7 -20
- package/table-head-cell/index.js +7 -21
- package/tabs/index.js +103 -165
- package/tabs/types.d.ts +1 -0
- package/tabs-option/index.js +20 -44
- package/tag/index.d.ts +1 -1
- package/tag/index.js +42 -36
- package/tag/types.d.ts +13 -7
- package/textarea/index.js +92 -167
- package/theme.css +80 -49
- package/tile-control/index.js +55 -96
- package/tile-control-option/index.js +40 -86
- package/time-picker/index.js +224 -368
- package/time-picker/types.d.ts +5 -1
- package/title/index.js +6 -20
- package/toast/index.d.ts +17 -0
- package/toast/index.js +115 -0
- package/toast/types.d.ts +28 -0
- package/toast/utils.d.ts +5 -0
- package/toast/utils.js +6 -0
- package/toast-manager/index.d.ts +17 -0
- package/toast-manager/index.js +195 -0
- package/toast-manager/types.d.ts +7 -0
- package/toggle/index.js +55 -108
- package/toggle/types.d.ts +1 -0
- package/types.d.ts +7 -0
- package/utils/colors.d.ts +10 -0
- package/utils/colors.js +121 -0
- package/{utils.d.ts → utils/index.d.ts} +18 -9
- package/{utils.js → utils/index.js} +118 -39
- package/vertical-stepper/index.js +29 -50
- package/vertical-stepper-item/index.js +13 -37
- package/card-button/index.d.ts +0 -11
- package/card-button/index.js +0 -77
- package/card-button/types.d.ts +0 -12
- package/card-link/index.d.ts +0 -12
- package/card-link/index.js +0 -115
- package/card-link/types.d.ts +0 -14
- package/dropdown/index.d.ts +0 -12
- package/dropdown/index.js +0 -415
- package/dropdown/types.d.ts +0 -30
- package/dropdown-text-option/index.js +0 -104
- package/dropdown-text-option/types.d.ts +0 -16
- package/search/index.d.ts +0 -14
- package/search/index.js +0 -523
- package/search/types.d.ts +0 -25
- package/search-option/index.d.ts +0 -11
- package/search-option/index.js +0 -55
- package/search-option/types.d.ts +0 -9
- package/select/index.d.ts +0 -13
- package/select/index.js +0 -316
- package/select/types.d.ts +0 -53
- package/select-option/index.d.ts +0 -11
- package/select-option/index.js +0 -8
- package/tag/utils.d.ts +0 -2
- package/tag/utils.js +0 -1
- package/tag-close/index.d.ts +0 -12
- package/tag-close/index.js +0 -38
- package/tag-close/types.d.ts +0 -3
- package/tag-close/types.js +0 -1
- /package/{card-button → chip}/types.js +0 -0
- /package/{card-link → color-menu}/types.js +0 -0
- /package/{dropdown-text-option → color-swatch}/types.js +0 -0
- /package/{dropdown → select-button}/types.js +0 -0
- /package/{search → select-menu}/types.js +0 -0
- /package/{search-option → select-menu-option}/types.js +0 -0
- /package/{select → toast}/types.js +0 -0
- /package/{select-option → toast-manager}/types.js +0 -0
package/file-drop/index.js
CHANGED
|
@@ -1,186 +1,44 @@
|
|
|
1
|
-
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
-
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
-
|
|
4
|
-
var _$filePicker, _$dropArea, _$placeholder, _setDragEffect, _onDragEnter, _onDragLeave, _onDragOver, _onDrop, _onFilePickerChange, _onFilePickerInvalid, _onChangeReactHandler, _onInvalidReactHandler, _dispatchChangeEvent, _dispatchInvalidEvent;
|
|
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 '../text';
|
|
15
2
|
import '../file-picker';
|
|
16
3
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getIntegerAttribute, getReactEventHandler, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
17
|
-
const templateHTML = '<style>:host{display:block}#wrapper{position:relative;display:flex;flex-direction:row;flex-wrap:wrap;justify-content:center;align-content:center;gap:8px;height:148px;min-width:148px;box-sizing:border-box;padding:16px;border-radius:var(--sinch-shape-radius-m);background-color:var(--sinch-color-
|
|
4
|
+
const templateHTML = '<style>:host{display:block}#wrapper{position:relative;display:flex;flex-direction:row;flex-wrap:wrap;justify-content:center;align-content:center;gap:8px;height:148px;min-width:148px;box-sizing:border-box;padding:16px;border-radius:var(--sinch-shape-radius-m);background-color:var(--sinch-color-bg-primary-contrast)}#wrapper.drop.valid{background-color:var(--sinch-color-bg-comp-blue)}#wrapper::after{content:"";position:absolute;top:0;left:0;right:0;bottom:0;border:1px dashed var(--sinch-color-stormy-100);border-radius:var(--sinch-shape-radius-m);pointer-events:none}#placeholder{align-self:center;text-align:center}:host([invalid]) #wrapper::after{border-color:var(--sinch-color-text-invalid);border-width:1px}#wrapper.drop::after{pointer-events:all}#wrapper.drop.valid::after{border-color:var(--sinch-color-aqua-400);border-width:2px}#wrapper.drop #placeholder{color:var(--sinch-color-text-muted)}:host([disabled]) #wrapper #placeholder{color:var(--sinch-color-stormy-100)}:host([disabled]) #wrapper{background-color:var(--sinch-color-snow-100)}:host([disabled]) #wrapper::after{border-color:var(--sinch-color-stormy-100);border-width:1px}</style><div id="wrapper"><sinch-text id="placeholder" type="m" aria-hidden="true"></sinch-text><sinch-file-picker id="file-picker"><slot></slot></sinch-file-picker></div>';
|
|
18
5
|
import { areFilesAccepted, doFilesSatisfySize } from './utils';
|
|
19
6
|
const template = document.createElement('template');
|
|
20
7
|
template.innerHTML = templateHTML;
|
|
21
|
-
defineCustomElement('sinch-file-drop',
|
|
8
|
+
defineCustomElement('sinch-file-drop', class extends NectaryElement {
|
|
9
|
+
#$filePicker;
|
|
10
|
+
#$dropArea;
|
|
11
|
+
#$placeholder;
|
|
12
|
+
|
|
22
13
|
constructor() {
|
|
23
14
|
super();
|
|
24
|
-
|
|
25
|
-
_classPrivateMethodInitSpec(this, _dispatchInvalidEvent);
|
|
26
|
-
|
|
27
|
-
_classPrivateMethodInitSpec(this, _dispatchChangeEvent);
|
|
28
|
-
|
|
29
|
-
_classPrivateMethodInitSpec(this, _setDragEffect);
|
|
30
|
-
|
|
31
|
-
_classPrivateFieldInitSpec(this, _$filePicker, {
|
|
32
|
-
writable: true,
|
|
33
|
-
value: void 0
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
_classPrivateFieldInitSpec(this, _$dropArea, {
|
|
37
|
-
writable: true,
|
|
38
|
-
value: void 0
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
_classPrivateFieldInitSpec(this, _$placeholder, {
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
_classPrivateFieldInitSpec(this, _onDragEnter, {
|
|
47
|
-
writable: true,
|
|
48
|
-
value: e => {
|
|
49
|
-
e.stopPropagation();
|
|
50
|
-
e.preventDefault();
|
|
51
|
-
const hasTypes = e.dataTransfer?.types?.includes('Files') === true;
|
|
52
|
-
const hasItems = e.dataTransfer?.items != null && e.dataTransfer.items.length > 0;
|
|
53
|
-
|
|
54
|
-
_classPrivateMethodGet(this, _setDragEffect, _setDragEffect2).call(this, true, hasTypes || hasItems);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
_classPrivateFieldInitSpec(this, _onDragLeave, {
|
|
59
|
-
writable: true,
|
|
60
|
-
value: e => {
|
|
61
|
-
e.stopPropagation();
|
|
62
|
-
e.preventDefault();
|
|
63
|
-
|
|
64
|
-
_classPrivateMethodGet(this, _setDragEffect, _setDragEffect2).call(this, false);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
_classPrivateFieldInitSpec(this, _onDragOver, {
|
|
69
|
-
writable: true,
|
|
70
|
-
value: e => {
|
|
71
|
-
e.stopPropagation();
|
|
72
|
-
e.preventDefault();
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
_classPrivateFieldInitSpec(this, _onDrop, {
|
|
77
|
-
writable: true,
|
|
78
|
-
value: e => {
|
|
79
|
-
e.stopPropagation();
|
|
80
|
-
e.preventDefault();
|
|
81
|
-
|
|
82
|
-
_classPrivateMethodGet(this, _setDragEffect, _setDragEffect2).call(this, false);
|
|
83
|
-
|
|
84
|
-
if (this.disabled) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const dt = e.dataTransfer;
|
|
89
|
-
|
|
90
|
-
if (dt === null) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (dt.files.length === 0) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!this.multiple && dt.files.length > 1) {
|
|
99
|
-
_classPrivateMethodGet(this, _dispatchInvalidEvent, _dispatchInvalidEvent2).call(this, 'multiple');
|
|
100
|
-
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const files = Array.from(dt.files);
|
|
105
|
-
|
|
106
|
-
if (!areFilesAccepted(files, this.accept)) {
|
|
107
|
-
_classPrivateMethodGet(this, _dispatchInvalidEvent, _dispatchInvalidEvent2).call(this, 'accept');
|
|
108
|
-
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (!doFilesSatisfySize(files, this.size)) {
|
|
113
|
-
_classPrivateMethodGet(this, _dispatchInvalidEvent, _dispatchInvalidEvent2).call(this, 'size');
|
|
114
|
-
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
_classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, files);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
_classPrivateFieldInitSpec(this, _onFilePickerChange, {
|
|
123
|
-
writable: true,
|
|
124
|
-
value: e => {
|
|
125
|
-
_classPrivateMethodGet(this, _dispatchChangeEvent, _dispatchChangeEvent2).call(this, e.detail);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
_classPrivateFieldInitSpec(this, _onFilePickerInvalid, {
|
|
130
|
-
writable: true,
|
|
131
|
-
value: e => {
|
|
132
|
-
_classPrivateMethodGet(this, _dispatchInvalidEvent, _dispatchInvalidEvent2).call(this, e.detail);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
_classPrivateFieldInitSpec(this, _onChangeReactHandler, {
|
|
137
|
-
writable: true,
|
|
138
|
-
value: e => {
|
|
139
|
-
getReactEventHandler(this, 'on-change')?.(e);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
_classPrivateFieldInitSpec(this, _onInvalidReactHandler, {
|
|
144
|
-
writable: true,
|
|
145
|
-
value: e => {
|
|
146
|
-
getReactEventHandler(this, 'on-invalid')?.(e);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
|
|
150
15
|
const shadowRoot = this.attachShadow();
|
|
151
16
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
_classPrivateFieldSet(this, _$placeholder, shadowRoot.querySelector('#placeholder'));
|
|
156
|
-
|
|
157
|
-
_classPrivateFieldSet(this, _$filePicker, shadowRoot.querySelector('#file-picker'));
|
|
17
|
+
this.#$dropArea = shadowRoot.querySelector('#wrapper');
|
|
18
|
+
this.#$placeholder = shadowRoot.querySelector('#placeholder');
|
|
19
|
+
this.#$filePicker = shadowRoot.querySelector('#file-picker');
|
|
158
20
|
}
|
|
159
21
|
|
|
160
22
|
connectedCallback() {
|
|
161
|
-
this.addEventListener('-change',
|
|
162
|
-
this.addEventListener('-invalid',
|
|
163
|
-
this.addEventListener('dragenter',
|
|
164
|
-
this.addEventListener('dragleave',
|
|
165
|
-
this.addEventListener('dragover',
|
|
166
|
-
this.addEventListener('drop',
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
_classPrivateFieldGet(this, _$filePicker).addEventListener('-invalid', _classPrivateFieldGet(this, _onFilePickerInvalid));
|
|
23
|
+
this.addEventListener('-change', this.#onChangeReactHandler);
|
|
24
|
+
this.addEventListener('-invalid', this.#onInvalidReactHandler);
|
|
25
|
+
this.addEventListener('dragenter', this.#onDragEnter);
|
|
26
|
+
this.addEventListener('dragleave', this.#onDragLeave);
|
|
27
|
+
this.addEventListener('dragover', this.#onDragOver);
|
|
28
|
+
this.addEventListener('drop', this.#onDrop);
|
|
29
|
+
this.#$filePicker.addEventListener('-change', this.#onFilePickerChange);
|
|
30
|
+
this.#$filePicker.addEventListener('-invalid', this.#onFilePickerInvalid);
|
|
171
31
|
}
|
|
172
32
|
|
|
173
33
|
disconnectedCallback() {
|
|
174
|
-
this.removeEventListener('-change',
|
|
175
|
-
this.removeEventListener('-invalid',
|
|
176
|
-
this.removeEventListener('dragenter',
|
|
177
|
-
this.removeEventListener('dragleave',
|
|
178
|
-
this.removeEventListener('dragover',
|
|
179
|
-
this.removeEventListener('drop',
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
_classPrivateFieldGet(this, _$filePicker).removeEventListener('-invalid', _classPrivateFieldGet(this, _onFilePickerInvalid));
|
|
34
|
+
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
35
|
+
this.removeEventListener('-invalid', this.#onInvalidReactHandler);
|
|
36
|
+
this.removeEventListener('dragenter', this.#onDragEnter);
|
|
37
|
+
this.removeEventListener('dragleave', this.#onDragLeave);
|
|
38
|
+
this.removeEventListener('dragover', this.#onDragOver);
|
|
39
|
+
this.removeEventListener('drop', this.#onDrop);
|
|
40
|
+
this.#$filePicker.removeEventListener('-change', this.#onFilePickerChange);
|
|
41
|
+
this.#$filePicker.removeEventListener('-invalid', this.#onFilePickerInvalid);
|
|
184
42
|
}
|
|
185
43
|
|
|
186
44
|
static get observedAttributes() {
|
|
@@ -195,28 +53,26 @@ defineCustomElement('sinch-file-drop', (_$filePicker = new WeakMap(), _$dropArea
|
|
|
195
53
|
switch (name) {
|
|
196
54
|
case 'multiple':
|
|
197
55
|
{
|
|
198
|
-
updateAttribute(
|
|
56
|
+
updateAttribute(this.#$filePicker, 'multiple', newVal);
|
|
199
57
|
break;
|
|
200
58
|
}
|
|
201
59
|
|
|
202
60
|
case 'accept':
|
|
203
61
|
{
|
|
204
|
-
updateAttribute(
|
|
62
|
+
updateAttribute(this.#$filePicker, 'accept', newVal);
|
|
205
63
|
break;
|
|
206
64
|
}
|
|
207
65
|
|
|
208
66
|
case 'placeholder':
|
|
209
67
|
{
|
|
210
|
-
|
|
68
|
+
this.#$placeholder.textContent = newVal;
|
|
211
69
|
break;
|
|
212
70
|
}
|
|
213
71
|
|
|
214
72
|
case 'disabled':
|
|
215
73
|
{
|
|
216
74
|
updateBooleanAttribute(this, 'disabled', isAttrTrue(newVal));
|
|
217
|
-
|
|
218
|
-
_classPrivateMethodGet(this, _setDragEffect, _setDragEffect2).call(this, false);
|
|
219
|
-
|
|
75
|
+
this.#setDragEffect(false);
|
|
220
76
|
break;
|
|
221
77
|
}
|
|
222
78
|
|
|
@@ -228,7 +84,7 @@ defineCustomElement('sinch-file-drop', (_$filePicker = new WeakMap(), _$dropArea
|
|
|
228
84
|
|
|
229
85
|
case 'size':
|
|
230
86
|
{
|
|
231
|
-
updateAttribute(
|
|
87
|
+
updateAttribute(this.#$filePicker, 'size', newVal);
|
|
232
88
|
break;
|
|
233
89
|
}
|
|
234
90
|
}
|
|
@@ -247,7 +103,7 @@ defineCustomElement('sinch-file-drop', (_$filePicker = new WeakMap(), _$dropArea
|
|
|
247
103
|
}
|
|
248
104
|
|
|
249
105
|
get accept() {
|
|
250
|
-
return getAttribute(this, 'accept'
|
|
106
|
+
return getAttribute(this, 'accept');
|
|
251
107
|
}
|
|
252
108
|
|
|
253
109
|
get size() {
|
|
@@ -290,31 +146,98 @@ defineCustomElement('sinch-file-drop', (_$filePicker = new WeakMap(), _$dropArea
|
|
|
290
146
|
return getBooleanAttribute(this, 'invalid');
|
|
291
147
|
}
|
|
292
148
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
let isValid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
297
|
-
const isElementEnabled = !this.disabled;
|
|
149
|
+
#setDragEffect(shouldEnable) {
|
|
150
|
+
let isValid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
151
|
+
const isElementEnabled = !this.disabled;
|
|
298
152
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
153
|
+
if (shouldEnable) {
|
|
154
|
+
if (isElementEnabled) {
|
|
155
|
+
setClass(this.#$dropArea, 'drop', true);
|
|
156
|
+
setClass(this.#$dropArea, 'valid', isValid);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
setClass(this.#$dropArea, 'drop', false);
|
|
160
|
+
setClass(this.#$dropArea, 'valid', false);
|
|
303
161
|
}
|
|
304
|
-
} else {
|
|
305
|
-
setClass(_classPrivateFieldGet(this, _$dropArea), 'drop', false);
|
|
306
|
-
setClass(_classPrivateFieldGet(this, _$dropArea), 'valid', false);
|
|
307
162
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
163
|
+
|
|
164
|
+
#onDragEnter = e => {
|
|
165
|
+
e.stopPropagation();
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
const hasTypes = e.dataTransfer?.types?.includes('Files') === true;
|
|
168
|
+
const hasItems = e.dataTransfer?.items != null && e.dataTransfer.items.length > 0;
|
|
169
|
+
this.#setDragEffect(true, hasTypes || hasItems);
|
|
170
|
+
};
|
|
171
|
+
#onDragLeave = e => {
|
|
172
|
+
e.stopPropagation();
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
this.#setDragEffect(false);
|
|
175
|
+
};
|
|
176
|
+
#onDragOver = e => {
|
|
177
|
+
e.stopPropagation();
|
|
178
|
+
e.preventDefault();
|
|
179
|
+
};
|
|
180
|
+
#onDrop = e => {
|
|
181
|
+
e.stopPropagation();
|
|
182
|
+
e.preventDefault();
|
|
183
|
+
this.#setDragEffect(false);
|
|
184
|
+
|
|
185
|
+
if (this.disabled) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const dt = e.dataTransfer;
|
|
190
|
+
|
|
191
|
+
if (dt === null) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (dt.files.length === 0) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!this.multiple && dt.files.length > 1) {
|
|
200
|
+
this.#dispatchInvalidEvent('multiple');
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const files = Array.from(dt.files);
|
|
205
|
+
|
|
206
|
+
if (!areFilesAccepted(files, this.accept)) {
|
|
207
|
+
this.#dispatchInvalidEvent('accept');
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!doFilesSatisfySize(files, this.size)) {
|
|
212
|
+
this.#dispatchInvalidEvent('size');
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
this.#dispatchChangeEvent(files);
|
|
217
|
+
};
|
|
218
|
+
#onFilePickerChange = e => {
|
|
219
|
+
this.#dispatchChangeEvent(e.detail);
|
|
220
|
+
};
|
|
221
|
+
#onFilePickerInvalid = e => {
|
|
222
|
+
this.#dispatchInvalidEvent(e.detail);
|
|
223
|
+
};
|
|
224
|
+
#onChangeReactHandler = e => {
|
|
225
|
+
getReactEventHandler(this, 'on-change')?.(e);
|
|
226
|
+
};
|
|
227
|
+
#onInvalidReactHandler = e => {
|
|
228
|
+
getReactEventHandler(this, 'on-invalid')?.(e);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
#dispatchChangeEvent(files) {
|
|
232
|
+
this.dispatchEvent(new CustomEvent('-change', {
|
|
233
|
+
detail: files
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
#dispatchInvalidEvent(type) {
|
|
238
|
+
this.dispatchEvent(new CustomEvent('-invalid', {
|
|
239
|
+
detail: type
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
});
|
package/file-picker/index.d.ts
CHANGED
package/file-picker/index.js
CHANGED
|
@@ -1,122 +1,37 @@
|
|
|
1
|
-
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
-
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
-
|
|
4
|
-
var _$input, _$targetSlot, _$target, _onTargetSlotChange, _onTargetClick, _onInputChange, _onChangeReactHandler, _onInvalidReactHandler;
|
|
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
|
-
import '../dropdown';
|
|
11
1
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getFirstSlotElement, getIntegerAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
12
2
|
const templateHTML = '<style>:host{display:inline-block}::slotted(*){display:block}</style><slot></slot>';
|
|
13
3
|
import { doFilesSatisfySize } from './utils';
|
|
14
4
|
const template = document.createElement('template');
|
|
15
5
|
template.innerHTML = templateHTML;
|
|
16
|
-
defineCustomElement('sinch-file-picker',
|
|
6
|
+
defineCustomElement('sinch-file-picker', class extends NectaryElement {
|
|
7
|
+
#$input;
|
|
8
|
+
#$targetSlot;
|
|
9
|
+
#$target = null;
|
|
10
|
+
|
|
17
11
|
constructor() {
|
|
18
12
|
super();
|
|
19
|
-
|
|
20
|
-
_classPrivateFieldInitSpec(this, _$input, {
|
|
21
|
-
writable: true,
|
|
22
|
-
value: void 0
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
_classPrivateFieldInitSpec(this, _$targetSlot, {
|
|
26
|
-
writable: true,
|
|
27
|
-
value: void 0
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
_classPrivateFieldInitSpec(this, _$target, {
|
|
31
|
-
writable: true,
|
|
32
|
-
value: null
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
_classPrivateFieldInitSpec(this, _onTargetSlotChange, {
|
|
36
|
-
writable: true,
|
|
37
|
-
value: () => {
|
|
38
|
-
_classPrivateFieldGet(this, _$target)?.removeEventListener('-click', _classPrivateFieldGet(this, _onTargetClick));
|
|
39
|
-
|
|
40
|
-
_classPrivateFieldSet(this, _$target, getFirstSlotElement(_classPrivateFieldGet(this, _$targetSlot)));
|
|
41
|
-
|
|
42
|
-
_classPrivateFieldGet(this, _$target)?.addEventListener('-click', _classPrivateFieldGet(this, _onTargetClick));
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
_classPrivateFieldInitSpec(this, _onTargetClick, {
|
|
47
|
-
writable: true,
|
|
48
|
-
value: () => {
|
|
49
|
-
_classPrivateFieldGet(this, _$input).click();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
_classPrivateFieldInitSpec(this, _onInputChange, {
|
|
54
|
-
writable: true,
|
|
55
|
-
value: () => {
|
|
56
|
-
if (_classPrivateFieldGet(this, _$input).files === null) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const files = Array.from(_classPrivateFieldGet(this, _$input).files);
|
|
61
|
-
|
|
62
|
-
if (!doFilesSatisfySize(files, this.size)) {
|
|
63
|
-
this.dispatchEvent(new CustomEvent('-invalid', {
|
|
64
|
-
detail: 'size'
|
|
65
|
-
}));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this.dispatchEvent(new CustomEvent('-change', {
|
|
70
|
-
detail: files
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
_classPrivateFieldInitSpec(this, _onChangeReactHandler, {
|
|
76
|
-
writable: true,
|
|
77
|
-
value: e => {
|
|
78
|
-
getReactEventHandler(this, 'on-change')?.(e);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
_classPrivateFieldInitSpec(this, _onInvalidReactHandler, {
|
|
83
|
-
writable: true,
|
|
84
|
-
value: e => {
|
|
85
|
-
getReactEventHandler(this, 'on-invalid')?.(e);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
13
|
const shadowRoot = this.attachShadow();
|
|
90
14
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
_classPrivateFieldGet(this, _$input).type = 'file';
|
|
95
|
-
|
|
96
|
-
_classPrivateFieldSet(this, _$targetSlot, shadowRoot.querySelector('slot'));
|
|
15
|
+
this.#$input = document.createElement('input');
|
|
16
|
+
this.#$input.type = 'file';
|
|
17
|
+
this.#$targetSlot = shadowRoot.querySelector('slot');
|
|
97
18
|
}
|
|
98
19
|
|
|
99
20
|
connectedCallback() {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this
|
|
105
|
-
this.addEventListener('-invalid', _classPrivateFieldGet(this, _onInvalidReactHandler));
|
|
106
|
-
|
|
107
|
-
_classPrivateFieldGet(this, _onTargetSlotChange).call(this);
|
|
21
|
+
this.#$targetSlot.addEventListener('slotchange', this.#onTargetSlotChange);
|
|
22
|
+
this.#$input.addEventListener('change', this.#onInputChange);
|
|
23
|
+
this.addEventListener('-change', this.#onChangeReactHandler);
|
|
24
|
+
this.addEventListener('-invalid', this.#onInvalidReactHandler);
|
|
25
|
+
this.#onTargetSlotChange();
|
|
108
26
|
}
|
|
109
27
|
|
|
110
28
|
disconnectedCallback() {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this
|
|
116
|
-
this
|
|
117
|
-
_classPrivateFieldGet(this, _$target)?.removeEventListener('-click', _classPrivateFieldGet(this, _onTargetClick));
|
|
118
|
-
|
|
119
|
-
_classPrivateFieldSet(this, _$target, null);
|
|
29
|
+
this.#$targetSlot.removeEventListener('slotchange', this.#onTargetSlotChange);
|
|
30
|
+
this.#$input.removeEventListener('change', this.#onInputChange);
|
|
31
|
+
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
32
|
+
this.removeEventListener('-invalid', this.#onInvalidReactHandler);
|
|
33
|
+
this.#$target?.removeEventListener('-click', this.#onTargetClick);
|
|
34
|
+
this.#$target = null;
|
|
120
35
|
}
|
|
121
36
|
|
|
122
37
|
static get observedAttributes() {
|
|
@@ -136,7 +51,7 @@ defineCustomElement('sinch-file-picker', (_$input = new WeakMap(), _$targetSlot
|
|
|
136
51
|
}
|
|
137
52
|
|
|
138
53
|
get accept() {
|
|
139
|
-
return getAttribute(this, 'accept'
|
|
54
|
+
return getAttribute(this, 'accept');
|
|
140
55
|
}
|
|
141
56
|
|
|
142
57
|
get size() {
|
|
@@ -155,16 +70,48 @@ defineCustomElement('sinch-file-picker', (_$input = new WeakMap(), _$targetSlot
|
|
|
155
70
|
switch (name) {
|
|
156
71
|
case 'multiple':
|
|
157
72
|
{
|
|
158
|
-
updateBooleanAttribute(
|
|
73
|
+
updateBooleanAttribute(this.#$input, 'multiple', isAttrTrue(newVal));
|
|
159
74
|
break;
|
|
160
75
|
}
|
|
161
76
|
|
|
162
77
|
case 'accept':
|
|
163
78
|
{
|
|
164
|
-
updateAttribute(
|
|
79
|
+
updateAttribute(this.#$input, 'accept', newVal);
|
|
165
80
|
break;
|
|
166
81
|
}
|
|
167
82
|
}
|
|
168
83
|
}
|
|
169
84
|
|
|
170
|
-
|
|
85
|
+
#onTargetSlotChange = () => {
|
|
86
|
+
this.#$target?.removeEventListener('-click', this.#onTargetClick);
|
|
87
|
+
this.#$target = getFirstSlotElement(this.#$targetSlot);
|
|
88
|
+
this.#$target?.addEventListener('-click', this.#onTargetClick);
|
|
89
|
+
};
|
|
90
|
+
#onTargetClick = () => {
|
|
91
|
+
this.#$input.click();
|
|
92
|
+
};
|
|
93
|
+
#onInputChange = () => {
|
|
94
|
+
if (this.#$input.files === null) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const files = Array.from(this.#$input.files);
|
|
99
|
+
|
|
100
|
+
if (!doFilesSatisfySize(files, this.size)) {
|
|
101
|
+
this.dispatchEvent(new CustomEvent('-invalid', {
|
|
102
|
+
detail: 'size'
|
|
103
|
+
}));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.dispatchEvent(new CustomEvent('-change', {
|
|
108
|
+
detail: files
|
|
109
|
+
}));
|
|
110
|
+
};
|
|
111
|
+
#onChangeReactHandler = e => {
|
|
112
|
+
getReactEventHandler(this, 'on-change')?.(e);
|
|
113
|
+
};
|
|
114
|
+
#onInvalidReactHandler = e => {
|
|
115
|
+
getReactEventHandler(this, 'on-invalid')?.(e);
|
|
116
|
+
};
|
|
117
|
+
});
|