@sula-tech/webcomponents 0.12.0 → 0.13.0

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.
@@ -29045,10 +29045,6 @@ const SulaTextfield = class {
29045
29045
  * The textfield status
29046
29046
  */
29047
29047
  this.status = SulaTextfieldStatus.Default;
29048
- /**
29049
- * Max input length used to switch between the first and second mask pattern.
29050
- */
29051
- this.maskPatternSwitchMaxLength = 14;
29052
29048
  this.inputIsOpen = false;
29053
29049
  this.textValue = '';
29054
29050
  this.showPassword = false;
@@ -29167,13 +29163,13 @@ const SulaTextfield = class {
29167
29163
  }
29168
29164
  }
29169
29165
  handleInputMask(inputValue) {
29170
- var _a;
29166
+ var _a, _b;
29171
29167
  if (!this.inputElement)
29172
29168
  return;
29173
- const maskPattern = this.getMaskPatternByValueLength(inputValue);
29169
+ const valueWithoutMask = ((_a = inputValue !== null && inputValue !== void 0 ? inputValue : this.inputElement.value) !== null && _a !== void 0 ? _a : '').replace(/[^a-zA-Z0-9]/g, '');
29170
+ const maskPattern = this.getMaskPatternByValueLength(valueWithoutMask, (_b = inputValue !== null && inputValue !== void 0 ? inputValue : this.inputElement.value) !== null && _b !== void 0 ? _b : '');
29174
29171
  if (!maskPattern)
29175
29172
  return;
29176
- const valueWithoutMask = ((_a = inputValue !== null && inputValue !== void 0 ? inputValue : this.inputElement.value) !== null && _a !== void 0 ? _a : '').replace(/[^a-zA-Z0-9]/g, '');
29177
29173
  VMasker(this.inputElement).unMask();
29178
29174
  this.inputElement.value = VMasker.toPattern(valueWithoutMask, maskPattern);
29179
29175
  }
@@ -29200,17 +29196,57 @@ const SulaTextfield = class {
29200
29196
  }
29201
29197
  return [];
29202
29198
  }
29203
- getMaskPatternByValueLength(inputValue) {
29204
- var _a, _b, _c;
29199
+ getMaskPatternByValueLength(inputValue, rawInputValue) {
29205
29200
  const patterns = this.getMaskPatterns();
29206
29201
  if (patterns.length === 0)
29207
29202
  return undefined;
29208
29203
  if (patterns.length === 1)
29209
29204
  return patterns[0];
29210
- const currentValueLength = ((_b = inputValue !== null && inputValue !== void 0 ? inputValue : (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '').length;
29211
- const switchMaxLength = (_c = this.maskPatternSwitchMaxLength) !== null && _c !== void 0 ? _c : 14;
29212
- const selectedIndex = currentValueLength > switchMaxLength ? 1 : 0;
29213
- return patterns[Math.min(selectedIndex, patterns.length - 1)];
29205
+ const currentValueLength = (inputValue !== null && inputValue !== void 0 ? inputValue : '').length;
29206
+ const providedSwitchLengths = this.normalizeProvidedSwitchLengths();
29207
+ if (providedSwitchLengths.length === 0) {
29208
+ return this.getMaskPatternByAutoInference(patterns, currentValueLength, rawInputValue);
29209
+ }
29210
+ for (let i = 0; i < providedSwitchLengths.length; i++) {
29211
+ if (currentValueLength <= providedSwitchLengths[i]) {
29212
+ return patterns[Math.min(i, patterns.length - 1)];
29213
+ }
29214
+ }
29215
+ return patterns[patterns.length - 1];
29216
+ }
29217
+ getMaskPatternByAutoInference(patterns, currentValueLength, rawInputValue) {
29218
+ const capacities = patterns.map(pattern => (pattern.match(/[9AS]/g) || []).length);
29219
+ const eligibleCapacities = capacities.filter(capacity => capacity >= currentValueLength && capacity > 0);
29220
+ if (eligibleCapacities.length === 0) {
29221
+ return patterns[patterns.length - 1];
29222
+ }
29223
+ const selectedCapacity = Math.min(...eligibleCapacities);
29224
+ const candidateIndexes = capacities
29225
+ .map((capacity, index) => ({ capacity, index }))
29226
+ .filter(item => item.capacity === selectedCapacity)
29227
+ .map(item => item.index);
29228
+ if (candidateIndexes.length === 1) {
29229
+ return patterns[candidateIndexes[0]];
29230
+ }
29231
+ const rawLiterals = (rawInputValue !== null && rawInputValue !== void 0 ? rawInputValue : '').replace(/[a-zA-Z0-9]/g, '');
29232
+ if (rawLiterals.length > 0) {
29233
+ for (const candidateIndex of candidateIndexes) {
29234
+ const patternLiterals = patterns[candidateIndex].replace(/[9AS]/g, '');
29235
+ if (patternLiterals === rawLiterals) {
29236
+ return patterns[candidateIndex];
29237
+ }
29238
+ }
29239
+ }
29240
+ return patterns[candidateIndexes[0]];
29241
+ }
29242
+ normalizeProvidedSwitchLengths() {
29243
+ if (Array.isArray(this.maskPatternSwitchMaxLength)) {
29244
+ return this.maskPatternSwitchMaxLength.filter(value => Number.isFinite(value) && value > 0).sort((a, b) => a - b);
29245
+ }
29246
+ if (typeof this.maskPatternSwitchMaxLength === 'number' && Number.isFinite(this.maskPatternSwitchMaxLength) && this.maskPatternSwitchMaxLength > 0) {
29247
+ return [this.maskPatternSwitchMaxLength];
29248
+ }
29249
+ return [];
29214
29250
  }
29215
29251
  handlePasswordIconClicked() {
29216
29252
  const cursorPosition = this.inputElement.selectionStart;
@@ -29230,14 +29266,14 @@ const SulaTextfield = class {
29230
29266
  return this.icon;
29231
29267
  }
29232
29268
  render() {
29233
- return (index.h(index.Host, { key: 'b857d08cc9d53c1cfaa87a573d52026b9b72d088', ref: node => (this.node = node) }, index.h("div", { key: 'd173e497fbe8c78b899a1e66784d411981008abb' }, index.h("div", { key: 'bc1682f30d7ffb0eb890baba6d126d3cdbaf3a20', id: "button-container", class: {
29269
+ return (index.h(index.Host, { key: '0dbf51792e5bdc43328820106b083d194bbcae61', ref: node => (this.node = node) }, index.h("div", { key: '3659f51f5a9d0c75909e6a6939b8ff1b5c25e377' }, index.h("div", { key: '320da879fdea605e95525f54607c9cb285446133', id: "button-container", class: {
29234
29270
  'flex items-center border rounded-sm px-16 outline-none h-[72px] caret-brand-primary': true,
29235
29271
  'flex-row justify-between': !!this.icon || this.type === SulaTextfieldType.Password,
29236
29272
  'button-focus': this.inputIsFocused && !this.disabled && this.status === SulaTextfieldStatus.Default,
29237
29273
  'button-error': this.status === SulaTextfieldStatus.Error && !this.disabled,
29238
29274
  'bg-states-bg-disabled border-line-general cursor-not-allowed': this.disabled,
29239
29275
  'bg-surface-body border-line-input cursor-pointer': !this.disabled,
29240
- }, tabIndex: 0, onFocus: this.handleFocus, onClick: this.handleInputClick }, !this.disabled && (index.h("div", { key: '7e78f2a5b2d0bd3111ddfec6a592d907ac1aa078', class: { 'hidden flex-col w-full': true, 'pr-12': !!this.icon }, ref: node => (this.inputContainer = node) }, index.h("label", { key: 'd0419a71fb3372d34b07625acd95bae71b1133a0', class: "font-bold text-sm text-text-primary from-down" }, this.label), index.h("input", { key: '11926def24206e02e0fcd0e4ba7b94664f1ca21a', type: this.type, ref: node => (this.inputElement = node), placeholder: this.placeholder, class: "outline-none text-base text-text-primary bg-transparent", onInput: this.handleInputChanges, onFocus: this.handleInputFocus, value: this.textValue }))), index.h("div", { key: '93118f3270d2f325dd474805ed6870cb1cddb2bd', id: "textfield-label", class: { 'text-base flex items-center': true, 'text-text-primary': !this.disabled, 'text-text-disabled': this.disabled }, ref: node => (this.labelElement = node) }, this.label), (!!this.icon || this.type === SulaTextfieldType.Password) && (index.h("div", { key: 'bc78873f12cd069f1987dddbfd9eea29f5c07c8e', class: "flex items-center justify-center", onClick: this.handleIconClick }, index.h("sula-icon", { key: 'f8a30c1ea8f73e748ce43b4f0029a83435e88d2b', icon: this.getInputIcon(), customClass: `text-2xl ${this.disabled ? 'text-icon-disabled' : 'text-icon-primary'}` })))), (this.helpText || this.maxLength) && !this.disabled && (index.h("div", { key: 'e6cc2bed4087a75fe8ed2541af38e44778144485', class: "flex justify-between items-center px-16 mt-4 text-sm" }, this.helpText && (index.h("div", { key: 'ed826977d2f85c23c4e41c51bab2a35a093d4207', id: "textfield-help-text", class: { 'text-text-primary': this.status === SulaTextfieldStatus.Default, 'text-feedback-error': this.status === SulaTextfieldStatus.Error } }, this.helpText)), this.maxLength && (index.h("div", { key: '595dd29e865d45bcc1df11dc024eb1c9db77e990', id: "max-length-container", class: { 'text-text-primary': this.status === SulaTextfieldStatus.Default, 'text-feedback-error': this.status === SulaTextfieldStatus.Error } }, this.textValue ? this.textValue.length : 0, "/", this.maxLength)))))));
29276
+ }, tabIndex: 0, onFocus: this.handleFocus, onClick: this.handleInputClick }, !this.disabled && (index.h("div", { key: '44777180c60bb9a21ef64cffd98f465cf15af446', class: { 'hidden flex-col w-full': true, 'pr-12': !!this.icon }, ref: node => (this.inputContainer = node) }, index.h("label", { key: '75bc3b05a66ed7c00915842b275faf657b1784b3', class: "font-bold text-sm text-text-primary from-down" }, this.label), index.h("input", { key: '4f6bde78c385dc3c158c08be70f2277e56f7ab95', type: this.type, ref: node => (this.inputElement = node), placeholder: this.placeholder, class: "outline-none text-base text-text-primary bg-transparent", onInput: this.handleInputChanges, onFocus: this.handleInputFocus, value: this.textValue }))), index.h("div", { key: 'df7e84e77d3d05ba0328f736e6c03f45d32c9c76', id: "textfield-label", class: { 'text-base flex items-center': true, 'text-text-primary': !this.disabled, 'text-text-disabled': this.disabled }, ref: node => (this.labelElement = node) }, this.label), (!!this.icon || this.type === SulaTextfieldType.Password) && (index.h("div", { key: '55dba31d1ca9d6b213900b9a2d3aa02044b246ef', class: "flex items-center justify-center", onClick: this.handleIconClick }, index.h("sula-icon", { key: '19712e5575abb7aaef17a098de13543ed550dc6c', icon: this.getInputIcon(), customClass: `text-2xl ${this.disabled ? 'text-icon-disabled' : 'text-icon-primary'}` })))), (this.helpText || this.maxLength) && !this.disabled && (index.h("div", { key: '0c68e89181316ffed13f212a5c7f6ba78372e83c', class: "flex justify-between items-center px-16 mt-4 text-sm" }, this.helpText && (index.h("div", { key: 'af970054750c28cb8a9901fcf850c7c02fd059b9', id: "textfield-help-text", class: { 'text-text-primary': this.status === SulaTextfieldStatus.Default, 'text-feedback-error': this.status === SulaTextfieldStatus.Error } }, this.helpText)), this.maxLength && (index.h("div", { key: 'e78a661c6c614d2d6787159137cce01bf129e2c2', id: "max-length-container", class: { 'text-text-primary': this.status === SulaTextfieldStatus.Default, 'text-feedback-error': this.status === SulaTextfieldStatus.Error } }, this.textValue ? this.textValue.length : 0, "/", this.maxLength)))))));
29241
29277
  }
29242
29278
  static get watchers() { return {
29243
29279
  "value": ["watchValueHandler"],