@ship-ui/core 0.15.28 → 0.15.29

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.
@@ -6562,6 +6562,82 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImpor
6562
6562
  args: ['drop', ['$event']]
6563
6563
  }] } });
6564
6564
 
6565
+ class ShipInputMaskDirective {
6566
+ constructor() {
6567
+ this.#selfRef = inject(ElementRef);
6568
+ this.#renderer = inject(Renderer2);
6569
+ this.shInputMask = input('(999) 999-9999', ...(ngDevMode ? [{ debugName: "shInputMask" }] : []));
6570
+ }
6571
+ #selfRef;
6572
+ #renderer;
6573
+ onInput(event) {
6574
+ const inputElement = this.#selfRef.nativeElement;
6575
+ const oldRawValue = inputElement.value;
6576
+ const newRawValue = event.target.value;
6577
+ const oldCursorPos = inputElement.selectionStart ?? 0;
6578
+ const newCleanValue = this.#cleanValue(newRawValue);
6579
+ const maskedValue = this.#applyMask(newCleanValue);
6580
+ this.#renderer.setProperty(inputElement, 'value', maskedValue);
6581
+ const newCursorPos = this.#getNewCursorPosition(maskedValue, oldRawValue, oldCursorPos);
6582
+ inputElement.setSelectionRange(newCursorPos, newCursorPos);
6583
+ }
6584
+ #getNewCursorPosition(maskedValue, oldRawValue, oldCursorPos) {
6585
+ let digitsBeforeCursor = 0;
6586
+ for (let i = 0; i < oldCursorPos; i++) {
6587
+ if (oldRawValue[i] && oldRawValue[i].match(/\d/)) {
6588
+ digitsBeforeCursor++;
6589
+ }
6590
+ }
6591
+ let newCursorPos = 0;
6592
+ let digitsFound = 0;
6593
+ while (newCursorPos < maskedValue.length && digitsFound < digitsBeforeCursor) {
6594
+ if (maskedValue[newCursorPos].match(/\d/)) {
6595
+ digitsFound++;
6596
+ }
6597
+ newCursorPos++;
6598
+ }
6599
+ return newCursorPos;
6600
+ }
6601
+ #cleanValue(value) {
6602
+ if (!value)
6603
+ return '';
6604
+ return value.replace(/\D/g, '');
6605
+ }
6606
+ #applyMask(cleanValue) {
6607
+ const inputMask = this.shInputMask();
6608
+ if (typeof inputMask === 'function') {
6609
+ return inputMask(cleanValue) ?? '';
6610
+ }
6611
+ const pattern = inputMask;
6612
+ let masked = '';
6613
+ let digitIndex = 0;
6614
+ for (let i = 0; i < pattern.length && digitIndex < cleanValue.length; i++) {
6615
+ const maskChar = pattern[i];
6616
+ const digitChar = cleanValue[digitIndex];
6617
+ if (maskChar === '9') {
6618
+ masked += digitChar;
6619
+ digitIndex++;
6620
+ }
6621
+ else {
6622
+ masked += maskChar;
6623
+ }
6624
+ }
6625
+ return masked;
6626
+ }
6627
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: ShipInputMaskDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
6628
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.0", type: ShipInputMaskDirective, isStandalone: true, selector: "[shInputMask]", inputs: { shInputMask: { classPropertyName: "shInputMask", publicName: "shInputMask", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "input": "onInput($event)" } }, ngImport: i0 }); }
6629
+ }
6630
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: ShipInputMaskDirective, decorators: [{
6631
+ type: Directive,
6632
+ args: [{
6633
+ selector: '[shInputMask]',
6634
+ standalone: true,
6635
+ }]
6636
+ }], propDecorators: { onInput: [{
6637
+ type: HostListener,
6638
+ args: ['input', ['$event']]
6639
+ }] } });
6640
+
6565
6641
  class ShipPreventWheelDirective {
6566
6642
  wheel(event) {
6567
6643
  event.preventDefault();
@@ -6792,5 +6868,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImpor
6792
6868
  * Generated bundle index. Do not edit.
6793
6869
  */
6794
6870
 
6795
- export { GridSortableDirective, SHIP_CONFIG, ShipAlertComponent, ShipAlertContainerComponent, ShipAlertModule, ShipAlertService, ShipBlueprintComponent, ShipButtonComponent, ShipButtonGroupComponent, ShipCardComponent, ShipCheckboxComponent, ShipChipComponent, ShipColorPickerComponent, ShipDatepickerComponent, ShipDatepickerInputComponent, ShipDaterangeInputComponent, ShipDialogComponent, ShipDialogService, ShipDividerComponent, ShipEventCardComponent, ShipFileDragDropDirective, ShipFileUploadComponent, ShipFormFieldComponent, ShipIconComponent, ShipListComponent, ShipMenuComponent, ShipPopoverComponent, ShipPreventWheelDirective, ShipProgressBarComponent, ShipRadioComponent, ShipRangeSliderComponent, ShipResizeDirective, ShipSelectComponent, ShipSidenavComponent, ShipSortDirective, ShipSortableComponent, ShipSortableDirective, ShipSpinnerComponent, ShipStepperComponent, ShipStickyColumnsDirective, ShipTableComponent, ShipTabsComponent, ShipToggleCardComponent, ShipToggleComponent, ShipTooltipComponent, ShipTooltipDirective, ShipTooltipWrapper, ShipVirtualScrollComponent, TEST_NODES, moveIndex, watchHostClass };
6871
+ export { GridSortableDirective, SHIP_CONFIG, ShipAlertComponent, ShipAlertContainerComponent, ShipAlertModule, ShipAlertService, ShipBlueprintComponent, ShipButtonComponent, ShipButtonGroupComponent, ShipCardComponent, ShipCheckboxComponent, ShipChipComponent, ShipColorPickerComponent, ShipDatepickerComponent, ShipDatepickerInputComponent, ShipDaterangeInputComponent, ShipDialogComponent, ShipDialogService, ShipDividerComponent, ShipEventCardComponent, ShipFileDragDropDirective, ShipFileUploadComponent, ShipFormFieldComponent, ShipIconComponent, ShipInputMaskDirective, ShipListComponent, ShipMenuComponent, ShipPopoverComponent, ShipPreventWheelDirective, ShipProgressBarComponent, ShipRadioComponent, ShipRangeSliderComponent, ShipResizeDirective, ShipSelectComponent, ShipSidenavComponent, ShipSortDirective, ShipSortableComponent, ShipSortableDirective, ShipSpinnerComponent, ShipStepperComponent, ShipStickyColumnsDirective, ShipTableComponent, ShipTabsComponent, ShipToggleCardComponent, ShipToggleComponent, ShipTooltipComponent, ShipTooltipDirective, ShipTooltipWrapper, ShipVirtualScrollComponent, TEST_NODES, moveIndex, watchHostClass };
6796
6872
  //# sourceMappingURL=ship-ui-core.mjs.map