@stackblitz/sdk
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -1,2 +0,2 @@ | ||
var e="300";function t(){return Math.random().toString(36).substring(7)}function n(e){var t="";return e?(e.ctl&&(t+="ctl=1"),e.openFile&&(t+=(t.length?"&":"")+"file="+e.openFile),(e.view&&"preview"===e.view||"editor"===e.view)&&(t+=(t.length?"&":"")+"view="+e.view),t.length?"?"+t:t):t}function i(e,t,n){if(null===e.parentNode)throw new Error("Invalid Element");t.id=e.id,a(t,n),e.parentNode.replaceChild(t,e)}function r(e){if("string"==typeof e){var t=document.getElementById(e);if(null!==t)return t}else if(e instanceof HTMLElement)return e;throw new Error("Invalid Element")}function o(e){return e&&!1===e.newWindow?"_self":"_blank"}function a(t,n){n&&(n.hasOwnProperty("height")&&(t.height=""+n.height),n.hasOwnProperty("width")&&(t.width=""+n.width)),t.height||(t.height=e),t.width||t.setAttribute("style","width:100%;")}var d=function(e){var t=this;this.pending={},this.port=e,this.port.onmessage=function(e){if(e.data.payload.__reqid){var n=e.data.payload.__reqid,i=e.data.payload.__success;if(t.pending[n]){if(delete e.data.payload.__reqid,delete e.data.payload.__success,i){var r=0===Object.keys(e.data.payload).length&&e.data.payload.constructor===Object?null:e.data.payload;t.pending[n].resolve(r)}else{var o=e.data.payload.error?e.data.type+": "+e.data.payload.error:e.data.type;t.pending[n].reject(o)}delete t.pending[n]}}}};d.prototype.request=function(e){var n=this,i=t();return new Promise(function(t,r){n.pending[i]={resolve:t,reject:r},e.payload.__reqid=i,n.port.postMessage(e)})};var c=function(e,t){var n=this;this.rdc=new d(e),this.preview={},Object.defineProperty(this.preview,"origin",{value:t.previewOrigin,writable:!1}),this.editor={openFile:function(e){return n.rdc.request({type:"SDK_OPEN_FILE",payload:{path:e}})}}};c.prototype.applyFsDiff=function(e){return this.rdc.request({type:"SDK_APPLY_FS_DIFF",payload:e})},c.prototype.getFsSnapshot=function(){return this.rdc.request({type:"SDK_GET_FS_SNAPSHOT",payload:{}})};var p=[],s=function(e){var n=this;this.id=t(),this.element=e,this.pending=new Promise(function(e,t){var i=function(t){t.data.action&&"SDK_INIT_SUCCESS"===t.data.action&&t.data.id===n.id&&(n.vm=new c(t.ports[0],t.data.payload),e(n.vm),o())},r=function(){n.element.contentWindow.postMessage({action:"SDK_INIT",id:n.id},"*")};function o(){window.clearInterval(d),window.removeEventListener("message",i)}window.addEventListener("message",i),r();var a=0,d=window.setInterval(function(){if(n.vm)o();else{if(a>=20)return o(),t("Timeout: Unable to establish a connection with the StackBlitz VM"),void p.forEach(function(e,t){e.id===n.id&&p.splice(t,1)});a++,r()}},500)}),p.push(this)},l=function(e){var t=e instanceof Element?"element":"id",n=p.find(function(n){return n[t]===e});return n||null},u=["typescript","create-react-app","angular-cli"];function h(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function f(e){if(-1===u.indexOf(e.template))throw new Error("Unsupported project template, must be one of: "+u.join(", "));var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(h("project[title]",e.title)),t.appendChild(h("project[description]",e.description)),t.appendChild(h("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(h("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(h("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(h("project[files]["+n+"]",e.files[n]))}),t}function m(e,t){var i=f(e);i.action="https://stackblitz.com/run"+n(t),i.id="sb";var r=document.createElement("iframe");return r.src="data:text/html;charset=utf-8,<html><head><title></title></head><body>"+encodeURI(i.outerHTML)+"<script>document.getElementById('sb').submit();<\/script></body></html>",r}function v(e,t){var i=f(e);i.action="https://stackblitz.com/run"+n(t),i.target=o(t),document.body.appendChild(i),i.submit(),document.body.removeChild(i)}var w={connect:function(e){if(!e||!e.contentWindow)return Promise.reject("Provided element is not an iframe.");var t=l(e);return t?t.pending:new s(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t),o(t))},openProject:function(e,t){v(e,t)},openProjectId:function(e,t){window.open("https://stackblitz.com/edit/"+e+n(t),o(t))},embedGithubProject:function(e,t,o){var a=r(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/github/"+t+n(o),i(a,d,o),w.connect(d)},embedProject:function(e,t,n){var o=r(e),a=m(t,n);return i(o,a,n),w.connect(a)},embedProjectId:function(e,t,o){var a=r(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/edit/"+t+n(o),i(a,d,o),w.connect(d)}};module.exports=w; | ||
var e="300";function t(){return Math.random().toString(36).substring(7)}function n(e){var t="";return e?(e.ctl&&(t+="ctl=1"),e.openFile&&(t+=(t.length?"&":"")+"file="+e.openFile),(e.view&&"preview"===e.view||"editor"===e.view)&&(t+=(t.length?"&":"")+"view="+e.view),t.length?"?"+t:t):t}function i(e,t,n){if(null===e.parentNode)throw new Error("Invalid Element");t.id=e.id,a(t,n),e.parentNode.replaceChild(t,e)}function r(e){if("string"==typeof e){var t=document.getElementById(e);if(null!==t)return t}else if(e instanceof HTMLElement)return e;throw new Error("Invalid Element")}function o(e){return e&&!1===e.newWindow?"_self":"_blank"}function a(t,n){n&&(n.hasOwnProperty("height")&&(t.height=""+n.height),n.hasOwnProperty("width")&&(t.width=""+n.width)),t.height||(t.height=e),t.width||t.setAttribute("style","width:100%;")}var d=function(e){var t=this;this.pending={},this.port=e,this.port.onmessage=function(e){if(e.data.payload.__reqid){var n=e.data.payload.__reqid,i=e.data.payload.__success;if(t.pending[n]){if(delete e.data.payload.__reqid,delete e.data.payload.__success,i){var r=0===Object.keys(e.data.payload).length&&e.data.payload.constructor===Object?null:e.data.payload;t.pending[n].resolve(r)}else{var o=e.data.payload.error?e.data.type+": "+e.data.payload.error:e.data.type;t.pending[n].reject(o)}delete t.pending[n]}}}};d.prototype.request=function(e){var n=this,i=t();return new Promise(function(t,r){n.pending[i]={resolve:t,reject:r},e.payload.__reqid=i,n.port.postMessage(e)})};var c=function(e,t){var n=this;this.rdc=new d(e),this.preview={},Object.defineProperty(this.preview,"origin",{value:t.previewOrigin,writable:!1}),this.editor={openFile:function(e){return n.rdc.request({type:"SDK_OPEN_FILE",payload:{path:e}})}}};c.prototype.applyFsDiff=function(e){return this.rdc.request({type:"SDK_APPLY_FS_DIFF",payload:e})},c.prototype.getFsSnapshot=function(){return this.rdc.request({type:"SDK_GET_FS_SNAPSHOT",payload:{}})};var p=[],s=function(e){var n=this;this.id=t(),this.element=e,this.pending=new Promise(function(e,t){var i=function(t){t.data.action&&"SDK_INIT_SUCCESS"===t.data.action&&t.data.id===n.id&&(n.vm=new c(t.ports[0],t.data.payload),e(n.vm),o())},r=function(){n.element.contentWindow.postMessage({action:"SDK_INIT",id:n.id},"*")};function o(){window.clearInterval(d),window.removeEventListener("message",i)}window.addEventListener("message",i),r();var a=0,d=window.setInterval(function(){if(n.vm)o();else{if(a>=20)return o(),t("Timeout: Unable to establish a connection with the StackBlitz VM"),void p.forEach(function(e,t){e.id===n.id&&p.splice(t,1)});a++,r()}},500)}),p.push(this)},l=function(e){var t=e instanceof Element?"element":"id",n=p.find(function(n){return n[t]===e});return n||null},u=["typescript","create-react-app","angular-cli"];function h(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function f(e){if(-1===u.indexOf(e.template))throw new Error("Unsupported project template, must be one of: "+u.join(", "));var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(h("project[title]",e.title)),t.appendChild(h("project[description]",e.description)),t.appendChild(h("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(h("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(h("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(h("project[files]["+n+"]",e.files[n]))}),t}function m(e,t){var i=f(e);return i.action="https://stackblitz.com/run"+n(t),i.id="sb","<html><head><title></title></head><body>"+i.outerHTML+"<script>document.getElementById('sb').submit();<\/script></body></html>"}function v(e,t){var i=f(e);i.action="https://stackblitz.com/run"+n(t),i.target=o(t),document.body.appendChild(i),i.submit(),document.body.removeChild(i)}var w={connect:function(e){if(!e||!e.contentWindow)return Promise.reject("Provided element is not an iframe.");var t=l(e);return t?t.pending:new s(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t),o(t))},openProject:function(e,t){v(e,t)},openProjectId:function(e,t){window.open("https://stackblitz.com/edit/"+e+n(t),o(t))},embedGithubProject:function(e,t,o){var a=r(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/github/"+t+n(o),i(a,d,o),w.connect(d)},embedProject:function(e,t,n){var o=r(e),a=m(t,n),d=document.createElement("iframe");return i(o,d,n),d.contentDocument.write(a),w.connect(d)},embedProjectId:function(e,t,o){var a=r(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/edit/"+t+n(o),i(a,d,o),w.connect(d)}};module.exports=w; | ||
//# sourceMappingURL=sdk.js.map |
@@ -1,2 +0,2 @@ | ||
var e="300";function t(){return Math.random().toString(36).substring(7)}function n(e){var t="";return e?(e.ctl&&(t+="ctl=1"),e.openFile&&(t+=(t.length?"&":"")+"file="+e.openFile),(e.view&&"preview"===e.view||"editor"===e.view)&&(t+=(t.length?"&":"")+"view="+e.view),t.length?"?"+t:t):t}function i(e,t,n){if(null===e.parentNode)throw new Error("Invalid Element");t.id=e.id,a(t,n),e.parentNode.replaceChild(t,e)}function r(e){if("string"==typeof e){var t=document.getElementById(e);if(null!==t)return t}else if(e instanceof HTMLElement)return e;throw new Error("Invalid Element")}function o(e){return e&&!1===e.newWindow?"_self":"_blank"}function a(t,n){n&&(n.hasOwnProperty("height")&&(t.height=""+n.height),n.hasOwnProperty("width")&&(t.width=""+n.width)),t.height||(t.height=e),t.width||t.setAttribute("style","width:100%;")}var d=function(e){var t=this;this.pending={},this.port=e,this.port.onmessage=function(e){if(e.data.payload.__reqid){var n=e.data.payload.__reqid,i=e.data.payload.__success;if(t.pending[n]){if(delete e.data.payload.__reqid,delete e.data.payload.__success,i){var r=0===Object.keys(e.data.payload).length&&e.data.payload.constructor===Object?null:e.data.payload;t.pending[n].resolve(r)}else{var o=e.data.payload.error?e.data.type+": "+e.data.payload.error:e.data.type;t.pending[n].reject(o)}delete t.pending[n]}}}};d.prototype.request=function(e){var n=this,i=t();return new Promise(function(t,r){n.pending[i]={resolve:t,reject:r},e.payload.__reqid=i,n.port.postMessage(e)})};var c=function(e,t){var n=this;this.rdc=new d(e),this.preview={},Object.defineProperty(this.preview,"origin",{value:t.previewOrigin,writable:!1}),this.editor={openFile:function(e){return n.rdc.request({type:"SDK_OPEN_FILE",payload:{path:e}})}}};c.prototype.applyFsDiff=function(e){return this.rdc.request({type:"SDK_APPLY_FS_DIFF",payload:e})},c.prototype.getFsSnapshot=function(){return this.rdc.request({type:"SDK_GET_FS_SNAPSHOT",payload:{}})};var p=[],s=function(e){var n=this;this.id=t(),this.element=e,this.pending=new Promise(function(e,t){var i=function(t){t.data.action&&"SDK_INIT_SUCCESS"===t.data.action&&t.data.id===n.id&&(n.vm=new c(t.ports[0],t.data.payload),e(n.vm),o())},r=function(){n.element.contentWindow.postMessage({action:"SDK_INIT",id:n.id},"*")};function o(){window.clearInterval(d),window.removeEventListener("message",i)}window.addEventListener("message",i),r();var a=0,d=window.setInterval(function(){if(n.vm)o();else{if(a>=20)return o(),t("Timeout: Unable to establish a connection with the StackBlitz VM"),void p.forEach(function(e,t){e.id===n.id&&p.splice(t,1)});a++,r()}},500)}),p.push(this)},l=function(e){var t=e instanceof Element?"element":"id",n=p.find(function(n){return n[t]===e});return n||null},u=["typescript","create-react-app","angular-cli"];function h(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function f(e){if(-1===u.indexOf(e.template))throw new Error("Unsupported project template, must be one of: "+u.join(", "));var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(h("project[title]",e.title)),t.appendChild(h("project[description]",e.description)),t.appendChild(h("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(h("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(h("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(h("project[files]["+n+"]",e.files[n]))}),t}function m(e,t){var i=f(e);i.action="https://stackblitz.com/run"+n(t),i.id="sb";var r=document.createElement("iframe");return r.src="data:text/html;charset=utf-8,<html><head><title></title></head><body>"+encodeURI(i.outerHTML)+"<script>document.getElementById('sb').submit();<\/script></body></html>",r}function v(e,t){var i=f(e);i.action="https://stackblitz.com/run"+n(t),i.target=o(t),document.body.appendChild(i),i.submit(),document.body.removeChild(i)}var w={connect:function(e){if(!e||!e.contentWindow)return Promise.reject("Provided element is not an iframe.");var t=l(e);return t?t.pending:new s(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t),o(t))},openProject:function(e,t){v(e,t)},openProjectId:function(e,t){window.open("https://stackblitz.com/edit/"+e+n(t),o(t))},embedGithubProject:function(e,t,o){var a=r(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/github/"+t+n(o),i(a,d,o),w.connect(d)},embedProject:function(e,t,n){var o=r(e),a=m(t,n);return i(o,a,n),w.connect(a)},embedProjectId:function(e,t,o){var a=r(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/edit/"+t+n(o),i(a,d,o),w.connect(d)}};export default w; | ||
var e="300";function t(){return Math.random().toString(36).substring(7)}function n(e){var t="";return e?(e.ctl&&(t+="ctl=1"),e.openFile&&(t+=(t.length?"&":"")+"file="+e.openFile),(e.view&&"preview"===e.view||"editor"===e.view)&&(t+=(t.length?"&":"")+"view="+e.view),t.length?"?"+t:t):t}function i(e,t,n){if(null===e.parentNode)throw new Error("Invalid Element");t.id=e.id,a(t,n),e.parentNode.replaceChild(t,e)}function r(e){if("string"==typeof e){var t=document.getElementById(e);if(null!==t)return t}else if(e instanceof HTMLElement)return e;throw new Error("Invalid Element")}function o(e){return e&&!1===e.newWindow?"_self":"_blank"}function a(t,n){n&&(n.hasOwnProperty("height")&&(t.height=""+n.height),n.hasOwnProperty("width")&&(t.width=""+n.width)),t.height||(t.height=e),t.width||t.setAttribute("style","width:100%;")}var d=function(e){var t=this;this.pending={},this.port=e,this.port.onmessage=function(e){if(e.data.payload.__reqid){var n=e.data.payload.__reqid,i=e.data.payload.__success;if(t.pending[n]){if(delete e.data.payload.__reqid,delete e.data.payload.__success,i){var r=0===Object.keys(e.data.payload).length&&e.data.payload.constructor===Object?null:e.data.payload;t.pending[n].resolve(r)}else{var o=e.data.payload.error?e.data.type+": "+e.data.payload.error:e.data.type;t.pending[n].reject(o)}delete t.pending[n]}}}};d.prototype.request=function(e){var n=this,i=t();return new Promise(function(t,r){n.pending[i]={resolve:t,reject:r},e.payload.__reqid=i,n.port.postMessage(e)})};var c=function(e,t){var n=this;this.rdc=new d(e),this.preview={},Object.defineProperty(this.preview,"origin",{value:t.previewOrigin,writable:!1}),this.editor={openFile:function(e){return n.rdc.request({type:"SDK_OPEN_FILE",payload:{path:e}})}}};c.prototype.applyFsDiff=function(e){return this.rdc.request({type:"SDK_APPLY_FS_DIFF",payload:e})},c.prototype.getFsSnapshot=function(){return this.rdc.request({type:"SDK_GET_FS_SNAPSHOT",payload:{}})};var p=[],s=function(e){var n=this;this.id=t(),this.element=e,this.pending=new Promise(function(e,t){var i=function(t){t.data.action&&"SDK_INIT_SUCCESS"===t.data.action&&t.data.id===n.id&&(n.vm=new c(t.ports[0],t.data.payload),e(n.vm),o())},r=function(){n.element.contentWindow.postMessage({action:"SDK_INIT",id:n.id},"*")};function o(){window.clearInterval(d),window.removeEventListener("message",i)}window.addEventListener("message",i),r();var a=0,d=window.setInterval(function(){if(n.vm)o();else{if(a>=20)return o(),t("Timeout: Unable to establish a connection with the StackBlitz VM"),void p.forEach(function(e,t){e.id===n.id&&p.splice(t,1)});a++,r()}},500)}),p.push(this)},l=function(e){var t=e instanceof Element?"element":"id",n=p.find(function(n){return n[t]===e});return n||null},u=["typescript","create-react-app","angular-cli"];function h(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function f(e){if(-1===u.indexOf(e.template))throw new Error("Unsupported project template, must be one of: "+u.join(", "));var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(h("project[title]",e.title)),t.appendChild(h("project[description]",e.description)),t.appendChild(h("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(h("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(h("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(h("project[files]["+n+"]",e.files[n]))}),t}function m(e,t){var i=f(e);return i.action="https://stackblitz.com/run"+n(t),i.id="sb","<html><head><title></title></head><body>"+i.outerHTML+"<script>document.getElementById('sb').submit();<\/script></body></html>"}function v(e,t){var i=f(e);i.action="https://stackblitz.com/run"+n(t),i.target=o(t),document.body.appendChild(i),i.submit(),document.body.removeChild(i)}var w={connect:function(e){if(!e||!e.contentWindow)return Promise.reject("Provided element is not an iframe.");var t=l(e);return t?t.pending:new s(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t),o(t))},openProject:function(e,t){v(e,t)},openProjectId:function(e,t){window.open("https://stackblitz.com/edit/"+e+n(t),o(t))},embedGithubProject:function(e,t,o){var a=r(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/github/"+t+n(o),i(a,d,o),w.connect(d)},embedProject:function(e,t,n){var o=r(e),a=m(t,n),d=document.createElement("iframe");return i(o,d,n),d.contentDocument.write(a),w.connect(d)},embedProjectId:function(e,t,o){var a=r(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/edit/"+t+n(o),i(a,d,o),w.connect(d)}};export default w; | ||
//# sourceMappingURL=sdk.m.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.StackBlitzSDK=t()}(this,function(){var e="300";function t(){return Math.random().toString(36).substring(7)}function n(e){var t="";return e?(e.ctl&&(t+="ctl=1"),e.openFile&&(t+=(t.length?"&":"")+"file="+e.openFile),(e.view&&"preview"===e.view||"editor"===e.view)&&(t+=(t.length?"&":"")+"view="+e.view),t.length?"?"+t:t):t}function i(t,n,i){if(null===t.parentNode)throw new Error("Invalid Element");n.id=t.id,function(t,n){n&&(n.hasOwnProperty("height")&&(t.height=""+n.height),n.hasOwnProperty("width")&&(t.width=""+n.width));t.height||(t.height=e);t.width||t.setAttribute("style","width:100%;")}(n,i),t.parentNode.replaceChild(n,t)}function r(e){if("string"==typeof e){var t=document.getElementById(e);if(null!==t)return t}else if(e instanceof HTMLElement)return e;throw new Error("Invalid Element")}function o(e){return e&&!1===e.newWindow?"_self":"_blank"}var a=function(e){var t=this;this.pending={},this.port=e,this.port.onmessage=function(e){if(e.data.payload.__reqid){var n=e.data.payload.__reqid,i=e.data.payload.__success;if(t.pending[n]){if(delete e.data.payload.__reqid,delete e.data.payload.__success,i){var r=0===Object.keys(e.data.payload).length&&e.data.payload.constructor===Object?null:e.data.payload;t.pending[n].resolve(r)}else{var o=e.data.payload.error?e.data.type+": "+e.data.payload.error:e.data.type;t.pending[n].reject(o)}delete t.pending[n]}}}};a.prototype.request=function(e){var n=this,i=t();return new Promise(function(t,r){n.pending[i]={resolve:t,reject:r},e.payload.__reqid=i,n.port.postMessage(e)})};var d=function(e,t){var n=this;this.rdc=new a(e),this.preview={},Object.defineProperty(this.preview,"origin",{value:t.previewOrigin,writable:!1}),this.editor={openFile:function(e){return n.rdc.request({type:"SDK_OPEN_FILE",payload:{path:e}})}}};d.prototype.applyFsDiff=function(e){return this.rdc.request({type:"SDK_APPLY_FS_DIFF",payload:e})},d.prototype.getFsSnapshot=function(){return this.rdc.request({type:"SDK_GET_FS_SNAPSHOT",payload:{}})};var c=[],p=["typescript","create-react-app","angular-cli"];function s(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function l(e){if(-1===p.indexOf(e.template))throw new Error("Unsupported project template, must be one of: "+p.join(", "));var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(s("project[title]",e.title)),t.appendChild(s("project[description]",e.description)),t.appendChild(s("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(s("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(s("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(s("project[files]["+n+"]",e.files[n]))}),t}var u={connect:function(e){if(!e||!e.contentWindow)return Promise.reject("Provided element is not an iframe.");var n,i,r=(i=(n=e)instanceof Element?"element":"id",c.find(function(e){return e[i]===n})||null);return r?r.pending:new function(e){var n=this;this.id=t(),this.element=e,this.pending=new Promise(function(e,t){var i=function(t){t.data.action&&"SDK_INIT_SUCCESS"===t.data.action&&t.data.id===n.id&&(n.vm=new d(t.ports[0],t.data.payload),e(n.vm),o())},r=function(){n.element.contentWindow.postMessage({action:"SDK_INIT",id:n.id},"*")};function o(){window.clearInterval(p),window.removeEventListener("message",i)}window.addEventListener("message",i),r();var a=0,p=window.setInterval(function(){if(n.vm)o();else{if(a>=20)return o(),t("Timeout: Unable to establish a connection with the StackBlitz VM"),void c.forEach(function(e,t){e.id===n.id&&c.splice(t,1)});a++,r()}},500)}),c.push(this)}(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t),o(t))},openProject:function(e,t){var i,r;i=t,(r=l(e)).action="https://stackblitz.com/run"+n(i),r.target=o(i),document.body.appendChild(r),r.submit(),document.body.removeChild(r)},openProjectId:function(e,t){window.open("https://stackblitz.com/edit/"+e+n(t),o(t))},embedGithubProject:function(e,t,o){var a=r(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/github/"+t+n(o),i(a,d,o),u.connect(d)},embedProject:function(e,t,o){var a=r(e),d=function(e,t){var i=l(e);i.action="https://stackblitz.com/run"+n(t),i.id="sb";var r=document.createElement("iframe");return r.src="data:text/html;charset=utf-8,<html><head><title></title></head><body>"+encodeURI(i.outerHTML)+"<script>document.getElementById('sb').submit();<\/script></body></html>",r}(t,o);return i(a,d,o),u.connect(d)},embedProjectId:function(e,t,o){var a=r(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/edit/"+t+n(o),i(a,d,o),u.connect(d)}};return u}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.StackBlitzSDK=t()}(this,function(){var e="300";function t(){return Math.random().toString(36).substring(7)}function n(e){var t="";return e?(e.ctl&&(t+="ctl=1"),e.openFile&&(t+=(t.length?"&":"")+"file="+e.openFile),(e.view&&"preview"===e.view||"editor"===e.view)&&(t+=(t.length?"&":"")+"view="+e.view),t.length?"?"+t:t):t}function i(t,n,i){if(null===t.parentNode)throw new Error("Invalid Element");n.id=t.id,function(t,n){n&&(n.hasOwnProperty("height")&&(t.height=""+n.height),n.hasOwnProperty("width")&&(t.width=""+n.width));t.height||(t.height=e);t.width||t.setAttribute("style","width:100%;")}(n,i),t.parentNode.replaceChild(n,t)}function o(e){if("string"==typeof e){var t=document.getElementById(e);if(null!==t)return t}else if(e instanceof HTMLElement)return e;throw new Error("Invalid Element")}function r(e){return e&&!1===e.newWindow?"_self":"_blank"}var a=function(e){var t=this;this.pending={},this.port=e,this.port.onmessage=function(e){if(e.data.payload.__reqid){var n=e.data.payload.__reqid,i=e.data.payload.__success;if(t.pending[n]){if(delete e.data.payload.__reqid,delete e.data.payload.__success,i){var o=0===Object.keys(e.data.payload).length&&e.data.payload.constructor===Object?null:e.data.payload;t.pending[n].resolve(o)}else{var r=e.data.payload.error?e.data.type+": "+e.data.payload.error:e.data.type;t.pending[n].reject(r)}delete t.pending[n]}}}};a.prototype.request=function(e){var n=this,i=t();return new Promise(function(t,o){n.pending[i]={resolve:t,reject:o},e.payload.__reqid=i,n.port.postMessage(e)})};var d=function(e,t){var n=this;this.rdc=new a(e),this.preview={},Object.defineProperty(this.preview,"origin",{value:t.previewOrigin,writable:!1}),this.editor={openFile:function(e){return n.rdc.request({type:"SDK_OPEN_FILE",payload:{path:e}})}}};d.prototype.applyFsDiff=function(e){return this.rdc.request({type:"SDK_APPLY_FS_DIFF",payload:e})},d.prototype.getFsSnapshot=function(){return this.rdc.request({type:"SDK_GET_FS_SNAPSHOT",payload:{}})};var c=[],p=["typescript","create-react-app","angular-cli"];function s(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function l(e){if(-1===p.indexOf(e.template))throw new Error("Unsupported project template, must be one of: "+p.join(", "));var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(s("project[title]",e.title)),t.appendChild(s("project[description]",e.description)),t.appendChild(s("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(s("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(s("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(s("project[files]["+n+"]",e.files[n]))}),t}var u={connect:function(e){if(!e||!e.contentWindow)return Promise.reject("Provided element is not an iframe.");var n,i,o=(i=(n=e)instanceof Element?"element":"id",c.find(function(e){return e[i]===n})||null);return o?o.pending:new function(e){var n=this;this.id=t(),this.element=e,this.pending=new Promise(function(e,t){var i=function(t){t.data.action&&"SDK_INIT_SUCCESS"===t.data.action&&t.data.id===n.id&&(n.vm=new d(t.ports[0],t.data.payload),e(n.vm),r())},o=function(){n.element.contentWindow.postMessage({action:"SDK_INIT",id:n.id},"*")};function r(){window.clearInterval(p),window.removeEventListener("message",i)}window.addEventListener("message",i),o();var a=0,p=window.setInterval(function(){if(n.vm)r();else{if(a>=20)return r(),t("Timeout: Unable to establish a connection with the StackBlitz VM"),void c.forEach(function(e,t){e.id===n.id&&c.splice(t,1)});a++,o()}},500)}),c.push(this)}(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t),r(t))},openProject:function(e,t){var i,o;i=t,(o=l(e)).action="https://stackblitz.com/run"+n(i),o.target=r(i),document.body.appendChild(o),o.submit(),document.body.removeChild(o)},openProjectId:function(e,t){window.open("https://stackblitz.com/edit/"+e+n(t),r(t))},embedGithubProject:function(e,t,r){var a=o(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/github/"+t+n(r),i(a,d,r),u.connect(d)},embedProject:function(e,t,r){var a,d,c=o(e),p=(a=r,(d=l(t)).action="https://stackblitz.com/run"+n(a),d.id="sb","<html><head><title></title></head><body>"+d.outerHTML+"<script>document.getElementById('sb').submit();<\/script></body></html>"),s=document.createElement("iframe");return i(c,s,r),s.contentDocument.write(p),u.connect(s)},embedProjectId:function(e,t,r){var a=o(e),d=document.createElement("iframe");return d.src="https://stackblitz.com/edit/"+t+n(r),i(a,d,r),u.connect(d)}};return u}); | ||
//# sourceMappingURL=sdk.umd.js.map |
{ | ||
"name": "@stackblitz/sdk", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./bundles/sdk.js", |
@@ -5,4 +5,4 @@ import { VM } from './VM'; | ||
id: string; | ||
pending: Promise<VM> | null; | ||
vm: VM | null; | ||
pending: Promise<VM>; | ||
vm: VM; | ||
} | ||
@@ -9,0 +9,0 @@ export interface RequestData { |
import { Project, EmbedOptions, OpenOptions } from './interfaces'; | ||
export declare function createProjectFrame(project: Project, options?: EmbedOptions): HTMLIFrameElement; | ||
export declare function createProjectBlank(project: Project, options?: OpenOptions): void; | ||
export declare function createProjectFrameHTML(project: Project, options?: EmbedOptions): string; | ||
export declare function openProject(project: Project, options?: OpenOptions): void; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18
163
19075