vgapp 0.1.2 → 0.1.4

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.
@@ -1,41 +1,41 @@
1
- @charset "UTF-8";
2
- /**
3
- *--------------------------------------------------------------------------
4
- * Модуль: VGRollup
5
- * Автор: Vegas DEV
6
- * Лицензия: смотри LICENSE
7
- *--------------------------------------------------------------------------
8
- **/
9
- .vg-rollup {
10
- --vg-rollup-transition: all 0.5s ease-in-out ;
11
- --vg-rollup-fade-height: 100px ;
12
- --vg-rollup-fade-background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgb(255, 255, 255) 100%) ;
13
- transform: var(--vg-rollup-transition);
14
- }
15
- .vg-rollup-button {
16
- --vg-rollup-button-align: center ;
17
- text-align: var(--vg-rollup-button-align);
18
- }
19
- .vg-rollup-content--hidden {
20
- overflow: hidden;
21
- }
22
- .vg-rollup-content--fade {
23
- position: relative;
24
- }
25
- .vg-rollup-content--fade:after {
26
- content: "";
27
- position: absolute;
28
- left: 0;
29
- bottom: 0;
30
- width: 100%;
31
- height: var(--vg-rollup-fade-height);
32
- background: var(--vg-rollup-fade-background);
33
- }
34
- .vg-rollup-content--ellipsis {
35
- overflow: hidden;
36
- text-overflow: ellipsis;
37
- display: -webkit-box;
38
- -webkit-box-orient: vertical;
39
- }
40
-
41
- /*# sourceMappingURL=vgrollup.css.map */
1
+ @charset "UTF-8";
2
+ /**
3
+ *--------------------------------------------------------------------------
4
+ * Модуль: VGRollup
5
+ * Автор: Vegas DEV
6
+ * Лицензия: смотри LICENSE
7
+ *--------------------------------------------------------------------------
8
+ **/
9
+ .vg-rollup {
10
+ --vg-rollup-transition: all 0.5s ease-in-out ;
11
+ --vg-rollup-fade-height: 100px ;
12
+ --vg-rollup-fade-background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgb(255, 255, 255) 100%) ;
13
+ transform: var(--vg-rollup-transition);
14
+ }
15
+ .vg-rollup-button {
16
+ --vg-rollup-button-align: center ;
17
+ text-align: var(--vg-rollup-button-align);
18
+ }
19
+ .vg-rollup-content--hidden {
20
+ overflow: hidden;
21
+ }
22
+ .vg-rollup-content--fade {
23
+ position: relative;
24
+ }
25
+ .vg-rollup-content--fade:after {
26
+ content: "";
27
+ position: absolute;
28
+ left: 0;
29
+ bottom: 0;
30
+ width: 100%;
31
+ height: var(--vg-rollup-fade-height);
32
+ background: var(--vg-rollup-fade-background);
33
+ }
34
+ .vg-rollup-content--ellipsis {
35
+ overflow: hidden;
36
+ text-overflow: ellipsis;
37
+ display: -webkit-box;
38
+ -webkit-box-orient: vertical;
39
+ }
40
+
41
+ /*# sourceMappingURL=vgrollup.css.map */
@@ -0,0 +1,341 @@
1
+ import BaseModule from "../../base-module";
2
+ import {isEmptyObj, mergeDeepObject, transliterate} from "../../../utils/js/functions";
3
+ import {Manipulator} from "../../../utils/js/dom/manipulator";
4
+ import EventHandler from "../../../utils/js/dom/event";
5
+
6
+ /**
7
+ * Constants
8
+ */
9
+ const NAME = 'select';
10
+ const NAME_KEY = 'vg.select';
11
+
12
+ const CLASS_NAME_CONTAINER = 'vg-select';
13
+ const CLASS_NAME_DROPDOWN = 'vg-select-dropdown';
14
+ const CLASS_NAME_LIST = 'vg-select-list';
15
+ const CLASS_NAME_OPTION = 'vg-select-list--option';
16
+ const CLASS_NAME_OPTGROUP = 'vg-select-list--optgroup';
17
+ const CLASS_NAME_OPTGROUP_TITLE = 'vg-select-list--optgroup-title';
18
+ const CLASS_NAME_CURRENT = 'vg-select-current';
19
+ const CLASS_NAME_SEARCH = 'vg-select-search';
20
+ const CLASS_NAME_SELECTED = 'selected';
21
+
22
+ const EVENT_KEY_CHANGE = `${NAME_KEY}.change`;
23
+
24
+ let observerTimout;
25
+
26
+ class VGSelect extends BaseModule {
27
+ constructor(element, params = {}) {
28
+ super(element, params);
29
+
30
+ this._params = this._getParams(element, mergeDeepObject({
31
+ search: false
32
+ }, params));
33
+ }
34
+
35
+ static get NAME() {
36
+ return NAME;
37
+ }
38
+
39
+ static get NAME_KEY() {
40
+ return NAME_KEY;
41
+ }
42
+
43
+ build(isRebuild, elm = null) {
44
+ const _this = this;
45
+ let element = this._element;
46
+
47
+ if (elm) element = elm;
48
+
49
+ if (element.dataset?.inited === 'true' && !isRebuild) {
50
+ return;
51
+ } else if (isRebuild) {
52
+ _this.destroy(element);
53
+ }
54
+
55
+ element.parentElement.style.position = 'relative';
56
+
57
+ let option_selected = element.options[element.selectedIndex].innerText,
58
+ options = element.options;
59
+
60
+ // Создаем основной элемент с классами селекта
61
+ let classes = Manipulator.get(element,'class'),
62
+ select = document.createElement('div');
63
+
64
+ classes = classes.split(' ');
65
+
66
+ for (const _class of classes) {
67
+ select.classList.add(_class)
68
+ }
69
+
70
+ if (Manipulator.has(element, 'disabled')) select.classList.add('disabled')
71
+
72
+ let elData = Manipulator.get(element);
73
+ if (!isEmptyObj(elData)) {
74
+ for (const key of Object.keys(elData)) {
75
+ Manipulator.set(select,'data-' + key, elData[key]);
76
+ }
77
+ }
78
+
79
+ // Создаем элемент с отображением выбранного варианта
80
+ let current = document.createElement('div');
81
+ current.classList.add(CLASS_NAME_CURRENT);
82
+ current.innerText = option_selected.trim();
83
+ select.append(current);
84
+
85
+ // Создаем элемент выпадающего списка
86
+ let dropdown = document.createElement('div');
87
+ dropdown.classList.add(CLASS_NAME_DROPDOWN);
88
+ select.append(dropdown);
89
+
90
+ // Создаем список и варианты селекта
91
+ let list = document.createElement('ul');
92
+ list.classList.add(CLASS_NAME_LIST);
93
+
94
+ let optGroup = element.querySelectorAll('optgroup');
95
+
96
+ if (optGroup.length) {
97
+ let isSelected = false;
98
+ [...optGroup].forEach(function (el) {
99
+ let olOptGroup = document.createElement('ol');
100
+ olOptGroup.classList.add(CLASS_NAME_OPTGROUP);
101
+
102
+ let liLabel = document.createElement('li');
103
+ liLabel.innerHTML = el.label.trim();
104
+ liLabel.classList.add(CLASS_NAME_OPTGROUP_TITLE)
105
+
106
+ olOptGroup.prepend(liLabel)
107
+
108
+ let optGroupOptions = el.querySelectorAll('option');
109
+
110
+ createLi(optGroupOptions, olOptGroup, isSelected);
111
+
112
+ list.append(olOptGroup);
113
+ isSelected = true;
114
+ });
115
+ } else {
116
+ let isSelected = false;
117
+ createLi(options, list, isSelected);
118
+ }
119
+
120
+ function createLi(options, list, isSelected) {
121
+ let i = 0;
122
+ for (const option of options) {
123
+ let li = document.createElement('li');
124
+
125
+ li.innerHTML = option.innerHTML.trim().replace(/<\/[^>]+(>|$)/g, "")
126
+ li.dataset.value = Manipulator.get(option, 'value');
127
+ li.classList.add(CLASS_NAME_OPTION);
128
+
129
+ let liData = Manipulator.get(option);
130
+ if (!isEmptyObj(liData)) {
131
+ for (const key of Object.keys(liData)) {
132
+ Manipulator.set(li, 'data-' + key, liData[key]);
133
+ }
134
+ }
135
+
136
+ if (i === element.selectedIndex && !isSelected) {
137
+ li.classList.add('selected');
138
+ }
139
+
140
+ if (Manipulator.has(option, 'disabled')) li.classList.add('disabled');
141
+ if (Manipulator.has(option, 'hidden')) li.classList.add('hidden');
142
+
143
+ list.append(li);
144
+
145
+ i++;
146
+ }
147
+ }
148
+
149
+ dropdown.append(list);
150
+
151
+ // Добавляем все созданный контейнер после селекта
152
+ element.insertAdjacentElement('afterend', select);
153
+
154
+ // помечаем элемент инициализированным
155
+ element.dataset.inited = 'true';
156
+
157
+ if (_this._params.search) {
158
+ this.search(select);
159
+ }
160
+
161
+ this._addEventListeners(select);
162
+ }
163
+
164
+ destroy(select) {
165
+ let element = select.nextElementSibling;
166
+
167
+ if (element) {
168
+ if (element.classList.contains(CLASS_NAME_CONTAINER)) {
169
+ element.remove();
170
+
171
+ select.selectedIndex = 0;
172
+ [...select.querySelectorAll('option')].forEach(function (el, index) {
173
+ if (el.hasAttribute('selected')) {
174
+ select.selectedIndex = index;
175
+ }
176
+ });
177
+ }
178
+ }
179
+ }
180
+
181
+ refresh(select) {
182
+ const _this = this;
183
+
184
+ let observer = new MutationObserver(() => {
185
+ clearTimeout(observerTimout);
186
+ observerTimout = setTimeout(() => {
187
+ _this.build(true, select);
188
+ }, 100);
189
+ });
190
+
191
+ observer.observe(select, {
192
+ attributeFilter: ['disabled', 'required', 'style', 'hidden'],
193
+ childList: true,
194
+ subtree: true,
195
+ characterDataOldValue: true,
196
+ });
197
+ }
198
+
199
+ search(select) {
200
+ const _this = this;
201
+
202
+ let dropdown = select.querySelector('.' + CLASS_NAME_DROPDOWN);
203
+
204
+ let search_container = document.createElement('div');
205
+ search_container.classList.add(CLASS_NAME_SEARCH);
206
+
207
+ let input = document.createElement('input');
208
+ input.setAttribute('name', 'vg-select-search');
209
+ input.setAttribute('type', 'text');
210
+ input.setAttribute('placeholder', 'Поиск...');
211
+
212
+ search_container.append(input);
213
+ dropdown.prepend(search_container);
214
+
215
+ search_container.querySelector('[name=vg-select-search]').addEventListener('keyup', (e) => {
216
+ e.preventDefault();
217
+
218
+ let el = e.target;
219
+
220
+ let selectList = el?.closest('.' + CLASS_NAME_DROPDOWN).querySelector('.' + CLASS_NAME_LIST);
221
+ if (selectList) {
222
+ let options = [...selectList.querySelectorAll('.' + CLASS_NAME_OPTION)],
223
+ optionsGroup = [...selectList.querySelectorAll('.' + CLASS_NAME_OPTGROUP)],
224
+ value = el?.value;
225
+
226
+ options = options.concat(optionsGroup);
227
+
228
+ for (const option of options) {
229
+ Manipulator.show(option);
230
+ }
231
+
232
+ if (value.length) {
233
+ value = value.trim();
234
+ value = value.toLowerCase();
235
+ value = transliterate(value, true);
236
+
237
+ for (const option of options) {
238
+ let text = option.innerText.toLowerCase();
239
+
240
+ if (text.indexOf(value) === -1) Manipulator.hide(option);
241
+ }
242
+ }
243
+ }
244
+ });
245
+ }
246
+
247
+ dispose() {
248
+ super.dispose();
249
+ }
250
+
251
+ _addEventListeners(select) {
252
+ const _this = this;
253
+
254
+ select.querySelector('.' + CLASS_NAME_CURRENT).onclick = function (e) {
255
+ let el = e.target,
256
+ container = el.closest('.' + CLASS_NAME_CONTAINER);
257
+
258
+ let selects = document.querySelectorAll('.' + CLASS_NAME_CONTAINER);
259
+ if (selects.length) {
260
+ for (const els of selects) {
261
+ if (els !== container) {
262
+ els?.classList.remove('show');
263
+ }
264
+ }
265
+ }
266
+
267
+ if (container.classList.contains('show')) {
268
+ container.classList.remove('show');
269
+ } else {
270
+ container.classList.add('show');
271
+
272
+ if (_this._params.search) {
273
+ let input = container.querySelector('input');
274
+ if (input) input.focus();
275
+ }
276
+ }
277
+
278
+ return false;
279
+ }
280
+
281
+ select.querySelectorAll('.' + CLASS_NAME_OPTION).forEach((option) => {
282
+ option.addEventListener('click', (e) => {
283
+ e.preventDefault();
284
+
285
+ let el = e.target;
286
+
287
+ if (!el.classList.contains('disabled')) {
288
+ let container = el.closest('.' + CLASS_NAME_CONTAINER),
289
+ options = container.querySelectorAll('.' + CLASS_NAME_OPTION);
290
+
291
+ if (options.length) {
292
+ for (const option of options) {
293
+ option.classList.remove('selected');
294
+ }
295
+ }
296
+
297
+ el.classList.add('selected');
298
+
299
+ container.querySelector('.' + CLASS_NAME_CURRENT).innerText = el.innerText;
300
+ container.classList.remove('show');
301
+
302
+ let select = container.previousSibling;
303
+ select.value = el.dataset.value;
304
+ EventHandler.trigger(select, EVENT_KEY_CHANGE)
305
+ }
306
+ });
307
+ });
308
+
309
+ window.addEventListener('click', function (e) {
310
+ if (!e?.target.closest('.' + CLASS_NAME_CONTAINER)) {
311
+ let selects = document.querySelectorAll('.' + CLASS_NAME_CONTAINER);
312
+ if (selects.length) {
313
+ for (const el of selects) {
314
+ el?.classList.remove('show');
315
+ }
316
+ }
317
+ }
318
+ });
319
+
320
+ [...document.querySelectorAll('form')].forEach(function (form) {
321
+ form.addEventListener("reset", function () {
322
+ form.querySelectorAll('select.vg-select').forEach(function (select) {
323
+ VGSelect.init(select, {}, true)
324
+ })
325
+ });
326
+ });
327
+ }
328
+
329
+ /**
330
+ * Инициализация
331
+ * @param element
332
+ * @param params
333
+ * @param isRebuild
334
+ */
335
+ static init(element, params = {}, isRebuild = false) {
336
+ const instance = VGSelect.getOrCreateInstance(element, params);
337
+ instance.build(isRebuild);
338
+ }
339
+ }
340
+
341
+ export default VGSelect;
@@ -0,0 +1,74 @@
1
+ $select-current-map: (
2
+ background-color: white,
3
+ color: black,
4
+ border-width: 1px,
5
+ border-style: solid,
6
+ border-color: #dddddd,
7
+ border-radius: 5px,
8
+ padding-left: 16px,
9
+ padding-right: 40px,
10
+ padding-top: 16px,
11
+ padding-bottom: 16px,
12
+ line-height: 1.1,
13
+ font-size: 16px,
14
+ z-index: 10,
15
+ ) !default;
16
+
17
+ $select-current-svg: '<svg aria-hidden="true" focusable="false" data-prefix="fa-light" data-icon="chevron-down" class="svg-inline--fa fa-chevron-down fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M4 181C7 178 12 176 16 176C20 176 24 177 27 180L224 362L421 180C428 174 438 175 444 181C450 188 449 198 443 204L235 396C229 401 219 401 213 396L5 204C-1 198 -2 188 4 181Z" fill="gray"/></svg>' !default;
18
+
19
+ $select-dropdown-map: (
20
+ background-color: white,
21
+ color: black,
22
+ border-width: 1px,
23
+ border-style: solid,
24
+ border-color: #dddddd,
25
+ border-radius: $border-radius,
26
+ box-shadow: 0 7px 12px 1px rgba(68, 68, 68, 0.11),
27
+ z-index: 15,
28
+ ) !default;
29
+
30
+ $select-list-map: (
31
+ background-color: transparent,
32
+ color: black,
33
+ padding-left: 8px,
34
+ padding-right: 8px,
35
+ padding-top: 8px,
36
+ padding-bottom: 8px,
37
+ border-bottom-width: 1px,
38
+ border-bottom-style: solid,
39
+ border-bottom-color: #f5f5f5,
40
+ ) !default;
41
+
42
+ $select-optgroup-map: (
43
+ background-color: transparent,
44
+ color: #fff,
45
+ padding-left: 8px,
46
+ padding-right: 8px,
47
+ padding-top: 8px,
48
+ padding-bottom: 8px,
49
+ border-bottom-width: 1px,
50
+ border-bottom-style: solid,
51
+ border-bottom-color: #838383,
52
+ ) !default;
53
+
54
+ $select-list-max-height: 286px !default;
55
+ $select-list-scrollbar-width: 6px !default;
56
+ $select-list-scrollbar-bg: #F5F5F5 !default;
57
+ $select-list-scrollbar-thumb: #999 !default;
58
+
59
+ $select-list-hover-map: (
60
+ background-color: #f7f7f7,
61
+ color: black,
62
+ border-bottom-color: #f5f5f5,
63
+ ) !default;
64
+
65
+ $select-optgroup-hover-map: (
66
+ background-color: #f7f7f7,
67
+ color: black,
68
+ border-bottom-color: #f5f5f5,
69
+ ) !default;
70
+
71
+ $select-search-map: (
72
+ background-color: #f2f2f2,
73
+ color: #000000
74
+ ) !default;