Browse Source

feature: v3 support!!!

Ryan Chandler 3 years ago
parent
commit
c4a11a533b

+ 5 - 0
builds/cdn.js

@@ -0,0 +1,5 @@
+import clipboard from '../src/index'
+
+document.addEventListener('alpine:initializing', () => {
+    clipboard(window.Alpine)
+})

+ 0 - 70
dist/alpine-clipboard.ie11.js

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

File diff suppressed because it is too large
+ 0 - 0
dist/alpine-clipboard.ie11.js.map


+ 19 - 32
dist/alpine-clipboard.js

@@ -1,36 +1,23 @@
-(function (global, factory) {
-    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+(function (factory) {
     typeof define === 'function' && define.amd ? define(factory) :
-    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.AlpineClipboard = factory());
-}(this, (function () { 'use strict';
-
-    const AlpineClipboard = {
-      start() {
-        if (!window.Alpine) {
-          throw new Error('Alpine is required for `alpine-clipboard` to work.');
-        }
-
-        Alpine.addMagicProperty('clipboard', () => {
-          return function (target) {
-            if (typeof target === 'function') {
-              target = target();
-            }
-
-            return window.navigator.clipboard.writeText(target);
-          };
-        });
-      }
-
-    };
-
-    const deferrer = window.deferLoadingAlpine || (callback => callback());
-
-    window.deferLoadingAlpine = function (callback) {
-      AlpineClipboard.start();
-      deferrer(callback);
-    };
-
-    return AlpineClipboard;
+    factory();
+}((function () { 'use strict';
+
+    function clipboard (Alpine) {
+      Alpine.magic('clipboard', () => {
+        return function (target) {
+          if (typeof target === 'function') {
+            target = target();
+          }
+
+          return window.navigator.clipboard.writeText(target);
+        };
+      });
+    }
+
+    document.addEventListener('alpine:initializing', () => {
+      clipboard(window.Alpine);
+    });
 
 })));
 //# sourceMappingURL=alpine-clipboard.js.map

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

@@ -1 +1 @@
-{"version":3,"file":"alpine-clipboard.js","sources":["../src/index.js"],"sourcesContent":["const AlpineClipboard = {\n    start() {\n        if (!window.Alpine) {\n            throw new Error('Alpine is required for `alpine-clipboard` to work.')\n        }\n\n        Alpine.addMagicProperty('clipboard', () => {\n            return function (target) {\n                if (typeof target === 'function') {\n                    target = target()\n                }\n                \n                return window.navigator.clipboard.writeText(target)\n            }\n        })\n    }\n}\n\nconst deferrer = window.deferLoadingAlpine || ((callback) => callback())\n\nwindow.deferLoadingAlpine = function (callback) {\n    AlpineClipboard.start()\n\n    deferrer(callback)\n}\n\nexport default AlpineClipboard"],"names":["AlpineClipboard","start","window","Alpine","Error","addMagicProperty","target","navigator","clipboard","writeText","deferrer","deferLoadingAlpine","callback"],"mappings":";;;;;;UAAMA,eAAe,GAAG;IACpBC,EAAAA,KAAK,GAAG;IACJ,QAAI,CAACC,MAAM,CAACC,MAAZ,EAAoB;IAChB,YAAM,IAAIC,KAAJ,CAAU,oDAAV,CAAN;IACH;;IAEDD,IAAAA,MAAM,CAACE,gBAAP,CAAwB,WAAxB,EAAqC,MAAM;IACvC,aAAO,UAAUC,MAAV,EAAkB;IACrB,YAAI,OAAOA,MAAP,KAAkB,UAAtB,EAAkC;IAC9BA,UAAAA,MAAM,GAAGA,MAAM,EAAf;IACH;;IAED,eAAOJ,MAAM,CAACK,SAAP,CAAiBC,SAAjB,CAA2BC,SAA3B,CAAqCH,MAArC,CAAP;IACH,OAND;IAOH,KARD;IASH;;IAfmB;;IAkBxB,MAAMI,QAAQ,GAAGR,MAAM,CAACS,kBAAP,KAA+BC,QAAD,IAAcA,QAAQ,EAApD,CAAjB;;IAEAV,MAAM,CAACS,kBAAP,GAA4B,UAAUC,QAAV,EAAoB;IAC5CZ,EAAAA,eAAe,CAACC,KAAhB;IAEAS,EAAAA,QAAQ,CAACE,QAAD,CAAR;IACH,CAJD;;;;;;;;"}
+{"version":3,"file":"alpine-clipboard.js","sources":["../src/index.js","../builds/cdn.js"],"sourcesContent":["export default function (Alpine) {\n    Alpine.magic('clipboard', () => {\n        return function (target) {\n            if (typeof target === 'function') {\n                target = target()\n            }\n\n            return window.navigator.clipboard.writeText(target)\n        }\n    })\n}","import clipboard from '../src/index'\n\ndocument.addEventListener('alpine:initializing', () => {\n    clipboard(window.Alpine)\n})"],"names":["Alpine","magic","target","window","navigator","clipboard","writeText","document","addEventListener"],"mappings":";;;;;IAAe,oBAAUA,MAAV,EAAkB;IAC7BA,EAAAA,MAAM,CAACC,KAAP,CAAa,WAAb,EAA0B,MAAM;IAC5B,WAAO,UAAUC,MAAV,EAAkB;IACrB,UAAI,OAAOA,MAAP,KAAkB,UAAtB,EAAkC;IAC9BA,QAAAA,MAAM,GAAGA,MAAM,EAAf;IACH;;IAED,aAAOC,MAAM,CAACC,SAAP,CAAiBC,SAAjB,CAA2BC,SAA3B,CAAqCJ,MAArC,CAAP;IACH,KAND;IAOH,GARD;IASH;;ICRDK,QAAQ,CAACC,gBAAT,CAA0B,qBAA1B,EAAiD,MAAM;IACnDH,EAAAA,SAAS,CAACF,MAAM,CAACH,MAAR,CAAT;IACH,CAFD;;;;;;"}

File diff suppressed because it is too large
+ 4685 - 225
package-lock.json


+ 2 - 3
package.json

@@ -8,15 +8,14 @@
         "type": "git",
         "url": "https://github.com/ryangjchandler/alpine-clipboard"
     },
-
     "main": "src/index.js",
     "scripts": {
-        "build": "rollup -c && rollup -c rollup.ie11.config.js",
+        "build": "rollup -c",
         "watch": "rollup -c -w"
     },
     "devDependencies": {
-        "@babel/preset-env": "^7.12.11",
         "@babel/core": "^7.12.10",
+        "@babel/preset-env": "^7.12.11",
         "rollup": "^2.35.1",
         "rollup-plugin-babel": "^4.4.0",
         "rollup-plugin-filesize": "^9.1.0",

+ 1 - 1
rollup.config.js

@@ -4,7 +4,7 @@ import filesize from 'rollup-plugin-filesize'
 import resolve from 'rollup-plugin-node-resolve'
 
 export default {
-    input: 'src/index.js',
+    input: 'builds/cdn.js',
     output: [
         {
             name: 'AlpineClipboard',

+ 9 - 25
src/index.js

@@ -1,27 +1,11 @@
-const AlpineClipboard = {
-    start() {
-        if (!window.Alpine) {
-            throw new Error('Alpine is required for `alpine-clipboard` to work.')
-        }
-
-        Alpine.addMagicProperty('clipboard', () => {
-            return function (target) {
-                if (typeof target === 'function') {
-                    target = target()
-                }
-                
-                return window.navigator.clipboard.writeText(target)
+export default function (Alpine) {
+    Alpine.magic('clipboard', () => {
+        return function (target) {
+            if (typeof target === 'function') {
+                target = target()
             }
-        })
-    }
-}
-
-const deferrer = window.deferLoadingAlpine || ((callback) => callback())
 
-window.deferLoadingAlpine = function (callback) {
-    AlpineClipboard.start()
-
-    deferrer(callback)
-}
-
-export default AlpineClipboard
+            return window.navigator.clipboard.writeText(target)
+        }
+    })
+}

+ 27 - 0
src/index.old.js

@@ -0,0 +1,27 @@
+const AlpineClipboard = {
+    start() {
+        if (!window.Alpine) {
+            throw new Error('Alpine is required for `alpine-clipboard` to work.')
+        }
+
+        Alpine.addMagicProperty('clipboard', () => {
+            return function (target) {
+                if (typeof target === 'function') {
+                    target = target()
+                }
+                
+                return window.navigator.clipboard.writeText(target)
+            }
+        })
+    }
+}
+
+const deferrer = window.deferLoadingAlpine || ((callback) => callback())
+
+window.deferLoadingAlpine = function (callback) {
+    AlpineClipboard.start()
+
+    deferrer(callback)
+}
+
+export default AlpineClipboard

Some files were not shown because too many files changed in this diff