aloha-vue 1.2.234 → 1.2.235

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/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "Vue.js"
15
15
  ],
16
16
  "homepage": "https://github.com/ilia-brykin/aloha/#README.md",
17
- "version": "1.2.234",
17
+ "version": "1.2.235",
18
18
  "author": {
19
19
  "name": "Ilia Brykin",
20
20
  "email": "brykin.ilia@gmail.com"
@@ -33,6 +33,8 @@ export default function InputEventsAPI(props, {
33
33
  const thousandDivider = toRef(props, "thousandDivider");
34
34
  const validationOnChange = toRef(props, "validationOnChange");
35
35
 
36
+ const isTimeoutActive = ref(0);
37
+
36
38
  const allowedButtons = [
37
39
  AKeysCode.tab,
38
40
  AKeysCode.del,
@@ -128,7 +130,11 @@ export default function InputEventsAPI(props, {
128
130
  };
129
131
 
130
132
  const handleMinus = ({ value }) => {
133
+ if (min.value >= 0) {
134
+ return;
135
+ }
131
136
  if (value[0] !== "-") {
137
+ isTimeoutActive.value++;
132
138
  setTimeout(() => {
133
139
  const newVal = `-${ value }`;
134
140
 
@@ -140,12 +146,14 @@ export default function InputEventsAPI(props, {
140
146
  }
141
147
 
142
148
  setValueLocal(newVal);
149
+ isTimeoutActive.value--;
143
150
  });
144
151
  }
145
152
  };
146
153
 
147
154
  const handlePlus = ({ value }) => {
148
155
  if (value[0] === "-") {
156
+ isTimeoutActive.value++;
149
157
  setTimeout(() => {
150
158
  const newVal = value.replace("-", "");
151
159
 
@@ -157,32 +165,38 @@ export default function InputEventsAPI(props, {
157
165
  }
158
166
 
159
167
  setValueLocal(newVal);
168
+ isTimeoutActive.value--;
160
169
  });
161
170
  }
162
171
  };
163
172
 
164
173
  const handleArrowLeft = ({ value }) => {
174
+ isTimeoutActive.value++;
165
175
  setTimeout(() => {
166
176
  const cursorPositionAfterPress = inputRef.value.selectionStart;
167
177
  if (thousandDivider.value && value[cursorPositionAfterPress - 1] === thousandDivider.value) {
168
178
  const positionToSet = cursorPositionAfterPress - 1;
169
179
  setCursorPosition(positionToSet);
170
180
  }
181
+ isTimeoutActive.value--;
171
182
  });
172
183
  };
173
184
 
174
185
  const handleArrowRight = ({ value }) => {
175
186
  setTimeout(() => {
187
+ isTimeoutActive.value++;
176
188
  const cursorPositionAfterPress = inputRef.value.selectionStart;
177
189
  if (thousandDivider.value && value[cursorPositionAfterPress - 1] === thousandDivider.value) {
178
190
  const positionToSet = cursorPositionAfterPress + 1;
179
191
  setCursorPosition(positionToSet);
180
192
  }
193
+ isTimeoutActive.value--;
181
194
  });
182
195
  };
183
196
 
184
197
  const setDecimalDivider = ({ value }) => {
185
198
  setTimeout(() => {
199
+ isTimeoutActive.value++;
186
200
  const positionToSet = value.length + 1;
187
201
  let valueAfterKeyPress = inputRef.value.value;
188
202
  if (valueAfterKeyPress[valueAfterKeyPress.length - 1] === decimalDivider.value) {
@@ -190,31 +204,41 @@ export default function InputEventsAPI(props, {
190
204
  setValueLocal(valueAfterKeyPress);
191
205
  setCursorPosition(positionToSet);
192
206
  }
207
+ isTimeoutActive.value--;
193
208
  });
194
209
  };
195
210
 
211
+ const setCursorPositionForBackspace = ({ cursorPosition, numberOfSymbols }) => {
212
+ let positionToSet = cursorPosition ? cursorPosition - 1 : cursorPosition;
213
+ const numberOfSymbolsAfterEvent = inputRef.value.value.length;
214
+ if (numberOfSymbolsAfterEvent < numberOfSymbols - 1 && positionToSet > 0) {
215
+ positionToSet--;
216
+ }
217
+ setCursorPosition(positionToSet);
218
+ };
219
+
196
220
  const handleBackspace = ({ hasDecimalDivider, value, cursorPosition }) => {
197
- if (!isInteger.value && hasDecimalDivider) {
221
+ const numberOfSymbols = value.length;
222
+ if (!isInteger.value) {
198
223
  const decimalDividerIndex = value.indexOf(decimalDivider.value);
199
- if (decimalDividerIndex === cursorPosition - 1) {
224
+ if (hasDecimalDivider && decimalDividerIndex === cursorPosition - 1) {
200
225
  const splitVal = value.split(decimalDivider.value);
201
226
  const intVal = splitVal[0];
227
+ isTimeoutActive.value++;
202
228
  setTimeout(() => {
229
+ setCursorPositionForBackspace({ cursorPosition, numberOfSymbols });
203
230
  setValueLocal(intVal);
231
+ isTimeoutActive.value--;
204
232
  });
205
- }
206
233
 
207
- return;
208
- }
209
- const numberOfSymbols = value.length;
210
- setTimeout(() => {
211
- let positionToSet = cursorPosition ? cursorPosition - 1 : cursorPosition;
212
- const numberOfSymbolsAfterEvent = inputRef.value.value.length;
213
- if (numberOfSymbolsAfterEvent < numberOfSymbols - 1 && positionToSet > 0) {
214
- positionToSet--;
234
+ return;
215
235
  }
216
- setCursorPosition(positionToSet);
217
- });
236
+ isTimeoutActive.value++;
237
+ setTimeout(() => {
238
+ setCursorPositionForBackspace({ cursorPosition, numberOfSymbols });
239
+ isTimeoutActive.value--;
240
+ });
241
+ }
218
242
  };
219
243
 
220
244
  const handleDelete = ({ value, $event, hasDecimalDivider, cursorPosition }) => {
@@ -257,16 +281,23 @@ export default function InputEventsAPI(props, {
257
281
  setCursorPosition(positionToSet + 1);
258
282
  } else {
259
283
  setTimeout(() => {
284
+ isTimeoutActive.value++;
260
285
  const valueAfterKeyPress = inputRef.value.value;
261
286
  if (valueAfterKeyPress.length < value.length - 1) {
262
287
  setCursorPosition(cursorPosition > 0 ? cursorPosition - 1 : 0);
263
288
  }
289
+ isTimeoutActive.value--;
264
290
  });
265
291
  }
266
292
  }
267
293
  };
268
294
 
269
295
  const handleKeydown = $event => {
296
+ if (isTimeoutActive.value) {
297
+ $event.preventDefault();
298
+
299
+ return;
300
+ }
270
301
  const value = $event.target.value;
271
302
  const keyCode = $event.keyCode;
272
303
  const keyValue = $event.key;
@@ -364,8 +395,10 @@ export default function InputEventsAPI(props, {
364
395
  splitVal[cursorPosition] = keyValue;
365
396
  const newVal = splitVal.join("");
366
397
  setValueLocal(newVal);
398
+ isTimeoutActive.value++;
367
399
  setTimeout(() => {
368
400
  setCursorPosition(cursorPosition + 1);
401
+ isTimeoutActive.value--;
369
402
  });
370
403
 
371
404
  return;
@@ -380,6 +413,7 @@ export default function InputEventsAPI(props, {
380
413
 
381
414
  if ($event.keyCode !== AKeysCode.home && $event.keyCode !== AKeysCode.end && !$event.ctrlKey) {
382
415
  const numberOfSymbols = value.length;
416
+ isTimeoutActive.value++;
383
417
  setTimeout(() => {
384
418
  let positionToSet = cursorPosition + 1;
385
419
  const numberOfSymbolsAfterEvent = inputRef.value.value.length;
@@ -389,6 +423,7 @@ export default function InputEventsAPI(props, {
389
423
  positionToSet--;
390
424
  }
391
425
  setCursorPosition(positionToSet);
426
+ isTimeoutActive.value--;
392
427
  });
393
428
  }
394
429
  };
@@ -470,20 +505,38 @@ export default function InputEventsAPI(props, {
470
505
  };
471
506
 
472
507
  const onClickNumber = $event => {
508
+ isTimeoutActive.value++;
473
509
  setTimeout(() => {
474
510
  const cursorPosition = $event.target.selectionStart;
475
511
  const value = $event.target.value;
476
512
  if (thousandDivider.value && thousandDivider.value === value[cursorPosition - 1]) {
477
513
  setCursorPosition(cursorPosition - 1);
478
514
  }
515
+ isTimeoutActive.value--;
479
516
  });
480
517
  };
481
518
 
482
519
  const initFirstCheck = () => {
483
520
  setTimeout(() => {
484
- let valueToSet = required.value ? "0" : modelUndefinedLocal.value;
485
- if (modelValue.value) {
521
+ let valueToSet;
522
+ if (modelValue.value || modelValue.value === 0) {
486
523
  valueToSet = modelValue.value.toString().replace(".", decimalDivider.value);
524
+ if (decimalDivider.value) {
525
+ const splitVal = valueToSet.toString().split(decimalDivider.value);
526
+ const intPart = splitVal[0];
527
+ const setMinusSymbol = intPart[0] === "-" ? "-" : "";
528
+ const floatPart = splitVal.length > 1 ? splitVal[1] : "";
529
+ const floatPartLength = floatPart.length;
530
+ const zerosToAdd = times(symbolsAfterDecimalDivider.value - floatPartLength, () => "0").join("");
531
+
532
+ valueToSet = `${ setMinusSymbol }${ intPart }${ decimalDivider.value }${ floatPart }${ zerosToAdd }`;
533
+ }
534
+ } else {
535
+ valueToSet = required.value ? [
536
+ "0",
537
+ decimalDivider.value,
538
+ times(symbolsAfterDecimalDivider.value, () => "0").join(""),
539
+ ].join("") : modelUndefinedLocal.value;
487
540
  }
488
541
  handleInput(null, valueToSet);
489
542
  });
@@ -5,6 +5,7 @@ import {
5
5
  } from "vue";
6
6
 
7
7
  import {
8
+ isNil,
8
9
  times,
9
10
  } from "lodash-es";
10
11
 
@@ -26,14 +27,6 @@ export default function ModelAPI(props, {
26
27
  return Number(`${ displayValue.value }`.replaceAll(thousandDivider.value, "").replace(decimalDivider.value, "."));
27
28
  });
28
29
 
29
- const setCurrentValue = value => {
30
- displayValue.value = value;
31
- const newVal = modelType.value === "number"
32
- ? Number(`${ value }`.replaceAll(thousandDivider.value, "").replace(decimalDivider.value, "."))
33
- : value;
34
- changeModel({ model: newVal });
35
- };
36
-
37
30
  const modelUndefinedLocal = computed(() => {
38
31
  return required.value
39
32
  ? [
@@ -43,6 +36,20 @@ export default function ModelAPI(props, {
43
36
  ].join("")
44
37
  : modelUndefined.value;
45
38
  });
39
+
40
+ const setCurrentValue = value => {
41
+ displayValue.value = value;
42
+ let newVal;
43
+ if (!required.value && isNil(value)) {
44
+ newVal = modelUndefinedLocal.value;
45
+ } else {
46
+ newVal = modelType.value === "number"
47
+ ? Number(`${ value }`.replaceAll(thousandDivider.value, "").replace(decimalDivider.value, "."))
48
+ : value;
49
+ }
50
+ changeModel({ model: newVal });
51
+ };
52
+
46
53
  const clearModel = () => {
47
54
  if (disabled.value) {
48
55
  return;