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 / masked / pattern / fixed-definition.js

fixed-definition.js in Booking Calendar 11.9, at vendors/imask/esm/masked/pattern/fixed-definition.js

153 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import ChangeDetails from '../../core/change-details.js';
2 import { DIRECTION, isString } from '../../core/utils.js';
3 import ContinuousTailDetails from '../../core/continuous-tail-details.js';
4 import '../../core/holder.js';
5
6 class PatternFixedDefinition {
7 /** */
8
9 /** */
10
11 /** */
12
13 /** */
14
15 /** */
16
17 /** */
18
19 constructor(opts) {
20 Object.assign(this, opts);
21 this._value = '';
22 this.isFixed = true;
23 }
24 get value() {
25 return this._value;
26 }
27 get unmaskedValue() {
28 return this.isUnmasking ? this.value : '';
29 }
30 get rawInputValue() {
31 return this._isRawInput ? this.value : '';
32 }
33 get displayValue() {
34 return this.value;
35 }
36 reset() {
37 this._isRawInput = false;
38 this._value = '';
39 }
40 remove(fromPos, toPos) {
41 if (fromPos === void 0) {
42 fromPos = 0;
43 }
44 if (toPos === void 0) {
45 toPos = this._value.length;
46 }
47 this._value = this._value.slice(0, fromPos) + this._value.slice(toPos);
48 if (!this._value) this._isRawInput = false;
49 return new ChangeDetails();
50 }
51 nearestInputPos(cursorPos, direction) {
52 if (direction === void 0) {
53 direction = DIRECTION.NONE;
54 }
55 const minPos = 0;
56 const maxPos = this._value.length;
57 switch (direction) {
58 case DIRECTION.LEFT:
59 case DIRECTION.FORCE_LEFT:
60 return minPos;
61 case DIRECTION.NONE:
62 case DIRECTION.RIGHT:
63 case DIRECTION.FORCE_RIGHT:
64 default:
65 return maxPos;
66 }
67 }
68 totalInputPositions(fromPos, toPos) {
69 if (fromPos === void 0) {
70 fromPos = 0;
71 }
72 if (toPos === void 0) {
73 toPos = this._value.length;
74 }
75 return this._isRawInput ? toPos - fromPos : 0;
76 }
77 extractInput(fromPos, toPos, flags) {
78 if (fromPos === void 0) {
79 fromPos = 0;
80 }
81 if (toPos === void 0) {
82 toPos = this._value.length;
83 }
84 if (flags === void 0) {
85 flags = {};
86 }
87 return flags.raw && this._isRawInput && this._value.slice(fromPos, toPos) || '';
88 }
89 get isComplete() {
90 return true;
91 }
92 get isFilled() {
93 return Boolean(this._value);
94 }
95 _appendChar(ch, flags) {
96 if (flags === void 0) {
97 flags = {};
98 }
99 if (this.isFilled) return new ChangeDetails();
100 const appendEager = this.eager === true || this.eager === 'append';
101 const appended = this.char === ch;
102 const isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && (!flags.raw || !appendEager) && !flags.tail;
103 const details = new ChangeDetails({
104 inserted: this.char,
105 rawInserted: isResolved ? this.char : ''
106 });
107 this._value = this.char;
108 this._isRawInput = isResolved && (flags.raw || flags.input);
109 return details;
110 }
111 _appendEager() {
112 return this._appendChar(this.char, {
113 tail: true
114 });
115 }
116 _appendPlaceholder() {
117 const details = new ChangeDetails();
118 if (this.isFilled) return details;
119 this._value = details.inserted = this.char;
120 return details;
121 }
122 extractTail() {
123 return new ContinuousTailDetails('');
124 }
125 appendTail(tail) {
126 if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
127 return tail.appendTo(this);
128 }
129 append(str, flags, tail) {
130 const details = this._appendChar(str[0], flags);
131 if (tail != null) {
132 details.tailShift += this.appendTail(tail).tailShift;
133 }
134 return details;
135 }
136 doCommit() {}
137 get state() {
138 return {
139 _value: this._value,
140 _rawInputValue: this.rawInputValue
141 };
142 }
143 set state(state) {
144 this._value = state._value;
145 this._isRawInput = Boolean(state._rawInputValue);
146 }
147 pad(flags) {
148 return this._appendPlaceholder();
149 }
150 }
151
152 export { PatternFixedDefinition as default };
153