vueless 0.0.464 → 0.0.466

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.464",
3
+ "version": "0.0.466",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -297,7 +297,7 @@ import {
297
297
  toggleRowVisibility,
298
298
  switchRowCheck,
299
299
  getFlatRows,
300
- rowsHasId,
300
+ addRowId,
301
301
  } from "./utilTable.js";
302
302
 
303
303
  import { PX_IN_REM } from "../constants.js";
@@ -565,20 +565,13 @@ watch(isFooterSticky, (newValue) =>
565
565
  newValue ? nextTick(setFooterCellWidth) : setFooterCellWidth(null),
566
566
  );
567
567
  watch(
568
- () => selectedRows.value.length,
568
+ () => selectedRows.value,
569
569
  () => {
570
- tableRows.value = tableRows.value.map((row) => syncRowCheck(row, selectedRows.value));
570
+ tableRows.value = tableRows.value
571
+ .map(addRowId)
572
+ .map((row) => syncRowCheck(row, selectedRows.value));
571
573
  },
572
- );
573
- watch(
574
- () => props.rows,
575
- () => {
576
- if (!rowsHasId(props.rows)) {
577
- // eslint-disable-next-line no-console
578
- console.warn("[Vueless][UTable]: Each table row must have unique id.");
579
- }
580
- },
581
- { deep: true, immediate: true },
574
+ { deep: true },
582
575
  );
583
576
 
584
577
  onMounted(() => {
@@ -405,7 +405,6 @@ CellSlots.args = {
405
405
  { key: "tags", label: "tags" },
406
406
  ],
407
407
  row: {
408
- id: getRandomId(),
409
408
  link: "some link",
410
409
  money: {
411
410
  sum: 10,
@@ -418,7 +417,6 @@ CellSlots.args = {
418
417
  },
419
418
  row: [
420
419
  {
421
- id: getRandomId(),
422
420
  isHidden: false,
423
421
  link: "some link",
424
422
  money: {
@@ -432,7 +430,6 @@ CellSlots.args = {
432
430
  },
433
431
  },
434
432
  {
435
- id: getRandomId(),
436
433
  isHidden: false,
437
434
  link: "some link",
438
435
  money: {
@@ -1,3 +1,5 @@
1
+ import { getRandomId } from "../utils/utilUI";
2
+
1
3
  export function normalizeColumns(columns) {
2
4
  return columns.map((column) => (typeof column === "string" ? { label: column } : column));
3
5
  }
@@ -15,13 +17,29 @@ export function getFilteredRow(row, columns) {
15
17
  export function syncRowCheck(row, selectedRows) {
16
18
  row.isChecked = selectedRows.includes(row.id);
17
19
 
18
- if (row.row) {
20
+ if (row.row && !Array.isArray(row.row)) {
19
21
  row.row = syncRowCheck(row.row, selectedRows);
20
22
  }
21
23
 
22
24
  return row;
23
25
  }
24
26
 
27
+ export function addRowId(row) {
28
+ const hasRowId = typeof row.id !== "undefined" && row.id !== null && row.id !== "";
29
+
30
+ row.id = hasRowId ? row.id : getRandomId();
31
+
32
+ if (row.row && !Array.isArray(row.row)) {
33
+ row.row = addRowId(row.row);
34
+ }
35
+
36
+ if (row.row && Array.isArray(row.row)) {
37
+ row.row = row.row.map((nestedRow) => addRowId(nestedRow));
38
+ }
39
+
40
+ return row;
41
+ }
42
+
25
43
  export function toggleRowVisibility(row, targetRowId) {
26
44
  if (row.id === targetRowId) {
27
45
  if (Object.hasOwn(row, "isHidden")) {
@@ -73,28 +91,3 @@ export function getFlatRows(tableRows) {
73
91
 
74
92
  return rows;
75
93
  }
76
-
77
- export function rowsHasId(rows) {
78
- const ids = new Set();
79
- let totalRows = 0;
80
-
81
- function addId(row) {
82
- totalRows++;
83
-
84
- if (typeof row.id !== "undefined") {
85
- ids.add(row.id);
86
- }
87
-
88
- if (row.row && !Array.isArray(row.row)) {
89
- addId(row.row);
90
- }
91
-
92
- if (row.row && Array.isArray(row.row)) {
93
- row.row.forEach(addId);
94
- }
95
- }
96
-
97
- rows.forEach((row) => addId(row));
98
-
99
- return ids.size === totalRows;
100
- }
@@ -12,12 +12,12 @@
12
12
  v-text="symbol + currencySpace"
13
13
  />
14
14
 
15
- <span v-if="sum" v-bind="mathSignAttrs" v-text="mathSign" />
15
+ <span v-if="value" v-bind="mathSignAttrs" v-text="mathSign" />
16
16
 
17
17
  <span v-bind="integerAttrs" v-text="preparedMoney.integer" />
18
18
 
19
19
  <span
20
- v-if="!integer"
20
+ v-if="maxFractionDigits > 0"
21
21
  v-bind="pennyAttrs"
22
22
  v-text="preparedMoney.decimalSeparator + preparedMoney.penny"
23
23
  />
@@ -52,7 +52,7 @@ const props = defineProps({
52
52
  /**
53
53
  * Money value.
54
54
  */
55
- sum: {
55
+ value: {
56
56
  type: Number,
57
57
  default: 0,
58
58
  },
@@ -110,11 +110,19 @@ const props = defineProps({
110
110
  },
111
111
 
112
112
  /**
113
- * Set the numeral decimal scale after the comma.
113
+ * Minimal number of signs after the decimal separator (fractional part of a number).
114
114
  */
115
- decimalScale: {
115
+ minFractionDigits: {
116
116
  type: Number,
117
- default: getDefault(defaultConfig, UMoney).decimalScale,
117
+ default: getDefault(defaultConfig, UMoney).minFractionDigits,
118
+ },
119
+
120
+ /**
121
+ * Maximal number of signs after the decimal separator (fractional part of a number).
122
+ */
123
+ maxFractionDigits: {
124
+ type: Number,
125
+ default: getDefault(defaultConfig, UMoney).maxFractionDigits,
118
126
  },
119
127
 
120
128
  /**
@@ -126,20 +134,20 @@ const props = defineProps({
126
134
  },
127
135
 
128
136
  /**
129
- * Money align.
130
- * @values right, left
137
+ * A symbol used to separate the thousand parts of a number.
131
138
  */
132
- align: {
139
+ thousandsSeparator: {
133
140
  type: String,
134
- default: getDefault(defaultConfig, UMoney).align,
141
+ default: getDefault(defaultConfig, UMoney).thousandsSeparator,
135
142
  },
136
143
 
137
144
  /**
138
- * Make money sum integer.
145
+ * Money align.
146
+ * @values right, left
139
147
  */
140
- integer: {
141
- type: Boolean,
142
- default: getDefault(defaultConfig, UMoney).integer,
148
+ align: {
149
+ type: String,
150
+ default: getDefault(defaultConfig, UMoney).align,
143
151
  },
144
152
 
145
153
  /**
@@ -200,6 +208,12 @@ const mathSign = computed(() => {
200
208
  });
201
209
 
202
210
  const preparedMoney = computed(() => {
203
- return separatedMoney(Math.abs(props.sum), props.decimalScale, props.decimalSeparator);
211
+ return separatedMoney(
212
+ Math.abs(props.value),
213
+ props.minFractionDigits,
214
+ props.maxFractionDigits,
215
+ props.decimalSeparator,
216
+ props.thousandsSeparator,
217
+ );
204
218
  });
205
219
  </script>
@@ -53,8 +53,10 @@ export default /*tw*/ {
53
53
  sign: "default",
54
54
  align: "left",
55
55
  symbolAlign: "right",
56
- decimalScale: 2,
56
+ minFractionDigits: 0,
57
+ maxFractionDigits: 2,
57
58
  decimalSeparator: ",",
59
+ thousandsSeparator: " ",
58
60
  planned: false,
59
61
  integer: false,
60
62
  symbolDivided: true,
@@ -16,7 +16,7 @@ export default {
16
16
  title: "Text & Content / Money",
17
17
  component: UMoney,
18
18
  args: {
19
- sum: 10,
19
+ value: 10,
20
20
  symbol: "$",
21
21
  sign: "positive",
22
22
  },
@@ -73,12 +73,12 @@ export const Default = DefaultTemplate.bind({});
73
73
  Default.args = {};
74
74
 
75
75
  export const OtherValues = DefaultTemplate.bind({});
76
- OtherValues.args = { sum: 10, symbol: "$", sign: "negative" };
76
+ OtherValues.args = { value: 10, symbol: "$", sign: "negative" };
77
77
 
78
78
  export const Colors = EnumVariantTemplate.bind({});
79
79
  Colors.args = {
80
80
  enum: "color",
81
- sum: 0,
81
+ value: 0,
82
82
  symbol: "$",
83
83
  sign: "default",
84
84
  };
@@ -95,11 +95,8 @@ SymbolAlign.args = { enum: "symbolAlign" };
95
95
  export const Planned = DefaultTemplate.bind({});
96
96
  Planned.args = { planned: true };
97
97
 
98
- export const Integer = DefaultTemplate.bind({});
99
- Integer.args = { integer: true };
100
-
101
- export const NumeralDecimalScale3 = DefaultTemplate.bind({});
102
- NumeralDecimalScale3.args = { numeralDecimalScale: 3 };
98
+ export const MinFractionDigits3 = DefaultTemplate.bind({});
99
+ MinFractionDigits3.args = { value: 25.67, minFractionDigits: 3, maxFractionDigits: 3 };
103
100
 
104
101
  export const Align = EnumVariantTemplate.bind({});
105
102
  Align.args = { enum: "align" };
@@ -8,21 +8,39 @@ export const ADD_SPACE_IN_MONEY_REG_EX = /(\d)(?=(\d{3})+(\D|$))/g;
8
8
  export const SINGLE_ZERO = "0";
9
9
  export const DOUBLE_ZERO = "00";
10
10
 
11
- export function separatedMoney(money, decimalPlaces = 2, decimalSeparator = ",") {
12
- const roundedMoney = money ? money.toFixed(decimalPlaces) : 0;
11
+ export function separatedMoney(
12
+ money,
13
+ minFractionDigits = 0,
14
+ maxFractionDigits = 2,
15
+ decimalSeparator = ",",
16
+ thousandsSeparator = " ",
17
+ ) {
18
+ const options = {
19
+ minimumFractionDigits: minFractionDigits,
20
+ maximumFractionDigits: maxFractionDigits,
21
+ };
13
22
 
14
- let [integer, penny] = String(roundedMoney).split(".");
23
+ const formattedMoney =
24
+ money !== undefined && money !== null ? Number(money).toLocaleString("en-US", options) : "0";
15
25
 
16
- integer = integer.replace(ADD_SPACE_IN_MONEY_REG_EX, "$1 ");
26
+ let [integer, penny = ""] = formattedMoney.split(".");
17
27
 
18
- if (!roundedMoney) {
28
+ integer = integer.replace(/,/g, thousandsSeparator);
29
+
30
+ if (!money && money !== 0) {
19
31
  integer = SINGLE_ZERO;
20
32
  penny = DOUBLE_ZERO;
21
33
  }
22
34
 
23
- if (decimalPlaces === 0) {
35
+ if (penny === "") {
36
+ decimalSeparator = "";
37
+ }
38
+
39
+ if (minFractionDigits === 0 && maxFractionDigits === 0) {
24
40
  decimalSeparator = "";
25
41
  penny = "";
42
+ } else if (penny.length < minFractionDigits) {
43
+ penny = penny.padEnd(minFractionDigits, "0");
26
44
  }
27
45
 
28
46
  return { integer, penny, decimalSeparator };
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.464",
4
+ "version": "0.0.466",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",
@@ -6745,7 +6745,7 @@
6745
6745
  "description": "",
6746
6746
  "attributes": [
6747
6747
  {
6748
- "name": "sum",
6748
+ "name": "value",
6749
6749
  "description": "Money value.",
6750
6750
  "value": {
6751
6751
  "kind": "expression",
@@ -6808,8 +6808,17 @@
6808
6808
  "default": "default"
6809
6809
  },
6810
6810
  {
6811
- "name": "decimalScale",
6812
- "description": "Set the numeral decimal scale after the comma.",
6811
+ "name": "minFractionDigits",
6812
+ "description": "Minimal number of signs after the decimal separator (fractional part of a number).",
6813
+ "value": {
6814
+ "kind": "expression",
6815
+ "type": "number"
6816
+ },
6817
+ "default": "0"
6818
+ },
6819
+ {
6820
+ "name": "maxFractionDigits",
6821
+ "description": "Maximal number of signs after the decimal separator (fractional part of a number).",
6813
6822
  "value": {
6814
6823
  "kind": "expression",
6815
6824
  "type": "number"
@@ -6826,22 +6835,22 @@
6826
6835
  "default": ","
6827
6836
  },
6828
6837
  {
6829
- "name": "align",
6830
- "description": "Money align.",
6838
+ "name": "thousandsSeparator",
6839
+ "description": "A symbol used to separate the thousand parts of a number.",
6831
6840
  "value": {
6832
6841
  "kind": "expression",
6833
- "type": "'right' | 'left'"
6842
+ "type": "string"
6834
6843
  },
6835
- "default": "left"
6844
+ "default": " "
6836
6845
  },
6837
6846
  {
6838
- "name": "integer",
6839
- "description": "Make money sum integer.",
6847
+ "name": "align",
6848
+ "description": "Money align.",
6840
6849
  "value": {
6841
6850
  "kind": "expression",
6842
- "type": "boolean"
6851
+ "type": "'right' | 'left'"
6843
6852
  },
6844
- "default": "false"
6853
+ "default": "left"
6845
6854
  },
6846
6855
  {
6847
6856
  "name": "planned",