@mustib/web-components 0.0.0-alpha.1 → 0.0.0-alpha.2

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.
@@ -1,9 +1,8 @@
1
- import { M as MUElement, E as EventAction, _ as __decorate, g as getElementBoundaries, d as debounce, a as disableElementScroll, e as enableElementScroll } from '../mu-element-CZDI_RCY.js';
2
- import { property } from 'lit/decorators.js';
1
+ import { M as MUElement, E as EventAction, _ as __decorate, g as getElementBoundaries, d as debounce, a as disableElementScroll, e as enableElementScroll } from '../mu-element-BTuCCJpo.js';
3
2
  import { css, html } from 'lit';
4
- import { MuSelectItem } from './mu-select-item.js';
3
+ import { property } from 'lit/decorators.js';
5
4
  import { MuTransparent } from './mu-transparent.js';
6
- import { staticProperty } from '../decorators.js';
5
+ import { MuSelectItem } from './mu-select-item.js';
7
6
 
8
7
  class MuSelectItems extends MUElement {
9
8
  constructor() {
@@ -24,7 +23,7 @@ class MuSelectItems extends MUElement {
24
23
  this.openMode = 'no-scroll';
25
24
  this.eventActionData = {
26
25
  eventAction: MuSelectItems.eventAction,
27
- events: ['click', 'pointerover', 'pointerdown']
26
+ events: ['click', 'pointerover', 'pointerdown'],
28
27
  };
29
28
  this._isReady = this.generateIsReadyPromise();
30
29
  this._items = [];
@@ -38,22 +37,22 @@ class MuSelectItems extends MUElement {
38
37
  const boundaries = getElementBoundaries(this.parentElement);
39
38
  const yAxisPosition = boundaries.elementTop >= boundaries.elementBottom ? 'top' : 'bottom';
40
39
  this.setAttribute('items-y-axis', yAxisPosition);
41
- this.style.setProperty('--items-max-height', Math.max(boundaries.elementTop, boundaries.elementBottom) + 'px');
40
+ this.style.setProperty('--items-max-height', `${Math.max(boundaries.elementTop, boundaries.elementBottom)}px`);
42
41
  if (this.position === 'fixed') {
43
42
  this.style.setProperty('--items-position', 'fixed');
44
- this.style.setProperty('--items-width', boundaries.width + 'px');
43
+ this.style.setProperty('--items-width', `${boundaries.width}px`);
45
44
  if (yAxisPosition === 'top') {
46
- this.style.setProperty('--items-bottom', boundaries.elementBottom + boundaries.height + 'px');
45
+ this.style.setProperty('--items-bottom', `${boundaries.elementBottom + boundaries.height}px`);
47
46
  this.style.setProperty('--items-top', 'unset');
48
47
  this.style.setProperty('--items-transform-origin', 'bottom');
49
48
  }
50
49
  else {
51
- this.style.setProperty('--items-top', boundaries.elementTop + boundaries.height + 'px');
50
+ this.style.setProperty('--items-top', `${boundaries.elementTop + boundaries.height}px`);
52
51
  this.style.setProperty('--items-bottom', 'unset');
53
52
  this.style.setProperty('--items-transform-origin', 'top');
54
53
  }
55
- this.style.setProperty('--items-left', boundaries.elementLeft + 'px');
56
- this.style.setProperty('--items-right', boundaries.elementRight + 'px');
54
+ this.style.setProperty('--items-left', `${boundaries.elementLeft}px`);
55
+ this.style.setProperty('--items-right', `${boundaries.elementRight}px`);
57
56
  }
58
57
  else {
59
58
  this.style.setProperty('--items-position', 'absolute');
@@ -94,7 +93,7 @@ class MuSelectItems extends MUElement {
94
93
  value,
95
94
  selected: false,
96
95
  active: false,
97
- index: this._items.length
96
+ index: this._items.length,
98
97
  };
99
98
  this._itemsValuesMap.set(value, item);
100
99
  this._itemsElementsMap.set(element, item);
@@ -104,8 +103,10 @@ class MuSelectItems extends MUElement {
104
103
  if (previouslyActiveItem?.value === value)
105
104
  this._addActiveItemState(item);
106
105
  };
107
- this.renderRoot.querySelector('slot#items-slot').assignedElements({ flatten: true }).forEach((child) => {
108
- if ((child instanceof MuTransparent)) {
106
+ this.renderRoot.querySelector('slot#items-slot')
107
+ .assignedElements({ flatten: true })
108
+ .forEach((child) => {
109
+ if (child instanceof MuTransparent) {
109
110
  const contents = child.contents;
110
111
  contents.forEach((content) => {
111
112
  if (!(content instanceof MuSelectItem))
@@ -122,12 +123,19 @@ class MuSelectItems extends MUElement {
122
123
  if (removedSelected.size > 0) {
123
124
  if (!this.isControlled) {
124
125
  this._selectedValues.clear();
125
- newSelectedValues.forEach(value => {
126
+ newSelectedValues.forEach((value) => {
126
127
  this._addSelectState(this._itemsValuesMap.get(value));
127
128
  });
128
129
  }
129
130
  const eventName = 'mu-select-items-change-orphans';
130
- this.dispatchEvent(new CustomEvent(eventName, { bubbles: true, composed: true, detail: { orphanValues: Array.from(removedSelected), values: Array.from(newSelectedValues) } }));
131
+ this.dispatchEvent(new CustomEvent(eventName, {
132
+ bubbles: true,
133
+ composed: true,
134
+ detail: {
135
+ orphanValues: Array.from(removedSelected),
136
+ values: Array.from(newSelectedValues),
137
+ },
138
+ }));
131
139
  }
132
140
  if (!this._isReady.resolved)
133
141
  this._isReady.resolve();
@@ -139,7 +147,12 @@ class MuSelectItems extends MUElement {
139
147
  }
140
148
  get parentElement() {
141
149
  const selector = this.getAttribute('parent-selector');
142
- const element = selector ? this.closestPierce(selector) : super.parentElement;
150
+ const element = selector
151
+ ? this.closestPierce(selector)
152
+ : super.parentElement;
153
+ if (!element) {
154
+ throw new Error(`no parent element found for (${this.tagName.toLowerCase()}) element ${selector === null ? '' : `with the selector ${selector}`}`);
155
+ }
143
156
  return element;
144
157
  }
145
158
  get activeValue() {
@@ -165,7 +178,9 @@ class MuSelectItems extends MUElement {
165
178
  this._resizeObserver?.disconnect();
166
179
  }
167
180
  unselect(values) {
168
- values.forEach(value => this._changeSelectState('remove', value));
181
+ values.forEach((value) => {
182
+ this._changeSelectState('remove', value);
183
+ });
169
184
  }
170
185
  unselectAll() {
171
186
  this.unselect(this.getValue());
@@ -185,17 +200,20 @@ class MuSelectItems extends MUElement {
185
200
  */
186
201
  focusFirstNavigableItem(direction) {
187
202
  this.updateComplete.then(() => {
188
- const item = this._activeItem || this._getNavigationItem({ direction, switchBack: true });
203
+ const item = this._activeItem ||
204
+ this._getNavigationItem({ direction, switchBack: true });
189
205
  this._addActiveItemState(item);
190
206
  });
191
207
  }
192
- _getNavigationItem({ direction, switchBack = false, fromIndex = direction === 'next' ? -1 : this._items.length }) {
208
+ _getNavigationItem({ direction, switchBack = false, fromIndex = direction === 'next' ? -1 : this._items.length, }) {
193
209
  return this.getNavigationItem({
194
210
  fromIndex,
195
211
  direction,
196
212
  switchBack,
197
213
  items: this._items,
198
- isNavigable: (item) => !(item.element.disabled || item.element.readonly || item.element.filteredOut)
214
+ isNavigable: (item) => !(item.element.disabled ||
215
+ item.element.readonly ||
216
+ item.element.filteredOut),
199
217
  });
200
218
  }
201
219
  /**
@@ -204,27 +222,40 @@ class MuSelectItems extends MUElement {
204
222
  switchActiveItem(direction, options) {
205
223
  const { switchBack = true } = options ?? {};
206
224
  const activeIndex = this._activeItem?.index;
207
- const newActiveItem = this._getNavigationItem({ direction, switchBack, fromIndex: activeIndex });
225
+ const newActiveItem = this._getNavigationItem({
226
+ direction,
227
+ switchBack,
228
+ fromIndex: activeIndex,
229
+ });
208
230
  return this._addActiveItemState(newActiveItem);
209
231
  }
210
232
  _addActiveItemState(item) {
211
- if (!item || item.element.disabled || item.element.readonly || item.element.filteredOut)
233
+ if (!item ||
234
+ item.element.disabled ||
235
+ item.element.readonly ||
236
+ item.element.filteredOut)
212
237
  return;
213
238
  this.clearActiveItem();
214
239
  item.element.active = item.active = true;
215
240
  this._activeItem = item;
216
- item.element.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
241
+ item.element.scrollIntoView({
242
+ behavior: 'smooth',
243
+ block: 'nearest',
244
+ inline: 'start',
245
+ });
217
246
  this._dispatchActiveItemChange({ id: item.element.id });
218
247
  return true;
219
248
  }
220
249
  clearFilteredOutItems() {
221
- this._items.forEach(item => {
250
+ this._items.forEach((item) => {
222
251
  item.element.filteredOut = false;
223
252
  });
224
253
  }
225
254
  filterOutItems(value) {
226
- this._items.forEach(item => {
227
- const isFilteredOut = !item.value.toLowerCase().includes(value.toLowerCase());
255
+ this._items.forEach((item) => {
256
+ const isFilteredOut = !item.value
257
+ .toLowerCase()
258
+ .includes(value.toLowerCase());
228
259
  item.element.filteredOut = isFilteredOut;
229
260
  if (isFilteredOut && this._activeItem === item)
230
261
  this.clearActiveItem();
@@ -235,7 +266,11 @@ class MuSelectItems extends MUElement {
235
266
  */
236
267
  _dispatchActiveItemChange({ id }) {
237
268
  const eventName = 'mu-select-items-active-item-change';
238
- this.dispatchEvent(new CustomEvent(eventName, { bubbles: true, composed: true, detail: { id } }));
269
+ this.dispatchEvent(new CustomEvent(eventName, {
270
+ bubbles: true,
271
+ composed: true,
272
+ detail: { id },
273
+ }));
239
274
  }
240
275
  /**
241
276
  *
@@ -251,7 +286,9 @@ class MuSelectItems extends MUElement {
251
286
  *
252
287
  */
253
288
  getMuSelectItemFromEvent(e) {
254
- const item = e.target instanceof HTMLElement ? e.target.closest('mu-select-item') : null;
289
+ const item = e.target instanceof HTMLElement
290
+ ? e.target.closest('mu-select-item')
291
+ : null;
255
292
  if (item && !(item.disabled || item.readonly || item.filteredOut))
256
293
  return this._itemsElementsMap.get(item);
257
294
  }
@@ -287,7 +324,7 @@ class MuSelectItems extends MUElement {
287
324
  detail,
288
325
  bubbles: true,
289
326
  composed: true,
290
- cancelable: true
327
+ cancelable: true,
291
328
  });
292
329
  this.dispatchEvent(event);
293
330
  }
@@ -307,7 +344,7 @@ class MuSelectItems extends MUElement {
307
344
  */
308
345
  _changeSelectState(type, _item) {
309
346
  const item = typeof _item === 'string' ? this._itemsValuesMap.get(_item) : _item;
310
- if (!(item) || !item.element.interactable)
347
+ if (!item || !item.element.interactable)
311
348
  return;
312
349
  let operation = type;
313
350
  if (operation === 'toggle') {
@@ -318,20 +355,29 @@ class MuSelectItems extends MUElement {
318
355
  case 'add-only':
319
356
  case 'add':
320
357
  if (!this.multiple || operation === 'add-only') {
321
- this._debounceDispatchChangeEvent({ values: [item.value], isCurrentSelection: !isControlled });
358
+ this._debounceDispatchChangeEvent({
359
+ values: [item.value],
360
+ isCurrentSelection: !isControlled,
361
+ });
322
362
  if (!isControlled) {
323
363
  this._clearSelectState();
324
364
  this._addSelectState(item);
325
365
  }
326
366
  return;
327
367
  }
328
- this._debounceDispatchChangeEvent({ values: [...this._selectedValues, item.value], isCurrentSelection: !isControlled });
368
+ this._debounceDispatchChangeEvent({
369
+ values: [...this._selectedValues, item.value],
370
+ isCurrentSelection: !isControlled,
371
+ });
329
372
  if (!isControlled) {
330
373
  this._addSelectState(item);
331
374
  }
332
375
  return;
333
376
  case 'remove':
334
- this._debounceDispatchChangeEvent({ values: [...this._selectedValues].filter(value => value !== item.value), isCurrentSelection: !isControlled });
377
+ this._debounceDispatchChangeEvent({
378
+ values: [...this._selectedValues].filter((value) => value !== item.value),
379
+ isCurrentSelection: !isControlled,
380
+ });
335
381
  if (!isControlled) {
336
382
  this._removeSelectState(item);
337
383
  }
@@ -346,7 +392,7 @@ class MuSelectItems extends MUElement {
346
392
  _changeSelectStateFromAttributeValue(value) {
347
393
  if (!value)
348
394
  return;
349
- const validValues = (Array.isArray(value) ? value : value.split(',')).filter(value => {
395
+ const validValues = (Array.isArray(value) ? value : value.split(',')).filter((value) => {
350
396
  if (value === '')
351
397
  return false;
352
398
  const isValid = this._itemsValuesMap.has(value);
@@ -360,15 +406,19 @@ class MuSelectItems extends MUElement {
360
406
  }
361
407
  const newSelectedValues = new Set(validValues);
362
408
  const removedValues = this._selectedValues.difference(newSelectedValues);
363
- removedValues.forEach(value => {
409
+ removedValues.forEach((value) => {
364
410
  this._removeSelectState(this._itemsValuesMap.get(value));
365
411
  });
366
- validValues.forEach(value => {
412
+ validValues.forEach((value) => {
367
413
  const item = this._itemsValuesMap.get(value);
368
414
  this._addSelectState(item);
369
415
  });
370
416
  const eventName = 'mu-select-items-change-forced';
371
- this.dispatchEvent(new CustomEvent(eventName, { bubbles: true, composed: true, detail: { values: validValues } }));
417
+ this.dispatchEvent(new CustomEvent(eventName, {
418
+ bubbles: true,
419
+ composed: true,
420
+ detail: { values: validValues },
421
+ }));
372
422
  }
373
423
  /**
374
424
  * This method handles open state changes
@@ -385,7 +435,9 @@ class MuSelectItems extends MUElement {
385
435
  this.opened ? disableElementScroll() : enableElementScroll();
386
436
  break;
387
437
  case 'dynamic':
388
- this.opened ? window.addEventListener('scroll', this._calculateSizes) : window.removeEventListener('scroll', this._calculateSizes);
438
+ this.opened
439
+ ? window.addEventListener('scroll', this._calculateSizes)
440
+ : window.removeEventListener('scroll', this._calculateSizes);
389
441
  break;
390
442
  default:
391
443
  this.openMode;
@@ -441,7 +493,9 @@ class MuSelectItems extends MUElement {
441
493
  `;
442
494
  }
443
495
  }
444
- MuSelectItems.styles = [MUElement.cssBase, css `
496
+ MuSelectItems.styles = [
497
+ MUElement.cssBase,
498
+ css `
445
499
  #container {
446
500
  --select-items-background-color: var(--mu-select-items-background-color, var(--mu-color-800));
447
501
  --select-items-border-color: var(--mu-select-items-border-color, var(--mu-color-500));
@@ -485,7 +539,8 @@ MuSelectItems.styles = [MUElement.cssBase, css `
485
539
  --select-items-border-color: var(--mu-select-items-border-color, var(--mu-color-300));
486
540
  }
487
541
  }
488
- `];
542
+ `,
543
+ ];
489
544
  MuSelectItems.eventAction = new EventAction({
490
545
  currTargetSelector: 'mu-select-item',
491
546
  getEventAttributeName(eventName) {
@@ -497,7 +552,7 @@ MuSelectItems.eventAction = new EventAction({
497
552
  },
498
553
  closed({ event }) {
499
554
  return !event.currentTarget.opened;
500
- }
555
+ },
501
556
  },
502
557
  actions: {
503
558
  'toggle-select'(data) {
@@ -507,14 +562,14 @@ MuSelectItems.eventAction = new EventAction({
507
562
  const item = items._itemsValuesMap.get(data.actionParam);
508
563
  items._changeSelectState('toggle', item);
509
564
  },
510
- 'select'(data) {
565
+ select(data) {
511
566
  const items = data.event.currentTarget;
512
567
  if (!items.interactable)
513
568
  return;
514
569
  const item = items._itemsValuesMap.get(data.actionParam);
515
570
  items._changeSelectState('add', item);
516
571
  },
517
- 'unselect'(data) {
572
+ unselect(data) {
518
573
  const items = data.event.currentTarget;
519
574
  if (!items.interactable)
520
575
  return;
@@ -527,44 +582,51 @@ MuSelectItems.eventAction = new EventAction({
527
582
  return;
528
583
  const item = items._itemsValuesMap.get(data.actionParam);
529
584
  items._addActiveItemState(item);
530
- }
531
- }
585
+ },
586
+ },
532
587
  });
533
588
  __decorate([
534
589
  property({
535
- reflect: true, type: Boolean,
590
+ reflect: true,
591
+ type: Boolean,
536
592
  })
537
593
  ], MuSelectItems.prototype, "opened", void 0);
538
594
  __decorate([
539
- staticProperty({
540
- converter: Boolean,
595
+ property({
596
+ type: Boolean,
541
597
  })
542
598
  ], MuSelectItems.prototype, "multiple", void 0);
543
599
  __decorate([
544
600
  property({
545
- reflect: true, type: Array,
601
+ reflect: true,
602
+ type: Array,
546
603
  converter: {
547
- toAttribute(value, type) {
604
+ toAttribute(value, _type) {
548
605
  return Array.isArray(value) ? value.join(',') : value;
549
606
  },
550
- fromAttribute(value, type) {
607
+ fromAttribute(value, _type) {
551
608
  return value?.split(',');
552
- }
553
- }
609
+ },
610
+ },
554
611
  })
555
612
  ], MuSelectItems.prototype, "value", void 0);
556
613
  __decorate([
557
- staticProperty({ converter: Boolean })
614
+ property({
615
+ type: Boolean,
616
+ attribute: 'no-clear-active-on-close',
617
+ })
558
618
  ], MuSelectItems.prototype, "noClearActiveOnClose", void 0);
559
619
  __decorate([
560
- staticProperty()
620
+ property({
621
+ attribute: 'default-value',
622
+ })
561
623
  ], MuSelectItems.prototype, "defaultValue", void 0);
562
624
  __decorate([
563
- staticProperty()
625
+ property()
564
626
  ], MuSelectItems.prototype, "position", void 0);
565
627
  __decorate([
566
- staticProperty({ attribute: 'open-mode' })
628
+ property({ attribute: 'open-mode' })
567
629
  ], MuSelectItems.prototype, "openMode", void 0);
568
- MuSelectItems.register("mu-select-items");
630
+ MuSelectItems.register('mu-select-items');
569
631
 
570
632
  export { MuSelectItems };
@@ -2,6 +2,12 @@ import { CSSResultGroup } from 'lit';
2
2
  import { MUElement } from './mu-element.js';
3
3
  import '@mustib/utils/browser';
4
4
 
5
+ type MuSelectLabelContentComponent = {
6
+ attributes: {
7
+ type: MuSelectLabelContent['type'];
8
+ active: MuSelectLabelContent['active'];
9
+ };
10
+ };
5
11
  declare const types: readonly ["label", "value", "autocomplete", "template"];
6
12
  /**
7
13
  * Use this element to define custom markup for the label and value.
@@ -20,7 +26,7 @@ declare class MuSelectLabelContent extends MUElement {
20
26
  static generateTemplate(instance: MuSelectLabelContent): any;
21
27
  eventActionData: undefined;
22
28
  _addEventActionAttributes: undefined;
23
- type: typeof types[number];
29
+ type: (typeof types)[number];
24
30
  active: boolean;
25
31
  contentEl?: HTMLElement | null;
26
32
  activeTemplateValue?: string;
@@ -36,3 +42,4 @@ declare global {
36
42
  }
37
43
 
38
44
  export { MuSelectLabelContent };
45
+ export type { MuSelectLabelContentComponent };
@@ -1,8 +1,7 @@
1
- import { M as MUElement, _ as __decorate } from '../mu-element-CZDI_RCY.js';
1
+ import { M as MUElement, _ as __decorate } from '../mu-element-BTuCCJpo.js';
2
2
  import { css, nothing, html } from 'lit';
3
3
  import { property, state } from 'lit/decorators.js';
4
4
  import { repeat } from 'lit/directives/repeat.js';
5
- import '../decorators.js';
6
5
 
7
6
  const types = ['label', 'value', 'autocomplete', 'template'];
8
7
  const contentSelector = '[data-is="content"]';
@@ -28,12 +27,14 @@ class MuSelectLabelContent extends MUElement {
28
27
  */
29
28
  static generateTemplate(instance) {
30
29
  const value = instance._value;
31
- return value.length ? repeat(value, value => value, (v) => html `
30
+ return value.length
31
+ ? repeat(value, (value) => value, (v) => html `
32
32
  <div id='template' ?active=${v === instance.activeTemplateValue} part='template' data-select-pointerdown='#nothing&&#prevent'>
33
33
  <span id='template-value' part='template-value'>${v}</span>
34
34
  <mu-icon name='closeLine' id='template-remove' part='template-remove' data-select-click='remove-value:${v}'></mu-icon>
35
35
  </div>
36
- `) : nothing;
36
+ `)
37
+ : nothing;
37
38
  }
38
39
  async setValue(value) {
39
40
  await this.updateComplete;
@@ -43,20 +44,21 @@ class MuSelectLabelContent extends MUElement {
43
44
  case 'label':
44
45
  console.warn('mu-select-label-content with type="label" should not change the value', this);
45
46
  break;
46
- case "value":
47
+ case 'value':
47
48
  if (contentEl)
48
49
  contentEl.textContent = value.join(', ');
49
50
  else
50
51
  this.textContent = value.join(', ');
51
52
  break;
52
- case "autocomplete":
53
+ case 'autocomplete':
53
54
  if (contentEl && contentEl instanceof HTMLInputElement)
54
55
  contentEl.value = value.join(', ');
55
56
  else
56
57
  console.warn(`mu-select-label-content with type="autocomplete" should have an input element with ${contentSelector} attribute to change the value`, this);
57
58
  break;
58
- case "template":
59
- if (this.activeTemplateValue && !value.includes(this.activeTemplateValue))
59
+ case 'template':
60
+ if (this.activeTemplateValue &&
61
+ !value.includes(this.activeTemplateValue))
60
62
  this.activeTemplateValue = undefined;
61
63
  this.requestUpdate();
62
64
  break;
@@ -81,7 +83,9 @@ class MuSelectLabelContent extends MUElement {
81
83
  `;
82
84
  }
83
85
  }
84
- MuSelectLabelContent.styles = [MUElement.cssBase, css `
86
+ MuSelectLabelContent.styles = [
87
+ MUElement.cssBase,
88
+ css `
85
89
  :host {
86
90
  overflow: hidden;
87
91
  }
@@ -144,7 +148,8 @@ MuSelectLabelContent.styles = [MUElement.cssBase, css `
144
148
  --select-label-template-remove-background-color: var(--mu-select-label-template-remove-background-color ,var(--mu-color-200));
145
149
  }
146
150
  }
147
- `];
151
+ `,
152
+ ];
148
153
  __decorate([
149
154
  property()
150
155
  ], MuSelectLabelContent.prototype, "type", void 0);
@@ -6,6 +6,14 @@ import './mu-icon.js';
6
6
  import '@mustib/utils/browser';
7
7
  import './mu-transparent.js';
8
8
 
9
+ type MuSelectLabelComponent = {
10
+ attributes: {
11
+ opened: MuSelectLabel['opened'];
12
+ label: MuSelectLabel['label'];
13
+ legend: MuSelectLabel['legend'];
14
+ type: MuSelectLabel['type'];
15
+ };
16
+ };
9
17
  declare class MuSelectLabel extends MUElement {
10
18
  static styles: CSSResultGroup;
11
19
  opened: boolean;
@@ -50,3 +58,4 @@ declare global {
50
58
  }
51
59
 
52
60
  export { MuSelectLabel };
61
+ export type { MuSelectLabelComponent };