phoenix_duskmoon 9.12.0 → 9.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=[`dm-click`,`dm-change`,`dm-input`,`dm-focus`,`dm-blur`,`dm-submit`,`dm-select`,`dm-close`,`dm-open`,`dm-toggle`],t=Symbol.for(`phoenix-duskmoon.copy-listener`),n=new WeakMap,
|
|
1
|
+
const e=[`dm-click`,`dm-change`,`dm-input`,`dm-focus`,`dm-blur`,`dm-submit`,`dm-select`,`dm-close`,`dm-open`,`dm-toggle`],t=Symbol.for(`phoenix-duskmoon.copy-listener`),n=Symbol.for(`phoenix-duskmoon.dialog-behavior-listeners`),r=new WeakMap,i={mounted(){this._sendListeners=[],this._setupEventBridging(),this._setupAutomaticForwarding()},updated(){this._setupAutomaticForwarding()},destroyed(){this._sendListeners&&(this._sendListeners.forEach(({event:e,listener:t})=>{this.el.removeEventListener(e,t)}),this._sendListeners=null),e.forEach(e=>{let t=`_dm_listener_${e}`;this[t]&&(this.el.removeEventListener(e,this[t]),this[t]=null)})},_setupEventBridging(){let e=this.el.attributes,t=this.el.getAttribute(`phx-target`),n=(e,n,r)=>{t?this.pushEventTo(t,e,n,r):this.pushEvent(e,n,r)};for(let t=0;t<e.length;t++){let r=e[t];if(/^duskmoon-send-/.test(r.name)){let e=r.name.replace(/^duskmoon-send-/,``),[t,i]=r.value.split(`;`),a=({detail:r})=>{n(t,r||{},t=>{i&&typeof this[i]==`function`&&this[i](t,r,e)})};this.el.addEventListener(e,a),this._sendListeners.push({event:e,listener:a})}if(/^duskmoon-receive-/.test(r.name)){let e=r.name.replace(/^duskmoon-receive-/,``),t=r.value;this.handleEvent(e,n=>{t&&typeof this.el[t]==`function`?this.el[t](n):this.el.dispatchEvent(new CustomEvent(e,{detail:n,bubbles:!0,composed:!0}))})}if(r.name===`duskmoon-receive`){let[e,t]=r.value.split(`;`);this.handleEvent(e,e=>{typeof this.el[t]==`function`&&this.el[t](e)})}}},_setupAutomaticForwarding(){let t=this.el.getAttribute(`phx-target`);e.forEach(e=>{let n=`phx-`+e.replace(`dm-`,``),r=this.el.getAttribute(n);if(r){let n=`_dm_listener_${e}`;this[n]&&this.el.removeEventListener(e,this[n]),this[n]=e=>{let n={...e.detail||{},value:this.el.value,name:this.el.name,checked:this.el.checked};t?this.pushEventTo(t,r,n):this.pushEvent(r,n)},this.el.addEventListener(e,this[n])}})}},a={...i,mounted(){i.mounted.call(this),this._setupFormIntegration()},_setupFormIntegration(){let e=this.el.getAttribute(`name`),t=this.el.getAttribute(`phx-feedback-for`)||e;t&&this._setupFeedbackObserver(t)},destroyed(){i.destroyed.call(this),this._feedbackObserver&&(this._feedbackObserver.disconnect(),this._feedbackObserver=null)},_setupFeedbackObserver(e){let t=this.el.closest(`form`);t&&(this._feedbackObserver=new MutationObserver(n=>{n.forEach(n=>{if(n.attributeName===`class`){let n=t.classList.contains(`phx-no-feedback`);this.el.dispatchEvent(new CustomEvent(`dm-feedback-change`,{detail:{showFeedback:!n,field:e}}))}})}),this._feedbackObserver.observe(t,{attributes:!0,attributeFilter:[`class`]}))}};async function o(e,t=globalThis){let n=t.navigator?.clipboard;if(typeof n?.writeText==`function`){await n.writeText(e);return}let r=t.document;if(!r?.body||typeof r.execCommand!=`function`)throw Error(`Clipboard API is unavailable`);let i=r.createElement(`textarea`),a=r.activeElement;i.value=e,i.setAttribute(`readonly`,``),i.style.position=`fixed`,i.style.opacity=`0`,r.body.appendChild(i);try{if(i.focus(),i.select(),!r.execCommand(`copy`))throw Error(`Clipboard copy command failed`)}finally{r.body.removeChild(i),a?.focus?.()}}function s(e){let t=e.nextElementSibling;return t?.matches?.(`[data-copy-status]`)?t:e.parentElement?.querySelector?.(`[data-copy-status]`)??null}function c(e,t,n,i){let a=e.querySelector?.(`[data-copy-label]`),o=s(e),c=r.get(e),l=i.cancelReset??globalThis.clearTimeout,u=i.scheduleReset??globalThis.setTimeout;c?.timer!==void 0&&l(c.timer);let d=c?.originalLabel??a?.textContent??`Copy`;a&&(a.textContent=t),o&&(o.textContent=t),e.dataset.copyState=n;let f=u(()=>{a&&(a.textContent=d),o&&(o.textContent=``),delete e.dataset.copyState,r.delete(e)},2e3);r.set(e,{originalLabel:d,timer:f})}async function l(e,t={}){let n=e.target?.closest?.(`[data-copy-value]`);if(!n||n.disabled||n.getAttribute?.(`aria-disabled`)===`true`)return;let r=t.copy??o;try{await r(n.dataset.copyValue),c(n,n.dataset.copySuccess??`Copied`,`success`,t)}catch{c(n,n.dataset.copyFailure??`Copy failed`,`error`,t)}}function u(e=globalThis.document,n={}){if(!e?.addEventListener||e[t])return;let r=e=>l(e,n);e.addEventListener(`click`,r),e[t]=r}function d(e){let t=e.composedPath?.()??[],n=t.find(e=>e.matches?.(`[data-dm-confirm-action="true"]`)),r=t.find(e=>e.matches?.(`dialog[data-dm-confirm-dialog="true"]`));n&&r?.open&&r.close()}function f(e=globalThis.document){!e?.addEventListener||e[n]||(e.addEventListener(`click`,d,!0),e[n]=d)}u(),f(),typeof window<`u`&&(window.__WebComponentHook__=i,window.__FormElementHook__=a);export{a as FormElementHook,i as WebComponentHook,o as copyTextToClipboard,l as handleClipboardClick,d as handleDialogConfirmClick,u as installClipboardBehavior,f as installDialogBehavior};
|