@getflip/swirl-components 0.340.1 → 0.341.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.
Files changed (29) hide show
  1. package/components.json +1 -1
  2. package/dist/cjs/{maska-BX2QG_K8.js → index-BOqO2Grl.js} +3593 -17
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/swirl-components.cjs.js +1 -1
  5. package/dist/cjs/swirl-date-input.cjs.entry.js +92 -37
  6. package/dist/cjs/swirl-time-input.cjs.entry.js +78 -49
  7. package/dist/collection/components/swirl-date-input/swirl-date-input.js +88 -33
  8. package/dist/collection/components/swirl-date-input/swirl-date-input.stories.js +1 -1
  9. package/dist/collection/components/swirl-time-input/swirl-time-input.js +77 -46
  10. package/dist/collection/components/swirl-time-input/swirl-time-input.stories.js +1 -1
  11. package/dist/components/assets/pdfjs/pdf.worker.min.mjs +4 -1
  12. package/dist/components/{maska.js → index3.js} +3593 -17
  13. package/dist/components/swirl-date-input.js +88 -33
  14. package/dist/components/swirl-time-input.js +78 -48
  15. package/dist/esm/{maska-CSSJQ9ZE.js → index-D3UoejeY.js} +3593 -17
  16. package/dist/esm/loader.js +1 -1
  17. package/dist/esm/swirl-components.js +1 -1
  18. package/dist/esm/swirl-date-input.entry.js +88 -33
  19. package/dist/esm/swirl-time-input.entry.js +76 -47
  20. package/dist/swirl-components/p-1bbb3a4b.entry.js +1 -0
  21. package/dist/swirl-components/p-96441b7e.entry.js +1 -0
  22. package/dist/swirl-components/p-D3UoejeY.js +1 -0
  23. package/dist/swirl-components/swirl-components.esm.js +1 -1
  24. package/dist/types/components/swirl-date-input/swirl-date-input.d.ts +2 -2
  25. package/dist/types/components/swirl-time-input/swirl-time-input.d.ts +1 -2
  26. package/package.json +2 -2
  27. package/dist/swirl-components/p-1217fdca.entry.js +0 -1
  28. package/dist/swirl-components/p-CSSJQ9ZE.js +0 -6
  29. package/dist/swirl-components/p-b96b8029.entry.js +0 -1
@@ -1,7 +1,7 @@
1
1
  import { h, Host, } from "@stencil/core";
2
2
  import classnames from "classnames";
3
3
  import { format, isValid, parse } from "date-fns";
4
- import { create as createMask } from "maska/dist/es6/maska";
4
+ import IMask from "imask";
5
5
  import { DesktopMediaQuery } from "../../services/media-query.service";
6
6
  const internalTimeFormat = "HH:mm:ss";
7
7
  export class SwirlTimeInput {
@@ -10,43 +10,8 @@ export class SwirlTimeInput {
10
10
  this.placeholder = "hh:mm";
11
11
  this.iconSize = 24;
12
12
  this.mediaQueryUnsubscribe = () => { };
13
- this.onChange = (event) => {
14
- const value = event.target.value;
15
- let newValue;
16
- if (value === "") {
17
- this.value = undefined;
18
- this.valueChange.emit(undefined);
19
- }
20
- const newDate = parse(value, this.format, new Date());
21
- const formatRegExp = new RegExp(`^${this.format.replace(/[Hhms]/g, "\\d")}$`);
22
- if (!Boolean(value.match(formatRegExp))) {
23
- return;
24
- }
25
- if (!isValid(newDate)) {
26
- newValue = format(new Date(), internalTimeFormat);
27
- }
28
- else {
29
- newValue = format(newDate, internalTimeFormat);
30
- }
31
- this.value = newValue;
32
- this.valueChange.emit(newValue);
33
- };
34
13
  this.onBlur = (event) => {
35
14
  this.inputBlur.emit(event);
36
- const input = event.target;
37
- const dateValue = parse(input.value, this.format, new Date());
38
- if (!isValid(dateValue) && Boolean(this.value)) {
39
- const currentDateValue = Boolean(this.value)
40
- ? parse(this.value, internalTimeFormat, new Date())
41
- : undefined;
42
- if (!Boolean(currentDateValue) || !isValid(currentDateValue)) {
43
- this.value = "";
44
- }
45
- input.value = format(currentDateValue, this.format);
46
- }
47
- };
48
- this.onInput = (event) => {
49
- this.onChange(event);
50
15
  };
51
16
  this.onClick = (event) => {
52
17
  event.preventDefault();
@@ -79,35 +44,98 @@ export class SwirlTimeInput {
79
44
  watchFormat() {
80
45
  this.setupMask();
81
46
  }
47
+ watchValue(newValue, oldValue) {
48
+ if (newValue !== oldValue) {
49
+ this.valueChange.emit(newValue);
50
+ }
51
+ }
82
52
  updateIconSize(smallIcon) {
83
53
  this.iconSize = smallIcon ? 20 : 24;
84
54
  }
85
55
  handleAutoSelect(event) {
86
56
  if (!this.autoSelect) {
57
+ setTimeout(() => {
58
+ if (event.target &&
59
+ event.target instanceof HTMLInputElement &&
60
+ event.target.setSelectionRange) {
61
+ event.target.setSelectionRange(0, 0);
62
+ }
63
+ });
87
64
  return;
88
65
  }
89
- event.target.select();
66
+ if (event.target && event.target instanceof HTMLInputElement) {
67
+ event.target.select();
68
+ }
90
69
  }
91
70
  setupMask() {
92
71
  this.mask?.destroy();
93
- this.mask = createMask(`#${this.id}`, {
94
- mask: this.format.replace(/[Hhms]/g, "#"),
72
+ // Due to automatic padding with 0s, we need to replace single characters with full length blocks.
73
+ const pattern = this.format
74
+ .replace(/(?<!H)H(?!H)/g, "HH")
75
+ .replace(/(?<!h)h(?!h)/g, "hh")
76
+ .replace(/(?<!m)m(?!m)/g, "mm")
77
+ .replace(/(?<!s)s(?!s)/g, "ss");
78
+ this.mask = IMask(this.inputEl, {
79
+ mask: Date,
80
+ pattern: pattern.replace(/([^A-Za-z0-9])/g, "$1`"), // Add backticks to separators to prevent symbols from shifting back
81
+ autofix: "pad",
82
+ lazy: true,
83
+ overwrite: true,
84
+ eager: "append",
85
+ blocks: {
86
+ HH: {
87
+ mask: IMask.MaskedRange,
88
+ from: 0,
89
+ to: 23,
90
+ maxLength: 2,
91
+ },
92
+ hh: {
93
+ mask: IMask.MaskedRange,
94
+ from: 1,
95
+ to: 12,
96
+ maxLength: 2,
97
+ },
98
+ mm: {
99
+ mask: IMask.MaskedRange,
100
+ from: 0,
101
+ to: 59,
102
+ maxLength: 2,
103
+ },
104
+ ss: {
105
+ mask: IMask.MaskedRange,
106
+ from: 0,
107
+ to: 59,
108
+ maxLength: 2,
109
+ },
110
+ },
111
+ format: (date) => {
112
+ if (!isValid(date)) {
113
+ return "";
114
+ }
115
+ this.value = format(date, internalTimeFormat);
116
+ return format(date, pattern);
117
+ },
118
+ parse: (str) => {
119
+ return parse(str, pattern, new Date());
120
+ },
95
121
  });
122
+ // Set the initial value if it exists
123
+ if (this.value) {
124
+ const dateValue = parse(this.value, internalTimeFormat, new Date());
125
+ if (isValid(dateValue)) {
126
+ const formattedValue = format(dateValue, pattern);
127
+ this.mask.value = formattedValue;
128
+ }
129
+ }
96
130
  }
97
131
  render() {
98
132
  const ariaInvalid = this.invalid === true || this.invalid === false
99
133
  ? String(this.invalid)
100
134
  : undefined;
101
- const dateValue = Boolean(this.value)
102
- ? parse(this.value, internalTimeFormat, new Date())
103
- : undefined;
104
- const displayValue = isValid(dateValue)
105
- ? format(dateValue, this.format)
106
- : undefined;
107
135
  const className = classnames("time-input", {
108
136
  "time-input--inline": this.inline,
109
137
  });
110
- return (h(Host, { key: '2d01caa594161a39badac0b0c1914fe0111f93b6' }, h("div", { key: '12e350dcf0b59510a885f2e38662ae52ca183d53', class: className }, h("input", { key: 'ddcb1410c0abe8f43854b41e773fc4ad0ee69c54', "aria-describedby": this.swirlAriaDescribedby, "aria-disabled": this.disabled ? "true" : undefined, "aria-invalid": ariaInvalid, autoFocus: this.autoFocus, class: "time-input__input", disabled: this.disabled, id: this.id, inputmode: "numeric", onBlur: this.onBlur, onClick: this.onClick, onFocus: this.onFocus, onInput: this.onInput, placeholder: this.placeholder, ref: (el) => (this.inputEl = el), required: this.required, type: "text", value: displayValue }), h("span", { key: '38d168f83acc421e7c987c1fab1f71b44de57e63', class: "time-input__icon" }, h("swirl-icon-time-outlined", { key: 'fe08cb78cf03822f99d98f4d9f33e0c103286d80', size: this.iconSize })))));
138
+ return (h(Host, { key: '8947322735a4ce58217aff86dcc3b5132905b82a' }, h("div", { key: '1368952e9638f3337d3b67b3ce6a22ce9c736dfd', class: className }, h("input", { key: '23299e8dce3200618853f2bc319fdfc741f215e1', "aria-describedby": this.swirlAriaDescribedby, "aria-disabled": this.disabled ? "true" : undefined, "aria-invalid": ariaInvalid, autoFocus: this.autoFocus, class: "time-input__input", disabled: this.disabled, id: this.id, inputmode: "numeric", onBlur: this.onBlur, onClick: this.onClick, onFocus: this.onFocus, placeholder: this.placeholder, ref: (el) => (this.inputEl = el), required: this.required, type: "text" }), h("span", { key: 'd793539f7f1b7027a97d02649f1f89a5251ceb33', class: "time-input__icon" }, h("swirl-icon-time-outlined", { key: '3fe2d103178eb908b82fa0fed4918253de760618', size: this.iconSize })))));
111
139
  }
112
140
  static get is() { return "swirl-time-input"; }
113
141
  static get encapsulation() { return "scoped"; }
@@ -385,6 +413,9 @@ export class SwirlTimeInput {
385
413
  return [{
386
414
  "propName": "format",
387
415
  "methodName": "watchFormat"
416
+ }, {
417
+ "propName": "value",
418
+ "methodName": "watchValue"
388
419
  }];
389
420
  }
390
421
  }
@@ -6,7 +6,7 @@ export default {
6
6
  description: "See https://date-fns.org/v2.29.3/docs/format.",
7
7
  table: {
8
8
  type: {
9
- detail: '"h", "H", "m", "s", and separators (e.g. ":")',
9
+ detail: '"hh", "HH", "mm", "ss", and separators (e.g. ":", ".", ",")',
10
10
  summary: "Allowed patterns",
11
11
  },
12
12
  },