osl-base-extended 18.4.1 → 20.1.1
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.
|
@@ -1529,6 +1529,13 @@ class Oslinput {
|
|
|
1529
1529
|
const isNumeric = this.type === 'number' || this.type === 'int' || this.decimalPortion !== null;
|
|
1530
1530
|
return isNumeric && !this.allowNegative ? 0 : null;
|
|
1531
1531
|
}
|
|
1532
|
+
/**
|
|
1533
|
+
* Native maxlength would count the display commas, so decimal fields enforce maxLength
|
|
1534
|
+
* on the raw value instead (see onKeyDown / onModelChange). Other inputs are unchanged.
|
|
1535
|
+
*/
|
|
1536
|
+
get maxLengthAttr() {
|
|
1537
|
+
return this.decimalPortion !== null ? null : this.maxLength;
|
|
1538
|
+
}
|
|
1532
1539
|
modelChange = new EventEmitter();
|
|
1533
1540
|
changeEv = new EventEmitter();
|
|
1534
1541
|
showPassword = false;
|
|
@@ -1540,6 +1547,29 @@ class Oslinput {
|
|
|
1540
1547
|
return 'text';
|
|
1541
1548
|
return this.type;
|
|
1542
1549
|
}
|
|
1550
|
+
/**
|
|
1551
|
+
* Value shown in the input. Decimal fields get thousands separators (e.g. 1234567.5 -> 1,234,567.50),
|
|
1552
|
+
* both while typing and when disabled. The bound model / emitted value always stays raw (no commas).
|
|
1553
|
+
*/
|
|
1554
|
+
get displayModel() {
|
|
1555
|
+
if (this.decimalPortion === null)
|
|
1556
|
+
return this.model;
|
|
1557
|
+
if (this.model === null || this.model === undefined || this.model === '')
|
|
1558
|
+
return this.model;
|
|
1559
|
+
let raw = String(this.model);
|
|
1560
|
+
if (this.disabled)
|
|
1561
|
+
raw = this.formatDecimal(raw);
|
|
1562
|
+
return this.groupThousands(raw);
|
|
1563
|
+
}
|
|
1564
|
+
/** Inserts commas into the integer part only; keeps the (possibly partial) decimal part as typed. */
|
|
1565
|
+
groupThousands(value) {
|
|
1566
|
+
const isNegative = value.startsWith('-');
|
|
1567
|
+
const body = isNegative ? value.slice(1) : value;
|
|
1568
|
+
const dotIndex = body.indexOf('.');
|
|
1569
|
+
const intPart = dotIndex === -1 ? body : body.slice(0, dotIndex);
|
|
1570
|
+
const fracPart = dotIndex === -1 ? '' : body.slice(dotIndex);
|
|
1571
|
+
return (isNegative ? '-' : '') + intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',') + fracPart;
|
|
1572
|
+
}
|
|
1543
1573
|
get hasWrapper() {
|
|
1544
1574
|
return !!(this.prefixIcon || this.suffixIcon || this.type === 'password');
|
|
1545
1575
|
}
|
|
@@ -1640,6 +1670,11 @@ class Oslinput {
|
|
|
1640
1670
|
event.preventDefault();
|
|
1641
1671
|
return;
|
|
1642
1672
|
}
|
|
1673
|
+
if (this.maxLength !== null &&
|
|
1674
|
+
this.valueOutsideSelection(event.target).replace(/,/g, '').length >= this.maxLength) {
|
|
1675
|
+
event.preventDefault();
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1643
1678
|
if (key === '.' && (this.decimalPortion === 0 || this.valueOutsideSelection(event.target).includes('.'))) {
|
|
1644
1679
|
event.preventDefault();
|
|
1645
1680
|
return;
|
|
@@ -1721,10 +1756,15 @@ class Oslinput {
|
|
|
1721
1756
|
return true;
|
|
1722
1757
|
return false;
|
|
1723
1758
|
}
|
|
1724
|
-
onModelChange(value) {
|
|
1759
|
+
onModelChange(value, inputEl) {
|
|
1725
1760
|
if (this.decimalPortion !== null) {
|
|
1726
|
-
|
|
1761
|
+
let cleaned = this.cleanDecimalInput(value);
|
|
1762
|
+
if (this.maxLength !== null && cleaned.length > this.maxLength) {
|
|
1763
|
+
cleaned = cleaned.slice(0, this.maxLength); // e.g. paste — mirrors native maxlength truncation
|
|
1764
|
+
}
|
|
1727
1765
|
this.model = cleaned;
|
|
1766
|
+
if (inputEl)
|
|
1767
|
+
this.reformatWithCaret(inputEl);
|
|
1728
1768
|
this.modelChange.emit(this.model);
|
|
1729
1769
|
return;
|
|
1730
1770
|
}
|
|
@@ -1752,6 +1792,28 @@ class Oslinput {
|
|
|
1752
1792
|
this.model = processed;
|
|
1753
1793
|
this.modelChange.emit(this.model);
|
|
1754
1794
|
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Writes the comma-grouped display value straight into the input and restores the caret,
|
|
1797
|
+
* so inserting/removing commas while typing doesn't jump the cursor to the end.
|
|
1798
|
+
*/
|
|
1799
|
+
reformatWithCaret(inputEl) {
|
|
1800
|
+
const typed = inputEl.value;
|
|
1801
|
+
const caret = inputEl.selectionStart ?? typed.length;
|
|
1802
|
+
// Count meaningful (non-comma) chars before the caret, then find the same spot in the new string.
|
|
1803
|
+
const charsBeforeCaret = typed.slice(0, caret).replace(/,/g, '').length;
|
|
1804
|
+
const display = this.displayModel == null ? '' : String(this.displayModel);
|
|
1805
|
+
if (display === typed)
|
|
1806
|
+
return;
|
|
1807
|
+
inputEl.value = display;
|
|
1808
|
+
let pos = 0;
|
|
1809
|
+
let seen = 0;
|
|
1810
|
+
while (pos < display.length && seen < charsBeforeCaret) {
|
|
1811
|
+
if (display[pos] !== ',')
|
|
1812
|
+
seen++;
|
|
1813
|
+
pos++;
|
|
1814
|
+
}
|
|
1815
|
+
inputEl.setSelectionRange(pos, pos);
|
|
1816
|
+
}
|
|
1755
1817
|
onChange() {
|
|
1756
1818
|
if (this.decimalPortion !== null)
|
|
1757
1819
|
return;
|
|
@@ -1787,11 +1849,11 @@ class Oslinput {
|
|
|
1787
1849
|
return result;
|
|
1788
1850
|
}
|
|
1789
1851
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: Oslinput, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1790
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.9", type: Oslinput, isStandalone: false, selector: "osl-input", inputs: { label: "label", required: "required", disabled: "disabled", model: "model", type: "type", placeholder: "placeholder", mask: "mask", min: "min", max: "max", minLength: "minLength", maxLength: "maxLength", prefixIcon: "prefixIcon", suffixIcon: "suffixIcon", suffixRef: "suffixRef", skeletonLoading: "skeletonLoading", skeletonTheme: "skeletonTheme", onlyChars: "onlyChars", isCapitalize: "isCapitalize", decimalPortion: "decimalPortion", allowNegative: "allowNegative" }, outputs: { modelChange: "modelChange", changeEv: "changeEv" }, usesOnChanges: true, ngImport: i0, template: "<div class=\"d-flex flex-column\">\r\n @if(label){\r\n <div [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\">\r\n <label class=\"label\" [class.txt-clr-red]=\"myField.touched && myField.invalid\">\r\n <span class=\"label-text\" [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\" [title]=\"label\">{{label}}</span><span class=\"txt-clr-red label-required\">{{required?'*':''}}</span>\r\n </label>\r\n </div>\r\n}\r\n\r\n <div class=\"input-wrapper\" [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\" [class.plain]=\"!hasWrapper\" [class.error]=\"myField.touched && myField.invalid\" [class.input-disabled]=\"disabled\">\r\n @if(prefixIcon) {\r\n <mat-icon class=\"input-icon prefix-icon\">{{prefixIcon}}</mat-icon>\r\n }\r\n <input\r\n\r\n [type]=\"inputType\"\r\n [ngModel]=\"
|
|
1852
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.9", type: Oslinput, isStandalone: false, selector: "osl-input", inputs: { label: "label", required: "required", disabled: "disabled", model: "model", type: "type", placeholder: "placeholder", mask: "mask", min: "min", max: "max", minLength: "minLength", maxLength: "maxLength", prefixIcon: "prefixIcon", suffixIcon: "suffixIcon", suffixRef: "suffixRef", skeletonLoading: "skeletonLoading", skeletonTheme: "skeletonTheme", onlyChars: "onlyChars", isCapitalize: "isCapitalize", decimalPortion: "decimalPortion", allowNegative: "allowNegative" }, outputs: { modelChange: "modelChange", changeEv: "changeEv" }, usesOnChanges: true, ngImport: i0, template: "<div class=\"d-flex flex-column\">\r\n @if(label){\r\n <div [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\">\r\n <label class=\"label\" [class.txt-clr-red]=\"myField.touched && myField.invalid\">\r\n <span class=\"label-text\" [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\" [title]=\"label\">{{label}}</span><span class=\"txt-clr-red label-required\">{{required?'*':''}}</span>\r\n </label>\r\n </div>\r\n}\r\n\r\n <div class=\"input-wrapper\" [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\" [class.plain]=\"!hasWrapper\" [class.error]=\"myField.touched && myField.invalid\" [class.input-disabled]=\"disabled\">\r\n @if(prefixIcon) {\r\n <mat-icon class=\"input-icon prefix-icon\">{{prefixIcon}}</mat-icon>\r\n }\r\n <input\r\n\r\n [type]=\"inputType\"\r\n [ngModel]=\"displayModel\"\r\n (ngModelChange)=\"onModelChange($event, inputEl)\"\r\n (keydown)=\"onKeyDown($event)\"\r\n (focus)=\"onFocusIn($event)\"\r\n (blur)=\"onFocusOut()\"\r\n (change)=\"onChange()\"\r\n [required]=\"required\"\r\n [disabled]=\"disabled\"\r\n [placeholder]=\"placeholder\"\r\n [attr.min]=\"minAttr\"\r\n [attr.max]=\"max || null\"\r\n [attr.minlength]=\"minLength\"\r\n [attr.maxlength]=\"maxLengthAttr\"\r\n [email]=\"type === 'email'\"\r\n #myField=\"ngModel\"\r\n #inputEl\r\n class=\"inner-input\"\r\n >\r\n @if(type === 'password') {\r\n <button type=\"button\" class=\"password-toggle\" (click)=\"togglePassword()\" tabindex=\"-1\">\r\n <mat-icon>{{showPassword ? 'visibility_off' : 'visibility'}}</mat-icon>\r\n </button>\r\n }\r\n @if(suffixRef){\r\n <ng-container *ngTemplateOutlet=\"suffixRef; context: { $implicit: this }\"></ng-container>\r\n \r\n }\r\n @if(suffixIcon && type !== 'password') {\r\n <mat-icon class=\"input-icon suffix-icon\">{{suffixIcon}}</mat-icon>\r\n }\r\n </div>\r\n\r\n @if(myField.touched && myField.invalid) {\r\n @if(myField.errors?.['required']) {\r\n <mat-hint class=\"hint\">{{label}} is Required!</mat-hint>\r\n } @else if(myField.errors?.['email']) {\r\n <mat-hint class=\"hint\">Please enter a valid email address.</mat-hint>\r\n } @else if(myField.errors?.['minlength']) {\r\n <mat-hint class=\"hint\">Minimum {{minLength}} characters required.</mat-hint>\r\n } @else if(myField.errors?.['maxlength']) {\r\n <mat-hint class=\"hint\">Maximum {{maxLength}} characters allowed.</mat-hint>\r\n } @else if(myField.errors?.['min']) {\r\n <mat-hint class=\"hint\">Value must be at least {{min}}.</mat-hint>\r\n } @else if(myField.errors?.['max']) {\r\n <mat-hint class=\"hint\">Value must be at most {{max}}.</mat-hint>\r\n }\r\n }\r\n</div>\r\n", styles: [".label{font-size:var(--osl-label-font-size);margin-bottom:var(--osl-label-gap, 3px);display:flex;align-items:center;overflow:hidden}.label-text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.label-required{flex-shrink:0}.input-wrapper{display:flex;align-items:center;height:var(--osl-control-height);width:100%;border-radius:var(--osl-border-radius);border:1px solid var(--osl-border-color);padding:0 8px;gap:6px;transition:border-color .5s}.input-wrapper:focus-within{border-color:var(--osl-focus-border-color)}.input-wrapper.error{border-color:var(--osl-error-color)}.input-wrapper.input-disabled{background:#f5f5f5;opacity:.7}.input-wrapper.plain{padding:0;border:none;height:auto;gap:0}.input-wrapper.plain .inner-input{border:1px solid var(--osl-border-color);border-radius:var(--osl-border-radius);padding:5px;height:var(--osl-control-height)}.input-wrapper.plain .inner-input:focus{border-color:var(--osl-focus-border-color)}.input-wrapper.plain .inner-input.error{border-color:var(--osl-error-color)}.inner-input{flex:1;min-width:0;height:100%;border:none;outline:none;font-size:var(--osl-text-font-size);background:transparent;width:100%}.inner-input:disabled{background:transparent}.inner-input::placeholder{font-size:var(--osl-label-font-size);color:#aaa}.input-icon{font-size:18px;width:18px;height:18px;color:#888;flex-shrink:0;-webkit-user-select:none;user-select:none}.password-toggle{display:flex;align-items:center;justify-content:center;background:none;border:none;padding:0;cursor:pointer;color:#888;flex-shrink:0}.password-toggle mat-icon{font-size:18px;width:18px;height:18px}.password-toggle:hover{color:#333}.hint{color:var(--osl-error-color);margin-top:2px;font-size:var(--osl-hint-font-size)}.txt-clr-red{color:var(--osl-error-color)}\n"], dependencies: [{ kind: "directive", type: i1$2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i1$1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i1$1.EmailValidator, selector: "[email][formControlName],[email][formControl],[email][ngModel]", inputs: ["email"] }, { kind: "directive", type: i1$1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i2$2.MatHint, selector: "mat-hint", inputs: ["align", "id"] }, { kind: "component", type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: OslSkeletonDirective, selector: "[oslSkeleton]", inputs: ["oslSkeleton", "oslSkeletonType", "oslSkeletonAnimation", "oslSkeletonTheme", "oslSkeletonColor", "oslSkeletonHighlight", "oslSkeletonRadius", "oslSkeletonRows", "oslSkeletonRowGap", "oslSkeletonZIndex", "oslSkeletonDelay", "oslSkeletonDuration", "oslSkeletonMinHeight", "oslSkeletonForceReread", "oslSkeletonCircleSize", "oslSkeletonListItems", "oslSkeletonTableRows", "oslSkeletonTableCols", "oslSkeletonCardLines", "oslSkeletonBgColor"] }] });
|
|
1791
1853
|
}
|
|
1792
1854
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: Oslinput, decorators: [{
|
|
1793
1855
|
type: Component,
|
|
1794
|
-
args: [{ selector: 'osl-input', standalone: false, template: "<div class=\"d-flex flex-column\">\r\n @if(label){\r\n <div [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\">\r\n <label class=\"label\" [class.txt-clr-red]=\"myField.touched && myField.invalid\">\r\n <span class=\"label-text\" [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\" [title]=\"label\">{{label}}</span><span class=\"txt-clr-red label-required\">{{required?'*':''}}</span>\r\n </label>\r\n </div>\r\n}\r\n\r\n <div class=\"input-wrapper\" [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\" [class.plain]=\"!hasWrapper\" [class.error]=\"myField.touched && myField.invalid\" [class.input-disabled]=\"disabled\">\r\n @if(prefixIcon) {\r\n <mat-icon class=\"input-icon prefix-icon\">{{prefixIcon}}</mat-icon>\r\n }\r\n <input\r\n\r\n [type]=\"inputType\"\r\n [ngModel]=\"
|
|
1856
|
+
args: [{ selector: 'osl-input', standalone: false, template: "<div class=\"d-flex flex-column\">\r\n @if(label){\r\n <div [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\">\r\n <label class=\"label\" [class.txt-clr-red]=\"myField.touched && myField.invalid\">\r\n <span class=\"label-text\" [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\" [title]=\"label\">{{label}}</span><span class=\"txt-clr-red label-required\">{{required?'*':''}}</span>\r\n </label>\r\n </div>\r\n}\r\n\r\n <div class=\"input-wrapper\" [oslSkeleton]=\"skeletonLoading\" [oslSkeletonTheme]=\"skeletonTheme\" [class.plain]=\"!hasWrapper\" [class.error]=\"myField.touched && myField.invalid\" [class.input-disabled]=\"disabled\">\r\n @if(prefixIcon) {\r\n <mat-icon class=\"input-icon prefix-icon\">{{prefixIcon}}</mat-icon>\r\n }\r\n <input\r\n\r\n [type]=\"inputType\"\r\n [ngModel]=\"displayModel\"\r\n (ngModelChange)=\"onModelChange($event, inputEl)\"\r\n (keydown)=\"onKeyDown($event)\"\r\n (focus)=\"onFocusIn($event)\"\r\n (blur)=\"onFocusOut()\"\r\n (change)=\"onChange()\"\r\n [required]=\"required\"\r\n [disabled]=\"disabled\"\r\n [placeholder]=\"placeholder\"\r\n [attr.min]=\"minAttr\"\r\n [attr.max]=\"max || null\"\r\n [attr.minlength]=\"minLength\"\r\n [attr.maxlength]=\"maxLengthAttr\"\r\n [email]=\"type === 'email'\"\r\n #myField=\"ngModel\"\r\n #inputEl\r\n class=\"inner-input\"\r\n >\r\n @if(type === 'password') {\r\n <button type=\"button\" class=\"password-toggle\" (click)=\"togglePassword()\" tabindex=\"-1\">\r\n <mat-icon>{{showPassword ? 'visibility_off' : 'visibility'}}</mat-icon>\r\n </button>\r\n }\r\n @if(suffixRef){\r\n <ng-container *ngTemplateOutlet=\"suffixRef; context: { $implicit: this }\"></ng-container>\r\n \r\n }\r\n @if(suffixIcon && type !== 'password') {\r\n <mat-icon class=\"input-icon suffix-icon\">{{suffixIcon}}</mat-icon>\r\n }\r\n </div>\r\n\r\n @if(myField.touched && myField.invalid) {\r\n @if(myField.errors?.['required']) {\r\n <mat-hint class=\"hint\">{{label}} is Required!</mat-hint>\r\n } @else if(myField.errors?.['email']) {\r\n <mat-hint class=\"hint\">Please enter a valid email address.</mat-hint>\r\n } @else if(myField.errors?.['minlength']) {\r\n <mat-hint class=\"hint\">Minimum {{minLength}} characters required.</mat-hint>\r\n } @else if(myField.errors?.['maxlength']) {\r\n <mat-hint class=\"hint\">Maximum {{maxLength}} characters allowed.</mat-hint>\r\n } @else if(myField.errors?.['min']) {\r\n <mat-hint class=\"hint\">Value must be at least {{min}}.</mat-hint>\r\n } @else if(myField.errors?.['max']) {\r\n <mat-hint class=\"hint\">Value must be at most {{max}}.</mat-hint>\r\n }\r\n }\r\n</div>\r\n", styles: [".label{font-size:var(--osl-label-font-size);margin-bottom:var(--osl-label-gap, 3px);display:flex;align-items:center;overflow:hidden}.label-text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.label-required{flex-shrink:0}.input-wrapper{display:flex;align-items:center;height:var(--osl-control-height);width:100%;border-radius:var(--osl-border-radius);border:1px solid var(--osl-border-color);padding:0 8px;gap:6px;transition:border-color .5s}.input-wrapper:focus-within{border-color:var(--osl-focus-border-color)}.input-wrapper.error{border-color:var(--osl-error-color)}.input-wrapper.input-disabled{background:#f5f5f5;opacity:.7}.input-wrapper.plain{padding:0;border:none;height:auto;gap:0}.input-wrapper.plain .inner-input{border:1px solid var(--osl-border-color);border-radius:var(--osl-border-radius);padding:5px;height:var(--osl-control-height)}.input-wrapper.plain .inner-input:focus{border-color:var(--osl-focus-border-color)}.input-wrapper.plain .inner-input.error{border-color:var(--osl-error-color)}.inner-input{flex:1;min-width:0;height:100%;border:none;outline:none;font-size:var(--osl-text-font-size);background:transparent;width:100%}.inner-input:disabled{background:transparent}.inner-input::placeholder{font-size:var(--osl-label-font-size);color:#aaa}.input-icon{font-size:18px;width:18px;height:18px;color:#888;flex-shrink:0;-webkit-user-select:none;user-select:none}.password-toggle{display:flex;align-items:center;justify-content:center;background:none;border:none;padding:0;cursor:pointer;color:#888;flex-shrink:0}.password-toggle mat-icon{font-size:18px;width:18px;height:18px}.password-toggle:hover{color:#333}.hint{color:var(--osl-error-color);margin-top:2px;font-size:var(--osl-hint-font-size)}.txt-clr-red{color:var(--osl-error-color)}\n"] }]
|
|
1795
1857
|
}], propDecorators: { label: [{
|
|
1796
1858
|
type: Input,
|
|
1797
1859
|
args: ['label']
|