@nectary/components 4.1.4 → 4.2.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/button/index.js CHANGED
@@ -159,8 +159,11 @@ defineCustomElement('sinch-button', class extends NectaryElement {
159
159
  }
160
160
  }
161
161
  };
162
- #onButtonClick = () => {
163
- if (!this.disabled) {
162
+ #onButtonClick = e => {
163
+ if (this.disabled) {
164
+ e.stopPropagation();
165
+ e.preventDefault();
166
+ } else {
164
167
  this.dispatchEvent(new CustomEvent('-click'));
165
168
  }
166
169
  };
@@ -1,8 +1,8 @@
1
1
  import '../text';
2
2
  import '../file-picker';
3
3
  import { defineCustomElement, getAttribute, getBooleanAttribute, getIntegerAttribute, getReactEventHandler, isAttrEqual, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute } from '../utils';
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-comp-file-drop-shape-radius);background-color:var(--sinch-comp-file-drop-color-default-background-initial)}#wrapper::after{content:"";position:absolute;top:0;left:0;right:0;bottom:0;border:1px dashed var(--sinch-comp-file-drop-color-default-border-initial);border-radius:var(--sinch-comp-file-drop-shape-radius);pointer-events:none}#placeholder{align-self:center;text-align:center;--sinch-global-color-text:var(--sinch-comp-file-drop-color-default-placeholder-initial);--sinch-comp-text-font:var(--sinch-comp-file-drop-font-placeholder)}:host([invalid]) #wrapper{background-color:var(--sinch-comp-file-drop-color-invalid-background-initial)}:host([invalid]) #wrapper::after{border-color:var(--sinch-comp-file-drop-color-invalid-border-initial);border-width:1px}#wrapper.drop::after{pointer-events:all}#wrapper.drop.valid{background-color:var(--sinch-comp-file-drop-color-default-background-active)}#wrapper.drop.valid::after{border-color:var(--sinch-comp-file-drop-color-default-border-active);border-width:2px}#wrapper.drop.valid>#placeholder{--sinch-global-color-text:var(--sinch-comp-file-drop-color-default-placeholder-active)}:host([disabled])>#wrapper>#placeholder{--sinch-global-color-text:var(--sinch-comp-file-drop-color-disabled-placeholder-initial)}:host([disabled])>#wrapper{background-color:var(--sinch-comp-file-drop-color-disabled-background-initial)}:host([disabled])>#wrapper::after{border-color:var(--sinch-comp-file-drop-color-disabled-border-initial);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>';
5
- import { areFilesAccepted, doFilesSatisfySize } from './utils';
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-comp-file-drop-shape-radius);background-color:var(--sinch-comp-file-drop-color-default-background-initial)}#wrapper::after{content:"";position:absolute;top:0;left:0;right:0;bottom:0;border:1px dashed var(--sinch-comp-file-drop-color-default-border-initial);border-radius:var(--sinch-comp-file-drop-shape-radius);pointer-events:none}#placeholder{align-self:center;text-align:center;--sinch-global-color-text:var(--sinch-comp-file-drop-color-default-placeholder-initial);--sinch-comp-text-font:var(--sinch-comp-file-drop-font-placeholder)}:host([invalid]) #wrapper{background-color:var(--sinch-comp-file-drop-color-invalid-background-initial)}:host([invalid]) #wrapper::after{border-color:var(--sinch-comp-file-drop-color-invalid-border-initial);border-width:1px}#wrapper.drop::after{pointer-events:all}#wrapper.drop.valid{background-color:var(--sinch-comp-file-drop-color-default-background-active)}#wrapper.drop.valid::after{border-color:var(--sinch-comp-file-drop-color-default-border-active);border-width:2px}#wrapper.drop.valid>#placeholder{--sinch-global-color-text:var(--sinch-comp-file-drop-color-default-placeholder-active)}#wrapper.drop.invalid{background-color:var(--sinch-comp-file-drop-color-invalid-background-active)}#wrapper.drop.invalid::after{border-color:var(--sinch-comp-file-drop-color-invalid-border-active);border-width:2px}#wrapper.drop.invalid>#placeholder{--sinch-global-color-text:var(--sinch-comp-file-drop-color-invalid-placeholder-active)}:host([disabled])>#wrapper>#placeholder{--sinch-global-color-text:var(--sinch-comp-file-drop-color-disabled-placeholder-initial)}:host([disabled])>#wrapper{background-color:var(--sinch-comp-file-drop-color-disabled-background-initial)}:host([disabled])>#wrapper::after{border-color:var(--sinch-comp-file-drop-color-disabled-border-initial);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>';
5
+ import { areFilesAccepted, areItemsAccepted, doFilesSatisfySize } from './utils';
6
6
  const template = document.createElement('template');
7
7
  template.innerHTML = templateHTML;
8
8
  defineCustomElement('sinch-file-drop', class extends NectaryElement {
@@ -129,18 +129,24 @@ defineCustomElement('sinch-file-drop', class extends NectaryElement {
129
129
  if (isElementEnabled) {
130
130
  setClass(this.#$dropArea, 'drop', true);
131
131
  setClass(this.#$dropArea, 'valid', isValid);
132
+ setClass(this.#$dropArea, 'invalid', !isValid);
132
133
  }
133
134
  } else {
134
135
  setClass(this.#$dropArea, 'drop', false);
135
136
  setClass(this.#$dropArea, 'valid', false);
137
+ setClass(this.#$dropArea, 'invalid', false);
136
138
  }
137
139
  }
138
140
  #onDragEnter = e => {
139
141
  e.stopPropagation();
140
142
  e.preventDefault();
141
- const hasTypes = e.dataTransfer?.types?.includes('Files') === true;
142
- const hasItems = e.dataTransfer?.items != null && e.dataTransfer.items.length > 0;
143
- this.#setDragEffect(true, hasTypes || hasItems);
143
+ const items = e.dataTransfer?.items;
144
+ let isValidItems = false;
145
+ if (items != null && items.length > 0) {
146
+ const itemsArray = Array.from(items);
147
+ isValidItems = areItemsAccepted(itemsArray, this.accept);
148
+ }
149
+ this.#setDragEffect(true, isValidItems);
144
150
  };
145
151
  #onDragLeave = e => {
146
152
  e.stopPropagation();
@@ -1,2 +1,3 @@
1
1
  export declare const areFilesAccepted: (files: File[], accept: string | null) => boolean;
2
+ export declare const areItemsAccepted: (item: DataTransferItem[], accept: string | null) => boolean;
2
3
  export declare const doFilesSatisfySize: (files: File[], size: number | null) => boolean;
@@ -21,6 +21,26 @@ export const areFilesAccepted = (files, accept) => {
21
21
  });
22
22
  });
23
23
  };
24
+ export const areItemsAccepted = (item, accept) => {
25
+ if (accept === null) {
26
+ return true;
27
+ }
28
+ const acceptValues = accept.split(/\s*,\s*/);
29
+ return item.every(file => {
30
+ return acceptValues.some(acceptValue => {
31
+ if (acceptValue === 'image/*') {
32
+ return file.type.startsWith('image/');
33
+ }
34
+ if (acceptValue === 'video/*') {
35
+ return file.type.startsWith('video/');
36
+ }
37
+ if (acceptValue === 'audio/*') {
38
+ return file.type.startsWith('audio/');
39
+ }
40
+ return acceptValue === file.type;
41
+ });
42
+ });
43
+ };
24
44
  export const doFilesSatisfySize = (files, size) => {
25
45
  if (size === null || size <= 0) {
26
46
  return true;
@@ -1,4 +1,4 @@
1
- import { defineCustomElement, getAttribute, getBooleanAttribute, getFirstSlotElement, getIntegerAttribute, getReactEventHandler, isAttrEqual, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
1
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getIntegerAttribute, getReactEventHandler, isAttrEqual, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
2
2
  const templateHTML = '<style>:host{display:inline-block}::slotted(*){display:block}</style><slot></slot>';
3
3
  import { doFilesSatisfySize } from './utils';
4
4
  const template = document.createElement('template');
@@ -6,7 +6,6 @@ template.innerHTML = templateHTML;
6
6
  defineCustomElement('sinch-file-picker', class extends NectaryElement {
7
7
  #$input;
8
8
  #$targetSlot;
9
- #$target = null;
10
9
  #controller = null;
11
10
  constructor() {
12
11
  super();
@@ -30,7 +29,6 @@ defineCustomElement('sinch-file-picker', class extends NectaryElement {
30
29
  disconnectedCallback() {
31
30
  this.#controller.abort();
32
31
  this.#controller = null;
33
- this.#$target = null;
34
32
  }
35
33
  static get observedAttributes() {
36
34
  return ['accept', 'multiple'];
@@ -71,9 +69,8 @@ defineCustomElement('sinch-file-picker', class extends NectaryElement {
71
69
  updateAttribute(this, 'size', value);
72
70
  }
73
71
  #onTargetSlotChange = () => {
74
- this.#$target?.removeEventListener('-click', this.#onTargetClick);
75
- this.#$target = getFirstSlotElement(this.#$targetSlot, true);
76
- this.#$target?.addEventListener('-click', this.#onTargetClick);
72
+ this.#$targetSlot.removeEventListener('click', this.#onTargetClick);
73
+ this.#$targetSlot.addEventListener('click', this.#onTargetClick);
77
74
  };
78
75
  #onTargetClick = () => {
79
76
  this.#$input.click();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "4.1.4",
3
+ "version": "4.2.0",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",