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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-bulma",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "description": "not-* family UI components on Bulma CSS Framework",
5
5
  "main": "src/index.js",
6
6
  "svelte": "src/index.js",
@@ -1,126 +1,130 @@
1
1
  export default class UICommon {
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 = '_';
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
- * Reformats input from any string to strict phone format
10
- * @param {string} phone free style phone number
11
- * @returns {string} phone number
12
- **/
13
- static formatPhone(val, filler = this.FILLER) {
14
- //starting from 11 digits in phone number
15
- const slots = [1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5];
16
- let digits = val.replace(/\D/g, '');
17
- //if there are more, move them to country code slot
18
- if (digits.length > 11) {
19
- let d = digits.length - 11;
20
- while (d > 0) {
21
- d--;
22
- slots.unshift(1);
23
- }
24
- }
25
- let stack = ['', '', '', '', ''];
26
- Array.from(digits).forEach((digit, index) => {
27
- let slot = slots[index];
28
- stack[slot - 1] = (stack[slot - 1] + digit);
29
- });
30
- //creating map of parts lengths
31
- const lens = slots.reduce((acc, curr) => {
32
- if (typeof acc[curr] === 'undefined') {
33
- acc[curr] = 1;
34
- } else {
35
- acc[curr] += 1;
36
- }
37
- return acc;
38
- }, {});
39
- //fill empty positions with filler (_)
40
- for (let t in stack) {
41
- let dif = lens[parseInt(t) + 1] - stack[t].length;
42
- while (dif > 0) {
43
- stack[t] = (stack[t] + filler);
44
- dif--;
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
- static MONEY_SIGN = '₽';
55
+ static MONEY_SIGN = "₽";
51
56
 
52
- static setMoneySign(val) {
53
- this.MONEY_SIGN = val;
54
- }
57
+ static setMoneySign(val) {
58
+ this.MONEY_SIGN = val;
59
+ }
55
60
 
56
- static formatPrice(price) {
57
- let major = parseInt(Math.floor(price / 100)),
58
- minor = parseInt(price % 100);
59
- major = '' + major;
60
- return `${this.MONEY_SIGN}${major}.${minor}`;
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
- static formatLocaleDatetime(dt){
64
- const date = dt.toLocaleDateString(window.navigator.language);
65
- const time = dt.toLocaleTimeString(window.navigator.language);
66
- return `${date} ${time}`
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
- static tryFormatLocaleDateTime(value){
70
- if(typeof value == 'string'){
71
- const dt = new Date(value);
72
- return UICommon.formatLocaleDatetime(dt);
73
- }else if(typeof value == 'object'){
74
- return UICommon.formatLocaleDatetime(value);
75
- }else{
76
- return '';
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
- static formatTimestamp(timestamp, offset = 0) {
81
- let offsetLocal = new Date().getTimezoneOffset();
82
- let deltaOffset = (offsetLocal - parseInt(offset)) * 60 * 1000;
83
- let localDateTime = new Date(parseInt(timestamp) - deltaOffset);
84
- return localDateTime.toLocaleString(window.navigator.language);
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
- static TIME = {
88
- SECONDS: ['секунду', 'секунды', 'секунд'],
89
- MINUTES: ['минуту', 'минуты', 'минут'],
90
- HOURS: ['час', 'часа', 'часов']
91
- };
92
+ static TIME = {
93
+ SECONDS: ["секунду", "секунды", "секунд"],
94
+ MINUTES: ["минуту", "минуты", "минут"],
95
+ HOURS: ["час", "часа", "часов"],
96
+ };
92
97
 
93
- static declOfNum(n, text_forms) {
94
- n = Math.abs(n) % 100;
95
- let n1 = n % 10;
96
- if (n > 10 && n < 20) {
97
- return text_forms[2];
98
- }
99
- if (n1 > 1 && n1 < 5) {
100
- return text_forms[1];
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
- static humanizedTimeDiff(date /* unix time */) {
109
- let currentTime = new Date().getTime();
110
- let sec = Math.round((currentTime - date) / 1000);
111
- let unit;
112
- if (sec < 60) {
113
- unit = this.declOfNum(sec, this.TIME.SECONDS);
114
- return `${sec} ${unit} назад`;
115
- } else if (sec < 3600) {
116
- let min = Math.floor(sec / 60);
117
- unit = this.declOfNum(min, this.TIME.MINUTES);
118
- return `${min} ${unit} назад`;
119
- } else {
120
- let hours = Math.floor(sec / (60 * 60));
121
- unit = this.declOfNum(hours, this.TIME.HOURS);
122
- return `${hours} ${unit} назад`;
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(true);
15
+ document.getElementById(id).scrollIntoView(options);
15
16
  }, 100);
16
17
  };
17
18