@mustib/web-components 0.0.0-alpha.3 → 0.0.0-alpha.4

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.
@@ -27,6 +27,7 @@ type RangeFill = {
27
27
  element: MuRangeFill;
28
28
  linkedThumbs: RangeThumb[];
29
29
  };
30
+ type ChangeEventSrc = 'pointerdown' | 'pointerup' | 'pointermove' | 'keydown' | 'insert';
30
31
  type Events = {
31
32
  /**
32
33
  * Emitted when pointerdown on a non-thumb element and empty-area attribute has a value of "dispatch".
@@ -44,6 +45,7 @@ type Events = {
44
45
  name: string;
45
46
  value: number;
46
47
  }[];
48
+ src: ChangeEventSrc;
47
49
  }>;
48
50
  /**
49
51
  * Emitted when new thumbs are added after the initial render.
@@ -151,11 +153,15 @@ declare class MuRange extends MuElement {
151
153
  * Switches the active thumb for keyboard navigation
152
154
  */
153
155
  switchNavigationActiveItem(direction: 'next' | 'prev'): boolean;
154
- dispatchChangeEvent(thumbs?: {
156
+ dispatchChangeEvent(thumbs: {
155
157
  name: string;
156
158
  value: number;
157
- }[]): void;
158
- _setThumbValue(thumb: RangeThumb, value: number): void;
159
+ }[] | undefined, src: ChangeEventSrc): void;
160
+ _setThumbValue({ src, thumb, value, }: {
161
+ thumb: RangeThumb;
162
+ value: number;
163
+ src: ChangeEventSrc;
164
+ }): void;
159
165
  /**
160
166
  * Updates the range fill element
161
167
  */
@@ -215,7 +215,7 @@ class MuRange extends MuElement {
215
215
  e.preventDefault();
216
216
  this.focus();
217
217
  thumb.element.focused = true;
218
- this._setThumbValue(thumb, value);
218
+ this._setThumbValue({ thumb, value, src: 'keydown' });
219
219
  };
220
220
  const jumpPercentage = 10;
221
221
  const jumpStepValue = (thumb.element.maxValue - thumb.element.minValue) / jumpPercentage;
@@ -317,7 +317,7 @@ class MuRange extends MuElement {
317
317
  : rightThumb;
318
318
  }
319
319
  if (candidateThumb) {
320
- this._setThumbValue(candidateThumb, value);
320
+ this._setThumbValue({ thumb: candidateThumb, value, src: 'pointerdown' });
321
321
  this.activeThumb = candidateThumb;
322
322
  }
323
323
  };
@@ -328,13 +328,13 @@ class MuRange extends MuElement {
328
328
  if (!this.activeThumb)
329
329
  return;
330
330
  const { value } = this._getValuesFromEvent(e);
331
- this._setThumbValue(this.activeThumb, value);
331
+ this._setThumbValue({ thumb: this.activeThumb, value, src: 'pointerup' });
332
332
  };
333
333
  this._pointermoveHandler = (e) => {
334
334
  if (!this.activeThumb)
335
335
  return;
336
336
  const { value } = this._getValuesFromEvent(e);
337
- this._setThumbValue(this.activeThumb, value);
337
+ this._setThumbValue({ thumb: this.activeThumb, value, src: 'pointermove' });
338
338
  };
339
339
  this._documentPointermoveHandler = throttle((e) => {
340
340
  this._pointermoveHandler(e);
@@ -390,7 +390,7 @@ class MuRange extends MuElement {
390
390
  const thumb = this._thumbsElementsMap.get(thumbEl);
391
391
  if (!thumb)
392
392
  return;
393
- this._setThumbValue(thumb, thumbEl.value);
393
+ this._setThumbValue({ thumb, value: thumb.value, src: 'insert' });
394
394
  this.activeThumb = thumb;
395
395
  }
396
396
  /**
@@ -414,17 +414,17 @@ class MuRange extends MuElement {
414
414
  navigationThumb.element.focused = true;
415
415
  return true;
416
416
  }
417
- dispatchChangeEvent(thumbs = this._thumbs) {
417
+ dispatchChangeEvent(thumbs = this._thumbs, src) {
418
418
  const eventName = 'mu-range-change';
419
419
  const data = thumbs.map((thumb) => ({ name: thumb.name, value: thumb.value }));
420
420
  this.dispatchEvent(new CustomEvent(eventName, {
421
421
  bubbles: true,
422
422
  composed: true,
423
- detail: { data: data },
423
+ detail: { data: data, src },
424
424
  cancelable: true,
425
425
  }));
426
426
  }
427
- _setThumbValue(thumb, value) {
427
+ _setThumbValue({ src, thumb, value, }) {
428
428
  const stepValue = this._getThumbStepValue(thumb, value);
429
429
  if (stepValue === thumb.value)
430
430
  return;
@@ -434,7 +434,7 @@ class MuRange extends MuElement {
434
434
  name: _thumb.name,
435
435
  value: _thumb.name === thumb.name ? stepValue : thumb.value,
436
436
  }));
437
- this.dispatchChangeEvent(sortedThumbs);
437
+ this.dispatchChangeEvent(sortedThumbs, src);
438
438
  return;
439
439
  }
440
440
  const success = thumb.element.setValue(stepValue);
@@ -442,7 +442,7 @@ class MuRange extends MuElement {
442
442
  thumb.value = stepValue;
443
443
  this.sortThumbs();
444
444
  thumb.linkedFillElements?.forEach(this.updateRangeFill);
445
- this.dispatchChangeEvent();
445
+ this.dispatchChangeEvent(undefined, src);
446
446
  }
447
447
  }
448
448
  /**
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "description": "A customizable web-components library with lit",
5
5
  "private": false,
6
- "version": "0.0.0-alpha.3",
6
+ "version": "0.0.0-alpha.4",
7
7
  "dependencies": {
8
8
  "@mustib/utils": "2.7.0"
9
9
  },