flyonui
Version:
The easiest, free and open-source Tailwind CSS component library with semantic classes.
16 lines • 4.63 kB
JavaScript
var t={392:(t,e,i)=>{i.d(e,{JD:()=>s});
/*
* @version: 3.2.2
* @author: Preline Labs Ltd.
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
* Copyright 2024 Preline Labs Ltd.
*/
const s=(t,e,i=null)=>{const s=new CustomEvent(t,{detail:{payload:i},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(s)}},709:(t,e,i)=>{i.d(e,{A:()=>s});class s{constructor(t,e,i){this.el=t,this.options=e,this.events=i,this.el=t,this.options=e,this.events={}}createCollection(t,e){var i;t.push({id:(null===(i=null==e?void 0:e.el)||void 0===i?void 0:i.id)||t.length+1,element:e})}fireEvent(t,e=null){if(this.events.hasOwnProperty(t))return this.events[t](e)}on(t,e){this.events[t]=e}}}},e={};function i(s){var o=e[s];if(void 0!==o)return o.exports;var l=e[s]={exports:{}};return t[s](l,l.exports,i),l.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var s={};i.d(s,{A:()=>n});var o=i(392),l=i(709);
/*
* HSCopyMarkup
* @version: 3.2.2
* @author: Preline Labs Ltd.
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
* Copyright 2024 Preline Labs Ltd.
*/
class r extends l.A{constructor(t,e){super(t,e),this.count=0;const i=t.getAttribute("data-copy-markup"),s=i?JSON.parse(i):{},o=Object.assign(Object.assign({},s),e);this.targetSelector=(null==o?void 0:o.targetSelector)||null,this.wrapperSelector=(null==o?void 0:o.wrapperSelector)||null,this.limit=(null==o?void 0:o.limit)||null,this.items=[],this.targetSelector&&this.init()}elementClick(){this.copy()}deleteItemButtonClick(t){this.delete(t)}init(){this.createCollection(window.$hsCopyMarkupCollection,this),this.onElementClickListener=()=>this.elementClick(),this.setTarget(),this.setWrapper(),this.addPredefinedItems(),this.el.addEventListener("click",this.onElementClickListener)}copy(){if(this.limit&&this.items.length>=this.limit)return!1;this.el.hasAttribute("disabled")&&this.el.setAttribute("disabled","");const t=this.target.cloneNode(!0),e=`${this.target.id}-${this.count++}`;t.setAttribute("id",e),this.addToItems(t),this.limit&&this.items.length>=this.limit&&this.el.setAttribute("disabled","disabled"),this.fireEvent("copy",t),(0,o.JD)("copy.copyMarkup",t,t)}addPredefinedItems(){Array.from(this.wrapper.children).filter(t=>!t.classList.contains("[--ignore-for-count]")).forEach(t=>{this.addToItems(t)}),this.limit&&this.items.length>=this.limit&&this.el.setAttribute("disabled","disabled")}setTarget(){const t="string"==typeof this.targetSelector?document.querySelector(this.targetSelector).cloneNode(!0):this.targetSelector.cloneNode(!0);this.target=t}setWrapper(){this.wrapper="string"==typeof this.wrapperSelector?document.querySelector(this.wrapperSelector):this.wrapperSelector}addToItems(t){const e=t.querySelector("[data-copy-markup-delete-item]");this.wrapper?this.wrapper.append(t):this.el.before(t),e&&(this.onDeleteItemButtonClickListener=()=>this.deleteItemButtonClick(t),e.addEventListener("click",this.onDeleteItemButtonClickListener)),this.items.push(t)}delete(t){if(t){const e=this.items.indexOf(t);-1!==e&&this.items.splice(e,1),t.remove(),this.fireEvent("delete",t),(0,o.JD)("delete.copyMarkup",t,t),this.limit&&this.items.length<this.limit&&this.el.removeAttribute("disabled")}}destroy(){const t=this.wrapper.querySelectorAll("[data-copy-markup-delete-item]");this.el.removeEventListener("click",this.onElementClickListener),t.length&&t.forEach(t=>t.removeEventListener("click",this.onDeleteItemButtonClickListener)),this.el.removeAttribute("disabled"),this.target=null,this.wrapper=null,this.items=null,window.$hsCopyMarkupCollection=window.$hsCopyMarkupCollection.filter(({element:t})=>t.el!==this.el)}static getInstance(t,e){const i=window.$hsCopyMarkupCollection.find(e=>e.element.el===("string"==typeof t?document.querySelector(t):t));return i?e?i:i.element:null}static autoInit(){window.$hsCopyMarkupCollection||(window.$hsCopyMarkupCollection=[]),window.$hsCopyMarkupCollection&&(window.$hsCopyMarkupCollection=window.$hsCopyMarkupCollection.filter(({element:t})=>document.contains(t.el))),document.querySelectorAll("[data-copy-markup]:not(.--prevent-on-load-init)").forEach(t=>{if(!window.$hsCopyMarkupCollection.find(e=>{var i;return(null===(i=null==e?void 0:e.element)||void 0===i?void 0:i.el)===t})){const e=t.getAttribute("data-copy-markup"),i=e?JSON.parse(e):{};new r(t,i)}})}}window.addEventListener("load",()=>{r.autoInit()}),"undefined"!=typeof window&&(window.HSCopyMarkup=r);const n=r,a=s.A;export{a as default};