@xleddyl/443-components-vue 0.16.31 → 0.16.32

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` |
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. |
@@ -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;
@@ -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.32",
4
4
  "description": "Compact, scoped dashboard components for Vue and Nuxt",
5
5
  "license": "MIT",
6
6
  "author": "Edoardo Alberti (https://github.com/xleddyl)",