@nectary/components 0.39.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.
Files changed (115) hide show
  1. package/accordion/index.js +47 -84
  2. package/accordion-item/index.js +26 -53
  3. package/action-menu/index.d.ts +0 -1
  4. package/action-menu/index.js +179 -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 +51 -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 +42 -92
  16. package/card/index.js +21 -59
  17. package/chat-avatar/index.js +8 -22
  18. package/chat-block/index.js +29 -69
  19. package/chat-bubble/index.js +6 -20
  20. package/checkbox/index.js +55 -107
  21. package/chip/index.d.ts +13 -0
  22. package/chip/index.js +137 -0
  23. package/chip/types.d.ts +38 -0
  24. package/color-menu/index.d.ts +13 -0
  25. package/color-menu/index.js +464 -0
  26. package/color-menu/types.d.ts +37 -0
  27. package/color-swatch/index.d.ts +13 -0
  28. package/color-swatch/index.js +59 -0
  29. package/color-swatch/types.d.ts +12 -0
  30. package/colors.json +57 -49
  31. package/date-picker/index.js +161 -292
  32. package/dialog/index.js +70 -142
  33. package/dropdown-checkbox-option/index.js +6 -20
  34. package/dropdown-radio-option/index.js +6 -20
  35. package/field/index.js +25 -63
  36. package/file-drop/index.js +123 -200
  37. package/file-picker/index.d.ts +0 -1
  38. package/file-picker/index.js +55 -108
  39. package/file-status/index.js +15 -39
  40. package/help-tooltip/index.js +1 -1
  41. package/horizontal-stepper/index.js +33 -59
  42. package/horizontal-stepper-item/index.js +13 -37
  43. package/icon-button/index.js +39 -84
  44. package/icons-channel/notify/index.d.ts +11 -0
  45. package/icons-channel/notify/index.js +4 -0
  46. package/illustrations/create-illustration-class.js +1 -1
  47. package/inline-alert/index.js +29 -81
  48. package/input/index.js +113 -222
  49. package/link/index.js +46 -96
  50. package/list-item/index.js +1 -1
  51. package/package.json +12 -14
  52. package/pagination/index.js +109 -163
  53. package/popover/index.js +224 -294
  54. package/progress/index.js +9 -28
  55. package/radio/index.js +103 -169
  56. package/radio-option/index.js +24 -48
  57. package/segment/index.js +49 -130
  58. package/segment-collapse/index.js +24 -49
  59. package/segmented-control/index.js +36 -73
  60. package/segmented-control-option/index.js +41 -87
  61. package/segmented-icon-control/index.js +47 -84
  62. package/segmented-icon-control-option/index.js +38 -79
  63. package/select-button/index.d.ts +13 -0
  64. package/select-button/index.js +153 -0
  65. package/select-button/types.d.ts +43 -0
  66. package/select-menu/index.d.ts +11 -0
  67. package/select-menu/index.js +346 -0
  68. package/select-menu/types.d.ts +29 -0
  69. package/select-menu/types.js +1 -0
  70. package/{dropdown-text-option → select-menu-option}/index.d.ts +5 -7
  71. package/select-menu-option/index.js +76 -0
  72. package/{select-option → select-menu-option}/types.d.ts +8 -9
  73. package/stop-events/index.js +7 -20
  74. package/table-head-cell/index.js +7 -21
  75. package/tabs/index.js +103 -165
  76. package/tabs-option/index.js +20 -44
  77. package/tag/index.d.ts +0 -1
  78. package/tag/index.js +37 -38
  79. package/tag/types.d.ts +13 -7
  80. package/textarea/index.js +92 -167
  81. package/theme.css +80 -49
  82. package/tile-control/index.js +55 -96
  83. package/tile-control-option/index.js +40 -86
  84. package/time-picker/index.js +216 -368
  85. package/title/index.js +6 -20
  86. package/toast/index.js +32 -70
  87. package/toast-manager/index.js +141 -217
  88. package/toggle/index.js +54 -106
  89. package/types.d.ts +7 -0
  90. package/utils/colors.d.ts +10 -0
  91. package/utils/colors.js +121 -0
  92. package/{utils.d.ts → utils/index.d.ts} +17 -9
  93. package/{utils.js → utils/index.js} +96 -39
  94. package/vertical-stepper/index.js +29 -50
  95. package/vertical-stepper-item/index.js +13 -37
  96. package/dropdown/index.d.ts +0 -12
  97. package/dropdown/index.js +0 -415
  98. package/dropdown/types.d.ts +0 -32
  99. package/dropdown-text-option/index.js +0 -104
  100. package/dropdown-text-option/types.d.ts +0 -16
  101. package/select/index.d.ts +0 -13
  102. package/select/index.js +0 -316
  103. package/select/types.d.ts +0 -53
  104. package/select-option/index.d.ts +0 -11
  105. package/select-option/index.js +0 -8
  106. package/tag/utils.d.ts +0 -5
  107. package/tag/utils.js +0 -6
  108. package/tag-close/index.d.ts +0 -12
  109. package/tag-close/index.js +0 -42
  110. package/tag-close/types.d.ts +0 -5
  111. /package/{dropdown-text-option → chip}/types.js +0 -0
  112. /package/{dropdown → color-menu}/types.js +0 -0
  113. /package/{select-option → color-swatch}/types.js +0 -0
  114. /package/{select → select-button}/types.js +0 -0
  115. /package/{tag-close → select-menu-option}/types.js +0 -0
package/toggle/index.js CHANGED
@@ -1,115 +1,36 @@
1
- import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
- import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
-
4
- var _$input, _$label, _onInput, _onCheckboxFocus, _onCheckboxBlur, _onChangeReactHandler, _onFocusReactHandler, _onBlurReactHandler;
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
1
  import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute, updateExplicitBooleanAttribute } from '../utils';
11
2
  const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;box-sizing:border-box;width:100%;height:32px}:host([small]:not([small=false])) #wrapper{font:var(--sinch-font-small-text)}#input{all:initial;display:block;position:absolute;left:0;top:6px;width:40px;height:20px;cursor:pointer;pointer-events:initial}#input:disabled{cursor:initial}:host([small]:not([small=false])) #input{width:32px;height:16px;top:8px}#input:focus-visible::after{position:absolute;content:"";left:-4px;top:-4px;right:-4px;bottom:-4px;border:2px solid var(--sinch-color-aqua-400);border-radius:18px;pointer-events:none}:host([small]:not([small=false])) #input:focus-visible::after{border-radius:14px}@supports not selector(:focus-visible){#input:focus::after{position:absolute;content:"";left:-4px;top:-4px;right:-4px;bottom:-4px;border:2px solid var(--sinch-color-aqua-400);border-radius:18px;pointer-events:none}:host([small]:not([small=false])) #input:focus::after{border-radius:14px}}#knob-container{position:relative;box-sizing:border-box;width:40px;height:20px;border-radius:10px;pointer-events:none;padding:2px;background-color:var(--sinch-color-stormy-100);overflow:hidden}:host([small]:not([small=false])) #knob-container{width:32px;height:16px;border-radius:8px}#input:checked~#knob-container{background-color:var(--sinch-color-tropical-500)}#knob{position:relative;box-sizing:border-box;width:16px;height:16px;border-radius:50%;background-color:var(--sinch-color-snow-100);box-shadow:var(--sinch-elevation-level-1);transform:translateX(0);transition:transform .1s ease-in-out}:host([small]:not([small=false])) #knob{width:12px;height:12px}#input:checked~#knob-container>#knob{transform:translateX(20px)}:host([small]:not([small=false])) #input:checked~#knob-container>#knob{transform:translateX(16px)}#knob::after,#knob::before{font:var(--sinch-font-body);color:var(--sinch-color-snow-100);text-transform:uppercase;font-size:8px;line-height:16px;display:none;position:absolute;top:0;padding:0 3px}#knob::before{content:"on";right:100%}#knob::after{content:"off";left:100%}:host([labeled]:not([labeled=false]):is(:not([small]),[small=false])) #knob::after,:host([labeled]:not([labeled=false]):is(:not([small]),[small=false])) #knob::before{display:block}@media (prefers-reduced-motion){#knob{transition:none}}#label{flex:1;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;padding-left:8px;font:var(--sinch-font-body);color:var(--sinch-color-text-default)}#label:empty{display:none}#input:disabled~#label{color:var(--sinch-color-stormy-200)}#input:disabled~#knob-container{background-color:var(--sinch-color-snow-700)}#input:checked:disabled~#knob-container{background-color:var(--sinch-color-tropical-100)}</style><div id="wrapper"><input id="input" type="checkbox"><div id="knob-container"><div id="knob"></div></div><label id="label" for="input"></label></div>';
12
3
  const template = document.createElement('template');
13
4
  template.innerHTML = templateHTML;
14
- defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new WeakMap(), _onInput = new WeakMap(), _onCheckboxFocus = new WeakMap(), _onCheckboxBlur = new WeakMap(), _onChangeReactHandler = new WeakMap(), _onFocusReactHandler = new WeakMap(), _onBlurReactHandler = new WeakMap(), class extends NectaryElement {
5
+ defineCustomElement('sinch-toggle', class extends NectaryElement {
6
+ #$input;
7
+ #$label;
8
+
15
9
  constructor() {
16
10
  super();
17
-
18
- _classPrivateFieldInitSpec(this, _$input, {
19
- writable: true,
20
- value: void 0
21
- });
22
-
23
- _classPrivateFieldInitSpec(this, _$label, {
24
- writable: true,
25
- value: void 0
26
- });
27
-
28
- _classPrivateFieldInitSpec(this, _onInput, {
29
- writable: true,
30
- value: e => {
31
- e.stopPropagation();
32
-
33
- const isChecked = _classPrivateFieldGet(this, _$input).checked;
34
-
35
- _classPrivateFieldGet(this, _$input).checked = this.checked;
36
- this.dispatchEvent(new CustomEvent('change', {
37
- detail: isChecked,
38
- bubbles: true
39
- }));
40
- this.dispatchEvent(new CustomEvent('-change', {
41
- detail: isChecked
42
- }));
43
- }
44
- });
45
-
46
- _classPrivateFieldInitSpec(this, _onCheckboxFocus, {
47
- writable: true,
48
- value: () => {
49
- this.dispatchEvent(new CustomEvent('-focus'));
50
- }
51
- });
52
-
53
- _classPrivateFieldInitSpec(this, _onCheckboxBlur, {
54
- writable: true,
55
- value: () => {
56
- this.dispatchEvent(new CustomEvent('-blur'));
57
- }
58
- });
59
-
60
- _classPrivateFieldInitSpec(this, _onChangeReactHandler, {
61
- writable: true,
62
- value: e => {
63
- getReactEventHandler(this, 'on-change')?.(e);
64
- }
65
- });
66
-
67
- _classPrivateFieldInitSpec(this, _onFocusReactHandler, {
68
- writable: true,
69
- value: e => {
70
- getReactEventHandler(this, 'on-focus')?.(e);
71
- }
72
- });
73
-
74
- _classPrivateFieldInitSpec(this, _onBlurReactHandler, {
75
- writable: true,
76
- value: e => {
77
- getReactEventHandler(this, 'on-blur')?.(e);
78
- }
79
- });
80
-
81
11
  const shadowRoot = this.attachShadow();
82
12
  shadowRoot.appendChild(template.content.cloneNode(true));
83
-
84
- _classPrivateFieldSet(this, _$input, shadowRoot.querySelector('#input'));
85
-
86
- _classPrivateFieldSet(this, _$label, shadowRoot.querySelector('#label'));
13
+ this.#$input = shadowRoot.querySelector('#input');
14
+ this.#$label = shadowRoot.querySelector('#label');
87
15
  }
88
16
 
89
17
  connectedCallback() {
90
18
  this.setAttribute('role', 'checkbox');
91
-
92
- _classPrivateFieldGet(this, _$input).addEventListener('input', _classPrivateFieldGet(this, _onInput));
93
-
94
- _classPrivateFieldGet(this, _$input).addEventListener('focus', _classPrivateFieldGet(this, _onCheckboxFocus));
95
-
96
- _classPrivateFieldGet(this, _$input).addEventListener('blur', _classPrivateFieldGet(this, _onCheckboxBlur));
97
-
98
- this.addEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
99
- this.addEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
100
- this.addEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
19
+ this.#$input.addEventListener('input', this.#onInput);
20
+ this.#$input.addEventListener('focus', this.#onCheckboxFocus);
21
+ this.#$input.addEventListener('blur', this.#onCheckboxBlur);
22
+ this.addEventListener('-change', this.#onChangeReactHandler);
23
+ this.addEventListener('-focus', this.#onFocusReactHandler);
24
+ this.addEventListener('-blur', this.#onBlurReactHandler);
101
25
  }
102
26
 
103
27
  disconnectedCallback() {
104
- _classPrivateFieldGet(this, _$input).removeEventListener('input', _classPrivateFieldGet(this, _onInput));
105
-
106
- _classPrivateFieldGet(this, _$input).removeEventListener('focus', _classPrivateFieldGet(this, _onCheckboxFocus));
107
-
108
- _classPrivateFieldGet(this, _$input).removeEventListener('blur', _classPrivateFieldGet(this, _onCheckboxBlur));
109
-
110
- this.removeEventListener('-change', _classPrivateFieldGet(this, _onChangeReactHandler));
111
- this.removeEventListener('-focus', _classPrivateFieldGet(this, _onFocusReactHandler));
112
- this.removeEventListener('-blur', _classPrivateFieldGet(this, _onBlurReactHandler));
28
+ this.#$input.removeEventListener('input', this.#onInput);
29
+ this.#$input.removeEventListener('focus', this.#onCheckboxFocus);
30
+ this.#$input.removeEventListener('blur', this.#onCheckboxBlur);
31
+ this.removeEventListener('-change', this.#onChangeReactHandler);
32
+ this.removeEventListener('-focus', this.#onFocusReactHandler);
33
+ this.removeEventListener('-blur', this.#onBlurReactHandler);
113
34
  }
114
35
 
115
36
  static get observedAttributes() {
@@ -161,21 +82,21 @@ defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new Weak
161
82
  }
162
83
 
163
84
  get text() {
164
- return getAttribute(this, 'text', null);
85
+ return getAttribute(this, 'text');
165
86
  }
166
87
 
167
88
  attributeChangedCallback(name, _, newVal) {
168
89
  switch (name) {
169
90
  case 'text':
170
91
  {
171
- _classPrivateFieldGet(this, _$label).textContent = newVal;
92
+ this.#$label.textContent = newVal;
172
93
  break;
173
94
  }
174
95
 
175
96
  case 'checked':
176
97
  {
177
98
  const isChecked = isAttrTrue(newVal);
178
- _classPrivateFieldGet(this, _$input).checked = isChecked;
99
+ this.#$input.checked = isChecked;
179
100
  updateExplicitBooleanAttribute(this, 'aria-checked', isChecked);
180
101
  break;
181
102
  }
@@ -183,7 +104,7 @@ defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new Weak
183
104
  case 'disabled':
184
105
  {
185
106
  const isDisabled = isAttrTrue(newVal);
186
- _classPrivateFieldGet(this, _$input).disabled = isDisabled;
107
+ this.#$input.disabled = isDisabled;
187
108
  updateBooleanAttribute(this, 'disabled', isDisabled);
188
109
  break;
189
110
  }
@@ -191,11 +112,38 @@ defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new Weak
191
112
  }
192
113
 
193
114
  focus() {
194
- _classPrivateFieldGet(this, _$input).focus();
115
+ this.#$input.focus();
195
116
  }
196
117
 
197
118
  blur() {
198
- _classPrivateFieldGet(this, _$input).blur();
199
- }
200
-
201
- }));
119
+ this.#$input.blur();
120
+ }
121
+
122
+ #onInput = e => {
123
+ e.stopPropagation();
124
+ const isChecked = this.#$input.checked;
125
+ this.#$input.checked = this.checked;
126
+ this.dispatchEvent(new CustomEvent('change', {
127
+ detail: isChecked,
128
+ bubbles: true
129
+ }));
130
+ this.dispatchEvent(new CustomEvent('-change', {
131
+ detail: isChecked
132
+ }));
133
+ };
134
+ #onCheckboxFocus = () => {
135
+ this.dispatchEvent(new CustomEvent('-focus'));
136
+ };
137
+ #onCheckboxBlur = () => {
138
+ this.dispatchEvent(new CustomEvent('-blur'));
139
+ };
140
+ #onChangeReactHandler = e => {
141
+ getReactEventHandler(this, 'on-change')?.(e);
142
+ };
143
+ #onFocusReactHandler = e => {
144
+ getReactEventHandler(this, 'on-focus')?.(e);
145
+ };
146
+ #onBlurReactHandler = e => {
147
+ getReactEventHandler(this, 'on-blur')?.(e);
148
+ };
149
+ });
package/types.d.ts CHANGED
@@ -12,3 +12,10 @@ export type TRect = {
12
12
  width: number,
13
13
  height: number,
14
14
  }
15
+
16
+ export type TContextKeyboard = {
17
+ code: string,
18
+ preventDefault: () => void,
19
+ }
20
+
21
+ export type TContextVisibility = boolean
@@ -0,0 +1,10 @@
1
+ export declare const NO_COLOR: "";
2
+ export declare type TSinchColorName = typeof NO_COLOR | 'Blue 10' | 'Blue 20' | 'Blue 30' | 'Blue 40' | 'Blue 50' | 'Green 10' | 'Green 20' | 'Green 30' | 'Yellow 20' | 'Yellow 10' | 'Orange 10' | 'Orange 30' | 'Orange 20' | 'Coral 10' | 'Pink 10' | 'Pink 20' | 'Brown 10' | 'Brown 20' | 'Gray 10' | 'Gray 20' | 'Red 10' | 'Skin tone 0' | 'Skin tone 10' | 'Skin tone 20' | 'Skin tone 30' | 'Skin tone 40' | 'Skin tone 50';
3
+ export declare const colorNameValues: readonly TSinchColorName[];
4
+ declare type TAssertColorName = (value: string | null) => asserts value is TSinchColorName;
5
+ export declare const assertColorNameValue: TAssertColorName;
6
+ export declare const colorMap: Record<TSinchColorName, {
7
+ value: string;
8
+ isInverted: boolean;
9
+ }>;
10
+ export {};
@@ -0,0 +1,121 @@
1
+ export const NO_COLOR = '';
2
+ export const colorNameValues = [NO_COLOR, 'Blue 10', 'Blue 20', 'Blue 30', 'Blue 40', 'Blue 50', 'Green 10', 'Green 20', 'Green 30', 'Yellow 10', 'Yellow 20', 'Orange 10', 'Orange 20', 'Orange 30', 'Pink 10', 'Pink 20', 'Brown 10', 'Brown 20', 'Gray 10', 'Gray 20', 'Coral 10', 'Red 10', 'Skin tone 0', 'Skin tone 10', 'Skin tone 20', 'Skin tone 30', 'Skin tone 40', 'Skin tone 50'];
3
+ export const assertColorNameValue = value => {
4
+ if (value === null || !colorNameValues.includes(value)) {
5
+ throw new Error(`Invalid color name: "${value}"`);
6
+ }
7
+ };
8
+ export const colorMap = {
9
+ [NO_COLOR]: {
10
+ value: NO_COLOR,
11
+ isInverted: false
12
+ },
13
+ 'Blue 50': {
14
+ value: 'night-400',
15
+ isInverted: true
16
+ },
17
+ 'Blue 40': {
18
+ value: 'aqua-400',
19
+ isInverted: false
20
+ },
21
+ 'Blue 30': {
22
+ value: 'aqua-200',
23
+ isInverted: false
24
+ },
25
+ 'Blue 20': {
26
+ value: 'night-200',
27
+ isInverted: false
28
+ },
29
+ 'Blue 10': {
30
+ value: 'informative-200',
31
+ isInverted: false
32
+ },
33
+ 'Green 30': {
34
+ value: 'grass-400',
35
+ isInverted: false
36
+ },
37
+ 'Green 20': {
38
+ value: 'grass-200',
39
+ isInverted: false
40
+ },
41
+ 'Green 10': {
42
+ value: 'success-200',
43
+ isInverted: false
44
+ },
45
+ 'Yellow 20': {
46
+ value: 'bolt-400',
47
+ isInverted: false
48
+ },
49
+ 'Yellow 10': {
50
+ value: 'bolt-200',
51
+ isInverted: false
52
+ },
53
+ 'Orange 30': {
54
+ value: 'orange-400',
55
+ isInverted: false
56
+ },
57
+ 'Orange 20': {
58
+ value: 'orange-200',
59
+ isInverted: false
60
+ },
61
+ 'Orange 10': {
62
+ value: 'warning-200',
63
+ isInverted: false
64
+ },
65
+ 'Pink 20': {
66
+ value: 'candy-400',
67
+ isInverted: false
68
+ },
69
+ 'Pink 10': {
70
+ value: 'candy-200',
71
+ isInverted: false
72
+ },
73
+ 'Brown 20': {
74
+ value: 'mud-400',
75
+ isInverted: true
76
+ },
77
+ 'Brown 10': {
78
+ value: 'mud-200',
79
+ isInverted: false
80
+ },
81
+ 'Gray 20': {
82
+ value: 'dirt-400',
83
+ isInverted: false
84
+ },
85
+ 'Gray 10': {
86
+ value: 'dirt-200',
87
+ isInverted: false
88
+ },
89
+ 'Coral 10': {
90
+ value: 'berry-200',
91
+ isInverted: false
92
+ },
93
+ 'Red 10': {
94
+ value: 'error-200',
95
+ isInverted: false
96
+ },
97
+ 'Skin tone 0': {
98
+ value: 'skin-tone-10',
99
+ isInverted: false
100
+ },
101
+ 'Skin tone 10': {
102
+ value: 'skin-tone-20',
103
+ isInverted: false
104
+ },
105
+ 'Skin tone 20': {
106
+ value: 'skin-tone-30',
107
+ isInverted: false
108
+ },
109
+ 'Skin tone 30': {
110
+ value: 'skin-tone-40',
111
+ isInverted: false
112
+ },
113
+ 'Skin tone 40': {
114
+ value: 'skin-tone-50',
115
+ isInverted: false
116
+ },
117
+ 'Skin tone 50': {
118
+ value: 'skin-tone-60',
119
+ isInverted: true
120
+ }
121
+ };
@@ -1,4 +1,4 @@
1
- import type { TRect } from './types';
1
+ import type { TRect } from '../types';
2
2
  export declare const defineCustomElement: (name: string, constructor: CustomElementConstructor) => void;
3
3
  export declare const setNectaryRegistry: (registry: CustomElementRegistry) => void;
4
4
  declare global {
@@ -16,8 +16,7 @@ export declare const isAttrTrue: (attrValue: string | null) => boolean;
16
16
  export declare const getBooleanAttribute: ($element: Element, attrName: string) => boolean;
17
17
  export declare const updateBooleanAttribute: ($element: Element, attrName: string, attrValue: boolean | null | undefined) => void;
18
18
  export declare const updateAttribute: ($element: Element, attrName: string, attrValue: string | number | boolean | null | undefined) => void;
19
- export declare function getAttribute($element: Element, attrName: string): string | undefined;
20
- export declare function getAttribute($element: Element, attrName: string, defaultValue: null): string | null;
19
+ export declare function getAttribute($element: Element, attrName: string): string | null;
21
20
  export declare function getAttribute($element: Element, attrName: string, defaultValue: string): string;
22
21
  export declare const isLiteralValue: <T extends readonly string[]>(literals: T, value: string | null | undefined) => value is T[number];
23
22
  export declare const updateLiteralAttribute: <T extends readonly string[]>($element: Element, literals: T, attrName: string, attrValue: string | null | undefined) => void;
@@ -25,15 +24,16 @@ export declare function getLiteralAttribute<T extends readonly string[]>($elemen
25
24
  export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: null): T[number] | null;
26
25
  export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: T[number]): T[number];
27
26
  export declare const clampNumber: (value: number, min: number, max: number) => number;
28
- declare type TRange = {
27
+ declare type IntegerOptions = {
29
28
  min?: number;
30
29
  max?: number;
30
+ defaultValue?: number | null;
31
+ itemSizeMultiplier?: number;
32
+ itemSpaceBetween?: number;
31
33
  };
32
- export declare const attrValueToInteger: (value: string | null, range?: TRange) => number | null;
33
- export declare const attrValueToPixels: (value: string | null, options?: TRange & {
34
- multiplier?: number;
35
- }) => string;
36
- export declare const updateIntegerAttribute: ($element: Element, attrName: string, attrValue: string | number | null | undefined, range?: TRange) => void;
34
+ export declare const attrValueToInteger: (value: string | null, options?: IntegerOptions) => number | null;
35
+ export declare const attrValueToPixels: (value: string | null, options?: IntegerOptions) => string;
36
+ export declare const updateIntegerAttribute: ($element: Element, attrName: string, attrValue: string | number | null | undefined, options?: IntegerOptions) => void;
37
37
  export declare function getIntegerAttribute($element: Element, attrName: string): number | undefined;
38
38
  export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: null): number | null;
39
39
  export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: number): number;
@@ -49,4 +49,12 @@ export declare const throttleAnimationFrame: (cb: (...args: any[]) => void) => {
49
49
  };
50
50
  export declare const getFirstSlotElement: (root: HTMLSlotElement) => HTMLElement | null;
51
51
  export declare const cloneNode: (el: Element, deep: boolean) => Element;
52
+ export declare const isElementFocused: ($el: Element | null) => boolean;
53
+ export declare class Context {
54
+ #private;
55
+ constructor($element: Element, name: string);
56
+ get elements(): Iterable<Element>;
57
+ subscribe(): void;
58
+ unsubscribe(): void;
59
+ }
52
60
  export {};
@@ -1,5 +1,4 @@
1
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
- import pkg from './package.json';
1
+ import pkg from '../package.json';
3
2
  const nectaryDefinitions = new Map();
4
3
  let nectaryRegistry = null;
5
4
  export const defineCustomElement = (name, constructor) => {
@@ -29,12 +28,6 @@ export const setNectaryRegistry = registry => {
29
28
  nectaryDefinitions.clear();
30
29
  };
31
30
  export class NectaryElement extends HTMLElement {
32
- constructor() {
33
- super(...arguments);
34
-
35
- _defineProperty(this, '__version', pkg.version);
36
- }
37
-
38
31
  attachShadow(options) {
39
32
  return super.attachShadow({
40
33
  mode: 'closed',
@@ -44,6 +37,7 @@ export class NectaryElement extends HTMLElement {
44
37
  });
45
38
  }
46
39
 
40
+ __version = pkg.version;
47
41
  }
48
42
  export const getReactEventHandler = ($element, handlerName) => {
49
43
  for (const key in $element) {
@@ -81,7 +75,8 @@ export const updateAttribute = ($element, attrName, attrValue) => {
81
75
  $element.removeAttribute(attrName);
82
76
  }
83
77
  };
84
- export function getAttribute($element, attrName, defaultValue) {
78
+ export function getAttribute($element, attrName) {
79
+ let defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
85
80
  return $element.getAttribute(attrName) ?? defaultValue;
86
81
  }
87
82
  export const isLiteralValue = (literals, value) => {
@@ -110,59 +105,79 @@ export function getLiteralAttribute($element, literals, attrName, defaultValue)
110
105
  export const clampNumber = (value, min, max) => {
111
106
  return Math.min(max, Math.max(min, value));
112
107
  };
108
+ const DEFAULT_INTEGER_OPTIONS = {
109
+ itemSizeMultiplier: 1,
110
+ itemSpaceBetween: 0,
111
+ defaultValue: null
112
+ };
113
113
 
114
- const applyRange = (value, range) => {
114
+ const applyRange = (value, _ref) => {
115
+ let {
116
+ min,
117
+ max
118
+ } = _ref;
115
119
  let result = value;
116
120
 
117
- if (typeof range.min === 'number') {
118
- result = Math.max(range.min, result);
121
+ if (min != null) {
122
+ result = Math.max(min, result);
119
123
  }
120
124
 
121
- if (typeof range.max === 'number') {
122
- result = Math.min(range.max, result);
125
+ if (max != null) {
126
+ result = Math.min(max, result);
123
127
  }
124
128
 
125
129
  return result;
126
130
  };
127
131
 
128
132
  export const attrValueToInteger = function (value) {
129
- let range = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
133
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
134
+ const {
135
+ defaultValue = null,
136
+ itemSizeMultiplier = 1,
137
+ itemSpaceBetween = 0
138
+ } = options;
139
+ let intValue = defaultValue;
130
140
 
131
- if (value === null) {
132
- return null;
133
- }
141
+ if (value !== null) {
142
+ const int = parseInt(value);
134
143
 
135
- const int = parseInt(value);
144
+ if (Number.isInteger(int)) {
145
+ intValue = applyRange(int, options);
146
+ }
147
+ }
136
148
 
137
- if (!Number.isInteger(int)) {
138
- return null;
149
+ if (intValue !== null) {
150
+ return intValue * itemSizeMultiplier + Math.max(intValue - 1, 0) * itemSpaceBetween;
139
151
  }
140
152
 
141
- return applyRange(int, range);
153
+ return null;
142
154
  };
143
155
  export const attrValueToPixels = function (value) {
144
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
145
- const int = attrValueToInteger(value, {
146
- min: options.min ?? 0,
147
- max: options.max
148
- });
149
- return int === null ? 'unset' : `${int * (options.multiplier ?? 1)}px`;
156
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
157
+ const int = attrValueToInteger(value, options);
158
+ return int === null ? 'unset' : `${int}px`;
150
159
  };
151
160
  export const updateIntegerAttribute = function ($element, attrName, attrValue) {
152
- let range = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
153
-
154
- if (attrValue == null) {
155
- $element.removeAttribute(attrName);
156
- return;
161
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_INTEGER_OPTIONS;
162
+ const {
163
+ defaultValue = null,
164
+ itemSizeMultiplier: multiplier = 1
165
+ } = options;
166
+ let intValue = null;
167
+
168
+ if (typeof attrValue === 'string') {
169
+ intValue = attrValueToInteger(attrValue, options);
170
+ } else if (typeof attrValue === 'number') {
171
+ intValue = applyRange(attrValue, options) * multiplier;
172
+ } else {
173
+ intValue = defaultValue;
157
174
  }
158
175
 
159
- const intValue = typeof attrValue === 'string' ? attrValueToInteger(attrValue, range) : applyRange(attrValue, range);
160
-
161
176
  if (intValue === null) {
162
- return;
177
+ $element.removeAttribute(attrName);
178
+ } else {
179
+ $element.setAttribute(attrName, intValue.toFixed(0));
163
180
  }
164
-
165
- $element.setAttribute(attrName, intValue.toFixed(0));
166
181
  };
167
182
  export function getIntegerAttribute($element, attrName, defaultValue) {
168
183
  return attrValueToInteger($element.getAttribute(attrName)) ?? defaultValue;
@@ -283,4 +298,46 @@ export const cloneNode = (el, deep) => {
283
298
  }
284
299
 
285
300
  return el.cloneNode(deep);
286
- };
301
+ };
302
+ export const isElementFocused = $el => {
303
+ return $el !== null && $el === $el.getRootNode().activeElement;
304
+ };
305
+ export class Context {
306
+ #$root;
307
+ #listeners = new Set();
308
+ #name;
309
+ #isSubscribed = false;
310
+
311
+ constructor($element, name) {
312
+ this.#$root = $element;
313
+ this.#name = name;
314
+ }
315
+
316
+ get elements() {
317
+ return this.#listeners;
318
+ }
319
+
320
+ subscribe() {
321
+ if (this.#isSubscribed) {
322
+ return;
323
+ }
324
+
325
+ this.#$root.addEventListener(`-context-connect-${this.#name}`, this.#onConnect);
326
+ this.#$root.addEventListener(`-context-disconnect-${this.#name}`, this.#onDisconnect);
327
+ this.#isSubscribed = true;
328
+ }
329
+
330
+ unsubscribe() {
331
+ this.#listeners.clear();
332
+ this.#$root.removeEventListener(`-context-connect-${this.#name}`, this.#onConnect);
333
+ this.#$root.removeEventListener(`-context-disconnect-${this.#name}`, this.#onDisconnect);
334
+ this.#isSubscribed = false;
335
+ }
336
+
337
+ #onConnect = e => {
338
+ this.#listeners.add(e.target);
339
+ };
340
+ #onDisconnect = e => {
341
+ this.#listeners.delete(e.target);
342
+ };
343
+ }