PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
booking / vendors / imask / esm / core / action-details.js

action-details.js in Booking Calendar 11.9, at vendors/imask/esm/core/action-details.js

78 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { DIRECTION } from './utils.js';
2
3 /** Provides details of changing input */
4 class ActionDetails {
5 /** Current input value */
6
7 /** Current cursor position */
8
9 /** Old input value */
10
11 /** Old selection */
12
13 constructor(opts) {
14 Object.assign(this, opts);
15
16 // double check if left part was changed (autofilling, other non-standard input triggers)
17 while (this.value.slice(0, this.startChangePos) !== this.oldValue.slice(0, this.startChangePos)) {
18 --this.oldSelection.start;
19 }
20 if (this.insertedCount) {
21 // double check right part
22 while (this.value.slice(this.cursorPos) !== this.oldValue.slice(this.oldSelection.end)) {
23 if (this.value.length - this.cursorPos < this.oldValue.length - this.oldSelection.end) ++this.oldSelection.end;else ++this.cursorPos;
24 }
25 }
26 }
27
28 /** Start changing position */
29 get startChangePos() {
30 return Math.min(this.cursorPos, this.oldSelection.start);
31 }
32
33 /** Inserted symbols count */
34 get insertedCount() {
35 return this.cursorPos - this.startChangePos;
36 }
37
38 /** Inserted symbols */
39 get inserted() {
40 return this.value.substr(this.startChangePos, this.insertedCount);
41 }
42
43 /** Removed symbols count */
44 get removedCount() {
45 // Math.max for opposite operation
46 return Math.max(this.oldSelection.end - this.startChangePos ||
47 // for Delete
48 this.oldValue.length - this.value.length, 0);
49 }
50
51 /** Removed symbols */
52 get removed() {
53 return this.oldValue.substr(this.startChangePos, this.removedCount);
54 }
55
56 /** Unchanged head symbols */
57 get head() {
58 return this.value.substring(0, this.startChangePos);
59 }
60
61 /** Unchanged tail symbols */
62 get tail() {
63 return this.value.substring(this.startChangePos + this.insertedCount);
64 }
65
66 /** Remove direction */
67 get removeDirection() {
68 if (!this.removedCount || this.insertedCount) return DIRECTION.NONE;
69
70 // align right if delete at right
71 return (this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos) &&
72 // if not range removed (event with backspace)
73 this.oldSelection.end === this.oldSelection.start ? DIRECTION.RIGHT : DIRECTION.LEFT;
74 }
75 }
76
77 export { ActionDetails as default };
78