@nectary/components 0.43.0 → 0.44.1

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.
@@ -44,7 +44,7 @@ export declare type TSinchFileDropReact = TSinchElementReact<TSinchFileDropEleme
44
44
  /** Placeholder */
45
45
  placeholder: string;
46
46
  /** Change value handler */
47
- 'on-change'?: (e: CustomEvent<File[]>) => void;
47
+ 'on-change': (e: CustomEvent<File[]>) => void;
48
48
  /** Invalid handler */
49
- 'on-invalid'?: (e: CustomEvent<TSinchFileDropInvalidType>) => void;
49
+ 'on-invalid': (e: CustomEvent<TSinchFileDropInvalidType>) => void;
50
50
  };
@@ -28,5 +28,5 @@ export declare type TSinchFilePickerReact = TSinchElementReact<TSinchFilePickerE
28
28
  /** Change value handler */
29
29
  'on-change': (e: CustomEvent<File[]>) => void;
30
30
  /** Invalid handler */
31
- 'on-invalid'?: (e: CustomEvent<TSinchFilePickerInvalidType>) => void;
31
+ 'on-invalid': (e: CustomEvent<TSinchFilePickerInvalidType>) => void;
32
32
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "0.43.0",
3
+ "version": "0.44.1",
4
4
  "files": [
5
- "theme.css",
6
- "theme/*.css",
7
- "theme/*.json",
5
+ "**/*/*.css",
6
+ "**/*/*.json",
8
7
  "**/*/*.js",
9
8
  "**/*/*.d.ts",
9
+ "theme.css",
10
10
  "types.d.ts",
11
11
  "colors.json"
12
12
  ],
@@ -1,4 +1,4 @@
1
- import { defineCustomElement, getAttribute, getBooleanAttribute, getCsvSet, getFirstCsvValue, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv } from '../utils';
1
+ import { defineCustomElement, getAttribute, getBooleanAttribute, unpackCsv, getFirstCsvValue, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv } from '../utils';
2
2
  const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:row}</style><div id="wrapper"><slot></slot></div>';
3
3
  const template = document.createElement('template');
4
4
  template.innerHTML = templateHTML;
@@ -69,9 +69,9 @@ defineCustomElement('sinch-segmented-icon-control', class extends NectaryElement
69
69
  };
70
70
  #onValueChange(csv) {
71
71
  if (this.multiple) {
72
- const values = getCsvSet(csv);
72
+ const values = unpackCsv(csv);
73
73
  for (const $option of this.#$slot.assignedElements()) {
74
- const isChecked = !getBooleanAttribute($option, 'disabled') && values.has(getAttribute($option, 'value', ''));
74
+ const isChecked = !getBooleanAttribute($option, 'disabled') && values.includes(getAttribute($option, 'value', ''));
75
75
  updateBooleanAttribute($option, 'data-checked', isChecked);
76
76
  }
77
77
  } else {
@@ -1,4 +1,4 @@
1
- import { attrValueToPixels, defineCustomElement, dispatchContextConnectEvent, dispatchContextDisconnectEvent, getAttribute, getBooleanAttribute, getCsvSet, getFirstCsvValue, getIntegerAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv, updateExplicitBooleanAttribute, updateIntegerAttribute } from '../utils';
1
+ import { attrValueToPixels, defineCustomElement, dispatchContextConnectEvent, dispatchContextDisconnectEvent, getAttribute, getBooleanAttribute, unpackCsv, getFirstCsvValue, getIntegerAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv, updateExplicitBooleanAttribute, updateIntegerAttribute } from '../utils';
2
2
  const templateHTML = '<style>:host{display:block;outline:0}#listbox{overflow-y:auto}</style><div id="listbox" role="presentation"><slot></slot></div>';
3
3
  const ITEM_HEIGHT = 40;
4
4
  const template = document.createElement('template');
@@ -159,9 +159,9 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
159
159
  };
160
160
  #onValueChange(csv) {
161
161
  if (this.multiple) {
162
- const values = getCsvSet(csv);
162
+ const values = unpackCsv(csv);
163
163
  for (const $option of this.#getOptionElements()) {
164
- const isChecked = !getBooleanAttribute($option, 'disabled') && values.has(getAttribute($option, 'value', ''));
164
+ const isChecked = !getBooleanAttribute($option, 'disabled') && values.includes(getAttribute($option, 'value', ''));
165
165
  updateBooleanAttribute($option, 'data-checked', isChecked);
166
166
  }
167
167
  } else {
@@ -1,17 +1,17 @@
1
- import { defineCustomElement, getCsvSet } from '../utils';
1
+ import { defineCustomElement, unpackCsv } from '../utils';
2
2
  defineCustomElement('sinch-stop-events', class extends HTMLElement {
3
3
  constructor() {
4
4
  super();
5
5
  this.style.display = 'contents';
6
6
  }
7
7
  connectedCallback() {
8
- const events = getCsvSet(this.getAttribute('events'));
8
+ const events = unpackCsv(this.getAttribute('events'));
9
9
  for (const event of events) {
10
10
  this.addEventListener(event, this.#stopEvent);
11
11
  }
12
12
  }
13
13
  disconnectedCallback() {
14
- const events = getCsvSet(this.getAttribute('events'));
14
+ const events = unpackCsv(this.getAttribute('events'));
15
15
  for (const event of events) {
16
16
  this.removeEventListener(event, this.#stopEvent);
17
17
  }
@@ -1,4 +1,4 @@
1
- import { defineCustomElement, getAttribute, getBooleanAttribute, getCsvSet, getFirstCsvValue, getIntegerAttribute, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv, updateIntegerAttribute } from '../utils';
1
+ import { defineCustomElement, getAttribute, getBooleanAttribute, unpackCsv, getFirstCsvValue, getIntegerAttribute, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv, updateIntegerAttribute } from '../utils';
2
2
  const templateHTML = '<style>:host{display:block;outline:0;--sinch-grid-num-columns:1}#wrapper{display:grid;grid-template-columns:repeat(var(--sinch-grid-num-columns),auto);gap:16px;width:fit-content}:host([small]:not([small=false])) #wrapper{gap:8px}:host([cols="2"]){--sinch-grid-num-columns:2}:host([cols="3"]){--sinch-grid-num-columns:3}:host([cols="4"]){--sinch-grid-num-columns:4}:host([cols="5"]){--sinch-grid-num-columns:5}:host([cols="6"]){--sinch-grid-num-columns:6}:host([cols="7"]){--sinch-grid-num-columns:7}:host([cols="8"]){--sinch-grid-num-columns:8}</style><div id="wrapper"><slot></slot></div>';
3
3
  const template = document.createElement('template');
4
4
  template.innerHTML = templateHTML;
@@ -91,9 +91,9 @@ defineCustomElement('sinch-tile-control', class extends NectaryElement {
91
91
  };
92
92
  #onValueChange(csv) {
93
93
  if (this.multiple) {
94
- const values = getCsvSet(csv);
94
+ const values = unpackCsv(csv);
95
95
  for (const $option of this.#$slot.assignedElements()) {
96
- const isChecked = !getBooleanAttribute($option, 'disabled') && values.has(getAttribute($option, 'value', ''));
96
+ const isChecked = !getBooleanAttribute($option, 'disabled') && values.includes(getAttribute($option, 'value', ''));
97
97
  updateBooleanAttribute($option, 'data-checked', isChecked);
98
98
  }
99
99
  } else {
package/utils/csv.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- export declare const getCsvSet: (acc: string) => Set<string>;
2
- export declare const updateCsv: (acc: string, value: string, setActive: boolean) => string;
1
+ export declare const CSV_DELIMITER = ",";
2
+ export declare const packCsv: (values: string[]) => string;
3
+ export declare const unpackCsv: (csv: string) => string[];
4
+ export declare const updateCsv: (csv: string, value: string, setActive: boolean) => string;
3
5
  export declare const getFirstCsvValue: (acc: string) => string | null;
package/utils/csv.js CHANGED
@@ -1,21 +1,22 @@
1
- const unpackCsv = csv => {
2
- return csv === '' ? [] : csv.split(',');
1
+ export const CSV_DELIMITER = ',';
2
+ export const packCsv = values => {
3
+ return values.join(CSV_DELIMITER);
3
4
  };
4
- const packCsv = values => {
5
- return Array.from(values).join(',');
5
+ export const unpackCsv = csv => {
6
+ return csv.length === 0 ? [] : csv.split(CSV_DELIMITER);
6
7
  };
7
- export const getCsvSet = acc => {
8
- return new Set(unpackCsv(acc));
9
- };
10
- export const updateCsv = (acc, value, setActive) => {
11
- const values = getCsvSet(acc);
8
+ export const updateCsv = (csv, value, setActive) => {
9
+ const values = unpackCsv(csv);
10
+ const index = values.indexOf(value);
12
11
  if (setActive) {
13
- values.add(value);
14
- } else {
15
- values.delete(value);
12
+ if (index < 0) {
13
+ values.push(value);
14
+ }
15
+ } else if (index >= 0) {
16
+ values.splice(index, 1);
16
17
  }
17
18
  return packCsv(values);
18
19
  };
19
20
  export const getFirstCsvValue = acc => {
20
- return acc === '' ? null : unpackCsv(acc)[0];
21
+ return acc.length === 0 ? null : unpackCsv(acc)[0];
21
22
  };