1'use strict'; 2 3function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } 4function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } 5function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } 6function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } 7function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } 8function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } 9function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } 10function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } 11function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } 12function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } 13function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } 14function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } 15function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } 16function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } 17function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } 18var id = 0; 19function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } 20import { Controller } from '@hotwired/stimulus'; 21import Sortable from 'sortablejs'; 22var _insertedAtPosition = /*#__PURE__*/_classPrivateFieldLooseKey("insertedAtPosition"); 23var _getCollectionItemFromTarget = /*#__PURE__*/_classPrivateFieldLooseKey("getCollectionItemFromTarget"); 24var _change = /*#__PURE__*/_classPrivateFieldLooseKey("change"); 25var _default = /*#__PURE__*/function (_Controller) { 26 _inheritsLoose(_default, _Controller); 27 function _default() { 28 var _this; 29 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 30 args[_key] = arguments[_key]; 31 } 32 _this = _callSuper(this, _default, [].concat(args));
33 Object.defineProperty(_assertThisInitialized(_this), _change, { 34 value: _change2 35 }); 36 Object.defineProperty(_assertThisInitialized(_this), _getCollectionItemFromTarget, { 37 value: _getCollectionItemFromTarget2 38 }); 39 Object.defineProperty(_assertThisInitialized(_this), _insertedAtPosition, { 40 value: _insertedAtPosition2 41 }); 42 _this.prototype = void 0; 43 return _this; 44 } 45 var _proto = _default.prototype; 46 _proto.connect = function connect() { 47 var _this2 = this; 48 this.element[this.identifier] = this; 49 this.prototype = this.element.dataset.prototype; 50 this.prototypeName = this.element.dataset.prototypeName; 51 this.autoIncrement = this.length; 52 if (this.hasMinValue && this.minValue && this.prototype !== undefined) { 53 for (var i = this.length; i < this.minValue; i++) { 54 this.add(); 55 } 56 } 57 if (this.allowDragAndDropValue) { 58 var sortableOptions = { 59 draggable: '[data-arkounay--ux-collection--collection-target="collectionElement"]', 60 onSort: function onSort() { 61 _classPrivateFieldLooseBase(_this2, _change)[_change](); 62 } 63 }; 64 if (this.hasDragAndDropPreventOnFilterValue) { 65 sortableOptions.preventOnFilter = this.dragAndDropPreventOnFilterValue; 66 } 67 if (this.hasDragAndDropFilterValue) { 68 sortableOptions.filter = this.dragAndDropFilterValue; 69 } 70 Sortable.create(this.element, sortableOptions); 71 } 72 _classPrivateFieldLooseBase(this, _change)[_change](); 73 this._dispatchEvent('ux-collection:connect'); 74 }; 75 _proto.moveUp = function moveUp(e) { 76 e.preventDefault(); 77 var element = _classPrivateFieldLooseBase(this, _getCollectionItemFromTarget)[_getCollectionItemFromTarget](e.target); 78 var index = this.collectionElementTargets.indexOf(element); 79 if (index === 0) { 80 return; 81 } 82 var newIndex = index - 1; 83 84 // move the dom element up 85 this.collectionElementTargets[newIndex].before(element); 86 _classPrivateFieldLooseBase(this, _change)[_change](); 87 this._dispatchEvent('ux-collection:moveUp', newIndex); 88 }; 89 _proto.moveDown = function moveDown(e) { 90 e.preventDefault(); 91 var element = _classPrivateFieldLooseBase(this, _getCollectionItemFromTarget)[_getCollectionItemFromTarget](e.target); 92 var index = this.collectionElementTargets.indexOf(element); 93 if (index === this.length - 1) { 94 return; 95 } 96 var newIndex = index + 1; 97 98 // move the dom element down 99 this.collectionElementTargets[newIndex].after(element); 100 _classPrivateFieldLooseBase(this, _change)[_change](); 101 this._dispatchEvent('ux-collection:moveDown', newIndex); 102 }; 103 _proto.remove = function remove(e) { 104 e.preventDefault(); 105 var element = _classPrivateFieldLooseBase(this, _getCollectionItemFromTarget)[_getCollectionItemFromTarget](e.target); 106 element.remove(); 107 _classPrivateFieldLooseBase(this, _change)[_change](); 108 this._dispatchEvent('ux-collection:remove', element); 109 }; 110 _proto.add = function add(e, position) { 111 e == null || e.preventDefault(); 112 var prototype = this.prototype.replaceAll(this.prototypeName, this.autoIncrement); 113 if (this.length === 0) { 114 this.element.insertAdjacentHTML('afterbegin', prototype); 115 position = -1; 116 } else { 117 if (position === undefined) { 118 position = this.length - 1; 119 } 120 this.collectionElementTargets[position].insertAdjacentHTML('afterend', prototype); 121 } 122 return _classPrivateFieldLooseBase(this, _insertedAtPosition)[_insertedAtPosition](position); 123 }; 124 _proto.insert = function insert(e) { 125 e.preventDefault(); 126 var prototype = this.prototype.replaceAll(this.prototypeName, this.autoIncrement); 127 var position = this.insertTargets.indexOf(e.currentTarget); 128 this.collectionElementTargets[position].insertAdjacentHTML('afterend', prototype); 129 return _classPrivateFieldLooseBase(this, _insertedAtPosition)[_insertedAtPosition](position); 130 }; 131 _proto._dispatchEvent = function _dispatchEvent(name, payload) { 132 this.element.dispatchEvent(new CustomEvent(name, { 133 detail: payload 134 })); 135 }; 136 _createClass(_default, [{ 137 key: "length", 138 get: function get() { 139 return this.collectionElementTargets.length; 140 } 141 }]); 142 return _default; 143}(Controller); 144function _insertedAtPosition2(position) { 145 var added = this.collectionElementTargets[position + 1]; 146 _classPrivateFieldLooseBase(this, _change)[_change](); 147 this._dispatchEvent('ux-collection:add', added); 148 this.autoIncrement++; 149 return added; 150} 151function _getCollectionItemFromTarget2(target) { 152 return target.closest('[data-arkounay--ux-collection--collection-target="collectionElement"]'); 153} 154function _change2() { 155 this._dispatchEvent('ux-collection:before-change'); 156 if (this.hasPositionSelectorValue) { 157 for (var i = 0; i < this.length; i++) { 158 this.collectionElementTargets[i].querySelector(this.positionSelectorValue).value = i; 159 } 160 } else if (this.allowDragAndDropValue || this.displaySortButtonsValue || this.displayInsertButtonValue) { 161 var namePrefix = this.element.dataset.namePrefix; 162 // refresh all form names if no position fields 163 for (var _i = 0; _i < this.length; _i++) { 164 var replaceRegExp = new RegExp((namePrefix + "[\\d+]").replaceAll('[', '\\[').replaceAll(']', '\\]'), 'g'); 165 for (var _iterator = _createForOfIteratorHelperLoose(this.collectionElementTargets[_i].querySelectorAll(["[data-name-prefix^=\"" + namePrefix + "[\"]"])), _step; !(_step = _iterator()).done;) { 166 var collection = _step.value; 167 // replace data-name-prefix for nested collection, otherwise sub-collections will have a bad namePrefix 168 collection.dataset.namePrefix = collection.dataset.namePrefix.replaceAll(replaceRegExp, namePrefix + "[" + _i + "]"); 169 } 170 for (var _iterator2 = _createForOfIteratorHelperLoose(this.collectionElementTargets[_i].querySelectorAll(["[data-name-prefix^=\"" + namePrefix + "[\"]"])), _step2; !(_step2 = _iterator2()).done;) { 171 var _collection = _step2.value; 172 // replace data-prototype for nested collection, otherwise sub-collections will have a bad inputs 173 _collection.dataset.prototype = _collection.dataset.prototype.replaceAll(replaceRegExp, namePrefix + "[" + _i + "]"); 174 } 175 for (var _iterator3 = _createForOfIteratorHelperLoose(this.collectionElementTargets[_i].querySelectorAll(["[name^=\"" + namePrefix + "[\"]"])), _step3; !(_step3 = _iterator3()).done;) { 176 var input = _step3.value; 177 var newName = input.name.replaceAll(replaceRegExp, namePrefix + "[" + _i + "]").replaceAll('_ux_collection_tmp_swap', ''); 178 179 // if a radio's name changes to an already existing name, it might uncheck the one which has the same name. 180 // to prevent this I append _ux_collection_tmp_swap to get a temporary name. It'll get changed back when reassigning names 181 var inputsWithSameName = this.element.querySelectorAll("[name=\"" + newName + "\"]"); 182 for (var _iterator4 = _createForOfIteratorHelperLoose(inputsWithSameName), _step4; !(_step4 = _iterator4()).done;) { 183 var inputWithSameName = _step4.value; 184 if (_classPrivateFieldLooseBase(this, _getCollectionItemFromTarget)[_getCollectionItemFromTarget](inputWithSameName) !== this.collectionElementTargets[_i]) { 185 inputWithSameName.name += '_ux_collection_tmp_swap'; 186 } 187 } 188 input.name = newName; 189 } 190 } 191 } 192 193 // refresh button positions 194 if (this.upTargets.length > 0) { 195 if (this.displaySortButtonsValue) { 196 for (var _i2 = 0; _i2 < this.length; _i2++) { 197 this.upTargets[_i2].classList.remove('d-none'); 198 this.downTargets[_i2].classList.remove('d-none'); 199 } 200 this.upTargets[0].classList.add('d-none'); 201 this.downTargets[this.downTargets.length - 1].classList.add('d-none'); 202 } else { 203 for (var _i3 = 0; _i3 < this.length; _i3++) { 204 this.upTargets[_i3].classList.add('d-none'); 205 this.downTargets[_i3].classList.add('d-none'); 206 } 207 } 208 } 209 210 // hide add button if there is a max value 211 if (this.hasMaxValue) { 212 var hasReachedMaxValue = this.length >= this.maxValue; 213 if (this.hasAddTarget) { 214 this.addTarget.classList.toggle('d-none', hasReachedMaxValue); 215 } 216 if (this.displayInsertButtonValue) { 217 for (var _iterator5 = _createForOfIteratorHelperLoose(this.insertTargets), _step5; !(_step5 = _iterator5()).done;) { 218 var insertTarget = _step5.value; 219 insertTarget.classList.toggle('d-none', hasReachedMaxValue); 220 } 221 for (var _iterator6 = _createForOfIteratorHelperLoose(this.collectionElementTargets), _step6; !(_step6 = _iterator6()).done;) { 222 var element = _step6.value; 223 element.classList.toggle('collection-element-with-insert', !hasReachedMaxValue); 224 element.classList.toggle('mb-3', hasReachedMaxValue); 225 } 226 } 227 } 228 if (this.displayInsertButtonValue) { 229 this.addWrapperTarget.classList.toggle('d-none', this.length > 0); 230 if (this.hasInsertTextTarget) { 231 for (var _i4 = 0; _i4 < this.insertTextTargets.length - 1; _i4++) { 232 this.insertTextTargets[_i4].textContent = this.insertTextTargets[_i4].dataset.insertText; 233 } 234 this.insertTextTargets[this.insertTextTargets.length - 1].textContent = this.insertTextTargets[this.insertTextTargets.length - 1].dataset.addText; 235 } 236 } 237 238 // hide remove button if there is a min value 239 if (this.hasMinValue && this.hasMinValue > 0 && this.deleteTargets.length > 0) { 240 var hideDelete = this.length <= this.minValue; 241 for (var _i5 = 0; _i5 < this.collectionElementTargets.length; _i5++) { 242 this.collectionElementTargets[_i5].classList.toggle('collection-hide-delete', hideDelete); 243 } 244 for (var _i6 = 0; _i6 < this.deleteTargets.length; _i6++) { 245 this.deleteTargets[_i6].classList.toggle('d-none', hideDelete); 246 } 247 } 248 this._dispatchEvent('ux-collection:change'); 249} 250_default.targets = ['collectionElement', 'up', 'down', 'add', 'addWrapper', 'delete', 'insert', 'insertText']; 251_default.values = { 252 min: Number, 253 max: Number, 254 allowDragAndDrop: Boolean, 255 dragAndDropFilter: String, 256 dragAndDropPreventOnFilter: Boolean, 257 displaySortButtons: Boolean, 258 displayInsertButton: Boolean, 259 positionSelector: String 260}; 261export { _default as default };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.