@muten/shadcn 0.2.11 → 0.2.12

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.
package/kit.css CHANGED
@@ -606,8 +606,8 @@ input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webki
606
606
  .cx-otp[data-state="bad"] .cn-input-otp-slot { border-color: var(--destructive); }
607
607
  .cx-otp[data-state="bad"] { animation: cx-shake calc(var(--t-move) * 1.35) var(--ease-out); }
608
608
  .cx-otp[data-state="ok"] .cn-input-otp-slot { border-color: var(--success); color: var(--success); }
609
- #otp-msg[data-tone="bad"] { color: var(--destructive); }
610
- #otp-msg[data-tone="ok"] { color: var(--success); }
609
+ [data-otp-msg][data-tone="bad"] { color: var(--destructive); }
610
+ [data-otp-msg][data-tone="ok"] { color: var(--success); }
611
611
 
612
612
  /* ── Color picker ── */
613
613
  .cx-swatch-row { display: flex; flex-wrap: wrap; gap: 10px; }
@@ -713,7 +713,7 @@ input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webki
713
713
  .cx-pagination .cx-pg-num .cn-button, .cx-pg-gap { width: 32px; }
714
714
  .cx-pg-gap { display: flex; justify-content: center; }
715
715
  .cx-pg-list { transition: opacity 160ms ease; }
716
- .cx-pg-list[data-loading] { opacity: .45; }
716
+ .cx-pg-list[data-loading="true"] { opacity: .45; } /* muten writes "false" too: only true dims */
717
717
  .cx-pg-empty { border-top-color: transparent; }
718
718
  /* virtual list */
719
719
  .cx-vlist { height: 364px; overflow-y: auto; border-radius: calc(var(--radius) * 1.2); box-shadow: 0 0 0 1px var(--border); overscroll-behavior: contain; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muten/shadcn",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "shadcn-style component registry for muten - own-the-source parts you add with `muten add`.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,7 +1,9 @@
1
1
  # InputOtp - the verification code: slots in two groups, a caret, “Verificando…”, ok / bad, a resend countdown. The
2
2
  # PAGE checks the code: onInput gets it when complete; answer with state ("ok" | "bad") and message.
3
3
  # InputOtp(value: code, length: 6, hint: "We sent it to +57 300 123 4567", state: otpState, message: otpMsg, onInput: check)
4
+ # InputOtp(length: 8, letters: true, resendIn: 0, …) a code copied from another screen (KQ4M-7T2X): letters and
5
+ # digits, in capitals, a pasted dash dropped, and no resend button (resendIn 0 never offers one).
4
6
  # shadcn-for-muten · Custom (kit values) · host JS input-otp.js.
5
- part InputOtp(value: text = "", length: number = 6, hint: text = "", state: text = "", message: text = "", resendIn: number = 30, onInput: action) {
6
- Custom InputOtp inputs(value: $value, length: $length, hint: $hint, state: $state, message: $message, resendIn: $resendIn) on(input: $onInput) class("cx-otp-host")
7
+ part InputOtp(value: text = "", length: number = 6, letters: bool = false, hint: text = "", state: text = "", message: text = "", resendIn: number = 30, onInput: action) {
8
+ Custom InputOtp inputs(value: $value, length: $length, letters: $letters, hint: $hint, state: $state, message: $message, resendIn: $resendIn) on(input: $onInput) class("cx-otp-host")
7
9
  }
@@ -90,7 +90,7 @@ Object.assign(ES, {
90
90
  'maximum': 'máximo', 'minimum': 'mínimo', 'Currency': 'Moneda', 'Country': 'País', '{0} (it has no minor unit)': '{0} (no tiene unidad menor)', 'cents of {0}': 'centavos de {0}',
91
91
  'Saved as: {0} {1}': 'Se guarda: {0} {1}', 'Type a price': 'Escribe un precio', 'Search currency': 'Buscar moneda', 'Search country': 'Buscar país',
92
92
  'Saved as +{0}': 'Se guarda como +{0}', '{0} digits short for a number from {1}': 'Faltan {0} dígitos para un número de {1}', '{0} digits, without the {1}': '{0} dígitos, sin el {1}',
93
- '{0}-digit code': 'Código de {0} dígitos', 'Checking…': 'Verificando…', 'Resend in 0:{0}': 'Reenviar en 0:{0}', 'Resend code': 'Reenviar código',
93
+ '{0}-digit code': 'Código de {0} dígitos', '{0}-character code': 'Código de {0} caracteres', 'Checking…': 'Verificando…', 'Resend in 0:{0}': 'Reenviar en 0:{0}', 'Resend code': 'Reenviar código',
94
94
  'We sent you a new code': 'Te enviamos un código nuevo', 'Done, it is verified': 'Listo, quedó verificado', 'That is not the code': 'Ese código no es',
95
95
  });
96
96
 
@@ -157,7 +157,14 @@ export function phoneField(root, i, core, on) {
157
157
  export function otpField(root, i, core, on) {
158
158
  const { $ } = core, T = (k, ...a) => core.t(core.langOf(root), k, ...a);
159
159
  const len = Number(i.length) || 6, half = Math.ceil(len / 2);
160
- root.innerHTML = `<div class="cx-vline cx-otp-stack"><div class="cx-otp"><input class="cx-otp-input" inputmode="numeric" autocomplete="one-time-code" maxlength="${len}" aria-label="${T('{0}-digit code', len)}"><div data-slot="input-otp" class="cn-input-otp" aria-hidden="true"><div data-slot="input-otp-group" class="cn-input-otp-group"></div><div data-slot="input-otp-separator" class="cn-input-otp-separator cx-otp-sep"><span></span></div><div data-slot="input-otp-group" class="cn-input-otp-group"></div></div></div><p class="cx-note" data-otp-msg></p><button data-slot="button" class="cn-button cn-button-variant-link cn-button-size-sm group/button" data-otp-resend disabled></button></div>`;
160
+ // letters: a code people copy from another screen (KQ4M-7T2X), so letters and digits, shown in capitals, and room in the
161
+ // field for a pasted dash or spaces, which are dropped (maxlength would otherwise cut the paste before the cleanup)
162
+ const letters = i.letters === true || i.letters === 'true';
163
+ const keep = letters ? (v) => v.toUpperCase().replace(/[^A-Z0-9]/g, '') : (v) => v.replace(/\D/g, '');
164
+ const field = letters
165
+ ? `inputmode="text" autocapitalize="characters" autocomplete="off" spellcheck="false" maxlength="${len * 2}" aria-label="${T('{0}-character code', len)}"`
166
+ : `inputmode="numeric" autocomplete="one-time-code" maxlength="${len}" aria-label="${T('{0}-digit code', len)}"`;
167
+ root.innerHTML = `<div class="cx-vline cx-otp-stack"><div class="cx-otp"><input class="cx-otp-input" ${field}><div data-slot="input-otp" class="cn-input-otp" aria-hidden="true"><div data-slot="input-otp-group" class="cn-input-otp-group"></div><div data-slot="input-otp-separator" class="cn-input-otp-separator cx-otp-sep"><span></span></div><div data-slot="input-otp-group" class="cn-input-otp-group"></div></div></div><p class="cx-note" data-otp-msg></p><button data-slot="button" class="cn-button cn-button-variant-link cn-button-size-sm group/button" data-otp-resend disabled></button></div>`;
161
168
  const otpIn = $('.cx-otp-input', root), otpBox = $('.cx-otp', root), otpMsg = $('[data-otp-msg]', root), resend = $('[data-otp-resend]', root);
162
169
  const slots = [];
163
170
  root.querySelectorAll('.cn-input-otp-group').forEach((g, gi) => { const n = gi ? len - half : half; for (let k = 0; k < n; k++) { const s = document.createElement('div'); s.className = 'cn-input-otp-slot'; s.dataset.slot = 'input-otp-slot'; g.appendChild(s); slots.push(s); } });
@@ -166,16 +173,20 @@ export function otpField(root, i, core, on) {
166
173
  const paint = () => { const v = otpIn.value, focused = document.activeElement === otpIn, at = Math.min(v.length, len - 1); slots.forEach((s, k) => { s.textContent = v[k] || ''; const act = focused && k === at && !busy; s.dataset.active = act; if (act && !v[k]) s.innerHTML = '<span class="cx-caret"></span>'; }); };
167
174
  const toEnd = () => { const n = otpIn.value.length; otpIn.setSelectionRange(n, n); };
168
175
  otpIn.addEventListener('input', () => {
169
- otpIn.value = otpIn.value.replace(/\D/g, '').slice(0, len); delete otpBox.dataset.state; otpMsg.removeAttribute('data-tone'); otpMsg.textContent = hint; paint();
176
+ otpIn.value = keep(otpIn.value).slice(0, len); delete otpBox.dataset.state; otpMsg.removeAttribute('data-tone'); otpMsg.textContent = hint; paint();
170
177
  if (otpIn.value.length === len) { busy = true; otpIn.readOnly = true; otpMsg.textContent = T('Checking…'); paint(); on?.complete?.(otpIn.value); }
171
178
  });
172
179
  ['focus', 'blur', 'click', 'keyup'].forEach((t) => otpIn.addEventListener(t, () => { toEnd(); paint(); }));
173
180
  otpIn.addEventListener('select', toEnd);
181
+ // resendIn 0: a code that is not sent again (one a shop gave you, one a terminal shows), so no resend button at all
174
182
  let left = Number(i.resendIn ?? 30), rt = 0;
183
+ const resends = left > 0;
184
+ resend.hidden = !resends;
175
185
  const tick = () => { left--; resend.disabled = left > 0; resend.textContent = left > 0 ? T('Resend in 0:{0}', String(left).padStart(2, '0')) : T('Resend code'); if (left > 0) rt = setTimeout(tick, 1000); };
176
186
  resend.textContent = T('Resend in 0:{0}', String(left).padStart(2, '0'));
177
187
  resend.onclick = () => { left = Number(i.resendIn ?? 30) + 1; clearTimeout(rt); tick(); otpMsg.removeAttribute('data-tone'); otpMsg.textContent = T('We sent you a new code'); otpIn.value = ''; delete otpBox.dataset.state; otpIn.focus(); on?.resend?.(); };
178
- rt = setTimeout(tick, 1000); paint();
188
+ if (resends) rt = setTimeout(tick, 1000);
189
+ paint();
179
190
  const answer = (st, msg) => {
180
191
  if (!st || st === 'checking') return;
181
192
  busy = false; otpIn.readOnly = false;
@@ -2,6 +2,20 @@
2
2
  // the Modal part's (muten state + kit.css). This only does what markup cannot: history (Back closes), Esc, the focus
3
3
  // trap, the scroll lock, the auto mode (dialog on a wide screen, drawer on a phone) and the drawer's drag to close.
4
4
  // Same rules as the reference artifact's modal.
5
+ // MODALS STACK (a receipt opened over a cita): Back, Esc and the focus trap belong to the TOP one only, and the page's
6
+ // scroll is unlocked when the last one closes. Each modal used to listen to every Back: closing the receipt went back
7
+ // in history and that Back also closed the cita under it, leaving the agenda without its buttons (21-10-2026).
8
+ const stack = (globalThis.__cxModals ||= { list: [], skip: 0, wired: false });
9
+ if (!stack.wired) {
10
+ stack.wired = true;
11
+ addEventListener('popstate', () => {
12
+ // the history.back() a modal makes when it closes itself is its own, not a Back for the one under it
13
+ if (stack.skip > 0) { stack.skip -= 1; return; }
14
+ stack.list.at(-1)?.onPop();
15
+ });
16
+ }
17
+ const isTop = (me) => stack.list.at(-1) === me;
18
+
5
19
  export function mount(el, inputs, on) {
6
20
  const mdl = el.closest('.cx-modal'), root = mdl.parentElement, ov = root.querySelector(':scope > .cx-overlay');
7
21
  const body = mdl.querySelector(':scope > .cx-modal-body');
@@ -11,6 +25,7 @@ export function mount(el, inputs, on) {
11
25
  // of opening: a dialog that only learns it is a dialog as it opens animates its centring from the corner
12
26
  const resolve = () => { if (auto && !isOpen) mdl.dataset.mode = phone.matches ? 'drawer' : 'dialog'; };
13
27
  let isOpen = false, pushed = false, lastFocus = null;
28
+ const me = { onPop: () => { if (isOpen) { pushed = false; close(); } } };
14
29
  queueMicrotask(() => resolve()); phone.addEventListener('change', resolve);
15
30
  // the footer sticks under the scrolling body, not inside it
16
31
  const placeFooter = () => { const f = body.querySelector('.cx-modal-foot'); if (f) mdl.appendChild(f); };
@@ -40,6 +55,7 @@ export function mount(el, inputs, on) {
40
55
  if (auto) mdl.dataset.mode = phone.matches ? 'drawer' : 'dialog';
41
56
  if (wantsAnchor()) place(); else unplace();
42
57
  lastFocus = document.activeElement;
58
+ stack.list.push(me);
43
59
  document.documentElement.classList.add('cx-locked');
44
60
  // on the phone, focusing a field would throw the keyboard over the sheet: focus the sheet itself
45
61
  requestAnimationFrame(() => { ((mdl.dataset.mode === 'dialog' && focusables().find((x) => x.matches('input, textarea'))) || mdl).focus({ preventScroll: true }); });
@@ -48,9 +64,10 @@ export function mount(el, inputs, on) {
48
64
  const shut = () => {
49
65
  if (!isOpen) return; isOpen = false;
50
66
  mdl.style.transform = ''; if (ov) ov.style.opacity = '';
51
- document.documentElement.classList.remove('cx-locked');
67
+ stack.list = stack.list.filter((one) => one !== me);
68
+ if (stack.list.length === 0) document.documentElement.classList.remove('cx-locked');
52
69
  lastFocus?.focus?.({ preventScroll: true });
53
- if (pushed) { pushed = false; history.back(); }
70
+ if (pushed) { pushed = false; stack.skip += 1; history.back(); }
54
71
  };
55
72
  mdl.tabIndex = -1;
56
73
  // A link inside (a menu in a drawer): close first, then go. Closing undoes the history entry the modal pushed, and
@@ -64,9 +81,8 @@ export function mount(el, inputs, on) {
64
81
  pushed = false; addEventListener('popstate', go);
65
82
  close(); history.back();
66
83
  }, true);
67
- addEventListener('popstate', () => { if (isOpen) { pushed = false; close(); } });
68
84
  document.addEventListener('keydown', (e) => {
69
- if (!isOpen) return;
85
+ if (!isOpen || !isTop(me)) return;
70
86
  if (e.key === 'Escape') { e.preventDefault(); close(); }
71
87
  if (e.key === 'Tab') { const f = focusables(); if (!f.length) return; const first = f[0], last = f[f.length - 1]; if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); } else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); } }
72
88
  });
package/registry.json CHANGED
@@ -457,7 +457,7 @@
457
457
  "part": "InputOtp",
458
458
  "file": "registry/input-otp.muten",
459
459
  "component": "InputOtp",
460
- "description": "InputOtp(value, length, hint, state, message, resendIn, onInput): slots, caret, ok/bad, resend countdown."
460
+ "description": "InputOtp(value, length, letters, hint, state, message, resendIn, onInput): slots, caret, ok/bad, resend countdown (none with resendIn 0); letters for a code like KQ4M-7T2X."
461
461
  },
462
462
  {
463
463
  "name": "input",