| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
/******/ "use strict"; |
| 3 |
/******/ var __webpack_modules__ = ({ |
| 4 |
|
| 5 |
/***/ "./assets/src/js/admin/init-tom-select.js" |
| 6 |
/*!************************************************!*\ |
| 7 |
!*** ./assets/src/js/admin/init-tom-select.js ***! |
| 8 |
\************************************************/ |
| 9 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 10 |
|
| 11 |
__webpack_require__.r(__webpack_exports__); |
| 12 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 13 |
/* harmony export */ initElsTomSelect: () => (/* binding */ initElsTomSelect), |
| 14 |
/* harmony export */ initTomSelect: () => (/* binding */ initTomSelect), |
| 15 |
/* harmony export */ searchUserOnListPost: () => (/* binding */ searchUserOnListPost) |
| 16 |
/* harmony export */ }); |
| 17 |
/* harmony import */ var _utils_admin_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils-admin.js */ "./assets/src/js/admin/utils-admin.js"); |
| 18 |
|
| 19 |
|
| 20 |
/** |
| 21 |
* Handle data response from API for tom-select |
| 22 |
* |
| 23 |
* @param {*} response |
| 24 |
* @param {*} tomSelectEl |
| 25 |
* @param dataStruct |
| 26 |
* @param fetchAPI |
| 27 |
* @param customOptions |
| 28 |
* @param {*} callBack |
| 29 |
*/ |
| 30 |
const handleResponse = (response, tomSelectEl, dataStruct, fetchAPI, customOptions = {}, callBack) => { |
| 31 |
if (!response || !tomSelectEl || !dataStruct || !fetchAPI || !callBack) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
//Function format render data |
| 36 |
const getTextOption = data => { |
| 37 |
if (!dataStruct.keyGetValue?.text || !dataStruct.keyGetValue.key_render) { |
| 38 |
return; |
| 39 |
} |
| 40 |
let text = dataStruct.keyGetValue.text; |
| 41 |
for (const [key, value] of Object.entries(dataStruct.keyGetValue.key_render)) { |
| 42 |
text = text.replace(new RegExp(`{{${value}}}`, 'g'), data[value]); |
| 43 |
} |
| 44 |
return text; |
| 45 |
}; |
| 46 |
|
| 47 |
// Get default item tom-select |
| 48 |
const defaultIds = tomSelectEl.dataset?.saved ? JSON.parse(tomSelectEl.dataset.saved) : 0; |
| 49 |
let options = []; |
| 50 |
|
| 51 |
// Format response data set option tom-select |
| 52 |
if (response.data[dataStruct.dataType].length > 0) { |
| 53 |
options = response.data[dataStruct.dataType].map(item => ({ |
| 54 |
value: item[dataStruct.keyGetValue.value], |
| 55 |
text: getTextOption(item) |
| 56 |
})); |
| 57 |
} |
| 58 |
|
| 59 |
// Setting option tom-select |
| 60 |
const settingOption = { |
| 61 |
items: defaultIds, |
| 62 |
render: { |
| 63 |
item(data, escape) { |
| 64 |
return `` + `<li data-id="${data.value}"> |
| 65 |
<div class="item">${data.text}</div> |
| 66 |
</li>`; |
| 67 |
} |
| 68 |
}, |
| 69 |
onChange: data => { |
| 70 |
if (data.length < 1) { |
| 71 |
tomSelectEl.value = ''; |
| 72 |
} |
| 73 |
}, |
| 74 |
...customOptions, |
| 75 |
options |
| 76 |
}; |
| 77 |
if (null != tomSelectEl.tomSelectInstance) { |
| 78 |
tomSelectEl.tomSelectInstance.addOptions(options); |
| 79 |
return options; |
| 80 |
} |
| 81 |
tomSelectEl.tomSelectInstance = _utils_admin_js__WEBPACK_IMPORTED_MODULE_0__.AdminUtilsFunctions.buildTomSelect(tomSelectEl, settingOption, fetchAPI, {}, callBack); |
| 82 |
return options; |
| 83 |
}; |
| 84 |
|
| 85 |
//Init Tom-select with available options |
| 86 |
const initTomSelectWithOption = (tomSelectEl, settingTomSelect = {}) => { |
| 87 |
if (!tomSelectEl) { |
| 88 |
return null; |
| 89 |
} |
| 90 |
if (null != tomSelectEl.tomSelectInstance) { |
| 91 |
return null; |
| 92 |
} |
| 93 |
tomSelectEl.tomSelectInstance = _utils_admin_js__WEBPACK_IMPORTED_MODULE_0__.AdminUtilsFunctions.buildTomSelect(tomSelectEl, settingTomSelect); |
| 94 |
}; |
| 95 |
|
| 96 |
// Init Tom-select |
| 97 |
const initTomSelect = (tomSelectEl, customOptions = {}, customParams = {}) => { |
| 98 |
var _dataStruct$dataSendA, _dataStruct$urlApi; |
| 99 |
if (!tomSelectEl) { |
| 100 |
return; |
| 101 |
} |
| 102 |
if (tomSelectEl.classList.contains('loaded')) { |
| 103 |
return; |
| 104 |
} |
| 105 |
tomSelectEl.classList.add('loaded'); |
| 106 |
const defaultIds = tomSelectEl.dataset?.saved ? JSON.parse(tomSelectEl.dataset.saved) : 0; |
| 107 |
const dataStruct = tomSelectEl?.dataset?.struct ? JSON.parse(tomSelectEl.dataset.struct) : ''; |
| 108 |
if (!dataStruct) { |
| 109 |
initTomSelectWithOption(tomSelectEl); |
| 110 |
return; |
| 111 |
} |
| 112 |
const getParentElByTagName = (tag, el) => { |
| 113 |
const newEl = el.parentElement; |
| 114 |
if (newEl.tagName.toLowerCase() === tag) { |
| 115 |
return newEl; |
| 116 |
} |
| 117 |
if (newEl.tagName.toLowerCase() === 'html') { |
| 118 |
return false; |
| 119 |
} |
| 120 |
return getParentElByTagName(tag, newEl); |
| 121 |
}; |
| 122 |
const formParent = getParentElByTagName('form', tomSelectEl); |
| 123 |
if (formParent) { |
| 124 |
const elInput = formParent.querySelector('input[name="' + tomSelectEl.getAttribute('name') + '"]'); |
| 125 |
if (elInput) { |
| 126 |
elInput.remove(); |
| 127 |
} |
| 128 |
} |
| 129 |
const dataSendApi = (_dataStruct$dataSendA = dataStruct.dataSendApi) !== null && _dataStruct$dataSendA !== void 0 ? _dataStruct$dataSendA : ''; |
| 130 |
const urlApi = (_dataStruct$urlApi = dataStruct.urlApi) !== null && _dataStruct$urlApi !== void 0 ? _dataStruct$urlApi : ''; |
| 131 |
const settingTomSelect = { |
| 132 |
...dataStruct.setting, |
| 133 |
...customOptions |
| 134 |
}; |
| 135 |
if (!urlApi) { |
| 136 |
initTomSelectWithOption(tomSelectEl, settingTomSelect); |
| 137 |
return; |
| 138 |
} |
| 139 |
const fetchFunction = (keySearch = '', customParams, callback) => { |
| 140 |
const url = urlApi; |
| 141 |
const dataSend = { |
| 142 |
current_ids: defaultIds, |
| 143 |
...dataSendApi, |
| 144 |
...customParams |
| 145 |
}; |
| 146 |
dataSend.search = keySearch; |
| 147 |
const params = { |
| 148 |
headers: { |
| 149 |
'Content-Type': 'application/json', |
| 150 |
'X-WP-Nonce': lpData.nonce |
| 151 |
}, |
| 152 |
method: 'POST', |
| 153 |
body: JSON.stringify(dataSend) |
| 154 |
}; |
| 155 |
_utils_admin_js__WEBPACK_IMPORTED_MODULE_0__.Utils.lpFetchAPI(url, params, callback); |
| 156 |
}; |
| 157 |
const callBackApi = { |
| 158 |
success: response => { |
| 159 |
handleResponse(response, tomSelectEl, dataStruct, fetchFunction, settingTomSelect, callBackApi); |
| 160 |
} |
| 161 |
}; |
| 162 |
|
| 163 |
// Fetch data for first load tom-select |
| 164 |
// Get ids selected, and show list without ids selected with limit. |
| 165 |
let idNotIn = []; |
| 166 |
if (typeof defaultIds === 'object') { |
| 167 |
idNotIn = Object.entries(defaultIds).map(([key, value]) => ({ |
| 168 |
key, |
| 169 |
value |
| 170 |
})); |
| 171 |
} |
| 172 |
if (dataSendApi?.id_not_in) { |
| 173 |
idNotIn = [...idNotIn, ...dataSendApi.id_not_in]; |
| 174 |
} |
| 175 |
customParams.id_not_in = idNotIn.join(','); |
| 176 |
fetchFunction('', customParams, callBackApi); |
| 177 |
}; |
| 178 |
|
| 179 |
// Init Tom-select user in admin |
| 180 |
const searchUserOnListPost = () => { |
| 181 |
if (lpData.show_search_author_field === '0') { |
| 182 |
return; |
| 183 |
} |
| 184 |
const elPostFilter = document.querySelector('#posts-filter'); |
| 185 |
if (!elPostFilter) { |
| 186 |
return; |
| 187 |
} |
| 188 |
let elSearchPost = elPostFilter.querySelector('.search-box'); |
| 189 |
if (!elSearchPost) { |
| 190 |
elPostFilter.insertAdjacentHTML('afterbegin', lpData.show_search_author_field); |
| 191 |
elSearchPost = elPostFilter.querySelector('.search-box'); |
| 192 |
} |
| 193 |
if (!elSearchPost) { |
| 194 |
return; |
| 195 |
} |
| 196 |
const selectNew = elSearchPost.querySelector('select#author'); |
| 197 |
if (selectNew) { |
| 198 |
return; |
| 199 |
} |
| 200 |
const createSelectUserHtml = () => { |
| 201 |
let defaultId = ''; |
| 202 |
const authorIdFilter = lpData.urlParams.author; |
| 203 |
if (authorIdFilter) { |
| 204 |
defaultId = JSON.stringify(authorIdFilter); |
| 205 |
} |
| 206 |
const dataStruct = { |
| 207 |
urlApi: _utils_admin_js__WEBPACK_IMPORTED_MODULE_0__.Api.admin.apiSearchUsers, |
| 208 |
dataType: 'users', |
| 209 |
keyGetValue: { |
| 210 |
value: 'ID', |
| 211 |
text: '{{display_name}}(#{{ID}}) - {{user_email}}', |
| 212 |
key_render: { |
| 213 |
display_name: 'display_name', |
| 214 |
user_email: 'user_email', |
| 215 |
ID: 'ID' |
| 216 |
} |
| 217 |
}, |
| 218 |
setting: { |
| 219 |
placeholder: 'Choose user' |
| 220 |
} |
| 221 |
}; |
| 222 |
const dataStructJson = JSON.stringify(dataStruct); |
| 223 |
const htmlSelectUser = `` + `<select data-struct='${dataStructJson}' style='display:none;' data-saved='${defaultId}' |
| 224 |
id="author" name="author" class="select lp-tom-select">` + `</select>`; |
| 225 |
const elInputSearch = elSearchPost.querySelector('input[name="s"]'); |
| 226 |
if (elInputSearch) { |
| 227 |
elInputSearch.insertAdjacentHTML('afterend', htmlSelectUser); |
| 228 |
} |
| 229 |
|
| 230 |
// Remove input hide default of WP. |
| 231 |
const elInputAuthor = elPostFilter.querySelector('input[name="author"]'); |
| 232 |
if (elInputAuthor) { |
| 233 |
elInputAuthor.remove(); |
| 234 |
} |
| 235 |
}; |
| 236 |
createSelectUserHtml(); |
| 237 |
}; |
| 238 |
const initElsTomSelect = () => { |
| 239 |
const tomSelectEls = document.querySelectorAll('select.lp-tom-select:not(.loaded)'); |
| 240 |
if (tomSelectEls.length) { |
| 241 |
tomSelectEls.forEach(tomSelectEl => { |
| 242 |
// Not build elements tom-select in Widget left classic of WordPress. |
| 243 |
if (tomSelectEl.closest('.widget-liquid-left')) { |
| 244 |
return; |
| 245 |
} |
| 246 |
initTomSelect(tomSelectEl); |
| 247 |
}); |
| 248 |
} |
| 249 |
}; |
| 250 |
|
| 251 |
|
| 252 |
/***/ }, |
| 253 |
|
| 254 |
/***/ "./assets/src/js/admin/utils-admin.js" |
| 255 |
/*!********************************************!*\ |
| 256 |
!*** ./assets/src/js/admin/utils-admin.js ***! |
| 257 |
\********************************************/ |
| 258 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 259 |
|
| 260 |
__webpack_require__.r(__webpack_exports__); |
| 261 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 262 |
/* harmony export */ AdminUtilsFunctions: () => (/* binding */ AdminUtilsFunctions), |
| 263 |
/* harmony export */ Api: () => (/* reexport safe */ _api_js__WEBPACK_IMPORTED_MODULE_2__["default"]), |
| 264 |
/* harmony export */ Utils: () => (/* reexport module object */ _utils_js__WEBPACK_IMPORTED_MODULE_0__) |
| 265 |
/* harmony export */ }); |
| 266 |
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils.js */ "./assets/src/js/utils.js"); |
| 267 |
/* harmony import */ var tom_select__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! tom-select */ "./node_modules/tom-select/dist/esm/tom-select.complete.js"); |
| 268 |
/* harmony import */ var _api_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../api.js */ "./assets/src/js/api.js"); |
| 269 |
/** |
| 270 |
* Library run on Admin |
| 271 |
* |
| 272 |
* @since 4.2.6.9 |
| 273 |
* @version 1.0.1 |
| 274 |
*/ |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
const AdminUtilsFunctions = { |
| 279 |
buildTomSelect(elTomSelect, options, fetchAPI, dataSend, callBackHandleData) { |
| 280 |
if (!elTomSelect) { |
| 281 |
return; |
| 282 |
} |
| 283 |
const optionDefault = { |
| 284 |
plugins: { |
| 285 |
remove_button: { |
| 286 |
title: 'Remove this item' |
| 287 |
}, |
| 288 |
dropdown_input: {} |
| 289 |
}, |
| 290 |
onInitialize() {}, |
| 291 |
onItemAdd(e) { |
| 292 |
// Get list without current item. |
| 293 |
if (fetchAPI) { |
| 294 |
const selectedOptions = Array.from(elTomSelect.selectedOptions); |
| 295 |
const selectedValues = selectedOptions.map(option => option.value); |
| 296 |
selectedValues.push(e); |
| 297 |
dataSend.id_not_in = selectedValues.join(','); |
| 298 |
fetchAPI('', dataSend, callBackHandleData); |
| 299 |
} |
| 300 |
} |
| 301 |
}; |
| 302 |
if (fetchAPI) { |
| 303 |
optionDefault.load = (keySearch, callbackTom) => { |
| 304 |
const selectedOptions = Array.from(elTomSelect.selectedOptions); |
| 305 |
const selectedValues = selectedOptions.map(option => option.value); |
| 306 |
dataSend.id_not_in = selectedValues.join(','); |
| 307 |
fetchAPI(keySearch, dataSend, AdminUtilsFunctions.callBackTomSelectSearchAPI(callbackTom, callBackHandleData)); |
| 308 |
}; |
| 309 |
} |
| 310 |
options = { |
| 311 |
...optionDefault, |
| 312 |
...options |
| 313 |
}; |
| 314 |
const items_selected = options.options; |
| 315 |
/*if ( options?.options?.length > 20 ) { |
| 316 |
const chunkSize = 20; |
| 317 |
const length = options.options.length; |
| 318 |
let i = 0; |
| 319 |
const chunkedOptions = { ...options }; |
| 320 |
chunkedOptions.options = items_selected.slice( i, chunkSize ); |
| 321 |
const tomSelect = new TomSelect( elTomSelect, chunkedOptions ); |
| 322 |
i += chunkSize; |
| 323 |
const interval = setInterval( () => { |
| 324 |
if ( i > ( length - 1 ) ) { |
| 325 |
clearInterval( interval ); |
| 326 |
} |
| 327 |
const optionsSlice = items_selected.slice( i, i + chunkSize ); |
| 328 |
i += chunkSize; |
| 329 |
tomSelect.addOptions( optionsSlice ); |
| 330 |
tomSelect.setValue( options.items ); |
| 331 |
}, 200 ); |
| 332 |
return tomSelect; |
| 333 |
}*/ |
| 334 |
|
| 335 |
return new tom_select__WEBPACK_IMPORTED_MODULE_1__["default"](elTomSelect, options); |
| 336 |
}, |
| 337 |
callBackTomSelectSearchAPI(callbackTom, callBackHandleData) { |
| 338 |
return { |
| 339 |
success: response => { |
| 340 |
const options = callBackHandleData.success(response); |
| 341 |
callbackTom(options); |
| 342 |
} |
| 343 |
}; |
| 344 |
}, |
| 345 |
fetchCourses(keySearch = '', dataSend = {}, callback) { |
| 346 |
const url = _api_js__WEBPACK_IMPORTED_MODULE_2__["default"].admin.apiSearchCourses; |
| 347 |
dataSend.search = keySearch; |
| 348 |
const params = { |
| 349 |
headers: { |
| 350 |
'Content-Type': 'application/json', |
| 351 |
'X-WP-Nonce': lpDataAdmin.nonce |
| 352 |
}, |
| 353 |
method: 'POST', |
| 354 |
body: JSON.stringify(dataSend) |
| 355 |
}; |
| 356 |
_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI(url, params, callback); |
| 357 |
}, |
| 358 |
fetchUsers(keySearch = '', dataSend = {}, callback) { |
| 359 |
const url = _api_js__WEBPACK_IMPORTED_MODULE_2__["default"].admin.apiSearchUsers; |
| 360 |
dataSend.search = keySearch; |
| 361 |
const params = { |
| 362 |
headers: { |
| 363 |
'Content-Type': 'application/json', |
| 364 |
'X-WP-Nonce': lpDataAdmin.nonce |
| 365 |
}, |
| 366 |
method: 'POST', |
| 367 |
body: JSON.stringify(dataSend) |
| 368 |
}; |
| 369 |
_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI(url, params, callback); |
| 370 |
} |
| 371 |
}; |
| 372 |
|
| 373 |
|
| 374 |
/***/ }, |
| 375 |
|
| 376 |
/***/ "./assets/src/js/api.js" |
| 377 |
/*!******************************!*\ |
| 378 |
!*** ./assets/src/js/api.js ***! |
| 379 |
\******************************/ |
| 380 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 381 |
|
| 382 |
__webpack_require__.r(__webpack_exports__); |
| 383 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 384 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 385 |
/* harmony export */ }); |
| 386 |
/** |
| 387 |
* List API on backend |
| 388 |
* |
| 389 |
* @since 4.2.6 |
| 390 |
* @version 1.0.2 |
| 391 |
*/ |
| 392 |
|
| 393 |
const lplistAPI = {}; |
| 394 |
let lp_rest_url; |
| 395 |
if ('undefined' !== typeof lpDataAdmin) { |
| 396 |
lp_rest_url = lpDataAdmin.lp_rest_url; |
| 397 |
lplistAPI.admin = { |
| 398 |
apiAdminNotice: lp_rest_url + 'lp/v1/admin/tools/admin-notices', |
| 399 |
apiAddons: lp_rest_url + 'lp/v1/addon/all', |
| 400 |
apiAddonAction: lp_rest_url + 'lp/v1/addon/action-n', |
| 401 |
apiAddonsPurchase: lp_rest_url + 'lp/v1/addon/info-addons-purchase', |
| 402 |
apiSearchCourses: lp_rest_url + 'lp/v1/admin/tools/search-course', |
| 403 |
apiSearchUsers: lp_rest_url + 'lp/v1/admin/tools/search-user', |
| 404 |
apiAssignUserCourse: lp_rest_url + 'lp/v1/admin/tools/assign-user-course', |
| 405 |
apiUnAssignUserCourse: lp_rest_url + 'lp/v1/admin/tools/unassign-user-course' |
| 406 |
}; |
| 407 |
} |
| 408 |
if ('undefined' !== typeof lpData) { |
| 409 |
lp_rest_url = lpData.lp_rest_url; |
| 410 |
lplistAPI.frontend = { |
| 411 |
apiWidgets: lp_rest_url + 'lp/v1/widgets/api', |
| 412 |
apiCourses: lp_rest_url + 'lp/v1/courses/archive-course', |
| 413 |
// Deprecated API, don't load from v4.3.7 |
| 414 |
apiAJAX: lp_rest_url + 'lp/v1/load_content_via_ajax/', |
| 415 |
// Deprecated since 4.3.0 |
| 416 |
apiProfileCoverImage: lp_rest_url + 'lp/v1/profile/cover-image' |
| 417 |
}; |
| 418 |
} |
| 419 |
if (lp_rest_url) { |
| 420 |
lplistAPI.apiCourses = lp_rest_url + 'lp/v1/courses/'; |
| 421 |
lplistAPI.apiEditCoursesArchiveBlock = lp_rest_url + 'lp/v1/courses/edit-archive-block'; |
| 422 |
lplistAPI.apiCoursesSuggest = lp_rest_url + 'lp/v1/courses/courses-suggest'; |
| 423 |
} |
| 424 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (lplistAPI); |
| 425 |
|
| 426 |
/***/ }, |
| 427 |
|
| 428 |
/***/ "./assets/src/js/utils.js" |
| 429 |
/*!********************************!*\ |
| 430 |
!*** ./assets/src/js/utils.js ***! |
| 431 |
\********************************/ |
| 432 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 433 |
|
| 434 |
__webpack_require__.r(__webpack_exports__); |
| 435 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 436 |
/* harmony export */ debounce: () => (/* binding */ debounce), |
| 437 |
/* harmony export */ eventHandlers: () => (/* binding */ eventHandlers), |
| 438 |
/* harmony export */ getDataOfForm: () => (/* binding */ getDataOfForm), |
| 439 |
/* harmony export */ getFieldKeysOfForm: () => (/* binding */ getFieldKeysOfForm), |
| 440 |
/* harmony export */ listenElementCreated: () => (/* binding */ listenElementCreated), |
| 441 |
/* harmony export */ listenElementViewed: () => (/* binding */ listenElementViewed), |
| 442 |
/* harmony export */ lpAddQueryArgs: () => (/* binding */ lpAddQueryArgs), |
| 443 |
/* harmony export */ lpAjaxParseJsonOld: () => (/* binding */ lpAjaxParseJsonOld), |
| 444 |
/* harmony export */ lpClassName: () => (/* binding */ lpClassName), |
| 445 |
/* harmony export */ lpFetchAPI: () => (/* binding */ lpFetchAPI), |
| 446 |
/* harmony export */ lpGetCurrentURLNoParam: () => (/* binding */ lpGetCurrentURLNoParam), |
| 447 |
/* harmony export */ lpOnElementReady: () => (/* binding */ lpOnElementReady), |
| 448 |
/* harmony export */ lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl), |
| 449 |
/* harmony export */ lpShowHideEl: () => (/* binding */ lpShowHideEl), |
| 450 |
/* harmony export */ mergeDataWithDatForm: () => (/* binding */ mergeDataWithDatForm), |
| 451 |
/* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse) |
| 452 |
/* harmony export */ }); |
| 453 |
/** |
| 454 |
* Utils functions |
| 455 |
* |
| 456 |
* @param url |
| 457 |
* @param data |
| 458 |
* @param functions |
| 459 |
* @since 4.2.5.1 |
| 460 |
* @version 1.0.6 |
| 461 |
*/ |
| 462 |
const lpClassName = { |
| 463 |
hidden: 'lp-hidden', |
| 464 |
loading: 'loading', |
| 465 |
elCollapse: 'lp-collapse', |
| 466 |
elSectionToggle: '.lp-section-toggle', |
| 467 |
elTriggerToggle: '.lp-trigger-toggle' |
| 468 |
}; |
| 469 |
const lpFetchAPI = (url, data = {}, functions = {}) => { |
| 470 |
if ('function' === typeof functions.before) { |
| 471 |
functions.before(); |
| 472 |
} |
| 473 |
fetch(url, { |
| 474 |
method: 'GET', |
| 475 |
...data |
| 476 |
}).then(response => response.json()).then(response => { |
| 477 |
if ('function' === typeof functions.success) { |
| 478 |
functions.success(response); |
| 479 |
} |
| 480 |
}).catch(err => { |
| 481 |
if ('function' === typeof functions.error) { |
| 482 |
functions.error(err); |
| 483 |
} |
| 484 |
}).finally(() => { |
| 485 |
if ('function' === typeof functions.completed) { |
| 486 |
functions.completed(); |
| 487 |
} |
| 488 |
}); |
| 489 |
}; |
| 490 |
|
| 491 |
/** |
| 492 |
* Get current URL without params. |
| 493 |
* |
| 494 |
* @since 4.2.5.1 |
| 495 |
*/ |
| 496 |
const lpGetCurrentURLNoParam = () => { |
| 497 |
let currentUrl = window.location.href; |
| 498 |
const hasParams = currentUrl.includes('?'); |
| 499 |
if (hasParams) { |
| 500 |
currentUrl = currentUrl.split('?')[0]; |
| 501 |
} |
| 502 |
return currentUrl; |
| 503 |
}; |
| 504 |
const lpAddQueryArgs = (endpoint, args) => { |
| 505 |
const url = new URL(endpoint); |
| 506 |
Object.keys(args).forEach(arg => { |
| 507 |
url.searchParams.set(arg, args[arg]); |
| 508 |
}); |
| 509 |
return url; |
| 510 |
}; |
| 511 |
|
| 512 |
/** |
| 513 |
* Listen element viewed. |
| 514 |
* |
| 515 |
* @param el |
| 516 |
* @param callback |
| 517 |
* @since 4.2.5.8 |
| 518 |
*/ |
| 519 |
const listenElementViewed = (el, callback) => { |
| 520 |
const observerSeeItem = new IntersectionObserver(function (entries) { |
| 521 |
for (const entry of entries) { |
| 522 |
if (entry.isIntersecting) { |
| 523 |
callback(entry); |
| 524 |
} |
| 525 |
} |
| 526 |
}); |
| 527 |
observerSeeItem.observe(el); |
| 528 |
}; |
| 529 |
|
| 530 |
/** |
| 531 |
* Listen element created. |
| 532 |
* |
| 533 |
* @param callback |
| 534 |
* @since 4.2.5.8 |
| 535 |
*/ |
| 536 |
const listenElementCreated = callback => { |
| 537 |
const observerCreateItem = new MutationObserver(function (mutations) { |
| 538 |
mutations.forEach(function (mutation) { |
| 539 |
if (mutation.addedNodes) { |
| 540 |
mutation.addedNodes.forEach(function (node) { |
| 541 |
if (node.nodeType === 1) { |
| 542 |
callback(node); |
| 543 |
} |
| 544 |
}); |
| 545 |
} |
| 546 |
}); |
| 547 |
}); |
| 548 |
observerCreateItem.observe(document, { |
| 549 |
childList: true, |
| 550 |
subtree: true |
| 551 |
}); |
| 552 |
// End. |
| 553 |
}; |
| 554 |
|
| 555 |
/** |
| 556 |
* Listen element created. |
| 557 |
* |
| 558 |
* @param selector |
| 559 |
* @param callback |
| 560 |
* @since 4.2.7.1 |
| 561 |
*/ |
| 562 |
const lpOnElementReady = (selector, callback) => { |
| 563 |
const element = document.querySelector(selector); |
| 564 |
if (element) { |
| 565 |
callback(element); |
| 566 |
return; |
| 567 |
} |
| 568 |
const observer = new MutationObserver((mutations, obs) => { |
| 569 |
const element = document.querySelector(selector); |
| 570 |
if (element) { |
| 571 |
obs.disconnect(); |
| 572 |
callback(element); |
| 573 |
} |
| 574 |
}); |
| 575 |
observer.observe(document.documentElement, { |
| 576 |
childList: true, |
| 577 |
subtree: true |
| 578 |
}); |
| 579 |
}; |
| 580 |
|
| 581 |
// Parse JSON from string with content include LP_AJAX_START. |
| 582 |
const lpAjaxParseJsonOld = data => { |
| 583 |
if (typeof data !== 'string') { |
| 584 |
return data; |
| 585 |
} |
| 586 |
const m = String.raw({ |
| 587 |
raw: data |
| 588 |
}).match(/<-- LP_AJAX_START -->(.*)<-- LP_AJAX_END -->/s); |
| 589 |
try { |
| 590 |
if (m) { |
| 591 |
data = JSON.parse(m[1].replace(/(?:\r\n|\r|\n)/g, '')); |
| 592 |
} else { |
| 593 |
data = JSON.parse(data); |
| 594 |
} |
| 595 |
} catch (e) { |
| 596 |
data = {}; |
| 597 |
} |
| 598 |
return data; |
| 599 |
}; |
| 600 |
|
| 601 |
// status 0: hide, 1: show |
| 602 |
const lpShowHideEl = (el, status = 0) => { |
| 603 |
if (!el) { |
| 604 |
return; |
| 605 |
} |
| 606 |
if (!status) { |
| 607 |
el.classList.add(lpClassName.hidden); |
| 608 |
} else { |
| 609 |
el.classList.remove(lpClassName.hidden); |
| 610 |
} |
| 611 |
}; |
| 612 |
|
| 613 |
// status 0: hide, 1: show |
| 614 |
const lpSetLoadingEl = (el, status) => { |
| 615 |
if (!el) { |
| 616 |
return; |
| 617 |
} |
| 618 |
if (!status) { |
| 619 |
el.classList.remove(lpClassName.loading); |
| 620 |
} else { |
| 621 |
el.classList.add(lpClassName.loading); |
| 622 |
} |
| 623 |
}; |
| 624 |
|
| 625 |
// Toggle collapse section |
| 626 |
const toggleCollapse = (e, target, elTriggerClassName = '', elsExclude = [], callback) => { |
| 627 |
if (!elTriggerClassName) { |
| 628 |
elTriggerClassName = lpClassName.elTriggerToggle; |
| 629 |
} |
| 630 |
|
| 631 |
// Exclude elements, which should not trigger the collapse toggle |
| 632 |
if (elsExclude && elsExclude.length > 0) { |
| 633 |
for (const elExclude of elsExclude) { |
| 634 |
if (target.closest(elExclude)) { |
| 635 |
return; |
| 636 |
} |
| 637 |
} |
| 638 |
} |
| 639 |
const elTrigger = target.closest(elTriggerClassName); |
| 640 |
if (!elTrigger) { |
| 641 |
return; |
| 642 |
} |
| 643 |
|
| 644 |
//console.log( 'elTrigger', elTrigger ); |
| 645 |
|
| 646 |
const elSectionToggle = elTrigger.closest(`${lpClassName.elSectionToggle}`); |
| 647 |
if (!elSectionToggle) { |
| 648 |
return; |
| 649 |
} |
| 650 |
elSectionToggle.classList.toggle(`${lpClassName.elCollapse}`); |
| 651 |
if ('function' === typeof callback) { |
| 652 |
callback(elSectionToggle); |
| 653 |
} |
| 654 |
}; |
| 655 |
|
| 656 |
// Get data of form |
| 657 |
const getDataOfForm = form => { |
| 658 |
const dataSend = {}; |
| 659 |
const formData = new FormData(form); |
| 660 |
for (const pair of formData.entries()) { |
| 661 |
const key = pair[0]; |
| 662 |
const value = formData.getAll(key); |
| 663 |
if (!dataSend.hasOwnProperty(key)) { |
| 664 |
// Convert value array to string. |
| 665 |
dataSend[key] = value.join(','); |
| 666 |
} |
| 667 |
} |
| 668 |
return dataSend; |
| 669 |
}; |
| 670 |
|
| 671 |
// Get field keys of form |
| 672 |
const getFieldKeysOfForm = form => { |
| 673 |
const keys = []; |
| 674 |
const elements = form.elements; |
| 675 |
for (let i = 0; i < elements.length; i++) { |
| 676 |
const name = elements[i].name; |
| 677 |
if (name && !keys.includes(name)) { |
| 678 |
keys.push(name); |
| 679 |
} |
| 680 |
} |
| 681 |
return keys; |
| 682 |
}; |
| 683 |
|
| 684 |
// Merge data handle with data form. |
| 685 |
const mergeDataWithDatForm = (elForm, dataHandle) => { |
| 686 |
const dataForm = getDataOfForm(elForm); |
| 687 |
const keys = getFieldKeysOfForm(elForm); |
| 688 |
keys.forEach(key => { |
| 689 |
if (!dataForm.hasOwnProperty(key)) { |
| 690 |
delete dataHandle[key]; |
| 691 |
} else if (dataForm[key][0] === '') { |
| 692 |
delete dataForm[key]; |
| 693 |
delete dataHandle[key]; |
| 694 |
} |
| 695 |
}); |
| 696 |
dataHandle = { |
| 697 |
...dataHandle, |
| 698 |
...dataForm |
| 699 |
}; |
| 700 |
return dataHandle; |
| 701 |
}; |
| 702 |
|
| 703 |
/** |
| 704 |
* Event trigger |
| 705 |
* For each list of event handlers, listen event on document. |
| 706 |
* |
| 707 |
* eventName: 'click', 'change', ... |
| 708 |
* eventHandlers = [ { selector: '.lp-button', callBack: function(){}, class: object } ] |
| 709 |
* |
| 710 |
* @param eventName |
| 711 |
* @param eventHandlers |
| 712 |
*/ |
| 713 |
const eventHandlers = (eventName, eventHandlers) => { |
| 714 |
document.addEventListener(eventName, e => { |
| 715 |
const target = e.target; |
| 716 |
let args = { |
| 717 |
e, |
| 718 |
target |
| 719 |
}; |
| 720 |
eventHandlers.forEach(eventHandler => { |
| 721 |
args = { |
| 722 |
...args, |
| 723 |
...eventHandler |
| 724 |
}; |
| 725 |
|
| 726 |
//console.log( args ); |
| 727 |
|
| 728 |
// Check condition before call back |
| 729 |
if (eventHandler.conditionBeforeCallBack) { |
| 730 |
if (eventHandler.conditionBeforeCallBack(args) !== true) { |
| 731 |
return; |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
// Special check for keydown event with checkIsEventEnter = true |
| 736 |
if (eventName === 'keydown' && eventHandler.checkIsEventEnter) { |
| 737 |
if (e.key !== 'Enter') { |
| 738 |
return; |
| 739 |
} |
| 740 |
} |
| 741 |
if (target.closest(eventHandler.selector)) { |
| 742 |
if (eventHandler.class) { |
| 743 |
// Call method of class, function callBack will understand exactly {this} is class object. |
| 744 |
eventHandler.class[eventHandler.callBack](args); |
| 745 |
} else { |
| 746 |
// For send args is objected, {this} is eventHandler object, not class object. |
| 747 |
eventHandler.callBack(args); |
| 748 |
} |
| 749 |
} |
| 750 |
}); |
| 751 |
}); |
| 752 |
}; |
| 753 |
|
| 754 |
/** |
| 755 |
* Debounce - delays function execution until after `wait` ms of inactivity. |
| 756 |
* |
| 757 |
* Each call resets the timer. Only the last call in a burst executes. |
| 758 |
* |
| 759 |
* USE CASES: |
| 760 |
* - Search inputs, form validation, window resize |
| 761 |
* - Multiple elements need independent timers |
| 762 |
* - When you need to call with different arguments |
| 763 |
* |
| 764 |
* EXAMPLES: |
| 765 |
* const debouncedSearch = debounce( (query) => fetchResults(query), 300 ); |
| 766 |
* searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value)); |
| 767 |
* |
| 768 |
* const debouncedResize = debounce( recalculateLayout, 250 ); |
| 769 |
* window.addEventListener('resize', debouncedResize); |
| 770 |
* |
| 771 |
* ⚠️ Create ONCE outside event handlers, not inside. |
| 772 |
* |
| 773 |
* @param {Function} func - Function to debounce (can be anonymous) |
| 774 |
* @param {number} wait - Milliseconds to wait (default: 500) |
| 775 |
* @return {Function} Debounced wrapper function |
| 776 |
* @since 4.3.7 |
| 777 |
* @version 1.0.0 |
| 778 |
*/ |
| 779 |
const debounce = (func, wait = 500) => { |
| 780 |
let timer; |
| 781 |
return args => { |
| 782 |
clearTimeout(timer); |
| 783 |
timer = setTimeout(() => func(args), wait); |
| 784 |
}; |
| 785 |
}; |
| 786 |
|
| 787 |
/***/ }, |
| 788 |
|
| 789 |
/***/ "./node_modules/@orchidjs/sifter/dist/esm/sifter.js" |
| 790 |
/*!**********************************************************!*\ |
| 791 |
!*** ./node_modules/@orchidjs/sifter/dist/esm/sifter.js ***! |
| 792 |
\**********************************************************/ |
| 793 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 794 |
|
| 795 |
__webpack_require__.r(__webpack_exports__); |
| 796 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 797 |
/* harmony export */ Sifter: () => (/* binding */ Sifter), |
| 798 |
/* harmony export */ cmp: () => (/* reexport safe */ _utils_js__WEBPACK_IMPORTED_MODULE_0__.cmp), |
| 799 |
/* harmony export */ getAttr: () => (/* reexport safe */ _utils_js__WEBPACK_IMPORTED_MODULE_0__.getAttr), |
| 800 |
/* harmony export */ getAttrNesting: () => (/* reexport safe */ _utils_js__WEBPACK_IMPORTED_MODULE_0__.getAttrNesting), |
| 801 |
/* harmony export */ getPattern: () => (/* reexport safe */ _orchidjs_unicode_variants__WEBPACK_IMPORTED_MODULE_1__.getPattern), |
| 802 |
/* harmony export */ iterate: () => (/* reexport safe */ _utils_js__WEBPACK_IMPORTED_MODULE_0__.iterate), |
| 803 |
/* harmony export */ propToArray: () => (/* reexport safe */ _utils_js__WEBPACK_IMPORTED_MODULE_0__.propToArray), |
| 804 |
/* harmony export */ scoreValue: () => (/* reexport safe */ _utils_js__WEBPACK_IMPORTED_MODULE_0__.scoreValue) |
| 805 |
/* harmony export */ }); |
| 806 |
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils.js */ "./node_modules/@orchidjs/sifter/dist/esm/utils.js"); |
| 807 |
/* harmony import */ var _orchidjs_unicode_variants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @orchidjs/unicode-variants */ "./node_modules/@orchidjs/unicode-variants/dist/esm/index.js"); |
| 808 |
/* harmony import */ var _types_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./types.js */ "./node_modules/@orchidjs/sifter/dist/esm/types.js"); |
| 809 |
/** |
| 810 |
* sifter.js |
| 811 |
* Copyright (c) 2013–2020 Brian Reavis & contributors |
| 812 |
* |
| 813 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 814 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 815 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 816 |
* |
| 817 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 818 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 819 |
* ANY KIND, either express or implied. See the License for the specific language |
| 820 |
* governing permissions and limitations under the License. |
| 821 |
* |
| 822 |
* @author Brian Reavis <brian@thirdroute.com> |
| 823 |
*/ |
| 824 |
|
| 825 |
|
| 826 |
class Sifter { |
| 827 |
items; // []|{}; |
| 828 |
settings; |
| 829 |
/** |
| 830 |
* Textually searches arrays and hashes of objects |
| 831 |
* by property (or multiple properties). Designed |
| 832 |
* specifically for autocomplete. |
| 833 |
* |
| 834 |
*/ |
| 835 |
constructor(items, settings) { |
| 836 |
this.items = items; |
| 837 |
this.settings = settings || { diacritics: true }; |
| 838 |
} |
| 839 |
; |
| 840 |
/** |
| 841 |
* Splits a search string into an array of individual |
| 842 |
* regexps to be used to match results. |
| 843 |
* |
| 844 |
*/ |
| 845 |
tokenize(query, respect_word_boundaries, weights) { |
| 846 |
if (!query || !query.length) |
| 847 |
return []; |
| 848 |
const tokens = []; |
| 849 |
const words = query.split(/\s+/); |
| 850 |
var field_regex; |
| 851 |
if (weights) { |
| 852 |
field_regex = new RegExp('^(' + Object.keys(weights).map(_orchidjs_unicode_variants__WEBPACK_IMPORTED_MODULE_1__.escape_regex).join('|') + ')\:(.*)$'); |
| 853 |
} |
| 854 |
words.forEach((word) => { |
| 855 |
let field_match; |
| 856 |
let field = null; |
| 857 |
let regex = null; |
| 858 |
// look for "field:query" tokens |
| 859 |
if (field_regex && (field_match = word.match(field_regex))) { |
| 860 |
field = field_match[1]; |
| 861 |
word = field_match[2]; |
| 862 |
} |
| 863 |
if (word.length > 0) { |
| 864 |
if (this.settings.diacritics) { |
| 865 |
regex = (0,_orchidjs_unicode_variants__WEBPACK_IMPORTED_MODULE_1__.getPattern)(word) || null; |
| 866 |
} |
| 867 |
else { |
| 868 |
regex = (0,_orchidjs_unicode_variants__WEBPACK_IMPORTED_MODULE_1__.escape_regex)(word); |
| 869 |
} |
| 870 |
if (regex && respect_word_boundaries) |
| 871 |
regex = "\\b" + regex; |
| 872 |
} |
| 873 |
tokens.push({ |
| 874 |
string: word, |
| 875 |
regex: regex ? new RegExp(regex, 'iu') : null, |
| 876 |
field: field, |
| 877 |
}); |
| 878 |
}); |
| 879 |
return tokens; |
| 880 |
} |
| 881 |
; |
| 882 |
/** |
| 883 |
* Returns a function to be used to score individual results. |
| 884 |
* |
| 885 |
* Good matches will have a higher score than poor matches. |
| 886 |
* If an item is not a match, 0 will be returned by the function. |
| 887 |
* |
| 888 |
* @returns {T.ScoreFn} |
| 889 |
*/ |
| 890 |
getScoreFunction(query, options) { |
| 891 |
var search = this.prepareSearch(query, options); |
| 892 |
return this._getScoreFunction(search); |
| 893 |
} |
| 894 |
/** |
| 895 |
* @returns {T.ScoreFn} |
| 896 |
* |
| 897 |
*/ |
| 898 |
_getScoreFunction(search) { |
| 899 |
const tokens = search.tokens, token_count = tokens.length; |
| 900 |
if (!token_count) { |
| 901 |
return function () { return 0; }; |
| 902 |
} |
| 903 |
const fields = search.options.fields, weights = search.weights, field_count = fields.length, getAttrFn = search.getAttrFn; |
| 904 |
if (!field_count) { |
| 905 |
return function () { return 1; }; |
| 906 |
} |
| 907 |
/** |
| 908 |
* Calculates the score of an object |
| 909 |
* against the search query. |
| 910 |
* |
| 911 |
*/ |
| 912 |
const scoreObject = (function () { |
| 913 |
if (field_count === 1) { |
| 914 |
return function (token, data) { |
| 915 |
const field = fields[0].field; |
| 916 |
return (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.scoreValue)(getAttrFn(data, field), token, weights[field] || 1); |
| 917 |
}; |
| 918 |
} |
| 919 |
return function (token, data) { |
| 920 |
var sum = 0; |
| 921 |
// is the token specific to a field? |
| 922 |
if (token.field) { |
| 923 |
const value = getAttrFn(data, token.field); |
| 924 |
if (!token.regex && value) { |
| 925 |
sum += (1 / field_count); |
| 926 |
} |
| 927 |
else { |
| 928 |
sum += (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.scoreValue)(value, token, 1); |
| 929 |
} |
| 930 |
} |
| 931 |
else { |
| 932 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.iterate)(weights, (weight, field) => { |
| 933 |
sum += (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.scoreValue)(getAttrFn(data, field), token, weight); |
| 934 |
}); |
| 935 |
} |
| 936 |
return sum / field_count; |
| 937 |
}; |
| 938 |
})(); |
| 939 |
if (token_count === 1) { |
| 940 |
return function (data) { |
| 941 |
return scoreObject(tokens[0], data); |
| 942 |
}; |
| 943 |
} |
| 944 |
if (search.options.conjunction === 'and') { |
| 945 |
return function (data) { |
| 946 |
var score, sum = 0; |
| 947 |
for (let token of tokens) { |
| 948 |
score = scoreObject(token, data); |
| 949 |
if (score <= 0) |
| 950 |
return 0; |
| 951 |
sum += score; |
| 952 |
} |
| 953 |
return sum / token_count; |
| 954 |
}; |
| 955 |
} |
| 956 |
else { |
| 957 |
return function (data) { |
| 958 |
var sum = 0; |
| 959 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.iterate)(tokens, (token) => { |
| 960 |
sum += scoreObject(token, data); |
| 961 |
}); |
| 962 |
return sum / token_count; |
| 963 |
}; |
| 964 |
} |
| 965 |
} |
| 966 |
; |
| 967 |
/** |
| 968 |
* Returns a function that can be used to compare two |
| 969 |
* results, for sorting purposes. If no sorting should |
| 970 |
* be performed, `null` will be returned. |
| 971 |
* |
| 972 |
* @return function(a,b) |
| 973 |
*/ |
| 974 |
getSortFunction(query, options) { |
| 975 |
var search = this.prepareSearch(query, options); |
| 976 |
return this._getSortFunction(search); |
| 977 |
} |
| 978 |
_getSortFunction(search) { |
| 979 |
var implicit_score, sort_flds = []; |
| 980 |
const self = this, options = search.options, sort = (!search.query && options.sort_empty) ? options.sort_empty : options.sort; |
| 981 |
if (typeof sort == 'function') { |
| 982 |
return sort.bind(this); |
| 983 |
} |
| 984 |
/** |
| 985 |
* Fetches the specified sort field value |
| 986 |
* from a search result item. |
| 987 |
* |
| 988 |
*/ |
| 989 |
const get_field = function (name, result) { |
| 990 |
if (name === '$score') |
| 991 |
return result.score; |
| 992 |
return search.getAttrFn(self.items[result.id], name); |
| 993 |
}; |
| 994 |
// parse options |
| 995 |
if (sort) { |
| 996 |
for (let s of sort) { |
| 997 |
if (search.query || s.field !== '$score') { |
| 998 |
sort_flds.push(s); |
| 999 |
} |
| 1000 |
} |
| 1001 |
} |
| 1002 |
// the "$score" field is implied to be the primary |
| 1003 |
// sort field, unless it's manually specified |
| 1004 |
if (search.query) { |
| 1005 |
implicit_score = true; |
| 1006 |
for (let fld of sort_flds) { |
| 1007 |
if (fld.field === '$score') { |
| 1008 |
implicit_score = false; |
| 1009 |
break; |
| 1010 |
} |
| 1011 |
} |
| 1012 |
if (implicit_score) { |
| 1013 |
sort_flds.unshift({ field: '$score', direction: 'desc' }); |
| 1014 |
} |
| 1015 |
// without a search.query, all items will have the same score |
| 1016 |
} |
| 1017 |
else { |
| 1018 |
sort_flds = sort_flds.filter((fld) => fld.field !== '$score'); |
| 1019 |
} |
| 1020 |
// build function |
| 1021 |
const sort_flds_count = sort_flds.length; |
| 1022 |
if (!sort_flds_count) { |
| 1023 |
return null; |
| 1024 |
} |
| 1025 |
return function (a, b) { |
| 1026 |
var result, field; |
| 1027 |
for (let sort_fld of sort_flds) { |
| 1028 |
field = sort_fld.field; |
| 1029 |
let multiplier = sort_fld.direction === 'desc' ? -1 : 1; |
| 1030 |
result = multiplier * (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.cmp)(get_field(field, a), get_field(field, b)); |
| 1031 |
if (result) |
| 1032 |
return result; |
| 1033 |
} |
| 1034 |
return 0; |
| 1035 |
}; |
| 1036 |
} |
| 1037 |
; |
| 1038 |
/** |
| 1039 |
* Parses a search query and returns an object |
| 1040 |
* with tokens and fields ready to be populated |
| 1041 |
* with results. |
| 1042 |
* |
| 1043 |
*/ |
| 1044 |
prepareSearch(query, optsUser) { |
| 1045 |
const weights = {}; |
| 1046 |
var options = Object.assign({}, optsUser); |
| 1047 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.propToArray)(options, 'sort'); |
| 1048 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.propToArray)(options, 'sort_empty'); |
| 1049 |
// convert fields to new format |
| 1050 |
if (options.fields) { |
| 1051 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.propToArray)(options, 'fields'); |
| 1052 |
const fields = []; |
| 1053 |
options.fields.forEach((field) => { |
| 1054 |
if (typeof field == 'string') { |
| 1055 |
field = { field: field, weight: 1 }; |
| 1056 |
} |
| 1057 |
fields.push(field); |
| 1058 |
weights[field.field] = ('weight' in field) ? field.weight : 1; |
| 1059 |
}); |
| 1060 |
options.fields = fields; |
| 1061 |
} |
| 1062 |
return { |
| 1063 |
options: options, |
| 1064 |
query: query.toLowerCase().trim(), |
| 1065 |
tokens: this.tokenize(query, options.respect_word_boundaries, weights), |
| 1066 |
total: 0, |
| 1067 |
items: [], |
| 1068 |
weights: weights, |
| 1069 |
getAttrFn: (options.nesting) ? _utils_js__WEBPACK_IMPORTED_MODULE_0__.getAttrNesting : _utils_js__WEBPACK_IMPORTED_MODULE_0__.getAttr, |
| 1070 |
}; |
| 1071 |
} |
| 1072 |
; |
| 1073 |
/** |
| 1074 |
* Searches through all items and returns a sorted array of matches. |
| 1075 |
* |
| 1076 |
*/ |
| 1077 |
search(query, options) { |
| 1078 |
var self = this, score, search; |
| 1079 |
search = this.prepareSearch(query, options); |
| 1080 |
options = search.options; |
| 1081 |
query = search.query; |
| 1082 |
// generate result scoring function |
| 1083 |
const fn_score = options.score || self._getScoreFunction(search); |
| 1084 |
// perform search and sort |
| 1085 |
if (query.length) { |
| 1086 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.iterate)(self.items, (item, id) => { |
| 1087 |
score = fn_score(item); |
| 1088 |
if (options.filter === false || score > 0) { |
| 1089 |
search.items.push({ 'score': score, 'id': id }); |
| 1090 |
} |
| 1091 |
}); |
| 1092 |
} |
| 1093 |
else { |
| 1094 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.iterate)(self.items, (_, id) => { |
| 1095 |
search.items.push({ 'score': 1, 'id': id }); |
| 1096 |
}); |
| 1097 |
} |
| 1098 |
const fn_sort = self._getSortFunction(search); |
| 1099 |
if (fn_sort) |
| 1100 |
search.items.sort(fn_sort); |
| 1101 |
// apply limits |
| 1102 |
search.total = search.items.length; |
| 1103 |
if (typeof options.limit === 'number') { |
| 1104 |
search.items = search.items.slice(0, options.limit); |
| 1105 |
} |
| 1106 |
return search; |
| 1107 |
} |
| 1108 |
; |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
//# sourceMappingURL=sifter.js.map |
| 1113 |
|
| 1114 |
/***/ }, |
| 1115 |
|
| 1116 |
/***/ "./node_modules/@orchidjs/sifter/dist/esm/types.js" |
| 1117 |
/*!*********************************************************!*\ |
| 1118 |
!*** ./node_modules/@orchidjs/sifter/dist/esm/types.js ***! |
| 1119 |
\*********************************************************/ |
| 1120 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1121 |
|
| 1122 |
__webpack_require__.r(__webpack_exports__); |
| 1123 |
|
| 1124 |
//# sourceMappingURL=types.js.map |
| 1125 |
|
| 1126 |
/***/ }, |
| 1127 |
|
| 1128 |
/***/ "./node_modules/@orchidjs/sifter/dist/esm/utils.js" |
| 1129 |
/*!*********************************************************!*\ |
| 1130 |
!*** ./node_modules/@orchidjs/sifter/dist/esm/utils.js ***! |
| 1131 |
\*********************************************************/ |
| 1132 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1133 |
|
| 1134 |
__webpack_require__.r(__webpack_exports__); |
| 1135 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1136 |
/* harmony export */ cmp: () => (/* binding */ cmp), |
| 1137 |
/* harmony export */ getAttr: () => (/* binding */ getAttr), |
| 1138 |
/* harmony export */ getAttrNesting: () => (/* binding */ getAttrNesting), |
| 1139 |
/* harmony export */ iterate: () => (/* binding */ iterate), |
| 1140 |
/* harmony export */ propToArray: () => (/* binding */ propToArray), |
| 1141 |
/* harmony export */ scoreValue: () => (/* binding */ scoreValue) |
| 1142 |
/* harmony export */ }); |
| 1143 |
/* harmony import */ var _orchidjs_unicode_variants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @orchidjs/unicode-variants */ "./node_modules/@orchidjs/unicode-variants/dist/esm/index.js"); |
| 1144 |
|
| 1145 |
/** |
| 1146 |
* A property getter resolving dot-notation |
| 1147 |
* @param {Object} obj The root object to fetch property on |
| 1148 |
* @param {String} name The optionally dotted property name to fetch |
| 1149 |
* @return {Object} The resolved property value |
| 1150 |
*/ |
| 1151 |
const getAttr = (obj, name) => { |
| 1152 |
if (!obj) |
| 1153 |
return; |
| 1154 |
return obj[name]; |
| 1155 |
}; |
| 1156 |
/** |
| 1157 |
* A property getter resolving dot-notation |
| 1158 |
* @param {Object} obj The root object to fetch property on |
| 1159 |
* @param {String} name The optionally dotted property name to fetch |
| 1160 |
* @return {Object} The resolved property value |
| 1161 |
*/ |
| 1162 |
const getAttrNesting = (obj, name) => { |
| 1163 |
if (!obj) |
| 1164 |
return; |
| 1165 |
var part, names = name.split("."); |
| 1166 |
while ((part = names.shift()) && (obj = obj[part])) |
| 1167 |
; |
| 1168 |
return obj; |
| 1169 |
}; |
| 1170 |
/** |
| 1171 |
* Calculates how close of a match the |
| 1172 |
* given value is against a search token. |
| 1173 |
* |
| 1174 |
*/ |
| 1175 |
const scoreValue = (value, token, weight) => { |
| 1176 |
var score, pos; |
| 1177 |
if (!value) |
| 1178 |
return 0; |
| 1179 |
value = value + ''; |
| 1180 |
if (token.regex == null) |
| 1181 |
return 0; |
| 1182 |
pos = value.search(token.regex); |
| 1183 |
if (pos === -1) |
| 1184 |
return 0; |
| 1185 |
score = token.string.length / value.length; |
| 1186 |
if (pos === 0) |
| 1187 |
score += 0.5; |
| 1188 |
return score * weight; |
| 1189 |
}; |
| 1190 |
/** |
| 1191 |
* Cast object property to an array if it exists and has a value |
| 1192 |
* |
| 1193 |
*/ |
| 1194 |
const propToArray = (obj, key) => { |
| 1195 |
var value = obj[key]; |
| 1196 |
if (typeof value == 'function') |
| 1197 |
return value; |
| 1198 |
if (value && !Array.isArray(value)) { |
| 1199 |
obj[key] = [value]; |
| 1200 |
} |
| 1201 |
}; |
| 1202 |
/** |
| 1203 |
* Iterates over arrays and hashes. |
| 1204 |
* |
| 1205 |
* ``` |
| 1206 |
* iterate(this.items, function(item, id) { |
| 1207 |
* // invoked for each item |
| 1208 |
* }); |
| 1209 |
* ``` |
| 1210 |
* |
| 1211 |
*/ |
| 1212 |
const iterate = (object, callback) => { |
| 1213 |
if (Array.isArray(object)) { |
| 1214 |
object.forEach(callback); |
| 1215 |
} |
| 1216 |
else { |
| 1217 |
for (var key in object) { |
| 1218 |
if (object.hasOwnProperty(key)) { |
| 1219 |
callback(object[key], key); |
| 1220 |
} |
| 1221 |
} |
| 1222 |
} |
| 1223 |
}; |
| 1224 |
const cmp = (a, b) => { |
| 1225 |
if (typeof a === 'number' && typeof b === 'number') { |
| 1226 |
return a > b ? 1 : (a < b ? -1 : 0); |
| 1227 |
} |
| 1228 |
a = (0,_orchidjs_unicode_variants__WEBPACK_IMPORTED_MODULE_0__.asciifold)(a + '').toLowerCase(); |
| 1229 |
b = (0,_orchidjs_unicode_variants__WEBPACK_IMPORTED_MODULE_0__.asciifold)(b + '').toLowerCase(); |
| 1230 |
if (a > b) |
| 1231 |
return 1; |
| 1232 |
if (b > a) |
| 1233 |
return -1; |
| 1234 |
return 0; |
| 1235 |
}; |
| 1236 |
//# sourceMappingURL=utils.js.map |
| 1237 |
|
| 1238 |
/***/ }, |
| 1239 |
|
| 1240 |
/***/ "./node_modules/@orchidjs/unicode-variants/dist/esm/index.js" |
| 1241 |
/*!*******************************************************************!*\ |
| 1242 |
!*** ./node_modules/@orchidjs/unicode-variants/dist/esm/index.js ***! |
| 1243 |
\*******************************************************************/ |
| 1244 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1245 |
|
| 1246 |
__webpack_require__.r(__webpack_exports__); |
| 1247 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1248 |
/* harmony export */ _asciifold: () => (/* binding */ _asciifold), |
| 1249 |
/* harmony export */ asciifold: () => (/* binding */ asciifold), |
| 1250 |
/* harmony export */ code_points: () => (/* binding */ code_points), |
| 1251 |
/* harmony export */ escape_regex: () => (/* reexport safe */ _regex_js__WEBPACK_IMPORTED_MODULE_0__.escape_regex), |
| 1252 |
/* harmony export */ generateMap: () => (/* binding */ generateMap), |
| 1253 |
/* harmony export */ generateSets: () => (/* binding */ generateSets), |
| 1254 |
/* harmony export */ generator: () => (/* binding */ generator), |
| 1255 |
/* harmony export */ getPattern: () => (/* binding */ getPattern), |
| 1256 |
/* harmony export */ initialize: () => (/* binding */ initialize), |
| 1257 |
/* harmony export */ mapSequence: () => (/* binding */ mapSequence), |
| 1258 |
/* harmony export */ normalize: () => (/* binding */ normalize), |
| 1259 |
/* harmony export */ substringsToPattern: () => (/* binding */ substringsToPattern), |
| 1260 |
/* harmony export */ unicode_map: () => (/* binding */ unicode_map) |
| 1261 |
/* harmony export */ }); |
| 1262 |
/* harmony import */ var _regex_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./regex.js */ "./node_modules/@orchidjs/unicode-variants/dist/esm/regex.js"); |
| 1263 |
/* harmony import */ var _strings_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./strings.js */ "./node_modules/@orchidjs/unicode-variants/dist/esm/strings.js"); |
| 1264 |
|
| 1265 |
|
| 1266 |
const code_points = [[0, 65535]]; |
| 1267 |
const accent_pat = '[\u0300-\u036F\u{b7}\u{2be}\u{2bc}]'; |
| 1268 |
let unicode_map; |
| 1269 |
let multi_char_reg; |
| 1270 |
const max_char_length = 3; |
| 1271 |
const latin_convert = {}; |
| 1272 |
const latin_condensed = { |
| 1273 |
'/': '⁄∕', |
| 1274 |
'0': '߀', |
| 1275 |
"a": "ⱥɐɑ", |
| 1276 |
"aa": "ꜳ", |
| 1277 |
"ae": "æǽǣ", |
| 1278 |
"ao": "ꜵ", |
| 1279 |
"au": "ꜷ", |
| 1280 |
"av": "ꜹꜻ", |
| 1281 |
"ay": "ꜽ", |
| 1282 |
"b": "ƀɓƃ", |
| 1283 |
"c": "ꜿƈȼↄ", |
| 1284 |
"d": "đɗɖ� |
| 1285 |
ƌꮷԁɦ", |
| 1286 |
"e": "ɛǝᴇɇ", |
| 1287 |
"f": "ꝼƒ", |
| 1288 |
"g": "ǥɠꞡᵹꝿɢ", |
| 1289 |
"h": "ħⱨⱶɥ", |
| 1290 |
"i": "ɨı", |
| 1291 |
"j": "ɉȷ", |
| 1292 |
"k": "ƙⱪꝁꝃ� |
| 1293 |
ꞣ", |
| 1294 |
"l": "łƚɫⱡꝉꝇꞁɭ", |
| 1295 |
"m": "ɱɯϻ", |
| 1296 |
"n": "ꞥƞɲꞑᴎлԉ", |
| 1297 |
"o": "øǿɔɵꝋꝍᴑ", |
| 1298 |
"oe": "œ", |
| 1299 |
"oi": "ƣ", |
| 1300 |
"oo": "ꝏ", |
| 1301 |
"ou": "ȣ", |
| 1302 |
"p": "ƥᵽꝑꝓꝕρ", |
| 1303 |
"q": "ꝗꝙɋ", |
| 1304 |
"r": "ɍɽꝛꞧꞃ", |
| 1305 |
"s": "ßȿꞩ� |
| 1306 |
ʂ", |
| 1307 |
"t": "ŧƭʈⱦꞇ", |
| 1308 |
"th": "þ", |
| 1309 |
"tz": "ꜩ", |
| 1310 |
"u": "ʉ", |
| 1311 |
"v": "ʋꝟʌ", |
| 1312 |
"vy": "ꝡ", |
| 1313 |
"w": "ⱳ", |
| 1314 |
"y": "ƴɏỿ", |
| 1315 |
"z": "ƶȥɀⱬꝣ", |
| 1316 |
"hv": "ƕ" |
| 1317 |
}; |
| 1318 |
for (let latin in latin_condensed) { |
| 1319 |
let unicode = latin_condensed[latin] || ''; |
| 1320 |
for (let i = 0; i < unicode.length; i++) { |
| 1321 |
let char = unicode.substring(i, i + 1); |
| 1322 |
latin_convert[char] = latin; |
| 1323 |
} |
| 1324 |
} |
| 1325 |
const convert_pat = new RegExp(Object.keys(latin_convert).join('|') + '|' + accent_pat, 'gu'); |
| 1326 |
/** |
| 1327 |
* Initialize the unicode_map from the give code point ranges |
| 1328 |
*/ |
| 1329 |
const initialize = (_code_points) => { |
| 1330 |
if (unicode_map !== undefined) |
| 1331 |
return; |
| 1332 |
unicode_map = generateMap(_code_points || code_points); |
| 1333 |
}; |
| 1334 |
/** |
| 1335 |
* Helper method for normalize a string |
| 1336 |
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize |
| 1337 |
*/ |
| 1338 |
const normalize = (str, form = 'NFKD') => str.normalize(form); |
| 1339 |
/** |
| 1340 |
* Remove accents without reordering string |
| 1341 |
* calling str.normalize('NFKD') on \u{594}\u{595}\u{596} becomes \u{596}\u{594}\u{595} |
| 1342 |
* via https://github.com/krisk/Fuse/issues/133#issuecomment-318692703 |
| 1343 |
*/ |
| 1344 |
const asciifold = (str) => { |
| 1345 |
return Array.from(str).reduce( |
| 1346 |
/** |
| 1347 |
* @param {string} result |
| 1348 |
* @param {string} char |
| 1349 |
*/ |
| 1350 |
(result, char) => { |
| 1351 |
return result + _asciifold(char); |
| 1352 |
}, ''); |
| 1353 |
}; |
| 1354 |
const _asciifold = (str) => { |
| 1355 |
str = normalize(str) |
| 1356 |
.toLowerCase() |
| 1357 |
.replace(convert_pat, (/** @type {string} */ char) => { |
| 1358 |
return latin_convert[char] || ''; |
| 1359 |
}); |
| 1360 |
//return str; |
| 1361 |
return normalize(str, 'NFC'); |
| 1362 |
}; |
| 1363 |
/** |
| 1364 |
* Generate a list of unicode variants from the list of code points |
| 1365 |
*/ |
| 1366 |
function* generator(code_points) { |
| 1367 |
for (const [code_point_min, code_point_max] of code_points) { |
| 1368 |
for (let i = code_point_min; i <= code_point_max; i++) { |
| 1369 |
let composed = String.fromCharCode(i); |
| 1370 |
let folded = asciifold(composed); |
| 1371 |
if (folded == composed.toLowerCase()) { |
| 1372 |
continue; |
| 1373 |
} |
| 1374 |
// skip when folded is a string longer than 3 characters long |
| 1375 |
// bc the resulting regex patterns will be long |
| 1376 |
// eg: |
| 1377 |
// folded صلى الله عليه وسل� |
| 1378 |
length 18 code point 65018 |
| 1379 |
// folded جل جلاله length 8 code point 65019 |
| 1380 |
if (folded.length > max_char_length) { |
| 1381 |
continue; |
| 1382 |
} |
| 1383 |
if (folded.length == 0) { |
| 1384 |
continue; |
| 1385 |
} |
| 1386 |
yield { folded: folded, composed: composed, code_point: i }; |
| 1387 |
} |
| 1388 |
} |
| 1389 |
} |
| 1390 |
/** |
| 1391 |
* Generate a unicode map from the list of code points |
| 1392 |
*/ |
| 1393 |
const generateSets = (code_points) => { |
| 1394 |
const unicode_sets = {}; |
| 1395 |
const addMatching = (folded, to_add) => { |
| 1396 |
/** @type {Set<string>} */ |
| 1397 |
const folded_set = unicode_sets[folded] || new Set(); |
| 1398 |
const patt = new RegExp('^' + (0,_regex_js__WEBPACK_IMPORTED_MODULE_0__.setToPattern)(folded_set) + '$', 'iu'); |
| 1399 |
if (to_add.match(patt)) { |
| 1400 |
return; |
| 1401 |
} |
| 1402 |
folded_set.add((0,_regex_js__WEBPACK_IMPORTED_MODULE_0__.escape_regex)(to_add)); |
| 1403 |
unicode_sets[folded] = folded_set; |
| 1404 |
}; |
| 1405 |
for (let value of generator(code_points)) { |
| 1406 |
addMatching(value.folded, value.folded); |
| 1407 |
addMatching(value.folded, value.composed); |
| 1408 |
} |
| 1409 |
return unicode_sets; |
| 1410 |
}; |
| 1411 |
/** |
| 1412 |
* Generate a unicode map from the list of code points |
| 1413 |
* ae => (?:(?:ae|Æ|Ǽ|Ǣ)|(?:A|Ⓐ|A...)(?:E|ɛ|Ⓔ...)) |
| 1414 |
*/ |
| 1415 |
const generateMap = (code_points) => { |
| 1416 |
const unicode_sets = generateSets(code_points); |
| 1417 |
const unicode_map = {}; |
| 1418 |
let multi_char = []; |
| 1419 |
for (let folded in unicode_sets) { |
| 1420 |
let set = unicode_sets[folded]; |
| 1421 |
if (set) { |
| 1422 |
unicode_map[folded] = (0,_regex_js__WEBPACK_IMPORTED_MODULE_0__.setToPattern)(set); |
| 1423 |
} |
| 1424 |
if (folded.length > 1) { |
| 1425 |
multi_char.push((0,_regex_js__WEBPACK_IMPORTED_MODULE_0__.escape_regex)(folded)); |
| 1426 |
} |
| 1427 |
} |
| 1428 |
multi_char.sort((a, b) => b.length - a.length); |
| 1429 |
const multi_char_patt = (0,_regex_js__WEBPACK_IMPORTED_MODULE_0__.arrayToPattern)(multi_char); |
| 1430 |
multi_char_reg = new RegExp('^' + multi_char_patt, 'u'); |
| 1431 |
return unicode_map; |
| 1432 |
}; |
| 1433 |
/** |
| 1434 |
* Map each element of an array from its folded value to all possible unicode matches |
| 1435 |
*/ |
| 1436 |
const mapSequence = (strings, min_replacement = 1) => { |
| 1437 |
let chars_replaced = 0; |
| 1438 |
strings = strings.map((str) => { |
| 1439 |
if (unicode_map[str]) { |
| 1440 |
chars_replaced += str.length; |
| 1441 |
} |
| 1442 |
return unicode_map[str] || str; |
| 1443 |
}); |
| 1444 |
if (chars_replaced >= min_replacement) { |
| 1445 |
return (0,_regex_js__WEBPACK_IMPORTED_MODULE_0__.sequencePattern)(strings); |
| 1446 |
} |
| 1447 |
return ''; |
| 1448 |
}; |
| 1449 |
/** |
| 1450 |
* Convert a short string and split it into all possible patterns |
| 1451 |
* Keep a pattern only if min_replacement is met |
| 1452 |
* |
| 1453 |
* 'abc' |
| 1454 |
* => [['abc'],['ab','c'],['a','bc'],['a','b','c']] |
| 1455 |
* => ['abc-pattern','ab-c-pattern'...] |
| 1456 |
*/ |
| 1457 |
const substringsToPattern = (str, min_replacement = 1) => { |
| 1458 |
min_replacement = Math.max(min_replacement, str.length - 1); |
| 1459 |
return (0,_regex_js__WEBPACK_IMPORTED_MODULE_0__.arrayToPattern)((0,_strings_js__WEBPACK_IMPORTED_MODULE_1__.allSubstrings)(str).map((sub_pat) => { |
| 1460 |
return mapSequence(sub_pat, min_replacement); |
| 1461 |
})); |
| 1462 |
}; |
| 1463 |
/** |
| 1464 |
* Convert an array of sequences into a pattern |
| 1465 |
* [{start:0,end:3,length:3,substr:'iii'}...] => (?:iii...) |
| 1466 |
*/ |
| 1467 |
const sequencesToPattern = (sequences, all = true) => { |
| 1468 |
let min_replacement = sequences.length > 1 ? 1 : 0; |
| 1469 |
return (0,_regex_js__WEBPACK_IMPORTED_MODULE_0__.arrayToPattern)(sequences.map((sequence) => { |
| 1470 |
let seq = []; |
| 1471 |
const len = all ? sequence.length() : sequence.length() - 1; |
| 1472 |
for (let j = 0; j < len; j++) { |
| 1473 |
seq.push(substringsToPattern(sequence.substrs[j] || '', min_replacement)); |
| 1474 |
} |
| 1475 |
return (0,_regex_js__WEBPACK_IMPORTED_MODULE_0__.sequencePattern)(seq); |
| 1476 |
})); |
| 1477 |
}; |
| 1478 |
/** |
| 1479 |
* Return true if the sequence is already in the sequences |
| 1480 |
*/ |
| 1481 |
const inSequences = (needle_seq, sequences) => { |
| 1482 |
for (const seq of sequences) { |
| 1483 |
if (seq.start != needle_seq.start || seq.end != needle_seq.end) { |
| 1484 |
continue; |
| 1485 |
} |
| 1486 |
if (seq.substrs.join('') !== needle_seq.substrs.join('')) { |
| 1487 |
continue; |
| 1488 |
} |
| 1489 |
let needle_parts = needle_seq.parts; |
| 1490 |
const filter = (part) => { |
| 1491 |
for (const needle_part of needle_parts) { |
| 1492 |
if (needle_part.start === part.start && needle_part.substr === part.substr) { |
| 1493 |
return false; |
| 1494 |
} |
| 1495 |
if (part.length == 1 || needle_part.length == 1) { |
| 1496 |
continue; |
| 1497 |
} |
| 1498 |
// check for overlapping parts |
| 1499 |
// a = ['::=','=='] |
| 1500 |
// b = ['::','==='] |
| 1501 |
// a = ['r','sm'] |
| 1502 |
// b = ['rs','m'] |
| 1503 |
if (part.start < needle_part.start && part.end > needle_part.start) { |
| 1504 |
return true; |
| 1505 |
} |
| 1506 |
if (needle_part.start < part.start && needle_part.end > part.start) { |
| 1507 |
return true; |
| 1508 |
} |
| 1509 |
} |
| 1510 |
return false; |
| 1511 |
}; |
| 1512 |
let filtered = seq.parts.filter(filter); |
| 1513 |
if (filtered.length > 0) { |
| 1514 |
continue; |
| 1515 |
} |
| 1516 |
return true; |
| 1517 |
} |
| 1518 |
return false; |
| 1519 |
}; |
| 1520 |
class Sequence { |
| 1521 |
parts; |
| 1522 |
substrs; |
| 1523 |
start; |
| 1524 |
end; |
| 1525 |
constructor() { |
| 1526 |
this.parts = []; |
| 1527 |
this.substrs = []; |
| 1528 |
this.start = 0; |
| 1529 |
this.end = 0; |
| 1530 |
} |
| 1531 |
add(part) { |
| 1532 |
if (part) { |
| 1533 |
this.parts.push(part); |
| 1534 |
this.substrs.push(part.substr); |
| 1535 |
this.start = Math.min(part.start, this.start); |
| 1536 |
this.end = Math.max(part.end, this.end); |
| 1537 |
} |
| 1538 |
} |
| 1539 |
last() { |
| 1540 |
return this.parts[this.parts.length - 1]; |
| 1541 |
} |
| 1542 |
length() { |
| 1543 |
return this.parts.length; |
| 1544 |
} |
| 1545 |
clone(position, last_piece) { |
| 1546 |
let clone = new Sequence(); |
| 1547 |
let parts = JSON.parse(JSON.stringify(this.parts)); |
| 1548 |
let last_part = parts.pop(); |
| 1549 |
for (const part of parts) { |
| 1550 |
clone.add(part); |
| 1551 |
} |
| 1552 |
let last_substr = last_piece.substr.substring(0, position - last_part.start); |
| 1553 |
let clone_last_len = last_substr.length; |
| 1554 |
clone.add({ start: last_part.start, end: last_part.start + clone_last_len, length: clone_last_len, substr: last_substr }); |
| 1555 |
return clone; |
| 1556 |
} |
| 1557 |
} |
| 1558 |
/** |
| 1559 |
* Expand a regular expression pattern to include unicode variants |
| 1560 |
* eg /a/ becomes /aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁ� |
| 1561 |
ⱥɐɑAⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢ� |
| 1562 |
ǺǍȀȂẠẬẶḀĄȺⱯ/ |
| 1563 |
* |
| 1564 |
* Issue: |
| 1565 |
* ﺊﺋ [ 'ﺊ = \\u{fe8a}', 'ﺋ = \\u{fe8b}' ] |
| 1566 |
* becomes: ئئ [ 'ي = \\u{64a}', 'ٔ = \\u{654}', 'ي = \\u{64a}', 'ٔ = \\u{654}' ] |
| 1567 |
* |
| 1568 |
* İIJ = IIJ = � |
| 1569 |
�J |
| 1570 |
* |
| 1571 |
* 1/2/4 |
| 1572 |
*/ |
| 1573 |
const getPattern = (str) => { |
| 1574 |
initialize(); |
| 1575 |
str = asciifold(str); |
| 1576 |
let pattern = ''; |
| 1577 |
let sequences = [new Sequence()]; |
| 1578 |
for (let i = 0; i < str.length; i++) { |
| 1579 |
let substr = str.substring(i); |
| 1580 |
let match = substr.match(multi_char_reg); |
| 1581 |
const char = str.substring(i, i + 1); |
| 1582 |
const match_str = match ? match[0] : null; |
| 1583 |
// loop through sequences |
| 1584 |
// add either the char or multi_match |
| 1585 |
let overlapping = []; |
| 1586 |
let added_types = new Set(); |
| 1587 |
for (const sequence of sequences) { |
| 1588 |
const last_piece = sequence.last(); |
| 1589 |
if (!last_piece || last_piece.length == 1 || last_piece.end <= i) { |
| 1590 |
// if we have a multi match |
| 1591 |
if (match_str) { |
| 1592 |
const len = match_str.length; |
| 1593 |
sequence.add({ start: i, end: i + len, length: len, substr: match_str }); |
| 1594 |
added_types.add('1'); |
| 1595 |
} |
| 1596 |
else { |
| 1597 |
sequence.add({ start: i, end: i + 1, length: 1, substr: char }); |
| 1598 |
added_types.add('2'); |
| 1599 |
} |
| 1600 |
} |
| 1601 |
else if (match_str) { |
| 1602 |
let clone = sequence.clone(i, last_piece); |
| 1603 |
const len = match_str.length; |
| 1604 |
clone.add({ start: i, end: i + len, length: len, substr: match_str }); |
| 1605 |
overlapping.push(clone); |
| 1606 |
} |
| 1607 |
else { |
| 1608 |
// don't add char |
| 1609 |
// adding would create invalid patterns: 234 => [2,34,4] |
| 1610 |
added_types.add('3'); |
| 1611 |
} |
| 1612 |
} |
| 1613 |
// if we have overlapping |
| 1614 |
if (overlapping.length > 0) { |
| 1615 |
// ['ii','iii'] before ['i','i','iii'] |
| 1616 |
overlapping = overlapping.sort((a, b) => { |
| 1617 |
return a.length() - b.length(); |
| 1618 |
}); |
| 1619 |
for (let clone of overlapping) { |
| 1620 |
// don't add if we already have an equivalent sequence |
| 1621 |
if (inSequences(clone, sequences)) { |
| 1622 |
continue; |
| 1623 |
} |
| 1624 |
sequences.push(clone); |
| 1625 |
} |
| 1626 |
continue; |
| 1627 |
} |
| 1628 |
// if we haven't done anything unique |
| 1629 |
// clean up the patterns |
| 1630 |
// helps keep patterns smaller |
| 1631 |
// if str = 'r₨㎧aarss', pattern will be 446 instead of 655 |
| 1632 |
if (i > 0 && added_types.size == 1 && !added_types.has('3')) { |
| 1633 |
pattern += sequencesToPattern(sequences, false); |
| 1634 |
let new_seq = new Sequence(); |
| 1635 |
const old_seq = sequences[0]; |
| 1636 |
if (old_seq) { |
| 1637 |
new_seq.add(old_seq.last()); |
| 1638 |
} |
| 1639 |
sequences = [new_seq]; |
| 1640 |
} |
| 1641 |
} |
| 1642 |
pattern += sequencesToPattern(sequences, true); |
| 1643 |
return pattern; |
| 1644 |
}; |
| 1645 |
|
| 1646 |
//# sourceMappingURL=index.js.map |
| 1647 |
|
| 1648 |
/***/ }, |
| 1649 |
|
| 1650 |
/***/ "./node_modules/@orchidjs/unicode-variants/dist/esm/regex.js" |
| 1651 |
/*!*******************************************************************!*\ |
| 1652 |
!*** ./node_modules/@orchidjs/unicode-variants/dist/esm/regex.js ***! |
| 1653 |
\*******************************************************************/ |
| 1654 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1655 |
|
| 1656 |
__webpack_require__.r(__webpack_exports__); |
| 1657 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1658 |
/* harmony export */ arrayToPattern: () => (/* binding */ arrayToPattern), |
| 1659 |
/* harmony export */ escape_regex: () => (/* binding */ escape_regex), |
| 1660 |
/* harmony export */ hasDuplicates: () => (/* binding */ hasDuplicates), |
| 1661 |
/* harmony export */ maxValueLength: () => (/* binding */ maxValueLength), |
| 1662 |
/* harmony export */ sequencePattern: () => (/* binding */ sequencePattern), |
| 1663 |
/* harmony export */ setToPattern: () => (/* binding */ setToPattern), |
| 1664 |
/* harmony export */ unicodeLength: () => (/* binding */ unicodeLength) |
| 1665 |
/* harmony export */ }); |
| 1666 |
/** |
| 1667 |
* Convert array of strings to a regular expression |
| 1668 |
* ex ['ab','a'] => (?:ab|a) |
| 1669 |
* ex ['a','b'] => [ab] |
| 1670 |
*/ |
| 1671 |
const arrayToPattern = (chars) => { |
| 1672 |
chars = chars.filter(Boolean); |
| 1673 |
if (chars.length < 2) { |
| 1674 |
return chars[0] || ''; |
| 1675 |
} |
| 1676 |
return (maxValueLength(chars) == 1) ? '[' + chars.join('') + ']' : '(?:' + chars.join('|') + ')'; |
| 1677 |
}; |
| 1678 |
const sequencePattern = (array) => { |
| 1679 |
if (!hasDuplicates(array)) { |
| 1680 |
return array.join(''); |
| 1681 |
} |
| 1682 |
let pattern = ''; |
| 1683 |
let prev_char_count = 0; |
| 1684 |
const prev_pattern = () => { |
| 1685 |
if (prev_char_count > 1) { |
| 1686 |
pattern += '{' + prev_char_count + '}'; |
| 1687 |
} |
| 1688 |
}; |
| 1689 |
array.forEach((char, i) => { |
| 1690 |
if (char === array[i - 1]) { |
| 1691 |
prev_char_count++; |
| 1692 |
return; |
| 1693 |
} |
| 1694 |
prev_pattern(); |
| 1695 |
pattern += char; |
| 1696 |
prev_char_count = 1; |
| 1697 |
}); |
| 1698 |
prev_pattern(); |
| 1699 |
return pattern; |
| 1700 |
}; |
| 1701 |
/** |
| 1702 |
* Convert array of strings to a regular expression |
| 1703 |
* ex ['ab','a'] => (?:ab|a) |
| 1704 |
* ex ['a','b'] => [ab] |
| 1705 |
*/ |
| 1706 |
const setToPattern = (chars) => { |
| 1707 |
let array = Array.from(chars); |
| 1708 |
return arrayToPattern(array); |
| 1709 |
}; |
| 1710 |
/** |
| 1711 |
* https://stackoverflow.com/questions/7376598/in-javascript-how-do-i-check-if-an-array-has-duplicate-values |
| 1712 |
*/ |
| 1713 |
const hasDuplicates = (array) => { |
| 1714 |
return (new Set(array)).size !== array.length; |
| 1715 |
}; |
| 1716 |
/** |
| 1717 |
* https://stackoverflow.com/questions/63006601/why-does-u-throw-an-invalid-escape-error |
| 1718 |
*/ |
| 1719 |
const escape_regex = (str) => { |
| 1720 |
return (str + '').replace(/([\$\(\)\*\+\.\?\[\]\^\{\|\}\\])/gu, '\\$1'); |
| 1721 |
}; |
| 1722 |
/** |
| 1723 |
* Return the max length of array values |
| 1724 |
*/ |
| 1725 |
const maxValueLength = (array) => { |
| 1726 |
return array.reduce((longest, value) => Math.max(longest, unicodeLength(value)), 0); |
| 1727 |
}; |
| 1728 |
const unicodeLength = (str) => { |
| 1729 |
return Array.from(str).length; |
| 1730 |
}; |
| 1731 |
//# sourceMappingURL=regex.js.map |
| 1732 |
|
| 1733 |
/***/ }, |
| 1734 |
|
| 1735 |
/***/ "./node_modules/@orchidjs/unicode-variants/dist/esm/strings.js" |
| 1736 |
/*!*********************************************************************!*\ |
| 1737 |
!*** ./node_modules/@orchidjs/unicode-variants/dist/esm/strings.js ***! |
| 1738 |
\*********************************************************************/ |
| 1739 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1740 |
|
| 1741 |
__webpack_require__.r(__webpack_exports__); |
| 1742 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1743 |
/* harmony export */ allSubstrings: () => (/* binding */ allSubstrings) |
| 1744 |
/* harmony export */ }); |
| 1745 |
/** |
| 1746 |
* Get all possible combinations of substrings that add up to the given string |
| 1747 |
* https://stackoverflow.com/questions/30169587/find-all-the-combination-of-substrings-that-add-up-to-the-given-string |
| 1748 |
*/ |
| 1749 |
const allSubstrings = (input) => { |
| 1750 |
if (input.length === 1) |
| 1751 |
return [[input]]; |
| 1752 |
let result = []; |
| 1753 |
const start = input.substring(1); |
| 1754 |
const suba = allSubstrings(start); |
| 1755 |
suba.forEach(function (subresult) { |
| 1756 |
let tmp = subresult.slice(0); |
| 1757 |
tmp[0] = input.charAt(0) + tmp[0]; |
| 1758 |
result.push(tmp); |
| 1759 |
tmp = subresult.slice(0); |
| 1760 |
tmp.unshift(input.charAt(0)); |
| 1761 |
result.push(tmp); |
| 1762 |
}); |
| 1763 |
return result; |
| 1764 |
}; |
| 1765 |
//# sourceMappingURL=strings.js.map |
| 1766 |
|
| 1767 |
/***/ }, |
| 1768 |
|
| 1769 |
/***/ "./node_modules/tom-select/dist/esm/constants.js" |
| 1770 |
/*!*******************************************************!*\ |
| 1771 |
!*** ./node_modules/tom-select/dist/esm/constants.js ***! |
| 1772 |
\*******************************************************/ |
| 1773 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1774 |
|
| 1775 |
__webpack_require__.r(__webpack_exports__); |
| 1776 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1777 |
/* harmony export */ IS_MAC: () => (/* binding */ IS_MAC), |
| 1778 |
/* harmony export */ KEY_A: () => (/* binding */ KEY_A), |
| 1779 |
/* harmony export */ KEY_BACKSPACE: () => (/* binding */ KEY_BACKSPACE), |
| 1780 |
/* harmony export */ KEY_DELETE: () => (/* binding */ KEY_DELETE), |
| 1781 |
/* harmony export */ KEY_DOWN: () => (/* binding */ KEY_DOWN), |
| 1782 |
/* harmony export */ KEY_ESC: () => (/* binding */ KEY_ESC), |
| 1783 |
/* harmony export */ KEY_LEFT: () => (/* binding */ KEY_LEFT), |
| 1784 |
/* harmony export */ KEY_RETURN: () => (/* binding */ KEY_RETURN), |
| 1785 |
/* harmony export */ KEY_RIGHT: () => (/* binding */ KEY_RIGHT), |
| 1786 |
/* harmony export */ KEY_SHORTCUT: () => (/* binding */ KEY_SHORTCUT), |
| 1787 |
/* harmony export */ KEY_TAB: () => (/* binding */ KEY_TAB), |
| 1788 |
/* harmony export */ KEY_UP: () => (/* binding */ KEY_UP) |
| 1789 |
/* harmony export */ }); |
| 1790 |
const KEY_A = 65; |
| 1791 |
const KEY_RETURN = 13; |
| 1792 |
const KEY_ESC = 27; |
| 1793 |
const KEY_LEFT = 37; |
| 1794 |
const KEY_UP = 38; |
| 1795 |
const KEY_RIGHT = 39; |
| 1796 |
const KEY_DOWN = 40; |
| 1797 |
const KEY_BACKSPACE = 8; |
| 1798 |
const KEY_DELETE = 46; |
| 1799 |
const KEY_TAB = 9; |
| 1800 |
const IS_MAC = typeof navigator === 'undefined' ? false : /Mac/.test(navigator.userAgent); |
| 1801 |
const KEY_SHORTCUT = IS_MAC ? 'metaKey' : 'ctrlKey'; // ctrl key or apple key for ma |
| 1802 |
//# sourceMappingURL=constants.js.map |
| 1803 |
|
| 1804 |
/***/ }, |
| 1805 |
|
| 1806 |
/***/ "./node_modules/tom-select/dist/esm/contrib/highlight.js" |
| 1807 |
/*!***************************************************************!*\ |
| 1808 |
!*** ./node_modules/tom-select/dist/esm/contrib/highlight.js ***! |
| 1809 |
\***************************************************************/ |
| 1810 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1811 |
|
| 1812 |
__webpack_require__.r(__webpack_exports__); |
| 1813 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1814 |
/* harmony export */ highlight: () => (/* binding */ highlight), |
| 1815 |
/* harmony export */ removeHighlight: () => (/* binding */ removeHighlight) |
| 1816 |
/* harmony export */ }); |
| 1817 |
/* harmony import */ var _vanilla_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../vanilla.js */ "./node_modules/tom-select/dist/esm/vanilla.js"); |
| 1818 |
/** |
| 1819 |
* highlight v3 | MIT license | Johann Burkard <jb@eaio.com> |
| 1820 |
* Highlights arbitrary terms in a node. |
| 1821 |
* |
| 1822 |
* - Modified by Marshal <beatgates@gmail.com> 2011-6-24 (added regex) |
| 1823 |
* - Modified by Brian Reavis <brian@thirdroute.com> 2012-8-27 (cleanup) |
| 1824 |
*/ |
| 1825 |
|
| 1826 |
const highlight = (element, regex) => { |
| 1827 |
if (regex === null) |
| 1828 |
return; |
| 1829 |
// convet string to regex |
| 1830 |
if (typeof regex === 'string') { |
| 1831 |
if (!regex.length) |
| 1832 |
return; |
| 1833 |
regex = new RegExp(regex, 'i'); |
| 1834 |
} |
| 1835 |
// Wrap matching part of text node with highlighting <span>, e.g. |
| 1836 |
// Soccer -> <span class="highlight">Soc</span>cer for regex = /soc/i |
| 1837 |
const highlightText = (node) => { |
| 1838 |
var match = node.data.match(regex); |
| 1839 |
if (match && node.data.length > 0) { |
| 1840 |
var spannode = document.createElement('span'); |
| 1841 |
spannode.className = 'highlight'; |
| 1842 |
var middlebit = node.splitText(match.index); |
| 1843 |
middlebit.splitText(match[0].length); |
| 1844 |
var middleclone = middlebit.cloneNode(true); |
| 1845 |
spannode.appendChild(middleclone); |
| 1846 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_0__.replaceNode)(middlebit, spannode); |
| 1847 |
return 1; |
| 1848 |
} |
| 1849 |
return 0; |
| 1850 |
}; |
| 1851 |
// Recurse element node, looking for child text nodes to highlight, unless element |
| 1852 |
// is childless, <script>, <style>, or already highlighted: <span class="hightlight"> |
| 1853 |
const highlightChildren = (node) => { |
| 1854 |
if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName) && (node.className !== 'highlight' || node.tagName !== 'SPAN')) { |
| 1855 |
Array.from(node.childNodes).forEach(element => { |
| 1856 |
highlightRecursive(element); |
| 1857 |
}); |
| 1858 |
} |
| 1859 |
}; |
| 1860 |
const highlightRecursive = (node) => { |
| 1861 |
if (node.nodeType === 3) { |
| 1862 |
return highlightText(node); |
| 1863 |
} |
| 1864 |
highlightChildren(node); |
| 1865 |
return 0; |
| 1866 |
}; |
| 1867 |
highlightRecursive(element); |
| 1868 |
}; |
| 1869 |
/** |
| 1870 |
* removeHighlight fn copied from highlight v5 and |
| 1871 |
* edited to remove with(), pass js strict mode, and use without jquery |
| 1872 |
*/ |
| 1873 |
const removeHighlight = (el) => { |
| 1874 |
var elements = el.querySelectorAll("span.highlight"); |
| 1875 |
Array.prototype.forEach.call(elements, function (el) { |
| 1876 |
var parent = el.parentNode; |
| 1877 |
parent.replaceChild(el.firstChild, el); |
| 1878 |
parent.normalize(); |
| 1879 |
}); |
| 1880 |
}; |
| 1881 |
//# sourceMappingURL=highlight.js.map |
| 1882 |
|
| 1883 |
/***/ }, |
| 1884 |
|
| 1885 |
/***/ "./node_modules/tom-select/dist/esm/contrib/microevent.js" |
| 1886 |
/*!****************************************************************!*\ |
| 1887 |
!*** ./node_modules/tom-select/dist/esm/contrib/microevent.js ***! |
| 1888 |
\****************************************************************/ |
| 1889 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1890 |
|
| 1891 |
__webpack_require__.r(__webpack_exports__); |
| 1892 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1893 |
/* harmony export */ "default": () => (/* binding */ MicroEvent) |
| 1894 |
/* harmony export */ }); |
| 1895 |
/** |
| 1896 |
* MicroEvent - to make any js object an event emitter |
| 1897 |
* |
| 1898 |
* - pure javascript - server compatible, browser compatible |
| 1899 |
* - dont rely on the browser doms |
| 1900 |
* - super simple - you get it immediatly, no mistery, no magic involved |
| 1901 |
* |
| 1902 |
* @author Jerome Etienne (https://github.com/jeromeetienne) |
| 1903 |
*/ |
| 1904 |
/** |
| 1905 |
* Execute callback for each event in space separated list of event names |
| 1906 |
* |
| 1907 |
*/ |
| 1908 |
function forEvents(events, callback) { |
| 1909 |
events.split(/\s+/).forEach((event) => { |
| 1910 |
callback(event); |
| 1911 |
}); |
| 1912 |
} |
| 1913 |
class MicroEvent { |
| 1914 |
constructor() { |
| 1915 |
this._events = {}; |
| 1916 |
} |
| 1917 |
on(events, fct) { |
| 1918 |
forEvents(events, (event) => { |
| 1919 |
const event_array = this._events[event] || []; |
| 1920 |
event_array.push(fct); |
| 1921 |
this._events[event] = event_array; |
| 1922 |
}); |
| 1923 |
} |
| 1924 |
off(events, fct) { |
| 1925 |
var n = arguments.length; |
| 1926 |
if (n === 0) { |
| 1927 |
this._events = {}; |
| 1928 |
return; |
| 1929 |
} |
| 1930 |
forEvents(events, (event) => { |
| 1931 |
if (n === 1) { |
| 1932 |
delete this._events[event]; |
| 1933 |
return; |
| 1934 |
} |
| 1935 |
const event_array = this._events[event]; |
| 1936 |
if (event_array === undefined) |
| 1937 |
return; |
| 1938 |
event_array.splice(event_array.indexOf(fct), 1); |
| 1939 |
this._events[event] = event_array; |
| 1940 |
}); |
| 1941 |
} |
| 1942 |
trigger(events, ...args) { |
| 1943 |
var self = this; |
| 1944 |
forEvents(events, (event) => { |
| 1945 |
const event_array = self._events[event]; |
| 1946 |
if (event_array === undefined) |
| 1947 |
return; |
| 1948 |
event_array.forEach(fct => { |
| 1949 |
fct.apply(self, args); |
| 1950 |
}); |
| 1951 |
}); |
| 1952 |
} |
| 1953 |
} |
| 1954 |
; |
| 1955 |
//# sourceMappingURL=microevent.js.map |
| 1956 |
|
| 1957 |
/***/ }, |
| 1958 |
|
| 1959 |
/***/ "./node_modules/tom-select/dist/esm/contrib/microplugin.js" |
| 1960 |
/*!*****************************************************************!*\ |
| 1961 |
!*** ./node_modules/tom-select/dist/esm/contrib/microplugin.js ***! |
| 1962 |
\*****************************************************************/ |
| 1963 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1964 |
|
| 1965 |
__webpack_require__.r(__webpack_exports__); |
| 1966 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1967 |
/* harmony export */ "default": () => (/* binding */ MicroPlugin) |
| 1968 |
/* harmony export */ }); |
| 1969 |
/** |
| 1970 |
* microplugin.js |
| 1971 |
* Copyright (c) 2013 Brian Reavis & contributors |
| 1972 |
* |
| 1973 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 1974 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 1975 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 1976 |
* |
| 1977 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 1978 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 1979 |
* ANY KIND, either express or implied. See the License for the specific language |
| 1980 |
* governing permissions and limitations under the License. |
| 1981 |
* |
| 1982 |
* @author Brian Reavis <brian@thirdroute.com> |
| 1983 |
*/ |
| 1984 |
function MicroPlugin(Interface) { |
| 1985 |
Interface.plugins = {}; |
| 1986 |
return class extends Interface { |
| 1987 |
constructor() { |
| 1988 |
super(...arguments); |
| 1989 |
this.plugins = { |
| 1990 |
names: [], |
| 1991 |
settings: {}, |
| 1992 |
requested: {}, |
| 1993 |
loaded: {} |
| 1994 |
}; |
| 1995 |
} |
| 1996 |
/** |
| 1997 |
* Registers a plugin. |
| 1998 |
* |
| 1999 |
* @param {function} fn |
| 2000 |
*/ |
| 2001 |
static define(name, fn) { |
| 2002 |
Interface.plugins[name] = { |
| 2003 |
'name': name, |
| 2004 |
'fn': fn |
| 2005 |
}; |
| 2006 |
} |
| 2007 |
/** |
| 2008 |
* Initializes the listed plugins (with options). |
| 2009 |
* Acceptable formats: |
| 2010 |
* |
| 2011 |
* List (without options): |
| 2012 |
* ['a', 'b', 'c'] |
| 2013 |
* |
| 2014 |
* List (with options): |
| 2015 |
* [{'name': 'a', options: {}}, {'name': 'b', options: {}}] |
| 2016 |
* |
| 2017 |
* Hash (with options): |
| 2018 |
* {'a': { ... }, 'b': { ... }, 'c': { ... }} |
| 2019 |
* |
| 2020 |
* @param {array|object} plugins |
| 2021 |
*/ |
| 2022 |
initializePlugins(plugins) { |
| 2023 |
var key, name; |
| 2024 |
const self = this; |
| 2025 |
const queue = []; |
| 2026 |
if (Array.isArray(plugins)) { |
| 2027 |
plugins.forEach((plugin) => { |
| 2028 |
if (typeof plugin === 'string') { |
| 2029 |
queue.push(plugin); |
| 2030 |
} |
| 2031 |
else { |
| 2032 |
self.plugins.settings[plugin.name] = plugin.options; |
| 2033 |
queue.push(plugin.name); |
| 2034 |
} |
| 2035 |
}); |
| 2036 |
} |
| 2037 |
else if (plugins) { |
| 2038 |
for (key in plugins) { |
| 2039 |
if (plugins.hasOwnProperty(key)) { |
| 2040 |
self.plugins.settings[key] = plugins[key]; |
| 2041 |
queue.push(key); |
| 2042 |
} |
| 2043 |
} |
| 2044 |
} |
| 2045 |
while (name = queue.shift()) { |
| 2046 |
self.require(name); |
| 2047 |
} |
| 2048 |
} |
| 2049 |
loadPlugin(name) { |
| 2050 |
var self = this; |
| 2051 |
var plugins = self.plugins; |
| 2052 |
var plugin = Interface.plugins[name]; |
| 2053 |
if (!Interface.plugins.hasOwnProperty(name)) { |
| 2054 |
throw new Error('Unable to find "' + name + '" plugin'); |
| 2055 |
} |
| 2056 |
plugins.requested[name] = true; |
| 2057 |
plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]); |
| 2058 |
plugins.names.push(name); |
| 2059 |
} |
| 2060 |
/** |
| 2061 |
* Initializes a plugin. |
| 2062 |
* |
| 2063 |
*/ |
| 2064 |
require(name) { |
| 2065 |
var self = this; |
| 2066 |
var plugins = self.plugins; |
| 2067 |
if (!self.plugins.loaded.hasOwnProperty(name)) { |
| 2068 |
if (plugins.requested[name]) { |
| 2069 |
throw new Error('Plugin has circular dependency ("' + name + '")'); |
| 2070 |
} |
| 2071 |
self.loadPlugin(name); |
| 2072 |
} |
| 2073 |
return plugins.loaded[name]; |
| 2074 |
} |
| 2075 |
}; |
| 2076 |
} |
| 2077 |
//# sourceMappingURL=microplugin.js.map |
| 2078 |
|
| 2079 |
/***/ }, |
| 2080 |
|
| 2081 |
/***/ "./node_modules/tom-select/dist/esm/defaults.js" |
| 2082 |
/*!******************************************************!*\ |
| 2083 |
!*** ./node_modules/tom-select/dist/esm/defaults.js ***! |
| 2084 |
\******************************************************/ |
| 2085 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2086 |
|
| 2087 |
__webpack_require__.r(__webpack_exports__); |
| 2088 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2089 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 2090 |
/* harmony export */ }); |
| 2091 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ |
| 2092 |
options: [], |
| 2093 |
optgroups: [], |
| 2094 |
plugins: [], |
| 2095 |
delimiter: ',', |
| 2096 |
splitOn: null, // regexp or string for splitting up values from a paste command |
| 2097 |
persist: true, |
| 2098 |
diacritics: true, |
| 2099 |
create: null, |
| 2100 |
createOnBlur: false, |
| 2101 |
createFilter: null, |
| 2102 |
highlight: true, |
| 2103 |
openOnFocus: true, |
| 2104 |
shouldOpen: null, |
| 2105 |
maxOptions: 50, |
| 2106 |
maxItems: null, |
| 2107 |
hideSelected: null, |
| 2108 |
duplicates: false, |
| 2109 |
addPrecedence: false, |
| 2110 |
selectOnTab: false, |
| 2111 |
preload: null, |
| 2112 |
allowEmptyOption: false, |
| 2113 |
//closeAfterSelect: false, |
| 2114 |
refreshThrottle: 300, |
| 2115 |
loadThrottle: 300, |
| 2116 |
loadingClass: 'loading', |
| 2117 |
dataAttr: null, //'data-data', |
| 2118 |
optgroupField: 'optgroup', |
| 2119 |
valueField: 'value', |
| 2120 |
labelField: 'text', |
| 2121 |
disabledField: 'disabled', |
| 2122 |
optgroupLabelField: 'label', |
| 2123 |
optgroupValueField: 'value', |
| 2124 |
lockOptgroupOrder: false, |
| 2125 |
sortField: '$order', |
| 2126 |
searchField: ['text'], |
| 2127 |
searchConjunction: 'and', |
| 2128 |
mode: null, |
| 2129 |
wrapperClass: 'ts-wrapper', |
| 2130 |
controlClass: 'ts-control', |
| 2131 |
dropdownClass: 'ts-dropdown', |
| 2132 |
dropdownContentClass: 'ts-dropdown-content', |
| 2133 |
itemClass: 'item', |
| 2134 |
optionClass: 'option', |
| 2135 |
dropdownParent: null, |
| 2136 |
controlInput: '<input type="text" autocomplete="off" size="1" />', |
| 2137 |
copyClassesToDropdown: false, |
| 2138 |
placeholder: null, |
| 2139 |
hidePlaceholder: null, |
| 2140 |
shouldLoad: function (query) { |
| 2141 |
return query.length > 0; |
| 2142 |
}, |
| 2143 |
/* |
| 2144 |
load : null, // function(query, callback) { ... } |
| 2145 |
score : null, // function(search) { ... } |
| 2146 |
onInitialize : null, // function() { ... } |
| 2147 |
onChange : null, // function(value) { ... } |
| 2148 |
onItemAdd : null, // function(value, $item) { ... } |
| 2149 |
onItemRemove : null, // function(value) { ... } |
| 2150 |
onClear : null, // function() { ... } |
| 2151 |
onOptionAdd : null, // function(value, data) { ... } |
| 2152 |
onOptionRemove : null, // function(value) { ... } |
| 2153 |
onOptionClear : null, // function() { ... } |
| 2154 |
onOptionGroupAdd : null, // function(id, data) { ... } |
| 2155 |
onOptionGroupRemove : null, // function(id) { ... } |
| 2156 |
onOptionGroupClear : null, // function() { ... } |
| 2157 |
onDropdownOpen : null, // function(dropdown) { ... } |
| 2158 |
onDropdownClose : null, // function(dropdown) { ... } |
| 2159 |
onType : null, // function(str) { ... } |
| 2160 |
onDelete : null, // function(values) { ... } |
| 2161 |
*/ |
| 2162 |
render: { |
| 2163 |
/* |
| 2164 |
item: null, |
| 2165 |
optgroup: null, |
| 2166 |
optgroup_header: null, |
| 2167 |
option: null, |
| 2168 |
option_create: null |
| 2169 |
*/ |
| 2170 |
} |
| 2171 |
}); |
| 2172 |
//# sourceMappingURL=defaults.js.map |
| 2173 |
|
| 2174 |
/***/ }, |
| 2175 |
|
| 2176 |
/***/ "./node_modules/tom-select/dist/esm/getSettings.js" |
| 2177 |
/*!*********************************************************!*\ |
| 2178 |
!*** ./node_modules/tom-select/dist/esm/getSettings.js ***! |
| 2179 |
\*********************************************************/ |
| 2180 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2181 |
|
| 2182 |
__webpack_require__.r(__webpack_exports__); |
| 2183 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2184 |
/* harmony export */ "default": () => (/* binding */ getSettings) |
| 2185 |
/* harmony export */ }); |
| 2186 |
/* harmony import */ var _defaults_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./defaults.js */ "./node_modules/tom-select/dist/esm/defaults.js"); |
| 2187 |
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils.js */ "./node_modules/tom-select/dist/esm/utils.js"); |
| 2188 |
|
| 2189 |
|
| 2190 |
function getSettings(input, settings_user) { |
| 2191 |
var settings = Object.assign({}, _defaults_js__WEBPACK_IMPORTED_MODULE_0__["default"], settings_user); |
| 2192 |
var attr_data = settings.dataAttr; |
| 2193 |
var field_label = settings.labelField; |
| 2194 |
var field_value = settings.valueField; |
| 2195 |
var field_disabled = settings.disabledField; |
| 2196 |
var field_optgroup = settings.optgroupField; |
| 2197 |
var field_optgroup_label = settings.optgroupLabelField; |
| 2198 |
var field_optgroup_value = settings.optgroupValueField; |
| 2199 |
var tag_name = input.tagName.toLowerCase(); |
| 2200 |
var placeholder = input.getAttribute('placeholder') || input.getAttribute('data-placeholder'); |
| 2201 |
if (!placeholder && !settings.allowEmptyOption) { |
| 2202 |
let option = input.querySelector('option[value=""]'); |
| 2203 |
if (option) { |
| 2204 |
placeholder = option.textContent; |
| 2205 |
} |
| 2206 |
} |
| 2207 |
var settings_element = { |
| 2208 |
placeholder: placeholder, |
| 2209 |
options: [], |
| 2210 |
optgroups: [], |
| 2211 |
items: [], |
| 2212 |
maxItems: null, |
| 2213 |
}; |
| 2214 |
/** |
| 2215 |
* Initialize from a <select> element. |
| 2216 |
* |
| 2217 |
*/ |
| 2218 |
var init_select = () => { |
| 2219 |
var tagName; |
| 2220 |
var options = settings_element.options; |
| 2221 |
var optionsMap = {}; |
| 2222 |
var group_count = 1; |
| 2223 |
let $order = 0; |
| 2224 |
var readData = (el) => { |
| 2225 |
var data = Object.assign({}, el.dataset); // get plain object from DOMStringMap |
| 2226 |
var json = attr_data && data[attr_data]; |
| 2227 |
if (typeof json === 'string' && json.length) { |
| 2228 |
data = Object.assign(data, JSON.parse(json)); |
| 2229 |
} |
| 2230 |
return data; |
| 2231 |
}; |
| 2232 |
var addOption = (option, group) => { |
| 2233 |
var value = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.hash_key)(option.value); |
| 2234 |
if (value == null) |
| 2235 |
return; |
| 2236 |
if (!value && !settings.allowEmptyOption) |
| 2237 |
return; |
| 2238 |
// if the option already exists, it's probably been |
| 2239 |
// duplicated in another optgroup. in this case, push |
| 2240 |
// the current group to the "optgroup" property on the |
| 2241 |
// existing option so that it's rendered in both places. |
| 2242 |
if (optionsMap.hasOwnProperty(value)) { |
| 2243 |
if (group) { |
| 2244 |
var arr = optionsMap[value][field_optgroup]; |
| 2245 |
if (!arr) { |
| 2246 |
optionsMap[value][field_optgroup] = group; |
| 2247 |
} |
| 2248 |
else if (!Array.isArray(arr)) { |
| 2249 |
optionsMap[value][field_optgroup] = [arr, group]; |
| 2250 |
} |
| 2251 |
else { |
| 2252 |
arr.push(group); |
| 2253 |
} |
| 2254 |
} |
| 2255 |
} |
| 2256 |
else { |
| 2257 |
var option_data = readData(option); |
| 2258 |
option_data[field_label] = option_data[field_label] || option.textContent; |
| 2259 |
option_data[field_value] = option_data[field_value] || value; |
| 2260 |
option_data[field_disabled] = option_data[field_disabled] || option.disabled; |
| 2261 |
option_data[field_optgroup] = option_data[field_optgroup] || group; |
| 2262 |
option_data.$option = option; |
| 2263 |
option_data.$order = option_data.$order || ++$order; |
| 2264 |
optionsMap[value] = option_data; |
| 2265 |
options.push(option_data); |
| 2266 |
} |
| 2267 |
if (option.selected) { |
| 2268 |
settings_element.items.push(value); |
| 2269 |
} |
| 2270 |
}; |
| 2271 |
var addGroup = (optgroup) => { |
| 2272 |
var id, optgroup_data; |
| 2273 |
optgroup_data = readData(optgroup); |
| 2274 |
optgroup_data[field_optgroup_label] = optgroup_data[field_optgroup_label] || optgroup.getAttribute('label') || ''; |
| 2275 |
optgroup_data[field_optgroup_value] = optgroup_data[field_optgroup_value] || group_count++; |
| 2276 |
optgroup_data[field_disabled] = optgroup_data[field_disabled] || optgroup.disabled; |
| 2277 |
optgroup_data.$order = optgroup_data.$order || ++$order; |
| 2278 |
settings_element.optgroups.push(optgroup_data); |
| 2279 |
id = optgroup_data[field_optgroup_value]; |
| 2280 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.iterate)(optgroup.children, (option) => { |
| 2281 |
addOption(option, id); |
| 2282 |
}); |
| 2283 |
}; |
| 2284 |
settings_element.maxItems = input.hasAttribute('multiple') ? null : 1; |
| 2285 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.iterate)(input.children, (child) => { |
| 2286 |
tagName = child.tagName.toLowerCase(); |
| 2287 |
if (tagName === 'optgroup') { |
| 2288 |
addGroup(child); |
| 2289 |
} |
| 2290 |
else if (tagName === 'option') { |
| 2291 |
addOption(child); |
| 2292 |
} |
| 2293 |
}); |
| 2294 |
}; |
| 2295 |
/** |
| 2296 |
* Initialize from a <input type="text"> element. |
| 2297 |
* |
| 2298 |
*/ |
| 2299 |
var init_textbox = () => { |
| 2300 |
const data_raw = input.getAttribute(attr_data); |
| 2301 |
if (!data_raw) { |
| 2302 |
var value = input.value.trim() || ''; |
| 2303 |
if (!settings.allowEmptyOption && !value.length) |
| 2304 |
return; |
| 2305 |
const values = value.split(settings.delimiter); |
| 2306 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.iterate)(values, (value) => { |
| 2307 |
const option = {}; |
| 2308 |
option[field_label] = value; |
| 2309 |
option[field_value] = value; |
| 2310 |
settings_element.options.push(option); |
| 2311 |
}); |
| 2312 |
settings_element.items = values; |
| 2313 |
} |
| 2314 |
else { |
| 2315 |
settings_element.options = JSON.parse(data_raw); |
| 2316 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.iterate)(settings_element.options, (opt) => { |
| 2317 |
settings_element.items.push(opt[field_value]); |
| 2318 |
}); |
| 2319 |
} |
| 2320 |
}; |
| 2321 |
if (tag_name === 'select') { |
| 2322 |
init_select(); |
| 2323 |
} |
| 2324 |
else { |
| 2325 |
init_textbox(); |
| 2326 |
} |
| 2327 |
return Object.assign({}, _defaults_js__WEBPACK_IMPORTED_MODULE_0__["default"], settings_element, settings_user); |
| 2328 |
} |
| 2329 |
; |
| 2330 |
//# sourceMappingURL=getSettings.js.map |
| 2331 |
|
| 2332 |
/***/ }, |
| 2333 |
|
| 2334 |
/***/ "./node_modules/tom-select/dist/esm/plugins/caret_position/plugin.js" |
| 2335 |
/*!***************************************************************************!*\ |
| 2336 |
!*** ./node_modules/tom-select/dist/esm/plugins/caret_position/plugin.js ***! |
| 2337 |
\***************************************************************************/ |
| 2338 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2339 |
|
| 2340 |
__webpack_require__.r(__webpack_exports__); |
| 2341 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2342 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 2343 |
/* harmony export */ }); |
| 2344 |
/** |
| 2345 |
* Tom Select v2.4.3 |
| 2346 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 2347 |
*/ |
| 2348 |
|
| 2349 |
/** |
| 2350 |
* Converts a scalar to its best string representation |
| 2351 |
* for hash keys and HTML attribute values. |
| 2352 |
* |
| 2353 |
* Transformations: |
| 2354 |
* 'str' -> 'str' |
| 2355 |
* null -> '' |
| 2356 |
* undefined -> '' |
| 2357 |
* true -> '1' |
| 2358 |
* false -> '0' |
| 2359 |
* 0 -> '0' |
| 2360 |
* 1 -> '1' |
| 2361 |
* |
| 2362 |
*/ |
| 2363 |
|
| 2364 |
/** |
| 2365 |
* Iterates over arrays and hashes. |
| 2366 |
* |
| 2367 |
* ``` |
| 2368 |
* iterate(this.items, function(item, id) { |
| 2369 |
* // invoked for each item |
| 2370 |
* }); |
| 2371 |
* ``` |
| 2372 |
* |
| 2373 |
*/ |
| 2374 |
const iterate = (object, callback) => { |
| 2375 |
if (Array.isArray(object)) { |
| 2376 |
object.forEach(callback); |
| 2377 |
} else { |
| 2378 |
for (var key in object) { |
| 2379 |
if (object.hasOwnProperty(key)) { |
| 2380 |
callback(object[key], key); |
| 2381 |
} |
| 2382 |
} |
| 2383 |
} |
| 2384 |
}; |
| 2385 |
|
| 2386 |
/** |
| 2387 |
* Remove css classes |
| 2388 |
* |
| 2389 |
*/ |
| 2390 |
const removeClasses = (elmts, ...classes) => { |
| 2391 |
var norm_classes = classesArray(classes); |
| 2392 |
elmts = castAsArray(elmts); |
| 2393 |
elmts.map(el => { |
| 2394 |
norm_classes.map(cls => { |
| 2395 |
el.classList.remove(cls); |
| 2396 |
}); |
| 2397 |
}); |
| 2398 |
}; |
| 2399 |
|
| 2400 |
/** |
| 2401 |
* Return arguments |
| 2402 |
* |
| 2403 |
*/ |
| 2404 |
const classesArray = args => { |
| 2405 |
var classes = []; |
| 2406 |
iterate(args, _classes => { |
| 2407 |
if (typeof _classes === 'string') { |
| 2408 |
_classes = _classes.trim().split(/[\t\n\f\r\s]/); |
| 2409 |
} |
| 2410 |
if (Array.isArray(_classes)) { |
| 2411 |
classes = classes.concat(_classes); |
| 2412 |
} |
| 2413 |
}); |
| 2414 |
return classes.filter(Boolean); |
| 2415 |
}; |
| 2416 |
|
| 2417 |
/** |
| 2418 |
* Create an array from arg if it's not already an array |
| 2419 |
* |
| 2420 |
*/ |
| 2421 |
const castAsArray = arg => { |
| 2422 |
if (!Array.isArray(arg)) { |
| 2423 |
arg = [arg]; |
| 2424 |
} |
| 2425 |
return arg; |
| 2426 |
}; |
| 2427 |
|
| 2428 |
/** |
| 2429 |
* Get the index of an element amongst sibling nodes of the same type |
| 2430 |
* |
| 2431 |
*/ |
| 2432 |
const nodeIndex = (el, amongst) => { |
| 2433 |
if (!el) return -1; |
| 2434 |
amongst = amongst || el.nodeName; |
| 2435 |
var i = 0; |
| 2436 |
while (el = el.previousElementSibling) { |
| 2437 |
if (el.matches(amongst)) { |
| 2438 |
i++; |
| 2439 |
} |
| 2440 |
} |
| 2441 |
return i; |
| 2442 |
}; |
| 2443 |
|
| 2444 |
/** |
| 2445 |
* Plugin: "dropdown_input" (Tom Select) |
| 2446 |
* Copyright (c) contributors |
| 2447 |
* |
| 2448 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 2449 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 2450 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 2451 |
* |
| 2452 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 2453 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 2454 |
* ANY KIND, either express or implied. See the License for the specific language |
| 2455 |
* governing permissions and limitations under the License. |
| 2456 |
* |
| 2457 |
*/ |
| 2458 |
|
| 2459 |
function plugin () { |
| 2460 |
var self = this; |
| 2461 |
|
| 2462 |
/** |
| 2463 |
* Moves the caret to the specified index. |
| 2464 |
* |
| 2465 |
* The input must be moved by leaving it in place and moving the |
| 2466 |
* siblings, due to the fact that focus cannot be restored once lost |
| 2467 |
* on mobile webkit devices |
| 2468 |
* |
| 2469 |
*/ |
| 2470 |
self.hook('instead', 'setCaret', new_pos => { |
| 2471 |
if (self.settings.mode === 'single' || !self.control.contains(self.control_input)) { |
| 2472 |
new_pos = self.items.length; |
| 2473 |
} else { |
| 2474 |
new_pos = Math.max(0, Math.min(self.items.length, new_pos)); |
| 2475 |
if (new_pos != self.caretPos && !self.isPending) { |
| 2476 |
self.controlChildren().forEach((child, j) => { |
| 2477 |
if (j < new_pos) { |
| 2478 |
self.control_input.insertAdjacentElement('beforebegin', child); |
| 2479 |
} else { |
| 2480 |
self.control.appendChild(child); |
| 2481 |
} |
| 2482 |
}); |
| 2483 |
} |
| 2484 |
} |
| 2485 |
self.caretPos = new_pos; |
| 2486 |
}); |
| 2487 |
self.hook('instead', 'moveCaret', direction => { |
| 2488 |
if (!self.isFocused) return; |
| 2489 |
|
| 2490 |
// move caret before or after selected items |
| 2491 |
const last_active = self.getLastActive(direction); |
| 2492 |
if (last_active) { |
| 2493 |
const idx = nodeIndex(last_active); |
| 2494 |
self.setCaret(direction > 0 ? idx + 1 : idx); |
| 2495 |
self.setActiveItem(); |
| 2496 |
removeClasses(last_active, 'last-active'); |
| 2497 |
|
| 2498 |
// move caret left or right of current position |
| 2499 |
} else { |
| 2500 |
self.setCaret(self.caretPos + direction); |
| 2501 |
} |
| 2502 |
}); |
| 2503 |
} |
| 2504 |
|
| 2505 |
|
| 2506 |
//# sourceMappingURL=plugin.js.map |
| 2507 |
|
| 2508 |
|
| 2509 |
/***/ }, |
| 2510 |
|
| 2511 |
/***/ "./node_modules/tom-select/dist/esm/plugins/change_listener/plugin.js" |
| 2512 |
/*!****************************************************************************!*\ |
| 2513 |
!*** ./node_modules/tom-select/dist/esm/plugins/change_listener/plugin.js ***! |
| 2514 |
\****************************************************************************/ |
| 2515 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2516 |
|
| 2517 |
__webpack_require__.r(__webpack_exports__); |
| 2518 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2519 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 2520 |
/* harmony export */ }); |
| 2521 |
/** |
| 2522 |
* Tom Select v2.4.3 |
| 2523 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 2524 |
*/ |
| 2525 |
|
| 2526 |
/** |
| 2527 |
* Converts a scalar to its best string representation |
| 2528 |
* for hash keys and HTML attribute values. |
| 2529 |
* |
| 2530 |
* Transformations: |
| 2531 |
* 'str' -> 'str' |
| 2532 |
* null -> '' |
| 2533 |
* undefined -> '' |
| 2534 |
* true -> '1' |
| 2535 |
* false -> '0' |
| 2536 |
* 0 -> '0' |
| 2537 |
* 1 -> '1' |
| 2538 |
* |
| 2539 |
*/ |
| 2540 |
|
| 2541 |
/** |
| 2542 |
* Add event helper |
| 2543 |
* |
| 2544 |
*/ |
| 2545 |
const addEvent = (target, type, callback, options) => { |
| 2546 |
target.addEventListener(type, callback, options); |
| 2547 |
}; |
| 2548 |
|
| 2549 |
/** |
| 2550 |
* Plugin: "change_listener" (Tom Select) |
| 2551 |
* Copyright (c) contributors |
| 2552 |
* |
| 2553 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 2554 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 2555 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 2556 |
* |
| 2557 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 2558 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 2559 |
* ANY KIND, either express or implied. See the License for the specific language |
| 2560 |
* governing permissions and limitations under the License. |
| 2561 |
* |
| 2562 |
*/ |
| 2563 |
|
| 2564 |
function plugin () { |
| 2565 |
addEvent(this.input, 'change', () => { |
| 2566 |
this.sync(); |
| 2567 |
}); |
| 2568 |
} |
| 2569 |
|
| 2570 |
|
| 2571 |
//# sourceMappingURL=plugin.js.map |
| 2572 |
|
| 2573 |
|
| 2574 |
/***/ }, |
| 2575 |
|
| 2576 |
/***/ "./node_modules/tom-select/dist/esm/plugins/checkbox_options/plugin.js" |
| 2577 |
/*!*****************************************************************************!*\ |
| 2578 |
!*** ./node_modules/tom-select/dist/esm/plugins/checkbox_options/plugin.js ***! |
| 2579 |
\*****************************************************************************/ |
| 2580 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2581 |
|
| 2582 |
__webpack_require__.r(__webpack_exports__); |
| 2583 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2584 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 2585 |
/* harmony export */ }); |
| 2586 |
/** |
| 2587 |
* Tom Select v2.4.3 |
| 2588 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 2589 |
*/ |
| 2590 |
|
| 2591 |
/** |
| 2592 |
* Converts a scalar to its best string representation |
| 2593 |
* for hash keys and HTML attribute values. |
| 2594 |
* |
| 2595 |
* Transformations: |
| 2596 |
* 'str' -> 'str' |
| 2597 |
* null -> '' |
| 2598 |
* undefined -> '' |
| 2599 |
* true -> '1' |
| 2600 |
* false -> '0' |
| 2601 |
* 0 -> '0' |
| 2602 |
* 1 -> '1' |
| 2603 |
* |
| 2604 |
*/ |
| 2605 |
const hash_key = value => { |
| 2606 |
if (typeof value === 'undefined' || value === null) return null; |
| 2607 |
return get_hash(value); |
| 2608 |
}; |
| 2609 |
const get_hash = value => { |
| 2610 |
if (typeof value === 'boolean') return value ? '1' : '0'; |
| 2611 |
return value + ''; |
| 2612 |
}; |
| 2613 |
|
| 2614 |
/** |
| 2615 |
* Prevent default |
| 2616 |
* |
| 2617 |
*/ |
| 2618 |
const preventDefault = (evt, stop = false) => { |
| 2619 |
if (evt) { |
| 2620 |
evt.preventDefault(); |
| 2621 |
if (stop) { |
| 2622 |
evt.stopPropagation(); |
| 2623 |
} |
| 2624 |
} |
| 2625 |
}; |
| 2626 |
|
| 2627 |
/** |
| 2628 |
* Return a dom element from either a dom query string, jQuery object, a dom element or html string |
| 2629 |
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 |
| 2630 |
* |
| 2631 |
* param query should be {} |
| 2632 |
*/ |
| 2633 |
const getDom = query => { |
| 2634 |
if (query.jquery) { |
| 2635 |
return query[0]; |
| 2636 |
} |
| 2637 |
if (query instanceof HTMLElement) { |
| 2638 |
return query; |
| 2639 |
} |
| 2640 |
if (isHtmlString(query)) { |
| 2641 |
var tpl = document.createElement('template'); |
| 2642 |
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result |
| 2643 |
return tpl.content.firstChild; |
| 2644 |
} |
| 2645 |
return document.querySelector(query); |
| 2646 |
}; |
| 2647 |
const isHtmlString = arg => { |
| 2648 |
if (typeof arg === 'string' && arg.indexOf('<') > -1) { |
| 2649 |
return true; |
| 2650 |
} |
| 2651 |
return false; |
| 2652 |
}; |
| 2653 |
|
| 2654 |
/** |
| 2655 |
* Plugin: "checkbox_options" (Tom Select) |
| 2656 |
* Copyright (c) contributors |
| 2657 |
* |
| 2658 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 2659 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 2660 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 2661 |
* |
| 2662 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 2663 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 2664 |
* ANY KIND, either express or implied. See the License for the specific language |
| 2665 |
* governing permissions and limitations under the License. |
| 2666 |
* |
| 2667 |
*/ |
| 2668 |
|
| 2669 |
function plugin (userOptions) { |
| 2670 |
var self = this; |
| 2671 |
var orig_onOptionSelect = self.onOptionSelect; |
| 2672 |
self.settings.hideSelected = false; |
| 2673 |
const cbOptions = Object.assign({ |
| 2674 |
// so that the user may add different ones as well |
| 2675 |
className: "tomselect-checkbox", |
| 2676 |
// the following default to the historic plugin's values |
| 2677 |
checkedClassNames: undefined, |
| 2678 |
uncheckedClassNames: undefined |
| 2679 |
}, userOptions); |
| 2680 |
var UpdateChecked = function UpdateChecked(checkbox, toCheck) { |
| 2681 |
if (toCheck) { |
| 2682 |
checkbox.checked = true; |
| 2683 |
if (cbOptions.uncheckedClassNames) { |
| 2684 |
checkbox.classList.remove(...cbOptions.uncheckedClassNames); |
| 2685 |
} |
| 2686 |
if (cbOptions.checkedClassNames) { |
| 2687 |
checkbox.classList.add(...cbOptions.checkedClassNames); |
| 2688 |
} |
| 2689 |
} else { |
| 2690 |
checkbox.checked = false; |
| 2691 |
if (cbOptions.checkedClassNames) { |
| 2692 |
checkbox.classList.remove(...cbOptions.checkedClassNames); |
| 2693 |
} |
| 2694 |
if (cbOptions.uncheckedClassNames) { |
| 2695 |
checkbox.classList.add(...cbOptions.uncheckedClassNames); |
| 2696 |
} |
| 2697 |
} |
| 2698 |
}; |
| 2699 |
|
| 2700 |
// update the checkbox for an option |
| 2701 |
var UpdateCheckbox = function UpdateCheckbox(option) { |
| 2702 |
setTimeout(() => { |
| 2703 |
var checkbox = option.querySelector('input.' + cbOptions.className); |
| 2704 |
if (checkbox instanceof HTMLInputElement) { |
| 2705 |
UpdateChecked(checkbox, option.classList.contains('selected')); |
| 2706 |
} |
| 2707 |
}, 1); |
| 2708 |
}; |
| 2709 |
|
| 2710 |
// add checkbox to option template |
| 2711 |
self.hook('after', 'setupTemplates', () => { |
| 2712 |
var orig_render_option = self.settings.render.option; |
| 2713 |
self.settings.render.option = (data, escape_html) => { |
| 2714 |
var rendered = getDom(orig_render_option.call(self, data, escape_html)); |
| 2715 |
var checkbox = document.createElement('input'); |
| 2716 |
if (cbOptions.className) { |
| 2717 |
checkbox.classList.add(cbOptions.className); |
| 2718 |
} |
| 2719 |
checkbox.addEventListener('click', function (evt) { |
| 2720 |
preventDefault(evt); |
| 2721 |
}); |
| 2722 |
checkbox.type = 'checkbox'; |
| 2723 |
const hashed = hash_key(data[self.settings.valueField]); |
| 2724 |
UpdateChecked(checkbox, !!(hashed && self.items.indexOf(hashed) > -1)); |
| 2725 |
rendered.prepend(checkbox); |
| 2726 |
return rendered; |
| 2727 |
}; |
| 2728 |
}); |
| 2729 |
|
| 2730 |
// uncheck when item removed |
| 2731 |
self.on('item_remove', value => { |
| 2732 |
var option = self.getOption(value); |
| 2733 |
if (option) { |
| 2734 |
// if dropdown hasn't been opened yet, the option won't exist |
| 2735 |
option.classList.remove('selected'); // selected class won't be removed yet |
| 2736 |
UpdateCheckbox(option); |
| 2737 |
} |
| 2738 |
}); |
| 2739 |
|
| 2740 |
// check when item added |
| 2741 |
self.on('item_add', value => { |
| 2742 |
var option = self.getOption(value); |
| 2743 |
if (option) { |
| 2744 |
// if dropdown hasn't been opened yet, the option won't exist |
| 2745 |
UpdateCheckbox(option); |
| 2746 |
} |
| 2747 |
}); |
| 2748 |
|
| 2749 |
// remove items when selected option is clicked |
| 2750 |
self.hook('instead', 'onOptionSelect', (evt, option) => { |
| 2751 |
if (option.classList.contains('selected')) { |
| 2752 |
option.classList.remove('selected'); |
| 2753 |
self.removeItem(option.dataset.value); |
| 2754 |
self.refreshOptions(); |
| 2755 |
preventDefault(evt, true); |
| 2756 |
return; |
| 2757 |
} |
| 2758 |
orig_onOptionSelect.call(self, evt, option); |
| 2759 |
UpdateCheckbox(option); |
| 2760 |
}); |
| 2761 |
} |
| 2762 |
|
| 2763 |
|
| 2764 |
//# sourceMappingURL=plugin.js.map |
| 2765 |
|
| 2766 |
|
| 2767 |
/***/ }, |
| 2768 |
|
| 2769 |
/***/ "./node_modules/tom-select/dist/esm/plugins/clear_button/plugin.js" |
| 2770 |
/*!*************************************************************************!*\ |
| 2771 |
!*** ./node_modules/tom-select/dist/esm/plugins/clear_button/plugin.js ***! |
| 2772 |
\*************************************************************************/ |
| 2773 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2774 |
|
| 2775 |
__webpack_require__.r(__webpack_exports__); |
| 2776 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2777 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 2778 |
/* harmony export */ }); |
| 2779 |
/** |
| 2780 |
* Tom Select v2.4.3 |
| 2781 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 2782 |
*/ |
| 2783 |
|
| 2784 |
/** |
| 2785 |
* Return a dom element from either a dom query string, jQuery object, a dom element or html string |
| 2786 |
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 |
| 2787 |
* |
| 2788 |
* param query should be {} |
| 2789 |
*/ |
| 2790 |
const getDom = query => { |
| 2791 |
if (query.jquery) { |
| 2792 |
return query[0]; |
| 2793 |
} |
| 2794 |
if (query instanceof HTMLElement) { |
| 2795 |
return query; |
| 2796 |
} |
| 2797 |
if (isHtmlString(query)) { |
| 2798 |
var tpl = document.createElement('template'); |
| 2799 |
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result |
| 2800 |
return tpl.content.firstChild; |
| 2801 |
} |
| 2802 |
return document.querySelector(query); |
| 2803 |
}; |
| 2804 |
const isHtmlString = arg => { |
| 2805 |
if (typeof arg === 'string' && arg.indexOf('<') > -1) { |
| 2806 |
return true; |
| 2807 |
} |
| 2808 |
return false; |
| 2809 |
}; |
| 2810 |
|
| 2811 |
/** |
| 2812 |
* Plugin: "dropdown_header" (Tom Select) |
| 2813 |
* Copyright (c) contributors |
| 2814 |
* |
| 2815 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 2816 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 2817 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 2818 |
* |
| 2819 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 2820 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 2821 |
* ANY KIND, either express or implied. See the License for the specific language |
| 2822 |
* governing permissions and limitations under the License. |
| 2823 |
* |
| 2824 |
*/ |
| 2825 |
|
| 2826 |
function plugin (userOptions) { |
| 2827 |
const self = this; |
| 2828 |
const options = Object.assign({ |
| 2829 |
className: 'clear-button', |
| 2830 |
title: 'Clear All', |
| 2831 |
html: data => { |
| 2832 |
return `<div class="${data.className}" title="${data.title}">⨯</div>`; |
| 2833 |
} |
| 2834 |
}, userOptions); |
| 2835 |
self.on('initialize', () => { |
| 2836 |
var button = getDom(options.html(options)); |
| 2837 |
button.addEventListener('click', evt => { |
| 2838 |
if (self.isLocked) return; |
| 2839 |
self.clear(); |
| 2840 |
if (self.settings.mode === 'single' && self.settings.allowEmptyOption) { |
| 2841 |
self.addItem(''); |
| 2842 |
} |
| 2843 |
evt.preventDefault(); |
| 2844 |
evt.stopPropagation(); |
| 2845 |
}); |
| 2846 |
self.control.appendChild(button); |
| 2847 |
}); |
| 2848 |
} |
| 2849 |
|
| 2850 |
|
| 2851 |
//# sourceMappingURL=plugin.js.map |
| 2852 |
|
| 2853 |
|
| 2854 |
/***/ }, |
| 2855 |
|
| 2856 |
/***/ "./node_modules/tom-select/dist/esm/plugins/drag_drop/plugin.js" |
| 2857 |
/*!**********************************************************************!*\ |
| 2858 |
!*** ./node_modules/tom-select/dist/esm/plugins/drag_drop/plugin.js ***! |
| 2859 |
\**********************************************************************/ |
| 2860 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2861 |
|
| 2862 |
__webpack_require__.r(__webpack_exports__); |
| 2863 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2864 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 2865 |
/* harmony export */ }); |
| 2866 |
/** |
| 2867 |
* Tom Select v2.4.3 |
| 2868 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 2869 |
*/ |
| 2870 |
|
| 2871 |
/** |
| 2872 |
* Converts a scalar to its best string representation |
| 2873 |
* for hash keys and HTML attribute values. |
| 2874 |
* |
| 2875 |
* Transformations: |
| 2876 |
* 'str' -> 'str' |
| 2877 |
* null -> '' |
| 2878 |
* undefined -> '' |
| 2879 |
* true -> '1' |
| 2880 |
* false -> '0' |
| 2881 |
* 0 -> '0' |
| 2882 |
* 1 -> '1' |
| 2883 |
* |
| 2884 |
*/ |
| 2885 |
|
| 2886 |
/** |
| 2887 |
* Prevent default |
| 2888 |
* |
| 2889 |
*/ |
| 2890 |
const preventDefault = (evt, stop = false) => { |
| 2891 |
if (evt) { |
| 2892 |
evt.preventDefault(); |
| 2893 |
if (stop) { |
| 2894 |
evt.stopPropagation(); |
| 2895 |
} |
| 2896 |
} |
| 2897 |
}; |
| 2898 |
|
| 2899 |
/** |
| 2900 |
* Add event helper |
| 2901 |
* |
| 2902 |
*/ |
| 2903 |
const addEvent = (target, type, callback, options) => { |
| 2904 |
target.addEventListener(type, callback, options); |
| 2905 |
}; |
| 2906 |
|
| 2907 |
/** |
| 2908 |
* Iterates over arrays and hashes. |
| 2909 |
* |
| 2910 |
* ``` |
| 2911 |
* iterate(this.items, function(item, id) { |
| 2912 |
* // invoked for each item |
| 2913 |
* }); |
| 2914 |
* ``` |
| 2915 |
* |
| 2916 |
*/ |
| 2917 |
const iterate = (object, callback) => { |
| 2918 |
if (Array.isArray(object)) { |
| 2919 |
object.forEach(callback); |
| 2920 |
} else { |
| 2921 |
for (var key in object) { |
| 2922 |
if (object.hasOwnProperty(key)) { |
| 2923 |
callback(object[key], key); |
| 2924 |
} |
| 2925 |
} |
| 2926 |
} |
| 2927 |
}; |
| 2928 |
|
| 2929 |
/** |
| 2930 |
* Return a dom element from either a dom query string, jQuery object, a dom element or html string |
| 2931 |
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 |
| 2932 |
* |
| 2933 |
* param query should be {} |
| 2934 |
*/ |
| 2935 |
const getDom = query => { |
| 2936 |
if (query.jquery) { |
| 2937 |
return query[0]; |
| 2938 |
} |
| 2939 |
if (query instanceof HTMLElement) { |
| 2940 |
return query; |
| 2941 |
} |
| 2942 |
if (isHtmlString(query)) { |
| 2943 |
var tpl = document.createElement('template'); |
| 2944 |
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result |
| 2945 |
return tpl.content.firstChild; |
| 2946 |
} |
| 2947 |
return document.querySelector(query); |
| 2948 |
}; |
| 2949 |
const isHtmlString = arg => { |
| 2950 |
if (typeof arg === 'string' && arg.indexOf('<') > -1) { |
| 2951 |
return true; |
| 2952 |
} |
| 2953 |
return false; |
| 2954 |
}; |
| 2955 |
|
| 2956 |
/** |
| 2957 |
* Set attributes of an element |
| 2958 |
* |
| 2959 |
*/ |
| 2960 |
const setAttr = (el, attrs) => { |
| 2961 |
iterate(attrs, (val, attr) => { |
| 2962 |
if (val == null) { |
| 2963 |
el.removeAttribute(attr); |
| 2964 |
} else { |
| 2965 |
el.setAttribute(attr, '' + val); |
| 2966 |
} |
| 2967 |
}); |
| 2968 |
}; |
| 2969 |
|
| 2970 |
/** |
| 2971 |
* Plugin: "drag_drop" (Tom Select) |
| 2972 |
* Copyright (c) contributors |
| 2973 |
* |
| 2974 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 2975 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 2976 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 2977 |
* |
| 2978 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 2979 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 2980 |
* ANY KIND, either express or implied. See the License for the specific language |
| 2981 |
* governing permissions and limitations under the License. |
| 2982 |
* |
| 2983 |
*/ |
| 2984 |
|
| 2985 |
const insertAfter = (referenceNode, newNode) => { |
| 2986 |
var _referenceNode$parent; |
| 2987 |
(_referenceNode$parent = referenceNode.parentNode) == null || _referenceNode$parent.insertBefore(newNode, referenceNode.nextSibling); |
| 2988 |
}; |
| 2989 |
const insertBefore = (referenceNode, newNode) => { |
| 2990 |
var _referenceNode$parent2; |
| 2991 |
(_referenceNode$parent2 = referenceNode.parentNode) == null || _referenceNode$parent2.insertBefore(newNode, referenceNode); |
| 2992 |
}; |
| 2993 |
const isBefore = (referenceNode, newNode) => { |
| 2994 |
do { |
| 2995 |
var _newNode; |
| 2996 |
newNode = (_newNode = newNode) == null ? void 0 : _newNode.previousElementSibling; |
| 2997 |
if (referenceNode == newNode) { |
| 2998 |
return true; |
| 2999 |
} |
| 3000 |
} while (newNode && newNode.previousElementSibling); |
| 3001 |
return false; |
| 3002 |
}; |
| 3003 |
function plugin () { |
| 3004 |
var self = this; |
| 3005 |
if (self.settings.mode !== 'multi') return; |
| 3006 |
var orig_lock = self.lock; |
| 3007 |
var orig_unlock = self.unlock; |
| 3008 |
let sortable = true; |
| 3009 |
let drag_item; |
| 3010 |
|
| 3011 |
/** |
| 3012 |
* Add draggable attribute to item |
| 3013 |
*/ |
| 3014 |
self.hook('after', 'setupTemplates', () => { |
| 3015 |
var orig_render_item = self.settings.render.item; |
| 3016 |
self.settings.render.item = (data, escape) => { |
| 3017 |
const item = getDom(orig_render_item.call(self, data, escape)); |
| 3018 |
setAttr(item, { |
| 3019 |
'draggable': 'true' |
| 3020 |
}); |
| 3021 |
|
| 3022 |
// prevent doc_mousedown (see tom-select.ts) |
| 3023 |
const mousedown = evt => { |
| 3024 |
if (!sortable) preventDefault(evt); |
| 3025 |
evt.stopPropagation(); |
| 3026 |
}; |
| 3027 |
const dragStart = evt => { |
| 3028 |
drag_item = item; |
| 3029 |
setTimeout(() => { |
| 3030 |
item.classList.add('ts-dragging'); |
| 3031 |
}, 0); |
| 3032 |
}; |
| 3033 |
const dragOver = evt => { |
| 3034 |
evt.preventDefault(); |
| 3035 |
item.classList.add('ts-drag-over'); |
| 3036 |
moveitem(item, drag_item); |
| 3037 |
}; |
| 3038 |
const dragLeave = () => { |
| 3039 |
item.classList.remove('ts-drag-over'); |
| 3040 |
}; |
| 3041 |
const moveitem = (targetitem, dragitem) => { |
| 3042 |
if (dragitem === undefined) return; |
| 3043 |
if (isBefore(dragitem, item)) { |
| 3044 |
insertAfter(targetitem, dragitem); |
| 3045 |
} else { |
| 3046 |
insertBefore(targetitem, dragitem); |
| 3047 |
} |
| 3048 |
}; |
| 3049 |
const dragend = () => { |
| 3050 |
var _drag_item; |
| 3051 |
document.querySelectorAll('.ts-drag-over').forEach(el => el.classList.remove('ts-drag-over')); |
| 3052 |
(_drag_item = drag_item) == null || _drag_item.classList.remove('ts-dragging'); |
| 3053 |
drag_item = undefined; |
| 3054 |
var values = []; |
| 3055 |
self.control.querySelectorAll(`[data-value]`).forEach(el => { |
| 3056 |
if (el.dataset.value) { |
| 3057 |
let value = el.dataset.value; |
| 3058 |
if (value) { |
| 3059 |
values.push(value); |
| 3060 |
} |
| 3061 |
} |
| 3062 |
}); |
| 3063 |
self.setValue(values); |
| 3064 |
}; |
| 3065 |
addEvent(item, 'mousedown', mousedown); |
| 3066 |
addEvent(item, 'dragstart', dragStart); |
| 3067 |
addEvent(item, 'dragenter', dragOver); |
| 3068 |
addEvent(item, 'dragover', dragOver); |
| 3069 |
addEvent(item, 'dragleave', dragLeave); |
| 3070 |
addEvent(item, 'dragend', dragend); |
| 3071 |
return item; |
| 3072 |
}; |
| 3073 |
}); |
| 3074 |
self.hook('instead', 'lock', () => { |
| 3075 |
sortable = false; |
| 3076 |
return orig_lock.call(self); |
| 3077 |
}); |
| 3078 |
self.hook('instead', 'unlock', () => { |
| 3079 |
sortable = true; |
| 3080 |
return orig_unlock.call(self); |
| 3081 |
}); |
| 3082 |
} |
| 3083 |
|
| 3084 |
|
| 3085 |
//# sourceMappingURL=plugin.js.map |
| 3086 |
|
| 3087 |
|
| 3088 |
/***/ }, |
| 3089 |
|
| 3090 |
/***/ "./node_modules/tom-select/dist/esm/plugins/dropdown_header/plugin.js" |
| 3091 |
/*!****************************************************************************!*\ |
| 3092 |
!*** ./node_modules/tom-select/dist/esm/plugins/dropdown_header/plugin.js ***! |
| 3093 |
\****************************************************************************/ |
| 3094 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3095 |
|
| 3096 |
__webpack_require__.r(__webpack_exports__); |
| 3097 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3098 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 3099 |
/* harmony export */ }); |
| 3100 |
/** |
| 3101 |
* Tom Select v2.4.3 |
| 3102 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3103 |
*/ |
| 3104 |
|
| 3105 |
/** |
| 3106 |
* Converts a scalar to its best string representation |
| 3107 |
* for hash keys and HTML attribute values. |
| 3108 |
* |
| 3109 |
* Transformations: |
| 3110 |
* 'str' -> 'str' |
| 3111 |
* null -> '' |
| 3112 |
* undefined -> '' |
| 3113 |
* true -> '1' |
| 3114 |
* false -> '0' |
| 3115 |
* 0 -> '0' |
| 3116 |
* 1 -> '1' |
| 3117 |
* |
| 3118 |
*/ |
| 3119 |
|
| 3120 |
/** |
| 3121 |
* Prevent default |
| 3122 |
* |
| 3123 |
*/ |
| 3124 |
const preventDefault = (evt, stop = false) => { |
| 3125 |
if (evt) { |
| 3126 |
evt.preventDefault(); |
| 3127 |
if (stop) { |
| 3128 |
evt.stopPropagation(); |
| 3129 |
} |
| 3130 |
} |
| 3131 |
}; |
| 3132 |
|
| 3133 |
/** |
| 3134 |
* Return a dom element from either a dom query string, jQuery object, a dom element or html string |
| 3135 |
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 |
| 3136 |
* |
| 3137 |
* param query should be {} |
| 3138 |
*/ |
| 3139 |
const getDom = query => { |
| 3140 |
if (query.jquery) { |
| 3141 |
return query[0]; |
| 3142 |
} |
| 3143 |
if (query instanceof HTMLElement) { |
| 3144 |
return query; |
| 3145 |
} |
| 3146 |
if (isHtmlString(query)) { |
| 3147 |
var tpl = document.createElement('template'); |
| 3148 |
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result |
| 3149 |
return tpl.content.firstChild; |
| 3150 |
} |
| 3151 |
return document.querySelector(query); |
| 3152 |
}; |
| 3153 |
const isHtmlString = arg => { |
| 3154 |
if (typeof arg === 'string' && arg.indexOf('<') > -1) { |
| 3155 |
return true; |
| 3156 |
} |
| 3157 |
return false; |
| 3158 |
}; |
| 3159 |
|
| 3160 |
/** |
| 3161 |
* Plugin: "dropdown_header" (Tom Select) |
| 3162 |
* Copyright (c) contributors |
| 3163 |
* |
| 3164 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 3165 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 3166 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3167 |
* |
| 3168 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 3169 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 3170 |
* ANY KIND, either express or implied. See the License for the specific language |
| 3171 |
* governing permissions and limitations under the License. |
| 3172 |
* |
| 3173 |
*/ |
| 3174 |
|
| 3175 |
function plugin (userOptions) { |
| 3176 |
const self = this; |
| 3177 |
const options = Object.assign({ |
| 3178 |
title: 'Untitled', |
| 3179 |
headerClass: 'dropdown-header', |
| 3180 |
titleRowClass: 'dropdown-header-title', |
| 3181 |
labelClass: 'dropdown-header-label', |
| 3182 |
closeClass: 'dropdown-header-close', |
| 3183 |
html: data => { |
| 3184 |
return '<div class="' + data.headerClass + '">' + '<div class="' + data.titleRowClass + '">' + '<span class="' + data.labelClass + '">' + data.title + '</span>' + '<a class="' + data.closeClass + '">×</a>' + '</div>' + '</div>'; |
| 3185 |
} |
| 3186 |
}, userOptions); |
| 3187 |
self.on('initialize', () => { |
| 3188 |
var header = getDom(options.html(options)); |
| 3189 |
var close_link = header.querySelector('.' + options.closeClass); |
| 3190 |
if (close_link) { |
| 3191 |
close_link.addEventListener('click', evt => { |
| 3192 |
preventDefault(evt, true); |
| 3193 |
self.close(); |
| 3194 |
}); |
| 3195 |
} |
| 3196 |
self.dropdown.insertBefore(header, self.dropdown.firstChild); |
| 3197 |
}); |
| 3198 |
} |
| 3199 |
|
| 3200 |
|
| 3201 |
//# sourceMappingURL=plugin.js.map |
| 3202 |
|
| 3203 |
|
| 3204 |
/***/ }, |
| 3205 |
|
| 3206 |
/***/ "./node_modules/tom-select/dist/esm/plugins/dropdown_input/plugin.js" |
| 3207 |
/*!***************************************************************************!*\ |
| 3208 |
!*** ./node_modules/tom-select/dist/esm/plugins/dropdown_input/plugin.js ***! |
| 3209 |
\***************************************************************************/ |
| 3210 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3211 |
|
| 3212 |
__webpack_require__.r(__webpack_exports__); |
| 3213 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3214 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 3215 |
/* harmony export */ }); |
| 3216 |
/** |
| 3217 |
* Tom Select v2.4.3 |
| 3218 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3219 |
*/ |
| 3220 |
|
| 3221 |
const KEY_ESC = 27; |
| 3222 |
const KEY_TAB = 9; |
| 3223 |
// ctrl key or apple key for ma |
| 3224 |
|
| 3225 |
/** |
| 3226 |
* Converts a scalar to its best string representation |
| 3227 |
* for hash keys and HTML attribute values. |
| 3228 |
* |
| 3229 |
* Transformations: |
| 3230 |
* 'str' -> 'str' |
| 3231 |
* null -> '' |
| 3232 |
* undefined -> '' |
| 3233 |
* true -> '1' |
| 3234 |
* false -> '0' |
| 3235 |
* 0 -> '0' |
| 3236 |
* 1 -> '1' |
| 3237 |
* |
| 3238 |
*/ |
| 3239 |
|
| 3240 |
/** |
| 3241 |
* Prevent default |
| 3242 |
* |
| 3243 |
*/ |
| 3244 |
const preventDefault = (evt, stop = false) => { |
| 3245 |
if (evt) { |
| 3246 |
evt.preventDefault(); |
| 3247 |
if (stop) { |
| 3248 |
evt.stopPropagation(); |
| 3249 |
} |
| 3250 |
} |
| 3251 |
}; |
| 3252 |
|
| 3253 |
/** |
| 3254 |
* Add event helper |
| 3255 |
* |
| 3256 |
*/ |
| 3257 |
const addEvent = (target, type, callback, options) => { |
| 3258 |
target.addEventListener(type, callback, options); |
| 3259 |
}; |
| 3260 |
|
| 3261 |
/** |
| 3262 |
* Iterates over arrays and hashes. |
| 3263 |
* |
| 3264 |
* ``` |
| 3265 |
* iterate(this.items, function(item, id) { |
| 3266 |
* // invoked for each item |
| 3267 |
* }); |
| 3268 |
* ``` |
| 3269 |
* |
| 3270 |
*/ |
| 3271 |
const iterate = (object, callback) => { |
| 3272 |
if (Array.isArray(object)) { |
| 3273 |
object.forEach(callback); |
| 3274 |
} else { |
| 3275 |
for (var key in object) { |
| 3276 |
if (object.hasOwnProperty(key)) { |
| 3277 |
callback(object[key], key); |
| 3278 |
} |
| 3279 |
} |
| 3280 |
} |
| 3281 |
}; |
| 3282 |
|
| 3283 |
/** |
| 3284 |
* Return a dom element from either a dom query string, jQuery object, a dom element or html string |
| 3285 |
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 |
| 3286 |
* |
| 3287 |
* param query should be {} |
| 3288 |
*/ |
| 3289 |
const getDom = query => { |
| 3290 |
if (query.jquery) { |
| 3291 |
return query[0]; |
| 3292 |
} |
| 3293 |
if (query instanceof HTMLElement) { |
| 3294 |
return query; |
| 3295 |
} |
| 3296 |
if (isHtmlString(query)) { |
| 3297 |
var tpl = document.createElement('template'); |
| 3298 |
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result |
| 3299 |
return tpl.content.firstChild; |
| 3300 |
} |
| 3301 |
return document.querySelector(query); |
| 3302 |
}; |
| 3303 |
const isHtmlString = arg => { |
| 3304 |
if (typeof arg === 'string' && arg.indexOf('<') > -1) { |
| 3305 |
return true; |
| 3306 |
} |
| 3307 |
return false; |
| 3308 |
}; |
| 3309 |
|
| 3310 |
/** |
| 3311 |
* Add css classes |
| 3312 |
* |
| 3313 |
*/ |
| 3314 |
const addClasses = (elmts, ...classes) => { |
| 3315 |
var norm_classes = classesArray(classes); |
| 3316 |
elmts = castAsArray(elmts); |
| 3317 |
elmts.map(el => { |
| 3318 |
norm_classes.map(cls => { |
| 3319 |
el.classList.add(cls); |
| 3320 |
}); |
| 3321 |
}); |
| 3322 |
}; |
| 3323 |
|
| 3324 |
/** |
| 3325 |
* Return arguments |
| 3326 |
* |
| 3327 |
*/ |
| 3328 |
const classesArray = args => { |
| 3329 |
var classes = []; |
| 3330 |
iterate(args, _classes => { |
| 3331 |
if (typeof _classes === 'string') { |
| 3332 |
_classes = _classes.trim().split(/[\t\n\f\r\s]/); |
| 3333 |
} |
| 3334 |
if (Array.isArray(_classes)) { |
| 3335 |
classes = classes.concat(_classes); |
| 3336 |
} |
| 3337 |
}); |
| 3338 |
return classes.filter(Boolean); |
| 3339 |
}; |
| 3340 |
|
| 3341 |
/** |
| 3342 |
* Create an array from arg if it's not already an array |
| 3343 |
* |
| 3344 |
*/ |
| 3345 |
const castAsArray = arg => { |
| 3346 |
if (!Array.isArray(arg)) { |
| 3347 |
arg = [arg]; |
| 3348 |
} |
| 3349 |
return arg; |
| 3350 |
}; |
| 3351 |
|
| 3352 |
/** |
| 3353 |
* Plugin: "dropdown_input" (Tom Select) |
| 3354 |
* Copyright (c) contributors |
| 3355 |
* |
| 3356 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 3357 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 3358 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3359 |
* |
| 3360 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 3361 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 3362 |
* ANY KIND, either express or implied. See the License for the specific language |
| 3363 |
* governing permissions and limitations under the License. |
| 3364 |
* |
| 3365 |
*/ |
| 3366 |
|
| 3367 |
function plugin () { |
| 3368 |
const self = this; |
| 3369 |
self.settings.shouldOpen = true; // make sure the input is shown even if there are no options to display in the dropdown |
| 3370 |
|
| 3371 |
self.hook('before', 'setup', () => { |
| 3372 |
self.focus_node = self.control; |
| 3373 |
addClasses(self.control_input, 'dropdown-input'); |
| 3374 |
const div = getDom('<div class="dropdown-input-wrap">'); |
| 3375 |
div.append(self.control_input); |
| 3376 |
self.dropdown.insertBefore(div, self.dropdown.firstChild); |
| 3377 |
|
| 3378 |
// set a placeholder in the select control |
| 3379 |
const placeholder = getDom('<input class="items-placeholder" tabindex="-1" />'); |
| 3380 |
placeholder.placeholder = self.settings.placeholder || ''; |
| 3381 |
self.control.append(placeholder); |
| 3382 |
}); |
| 3383 |
self.on('initialize', () => { |
| 3384 |
// set tabIndex on control to -1, otherwise [shift+tab] will put focus right back on control_input |
| 3385 |
self.control_input.addEventListener('keydown', evt => { |
| 3386 |
//addEvent(self.control_input,'keydown' as const,(evt:KeyboardEvent) =>{ |
| 3387 |
switch (evt.keyCode) { |
| 3388 |
case KEY_ESC: |
| 3389 |
if (self.isOpen) { |
| 3390 |
preventDefault(evt, true); |
| 3391 |
self.close(); |
| 3392 |
} |
| 3393 |
self.clearActiveItems(); |
| 3394 |
return; |
| 3395 |
case KEY_TAB: |
| 3396 |
self.focus_node.tabIndex = -1; |
| 3397 |
break; |
| 3398 |
} |
| 3399 |
return self.onKeyDown.call(self, evt); |
| 3400 |
}); |
| 3401 |
self.on('blur', () => { |
| 3402 |
self.focus_node.tabIndex = self.isDisabled ? -1 : self.tabIndex; |
| 3403 |
}); |
| 3404 |
|
| 3405 |
// give the control_input focus when the dropdown is open |
| 3406 |
self.on('dropdown_open', () => { |
| 3407 |
self.control_input.focus(); |
| 3408 |
}); |
| 3409 |
|
| 3410 |
// prevent onBlur from closing when focus is on the control_input |
| 3411 |
const orig_onBlur = self.onBlur; |
| 3412 |
self.hook('instead', 'onBlur', evt => { |
| 3413 |
if (evt && evt.relatedTarget == self.control_input) return; |
| 3414 |
return orig_onBlur.call(self); |
| 3415 |
}); |
| 3416 |
addEvent(self.control_input, 'blur', () => self.onBlur()); |
| 3417 |
|
| 3418 |
// return focus to control to allow further keyboard input |
| 3419 |
self.hook('before', 'close', () => { |
| 3420 |
if (!self.isOpen) return; |
| 3421 |
self.focus_node.focus({ |
| 3422 |
preventScroll: true |
| 3423 |
}); |
| 3424 |
}); |
| 3425 |
}); |
| 3426 |
} |
| 3427 |
|
| 3428 |
|
| 3429 |
//# sourceMappingURL=plugin.js.map |
| 3430 |
|
| 3431 |
|
| 3432 |
/***/ }, |
| 3433 |
|
| 3434 |
/***/ "./node_modules/tom-select/dist/esm/plugins/input_autogrow/plugin.js" |
| 3435 |
/*!***************************************************************************!*\ |
| 3436 |
!*** ./node_modules/tom-select/dist/esm/plugins/input_autogrow/plugin.js ***! |
| 3437 |
\***************************************************************************/ |
| 3438 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3439 |
|
| 3440 |
__webpack_require__.r(__webpack_exports__); |
| 3441 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3442 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 3443 |
/* harmony export */ }); |
| 3444 |
/** |
| 3445 |
* Tom Select v2.4.3 |
| 3446 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3447 |
*/ |
| 3448 |
|
| 3449 |
/** |
| 3450 |
* Converts a scalar to its best string representation |
| 3451 |
* for hash keys and HTML attribute values. |
| 3452 |
* |
| 3453 |
* Transformations: |
| 3454 |
* 'str' -> 'str' |
| 3455 |
* null -> '' |
| 3456 |
* undefined -> '' |
| 3457 |
* true -> '1' |
| 3458 |
* false -> '0' |
| 3459 |
* 0 -> '0' |
| 3460 |
* 1 -> '1' |
| 3461 |
* |
| 3462 |
*/ |
| 3463 |
|
| 3464 |
/** |
| 3465 |
* Add event helper |
| 3466 |
* |
| 3467 |
*/ |
| 3468 |
const addEvent = (target, type, callback, options) => { |
| 3469 |
target.addEventListener(type, callback, options); |
| 3470 |
}; |
| 3471 |
|
| 3472 |
/** |
| 3473 |
* Plugin: "input_autogrow" (Tom Select) |
| 3474 |
* |
| 3475 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 3476 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 3477 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3478 |
* |
| 3479 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 3480 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 3481 |
* ANY KIND, either express or implied. See the License for the specific language |
| 3482 |
* governing permissions and limitations under the License. |
| 3483 |
* |
| 3484 |
*/ |
| 3485 |
|
| 3486 |
function plugin () { |
| 3487 |
var self = this; |
| 3488 |
self.on('initialize', () => { |
| 3489 |
var test_input = document.createElement('span'); |
| 3490 |
var control = self.control_input; |
| 3491 |
test_input.style.cssText = 'position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; '; |
| 3492 |
self.wrapper.appendChild(test_input); |
| 3493 |
var transfer_styles = ['letterSpacing', 'fontSize', 'fontFamily', 'fontWeight', 'textTransform']; |
| 3494 |
for (const style_name of transfer_styles) { |
| 3495 |
// @ts-ignore TS7015 https://stackoverflow.com/a/50506154/697576 |
| 3496 |
test_input.style[style_name] = control.style[style_name]; |
| 3497 |
} |
| 3498 |
|
| 3499 |
/** |
| 3500 |
* Set the control width |
| 3501 |
* |
| 3502 |
*/ |
| 3503 |
var resize = () => { |
| 3504 |
test_input.textContent = control.value; |
| 3505 |
control.style.width = test_input.clientWidth + 'px'; |
| 3506 |
}; |
| 3507 |
resize(); |
| 3508 |
self.on('update item_add item_remove', resize); |
| 3509 |
addEvent(control, 'input', resize); |
| 3510 |
addEvent(control, 'keyup', resize); |
| 3511 |
addEvent(control, 'blur', resize); |
| 3512 |
addEvent(control, 'update', resize); |
| 3513 |
}); |
| 3514 |
} |
| 3515 |
|
| 3516 |
|
| 3517 |
//# sourceMappingURL=plugin.js.map |
| 3518 |
|
| 3519 |
|
| 3520 |
/***/ }, |
| 3521 |
|
| 3522 |
/***/ "./node_modules/tom-select/dist/esm/plugins/no_active_items/plugin.js" |
| 3523 |
/*!****************************************************************************!*\ |
| 3524 |
!*** ./node_modules/tom-select/dist/esm/plugins/no_active_items/plugin.js ***! |
| 3525 |
\****************************************************************************/ |
| 3526 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3527 |
|
| 3528 |
__webpack_require__.r(__webpack_exports__); |
| 3529 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3530 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 3531 |
/* harmony export */ }); |
| 3532 |
/** |
| 3533 |
* Tom Select v2.4.3 |
| 3534 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3535 |
*/ |
| 3536 |
|
| 3537 |
/** |
| 3538 |
* Plugin: "no_active_items" (Tom Select) |
| 3539 |
* |
| 3540 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 3541 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 3542 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3543 |
* |
| 3544 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 3545 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 3546 |
* ANY KIND, either express or implied. See the License for the specific language |
| 3547 |
* governing permissions and limitations under the License. |
| 3548 |
* |
| 3549 |
*/ |
| 3550 |
|
| 3551 |
function plugin () { |
| 3552 |
this.hook('instead', 'setActiveItem', () => {}); |
| 3553 |
this.hook('instead', 'selectAll', () => {}); |
| 3554 |
} |
| 3555 |
|
| 3556 |
|
| 3557 |
//# sourceMappingURL=plugin.js.map |
| 3558 |
|
| 3559 |
|
| 3560 |
/***/ }, |
| 3561 |
|
| 3562 |
/***/ "./node_modules/tom-select/dist/esm/plugins/no_backspace_delete/plugin.js" |
| 3563 |
/*!********************************************************************************!*\ |
| 3564 |
!*** ./node_modules/tom-select/dist/esm/plugins/no_backspace_delete/plugin.js ***! |
| 3565 |
\********************************************************************************/ |
| 3566 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3567 |
|
| 3568 |
__webpack_require__.r(__webpack_exports__); |
| 3569 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3570 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 3571 |
/* harmony export */ }); |
| 3572 |
/** |
| 3573 |
* Tom Select v2.4.3 |
| 3574 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3575 |
*/ |
| 3576 |
|
| 3577 |
/** |
| 3578 |
* Plugin: "input_autogrow" (Tom Select) |
| 3579 |
* |
| 3580 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 3581 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 3582 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3583 |
* |
| 3584 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 3585 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 3586 |
* ANY KIND, either express or implied. See the License for the specific language |
| 3587 |
* governing permissions and limitations under the License. |
| 3588 |
* |
| 3589 |
*/ |
| 3590 |
|
| 3591 |
function plugin () { |
| 3592 |
var self = this; |
| 3593 |
var orig_deleteSelection = self.deleteSelection; |
| 3594 |
this.hook('instead', 'deleteSelection', evt => { |
| 3595 |
if (self.activeItems.length) { |
| 3596 |
return orig_deleteSelection.call(self, evt); |
| 3597 |
} |
| 3598 |
return false; |
| 3599 |
}); |
| 3600 |
} |
| 3601 |
|
| 3602 |
|
| 3603 |
//# sourceMappingURL=plugin.js.map |
| 3604 |
|
| 3605 |
|
| 3606 |
/***/ }, |
| 3607 |
|
| 3608 |
/***/ "./node_modules/tom-select/dist/esm/plugins/optgroup_columns/plugin.js" |
| 3609 |
/*!*****************************************************************************!*\ |
| 3610 |
!*** ./node_modules/tom-select/dist/esm/plugins/optgroup_columns/plugin.js ***! |
| 3611 |
\*****************************************************************************/ |
| 3612 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3613 |
|
| 3614 |
__webpack_require__.r(__webpack_exports__); |
| 3615 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3616 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 3617 |
/* harmony export */ }); |
| 3618 |
/** |
| 3619 |
* Tom Select v2.4.3 |
| 3620 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3621 |
*/ |
| 3622 |
|
| 3623 |
const KEY_LEFT = 37; |
| 3624 |
const KEY_RIGHT = 39; |
| 3625 |
// ctrl key or apple key for ma |
| 3626 |
|
| 3627 |
/** |
| 3628 |
* Get the closest node to the evt.target matching the selector |
| 3629 |
* Stops at wrapper |
| 3630 |
* |
| 3631 |
*/ |
| 3632 |
const parentMatch = (target, selector, wrapper) => { |
| 3633 |
while (target && target.matches) { |
| 3634 |
if (target.matches(selector)) { |
| 3635 |
return target; |
| 3636 |
} |
| 3637 |
target = target.parentNode; |
| 3638 |
} |
| 3639 |
}; |
| 3640 |
|
| 3641 |
/** |
| 3642 |
* Get the index of an element amongst sibling nodes of the same type |
| 3643 |
* |
| 3644 |
*/ |
| 3645 |
const nodeIndex = (el, amongst) => { |
| 3646 |
if (!el) return -1; |
| 3647 |
amongst = amongst || el.nodeName; |
| 3648 |
var i = 0; |
| 3649 |
while (el = el.previousElementSibling) { |
| 3650 |
if (el.matches(amongst)) { |
| 3651 |
i++; |
| 3652 |
} |
| 3653 |
} |
| 3654 |
return i; |
| 3655 |
}; |
| 3656 |
|
| 3657 |
/** |
| 3658 |
* Plugin: "optgroup_columns" (Tom Select.js) |
| 3659 |
* Copyright (c) contributors |
| 3660 |
* |
| 3661 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 3662 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 3663 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3664 |
* |
| 3665 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 3666 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 3667 |
* ANY KIND, either express or implied. See the License for the specific language |
| 3668 |
* governing permissions and limitations under the License. |
| 3669 |
* |
| 3670 |
*/ |
| 3671 |
|
| 3672 |
function plugin () { |
| 3673 |
var self = this; |
| 3674 |
var orig_keydown = self.onKeyDown; |
| 3675 |
self.hook('instead', 'onKeyDown', evt => { |
| 3676 |
var index, option, options, optgroup; |
| 3677 |
if (!self.isOpen || !(evt.keyCode === KEY_LEFT || evt.keyCode === KEY_RIGHT)) { |
| 3678 |
return orig_keydown.call(self, evt); |
| 3679 |
} |
| 3680 |
self.ignoreHover = true; |
| 3681 |
optgroup = parentMatch(self.activeOption, '[data-group]'); |
| 3682 |
index = nodeIndex(self.activeOption, '[data-selectable]'); |
| 3683 |
if (!optgroup) { |
| 3684 |
return; |
| 3685 |
} |
| 3686 |
if (evt.keyCode === KEY_LEFT) { |
| 3687 |
optgroup = optgroup.previousSibling; |
| 3688 |
} else { |
| 3689 |
optgroup = optgroup.nextSibling; |
| 3690 |
} |
| 3691 |
if (!optgroup) { |
| 3692 |
return; |
| 3693 |
} |
| 3694 |
options = optgroup.querySelectorAll('[data-selectable]'); |
| 3695 |
option = options[Math.min(options.length - 1, index)]; |
| 3696 |
if (option) { |
| 3697 |
self.setActiveOption(option); |
| 3698 |
} |
| 3699 |
}); |
| 3700 |
} |
| 3701 |
|
| 3702 |
|
| 3703 |
//# sourceMappingURL=plugin.js.map |
| 3704 |
|
| 3705 |
|
| 3706 |
/***/ }, |
| 3707 |
|
| 3708 |
/***/ "./node_modules/tom-select/dist/esm/plugins/remove_button/plugin.js" |
| 3709 |
/*!**************************************************************************!*\ |
| 3710 |
!*** ./node_modules/tom-select/dist/esm/plugins/remove_button/plugin.js ***! |
| 3711 |
\**************************************************************************/ |
| 3712 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3713 |
|
| 3714 |
__webpack_require__.r(__webpack_exports__); |
| 3715 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3716 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 3717 |
/* harmony export */ }); |
| 3718 |
/** |
| 3719 |
* Tom Select v2.4.3 |
| 3720 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3721 |
*/ |
| 3722 |
|
| 3723 |
/** |
| 3724 |
* Converts a scalar to its best string representation |
| 3725 |
* for hash keys and HTML attribute values. |
| 3726 |
* |
| 3727 |
* Transformations: |
| 3728 |
* 'str' -> 'str' |
| 3729 |
* null -> '' |
| 3730 |
* undefined -> '' |
| 3731 |
* true -> '1' |
| 3732 |
* false -> '0' |
| 3733 |
* 0 -> '0' |
| 3734 |
* 1 -> '1' |
| 3735 |
* |
| 3736 |
*/ |
| 3737 |
|
| 3738 |
/** |
| 3739 |
* Escapes a string for use within HTML. |
| 3740 |
* |
| 3741 |
*/ |
| 3742 |
const escape_html = str => { |
| 3743 |
return (str + '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); |
| 3744 |
}; |
| 3745 |
|
| 3746 |
/** |
| 3747 |
* Prevent default |
| 3748 |
* |
| 3749 |
*/ |
| 3750 |
const preventDefault = (evt, stop = false) => { |
| 3751 |
if (evt) { |
| 3752 |
evt.preventDefault(); |
| 3753 |
if (stop) { |
| 3754 |
evt.stopPropagation(); |
| 3755 |
} |
| 3756 |
} |
| 3757 |
}; |
| 3758 |
|
| 3759 |
/** |
| 3760 |
* Add event helper |
| 3761 |
* |
| 3762 |
*/ |
| 3763 |
const addEvent = (target, type, callback, options) => { |
| 3764 |
target.addEventListener(type, callback, options); |
| 3765 |
}; |
| 3766 |
|
| 3767 |
/** |
| 3768 |
* Return a dom element from either a dom query string, jQuery object, a dom element or html string |
| 3769 |
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 |
| 3770 |
* |
| 3771 |
* param query should be {} |
| 3772 |
*/ |
| 3773 |
const getDom = query => { |
| 3774 |
if (query.jquery) { |
| 3775 |
return query[0]; |
| 3776 |
} |
| 3777 |
if (query instanceof HTMLElement) { |
| 3778 |
return query; |
| 3779 |
} |
| 3780 |
if (isHtmlString(query)) { |
| 3781 |
var tpl = document.createElement('template'); |
| 3782 |
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result |
| 3783 |
return tpl.content.firstChild; |
| 3784 |
} |
| 3785 |
return document.querySelector(query); |
| 3786 |
}; |
| 3787 |
const isHtmlString = arg => { |
| 3788 |
if (typeof arg === 'string' && arg.indexOf('<') > -1) { |
| 3789 |
return true; |
| 3790 |
} |
| 3791 |
return false; |
| 3792 |
}; |
| 3793 |
|
| 3794 |
/** |
| 3795 |
* Plugin: "remove_button" (Tom Select) |
| 3796 |
* Copyright (c) contributors |
| 3797 |
* |
| 3798 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 3799 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 3800 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3801 |
* |
| 3802 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 3803 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 3804 |
* ANY KIND, either express or implied. See the License for the specific language |
| 3805 |
* governing permissions and limitations under the License. |
| 3806 |
* |
| 3807 |
*/ |
| 3808 |
|
| 3809 |
function plugin (userOptions) { |
| 3810 |
const options = Object.assign({ |
| 3811 |
label: '×', |
| 3812 |
title: 'Remove', |
| 3813 |
className: 'remove', |
| 3814 |
append: true |
| 3815 |
}, userOptions); |
| 3816 |
|
| 3817 |
//options.className = 'remove-single'; |
| 3818 |
var self = this; |
| 3819 |
|
| 3820 |
// override the render method to add remove button to each item |
| 3821 |
if (!options.append) { |
| 3822 |
return; |
| 3823 |
} |
| 3824 |
var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>'; |
| 3825 |
self.hook('after', 'setupTemplates', () => { |
| 3826 |
var orig_render_item = self.settings.render.item; |
| 3827 |
self.settings.render.item = (data, escape) => { |
| 3828 |
var item = getDom(orig_render_item.call(self, data, escape)); |
| 3829 |
var close_button = getDom(html); |
| 3830 |
item.appendChild(close_button); |
| 3831 |
addEvent(close_button, 'mousedown', evt => { |
| 3832 |
preventDefault(evt, true); |
| 3833 |
}); |
| 3834 |
addEvent(close_button, 'click', evt => { |
| 3835 |
if (self.isLocked) return; |
| 3836 |
|
| 3837 |
// propagating will trigger the dropdown to show for single mode |
| 3838 |
preventDefault(evt, true); |
| 3839 |
if (self.isLocked) return; |
| 3840 |
if (!self.shouldDelete([item], evt)) return; |
| 3841 |
self.removeItem(item); |
| 3842 |
self.refreshOptions(false); |
| 3843 |
self.inputState(); |
| 3844 |
}); |
| 3845 |
return item; |
| 3846 |
}; |
| 3847 |
}); |
| 3848 |
} |
| 3849 |
|
| 3850 |
|
| 3851 |
//# sourceMappingURL=plugin.js.map |
| 3852 |
|
| 3853 |
|
| 3854 |
/***/ }, |
| 3855 |
|
| 3856 |
/***/ "./node_modules/tom-select/dist/esm/plugins/restore_on_backspace/plugin.js" |
| 3857 |
/*!*********************************************************************************!*\ |
| 3858 |
!*** ./node_modules/tom-select/dist/esm/plugins/restore_on_backspace/plugin.js ***! |
| 3859 |
\*********************************************************************************/ |
| 3860 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3861 |
|
| 3862 |
__webpack_require__.r(__webpack_exports__); |
| 3863 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3864 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 3865 |
/* harmony export */ }); |
| 3866 |
/** |
| 3867 |
* Tom Select v2.4.3 |
| 3868 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3869 |
*/ |
| 3870 |
|
| 3871 |
/** |
| 3872 |
* Plugin: "restore_on_backspace" (Tom Select) |
| 3873 |
* Copyright (c) contributors |
| 3874 |
* |
| 3875 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 3876 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 3877 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 3878 |
* |
| 3879 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 3880 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 3881 |
* ANY KIND, either express or implied. See the License for the specific language |
| 3882 |
* governing permissions and limitations under the License. |
| 3883 |
* |
| 3884 |
*/ |
| 3885 |
|
| 3886 |
function plugin (userOptions) { |
| 3887 |
const self = this; |
| 3888 |
const options = Object.assign({ |
| 3889 |
text: option => { |
| 3890 |
return option[self.settings.labelField]; |
| 3891 |
} |
| 3892 |
}, userOptions); |
| 3893 |
self.on('item_remove', function (value) { |
| 3894 |
if (!self.isFocused) { |
| 3895 |
return; |
| 3896 |
} |
| 3897 |
if (self.control_input.value.trim() === '') { |
| 3898 |
var option = self.options[value]; |
| 3899 |
if (option) { |
| 3900 |
self.setTextboxValue(options.text.call(self, option)); |
| 3901 |
} |
| 3902 |
} |
| 3903 |
}); |
| 3904 |
} |
| 3905 |
|
| 3906 |
|
| 3907 |
//# sourceMappingURL=plugin.js.map |
| 3908 |
|
| 3909 |
|
| 3910 |
/***/ }, |
| 3911 |
|
| 3912 |
/***/ "./node_modules/tom-select/dist/esm/plugins/virtual_scroll/plugin.js" |
| 3913 |
/*!***************************************************************************!*\ |
| 3914 |
!*** ./node_modules/tom-select/dist/esm/plugins/virtual_scroll/plugin.js ***! |
| 3915 |
\***************************************************************************/ |
| 3916 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3917 |
|
| 3918 |
__webpack_require__.r(__webpack_exports__); |
| 3919 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3920 |
/* harmony export */ "default": () => (/* binding */ plugin) |
| 3921 |
/* harmony export */ }); |
| 3922 |
/** |
| 3923 |
* Tom Select v2.4.3 |
| 3924 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 3925 |
*/ |
| 3926 |
|
| 3927 |
/** |
| 3928 |
* Converts a scalar to its best string representation |
| 3929 |
* for hash keys and HTML attribute values. |
| 3930 |
* |
| 3931 |
* Transformations: |
| 3932 |
* 'str' -> 'str' |
| 3933 |
* null -> '' |
| 3934 |
* undefined -> '' |
| 3935 |
* true -> '1' |
| 3936 |
* false -> '0' |
| 3937 |
* 0 -> '0' |
| 3938 |
* 1 -> '1' |
| 3939 |
* |
| 3940 |
*/ |
| 3941 |
|
| 3942 |
/** |
| 3943 |
* Iterates over arrays and hashes. |
| 3944 |
* |
| 3945 |
* ``` |
| 3946 |
* iterate(this.items, function(item, id) { |
| 3947 |
* // invoked for each item |
| 3948 |
* }); |
| 3949 |
* ``` |
| 3950 |
* |
| 3951 |
*/ |
| 3952 |
const iterate = (object, callback) => { |
| 3953 |
if (Array.isArray(object)) { |
| 3954 |
object.forEach(callback); |
| 3955 |
} else { |
| 3956 |
for (var key in object) { |
| 3957 |
if (object.hasOwnProperty(key)) { |
| 3958 |
callback(object[key], key); |
| 3959 |
} |
| 3960 |
} |
| 3961 |
} |
| 3962 |
}; |
| 3963 |
|
| 3964 |
/** |
| 3965 |
* Add css classes |
| 3966 |
* |
| 3967 |
*/ |
| 3968 |
const addClasses = (elmts, ...classes) => { |
| 3969 |
var norm_classes = classesArray(classes); |
| 3970 |
elmts = castAsArray(elmts); |
| 3971 |
elmts.map(el => { |
| 3972 |
norm_classes.map(cls => { |
| 3973 |
el.classList.add(cls); |
| 3974 |
}); |
| 3975 |
}); |
| 3976 |
}; |
| 3977 |
|
| 3978 |
/** |
| 3979 |
* Return arguments |
| 3980 |
* |
| 3981 |
*/ |
| 3982 |
const classesArray = args => { |
| 3983 |
var classes = []; |
| 3984 |
iterate(args, _classes => { |
| 3985 |
if (typeof _classes === 'string') { |
| 3986 |
_classes = _classes.trim().split(/[\t\n\f\r\s]/); |
| 3987 |
} |
| 3988 |
if (Array.isArray(_classes)) { |
| 3989 |
classes = classes.concat(_classes); |
| 3990 |
} |
| 3991 |
}); |
| 3992 |
return classes.filter(Boolean); |
| 3993 |
}; |
| 3994 |
|
| 3995 |
/** |
| 3996 |
* Create an array from arg if it's not already an array |
| 3997 |
* |
| 3998 |
*/ |
| 3999 |
const castAsArray = arg => { |
| 4000 |
if (!Array.isArray(arg)) { |
| 4001 |
arg = [arg]; |
| 4002 |
} |
| 4003 |
return arg; |
| 4004 |
}; |
| 4005 |
|
| 4006 |
/** |
| 4007 |
* Plugin: "restore_on_backspace" (Tom Select) |
| 4008 |
* Copyright (c) contributors |
| 4009 |
* |
| 4010 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 4011 |
* file except in compliance with the License. You may obtain a copy of the License at: |
| 4012 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 4013 |
* |
| 4014 |
* Unless required by applicable law or agreed to in writing, software distributed under |
| 4015 |
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 4016 |
* ANY KIND, either express or implied. See the License for the specific language |
| 4017 |
* governing permissions and limitations under the License. |
| 4018 |
* |
| 4019 |
*/ |
| 4020 |
|
| 4021 |
function plugin () { |
| 4022 |
const self = this; |
| 4023 |
const orig_canLoad = self.canLoad; |
| 4024 |
const orig_clearActiveOption = self.clearActiveOption; |
| 4025 |
const orig_loadCallback = self.loadCallback; |
| 4026 |
var pagination = {}; |
| 4027 |
var dropdown_content; |
| 4028 |
var loading_more = false; |
| 4029 |
var load_more_opt; |
| 4030 |
var default_values = []; |
| 4031 |
if (!self.settings.shouldLoadMore) { |
| 4032 |
// return true if additional results should be loaded |
| 4033 |
self.settings.shouldLoadMore = () => { |
| 4034 |
const scroll_percent = dropdown_content.clientHeight / (dropdown_content.scrollHeight - dropdown_content.scrollTop); |
| 4035 |
if (scroll_percent > 0.9) { |
| 4036 |
return true; |
| 4037 |
} |
| 4038 |
if (self.activeOption) { |
| 4039 |
var selectable = self.selectable(); |
| 4040 |
var index = Array.from(selectable).indexOf(self.activeOption); |
| 4041 |
if (index >= selectable.length - 2) { |
| 4042 |
return true; |
| 4043 |
} |
| 4044 |
} |
| 4045 |
return false; |
| 4046 |
}; |
| 4047 |
} |
| 4048 |
if (!self.settings.firstUrl) { |
| 4049 |
throw 'virtual_scroll plugin requires a firstUrl() method'; |
| 4050 |
} |
| 4051 |
|
| 4052 |
// in order for virtual scrolling to work, |
| 4053 |
// options need to be ordered the same way they're returned from the remote data source |
| 4054 |
self.settings.sortField = [{ |
| 4055 |
field: '$order' |
| 4056 |
}, { |
| 4057 |
field: '$score' |
| 4058 |
}]; |
| 4059 |
|
| 4060 |
// can we load more results for given query? |
| 4061 |
const canLoadMore = query => { |
| 4062 |
if (typeof self.settings.maxOptions === 'number' && dropdown_content.children.length >= self.settings.maxOptions) { |
| 4063 |
return false; |
| 4064 |
} |
| 4065 |
if (query in pagination && pagination[query]) { |
| 4066 |
return true; |
| 4067 |
} |
| 4068 |
return false; |
| 4069 |
}; |
| 4070 |
const clearFilter = (option, value) => { |
| 4071 |
if (self.items.indexOf(value) >= 0 || default_values.indexOf(value) >= 0) { |
| 4072 |
return true; |
| 4073 |
} |
| 4074 |
return false; |
| 4075 |
}; |
| 4076 |
|
| 4077 |
// set the next url that will be |
| 4078 |
self.setNextUrl = (value, next_url) => { |
| 4079 |
pagination[value] = next_url; |
| 4080 |
}; |
| 4081 |
|
| 4082 |
// getUrl() to be used in settings.load() |
| 4083 |
self.getUrl = query => { |
| 4084 |
if (query in pagination) { |
| 4085 |
const next_url = pagination[query]; |
| 4086 |
pagination[query] = false; |
| 4087 |
return next_url; |
| 4088 |
} |
| 4089 |
|
| 4090 |
// if the user goes back to a previous query |
| 4091 |
// we need to load the first page again |
| 4092 |
self.clearPagination(); |
| 4093 |
return self.settings.firstUrl.call(self, query); |
| 4094 |
}; |
| 4095 |
|
| 4096 |
// clear pagination |
| 4097 |
self.clearPagination = () => { |
| 4098 |
pagination = {}; |
| 4099 |
}; |
| 4100 |
|
| 4101 |
// don't clear the active option (and cause unwanted dropdown scroll) |
| 4102 |
// while loading more results |
| 4103 |
self.hook('instead', 'clearActiveOption', () => { |
| 4104 |
if (loading_more) { |
| 4105 |
return; |
| 4106 |
} |
| 4107 |
return orig_clearActiveOption.call(self); |
| 4108 |
}); |
| 4109 |
|
| 4110 |
// override the canLoad method |
| 4111 |
self.hook('instead', 'canLoad', query => { |
| 4112 |
// first time the query has been seen |
| 4113 |
if (!(query in pagination)) { |
| 4114 |
return orig_canLoad.call(self, query); |
| 4115 |
} |
| 4116 |
return canLoadMore(query); |
| 4117 |
}); |
| 4118 |
|
| 4119 |
// wrap the load |
| 4120 |
self.hook('instead', 'loadCallback', (options, optgroups) => { |
| 4121 |
if (!loading_more) { |
| 4122 |
self.clearOptions(clearFilter); |
| 4123 |
} else if (load_more_opt) { |
| 4124 |
const first_option = options[0]; |
| 4125 |
if (first_option !== undefined) { |
| 4126 |
load_more_opt.dataset.value = first_option[self.settings.valueField]; |
| 4127 |
} |
| 4128 |
} |
| 4129 |
orig_loadCallback.call(self, options, optgroups); |
| 4130 |
loading_more = false; |
| 4131 |
}); |
| 4132 |
|
| 4133 |
// add templates to dropdown |
| 4134 |
// loading_more if we have another url in the queue |
| 4135 |
// no_more_results if we don't have another url in the queue |
| 4136 |
self.hook('after', 'refreshOptions', () => { |
| 4137 |
const query = self.lastValue; |
| 4138 |
var option; |
| 4139 |
if (canLoadMore(query)) { |
| 4140 |
option = self.render('loading_more', { |
| 4141 |
query: query |
| 4142 |
}); |
| 4143 |
if (option) { |
| 4144 |
option.setAttribute('data-selectable', ''); // so that navigating dropdown with [down] keypresses can navigate to this node |
| 4145 |
load_more_opt = option; |
| 4146 |
} |
| 4147 |
} else if (query in pagination && !dropdown_content.querySelector('.no-results')) { |
| 4148 |
option = self.render('no_more_results', { |
| 4149 |
query: query |
| 4150 |
}); |
| 4151 |
} |
| 4152 |
if (option) { |
| 4153 |
addClasses(option, self.settings.optionClass); |
| 4154 |
dropdown_content.append(option); |
| 4155 |
} |
| 4156 |
}); |
| 4157 |
|
| 4158 |
// add scroll listener and default templates |
| 4159 |
self.on('initialize', () => { |
| 4160 |
default_values = Object.keys(self.options); |
| 4161 |
dropdown_content = self.dropdown_content; |
| 4162 |
|
| 4163 |
// default templates |
| 4164 |
self.settings.render = Object.assign({}, { |
| 4165 |
loading_more: () => { |
| 4166 |
return `<div class="loading-more-results">Loading more results ... </div>`; |
| 4167 |
}, |
| 4168 |
no_more_results: () => { |
| 4169 |
return `<div class="no-more-results">No more results</div>`; |
| 4170 |
} |
| 4171 |
}, self.settings.render); |
| 4172 |
|
| 4173 |
// watch dropdown content scroll position |
| 4174 |
dropdown_content.addEventListener('scroll', () => { |
| 4175 |
if (!self.settings.shouldLoadMore.call(self)) { |
| 4176 |
return; |
| 4177 |
} |
| 4178 |
|
| 4179 |
// !important: this will get checked again in load() but we still need to check here otherwise loading_more will be set to true |
| 4180 |
if (!canLoadMore(self.lastValue)) { |
| 4181 |
return; |
| 4182 |
} |
| 4183 |
|
| 4184 |
// don't call load() too much |
| 4185 |
if (loading_more) return; |
| 4186 |
loading_more = true; |
| 4187 |
self.load.call(self, self.lastValue); |
| 4188 |
}); |
| 4189 |
}); |
| 4190 |
} |
| 4191 |
|
| 4192 |
|
| 4193 |
//# sourceMappingURL=plugin.js.map |
| 4194 |
|
| 4195 |
|
| 4196 |
/***/ }, |
| 4197 |
|
| 4198 |
/***/ "./node_modules/tom-select/dist/esm/tom-select.complete.js" |
| 4199 |
/*!*****************************************************************!*\ |
| 4200 |
!*** ./node_modules/tom-select/dist/esm/tom-select.complete.js ***! |
| 4201 |
\*****************************************************************/ |
| 4202 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 4203 |
|
| 4204 |
__webpack_require__.r(__webpack_exports__); |
| 4205 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4206 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 4207 |
/* harmony export */ }); |
| 4208 |
/* harmony import */ var _tom_select_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tom-select.js */ "./node_modules/tom-select/dist/esm/tom-select.js"); |
| 4209 |
/* harmony import */ var _plugins_change_listener_plugin_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./plugins/change_listener/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/change_listener/plugin.js"); |
| 4210 |
/* harmony import */ var _plugins_checkbox_options_plugin_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./plugins/checkbox_options/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/checkbox_options/plugin.js"); |
| 4211 |
/* harmony import */ var _plugins_clear_button_plugin_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./plugins/clear_button/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/clear_button/plugin.js"); |
| 4212 |
/* harmony import */ var _plugins_drag_drop_plugin_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./plugins/drag_drop/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/drag_drop/plugin.js"); |
| 4213 |
/* harmony import */ var _plugins_dropdown_header_plugin_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./plugins/dropdown_header/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/dropdown_header/plugin.js"); |
| 4214 |
/* harmony import */ var _plugins_caret_position_plugin_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./plugins/caret_position/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/caret_position/plugin.js"); |
| 4215 |
/* harmony import */ var _plugins_dropdown_input_plugin_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./plugins/dropdown_input/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/dropdown_input/plugin.js"); |
| 4216 |
/* harmony import */ var _plugins_input_autogrow_plugin_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./plugins/input_autogrow/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/input_autogrow/plugin.js"); |
| 4217 |
/* harmony import */ var _plugins_no_backspace_delete_plugin_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./plugins/no_backspace_delete/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/no_backspace_delete/plugin.js"); |
| 4218 |
/* harmony import */ var _plugins_no_active_items_plugin_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./plugins/no_active_items/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/no_active_items/plugin.js"); |
| 4219 |
/* harmony import */ var _plugins_optgroup_columns_plugin_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./plugins/optgroup_columns/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/optgroup_columns/plugin.js"); |
| 4220 |
/* harmony import */ var _plugins_remove_button_plugin_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./plugins/remove_button/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/remove_button/plugin.js"); |
| 4221 |
/* harmony import */ var _plugins_restore_on_backspace_plugin_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./plugins/restore_on_backspace/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/restore_on_backspace/plugin.js"); |
| 4222 |
/* harmony import */ var _plugins_virtual_scroll_plugin_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./plugins/virtual_scroll/plugin.js */ "./node_modules/tom-select/dist/esm/plugins/virtual_scroll/plugin.js"); |
| 4223 |
|
| 4224 |
|
| 4225 |
|
| 4226 |
|
| 4227 |
|
| 4228 |
|
| 4229 |
|
| 4230 |
|
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
|
| 4236 |
|
| 4237 |
|
| 4238 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('change_listener', _plugins_change_listener_plugin_js__WEBPACK_IMPORTED_MODULE_1__["default"]); |
| 4239 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('checkbox_options', _plugins_checkbox_options_plugin_js__WEBPACK_IMPORTED_MODULE_2__["default"]); |
| 4240 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('clear_button', _plugins_clear_button_plugin_js__WEBPACK_IMPORTED_MODULE_3__["default"]); |
| 4241 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('drag_drop', _plugins_drag_drop_plugin_js__WEBPACK_IMPORTED_MODULE_4__["default"]); |
| 4242 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('dropdown_header', _plugins_dropdown_header_plugin_js__WEBPACK_IMPORTED_MODULE_5__["default"]); |
| 4243 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('caret_position', _plugins_caret_position_plugin_js__WEBPACK_IMPORTED_MODULE_6__["default"]); |
| 4244 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('dropdown_input', _plugins_dropdown_input_plugin_js__WEBPACK_IMPORTED_MODULE_7__["default"]); |
| 4245 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('input_autogrow', _plugins_input_autogrow_plugin_js__WEBPACK_IMPORTED_MODULE_8__["default"]); |
| 4246 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('no_backspace_delete', _plugins_no_backspace_delete_plugin_js__WEBPACK_IMPORTED_MODULE_9__["default"]); |
| 4247 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('no_active_items', _plugins_no_active_items_plugin_js__WEBPACK_IMPORTED_MODULE_10__["default"]); |
| 4248 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('optgroup_columns', _plugins_optgroup_columns_plugin_js__WEBPACK_IMPORTED_MODULE_11__["default"]); |
| 4249 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('remove_button', _plugins_remove_button_plugin_js__WEBPACK_IMPORTED_MODULE_12__["default"]); |
| 4250 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('restore_on_backspace', _plugins_restore_on_backspace_plugin_js__WEBPACK_IMPORTED_MODULE_13__["default"]); |
| 4251 |
_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"].define('virtual_scroll', _plugins_virtual_scroll_plugin_js__WEBPACK_IMPORTED_MODULE_14__["default"]); |
| 4252 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_tom_select_js__WEBPACK_IMPORTED_MODULE_0__["default"]); |
| 4253 |
//# sourceMappingURL=tom-select.complete.js.map |
| 4254 |
|
| 4255 |
/***/ }, |
| 4256 |
|
| 4257 |
/***/ "./node_modules/tom-select/dist/esm/tom-select.js" |
| 4258 |
/*!********************************************************!*\ |
| 4259 |
!*** ./node_modules/tom-select/dist/esm/tom-select.js ***! |
| 4260 |
\********************************************************/ |
| 4261 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 4262 |
|
| 4263 |
__webpack_require__.r(__webpack_exports__); |
| 4264 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4265 |
/* harmony export */ "default": () => (/* binding */ TomSelect) |
| 4266 |
/* harmony export */ }); |
| 4267 |
/* harmony import */ var _contrib_microevent_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./contrib/microevent.js */ "./node_modules/tom-select/dist/esm/contrib/microevent.js"); |
| 4268 |
/* harmony import */ var _contrib_microplugin_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./contrib/microplugin.js */ "./node_modules/tom-select/dist/esm/contrib/microplugin.js"); |
| 4269 |
/* harmony import */ var _orchidjs_sifter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @orchidjs/sifter */ "./node_modules/@orchidjs/sifter/dist/esm/sifter.js"); |
| 4270 |
/* harmony import */ var _orchidjs_unicode_variants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @orchidjs/unicode-variants */ "./node_modules/@orchidjs/unicode-variants/dist/esm/index.js"); |
| 4271 |
/* harmony import */ var _contrib_highlight_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./contrib/highlight.js */ "./node_modules/tom-select/dist/esm/contrib/highlight.js"); |
| 4272 |
/* harmony import */ var _constants_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./constants.js */ "./node_modules/tom-select/dist/esm/constants.js"); |
| 4273 |
/* harmony import */ var _getSettings_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./getSettings.js */ "./node_modules/tom-select/dist/esm/getSettings.js"); |
| 4274 |
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./utils.js */ "./node_modules/tom-select/dist/esm/utils.js"); |
| 4275 |
/* harmony import */ var _vanilla_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./vanilla.js */ "./node_modules/tom-select/dist/esm/vanilla.js"); |
| 4276 |
|
| 4277 |
|
| 4278 |
|
| 4279 |
|
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
|
| 4284 |
|
| 4285 |
var instance_i = 0; |
| 4286 |
class TomSelect extends (0,_contrib_microplugin_js__WEBPACK_IMPORTED_MODULE_1__["default"])(_contrib_microevent_js__WEBPACK_IMPORTED_MODULE_0__["default"]) { |
| 4287 |
constructor(input_arg, user_settings) { |
| 4288 |
super(); |
| 4289 |
this.order = 0; |
| 4290 |
this.isOpen = false; |
| 4291 |
this.isDisabled = false; |
| 4292 |
this.isReadOnly = false; |
| 4293 |
this.isInvalid = false; // @deprecated 1.8 |
| 4294 |
this.isValid = true; |
| 4295 |
this.isLocked = false; |
| 4296 |
this.isFocused = false; |
| 4297 |
this.isInputHidden = false; |
| 4298 |
this.isSetup = false; |
| 4299 |
this.ignoreFocus = false; |
| 4300 |
this.ignoreHover = false; |
| 4301 |
this.hasOptions = false; |
| 4302 |
this.lastValue = ''; |
| 4303 |
this.caretPos = 0; |
| 4304 |
this.loading = 0; |
| 4305 |
this.loadedSearches = {}; |
| 4306 |
this.activeOption = null; |
| 4307 |
this.activeItems = []; |
| 4308 |
this.optgroups = {}; |
| 4309 |
this.options = {}; |
| 4310 |
this.userOptions = {}; |
| 4311 |
this.items = []; |
| 4312 |
this.refreshTimeout = null; |
| 4313 |
instance_i++; |
| 4314 |
var dir; |
| 4315 |
var input = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)(input_arg); |
| 4316 |
if (input.tomselect) { |
| 4317 |
throw new Error('Tom Select already initialized on this element'); |
| 4318 |
} |
| 4319 |
input.tomselect = this; |
| 4320 |
// detect rtl environment |
| 4321 |
var computedStyle = window.getComputedStyle && window.getComputedStyle(input, null); |
| 4322 |
dir = computedStyle.getPropertyValue('direction'); |
| 4323 |
// setup default state |
| 4324 |
const settings = (0,_getSettings_js__WEBPACK_IMPORTED_MODULE_6__["default"])(input, user_settings); |
| 4325 |
this.settings = settings; |
| 4326 |
this.input = input; |
| 4327 |
this.tabIndex = input.tabIndex || 0; |
| 4328 |
this.is_select_tag = input.tagName.toLowerCase() === 'select'; |
| 4329 |
this.rtl = /rtl/i.test(dir); |
| 4330 |
this.inputId = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.getId)(input, 'tomselect-' + instance_i); |
| 4331 |
this.isRequired = input.required; |
| 4332 |
// search system |
| 4333 |
this.sifter = new _orchidjs_sifter__WEBPACK_IMPORTED_MODULE_2__.Sifter(this.options, { diacritics: settings.diacritics }); |
| 4334 |
// option-dependent defaults |
| 4335 |
settings.mode = settings.mode || (settings.maxItems === 1 ? 'single' : 'multi'); |
| 4336 |
if (typeof settings.hideSelected !== 'boolean') { |
| 4337 |
settings.hideSelected = settings.mode === 'multi'; |
| 4338 |
} |
| 4339 |
if (typeof settings.hidePlaceholder !== 'boolean') { |
| 4340 |
settings.hidePlaceholder = settings.mode !== 'multi'; |
| 4341 |
} |
| 4342 |
// set up createFilter callback |
| 4343 |
var filter = settings.createFilter; |
| 4344 |
if (typeof filter !== 'function') { |
| 4345 |
if (typeof filter === 'string') { |
| 4346 |
filter = new RegExp(filter); |
| 4347 |
} |
| 4348 |
if (filter instanceof RegExp) { |
| 4349 |
settings.createFilter = (input) => filter.test(input); |
| 4350 |
} |
| 4351 |
else { |
| 4352 |
settings.createFilter = (value) => { |
| 4353 |
return this.settings.duplicates || !this.options[value]; |
| 4354 |
}; |
| 4355 |
} |
| 4356 |
} |
| 4357 |
this.initializePlugins(settings.plugins); |
| 4358 |
this.setupCallbacks(); |
| 4359 |
this.setupTemplates(); |
| 4360 |
// Create all elements |
| 4361 |
const wrapper = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)('<div>'); |
| 4362 |
const control = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)('<div>'); |
| 4363 |
const dropdown = this._render('dropdown'); |
| 4364 |
const dropdown_content = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)(`<div role="listbox" tabindex="-1">`); |
| 4365 |
const classes = this.input.getAttribute('class') || ''; |
| 4366 |
const inputMode = settings.mode; |
| 4367 |
var control_input; |
| 4368 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(wrapper, settings.wrapperClass, classes, inputMode); |
| 4369 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(control, settings.controlClass); |
| 4370 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(wrapper, control); |
| 4371 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown, settings.dropdownClass, inputMode); |
| 4372 |
if (settings.copyClassesToDropdown) { |
| 4373 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown, classes); |
| 4374 |
} |
| 4375 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown_content, settings.dropdownContentClass); |
| 4376 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(dropdown, dropdown_content); |
| 4377 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)(settings.dropdownParent || wrapper).appendChild(dropdown); |
| 4378 |
// default controlInput |
| 4379 |
if ((0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.isHtmlString)(settings.controlInput)) { |
| 4380 |
control_input = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)(settings.controlInput); |
| 4381 |
// set attributes |
| 4382 |
var attrs = ['autocorrect', 'autocapitalize', 'autocomplete', 'spellcheck']; |
| 4383 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(attrs, (attr) => { |
| 4384 |
if (input.getAttribute(attr)) { |
| 4385 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(control_input, { [attr]: input.getAttribute(attr) }); |
| 4386 |
} |
| 4387 |
}); |
| 4388 |
control_input.tabIndex = -1; |
| 4389 |
control.appendChild(control_input); |
| 4390 |
this.focus_node = control_input; |
| 4391 |
// dom element |
| 4392 |
} |
| 4393 |
else if (settings.controlInput) { |
| 4394 |
control_input = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)(settings.controlInput); |
| 4395 |
this.focus_node = control_input; |
| 4396 |
} |
| 4397 |
else { |
| 4398 |
control_input = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)('<input/>'); |
| 4399 |
this.focus_node = control; |
| 4400 |
} |
| 4401 |
this.wrapper = wrapper; |
| 4402 |
this.dropdown = dropdown; |
| 4403 |
this.dropdown_content = dropdown_content; |
| 4404 |
this.control = control; |
| 4405 |
this.control_input = control_input; |
| 4406 |
this.setup(); |
| 4407 |
} |
| 4408 |
/** |
| 4409 |
* set up event bindings. |
| 4410 |
* |
| 4411 |
*/ |
| 4412 |
setup() { |
| 4413 |
const self = this; |
| 4414 |
const settings = self.settings; |
| 4415 |
const control_input = self.control_input; |
| 4416 |
const dropdown = self.dropdown; |
| 4417 |
const dropdown_content = self.dropdown_content; |
| 4418 |
const wrapper = self.wrapper; |
| 4419 |
const control = self.control; |
| 4420 |
const input = self.input; |
| 4421 |
const focus_node = self.focus_node; |
| 4422 |
const passive_event = { passive: true }; |
| 4423 |
const listboxId = self.inputId + '-ts-dropdown'; |
| 4424 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(dropdown_content, { |
| 4425 |
id: listboxId |
| 4426 |
}); |
| 4427 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(focus_node, { |
| 4428 |
role: 'combobox', |
| 4429 |
'aria-haspopup': 'listbox', |
| 4430 |
'aria-expanded': 'false', |
| 4431 |
'aria-controls': listboxId |
| 4432 |
}); |
| 4433 |
const control_id = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.getId)(focus_node, self.inputId + '-ts-control'); |
| 4434 |
const query = "label[for='" + (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.escapeQuery)(self.inputId) + "']"; |
| 4435 |
const label = document.querySelector(query); |
| 4436 |
const label_click = self.focus.bind(self); |
| 4437 |
if (label) { |
| 4438 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(label, 'click', label_click); |
| 4439 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(label, { for: control_id }); |
| 4440 |
const label_id = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.getId)(label, self.inputId + '-ts-label'); |
| 4441 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(focus_node, { 'aria-labelledby': label_id }); |
| 4442 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(dropdown_content, { 'aria-labelledby': label_id }); |
| 4443 |
} |
| 4444 |
wrapper.style.width = input.style.width; |
| 4445 |
if (self.plugins.names.length) { |
| 4446 |
const classes_plugins = 'plugin-' + self.plugins.names.join(' plugin-'); |
| 4447 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)([wrapper, dropdown], classes_plugins); |
| 4448 |
} |
| 4449 |
if ((settings.maxItems === null || settings.maxItems > 1) && self.is_select_tag) { |
| 4450 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(input, { multiple: 'multiple' }); |
| 4451 |
} |
| 4452 |
if (settings.placeholder) { |
| 4453 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(control_input, { placeholder: settings.placeholder }); |
| 4454 |
} |
| 4455 |
// if splitOn was not passed in, construct it from the delimiter to allow pasting universally |
| 4456 |
if (!settings.splitOn && settings.delimiter) { |
| 4457 |
settings.splitOn = new RegExp('\\s*' + (0,_orchidjs_unicode_variants__WEBPACK_IMPORTED_MODULE_3__.escape_regex)(settings.delimiter) + '+\\s*'); |
| 4458 |
} |
| 4459 |
// debounce user defined load() if loadThrottle > 0 |
| 4460 |
// after initializePlugins() so plugins can create/modify user defined loaders |
| 4461 |
if (settings.load && settings.loadThrottle) { |
| 4462 |
settings.load = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.loadDebounce)(settings.load, settings.loadThrottle); |
| 4463 |
} |
| 4464 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(dropdown, 'mousemove', () => { |
| 4465 |
self.ignoreHover = false; |
| 4466 |
}); |
| 4467 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(dropdown, 'mouseenter', (e) => { |
| 4468 |
var target_match = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.parentMatch)(e.target, '[data-selectable]', dropdown); |
| 4469 |
if (target_match) |
| 4470 |
self.onOptionHover(e, target_match); |
| 4471 |
}, { capture: true }); |
| 4472 |
// clicking on an option should select it |
| 4473 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(dropdown, 'click', (evt) => { |
| 4474 |
const option = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.parentMatch)(evt.target, '[data-selectable]'); |
| 4475 |
if (option) { |
| 4476 |
self.onOptionSelect(evt, option); |
| 4477 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(evt, true); |
| 4478 |
} |
| 4479 |
}); |
| 4480 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(control, 'click', (evt) => { |
| 4481 |
var target_match = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.parentMatch)(evt.target, '[data-ts-item]', control); |
| 4482 |
if (target_match && self.onItemSelect(evt, target_match)) { |
| 4483 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(evt, true); |
| 4484 |
return; |
| 4485 |
} |
| 4486 |
// retain focus (see control_input mousedown) |
| 4487 |
if (control_input.value != '') { |
| 4488 |
return; |
| 4489 |
} |
| 4490 |
self.onClick(); |
| 4491 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(evt, true); |
| 4492 |
}); |
| 4493 |
// keydown on focus_node for arrow_down/arrow_up |
| 4494 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(focus_node, 'keydown', (e) => self.onKeyDown(e)); |
| 4495 |
// keypress and input/keyup |
| 4496 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(control_input, 'keypress', (e) => self.onKeyPress(e)); |
| 4497 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(control_input, 'input', (e) => self.onInput(e)); |
| 4498 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(focus_node, 'blur', (e) => self.onBlur(e)); |
| 4499 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(focus_node, 'focus', (e) => self.onFocus(e)); |
| 4500 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(control_input, 'paste', (e) => self.onPaste(e)); |
| 4501 |
const doc_mousedown = (evt) => { |
| 4502 |
// blur if target is outside of this instance |
| 4503 |
// dropdown is not always inside wrapper |
| 4504 |
const target = evt.composedPath()[0]; |
| 4505 |
if (!wrapper.contains(target) && !dropdown.contains(target)) { |
| 4506 |
if (self.isFocused) { |
| 4507 |
self.blur(); |
| 4508 |
} |
| 4509 |
self.inputState(); |
| 4510 |
return; |
| 4511 |
} |
| 4512 |
// retain focus by preventing native handling. if the |
| 4513 |
// event target is the input it should not be modified. |
| 4514 |
// otherwise, text selection within the input won't work. |
| 4515 |
// Fixes bug #212 which is no covered by tests |
| 4516 |
if (target == control_input && self.isOpen) { |
| 4517 |
evt.stopPropagation(); |
| 4518 |
// clicking anywhere in the control should not blur the control_input (which would close the dropdown) |
| 4519 |
} |
| 4520 |
else { |
| 4521 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(evt, true); |
| 4522 |
} |
| 4523 |
}; |
| 4524 |
const win_scroll = () => { |
| 4525 |
if (self.isOpen) { |
| 4526 |
self.positionDropdown(); |
| 4527 |
} |
| 4528 |
}; |
| 4529 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(document, 'mousedown', doc_mousedown); |
| 4530 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(window, 'scroll', win_scroll, passive_event); |
| 4531 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(window, 'resize', win_scroll, passive_event); |
| 4532 |
this._destroy = () => { |
| 4533 |
document.removeEventListener('mousedown', doc_mousedown); |
| 4534 |
window.removeEventListener('scroll', win_scroll); |
| 4535 |
window.removeEventListener('resize', win_scroll); |
| 4536 |
if (label) |
| 4537 |
label.removeEventListener('click', label_click); |
| 4538 |
}; |
| 4539 |
// store original html and tab index so that they can be |
| 4540 |
// restored when the destroy() method is called. |
| 4541 |
this.revertSettings = { |
| 4542 |
innerHTML: input.innerHTML, |
| 4543 |
tabIndex: input.tabIndex |
| 4544 |
}; |
| 4545 |
input.tabIndex = -1; |
| 4546 |
input.insertAdjacentElement('afterend', self.wrapper); |
| 4547 |
self.sync(false); |
| 4548 |
settings.items = []; |
| 4549 |
delete settings.optgroups; |
| 4550 |
delete settings.options; |
| 4551 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(input, 'invalid', () => { |
| 4552 |
if (self.isValid) { |
| 4553 |
self.isValid = false; |
| 4554 |
self.isInvalid = true; |
| 4555 |
self.refreshState(); |
| 4556 |
} |
| 4557 |
}); |
| 4558 |
self.updateOriginalInput(); |
| 4559 |
self.refreshItems(); |
| 4560 |
self.close(false); |
| 4561 |
self.inputState(); |
| 4562 |
self.isSetup = true; |
| 4563 |
if (input.disabled) { |
| 4564 |
self.disable(); |
| 4565 |
} |
| 4566 |
else if (input.readOnly) { |
| 4567 |
self.setReadOnly(true); |
| 4568 |
} |
| 4569 |
else { |
| 4570 |
self.enable(); //sets tabIndex |
| 4571 |
} |
| 4572 |
self.on('change', this.onChange); |
| 4573 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(input, 'tomselected', 'ts-hidden-accessible'); |
| 4574 |
self.trigger('initialize'); |
| 4575 |
// preload options |
| 4576 |
if (settings.preload === true) { |
| 4577 |
self.preload(); |
| 4578 |
} |
| 4579 |
} |
| 4580 |
/** |
| 4581 |
* Register options and optgroups |
| 4582 |
* |
| 4583 |
*/ |
| 4584 |
setupOptions(options = [], optgroups = []) { |
| 4585 |
// build options table |
| 4586 |
this.addOptions(options); |
| 4587 |
// build optgroup table |
| 4588 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(optgroups, (optgroup) => { |
| 4589 |
this.registerOptionGroup(optgroup); |
| 4590 |
}); |
| 4591 |
} |
| 4592 |
/** |
| 4593 |
* Sets up default rendering functions. |
| 4594 |
*/ |
| 4595 |
setupTemplates() { |
| 4596 |
var self = this; |
| 4597 |
var field_label = self.settings.labelField; |
| 4598 |
var field_optgroup = self.settings.optgroupLabelField; |
| 4599 |
var templates = { |
| 4600 |
'optgroup': (data) => { |
| 4601 |
let optgroup = document.createElement('div'); |
| 4602 |
optgroup.className = 'optgroup'; |
| 4603 |
optgroup.appendChild(data.options); |
| 4604 |
return optgroup; |
| 4605 |
}, |
| 4606 |
'optgroup_header': (data, escape) => { |
| 4607 |
return '<div class="optgroup-header">' + escape(data[field_optgroup]) + '</div>'; |
| 4608 |
}, |
| 4609 |
'option': (data, escape) => { |
| 4610 |
return '<div>' + escape(data[field_label]) + '</div>'; |
| 4611 |
}, |
| 4612 |
'item': (data, escape) => { |
| 4613 |
return '<div>' + escape(data[field_label]) + '</div>'; |
| 4614 |
}, |
| 4615 |
'option_create': (data, escape) => { |
| 4616 |
return '<div class="create">Add <strong>' + escape(data.input) + '</strong>…</div>'; |
| 4617 |
}, |
| 4618 |
'no_results': () => { |
| 4619 |
return '<div class="no-results">No results found</div>'; |
| 4620 |
}, |
| 4621 |
'loading': () => { |
| 4622 |
return '<div class="spinner"></div>'; |
| 4623 |
}, |
| 4624 |
'not_loading': () => { }, |
| 4625 |
'dropdown': () => { |
| 4626 |
return '<div></div>'; |
| 4627 |
} |
| 4628 |
}; |
| 4629 |
self.settings.render = Object.assign({}, templates, self.settings.render); |
| 4630 |
} |
| 4631 |
/** |
| 4632 |
* Maps fired events to callbacks provided |
| 4633 |
* in the settings used when creating the control. |
| 4634 |
*/ |
| 4635 |
setupCallbacks() { |
| 4636 |
var key, fn; |
| 4637 |
var callbacks = { |
| 4638 |
'initialize': 'onInitialize', |
| 4639 |
'change': 'onChange', |
| 4640 |
'item_add': 'onItemAdd', |
| 4641 |
'item_remove': 'onItemRemove', |
| 4642 |
'item_select': 'onItemSelect', |
| 4643 |
'clear': 'onClear', |
| 4644 |
'option_add': 'onOptionAdd', |
| 4645 |
'option_remove': 'onOptionRemove', |
| 4646 |
'option_clear': 'onOptionClear', |
| 4647 |
'optgroup_add': 'onOptionGroupAdd', |
| 4648 |
'optgroup_remove': 'onOptionGroupRemove', |
| 4649 |
'optgroup_clear': 'onOptionGroupClear', |
| 4650 |
'dropdown_open': 'onDropdownOpen', |
| 4651 |
'dropdown_close': 'onDropdownClose', |
| 4652 |
'type': 'onType', |
| 4653 |
'load': 'onLoad', |
| 4654 |
'focus': 'onFocus', |
| 4655 |
'blur': 'onBlur' |
| 4656 |
}; |
| 4657 |
for (key in callbacks) { |
| 4658 |
fn = this.settings[callbacks[key]]; |
| 4659 |
if (fn) |
| 4660 |
this.on(key, fn); |
| 4661 |
} |
| 4662 |
} |
| 4663 |
/** |
| 4664 |
* Sync the Tom Select instance with the original input or select |
| 4665 |
* |
| 4666 |
*/ |
| 4667 |
sync(get_settings = true) { |
| 4668 |
const self = this; |
| 4669 |
const settings = get_settings ? (0,_getSettings_js__WEBPACK_IMPORTED_MODULE_6__["default"])(self.input, { delimiter: self.settings.delimiter }) : self.settings; |
| 4670 |
self.setupOptions(settings.options, settings.optgroups); |
| 4671 |
self.setValue(settings.items || [], true); // silent prevents recursion |
| 4672 |
self.lastQuery = null; // so updated options will be displayed in dropdown |
| 4673 |
} |
| 4674 |
/** |
| 4675 |
* Triggered when the main control element |
| 4676 |
* has a click event. |
| 4677 |
* |
| 4678 |
*/ |
| 4679 |
onClick() { |
| 4680 |
var self = this; |
| 4681 |
if (self.activeItems.length > 0) { |
| 4682 |
self.clearActiveItems(); |
| 4683 |
self.focus(); |
| 4684 |
return; |
| 4685 |
} |
| 4686 |
if (self.isFocused && self.isOpen) { |
| 4687 |
self.blur(); |
| 4688 |
} |
| 4689 |
else { |
| 4690 |
self.focus(); |
| 4691 |
} |
| 4692 |
} |
| 4693 |
/** |
| 4694 |
* @deprecated v1.7 |
| 4695 |
* |
| 4696 |
*/ |
| 4697 |
onMouseDown() { } |
| 4698 |
/** |
| 4699 |
* Triggered when the value of the control has been changed. |
| 4700 |
* This should propagate the event to the original DOM |
| 4701 |
* input / select element. |
| 4702 |
*/ |
| 4703 |
onChange() { |
| 4704 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.triggerEvent)(this.input, 'input'); |
| 4705 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.triggerEvent)(this.input, 'change'); |
| 4706 |
} |
| 4707 |
/** |
| 4708 |
* Triggered on <input> paste. |
| 4709 |
* |
| 4710 |
*/ |
| 4711 |
onPaste(e) { |
| 4712 |
var self = this; |
| 4713 |
if (self.isInputHidden || self.isLocked) { |
| 4714 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4715 |
return; |
| 4716 |
} |
| 4717 |
// If a regex or string is included, this will split the pasted |
| 4718 |
// input and create Items for each separate value |
| 4719 |
if (!self.settings.splitOn) { |
| 4720 |
return; |
| 4721 |
} |
| 4722 |
// Wait for pasted text to be recognized in value |
| 4723 |
setTimeout(() => { |
| 4724 |
var pastedText = self.inputValue(); |
| 4725 |
if (!pastedText.match(self.settings.splitOn)) { |
| 4726 |
return; |
| 4727 |
} |
| 4728 |
var splitInput = pastedText.trim().split(self.settings.splitOn); |
| 4729 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(splitInput, (piece) => { |
| 4730 |
const hash = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(piece); |
| 4731 |
if (hash) { |
| 4732 |
if (this.options[piece]) { |
| 4733 |
self.addItem(piece); |
| 4734 |
} |
| 4735 |
else { |
| 4736 |
self.createItem(piece); |
| 4737 |
} |
| 4738 |
} |
| 4739 |
}); |
| 4740 |
}, 0); |
| 4741 |
} |
| 4742 |
/** |
| 4743 |
* Triggered on <input> keypress. |
| 4744 |
* |
| 4745 |
*/ |
| 4746 |
onKeyPress(e) { |
| 4747 |
var self = this; |
| 4748 |
if (self.isLocked) { |
| 4749 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4750 |
return; |
| 4751 |
} |
| 4752 |
var character = String.fromCharCode(e.keyCode || e.which); |
| 4753 |
if (self.settings.create && self.settings.mode === 'multi' && character === self.settings.delimiter) { |
| 4754 |
self.createItem(); |
| 4755 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4756 |
return; |
| 4757 |
} |
| 4758 |
} |
| 4759 |
/** |
| 4760 |
* Triggered on <input> keydown. |
| 4761 |
* |
| 4762 |
*/ |
| 4763 |
onKeyDown(e) { |
| 4764 |
var self = this; |
| 4765 |
self.ignoreHover = true; |
| 4766 |
if (self.isLocked) { |
| 4767 |
if (e.keyCode !== _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_TAB) { |
| 4768 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4769 |
} |
| 4770 |
return; |
| 4771 |
} |
| 4772 |
switch (e.keyCode) { |
| 4773 |
// ctrl+A: select all |
| 4774 |
case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_A: |
| 4775 |
if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.isKeyDown)(_constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_SHORTCUT, e)) { |
| 4776 |
if (self.control_input.value == '') { |
| 4777 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4778 |
self.selectAll(); |
| 4779 |
return; |
| 4780 |
} |
| 4781 |
} |
| 4782 |
break; |
| 4783 |
// esc: close dropdown |
| 4784 |
case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_ESC: |
| 4785 |
if (self.isOpen) { |
| 4786 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e, true); |
| 4787 |
self.close(); |
| 4788 |
} |
| 4789 |
self.clearActiveItems(); |
| 4790 |
return; |
| 4791 |
// down: open dropdown or move selection down |
| 4792 |
case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_DOWN: |
| 4793 |
if (!self.isOpen && self.hasOptions) { |
| 4794 |
self.open(); |
| 4795 |
} |
| 4796 |
else if (self.activeOption) { |
| 4797 |
let next = self.getAdjacent(self.activeOption, 1); |
| 4798 |
if (next) |
| 4799 |
self.setActiveOption(next); |
| 4800 |
} |
| 4801 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4802 |
return; |
| 4803 |
// up: move selection up |
| 4804 |
case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_UP: |
| 4805 |
if (self.activeOption) { |
| 4806 |
let prev = self.getAdjacent(self.activeOption, -1); |
| 4807 |
if (prev) |
| 4808 |
self.setActiveOption(prev); |
| 4809 |
} |
| 4810 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4811 |
return; |
| 4812 |
// return: select active option |
| 4813 |
case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_RETURN: |
| 4814 |
if (self.canSelect(self.activeOption)) { |
| 4815 |
self.onOptionSelect(e, self.activeOption); |
| 4816 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4817 |
// if the option_create=null, the dropdown might be closed |
| 4818 |
} |
| 4819 |
else if (self.settings.create && self.createItem()) { |
| 4820 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4821 |
// don't submit form when searching for a value |
| 4822 |
} |
| 4823 |
else if (document.activeElement == self.control_input && self.isOpen) { |
| 4824 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4825 |
} |
| 4826 |
return; |
| 4827 |
// left: modifiy item selection to the left |
| 4828 |
case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_LEFT: |
| 4829 |
self.advanceSelection(-1, e); |
| 4830 |
return; |
| 4831 |
// right: modifiy item selection to the right |
| 4832 |
case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_RIGHT: |
| 4833 |
self.advanceSelection(1, e); |
| 4834 |
return; |
| 4835 |
// tab: select active option and/or create item |
| 4836 |
case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_TAB: |
| 4837 |
if (self.settings.selectOnTab) { |
| 4838 |
if (self.canSelect(self.activeOption)) { |
| 4839 |
self.onOptionSelect(e, self.activeOption); |
| 4840 |
// prevent default [tab] behaviour of jump to the next field |
| 4841 |
// if select isFull, then the dropdown won't be open and [tab] will work normally |
| 4842 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4843 |
} |
| 4844 |
if (self.settings.create && self.createItem()) { |
| 4845 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4846 |
} |
| 4847 |
} |
| 4848 |
return; |
| 4849 |
// delete|backspace: delete items |
| 4850 |
case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_BACKSPACE: |
| 4851 |
case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_DELETE: |
| 4852 |
self.deleteSelection(e); |
| 4853 |
return; |
| 4854 |
} |
| 4855 |
// don't enter text in the control_input when active items are selected |
| 4856 |
if (self.isInputHidden && !(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.isKeyDown)(_constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_SHORTCUT, e)) { |
| 4857 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4858 |
} |
| 4859 |
} |
| 4860 |
/** |
| 4861 |
* Triggered on <input> keyup. |
| 4862 |
* |
| 4863 |
*/ |
| 4864 |
onInput(e) { |
| 4865 |
if (this.isLocked) { |
| 4866 |
return; |
| 4867 |
} |
| 4868 |
const value = this.inputValue(); |
| 4869 |
if (this.lastValue === value) |
| 4870 |
return; |
| 4871 |
this.lastValue = value; |
| 4872 |
if (value == '') { |
| 4873 |
this._onInput(); |
| 4874 |
return; |
| 4875 |
} |
| 4876 |
if (this.refreshTimeout) { |
| 4877 |
window.clearTimeout(this.refreshTimeout); |
| 4878 |
} |
| 4879 |
this.refreshTimeout = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.timeout)(() => { |
| 4880 |
this.refreshTimeout = null; |
| 4881 |
this._onInput(); |
| 4882 |
}, this.settings.refreshThrottle); |
| 4883 |
} |
| 4884 |
_onInput() { |
| 4885 |
const value = this.lastValue; |
| 4886 |
if (this.settings.shouldLoad.call(this, value)) { |
| 4887 |
this.load(value); |
| 4888 |
} |
| 4889 |
this.refreshOptions(); |
| 4890 |
this.trigger('type', value); |
| 4891 |
} |
| 4892 |
/** |
| 4893 |
* Triggered when the user rolls over |
| 4894 |
* an option in the autocomplete dropdown menu. |
| 4895 |
* |
| 4896 |
*/ |
| 4897 |
onOptionHover(evt, option) { |
| 4898 |
if (this.ignoreHover) |
| 4899 |
return; |
| 4900 |
this.setActiveOption(option, false); |
| 4901 |
} |
| 4902 |
/** |
| 4903 |
* Triggered on <input> focus. |
| 4904 |
* |
| 4905 |
*/ |
| 4906 |
onFocus(e) { |
| 4907 |
var self = this; |
| 4908 |
var wasFocused = self.isFocused; |
| 4909 |
if (self.isDisabled || self.isReadOnly) { |
| 4910 |
self.blur(); |
| 4911 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 4912 |
return; |
| 4913 |
} |
| 4914 |
if (self.ignoreFocus) |
| 4915 |
return; |
| 4916 |
self.isFocused = true; |
| 4917 |
if (self.settings.preload === 'focus') |
| 4918 |
self.preload(); |
| 4919 |
if (!wasFocused) |
| 4920 |
self.trigger('focus'); |
| 4921 |
if (!self.activeItems.length) { |
| 4922 |
self.inputState(); |
| 4923 |
self.refreshOptions(!!self.settings.openOnFocus); |
| 4924 |
} |
| 4925 |
self.refreshState(); |
| 4926 |
} |
| 4927 |
/** |
| 4928 |
* Triggered on <input> blur. |
| 4929 |
* |
| 4930 |
*/ |
| 4931 |
onBlur(e) { |
| 4932 |
if (document.hasFocus() === false) |
| 4933 |
return; |
| 4934 |
var self = this; |
| 4935 |
if (!self.isFocused) |
| 4936 |
return; |
| 4937 |
self.isFocused = false; |
| 4938 |
self.ignoreFocus = false; |
| 4939 |
var deactivate = () => { |
| 4940 |
self.close(); |
| 4941 |
self.setActiveItem(); |
| 4942 |
self.setCaret(self.items.length); |
| 4943 |
self.trigger('blur'); |
| 4944 |
}; |
| 4945 |
if (self.settings.create && self.settings.createOnBlur) { |
| 4946 |
self.createItem(null, deactivate); |
| 4947 |
} |
| 4948 |
else { |
| 4949 |
deactivate(); |
| 4950 |
} |
| 4951 |
} |
| 4952 |
/** |
| 4953 |
* Triggered when the user clicks on an option |
| 4954 |
* in the autocomplete dropdown menu. |
| 4955 |
* |
| 4956 |
*/ |
| 4957 |
onOptionSelect(evt, option) { |
| 4958 |
var value, self = this; |
| 4959 |
// should not be possible to trigger a option under a disabled optgroup |
| 4960 |
if (option.parentElement && option.parentElement.matches('[data-disabled]')) { |
| 4961 |
return; |
| 4962 |
} |
| 4963 |
if (option.classList.contains('create')) { |
| 4964 |
self.createItem(null, () => { |
| 4965 |
if (self.settings.closeAfterSelect) { |
| 4966 |
self.close(); |
| 4967 |
} |
| 4968 |
}); |
| 4969 |
} |
| 4970 |
else { |
| 4971 |
value = option.dataset.value; |
| 4972 |
if (typeof value !== 'undefined') { |
| 4973 |
self.lastQuery = null; |
| 4974 |
self.addItem(value); |
| 4975 |
if (self.settings.closeAfterSelect) { |
| 4976 |
self.close(); |
| 4977 |
} |
| 4978 |
if (!self.settings.hideSelected && evt.type && /click/.test(evt.type)) { |
| 4979 |
self.setActiveOption(option); |
| 4980 |
} |
| 4981 |
} |
| 4982 |
} |
| 4983 |
} |
| 4984 |
/** |
| 4985 |
* Return true if the given option can be selected |
| 4986 |
* |
| 4987 |
*/ |
| 4988 |
canSelect(option) { |
| 4989 |
if (this.isOpen && option && this.dropdown_content.contains(option)) { |
| 4990 |
return true; |
| 4991 |
} |
| 4992 |
return false; |
| 4993 |
} |
| 4994 |
/** |
| 4995 |
* Triggered when the user clicks on an item |
| 4996 |
* that has been selected. |
| 4997 |
* |
| 4998 |
*/ |
| 4999 |
onItemSelect(evt, item) { |
| 5000 |
var self = this; |
| 5001 |
if (!self.isLocked && self.settings.mode === 'multi') { |
| 5002 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(evt); |
| 5003 |
self.setActiveItem(item, evt); |
| 5004 |
return true; |
| 5005 |
} |
| 5006 |
return false; |
| 5007 |
} |
| 5008 |
/** |
| 5009 |
* Determines whether or not to invoke |
| 5010 |
* the user-provided option provider / loader |
| 5011 |
* |
| 5012 |
* Note, there is a subtle difference between |
| 5013 |
* this.canLoad() and this.settings.shouldLoad(); |
| 5014 |
* |
| 5015 |
* - settings.shouldLoad() is a user-input validator. |
| 5016 |
* When false is returned, the not_loading template |
| 5017 |
* will be added to the dropdown |
| 5018 |
* |
| 5019 |
* - canLoad() is lower level validator that checks |
| 5020 |
* the Tom Select instance. There is no inherent user |
| 5021 |
* feedback when canLoad returns false |
| 5022 |
* |
| 5023 |
*/ |
| 5024 |
canLoad(value) { |
| 5025 |
if (!this.settings.load) |
| 5026 |
return false; |
| 5027 |
if (this.loadedSearches.hasOwnProperty(value)) |
| 5028 |
return false; |
| 5029 |
return true; |
| 5030 |
} |
| 5031 |
/** |
| 5032 |
* Invokes the user-provided option provider / loader. |
| 5033 |
* |
| 5034 |
*/ |
| 5035 |
load(value) { |
| 5036 |
const self = this; |
| 5037 |
if (!self.canLoad(value)) |
| 5038 |
return; |
| 5039 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(self.wrapper, self.settings.loadingClass); |
| 5040 |
self.loading++; |
| 5041 |
const callback = self.loadCallback.bind(self); |
| 5042 |
self.settings.load.call(self, value, callback); |
| 5043 |
} |
| 5044 |
/** |
| 5045 |
* Invoked by the user-provided option provider |
| 5046 |
* |
| 5047 |
*/ |
| 5048 |
loadCallback(options, optgroups) { |
| 5049 |
const self = this; |
| 5050 |
self.loading = Math.max(self.loading - 1, 0); |
| 5051 |
self.lastQuery = null; |
| 5052 |
self.clearActiveOption(); // when new results load, focus should be on first option |
| 5053 |
self.setupOptions(options, optgroups); |
| 5054 |
self.refreshOptions(self.isFocused && !self.isInputHidden); |
| 5055 |
if (!self.loading) { |
| 5056 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(self.wrapper, self.settings.loadingClass); |
| 5057 |
} |
| 5058 |
self.trigger('load', options, optgroups); |
| 5059 |
} |
| 5060 |
preload() { |
| 5061 |
var classList = this.wrapper.classList; |
| 5062 |
if (classList.contains('preloaded')) |
| 5063 |
return; |
| 5064 |
classList.add('preloaded'); |
| 5065 |
this.load(''); |
| 5066 |
} |
| 5067 |
/** |
| 5068 |
* Sets the input field of the control to the specified value. |
| 5069 |
* |
| 5070 |
*/ |
| 5071 |
setTextboxValue(value = '') { |
| 5072 |
var input = this.control_input; |
| 5073 |
var changed = input.value !== value; |
| 5074 |
if (changed) { |
| 5075 |
input.value = value; |
| 5076 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.triggerEvent)(input, 'update'); |
| 5077 |
this.lastValue = value; |
| 5078 |
} |
| 5079 |
} |
| 5080 |
/** |
| 5081 |
* Returns the value of the control. If multiple items |
| 5082 |
* can be selected (e.g. <select multiple>), this returns |
| 5083 |
* an array. If only one item can be selected, this |
| 5084 |
* returns a string. |
| 5085 |
* |
| 5086 |
*/ |
| 5087 |
getValue() { |
| 5088 |
if (this.is_select_tag && this.input.hasAttribute('multiple')) { |
| 5089 |
return this.items; |
| 5090 |
} |
| 5091 |
return this.items.join(this.settings.delimiter); |
| 5092 |
} |
| 5093 |
/** |
| 5094 |
* Resets the selected items to the given value. |
| 5095 |
* |
| 5096 |
*/ |
| 5097 |
setValue(value, silent) { |
| 5098 |
var events = silent ? [] : ['change']; |
| 5099 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.debounce_events)(this, events, () => { |
| 5100 |
this.clear(silent); |
| 5101 |
this.addItems(value, silent); |
| 5102 |
}); |
| 5103 |
} |
| 5104 |
/** |
| 5105 |
* Resets the number of max items to the given value |
| 5106 |
* |
| 5107 |
*/ |
| 5108 |
setMaxItems(value) { |
| 5109 |
if (value === 0) |
| 5110 |
value = null; //reset to unlimited items. |
| 5111 |
this.settings.maxItems = value; |
| 5112 |
this.refreshState(); |
| 5113 |
} |
| 5114 |
/** |
| 5115 |
* Sets the selected item. |
| 5116 |
* |
| 5117 |
*/ |
| 5118 |
setActiveItem(item, e) { |
| 5119 |
var self = this; |
| 5120 |
var eventName; |
| 5121 |
var i, begin, end, swap; |
| 5122 |
var last; |
| 5123 |
if (self.settings.mode === 'single') |
| 5124 |
return; |
| 5125 |
// clear the active selection |
| 5126 |
if (!item) { |
| 5127 |
self.clearActiveItems(); |
| 5128 |
if (self.isFocused) { |
| 5129 |
self.inputState(); |
| 5130 |
} |
| 5131 |
return; |
| 5132 |
} |
| 5133 |
// modify selection |
| 5134 |
eventName = e && e.type.toLowerCase(); |
| 5135 |
if (eventName === 'click' && (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.isKeyDown)('shiftKey', e) && self.activeItems.length) { |
| 5136 |
last = self.getLastActive(); |
| 5137 |
begin = Array.prototype.indexOf.call(self.control.children, last); |
| 5138 |
end = Array.prototype.indexOf.call(self.control.children, item); |
| 5139 |
if (begin > end) { |
| 5140 |
swap = begin; |
| 5141 |
begin = end; |
| 5142 |
end = swap; |
| 5143 |
} |
| 5144 |
for (i = begin; i <= end; i++) { |
| 5145 |
item = self.control.children[i]; |
| 5146 |
if (self.activeItems.indexOf(item) === -1) { |
| 5147 |
self.setActiveItemClass(item); |
| 5148 |
} |
| 5149 |
} |
| 5150 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 5151 |
} |
| 5152 |
else if ((eventName === 'click' && (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.isKeyDown)(_constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_SHORTCUT, e)) || (eventName === 'keydown' && (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.isKeyDown)('shiftKey', e))) { |
| 5153 |
if (item.classList.contains('active')) { |
| 5154 |
self.removeActiveItem(item); |
| 5155 |
} |
| 5156 |
else { |
| 5157 |
self.setActiveItemClass(item); |
| 5158 |
} |
| 5159 |
} |
| 5160 |
else { |
| 5161 |
self.clearActiveItems(); |
| 5162 |
self.setActiveItemClass(item); |
| 5163 |
} |
| 5164 |
// ensure control has focus |
| 5165 |
self.inputState(); |
| 5166 |
if (!self.isFocused) { |
| 5167 |
self.focus(); |
| 5168 |
} |
| 5169 |
} |
| 5170 |
/** |
| 5171 |
* Set the active and last-active classes |
| 5172 |
* |
| 5173 |
*/ |
| 5174 |
setActiveItemClass(item) { |
| 5175 |
const self = this; |
| 5176 |
const last_active = self.control.querySelector('.last-active'); |
| 5177 |
if (last_active) |
| 5178 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(last_active, 'last-active'); |
| 5179 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(item, 'active last-active'); |
| 5180 |
self.trigger('item_select', item); |
| 5181 |
if (self.activeItems.indexOf(item) == -1) { |
| 5182 |
self.activeItems.push(item); |
| 5183 |
} |
| 5184 |
} |
| 5185 |
/** |
| 5186 |
* Remove active item |
| 5187 |
* |
| 5188 |
*/ |
| 5189 |
removeActiveItem(item) { |
| 5190 |
var idx = this.activeItems.indexOf(item); |
| 5191 |
this.activeItems.splice(idx, 1); |
| 5192 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(item, 'active'); |
| 5193 |
} |
| 5194 |
/** |
| 5195 |
* Clears all the active items |
| 5196 |
* |
| 5197 |
*/ |
| 5198 |
clearActiveItems() { |
| 5199 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(this.activeItems, 'active'); |
| 5200 |
this.activeItems = []; |
| 5201 |
} |
| 5202 |
/** |
| 5203 |
* Sets the selected item in the dropdown menu |
| 5204 |
* of available options. |
| 5205 |
* |
| 5206 |
*/ |
| 5207 |
setActiveOption(option, scroll = true) { |
| 5208 |
if (option === this.activeOption) { |
| 5209 |
return; |
| 5210 |
} |
| 5211 |
this.clearActiveOption(); |
| 5212 |
if (!option) |
| 5213 |
return; |
| 5214 |
this.activeOption = option; |
| 5215 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(this.focus_node, { 'aria-activedescendant': option.getAttribute('id') }); |
| 5216 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(option, { 'aria-selected': 'true' }); |
| 5217 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(option, 'active'); |
| 5218 |
if (scroll) |
| 5219 |
this.scrollToOption(option); |
| 5220 |
} |
| 5221 |
/** |
| 5222 |
* Sets the dropdown_content scrollTop to display the option |
| 5223 |
* |
| 5224 |
*/ |
| 5225 |
scrollToOption(option, behavior) { |
| 5226 |
if (!option) |
| 5227 |
return; |
| 5228 |
const content = this.dropdown_content; |
| 5229 |
const height_menu = content.clientHeight; |
| 5230 |
const scrollTop = content.scrollTop || 0; |
| 5231 |
const height_item = option.offsetHeight; |
| 5232 |
const y = option.getBoundingClientRect().top - content.getBoundingClientRect().top + scrollTop; |
| 5233 |
if (y + height_item > height_menu + scrollTop) { |
| 5234 |
this.scroll(y - height_menu + height_item, behavior); |
| 5235 |
} |
| 5236 |
else if (y < scrollTop) { |
| 5237 |
this.scroll(y, behavior); |
| 5238 |
} |
| 5239 |
} |
| 5240 |
/** |
| 5241 |
* Scroll the dropdown to the given position |
| 5242 |
* |
| 5243 |
*/ |
| 5244 |
scroll(scrollTop, behavior) { |
| 5245 |
const content = this.dropdown_content; |
| 5246 |
if (behavior) { |
| 5247 |
content.style.scrollBehavior = behavior; |
| 5248 |
} |
| 5249 |
content.scrollTop = scrollTop; |
| 5250 |
content.style.scrollBehavior = ''; |
| 5251 |
} |
| 5252 |
/** |
| 5253 |
* Clears the active option |
| 5254 |
* |
| 5255 |
*/ |
| 5256 |
clearActiveOption() { |
| 5257 |
if (this.activeOption) { |
| 5258 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(this.activeOption, 'active'); |
| 5259 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(this.activeOption, { 'aria-selected': null }); |
| 5260 |
} |
| 5261 |
this.activeOption = null; |
| 5262 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(this.focus_node, { 'aria-activedescendant': null }); |
| 5263 |
} |
| 5264 |
/** |
| 5265 |
* Selects all items (CTRL + A). |
| 5266 |
*/ |
| 5267 |
selectAll() { |
| 5268 |
const self = this; |
| 5269 |
if (self.settings.mode === 'single') |
| 5270 |
return; |
| 5271 |
const activeItems = self.controlChildren(); |
| 5272 |
if (!activeItems.length) |
| 5273 |
return; |
| 5274 |
self.inputState(); |
| 5275 |
self.close(); |
| 5276 |
self.activeItems = activeItems; |
| 5277 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(activeItems, (item) => { |
| 5278 |
self.setActiveItemClass(item); |
| 5279 |
}); |
| 5280 |
} |
| 5281 |
/** |
| 5282 |
* Determines if the control_input should be in a hidden or visible state |
| 5283 |
* |
| 5284 |
*/ |
| 5285 |
inputState() { |
| 5286 |
var self = this; |
| 5287 |
if (!self.control.contains(self.control_input)) |
| 5288 |
return; |
| 5289 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(self.control_input, { placeholder: self.settings.placeholder }); |
| 5290 |
if (self.activeItems.length > 0 || (!self.isFocused && self.settings.hidePlaceholder && self.items.length > 0)) { |
| 5291 |
self.setTextboxValue(); |
| 5292 |
self.isInputHidden = true; |
| 5293 |
} |
| 5294 |
else { |
| 5295 |
if (self.settings.hidePlaceholder && self.items.length > 0) { |
| 5296 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(self.control_input, { placeholder: '' }); |
| 5297 |
} |
| 5298 |
self.isInputHidden = false; |
| 5299 |
} |
| 5300 |
self.wrapper.classList.toggle('input-hidden', self.isInputHidden); |
| 5301 |
} |
| 5302 |
/** |
| 5303 |
* Get the input value |
| 5304 |
*/ |
| 5305 |
inputValue() { |
| 5306 |
return this.control_input.value.trim(); |
| 5307 |
} |
| 5308 |
/** |
| 5309 |
* Gives the control focus. |
| 5310 |
*/ |
| 5311 |
focus() { |
| 5312 |
var self = this; |
| 5313 |
if (self.isDisabled || self.isReadOnly) |
| 5314 |
return; |
| 5315 |
self.ignoreFocus = true; |
| 5316 |
if (self.control_input.offsetWidth) { |
| 5317 |
self.control_input.focus(); |
| 5318 |
} |
| 5319 |
else { |
| 5320 |
self.focus_node.focus(); |
| 5321 |
} |
| 5322 |
setTimeout(() => { |
| 5323 |
self.ignoreFocus = false; |
| 5324 |
self.onFocus(); |
| 5325 |
}, 0); |
| 5326 |
} |
| 5327 |
/** |
| 5328 |
* Forces the control out of focus. |
| 5329 |
* |
| 5330 |
*/ |
| 5331 |
blur() { |
| 5332 |
this.focus_node.blur(); |
| 5333 |
this.onBlur(); |
| 5334 |
} |
| 5335 |
/** |
| 5336 |
* Returns a function that scores an object |
| 5337 |
* to show how good of a match it is to the |
| 5338 |
* provided query. |
| 5339 |
* |
| 5340 |
* @return {function} |
| 5341 |
*/ |
| 5342 |
getScoreFunction(query) { |
| 5343 |
return this.sifter.getScoreFunction(query, this.getSearchOptions()); |
| 5344 |
} |
| 5345 |
/** |
| 5346 |
* Returns search options for sifter (the system |
| 5347 |
* for scoring and sorting results). |
| 5348 |
* |
| 5349 |
* @see https://github.com/orchidjs/sifter.js |
| 5350 |
* @return {object} |
| 5351 |
*/ |
| 5352 |
getSearchOptions() { |
| 5353 |
var settings = this.settings; |
| 5354 |
var sort = settings.sortField; |
| 5355 |
if (typeof settings.sortField === 'string') { |
| 5356 |
sort = [{ field: settings.sortField }]; |
| 5357 |
} |
| 5358 |
return { |
| 5359 |
fields: settings.searchField, |
| 5360 |
conjunction: settings.searchConjunction, |
| 5361 |
sort: sort, |
| 5362 |
nesting: settings.nesting |
| 5363 |
}; |
| 5364 |
} |
| 5365 |
/** |
| 5366 |
* Searches through available options and returns |
| 5367 |
* a sorted array of matches. |
| 5368 |
* |
| 5369 |
*/ |
| 5370 |
search(query) { |
| 5371 |
var result, calculateScore; |
| 5372 |
var self = this; |
| 5373 |
var options = this.getSearchOptions(); |
| 5374 |
// validate user-provided result scoring function |
| 5375 |
if (self.settings.score) { |
| 5376 |
calculateScore = self.settings.score.call(self, query); |
| 5377 |
if (typeof calculateScore !== 'function') { |
| 5378 |
throw new Error('Tom Select "score" setting must be a function that returns a function'); |
| 5379 |
} |
| 5380 |
} |
| 5381 |
// perform search |
| 5382 |
if (query !== self.lastQuery) { |
| 5383 |
self.lastQuery = query; |
| 5384 |
result = self.sifter.search(query, Object.assign(options, { score: calculateScore })); |
| 5385 |
self.currentResults = result; |
| 5386 |
} |
| 5387 |
else { |
| 5388 |
result = Object.assign({}, self.currentResults); |
| 5389 |
} |
| 5390 |
// filter out selected items |
| 5391 |
if (self.settings.hideSelected) { |
| 5392 |
result.items = result.items.filter((item) => { |
| 5393 |
let hashed = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(item.id); |
| 5394 |
return !(hashed && self.items.indexOf(hashed) !== -1); |
| 5395 |
}); |
| 5396 |
} |
| 5397 |
return result; |
| 5398 |
} |
| 5399 |
/** |
| 5400 |
* Refreshes the list of available options shown |
| 5401 |
* in the autocomplete dropdown menu. |
| 5402 |
* |
| 5403 |
*/ |
| 5404 |
refreshOptions(triggerDropdown = true) { |
| 5405 |
var i, j, k, n, optgroup, optgroups, html, has_create_option, active_group; |
| 5406 |
var create; |
| 5407 |
const groups = {}; |
| 5408 |
const groups_order = []; |
| 5409 |
var self = this; |
| 5410 |
var query = self.inputValue(); |
| 5411 |
const same_query = query === self.lastQuery || (query == '' && self.lastQuery == null); |
| 5412 |
var results = self.search(query); |
| 5413 |
var active_option = null; |
| 5414 |
var show_dropdown = self.settings.shouldOpen || false; |
| 5415 |
var dropdown_content = self.dropdown_content; |
| 5416 |
if (same_query) { |
| 5417 |
active_option = self.activeOption; |
| 5418 |
if (active_option) { |
| 5419 |
active_group = active_option.closest('[data-group]'); |
| 5420 |
} |
| 5421 |
} |
| 5422 |
// build markup |
| 5423 |
n = results.items.length; |
| 5424 |
if (typeof self.settings.maxOptions === 'number') { |
| 5425 |
n = Math.min(n, self.settings.maxOptions); |
| 5426 |
} |
| 5427 |
if (n > 0) { |
| 5428 |
show_dropdown = true; |
| 5429 |
} |
| 5430 |
// get fragment for group and the position of the group in group_order |
| 5431 |
const getGroupFragment = (optgroup, order) => { |
| 5432 |
let group_order_i = groups[optgroup]; |
| 5433 |
if (group_order_i !== undefined) { |
| 5434 |
let order_group = groups_order[group_order_i]; |
| 5435 |
if (order_group !== undefined) { |
| 5436 |
return [group_order_i, order_group.fragment]; |
| 5437 |
} |
| 5438 |
} |
| 5439 |
let group_fragment = document.createDocumentFragment(); |
| 5440 |
group_order_i = groups_order.length; |
| 5441 |
groups_order.push({ fragment: group_fragment, order, optgroup }); |
| 5442 |
return [group_order_i, group_fragment]; |
| 5443 |
}; |
| 5444 |
// render and group available options individually |
| 5445 |
for (i = 0; i < n; i++) { |
| 5446 |
// get option dom element |
| 5447 |
let item = results.items[i]; |
| 5448 |
if (!item) |
| 5449 |
continue; |
| 5450 |
let opt_value = item.id; |
| 5451 |
let option = self.options[opt_value]; |
| 5452 |
if (option === undefined) |
| 5453 |
continue; |
| 5454 |
let opt_hash = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.get_hash)(opt_value); |
| 5455 |
let option_el = self.getOption(opt_hash, true); |
| 5456 |
// toggle 'selected' class |
| 5457 |
if (!self.settings.hideSelected) { |
| 5458 |
option_el.classList.toggle('selected', self.items.includes(opt_hash)); |
| 5459 |
} |
| 5460 |
optgroup = option[self.settings.optgroupField] || ''; |
| 5461 |
optgroups = Array.isArray(optgroup) ? optgroup : [optgroup]; |
| 5462 |
for (j = 0, k = optgroups && optgroups.length; j < k; j++) { |
| 5463 |
optgroup = optgroups[j]; |
| 5464 |
let order = option.$order; |
| 5465 |
let self_optgroup = self.optgroups[optgroup]; |
| 5466 |
if (self_optgroup === undefined) { |
| 5467 |
optgroup = ''; |
| 5468 |
} |
| 5469 |
else { |
| 5470 |
order = self_optgroup.$order; |
| 5471 |
} |
| 5472 |
const [group_order_i, group_fragment] = getGroupFragment(optgroup, order); |
| 5473 |
// nodes can only have one parent, so if the option is in mutple groups, we need a clone |
| 5474 |
if (j > 0) { |
| 5475 |
option_el = option_el.cloneNode(true); |
| 5476 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(option_el, { id: option.$id + '-clone-' + j, 'aria-selected': null }); |
| 5477 |
option_el.classList.add('ts-cloned'); |
| 5478 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(option_el, 'active'); |
| 5479 |
// make sure we keep the activeOption in the same group |
| 5480 |
if (self.activeOption && self.activeOption.dataset.value == opt_value) { |
| 5481 |
if (active_group && active_group.dataset.group === optgroup.toString()) { |
| 5482 |
active_option = option_el; |
| 5483 |
} |
| 5484 |
} |
| 5485 |
} |
| 5486 |
group_fragment.appendChild(option_el); |
| 5487 |
if (optgroup != '') { |
| 5488 |
groups[optgroup] = group_order_i; |
| 5489 |
} |
| 5490 |
} |
| 5491 |
} |
| 5492 |
// sort optgroups |
| 5493 |
if (self.settings.lockOptgroupOrder) { |
| 5494 |
groups_order.sort((a, b) => { |
| 5495 |
return a.order - b.order; |
| 5496 |
}); |
| 5497 |
} |
| 5498 |
// render optgroup headers & join groups |
| 5499 |
html = document.createDocumentFragment(); |
| 5500 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(groups_order, (group_order) => { |
| 5501 |
let group_fragment = group_order.fragment; |
| 5502 |
let optgroup = group_order.optgroup; |
| 5503 |
if (!group_fragment || !group_fragment.children.length) |
| 5504 |
return; |
| 5505 |
let group_heading = self.optgroups[optgroup]; |
| 5506 |
if (group_heading !== undefined) { |
| 5507 |
let group_options = document.createDocumentFragment(); |
| 5508 |
let header = self.render('optgroup_header', group_heading); |
| 5509 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(group_options, header); |
| 5510 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(group_options, group_fragment); |
| 5511 |
let group_html = self.render('optgroup', { group: group_heading, options: group_options }); |
| 5512 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(html, group_html); |
| 5513 |
} |
| 5514 |
else { |
| 5515 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(html, group_fragment); |
| 5516 |
} |
| 5517 |
}); |
| 5518 |
dropdown_content.innerHTML = ''; |
| 5519 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(dropdown_content, html); |
| 5520 |
// highlight matching terms inline |
| 5521 |
if (self.settings.highlight) { |
| 5522 |
(0,_contrib_highlight_js__WEBPACK_IMPORTED_MODULE_4__.removeHighlight)(dropdown_content); |
| 5523 |
if (results.query.length && results.tokens.length) { |
| 5524 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(results.tokens, (tok) => { |
| 5525 |
(0,_contrib_highlight_js__WEBPACK_IMPORTED_MODULE_4__.highlight)(dropdown_content, tok.regex); |
| 5526 |
}); |
| 5527 |
} |
| 5528 |
} |
| 5529 |
// helper method for adding templates to dropdown |
| 5530 |
var add_template = (template) => { |
| 5531 |
let content = self.render(template, { input: query }); |
| 5532 |
if (content) { |
| 5533 |
show_dropdown = true; |
| 5534 |
dropdown_content.insertBefore(content, dropdown_content.firstChild); |
| 5535 |
} |
| 5536 |
return content; |
| 5537 |
}; |
| 5538 |
// add loading message |
| 5539 |
if (self.loading) { |
| 5540 |
add_template('loading'); |
| 5541 |
// invalid query |
| 5542 |
} |
| 5543 |
else if (!self.settings.shouldLoad.call(self, query)) { |
| 5544 |
add_template('not_loading'); |
| 5545 |
// add no_results message |
| 5546 |
} |
| 5547 |
else if (results.items.length === 0) { |
| 5548 |
add_template('no_results'); |
| 5549 |
} |
| 5550 |
// add create option |
| 5551 |
has_create_option = self.canCreate(query); |
| 5552 |
if (has_create_option) { |
| 5553 |
create = add_template('option_create'); |
| 5554 |
} |
| 5555 |
// activate |
| 5556 |
self.hasOptions = results.items.length > 0 || has_create_option; |
| 5557 |
if (show_dropdown) { |
| 5558 |
if (results.items.length > 0) { |
| 5559 |
if (!active_option && self.settings.mode === 'single' && self.items[0] != undefined) { |
| 5560 |
active_option = self.getOption(self.items[0]); |
| 5561 |
} |
| 5562 |
if (!dropdown_content.contains(active_option)) { |
| 5563 |
let active_index = 0; |
| 5564 |
if (create && !self.settings.addPrecedence) { |
| 5565 |
active_index = 1; |
| 5566 |
} |
| 5567 |
active_option = self.selectable()[active_index]; |
| 5568 |
} |
| 5569 |
} |
| 5570 |
else if (create) { |
| 5571 |
active_option = create; |
| 5572 |
} |
| 5573 |
if (triggerDropdown && !self.isOpen) { |
| 5574 |
self.open(); |
| 5575 |
self.scrollToOption(active_option, 'auto'); |
| 5576 |
} |
| 5577 |
self.setActiveOption(active_option); |
| 5578 |
} |
| 5579 |
else { |
| 5580 |
self.clearActiveOption(); |
| 5581 |
if (triggerDropdown && self.isOpen) { |
| 5582 |
self.close(false); // if create_option=null, we want the dropdown to close but not reset the textbox value |
| 5583 |
} |
| 5584 |
} |
| 5585 |
} |
| 5586 |
/** |
| 5587 |
* Return list of selectable options |
| 5588 |
* |
| 5589 |
*/ |
| 5590 |
selectable() { |
| 5591 |
return this.dropdown_content.querySelectorAll('[data-selectable]'); |
| 5592 |
} |
| 5593 |
/** |
| 5594 |
* Adds an available option. If it already exists, |
| 5595 |
* nothing will happen. Note: this does not refresh |
| 5596 |
* the options list dropdown (use `refreshOptions` |
| 5597 |
* for that). |
| 5598 |
* |
| 5599 |
* Usage: |
| 5600 |
* |
| 5601 |
* this.addOption(data) |
| 5602 |
* |
| 5603 |
*/ |
| 5604 |
addOption(data, user_created = false) { |
| 5605 |
const self = this; |
| 5606 |
// @deprecated 1.7.7 |
| 5607 |
// use addOptions( array, user_created ) for adding multiple options |
| 5608 |
if (Array.isArray(data)) { |
| 5609 |
self.addOptions(data, user_created); |
| 5610 |
return false; |
| 5611 |
} |
| 5612 |
const key = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(data[self.settings.valueField]); |
| 5613 |
if (key === null || self.options.hasOwnProperty(key)) { |
| 5614 |
return false; |
| 5615 |
} |
| 5616 |
data.$order = data.$order || ++self.order; |
| 5617 |
data.$id = self.inputId + '-opt-' + data.$order; |
| 5618 |
self.options[key] = data; |
| 5619 |
self.lastQuery = null; |
| 5620 |
if (user_created) { |
| 5621 |
self.userOptions[key] = user_created; |
| 5622 |
self.trigger('option_add', key, data); |
| 5623 |
} |
| 5624 |
return key; |
| 5625 |
} |
| 5626 |
/** |
| 5627 |
* Add multiple options |
| 5628 |
* |
| 5629 |
*/ |
| 5630 |
addOptions(data, user_created = false) { |
| 5631 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(data, (dat) => { |
| 5632 |
this.addOption(dat, user_created); |
| 5633 |
}); |
| 5634 |
} |
| 5635 |
/** |
| 5636 |
* @deprecated 1.7.7 |
| 5637 |
*/ |
| 5638 |
registerOption(data) { |
| 5639 |
return this.addOption(data); |
| 5640 |
} |
| 5641 |
/** |
| 5642 |
* Registers an option group to the pool of option groups. |
| 5643 |
* |
| 5644 |
* @return {boolean|string} |
| 5645 |
*/ |
| 5646 |
registerOptionGroup(data) { |
| 5647 |
var key = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(data[this.settings.optgroupValueField]); |
| 5648 |
if (key === null) |
| 5649 |
return false; |
| 5650 |
data.$order = data.$order || ++this.order; |
| 5651 |
this.optgroups[key] = data; |
| 5652 |
return key; |
| 5653 |
} |
| 5654 |
/** |
| 5655 |
* Registers a new optgroup for options |
| 5656 |
* to be bucketed into. |
| 5657 |
* |
| 5658 |
*/ |
| 5659 |
addOptionGroup(id, data) { |
| 5660 |
var hashed_id; |
| 5661 |
data[this.settings.optgroupValueField] = id; |
| 5662 |
if (hashed_id = this.registerOptionGroup(data)) { |
| 5663 |
this.trigger('optgroup_add', hashed_id, data); |
| 5664 |
} |
| 5665 |
} |
| 5666 |
/** |
| 5667 |
* Removes an existing option group. |
| 5668 |
* |
| 5669 |
*/ |
| 5670 |
removeOptionGroup(id) { |
| 5671 |
if (this.optgroups.hasOwnProperty(id)) { |
| 5672 |
delete this.optgroups[id]; |
| 5673 |
this.clearCache(); |
| 5674 |
this.trigger('optgroup_remove', id); |
| 5675 |
} |
| 5676 |
} |
| 5677 |
/** |
| 5678 |
* Clears all existing option groups. |
| 5679 |
*/ |
| 5680 |
clearOptionGroups() { |
| 5681 |
this.optgroups = {}; |
| 5682 |
this.clearCache(); |
| 5683 |
this.trigger('optgroup_clear'); |
| 5684 |
} |
| 5685 |
/** |
| 5686 |
* Updates an option available for selection. If |
| 5687 |
* it is visible in the selected items or options |
| 5688 |
* dropdown, it will be re-rendered automatically. |
| 5689 |
* |
| 5690 |
*/ |
| 5691 |
updateOption(value, data) { |
| 5692 |
const self = this; |
| 5693 |
var item_new; |
| 5694 |
var index_item; |
| 5695 |
const value_old = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(value); |
| 5696 |
const value_new = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(data[self.settings.valueField]); |
| 5697 |
// sanity checks |
| 5698 |
if (value_old === null) |
| 5699 |
return; |
| 5700 |
const data_old = self.options[value_old]; |
| 5701 |
if (data_old == undefined) |
| 5702 |
return; |
| 5703 |
if (typeof value_new !== 'string') |
| 5704 |
throw new Error('Value must be set in option data'); |
| 5705 |
const option = self.getOption(value_old); |
| 5706 |
const item = self.getItem(value_old); |
| 5707 |
data.$order = data.$order || data_old.$order; |
| 5708 |
delete self.options[value_old]; |
| 5709 |
// invalidate render cache |
| 5710 |
// don't remove existing node yet, we'll remove it after replacing it |
| 5711 |
self.uncacheValue(value_new); |
| 5712 |
self.options[value_new] = data; |
| 5713 |
// update the option if it's in the dropdown |
| 5714 |
if (option) { |
| 5715 |
if (self.dropdown_content.contains(option)) { |
| 5716 |
const option_new = self._render('option', data); |
| 5717 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.replaceNode)(option, option_new); |
| 5718 |
if (self.activeOption === option) { |
| 5719 |
self.setActiveOption(option_new); |
| 5720 |
} |
| 5721 |
} |
| 5722 |
option.remove(); |
| 5723 |
} |
| 5724 |
// update the item if we have one |
| 5725 |
if (item) { |
| 5726 |
index_item = self.items.indexOf(value_old); |
| 5727 |
if (index_item !== -1) { |
| 5728 |
self.items.splice(index_item, 1, value_new); |
| 5729 |
} |
| 5730 |
item_new = self._render('item', data); |
| 5731 |
if (item.classList.contains('active')) |
| 5732 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(item_new, 'active'); |
| 5733 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.replaceNode)(item, item_new); |
| 5734 |
} |
| 5735 |
// invalidate last query because we might have updated the sortField |
| 5736 |
self.lastQuery = null; |
| 5737 |
} |
| 5738 |
/** |
| 5739 |
* Removes a single option. |
| 5740 |
* |
| 5741 |
*/ |
| 5742 |
removeOption(value, silent) { |
| 5743 |
const self = this; |
| 5744 |
value = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.get_hash)(value); |
| 5745 |
self.uncacheValue(value); |
| 5746 |
delete self.userOptions[value]; |
| 5747 |
delete self.options[value]; |
| 5748 |
self.lastQuery = null; |
| 5749 |
self.trigger('option_remove', value); |
| 5750 |
self.removeItem(value, silent); |
| 5751 |
} |
| 5752 |
/** |
| 5753 |
* Clears all options. |
| 5754 |
*/ |
| 5755 |
clearOptions(filter) { |
| 5756 |
const boundFilter = (filter || this.clearFilter).bind(this); |
| 5757 |
this.loadedSearches = {}; |
| 5758 |
this.userOptions = {}; |
| 5759 |
this.clearCache(); |
| 5760 |
const selected = {}; |
| 5761 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(this.options, (option, key) => { |
| 5762 |
if (boundFilter(option, key)) { |
| 5763 |
selected[key] = option; |
| 5764 |
} |
| 5765 |
}); |
| 5766 |
this.options = this.sifter.items = selected; |
| 5767 |
this.lastQuery = null; |
| 5768 |
this.trigger('option_clear'); |
| 5769 |
} |
| 5770 |
/** |
| 5771 |
* Used by clearOptions() to decide whether or not an option should be removed |
| 5772 |
* Return true to keep an option, false to remove |
| 5773 |
* |
| 5774 |
*/ |
| 5775 |
clearFilter(option, value) { |
| 5776 |
if (this.items.indexOf(value) >= 0) { |
| 5777 |
return true; |
| 5778 |
} |
| 5779 |
return false; |
| 5780 |
} |
| 5781 |
/** |
| 5782 |
* Returns the dom element of the option |
| 5783 |
* matching the given value. |
| 5784 |
* |
| 5785 |
*/ |
| 5786 |
getOption(value, create = false) { |
| 5787 |
const hashed = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(value); |
| 5788 |
if (hashed === null) |
| 5789 |
return null; |
| 5790 |
const option = this.options[hashed]; |
| 5791 |
if (option != undefined) { |
| 5792 |
if (option.$div) { |
| 5793 |
return option.$div; |
| 5794 |
} |
| 5795 |
if (create) { |
| 5796 |
return this._render('option', option); |
| 5797 |
} |
| 5798 |
} |
| 5799 |
return null; |
| 5800 |
} |
| 5801 |
/** |
| 5802 |
* Returns the dom element of the next or previous dom element of the same type |
| 5803 |
* Note: adjacent options may not be adjacent DOM elements (optgroups) |
| 5804 |
* |
| 5805 |
*/ |
| 5806 |
getAdjacent(option, direction, type = 'option') { |
| 5807 |
var self = this, all; |
| 5808 |
if (!option) { |
| 5809 |
return null; |
| 5810 |
} |
| 5811 |
if (type == 'item') { |
| 5812 |
all = self.controlChildren(); |
| 5813 |
} |
| 5814 |
else { |
| 5815 |
all = self.dropdown_content.querySelectorAll('[data-selectable]'); |
| 5816 |
} |
| 5817 |
for (let i = 0; i < all.length; i++) { |
| 5818 |
if (all[i] != option) { |
| 5819 |
continue; |
| 5820 |
} |
| 5821 |
if (direction > 0) { |
| 5822 |
return all[i + 1]; |
| 5823 |
} |
| 5824 |
return all[i - 1]; |
| 5825 |
} |
| 5826 |
return null; |
| 5827 |
} |
| 5828 |
/** |
| 5829 |
* Returns the dom element of the item |
| 5830 |
* matching the given value. |
| 5831 |
* |
| 5832 |
*/ |
| 5833 |
getItem(item) { |
| 5834 |
if (typeof item == 'object') { |
| 5835 |
return item; |
| 5836 |
} |
| 5837 |
var value = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(item); |
| 5838 |
return value !== null |
| 5839 |
? this.control.querySelector(`[data-value="${(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addSlashes)(value)}"]`) |
| 5840 |
: null; |
| 5841 |
} |
| 5842 |
/** |
| 5843 |
* "Selects" multiple items at once. Adds them to the list |
| 5844 |
* at the current caret position. |
| 5845 |
* |
| 5846 |
*/ |
| 5847 |
addItems(values, silent) { |
| 5848 |
var self = this; |
| 5849 |
var items = Array.isArray(values) ? values : [values]; |
| 5850 |
items = items.filter(x => self.items.indexOf(x) === -1); |
| 5851 |
const last_item = items[items.length - 1]; |
| 5852 |
items.forEach(item => { |
| 5853 |
self.isPending = (item !== last_item); |
| 5854 |
self.addItem(item, silent); |
| 5855 |
}); |
| 5856 |
} |
| 5857 |
/** |
| 5858 |
* "Selects" an item. Adds it to the list |
| 5859 |
* at the current caret position. |
| 5860 |
* |
| 5861 |
*/ |
| 5862 |
addItem(value, silent) { |
| 5863 |
var events = silent ? [] : ['change', 'dropdown_close']; |
| 5864 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.debounce_events)(this, events, () => { |
| 5865 |
var item, wasFull; |
| 5866 |
const self = this; |
| 5867 |
const inputMode = self.settings.mode; |
| 5868 |
const hashed = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(value); |
| 5869 |
if (hashed && self.items.indexOf(hashed) !== -1) { |
| 5870 |
if (inputMode === 'single') { |
| 5871 |
self.close(); |
| 5872 |
} |
| 5873 |
if (inputMode === 'single' || !self.settings.duplicates) { |
| 5874 |
return; |
| 5875 |
} |
| 5876 |
} |
| 5877 |
if (hashed === null || !self.options.hasOwnProperty(hashed)) |
| 5878 |
return; |
| 5879 |
if (inputMode === 'single') |
| 5880 |
self.clear(silent); |
| 5881 |
if (inputMode === 'multi' && self.isFull()) |
| 5882 |
return; |
| 5883 |
item = self._render('item', self.options[hashed]); |
| 5884 |
if (self.control.contains(item)) { // duplicates |
| 5885 |
item = item.cloneNode(true); |
| 5886 |
} |
| 5887 |
wasFull = self.isFull(); |
| 5888 |
self.items.splice(self.caretPos, 0, hashed); |
| 5889 |
self.insertAtCaret(item); |
| 5890 |
if (self.isSetup) { |
| 5891 |
// update menu / remove the option (if this is not one item being added as part of series) |
| 5892 |
if (!self.isPending && self.settings.hideSelected) { |
| 5893 |
let option = self.getOption(hashed); |
| 5894 |
let next = self.getAdjacent(option, 1); |
| 5895 |
if (next) { |
| 5896 |
self.setActiveOption(next); |
| 5897 |
} |
| 5898 |
} |
| 5899 |
// refreshOptions after setActiveOption(), |
| 5900 |
// otherwise setActiveOption() will be called by refreshOptions() with the wrong value |
| 5901 |
if (!self.isPending && !self.settings.closeAfterSelect) { |
| 5902 |
self.refreshOptions(self.isFocused && inputMode !== 'single'); |
| 5903 |
} |
| 5904 |
// hide the menu if the maximum number of items have been selected or no options are left |
| 5905 |
if (self.settings.closeAfterSelect != false && self.isFull()) { |
| 5906 |
self.close(); |
| 5907 |
} |
| 5908 |
else if (!self.isPending) { |
| 5909 |
self.positionDropdown(); |
| 5910 |
} |
| 5911 |
self.trigger('item_add', hashed, item); |
| 5912 |
if (!self.isPending) { |
| 5913 |
self.updateOriginalInput({ silent: silent }); |
| 5914 |
} |
| 5915 |
} |
| 5916 |
if (!self.isPending || (!wasFull && self.isFull())) { |
| 5917 |
self.inputState(); |
| 5918 |
self.refreshState(); |
| 5919 |
} |
| 5920 |
}); |
| 5921 |
} |
| 5922 |
/** |
| 5923 |
* Removes the selected item matching |
| 5924 |
* the provided value. |
| 5925 |
* |
| 5926 |
*/ |
| 5927 |
removeItem(item = null, silent) { |
| 5928 |
const self = this; |
| 5929 |
item = self.getItem(item); |
| 5930 |
if (!item) |
| 5931 |
return; |
| 5932 |
var i, idx; |
| 5933 |
const value = item.dataset.value; |
| 5934 |
i = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.nodeIndex)(item); |
| 5935 |
item.remove(); |
| 5936 |
if (item.classList.contains('active')) { |
| 5937 |
idx = self.activeItems.indexOf(item); |
| 5938 |
self.activeItems.splice(idx, 1); |
| 5939 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(item, 'active'); |
| 5940 |
} |
| 5941 |
self.items.splice(i, 1); |
| 5942 |
self.lastQuery = null; |
| 5943 |
if (!self.settings.persist && self.userOptions.hasOwnProperty(value)) { |
| 5944 |
self.removeOption(value, silent); |
| 5945 |
} |
| 5946 |
if (i < self.caretPos) { |
| 5947 |
self.setCaret(self.caretPos - 1); |
| 5948 |
} |
| 5949 |
self.updateOriginalInput({ silent: silent }); |
| 5950 |
self.refreshState(); |
| 5951 |
self.positionDropdown(); |
| 5952 |
self.trigger('item_remove', value, item); |
| 5953 |
} |
| 5954 |
/** |
| 5955 |
* Invokes the `create` method provided in the |
| 5956 |
* TomSelect options that should provide the data |
| 5957 |
* for the new item, given the user input. |
| 5958 |
* |
| 5959 |
* Once this completes, it will be added |
| 5960 |
* to the item list. |
| 5961 |
* |
| 5962 |
*/ |
| 5963 |
createItem(input = null, callback = () => { }) { |
| 5964 |
// triggerDropdown parameter @deprecated 2.1.1 |
| 5965 |
if (arguments.length === 3) { |
| 5966 |
callback = arguments[2]; |
| 5967 |
} |
| 5968 |
if (typeof callback != 'function') { |
| 5969 |
callback = () => { }; |
| 5970 |
} |
| 5971 |
var self = this; |
| 5972 |
var caret = self.caretPos; |
| 5973 |
var output; |
| 5974 |
input = input || self.inputValue(); |
| 5975 |
if (!self.canCreate(input)) { |
| 5976 |
callback(); |
| 5977 |
return false; |
| 5978 |
} |
| 5979 |
self.lock(); |
| 5980 |
var created = false; |
| 5981 |
var create = (data) => { |
| 5982 |
self.unlock(); |
| 5983 |
if (!data || typeof data !== 'object') |
| 5984 |
return callback(); |
| 5985 |
var value = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(data[self.settings.valueField]); |
| 5986 |
if (typeof value !== 'string') { |
| 5987 |
return callback(); |
| 5988 |
} |
| 5989 |
self.setTextboxValue(); |
| 5990 |
self.addOption(data, true); |
| 5991 |
self.setCaret(caret); |
| 5992 |
self.addItem(value); |
| 5993 |
callback(data); |
| 5994 |
created = true; |
| 5995 |
}; |
| 5996 |
if (typeof self.settings.create === 'function') { |
| 5997 |
output = self.settings.create.call(this, input, create); |
| 5998 |
} |
| 5999 |
else { |
| 6000 |
output = { |
| 6001 |
[self.settings.labelField]: input, |
| 6002 |
[self.settings.valueField]: input, |
| 6003 |
}; |
| 6004 |
} |
| 6005 |
if (!created) { |
| 6006 |
create(output); |
| 6007 |
} |
| 6008 |
return true; |
| 6009 |
} |
| 6010 |
/** |
| 6011 |
* Re-renders the selected item lists. |
| 6012 |
*/ |
| 6013 |
refreshItems() { |
| 6014 |
var self = this; |
| 6015 |
self.lastQuery = null; |
| 6016 |
if (self.isSetup) { |
| 6017 |
self.addItems(self.items); |
| 6018 |
} |
| 6019 |
self.updateOriginalInput(); |
| 6020 |
self.refreshState(); |
| 6021 |
} |
| 6022 |
/** |
| 6023 |
* Updates all state-dependent attributes |
| 6024 |
* and CSS classes. |
| 6025 |
*/ |
| 6026 |
refreshState() { |
| 6027 |
const self = this; |
| 6028 |
self.refreshValidityState(); |
| 6029 |
const isFull = self.isFull(); |
| 6030 |
const isLocked = self.isLocked; |
| 6031 |
self.wrapper.classList.toggle('rtl', self.rtl); |
| 6032 |
const wrap_classList = self.wrapper.classList; |
| 6033 |
wrap_classList.toggle('focus', self.isFocused); |
| 6034 |
wrap_classList.toggle('disabled', self.isDisabled); |
| 6035 |
wrap_classList.toggle('readonly', self.isReadOnly); |
| 6036 |
wrap_classList.toggle('required', self.isRequired); |
| 6037 |
wrap_classList.toggle('invalid', !self.isValid); |
| 6038 |
wrap_classList.toggle('locked', isLocked); |
| 6039 |
wrap_classList.toggle('full', isFull); |
| 6040 |
wrap_classList.toggle('input-active', self.isFocused && !self.isInputHidden); |
| 6041 |
wrap_classList.toggle('dropdown-active', self.isOpen); |
| 6042 |
wrap_classList.toggle('has-options', (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.isEmptyObject)(self.options)); |
| 6043 |
wrap_classList.toggle('has-items', self.items.length > 0); |
| 6044 |
} |
| 6045 |
/** |
| 6046 |
* Update the `required` attribute of both input and control input. |
| 6047 |
* |
| 6048 |
* The `required` property needs to be activated on the control input |
| 6049 |
* for the error to be displayed at the right place. `required` also |
| 6050 |
* needs to be temporarily deactivated on the input since the input is |
| 6051 |
* hidden and can't show errors. |
| 6052 |
*/ |
| 6053 |
refreshValidityState() { |
| 6054 |
var self = this; |
| 6055 |
if (!self.input.validity) { |
| 6056 |
return; |
| 6057 |
} |
| 6058 |
self.isValid = self.input.validity.valid; |
| 6059 |
self.isInvalid = !self.isValid; |
| 6060 |
} |
| 6061 |
/** |
| 6062 |
* Determines whether or not more items can be added |
| 6063 |
* to the control without exceeding the user-defined maximum. |
| 6064 |
* |
| 6065 |
* @returns {boolean} |
| 6066 |
*/ |
| 6067 |
isFull() { |
| 6068 |
return this.settings.maxItems !== null && this.items.length >= this.settings.maxItems; |
| 6069 |
} |
| 6070 |
/** |
| 6071 |
* Refreshes the original <select> or <input> |
| 6072 |
* element to reflect the current state. |
| 6073 |
* |
| 6074 |
*/ |
| 6075 |
updateOriginalInput(opts = {}) { |
| 6076 |
const self = this; |
| 6077 |
var option, label; |
| 6078 |
const empty_option = self.input.querySelector('option[value=""]'); |
| 6079 |
if (self.is_select_tag) { |
| 6080 |
const selected = []; |
| 6081 |
const has_selected = self.input.querySelectorAll('option:checked').length; |
| 6082 |
function AddSelected(option_el, value, label) { |
| 6083 |
if (!option_el) { |
| 6084 |
option_el = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)('<option value="' + (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.escape_html)(value) + '">' + (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.escape_html)(label) + '</option>'); |
| 6085 |
} |
| 6086 |
// don't move empty option from top of list |
| 6087 |
// fixes bug in firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1725293 |
| 6088 |
if (option_el != empty_option) { |
| 6089 |
self.input.append(option_el); |
| 6090 |
} |
| 6091 |
selected.push(option_el); |
| 6092 |
// marking empty option as selected can break validation |
| 6093 |
// fixes https://github.com/orchidjs/tom-select/issues/303 |
| 6094 |
if (option_el != empty_option || has_selected > 0) { |
| 6095 |
option_el.selected = true; |
| 6096 |
} |
| 6097 |
return option_el; |
| 6098 |
} |
| 6099 |
// unselect all selected options |
| 6100 |
self.input.querySelectorAll('option:checked').forEach((option_el) => { |
| 6101 |
option_el.selected = false; |
| 6102 |
}); |
| 6103 |
// nothing selected? |
| 6104 |
if (self.items.length == 0 && self.settings.mode == 'single') { |
| 6105 |
AddSelected(empty_option, "", ""); |
| 6106 |
// order selected <option> tags for values in self.items |
| 6107 |
} |
| 6108 |
else { |
| 6109 |
self.items.forEach((value) => { |
| 6110 |
option = self.options[value]; |
| 6111 |
label = option[self.settings.labelField] || ''; |
| 6112 |
if (selected.includes(option.$option)) { |
| 6113 |
const reuse_opt = self.input.querySelector(`option[value="${(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addSlashes)(value)}"]:not(:checked)`); |
| 6114 |
AddSelected(reuse_opt, value, label); |
| 6115 |
} |
| 6116 |
else { |
| 6117 |
option.$option = AddSelected(option.$option, value, label); |
| 6118 |
} |
| 6119 |
}); |
| 6120 |
} |
| 6121 |
} |
| 6122 |
else { |
| 6123 |
self.input.value = self.getValue(); |
| 6124 |
} |
| 6125 |
if (self.isSetup) { |
| 6126 |
if (!opts.silent) { |
| 6127 |
self.trigger('change', self.getValue()); |
| 6128 |
} |
| 6129 |
} |
| 6130 |
} |
| 6131 |
/** |
| 6132 |
* Shows the autocomplete dropdown containing |
| 6133 |
* the available options. |
| 6134 |
*/ |
| 6135 |
open() { |
| 6136 |
var self = this; |
| 6137 |
if (self.isLocked || self.isOpen || (self.settings.mode === 'multi' && self.isFull())) |
| 6138 |
return; |
| 6139 |
self.isOpen = true; |
| 6140 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(self.focus_node, { 'aria-expanded': 'true' }); |
| 6141 |
self.refreshState(); |
| 6142 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.applyCSS)(self.dropdown, { visibility: 'hidden', display: 'block' }); |
| 6143 |
self.positionDropdown(); |
| 6144 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.applyCSS)(self.dropdown, { visibility: 'visible', display: 'block' }); |
| 6145 |
self.focus(); |
| 6146 |
self.trigger('dropdown_open', self.dropdown); |
| 6147 |
} |
| 6148 |
/** |
| 6149 |
* Closes the autocomplete dropdown menu. |
| 6150 |
*/ |
| 6151 |
close(setTextboxValue = true) { |
| 6152 |
var self = this; |
| 6153 |
var trigger = self.isOpen; |
| 6154 |
if (setTextboxValue) { |
| 6155 |
// before blur() to prevent form onchange event |
| 6156 |
self.setTextboxValue(); |
| 6157 |
if (self.settings.mode === 'single' && self.items.length) { |
| 6158 |
self.inputState(); |
| 6159 |
} |
| 6160 |
} |
| 6161 |
self.isOpen = false; |
| 6162 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(self.focus_node, { 'aria-expanded': 'false' }); |
| 6163 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.applyCSS)(self.dropdown, { display: 'none' }); |
| 6164 |
if (self.settings.hideSelected) { |
| 6165 |
self.clearActiveOption(); |
| 6166 |
} |
| 6167 |
self.refreshState(); |
| 6168 |
if (trigger) |
| 6169 |
self.trigger('dropdown_close', self.dropdown); |
| 6170 |
} |
| 6171 |
/** |
| 6172 |
* Calculates and applies the appropriate |
| 6173 |
* position of the dropdown if dropdownParent = 'body'. |
| 6174 |
* Otherwise, position is determined by css |
| 6175 |
*/ |
| 6176 |
positionDropdown() { |
| 6177 |
if (this.settings.dropdownParent !== 'body') { |
| 6178 |
return; |
| 6179 |
} |
| 6180 |
var context = this.control; |
| 6181 |
var rect = context.getBoundingClientRect(); |
| 6182 |
var top = context.offsetHeight + rect.top + window.scrollY; |
| 6183 |
var left = rect.left + window.scrollX; |
| 6184 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.applyCSS)(this.dropdown, { |
| 6185 |
width: rect.width + 'px', |
| 6186 |
top: top + 'px', |
| 6187 |
left: left + 'px' |
| 6188 |
}); |
| 6189 |
} |
| 6190 |
/** |
| 6191 |
* Resets / clears all selected items |
| 6192 |
* from the control. |
| 6193 |
* |
| 6194 |
*/ |
| 6195 |
clear(silent) { |
| 6196 |
var self = this; |
| 6197 |
if (!self.items.length) |
| 6198 |
return; |
| 6199 |
var items = self.controlChildren(); |
| 6200 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(items, (item) => { |
| 6201 |
self.removeItem(item, true); |
| 6202 |
}); |
| 6203 |
self.inputState(); |
| 6204 |
if (!silent) |
| 6205 |
self.updateOriginalInput(); |
| 6206 |
self.trigger('clear'); |
| 6207 |
} |
| 6208 |
/** |
| 6209 |
* A helper method for inserting an element |
| 6210 |
* at the current caret position. |
| 6211 |
* |
| 6212 |
*/ |
| 6213 |
insertAtCaret(el) { |
| 6214 |
const self = this; |
| 6215 |
const caret = self.caretPos; |
| 6216 |
const target = self.control; |
| 6217 |
target.insertBefore(el, target.children[caret] || null); |
| 6218 |
self.setCaret(caret + 1); |
| 6219 |
} |
| 6220 |
/** |
| 6221 |
* Removes the current selected item(s). |
| 6222 |
* |
| 6223 |
*/ |
| 6224 |
deleteSelection(e) { |
| 6225 |
var direction, selection, caret, tail; |
| 6226 |
var self = this; |
| 6227 |
direction = (e && e.keyCode === _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_BACKSPACE) ? -1 : 1; |
| 6228 |
selection = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.getSelection)(self.control_input); |
| 6229 |
// determine items that will be removed |
| 6230 |
const rm_items = []; |
| 6231 |
if (self.activeItems.length) { |
| 6232 |
tail = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getTail)(self.activeItems, direction); |
| 6233 |
caret = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.nodeIndex)(tail); |
| 6234 |
if (direction > 0) { |
| 6235 |
caret++; |
| 6236 |
} |
| 6237 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(self.activeItems, (item) => rm_items.push(item)); |
| 6238 |
} |
| 6239 |
else if ((self.isFocused || self.settings.mode === 'single') && self.items.length) { |
| 6240 |
const items = self.controlChildren(); |
| 6241 |
let rm_item; |
| 6242 |
if (direction < 0 && selection.start === 0 && selection.length === 0) { |
| 6243 |
rm_item = items[self.caretPos - 1]; |
| 6244 |
} |
| 6245 |
else if (direction > 0 && selection.start === self.inputValue().length) { |
| 6246 |
rm_item = items[self.caretPos]; |
| 6247 |
} |
| 6248 |
if (rm_item !== undefined) { |
| 6249 |
rm_items.push(rm_item); |
| 6250 |
} |
| 6251 |
} |
| 6252 |
if (!self.shouldDelete(rm_items, e)) { |
| 6253 |
return false; |
| 6254 |
} |
| 6255 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e, true); |
| 6256 |
// perform removal |
| 6257 |
if (typeof caret !== 'undefined') { |
| 6258 |
self.setCaret(caret); |
| 6259 |
} |
| 6260 |
while (rm_items.length) { |
| 6261 |
self.removeItem(rm_items.pop()); |
| 6262 |
} |
| 6263 |
self.inputState(); |
| 6264 |
self.positionDropdown(); |
| 6265 |
self.refreshOptions(false); |
| 6266 |
return true; |
| 6267 |
} |
| 6268 |
/** |
| 6269 |
* Return true if the items should be deleted |
| 6270 |
*/ |
| 6271 |
shouldDelete(items, evt) { |
| 6272 |
const values = items.map(item => item.dataset.value); |
| 6273 |
// allow the callback to abort |
| 6274 |
if (!values.length || (typeof this.settings.onDelete === 'function' && this.settings.onDelete(values, evt) === false)) { |
| 6275 |
return false; |
| 6276 |
} |
| 6277 |
return true; |
| 6278 |
} |
| 6279 |
/** |
| 6280 |
* Selects the previous / next item (depending on the `direction` argument). |
| 6281 |
* |
| 6282 |
* > 0 - right |
| 6283 |
* < 0 - left |
| 6284 |
* |
| 6285 |
*/ |
| 6286 |
advanceSelection(direction, e) { |
| 6287 |
var last_active, adjacent, self = this; |
| 6288 |
if (self.rtl) |
| 6289 |
direction *= -1; |
| 6290 |
if (self.inputValue().length) |
| 6291 |
return; |
| 6292 |
// add or remove to active items |
| 6293 |
if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.isKeyDown)(_constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_SHORTCUT, e) || (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.isKeyDown)('shiftKey', e)) { |
| 6294 |
last_active = self.getLastActive(direction); |
| 6295 |
if (last_active) { |
| 6296 |
if (!last_active.classList.contains('active')) { |
| 6297 |
adjacent = last_active; |
| 6298 |
} |
| 6299 |
else { |
| 6300 |
adjacent = self.getAdjacent(last_active, direction, 'item'); |
| 6301 |
} |
| 6302 |
// if no active item, get items adjacent to the control input |
| 6303 |
} |
| 6304 |
else if (direction > 0) { |
| 6305 |
adjacent = self.control_input.nextElementSibling; |
| 6306 |
} |
| 6307 |
else { |
| 6308 |
adjacent = self.control_input.previousElementSibling; |
| 6309 |
} |
| 6310 |
if (adjacent) { |
| 6311 |
if (adjacent.classList.contains('active')) { |
| 6312 |
self.removeActiveItem(last_active); |
| 6313 |
} |
| 6314 |
self.setActiveItemClass(adjacent); // mark as last_active !! after removeActiveItem() on last_active |
| 6315 |
} |
| 6316 |
// move caret to the left or right |
| 6317 |
} |
| 6318 |
else { |
| 6319 |
self.moveCaret(direction); |
| 6320 |
} |
| 6321 |
} |
| 6322 |
moveCaret(direction) { } |
| 6323 |
/** |
| 6324 |
* Get the last active item |
| 6325 |
* |
| 6326 |
*/ |
| 6327 |
getLastActive(direction) { |
| 6328 |
let last_active = this.control.querySelector('.last-active'); |
| 6329 |
if (last_active) { |
| 6330 |
return last_active; |
| 6331 |
} |
| 6332 |
var result = this.control.querySelectorAll('.active'); |
| 6333 |
if (result) { |
| 6334 |
return (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getTail)(result, direction); |
| 6335 |
} |
| 6336 |
} |
| 6337 |
/** |
| 6338 |
* Moves the caret to the specified index. |
| 6339 |
* |
| 6340 |
* The input must be moved by leaving it in place and moving the |
| 6341 |
* siblings, due to the fact that focus cannot be restored once lost |
| 6342 |
* on mobile webkit devices |
| 6343 |
* |
| 6344 |
*/ |
| 6345 |
setCaret(new_pos) { |
| 6346 |
this.caretPos = this.items.length; |
| 6347 |
} |
| 6348 |
/** |
| 6349 |
* Return list of item dom elements |
| 6350 |
* |
| 6351 |
*/ |
| 6352 |
controlChildren() { |
| 6353 |
return Array.from(this.control.querySelectorAll('[data-ts-item]')); |
| 6354 |
} |
| 6355 |
/** |
| 6356 |
* Disables user input on the control. Used while |
| 6357 |
* items are being asynchronously created. |
| 6358 |
*/ |
| 6359 |
lock() { |
| 6360 |
this.setLocked(true); |
| 6361 |
} |
| 6362 |
/** |
| 6363 |
* Re-enables user input on the control. |
| 6364 |
*/ |
| 6365 |
unlock() { |
| 6366 |
this.setLocked(false); |
| 6367 |
} |
| 6368 |
/** |
| 6369 |
* Disable or enable user input on the control |
| 6370 |
*/ |
| 6371 |
setLocked(lock = this.isReadOnly || this.isDisabled) { |
| 6372 |
this.isLocked = lock; |
| 6373 |
this.refreshState(); |
| 6374 |
} |
| 6375 |
/** |
| 6376 |
* Disables user input on the control completely. |
| 6377 |
* While disabled, it cannot receive focus. |
| 6378 |
*/ |
| 6379 |
disable() { |
| 6380 |
this.setDisabled(true); |
| 6381 |
this.close(); |
| 6382 |
} |
| 6383 |
/** |
| 6384 |
* Enables the control so that it can respond |
| 6385 |
* to focus and user input. |
| 6386 |
*/ |
| 6387 |
enable() { |
| 6388 |
this.setDisabled(false); |
| 6389 |
} |
| 6390 |
setDisabled(disabled) { |
| 6391 |
this.focus_node.tabIndex = disabled ? -1 : this.tabIndex; |
| 6392 |
this.isDisabled = disabled; |
| 6393 |
this.input.disabled = disabled; |
| 6394 |
this.control_input.disabled = disabled; |
| 6395 |
this.setLocked(); |
| 6396 |
} |
| 6397 |
setReadOnly(isReadOnly) { |
| 6398 |
this.isReadOnly = isReadOnly; |
| 6399 |
this.input.readOnly = isReadOnly; |
| 6400 |
this.control_input.readOnly = isReadOnly; |
| 6401 |
this.setLocked(); |
| 6402 |
} |
| 6403 |
/** |
| 6404 |
* Completely destroys the control and |
| 6405 |
* unbinds all event listeners so that it can |
| 6406 |
* be garbage collected. |
| 6407 |
*/ |
| 6408 |
destroy() { |
| 6409 |
var self = this; |
| 6410 |
var revertSettings = self.revertSettings; |
| 6411 |
self.trigger('destroy'); |
| 6412 |
self.off(); |
| 6413 |
self.wrapper.remove(); |
| 6414 |
self.dropdown.remove(); |
| 6415 |
self.input.innerHTML = revertSettings.innerHTML; |
| 6416 |
self.input.tabIndex = revertSettings.tabIndex; |
| 6417 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(self.input, 'tomselected', 'ts-hidden-accessible'); |
| 6418 |
self._destroy(); |
| 6419 |
delete self.input.tomselect; |
| 6420 |
} |
| 6421 |
/** |
| 6422 |
* A helper method for rendering "item" and |
| 6423 |
* "option" templates, given the data. |
| 6424 |
* |
| 6425 |
*/ |
| 6426 |
render(templateName, data) { |
| 6427 |
var id, html; |
| 6428 |
const self = this; |
| 6429 |
if (typeof this.settings.render[templateName] !== 'function') { |
| 6430 |
return null; |
| 6431 |
} |
| 6432 |
// render markup |
| 6433 |
html = self.settings.render[templateName].call(this, data, _utils_js__WEBPACK_IMPORTED_MODULE_7__.escape_html); |
| 6434 |
if (!html) { |
| 6435 |
return null; |
| 6436 |
} |
| 6437 |
html = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)(html); |
| 6438 |
// add mandatory attributes |
| 6439 |
if (templateName === 'option' || templateName === 'option_create') { |
| 6440 |
if (data[self.settings.disabledField]) { |
| 6441 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(html, { 'aria-disabled': 'true' }); |
| 6442 |
} |
| 6443 |
else { |
| 6444 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(html, { 'data-selectable': '' }); |
| 6445 |
} |
| 6446 |
} |
| 6447 |
else if (templateName === 'optgroup') { |
| 6448 |
id = data.group[self.settings.optgroupValueField]; |
| 6449 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(html, { 'data-group': id }); |
| 6450 |
if (data.group[self.settings.disabledField]) { |
| 6451 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(html, { 'data-disabled': '' }); |
| 6452 |
} |
| 6453 |
} |
| 6454 |
if (templateName === 'option' || templateName === 'item') { |
| 6455 |
const value = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.get_hash)(data[self.settings.valueField]); |
| 6456 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(html, { 'data-value': value }); |
| 6457 |
// make sure we have some classes if a template is overwritten |
| 6458 |
if (templateName === 'item') { |
| 6459 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(html, self.settings.itemClass); |
| 6460 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(html, { 'data-ts-item': '' }); |
| 6461 |
} |
| 6462 |
else { |
| 6463 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(html, self.settings.optionClass); |
| 6464 |
(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(html, { |
| 6465 |
role: 'option', |
| 6466 |
id: data.$id |
| 6467 |
}); |
| 6468 |
// update cache |
| 6469 |
data.$div = html; |
| 6470 |
self.options[value] = data; |
| 6471 |
} |
| 6472 |
} |
| 6473 |
return html; |
| 6474 |
} |
| 6475 |
/** |
| 6476 |
* Type guarded rendering |
| 6477 |
* |
| 6478 |
*/ |
| 6479 |
_render(templateName, data) { |
| 6480 |
const html = this.render(templateName, data); |
| 6481 |
if (html == null) { |
| 6482 |
throw 'HTMLElement expected'; |
| 6483 |
} |
| 6484 |
return html; |
| 6485 |
} |
| 6486 |
/** |
| 6487 |
* Clears the render cache for a template. If |
| 6488 |
* no template is given, clears all render |
| 6489 |
* caches. |
| 6490 |
* |
| 6491 |
*/ |
| 6492 |
clearCache() { |
| 6493 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(this.options, (option) => { |
| 6494 |
if (option.$div) { |
| 6495 |
option.$div.remove(); |
| 6496 |
delete option.$div; |
| 6497 |
} |
| 6498 |
}); |
| 6499 |
} |
| 6500 |
/** |
| 6501 |
* Removes a value from item and option caches |
| 6502 |
* |
| 6503 |
*/ |
| 6504 |
uncacheValue(value) { |
| 6505 |
const option_el = this.getOption(value); |
| 6506 |
if (option_el) |
| 6507 |
option_el.remove(); |
| 6508 |
} |
| 6509 |
/** |
| 6510 |
* Determines whether or not to display the |
| 6511 |
* create item prompt, given a user input. |
| 6512 |
* |
| 6513 |
*/ |
| 6514 |
canCreate(input) { |
| 6515 |
return this.settings.create && (input.length > 0) && this.settings.createFilter.call(this, input); |
| 6516 |
} |
| 6517 |
/** |
| 6518 |
* Wraps this.`method` so that `new_fn` can be invoked 'before', 'after', or 'instead' of the original method |
| 6519 |
* |
| 6520 |
* this.hook('instead','onKeyDown',function( arg1, arg2 ...){ |
| 6521 |
* |
| 6522 |
* }); |
| 6523 |
*/ |
| 6524 |
hook(when, method, new_fn) { |
| 6525 |
var self = this; |
| 6526 |
var orig_method = self[method]; |
| 6527 |
self[method] = function () { |
| 6528 |
var result, result_new; |
| 6529 |
if (when === 'after') { |
| 6530 |
result = orig_method.apply(self, arguments); |
| 6531 |
} |
| 6532 |
result_new = new_fn.apply(self, arguments); |
| 6533 |
if (when === 'instead') { |
| 6534 |
return result_new; |
| 6535 |
} |
| 6536 |
if (when === 'before') { |
| 6537 |
result = orig_method.apply(self, arguments); |
| 6538 |
} |
| 6539 |
return result; |
| 6540 |
}; |
| 6541 |
} |
| 6542 |
} |
| 6543 |
; |
| 6544 |
//# sourceMappingURL=tom-select.js.map |
| 6545 |
|
| 6546 |
/***/ }, |
| 6547 |
|
| 6548 |
/***/ "./node_modules/tom-select/dist/esm/utils.js" |
| 6549 |
/*!***************************************************!*\ |
| 6550 |
!*** ./node_modules/tom-select/dist/esm/utils.js ***! |
| 6551 |
\***************************************************/ |
| 6552 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 6553 |
|
| 6554 |
__webpack_require__.r(__webpack_exports__); |
| 6555 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 6556 |
/* harmony export */ addEvent: () => (/* binding */ addEvent), |
| 6557 |
/* harmony export */ addSlashes: () => (/* binding */ addSlashes), |
| 6558 |
/* harmony export */ append: () => (/* binding */ append), |
| 6559 |
/* harmony export */ debounce_events: () => (/* binding */ debounce_events), |
| 6560 |
/* harmony export */ escape_html: () => (/* binding */ escape_html), |
| 6561 |
/* harmony export */ getId: () => (/* binding */ getId), |
| 6562 |
/* harmony export */ getSelection: () => (/* binding */ getSelection), |
| 6563 |
/* harmony export */ get_hash: () => (/* binding */ get_hash), |
| 6564 |
/* harmony export */ hash_key: () => (/* binding */ hash_key), |
| 6565 |
/* harmony export */ isKeyDown: () => (/* binding */ isKeyDown), |
| 6566 |
/* harmony export */ iterate: () => (/* binding */ iterate), |
| 6567 |
/* harmony export */ loadDebounce: () => (/* binding */ loadDebounce), |
| 6568 |
/* harmony export */ preventDefault: () => (/* binding */ preventDefault), |
| 6569 |
/* harmony export */ timeout: () => (/* binding */ timeout) |
| 6570 |
/* harmony export */ }); |
| 6571 |
/** |
| 6572 |
* Converts a scalar to its best string representation |
| 6573 |
* for hash keys and HTML attribute values. |
| 6574 |
* |
| 6575 |
* Transformations: |
| 6576 |
* 'str' -> 'str' |
| 6577 |
* null -> '' |
| 6578 |
* undefined -> '' |
| 6579 |
* true -> '1' |
| 6580 |
* false -> '0' |
| 6581 |
* 0 -> '0' |
| 6582 |
* 1 -> '1' |
| 6583 |
* |
| 6584 |
*/ |
| 6585 |
const hash_key = (value) => { |
| 6586 |
if (typeof value === 'undefined' || value === null) |
| 6587 |
return null; |
| 6588 |
return get_hash(value); |
| 6589 |
}; |
| 6590 |
const get_hash = (value) => { |
| 6591 |
if (typeof value === 'boolean') |
| 6592 |
return value ? '1' : '0'; |
| 6593 |
return value + ''; |
| 6594 |
}; |
| 6595 |
/** |
| 6596 |
* Escapes a string for use within HTML. |
| 6597 |
* |
| 6598 |
*/ |
| 6599 |
const escape_html = (str) => { |
| 6600 |
return (str + '') |
| 6601 |
.replace(/&/g, '&') |
| 6602 |
.replace(/</g, '<') |
| 6603 |
.replace(/>/g, '>') |
| 6604 |
.replace(/"/g, '"'); |
| 6605 |
}; |
| 6606 |
/** |
| 6607 |
* use setTimeout if timeout > 0 |
| 6608 |
*/ |
| 6609 |
const timeout = (fn, timeout) => { |
| 6610 |
if (timeout > 0) { |
| 6611 |
return window.setTimeout(fn, timeout); |
| 6612 |
} |
| 6613 |
fn.call(null); |
| 6614 |
return null; |
| 6615 |
}; |
| 6616 |
/** |
| 6617 |
* Debounce the user provided load function |
| 6618 |
* |
| 6619 |
*/ |
| 6620 |
const loadDebounce = (fn, delay) => { |
| 6621 |
var timeout; |
| 6622 |
return function (value, callback) { |
| 6623 |
var self = this; |
| 6624 |
if (timeout) { |
| 6625 |
self.loading = Math.max(self.loading - 1, 0); |
| 6626 |
clearTimeout(timeout); |
| 6627 |
} |
| 6628 |
timeout = setTimeout(function () { |
| 6629 |
timeout = null; |
| 6630 |
self.loadedSearches[value] = true; |
| 6631 |
fn.call(self, value, callback); |
| 6632 |
}, delay); |
| 6633 |
}; |
| 6634 |
}; |
| 6635 |
/** |
| 6636 |
* Debounce all fired events types listed in `types` |
| 6637 |
* while executing the provided `fn`. |
| 6638 |
* |
| 6639 |
*/ |
| 6640 |
const debounce_events = (self, types, fn) => { |
| 6641 |
var type; |
| 6642 |
var trigger = self.trigger; |
| 6643 |
var event_args = {}; |
| 6644 |
// override trigger method |
| 6645 |
self.trigger = function () { |
| 6646 |
var type = arguments[0]; |
| 6647 |
if (types.indexOf(type) !== -1) { |
| 6648 |
event_args[type] = arguments; |
| 6649 |
} |
| 6650 |
else { |
| 6651 |
return trigger.apply(self, arguments); |
| 6652 |
} |
| 6653 |
}; |
| 6654 |
// invoke provided function |
| 6655 |
fn.apply(self, []); |
| 6656 |
self.trigger = trigger; |
| 6657 |
// trigger queued events |
| 6658 |
for (type of types) { |
| 6659 |
if (type in event_args) { |
| 6660 |
trigger.apply(self, event_args[type]); |
| 6661 |
} |
| 6662 |
} |
| 6663 |
}; |
| 6664 |
/** |
| 6665 |
* Determines the current selection within a text input control. |
| 6666 |
* Returns an object containing: |
| 6667 |
* - start |
| 6668 |
* - length |
| 6669 |
* |
| 6670 |
* Note: "selectionStart, selectionEnd ... apply only to inputs of types text, search, URL, tel and password" |
| 6671 |
* - https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange |
| 6672 |
*/ |
| 6673 |
const getSelection = (input) => { |
| 6674 |
return { |
| 6675 |
start: input.selectionStart || 0, |
| 6676 |
length: (input.selectionEnd || 0) - (input.selectionStart || 0), |
| 6677 |
}; |
| 6678 |
}; |
| 6679 |
/** |
| 6680 |
* Prevent default |
| 6681 |
* |
| 6682 |
*/ |
| 6683 |
const preventDefault = (evt, stop = false) => { |
| 6684 |
if (evt) { |
| 6685 |
evt.preventDefault(); |
| 6686 |
if (stop) { |
| 6687 |
evt.stopPropagation(); |
| 6688 |
} |
| 6689 |
} |
| 6690 |
}; |
| 6691 |
/** |
| 6692 |
* Add event helper |
| 6693 |
* |
| 6694 |
*/ |
| 6695 |
const addEvent = (target, type, callback, options) => { |
| 6696 |
target.addEventListener(type, callback, options); |
| 6697 |
}; |
| 6698 |
/** |
| 6699 |
* Return true if the requested key is down |
| 6700 |
* Will return false if more than one control character is pressed ( when [ctrl+shift+a] != [ctrl+a] ) |
| 6701 |
* The current evt may not always set ( eg calling advanceSelection() ) |
| 6702 |
* |
| 6703 |
*/ |
| 6704 |
const isKeyDown = (key_name, evt) => { |
| 6705 |
if (!evt) { |
| 6706 |
return false; |
| 6707 |
} |
| 6708 |
if (!evt[key_name]) { |
| 6709 |
return false; |
| 6710 |
} |
| 6711 |
var count = (evt.altKey ? 1 : 0) + (evt.ctrlKey ? 1 : 0) + (evt.shiftKey ? 1 : 0) + (evt.metaKey ? 1 : 0); |
| 6712 |
if (count === 1) { |
| 6713 |
return true; |
| 6714 |
} |
| 6715 |
return false; |
| 6716 |
}; |
| 6717 |
/** |
| 6718 |
* Get the id of an element |
| 6719 |
* If the id attribute is not set, set the attribute with the given id |
| 6720 |
* |
| 6721 |
*/ |
| 6722 |
const getId = (el, id) => { |
| 6723 |
const existing_id = el.getAttribute('id'); |
| 6724 |
if (existing_id) { |
| 6725 |
return existing_id; |
| 6726 |
} |
| 6727 |
el.setAttribute('id', id); |
| 6728 |
return id; |
| 6729 |
}; |
| 6730 |
/** |
| 6731 |
* Returns a string with backslashes added before characters that need to be escaped. |
| 6732 |
*/ |
| 6733 |
const addSlashes = (str) => { |
| 6734 |
return str.replace(/[\\"']/g, '\\$&'); |
| 6735 |
}; |
| 6736 |
/** |
| 6737 |
* |
| 6738 |
*/ |
| 6739 |
const append = (parent, node) => { |
| 6740 |
if (node) |
| 6741 |
parent.append(node); |
| 6742 |
}; |
| 6743 |
/** |
| 6744 |
* Iterates over arrays and hashes. |
| 6745 |
* |
| 6746 |
* ``` |
| 6747 |
* iterate(this.items, function(item, id) { |
| 6748 |
* // invoked for each item |
| 6749 |
* }); |
| 6750 |
* ``` |
| 6751 |
* |
| 6752 |
*/ |
| 6753 |
const iterate = (object, callback) => { |
| 6754 |
if (Array.isArray(object)) { |
| 6755 |
object.forEach(callback); |
| 6756 |
} |
| 6757 |
else { |
| 6758 |
for (var key in object) { |
| 6759 |
if (object.hasOwnProperty(key)) { |
| 6760 |
callback(object[key], key); |
| 6761 |
} |
| 6762 |
} |
| 6763 |
} |
| 6764 |
}; |
| 6765 |
//# sourceMappingURL=utils.js.map |
| 6766 |
|
| 6767 |
/***/ }, |
| 6768 |
|
| 6769 |
/***/ "./node_modules/tom-select/dist/esm/vanilla.js" |
| 6770 |
/*!*****************************************************!*\ |
| 6771 |
!*** ./node_modules/tom-select/dist/esm/vanilla.js ***! |
| 6772 |
\*****************************************************/ |
| 6773 |
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 6774 |
|
| 6775 |
__webpack_require__.r(__webpack_exports__); |
| 6776 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 6777 |
/* harmony export */ addClasses: () => (/* binding */ addClasses), |
| 6778 |
/* harmony export */ applyCSS: () => (/* binding */ applyCSS), |
| 6779 |
/* harmony export */ castAsArray: () => (/* binding */ castAsArray), |
| 6780 |
/* harmony export */ classesArray: () => (/* binding */ classesArray), |
| 6781 |
/* harmony export */ escapeQuery: () => (/* binding */ escapeQuery), |
| 6782 |
/* harmony export */ getDom: () => (/* binding */ getDom), |
| 6783 |
/* harmony export */ getTail: () => (/* binding */ getTail), |
| 6784 |
/* harmony export */ isEmptyObject: () => (/* binding */ isEmptyObject), |
| 6785 |
/* harmony export */ isHtmlString: () => (/* binding */ isHtmlString), |
| 6786 |
/* harmony export */ nodeIndex: () => (/* binding */ nodeIndex), |
| 6787 |
/* harmony export */ parentMatch: () => (/* binding */ parentMatch), |
| 6788 |
/* harmony export */ removeClasses: () => (/* binding */ removeClasses), |
| 6789 |
/* harmony export */ replaceNode: () => (/* binding */ replaceNode), |
| 6790 |
/* harmony export */ setAttr: () => (/* binding */ setAttr), |
| 6791 |
/* harmony export */ triggerEvent: () => (/* binding */ triggerEvent) |
| 6792 |
/* harmony export */ }); |
| 6793 |
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils.js */ "./node_modules/tom-select/dist/esm/utils.js"); |
| 6794 |
|
| 6795 |
/** |
| 6796 |
* Return a dom element from either a dom query string, jQuery object, a dom element or html string |
| 6797 |
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 |
| 6798 |
* |
| 6799 |
* param query should be {} |
| 6800 |
*/ |
| 6801 |
const getDom = (query) => { |
| 6802 |
if (query.jquery) { |
| 6803 |
return query[0]; |
| 6804 |
} |
| 6805 |
if (query instanceof HTMLElement) { |
| 6806 |
return query; |
| 6807 |
} |
| 6808 |
if (isHtmlString(query)) { |
| 6809 |
var tpl = document.createElement('template'); |
| 6810 |
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result |
| 6811 |
return tpl.content.firstChild; |
| 6812 |
} |
| 6813 |
return document.querySelector(query); |
| 6814 |
}; |
| 6815 |
const isHtmlString = (arg) => { |
| 6816 |
if (typeof arg === 'string' && arg.indexOf('<') > -1) { |
| 6817 |
return true; |
| 6818 |
} |
| 6819 |
return false; |
| 6820 |
}; |
| 6821 |
const escapeQuery = (query) => { |
| 6822 |
return query.replace(/['"\\]/g, '\\$&'); |
| 6823 |
}; |
| 6824 |
/** |
| 6825 |
* Dispatch an event |
| 6826 |
* |
| 6827 |
*/ |
| 6828 |
const triggerEvent = (dom_el, event_name) => { |
| 6829 |
var event = document.createEvent('HTMLEvents'); |
| 6830 |
event.initEvent(event_name, true, false); |
| 6831 |
dom_el.dispatchEvent(event); |
| 6832 |
}; |
| 6833 |
/** |
| 6834 |
* Apply CSS rules to a dom element |
| 6835 |
* |
| 6836 |
*/ |
| 6837 |
const applyCSS = (dom_el, css) => { |
| 6838 |
Object.assign(dom_el.style, css); |
| 6839 |
}; |
| 6840 |
/** |
| 6841 |
* Add css classes |
| 6842 |
* |
| 6843 |
*/ |
| 6844 |
const addClasses = (elmts, ...classes) => { |
| 6845 |
var norm_classes = classesArray(classes); |
| 6846 |
elmts = castAsArray(elmts); |
| 6847 |
elmts.map(el => { |
| 6848 |
norm_classes.map(cls => { |
| 6849 |
el.classList.add(cls); |
| 6850 |
}); |
| 6851 |
}); |
| 6852 |
}; |
| 6853 |
/** |
| 6854 |
* Remove css classes |
| 6855 |
* |
| 6856 |
*/ |
| 6857 |
const removeClasses = (elmts, ...classes) => { |
| 6858 |
var norm_classes = classesArray(classes); |
| 6859 |
elmts = castAsArray(elmts); |
| 6860 |
elmts.map(el => { |
| 6861 |
norm_classes.map(cls => { |
| 6862 |
el.classList.remove(cls); |
| 6863 |
}); |
| 6864 |
}); |
| 6865 |
}; |
| 6866 |
/** |
| 6867 |
* Return arguments |
| 6868 |
* |
| 6869 |
*/ |
| 6870 |
const classesArray = (args) => { |
| 6871 |
var classes = []; |
| 6872 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.iterate)(args, (_classes) => { |
| 6873 |
if (typeof _classes === 'string') { |
| 6874 |
_classes = _classes.trim().split(/[\t\n\f\r\s]/); |
| 6875 |
} |
| 6876 |
if (Array.isArray(_classes)) { |
| 6877 |
classes = classes.concat(_classes); |
| 6878 |
} |
| 6879 |
}); |
| 6880 |
return classes.filter(Boolean); |
| 6881 |
}; |
| 6882 |
/** |
| 6883 |
* Create an array from arg if it's not already an array |
| 6884 |
* |
| 6885 |
*/ |
| 6886 |
const castAsArray = (arg) => { |
| 6887 |
if (!Array.isArray(arg)) { |
| 6888 |
arg = [arg]; |
| 6889 |
} |
| 6890 |
return arg; |
| 6891 |
}; |
| 6892 |
/** |
| 6893 |
* Get the closest node to the evt.target matching the selector |
| 6894 |
* Stops at wrapper |
| 6895 |
* |
| 6896 |
*/ |
| 6897 |
const parentMatch = (target, selector, wrapper) => { |
| 6898 |
if (wrapper && !wrapper.contains(target)) { |
| 6899 |
return; |
| 6900 |
} |
| 6901 |
while (target && target.matches) { |
| 6902 |
if (target.matches(selector)) { |
| 6903 |
return target; |
| 6904 |
} |
| 6905 |
target = target.parentNode; |
| 6906 |
} |
| 6907 |
}; |
| 6908 |
/** |
| 6909 |
* Get the first or last item from an array |
| 6910 |
* |
| 6911 |
* > 0 - right (last) |
| 6912 |
* <= 0 - left (first) |
| 6913 |
* |
| 6914 |
*/ |
| 6915 |
const getTail = (list, direction = 0) => { |
| 6916 |
if (direction > 0) { |
| 6917 |
return list[list.length - 1]; |
| 6918 |
} |
| 6919 |
return list[0]; |
| 6920 |
}; |
| 6921 |
/** |
| 6922 |
* Return true if an object is empty |
| 6923 |
* |
| 6924 |
*/ |
| 6925 |
const isEmptyObject = (obj) => { |
| 6926 |
return (Object.keys(obj).length === 0); |
| 6927 |
}; |
| 6928 |
/** |
| 6929 |
* Get the index of an element amongst sibling nodes of the same type |
| 6930 |
* |
| 6931 |
*/ |
| 6932 |
const nodeIndex = (el, amongst) => { |
| 6933 |
if (!el) |
| 6934 |
return -1; |
| 6935 |
amongst = amongst || el.nodeName; |
| 6936 |
var i = 0; |
| 6937 |
while (el = el.previousElementSibling) { |
| 6938 |
if (el.matches(amongst)) { |
| 6939 |
i++; |
| 6940 |
} |
| 6941 |
} |
| 6942 |
return i; |
| 6943 |
}; |
| 6944 |
/** |
| 6945 |
* Set attributes of an element |
| 6946 |
* |
| 6947 |
*/ |
| 6948 |
const setAttr = (el, attrs) => { |
| 6949 |
(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.iterate)(attrs, (val, attr) => { |
| 6950 |
if (val == null) { |
| 6951 |
el.removeAttribute(attr); |
| 6952 |
} |
| 6953 |
else { |
| 6954 |
el.setAttribute(attr, '' + val); |
| 6955 |
} |
| 6956 |
}); |
| 6957 |
}; |
| 6958 |
/** |
| 6959 |
* Replace a node |
| 6960 |
*/ |
| 6961 |
const replaceNode = (existing, replacement) => { |
| 6962 |
if (existing.parentNode) |
| 6963 |
existing.parentNode.replaceChild(replacement, existing); |
| 6964 |
}; |
| 6965 |
//# sourceMappingURL=vanilla.js.map |
| 6966 |
|
| 6967 |
/***/ } |
| 6968 |
|
| 6969 |
/******/ }); |
| 6970 |
/************************************************************************/ |
| 6971 |
/******/ // The module cache |
| 6972 |
/******/ const __webpack_module_cache__ = {}; |
| 6973 |
/******/ |
| 6974 |
/******/ // The require function |
| 6975 |
/******/ function __webpack_require__(moduleId) { |
| 6976 |
/******/ // Check if module is in cache |
| 6977 |
/******/ const cachedModule = __webpack_module_cache__[moduleId]; |
| 6978 |
/******/ if (cachedModule !== undefined) { |
| 6979 |
/******/ return cachedModule.exports; |
| 6980 |
/******/ } |
| 6981 |
/******/ // Create a new module (and put it into the cache) |
| 6982 |
/******/ const module = __webpack_module_cache__[moduleId] = { |
| 6983 |
/******/ // no module.id needed |
| 6984 |
/******/ // no module.loaded needed |
| 6985 |
/******/ exports: {} |
| 6986 |
/******/ }; |
| 6987 |
/******/ |
| 6988 |
/******/ // Execute the module function |
| 6989 |
/******/ if (!(moduleId in __webpack_modules__)) { |
| 6990 |
/******/ delete __webpack_module_cache__[moduleId]; |
| 6991 |
/******/ const e = new Error("Cannot find module '" + moduleId + "'"); |
| 6992 |
/******/ e.code = 'MODULE_NOT_FOUND'; |
| 6993 |
/******/ throw e; |
| 6994 |
/******/ } |
| 6995 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 6996 |
/******/ |
| 6997 |
/******/ // Return the exports of the module |
| 6998 |
/******/ return module.exports; |
| 6999 |
/******/ } |
| 7000 |
/******/ |
| 7001 |
/************************************************************************/ |
| 7002 |
/******/ /* webpack/runtime/define property getters */ |
| 7003 |
/******/ (() => { |
| 7004 |
/******/ // define getter/value functions for harmony exports |
| 7005 |
/******/ __webpack_require__.d = (exports, definition) => { |
| 7006 |
/******/ if(Array.isArray(definition)) { |
| 7007 |
/******/ var i = 0; |
| 7008 |
/******/ while(i < definition.length) { |
| 7009 |
/******/ var key = definition[i++]; |
| 7010 |
/******/ var binding = definition[i++]; |
| 7011 |
/******/ if(!__webpack_require__.o(exports, key)) { |
| 7012 |
/******/ if(binding === 0) { |
| 7013 |
/******/ Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] }); |
| 7014 |
/******/ } else { |
| 7015 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: binding }); |
| 7016 |
/******/ } |
| 7017 |
/******/ } else if(binding === 0) { i++; } |
| 7018 |
/******/ } |
| 7019 |
/******/ } else { |
| 7020 |
/******/ for(var key in definition) { |
| 7021 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 7022 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 7023 |
/******/ } |
| 7024 |
/******/ } |
| 7025 |
/******/ } |
| 7026 |
/******/ }; |
| 7027 |
/******/ })(); |
| 7028 |
/******/ |
| 7029 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 7030 |
/******/ (() => { |
| 7031 |
/******/ __webpack_require__.o = (obj, prop) => (Object.hasOwn(obj, prop)) |
| 7032 |
/******/ })(); |
| 7033 |
/******/ |
| 7034 |
/******/ /* webpack/runtime/make namespace object */ |
| 7035 |
/******/ (() => { |
| 7036 |
/******/ // define __esModule on exports |
| 7037 |
/******/ __webpack_require__.r = (exports) => { |
| 7038 |
/******/ if(Symbol.toStringTag) { |
| 7039 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 7040 |
/******/ } |
| 7041 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 7042 |
/******/ }; |
| 7043 |
/******/ })(); |
| 7044 |
/******/ |
| 7045 |
/************************************************************************/ |
| 7046 |
let __webpack_exports__ = {}; |
| 7047 |
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. |
| 7048 |
(() => { |
| 7049 |
/*!**************************************!*\ |
| 7050 |
!*** ./assets/src/js/admin/admin.js ***! |
| 7051 |
\**************************************/ |
| 7052 |
__webpack_require__.r(__webpack_exports__); |
| 7053 |
/* harmony import */ var _init_tom_select_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./init-tom-select.js */ "./assets/src/js/admin/init-tom-select.js"); |
| 7054 |
/* harmony import */ var _utils_admin_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils-admin.js */ "./assets/src/js/admin/utils-admin.js"); |
| 7055 |
|
| 7056 |
|
| 7057 |
(function ($) { |
| 7058 |
/** |
| 7059 |
* Callback event for button to creating pages inside error message. |
| 7060 |
* |
| 7061 |
* @param {Event} e |
| 7062 |
*/ |
| 7063 |
|
| 7064 |
const createPages = function createPages(e) { |
| 7065 |
const $button = $(this).addClass('disabled'); |
| 7066 |
e.preventDefault(); |
| 7067 |
$.post({ |
| 7068 |
url: $button.attr('href'), |
| 7069 |
data: { |
| 7070 |
'lp-ajax': 'create-pages' |
| 7071 |
}, |
| 7072 |
dataType: 'text', |
| 7073 |
success: function success(res) { |
| 7074 |
const $message = $button.closest('.lp-notice').html('<p>' + res + '</p>'); |
| 7075 |
setTimeout(function () { |
| 7076 |
$message.fadeOut(); |
| 7077 |
}, 2000); |
| 7078 |
} |
| 7079 |
}); |
| 7080 |
}; |
| 7081 |
const lpMetaboxFileInput = () => { |
| 7082 |
$('.lp-meta-box__file').each((i, element) => { |
| 7083 |
let lpImageFrame; |
| 7084 |
const imageGalleryIds = $(element).find('.lp-meta-box__file_input'); |
| 7085 |
const listImages = $(element).find('.lp-meta-box__file_list'); |
| 7086 |
const btnUpload = $(element).find('.btn-upload'); |
| 7087 |
const isMultil = !!$(element).data('multil'); |
| 7088 |
$(btnUpload).on('click', event => { |
| 7089 |
event.preventDefault(); |
| 7090 |
if (lpImageFrame) { |
| 7091 |
lpImageFrame.open(); |
| 7092 |
return; |
| 7093 |
} |
| 7094 |
lpImageFrame = wp.media({ |
| 7095 |
states: [new wp.media.controller.Library({ |
| 7096 |
filterable: 'all', |
| 7097 |
multiple: isMultil |
| 7098 |
})] |
| 7099 |
}); |
| 7100 |
lpImageFrame.on('select', function () { |
| 7101 |
const selection = lpImageFrame.state().get('selection'); |
| 7102 |
let attachmentIds = imageGalleryIds.val(); |
| 7103 |
selection.forEach(function (attachment) { |
| 7104 |
attachment = attachment.toJSON(); |
| 7105 |
if (attachment.id) { |
| 7106 |
if (!isMultil) { |
| 7107 |
attachmentIds = attachment.id; |
| 7108 |
listImages.empty(); |
| 7109 |
} else { |
| 7110 |
attachmentIds = attachmentIds ? attachmentIds + ',' + attachment.id : attachment.id; |
| 7111 |
} |
| 7112 |
listImages.append('<li class="lp-meta-box__file_list-item image" data-attachment_id="' + attachment.id + '"><img class="is_file" src="' + attachment.icon + '" /><span>' + attachment.filename + '</span><ul class="actions"><li><a href="#" class="delete"></a></li></ul></li>'); |
| 7113 |
} |
| 7114 |
}); |
| 7115 |
delImage(); |
| 7116 |
imageGalleryIds.val(attachmentIds); |
| 7117 |
}); |
| 7118 |
lpImageFrame.open(); |
| 7119 |
}); |
| 7120 |
if (isMultil) { |
| 7121 |
listImages.sortable({ |
| 7122 |
items: 'li.image', |
| 7123 |
cursor: 'move', |
| 7124 |
scrollSensitivity: 40, |
| 7125 |
forcePlaceholderSize: true, |
| 7126 |
forceHelperSize: false, |
| 7127 |
helper: 'clone', |
| 7128 |
opacity: 0.65, |
| 7129 |
placeholder: 'lp-metabox-sortable-placeholder', |
| 7130 |
start(event, ui) { |
| 7131 |
ui.item.css('background-color', '#f6f6f6'); |
| 7132 |
}, |
| 7133 |
stop(event, ui) { |
| 7134 |
ui.item.removeAttr('style'); |
| 7135 |
}, |
| 7136 |
update() { |
| 7137 |
let attachmentIds = ''; |
| 7138 |
listImages.find('li.image').css('cursor', 'default').each(function () { |
| 7139 |
const attachmentId = $(this).attr('data-attachment_id'); |
| 7140 |
attachmentIds = attachmentIds + attachmentId + ','; |
| 7141 |
}); |
| 7142 |
delImage(); |
| 7143 |
imageGalleryIds.val(attachmentIds); |
| 7144 |
} |
| 7145 |
}); |
| 7146 |
} |
| 7147 |
const delImage = () => { |
| 7148 |
$(listImages).find('li.image').each((i, ele) => { |
| 7149 |
const del = $(ele).find('a.delete'); |
| 7150 |
del.on('click', function () { |
| 7151 |
$(ele).remove(); |
| 7152 |
if (isMultil) { |
| 7153 |
let attachmentIds = ''; |
| 7154 |
$(listImages).find('li.image').css('cursor', 'default').each(function () { |
| 7155 |
const attachmentId = $(this).attr('data-attachment_id'); |
| 7156 |
attachmentIds = attachmentIds + attachmentId + ','; |
| 7157 |
}); |
| 7158 |
imageGalleryIds.val(attachmentIds); |
| 7159 |
} else { |
| 7160 |
imageGalleryIds.val(''); |
| 7161 |
} |
| 7162 |
return false; |
| 7163 |
}); |
| 7164 |
}); |
| 7165 |
}; |
| 7166 |
delImage(); |
| 7167 |
}); |
| 7168 |
}; |
| 7169 |
const onReady = function onReady() { |
| 7170 |
lpMetaboxFileInput(); |
| 7171 |
//updateDb(); |
| 7172 |
$('.learn-press-dropdown-pages').LP('DropdownPages'); |
| 7173 |
//$( '.learn-press-advertisement-slider' ).LP( 'Advertisement', 'a', 's' ).appendTo( $( '#wpbody-content' ) ); |
| 7174 |
//$( '.learn-press-toggle-item-preview' ).on( 'change', updateItemPreview ); |
| 7175 |
$('.learn-press-tip').LP('QuickTip'); //$('.learn-press-tabs').LP('AdminTab'); |
| 7176 |
|
| 7177 |
$(document).on('click', '#learn-press-create-pages', createPages) |
| 7178 |
//.on( 'click', '.lp-upgrade-notice .close-notice', hideUpgradeMessage ) |
| 7179 |
//.on( 'click', '.plugin-action-buttons a', pluginActions ) |
| 7180 |
//.on( 'click', '[data-remove-confirm]', preventDefault ) |
| 7181 |
.on('mousedown', '.lp-sortable-handle', function (e) { |
| 7182 |
$('html, body').addClass('lp-item-moving'); |
| 7183 |
$(e.target).closest('.lp-sortable-handle').css('cursor', 'inherit'); |
| 7184 |
}).on('mouseup', function (e) { |
| 7185 |
$('html, body').removeClass('lp-item-moving'); |
| 7186 |
$('.lp-sortable-handle').css('cursor', ''); |
| 7187 |
}); |
| 7188 |
|
| 7189 |
// Scroll to Passing grade when click link final Quiz in Course Setting. |
| 7190 |
if (window.location.hash) { |
| 7191 |
const hash = window.location.hash; |
| 7192 |
if (hash === '#_lp_passing_grade') { |
| 7193 |
const ele = document.querySelector(hash); |
| 7194 |
$('html, body').animate({ |
| 7195 |
scrollTop: $(hash).offset().top |
| 7196 |
}, 900, 'swing'); |
| 7197 |
ele.parentNode.style.border = '2px solid orangered'; |
| 7198 |
} |
| 7199 |
} |
| 7200 |
|
| 7201 |
// Show/hide meta-box field with type checkbox |
| 7202 |
/*$( 'input' ).on( 'click', function( e ) { |
| 7203 |
const el = $( e.target ); |
| 7204 |
if ( ! el.length ) { |
| 7205 |
return; |
| 7206 |
} |
| 7207 |
const id = el.attr( 'id' ); |
| 7208 |
if ( ! id ) { |
| 7209 |
return; |
| 7210 |
} |
| 7211 |
const classHide = id.replace( 'learn_press_', '' ); |
| 7212 |
const elHide = $( `.show_if_${ classHide }` ); |
| 7213 |
if ( el.is( ':checked' ) ) { |
| 7214 |
elHide.show(); |
| 7215 |
} else { |
| 7216 |
elHide.hide(); |
| 7217 |
} |
| 7218 |
} );*/ |
| 7219 |
}; |
| 7220 |
$(document).ready(onReady); |
| 7221 |
})(jQuery); |
| 7222 |
const showHideOptionsDependency = (e, target) => { |
| 7223 |
if (target.tagName === 'INPUT') { |
| 7224 |
if (target.closest('.forminp ')) { |
| 7225 |
const nameInput = target.name; |
| 7226 |
const classDependency = nameInput.replace('learn_press_', ''); |
| 7227 |
const elClassDependency = document.querySelectorAll(`.show_if_${classDependency}`); |
| 7228 |
if (elClassDependency) { |
| 7229 |
elClassDependency.forEach(el => { |
| 7230 |
el.classList.toggle('lp-option-disabled'); |
| 7231 |
}); |
| 7232 |
} |
| 7233 |
} else if (target.closest('.lp-meta-box')) { |
| 7234 |
const elLPMetaBox = target.closest('.lp-meta-box'); |
| 7235 |
const nameInput = target.name; |
| 7236 |
const elClassDependency = elLPMetaBox.querySelectorAll(`[data-dependency="${nameInput}"]`); |
| 7237 |
if (elClassDependency) { |
| 7238 |
elClassDependency.forEach(el => { |
| 7239 |
el.classList.toggle('lp-option-disabled'); |
| 7240 |
}); |
| 7241 |
} |
| 7242 |
} |
| 7243 |
} |
| 7244 |
}; |
| 7245 |
|
| 7246 |
// Events |
| 7247 |
document.addEventListener('click', e => { |
| 7248 |
const target = e.target; |
| 7249 |
showHideOptionsDependency(e, target); |
| 7250 |
// For case click add on Widgets of WordPress. |
| 7251 |
(0,_init_tom_select_js__WEBPACK_IMPORTED_MODULE_0__.initElsTomSelect)(); |
| 7252 |
}); |
| 7253 |
document.addEventListener('DOMContentLoaded', () => { |
| 7254 |
(0,_init_tom_select_js__WEBPACK_IMPORTED_MODULE_0__.searchUserOnListPost)(); |
| 7255 |
// Sure that the TomSelect is loaded if listen can't find elements. |
| 7256 |
(0,_init_tom_select_js__WEBPACK_IMPORTED_MODULE_0__.initElsTomSelect)(); |
| 7257 |
}); |
| 7258 |
|
| 7259 |
// Listen element select created on DOM. |
| 7260 |
_utils_admin_js__WEBPACK_IMPORTED_MODULE_1__.Utils.lpOnElementReady('select.lp-tom-select', e => { |
| 7261 |
(0,_init_tom_select_js__WEBPACK_IMPORTED_MODULE_0__.initElsTomSelect)(); |
| 7262 |
}); |
| 7263 |
_utils_admin_js__WEBPACK_IMPORTED_MODULE_1__.Utils.lpOnElementReady('#posts-filter', e => { |
| 7264 |
(0,_init_tom_select_js__WEBPACK_IMPORTED_MODULE_0__.searchUserOnListPost)(); |
| 7265 |
}); |
| 7266 |
window.lpFindTomSelect = _init_tom_select_js__WEBPACK_IMPORTED_MODULE_0__.initElsTomSelect; |
| 7267 |
})(); |
| 7268 |
|
| 7269 |
/******/ })() |
| 7270 |
; |
| 7271 |
//# sourceMappingURL=admin.js.map |