preline
Version:
Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.
9 lines • 3.46 kB
JavaScript
var t={615:(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}}},926:(t,e,i)=>{i.d(e,{JD:()=>s});const s=(t,e,i=null)=>{const s=new CustomEvent(t,{detail:{payload:i},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(s)}}},e={};function i(s){var r=e[s];if(void 0!==r)return r.exports;var o=e[s]={exports:{}};return t[s](o,o.exports,i),o.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:()=>l});var r=i(926),o=i(615);
/*
* HSCopyMarkup
* @version: 2.5.0
* @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 n extends o.A{constructor(t,e){super(t,e);const i=t.getAttribute("data-hs-copy-markup"),s=i?JSON.parse(i):{},r=Object.assign(Object.assign({},s),e);this.targetSelector=(null==r?void 0:r.targetSelector)||null,this.wrapperSelector=(null==r?void 0:r.wrapperSelector)||null,this.limit=(null==r?void 0:r.limit)||null,this.items=[],this.targetSelector&&this.init()}init(){this.createCollection(window.$hsCopyMarkupCollection,this),this.setTarget(),this.setWrapper(),this.addPredefinedItems(),this.el.addEventListener("click",(()=>this.copy()))}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);this.addToItems(t),this.limit&&this.items.length>=this.limit&&this.el.setAttribute("disabled","disabled"),this.fireEvent("copy",t),(0,r.JD)("copy.hs.copyMarkup",t,t)}addPredefinedItems(){Array.from(this.wrapper.children).filter((t=>!t.classList.contains("[--ignore-for-count]"))).forEach((t=>{this.addToItems(t)}))}setTarget(){const t="string"==typeof this.targetSelector?document.querySelector(this.targetSelector).cloneNode(!0):this.targetSelector.cloneNode(!0);t.removeAttribute("id"),this.target=t}setWrapper(){this.wrapper="string"==typeof this.wrapperSelector?document.querySelector(this.wrapperSelector):this.wrapperSelector}addToItems(t){const e=t.querySelector("[data-hs-copy-markup-delete-item]");this.wrapper?this.wrapper.append(t):this.el.before(t),e&&e.addEventListener("click",(()=>this.delete(t))),this.items.push(t)}delete(t){const e=this.items.indexOf(t);-1!==e&&this.items.splice(e,1),t.remove(),this.fireEvent("delete",t),(0,r.JD)("delete.hs.copyMarkup",t,t)}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=[]),document.querySelectorAll("[data-hs-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-hs-copy-markup"),i=e?JSON.parse(e):{};new n(t,i)}}))}}window.addEventListener("load",(()=>{n.autoInit()})),"undefined"!=typeof window&&(window.HSCopyMarkup=n);const l=n;var a=s.A;export{a as default};