@xleddyl/443-components-vue 0.16.31 → 0.16.33

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/CATALOG.md CHANGED
@@ -171,7 +171,7 @@ All field components work inside `FormField` and take `invalid`, `disabled`, `re
171
171
  | `Combobox` | Searchable select. Local filter, async `search`, `multiple` with tags, `creatable`. | Models: `v-model`, `v-model:query`. Props: `options` (`label`, `value`, `description`, `icon`, `color` (dot and tag color), `group` (divider with the group name, also the tooltip of a selected tag), `keywords`), `search(query, signal)`, `filter`, `multiple`, `hideTags`, `creatable`, `createActions`, `createTransform`, `createValidate` (a returned string is the inline error), `debounce`, `minQueryLength`, `maxSelected`, `clearable`, `loading`, `placeholder`, `emptyText`. Slots: `option`, `empty`, `header` (top of the panel, for example quick filter pills). Events: `create`, `open`, `close`. | `forms/combobox.vue` |
172
172
  | `TreeSelect` | Pick one node of a hierarchy (category, folder) with a drill-down panel, one level at a time. | Model: `TreeNodeId or null`. Props: `nodes` (`TreeNode`: `id`, `label`, `description`, `icon`, `disabled`, `children`), `leavesOnly` (parents only navigate), `separator` (path in the control and in search results, default `' / '`), `clearable`, `placeholder`, `searchPlaceholder`, `emptyText`, `icon`. Search lists every match with its path. Slots: `node` (`node`, `selected`, `path`), `empty`. Events: `open`, `close`. | `forms/tree-select.vue` |
173
173
  | `Switch` | On or off setting that applies at once. | Model: boolean. Props: `label`, `description`, `labelPosition`, `checkedIcon`, `uncheckedIcon`, `name`. Slots: default, `description`. | `forms/switch.vue` |
174
- | `NumberInput` | Locale aware number with stepper, min, max, step. | Model: number or null. Props: `min`, `max`, `step`, `largeStep`, `locale`, `formatOptions` (currency, percent), `stepper`, `wheel`, `align`, `icon`, `placeholder`. | `forms/number-input.vue` |
174
+ | `NumberInput` | Locale aware number with stepper, min, max, step. | Model: number or null. Props: `min`, `max`, `step`, `largeStep`, `locale`, `formatOptions` (currency, percent), `decimalSeparator` (`'.'` or `','`, default from the locale), `stepper`, `wheel`, `align`, `icon`, `placeholder`. Typing keeps only digits, one decimal separator (a typed `.` or `,` becomes the separator) and a leading `-` when `min` allows negatives. | `forms/number-input.vue` |
175
175
  | `PasswordInput` | Password with show or hide, optional generator, copy and strength meter. | Model: string. Props: `generate` (true or a function), `copy`, `strength`, `minLength`, `autocomplete`. Event: `generate`. | `forms/password-input.vue` |
176
176
  | `PinInput` | One time code or PIN in separate cells. | Model: string. Props: `length`, `mode` (numeric, alphanumeric, alphabetic), `mask`, `uppercase`, `separatorAfter`, `autocomplete`. Event: `complete(value)`. | `forms/pin-input.vue` |
177
177
  | `InputGroup` | Join an input with addons or buttons on its sides. | Props: `label`, `size`, `block`. Slot: default (inputs, `InputAddon`, `Button`). | `forms/input-group.vue` |
@@ -336,7 +336,7 @@ All are exported from `@xleddyl/443-components-vue` and auto-imported in Nuxt.
336
336
  | `toast` / `useToast` | Toasts. | `toast(title, opts)`, `toast.success`, `.error`, `.warning`, `.info`, `.loading`, `.promise(promise, { loading, success, error })`, `.update(id, opts)`, `.dismiss(id)`. Options: `description` (string or list), `action` (`label`, `onClick`), `duration`, `dismissible`. | `overlays/toast.vue` |
337
337
  | `useConfirm` | Ask yes or no. Returns a promise of `true` or `false`. | `await useConfirm()({ title, description, tone, confirmLabel, cancelLabel, body })`. Presets: `confirm.delete(title, options?)` (danger, Delete) and `confirm.discard(options?)` (unsaved changes). | `overlays/hooks.vue` |
338
338
  | `useAlert` | Show a message and wait until the user closes it. | `await useAlert()({ title, description, tone })`. | `overlays/hooks.vue` |
339
- | `usePrompt` | Ask for one text value. Returns the string or `null`. | `await usePrompt()({ title, label, value, placeholder, type, required, validate(value), onConfirm(value) })`. | `overlays/hooks.vue` |
339
+ | `usePrompt` | Ask for one text value. Returns the string or `null`. | `await usePrompt()({ title, label, value, placeholder, type, required, maxLength, validate(value), onConfirm(value) })`. | `overlays/hooks.vue` |
340
340
  | `useModal`, `useDrawer`, `useOverlay` | Open a component as a modal or drawer and await its result. Use it when the content is a component with its own logic. | `const result = await useModal().open(Component, props, { title, size, beforeClose })`. The handle has `id`, `close(result)`, `update(props)`. `useModal().close(id?)`, `closeAll()`. `useOverlay` is the base (option `as`). | `overlays/hooks.vue` |
341
341
  | `useModalContext` | Inside a component opened by `useModal` or `useDrawer`: close with a result and set the loading state. | `const { close, setLoading } = useModalContext<R>()`. | `overlays/hooks.vue` |
342
342
  | `useLoading`, `withLoading` | Global loading: top bar after a delay, or a blocking screen. Ref counted. | `useLoading().wrap(promise, { blocking, label })`, `start()` returns a stop function. `withLoading(fn)` wraps a function. Needs `OverlayHost`. | `overlays/hooks.vue` |
package/README.md CHANGED
@@ -49,6 +49,7 @@ Every component is registered with the prefix (`Button.vue` becomes `<KButton>`)
49
49
  | `cssLayers` | `'theme, base, k, components, utilities'` | Cascade layer order declared before any other CSS. The library layer `k` sits after the `theme` and `base` layers of Tailwind (so preflight does not reset components) and before `components` and `utilities` (so host classes win). `false` declares nothing. See [Scoping](#scoping). |
50
50
  | `locale` | `'en'` | Language of the built-in copy: `'en'`, `'it'`, `'de'`, or any code completed with `messages`. With `@nuxtjs/i18n` the current i18n locale wins. See [Languages](#languages). |
51
51
  | `messages` | `{}` | Overrides per locale code, for example `{ it: { common: { cancel: 'Indietro' } } }`. |
52
+ | `decimalSeparator` | locale | Decimal separator of `NumberInput` in display and editing, for example `'.'` in an Italian app. A typed `.` or `,` becomes this separator, and the display drops the group separators. |
52
53
  | `routeState.location` | `'query'` | Where `useRouteState` and the settings modal `route` keep their value by default: `'query'` (`?family=fam_1`) or `'hash'` (`#family/fam_1`). See [Deep links](#deep-links). |
53
54
  | `composables` | `true` | Auto-imports the composables. |
54
55
  | `global` | `false` | Puts `k-root` and `data-theme` on `<html>` for apps that are dashboard only. |
@@ -534,7 +535,7 @@ await run(() => api.save(form))
534
535
 
535
536
  - Toasts stay clear of an open Drawer: next to a left or right drawer the stack moves beside the panel (by its width) when there is room for it, otherwise it moves above the drawer footer (or below the header for top positions), so the drawer actions stay visible and the toasts stay clickable. The same footer rule applies to a Modal whose footer sits under the toasts (a sheet or a fullscreen modal).
536
537
  - Toasts stack behind the newest one (up to `max`, default 4) and expand on hover or focus, which also pauses their timers. Each tone has its own icon; `description` takes a string or a list of lines. `dismissible: false` hides the close button, `duration: Infinity` keeps a toast open, `progress` on the toaster shows a timer bar.
537
- - `useConfirm()` resolves `true` or `false`, `useAlert()` resolves when closed, `usePrompt()` resolves the string or `null`. `useConfirm()` and `useAlert()` also take `body`, a component rendered under the description (for example a list of the pages that use a file). The body can emit `close` to dismiss the dialog as cancelled, for example when one of its links is clicked. Prompt options: `label`, `placeholder`, `value`, `type`, `required`, `requiredText`, `validate(value)` (return an error message to keep the dialog open), `onConfirm(value)`. Without a host they fall back to the native browser dialogs.
538
+ - `useConfirm()` resolves `true` or `false`, `useAlert()` resolves when closed, `usePrompt()` resolves the string or `null`. `useConfirm()` and `useAlert()` also take `body`, a component rendered under the description (for example a list of the pages that use a file). The body can emit `close` to dismiss the dialog as cancelled, for example when one of its links is clicked. Prompt options: `label`, `placeholder`, `value`, `type`, `required`, `requiredText`, `maxLength`, `validate(value)` (return an error message to keep the dialog open), `onConfirm(value)`. Without a host they fall back to the native browser dialogs.
538
539
  - `modal.open(Component, props, options)` returns a promise for the result plus `id`, `close(result)` and `update(props)`. Options: `title`, `description`, `size`, `side` (drawers), `sheet`, `flush`, `dismissible`, `hideClose`, `closeLabel`, `as: 'modal' | 'drawer'`. Inside the component, `useModalContext<R>()` gives `close(result?)` and `setLoading(boolean)`. A component can open another modal on top; Escape and the backdrop resolve `undefined`. `modal.close(id?, result?)` and `modal.closeAll()` close from outside.
539
540
  - `useLoading()` is ref counted: `start()` returns a stop function, `wrap(promise | fn, options?)` and `withLoading(fn)` stop when settled, `active`, `count` and `blocking` are refs. The host shows a top progress bar after `delay`, and a blocking screen (a modal dialog, so the page is inert) for tasks started with `blocking: true`. `useLoadingState({ global? })` returns a scoped `{ loading, error, run }` for buttons and forms.
540
541
 
@@ -90,6 +90,7 @@ const props = defineProps({
90
90
  step: { type: Number, required: false, default: 1 },
91
91
  largeStep: { type: Number, required: false },
92
92
  locale: { type: String, required: false },
93
+ decimalSeparator: { type: String, required: false },
93
94
  formatOptions: { type: null, required: false },
94
95
  wheel: { type: Boolean, required: false },
95
96
  stepper: { type: Boolean, required: false, default: true },
@@ -134,6 +135,12 @@ const separators = computed(() => {
134
135
  group: parts.find((part) => part.type === "group")?.value ?? ","
135
136
  };
136
137
  });
138
+ const decimalSeparator = computed(
139
+ () => props.decimalSeparator ?? appLocale.value.decimalSeparator ?? separators.value.decimal
140
+ );
141
+ const customSeparator = computed(() => decimalSeparator.value !== separators.value.decimal);
142
+ const allowsFraction = computed(() => props.formatOptions?.maximumFractionDigits !== 0);
143
+ const allowsNegative = computed(() => props.min === void 0 || props.min < 0);
137
144
  const stepDecimals = computed(() => {
138
145
  const text = String(props.step);
139
146
  return text.includes(".") ? text.split(".")[1].length : 0;
@@ -141,9 +148,15 @@ const stepDecimals = computed(() => {
141
148
  const inputmode = computed(
142
149
  () => props.step % 1 === 0 && (props.min ?? -1) >= 0 && !props.formatOptions?.maximumFractionDigits ? "numeric" : "decimal"
143
150
  );
144
- const display = computed(
145
- () => model.value === null || model.value === void 0 || Number.isNaN(model.value) ? "" : formatter.value.format(model.value)
146
- );
151
+ function withSeparator(formatted) {
152
+ return formatted.map(
153
+ (part) => part.type === "decimal" ? decimalSeparator.value : part.type === "group" ? "" : part.value
154
+ ).join("");
155
+ }
156
+ const display = computed(() => {
157
+ if (model.value === null || model.value === void 0 || Number.isNaN(model.value)) return "";
158
+ return customSeparator.value ? withSeparator(formatter.value.formatToParts(model.value)) : formatter.value.format(model.value);
159
+ });
147
160
  const interactive = computed(() => !control.disabled.value && !props.readonly);
148
161
  const canDecrement = computed(
149
162
  () => interactive.value && (props.min === void 0 || (model.value ?? Infinity) > props.min)
@@ -153,13 +166,23 @@ const canIncrement = computed(
153
166
  );
154
167
  function toEditString(value) {
155
168
  if (value === null || value === void 0 || Number.isNaN(value)) return "";
156
- return editFormatter.value.format(isPercent.value ? value * 100 : value);
169
+ const edited = editFormatter.value.formatToParts(isPercent.value ? value * 100 : value);
170
+ return withSeparator(edited);
171
+ }
172
+ function sanitize(text) {
173
+ const cleaned = text.replace(/[^\d.,-]/g, "");
174
+ const negative = allowsNegative.value && cleaned.startsWith("-");
175
+ const unsigned = cleaned.replace(/-/g, "");
176
+ const mixed = unsigned.includes(".") && unsigned.includes(",");
177
+ const index = mixed ? Math.max(unsigned.lastIndexOf("."), unsigned.lastIndexOf(",")) : unsigned.search(/[.,]/);
178
+ const whole = (index < 0 ? unsigned : unsigned.slice(0, index)).replace(/[.,]/g, "");
179
+ const fraction = index < 0 ? null : unsigned.slice(index + 1).replace(/[.,]/g, "");
180
+ const sign = negative ? "-" : "";
181
+ if (fraction === null || !allowsFraction.value) return sign + whole;
182
+ return `${sign}${whole}${decimalSeparator.value}${fraction}`;
157
183
  }
158
184
  function parse(text) {
159
- const { decimal, group } = separators.value;
160
- let normalized = text.replace(/\s/g, "").split(group).join("");
161
- if (decimal !== ".") normalized = normalized.split(decimal).join(".");
162
- normalized = normalized.replace(/[^\d.\-+eE]/g, "");
185
+ const normalized = sanitize(text.replace(/\s/g, "")).replace(decimalSeparator.value, ".");
163
186
  if (!normalized || normalized === "-" || normalized === ".") return null;
164
187
  const parsed = Number(normalized);
165
188
  if (Number.isNaN(parsed)) return void 0;
@@ -200,7 +223,15 @@ function commit() {
200
223
  draft.value = toEditString(model.value);
201
224
  }
202
225
  function onInput(event) {
203
- draft.value = event.target.value;
226
+ const input = event.target;
227
+ const raw = input.value;
228
+ const next = sanitize(raw);
229
+ if (next !== raw) {
230
+ const caret = Math.max(0, (input.selectionStart ?? raw.length) - (raw.length - next.length));
231
+ input.value = next;
232
+ input.setSelectionRange(caret, caret);
233
+ }
234
+ draft.value = next;
204
235
  const parsed = parse(draft.value);
205
236
  if (parsed !== void 0) model.value = parsed;
206
237
  }
@@ -6,6 +6,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
6
6
  step?: (string | number) | undefined;
7
7
  largeStep?: number;
8
8
  locale?: string;
9
+ decimalSeparator?: string;
9
10
  formatOptions?: Intl.NumberFormatOptions;
10
11
  wheel?: boolean;
11
12
  stepper?: boolean;
@@ -250,6 +251,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
250
251
  step?: (string | number) | undefined;
251
252
  largeStep?: number;
252
253
  locale?: string;
254
+ decimalSeparator?: string;
253
255
  formatOptions?: Intl.NumberFormatOptions;
254
256
  wheel?: boolean;
255
257
  stepper?: boolean;
@@ -31,6 +31,7 @@
31
31
  v-model="promptValue"
32
32
  :type="current.type ?? 'text'"
33
33
  :placeholder="current.placeholder"
34
+ :maxlength="current.maxLength"
34
35
  :aria-labelledby="current.label ? void 0 : titleId"
35
36
  autofocus
36
37
  @keydown.enter.prevent="dialogRef?.confirm()"
@@ -28,6 +28,7 @@ export interface PromptOptions {
28
28
  type?: 'text' | 'email' | 'url' | 'password' | 'search' | 'tel';
29
29
  required?: boolean;
30
30
  requiredText?: string;
31
+ maxLength?: number;
31
32
  validate?: (value: string) => string | false | null | undefined;
32
33
  confirmLabel?: string;
33
34
  cancelLabel?: string;
@@ -10,6 +10,7 @@ export interface DefineLocaleOptions {
10
10
  dir?: 'ltr' | 'rtl';
11
11
  messages?: DeepPartial<KMessages>;
12
12
  base?: KLocale;
13
+ decimalSeparator?: string;
13
14
  }
14
15
  export declare function defineLocale(options: DefineLocaleOptions): KLocale;
15
16
  export declare function formatLocaleMessage(code: string, template: string, params?: MessageParams): string;
@@ -20,7 +20,8 @@ export function defineLocale(options) {
20
20
  return {
21
21
  code: options.code,
22
22
  dir: options.dir ?? base.dir,
23
- messages: mergeMessages(base.messages, options.messages)
23
+ messages: mergeMessages(base.messages, options.messages),
24
+ decimalSeparator: options.decimalSeparator ?? options.base?.decimalSeparator
24
25
  };
25
26
  }
26
27
  function pluralForm(code, forms, count) {
@@ -419,6 +419,7 @@ export interface KLocale {
419
419
  code: string;
420
420
  dir: 'ltr' | 'rtl';
421
421
  messages: KMessages;
422
+ decimalSeparator?: string;
422
423
  }
423
424
  export type DeepPartial<T> = {
424
425
  [K in keyof T]?: T[K] extends string ? T[K] : DeepPartial<T[K]>;
@@ -41,6 +41,7 @@ export interface ModuleOptions {
41
41
  fonts: boolean | ThemePreset[];
42
42
  locale: string;
43
43
  messages: Record<string, DeepPartial<KMessages>>;
44
+ decimalSeparator?: '.' | ',';
44
45
  routeState: {
45
46
  location?: 'query' | 'hash';
46
47
  };
@@ -53,6 +54,7 @@ export interface KRuntimeConfig {
53
54
  presetDefault: ThemePreset;
54
55
  locale: string;
55
56
  messages: Record<string, DeepPartial<KMessages>>;
57
+ decimalSeparator?: '.' | ',';
56
58
  routeLocation: 'query' | 'hash';
57
59
  }
58
60
  declare module '@nuxt/schema' {
@@ -119,6 +119,7 @@ export default defineNuxtModule({
119
119
  presetDefault,
120
120
  locale: options.locale,
121
121
  messages: options.messages,
122
+ decimalSeparator: options.decimalSeparator,
122
123
  routeLocation: options.routeState.location === "hash" ? "hash" : "query"
123
124
  };
124
125
  Object.assign(nuxt.options.runtimeConfig.public, { k: runtimeConfig });
@@ -12,7 +12,11 @@ export default defineNuxtPlugin({
12
12
  );
13
13
  const locale = computed(() => {
14
14
  const language = code.value.split("-")[0];
15
- const base = defineLocale({ code: language, messages: config.messages?.[language] });
15
+ const base = defineLocale({
16
+ code: language,
17
+ messages: config.messages?.[language],
18
+ decimalSeparator: config.decimalSeparator
19
+ });
16
20
  if (language === code.value) return base;
17
21
  return defineLocale({ code: code.value, base, messages: config.messages?.[code.value] });
18
22
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xleddyl/443-components-vue",
3
- "version": "0.16.31",
3
+ "version": "0.16.33",
4
4
  "description": "Compact, scoped dashboard components for Vue and Nuxt",
5
5
  "license": "MIT",
6
6
  "author": "Edoardo Alberti (https://github.com/xleddyl)",