vgapp 1.1.1 → 1.1.2
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.
|
@@ -274,13 +274,18 @@ class VGFormSender extends BaseModule {
|
|
|
274
274
|
* @param {FormData|null} data - Дополнительные данные для отправки
|
|
275
275
|
*/
|
|
276
276
|
request(event, data = null) {
|
|
277
|
-
const _this = this;
|
|
278
|
-
const mergeFormData = (target, source) => {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
277
|
+
const _this = this;
|
|
278
|
+
const mergeFormData = (target, source) => {
|
|
279
|
+
const replacedKeys = new Set();
|
|
280
|
+
source.forEach((value, key) => {
|
|
281
|
+
if (!replacedKeys.has(key)) {
|
|
282
|
+
target.delete(key);
|
|
283
|
+
replacedKeys.add(key);
|
|
284
|
+
}
|
|
285
|
+
target.append(key, value);
|
|
286
|
+
});
|
|
287
|
+
return target;
|
|
288
|
+
}
|
|
284
289
|
|
|
285
290
|
_this._alertBefore();
|
|
286
291
|
|
|
@@ -777,4 +782,4 @@ EventHandler.on(document, EVENT_SUBMIT_DATA_API, function (event) {
|
|
|
777
782
|
}
|
|
778
783
|
})
|
|
779
784
|
|
|
780
|
-
export default VGFormSender;
|
|
785
|
+
export default VGFormSender;
|
|
@@ -46,12 +46,12 @@ const EVENT_KEY_CLEAR = `${NAME_KEY}.clear`;
|
|
|
46
46
|
const EVENT_KEY_ERROR = `${NAME_KEY}.error`;
|
|
47
47
|
const EVENT_KEY_LOAD_NEXT = `${NAME_KEY}.loadNext`;
|
|
48
48
|
|
|
49
|
-
const SELECTOR_DATA_TOGGLE = '[data-vg-toggle="select"]';
|
|
50
|
-
const SELECTOR_CURRENT = `.${CLASS_NAME_CURRENT}`;
|
|
51
|
-
const SELECTOR_DROPDOWN = `.${CLASS_NAME_DROPDOWN}`;
|
|
52
|
-
const SELECTOR_SEARCH_INPUT = `.${CLASS_NAME_SEARCH} input`;
|
|
53
|
-
const SELECTOR_LIST = `.${CLASS_NAME_LIST}`;
|
|
54
|
-
const SELECTOR_LOAD_MORE_BTN = `.${CLASS_NAME_LOAD_MORE}`;
|
|
49
|
+
const SELECTOR_DATA_TOGGLE = '[data-vg-toggle="select"]';
|
|
50
|
+
const SELECTOR_CURRENT = `.${CLASS_NAME_CURRENT}`;
|
|
51
|
+
const SELECTOR_DROPDOWN = `.${CLASS_NAME_DROPDOWN}`;
|
|
52
|
+
const SELECTOR_SEARCH_INPUT = `.${CLASS_NAME_SEARCH} input`;
|
|
53
|
+
const SELECTOR_LIST = `.${CLASS_NAME_LIST}`;
|
|
54
|
+
const SELECTOR_LOAD_MORE_BTN = `.${CLASS_NAME_LOAD_MORE}`;
|
|
55
55
|
const DATA_ATTR_COPY_EXCLUDE_DEFAULT = ['inited', 'updating', 'exclude'];
|
|
56
56
|
|
|
57
57
|
/**
|
|
@@ -68,8 +68,8 @@ class VGSelect extends BaseModule {
|
|
|
68
68
|
constructor(element, params = {}) {
|
|
69
69
|
super(element, params);
|
|
70
70
|
|
|
71
|
-
this._params = this._getParams(element, mergeDeepObject({
|
|
72
|
-
lang: document.documentElement.lang || 'ru',
|
|
71
|
+
this._params = this._getParams(element, mergeDeepObject({
|
|
72
|
+
lang: document.documentElement.lang || 'ru',
|
|
73
73
|
// Dropdown placement behavior:
|
|
74
74
|
// - none: default CSS positioning (no JS)
|
|
75
75
|
// - auto: choose top/bottom based on available space in overflow ancestor/viewport
|
|
@@ -88,10 +88,10 @@ class VGSelect extends BaseModule {
|
|
|
88
88
|
perpage: 20,
|
|
89
89
|
loadMoreText: 'Загрузить ещё',
|
|
90
90
|
},
|
|
91
|
-
close: true,
|
|
92
|
-
tree: false,
|
|
93
|
-
exclude: '',
|
|
94
|
-
placeholder: '',
|
|
91
|
+
close: true,
|
|
92
|
+
tree: false,
|
|
93
|
+
exclude: 'data-filter-param',
|
|
94
|
+
placeholder: '',
|
|
95
95
|
onInit: null,
|
|
96
96
|
onShow: null,
|
|
97
97
|
onHide: null,
|
|
@@ -254,33 +254,32 @@ class VGSelect extends BaseModule {
|
|
|
254
254
|
parent.appendChild(frag);
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
static _isTreeEnabled(selector, params = {}) {
|
|
258
|
-
if (typeof params.tree === 'boolean') return params.tree;
|
|
259
|
-
if (selector?.dataset && typeof selector.dataset.tree !== 'undefined') {
|
|
260
|
-
return normalizeData(selector.dataset.tree) === true;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
static _getDataAttrCopyExclusions(selector, params = {}) {
|
|
267
|
-
const rawExclude = typeof params.exclude === 'string'
|
|
268
|
-
? params.exclude
|
|
269
|
-
: (selector.dataset.exclude || '');
|
|
270
|
-
const customExcluded = rawExclude
|
|
271
|
-
.split(',')
|
|
272
|
-
.map(item => this._normalizeDataAttrKey(item))
|
|
273
|
-
.filter(Boolean);
|
|
274
|
-
|
|
275
|
-
return new Set([...DATA_ATTR_COPY_EXCLUDE_DEFAULT, ...customExcluded]);
|
|
276
|
-
}
|
|
277
|
-
|
|
257
|
+
static _isTreeEnabled(selector, params = {}) {
|
|
258
|
+
if (typeof params.tree === 'boolean') return params.tree;
|
|
259
|
+
if (selector?.dataset && typeof selector.dataset.tree !== 'undefined') {
|
|
260
|
+
return normalizeData(selector.dataset.tree) === true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
static _getDataAttrCopyExclusions(selector, params = {}) {
|
|
267
|
+
const rawExclude = typeof params.exclude === 'string'
|
|
268
|
+
? params.exclude
|
|
269
|
+
: (selector.dataset.exclude || '');
|
|
270
|
+
const customExcluded = rawExclude
|
|
271
|
+
.split(',')
|
|
272
|
+
.map(item => this._normalizeDataAttrKey(item))
|
|
273
|
+
.filter(Boolean);
|
|
274
|
+
|
|
275
|
+
return new Set([...DATA_ATTR_COPY_EXCLUDE_DEFAULT, ...customExcluded]);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
278
|
static _normalizeDataAttrKey(value) {
|
|
279
279
|
return String(value || '')
|
|
280
280
|
.trim()
|
|
281
281
|
.replace(/^data-/, '')
|
|
282
|
-
.toLowerCase()
|
|
283
|
-
.replace(/-([a-z0-9])/g, (_, chr) => chr.toUpperCase());
|
|
282
|
+
.toLowerCase();
|
|
284
283
|
}
|
|
285
284
|
|
|
286
285
|
/**
|
|
@@ -339,14 +338,14 @@ class VGSelect extends BaseModule {
|
|
|
339
338
|
container.classList.add('disabled');
|
|
340
339
|
}
|
|
341
340
|
|
|
342
|
-
const elData = Manipulator.get(selector);
|
|
343
|
-
if (!isEmptyObj(elData)) {
|
|
344
|
-
const excludeDataAttrs = this._getDataAttrCopyExclusions(selector, params);
|
|
345
|
-
Object.keys(elData).forEach(key => {
|
|
346
|
-
if (excludeDataAttrs.has(key)) return;
|
|
347
|
-
Manipulator.set(container, `data-${key}`, elData[key]);
|
|
348
|
-
});
|
|
349
|
-
}
|
|
341
|
+
const elData = Manipulator.get(selector);
|
|
342
|
+
if (!isEmptyObj(elData)) {
|
|
343
|
+
const excludeDataAttrs = this._getDataAttrCopyExclusions(selector, params);
|
|
344
|
+
Object.keys(elData).forEach(key => {
|
|
345
|
+
if (excludeDataAttrs.has(key)) return;
|
|
346
|
+
Manipulator.set(container, `data-${key}`, elData[key]);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
350
349
|
|
|
351
350
|
const placeholder = selector.dataset.placeholder || '';
|
|
352
351
|
const isMultiple = selector.multiple;
|
|
@@ -401,8 +400,6 @@ class VGSelect extends BaseModule {
|
|
|
401
400
|
this.updateUI(selector);
|
|
402
401
|
const instance = VGSelect.getInstance(container);
|
|
403
402
|
|
|
404
|
-
console.log(instance);
|
|
405
|
-
|
|
406
403
|
let searchInput = null;
|
|
407
404
|
if (Manipulator.has(selector, 'data-search-enabled')) {
|
|
408
405
|
const search = document.createElement('div');
|
|
@@ -791,26 +788,28 @@ class VGSelect extends BaseModule {
|
|
|
791
788
|
* @param {string} value - Значение для выбора
|
|
792
789
|
* @param {Object} [data] - Дополнительные данные
|
|
793
790
|
*/
|
|
794
|
-
static changeSelector(select, value, data = {}) {
|
|
795
|
-
const container = select.nextElementSibling;
|
|
796
|
-
const instance = container ? VGSelect.getInstance(container) : null;
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
const opt = select.querySelector(`option[value="${CSS.escape(normalizeData(value))}"]`);
|
|
791
|
+
static changeSelector(select, value, data = {}) {
|
|
792
|
+
const container = select.nextElementSibling;
|
|
793
|
+
const instance = container ? VGSelect.getInstance(container) : null;
|
|
794
|
+
|
|
795
|
+
select.setAttribute('data-updating', 'true');
|
|
796
|
+
try {
|
|
797
|
+
const opt = select.querySelector(`option[value="${CSS.escape(normalizeData(value))}"]`);
|
|
802
798
|
if (!opt) {
|
|
803
799
|
instance?._triggerEvent(EVENT_KEY_ERROR, { error: 'Option not found', value });
|
|
804
800
|
return;
|
|
805
801
|
}
|
|
806
802
|
|
|
807
|
-
const
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
803
|
+
const wasSelected = opt.selected;
|
|
804
|
+
const selectedText = opt.textContent.trim();
|
|
805
|
+
|
|
806
|
+
if (select.multiple) {
|
|
807
|
+
opt.selected = data?.selected === false ? false : true;
|
|
808
|
+
} else {
|
|
809
|
+
[...select.options].forEach(o => o.selected = false);
|
|
810
|
+
opt.selected = true;
|
|
811
|
+
select.value = opt.value;
|
|
812
|
+
}
|
|
814
813
|
|
|
815
814
|
this.updateUI(select);
|
|
816
815
|
|
|
@@ -833,9 +832,9 @@ class VGSelect extends BaseModule {
|
|
|
833
832
|
* @param {number} index
|
|
834
833
|
* @param {Object} [data]
|
|
835
834
|
*/
|
|
836
|
-
static changeSelectorByIndex(select, index, data = {}) {
|
|
837
|
-
const container = select.nextElementSibling;
|
|
838
|
-
const instance = container ? VGSelect.getInstance(container) : null;
|
|
835
|
+
static changeSelectorByIndex(select, index, data = {}) {
|
|
836
|
+
const container = select.nextElementSibling;
|
|
837
|
+
const instance = container ? VGSelect.getInstance(container) : null;
|
|
839
838
|
|
|
840
839
|
select.setAttribute('data-updating', 'true');
|
|
841
840
|
try {
|
|
@@ -845,13 +844,17 @@ class VGSelect extends BaseModule {
|
|
|
845
844
|
return;
|
|
846
845
|
}
|
|
847
846
|
|
|
848
|
-
const wasSelected = opt.selected;
|
|
849
|
-
const selectedText = opt.textContent.trim();
|
|
850
|
-
const value = opt.value;
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
847
|
+
const wasSelected = opt.selected;
|
|
848
|
+
const selectedText = opt.textContent.trim();
|
|
849
|
+
const value = opt.value;
|
|
850
|
+
|
|
851
|
+
if (select.multiple) {
|
|
852
|
+
opt.selected = data?.selected === false ? false : true;
|
|
853
|
+
} else {
|
|
854
|
+
[...select.options].forEach(o => o.selected = false);
|
|
855
|
+
opt.selected = true;
|
|
856
|
+
select.value = opt.value;
|
|
857
|
+
}
|
|
855
858
|
|
|
856
859
|
this.updateUI(select);
|
|
857
860
|
|