vueless 0.0.761 → 0.0.763

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.761",
3
+ "version": "0.0.763",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -38,7 +38,7 @@ import {
38
38
  import { COMPONENT_NAME } from "./constants.ts";
39
39
 
40
40
  import type { Cell, Row, RowId, UTableProps, UTableRowAttrs, Config } from "./types.ts";
41
- import type { Ref, ComputedRef, VNode } from "vue";
41
+ import type { Ref, ComputedRef } from "vue";
42
42
 
43
43
  defineOptions({ inheritAttrs: false });
44
44
 
@@ -186,17 +186,6 @@ const isCheckedMoreOneTableItems = computed(() => {
186
186
 
187
187
  const tableRowWidthStyle = computed(() => ({ width: `${tableWidth.value / PX_IN_REM}rem` }));
188
188
 
189
- const hasSlotContentBeforeFirstRow = computed(() => {
190
- if (
191
- hasSlotContent(slots["before-first-row"]) &&
192
- typeof slots["before-first-row"] === "function"
193
- ) {
194
- return (slots["before-first-row"]({}) as VNode[])?.some((item) => Boolean(item.type));
195
- }
196
-
197
- return false;
198
- });
199
-
200
189
  const flatTableRows = computed(() => getFlatRows(tableRows.value));
201
190
 
202
191
  const isSelectedAllRows = computed(() => {
@@ -345,19 +334,16 @@ function onKeyupEsc(event: KeyboardEvent) {
345
334
 
346
335
  function isShownDateDivider(rowIndex: number) {
347
336
  const prevIndex = rowIndex ? rowIndex - 1 : rowIndex;
348
- const nextIndex = rowIndex ? rowIndex + 1 : rowIndex;
349
337
  const prevItem = tableRows.value[prevIndex];
350
- const nextItem = tableRows.value[nextIndex];
351
338
  const currentItem = tableRows.value[rowIndex];
352
339
 
353
340
  if (rowIndex === 0) {
354
- return hasSlotContentBeforeFirstRow.value;
341
+ return true;
355
342
  }
356
343
 
357
344
  const isPrevSameDate = prevItem?.rowDate === currentItem?.rowDate;
358
- const isNextSameDate = nextItem?.rowDate === currentItem?.rowDate;
359
345
 
360
- return !isPrevSameDate && isNextSameDate && props.dateDivider;
346
+ return !isPrevSameDate && props.dateDivider;
361
347
  }
362
348
 
363
349
  function onClickRow(row: Row) {
@@ -2,7 +2,6 @@ import type { FormatOptions } from "./types.ts";
2
2
 
3
3
  const isNumberValueRegExp = /^[\d,.\s-]+$/;
4
4
  const rawDecimalMark = ".";
5
- const comma = ",";
6
5
  const minus = "-";
7
6
 
8
7
  export function getRawValue(value: string | number, options: FormatOptions): string {
@@ -14,7 +13,8 @@ export function getRawValue(value: string | number, options: FormatOptions): str
14
13
 
15
14
  const rawValueWithPrefix = value
16
15
  .replaceAll(thousandsSeparator, "")
17
- .replace(decimalSeparator, ".");
16
+ .replaceAll(" ", "")
17
+ .replace(decimalSeparator, rawDecimalMark);
18
18
 
19
19
  return rawValueWithPrefix.replace(prefix, "");
20
20
  }
@@ -30,11 +30,14 @@ export function getFormattedValue(value: string | number, options: FormatOptions
30
30
  } = options;
31
31
 
32
32
  const invalidValuesRegExp = new RegExp("[^\\d,\\d.\\s-" + decimalSeparator + "]", "g");
33
- const doubleValueRegExp = new RegExp("([,\\.\\s" + decimalSeparator + "])+", "g");
33
+ const doubleValueRegExp = new RegExp("([,\\.\\s\\-" + decimalSeparator + "])+", "g");
34
+
35
+ const actualMinFractionDigit =
36
+ minFractionDigits <= maxFractionDigits ? minFractionDigits : maxFractionDigits;
34
37
 
35
38
  // slice to first decimal mark
36
39
  value = String(value)
37
- .replaceAll(comma, decimalSeparator)
40
+ .replaceAll(rawDecimalMark, decimalSeparator)
38
41
  .split(decimalSeparator)
39
42
  .slice(0, 2)
40
43
  .map((value: string, index: number) =>
@@ -51,14 +54,23 @@ export function getFormattedValue(value: string | number, options: FormatOptions
51
54
  const isNumber = isNumberValueRegExp.test(value);
52
55
  const isFloat = value.endsWith(rawDecimalMark) || value.endsWith(".0");
53
56
  const isMinus = value === minus;
54
- const isMinusWithin = value.includes(minus) && !value.startsWith(minus);
55
57
 
56
58
  if (isMinus && positiveOnly) {
57
59
  value = "";
58
60
  }
59
61
 
60
- if (isMinusWithin) {
61
- value = value.replaceAll(minus, "");
62
+ if (value.includes(minus)) {
63
+ let isFirstMinus = value.startsWith(minus);
64
+
65
+ value = value.replaceAll(minus, (match) => {
66
+ if (isFirstMinus) {
67
+ isFirstMinus = false;
68
+
69
+ return match;
70
+ }
71
+
72
+ return "";
73
+ });
62
74
  }
63
75
 
64
76
  if (!value || !isNumber || isFloat || isMinus) {
@@ -66,9 +78,9 @@ export function getFormattedValue(value: string | number, options: FormatOptions
66
78
  }
67
79
 
68
80
  const intlNumberOptions: Intl.NumberFormatOptions = {
69
- minimumFractionDigits:
70
- minFractionDigits <= maxFractionDigits ? minFractionDigits : maxFractionDigits,
81
+ minimumFractionDigits: actualMinFractionDigit,
71
82
  maximumFractionDigits: maxFractionDigits,
83
+ roundingMode: "trunc",
72
84
  };
73
85
 
74
86
  if (positiveOnly) {
@@ -86,20 +98,26 @@ export function getFormattedValue(value: string | number, options: FormatOptions
86
98
  positiveOnly: false,
87
99
  });
88
100
 
89
- const [integer, fraction = ""] = rawValue.split(rawDecimalMark);
90
- const bigInteger = intlNumber.format(BigInt(integer));
101
+ const formattedValue = intlNumber
102
+ .formatToParts((rawValue || 0) as unknown as number)
103
+ .map((part) => {
104
+ if (part.type === "group") part.value = thousandsSeparator;
105
+ if (part.type === "decimal") part.value = decimalSeparator;
106
+
107
+ if (part.type === "fraction") {
108
+ const fraction = rawValue.split(rawDecimalMark).at(-1) || "";
109
+ const formattedFraction = fraction
110
+ .split("")
111
+ .slice(actualMinFractionDigit, maxFractionDigits)
112
+ .join("");
91
113
 
92
- const formattedFraction = fraction
93
- .slice(minFractionDigits, maxFractionDigits)
94
- .padStart(maxFractionDigits, "0");
114
+ part.value = formattedFraction;
115
+ }
95
116
 
96
- const formattedBigInt = fraction
97
- ? bigInteger + `${rawDecimalMark}${formattedFraction}`
98
- : bigInteger;
117
+ return part;
118
+ });
99
119
 
100
- const formattedValue = formattedBigInt
101
- .replaceAll(comma, thousandsSeparator)
102
- .replaceAll(rawDecimalMark, decimalSeparator);
120
+ formattedValue.unshift({ value: prefix, type: "minusSign" });
103
121
 
104
- return prefix + formattedValue;
122
+ return formattedValue.map((part) => part.value).join("");
105
123
  }