@nectary/components 0.39.0 → 0.41.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 (142) hide show
  1. package/accordion/index.js +47 -84
  2. package/accordion-item/index.js +30 -53
  3. package/action-menu/index.d.ts +0 -1
  4. package/action-menu/index.js +177 -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 +52 -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 +46 -92
  16. package/button/types.d.ts +1 -1
  17. package/card/index.js +21 -59
  18. package/chat-avatar/index.js +8 -22
  19. package/chat-block/index.js +29 -69
  20. package/chat-bubble/index.js +6 -20
  21. package/checkbox/index.js +59 -107
  22. package/chip/index.d.ts +13 -0
  23. package/chip/index.js +140 -0
  24. package/chip/types.d.ts +37 -0
  25. package/color-menu/index.d.ts +14 -0
  26. package/color-menu/index.js +450 -0
  27. package/color-menu/types.d.ts +36 -0
  28. package/color-menu/utils.d.ts +1 -0
  29. package/color-menu/utils.js +15 -0
  30. package/color-swatch/index.d.ts +13 -0
  31. package/color-swatch/index.js +60 -0
  32. package/color-swatch/types.d.ts +11 -0
  33. package/colors.json +61 -49
  34. package/date-picker/index.js +162 -293
  35. package/dialog/index.js +70 -142
  36. package/field/index.js +44 -65
  37. package/file-drop/index.js +123 -200
  38. package/file-picker/index.d.ts +0 -1
  39. package/file-picker/index.js +55 -108
  40. package/file-status/index.js +15 -39
  41. package/help-tooltip/index.js +11 -28
  42. package/horizontal-stepper/index.js +33 -59
  43. package/horizontal-stepper-item/index.js +13 -37
  44. package/icon-button/index.d.ts +1 -0
  45. package/icon-button/index.js +51 -85
  46. package/icon-button/types.d.ts +16 -2
  47. package/icons-channel/notify/index.d.ts +11 -0
  48. package/icons-channel/notify/index.js +4 -0
  49. package/illustrations/create-illustration-class.js +1 -1
  50. package/inline-alert/index.js +29 -81
  51. package/input/index.js +117 -222
  52. package/link/index.js +51 -97
  53. package/list-item/index.js +1 -1
  54. package/package.json +12 -14
  55. package/pagination/index.js +113 -163
  56. package/pop/index.d.ts +11 -0
  57. package/pop/index.js +391 -0
  58. package/pop/types.d.ts +35 -0
  59. package/pop/utils.d.ts +7 -0
  60. package/pop/utils.js +18 -0
  61. package/popover/index.d.ts +1 -0
  62. package/popover/index.js +105 -314
  63. package/popover/types.d.ts +8 -1
  64. package/popover/utils.d.ts +5 -0
  65. package/popover/utils.js +17 -1
  66. package/progress/index.js +9 -28
  67. package/radio/index.js +103 -169
  68. package/radio-option/index.js +28 -48
  69. package/segment/index.js +49 -130
  70. package/segment-collapse/index.js +28 -49
  71. package/segmented-control/index.js +36 -73
  72. package/segmented-control-option/index.js +45 -87
  73. package/segmented-icon-control/index.js +47 -84
  74. package/segmented-icon-control-option/index.js +42 -79
  75. package/select-button/index.d.ts +13 -0
  76. package/select-button/index.js +158 -0
  77. package/select-button/types.d.ts +43 -0
  78. package/select-menu/index.d.ts +11 -0
  79. package/select-menu/index.js +345 -0
  80. package/select-menu/types.d.ts +29 -0
  81. package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
  82. package/select-menu-option/index.js +76 -0
  83. package/{select-option → select-menu-option}/types.d.ts +8 -9
  84. package/stop-events/index.js +7 -20
  85. package/table-head-cell/index.js +7 -21
  86. package/tabs/index.js +103 -165
  87. package/tabs-option/index.js +24 -44
  88. package/tag/index.d.ts +0 -1
  89. package/tag/index.js +35 -38
  90. package/tag/types.d.ts +12 -7
  91. package/textarea/index.js +96 -167
  92. package/theme.css +146 -49
  93. package/tile-control/index.js +55 -96
  94. package/tile-control-option/index.js +45 -87
  95. package/time-picker/index.js +216 -368
  96. package/title/index.js +6 -20
  97. package/toast/index.js +32 -70
  98. package/toast-manager/index.js +141 -217
  99. package/toggle/index.js +59 -107
  100. package/tooltip/index.d.ts +2 -0
  101. package/tooltip/index.js +160 -17
  102. package/tooltip/types.d.ts +13 -0
  103. package/tooltip/utils.d.ts +5 -0
  104. package/tooltip/utils.js +25 -1
  105. package/utils/animation.d.ts +17 -0
  106. package/utils/animation.js +142 -0
  107. package/utils/colors.d.ts +5 -0
  108. package/utils/colors.js +5 -0
  109. package/utils/context.d.ts +15 -0
  110. package/utils/context.js +57 -0
  111. package/{utils.d.ts → utils/index.d.ts} +15 -11
  112. package/{utils.js → utils/index.js} +104 -48
  113. package/vertical-stepper/index.js +29 -50
  114. package/vertical-stepper-item/index.js +13 -37
  115. package/dropdown/index.d.ts +0 -12
  116. package/dropdown/index.js +0 -415
  117. package/dropdown/types.d.ts +0 -32
  118. package/dropdown-checkbox-option/index.d.ts +0 -11
  119. package/dropdown-checkbox-option/index.js +0 -88
  120. package/dropdown-checkbox-option/types.d.ts +0 -15
  121. package/dropdown-radio-option/index.d.ts +0 -11
  122. package/dropdown-radio-option/index.js +0 -88
  123. package/dropdown-radio-option/types.d.ts +0 -15
  124. package/dropdown-text-option/index.js +0 -104
  125. package/dropdown-text-option/types.d.ts +0 -16
  126. package/select/index.d.ts +0 -13
  127. package/select/index.js +0 -316
  128. package/select/types.d.ts +0 -53
  129. package/select-option/index.d.ts +0 -11
  130. package/select-option/index.js +0 -8
  131. package/tag/utils.d.ts +0 -5
  132. package/tag/utils.js +0 -6
  133. package/tag-close/index.d.ts +0 -12
  134. package/tag-close/index.js +0 -42
  135. package/tag-close/types.d.ts +0 -5
  136. /package/{dropdown-checkbox-option → chip}/types.js +0 -0
  137. /package/{dropdown-radio-option → color-menu}/types.js +0 -0
  138. /package/{dropdown-text-option → color-swatch}/types.js +0 -0
  139. /package/{dropdown → pop}/types.js +0 -0
  140. /package/{select-option → select-button}/types.js +0 -0
  141. /package/{tag-close → select-menu}/types.js +0 -0
  142. /package/{select → select-menu-option}/types.js +0 -0
@@ -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-background-grey)}#wrapper.drop.valid{background-color:var(--sinch-color-background-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>';
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-border-focus);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', (_$filePicker = new WeakMap(), _$dropArea = new WeakMap(), _$placeholder = new WeakMap(), _setDragEffect = new WeakSet(), _onDragEnter = new WeakMap(), _onDragLeave = new WeakMap(), _onDragOver = new WeakMap(), _onDrop = new WeakMap(), _onFilePickerChange = new WeakMap(), _onFilePickerInvalid = new WeakMap(), _onChangeReactHandler = new WeakMap(), _onInvalidReactHandler = new WeakMap(), _dispatchChangeEvent = new WeakSet(), _dispatchInvalidEvent = new WeakSet(), class extends NectaryElement {
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
- _classPrivateFieldSet(this, _$dropArea, shadowRoot.querySelector('#wrapper'));
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', _classPrivateFieldGet(this, _onChangeReactHandler));
162
- this.addEventListener('-invalid', _classPrivateFieldGet(this, _onInvalidReactHandler));
163
- this.addEventListener('dragenter', _classPrivateFieldGet(this, _onDragEnter));
164
- this.addEventListener('dragleave', _classPrivateFieldGet(this, _onDragLeave));
165
- this.addEventListener('dragover', _classPrivateFieldGet(this, _onDragOver));
166
- this.addEventListener('drop', _classPrivateFieldGet(this, _onDrop));
167
-
168
- _classPrivateFieldGet(this, _$filePicker).addEventListener('-change', _classPrivateFieldGet(this, _onFilePickerChange));
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', _classPrivateFieldGet(this, _onChangeReactHandler));
175
- this.removeEventListener('-invalid', _classPrivateFieldGet(this, _onInvalidReactHandler));
176
- this.removeEventListener('dragenter', _classPrivateFieldGet(this, _onDragEnter));
177
- this.removeEventListener('dragleave', _classPrivateFieldGet(this, _onDragLeave));
178
- this.removeEventListener('dragover', _classPrivateFieldGet(this, _onDragOver));
179
- this.removeEventListener('drop', _classPrivateFieldGet(this, _onDrop));
180
-
181
- _classPrivateFieldGet(this, _$filePicker).removeEventListener('-change', _classPrivateFieldGet(this, _onFilePickerChange));
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(_classPrivateFieldGet(this, _$filePicker), 'multiple', newVal);
56
+ updateAttribute(this.#$filePicker, 'multiple', newVal);
199
57
  break;
200
58
  }
201
59
 
202
60
  case 'accept':
203
61
  {
204
- updateAttribute(_classPrivateFieldGet(this, _$filePicker), 'accept', newVal);
62
+ updateAttribute(this.#$filePicker, 'accept', newVal);
205
63
  break;
206
64
  }
207
65
 
208
66
  case 'placeholder':
209
67
  {
210
- _classPrivateFieldGet(this, _$placeholder).textContent = newVal;
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(_classPrivateFieldGet(this, _$filePicker), 'size', newVal);
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', null);
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
- function _setDragEffect2(shouldEnable) {
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
- if (shouldEnable) {
300
- if (isElementEnabled) {
301
- setClass(_classPrivateFieldGet(this, _$dropArea), 'drop', true);
302
- setClass(_classPrivateFieldGet(this, _$dropArea), 'valid', isValid);
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
- function _dispatchChangeEvent2(files) {
311
- this.dispatchEvent(new CustomEvent('-change', {
312
- detail: files
313
- }));
314
- }
315
-
316
- function _dispatchInvalidEvent2(type) {
317
- this.dispatchEvent(new CustomEvent('-invalid', {
318
- detail: type
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
+ });
@@ -1,4 +1,3 @@
1
- import '../dropdown';
2
1
  import type { TSinchFilePickerElement, TSinchFilePickerReact } from './types';
3
2
  declare global {
4
3
  namespace JSX {
@@ -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', (_$input = new WeakMap(), _$targetSlot = new WeakMap(), _$target = new WeakMap(), _onTargetSlotChange = new WeakMap(), _onTargetClick = new WeakMap(), _onInputChange = new WeakMap(), _onChangeReactHandler = new WeakMap(), _onInvalidReactHandler = new WeakMap(), class extends NectaryElement {
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
- _classPrivateFieldSet(this, _$input, document.createElement('input'));
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
- _classPrivateFieldGet(this, _$targetSlot).addEventListener('slotchange', _classPrivateFieldGet(this, _onTargetSlotChange));
101
-
102
- _classPrivateFieldGet(this, _$input).addEventListener('change', _classPrivateFieldGet(this, _onInputChange));
103
-
104
- this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
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
- _classPrivateFieldGet(this, _$targetSlot).removeEventListener('slotchange', _classPrivateFieldGet(this, _onTargetSlotChange));
112
-
113
- _classPrivateFieldGet(this, _$input).removeEventListener('change', _classPrivateFieldGet(this, _onInputChange));
114
-
115
- this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
116
- this.removeEventListener('-invalid', _classPrivateFieldGet(this, _onInvalidReactHandler));
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', null);
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(_classPrivateFieldGet(this, _$input), 'multiple', isAttrTrue(newVal));
73
+ updateBooleanAttribute(this.#$input, 'multiple', isAttrTrue(newVal));
159
74
  break;
160
75
  }
161
76
 
162
77
  case 'accept':
163
78
  {
164
- updateAttribute(_classPrivateFieldGet(this, _$input), 'accept', newVal);
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, true);
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
+ });