@nectary/components 5.61.0 → 5.62.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.
package/bundle.js CHANGED
@@ -6767,7 +6767,7 @@ class Dialog extends NectaryElement {
6767
6767
  };
6768
6768
  }
6769
6769
  defineCustomElement("sinch-dialog", Dialog);
6770
- const inputTypes = ["text", "password", "number"];
6770
+ const inputTypes = ["text", "password", "number", "email"];
6771
6771
  const MASK_SYMBOL_LETTER = "A";
6772
6772
  const MASK_SYMBOL_DIGIT = "0";
6773
6773
  const EMPTY_CHAR = " ";
@@ -7268,7 +7268,7 @@ class Input extends NectaryElement {
7268
7268
  break;
7269
7269
  }
7270
7270
  case "type": {
7271
- updateLiteralAttribute(this.#$input, inputTypes, "type", newVal);
7271
+ this.#applyNativeType();
7272
7272
  updateAttribute(this.#$input, "spellcheck", newVal === "password" ? "false" : null);
7273
7273
  this.#updateInputRole();
7274
7274
  this.#updateAriaValueAttributes();
@@ -7435,21 +7435,39 @@ class Input extends NectaryElement {
7435
7435
  return getAttribute(this, "autocomplete", "");
7436
7436
  }
7437
7437
  get selectionStart() {
7438
+ if (!this.#canSetSelection()) {
7439
+ return null;
7440
+ }
7438
7441
  return this.#$input.selectionStart;
7439
7442
  }
7440
7443
  set selectionStart(value) {
7444
+ if (!this.#canSetSelection()) {
7445
+ return;
7446
+ }
7441
7447
  this.#$input.selectionStart = value;
7442
7448
  }
7443
7449
  get selectionEnd() {
7450
+ if (!this.#canSetSelection()) {
7451
+ return null;
7452
+ }
7444
7453
  return this.#$input.selectionEnd;
7445
7454
  }
7446
7455
  set selectionEnd(value) {
7456
+ if (!this.#canSetSelection()) {
7457
+ return;
7458
+ }
7447
7459
  this.#$input.selectionEnd = value;
7448
7460
  }
7449
7461
  get selectionDirection() {
7462
+ if (!this.#canSetSelection()) {
7463
+ return null;
7464
+ }
7450
7465
  return this.#$input.selectionDirection;
7451
7466
  }
7452
7467
  set selectionDirection(value) {
7468
+ if (!this.#canSetSelection()) {
7469
+ return;
7470
+ }
7453
7471
  this.#$input.selectionDirection = value;
7454
7472
  }
7455
7473
  setSelectionRange(selectionStart, selectionEnd) {
@@ -7470,15 +7488,43 @@ class Input extends NectaryElement {
7470
7488
  blur() {
7471
7489
  this.#$input.blur();
7472
7490
  }
7491
+ // The native control exposes a caret for text and password. number and email throw.
7492
+ #canSetSelection() {
7493
+ const type = this.#$input.type;
7494
+ return type === "text" || type === "password";
7495
+ }
7496
+ // A mask rewrites the value from the caret. Email cannot report one, so the
7497
+ // native control is text while the mask is on. The host type stays email.
7498
+ #applyNativeType() {
7499
+ if (this.#maskSymbols !== null && this.type === "email") {
7500
+ this.#$input.type = "text";
7501
+ return;
7502
+ }
7503
+ updateLiteralAttribute(this.#$input, inputTypes, "type", this.getAttribute("type"));
7504
+ }
7505
+ #readSelection() {
7506
+ if (!this.#canSetSelection()) {
7507
+ return null;
7508
+ }
7509
+ return {
7510
+ start: this.#$input.selectionStart ?? 0,
7511
+ end: this.#$input.selectionEnd ?? 0
7512
+ };
7513
+ }
7473
7514
  #setSelectionRange = (start, end, direction) => {
7474
- if (this.type !== "number") {
7475
- this.#$input.setSelectionRange(start, end, direction);
7515
+ if (!this.#canSetSelection()) {
7516
+ return;
7476
7517
  }
7518
+ this.#$input.setSelectionRange(start, end, direction);
7477
7519
  };
7478
7520
  #onCompositionStart = () => {
7479
7521
  this.#isCompositionInProgress = true;
7480
7522
  if (this.#maskSymbols !== null) {
7481
- const selectionStart = this.#$input.selectionStart;
7523
+ const selection = this.#readSelection();
7524
+ if (selection === null) {
7525
+ return;
7526
+ }
7527
+ const selectionStart = selection.start;
7482
7528
  this.#compositionBeginValue = this.#$input.value;
7483
7529
  if (selectionStart === this.#$input.value.length) {
7484
7530
  return;
@@ -7495,7 +7541,11 @@ class Input extends NectaryElement {
7495
7541
  if (this.#maskSymbols !== null) {
7496
7542
  const value = this.#$input.value;
7497
7543
  const wasValueInserted = value.length !== this.#compositionBeginValue.length;
7498
- const res = endMaskedComposition(value, e.data, this.#maskSymbols, this.#$input.selectionStart, wasValueInserted);
7544
+ const selectionStart = this.#readSelection()?.start;
7545
+ if (selectionStart === void 0) {
7546
+ return;
7547
+ }
7548
+ const res = endMaskedComposition(value, e.data, this.#maskSymbols, selectionStart, wasValueInserted);
7499
7549
  this.#compositionBeginValue = "";
7500
7550
  if (res !== null) {
7501
7551
  const { value: value2, placeholder, mergedValue, cursorPos } = res;
@@ -7516,13 +7566,20 @@ class Input extends NectaryElement {
7516
7566
  }
7517
7567
  };
7518
7568
  #onMaskBeforeInput = (e) => {
7569
+ if (this.#readSelection() === null) {
7570
+ return;
7571
+ }
7519
7572
  this.#handleMaskBeforeInput(e.inputType, e.data);
7520
7573
  e.preventDefault();
7521
7574
  };
7522
7575
  #handleMaskBeforeInput(inputType, data2) {
7523
7576
  this.#wasClearedByMask = false;
7524
- const selectionStart = this.#$input.selectionStart ?? 0;
7525
- const selectionEnd = this.#$input.selectionEnd ?? 0;
7577
+ const selection = this.#readSelection();
7578
+ if (selection === null) {
7579
+ return;
7580
+ }
7581
+ const selectionStart = selection.start;
7582
+ const selectionEnd = selection.end;
7526
7583
  let res = null;
7527
7584
  switch (inputType) {
7528
7585
  case "insertText": {
@@ -7560,8 +7617,12 @@ class Input extends NectaryElement {
7560
7617
  }
7561
7618
  }
7562
7619
  #handleBeforeInput(inputType, data2) {
7563
- const selectionStart = this.#$input.selectionStart ?? 0;
7564
- const selectionEnd = this.#$input.selectionEnd ?? 0;
7620
+ const selection = this.#readSelection();
7621
+ if (selection === null) {
7622
+ return;
7623
+ }
7624
+ const selectionStart = selection.start;
7625
+ const selectionEnd = selection.end;
7565
7626
  const value = this.#$input.value;
7566
7627
  switch (inputType) {
7567
7628
  case "insertFromPaste": {
@@ -7596,14 +7657,15 @@ class Input extends NectaryElement {
7596
7657
  const prevValue = this.#previousValue;
7597
7658
  setFormValue(this.#internals, nextValue);
7598
7659
  if (prevValue !== nextValue) {
7599
- const nextSelectionStart = this.#$input.selectionStart;
7600
- const nextSelectionEnd = this.#$input.selectionEnd;
7601
- if (this.#isControlledInput === true && this.hasAttribute("value") === true) {
7660
+ const selection = this.#readSelection();
7661
+ if (this.type !== "email" && this.#isControlledInput === true && this.hasAttribute("value") === true) {
7602
7662
  this.#$input.value = prevValue;
7603
7663
  this.#setSelectionRange(this.#selectionStart, this.#selectionEnd);
7604
7664
  }
7605
- this.#selectionStart = nextSelectionStart;
7606
- this.#selectionEnd = nextSelectionEnd;
7665
+ if (selection !== null) {
7666
+ this.#selectionStart = selection.start;
7667
+ this.#selectionEnd = selection.end;
7668
+ }
7607
7669
  this.#dispatchChangeEvent(nextValue);
7608
7670
  }
7609
7671
  };
@@ -7630,12 +7692,11 @@ class Input extends NectaryElement {
7630
7692
  };
7631
7693
  #onCopy = (e) => {
7632
7694
  const value = this.#$input.value;
7633
- const selectionStart = this.#$input.selectionStart ?? 0;
7634
- const selectionEnd = this.#$input.selectionEnd ?? 0;
7635
- if (e.clipboardData === null || selectionStart === selectionEnd) {
7695
+ const selection = this.#readSelection();
7696
+ if (e.clipboardData === null || selection === null || selection.start === selection.end) {
7636
7697
  return;
7637
7698
  }
7638
- const copiedValue = this.#maskSymbols === null ? value.substring(selectionStart, selectionEnd) : getMergedValueSliced(value, this.#maskSymbols, selectionStart, selectionEnd);
7699
+ const copiedValue = this.#maskSymbols === null ? value.substring(selection.start, selection.end) : getMergedValueSliced(value, this.#maskSymbols, selection.start, selection.end);
7639
7700
  let replacedValue = null;
7640
7701
  const replaceWith = (value2) => {
7641
7702
  replacedValue = value2 ?? null;
@@ -7661,12 +7722,11 @@ class Input extends NectaryElement {
7661
7722
  };
7662
7723
  #onCut = (e) => {
7663
7724
  const value = this.#$input.value;
7664
- const selectionStart = this.#$input.selectionStart ?? 0;
7665
- const selectionEnd = this.#$input.selectionEnd ?? 0;
7666
- if (e.clipboardData === null || selectionStart === selectionEnd) {
7725
+ const selection = this.#readSelection();
7726
+ if (e.clipboardData === null || selection === null || selection.start === selection.end) {
7667
7727
  return;
7668
7728
  }
7669
- const copiedValue = this.#maskSymbols === null ? value.substring(selectionStart, selectionEnd) : getMergedValueSliced(value, this.#maskSymbols, selectionStart, selectionEnd);
7729
+ const copiedValue = this.#maskSymbols === null ? value.substring(selection.start, selection.end) : getMergedValueSliced(value, this.#maskSymbols, selection.start, selection.end);
7670
7730
  let replacedValue = null;
7671
7731
  const replaceWith = (value2) => {
7672
7732
  replacedValue = value2 ?? null;
@@ -7716,6 +7776,10 @@ class Input extends NectaryElement {
7716
7776
  return;
7717
7777
  }
7718
7778
  e.preventDefault();
7779
+ if (this.#readSelection() === null) {
7780
+ document.execCommand("insertText", false, replacedValue);
7781
+ return;
7782
+ }
7719
7783
  if (this.#maskSymbols !== null) {
7720
7784
  this.#handleMaskBeforeInput("insertFromPaste", replacedValue);
7721
7785
  } else {
@@ -7758,6 +7822,7 @@ class Input extends NectaryElement {
7758
7822
  this.#$input.addEventListener("change", this.#onMaskInputAutofillChange, { signal: this.#controller.signal });
7759
7823
  }
7760
7824
  this.#maskSymbols = getMaskSymbols(this.mask);
7825
+ this.#applyNativeType();
7761
7826
  const { value, placeholder } = splitValueAndMask(this.#$input.value, this.#maskSymbols);
7762
7827
  this.#$input.value = value;
7763
7828
  this.#$inputMask.textContent = placeholder;
@@ -7765,6 +7830,7 @@ class Input extends NectaryElement {
7765
7830
  this.#maskSymbols = null;
7766
7831
  this.#$input.removeEventListener("beforeinput", this.#onMaskBeforeInput);
7767
7832
  this.#$input.removeEventListener("change", this.#onMaskInputAutofillChange);
7833
+ this.#applyNativeType();
7768
7834
  }
7769
7835
  this.#updatePlaceholder();
7770
7836
  }
package/input/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Context, subscribeContext } from "../utils/context.js";
2
- import { getBooleanAttribute, getAttribute, updateAttribute, isAttrEqual, isAttrTrue, updateBooleanAttribute, updateLiteralAttribute, getLiteralAttribute, setClass } from "../utils/dom.js";
2
+ import { getBooleanAttribute, getAttribute, updateAttribute, isAttrEqual, isAttrTrue, updateBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, setClass } from "../utils/dom.js";
3
3
  import { defineCustomElement, NectaryElement } from "../utils/element.js";
4
4
  import { isElementFocused } from "../utils/slot.js";
5
5
  import { getReactEventHandler } from "../utils/get-react-event-handler.js";
@@ -207,7 +207,7 @@ class Input extends NectaryElement {
207
207
  break;
208
208
  }
209
209
  case "type": {
210
- updateLiteralAttribute(this.#$input, inputTypes, "type", newVal);
210
+ this.#applyNativeType();
211
211
  updateAttribute(this.#$input, "spellcheck", newVal === "password" ? "false" : null);
212
212
  this.#updateInputRole();
213
213
  this.#updateAriaValueAttributes();
@@ -374,21 +374,39 @@ class Input extends NectaryElement {
374
374
  return getAttribute(this, "autocomplete", "");
375
375
  }
376
376
  get selectionStart() {
377
+ if (!this.#canSetSelection()) {
378
+ return null;
379
+ }
377
380
  return this.#$input.selectionStart;
378
381
  }
379
382
  set selectionStart(value) {
383
+ if (!this.#canSetSelection()) {
384
+ return;
385
+ }
380
386
  this.#$input.selectionStart = value;
381
387
  }
382
388
  get selectionEnd() {
389
+ if (!this.#canSetSelection()) {
390
+ return null;
391
+ }
383
392
  return this.#$input.selectionEnd;
384
393
  }
385
394
  set selectionEnd(value) {
395
+ if (!this.#canSetSelection()) {
396
+ return;
397
+ }
386
398
  this.#$input.selectionEnd = value;
387
399
  }
388
400
  get selectionDirection() {
401
+ if (!this.#canSetSelection()) {
402
+ return null;
403
+ }
389
404
  return this.#$input.selectionDirection;
390
405
  }
391
406
  set selectionDirection(value) {
407
+ if (!this.#canSetSelection()) {
408
+ return;
409
+ }
392
410
  this.#$input.selectionDirection = value;
393
411
  }
394
412
  setSelectionRange(selectionStart, selectionEnd) {
@@ -409,15 +427,43 @@ class Input extends NectaryElement {
409
427
  blur() {
410
428
  this.#$input.blur();
411
429
  }
430
+ // The native control exposes a caret for text and password. number and email throw.
431
+ #canSetSelection() {
432
+ const type = this.#$input.type;
433
+ return type === "text" || type === "password";
434
+ }
435
+ // A mask rewrites the value from the caret. Email cannot report one, so the
436
+ // native control is text while the mask is on. The host type stays email.
437
+ #applyNativeType() {
438
+ if (this.#maskSymbols !== null && this.type === "email") {
439
+ this.#$input.type = "text";
440
+ return;
441
+ }
442
+ updateLiteralAttribute(this.#$input, inputTypes, "type", this.getAttribute("type"));
443
+ }
444
+ #readSelection() {
445
+ if (!this.#canSetSelection()) {
446
+ return null;
447
+ }
448
+ return {
449
+ start: this.#$input.selectionStart ?? 0,
450
+ end: this.#$input.selectionEnd ?? 0
451
+ };
452
+ }
412
453
  #setSelectionRange = (start, end, direction) => {
413
- if (this.type !== "number") {
414
- this.#$input.setSelectionRange(start, end, direction);
454
+ if (!this.#canSetSelection()) {
455
+ return;
415
456
  }
457
+ this.#$input.setSelectionRange(start, end, direction);
416
458
  };
417
459
  #onCompositionStart = () => {
418
460
  this.#isCompositionInProgress = true;
419
461
  if (this.#maskSymbols !== null) {
420
- const selectionStart = this.#$input.selectionStart;
462
+ const selection = this.#readSelection();
463
+ if (selection === null) {
464
+ return;
465
+ }
466
+ const selectionStart = selection.start;
421
467
  this.#compositionBeginValue = this.#$input.value;
422
468
  if (selectionStart === this.#$input.value.length) {
423
469
  return;
@@ -434,7 +480,11 @@ class Input extends NectaryElement {
434
480
  if (this.#maskSymbols !== null) {
435
481
  const value = this.#$input.value;
436
482
  const wasValueInserted = value.length !== this.#compositionBeginValue.length;
437
- const res = endMaskedComposition(value, e.data, this.#maskSymbols, this.#$input.selectionStart, wasValueInserted);
483
+ const selectionStart = this.#readSelection()?.start;
484
+ if (selectionStart === void 0) {
485
+ return;
486
+ }
487
+ const res = endMaskedComposition(value, e.data, this.#maskSymbols, selectionStart, wasValueInserted);
438
488
  this.#compositionBeginValue = "";
439
489
  if (res !== null) {
440
490
  const { value: value2, placeholder, mergedValue, cursorPos } = res;
@@ -455,13 +505,20 @@ class Input extends NectaryElement {
455
505
  }
456
506
  };
457
507
  #onMaskBeforeInput = (e) => {
508
+ if (this.#readSelection() === null) {
509
+ return;
510
+ }
458
511
  this.#handleMaskBeforeInput(e.inputType, e.data);
459
512
  e.preventDefault();
460
513
  };
461
514
  #handleMaskBeforeInput(inputType, data) {
462
515
  this.#wasClearedByMask = false;
463
- const selectionStart = this.#$input.selectionStart ?? 0;
464
- const selectionEnd = this.#$input.selectionEnd ?? 0;
516
+ const selection = this.#readSelection();
517
+ if (selection === null) {
518
+ return;
519
+ }
520
+ const selectionStart = selection.start;
521
+ const selectionEnd = selection.end;
465
522
  let res = null;
466
523
  switch (inputType) {
467
524
  case "insertText": {
@@ -499,8 +556,12 @@ class Input extends NectaryElement {
499
556
  }
500
557
  }
501
558
  #handleBeforeInput(inputType, data) {
502
- const selectionStart = this.#$input.selectionStart ?? 0;
503
- const selectionEnd = this.#$input.selectionEnd ?? 0;
559
+ const selection = this.#readSelection();
560
+ if (selection === null) {
561
+ return;
562
+ }
563
+ const selectionStart = selection.start;
564
+ const selectionEnd = selection.end;
504
565
  const value = this.#$input.value;
505
566
  switch (inputType) {
506
567
  case "insertFromPaste": {
@@ -535,14 +596,15 @@ class Input extends NectaryElement {
535
596
  const prevValue = this.#previousValue;
536
597
  setFormValue(this.#internals, nextValue);
537
598
  if (prevValue !== nextValue) {
538
- const nextSelectionStart = this.#$input.selectionStart;
539
- const nextSelectionEnd = this.#$input.selectionEnd;
540
- if (this.#isControlledInput === true && this.hasAttribute("value") === true) {
599
+ const selection = this.#readSelection();
600
+ if (this.type !== "email" && this.#isControlledInput === true && this.hasAttribute("value") === true) {
541
601
  this.#$input.value = prevValue;
542
602
  this.#setSelectionRange(this.#selectionStart, this.#selectionEnd);
543
603
  }
544
- this.#selectionStart = nextSelectionStart;
545
- this.#selectionEnd = nextSelectionEnd;
604
+ if (selection !== null) {
605
+ this.#selectionStart = selection.start;
606
+ this.#selectionEnd = selection.end;
607
+ }
546
608
  this.#dispatchChangeEvent(nextValue);
547
609
  }
548
610
  };
@@ -569,12 +631,11 @@ class Input extends NectaryElement {
569
631
  };
570
632
  #onCopy = (e) => {
571
633
  const value = this.#$input.value;
572
- const selectionStart = this.#$input.selectionStart ?? 0;
573
- const selectionEnd = this.#$input.selectionEnd ?? 0;
574
- if (e.clipboardData === null || selectionStart === selectionEnd) {
634
+ const selection = this.#readSelection();
635
+ if (e.clipboardData === null || selection === null || selection.start === selection.end) {
575
636
  return;
576
637
  }
577
- const copiedValue = this.#maskSymbols === null ? value.substring(selectionStart, selectionEnd) : getMergedValueSliced(value, this.#maskSymbols, selectionStart, selectionEnd);
638
+ const copiedValue = this.#maskSymbols === null ? value.substring(selection.start, selection.end) : getMergedValueSliced(value, this.#maskSymbols, selection.start, selection.end);
578
639
  let replacedValue = null;
579
640
  const replaceWith = (value2) => {
580
641
  replacedValue = value2 ?? null;
@@ -600,12 +661,11 @@ class Input extends NectaryElement {
600
661
  };
601
662
  #onCut = (e) => {
602
663
  const value = this.#$input.value;
603
- const selectionStart = this.#$input.selectionStart ?? 0;
604
- const selectionEnd = this.#$input.selectionEnd ?? 0;
605
- if (e.clipboardData === null || selectionStart === selectionEnd) {
664
+ const selection = this.#readSelection();
665
+ if (e.clipboardData === null || selection === null || selection.start === selection.end) {
606
666
  return;
607
667
  }
608
- const copiedValue = this.#maskSymbols === null ? value.substring(selectionStart, selectionEnd) : getMergedValueSliced(value, this.#maskSymbols, selectionStart, selectionEnd);
668
+ const copiedValue = this.#maskSymbols === null ? value.substring(selection.start, selection.end) : getMergedValueSliced(value, this.#maskSymbols, selection.start, selection.end);
609
669
  let replacedValue = null;
610
670
  const replaceWith = (value2) => {
611
671
  replacedValue = value2 ?? null;
@@ -655,6 +715,10 @@ class Input extends NectaryElement {
655
715
  return;
656
716
  }
657
717
  e.preventDefault();
718
+ if (this.#readSelection() === null) {
719
+ document.execCommand("insertText", false, replacedValue);
720
+ return;
721
+ }
658
722
  if (this.#maskSymbols !== null) {
659
723
  this.#handleMaskBeforeInput("insertFromPaste", replacedValue);
660
724
  } else {
@@ -697,6 +761,7 @@ class Input extends NectaryElement {
697
761
  this.#$input.addEventListener("change", this.#onMaskInputAutofillChange, { signal: this.#controller.signal });
698
762
  }
699
763
  this.#maskSymbols = getMaskSymbols(this.mask);
764
+ this.#applyNativeType();
700
765
  const { value, placeholder } = splitValueAndMask(this.#$input.value, this.#maskSymbols);
701
766
  this.#$input.value = value;
702
767
  this.#$inputMask.textContent = placeholder;
@@ -704,6 +769,7 @@ class Input extends NectaryElement {
704
769
  this.#maskSymbols = null;
705
770
  this.#$input.removeEventListener("beforeinput", this.#onMaskBeforeInput);
706
771
  this.#$input.removeEventListener("change", this.#onMaskInputAutofillChange);
772
+ this.#applyNativeType();
707
773
  }
708
774
  this.#updatePlaceholder();
709
775
  }
package/input/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { NectaryComponentReactByType, NectaryComponentVanillaByType, NectaryComponentVanilla, NectaryComponentReact } from '../types';
2
2
  import type { TSinchSize } from '../utils/size';
3
- export type TSinchInputType = 'text' | 'password' | 'number';
3
+ export type TSinchInputType = 'text' | 'password' | 'number' | 'email';
4
4
  export type TSinchInputClipboardEvent = CustomEvent<{
5
5
  value: string;
6
6
  replaceWith: (value: string) => void;
package/input/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- const inputTypes = ["text", "password", "number"];
1
+ const inputTypes = ["text", "password", "number", "email"];
2
2
  const MASK_SYMBOL_LETTER = "A";
3
3
  const MASK_SYMBOL_DIGIT = "0";
4
4
  const EMPTY_CHAR = " ";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "5.61.0",
3
+ "version": "5.62.0",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",