not-bulma 1.0.59 → 1.0.60
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 +1 -1
- package/src/elements/common.js +114 -110
- package/src/elements/various/ui.title.svelte +3 -2
package/package.json
CHANGED
package/src/elements/common.js
CHANGED
|
@@ -1,126 +1,130 @@
|
|
|
1
1
|
export default class UICommon {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
static ERROR_DEFAULT = "Что пошло не так.";
|
|
3
|
+
static DEFAULT_REDIRECT_TIMEOUT = 3000;
|
|
4
|
+
static CLASS_OK = "is-success";
|
|
5
|
+
static CLASS_ERR = "is-danger";
|
|
6
|
+
static FILLER = "_";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
8
|
+
static SCROLL_OPTIONS = {
|
|
9
|
+
top: 0,
|
|
10
|
+
behavior: "smooth",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Reformats input from any string to strict phone format
|
|
15
|
+
* @param {string} phone free style phone number
|
|
16
|
+
* @returns {string} phone number
|
|
17
|
+
**/
|
|
18
|
+
static formatPhone(val, filler = this.FILLER) {
|
|
19
|
+
//starting from 11 digits in phone number
|
|
20
|
+
const slots = [1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5];
|
|
21
|
+
let digits = val.replace(/\D/g, "");
|
|
22
|
+
//if there are more, move them to country code slot
|
|
23
|
+
if (digits.length > 11) {
|
|
24
|
+
let d = digits.length - 11;
|
|
25
|
+
while (d > 0) {
|
|
26
|
+
d--;
|
|
27
|
+
slots.unshift(1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
let stack = ["", "", "", "", ""];
|
|
31
|
+
Array.from(digits).forEach((digit, index) => {
|
|
32
|
+
let slot = slots[index];
|
|
33
|
+
stack[slot - 1] = stack[slot - 1] + digit;
|
|
34
|
+
});
|
|
35
|
+
//creating map of parts lengths
|
|
36
|
+
const lens = slots.reduce((acc, curr) => {
|
|
37
|
+
if (typeof acc[curr] === "undefined") {
|
|
38
|
+
acc[curr] = 1;
|
|
39
|
+
} else {
|
|
40
|
+
acc[curr] += 1;
|
|
41
|
+
}
|
|
42
|
+
return acc;
|
|
43
|
+
}, {});
|
|
44
|
+
//fill empty positions with filler (_)
|
|
45
|
+
for (let t in stack) {
|
|
46
|
+
let dif = lens[parseInt(t) + 1] - stack[t].length;
|
|
47
|
+
while (dif > 0) {
|
|
48
|
+
stack[t] = stack[t] + filler;
|
|
49
|
+
dif--;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return `+${stack[0]} (${stack[1]}) ${stack[2]}-${stack[3]}-${stack[4]}`;
|
|
46
53
|
}
|
|
47
|
-
return `+${stack[0]} (${stack[1]}) ${stack[2]}-${stack[3]}-${stack[4]}`;
|
|
48
|
-
}
|
|
49
54
|
|
|
50
|
-
|
|
55
|
+
static MONEY_SIGN = "₽";
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
static setMoneySign(val) {
|
|
58
|
+
this.MONEY_SIGN = val;
|
|
59
|
+
}
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
static formatPrice(price) {
|
|
62
|
+
let major = parseInt(Math.floor(price / 100)),
|
|
63
|
+
minor = parseInt(price % 100);
|
|
64
|
+
major = "" + major;
|
|
65
|
+
return `${this.MONEY_SIGN}${major}.${minor}`;
|
|
66
|
+
}
|
|
62
67
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
static formatLocaleDatetime(dt) {
|
|
69
|
+
const date = dt.toLocaleDateString(window.navigator.language);
|
|
70
|
+
const time = dt.toLocaleTimeString(window.navigator.language);
|
|
71
|
+
return `${date} ${time}`;
|
|
72
|
+
}
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
static tryFormatLocaleDateTime(value) {
|
|
75
|
+
if (typeof value == "string") {
|
|
76
|
+
const dt = new Date(value);
|
|
77
|
+
return UICommon.formatLocaleDatetime(dt);
|
|
78
|
+
} else if (typeof value == "object") {
|
|
79
|
+
return UICommon.formatLocaleDatetime(value);
|
|
80
|
+
} else {
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
77
83
|
}
|
|
78
|
-
}
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
static formatTimestamp(timestamp, offset = 0) {
|
|
86
|
+
let offsetLocal = new Date().getTimezoneOffset();
|
|
87
|
+
let deltaOffset = (offsetLocal - parseInt(offset)) * 60 * 1000;
|
|
88
|
+
let localDateTime = new Date(parseInt(timestamp) - deltaOffset);
|
|
89
|
+
return localDateTime.toLocaleString(window.navigator.language);
|
|
90
|
+
}
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
static TIME = {
|
|
93
|
+
SECONDS: ["секунду", "секунды", "секунд"],
|
|
94
|
+
MINUTES: ["минуту", "минуты", "минут"],
|
|
95
|
+
HOURS: ["час", "часа", "часов"],
|
|
96
|
+
};
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
static declOfNum(n, text_forms) {
|
|
99
|
+
n = Math.abs(n) % 100;
|
|
100
|
+
let n1 = n % 10;
|
|
101
|
+
if (n > 10 && n < 20) {
|
|
102
|
+
return text_forms[2];
|
|
103
|
+
}
|
|
104
|
+
if (n1 > 1 && n1 < 5) {
|
|
105
|
+
return text_forms[1];
|
|
106
|
+
}
|
|
107
|
+
if (n1 == 1) {
|
|
108
|
+
return text_forms[0];
|
|
109
|
+
}
|
|
110
|
+
return text_forms[2];
|
|
101
111
|
}
|
|
102
|
-
if (n1 == 1) {
|
|
103
|
-
return text_forms[0];
|
|
104
|
-
}
|
|
105
|
-
return text_forms[2];
|
|
106
|
-
}
|
|
107
112
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
113
|
+
static humanizedTimeDiff(date /* unix time */) {
|
|
114
|
+
let currentTime = new Date().getTime();
|
|
115
|
+
let sec = Math.round((currentTime - date) / 1000);
|
|
116
|
+
let unit;
|
|
117
|
+
if (sec < 60) {
|
|
118
|
+
unit = this.declOfNum(sec, this.TIME.SECONDS);
|
|
119
|
+
return `${sec} ${unit} назад`;
|
|
120
|
+
} else if (sec < 3600) {
|
|
121
|
+
let min = Math.floor(sec / 60);
|
|
122
|
+
unit = this.declOfNum(min, this.TIME.MINUTES);
|
|
123
|
+
return `${min} ${unit} назад`;
|
|
124
|
+
} else {
|
|
125
|
+
let hours = Math.floor(sec / (60 * 60));
|
|
126
|
+
unit = this.declOfNum(hours, this.TIME.HOURS);
|
|
127
|
+
return `${hours} ${unit} назад`;
|
|
128
|
+
}
|
|
123
129
|
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
130
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { LOCALE } from "../../locale";
|
|
3
|
+
import UICommon from "../common";
|
|
3
4
|
|
|
4
5
|
export let id = `title-${Math.random()}`;
|
|
5
6
|
export let title = "";
|
|
@@ -9,9 +10,9 @@
|
|
|
9
10
|
export let spaced = false;
|
|
10
11
|
export let align = "left";
|
|
11
12
|
|
|
12
|
-
export const scrollToTop = () => {
|
|
13
|
+
export const scrollToTop = (options = UICommon.SCROLL_OPTIONS) => {
|
|
13
14
|
setTimeout(() => {
|
|
14
|
-
document.getElementById(id).scrollIntoView(
|
|
15
|
+
document.getElementById(id).scrollIntoView(options);
|
|
15
16
|
}, 100);
|
|
16
17
|
};
|
|
17
18
|
|