@mono-lit/helper 0.0.9 → 0.0.10

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 (161) hide show
  1. package/dist/accordion-core-DaNyPWRr.js +277 -0
  2. package/dist/alert-core-DWtHbX_-.js +134 -0
  3. package/dist/breadcrumb-list-core-Dh68T8Cf.js +747 -0
  4. package/dist/{mono-button-CLkHg3WW.js → button-core-DerXg84Q.js} +3 -276
  5. package/dist/button-dropdown-core-DKYEOyjy.js +654 -0
  6. package/dist/button-utils-D5-66M02.js +63 -0
  7. package/dist/card-utils-l80qAmrN.js +312 -0
  8. package/dist/chart-core-DV7hD3ZY.js +801 -0
  9. package/dist/checkbox-utils-DKdrhAzF.js +337 -0
  10. package/dist/chip-utils-DpRrd7Zj.js +403 -0
  11. package/dist/{data-source-controller-C6C4ej_M.js → data-source-controller-DS_JLrmS.js} +1 -1
  12. package/dist/{data-source-options-fxT5QIX4.js → data-source-options-DJUNU26C.js} +6 -6
  13. package/dist/{data-source-read-BL266IW0.js → data-source-read-uKJpRAzx.js} +2 -2
  14. package/dist/date-core-CyuSyvvG.js +734 -0
  15. package/dist/drawer-core-DbFWvNln.js +759 -0
  16. package/dist/dropdown-core-BCH1pK14.js +511 -0
  17. package/dist/dropdown-table-core-SfHUJVFq.js +1342 -0
  18. package/dist/export.js +1 -1
  19. package/dist/{field-path-BabiMrrA.js → field-path-DK2VBWHl.js} +1 -1
  20. package/dist/field-tooltip.css_raw-DVblekCl.js +5 -0
  21. package/dist/{field-validation.css_raw-Cx6SGrfP.js → field-validation.css_raw-BU7C6173.js} +1 -170
  22. package/dist/file-upload-core-Cz_dBQMx.js +624 -0
  23. package/dist/filter-builder-core-DyWjbBP7.js +381 -0
  24. package/dist/{filter-builder-B6Y2mmbM.js → filter-builder-vbqIuPhX.js} +1 -1
  25. package/dist/{filter-eval-ChDSaAUH.js → filter-eval-CqeBnMYh.js} +1 -1
  26. package/dist/{filter-odata-Bi27XUpQ.js → filter-odata-GsczYKNC.js} +1 -1
  27. package/dist/{hydration-flush-BaE9gN3C.js → hydration-flush-Volt9X7Q.js} +2 -1071
  28. package/dist/index.js +11 -11
  29. package/dist/{index.node-DTqDBca7.js → index.node-Csy9zrr1.js} +4 -4
  30. package/dist/index.node.js +11 -11
  31. package/dist/input-utils-BglY-k0H.js +1145 -0
  32. package/dist/menu-core-DkAYuCZ2.js +831 -0
  33. package/dist/modal-core-CSBSPN_m.js +844 -0
  34. package/dist/mono-button-DVvZ03P-.js +280 -0
  35. package/dist/{mono-button.shadow-DqZMpcqY.js → mono-button.shadow-BANxMGln.js} +6 -594
  36. package/dist/{mono-data-chart-NKPdAgVq.js → mono-data-chart-ChF4J9RT.js} +6 -6
  37. package/dist/{mono-data-dropdown-B2iRpJuI.js → mono-data-dropdown-Bgj2PDfm.js} +1 -1
  38. package/dist/{mono-data-grid-llJCX9MC.js → mono-data-grid-DJkp96N-.js} +144 -46
  39. package/dist/{mono-event-BPku9HpS.js → mono-event-CAZf0F_k.js} +14 -9
  40. package/dist/{mono-form-controller-BrA10erm.js → mono-form-controller-DxZLvyg6.js} +2 -1
  41. package/dist/mono-table-checkbox-core-BKOMx8R5.js +5288 -0
  42. package/dist/nav-core-B5qU2dzn.js +225 -0
  43. package/dist/{normalize-error-D93O4q8g.js → normalize-error-BEcd1tmS.js} +2 -2
  44. package/dist/otp-core-DXg3vFLh.js +758 -0
  45. package/dist/radio-utils-Dk9Tl1jz.js +319 -0
  46. package/dist/rich-text-editor-core-Ddd_QaLn.js +1280 -0
  47. package/dist/select-utils-BgArYHk8.js +2140 -0
  48. package/dist/sidebar-core-CD6txDo3.js +583 -0
  49. package/dist/slider-core-vcWr321-.js +1014 -0
  50. package/dist/src/components/dropdown-table/dropdown-table-core.d.ts +2 -2
  51. package/dist/src/components/dropdown-table/dropdown-table-types.d.ts +1 -1
  52. package/dist/src/components/dropdown-table/index.d.ts +1 -1
  53. package/dist/src/components/dropdown-table/index.shadow.d.ts +1 -1
  54. package/dist/src/components/dropdown-table/mono-data-dropdown.d.ts +1 -1
  55. package/dist/src/components/form/form-types.d.ts +9 -3
  56. package/dist/src/components/input/input-core.d.ts +1 -1
  57. package/dist/src/components/input/input-types.d.ts +1 -1
  58. package/dist/src/components/otp/otp-core.d.ts +1 -1
  59. package/dist/src/components/select/select-core.d.ts +1 -1
  60. package/dist/src/components/select/select-types.d.ts +1 -1
  61. package/dist/src/components/slider/slider-core.d.ts +1 -1
  62. package/dist/src/components/slider/slider-types.d.ts +1 -1
  63. package/dist/src/components/table/filter-suggestion.d.ts +171 -0
  64. package/dist/src/components/table/index.d.ts +5 -4
  65. package/dist/src/components/table/index.shadow.d.ts +5 -4
  66. package/dist/src/components/table/mono-data-grid.d.ts +22 -3
  67. package/dist/src/components/table/mono-table-empty-core.d.ts +37 -0
  68. package/dist/src/components/table/mono-table-search-core.d.ts +22 -3
  69. package/dist/src/components/table/table-types.d.ts +74 -4
  70. package/dist/src/components/tag-input/tag-input-core.d.ts +1 -1
  71. package/dist/src/components/tag-input/tag-input-types.d.ts +1 -1
  72. package/dist/src/components/textarea/textarea-core.d.ts +1 -1
  73. package/dist/src/composables/mono-event.d.ts +7 -1
  74. package/dist/src/entries/index.d.ts +8 -6
  75. package/dist/src/entries/index.node.d.ts +8 -6
  76. package/dist/src/search/index.d.ts +1 -1
  77. package/dist/src/utils/group-count.d.ts +36 -0
  78. package/dist/switch-utils-CTZ4id2V.js +338 -0
  79. package/dist/tabs-core-r5-B8k_N.js +317 -0
  80. package/dist/tag-input-utils-D2JA90DQ.js +3060 -0
  81. package/dist/textarea-utils-VU1KeXm8.js +821 -0
  82. package/dist/ui/accordion.js +2 -274
  83. package/dist/ui/alert.js +2 -131
  84. package/dist/ui/breadcrumb.js +4 -745
  85. package/dist/ui/button-dropdown.js +4 -652
  86. package/dist/ui/button.js +2 -63
  87. package/dist/ui/card.js +2 -310
  88. package/dist/ui/chart.js +4 -800
  89. package/dist/ui/checkbox.js +4 -335
  90. package/dist/ui/chip.js +4 -402
  91. package/dist/ui/date.js +3 -732
  92. package/dist/ui/drawer.js +3 -757
  93. package/dist/ui/dropdown-table.js +5 -1341
  94. package/dist/ui/dropdown.js +4 -509
  95. package/dist/ui/file-upload.js +3 -622
  96. package/dist/ui/filter.js +5 -380
  97. package/dist/ui/form.js +1 -1
  98. package/dist/ui/index.css +118 -1
  99. package/dist/ui/input.js +3 -1141
  100. package/dist/ui/menu.js +4 -828
  101. package/dist/ui/modal.js +4 -843
  102. package/dist/ui/nav.js +4 -223
  103. package/dist/ui/otp.js +4 -756
  104. package/dist/ui/radio.js +4 -317
  105. package/dist/ui/rich-text-editor.js +4 -1278
  106. package/dist/ui/select.js +5 -2138
  107. package/dist/ui/shadow/accordion.js +4 -273
  108. package/dist/ui/shadow/alert.js +4 -130
  109. package/dist/ui/shadow/breadcrumb.js +5 -744
  110. package/dist/ui/shadow/button-dropdown.js +6 -652
  111. package/dist/ui/shadow/button.js +3 -63
  112. package/dist/ui/shadow/card.js +4 -309
  113. package/dist/ui/shadow/chart.js +6 -1576
  114. package/dist/ui/shadow/checkbox.js +4 -334
  115. package/dist/ui/shadow/chip.js +4 -396
  116. package/dist/ui/shadow/date.js +7 -731
  117. package/dist/ui/shadow/drawer.js +4 -756
  118. package/dist/ui/shadow/dropdown-table.js +8 -1762
  119. package/dist/ui/shadow/dropdown.js +4 -508
  120. package/dist/ui/shadow/file-upload.js +4 -620
  121. package/dist/ui/shadow/filter.js +7 -379
  122. package/dist/ui/shadow/input.js +6 -1140
  123. package/dist/ui/shadow/menu.js +5 -828
  124. package/dist/ui/shadow/modal.js +6 -1063
  125. package/dist/ui/shadow/nav.js +5 -223
  126. package/dist/ui/shadow/otp.js +6 -754
  127. package/dist/ui/shadow/radio.js +4 -316
  128. package/dist/ui/shadow/rich-text-editor.js +4 -1276
  129. package/dist/ui/shadow/select.js +6 -2136
  130. package/dist/ui/shadow/sidebar.js +5 -581
  131. package/dist/ui/shadow/slider.js +5 -1010
  132. package/dist/ui/shadow/switch.js +4 -335
  133. package/dist/ui/shadow/table.js +10 -4501
  134. package/dist/ui/shadow/tabs.js +6 -315
  135. package/dist/ui/shadow/tag-input.js +7 -3057
  136. package/dist/ui/shadow/textarea.js +6 -817
  137. package/dist/ui/sidebar.js +3 -581
  138. package/dist/ui/slider.js +4 -1012
  139. package/dist/ui/switch.js +4 -336
  140. package/dist/ui/table.js +9 -4502
  141. package/dist/ui/tabs.js +4 -315
  142. package/dist/ui/tag-input.js +5 -3058
  143. package/dist/ui/textarea.js +4 -819
  144. package/dist/vue.d.ts +3 -2
  145. package/package.json +3 -3
  146. package/dist/chip-strip-bNfLn52Z.js +0 -215
  147. package/dist/data-source-controller-Dx6IQ2CN.js +0 -243
  148. package/dist/data-source-options-BM4r4PRw.js +0 -558
  149. package/dist/data-source-read-HyBCRg1t.js +0 -242
  150. package/dist/excel-BXzr3uI1.js +0 -784
  151. package/dist/export-ixRdCS2y.js +0 -2388
  152. package/dist/field-tooltip-addon-CWCp19mJ.js +0 -702
  153. package/dist/field-tooltip.css_raw-U5UeTa2d.js +0 -269
  154. package/dist/filter-builder-C0T3pMx2.js +0 -208
  155. package/dist/form-control-core-BbiACMtL.js +0 -226
  156. package/dist/icon-ClxnYhBG.js +0 -19
  157. package/dist/import-Dc4eXC02.js +0 -612
  158. package/dist/light-slots-_no0r2Z-.js +0 -246
  159. package/dist/markdown-uGlE_OfJ.js +0 -20191
  160. package/dist/mono-data-grid-e9ZVBlNN.js +0 -4240
  161. package/dist/normalize-error-BmLbgANw.js +0 -1048
package/dist/ui/otp.js CHANGED
@@ -1,762 +1,10 @@
1
- import { d as buildSizeStyle, g as monoHostChildNodes } from "../mono-ui-kvLVIf1V.js";
1
+ import { g as monoHostChildNodes } from "../mono-ui-kvLVIf1V.js";
2
2
  import { t as customElement } from "../mono-element-CKcT0rwv.js";
3
- import { a as defineHybridPropAliases, i as defineHybridPropAlias, r as booleanStringConverter, t as __decorate } from "../decorate-DbYFpi8R.js";
4
- import { t as dispatchMonoEvent } from "../mono-event-BPku9HpS.js";
3
+ import { t as __decorate } from "../decorate-DbYFpi8R.js";
5
4
  import { s as placeSlotNode } from "../light-slots-B5Ck0t_E.js";
6
- import { t as MonoFormControlCore } from "../form-control-core-CRZPZ1ru.js";
7
- import { n as cssPart } from "../css-class-B6Tc_MAx.js";
8
- import { t as FieldTooltipController } from "../field-tooltip-Csk4s2ve.js";
9
- import { t as FieldValidationController } from "../field-validation-CFmUmuDx.js";
10
- import { LitElement, html, isServer, nothing } from "lit";
11
- import { property, state } from "lit/decorators.js";
12
- import { ifDefined } from "lit/directives/if-defined.js";
13
- import { styleMap } from "lit/directives/style-map.js";
14
- import { live } from "lit/directives/live.js";
5
+ import { a as normaliseOtpValue, c as resolveOtpLength, d as spliceOtpValue, i as clampCaret, l as sanitizeOtpChar, n as OTP_DEFAULT_LENGTH, o as parseOtpGroups, r as backspaceOtp, s as removeOtpChar, t as MonoOtpCore, u as sanitizeOtpText } from "../otp-core-DXg3vFLh.js";
6
+ import { LitElement, html, isServer } from "lit";
15
7
 
16
- //#region src/components/otp/otp-utils.ts
17
- /**
18
- * Pure helpers behind `mono-otp`. The value is always a CONTIGUOUS prefix of the boxes — box i
19
- * holds `value[i]` — so every edit is a string operation and the boxes are just its characters.
20
- */
21
- const OTP_DEFAULT_LENGTH = 6;
22
- /** One character cleaned for `type`; `''` when it is not accepted. */
23
- function sanitizeOtpChar(ch, type = "numeric") {
24
- if (!ch) return "";
25
- if (type === "numeric") return /^[0-9]$/.test(ch) ? ch : "";
26
- if (type === "alphanumeric") return /^[A-Za-z0-9]$/.test(ch) ? ch.toUpperCase() : "";
27
- return /^\S$/u.test(ch) ? ch : "";
28
- }
29
- /** A whole string cleaned for `type` — rejected characters are dropped, not kept as holes. */
30
- function sanitizeOtpText(text, type = "numeric") {
31
- if (text == null) return "";
32
- let out = "";
33
- for (const ch of Array.from(String(text))) out += sanitizeOtpChar(ch, type);
34
- return out;
35
- }
36
- /** `length` from a prop or attribute: a whole number ≥ 1, else the default. */
37
- function resolveOtpLength(length) {
38
- const n = Math.floor(Number(length));
39
- return Number.isFinite(n) && n >= 1 ? n : 6;
40
- }
41
- /** The model for `length` boxes: cleaned and cut to fit. */
42
- function normaliseOtpValue(value, length, type = "numeric") {
43
- return Array.from(sanitizeOtpText(value, type)).slice(0, length).join("");
44
- }
45
- /**
46
- * Group sizes → the box indexes a separator goes BEFORE. `3` repeats (6 boxes → 3-3, 8 → 3-3-2);
47
- * a list is taken as given and any boxes past it form one last group.
48
- */
49
- function parseOtpGroups(groups, length) {
50
- if (groups == null || groups === "") return [];
51
- let sizes;
52
- if (typeof groups === "number") sizes = [groups];
53
- else if (Array.isArray(groups)) sizes = groups.map(Number);
54
- else sizes = String(groups).replace(/[[\]\s]/g, "").split(/[,\-|]/).filter(Boolean).map(Number);
55
- sizes = sizes.filter((n) => Number.isFinite(n) && n >= 1).map(Math.floor);
56
- if (!sizes.length) return [];
57
- const repeat = sizes.length === 1;
58
- const breaks = [];
59
- let at = 0;
60
- for (let k = 0;; k++) {
61
- const size = repeat ? sizes[0] : sizes[k];
62
- if (size == null) break;
63
- at += size;
64
- if (at >= length) break;
65
- breaks.push(at);
66
- }
67
- return breaks;
68
- }
69
- /**
70
- * Put `text` at box `index`. One character replaces that box; several (a paste, an SMS
71
- * autofill) overwrite from `index` onwards. Rejected characters are dropped first, so pasting
72
- * `"123-456"` into a numeric field fills six boxes.
73
- */
74
- function spliceOtpValue(value, index, text, length, type = "numeric") {
75
- const chars = Array.from(value);
76
- const clean = Array.from(sanitizeOtpText(text, type));
77
- if (!clean.length) return {
78
- value,
79
- caret: clampCaret(index, chars.length, length)
80
- };
81
- const at = Math.min(Math.max(0, index), chars.length);
82
- let next;
83
- if (clean.length === 1) {
84
- next = chars.slice();
85
- next[at] = clean[0];
86
- } else next = chars.slice(0, at).concat(clean);
87
- next = next.slice(0, length);
88
- return {
89
- value: next.join(""),
90
- caret: clampCaret(at + clean.length, next.length, length)
91
- };
92
- }
93
- /** Remove the character in box `index`; the boxes after it move left. */
94
- function removeOtpChar(value, index, length) {
95
- const chars = Array.from(value);
96
- if (index < 0 || index >= chars.length) return {
97
- value,
98
- caret: clampCaret(index, chars.length, length)
99
- };
100
- chars.splice(index, 1);
101
- return {
102
- value: chars.join(""),
103
- caret: clampCaret(index, chars.length, length)
104
- };
105
- }
106
- /**
107
- * Backspace in box `index`: clear it when it holds a character, otherwise step back and clear
108
- * the one before.
109
- */
110
- function backspaceOtp(value, index, length) {
111
- const filled = Array.from(value).length;
112
- if (index < filled) return removeOtpChar(value, index, length);
113
- if (filled === 0) return {
114
- value,
115
- caret: 0
116
- };
117
- return removeOtpChar(value, filled - 1, length);
118
- }
119
- /** The furthest box that can take focus: the first empty one, or the last box when full. */
120
- function clampCaret(index, filled, length) {
121
- return Math.max(0, Math.min(index, filled, length - 1));
122
- }
123
-
124
- //#endregion
125
- //#region src/components/otp/otp-core.ts
126
- /**
127
- * `MonoOtpCore` — all render-mode-agnostic logic for `mono-otp`: N single-character boxes that
128
- * behave as ONE field. The value is a contiguous prefix of the boxes (box i holds `value[i]`), so
129
- * focus can never land past the first empty box, Backspace / Delete shift the rest left, and a
130
- * paste or an SMS autofill overwrites from the focused box on (see `otp-utils.ts`).
131
- *
132
- * Same prop surface as mono-input (size / color / variant / label-position / validation-position
133
- * / tooltip / messages / states / sizing), wired to `controlMonoForm` through
134
- * `MonoFormControlCore`: `input` per edit (live rules), `change` when focus leaves the group
135
- * (change rules, marks touched), plus `complete` once every box is filled.
136
- *
137
- * Each build supplies `createRenderRoot()`, the slot strategy (the `_render*` hooks below) and
138
- * `renderIcon()` — light captures `slot="…"` children into `[data-mono-slot]` placeholders,
139
- * shadow uses native `<slot>`s.
140
- */
141
- const MonoOtpCore = (superClass) => {
142
- class MonoOtpCoreClass extends MonoFormControlCore(superClass) {
143
- constructor(...args) {
144
- super(...args);
145
- this.cssClass = {};
146
- this.cssClassName = "";
147
- this.type = "numeric";
148
- this.length = 6;
149
- this.separator = "-";
150
- this.mask = false;
151
- this.size = "md";
152
- this.color = "primary";
153
- this.variant = "outlined";
154
- this.labelPosition = "top";
155
- this.validationPosition = "bottom";
156
- this.modelValue = "";
157
- this.value = "";
158
- this.name = "";
159
- this.placeholder = "";
160
- this.label = "";
161
- this.helperText = "";
162
- this.tooltip = null;
163
- this._tooltip = new FieldTooltipController(this, () => this.tooltip);
164
- this._validation = new FieldValidationController(this, () => ({
165
- position: this.validationPosition,
166
- ...this._validationNotice ?? {
167
- state: void 0,
168
- text: void 0
169
- }
170
- }), () => this.renderRoot?.querySelector?.("[mono-otp] > [mono-field]"));
171
- this.validationState = "default";
172
- this.validationMessage = "";
173
- this.error = false;
174
- this.errorMessage = "";
175
- this.success = false;
176
- this.successMessage = "";
177
- this.autocomplete = "one-time-code";
178
- this.inputmode = "";
179
- this.disabled = false;
180
- this.readonly = false;
181
- this.required = false;
182
- this.clearable = false;
183
- this.autofocus = false;
184
- this._code = "";
185
- this._focusIndex = -1;
186
- this._hasPrefixSlotState = false;
187
- this._hasSuffixSlotState = false;
188
- this._hasLabelSlotState = false;
189
- this._hasHelperSlotState = false;
190
- this._committed = null;
191
- this._otpId = `mono-otp-${Math.random().toString(36).slice(2)}`;
192
- this._messageId = `${this._otpId}-message`;
193
- this._onCellInput = (event) => {
194
- const el = event.currentTarget;
195
- const i = this._indexOf(event);
196
- const old = Array.from(this._code)[i] ?? "";
197
- const raw = el.value;
198
- if (!this._editable) {
199
- el.value = old;
200
- event.stopPropagation();
201
- return;
202
- }
203
- if (raw === "") {
204
- el.value = old;
205
- const edit = removeOtpChar(this._code, i, this._length);
206
- if (edit.value === this._code) event.stopPropagation();
207
- this._apply(edit, i, event);
208
- return;
209
- }
210
- let text = raw;
211
- if (old && Array.from(raw).length === 2 && raw.includes(old)) text = raw.startsWith(old) ? raw.slice(old.length) : raw.slice(0, raw.length - old.length);
212
- const edit = spliceOtpValue(this._code, i, text, this._length, this.type);
213
- el.value = Array.from(edit.value)[i] ?? "";
214
- if (edit.value === this._code) event.stopPropagation();
215
- this._apply(edit, i, event);
216
- };
217
- this._onCellKeydown = (event) => {
218
- const i = this._indexOf(event);
219
- const n = this._length;
220
- const last = clampCaret(n, this._filled, n);
221
- switch (event.key) {
222
- case "Backspace":
223
- event.preventDefault();
224
- if (this._editable) this._apply(backspaceOtp(this._code, i, n), i, event);
225
- return;
226
- case "Delete":
227
- event.preventDefault();
228
- if (this._editable) this._apply(removeOtpChar(this._code, i, n), i, event);
229
- return;
230
- case "ArrowLeft":
231
- case "ArrowUp":
232
- event.preventDefault();
233
- this._focusCell(Math.max(0, i - 1));
234
- return;
235
- case "ArrowRight":
236
- case "ArrowDown":
237
- event.preventDefault();
238
- this._focusCell(Math.min(last, i + 1));
239
- return;
240
- case "Home":
241
- event.preventDefault();
242
- this._focusCell(0);
243
- return;
244
- case "End":
245
- event.preventDefault();
246
- this._focusCell(last);
247
- return;
248
- }
249
- if (this._editable && event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
250
- const edit = spliceOtpValue(this._code, i, event.key, n, this.type);
251
- if (edit.value === this._code && i < this._filled && sanitizeOtpChar(event.key, this.type)) {
252
- event.preventDefault();
253
- this._focusCell(edit.caret);
254
- }
255
- }
256
- };
257
- this._onCellPaste = (event) => {
258
- event.preventDefault();
259
- if (!this._editable) return;
260
- const text = event.clipboardData?.getData("text") ?? "";
261
- this._apply(spliceOtpValue(this._code, this._indexOf(event), text, this._length, this.type), this._indexOf(event), event);
262
- };
263
- this._onCellFocus = (event) => {
264
- const i = this._indexOf(event);
265
- const allowed = clampCaret(i, this._filled, this._length);
266
- if (allowed !== i) {
267
- this._focusCell(allowed);
268
- return;
269
- }
270
- this._focusIndex = i;
271
- event.currentTarget.select?.();
272
- };
273
- this._onCellClick = (event) => {
274
- event.currentTarget.select?.();
275
- };
276
- this._onFieldFocusIn = () => {
277
- if (this._committed === null) this._committed = this._code;
278
- };
279
- this._onFieldFocusOut = (event) => {
280
- const next = event.relatedTarget;
281
- if (next && this.renderRoot.contains(next)) return;
282
- this._focusIndex = -1;
283
- const before = this._committed;
284
- this._committed = null;
285
- if (before !== null && before !== this._code) dispatchMonoEvent(this, "change", this._detail(before, -1, event));
286
- };
287
- this._swallow = (event) => {
288
- event.stopPropagation();
289
- };
290
- this._onClear = () => {
291
- if (!this._editable) return;
292
- this.clear();
293
- this._focusCell(0);
294
- };
295
- defineHybridPropAliases(this, [
296
- "labelPosition",
297
- "validationPosition",
298
- "modelValue",
299
- "helperText",
300
- "validationState",
301
- "validationMessage",
302
- "errorMessage",
303
- "successMessage",
304
- "ariaLabelText",
305
- "cssClass",
306
- "minWidth",
307
- "maxWidth",
308
- "minHeight",
309
- "maxHeight"
310
- ]);
311
- for (const alias of [
312
- "ariaLabel",
313
- "aria-label",
314
- "arialabel"
315
- ]) Object.defineProperty(this, alias, {
316
- get: () => this.ariaLabelText,
317
- set: (value) => {
318
- this.ariaLabelText = value == null ? void 0 : String(value);
319
- },
320
- configurable: true,
321
- enumerable: false
322
- });
323
- defineHybridPropAlias(this, "maxlength", "length");
324
- }
325
- static get observedAttributes() {
326
- return [
327
- ...super.observedAttributes ?? [],
328
- "modelvalue",
329
- "helpertext",
330
- "validationstate",
331
- "validationmessage",
332
- "errormessage",
333
- "successmessage",
334
- "arialabeltext",
335
- "arialabel",
336
- "maxlength",
337
- "css-class",
338
- "cssclass"
339
- ];
340
- }
341
- attributeChangedCallback(name, oldValue, newValue) {
342
- super.attributeChangedCallback(name, oldValue, newValue);
343
- if (oldValue === newValue) return;
344
- switch (name) {
345
- case "css-class":
346
- case "cssclass":
347
- this.cssClassName = newValue ?? "";
348
- return;
349
- case "modelvalue":
350
- this.modelValue = newValue ?? "";
351
- return;
352
- case "helpertext":
353
- this.helperText = newValue ?? "";
354
- return;
355
- case "validationstate":
356
- this.validationState = newValue ?? "default";
357
- return;
358
- case "validationmessage":
359
- this.validationMessage = newValue ?? "";
360
- return;
361
- case "errormessage":
362
- this.errorMessage = newValue ?? "";
363
- return;
364
- case "successmessage":
365
- this.successMessage = newValue ?? "";
366
- return;
367
- case "arialabeltext":
368
- case "arialabel":
369
- this.ariaLabelText = newValue ?? void 0;
370
- return;
371
- case "maxlength":
372
- if (newValue != null) this.length = newValue;
373
- return;
374
- }
375
- }
376
- get complete() {
377
- return Array.from(this._code).length === this._length;
378
- }
379
- get _length() {
380
- return resolveOtpLength(this.length);
381
- }
382
- get _filled() {
383
- return Array.from(this._code).length;
384
- }
385
- willUpdate(changed) {
386
- if (changed.has("value") && !changed.has("modelValue") && String(this.value ?? "") !== this._code) this.modelValue = String(this.value ?? "");
387
- if (changed.has("modelValue") || changed.has("length") || changed.has("type")) {
388
- this._code = normaliseOtpValue(this.modelValue, this._length, this.type);
389
- if (this.value !== this._code) this.value = this._code;
390
- }
391
- super.willUpdate?.(changed);
392
- }
393
- firstUpdated(changed) {
394
- super.firstUpdated?.(changed);
395
- if (this.autofocus) this.focus();
396
- }
397
- _cellEl(i) {
398
- return this.renderRoot?.querySelector?.(`[mono-otp-cell][data-index="${i}"]`) ?? null;
399
- }
400
- _indexOf(event) {
401
- return Number(event.currentTarget.dataset.index ?? 0);
402
- }
403
- get _editable() {
404
- return !this.disabled && !this.readonly;
405
- }
406
- _focusCell(i) {
407
- const el = this._cellEl(i);
408
- if (!el) return;
409
- el.focus();
410
- el.select?.();
411
- }
412
- _detail(oldValue, index, sourceEvent) {
413
- return {
414
- modelValue: this._code,
415
- currentValue: this._code,
416
- oldValue,
417
- value: this._code,
418
- complete: this.complete,
419
- index,
420
- name: this.name,
421
- sourceEvent
422
- };
423
- }
424
- /** Commit an edit: write the model, fire `input` (+ `complete`), then move the caret. */
425
- _apply(edit, index, event) {
426
- const old = this._code;
427
- if (edit.value !== old) {
428
- this._code = edit.value;
429
- this.value = edit.value;
430
- this.modelValue = edit.value;
431
- dispatchMonoEvent(this, "input", this._detail(old, index, event));
432
- if (this.complete) dispatchMonoEvent(this, "complete", this._detail(old, index));
433
- }
434
- this._focusCell(edit.caret);
435
- this.updateComplete.then(() => {
436
- const el = this._cellEl(edit.caret);
437
- if (el && this._focusIndex === edit.caret) el.select?.();
438
- });
439
- }
440
- clear() {
441
- if (!this._code) return;
442
- const old = this._code;
443
- this._code = "";
444
- this.value = "";
445
- this.modelValue = "";
446
- const detail = this._detail(old, -1);
447
- dispatchMonoEvent(this, "input", detail);
448
- dispatchMonoEvent(this, "change", detail);
449
- dispatchMonoEvent(this, "clear", detail);
450
- if (this._committed !== null) this._committed = "";
451
- }
452
- focus(index) {
453
- const i = typeof index === "number" ? index : clampCaret(this._length, this._filled, this._length);
454
- this._focusCell(clampCaret(i, this._filled, this._length));
455
- }
456
- blur() {
457
- this._cellEl(this._focusIndex)?.blur();
458
- }
459
- get _resolvedValidationState() {
460
- if (this.validationState && this.validationState !== "default") return this.validationState;
461
- if (this.error || this.errorMessage) return "invalid";
462
- if (this.success || this.successMessage) return "valid";
463
- return "default";
464
- }
465
- get _validationNotice() {
466
- if (this.validationMessage) return {
467
- state: this._resolvedValidationState,
468
- text: this.validationMessage
469
- };
470
- if (this.errorMessage) return {
471
- state: "invalid",
472
- text: this.errorMessage
473
- };
474
- if (this.successMessage) return {
475
- state: "valid",
476
- text: this.successMessage
477
- };
478
- return null;
479
- }
480
- _cls(base, key) {
481
- return cssPart(this.cssClass, base, key);
482
- }
483
- get _hasLabel() {
484
- return !!(this.label || this._hasLabelSlotState);
485
- }
486
- get _describedBy() {
487
- return this.validationMessage || this.errorMessage || this.successMessage || this.helperText || this._hasHelperSlotState ? this._messageId : void 0;
488
- }
489
- get _inputMode() {
490
- return this.inputmode || (this.type === "numeric" ? "numeric" : "text");
491
- }
492
- _placeholderAt(i) {
493
- const chars = Array.from(this.placeholder ?? "");
494
- if (!chars.length) return void 0;
495
- return chars.length === this._length ? chars[i] : chars[0];
496
- }
497
- _cellLabel(i) {
498
- const base = this.ariaLabelText || this.label;
499
- const own = `${this.type === "numeric" ? "Digit" : "Character"} ${i + 1} of ${this._length}`;
500
- return base ? `${base} – ${own}` : own;
501
- }
502
- /** Label text — light: placeholder for the captured slot; shadow overrides with `<slot>`. */
503
- _renderLabelText() {
504
- return this._hasLabelSlotState ? html`<span data-mono-slot="label"></span>` : this.label;
505
- }
506
- _renderLabel() {
507
- if (!this._hasLabel) return nothing;
508
- return html`
509
- <label class=${this._cls("mono-otp-label", "label")} mono-label id=${`${this._otpId}-label`} for=${`${this._otpId}-0`}>
510
- ${this._renderLabelText()}
511
- ${this.required ? html`<span class=${this._cls("mono-otp-required", "required")} mono-required-mark>*</span>` : nothing}
512
- ${this._tooltip.render()}
513
- </label>
514
- `;
515
- }
516
- _renderHelperText(base) {
517
- if (!this.helperText && !this._hasHelperSlotState) return nothing;
518
- return html`<div class=${`${base} helper`} mono-message="helper">${this._hasHelperSlotState ? html`<span data-mono-slot="helper"></span>` : this.helperText}</div>`;
519
- }
520
- _renderMessage() {
521
- const base = this._cls("mono-otp-message", "message");
522
- if (this._validation.moved) {
523
- const notice = this._validationNotice;
524
- return html`${this._renderHelperText(base)}<div
525
- class=${`${base} ${notice.state}`}
526
- mono-message=${notice.state}
527
- mono-sr-only
528
- role=${notice.state === "invalid" ? "alert" : nothing}
529
- >${notice.text}</div>`;
530
- }
531
- if (this.validationMessage) {
532
- const s = this._resolvedValidationState;
533
- return html`<div class=${`${base} ${s}`} mono-message=${s} role=${s === "invalid" ? "alert" : nothing}>${this.validationMessage}</div>`;
534
- }
535
- if (this.errorMessage) return html`<div class=${`${base} invalid`} mono-message="invalid" role="alert">${this.errorMessage}</div>`;
536
- if (this.successMessage) return html`<div class=${`${base} valid`} mono-message="valid">${this.successMessage}</div>`;
537
- return this._renderHelperText(base);
538
- }
539
- /** Prefix / suffix inside the row — light: captured-slot placeholder; shadow overrides with `<slot>`. */
540
- _renderAffix(name) {
541
- if (!(name === "prefix" ? this._hasPrefixSlotState : this._hasSuffixSlotState)) return nothing;
542
- return html`<span class=${this._cls(`mono-otp-${name}`, name)} mono-otp-affix=${name}><span data-mono-slot=${name}></span></span>`;
543
- }
544
- _renderCell(i, chars, invalid) {
545
- return html`<input
546
- id=${`${this._otpId}-${i}`}
547
- class=${this._cls("mono-otp-cell", "cell")}
548
- mono-otp-cell
549
- data-index=${i}
550
- type=${this.mask ? "password" : "text"}
551
- .value=${live(chars[i] ?? "")}
552
- inputmode=${this._inputMode}
553
- pattern=${ifDefined(this.type === "numeric" ? "[0-9]*" : void 0)}
554
- autocomplete=${i === 0 ? this.autocomplete || "one-time-code" : "off"}
555
- autocapitalize=${this.type === "alphanumeric" ? "characters" : "off"}
556
- autocorrect="off"
557
- spellcheck="false"
558
- placeholder=${ifDefined(this._placeholderAt(i))}
559
- ?disabled=${this.disabled}
560
- ?readonly=${this.readonly}
561
- ?mono-filled=${i < chars.length}
562
- ?mono-active=${i === this._focusIndex}
563
- aria-label=${this._cellLabel(i)}
564
- aria-invalid=${invalid ? "true" : "false"}
565
- aria-describedby=${ifDefined(this._describedBy)}
566
- @input=${this._onCellInput}
567
- @change=${this._swallow}
568
- @keydown=${this._onCellKeydown}
569
- @paste=${this._onCellPaste}
570
- @focus=${this._onCellFocus}
571
- @click=${this._onCellClick}
572
- />`;
573
- }
574
- _renderCells() {
575
- const n = this._length;
576
- const chars = Array.from(this._code);
577
- const breaks = new Set(parseOtpGroups(this.groups, n));
578
- const invalid = this._resolvedValidationState === "invalid";
579
- const groups = [[]];
580
- for (let i = 0; i < n; i++) {
581
- if (breaks.has(i)) groups.push([]);
582
- groups[groups.length - 1].push(i);
583
- }
584
- return html`${groups.map((group, g) => html`${g > 0 ? html`<span class=${this._cls("mono-otp-separator", "separator")} mono-otp-separator aria-hidden="true">${this.separator}</span>` : nothing}<div class=${this._cls("mono-otp-group", "group")} mono-otp-group>${group.map((i) => this._renderCell(i, chars, invalid))}</div>`)}`;
585
- }
586
- _renderClear() {
587
- if (!(this.clearable && this._code && this._editable)) return nothing;
588
- return html`<button type="button" class=${this._cls("mono-otp-clear", "clear")} mono-clear aria-label="Clear code" @click=${this._onClear}>
589
- ${this.renderIcon("close")}
590
- </button>`;
591
- }
592
- /** Icon hook — light: UnoCSS `i-mdi-*`; shadow: inline SVG. */
593
- renderIcon(_name) {
594
- return html``;
595
- }
596
- render() {
597
- const state = this._resolvedValidationState;
598
- const lp = this.labelPosition === "left" || this.labelPosition === "right" ? this.labelPosition : nothing;
599
- return html`<div
600
- class=${[
601
- "mono-otp",
602
- this.size,
603
- this.color,
604
- this.variant,
605
- this.disabled ? "disabled" : "",
606
- this.cssClassName,
607
- this.cssClass?.root
608
- ].filter(Boolean).join(" ")}
609
- style=${styleMap(buildSizeStyle(this))}
610
- mono-otp
611
- mono-size=${this.size === "md" ? nothing : this.size}
612
- mono-color=${this.color === "primary" ? nothing : this.color}
613
- mono-variant=${this.variant === "outlined" ? nothing : this.variant}
614
- mono-label-position=${lp}
615
- mono-validation-position=${this.validationPosition === "bottom" ? nothing : this.validationPosition}
616
- mono-validation-state=${state === "default" ? nothing : state}
617
- mono-type=${this.type === "numeric" ? nothing : this.type}
618
- ?mono-mask=${this.mask}
619
- ?mono-complete=${this.complete}
620
- ?mono-disabled=${this.disabled}
621
- ?mono-readonly=${this.readonly}
622
- ?mono-required=${this.required}
623
- ?mono-clearable=${this.clearable}
624
- >
625
- ${this._renderLabel()}
626
- <div
627
- class=${this._cls("mono-otp-field", "field")}
628
- mono-field
629
- role="group"
630
- aria-labelledby=${ifDefined(!this.ariaLabelText && this._hasLabel ? `${this._otpId}-label` : void 0)}
631
- aria-label=${ifDefined(this.ariaLabelText || (!this._hasLabel ? "One-time code" : void 0))}
632
- aria-required=${ifDefined(this.required ? "true" : void 0)}
633
- @focusin=${this._onFieldFocusIn}
634
- @focusout=${this._onFieldFocusOut}
635
- >
636
- ${this._renderAffix("prefix")}
637
- ${this._renderCells()}
638
- ${this._validation.renderIcon()}
639
- ${this._renderClear()}
640
- ${this._renderAffix("suffix")}
641
- </div>
642
- ${this.name ? html`<input type="hidden" mono-otp-hidden name=${this.name} .value=${this._code} ?disabled=${this.disabled} />` : nothing}
643
- <div id=${this._messageId} class=${this.cssClass?.messageWrap ?? ""} mono-message-wrap>${this._renderMessage()}</div>
644
- ${this._validation.renderFloat()}
645
- </div>`;
646
- }
647
- }
648
- __decorate([property({ attribute: false })], MonoOtpCoreClass.prototype, "cssClass", void 0);
649
- __decorate([property({
650
- type: String,
651
- attribute: "css-class"
652
- })], MonoOtpCoreClass.prototype, "cssClassName", void 0);
653
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "type", void 0);
654
- __decorate([property()], MonoOtpCoreClass.prototype, "length", void 0);
655
- __decorate([property()], MonoOtpCoreClass.prototype, "groups", void 0);
656
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "separator", void 0);
657
- __decorate([property({
658
- reflect: true,
659
- converter: booleanStringConverter
660
- })], MonoOtpCoreClass.prototype, "mask", void 0);
661
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "size", void 0);
662
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "color", void 0);
663
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "variant", void 0);
664
- __decorate([property({
665
- type: String,
666
- attribute: "label-position"
667
- })], MonoOtpCoreClass.prototype, "labelPosition", void 0);
668
- __decorate([property({
669
- type: String,
670
- attribute: "validation-position"
671
- })], MonoOtpCoreClass.prototype, "validationPosition", void 0);
672
- __decorate([property({ attribute: "model-value" })], MonoOtpCoreClass.prototype, "modelValue", void 0);
673
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "value", void 0);
674
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "name", void 0);
675
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "placeholder", void 0);
676
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "label", void 0);
677
- __decorate([property({
678
- type: String,
679
- attribute: "helper-text"
680
- })], MonoOtpCoreClass.prototype, "helperText", void 0);
681
- __decorate([property()], MonoOtpCoreClass.prototype, "tooltip", void 0);
682
- __decorate([property({
683
- type: String,
684
- attribute: "validation-state"
685
- })], MonoOtpCoreClass.prototype, "validationState", void 0);
686
- __decorate([property({
687
- type: String,
688
- attribute: "validation-message"
689
- })], MonoOtpCoreClass.prototype, "validationMessage", void 0);
690
- __decorate([property({
691
- reflect: true,
692
- converter: booleanStringConverter
693
- })], MonoOtpCoreClass.prototype, "error", void 0);
694
- __decorate([property({
695
- type: String,
696
- attribute: "error-message"
697
- })], MonoOtpCoreClass.prototype, "errorMessage", void 0);
698
- __decorate([property({
699
- reflect: true,
700
- converter: booleanStringConverter
701
- })], MonoOtpCoreClass.prototype, "success", void 0);
702
- __decorate([property({
703
- type: String,
704
- attribute: "success-message"
705
- })], MonoOtpCoreClass.prototype, "successMessage", void 0);
706
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "autocomplete", void 0);
707
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "inputmode", void 0);
708
- __decorate([property({
709
- type: String,
710
- attribute: "aria-label"
711
- })], MonoOtpCoreClass.prototype, "ariaLabelText", void 0);
712
- __decorate([property({
713
- reflect: true,
714
- converter: booleanStringConverter
715
- })], MonoOtpCoreClass.prototype, "disabled", void 0);
716
- __decorate([property({
717
- reflect: true,
718
- converter: booleanStringConverter
719
- })], MonoOtpCoreClass.prototype, "readonly", void 0);
720
- __decorate([property({
721
- reflect: true,
722
- converter: booleanStringConverter
723
- })], MonoOtpCoreClass.prototype, "required", void 0);
724
- __decorate([property({
725
- reflect: true,
726
- converter: booleanStringConverter
727
- })], MonoOtpCoreClass.prototype, "clearable", void 0);
728
- __decorate([property({
729
- reflect: true,
730
- converter: booleanStringConverter
731
- })], MonoOtpCoreClass.prototype, "autofocus", void 0);
732
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "width", void 0);
733
- __decorate([property({ type: String })], MonoOtpCoreClass.prototype, "height", void 0);
734
- __decorate([property({
735
- type: String,
736
- attribute: "min-width"
737
- })], MonoOtpCoreClass.prototype, "minWidth", void 0);
738
- __decorate([property({
739
- type: String,
740
- attribute: "max-width"
741
- })], MonoOtpCoreClass.prototype, "maxWidth", void 0);
742
- __decorate([property({
743
- type: String,
744
- attribute: "min-height"
745
- })], MonoOtpCoreClass.prototype, "minHeight", void 0);
746
- __decorate([property({
747
- type: String,
748
- attribute: "max-height"
749
- })], MonoOtpCoreClass.prototype, "maxHeight", void 0);
750
- __decorate([state()], MonoOtpCoreClass.prototype, "_code", void 0);
751
- __decorate([state()], MonoOtpCoreClass.prototype, "_focusIndex", void 0);
752
- __decorate([state()], MonoOtpCoreClass.prototype, "_hasPrefixSlotState", void 0);
753
- __decorate([state()], MonoOtpCoreClass.prototype, "_hasSuffixSlotState", void 0);
754
- __decorate([state()], MonoOtpCoreClass.prototype, "_hasLabelSlotState", void 0);
755
- __decorate([state()], MonoOtpCoreClass.prototype, "_hasHelperSlotState", void 0);
756
- return MonoOtpCoreClass;
757
- };
758
-
759
- //#endregion
760
8
  //#region src/components/otp/mono-otp.ts
761
9
  let MonoOtp = class MonoOtp extends MonoOtpCore(LitElement) {
762
10
  constructor(..._args) {