source: trip-planner-front/node_modules/primeng/fesm2020/primeng-spinner.mjs@ 8d391a1

Last change on this file since 8d391a1 was 59329aa, checked in by Ema <ema_spirova@…>, 3 years ago

adding photos

  • Property mode set to 100644
File size: 16.9 KB
RevLine 
[59329aa]1import * as i0 from '@angular/core';
2import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Output, Input, ViewChild, NgModule } from '@angular/core';
3import * as i1 from '@angular/common';
4import { CommonModule } from '@angular/common';
5import { InputTextModule } from 'primeng/inputtext';
6import { NG_VALUE_ACCESSOR } from '@angular/forms';
7
8const SPINNER_VALUE_ACCESSOR = {
9 provide: NG_VALUE_ACCESSOR,
10 useExisting: forwardRef(() => Spinner),
11 multi: true
12};
13class Spinner {
14 constructor(el, cd) {
15 this.el = el;
16 this.cd = cd;
17 this.onChange = new EventEmitter();
18 this.onFocus = new EventEmitter();
19 this.onBlur = new EventEmitter();
20 this._step = 1;
21 this.onModelChange = () => { };
22 this.onModelTouched = () => { };
23 this.keyPattern = /[0-9\+\-]/;
24 this.negativeSeparator = '-';
25 }
26 get step() {
27 return this._step;
28 }
29 set step(val) {
30 this._step = val;
31 if (this._step != null) {
32 let tokens = this.step.toString().split(/[,]|[.]/);
33 this.calculatedPrecision = tokens[1] ? tokens[1].length : undefined;
34 }
35 }
36 ngOnInit() {
37 if (this.formatInput) {
38 this.localeDecimalSeparator = (1.1).toLocaleString().substring(1, 2);
39 this.localeThousandSeparator = (1000).toLocaleString().substring(1, 2);
40 this.thousandRegExp = new RegExp(`[${this.thousandSeparator || this.localeThousandSeparator}]`, 'gim');
41 if (this.decimalSeparator && this.thousandSeparator && this.decimalSeparator === this.thousandSeparator) {
42 console.warn("thousandSeparator and decimalSeparator cannot have the same value.");
43 }
44 }
45 }
46 repeat(event, interval, dir) {
47 let i = interval || 500;
48 this.clearTimer();
49 this.timer = setTimeout(() => {
50 this.repeat(event, 40, dir);
51 }, i);
52 this.spin(event, dir);
53 }
54 spin(event, dir) {
55 let step = this.step * dir;
56 let currentValue;
57 let precision = this.getPrecision();
58 if (this.value)
59 currentValue = (typeof this.value === 'string') ? this.parseValue(this.value) : this.value;
60 else
61 currentValue = 0;
62 if (precision)
63 this.value = parseFloat(this.toFixed(currentValue + step, precision));
64 else
65 this.value = currentValue + step;
66 if (this.maxlength !== undefined && this.value.toString().length > this.maxlength) {
67 this.value = currentValue;
68 }
69 if (this.min !== undefined && this.value < this.min) {
70 this.value = this.min;
71 }
72 if (this.max !== undefined && this.value > this.max) {
73 this.value = this.max;
74 }
75 this.formatValue();
76 this.onModelChange(this.value);
77 this.onChange.emit(event);
78 }
79 getPrecision() {
80 return this.precision === undefined ? this.calculatedPrecision : this.precision;
81 }
82 toFixed(value, precision) {
83 let power = Math.pow(10, precision || 0);
84 return String(Math.round(value * power) / power);
85 }
86 onUpButtonMousedown(event) {
87 if (!this.disabled) {
88 this.inputfieldViewChild.nativeElement.focus();
89 this.repeat(event, null, 1);
90 this.updateFilledState();
91 event.preventDefault();
92 }
93 }
94 onUpButtonMouseup(event) {
95 if (!this.disabled) {
96 this.clearTimer();
97 }
98 }
99 onUpButtonMouseleave(event) {
100 if (!this.disabled) {
101 this.clearTimer();
102 }
103 }
104 onDownButtonMousedown(event) {
105 if (!this.disabled) {
106 this.inputfieldViewChild.nativeElement.focus();
107 this.repeat(event, null, -1);
108 this.updateFilledState();
109 event.preventDefault();
110 }
111 }
112 onDownButtonMouseup(event) {
113 if (!this.disabled) {
114 this.clearTimer();
115 }
116 }
117 onDownButtonMouseleave(event) {
118 if (!this.disabled) {
119 this.clearTimer();
120 }
121 }
122 onInputKeydown(event) {
123 if (event.which == 38) {
124 this.spin(event, 1);
125 event.preventDefault();
126 }
127 else if (event.which == 40) {
128 this.spin(event, -1);
129 event.preventDefault();
130 }
131 }
132 onInputChange(event) {
133 this.onChange.emit(event);
134 }
135 onInput(event) {
136 this.value = this.parseValue(event.target.value);
137 this.onModelChange(this.value);
138 this.updateFilledState();
139 }
140 onInputBlur(event) {
141 this.focus = false;
142 this.formatValue();
143 this.onModelTouched();
144 this.onBlur.emit(event);
145 }
146 onInputFocus(event) {
147 this.focus = true;
148 this.onFocus.emit(event);
149 }
150 parseValue(val) {
151 let value;
152 let precision = this.getPrecision();
153 if (val.trim() === '') {
154 value = null;
155 }
156 else {
157 if (this.formatInput) {
158 val = val.replace(this.thousandRegExp, '');
159 }
160 if (precision) {
161 val = this.formatInput ? val.replace(this.decimalSeparator || this.localeDecimalSeparator, '.') : val.replace(',', '.');
162 value = parseFloat(val);
163 }
164 else {
165 value = parseInt(val, 10);
166 }
167 if (!isNaN(value)) {
168 if (this.max !== null && value > this.max) {
169 value = this.max;
170 }
171 if (this.min !== null && value < this.min) {
172 value = this.min;
173 }
174 }
175 else {
176 value = null;
177 }
178 }
179 return value;
180 }
181 formatValue() {
182 let value = this.value;
183 let precision = this.getPrecision();
184 if (value != null) {
185 if (this.formatInput) {
186 value = value.toLocaleString(undefined, { maximumFractionDigits: 20 });
187 if (this.decimalSeparator && this.thousandSeparator) {
188 value = value.split(this.localeDecimalSeparator);
189 if (precision && value[1]) {
190 value[1] = (this.decimalSeparator || this.localeDecimalSeparator) + value[1];
191 }
192 if (this.thousandSeparator && value[0].length > 3) {
193 value[0] = value[0].replace(new RegExp(`[${this.localeThousandSeparator}]`, 'gim'), this.thousandSeparator);
194 }
195 value = value.join('');
196 }
197 }
198 this.formattedValue = value.toString();
199 }
200 else {
201 this.formattedValue = null;
202 }
203 if (this.inputfieldViewChild && this.inputfieldViewChild.nativeElement) {
204 this.inputfieldViewChild.nativeElement.value = this.formattedValue;
205 }
206 }
207 clearTimer() {
208 if (this.timer) {
209 clearInterval(this.timer);
210 }
211 }
212 writeValue(value) {
213 this.value = value;
214 this.formatValue();
215 this.updateFilledState();
216 this.cd.markForCheck();
217 }
218 registerOnChange(fn) {
219 this.onModelChange = fn;
220 }
221 registerOnTouched(fn) {
222 this.onModelTouched = fn;
223 }
224 setDisabledState(val) {
225 this.disabled = val;
226 this.cd.markForCheck();
227 }
228 updateFilledState() {
229 this.filled = (this.value !== undefined && this.value != null);
230 }
231}
232Spinner.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Spinner, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
233Spinner.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: Spinner, selector: "p-spinner", inputs: { min: "min", max: "max", maxlength: "maxlength", size: "size", placeholder: "placeholder", inputId: "inputId", disabled: "disabled", readonly: "readonly", tabindex: "tabindex", required: "required", name: "name", ariaLabelledBy: "ariaLabelledBy", inputStyle: "inputStyle", inputStyleClass: "inputStyleClass", formatInput: "formatInput", decimalSeparator: "decimalSeparator", thousandSeparator: "thousandSeparator", precision: "precision", step: "step" }, outputs: { onChange: "onChange", onFocus: "onFocus", onBlur: "onBlur" }, host: { properties: { "class.ui-inputwrapper-filled": "filled", "class.ui-inputwrapper-focus": "focus" }, classAttribute: "p-element" }, providers: [SPINNER_VALUE_ACCESSOR], viewQueries: [{ propertyName: "inputfieldViewChild", first: true, predicate: ["inputfield"], descendants: true }], ngImport: i0, template: `
234 <span class="ui-spinner ui-widget ui-corner-all">
235 <input #inputfield type="text" [attr.id]="inputId" [value]="formattedValue||null" [attr.name]="name" [attr.aria-valumin]="min" [attr.aria-valuemax]="max" [attr.aria-valuenow]="value" [attr.aria-labelledby]="ariaLabelledBy"
236 [attr.size]="size" [attr.maxlength]="maxlength" [attr.tabindex]="tabindex" [attr.placeholder]="placeholder" [disabled]="disabled" [readonly]="readonly" [attr.required]="required"
237 (keydown)="onInputKeydown($event)" (blur)="onInputBlur($event)" (input)="onInput($event)" (change)="onInputChange($event)" (focus)="onInputFocus($event)"
238 [ngStyle]="inputStyle" [class]="inputStyleClass" [ngClass]="'ui-spinner-input ui-inputtext ui-widget ui-state-default ui-corner-all'">
239 <button type="button" [ngClass]="{'ui-spinner-button ui-spinner-up ui-corner-tr ui-button ui-widget ui-state-default':true,'ui-state-disabled':disabled}" [disabled]="disabled||readonly" tabindex="-1" [attr.readonly]="readonly"
240 (mouseleave)="onUpButtonMouseleave($event)" (mousedown)="onUpButtonMousedown($event)" (mouseup)="onUpButtonMouseup($event)">
241 <span class="ui-spinner-button-icon pi pi-caret-up ui-clickable"></span>
242 </button>
243 <button type="button" [ngClass]="{'ui-spinner-button ui-spinner-down ui-corner-br ui-button ui-widget ui-state-default':true,'ui-state-disabled':disabled}" [disabled]="disabled||readonly" tabindex="-1" [attr.readonly]="readonly"
244 (mouseleave)="onDownButtonMouseleave($event)" (mousedown)="onDownButtonMousedown($event)" (mouseup)="onDownButtonMouseup($event)">
245 <span class="ui-spinner-button-icon pi pi-caret-down ui-clickable"></span>
246 </button>
247 </span>
248 `, isInline: true, styles: [".ui-spinner{display:inline-block;overflow:visible;padding:0;position:relative;vertical-align:middle}.ui-spinner-input{vertical-align:middle;padding-right:1.5em}.ui-spinner-button{cursor:default;display:block;height:50%;margin:0;overflow:hidden;padding:0;position:absolute;right:0;text-align:center;vertical-align:middle;width:1.5em}.ui-spinner .ui-spinner-button-icon{position:absolute;top:50%;left:50%;margin-top:-.5em;margin-left:-.5em;width:1em}.ui-spinner-up{top:0}.ui-spinner-down{bottom:0}.ui-fluid .ui-spinner{width:100%}.ui-fluid .ui-spinner .ui-spinner-input{padding-right:2em;width:100%}.ui-fluid .ui-spinner .ui-spinner-button{width:1.5em}.ui-fluid .ui-spinner .ui-spinner-button .ui-spinner-button-icon{left:.7em}\n"], directives: [{ type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
249i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Spinner, decorators: [{
250 type: Component,
251 args: [{ selector: 'p-spinner', template: `
252 <span class="ui-spinner ui-widget ui-corner-all">
253 <input #inputfield type="text" [attr.id]="inputId" [value]="formattedValue||null" [attr.name]="name" [attr.aria-valumin]="min" [attr.aria-valuemax]="max" [attr.aria-valuenow]="value" [attr.aria-labelledby]="ariaLabelledBy"
254 [attr.size]="size" [attr.maxlength]="maxlength" [attr.tabindex]="tabindex" [attr.placeholder]="placeholder" [disabled]="disabled" [readonly]="readonly" [attr.required]="required"
255 (keydown)="onInputKeydown($event)" (blur)="onInputBlur($event)" (input)="onInput($event)" (change)="onInputChange($event)" (focus)="onInputFocus($event)"
256 [ngStyle]="inputStyle" [class]="inputStyleClass" [ngClass]="'ui-spinner-input ui-inputtext ui-widget ui-state-default ui-corner-all'">
257 <button type="button" [ngClass]="{'ui-spinner-button ui-spinner-up ui-corner-tr ui-button ui-widget ui-state-default':true,'ui-state-disabled':disabled}" [disabled]="disabled||readonly" tabindex="-1" [attr.readonly]="readonly"
258 (mouseleave)="onUpButtonMouseleave($event)" (mousedown)="onUpButtonMousedown($event)" (mouseup)="onUpButtonMouseup($event)">
259 <span class="ui-spinner-button-icon pi pi-caret-up ui-clickable"></span>
260 </button>
261 <button type="button" [ngClass]="{'ui-spinner-button ui-spinner-down ui-corner-br ui-button ui-widget ui-state-default':true,'ui-state-disabled':disabled}" [disabled]="disabled||readonly" tabindex="-1" [attr.readonly]="readonly"
262 (mouseleave)="onDownButtonMouseleave($event)" (mousedown)="onDownButtonMousedown($event)" (mouseup)="onDownButtonMouseup($event)">
263 <span class="ui-spinner-button-icon pi pi-caret-down ui-clickable"></span>
264 </button>
265 </span>
266 `, host: {
267 'class': 'p-element',
268 '[class.ui-inputwrapper-filled]': 'filled',
269 '[class.ui-inputwrapper-focus]': 'focus'
270 }, providers: [SPINNER_VALUE_ACCESSOR], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, styles: [".ui-spinner{display:inline-block;overflow:visible;padding:0;position:relative;vertical-align:middle}.ui-spinner-input{vertical-align:middle;padding-right:1.5em}.ui-spinner-button{cursor:default;display:block;height:50%;margin:0;overflow:hidden;padding:0;position:absolute;right:0;text-align:center;vertical-align:middle;width:1.5em}.ui-spinner .ui-spinner-button-icon{position:absolute;top:50%;left:50%;margin-top:-.5em;margin-left:-.5em;width:1em}.ui-spinner-up{top:0}.ui-spinner-down{bottom:0}.ui-fluid .ui-spinner{width:100%}.ui-fluid .ui-spinner .ui-spinner-input{padding-right:2em;width:100%}.ui-fluid .ui-spinner .ui-spinner-button{width:1.5em}.ui-fluid .ui-spinner .ui-spinner-button .ui-spinner-button-icon{left:.7em}\n"] }]
271 }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { onChange: [{
272 type: Output
273 }], onFocus: [{
274 type: Output
275 }], onBlur: [{
276 type: Output
277 }], min: [{
278 type: Input
279 }], max: [{
280 type: Input
281 }], maxlength: [{
282 type: Input
283 }], size: [{
284 type: Input
285 }], placeholder: [{
286 type: Input
287 }], inputId: [{
288 type: Input
289 }], disabled: [{
290 type: Input
291 }], readonly: [{
292 type: Input
293 }], tabindex: [{
294 type: Input
295 }], required: [{
296 type: Input
297 }], name: [{
298 type: Input
299 }], ariaLabelledBy: [{
300 type: Input
301 }], inputStyle: [{
302 type: Input
303 }], inputStyleClass: [{
304 type: Input
305 }], formatInput: [{
306 type: Input
307 }], decimalSeparator: [{
308 type: Input
309 }], thousandSeparator: [{
310 type: Input
311 }], precision: [{
312 type: Input
313 }], inputfieldViewChild: [{
314 type: ViewChild,
315 args: ['inputfield']
316 }], step: [{
317 type: Input
318 }] } });
319class SpinnerModule {
320}
321SpinnerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: SpinnerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
322SpinnerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: SpinnerModule, declarations: [Spinner], imports: [CommonModule, InputTextModule], exports: [Spinner] });
323SpinnerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: SpinnerModule, imports: [[CommonModule, InputTextModule]] });
324i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: SpinnerModule, decorators: [{
325 type: NgModule,
326 args: [{
327 imports: [CommonModule, InputTextModule],
328 exports: [Spinner],
329 declarations: [Spinner]
330 }]
331 }] });
332
333/**
334 * Generated bundle index. Do not edit.
335 */
336
337export { SPINNER_VALUE_ACCESSOR, Spinner, SpinnerModule };
Note: See TracBrowser for help on using the repository browser.