- md5
- 8f6fbba6fa5745cb0e16449bccf1da5a
- sha1
- 7f65502058a4d3560c5ce43a713885f03a7ea27d
- sha256
- 8695d19001f040f4a2a0defa9ecbcc7b1ca86b0b1d5c65bdc2456d5ac84762c3
"use strict";function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _wrapNativeSuper(a){var b="function"==typeof Map?new Map:void 0;return _wrapNativeSuper=function(a){function c(){return _construct(a,arguments,_getPrototypeOf(this).constructor)}if(null===a||!_isNativeFunction(a))return a;if("function"!=typeof a)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof b){if(b.has(a))return b.get(a);b.set(a,c)}return c.prototype=Object.create(a.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(c,a)},_wrapNativeSuper(a)}function _construct(){return _construct=_isNativeReflectConstruct()?Reflect.construct:function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&_setPrototypeOf(f,d.prototype),f},_construct.apply(null,arguments)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}function _isNativeFunction(a){return-1!==Function.toString.call(a).indexOf("[native code]")}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}(function(a){'use strict';function b(a){return a.ctrlKey||a.metaKey||a.shiftKey}var c={SPACE:32,ESC:27,ENTER:13},d=function(a){function d(){var a;_classCallCheck(this,d),a=e.call(this);var b=_assertThisInitialized(a);if(a.containerWithRows=_assertThisInitialized(a),a.rowsContainer)for(var f=a.querySelectorAll(a.rowsContainer),g=0,h=f.length;g<h;g++)if(f[g].closest("joomla-field-subform")===_assertThisInitialized(a)){a.containerWithRows=f[g];break}return a.lastRowIndex=a.getRows().length-1,a.template="",a.prepareTemplate(),(a.buttonAdd||a.buttonRemove)&&(a.addEventListener("click",function(a){var c=null,d=null;if(b.buttonAdd&&(c=a.target.matches(b.buttonAdd)?a.target:a.target.closest(b.buttonAdd)),b.buttonRemove&&(d=a.target.matches(b.buttonRemove)?a.target:a.target.closest(b.buttonRemove)),c&&c.closest("joomla-field-subform")===b){var e=c.closest("joomla-field-subform");e=e.closest(b.repeatableElement)===b?e:null,b.addRow(e),a.preventDefault()}else if(d&&d.closest("joomla-field-subform")===b){var f=d.closest(b.repeatableElement);b.removeRow(f),a.preventDefault()}}),a.addEventListener("keydown",function(a){if(a.keyCode===c.SPACE){var d=b.buttonAdd&&a.target.matches(b.buttonAdd),e=b.buttonRemove&&a.target.matches(b.buttonRemove);if((d||e)&&a.target.closest("joomla-field-subform")===b){var f=a.target.closest("joomla-field-subform");f=f.closest(b.repeatableElement)===b?f:null,e&&f?b.removeRow(f):d&&b.addRow(f),a.preventDefault()}}})),a.buttonMove&&a.setUpDragSort(),a}_inherits(d,a);var e=_createSuper(d);return _createClass(d,[{key:"buttonAdd",get:function get(){return this.getAttribute("button-add")}},{key:"buttonRemove",get:function get(){return this.getAttribute("button-remove")}},{key:"buttonMove",get:function get(){return this.getAttribute("button-move")}},{key:"rowsContainer",get:function get(){return this.getAttribute("rows-container")}},{key:"repeatableElement",get:function get(){return this.getAttribute("repeatable-element")}},{key:"minimum",get:function get(){return this.getAttribute("minimum")}},{key:"maximum",get:function get(){return this.getAttribute("maximum")}},{key:"name",get:function get(){return this.getAttribute("name")},set:function set(a){return this.template=this.template.replace(new RegExp(" name=\"".concat(this.name.replace(/[\[\]]/g,"\\$&")),"g")," name=\"".concat(a)),this.setAttribute("name",a)}}]),_createClass(d,[{key:"getRows",value:function getRows(){for(var a=this.containerWithRows.children,b=[],c=0,d=a.length;c<d;c++)a[c].matches(this.repeatableElement)&&b.push(a[c]);return b}},{key:"prepareTemplate",value:function prepareTemplate(){var a=[].slice.call(this.children).filter(function(a){return a.classList.contains("subform-repeatable-template-section")});if(a[0]&&(this.template=a[0].innerHTML),!this.template)throw new Error("The row template are required to subform element to work")}},{key:"addRow",value:function addRow(a){var b=this.getRows().length;if(b>=this.maximum)return null;var c;c="TBODY"===this.containerWithRows.nodeName||"TABLE"===this.containerWithRows.nodeName?document.createElement("tbody"):document.createElement("div"),c.innerHTML=this.template;var d=c.children[0];return a?a.parentNode.insertBefore(d,a.nextSibling):this.containerWithRows.append(d),this.buttonMove&&(d.setAttribute("draggable","false"),d.setAttribute("aria-grabbed","false"),d.setAttribute("tabindex","0")),d.setAttribute("data-new","1"),this.fixUniqueAttributes(d,b),this.dispatchEvent(new CustomEvent("subform-row-add",{detail:{row:d},bubbles:!0})),window.Joomla&&Joomla.Event.dispatch(d,"joomla:updated"),d}},{key:"removeRow",value:function removeRow(a){var b=this.getRows().length;b<=this.minimum||(this.dispatchEvent(new CustomEvent("subform-row-remove",{detail:{row:a},bubbles:!0})),window.Joomla&&Joomla.Event.dispatch(a,"joomla:removed"),a.parentNode.removeChild(a))}},{key:"fixUniqueAttributes",value:function fixUniqueAttributes(a,b){var c=this;b=b||0;var d=a.getAttribute("data-group"),e=a.getAttribute("data-base-name"),f=Math.max(this.lastRowIndex,b),g=e+f;this.lastRowIndex=f+1,a.setAttribute("data-group",g);var h=a.querySelectorAll("[name]"),j={};h=[].slice.call(h).filter(function(a){return a.closest("joomla-field-subform")===c});for(var w=0,i=h.length;w<i;w++){var k=h[w],m=k.getAttribute("name"),n=m.replace(/(\[\]$)/g,"").replace(/(\]\[)/g,"__").replace(/\[/g,"_").replace(/\]/g,""),o=m.replace("[".concat(d,"]["),"[".concat(g,"][")),p=n.replace(d,g).replace(/\W/g,"_"),q=0,r=n;if("checkbox"===k.type&&m.match(/\[\]$/)){if(q=j[n]?j[n].length:0,!q){var s=k.closest("fieldset.checkboxes"),t=a.querySelector("label[for=\"".concat(n,"\"]"));s&&s.setAttribute("id",p),t&&(t.setAttribute("for",p),t.setAttribute("id","".concat(p,"-lbl")))}r+=q,p+=q}else if("radio"===k.type){if(q=j[n]?j[n].length:0,!q){var u=k.closest("fieldset.radio"),v=a.querySelector("label[for=\"".concat(n,"\"]"));u&&u.setAttribute("id",p),v&&(v.setAttribute("for",p),v.setAttribute("id","".concat(p,"-lbl")))}r+=q,p+=q}j[n]?j[n].push(!0):j[n]=[!0],k.name=o,k.id&&(k.id=p);var l=a.querySelector("label[for=\"".concat(r,"\"]"));l&&(l.setAttribute("for",p),l.setAttribute("id","".concat(p,"-lbl")))}}},{key:"setUpDragSort",value:function setUpDragSort(){function a(a){return!a.form&&a.matches(f.buttonMove)?a:a.closest(f.buttonMove)}function d(a,b){var c=!1;if(a.parentNode===b.parentNode)for(var d=a;d;d=d.previousSibling)if(d===b){c=!0;break}c?b.parentNode.insertBefore(a,b):b.parentNode.insertBefore(a,b.nextSibling)}for(var e,f=this,g=null,h=!1,i=this.getRows(),j=0,k=i.length;j<k;j++)e=i[j],e.setAttribute("draggable","false"),e.setAttribute("aria-grabbed","false"),e.setAttribute("tabindex","0");this.addEventListener("touchstart",function(b){h=!0;var c=a(b.target),e=c?c.closest(f.repeatableElement):null;e&&e.closest("joomla-field-subform")===f&&(g?(e!==g&&d(g,e),g.setAttribute("draggable","false"),g.setAttribute("aria-grabbed","false"),g=null):(e.setAttribute("draggable","true"),e.setAttribute("aria-grabbed","true"),g=e),b.preventDefault())}),this.addEventListener("mousedown",function(b){var c=b.target;if(!h){var d=a(c),e=d?d.closest(f.repeatableElement):null;e&&e.closest("joomla-field-subform")===f&&(e.setAttribute("draggable","true"),e.setAttribute("aria-grabbed","true"),g=e)}}),this.addEventListener("mouseup",function(){g&&!h&&(g.setAttribute("draggable","false"),g.setAttribute("aria-grabbed","false"),g=null)}),this.addEventListener("keydown",function(a){if((a.keyCode===c.ESC||a.keyCode===c.SPACE||a.keyCode===c.ENTER)&&!a.target.form&&a.target.matches(f.repeatableElement)){var e=a.target;if(e&&e.closest("joomla-field-subform")===f&&(a.keyCode===c.SPACE&&b(a)&&("true"===e.getAttribute("aria-grabbed")?(e.setAttribute("draggable","false"),e.setAttribute("aria-grabbed","false"),g=null):(g&&(g.setAttribute("draggable","false"),g.setAttribute("aria-grabbed","false"),g=null),e.setAttribute("draggable","true"),e.setAttribute("aria-grabbed","true"),g=e),a.preventDefault()),a.keyCode===c.ESC&&g&&(g.setAttribute("draggable","false"),g.setAttribute("aria-grabbed","false"),g=null),a.keyCode===c.ENTER&&g)){if(g.setAttribute("draggable","false"),g.setAttribute("aria-grabbed","false"),e===g)return void(g=null);d(g,e),a.preventDefault(),g=null}}}),this.addEventListener("dragstart",function(a){var b=a.dataTransfer;g&&(b.effectAllowed="move",b.setData("text",""))}),this.addEventListener("dragover",function(a){g&&a.preventDefault()}),this.addEventListener("dragenter",function(a){var b=a.target;if(g&&(!f.rowsContainer||b.closest(f.rowsContainer)===f.containerWithRows)){var c=b.matches(f.repeatableElement)?b:b.closest(f.repeatableElement);c&&d(g,c)}}),this.addEventListener("dragend",function(){g&&(g.setAttribute("draggable","false"),g.setAttribute("aria-grabbed","false"),g=null)})}}]),d}(_wrapNativeSuper(HTMLElement));a.define("joomla-field-subform",d)})(customElements);
The same content is in 4 releases, Joomla 4.0.0-beta to 4.0.0-beta4. See them all, or every version of this file.