simp-select 1.0.0
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/.babelrc +3 -0
- package/.browserslistrc +3 -0
- package/.eslintignore +4 -0
- package/.eslintrc +29 -0
- package/LICENSE +21 -0
- package/dist/const/simpleSelection.const.d.ts +6 -0
- package/dist/demo/index.html +98 -0
- package/dist/main.css +1 -0
- package/dist/simpleSelect.d.ts +40 -0
- package/dist/simpleSelect.js +1588 -0
- package/dist/simpleSelectItem.d.ts +49 -0
- package/dist/simpleSelectItemDOM.d.ts +57 -0
- package/dist/style.css +1 -0
- package/dist/types/item.types.d.ts +24 -0
- package/dist/types/simpleSelect.types.d.ts +44 -0
- package/dist/utils/simpleSelection.utils.d.ts +10 -0
- package/dist/utils/store.d.ts +7 -0
- package/package.json +58 -0
- package/src/const/simpleSelection.const.ts +42 -0
- package/src/demo/index.html +256 -0
- package/src/simpleSelect.ts +152 -0
- package/src/simpleSelectItem.ts +535 -0
- package/src/simpleSelectItemDOM.ts +608 -0
- package/src/style.css +413 -0
- package/src/types/item.types.ts +26 -0
- package/src/types/simpleSelect.types.ts +59 -0
- package/src/utils/simpleSelection.utils.ts +66 -0
- package/src/utils/store.ts +60 -0
- package/tsconfig.json +16 -0
- package/webpack.config.js +77 -0
@@ -0,0 +1,1588 @@
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
3
|
+
module.exports = factory();
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
5
|
+
define("SimpleSelect", [], factory);
|
6
|
+
else if(typeof exports === 'object')
|
7
|
+
exports["SimpleSelect"] = factory();
|
8
|
+
else
|
9
|
+
root["SimpleSelect"] = factory();
|
10
|
+
})(typeof self === 'undefined' ? this : self, function() {
|
11
|
+
return /******/ (function() { // webpackBootstrap
|
12
|
+
/******/ "use strict";
|
13
|
+
/******/ var __webpack_modules__ = ({
|
14
|
+
|
15
|
+
/***/ 737:
|
16
|
+
/***/ (function(__unused_webpack_module, exports) {
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Object.defineProperty(exports, "__esModule", ({
|
21
|
+
value: true
|
22
|
+
}));
|
23
|
+
exports.initClass = exports.nameMark = exports.nameSelect = exports.simpleSelectionOptions = exports.simpleSelectLocale = void 0;
|
24
|
+
exports.simpleSelectLocale = {
|
25
|
+
noSearch: 'No matches for',
|
26
|
+
searchText: 'Search',
|
27
|
+
title: 'Select',
|
28
|
+
selected: 'Selected:',
|
29
|
+
all: 'all',
|
30
|
+
ok: 'Ok',
|
31
|
+
cansel: 'Cansel',
|
32
|
+
selectAll: 'Select all',
|
33
|
+
resetAll: 'Reset all'
|
34
|
+
};
|
35
|
+
exports.simpleSelectionOptions = {
|
36
|
+
isSearch: true,
|
37
|
+
isSearchInDropdown: false,
|
38
|
+
countShowSelected: 2,
|
39
|
+
isConfirmInMulti: false,
|
40
|
+
isConfirmInMultiOkClickOutside: false,
|
41
|
+
nativeOnDevice: ['Android', 'BlackBerry', 'iPhone', 'iPad', 'iPod', 'Opera Mini', 'IEMobile', 'Silk'],
|
42
|
+
locale: exports.simpleSelectLocale,
|
43
|
+
sepChars: ',',
|
44
|
+
isUp: false,
|
45
|
+
floatWidth: 767,
|
46
|
+
isCloneClass: true,
|
47
|
+
selectAll: false,
|
48
|
+
selectAllAfterClose: true,
|
49
|
+
resetAll: false,
|
50
|
+
resetAllAfterClose: true
|
51
|
+
};
|
52
|
+
exports.nameSelect = 'SimSel';
|
53
|
+
var markPrefix = 'simple-select-';
|
54
|
+
exports.nameMark = "".concat(markPrefix, "init");
|
55
|
+
exports.initClass = 'SimpleSel';
|
56
|
+
|
57
|
+
/***/ }),
|
58
|
+
|
59
|
+
/***/ 874:
|
60
|
+
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
65
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
66
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
67
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
68
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
69
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
70
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
71
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
72
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
73
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
74
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
75
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
76
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
77
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
78
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
79
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
80
|
+
Object.defineProperty(exports, "__esModule", ({
|
81
|
+
value: true
|
82
|
+
}));
|
83
|
+
exports.SimpleSelectItem = void 0;
|
84
|
+
var simpleSelection_utils_1 = __webpack_require__(679);
|
85
|
+
var simpleSelectItemDOM_1 = __webpack_require__(844);
|
86
|
+
var SimpleSelectItem = /*#__PURE__*/function (_simpleSelectItemDOM_) {
|
87
|
+
_inherits(SimpleSelectItem, _simpleSelectItemDOM_);
|
88
|
+
var _super = _createSuper(SimpleSelectItem);
|
89
|
+
function SimpleSelectItem(select, options, localOptions) {
|
90
|
+
var _thisSuper, _this;
|
91
|
+
_classCallCheck(this, SimpleSelectItem);
|
92
|
+
_this = _super.call(this, select, options, localOptions);
|
93
|
+
_defineProperty(_assertThisInitialized(_this), "closeOutsideHandler", void 0);
|
94
|
+
// not native
|
95
|
+
_defineProperty(_assertThisInitialized(_this), "closeEscHandler", void 0);
|
96
|
+
// not native
|
97
|
+
_defineProperty(_assertThisInitialized(_this), "changeListener", void 0);
|
98
|
+
// not native
|
99
|
+
_defineProperty(_assertThisInitialized(_this), "searchHandler", void 0);
|
100
|
+
// not native
|
101
|
+
_defineProperty(_assertThisInitialized(_this), "clickToggleOpen", void 0);
|
102
|
+
// not native
|
103
|
+
_defineProperty(_assertThisInitialized(_this), "triggerSetup", void 0);
|
104
|
+
// not native
|
105
|
+
_defineProperty(_assertThisInitialized(_this), "confirmOkHandler", void 0);
|
106
|
+
// not native
|
107
|
+
_defineProperty(_assertThisInitialized(_this), "confirmNoHandler", void 0);
|
108
|
+
// not native
|
109
|
+
_defineProperty(_assertThisInitialized(_this), "selectAllHandler", void 0);
|
110
|
+
// not native
|
111
|
+
_defineProperty(_assertThisInitialized(_this), "resetAllHandler", void 0);
|
112
|
+
// not native
|
113
|
+
_defineProperty(_assertThisInitialized(_this), "closeHandler", void 0);
|
114
|
+
// not native
|
115
|
+
_defineProperty(_assertThisInitialized(_this), "handleResize", void 0);
|
116
|
+
// not native
|
117
|
+
_defineProperty(_assertThisInitialized(_this), "mql", null);
|
118
|
+
_defineProperty(_assertThisInitialized(_this), "countOpen", 0);
|
119
|
+
_defineProperty(_assertThisInitialized(_this), "multiDebounceTime", 0);
|
120
|
+
_defineProperty(_assertThisInitialized(_this), "timeoutDebounceId", null);
|
121
|
+
if (!select) {
|
122
|
+
throw Error('Select is required');
|
123
|
+
}
|
124
|
+
_this.init();
|
125
|
+
_get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(SimpleSelectItem.prototype)), "initDom", _thisSuper).call(_thisSuper);
|
126
|
+
_this.initAfterDom();
|
127
|
+
return _this;
|
128
|
+
}
|
129
|
+
_createClass(SimpleSelectItem, [{
|
130
|
+
key: "init",
|
131
|
+
value: function init() {
|
132
|
+
var _this2 = this;
|
133
|
+
this.changeListener = this.changeListenerInit.bind(this);
|
134
|
+
this.$select.addEventListener('change', this.changeListener);
|
135
|
+
this.searchHandler = this.searchHandlerInit.bind(this);
|
136
|
+
this.closeOutsideHandler = this.closeOutsideHandlerInit.bind(this);
|
137
|
+
this.closeEscHandler = this.closeEscHandlerInit.bind(this);
|
138
|
+
this.clickToggleOpen = this.clickToggleOpenInit.bind(this);
|
139
|
+
this.triggerSetup = this.triggerSetupInit.bind(this);
|
140
|
+
this.confirmOkHandler = this.confirmOkHandlerInit.bind(this);
|
141
|
+
this.confirmNoHandler = this.confirmNoHandlerInit.bind(this);
|
142
|
+
this.selectAllHandler = this.selectAllHandlerInit.bind(this);
|
143
|
+
this.resetAllHandler = this.resetAllHandlerInit.bind(this);
|
144
|
+
this.closeHandler = this.closeHandlerInit.bind(this);
|
145
|
+
this.handleResize = this.handleResizeInit.bind(this);
|
146
|
+
if (this.options.callbackInitialization) {
|
147
|
+
this.options.callbackInitialization(this);
|
148
|
+
}
|
149
|
+
if (!this.isNative && this.options.floatWidth) {
|
150
|
+
this.mql = window.matchMedia("(max-width: ".concat(this.options.floatWidth, "px)"));
|
151
|
+
if (this.mql) {
|
152
|
+
// @ts-ignore
|
153
|
+
this.mql.onchange = this.handleResize;
|
154
|
+
this.handleResizeInit(this.mql);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
this.state.subscribe('isOpen', function (val) {
|
158
|
+
_this2.toggleOpenHandler();
|
159
|
+
if (!val && _this2.options.isConfirmInMulti) {
|
160
|
+
_this2.createList();
|
161
|
+
}
|
162
|
+
if (val) {
|
163
|
+
if (_this2.elemInputSearch) {
|
164
|
+
_this2.elemInputSearch.value = '';
|
165
|
+
}
|
166
|
+
}
|
167
|
+
// if (!val) {
|
168
|
+
// if (this.options.isConfirmInMulti) {
|
169
|
+
// this.triggerInit();
|
170
|
+
// }
|
171
|
+
// }
|
172
|
+
});
|
173
|
+
|
174
|
+
this.state.subscribe('filterStr', function (val) {
|
175
|
+
_this2.filterList(val);
|
176
|
+
});
|
177
|
+
if (!this.isNative) {
|
178
|
+
this.elemTopBody.addEventListener('click', this.clickToggleOpen);
|
179
|
+
this.elemTopBody.addEventListener('keyup', this.clickToggleOpen);
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}, {
|
183
|
+
key: "handleResizeInit",
|
184
|
+
value: function handleResizeInit(e) {
|
185
|
+
if (!e) {
|
186
|
+
return;
|
187
|
+
}
|
188
|
+
if (e.matches) {
|
189
|
+
this.state.setState('isFloat', true);
|
190
|
+
} else {
|
191
|
+
this.state.setState('isFloat', false);
|
192
|
+
}
|
193
|
+
}
|
194
|
+
}, {
|
195
|
+
key: "initAfterDom",
|
196
|
+
value: function initAfterDom() {
|
197
|
+
if (this.confirmOk) {
|
198
|
+
this.confirmOk.addEventListener('click', this.confirmOkHandler);
|
199
|
+
}
|
200
|
+
if (this.confirmNo) {
|
201
|
+
this.confirmNo.addEventListener('click', this.confirmNoHandler);
|
202
|
+
}
|
203
|
+
if (this.options.callbackInitialized) {
|
204
|
+
this.options.callbackInitialized(this);
|
205
|
+
}
|
206
|
+
if (this.isMulti && !this.options.isConfirmInMulti) {
|
207
|
+
if ((0, simpleSelection_utils_1.toCamelCase)('simple-debounce-time') in this.$select.dataset) {
|
208
|
+
this.multiDebounceTime = Number(this.$select.dataset[(0, simpleSelection_utils_1.toCamelCase)('simple-debounce-time')]);
|
209
|
+
} else if (this.options.debounceTime || this.options.debounceTime === 0) {
|
210
|
+
this.multiDebounceTime = this.options.debounceTime;
|
211
|
+
}
|
212
|
+
}
|
213
|
+
if (this.multiDebounceTime) {
|
214
|
+
this.multiDebounceChange = this.debounce(this.multiDebounceChange.bind(this), this.multiDebounceTime);
|
215
|
+
}
|
216
|
+
if (this.elemSelectAll) {
|
217
|
+
this.elemSelectAll.addEventListener('click', this.selectAllHandler);
|
218
|
+
}
|
219
|
+
if (this.elemResetAll) {
|
220
|
+
this.elemResetAll.addEventListener('click', this.resetAllHandler);
|
221
|
+
}
|
222
|
+
if (this.elemDropDownClose) {
|
223
|
+
this.elemDropDownClose.addEventListener('click', this.closeHandler);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
}, {
|
227
|
+
key: "debounce",
|
228
|
+
value: function debounce(func, delay) {
|
229
|
+
var _this3 = this;
|
230
|
+
return function () {
|
231
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
232
|
+
args[_key] = arguments[_key];
|
233
|
+
}
|
234
|
+
if (_this3.timeoutDebounceId) {
|
235
|
+
clearTimeout(_this3.timeoutDebounceId);
|
236
|
+
}
|
237
|
+
_this3.timeoutDebounceId = setTimeout(function () {
|
238
|
+
func.apply(void 0, args);
|
239
|
+
_this3.timeoutDebounceId = null;
|
240
|
+
}, delay);
|
241
|
+
};
|
242
|
+
}
|
243
|
+
}, {
|
244
|
+
key: "confirmOkHandlerInit",
|
245
|
+
value: function confirmOkHandlerInit(e) {
|
246
|
+
e.preventDefault();
|
247
|
+
this.confirmOkBuild();
|
248
|
+
}
|
249
|
+
}, {
|
250
|
+
key: "confirmOkBuild",
|
251
|
+
value: function confirmOkBuild() {
|
252
|
+
var options = this.$select.options;
|
253
|
+
if (!this.elemListBody) {
|
254
|
+
return;
|
255
|
+
}
|
256
|
+
var liItems = this.elemListBody.querySelectorAll('[data-sel-position]');
|
257
|
+
liItems.forEach(function (item) {
|
258
|
+
var pos = parseInt(item.dataset[(0, simpleSelection_utils_1.toCamelCase)('sel-position')], 10);
|
259
|
+
if (!pos && pos !== 0) {
|
260
|
+
return;
|
261
|
+
}
|
262
|
+
var option = options[pos];
|
263
|
+
if (!option || option.disabled) {
|
264
|
+
return;
|
265
|
+
}
|
266
|
+
option.selected = item.dataset[(0, simpleSelection_utils_1.toCamelCase)('sel-opt-checked')] === 'true';
|
267
|
+
});
|
268
|
+
this.state.setState('isOpen', false);
|
269
|
+
this.triggerInit();
|
270
|
+
}
|
271
|
+
}, {
|
272
|
+
key: "confirmNoHandlerInit",
|
273
|
+
value: function confirmNoHandlerInit(e) {
|
274
|
+
e.preventDefault();
|
275
|
+
this.state.setState('isOpen', false);
|
276
|
+
}
|
277
|
+
}, {
|
278
|
+
key: "closeHandlerInit",
|
279
|
+
value: function closeHandlerInit(e) {
|
280
|
+
e.preventDefault();
|
281
|
+
this.state.setState('isOpen', false);
|
282
|
+
}
|
283
|
+
}, {
|
284
|
+
key: "selectAllHandlerInit",
|
285
|
+
value: function selectAllHandlerInit(e) {
|
286
|
+
e.preventDefault();
|
287
|
+
Array.from(this.$select.options).forEach(function (option) {
|
288
|
+
if (option.disabled) {
|
289
|
+
return;
|
290
|
+
}
|
291
|
+
option.selected = true;
|
292
|
+
});
|
293
|
+
this.createList();
|
294
|
+
if (this.options.selectAllAfterClose) {
|
295
|
+
this.state.setState('isOpen', false);
|
296
|
+
}
|
297
|
+
this.triggerInit();
|
298
|
+
}
|
299
|
+
}, {
|
300
|
+
key: "resetAllHandlerInit",
|
301
|
+
value: function resetAllHandlerInit(e) {
|
302
|
+
e.preventDefault();
|
303
|
+
Array.from(this.$select.options).forEach(function (option) {
|
304
|
+
if (option.disabled) {
|
305
|
+
return;
|
306
|
+
}
|
307
|
+
option.selected = false;
|
308
|
+
});
|
309
|
+
this.createList();
|
310
|
+
if (this.options.selectAllAfterClose) {
|
311
|
+
this.state.setState('isOpen', false);
|
312
|
+
}
|
313
|
+
this.triggerInit();
|
314
|
+
}
|
315
|
+
// click for LI
|
316
|
+
}, {
|
317
|
+
key: "triggerSetupInit",
|
318
|
+
value: function triggerSetupInit(e) {
|
319
|
+
if (e.button !== 0) return;
|
320
|
+
var target = e.target;
|
321
|
+
var targetLi = target.closest('li');
|
322
|
+
if (targetLi) {
|
323
|
+
this.changeClickItem(targetLi);
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}, {
|
327
|
+
key: "changeClickItem",
|
328
|
+
value: function changeClickItem(item) {
|
329
|
+
if (item) {
|
330
|
+
var pos = Number(item.dataset[(0, simpleSelection_utils_1.toCamelCase)('sel-position')]) || 0;
|
331
|
+
var option = this.$select.options[pos];
|
332
|
+
if (option && !option.disabled) {
|
333
|
+
if (this.isMulti) {
|
334
|
+
if (this.options.isConfirmInMulti || this.isFloatWidth) {
|
335
|
+
if (item.dataset[(0, simpleSelection_utils_1.toCamelCase)('sel-opt-checked')] === 'true') {
|
336
|
+
item.dataset[(0, simpleSelection_utils_1.toCamelCase)('sel-opt-checked')] = 'false';
|
337
|
+
item.classList.remove('SimpleSel__list_item--checked');
|
338
|
+
} else {
|
339
|
+
item.dataset[(0, simpleSelection_utils_1.toCamelCase)('sel-opt-checked')] = 'true';
|
340
|
+
item.classList.add('SimpleSel__list_item--checked');
|
341
|
+
}
|
342
|
+
} else {
|
343
|
+
option.selected = !option.selected;
|
344
|
+
this.createList();
|
345
|
+
this.multiDebounceChange();
|
346
|
+
}
|
347
|
+
} else {
|
348
|
+
option.selected = !option.selected;
|
349
|
+
this.createList();
|
350
|
+
this.state.setState('isOpen', false);
|
351
|
+
this.triggerInit();
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}
|
355
|
+
}
|
356
|
+
}, {
|
357
|
+
key: "multiDebounceChange",
|
358
|
+
value: function multiDebounceChange() {
|
359
|
+
// can be overridden for multiselect - debounce
|
360
|
+
this.triggerInit();
|
361
|
+
}
|
362
|
+
}, {
|
363
|
+
key: "triggerInit",
|
364
|
+
value: function triggerInit() {
|
365
|
+
(0, simpleSelection_utils_1.triggerInputEvent)(this.$select);
|
366
|
+
}
|
367
|
+
}, {
|
368
|
+
key: "clickToggleOpenInit",
|
369
|
+
value: function clickToggleOpenInit(e) {
|
370
|
+
e.preventDefault();
|
371
|
+
if (this.isDisabled) {
|
372
|
+
return;
|
373
|
+
}
|
374
|
+
if (e.type === 'click') {
|
375
|
+
this.state.setState('isOpen', !this.state.getState('isOpen'));
|
376
|
+
return;
|
377
|
+
}
|
378
|
+
if (e instanceof KeyboardEvent) {
|
379
|
+
if (e.key === 'Enter') {
|
380
|
+
this.state.setState('isOpen', !this.state.getState('isOpen'));
|
381
|
+
}
|
382
|
+
}
|
383
|
+
}
|
384
|
+
}, {
|
385
|
+
key: "closeOutsideHandlerInit",
|
386
|
+
value: function closeOutsideHandlerInit(e) {
|
387
|
+
var target = e.target;
|
388
|
+
if (!target) {
|
389
|
+
return;
|
390
|
+
}
|
391
|
+
if (!this.elemWrap.contains(target)) {
|
392
|
+
if (this.options.isConfirmInMulti && this.options.isConfirmInMultiOkClickOutside) {
|
393
|
+
this.confirmOkBuild();
|
394
|
+
}
|
395
|
+
this.state.setState('isOpen', false);
|
396
|
+
}
|
397
|
+
}
|
398
|
+
}, {
|
399
|
+
key: "closeEscHandlerInit",
|
400
|
+
value: function closeEscHandlerInit(e) {
|
401
|
+
if (e.code === 'Escape') {
|
402
|
+
e.preventDefault();
|
403
|
+
e.stopPropagation();
|
404
|
+
this.state.setState('isOpen', false);
|
405
|
+
}
|
406
|
+
if (e.code === 'Tab') {
|
407
|
+
e.preventDefault();
|
408
|
+
e.stopPropagation();
|
409
|
+
if (!this.elemWrap.contains(e.target)) {
|
410
|
+
this.state.setState('isOpen', false);
|
411
|
+
}
|
412
|
+
}
|
413
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
414
|
+
e.preventDefault();
|
415
|
+
e.stopPropagation();
|
416
|
+
this.keyBoardChangeChecked(e.key === 'ArrowDown');
|
417
|
+
}
|
418
|
+
if (e.key === 'Enter') {
|
419
|
+
var target = e.target;
|
420
|
+
if (target && (0, simpleSelection_utils_1.toCamelCase)('sel-opt-item') in target.dataset) {
|
421
|
+
e.preventDefault();
|
422
|
+
e.stopPropagation();
|
423
|
+
this.changeClickItem(target);
|
424
|
+
}
|
425
|
+
}
|
426
|
+
}
|
427
|
+
}, {
|
428
|
+
key: "keyBoardChangeChecked",
|
429
|
+
value: function keyBoardChangeChecked(isDown) {
|
430
|
+
// eslint-disable-next-line max-len
|
431
|
+
var liItems = this.elemListBody.querySelectorAll('[data-sel-position]:not([data-sel-opt-disabled="true"])');
|
432
|
+
if (!liItems.length) {
|
433
|
+
return;
|
434
|
+
}
|
435
|
+
var indCurrent = 0;
|
436
|
+
var firstOption;
|
437
|
+
liItems.forEach(function (el, i) {
|
438
|
+
if (document.activeElement === el) {
|
439
|
+
indCurrent = i;
|
440
|
+
firstOption = el;
|
441
|
+
}
|
442
|
+
el.removeAttribute('tabindex');
|
443
|
+
});
|
444
|
+
if (!firstOption) {
|
445
|
+
firstOption = isDown ? liItems[0] : liItems[liItems.length - 1];
|
446
|
+
} else if (isDown) {
|
447
|
+
firstOption = liItems[indCurrent + 1] || liItems[0];
|
448
|
+
} else {
|
449
|
+
firstOption = liItems[indCurrent - 1] || liItems[liItems.length - 1];
|
450
|
+
}
|
451
|
+
firstOption.tabIndex = 0;
|
452
|
+
firstOption.focus();
|
453
|
+
}
|
454
|
+
}, {
|
455
|
+
key: "searchHandlerInit",
|
456
|
+
value: function searchHandlerInit(e) {
|
457
|
+
var target = e.target;
|
458
|
+
if (!target) {
|
459
|
+
return;
|
460
|
+
}
|
461
|
+
var value = target.value;
|
462
|
+
this.state.setState('filterStr', value);
|
463
|
+
}
|
464
|
+
}, {
|
465
|
+
key: "toggleOpenHandler",
|
466
|
+
value: function toggleOpenHandler() {
|
467
|
+
var isOpen = this.state.getState('isOpen');
|
468
|
+
if (isOpen) {
|
469
|
+
this.elemWrap.classList.add('SimpleSel--open');
|
470
|
+
document.addEventListener('click', this.closeOutsideHandler);
|
471
|
+
document.addEventListener('keyup', this.closeEscHandler);
|
472
|
+
if (this.elemInputSearch) {
|
473
|
+
this.elemInputSearch.focus();
|
474
|
+
// this.elemInputSearch.tabIndex = 0;
|
475
|
+
}
|
476
|
+
|
477
|
+
if (this.options.callbackOpen) {
|
478
|
+
this.options.callbackOpen(this);
|
479
|
+
}
|
480
|
+
this.countOpen++;
|
481
|
+
} else {
|
482
|
+
this.state.setState('filterList', '');
|
483
|
+
this.elemWrap.classList.remove('SimpleSel--open');
|
484
|
+
document.removeEventListener('click', this.closeOutsideHandler);
|
485
|
+
document.removeEventListener('keyup', this.closeEscHandler);
|
486
|
+
if (this.timeoutDebounceId) {
|
487
|
+
clearTimeout(this.timeoutDebounceId);
|
488
|
+
this.triggerInit();
|
489
|
+
}
|
490
|
+
if (this.options.callbackClose && this.countOpen > 0) {
|
491
|
+
this.options.callbackClose(this);
|
492
|
+
}
|
493
|
+
}
|
494
|
+
// this.bodyElement.classList.toggle('SimpleSel--open', this.state.getState('isOpen'))
|
495
|
+
}
|
496
|
+
}, {
|
497
|
+
key: "changeListenerInit",
|
498
|
+
value: function changeListenerInit(e) {
|
499
|
+
if (this.options.callbackChangeSelect) {
|
500
|
+
this.options.callbackChangeSelect(e, this);
|
501
|
+
}
|
502
|
+
this.createList(true);
|
503
|
+
// alert(e.target.value);
|
504
|
+
}
|
505
|
+
}, {
|
506
|
+
key: "getSelect",
|
507
|
+
value: function getSelect() {
|
508
|
+
return this.$select;
|
509
|
+
}
|
510
|
+
}, {
|
511
|
+
key: "handlerChangeChecked",
|
512
|
+
value: function handlerChangeChecked() {
|
513
|
+
if (this.elemListBody) {
|
514
|
+
this.elemListBody.addEventListener('mouseup', this.triggerSetup);
|
515
|
+
// this.elemListBody.addEventListener('mouseup', (e) => {})
|
516
|
+
}
|
517
|
+
}
|
518
|
+
}, {
|
519
|
+
key: "createList",
|
520
|
+
value: function createList() {
|
521
|
+
var isCompare = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
522
|
+
var newItems = [];
|
523
|
+
var group = this.$select.querySelectorAll('optgroup');
|
524
|
+
if (group && group.length) {
|
525
|
+
group.forEach(function (item, ind) {
|
526
|
+
newItems.push((0, simpleSelection_utils_1.getCreateListItem)(item, (ind + 1).toString(), true));
|
527
|
+
});
|
528
|
+
} else {
|
529
|
+
newItems.push((0, simpleSelection_utils_1.getCreateListItem)(this.$select, '1', false));
|
530
|
+
}
|
531
|
+
if (isCompare) {
|
532
|
+
var old = this.state.getState('items');
|
533
|
+
if (!(0, simpleSelection_utils_1.compareObj)(old, newItems)) {
|
534
|
+
this.state.setState('items', newItems);
|
535
|
+
}
|
536
|
+
} else {
|
537
|
+
this.state.setState('items', newItems);
|
538
|
+
}
|
539
|
+
}
|
540
|
+
}, {
|
541
|
+
key: "filterList",
|
542
|
+
value: function filterList(val) {
|
543
|
+
val = val.toLowerCase();
|
544
|
+
var items = (0, simpleSelection_utils_1.cloneObj)(this.state.getState('items'));
|
545
|
+
items.forEach(function (group) {
|
546
|
+
var isShowGroup = false;
|
547
|
+
group.items.forEach(function (item) {
|
548
|
+
if (item.title.toLowerCase().includes(val)) {
|
549
|
+
isShowGroup = true;
|
550
|
+
item.isShowFilter = true;
|
551
|
+
} else {
|
552
|
+
item.isShowFilter = false;
|
553
|
+
}
|
554
|
+
});
|
555
|
+
group.isShowFilter = isShowGroup;
|
556
|
+
});
|
557
|
+
this.state.setState('items', items);
|
558
|
+
}
|
559
|
+
}, {
|
560
|
+
key: "inputSearchHandler",
|
561
|
+
value: function inputSearchHandler() {
|
562
|
+
if (!this.elemInputSearch) {
|
563
|
+
return;
|
564
|
+
}
|
565
|
+
this.elemInputSearch.addEventListener('input', this.searchHandler);
|
566
|
+
}
|
567
|
+
}, {
|
568
|
+
key: "detachItem",
|
569
|
+
value: function detachItem() {
|
570
|
+
if (this.options.callbackDestroyInit) {
|
571
|
+
this.options.callbackDestroyInit(this);
|
572
|
+
}
|
573
|
+
var parentElement = this.elemWrap.parentNode;
|
574
|
+
this.$select.removeEventListener('change', this.changeListener);
|
575
|
+
if (this.elemInputSearch) {
|
576
|
+
this.elemInputSearch.removeEventListener('input', this.searchHandler);
|
577
|
+
}
|
578
|
+
if (this.confirmOk) {
|
579
|
+
this.confirmOk.removeEventListener('click', this.confirmOkHandler);
|
580
|
+
}
|
581
|
+
if (this.confirmNo) {
|
582
|
+
this.confirmNo.removeEventListener('click', this.confirmNoHandler);
|
583
|
+
}
|
584
|
+
parentElement.replaceChild(this.$select, this.elemWrap);
|
585
|
+
this.$select.classList.remove(this.classSelectInit);
|
586
|
+
if (this.elemSelectAll) {
|
587
|
+
this.elemSelectAll.removeEventListener('click', this.selectAllHandler);
|
588
|
+
}
|
589
|
+
if (this.elemResetAll) {
|
590
|
+
this.elemResetAll.removeEventListener('click', this.resetAllHandler);
|
591
|
+
}
|
592
|
+
if (this.options.callbackDestroy) {
|
593
|
+
this.options.callbackDestroy(this);
|
594
|
+
}
|
595
|
+
if (this.elemDropDownClose) {
|
596
|
+
this.elemDropDownClose.removeEventListener('click', this.closeHandler);
|
597
|
+
}
|
598
|
+
if (this.mql) {
|
599
|
+
this.mql.onchange = null;
|
600
|
+
this.mql = null;
|
601
|
+
}
|
602
|
+
}
|
603
|
+
}]);
|
604
|
+
return SimpleSelectItem;
|
605
|
+
}(simpleSelectItemDOM_1.SimpleSelectItemDOM);
|
606
|
+
exports.SimpleSelectItem = SimpleSelectItem;
|
607
|
+
|
608
|
+
/***/ }),
|
609
|
+
|
610
|
+
/***/ 844:
|
611
|
+
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
616
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
617
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
618
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
619
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
620
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
621
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
622
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
623
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
624
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
625
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
626
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
627
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
628
|
+
Object.defineProperty(exports, "__esModule", ({
|
629
|
+
value: true
|
630
|
+
}));
|
631
|
+
exports.SimpleSelectItemDOM = void 0;
|
632
|
+
var simpleSelection_utils_1 = __webpack_require__(679);
|
633
|
+
var store_1 = __webpack_require__(972);
|
634
|
+
var simpleSelection_const_1 = __webpack_require__(737);
|
635
|
+
var SimpleSelectItemDOM = /*#__PURE__*/function () {
|
636
|
+
function SimpleSelectItemDOM(select, options, localOptions) {
|
637
|
+
_classCallCheck(this, SimpleSelectItemDOM);
|
638
|
+
_defineProperty(this, "options", void 0);
|
639
|
+
_defineProperty(this, "$select", void 0);
|
640
|
+
_defineProperty(this, "id", void 0);
|
641
|
+
_defineProperty(this, "titlePlaceholder", void 0);
|
642
|
+
_defineProperty(this, "isDisabled", false);
|
643
|
+
_defineProperty(this, "isMulti", void 0);
|
644
|
+
_defineProperty(this, "state", (0, store_1.store)({
|
645
|
+
items: [],
|
646
|
+
isOpen: false,
|
647
|
+
filterStr: '',
|
648
|
+
isFloat: false
|
649
|
+
}));
|
650
|
+
// classSelectInit= 'SimpleSel__select_init'
|
651
|
+
_defineProperty(this, "classSelectInit", (0, simpleSelection_utils_1.getClass)('select_init'));
|
652
|
+
_defineProperty(this, "isNative", void 0);
|
653
|
+
_defineProperty(this, "elemWrap", document.createElement('div'));
|
654
|
+
// all
|
655
|
+
_defineProperty(this, "elemTop", document.createElement('div'));
|
656
|
+
// all
|
657
|
+
_defineProperty(this, "elemTopBody", document.createElement('div'));
|
658
|
+
// all
|
659
|
+
_defineProperty(this, "elemDropDown", null);
|
660
|
+
// not native
|
661
|
+
_defineProperty(this, "elemDropDownClose", null);
|
662
|
+
// not native
|
663
|
+
_defineProperty(this, "elemListBody", null);
|
664
|
+
// not native
|
665
|
+
_defineProperty(this, "elemInputSearch", null);
|
666
|
+
// not native
|
667
|
+
_defineProperty(this, "elemTitle", void 0);
|
668
|
+
// not native
|
669
|
+
_defineProperty(this, "confirmOk", null);
|
670
|
+
// not native
|
671
|
+
_defineProperty(this, "confirmNo", null);
|
672
|
+
// not native
|
673
|
+
_defineProperty(this, "elemControl", null);
|
674
|
+
// not native
|
675
|
+
_defineProperty(this, "elemSelectAll", null);
|
676
|
+
// not native
|
677
|
+
_defineProperty(this, "elemResetAll", null);
|
678
|
+
// not native
|
679
|
+
_defineProperty(this, "cloneClasses", '');
|
680
|
+
_defineProperty(this, "isShowCheckbox", false);
|
681
|
+
_defineProperty(this, "bodyLiHTMLBeforeFromSelect", null);
|
682
|
+
_defineProperty(this, "bodyLiHTMLAfterFromSelect", null);
|
683
|
+
_defineProperty(this, "isFloatWidth", false);
|
684
|
+
_defineProperty(this, "bodyOpenClass", "".concat(simpleSelection_const_1.initClass, "--body_open"));
|
685
|
+
var id = localOptions.id,
|
686
|
+
isNative = localOptions.isNative;
|
687
|
+
this.$select = select;
|
688
|
+
this.isMulti = select.multiple;
|
689
|
+
this.id = id;
|
690
|
+
this.isNative = isNative;
|
691
|
+
this.options = (0, simpleSelection_utils_1.cloneObj)(options);
|
692
|
+
if (this.options.isCloneClass) {
|
693
|
+
this.cloneClasses = this.$select.className;
|
694
|
+
}
|
695
|
+
if (options.callbackInitialization) {
|
696
|
+
this.options.callbackInitialization = options.callbackInitialization;
|
697
|
+
}
|
698
|
+
if (options.callbackInitialized) {
|
699
|
+
this.options.callbackInitialized = options.callbackInitialized;
|
700
|
+
}
|
701
|
+
if (options.callbackOpen) {
|
702
|
+
this.options.callbackOpen = options.callbackOpen;
|
703
|
+
}
|
704
|
+
if (options.callbackClose) {
|
705
|
+
this.options.callbackClose = options.callbackClose;
|
706
|
+
}
|
707
|
+
if (options.callbackDestroyInit) {
|
708
|
+
this.options.callbackDestroyInit = options.callbackDestroyInit;
|
709
|
+
}
|
710
|
+
if (options.callbackDestroy) {
|
711
|
+
this.options.callbackDestroy = options.callbackDestroy;
|
712
|
+
}
|
713
|
+
if (options.callbackChangeSelect) {
|
714
|
+
this.options.callbackChangeSelect = options.callbackChangeSelect;
|
715
|
+
}
|
716
|
+
if (options.changeBodyLi) {
|
717
|
+
this.options.changeBodyLi = options.changeBodyLi;
|
718
|
+
}
|
719
|
+
var dataConfirm = this.$select.dataset[(0, simpleSelection_utils_1.toCamelCase)('simple-is-confirm')];
|
720
|
+
if (this.isMulti && dataConfirm) {
|
721
|
+
this.options.isConfirmInMulti = dataConfirm === '1' || dataConfirm === 'true';
|
722
|
+
}
|
723
|
+
this.optionOverride();
|
724
|
+
this.isDisabled = this.$select.disabled;
|
725
|
+
// this.initDom()
|
726
|
+
}
|
727
|
+
_createClass(SimpleSelectItemDOM, [{
|
728
|
+
key: "optionOverride",
|
729
|
+
value: function optionOverride() {
|
730
|
+
var dataPlaceholder = (0, simpleSelection_utils_1.toCamelCase)('simple-placeholder');
|
731
|
+
if (this.$select.dataset[dataPlaceholder]) {
|
732
|
+
this.titlePlaceholder = this.$select.dataset[dataPlaceholder] || '';
|
733
|
+
} else {
|
734
|
+
this.titlePlaceholder = this.options.locale.title;
|
735
|
+
}
|
736
|
+
var dataResetAll = (0, simpleSelection_utils_1.toCamelCase)('simple-reset-all');
|
737
|
+
if (dataResetAll in this.$select.dataset) {
|
738
|
+
var resReset = this.$select.dataset[dataResetAll];
|
739
|
+
this.options.resetAll = !(resReset === 'false' || resReset === '0');
|
740
|
+
}
|
741
|
+
// const dataSelect = toCamelCase('simple-select-all');
|
742
|
+
// if (dataSelect in this.$select.dataset) {
|
743
|
+
// const resSelect = this.$select.dataset[dataSelect];
|
744
|
+
// this.options.selectAll = !(resSelect === 'false' || resSelect === '0');
|
745
|
+
// }
|
746
|
+
if (this.$select.hasAttribute('data-simple-select-all')) {
|
747
|
+
var resSelect = this.$select.getAttribute('data-simple-select-all');
|
748
|
+
this.options.selectAll = (0, simpleSelection_utils_1.ifTrueDataAttr)(resSelect);
|
749
|
+
}
|
750
|
+
var isShowCheckboxLocal = this.$select.dataset[(0, simpleSelection_utils_1.toCamelCase)('simple-show-checkbox')];
|
751
|
+
if (this.isMulti) {
|
752
|
+
this.isShowCheckbox = !(isShowCheckboxLocal && !(0, simpleSelection_utils_1.ifTrueDataAttr)(isShowCheckboxLocal));
|
753
|
+
} else if (isShowCheckboxLocal === 'true') {
|
754
|
+
this.isShowCheckbox = true;
|
755
|
+
}
|
756
|
+
var itemHtmlBefore = this.$select.dataset[(0, simpleSelection_utils_1.toCamelCase)('simple-item-html-before')];
|
757
|
+
if (itemHtmlBefore) {
|
758
|
+
this.bodyLiHTMLBeforeFromSelect = itemHtmlBefore;
|
759
|
+
}
|
760
|
+
var itemHtmlAfter = this.$select.dataset[(0, simpleSelection_utils_1.toCamelCase)('simple-item-html-after')];
|
761
|
+
if (itemHtmlAfter) {
|
762
|
+
this.bodyLiHTMLAfterFromSelect = itemHtmlAfter;
|
763
|
+
}
|
764
|
+
if (this.$select.hasAttribute('data-simple-up')) {
|
765
|
+
this.options.isUp = (0, simpleSelection_utils_1.ifTrueDataAttr)(this.$select.getAttribute('data-simple-up'));
|
766
|
+
}
|
767
|
+
}
|
768
|
+
}, {
|
769
|
+
key: "initDom",
|
770
|
+
value: function initDom() {
|
771
|
+
var _this = this;
|
772
|
+
this.createList(false);
|
773
|
+
this.createHTML();
|
774
|
+
this.state.subscribe('items', function (_val) {
|
775
|
+
_this.createListHTML();
|
776
|
+
_this.createTitleHTML();
|
777
|
+
});
|
778
|
+
this.state.subscribe('isOpen', function (val) {
|
779
|
+
_this.createListHTML();
|
780
|
+
_this.createTitleHTML();
|
781
|
+
_this.toggleTabIndex(val);
|
782
|
+
});
|
783
|
+
this.state.subscribe('isFloat', function (val) {
|
784
|
+
_this.isFloatWidth = val;
|
785
|
+
var cls = (0, simpleSelection_utils_1.getClass)('float', true);
|
786
|
+
_this.elemWrap.classList.toggle(cls, val);
|
787
|
+
});
|
788
|
+
}
|
789
|
+
}, {
|
790
|
+
key: "toggleTabIndex",
|
791
|
+
value: function toggleTabIndex(isOpen) {
|
792
|
+
var tabIndex = isOpen ? 0 : -1;
|
793
|
+
if (this.state.getState('isFloat')) {
|
794
|
+
document.body.classList.toggle(this.bodyOpenClass, isOpen);
|
795
|
+
}
|
796
|
+
if (this.elemInputSearch) {
|
797
|
+
this.elemInputSearch.tabIndex = tabIndex;
|
798
|
+
}
|
799
|
+
if (this.elemResetAll) {
|
800
|
+
this.elemResetAll.tabIndex = tabIndex;
|
801
|
+
}
|
802
|
+
if (this.elemSelectAll) {
|
803
|
+
this.elemSelectAll.tabIndex = tabIndex;
|
804
|
+
}
|
805
|
+
if (this.confirmOk) {
|
806
|
+
this.confirmOk.tabIndex = tabIndex;
|
807
|
+
}
|
808
|
+
if (this.confirmNo) {
|
809
|
+
this.confirmNo.tabIndex = tabIndex;
|
810
|
+
}
|
811
|
+
}
|
812
|
+
}, {
|
813
|
+
key: "updateHTML",
|
814
|
+
value: function updateHTML() {
|
815
|
+
this.createList(true);
|
816
|
+
}
|
817
|
+
}, {
|
818
|
+
key: "createHTML",
|
819
|
+
value: function createHTML() {
|
820
|
+
this.$select.classList.add(this.classSelectInit);
|
821
|
+
this.$select.tabIndex = -1;
|
822
|
+
this.elemTopBody.className = (0, simpleSelection_utils_1.getClass)('top_body');
|
823
|
+
this.elemTopBody.tabIndex = this.isDisabled ? -1 : 0;
|
824
|
+
this.createIcon();
|
825
|
+
this.elemTop.append(this.elemTopBody);
|
826
|
+
var resClassesWrap = simpleSelection_const_1.initClass;
|
827
|
+
if (this.options.isCloneClass) {
|
828
|
+
resClassesWrap += " ".concat(this.cloneClasses);
|
829
|
+
}
|
830
|
+
if (this.$select.hasAttribute('data-simple-add-classes')) {
|
831
|
+
resClassesWrap += " ".concat(this.$select.getAttribute('data-simple-add-classes'));
|
832
|
+
}
|
833
|
+
if (this.isDisabled) {
|
834
|
+
resClassesWrap += " ".concat((0, simpleSelection_utils_1.getClass)('disabled', true));
|
835
|
+
}
|
836
|
+
if (this.options.isUp) {
|
837
|
+
resClassesWrap += " ".concat((0, simpleSelection_utils_1.getClass)('up', true));
|
838
|
+
}
|
839
|
+
resClassesWrap += " ".concat(this.isMulti ? (0, simpleSelection_utils_1.getClass)('multi', true) : (0, simpleSelection_utils_1.getClass)('single', true));
|
840
|
+
this.elemWrap.className = resClassesWrap;
|
841
|
+
this.elemWrap.dataset.countAll = this.$select.options.length.toString();
|
842
|
+
this.elemTop.className = (0, simpleSelection_utils_1.getClass)('top');
|
843
|
+
// creating an initial structure
|
844
|
+
var parentElement = this.$select.parentNode;
|
845
|
+
if (parentElement) {
|
846
|
+
parentElement.replaceChild(this.elemWrap, this.$select);
|
847
|
+
this.elemWrap.appendChild(this.$select);
|
848
|
+
}
|
849
|
+
this.elemWrap.append(this.elemTop);
|
850
|
+
if (this.isNative) {
|
851
|
+
this.$select.classList.add((0, simpleSelection_utils_1.getClass)('native', true, this.classSelectInit));
|
852
|
+
this.elemWrap.classList.add((0, simpleSelection_utils_1.getClass)('native', true));
|
853
|
+
} else {
|
854
|
+
this.createDropDown();
|
855
|
+
this.createControlHTML();
|
856
|
+
this.createInputHTML();
|
857
|
+
}
|
858
|
+
this.createTitleHTML();
|
859
|
+
}
|
860
|
+
}, {
|
861
|
+
key: "createControlHTML",
|
862
|
+
value: function createControlHTML() {
|
863
|
+
if (!this.elemDropDown || !this.isMulti) {
|
864
|
+
return;
|
865
|
+
}
|
866
|
+
if (!this.options.selectAll && !this.options.resetAll) {
|
867
|
+
return;
|
868
|
+
}
|
869
|
+
this.elemControl = document.createElement('div');
|
870
|
+
this.elemControl.classList.add((0, simpleSelection_utils_1.getClass)('controls'));
|
871
|
+
this.elemDropDown.prepend(this.elemControl);
|
872
|
+
var classControl = (0, simpleSelection_utils_1.getClass)('control');
|
873
|
+
if (this.options.selectAll) {
|
874
|
+
this.elemSelectAll = (0, simpleSelection_utils_1.createButton)();
|
875
|
+
this.elemSelectAll.className = "".concat(classControl, " ").concat((0, simpleSelection_utils_1.getClass)('select_all', true, classControl));
|
876
|
+
this.elemSelectAll.innerHTML = "<span class=\"".concat((0, simpleSelection_utils_1.getClass)('select_all__icon'), "\"></span> ").concat(this.options.locale.selectAll);
|
877
|
+
this.elemControl.append(this.elemSelectAll);
|
878
|
+
}
|
879
|
+
if (this.options.resetAll) {
|
880
|
+
this.elemResetAll = (0, simpleSelection_utils_1.createButton)();
|
881
|
+
this.elemResetAll.className = "".concat(classControl, " ").concat((0, simpleSelection_utils_1.getClass)('reset_all', true, classControl));
|
882
|
+
this.elemResetAll.innerHTML = "<span class=\"".concat((0, simpleSelection_utils_1.getClass)('reset_all__icon'), "\"></span> ").concat(this.options.locale.resetAll);
|
883
|
+
this.elemControl.append(this.elemResetAll);
|
884
|
+
}
|
885
|
+
}
|
886
|
+
}, {
|
887
|
+
key: "createIcon",
|
888
|
+
value: function createIcon() {
|
889
|
+
var icon = document.createElement('span');
|
890
|
+
icon.className = (0, simpleSelection_utils_1.getClass)('icon');
|
891
|
+
this.elemTopBody.append(icon);
|
892
|
+
}
|
893
|
+
}, {
|
894
|
+
key: "createDropDown",
|
895
|
+
value: function createDropDown() {
|
896
|
+
if (this.isNative) {
|
897
|
+
return;
|
898
|
+
}
|
899
|
+
this.elemDropDown = document.createElement('div');
|
900
|
+
this.elemDropDown.className = (0, simpleSelection_utils_1.getClass)('body');
|
901
|
+
this.elemListBody = document.createElement('ul');
|
902
|
+
this.elemListBody.className = (0, simpleSelection_utils_1.getClass)('list');
|
903
|
+
this.elemWrap.append(this.elemDropDown);
|
904
|
+
this.elemDropDown.append(this.elemListBody);
|
905
|
+
this.elemDropDownClose = (0, simpleSelection_utils_1.createButton)();
|
906
|
+
this.elemDropDownClose.classList.add((0, simpleSelection_utils_1.getClass)('close'));
|
907
|
+
this.elemDropDown.append(this.elemDropDownClose);
|
908
|
+
if (this.isMulti) {
|
909
|
+
this.createIsConfirmInMultiHTML();
|
910
|
+
}
|
911
|
+
this.handlerChangeChecked();
|
912
|
+
}
|
913
|
+
}, {
|
914
|
+
key: "createIsConfirmInMultiHTML",
|
915
|
+
value: function createIsConfirmInMultiHTML() {
|
916
|
+
var _this$elemDropDown;
|
917
|
+
var confirm = document.createElement('div');
|
918
|
+
var classesItem = (0, simpleSelection_utils_1.getClass)('bottom_control');
|
919
|
+
this.confirmOk = (0, simpleSelection_utils_1.createButton)();
|
920
|
+
this.confirmNo = (0, simpleSelection_utils_1.createButton)();
|
921
|
+
confirm.append(this.confirmOk);
|
922
|
+
confirm.append(this.confirmNo);
|
923
|
+
this.confirmOk.innerHTML = this.options.locale.ok;
|
924
|
+
this.confirmNo.innerHTML = this.options.locale.cansel;
|
925
|
+
this.confirmOk.className = "".concat(classesItem, " ").concat((0, simpleSelection_utils_1.getClass)('ok', true, classesItem));
|
926
|
+
this.confirmNo.className = "".concat(classesItem, " ").concat((0, simpleSelection_utils_1.getClass)('no', true, classesItem));
|
927
|
+
var classes = (0, simpleSelection_utils_1.getClass)('bottom_controls');
|
928
|
+
if (!this.options.isConfirmInMulti) {
|
929
|
+
classes += " ".concat((0, simpleSelection_utils_1.getClass)('hide', true, classes));
|
930
|
+
}
|
931
|
+
confirm.className = classes;
|
932
|
+
(_this$elemDropDown = this.elemDropDown) === null || _this$elemDropDown === void 0 || _this$elemDropDown.append(confirm);
|
933
|
+
}
|
934
|
+
}, {
|
935
|
+
key: "createTitleHTML",
|
936
|
+
value: function createTitleHTML() {
|
937
|
+
var _this2 = this;
|
938
|
+
if (!this.elemTitle) {
|
939
|
+
this.elemTitle = document.createElement('div');
|
940
|
+
this.elemTitle.className = (0, simpleSelection_utils_1.getClass)('title');
|
941
|
+
this.elemTopBody.prepend(this.elemTitle);
|
942
|
+
}
|
943
|
+
var itemsChecked = this.getChecked();
|
944
|
+
this.elemTop.title = '';
|
945
|
+
var isPlaceholder = !itemsChecked.length;
|
946
|
+
var title = this.titlePlaceholder;
|
947
|
+
if (itemsChecked.length) {
|
948
|
+
var attrTitle = '';
|
949
|
+
itemsChecked.forEach(function (item, index) {
|
950
|
+
if (index !== 0) {
|
951
|
+
attrTitle += "".concat(_this2.options.sepChars, "<span class=\"").concat((0, simpleSelection_utils_1.getClass)('sep_space', true), "\"> </span>");
|
952
|
+
}
|
953
|
+
attrTitle += "".concat(item.title);
|
954
|
+
});
|
955
|
+
this.elemTop.title = attrTitle;
|
956
|
+
var maxShow = this.options.countShowSelected;
|
957
|
+
var maxShowAttr = Number(this.$select.dataset.simpleCountShowsSelected);
|
958
|
+
if (maxShowAttr && maxShowAttr > 0) {
|
959
|
+
maxShow = maxShowAttr;
|
960
|
+
}
|
961
|
+
if (itemsChecked.length > maxShow) {
|
962
|
+
title = "".concat(this.options.locale.selected, " ").concat(itemsChecked.length);
|
963
|
+
if (this.$select.querySelectorAll('option').length === itemsChecked.length) {
|
964
|
+
title += " (".concat(this.options.locale.all, ")");
|
965
|
+
}
|
966
|
+
} else if (attrTitle) {
|
967
|
+
title = attrTitle;
|
968
|
+
}
|
969
|
+
}
|
970
|
+
this.elemTitle.innerHTML = title;
|
971
|
+
this.elemTitle.classList.toggle('SimpleSel__title--placeholder', isPlaceholder);
|
972
|
+
this.elemTitle.classList.toggle('SimpleSel__title--fill', !isPlaceholder);
|
973
|
+
this.elemWrap.classList.toggle((0, simpleSelection_utils_1.getClass)('fill', true), !isPlaceholder);
|
974
|
+
}
|
975
|
+
}, {
|
976
|
+
key: "createListHTML",
|
977
|
+
value: function createListHTML() {
|
978
|
+
var _this3 = this;
|
979
|
+
if (!this.elemListBody) {
|
980
|
+
return;
|
981
|
+
}
|
982
|
+
var resBodyList = '';
|
983
|
+
var countShowItem = 0;
|
984
|
+
var countCheckedItems = 0;
|
985
|
+
var countCheckedFullItems = 0;
|
986
|
+
// this.items.forEach(group => {
|
987
|
+
this.state.getState('items').forEach(function (group) {
|
988
|
+
if (!group.isGroup) {
|
989
|
+
var _this3$createLi = _this3.createLi(group),
|
990
|
+
result = _this3$createLi.result,
|
991
|
+
countShow = _this3$createLi.countShow,
|
992
|
+
countChecked = _this3$createLi.countChecked,
|
993
|
+
countCheckedFull = _this3$createLi.countCheckedFull;
|
994
|
+
resBodyList += result;
|
995
|
+
countShowItem += countShow;
|
996
|
+
countCheckedItems += countChecked;
|
997
|
+
countCheckedFullItems += countCheckedFull;
|
998
|
+
} else {
|
999
|
+
var _this3$createLi2 = _this3.createLi(group),
|
1000
|
+
_result = _this3$createLi2.result,
|
1001
|
+
_countShow = _this3$createLi2.countShow,
|
1002
|
+
_countChecked = _this3$createLi2.countChecked,
|
1003
|
+
_countCheckedFull = _this3$createLi2.countCheckedFull;
|
1004
|
+
resBodyList += "<div class=\"".concat((0, simpleSelection_utils_1.getClass)('group_items'), "\">");
|
1005
|
+
resBodyList += _result;
|
1006
|
+
resBodyList += '</div>';
|
1007
|
+
countCheckedItems += _countChecked;
|
1008
|
+
countShowItem += _countShow;
|
1009
|
+
countCheckedFullItems += _countCheckedFull;
|
1010
|
+
}
|
1011
|
+
});
|
1012
|
+
var isSearch = this.state.getState('filterStr');
|
1013
|
+
if (isSearch && isSearch.length && countShowItem === 0) {
|
1014
|
+
resBodyList = "<div class=\"".concat((0, simpleSelection_utils_1.getClass)('no_match'), "\">");
|
1015
|
+
resBodyList = "".concat(this.options.locale.noSearch, " \"").concat(isSearch, "\"");
|
1016
|
+
resBodyList += '</div>';
|
1017
|
+
}
|
1018
|
+
this.elemWrap.dataset.countChecked = countCheckedItems.toString();
|
1019
|
+
this.elemWrap.dataset.countCheckedFull = countCheckedFullItems.toString();
|
1020
|
+
if (this.isMulti) {
|
1021
|
+
this.elemWrap.dataset.checkAllMulti = this.$select.options.length === countCheckedItems ? 'yes' : 'no';
|
1022
|
+
}
|
1023
|
+
this.elemListBody.innerHTML = resBodyList;
|
1024
|
+
}
|
1025
|
+
}, {
|
1026
|
+
key: "createInputHTML",
|
1027
|
+
value: function createInputHTML() {
|
1028
|
+
var isSearch = this.options.isSearch;
|
1029
|
+
var isSearchInDropdown = this.options.isSearchInDropdown;
|
1030
|
+
if ('simpleSelectSearch' in this.$select.dataset) {
|
1031
|
+
isSearch = this.$select.dataset.simpleSelectSearch !== 'false';
|
1032
|
+
}
|
1033
|
+
if ('simpleSelectSearchDropdown' in this.$select.dataset) {
|
1034
|
+
isSearchInDropdown = this.$select.dataset.simpleSelectSearchDropdown !== 'false';
|
1035
|
+
}
|
1036
|
+
if (!isSearch && !isSearchInDropdown) {
|
1037
|
+
return;
|
1038
|
+
}
|
1039
|
+
this.elemInputSearch = document.createElement('input');
|
1040
|
+
this.elemInputSearch.type = 'text';
|
1041
|
+
this.elemInputSearch.tabIndex = -1;
|
1042
|
+
this.elemInputSearch.autocomplete = 'off';
|
1043
|
+
this.elemInputSearch.ariaAutoComplete = 'none';
|
1044
|
+
this.elemInputSearch.inputMode = 'off';
|
1045
|
+
this.elemInputSearch.placeholder = this.options.locale.searchText;
|
1046
|
+
this.elemInputSearch.name = "".concat(simpleSelection_const_1.initClass, "_name_").concat(this.id);
|
1047
|
+
var className = (0, simpleSelection_utils_1.getClass)('search');
|
1048
|
+
if (isSearchInDropdown) {
|
1049
|
+
if (this.elemDropDown) {
|
1050
|
+
this.elemInputSearch.className = "".concat(className, " ").concat((0, simpleSelection_utils_1.getClass)('dropdown', true, className));
|
1051
|
+
this.elemDropDown.prepend(this.elemInputSearch);
|
1052
|
+
}
|
1053
|
+
} else {
|
1054
|
+
this.elemInputSearch.className = "".concat(className, " ").concat((0, simpleSelection_utils_1.getClass)('top', true, className));
|
1055
|
+
this.elemTop.append(this.elemInputSearch);
|
1056
|
+
}
|
1057
|
+
this.inputSearchHandler();
|
1058
|
+
}
|
1059
|
+
}, {
|
1060
|
+
key: "getChecked",
|
1061
|
+
value: function getChecked() {
|
1062
|
+
var items = this.state.getState('items');
|
1063
|
+
var res = [];
|
1064
|
+
items.forEach(function (group) {
|
1065
|
+
res = [].concat(_toConsumableArray(res), _toConsumableArray(group.items.filter(function (i) {
|
1066
|
+
return i.checked;
|
1067
|
+
})));
|
1068
|
+
});
|
1069
|
+
return res;
|
1070
|
+
}
|
1071
|
+
}, {
|
1072
|
+
key: "createLi",
|
1073
|
+
value: function createLi(data) {
|
1074
|
+
var _this4 = this;
|
1075
|
+
var result = '';
|
1076
|
+
var countShow = 0;
|
1077
|
+
var countChecked = 0;
|
1078
|
+
var countCheckedFull = 0;
|
1079
|
+
if (!data.isShowFilter) {
|
1080
|
+
return {
|
1081
|
+
result: result,
|
1082
|
+
countShow: countShow,
|
1083
|
+
countChecked: countChecked,
|
1084
|
+
countCheckedFull: countCheckedFull
|
1085
|
+
};
|
1086
|
+
}
|
1087
|
+
if (data.isGroup) {
|
1088
|
+
result += "<label class=\"".concat((0, simpleSelection_utils_1.getClass)('group_title'), "\">").concat(data.titleGroup, "</label>");
|
1089
|
+
result += "<ul class=\"".concat((0, simpleSelection_utils_1.getClass)('group'), "\">");
|
1090
|
+
}
|
1091
|
+
data.items.forEach(function (option) {
|
1092
|
+
if (!option.isShowFilter) {
|
1093
|
+
return;
|
1094
|
+
}
|
1095
|
+
countShow++;
|
1096
|
+
var classLiInit = (0, simpleSelection_utils_1.getClass)('list_item');
|
1097
|
+
var classLi = classLiInit;
|
1098
|
+
if (option.checked) {
|
1099
|
+
countChecked++;
|
1100
|
+
classLi += " ".concat((0, simpleSelection_utils_1.getClass)('checked', true, classLiInit));
|
1101
|
+
if (option.value) {
|
1102
|
+
countCheckedFull++;
|
1103
|
+
}
|
1104
|
+
}
|
1105
|
+
if (option.disabled) {
|
1106
|
+
classLi += " ".concat((0, simpleSelection_utils_1.getClass)('disabled', true, classLiInit));
|
1107
|
+
}
|
1108
|
+
if (!option.value) {
|
1109
|
+
classLi += " ".concat((0, simpleSelection_utils_1.getClass)('not_value', true, classLiInit));
|
1110
|
+
}
|
1111
|
+
var dataAttr = "data-sel-group-id=\"".concat(data.idGroup, "\"");
|
1112
|
+
dataAttr += " data-sel-position=\"".concat(option.position, "\"");
|
1113
|
+
dataAttr += " data-sel-id=\"".concat(option.id, "\"");
|
1114
|
+
if (option.value) {
|
1115
|
+
dataAttr += " data-sel-value=\"".concat(option.value, "\"");
|
1116
|
+
}
|
1117
|
+
dataAttr += ' data-sel-opt-item';
|
1118
|
+
dataAttr += " data-sel-opt-checked=\"".concat(option.checked, "\"");
|
1119
|
+
dataAttr += " data-sel-opt-disabled=\"".concat(option.disabled, "\"");
|
1120
|
+
result += "<li class=\"".concat(classLi, "\" ").concat(dataAttr, ">");
|
1121
|
+
var createLiBodyRes = _this4.createLiBody(option, _this4.$select.options[option.position]);
|
1122
|
+
result += typeof createLiBodyRes === 'string' ? createLiBodyRes : createLiBodyRes.outerHTML;
|
1123
|
+
result += '</li>';
|
1124
|
+
});
|
1125
|
+
if (data.isGroup) {
|
1126
|
+
result += '</ul>';
|
1127
|
+
}
|
1128
|
+
return {
|
1129
|
+
result: result,
|
1130
|
+
countShow: countShow,
|
1131
|
+
countChecked: countChecked,
|
1132
|
+
countCheckedFull: countCheckedFull
|
1133
|
+
};
|
1134
|
+
}
|
1135
|
+
}, {
|
1136
|
+
key: "createLiBody",
|
1137
|
+
value: function createLiBody(option, optionNative) {
|
1138
|
+
var item = document.createElement('div');
|
1139
|
+
item.className = (0, simpleSelection_utils_1.getClass)('list_item_body');
|
1140
|
+
var res = '';
|
1141
|
+
if (this.isShowCheckbox) {
|
1142
|
+
res = "<span class=\"".concat((0, simpleSelection_utils_1.getClass)('list_item_icon'), "\"></span>");
|
1143
|
+
}
|
1144
|
+
if (this.bodyLiHTMLBeforeFromSelect) {
|
1145
|
+
res += this.bodyLiHTMLBeforeFromSelect;
|
1146
|
+
}
|
1147
|
+
if (optionNative.hasAttribute('data-simple-html-before')) {
|
1148
|
+
res += optionNative.getAttribute('data-simple-html-before');
|
1149
|
+
}
|
1150
|
+
res += "".concat(option.title);
|
1151
|
+
if (this.bodyLiHTMLAfterFromSelect) {
|
1152
|
+
res += this.bodyLiHTMLAfterFromSelect;
|
1153
|
+
}
|
1154
|
+
if (optionNative.hasAttribute('data-simple-html-after')) {
|
1155
|
+
res += optionNative.getAttribute('data-simple-html-after');
|
1156
|
+
}
|
1157
|
+
item.innerHTML = res;
|
1158
|
+
if (this.options.changeBodyLi) {
|
1159
|
+
return this.options.changeBodyLi(item, optionNative);
|
1160
|
+
}
|
1161
|
+
return item;
|
1162
|
+
}
|
1163
|
+
}, {
|
1164
|
+
key: "handlerChangeChecked",
|
1165
|
+
value: function handlerChangeChecked() {
|
1166
|
+
console.error('This method need redefine');
|
1167
|
+
}
|
1168
|
+
// only desktop
|
1169
|
+
}, {
|
1170
|
+
key: "createList",
|
1171
|
+
value: function createList(_isCompare) {
|
1172
|
+
console.error('This method need redefine');
|
1173
|
+
}
|
1174
|
+
// only desktop
|
1175
|
+
}, {
|
1176
|
+
key: "inputSearchHandler",
|
1177
|
+
value: function inputSearchHandler() {
|
1178
|
+
console.error('This method need redefine');
|
1179
|
+
}
|
1180
|
+
}]);
|
1181
|
+
return SimpleSelectItemDOM;
|
1182
|
+
}();
|
1183
|
+
exports.SimpleSelectItemDOM = SimpleSelectItemDOM;
|
1184
|
+
|
1185
|
+
/***/ }),
|
1186
|
+
|
1187
|
+
/***/ 679:
|
1188
|
+
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
1189
|
+
|
1190
|
+
|
1191
|
+
|
1192
|
+
Object.defineProperty(exports, "__esModule", ({
|
1193
|
+
value: true
|
1194
|
+
}));
|
1195
|
+
exports.createButton = exports.cloneObj = exports.compareObj = exports.getClass = exports.getCreateListItem = exports.triggerInputEvent = exports.ifTrueDataAttr = exports.createDataAttr = exports.toCamelCase = void 0;
|
1196
|
+
var simpleSelection_const_1 = __webpack_require__(737);
|
1197
|
+
var toCamelCase = function toCamelCase(input) {
|
1198
|
+
return input.replace(/-([a-z])/g, function (_, letter) {
|
1199
|
+
return letter.toUpperCase();
|
1200
|
+
});
|
1201
|
+
};
|
1202
|
+
exports.toCamelCase = toCamelCase;
|
1203
|
+
var createDataAttr = function createDataAttr(name) {
|
1204
|
+
return "data-".concat(name);
|
1205
|
+
};
|
1206
|
+
exports.createDataAttr = createDataAttr;
|
1207
|
+
var ifTrueDataAttr = function ifTrueDataAttr(attr) {
|
1208
|
+
if (!attr) {
|
1209
|
+
return false;
|
1210
|
+
}
|
1211
|
+
return attr === 'true' || attr === '1';
|
1212
|
+
};
|
1213
|
+
exports.ifTrueDataAttr = ifTrueDataAttr;
|
1214
|
+
function triggerInputEvent(element) {
|
1215
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'change';
|
1216
|
+
var event = new Event(type, {
|
1217
|
+
bubbles: true,
|
1218
|
+
cancelable: true
|
1219
|
+
});
|
1220
|
+
element.dispatchEvent(event);
|
1221
|
+
}
|
1222
|
+
exports.triggerInputEvent = triggerInputEvent;
|
1223
|
+
var getCreateListItem = function getCreateListItem(item, idGroup, isGroup) {
|
1224
|
+
var options = item.querySelectorAll('option');
|
1225
|
+
var items = [];
|
1226
|
+
options.forEach(function (option, ind) {
|
1227
|
+
items.push({
|
1228
|
+
id: (ind + 1).toString(),
|
1229
|
+
position: option.index,
|
1230
|
+
title: option.innerHTML,
|
1231
|
+
// value: option.value,
|
1232
|
+
value: option.getAttribute('value'),
|
1233
|
+
checked: option.selected,
|
1234
|
+
disabled: option.disabled,
|
1235
|
+
isShowFilter: true
|
1236
|
+
});
|
1237
|
+
});
|
1238
|
+
var newItem = {
|
1239
|
+
isGroup: isGroup,
|
1240
|
+
idGroup: idGroup,
|
1241
|
+
items: items,
|
1242
|
+
isShowFilter: true
|
1243
|
+
};
|
1244
|
+
if (item instanceof HTMLOptGroupElement) {
|
1245
|
+
newItem.titleGroup = item.label || '';
|
1246
|
+
newItem.isDisabledGroup = item.disabled || false;
|
1247
|
+
}
|
1248
|
+
return newItem;
|
1249
|
+
};
|
1250
|
+
exports.getCreateListItem = getCreateListItem;
|
1251
|
+
var getClass = function getClass(cls) {
|
1252
|
+
var mod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
1253
|
+
var classInit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : simpleSelection_const_1.initClass;
|
1254
|
+
var sep = mod ? '--' : '__';
|
1255
|
+
return "".concat(classInit).concat(sep).concat(cls);
|
1256
|
+
};
|
1257
|
+
exports.getClass = getClass;
|
1258
|
+
var compareObj = function compareObj(obj1, obj2) {
|
1259
|
+
return JSON.stringify(obj1) === JSON.stringify(obj2);
|
1260
|
+
};
|
1261
|
+
exports.compareObj = compareObj;
|
1262
|
+
var cloneObj = function cloneObj(obj) {
|
1263
|
+
return JSON.parse(JSON.stringify(obj));
|
1264
|
+
};
|
1265
|
+
exports.cloneObj = cloneObj;
|
1266
|
+
var createButton = function createButton() {
|
1267
|
+
var btn = document.createElement('button');
|
1268
|
+
btn.type = 'button';
|
1269
|
+
btn.tabIndex = -1;
|
1270
|
+
return btn;
|
1271
|
+
};
|
1272
|
+
exports.createButton = createButton;
|
1273
|
+
|
1274
|
+
/***/ }),
|
1275
|
+
|
1276
|
+
/***/ 972:
|
1277
|
+
/***/ (function(__unused_webpack_module, exports) {
|
1278
|
+
|
1279
|
+
|
1280
|
+
|
1281
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
1282
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
1283
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
1284
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
1285
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
1286
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
1287
|
+
Object.defineProperty(exports, "__esModule", ({
|
1288
|
+
value: true
|
1289
|
+
}));
|
1290
|
+
exports.store = void 0;
|
1291
|
+
function store(obj) {
|
1292
|
+
var stateData = {};
|
1293
|
+
var subscribers = {}; /** подписка на конкретное свойство */
|
1294
|
+
var subscribersAll = []; /** подписка на все свойства */
|
1295
|
+
var getState = function getState(k) {
|
1296
|
+
if (!k) {
|
1297
|
+
return stateData;
|
1298
|
+
}
|
1299
|
+
if (!(k in stateData)) {
|
1300
|
+
return null;
|
1301
|
+
}
|
1302
|
+
return stateData[k];
|
1303
|
+
};
|
1304
|
+
var setState = function setState(k, val) {
|
1305
|
+
var prevState = _objectSpread({}, stateData);
|
1306
|
+
var prev = stateData[k] || stateData[k] == 0 ? stateData[k] : null;
|
1307
|
+
stateData[k] = val;
|
1308
|
+
if (k in subscribers) {
|
1309
|
+
subscribers[k].forEach(function (cb) {
|
1310
|
+
return cb(val, prev, stateData);
|
1311
|
+
});
|
1312
|
+
}
|
1313
|
+
subscribersAll.forEach(function (cb) {
|
1314
|
+
return cb(k, prevState, stateData);
|
1315
|
+
});
|
1316
|
+
};
|
1317
|
+
if (obj) {
|
1318
|
+
Object.keys(obj).forEach(function (k) {
|
1319
|
+
// @ts-ignore
|
1320
|
+
setState(k, obj[k]);
|
1321
|
+
});
|
1322
|
+
}
|
1323
|
+
return {
|
1324
|
+
getState: getState,
|
1325
|
+
setState: setState,
|
1326
|
+
subscribe: function subscribe(k, cb) {
|
1327
|
+
if (!(k in subscribers)) {
|
1328
|
+
subscribers[k] = [];
|
1329
|
+
}
|
1330
|
+
subscribers[k].push(cb);
|
1331
|
+
var cur = getState(k);
|
1332
|
+
cb(cur, null, getState());
|
1333
|
+
return function () {
|
1334
|
+
subscribers[k] = subscribers[k].filter(function (i) {
|
1335
|
+
return i !== cb;
|
1336
|
+
});
|
1337
|
+
};
|
1338
|
+
},
|
1339
|
+
subscribeAll: function subscribeAll(cb) {
|
1340
|
+
subscribersAll.push(cb);
|
1341
|
+
cb(null, null, getState());
|
1342
|
+
return function () {
|
1343
|
+
subscribersAll = subscribersAll.filter(function (i) {
|
1344
|
+
return i !== cb;
|
1345
|
+
});
|
1346
|
+
};
|
1347
|
+
},
|
1348
|
+
unSubscribe: function unSubscribe(k, cb) {
|
1349
|
+
if (k in subscribers) {
|
1350
|
+
subscribers[k] = subscribers[k].filter(function (i) {
|
1351
|
+
return i !== cb;
|
1352
|
+
});
|
1353
|
+
}
|
1354
|
+
}
|
1355
|
+
};
|
1356
|
+
}
|
1357
|
+
exports.store = store;
|
1358
|
+
|
1359
|
+
/***/ }),
|
1360
|
+
|
1361
|
+
/***/ 181:
|
1362
|
+
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
1363
|
+
|
1364
|
+
__webpack_require__.r(__webpack_exports__);
|
1365
|
+
// extracted by mini-css-extract-plugin
|
1366
|
+
|
1367
|
+
|
1368
|
+
/***/ })
|
1369
|
+
|
1370
|
+
/******/ });
|
1371
|
+
/************************************************************************/
|
1372
|
+
/******/ // The module cache
|
1373
|
+
/******/ var __webpack_module_cache__ = {};
|
1374
|
+
/******/
|
1375
|
+
/******/ // The require function
|
1376
|
+
/******/ function __webpack_require__(moduleId) {
|
1377
|
+
/******/ // Check if module is in cache
|
1378
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
1379
|
+
/******/ if (cachedModule !== undefined) {
|
1380
|
+
/******/ return cachedModule.exports;
|
1381
|
+
/******/ }
|
1382
|
+
/******/ // Create a new module (and put it into the cache)
|
1383
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
1384
|
+
/******/ // no module.id needed
|
1385
|
+
/******/ // no module.loaded needed
|
1386
|
+
/******/ exports: {}
|
1387
|
+
/******/ };
|
1388
|
+
/******/
|
1389
|
+
/******/ // Execute the module function
|
1390
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
1391
|
+
/******/
|
1392
|
+
/******/ // Return the exports of the module
|
1393
|
+
/******/ return module.exports;
|
1394
|
+
/******/ }
|
1395
|
+
/******/
|
1396
|
+
/************************************************************************/
|
1397
|
+
/******/ /* webpack/runtime/make namespace object */
|
1398
|
+
/******/ !function() {
|
1399
|
+
/******/ // define __esModule on exports
|
1400
|
+
/******/ __webpack_require__.r = function(exports) {
|
1401
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
1402
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
1403
|
+
/******/ }
|
1404
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
1405
|
+
/******/ };
|
1406
|
+
/******/ }();
|
1407
|
+
/******/
|
1408
|
+
/************************************************************************/
|
1409
|
+
var __webpack_exports__ = {};
|
1410
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
1411
|
+
!function() {
|
1412
|
+
var exports = __webpack_exports__;
|
1413
|
+
var __webpack_unused_export__;
|
1414
|
+
|
1415
|
+
|
1416
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
1417
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
1418
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
1419
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1420
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
1421
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
1422
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
1423
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
1424
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
1425
|
+
__webpack_unused_export__ = ({
|
1426
|
+
value: true
|
1427
|
+
});
|
1428
|
+
var simpleSelection_const_1 = __webpack_require__(737);
|
1429
|
+
var simpleSelection_utils_1 = __webpack_require__(679);
|
1430
|
+
var simpleSelectItem_1 = __webpack_require__(874);
|
1431
|
+
__webpack_require__(181);
|
1432
|
+
var SimpleSelect = /*#__PURE__*/function () {
|
1433
|
+
function SimpleSelect(selector, options) {
|
1434
|
+
_classCallCheck(this, SimpleSelect);
|
1435
|
+
_defineProperty(this, "callCount", Date.now());
|
1436
|
+
_defineProperty(this, "countInit", 0);
|
1437
|
+
// $selects: HTMLSelectElement[] = [];
|
1438
|
+
_defineProperty(this, "$selects", []);
|
1439
|
+
_defineProperty(this, "options", void 0);
|
1440
|
+
_defineProperty(this, "nameMarkTransform", (0, simpleSelection_utils_1.toCamelCase)(simpleSelection_const_1.nameMark));
|
1441
|
+
_defineProperty(this, "dataNameMark", (0, simpleSelection_utils_1.createDataAttr)(simpleSelection_const_1.nameMark));
|
1442
|
+
_defineProperty(this, "isNative", void 0);
|
1443
|
+
if (!selector) {
|
1444
|
+
selector = 'select';
|
1445
|
+
}
|
1446
|
+
// this.$selects = Array.from(document.querySelectorAll(selector));
|
1447
|
+
this.options = _objectSpread(_objectSpread({}, simpleSelection_const_1.simpleSelectionOptions), options);
|
1448
|
+
if (typeof selector === 'string') {
|
1449
|
+
this.init(Array.from(document.querySelectorAll(selector)));
|
1450
|
+
} else if (selector instanceof HTMLSelectElement) {
|
1451
|
+
this.init([selector]);
|
1452
|
+
} else if (selector instanceof NodeList) {
|
1453
|
+
this.init(Array.from(selector));
|
1454
|
+
} else if (Array.isArray(selector)) {
|
1455
|
+
this.init(selector);
|
1456
|
+
} else {
|
1457
|
+
console.warn('Wrong selector: ', selector);
|
1458
|
+
}
|
1459
|
+
}
|
1460
|
+
_createClass(SimpleSelect, [{
|
1461
|
+
key: "detectMobile",
|
1462
|
+
value: function detectMobile() {
|
1463
|
+
if (this.options.detectNative) {
|
1464
|
+
this.isNative = this.options.detectNative();
|
1465
|
+
return;
|
1466
|
+
}
|
1467
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
1468
|
+
// @ts-ignore
|
1469
|
+
var ua = navigator.userAgent || navigator.vendor || window.opera;
|
1470
|
+
var res = false;
|
1471
|
+
// Checks for iOs, Android, Blackberry, Opera Mini, and Windows mobile devices
|
1472
|
+
for (var i = 0; i < this.options.nativeOnDevice.length; i++) {
|
1473
|
+
if (ua.toString().toLowerCase().indexOf(this.options.nativeOnDevice[i].toLowerCase()) > 0) {
|
1474
|
+
if (this.options.nativeOnDevice[i]) {
|
1475
|
+
res = true;
|
1476
|
+
}
|
1477
|
+
}
|
1478
|
+
}
|
1479
|
+
this.isNative = res;
|
1480
|
+
}
|
1481
|
+
}, {
|
1482
|
+
key: "init",
|
1483
|
+
value: function init(selects) {
|
1484
|
+
var _this = this;
|
1485
|
+
this.detectMobile();
|
1486
|
+
selects.forEach(function ($select) {
|
1487
|
+
_this.build($select);
|
1488
|
+
});
|
1489
|
+
}
|
1490
|
+
}, {
|
1491
|
+
key: "createMethods",
|
1492
|
+
value: function createMethods(select) {
|
1493
|
+
var self = this;
|
1494
|
+
return {
|
1495
|
+
getInstance: function getInstance() {
|
1496
|
+
return select.getSelect();
|
1497
|
+
},
|
1498
|
+
reload: function reload() {
|
1499
|
+
self.rebuild(select);
|
1500
|
+
},
|
1501
|
+
update: function update() {
|
1502
|
+
select.updateHTML();
|
1503
|
+
},
|
1504
|
+
detach: function detach() {
|
1505
|
+
self.detach(select);
|
1506
|
+
}
|
1507
|
+
};
|
1508
|
+
}
|
1509
|
+
}, {
|
1510
|
+
key: "setMethods",
|
1511
|
+
value: function setMethods(select) {
|
1512
|
+
// @ts-ignore
|
1513
|
+
select.$select[simpleSelection_const_1.nameSelect] = this.createMethods(select);
|
1514
|
+
}
|
1515
|
+
}, {
|
1516
|
+
key: "setMethodsClear",
|
1517
|
+
value: function setMethodsClear(select) {
|
1518
|
+
// @ts-ignore
|
1519
|
+
delete select.$select[simpleSelection_const_1.nameSelect];
|
1520
|
+
}
|
1521
|
+
}, {
|
1522
|
+
key: "build",
|
1523
|
+
value: function build(select) {
|
1524
|
+
var isProcessed = (this.nameMarkTransform in select.dataset);
|
1525
|
+
if (isProcessed) {
|
1526
|
+
console.warn('This element has already been initialized', select);
|
1527
|
+
return;
|
1528
|
+
}
|
1529
|
+
this.countInit += 1;
|
1530
|
+
var id = "".concat(this.callCount, "-").concat(this.countInit);
|
1531
|
+
select.setAttribute(this.dataNameMark, id);
|
1532
|
+
// this.$selects.push(select);
|
1533
|
+
var newSelect = new simpleSelectItem_1.SimpleSelectItem(select, this.options, {
|
1534
|
+
id: id,
|
1535
|
+
isNative: this.isNative
|
1536
|
+
});
|
1537
|
+
this.$selects.push(newSelect);
|
1538
|
+
this.setMethods(newSelect);
|
1539
|
+
}
|
1540
|
+
}, {
|
1541
|
+
key: "detach",
|
1542
|
+
value: function detach(itemSelect) {
|
1543
|
+
itemSelect.detachItem();
|
1544
|
+
itemSelect.$select.removeAttribute(this.dataNameMark);
|
1545
|
+
this.setMethodsClear(itemSelect);
|
1546
|
+
this.$selects = this.$selects.filter(function (item) {
|
1547
|
+
return item !== itemSelect;
|
1548
|
+
});
|
1549
|
+
}
|
1550
|
+
}, {
|
1551
|
+
key: "rebuild",
|
1552
|
+
value: function rebuild(selectsItems) {
|
1553
|
+
var select = selectsItems.$select;
|
1554
|
+
this.detach(selectsItems);
|
1555
|
+
this.build(select);
|
1556
|
+
}
|
1557
|
+
}, {
|
1558
|
+
key: "getSelects",
|
1559
|
+
value: function getSelects() {
|
1560
|
+
return this.$selects;
|
1561
|
+
}
|
1562
|
+
}, {
|
1563
|
+
key: "getSelectFirst",
|
1564
|
+
value: function getSelectFirst() {
|
1565
|
+
// return this.$selects[0];
|
1566
|
+
return this.createMethods(this.$selects[0]);
|
1567
|
+
}
|
1568
|
+
}, {
|
1569
|
+
key: "getSelectById",
|
1570
|
+
value: function getSelectById(id) {
|
1571
|
+
var search = this.$selects.filter(function (item) {
|
1572
|
+
return item.id === id;
|
1573
|
+
})[0];
|
1574
|
+
if (!search) {
|
1575
|
+
return null;
|
1576
|
+
}
|
1577
|
+
return this.createMethods(search);
|
1578
|
+
}
|
1579
|
+
}]);
|
1580
|
+
return SimpleSelect;
|
1581
|
+
}();
|
1582
|
+
exports["default"] = SimpleSelect;
|
1583
|
+
}();
|
1584
|
+
__webpack_exports__ = __webpack_exports__["default"];
|
1585
|
+
/******/ return __webpack_exports__;
|
1586
|
+
/******/ })()
|
1587
|
+
;
|
1588
|
+
});
|