@lukso/web-components 1.187.0 → 1.188.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.
@@ -28,6 +28,7 @@ exports.LuksoAlert = class LuksoAlert extends index.TailwindStyledElement(style)
28
28
  this.hasIcon = false;
29
29
  this.title = "";
30
30
  this.description = "";
31
+ this.isFullWidth = false;
31
32
  this.styles = tailwindVariants.tv({
32
33
  base: "rounded-8 p-4 flex gap-3 items-center",
33
34
  variants: {
@@ -36,6 +37,9 @@ exports.LuksoAlert = class LuksoAlert extends index.TailwindStyledElement(style)
36
37
  warning: "bg-honey-92 text-yellow-25",
37
38
  error: "bg-red-95 text-red-55",
38
39
  success: "bg-green-95 text-green-45"
40
+ },
41
+ isFullWidth: {
42
+ true: "w-full"
39
43
  }
40
44
  }
41
45
  });
@@ -54,7 +58,8 @@ exports.LuksoAlert = class LuksoAlert extends index.TailwindStyledElement(style)
54
58
  }
55
59
  render() {
56
60
  const styles = this.styles({
57
- variant: this.variant
61
+ variant: this.variant,
62
+ isFullWidth: this.isFullWidth
58
63
  });
59
64
  return lit.html`
60
65
  <div class=${styles}>
@@ -86,6 +91,9 @@ __decorateClass([
86
91
  __decorateClass([
87
92
  decorators_js.property({ type: String })
88
93
  ], exports.LuksoAlert.prototype, "description", 2);
94
+ __decorateClass([
95
+ decorators_js.property({ type: Boolean, attribute: "is-full-width", reflect: true })
96
+ ], exports.LuksoAlert.prototype, "isFullWidth", 2);
89
97
  exports.LuksoAlert = __decorateClass([
90
98
  safeCustomElement.safeCustomElement("lukso-alert")
91
99
  ], exports.LuksoAlert);
@@ -8,6 +8,7 @@ export declare class LuksoAlert extends LuksoAlert_base {
8
8
  hasIcon: boolean;
9
9
  title: string | undefined;
10
10
  description: string | undefined;
11
+ isFullWidth: boolean;
11
12
  private styles;
12
13
  private get icon();
13
14
  render(): import('lit-html').TemplateResult<1>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/lukso-alert/index.ts"],"names":[],"mappings":"AAMA,OAAO,yBAAyB,CAAA;AAChC,OAAO,6BAA6B,CAAA;AAGpC,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAA;;AAEnE;;GAEG;AACH,qBACa,UAAW,SAAQ,eAA4B;IAE1D,OAAO,EAAE,YAAY,GAAG,SAAS,CAAS;IAG1C,OAAO,UAAQ;IAGf,KAAK,EAAE,MAAM,GAAG,SAAS,CAAK;IAG9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAK;IAEpC,OAAO,CAAC,MAAM,CAUZ;IAEF,OAAO,KAAK,IAAI,GAWf;IAED,MAAM;CA4BP;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,UAAU,CAAA;KAC1B;CACF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/lukso-alert/index.ts"],"names":[],"mappings":"AAMA,OAAO,yBAAyB,CAAA;AAChC,OAAO,6BAA6B,CAAA;AAGpC,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAA;;AAEnE;;GAEG;AACH,qBACa,UAAW,SAAQ,eAA4B;IAE1D,OAAO,EAAE,YAAY,GAAG,SAAS,CAAS;IAG1C,OAAO,UAAQ;IAGf,KAAK,EAAE,MAAM,GAAG,SAAS,CAAK;IAG9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAK;IAGpC,WAAW,UAAQ;IAEnB,OAAO,CAAC,MAAM,CAaZ;IAEF,OAAO,KAAK,IAAI,GAWf;IAED,MAAM;CA6BP;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,UAAU,CAAA;KAC1B;CACF"}
@@ -24,6 +24,7 @@ let LuksoAlert = class extends TailwindStyledElement(style) {
24
24
  this.hasIcon = false;
25
25
  this.title = "";
26
26
  this.description = "";
27
+ this.isFullWidth = false;
27
28
  this.styles = tv({
28
29
  base: "rounded-8 p-4 flex gap-3 items-center",
29
30
  variants: {
@@ -32,6 +33,9 @@ let LuksoAlert = class extends TailwindStyledElement(style) {
32
33
  warning: "bg-honey-92 text-yellow-25",
33
34
  error: "bg-red-95 text-red-55",
34
35
  success: "bg-green-95 text-green-45"
36
+ },
37
+ isFullWidth: {
38
+ true: "w-full"
35
39
  }
36
40
  }
37
41
  });
@@ -50,7 +54,8 @@ let LuksoAlert = class extends TailwindStyledElement(style) {
50
54
  }
51
55
  render() {
52
56
  const styles = this.styles({
53
- variant: this.variant
57
+ variant: this.variant,
58
+ isFullWidth: this.isFullWidth
54
59
  });
55
60
  return html`
56
61
  <div class=${styles}>
@@ -82,6 +87,9 @@ __decorateClass([
82
87
  __decorateClass([
83
88
  property({ type: String })
84
89
  ], LuksoAlert.prototype, "description", 2);
90
+ __decorateClass([
91
+ property({ type: Boolean, attribute: "is-full-width", reflect: true })
92
+ ], LuksoAlert.prototype, "isFullWidth", 2);
85
93
  LuksoAlert = __decorateClass([
86
94
  safeCustomElement("lukso-alert")
87
95
  ], LuksoAlert);
@@ -12,4 +12,6 @@ export declare const ErrorAlert: any;
12
12
  export declare const SuccessAlert: any;
13
13
  /** Example of alert without icon. */
14
14
  export declare const AlertWithoutIcon: any;
15
+ /** Example of a full-width alert. */
16
+ export declare const FullWidthAlert: any;
15
17
  //# sourceMappingURL=lukso-alert.stories.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lukso-alert.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/lukso-alert/lukso-alert.stories.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAA;AAE1D,OAAO,SAAS,CAAA;AAEhB,8DAA8D;AAC9D,QAAA,MAAM,IAAI,EAAE,IA4DX,CAAA;AAED,eAAe,IAAI,CAAA;AAUnB,gCAAgC;AAChC,eAAO,MAAM,SAAS,KAAoB,CAAA;AAK1C,mCAAmC;AACnC,eAAO,MAAM,YAAY,KAAoB,CAAA;AAM7C,iCAAiC;AACjC,eAAO,MAAM,UAAU,KAAoB,CAAA;AAM3C,mCAAmC;AACnC,eAAO,MAAM,YAAY,KAAoB,CAAA;AAM7C,sCAAsC;AACtC,eAAO,MAAM,gBAAgB,KAAoB,CAAA"}
1
+ {"version":3,"file":"lukso-alert.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/lukso-alert/lukso-alert.stories.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAA;AAE1D,OAAO,SAAS,CAAA;AAEhB,8DAA8D;AAC9D,QAAA,MAAM,IAAI,EAAE,IA0EX,CAAA;AAED,eAAe,IAAI,CAAA;AAWnB,gCAAgC;AAChC,eAAO,MAAM,SAAS,KAAoB,CAAA;AAK1C,mCAAmC;AACnC,eAAO,MAAM,YAAY,KAAoB,CAAA;AAM7C,iCAAiC;AACjC,eAAO,MAAM,UAAU,KAAoB,CAAA;AAM3C,mCAAmC;AACnC,eAAO,MAAM,YAAY,KAAoB,CAAA;AAM7C,sCAAsC;AACtC,eAAO,MAAM,gBAAgB,KAAoB,CAAA;AAKjD,qCAAqC;AACrC,eAAO,MAAM,cAAc,KAAoB,CAAA"}
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const style = "/*! tailwindcss v4.1.18 | MIT License | https://tailwindcss.com */\n:host {\n display: flex;\n}\n";
3
+ const style = "/*! tailwindcss v4.1.18 | MIT License | https://tailwindcss.com */\n:host {\n display: flex;\n}\n\n:host([is-full-width]) {\n width: 100%;\n}\n";
4
4
 
5
5
  module.exports = style;
@@ -1,3 +1,3 @@
1
- const style = "/*! tailwindcss v4.1.18 | MIT License | https://tailwindcss.com */\n:host {\n display: flex;\n}\n";
1
+ const style = "/*! tailwindcss v4.1.18 | MIT License | https://tailwindcss.com */\n:host {\n display: flex;\n}\n\n:host([is-full-width]) {\n width: 100%;\n}\n";
2
2
 
3
3
  export { style as default };
@@ -17,6 +17,7 @@ require('../../shared/assets/index.cjs');
17
17
  const cn = require('../../shared/tools/cn.cjs');
18
18
  require('viem');
19
19
  const style = require('./style.css.cjs');
20
+ const rules = require('./rules.cjs');
20
21
 
21
22
  var __defProp = Object.defineProperty;
22
23
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -44,6 +45,11 @@ exports.LuksoInput = class LuksoInput extends index.TailwindStyledElement(style)
44
45
  this.rightIcon = "";
45
46
  this.isRightIconClickable = false;
46
47
  this.keepFocusOnEscape = false;
48
+ this.noComma = false;
49
+ this.noLeadingDot = false;
50
+ this.onlyOneDot = false;
51
+ this.onlyNumbersAndDot = false;
52
+ this.noDecimal = false;
47
53
  this.hasFocus = false;
48
54
  this.hasHighlight = false;
49
55
  this.inputStyles = tailwindVariants.tv({
@@ -258,6 +264,17 @@ exports.LuksoInput = class LuksoInput extends index.TailwindStyledElement(style)
258
264
  }
259
265
  async handleInput(event) {
260
266
  const target = event.target;
267
+ if (this.activeRules.length > 0) {
268
+ const sanitized = this.activeRules.reduce(
269
+ (val, rule) => rule.sanitize(val),
270
+ target.value
271
+ );
272
+ if (sanitized !== target.value) {
273
+ const cursor = target.selectionStart ?? sanitized.length;
274
+ target.value = sanitized;
275
+ target.setSelectionRange(cursor, cursor);
276
+ }
277
+ }
261
278
  this.value = target?.value;
262
279
  await this.updateComplete;
263
280
  const changeEvent = new CustomEvent("on-input", {
@@ -286,7 +303,26 @@ exports.LuksoInput = class LuksoInput extends index.TailwindStyledElement(style)
286
303
  this.blur();
287
304
  }
288
305
  }
306
+ get activeRules() {
307
+ const rules$1 = [];
308
+ if (this.noComma) rules$1.push(rules.noComma);
309
+ if (this.noLeadingDot) rules$1.push(rules.noLeadingDot);
310
+ if (this.onlyOneDot) rules$1.push(rules.onlyOneDot);
311
+ if (this.onlyNumbersAndDot) rules$1.push(rules.onlyNumbersAndDot);
312
+ if (this.noDecimal) rules$1.push(rules.noDecimal);
313
+ return rules$1;
314
+ }
289
315
  async handleKeyDown(event) {
316
+ if (event.key.length === 1 && this.activeRules.length > 0) {
317
+ const input = event.target;
318
+ const isValid = this.activeRules.every(
319
+ (rule) => rule.validate(input, event.key)
320
+ );
321
+ if (!isValid) {
322
+ event.preventDefault();
323
+ return;
324
+ }
325
+ }
290
326
  await this.updateComplete;
291
327
  const target = event.target;
292
328
  const keyEvent = new CustomEvent("on-key-down", {
@@ -464,6 +500,21 @@ __decorateClass([
464
500
  __decorateClass([
465
501
  decorators_js.property({ type: Boolean, attribute: "keep-focus-on-escape" })
466
502
  ], exports.LuksoInput.prototype, "keepFocusOnEscape", 2);
503
+ __decorateClass([
504
+ decorators_js.property({ type: Boolean, attribute: "no-comma" })
505
+ ], exports.LuksoInput.prototype, "noComma", 2);
506
+ __decorateClass([
507
+ decorators_js.property({ type: Boolean, attribute: "no-leading-dot" })
508
+ ], exports.LuksoInput.prototype, "noLeadingDot", 2);
509
+ __decorateClass([
510
+ decorators_js.property({ type: Boolean, attribute: "only-one-dot" })
511
+ ], exports.LuksoInput.prototype, "onlyOneDot", 2);
512
+ __decorateClass([
513
+ decorators_js.property({ type: Boolean, attribute: "only-numbers-and-dot" })
514
+ ], exports.LuksoInput.prototype, "onlyNumbersAndDot", 2);
515
+ __decorateClass([
516
+ decorators_js.property({ type: Boolean, attribute: "no-decimal" })
517
+ ], exports.LuksoInput.prototype, "noDecimal", 2);
467
518
  __decorateClass([
468
519
  decorators_js.state()
469
520
  ], exports.LuksoInput.prototype, "hasFocus", 2);
@@ -29,6 +29,11 @@ export declare class LuksoInput extends LuksoInput_base {
29
29
  rightIcon: string | undefined;
30
30
  isRightIconClickable: boolean;
31
31
  keepFocusOnEscape: boolean;
32
+ noComma: boolean;
33
+ noLeadingDot: boolean;
34
+ onlyOneDot: boolean;
35
+ onlyNumbersAndDot: boolean;
36
+ noDecimal: boolean;
32
37
  private hasFocus;
33
38
  private hasHighlight;
34
39
  private inputStyles;
@@ -41,6 +46,7 @@ export declare class LuksoInput extends LuksoInput_base {
41
46
  private handleChange;
42
47
  private handleInput;
43
48
  private handleKeyUp;
49
+ private get activeRules();
44
50
  private handleKeyDown;
45
51
  private handleKeyPress;
46
52
  private handleMouseOver;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/lukso-input/index.ts"],"names":[],"mappings":"AAKA,OAAO,yBAAyB,CAAA;AAChC,OAAO,6BAA6B,CAAA;AACpC,OAAO,+BAA+B,CAAA;AACtC,OAAO,qCAAqC,CAAA;AAC5C,OAAO,+BAA+B,CAAA;AAKtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;;AAI/C;;;GAGG;AACH,qBACa,UAAW,SAAQ,eAA4B;IAE1D,KAAK,EAAE,MAAM,GAAG,SAAS,CAAK;IAG9B,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IAGxB,IAAI,SAAS;IAGb,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAG/B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IAGzB,YAAY,SAAO;IAGnB,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;IAGtB,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IAGvB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAG1B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAG/B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IAGzB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IAGxB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAG/B,WAAW,UAAQ;IAGnB,UAAU,UAAQ;IAGlB,UAAU,UAAQ;IAGlB,SAAS,UAAQ;IAGjB,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IAGvB,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IAGvB,UAAU,UAAQ;IAGlB,IAAI,EAAE,SAAS,CA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a,EAAE,UAAU,CAAA;KAC1B;CACF"}
@@ -13,6 +13,7 @@ import '../../shared/assets/index.js';
13
13
  import { cn } from '../../shared/tools/cn.js';
14
14
  import 'viem';
15
15
  import style from './style.css.js';
16
+ import { noComma, noLeadingDot, onlyOneDot, onlyNumbersAndDot, noDecimal } from './rules.js';
16
17
 
17
18
  var __defProp = Object.defineProperty;
18
19
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -40,6 +41,11 @@ let LuksoInput = class extends TailwindStyledElement(style) {
40
41
  this.rightIcon = "";
41
42
  this.isRightIconClickable = false;
42
43
  this.keepFocusOnEscape = false;
44
+ this.noComma = false;
45
+ this.noLeadingDot = false;
46
+ this.onlyOneDot = false;
47
+ this.onlyNumbersAndDot = false;
48
+ this.noDecimal = false;
43
49
  this.hasFocus = false;
44
50
  this.hasHighlight = false;
45
51
  this.inputStyles = tv({
@@ -254,6 +260,17 @@ let LuksoInput = class extends TailwindStyledElement(style) {
254
260
  }
255
261
  async handleInput(event) {
256
262
  const target = event.target;
263
+ if (this.activeRules.length > 0) {
264
+ const sanitized = this.activeRules.reduce(
265
+ (val, rule) => rule.sanitize(val),
266
+ target.value
267
+ );
268
+ if (sanitized !== target.value) {
269
+ const cursor = target.selectionStart ?? sanitized.length;
270
+ target.value = sanitized;
271
+ target.setSelectionRange(cursor, cursor);
272
+ }
273
+ }
257
274
  this.value = target?.value;
258
275
  await this.updateComplete;
259
276
  const changeEvent = new CustomEvent("on-input", {
@@ -282,7 +299,26 @@ let LuksoInput = class extends TailwindStyledElement(style) {
282
299
  this.blur();
283
300
  }
284
301
  }
302
+ get activeRules() {
303
+ const rules = [];
304
+ if (this.noComma) rules.push(noComma);
305
+ if (this.noLeadingDot) rules.push(noLeadingDot);
306
+ if (this.onlyOneDot) rules.push(onlyOneDot);
307
+ if (this.onlyNumbersAndDot) rules.push(onlyNumbersAndDot);
308
+ if (this.noDecimal) rules.push(noDecimal);
309
+ return rules;
310
+ }
285
311
  async handleKeyDown(event) {
312
+ if (event.key.length === 1 && this.activeRules.length > 0) {
313
+ const input = event.target;
314
+ const isValid = this.activeRules.every(
315
+ (rule) => rule.validate(input, event.key)
316
+ );
317
+ if (!isValid) {
318
+ event.preventDefault();
319
+ return;
320
+ }
321
+ }
286
322
  await this.updateComplete;
287
323
  const target = event.target;
288
324
  const keyEvent = new CustomEvent("on-key-down", {
@@ -460,6 +496,21 @@ __decorateClass([
460
496
  __decorateClass([
461
497
  property({ type: Boolean, attribute: "keep-focus-on-escape" })
462
498
  ], LuksoInput.prototype, "keepFocusOnEscape", 2);
499
+ __decorateClass([
500
+ property({ type: Boolean, attribute: "no-comma" })
501
+ ], LuksoInput.prototype, "noComma", 2);
502
+ __decorateClass([
503
+ property({ type: Boolean, attribute: "no-leading-dot" })
504
+ ], LuksoInput.prototype, "noLeadingDot", 2);
505
+ __decorateClass([
506
+ property({ type: Boolean, attribute: "only-one-dot" })
507
+ ], LuksoInput.prototype, "onlyOneDot", 2);
508
+ __decorateClass([
509
+ property({ type: Boolean, attribute: "only-numbers-and-dot" })
510
+ ], LuksoInput.prototype, "onlyNumbersAndDot", 2);
511
+ __decorateClass([
512
+ property({ type: Boolean, attribute: "no-decimal" })
513
+ ], LuksoInput.prototype, "noDecimal", 2);
463
514
  __decorateClass([
464
515
  state()
465
516
  ], LuksoInput.prototype, "hasFocus", 2);
@@ -20,4 +20,6 @@ export declare const Borderless: any;
20
20
  export declare const Small: any;
21
21
  /** Example of input with icon on right side. */
22
22
  export declare const RightIcon: any;
23
+ /** Example of input with number rules enabled. Combines `only-numbers-and-dot`, `no-comma`, `no-leading-dot` and `only-one-dot` to enforce a valid decimal number format. */
24
+ export declare const NumberRules: any;
23
25
  //# sourceMappingURL=lukso-input.stories.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lukso-input.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/lukso-input/lukso-input.stories.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAA;AAE1D,OAAO,SAAS,CAAA;AAEhB,+DAA+D;AAC/D,QAAA,MAAM,IAAI,EAAE,IAiSX,CAAA;AAED,eAAe,IAAI,CAAA;AAiEnB,8CAA8C;AAC9C,eAAO,MAAM,YAAY,KAAoB,CAAA;AAK7C,gDAAgD;AAChD,eAAO,MAAM,eAAe,KAAoB,CAAA;AAKhD,wEAAwE;AACxE,eAAO,MAAM,cAAc,KAAoB,CAAA;AAO/C,oCAAoC;AACpC,eAAO,MAAM,IAAI,KAAoB,CAAA;AAKrC,+FAA+F;AAC/F,eAAO,MAAM,SAAS,KAAoB,CAAA;AAK1C,oMAAoM;AACpM,eAAO,MAAM,WAAW,KAAoB,CAAA;AAO5C,sEAAsE;AACtE,eAAO,MAAM,UAAU,KAAoB,CAAA;AAM3C,qCAAqC;AACrC,eAAO,MAAM,KAAK,KAAoB,CAAA;AAKtC,gDAAgD;AAChD,eAAO,MAAM,SAAS,KAAoB,CAAA"}
1
+ {"version":3,"file":"lukso-input.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/lukso-input/lukso-input.stories.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAA;AAE1D,OAAO,SAAS,CAAA;AAEhB,+DAA+D;AAC/D,QAAA,MAAM,IAAI,EAAE,IAsWX,CAAA;AAED,eAAe,IAAI,CAAA;AA2EnB,8CAA8C;AAC9C,eAAO,MAAM,YAAY,KAAoB,CAAA;AAK7C,gDAAgD;AAChD,eAAO,MAAM,eAAe,KAAoB,CAAA;AAKhD,wEAAwE;AACxE,eAAO,MAAM,cAAc,KAAoB,CAAA;AAO/C,oCAAoC;AACpC,eAAO,MAAM,IAAI,KAAoB,CAAA;AAKrC,+FAA+F;AAC/F,eAAO,MAAM,SAAS,KAAoB,CAAA;AAK1C,oMAAoM;AACpM,eAAO,MAAM,WAAW,KAAoB,CAAA;AAO5C,sEAAsE;AACtE,eAAO,MAAM,UAAU,KAAoB,CAAA;AAM3C,qCAAqC;AACrC,eAAO,MAAM,KAAK,KAAoB,CAAA;AAKtC,gDAAgD;AAChD,eAAO,MAAM,SAAS,KAAoB,CAAA;AAO1C,6KAA6K;AAC7K,eAAO,MAAM,WAAW,KAAoB,CAAA"}
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const noComma = {
6
+ name: "noComma",
7
+ validate: (_, key) => !key.includes(","),
8
+ sanitize: (value) => value.replaceAll(",", "")
9
+ };
10
+ const noLeadingDot = {
11
+ name: "noLeadingDot",
12
+ validate: (input, key) => !(key === "." && input.selectionStart === 0),
13
+ sanitize: (value) => value.replace(/^\.+/, "")
14
+ };
15
+ const onlyOneDot = {
16
+ name: "onlyOneDot",
17
+ validate: (input, key) => !(key === "." && input.value.split(".").length > 1),
18
+ sanitize: (value) => {
19
+ const [integer, ...decimals] = value.split(".");
20
+ return decimals.length > 0 ? `${integer}.${decimals.join("")}` : integer;
21
+ }
22
+ };
23
+ const onlyNumbersAndDot = {
24
+ name: "onlyNumbersAndDot",
25
+ validate: (_, key) => key === "" || /^[0-9.]$/.test(key),
26
+ sanitize: (value) => value.replace(/[^0-9.]/g, "")
27
+ };
28
+ const noDecimal = {
29
+ name: "noDecimal",
30
+ validate: (_, key) => key !== ".",
31
+ sanitize: (value) => value.replaceAll(".", "")
32
+ };
33
+
34
+ exports.noComma = noComma;
35
+ exports.noDecimal = noDecimal;
36
+ exports.noLeadingDot = noLeadingDot;
37
+ exports.onlyNumbersAndDot = onlyNumbersAndDot;
38
+ exports.onlyOneDot = onlyOneDot;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Type definition for a validation rule applied to number input fields.
3
+ *
4
+ * - `name`: Unique identifier for the rule (used for logging/debugging).
5
+ * - `validate`: Function that receives the HTML input and the last typed key,
6
+ * and returns a boolean indicating whether the input is valid.
7
+ * - `sanitize`: Function that receives the full value (e.g. after paste/autofill)
8
+ * and returns a cleaned version that satisfies the rule.
9
+ */
10
+ export type InputRule = {
11
+ name: string;
12
+ validate: (input: HTMLInputElement, key: string) => boolean;
13
+ sanitize: (value: string) => string;
14
+ };
15
+ /**
16
+ * Rule: Disallow the comma (`,`) character in the input.
17
+ *
18
+ * This ensures that users only use dots (`.`) as decimal separators,
19
+ * which is standard in most programming and blockchain contexts.
20
+ */
21
+ export declare const noComma: InputRule;
22
+ /**
23
+ * Rule: Prevent the user from starting the input with a dot (`.`).
24
+ *
25
+ * For example, `.5` will be considered invalid; `0.5` is preferred.
26
+ * This helps avoid format inconsistencies and parsing errors.
27
+ */
28
+ export declare const noLeadingDot: InputRule;
29
+ /**
30
+ * Rule: Allow only one decimal point (`.`) in the input.
31
+ *
32
+ * This ensures valid decimal numbers like `123.45`,
33
+ * and rejects invalid ones like `123.4.5`.
34
+ */
35
+ export declare const onlyOneDot: InputRule;
36
+ /**
37
+ * Rule: Accept only digits (`0-9`) and a dot (`.`), or an empty string (when deleting).
38
+ *
39
+ * This prevents letters, symbols, and other invalid characters
40
+ * from being typed into the input field, but allows clearing the field.
41
+ */
42
+ export declare const onlyNumbersAndDot: InputRule;
43
+ /**
44
+ * Rule: Disallow the decimal point (`.`) character in the input.
45
+ *
46
+ * This ensures that users can only enter whole numbers (integers),
47
+ * preventing decimal values from being entered.
48
+ */
49
+ export declare const noDecimal: InputRule;
50
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../../../src/components/lukso-input/rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;IAC3D,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;CACpC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,OAAO,EAAE,SAIrB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,SAI1B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE,SAOxB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAI/B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,SAIvB,CAAA"}
@@ -0,0 +1,30 @@
1
+ const noComma = {
2
+ name: "noComma",
3
+ validate: (_, key) => !key.includes(","),
4
+ sanitize: (value) => value.replaceAll(",", "")
5
+ };
6
+ const noLeadingDot = {
7
+ name: "noLeadingDot",
8
+ validate: (input, key) => !(key === "." && input.selectionStart === 0),
9
+ sanitize: (value) => value.replace(/^\.+/, "")
10
+ };
11
+ const onlyOneDot = {
12
+ name: "onlyOneDot",
13
+ validate: (input, key) => !(key === "." && input.value.split(".").length > 1),
14
+ sanitize: (value) => {
15
+ const [integer, ...decimals] = value.split(".");
16
+ return decimals.length > 0 ? `${integer}.${decimals.join("")}` : integer;
17
+ }
18
+ };
19
+ const onlyNumbersAndDot = {
20
+ name: "onlyNumbersAndDot",
21
+ validate: (_, key) => key === "" || /^[0-9.]$/.test(key),
22
+ sanitize: (value) => value.replace(/[^0-9.]/g, "")
23
+ };
24
+ const noDecimal = {
25
+ name: "noDecimal",
26
+ validate: (_, key) => key !== ".",
27
+ sanitize: (value) => value.replaceAll(".", "")
28
+ };
29
+
30
+ export { noComma, noDecimal, noLeadingDot, onlyNumbersAndDot, onlyOneDot };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukso/web-components",
3
- "version": "1.187.0",
3
+ "version": "1.188.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",