@globalpayments/vega 2.37.1 → 2.37.2

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.
Files changed (63) hide show
  1. package/dist/cjs/{app-globals-e10d1859.js → app-globals-7087f121.js} +1 -1
  2. package/dist/cjs/index.cjs.js +1 -1
  3. package/dist/cjs/loader.cjs.js +2 -2
  4. package/dist/cjs/{string-input-formatter-slimmer-072b75a0.js → string-input-formatter-slimmer-f45931fd.js} +111 -32
  5. package/dist/cjs/vega-date-picker_2.cjs.entry.js +2 -2
  6. package/dist/cjs/vega-env-manager-23b8b23c.js +2 -2
  7. package/dist/cjs/vega-input.cjs.entry.js +6 -4
  8. package/dist/cjs/vega-loader-wrapper_2.cjs.entry.js +54 -1
  9. package/dist/cjs/vega-rich-text-editor_4.cjs.entry.js +1 -1
  10. package/dist/cjs/{vega-skeleton-loader-controller-ef43cfc1.js → vega-skeleton-loader-controller-00dbdf29.js} +11 -3
  11. package/dist/cjs/vega.cjs.js +2 -2
  12. package/dist/collection/components/vega-loader-wrapper/slimmers/controllers/manage-vega-loader-wrapper-z-index-controller.js +49 -0
  13. package/dist/collection/components/vega-loader-wrapper/vega-loader-wrapper.js +5 -0
  14. package/dist/collection/helpers/formatter/string-formatter/custom-formatter-strategy.js +3 -1
  15. package/dist/collection/helpers/formatter/string-formatter/number-mask-strategy.js +3 -1
  16. package/dist/collection/helpers/formatter/string-formatter/string-format-strategy.abstract.js +52 -0
  17. package/dist/collection/helpers/formatter/string-formatter/string-mask-strategy.js +6 -7
  18. package/dist/collection/helpers/formatter/string-formatter/thousand-comma-strategy.js +2 -1
  19. package/dist/collection/helpers/formatter/test/string-formatter/custom-formatter-strategy.test.js +2 -1
  20. package/dist/collection/helpers/formatter/test/string-formatter/number-mask-strategy.test.js +9 -0
  21. package/dist/collection/helpers/formatter/test/string-formatter/string-mask-strategy.test.js +62 -4
  22. package/dist/collection/helpers/loading-indicator/tests/vega-loader-controller.test.js +29 -2
  23. package/dist/collection/helpers/loading-indicator/vega-loader-controller.js +11 -3
  24. package/dist/collection/helpers/slimmers/string-input-formatter-slimmer.js +53 -25
  25. package/dist/collection/helpers/slimmers/test/string-input-formatter-slimmer.test.js +2 -1
  26. package/dist/esm/{app-globals-c1f2bea9.js → app-globals-4cca4a96.js} +1 -1
  27. package/dist/esm/index.js +1 -1
  28. package/dist/esm/loader.js +2 -2
  29. package/dist/esm/{string-input-formatter-slimmer-930f1125.js → string-input-formatter-slimmer-d4132497.js} +111 -33
  30. package/dist/esm/vega-date-picker_2.entry.js +2 -2
  31. package/dist/esm/vega-env-manager-8f8dc473.js +2 -2
  32. package/dist/esm/vega-input.entry.js +6 -4
  33. package/dist/esm/vega-loader-wrapper_2.entry.js +55 -2
  34. package/dist/esm/vega-rich-text-editor_4.entry.js +1 -1
  35. package/dist/esm/{vega-skeleton-loader-controller-0044d77f.js → vega-skeleton-loader-controller-5aea7aeb.js} +11 -3
  36. package/dist/esm/vega.js +2 -2
  37. package/dist/types/components/vega-date-picker/slimmers/controllers/vega-date-picker-format-controller.d.ts +1 -1
  38. package/dist/types/components/vega-input/slimmers/controllers/vega-input-mask-config-controller.d.ts +1 -1
  39. package/dist/types/components/vega-loader-wrapper/slimmers/controllers/manage-vega-loader-wrapper-z-index-controller.d.ts +21 -0
  40. package/dist/types/components/vega-loader-wrapper/vega-loader-wrapper.d.ts +2 -0
  41. package/dist/types/helpers/formatter/string-formatter/custom-formatter-strategy.d.ts +3 -3
  42. package/dist/types/helpers/formatter/string-formatter/number-mask-strategy.d.ts +2 -2
  43. package/dist/types/helpers/formatter/string-formatter/string-format-strategy.abstract.d.ts +48 -0
  44. package/dist/types/helpers/formatter/string-formatter/string-mask-strategy.d.ts +6 -10
  45. package/dist/types/helpers/formatter/string-formatter/thousand-comma-strategy.d.ts +2 -2
  46. package/dist/types/helpers/loading-indicator/vega-loader-controller.d.ts +1 -0
  47. package/dist/types/helpers/slimmers/string-input-formatter-slimmer.d.ts +20 -4
  48. package/dist/vega/index.esm.js +1 -1
  49. package/dist/vega/{p-6100e1aa.js → p-1d93b3a9.js} +1 -1
  50. package/dist/vega/p-20326c64.js +1 -0
  51. package/dist/vega/p-5f377954.js +1 -1
  52. package/dist/vega/p-76a8ccbb.js +1 -0
  53. package/dist/vega/{p-da66dad5.entry.js → p-9728d571.entry.js} +1 -1
  54. package/dist/vega/{p-9eb90ee8.entry.js → p-a2a34239.entry.js} +1 -1
  55. package/dist/vega/p-e4ce559d.entry.js +1 -0
  56. package/dist/vega/p-ecaf4cfa.entry.js +1 -0
  57. package/dist/vega/vega.esm.js +1 -1
  58. package/package.json +1 -1
  59. package/dist/types/helpers/formatter/string-formatter/string-format-strategy.d.ts +0 -12
  60. package/dist/vega/p-4c18ff36.js +0 -1
  61. package/dist/vega/p-84a7c18a.entry.js +0 -1
  62. package/dist/vega/p-a98475a2.entry.js +0 -1
  63. package/dist/vega/p-b2d47bdd.js +0 -1
@@ -1,16 +1,18 @@
1
+ import { StringFormatStrategy } from './string-format-strategy.abstract';
1
2
  import { isNonNullable } from '../../../types/type-guard';
2
3
  /**
3
4
  * A class for formatting string with the given mask format
4
5
  *
5
6
  * @augments StringFormatStrategy
6
7
  */
7
- export class StringMaskStrategy {
8
+ export class StringMaskStrategy extends StringFormatStrategy {
8
9
  /**
9
10
  * It creates a new instance of the Mask class.
10
11
  *
11
12
  * @param {MaskConfig} maskConfig - MaskConfig
12
13
  */
13
14
  constructor(maskConfig) {
15
+ super();
14
16
  /**
15
17
  * The insert mode means adding some special character in the input string, will replace part of input string if insertMode set to false.
16
18
  *
@@ -29,13 +31,10 @@ export class StringMaskStrategy {
29
31
  this.insertMode = maskConfig.insertMode === false ? false : true;
30
32
  }
31
33
  /**
32
- * Given a string, it replaces the mask with the matched input slot value
33
- *
34
- * @param {string} input - The input string that needs to be formatted.
35
- * @param {number} caretPosition - The current position of caret
36
- * @returns {string} The formatted string.
34
+ * @inheritDoc
37
35
  */
38
- format(input, caretPosition) {
36
+ format(input, inputStatus) {
37
+ const caretPosition = inputStatus === null || inputStatus === void 0 ? void 0 : inputStatus.caretPosition;
39
38
  if (input.length > this.getLengthLimit() && isNonNullable(caretPosition)) {
40
39
  const rawValueArr = [...input];
41
40
  const exceededLength = input.length - this.getLengthLimit();
@@ -1,9 +1,10 @@
1
+ import { StringFormatStrategy } from './string-format-strategy.abstract';
1
2
  /**
2
3
  * A class for formatting string with the "," as the thousand separator
3
4
  *
4
5
  * @augments StringFormatStrategy
5
6
  */
6
- export class ThousandCommaStrategy {
7
+ export class ThousandCommaStrategy extends StringFormatStrategy {
7
8
  /**
8
9
  * If the input is a number, format it as a string
9
10
  *
@@ -3,7 +3,8 @@ test('custom formatter strategy is working as expected', () => {
3
3
  const customFormatterStrategy = new CustomFormatterStrategy((value) => value.toUpperCase(), true);
4
4
  expect(customFormatterStrategy.format('test')).toBe('TEST');
5
5
  expect(customFormatterStrategy.calculateCaretPosition('test', null)).toBe(4);
6
- expect(customFormatterStrategy.shouldTriggerAtInit()).toBe(true);
6
+ expect(customFormatterStrategy.canFormat('init', 'component')).toBe(true);
7
+ expect(customFormatterStrategy.canFormat('init', 'native-input')).toBe(true);
7
8
  });
8
9
  test('custom formatter strategy method calculateCaretPosition is working as expected', () => {
9
10
  const customFormatterStrategy = new CustomFormatterStrategy((value) => value.toUpperCase());
@@ -89,4 +89,13 @@ describe('numberStrategy', () => {
89
89
  expect(numberStrategy.calculateCaretPosition('00.123', 6)).toBe(5);
90
90
  expect(numberStrategy.calculateCaretPosition('00.123', undefined)).toBe(undefined);
91
91
  });
92
+ it('canFormat should return as expect', () => {
93
+ const numberStrategy = new NumberMaskStrategy();
94
+ expect(numberStrategy.canFormat('init', 'component')).toBe(false);
95
+ expect(numberStrategy.canFormat('input', 'native-input')).toBe(true);
96
+ expect(numberStrategy.canFormat('blur', 'component', { isBlurred: true })).toBe(false);
97
+ expect(numberStrategy.canFormat('blur', 'component', { isBlurred: false })).toBe(false);
98
+ expect(numberStrategy.canFormat('blur', 'native-input', { isBlurred: true })).toBe(true);
99
+ expect(numberStrategy.canFormat('blur', 'native-input', { isBlurred: false })).toBe(false);
100
+ });
92
101
  });
@@ -55,7 +55,7 @@ test('should work as expected when slot and accept is regex', () => {
55
55
  expect(mask5.format('456')).toBe('');
56
56
  });
57
57
  test('mask format with caretPosition', () => {
58
- expect(StringMaskStrategy.ZIPCODE_MASK.format('123456', 3)).toBe('12456'); // |456 -> 12|456
58
+ expect(StringMaskStrategy.ZIPCODE_MASK.format('123456', { caretPosition: 3 })).toBe('12456'); // |456 -> 12|456
59
59
  });
60
60
  test('calculate caret position', () => {
61
61
  expect(StringMaskStrategy.PHONE_MASK.calculateCaretPosition('(123) 456-7890', null)).toEqual(null);
@@ -70,11 +70,11 @@ test('shouldOverrideComponentValueAfterBlur', () => {
70
70
  accept: /\d/g,
71
71
  };
72
72
  const mask1 = new StringMaskStrategy(maskConfig);
73
- expect(mask1.shouldOverrideComponentValueAfterBlur()).toBeFalsy();
73
+ expect(mask1.canFormat('blur', 'component', { isBlurred: true })).toBeFalsy();
74
74
  const mask2 = new StringMaskStrategy(Object.assign(Object.assign({}, maskConfig), { overrideValue: true }));
75
- expect(mask2.shouldOverrideComponentValueAfterBlur()).toBeTruthy();
75
+ expect(mask2.canFormat('blur', 'component', { isBlurred: true })).toBeTruthy();
76
76
  const mask3 = new StringMaskStrategy(Object.assign(Object.assign({}, maskConfig), { overrideValue: false }));
77
- expect(mask3.shouldOverrideComponentValueAfterBlur()).toBeFalsy();
77
+ expect(mask3.canFormat('blur', 'component', { isBlurred: true })).toBeFalsy();
78
78
  });
79
79
  test('format in different insert mode', () => {
80
80
  const maskConfig = {
@@ -87,3 +87,61 @@ test('format in different insert mode', () => {
87
87
  const mask2 = new StringMaskStrategy(Object.assign(Object.assign({}, maskConfig), { insertMode: false }));
88
88
  expect(mask2.format('123456')).toEqual('***456');
89
89
  });
90
+ describe('string-mask-strategy', () => {
91
+ test('canFormat should work as expect when setting triggerAtInit', () => {
92
+ const strategyTriggerAtInit = new StringMaskStrategy({
93
+ mask: '(999) 999-9999',
94
+ slot: '9',
95
+ accept: /\d/g,
96
+ triggerAtInit: true,
97
+ });
98
+ expect(strategyTriggerAtInit.canFormat('init', 'component')).toBeTruthy();
99
+ expect(strategyTriggerAtInit.canFormat('init', 'native-input')).toBeTruthy();
100
+ expect(strategyTriggerAtInit.canFormat('input', 'native-input')).toBeTruthy();
101
+ expect(strategyTriggerAtInit.canFormat('blur', 'component', { isBlurred: true })).toBeFalsy();
102
+ expect(strategyTriggerAtInit.canFormat('blur', 'component', { isBlurred: false })).toBeFalsy();
103
+ expect(strategyTriggerAtInit.canFormat('blur', 'native-input', { isBlurred: true })).toBeTruthy();
104
+ expect(strategyTriggerAtInit.canFormat('blur', 'native-input', { isBlurred: false })).toBeFalsy();
105
+ const strategyNotTriggerAtInit = new StringMaskStrategy({
106
+ mask: '(999) 999-9999',
107
+ slot: '9',
108
+ accept: /\d/g,
109
+ triggerAtInit: false,
110
+ });
111
+ expect(strategyNotTriggerAtInit.canFormat('init', 'component')).toBeFalsy();
112
+ expect(strategyNotTriggerAtInit.canFormat('init', 'native-input')).toBeFalsy();
113
+ expect(strategyNotTriggerAtInit.canFormat('input', 'native-input')).toBeTruthy();
114
+ expect(strategyNotTriggerAtInit.canFormat('blur', 'component', { isBlurred: true })).toBeFalsy();
115
+ expect(strategyNotTriggerAtInit.canFormat('blur', 'component', { isBlurred: false })).toBeFalsy();
116
+ expect(strategyNotTriggerAtInit.canFormat('blur', 'native-input', { isBlurred: true })).toBeTruthy();
117
+ expect(strategyNotTriggerAtInit.canFormat('blur', 'native-input', { isBlurred: false })).toBeFalsy();
118
+ });
119
+ test('canFormat should work as expect when setting overrideValue', () => {
120
+ const strategyOverrideValue = new StringMaskStrategy({
121
+ mask: '(999) 999-9999',
122
+ slot: '9',
123
+ accept: /\d/g,
124
+ overrideValue: true,
125
+ });
126
+ expect(strategyOverrideValue.canFormat('init', 'component')).toBeFalsy();
127
+ expect(strategyOverrideValue.canFormat('init', 'native-input')).toBeFalsy();
128
+ expect(strategyOverrideValue.canFormat('input', 'native-input')).toBeTruthy();
129
+ expect(strategyOverrideValue.canFormat('blur', 'component', { isBlurred: true })).toBeTruthy();
130
+ expect(strategyOverrideValue.canFormat('blur', 'component', { isBlurred: false })).toBeFalsy();
131
+ expect(strategyOverrideValue.canFormat('blur', 'native-input', { isBlurred: true })).toBeTruthy();
132
+ expect(strategyOverrideValue.canFormat('blur', 'native-input', { isBlurred: false })).toBeFalsy();
133
+ const strategyNotOverrideValue = new StringMaskStrategy({
134
+ mask: '(999) 999-9999',
135
+ slot: '9',
136
+ accept: /\d/g,
137
+ overrideValue: false,
138
+ });
139
+ expect(strategyNotOverrideValue.canFormat('init', 'component')).toBeFalsy();
140
+ expect(strategyNotOverrideValue.canFormat('init', 'native-input')).toBeFalsy();
141
+ expect(strategyNotOverrideValue.canFormat('input', 'native-input')).toBeTruthy();
142
+ expect(strategyNotOverrideValue.canFormat('blur', 'component', { isBlurred: true })).toBeFalsy();
143
+ expect(strategyNotOverrideValue.canFormat('blur', 'component', { isBlurred: false })).toBeFalsy();
144
+ expect(strategyNotOverrideValue.canFormat('blur', 'native-input', { isBlurred: true })).toBeTruthy();
145
+ expect(strategyNotOverrideValue.canFormat('blur', 'native-input', { isBlurred: false })).toBeFalsy();
146
+ });
147
+ });
@@ -120,7 +120,34 @@ describe('VegaLoaderController', () => {
120
120
  VegaLoader.close(loader);
121
121
  expect(document.querySelector('body')).toMatchInlineSnapshot(`
122
122
  <body>
123
- <div data-vega-loader-origin-position id="container" style="position: static;">
123
+ <div data-vega-loader-origin-position id="container" style="position: relative;">
124
+ <mock:shadow-root></mock:shadow-root>
125
+ </div>
126
+ </body>
127
+ `);
128
+ });
129
+ it('should restore original display position when loader closes', () => {
130
+ const container = document.createElement('div');
131
+ container.attachShadow({ mode: 'open' });
132
+ container.id = 'container';
133
+ container.style.position = `static`;
134
+ document.querySelector('body').append(container);
135
+ const loader = VegaLoader.load({ containerSelector: '#container' });
136
+ expect(document.querySelector('body')).toEqualHtml(`
137
+ <body>
138
+ <div data-vega-loader-origin-position="static" id="container" style="position: relative;">
139
+ <mock:shadow-root>
140
+ <vega-loader-wrapper class="absolute-wrapper" data-container="#container" id="vega-loader-TEST_UUID">
141
+ <vega-loading-indicator></vega-loading-indicator>
142
+ </vega-loader-wrapper>
143
+ </mock:shadow-root>
144
+ </div>
145
+ </body>
146
+ `);
147
+ VegaLoader.close(loader);
148
+ expect(document.querySelector('body')).toMatchInlineSnapshot(`
149
+ <body>
150
+ <div data-vega-loader-origin-position="static" id="container" style="position: static;">
124
151
  <mock:shadow-root></mock:shadow-root>
125
152
  </div>
126
153
  </body>
@@ -143,7 +170,7 @@ describe('VegaLoaderController', () => {
143
170
  VegaLoader.close(loader);
144
171
  expect(document.querySelector('body')).toMatchInlineSnapshot(`
145
172
  <body>
146
- <div data-vega-loader-origin-position id="container" style="position: static;"></div>
173
+ <div data-vega-loader-origin-position id="container" style="position: relative;"></div>
147
174
  </body>
148
175
  `);
149
176
  });
@@ -25,8 +25,13 @@ class VegaLoaderController {
25
25
  * @vegaVersion 1.16.0
26
26
  */
27
27
  load(options = {}) {
28
- const containerSelector = options.containerSelector || 'body';
29
- const containerElement = document.querySelector(containerSelector);
28
+ let containerSelector = options.containerSelector || 'body';
29
+ let containerElement = document.querySelector(containerSelector);
30
+ if (containerElement &&
31
+ VegaLoaderController.SPECIAL_ELEMENT_TO_WRAP_FULL_BODY.includes(containerElement.tagName)) {
32
+ containerSelector = 'body';
33
+ containerElement = document.querySelector('body');
34
+ }
30
35
  if (!containerElement) {
31
36
  LogUtility.error('Container is not found by selector: ', containerSelector);
32
37
  return null;
@@ -48,7 +53,9 @@ class VegaLoaderController {
48
53
  if (loader.dataset.container) {
49
54
  const container = document.querySelector(loader.dataset.container);
50
55
  if (container) {
51
- container.style.position = container.dataset['vegaLoaderOriginPosition'] || 'static';
56
+ if (container.dataset['vegaLoaderOriginPosition']) {
57
+ container.style.position = container.dataset['vegaLoaderOriginPosition'];
58
+ }
52
59
  }
53
60
  }
54
61
  loader.remove();
@@ -118,6 +125,7 @@ class VegaLoaderController {
118
125
  }
119
126
  }
120
127
  }
128
+ VegaLoaderController.SPECIAL_ELEMENT_TO_WRAP_FULL_BODY = ['VEGA-MODAL'];
121
129
  __decorate([
122
130
  InjectVegaTelemetrySlimmer()
123
131
  ], VegaLoaderController.prototype, "vegaPublicAPIRuntimeMetricsSlimmer", void 0);
@@ -30,7 +30,7 @@ export class StringInputFormatterSlimmer extends VegaSlimmer {
30
30
  }
31
31
  };
32
32
  /**
33
- * A function update the value of the input element by inputFormatStrategy output.
33
+ * A function updates the value of the input element by inputFormatStrategy output.
34
34
  *
35
35
  * @param {InputEvent} e - blur event
36
36
  */
@@ -38,17 +38,11 @@ export class StringInputFormatterSlimmer extends VegaSlimmer {
38
38
  if (this.blurFormatStrategy) {
39
39
  const target = e.target;
40
40
  const rawValue = target.value;
41
- const maskedValue = this.blurFormatStrategy.format(rawValue);
42
- this.updateInputValue(rawValue, maskedValue);
43
- if (this.host &&
44
- this.blurFormatStrategy.shouldOverrideComponentValueAfterBlur &&
45
- this.blurFormatStrategy.shouldOverrideComponentValueAfterBlur()) {
46
- this.host['value'] = maskedValue;
47
- }
41
+ this.formatValue(rawValue, 'blur');
48
42
  }
49
43
  };
50
44
  /**
51
- * A function update the value of the input element by inputFormatStrategy output.
45
+ * A function updates the value of the input element by inputFormatStrategy output.
52
46
  *
53
47
  * @param {InputEvent} e - input event
54
48
  */
@@ -57,11 +51,9 @@ export class StringInputFormatterSlimmer extends VegaSlimmer {
57
51
  const rawValue = target.value;
58
52
  const caretPosition = target.selectionStart; // selectionStart is nullable, link https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionstart
59
53
  if (this.inputFormatStrategy) {
60
- const maskedValue = this.inputFormatStrategy.format(rawValue.replace(/\s/g, ''),
61
- // Paste input is difference with type input, it can set much characters at one time,
62
- // so we should make caretPosition as undefined to format all value.
63
- e.inputType === 'insertFromPaste' ? null : caretPosition);
64
- this.updateInputValue(rawValue, maskedValue);
54
+ this.formatValue(rawValue.replace(/\s/g, ''), 'input', {
55
+ caretPosition: e.inputType === 'insertFromPaste' ? undefined : caretPosition,
56
+ });
65
57
  this.updateInputCaretPosition(rawValue, caretPosition);
66
58
  }
67
59
  };
@@ -123,22 +115,13 @@ export class StringInputFormatterSlimmer extends VegaSlimmer {
123
115
  */
124
116
  formatValueAfterSetup() {
125
117
  void waitForComponentDidRender(this.host).then(() => {
126
- var _a, _b, _c, _d;
127
- const rawValue = this.inputElement.value;
128
- if ((_b = (_a = this.inputFormatStrategy) === null || _a === void 0 ? void 0 : _a.shouldTriggerAtInit) === null || _b === void 0 ? void 0 : _b.call(_a)) {
129
- this.host['value'] = this.inputFormatStrategy.format(rawValue);
130
- }
131
- if (((_d = (_c = this.blurFormatStrategy) === null || _c === void 0 ? void 0 : _c.shouldTriggerAtInit) === null || _d === void 0 ? void 0 : _d.call(_c)) && !this.isOnFocus()) {
132
- const maskedValue = this.blurFormatStrategy.format(rawValue);
133
- this.updateInputValue(rawValue, maskedValue);
134
- }
118
+ this.formatValue(this.inputElement.value, 'init');
135
119
  });
136
120
  }
137
121
  /*
138
122
  * The below method is e2e-test covered in
139
123
  * @see{module:vega-input-credit-card-dynamic-mask-e2e}
140
124
  */
141
- /* istanbul ignore next */
142
125
  /**
143
126
  * The function `isOnFocus` checks if the input element is currently focused.
144
127
  *
@@ -156,7 +139,7 @@ export class StringInputFormatterSlimmer extends VegaSlimmer {
156
139
  * @param {string} rawValue - the original value
157
140
  * @param {string} maskedValue - masked value
158
141
  */
159
- updateInputValue(rawValue, maskedValue) {
142
+ updateNativeInputValue(rawValue, maskedValue) {
160
143
  // link: https://stackoverflow.com/questions/52003841/why-doesnt-event-target-value-include-and-e-for-number-inputs
161
144
  // If the input value is '123.', '123' will be got from `target.value` when the input element type is number
162
145
  // '123.' will be formatted to '123', then `this.inputElement.value = 123`, '.' will never be filled in
@@ -164,6 +147,17 @@ export class StringInputFormatterSlimmer extends VegaSlimmer {
164
147
  this.inputElement.value = maskedValue;
165
148
  }
166
149
  }
150
+ /**
151
+ * Update the host value
152
+ *
153
+ * @param {string} rawValue - the original value
154
+ * @param {string} maskedValue - the masked value
155
+ */
156
+ updateComponentValue(rawValue, maskedValue) {
157
+ if (maskedValue !== rawValue) {
158
+ this.host['value'] = maskedValue;
159
+ }
160
+ }
167
161
  /**
168
162
  * Updated the input caret position after the mask format
169
163
  *
@@ -177,6 +171,40 @@ export class StringInputFormatterSlimmer extends VegaSlimmer {
177
171
  this.inputElement.setSelectionRange(newCaretPosition, newCaretPosition);
178
172
  }
179
173
  }
174
+ /**
175
+ * Format the value based on the input and blur format strategies.
176
+ *
177
+ * @param {string} rawValue - The original input value
178
+ * @param {FormatTrigger} triggeredBy - The trigger of the format
179
+ * @param {{ caretPosition?: number }} options - The options for the format
180
+ * @param {number} options.caretPosition - The current input caret position
181
+ */
182
+ formatValue(rawValue, triggeredBy, options) {
183
+ const isBlurred = !this.isOnFocus();
184
+ const caretPosition = options === null || options === void 0 ? void 0 : options.caretPosition;
185
+ if (this.inputFormatStrategy) {
186
+ if (this.inputFormatStrategy.canFormat(triggeredBy, 'component')) {
187
+ const formattedComponentValue = this.inputFormatStrategy.format(rawValue);
188
+ this.updateComponentValue(rawValue, formattedComponentValue);
189
+ }
190
+ if (this.inputFormatStrategy.canFormat(triggeredBy, 'native-input')) {
191
+ const formattedNativeInputValue = this.inputFormatStrategy.format(rawValue, {
192
+ caretPosition: caretPosition,
193
+ });
194
+ this.updateNativeInputValue(rawValue, formattedNativeInputValue);
195
+ }
196
+ }
197
+ if (this.blurFormatStrategy && isBlurred) {
198
+ if (this.blurFormatStrategy.canFormat(triggeredBy, 'component', { isBlurred })) {
199
+ const formattedComponentValue = this.blurFormatStrategy.format(rawValue);
200
+ this.updateComponentValue(rawValue, formattedComponentValue);
201
+ }
202
+ if (this.blurFormatStrategy.canFormat(triggeredBy, 'native-input', { isBlurred })) {
203
+ const formattedNativeInputValue = this.blurFormatStrategy.format(rawValue);
204
+ this.updateNativeInputValue(rawValue, formattedNativeInputValue);
205
+ }
206
+ }
207
+ }
180
208
  }
181
209
  __decorate([
182
210
  MapToComponentField()
@@ -9,6 +9,7 @@ import { InjectVegaSlimmer } from 'vega-slimmer/core';
9
9
  import { StringInputFormatterSlimmer } from '../string-input-formatter-slimmer';
10
10
  import { StringMaskStrategy } from '../../formatter/string-formatter/string-mask-strategy';
11
11
  import { ThousandCommaStrategy } from '../../formatter/string-formatter/thousand-comma-strategy';
12
+ import { StringFormatStrategy } from '../../formatter/string-formatter/string-format-strategy.abstract';
12
13
  import { dispatchPasteEvent } from '../../../utils/spec-utils';
13
14
  const createMockedInput = () => {
14
15
  const inputEl = document.createElement('input');
@@ -197,7 +198,7 @@ describe('StringInputFormatterSlimmer test suite', () => {
197
198
  expect(inputEl.value).toEqual('(115) 902-4055');
198
199
  });
199
200
  test('should work proper while formatter have not implement calculateCaretPosition method', () => {
200
- class FormatterSlimmer {
201
+ class FormatterSlimmer extends StringFormatStrategy {
201
202
  format(input) {
202
203
  return input;
203
204
  }
@@ -1,5 +1,5 @@
1
1
  import { F as FeatureFlag } from './feature-flag-controller-4b3fe6f8.js';
2
- import { V as VegaLoader, a as VegaNotify, b as VegaEventManager, c as VegaZIndexManager, d as VegaSkeletonLoader } from './vega-skeleton-loader-controller-0044d77f.js';
2
+ import { V as VegaLoader, a as VegaNotify, b as VegaEventManager, c as VegaZIndexManager, d as VegaSkeletonLoader } from './vega-skeleton-loader-controller-5aea7aeb.js';
3
3
  import { V as VegaThemeManager } from './node-annotation.abstract-b2e36bc4.js';
4
4
  import { M as MapToComponentMethod, V as VegaSlimmer, s as setVegaLogLevel, G as GlobalSlimmersRegistry } from './global-slimmer-registry-17c4efd4.js';
5
5
  import { V as VegaDialog } from './vega-dialog-controller-34eb8967.js';
package/dist/esm/index.js CHANGED
@@ -8,7 +8,7 @@ export { I as Icons, g as getIconFromToken } from './icons-8627925e.js';
8
8
  export { b as Typography, a as TypographyKeys, T as TypographyUrls } from './typography-396de03f.js';
9
9
  export { e as BoxDisplay, B as BreakpointKeys, C as CssStates, F as FlexDirections } from './ui-8424715a.js';
10
10
  export { F as FrameworkEnum, v as VegaEnvManager } from './vega-env-manager-8f8dc473.js';
11
- export { b as VegaEventManager, V as VegaLoader, a as VegaNotify, d as VegaSkeletonLoader, c as VegaZIndexManager } from './vega-skeleton-loader-controller-0044d77f.js';
11
+ export { b as VegaEventManager, V as VegaLoader, a as VegaNotify, d as VegaSkeletonLoader, c as VegaZIndexManager } from './vega-skeleton-loader-controller-5aea7aeb.js';
12
12
  export { F as FeatureFlag } from './feature-flag-controller-4b3fe6f8.js';
13
13
  export { M as ModifyContentAction, R as RTENode, V as VegaThemeManager } from './node-annotation.abstract-b2e36bc4.js';
14
14
  export { V as VegaDialog } from './vega-dialog-controller-34eb8967.js';
@@ -1,10 +1,10 @@
1
1
  import { p as promiseResolve, b as bootstrapLazy } from './index-187f71d1.js';
2
- import { g as globalScripts } from './app-globals-c1f2bea9.js';
2
+ import { g as globalScripts } from './app-globals-4cca4a96.js';
3
3
  import './feature-flag-controller-4b3fe6f8.js';
4
4
  import './global-slimmer-registry-17c4efd4.js';
5
5
  import './index-44c794b4.js';
6
6
  import './_commonjsHelpers-9943807e.js';
7
- import './vega-skeleton-loader-controller-0044d77f.js';
7
+ import './vega-skeleton-loader-controller-5aea7aeb.js';
8
8
  import './create-public-api-runtime-metrics-slimmer-9ab05523.js';
9
9
  import './dynamic-slimmer-90b8af32.js';
10
10
  import './ui-62e4be97.js';
@@ -5,18 +5,71 @@ import { d as domNodeSubjectFactory } from './dom-node-subject-factory-97deb349.
5
5
  import { a as VegaInternalComponentDidRender } from './vega-internal-event-id-d0690d0d.js';
6
6
  import { a as waitForComponentDidRender } from './index-6e05b241.js';
7
7
 
8
+ /**
9
+ * String format strategy abstract class
10
+ */
11
+ class StringFormatStrategy {
12
+ /**
13
+ * Check if the {@link format} should be applied
14
+ *
15
+ * @param {FormatTrigger} triggeredBy - The trigger of the format
16
+ * @param {FormatTarget} target - The target of the format
17
+ * @param {InputStatus} inputStatus - The status of the input
18
+ * @returns {boolean} - Whether the format should be applied
19
+ */
20
+ canFormat(triggeredBy, target, inputStatus) {
21
+ if (triggeredBy === 'init') {
22
+ if (target === 'component' && isNonNullable(inputStatus === null || inputStatus === void 0 ? void 0 : inputStatus.isBlurred)) {
23
+ return false;
24
+ }
25
+ if (this.shouldTriggerAtInit()) {
26
+ return true;
27
+ }
28
+ }
29
+ if (triggeredBy === 'input' && target === 'native-input') {
30
+ return true;
31
+ }
32
+ if (triggeredBy === 'blur' && (inputStatus === null || inputStatus === void 0 ? void 0 : inputStatus.isBlurred)) {
33
+ if (target === 'component' && this.shouldOverrideComponentValueAfterBlur()) {
34
+ return true;
35
+ }
36
+ if (target === 'native-input') {
37
+ return true;
38
+ }
39
+ }
40
+ return false;
41
+ }
42
+ /**
43
+ * Determines whether a component value should be overridden based on the mask configuration.
44
+ *
45
+ * @returns {boolean} - Whether the component value should be overridden.
46
+ */
47
+ shouldOverrideComponentValueAfterBlur() {
48
+ return false;
49
+ }
50
+ /**
51
+ * Determines whether the format should be triggered at init.
52
+ *
53
+ * @returns {boolean} - Whether the format should be triggered at init.
54
+ */
55
+ shouldTriggerAtInit() {
56
+ return false; // TODO: trigger at init feature is not implemented to all strategies. To keep the same behavior as before so set false here as default.
57
+ }
58
+ }
59
+
8
60
  /**
9
61
  * A class for formatting string with the given mask format
10
62
  *
11
63
  * @augments StringFormatStrategy
12
64
  */
13
- class StringMaskStrategy {
65
+ class StringMaskStrategy extends StringFormatStrategy {
14
66
  /**
15
67
  * It creates a new instance of the Mask class.
16
68
  *
17
69
  * @param {MaskConfig} maskConfig - MaskConfig
18
70
  */
19
71
  constructor(maskConfig) {
72
+ super();
20
73
  /**
21
74
  * The insert mode means adding some special character in the input string, will replace part of input string if insertMode set to false.
22
75
  *
@@ -35,13 +88,10 @@ class StringMaskStrategy {
35
88
  this.insertMode = maskConfig.insertMode === false ? false : true;
36
89
  }
37
90
  /**
38
- * Given a string, it replaces the mask with the matched input slot value
39
- *
40
- * @param {string} input - The input string that needs to be formatted.
41
- * @param {number} caretPosition - The current position of caret
42
- * @returns {string} The formatted string.
91
+ * @inheritDoc
43
92
  */
44
- format(input, caretPosition) {
93
+ format(input, inputStatus) {
94
+ const caretPosition = inputStatus === null || inputStatus === void 0 ? void 0 : inputStatus.caretPosition;
45
95
  if (input.length > this.getLengthLimit() && isNonNullable(caretPosition)) {
46
96
  const rawValueArr = [...input];
47
97
  const exceededLength = input.length - this.getLengthLimit();
@@ -191,7 +241,7 @@ class StringInputFormatterSlimmer extends VegaSlimmer {
191
241
  }
192
242
  };
193
243
  /**
194
- * A function update the value of the input element by inputFormatStrategy output.
244
+ * A function updates the value of the input element by inputFormatStrategy output.
195
245
  *
196
246
  * @param {InputEvent} e - blur event
197
247
  */
@@ -199,17 +249,11 @@ class StringInputFormatterSlimmer extends VegaSlimmer {
199
249
  if (this.blurFormatStrategy) {
200
250
  const target = e.target;
201
251
  const rawValue = target.value;
202
- const maskedValue = this.blurFormatStrategy.format(rawValue);
203
- this.updateInputValue(rawValue, maskedValue);
204
- if (this.host &&
205
- this.blurFormatStrategy.shouldOverrideComponentValueAfterBlur &&
206
- this.blurFormatStrategy.shouldOverrideComponentValueAfterBlur()) {
207
- this.host['value'] = maskedValue;
208
- }
252
+ this.formatValue(rawValue, 'blur');
209
253
  }
210
254
  };
211
255
  /**
212
- * A function update the value of the input element by inputFormatStrategy output.
256
+ * A function updates the value of the input element by inputFormatStrategy output.
213
257
  *
214
258
  * @param {InputEvent} e - input event
215
259
  */
@@ -218,11 +262,9 @@ class StringInputFormatterSlimmer extends VegaSlimmer {
218
262
  const rawValue = target.value;
219
263
  const caretPosition = target.selectionStart; // selectionStart is nullable, link https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionstart
220
264
  if (this.inputFormatStrategy) {
221
- const maskedValue = this.inputFormatStrategy.format(rawValue.replace(/\s/g, ''),
222
- // Paste input is difference with type input, it can set much characters at one time,
223
- // so we should make caretPosition as undefined to format all value.
224
- e.inputType === 'insertFromPaste' ? null : caretPosition);
225
- this.updateInputValue(rawValue, maskedValue);
265
+ this.formatValue(rawValue.replace(/\s/g, ''), 'input', {
266
+ caretPosition: e.inputType === 'insertFromPaste' ? undefined : caretPosition,
267
+ });
226
268
  this.updateInputCaretPosition(rawValue, caretPosition);
227
269
  }
228
270
  };
@@ -284,22 +326,13 @@ class StringInputFormatterSlimmer extends VegaSlimmer {
284
326
  */
285
327
  formatValueAfterSetup() {
286
328
  void waitForComponentDidRender(this.host).then(() => {
287
- var _a, _b, _c, _d;
288
- const rawValue = this.inputElement.value;
289
- if ((_b = (_a = this.inputFormatStrategy) === null || _a === void 0 ? void 0 : _a.shouldTriggerAtInit) === null || _b === void 0 ? void 0 : _b.call(_a)) {
290
- this.host['value'] = this.inputFormatStrategy.format(rawValue);
291
- }
292
- if (((_d = (_c = this.blurFormatStrategy) === null || _c === void 0 ? void 0 : _c.shouldTriggerAtInit) === null || _d === void 0 ? void 0 : _d.call(_c)) && !this.isOnFocus()) {
293
- const maskedValue = this.blurFormatStrategy.format(rawValue);
294
- this.updateInputValue(rawValue, maskedValue);
295
- }
329
+ this.formatValue(this.inputElement.value, 'init');
296
330
  });
297
331
  }
298
332
  /*
299
333
  * The below method is e2e-test covered in
300
334
  * @see{module:vega-input-credit-card-dynamic-mask-e2e}
301
335
  */
302
- /* istanbul ignore next */
303
336
  /**
304
337
  * The function `isOnFocus` checks if the input element is currently focused.
305
338
  *
@@ -317,7 +350,7 @@ class StringInputFormatterSlimmer extends VegaSlimmer {
317
350
  * @param {string} rawValue - the original value
318
351
  * @param {string} maskedValue - masked value
319
352
  */
320
- updateInputValue(rawValue, maskedValue) {
353
+ updateNativeInputValue(rawValue, maskedValue) {
321
354
  // link: https://stackoverflow.com/questions/52003841/why-doesnt-event-target-value-include-and-e-for-number-inputs
322
355
  // If the input value is '123.', '123' will be got from `target.value` when the input element type is number
323
356
  // '123.' will be formatted to '123', then `this.inputElement.value = 123`, '.' will never be filled in
@@ -325,6 +358,17 @@ class StringInputFormatterSlimmer extends VegaSlimmer {
325
358
  this.inputElement.value = maskedValue;
326
359
  }
327
360
  }
361
+ /**
362
+ * Update the host value
363
+ *
364
+ * @param {string} rawValue - the original value
365
+ * @param {string} maskedValue - the masked value
366
+ */
367
+ updateComponentValue(rawValue, maskedValue) {
368
+ if (maskedValue !== rawValue) {
369
+ this.host['value'] = maskedValue;
370
+ }
371
+ }
328
372
  /**
329
373
  * Updated the input caret position after the mask format
330
374
  *
@@ -338,6 +382,40 @@ class StringInputFormatterSlimmer extends VegaSlimmer {
338
382
  this.inputElement.setSelectionRange(newCaretPosition, newCaretPosition);
339
383
  }
340
384
  }
385
+ /**
386
+ * Format the value based on the input and blur format strategies.
387
+ *
388
+ * @param {string} rawValue - The original input value
389
+ * @param {FormatTrigger} triggeredBy - The trigger of the format
390
+ * @param {{ caretPosition?: number }} options - The options for the format
391
+ * @param {number} options.caretPosition - The current input caret position
392
+ */
393
+ formatValue(rawValue, triggeredBy, options) {
394
+ const isBlurred = !this.isOnFocus();
395
+ const caretPosition = options === null || options === void 0 ? void 0 : options.caretPosition;
396
+ if (this.inputFormatStrategy) {
397
+ if (this.inputFormatStrategy.canFormat(triggeredBy, 'component')) {
398
+ const formattedComponentValue = this.inputFormatStrategy.format(rawValue);
399
+ this.updateComponentValue(rawValue, formattedComponentValue);
400
+ }
401
+ if (this.inputFormatStrategy.canFormat(triggeredBy, 'native-input')) {
402
+ const formattedNativeInputValue = this.inputFormatStrategy.format(rawValue, {
403
+ caretPosition: caretPosition,
404
+ });
405
+ this.updateNativeInputValue(rawValue, formattedNativeInputValue);
406
+ }
407
+ }
408
+ if (this.blurFormatStrategy && isBlurred) {
409
+ if (this.blurFormatStrategy.canFormat(triggeredBy, 'component', { isBlurred })) {
410
+ const formattedComponentValue = this.blurFormatStrategy.format(rawValue);
411
+ this.updateComponentValue(rawValue, formattedComponentValue);
412
+ }
413
+ if (this.blurFormatStrategy.canFormat(triggeredBy, 'native-input', { isBlurred })) {
414
+ const formattedNativeInputValue = this.blurFormatStrategy.format(rawValue);
415
+ this.updateNativeInputValue(rawValue, formattedNativeInputValue);
416
+ }
417
+ }
418
+ }
341
419
  }
342
420
  __decorate([
343
421
  MapToComponentField()
@@ -346,4 +424,4 @@ __decorate([
346
424
  MapToComponentMethod('componentDidRender')
347
425
  ], StringInputFormatterSlimmer.prototype, "componentDidRender", null);
348
426
 
349
- export { StringInputFormatterSlimmer as S, StringMaskStrategy as a };
427
+ export { StringFormatStrategy as S, StringInputFormatterSlimmer as a, StringMaskStrategy as b };