@dile/ui 3.8.1 → 3.8.3
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/components/input/__screenshots__/input-mask.spec.js/dile-input-mask-applies-lazy-separators-only-when-next-block-is-filled-1.png +0 -0
- package/components/input/input-mask.spec.js +55 -1
- package/components/input/src/DileInputMask.js +7 -1
- package/components/input/src/MaskPattern.js +13 -3
- package/package.json +3 -3
|
Binary file
|
|
@@ -223,7 +223,7 @@ describe('dile-input-mask', () => {
|
|
|
223
223
|
});
|
|
224
224
|
|
|
225
225
|
it('applies lazy separators only when next block is filled', async () => {
|
|
226
|
-
const el = await renderInputMask('<dile-input-mask name="iban" mask="AA-XXXX-0000"></dile-input-mask>');
|
|
226
|
+
const el = await renderInputMask('<dile-input-mask name="iban" mask="AA-XXXX-0000" lazySeparators></dile-input-mask>');
|
|
227
227
|
const input = el.shadowRoot.querySelector('input');
|
|
228
228
|
|
|
229
229
|
// Type 'ES' - should show 'ES' without trailing separator
|
|
@@ -256,5 +256,59 @@ describe('dile-input-mask', () => {
|
|
|
256
256
|
await el.updateComplete;
|
|
257
257
|
expect(el.maskedValue).toBe('ES-WSWQ-0000');
|
|
258
258
|
});
|
|
259
|
+
|
|
260
|
+
it('uses normal separators by default (lazySeparators=false)', async () => {
|
|
261
|
+
const el = await renderInputMask('<dile-input-mask name="test" mask="AA-XXXX-0000"></dile-input-mask>');
|
|
262
|
+
const input = el.shadowRoot.querySelector('input');
|
|
263
|
+
|
|
264
|
+
// Type 'ES' - should show 'ES-' (separator added immediately)
|
|
265
|
+
input.value = 'ES';
|
|
266
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
267
|
+
await el.updateComplete;
|
|
268
|
+
expect(el.maskedValue).toBe('ES-');
|
|
269
|
+
|
|
270
|
+
// Type 'ESWSWQ0000' - separators already included
|
|
271
|
+
input.value = 'ESWSWQ0000';
|
|
272
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
273
|
+
await el.updateComplete;
|
|
274
|
+
expect(el.maskedValue).toBe('ES-WSWQ-0000');
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('supports lazySeparators property', async () => {
|
|
278
|
+
const el = await renderInputMask('<dile-input-mask name="test" mask="AA-XXXX-0000" lazySeparators></dile-input-mask>');
|
|
279
|
+
const input = el.shadowRoot.querySelector('input');
|
|
280
|
+
|
|
281
|
+
// Type 'ES' - should show 'ES' without separator (lazy behavior)
|
|
282
|
+
input.value = 'ES';
|
|
283
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
284
|
+
await el.updateComplete;
|
|
285
|
+
expect(el.maskedValue).toBe('ES');
|
|
286
|
+
|
|
287
|
+
// Type 'ESW' - should show 'ES-W' (separator added when next block starts)
|
|
288
|
+
input.value = 'ESW';
|
|
289
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
290
|
+
await el.updateComplete;
|
|
291
|
+
expect(el.maskedValue).toBe('ES-W');
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('can toggle lazySeparators property dynamically', async () => {
|
|
295
|
+
const el = await renderInputMask('<dile-input-mask name="test" mask="AA-XXXX-0000"></dile-input-mask>');
|
|
296
|
+
const input = el.shadowRoot.querySelector('input');
|
|
297
|
+
|
|
298
|
+
// Initially with normal separators
|
|
299
|
+
input.value = 'ES';
|
|
300
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
301
|
+
await el.updateComplete;
|
|
302
|
+
expect(el.maskedValue).toBe('ES-');
|
|
303
|
+
|
|
304
|
+
// Toggle to lazy separators
|
|
305
|
+
el.lazySeparators = true;
|
|
306
|
+
await el.updateComplete;
|
|
307
|
+
input.value = 'ES';
|
|
308
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
309
|
+
await el.updateComplete;
|
|
310
|
+
expect(el.maskedValue).toBe('ES');
|
|
311
|
+
});
|
|
259
312
|
});
|
|
260
313
|
|
|
314
|
+
|
|
@@ -9,6 +9,7 @@ export class DileInputMask extends DileInput {
|
|
|
9
9
|
mask: { type: String },
|
|
10
10
|
maskedValue: { type: String },
|
|
11
11
|
language: { type: String },
|
|
12
|
+
lazySeparators: { type: Boolean },
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -18,6 +19,7 @@ export class DileInputMask extends DileInput {
|
|
|
18
19
|
this.maskedValue = '';
|
|
19
20
|
this.content = '';
|
|
20
21
|
this.language = 'en';
|
|
22
|
+
this.lazySeparators = false;
|
|
21
23
|
this._keyDownHandler = this.handleKeyDown.bind(this);
|
|
22
24
|
this._blurHandler = this.handleBlur.bind(this);
|
|
23
25
|
}
|
|
@@ -32,7 +34,7 @@ export class DileInputMask extends DileInput {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
createMaskController(mask) {
|
|
35
|
-
this.maskController = new MaskPattern(mask, this.language);
|
|
37
|
+
this.maskController = new MaskPattern(mask, this.language, this.lazySeparators);
|
|
36
38
|
this.maxChars = this.maskController.getTotalCharactersExpected();
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -46,6 +48,10 @@ export class DileInputMask extends DileInput {
|
|
|
46
48
|
if (changedProperties.has('language')) {
|
|
47
49
|
this.maskController.setLanguage(this.language);
|
|
48
50
|
}
|
|
51
|
+
if (changedProperties.has('lazySeparators')) {
|
|
52
|
+
this.maskController.setLazySeparators(this.lazySeparators);
|
|
53
|
+
this.updateMaskedValue();
|
|
54
|
+
}
|
|
49
55
|
if (changedProperties.has('value')) {
|
|
50
56
|
const transformedValue = this.maskController.transformValue(this.value.slice(0, this.maxChars));
|
|
51
57
|
this.content = transformedValue;
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
* '(000) 000-0000' = US phone format
|
|
15
15
|
*/
|
|
16
16
|
export class MaskPattern {
|
|
17
|
-
constructor(pattern, language = 'en') {
|
|
17
|
+
constructor(pattern, language = 'en', lazySeparators = false) {
|
|
18
18
|
this.pattern = pattern;
|
|
19
19
|
this.language = language;
|
|
20
|
+
this.lazySeparators = lazySeparators;
|
|
20
21
|
this.parsePattern();
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -50,6 +51,10 @@ export class MaskPattern {
|
|
|
50
51
|
this.language = language;
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
setLazySeparators(lazy) {
|
|
55
|
+
this.lazySeparators = lazy;
|
|
56
|
+
}
|
|
57
|
+
|
|
53
58
|
getTotalCharactersExpected() {
|
|
54
59
|
return this.patternMap.filter(p => p.type !== 'literal').length;
|
|
55
60
|
}
|
|
@@ -62,8 +67,13 @@ export class MaskPattern {
|
|
|
62
67
|
const patternInfo = this.patternMap[i];
|
|
63
68
|
|
|
64
69
|
if (patternInfo.type === 'literal') {
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
if (this.lazySeparators) {
|
|
71
|
+
// Lazy literals: only add if there are more input characters to fill slots after this literal
|
|
72
|
+
if (slotIndex < value.length) {
|
|
73
|
+
masked += patternInfo.char;
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
// Normal behavior: always add the literal
|
|
67
77
|
masked += patternInfo.char;
|
|
68
78
|
}
|
|
69
79
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/ui",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.3",
|
|
4
4
|
"description": "UI Core components from dile-components.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://dile-components.com/",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@dile/iconlib": "^
|
|
24
|
+
"@dile/iconlib": "^2.0.0",
|
|
25
25
|
"@dile/icons": "^2.5.1",
|
|
26
26
|
"lit": "^2.7.0 || ^3.0.0"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "807eac93fd36691a8fb656b5e0f2549ed9c887cb"
|
|
32
32
|
}
|