Quellcode durchsuchen

feature: add support for closures

Ryan Chandler vor 4 Jahren
Ursprung
Commit
6292b7712e

+ 1 - 1
dist/alpine-clipboard.js

@@ -1,2 +1,2 @@
-const e={start(){if(!window.Alpine)throw new Error("Alpine is required for `alpine-clipboard` to work.");Alpine.addMagicProperty("clipboard",()=>function(e){let n=e;if("string"!=typeof n)try{n=JSON.stringify(n)}catch(e){console.warn(e)}const t=document.createElement("textarea");if(t.value=n,t.setAttribute("readonly",""),t.style.cssText="position:fixed;pointer-events:none;z-index:-9999;opacity:0;",document.body.appendChild(t),navigator.userAgent&&navigator.userAgent.match(/ipad|ipod|iphone/i)){t.contentEditable=!0,t.readOnly=!0;const e=document.createRange();e.selectNodeContents(t);const n=window.getSelection();n.removeAllRanges(),n.addRange(e),t.setSelectionRange(0,999999)}else t.select();try{document.execCommand("copy")}catch(e){console.warn(err)}document.body.removeChild(t)})}},n=window.deferLoadingAlpine||(e=>e());window.deferLoadingAlpine=function(t){e.start(),n(t)},module.exports=e;
+const e={start(){if(!window.Alpine)throw new Error("Alpine is required for `alpine-clipboard` to work.");Alpine.addMagicProperty("clipboard",()=>function(e){let n=e;if("function"==typeof n)n=n();else if("string"!=typeof n)try{n=JSON.stringify(n)}catch(e){console.warn(e)}const t=document.createElement("textarea");if(t.value=n,t.setAttribute("readonly",""),t.style.cssText="position:fixed;pointer-events:none;z-index:-9999;opacity:0;",document.body.appendChild(t),navigator.userAgent&&navigator.userAgent.match(/ipad|ipod|iphone/i)){t.contentEditable=!0,t.readOnly=!0;const e=document.createRange();e.selectNodeContents(t);const n=window.getSelection();n.removeAllRanges(),n.addRange(e),t.setSelectionRange(0,999999)}else t.select();try{document.execCommand("copy")}catch(e){console.warn(err)}document.body.removeChild(t)})}},n=window.deferLoadingAlpine||(e=>e());window.deferLoadingAlpine=function(t){e.start(),n(t)},module.exports=e;
 //# sourceMappingURL=alpine-clipboard.js.map

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/alpine-clipboard.js.map


+ 1 - 1
dist/alpine-clipboard.modern.js

@@ -1,2 +1,2 @@
-const e={start(){if(!window.Alpine)throw new Error("Alpine is required for `alpine-clipboard` to work.");Alpine.addMagicProperty("clipboard",()=>function(e){let t=e;if("string"!=typeof t)try{t=JSON.stringify(t)}catch(e){console.warn(e)}const n=document.createElement("textarea");if(n.value=t,n.setAttribute("readonly",""),n.style.cssText="position:fixed;pointer-events:none;z-index:-9999;opacity:0;",document.body.appendChild(n),navigator.userAgent&&navigator.userAgent.match(/ipad|ipod|iphone/i)){n.contentEditable=!0,n.readOnly=!0;const e=document.createRange();e.selectNodeContents(n);const t=window.getSelection();t.removeAllRanges(),t.addRange(e),n.setSelectionRange(0,999999)}else n.select();try{document.execCommand("copy")}catch(e){console.warn(err)}document.body.removeChild(n)})}},t=window.deferLoadingAlpine||(e=>e());window.deferLoadingAlpine=function(n){e.start(),t(n)};export default e;
+const e={start(){if(!window.Alpine)throw new Error("Alpine is required for `alpine-clipboard` to work.");Alpine.addMagicProperty("clipboard",()=>function(e){let t=e;if("function"==typeof t)t=t();else if("string"!=typeof t)try{t=JSON.stringify(t)}catch(e){console.warn(e)}const n=document.createElement("textarea");if(n.value=t,n.setAttribute("readonly",""),n.style.cssText="position:fixed;pointer-events:none;z-index:-9999;opacity:0;",document.body.appendChild(n),navigator.userAgent&&navigator.userAgent.match(/ipad|ipod|iphone/i)){n.contentEditable=!0,n.readOnly=!0;const e=document.createRange();e.selectNodeContents(n);const t=window.getSelection();t.removeAllRanges(),t.addRange(e),n.setSelectionRange(0,999999)}else n.select();try{document.execCommand("copy")}catch(e){console.warn(err)}document.body.removeChild(n)})}},t=window.deferLoadingAlpine||(e=>e());window.deferLoadingAlpine=function(n){e.start(),t(n)};export default e;
 //# sourceMappingURL=alpine-clipboard.modern.js.map

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/alpine-clipboard.modern.js.map


+ 1 - 1
dist/alpine-clipboard.module.js

@@ -1,2 +1,2 @@
-const e={start(){if(!window.Alpine)throw new Error("Alpine is required for `alpine-clipboard` to work.");Alpine.addMagicProperty("clipboard",()=>function(e){let t=e;if("string"!=typeof t)try{t=JSON.stringify(t)}catch(e){console.warn(e)}const n=document.createElement("textarea");if(n.value=t,n.setAttribute("readonly",""),n.style.cssText="position:fixed;pointer-events:none;z-index:-9999;opacity:0;",document.body.appendChild(n),navigator.userAgent&&navigator.userAgent.match(/ipad|ipod|iphone/i)){n.contentEditable=!0,n.readOnly=!0;const e=document.createRange();e.selectNodeContents(n);const t=window.getSelection();t.removeAllRanges(),t.addRange(e),n.setSelectionRange(0,999999)}else n.select();try{document.execCommand("copy")}catch(e){console.warn(err)}document.body.removeChild(n)})}},t=window.deferLoadingAlpine||(e=>e());window.deferLoadingAlpine=function(n){e.start(),t(n)};export default e;
+const e={start(){if(!window.Alpine)throw new Error("Alpine is required for `alpine-clipboard` to work.");Alpine.addMagicProperty("clipboard",()=>function(e){let t=e;if("function"==typeof t)t=t();else if("string"!=typeof t)try{t=JSON.stringify(t)}catch(e){console.warn(e)}const n=document.createElement("textarea");if(n.value=t,n.setAttribute("readonly",""),n.style.cssText="position:fixed;pointer-events:none;z-index:-9999;opacity:0;",document.body.appendChild(n),navigator.userAgent&&navigator.userAgent.match(/ipad|ipod|iphone/i)){n.contentEditable=!0,n.readOnly=!0;const e=document.createRange();e.selectNodeContents(n);const t=window.getSelection();t.removeAllRanges(),t.addRange(e),n.setSelectionRange(0,999999)}else n.select();try{document.execCommand("copy")}catch(e){console.warn(err)}document.body.removeChild(n)})}},t=window.deferLoadingAlpine||(e=>e());window.deferLoadingAlpine=function(n){e.start(),t(n)};export default e;
 //# sourceMappingURL=alpine-clipboard.module.js.map

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/alpine-clipboard.module.js.map


+ 1 - 1
dist/alpine-clipboard.umd.js

@@ -1,2 +1,2 @@
-!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).alpineClipboard=n()}(this,function(){const e={start(){if(!window.Alpine)throw new Error("Alpine is required for `alpine-clipboard` to work.");Alpine.addMagicProperty("clipboard",()=>function(e){let n=e;if("string"!=typeof n)try{n=JSON.stringify(n)}catch(e){console.warn(e)}const t=document.createElement("textarea");if(t.value=n,t.setAttribute("readonly",""),t.style.cssText="position:fixed;pointer-events:none;z-index:-9999;opacity:0;",document.body.appendChild(t),navigator.userAgent&&navigator.userAgent.match(/ipad|ipod|iphone/i)){t.contentEditable=!0,t.readOnly=!0;const e=document.createRange();e.selectNodeContents(t);const n=window.getSelection();n.removeAllRanges(),n.addRange(e),t.setSelectionRange(0,999999)}else t.select();try{document.execCommand("copy")}catch(e){console.warn(err)}document.body.removeChild(t)})}},n=window.deferLoadingAlpine||(e=>e());return window.deferLoadingAlpine=function(t){e.start(),n(t)},e});
+!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).alpineClipboard=n()}(this,function(){const e={start(){if(!window.Alpine)throw new Error("Alpine is required for `alpine-clipboard` to work.");Alpine.addMagicProperty("clipboard",()=>function(e){let n=e;if("function"==typeof n)n=n();else if("string"!=typeof n)try{n=JSON.stringify(n)}catch(e){console.warn(e)}const t=document.createElement("textarea");if(t.value=n,t.setAttribute("readonly",""),t.style.cssText="position:fixed;pointer-events:none;z-index:-9999;opacity:0;",document.body.appendChild(t),navigator.userAgent&&navigator.userAgent.match(/ipad|ipod|iphone/i)){t.contentEditable=!0,t.readOnly=!0;const e=document.createRange();e.selectNodeContents(t);const n=window.getSelection();n.removeAllRanges(),n.addRange(e),t.setSelectionRange(0,999999)}else t.select();try{document.execCommand("copy")}catch(e){console.warn(err)}document.body.removeChild(t)})}},n=window.deferLoadingAlpine||(e=>e());return window.deferLoadingAlpine=function(t){e.start(),n(t)},e});
 //# sourceMappingURL=alpine-clipboard.umd.js.map

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/alpine-clipboard.umd.js.map


+ 4 - 0
examples/index.html

@@ -9,4 +9,8 @@
         <input x-model="input">
         <button type="button" @click="$clipboard(input)">Copy to Clipboard</button>
     </div>
+
+    <div x-data="{}">
+        <button type="button" @click="$clipboard(() => 'Testing')">Copy 'Testing' to Clipboard</button>
+    </div>
 </body>

+ 3 - 1
src/index.js

@@ -8,7 +8,9 @@ const AlpineClipboard = {
             return function (target) {
                 let value = target
 
-                if (typeof value !== 'string') {
+                if (typeof value === 'function') {
+                    value = value()
+                } else if (typeof value !== 'string') {
                     try {
                         value = JSON.stringify(value)
                     } catch (e) {

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.