@mustib/web-components 0.0.0-alpha.5 → 0.0.0-alpha.6

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.
@@ -29,6 +29,24 @@ type RangeFill = {
29
29
  };
30
30
  type ChangeEventSrc = 'pointerdown' | 'pointerup' | 'pointermove' | 'keydown' | 'insert';
31
31
  type Events = {
32
+ /**
33
+ * Emitted before change event
34
+ */
35
+ 'mu-range-start': CustomEvent<{
36
+ /**
37
+ * The source of start event
38
+ */
39
+ src: 'pointerdown' | 'keydown';
40
+ }>;
41
+ /**
42
+ * Emitted at the end of change event
43
+ */
44
+ 'mu-range-end': CustomEvent<{
45
+ /**
46
+ * The source of end event
47
+ */
48
+ src: 'pointerup' | 'keyup';
49
+ }>;
32
50
  /**
33
51
  * Emitted when pointerdown on a non-thumb element and empty-area attribute has a value of "dispatch".
34
52
  *
@@ -45,6 +63,9 @@ type Events = {
45
63
  name: string;
46
64
  value: number;
47
65
  }[];
66
+ /**
67
+ * The source of change event
68
+ */
48
69
  src: ChangeEventSrc;
49
70
  }>;
50
71
  /**
@@ -132,11 +153,28 @@ declare class MuRange extends MuElement {
132
153
  /**
133
154
  * this is used to prevent focus listener from running when the pointer is down otherwise active thumb will gain focus when the pointer is down
134
155
  */
135
- protected _isPointerDown: boolean;
156
+ protected get _isPointerDownStart(): boolean;
157
+ protected get _isKeyDownStart(): boolean;
158
+ /**
159
+ * the event that started change event
160
+ */
161
+ protected _startEvent?: 'pointerdown' | 'keydown';
162
+ protected get _hasStarted(): boolean;
136
163
  set activeThumb(thumb: RangeThumb | undefined);
137
164
  get activeThumb(): RangeThumb | undefined;
138
165
  constructor();
139
166
  disconnectedCallback(): void;
167
+ /**
168
+ * start thumb move
169
+ */
170
+ protected _start(data: {
171
+ activeThumb?: RangeThumb;
172
+ src: 'pointerdown' | 'keydown';
173
+ }): void;
174
+ /**
175
+ * end thumb move
176
+ */
177
+ protected _end(): void;
140
178
  /**
141
179
  *
142
180
  * @returns an array of objects containing the name and value of each thumb
@@ -153,6 +191,12 @@ declare class MuRange extends MuElement {
153
191
  * Switches the active thumb for keyboard navigation
154
192
  */
155
193
  switchNavigationActiveItem(direction: 'next' | 'prev'): boolean;
194
+ dispatchStartEvent(data: {
195
+ src: Events['mu-range-start']['detail']['src'];
196
+ }): void;
197
+ dispatchEndEvent(data: {
198
+ src: Events['mu-range-end']['detail']['src'];
199
+ }): void;
156
200
  dispatchChangeEvent(thumbs: {
157
201
  name: string;
158
202
  value: number;
@@ -202,6 +246,7 @@ declare class MuRange extends MuElement {
202
246
  */
203
247
  setValueFromString(valueString: string): Promise<void>;
204
248
  _keydownHandler: (e: KeyboardEvent) => void;
249
+ _documentKeyupHandler: () => void;
205
250
  _pointerdownHandler: (e: PointerEvent) => void;
206
251
  _documentPointerupHandler: (e: PointerEvent) => void;
207
252
  _pointermoveHandler: (e: PointerEvent) => void;
@@ -10,6 +10,18 @@ class MuRange extends MuElement {
10
10
  get isControlled() {
11
11
  return this.value !== undefined;
12
12
  }
13
+ /**
14
+ * this is used to prevent focus listener from running when the pointer is down otherwise active thumb will gain focus when the pointer is down
15
+ */
16
+ get _isPointerDownStart() {
17
+ return this._startEvent === 'pointerdown';
18
+ }
19
+ get _isKeyDownStart() {
20
+ return this._startEvent === 'keydown';
21
+ }
22
+ get _hasStarted() {
23
+ return this._startEvent !== undefined;
24
+ }
13
25
  set activeThumb(thumb) {
14
26
  if (thumb &&
15
27
  (thumb.element.transparent ||
@@ -64,10 +76,6 @@ class MuRange extends MuElement {
64
76
  this._thumbs = [];
65
77
  this._thumbsElementsMap = new Map();
66
78
  this._thumbsNamesMap = new Map();
67
- /**
68
- * this is used to prevent focus listener from running when the pointer is down otherwise active thumb will gain focus when the pointer is down
69
- */
70
- this._isPointerDown = false;
71
79
  this._slotChangeHandler = async () => {
72
80
  const previousThumbsElementsMap = new Map(this._thumbsElementsMap);
73
81
  this._thumbs = [];
@@ -188,6 +196,7 @@ class MuRange extends MuElement {
188
196
  const thumb = this.activeThumb;
189
197
  if (this.disabled || this.readonly || !thumb || e.defaultPrevented)
190
198
  return;
199
+ this.dispatchStartEvent({ src: 'keydown' });
191
200
  let increaseKey = 'ArrowRight';
192
201
  let decreaseKey = 'ArrowLeft';
193
202
  switch (this.axis) {
@@ -212,7 +221,15 @@ class MuRange extends MuElement {
212
221
  break;
213
222
  }
214
223
  const setValue = (value) => {
224
+ if (this._hasStarted && !this._isKeyDownStart)
225
+ return;
215
226
  e.preventDefault();
227
+ if (!this._isKeyDownStart) {
228
+ this._start({
229
+ activeThumb: thumb,
230
+ src: 'keydown',
231
+ });
232
+ }
216
233
  this.focus();
217
234
  thumb.element.focused = true;
218
235
  this._setThumbValue({ thumb, value, src: 'keydown' });
@@ -246,19 +263,25 @@ class MuRange extends MuElement {
246
263
  break;
247
264
  }
248
265
  };
266
+ this._documentKeyupHandler = () => {
267
+ this._end();
268
+ };
249
269
  this._pointerdownHandler = (e) => {
250
- if (this.disabled || this.readonly || e.defaultPrevented)
270
+ if (this.disabled ||
271
+ this.readonly ||
272
+ e.defaultPrevented ||
273
+ this._hasStarted)
251
274
  return;
252
- this._isPointerDown = true;
253
- document.addEventListener('pointermove', this._documentPointermoveHandler);
254
- document.addEventListener('pointerup', this._documentPointerupHandler);
255
275
  const thumbEl = MuElement.closestPierce('mu-range-thumb', e.target);
256
276
  if ((thumbEl && (thumbEl.disabled || thumbEl.readonly)) ||
257
277
  this.emptyArea === 'prevent')
258
278
  return;
259
279
  if (thumbEl && !thumbEl.transparent) {
260
280
  const activeThumb = this._thumbsElementsMap.get(thumbEl);
261
- this.activeThumb = activeThumb;
281
+ this._start({
282
+ activeThumb,
283
+ src: 'pointerdown',
284
+ });
262
285
  return;
263
286
  }
264
287
  if (this.emptyArea === 'dispatch') {
@@ -317,18 +340,19 @@ class MuRange extends MuElement {
317
340
  : rightThumb;
318
341
  }
319
342
  if (candidateThumb) {
343
+ this._start({
344
+ activeThumb: candidateThumb,
345
+ src: 'pointerdown',
346
+ });
320
347
  this._setThumbValue({ thumb: candidateThumb, value, src: 'pointerdown' });
321
- this.activeThumb = candidateThumb;
322
348
  }
323
349
  };
324
350
  this._documentPointerupHandler = (e) => {
325
- this._isPointerDown = false;
326
- document.removeEventListener('pointermove', this._documentPointermoveHandler);
327
- document.removeEventListener('pointerup', this._documentPointerupHandler);
328
- if (!this.activeThumb)
329
- return;
330
- const { value } = this._getValuesFromEvent(e);
331
- this._setThumbValue({ thumb: this.activeThumb, value, src: 'pointerup' });
351
+ if (this.activeThumb) {
352
+ const { value } = this._getValuesFromEvent(e);
353
+ this._setThumbValue({ thumb: this.activeThumb, value, src: 'pointerup' });
354
+ }
355
+ this._end();
332
356
  };
333
357
  this._pointermoveHandler = (e) => {
334
358
  if (!this.activeThumb)
@@ -349,7 +373,7 @@ class MuRange extends MuElement {
349
373
  }
350
374
  });
351
375
  this.addEventListener('focus', (e) => {
352
- if (this._isPointerDown ||
376
+ if (this._isPointerDownStart ||
353
377
  this.disabled ||
354
378
  this.readonly ||
355
379
  e.defaultPrevented)
@@ -369,6 +393,41 @@ class MuRange extends MuElement {
369
393
  disconnectedCallback() {
370
394
  document.removeEventListener('pointermove', this._documentPointermoveHandler);
371
395
  document.removeEventListener('pointerup', this._documentPointerupHandler);
396
+ document.removeEventListener('keyup', this._documentKeyupHandler);
397
+ }
398
+ /**
399
+ * start thumb move
400
+ */
401
+ _start(data) {
402
+ if (this._hasStarted)
403
+ return;
404
+ this._activeThumb = data.activeThumb;
405
+ if (!data.activeThumb)
406
+ return;
407
+ this._startEvent = data.src;
408
+ this.dispatchStartEvent({ src: data.src });
409
+ if (data.src === 'pointerdown') {
410
+ document.addEventListener('pointermove', this._documentPointermoveHandler);
411
+ document.addEventListener('pointerup', this._documentPointerupHandler);
412
+ }
413
+ if (data.src === 'keydown') {
414
+ document.addEventListener('keyup', this._documentKeyupHandler);
415
+ }
416
+ }
417
+ /**
418
+ * end thumb move
419
+ */
420
+ _end() {
421
+ document.removeEventListener('pointermove', this._documentPointermoveHandler);
422
+ document.removeEventListener('pointerup', this._documentPointerupHandler);
423
+ document.removeEventListener('keyup', this._documentKeyupHandler);
424
+ if (this._startEvent === 'pointerdown') {
425
+ this.dispatchEndEvent({ src: 'pointerup' });
426
+ }
427
+ if (this._startEvent === 'keydown') {
428
+ this.dispatchEndEvent({ src: 'keyup' });
429
+ }
430
+ this._startEvent = undefined;
372
431
  }
373
432
  /**
374
433
  *
@@ -414,6 +473,24 @@ class MuRange extends MuElement {
414
473
  navigationThumb.element.focused = true;
415
474
  return true;
416
475
  }
476
+ dispatchStartEvent(data) {
477
+ const eventName = 'mu-range-start';
478
+ this.dispatchEvent(new CustomEvent(eventName, {
479
+ bubbles: true,
480
+ composed: true,
481
+ cancelable: true,
482
+ detail: data,
483
+ }));
484
+ }
485
+ dispatchEndEvent(data) {
486
+ const eventName = 'mu-range-end';
487
+ this.dispatchEvent(new CustomEvent(eventName, {
488
+ bubbles: true,
489
+ composed: true,
490
+ cancelable: true,
491
+ detail: data,
492
+ }));
493
+ }
417
494
  dispatchChangeEvent(thumbs = this._thumbs, src) {
418
495
  const eventName = 'mu-range-change';
419
496
  const data = thumbs.map((thumb) => ({ name: thumb.name, value: thumb.value }));
@@ -36,7 +36,7 @@ declare class MuSelectLabel extends MuElement {
36
36
  setActiveDescendantId(id?: string): void;
37
37
  connectedCallback(): void;
38
38
  protected _assignLabelAndValueTypes(): void;
39
- get comboboxElement(): HTMLElement | MuSelectLabelContent | null | undefined;
39
+ get comboboxElement(): MuSelectLabelContent | HTMLElement | null | undefined;
40
40
  focus(options?: FocusOptions): void;
41
41
  protected _slotChangeHandler: () => void;
42
42
  protected firstUpdated(_changedProperties: PropertyValues): void;
package/package.json CHANGED
@@ -3,7 +3,10 @@
3
3
  "type": "module",
4
4
  "description": "A customizable web-components library with lit",
5
5
  "private": false,
6
- "version": "0.0.0-alpha.5",
6
+ "version": "0.0.0-alpha.6",
7
+ "lint-staged": {
8
+ "*.{js,ts,astro}": "biome check --write"
9
+ },
7
10
  "dependencies": {
8
11
  "@mustib/utils": "2.8.1"
9
12
  },
@@ -18,6 +21,8 @@
18
21
  "@tailwindcss/vite": "^4.1.12",
19
22
  "@types/node": "^24.9.2",
20
23
  "astro": "^5.12.8",
24
+ "husky": "^9.1.7",
25
+ "lint-staged": "^16.2.7",
21
26
  "rollup": "^4.52.5",
22
27
  "rollup-plugin-dts": "^6.2.3",
23
28
  "tailwindcss": "^4.1.12",