@stackblitz/sdk
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -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"Invalid Element";t.id=e.id,o(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"Invalid Element"}function o(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 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=[],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 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(s),window.removeEventListener("message",i)}window.addEventListener("message",i),r();var a=0,s=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)},p=function(e){var t=e instanceof Element?"element":"id",n=c.find(function(n){return n[t]===e});return n||null};function l(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function u(e){var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(l("project[title]",e.title)),t.appendChild(l("project[description]",e.description)),t.appendChild(l("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(l("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(l("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(l("project[files]["+n+"]",e.files[n]))}),t}function h(e,t){var i=document.createElement("iframe"),r=u(e);return r.id="sb",r.action="https://stackblitz.com/run"+n(t),i.src="data:text/html;charset=utf-8,<html><head><title></title></head><body>"+encodeURI(r.outerHTML)+"<script>document.getElementById('sb').submit();<\/script></body></html>",i}function f(e,t){document.createElement("iframe");var i=u(e);i.action="https://stackblitz.com/run"+n(t),i.target="_blank",document.body.appendChild(i),i.submit(),document.body.removeChild(i)}var m={connect:function(e){if(!e||!e.contentWindow)return Promise.reject("Provided element is not an iframe.");var t=p(e);return t?t.pending:new s(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t))},openProject:function(e,t){f(e,t)},openProjectId:function(e,t){window.open("https://stackblitz.com/edit/"+e+n(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),m.connect(d)},embedProject:function(e,t,n){var o=r(e),a=h(t,n);return i(o,a,n),m.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),m.connect(d)}};module.exports=m; | ||
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"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"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 s=[],p=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 s.forEach(function(e,t){e.id===n.id&&s.splice(t,1)});a++,r()}},500)}),s.push(this)},l=function(e){var t=e instanceof Element?"element":"id",n=s.find(function(n){return n[t]===e});return n||null};function u(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function h(e){var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(u("project[title]",e.title)),t.appendChild(u("project[description]",e.description)),t.appendChild(u("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(u("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(u("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(u("project[files]["+n+"]",e.files[n]))}),t}function f(e,t){var i=document.createElement("iframe"),r=h(e);return r.id="sb",r.action="https://stackblitz.com/run"+n(t),i.src="data:text/html;charset=utf-8,<html><head><title></title></head><body>"+encodeURI(r.outerHTML)+"<script>document.getElementById('sb').submit();<\/script></body></html>",i}function m(e,t){document.createElement("iframe");var i=h(e);i.action="https://stackblitz.com/run"+n(t),i.target=o(t),document.body.appendChild(i),i.submit(),document.body.removeChild(i)}var v={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 p(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t),o(t))},openProject:function(e,t){m(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),v.connect(d)},embedProject:function(e,t,n){var o=r(e),a=f(t,n);return i(o,a,n),v.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),v.connect(d)}};module.exports=v; | ||
//# 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"Invalid Element";t.id=e.id,o(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"Invalid Element"}function o(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 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=[],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 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(s),window.removeEventListener("message",i)}window.addEventListener("message",i),r();var a=0,s=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)},p=function(e){var t=e instanceof Element?"element":"id",n=c.find(function(n){return n[t]===e});return n||null};function l(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function u(e){var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(l("project[title]",e.title)),t.appendChild(l("project[description]",e.description)),t.appendChild(l("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(l("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(l("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(l("project[files]["+n+"]",e.files[n]))}),t}function h(e,t){var i=document.createElement("iframe"),r=u(e);return r.id="sb",r.action="https://stackblitz.com/run"+n(t),i.src="data:text/html;charset=utf-8,<html><head><title></title></head><body>"+encodeURI(r.outerHTML)+"<script>document.getElementById('sb').submit();<\/script></body></html>",i}function f(e,t){document.createElement("iframe");var i=u(e);i.action="https://stackblitz.com/run"+n(t),i.target="_blank",document.body.appendChild(i),i.submit(),document.body.removeChild(i)}var m={connect:function(e){if(!e||!e.contentWindow)return Promise.reject("Provided element is not an iframe.");var t=p(e);return t?t.pending:new s(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t))},openProject:function(e,t){f(e,t)},openProjectId:function(e,t){window.open("https://stackblitz.com/edit/"+e+n(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),m.connect(d)},embedProject:function(e,t,n){var o=r(e),a=h(t,n);return i(o,a,n),m.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),m.connect(d)}};export default m; | ||
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"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"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 s=[],p=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 s.forEach(function(e,t){e.id===n.id&&s.splice(t,1)});a++,r()}},500)}),s.push(this)},l=function(e){var t=e instanceof Element?"element":"id",n=s.find(function(n){return n[t]===e});return n||null};function u(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function h(e){var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(u("project[title]",e.title)),t.appendChild(u("project[description]",e.description)),t.appendChild(u("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(u("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(u("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(u("project[files]["+n+"]",e.files[n]))}),t}function f(e,t){var i=document.createElement("iframe"),r=h(e);return r.id="sb",r.action="https://stackblitz.com/run"+n(t),i.src="data:text/html;charset=utf-8,<html><head><title></title></head><body>"+encodeURI(r.outerHTML)+"<script>document.getElementById('sb').submit();<\/script></body></html>",i}function m(e,t){document.createElement("iframe");var i=h(e);i.action="https://stackblitz.com/run"+n(t),i.target=o(t),document.body.appendChild(i),i.submit(),document.body.removeChild(i)}var v={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 p(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t),o(t))},openProject:function(e,t){m(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),v.connect(d)},embedProject:function(e,t,n){var o=r(e),a=f(t,n);return i(o,a,n),v.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),v.connect(d)}};export default v; | ||
//# 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"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"Invalid Element"}var r=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]}}}};r.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 a=function(e,t){var n=this;this.rdc=new r(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}})}}};a.prototype.applyFsDiff=function(e){return this.rdc.request({type:"SDK_APPLY_FS_DIFF",payload:e})},a.prototype.getFsSnapshot=function(){return this.rdc.request({type:"SDK_GET_FS_SNAPSHOT",payload:{}})};var d=[];function c(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function s(e){var t=document.createElement("form");return t.method="POST",t.setAttribute("style","display:none;"),t.appendChild(c("project[title]",e.title)),t.appendChild(c("project[description]",e.description)),t.appendChild(c("project[template]",e.template)),e.tags&&e.tags.forEach(function(e,n){t.appendChild(c("project[tags]["+n+"]",e))}),e.dependencies&&t.appendChild(c("project[dependencies]",JSON.stringify(e.dependencies))),Object.keys(e.files).forEach(function(n){t.appendChild(c("project[files]["+n+"]",e.files[n]))}),t}var p={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",d.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 a(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(s),window.removeEventListener("message",i)}window.addEventListener("message",i),o();var c=0,s=window.setInterval(function(){if(n.vm)r();else{if(c>=20)return r(),t("Timeout: Unable to establish a connection with the StackBlitz VM"),void d.forEach(function(e,t){e.id===n.id&&d.splice(t,1)});c++,o()}},500)}),d.push(this)}(e).pending},openGithubProject:function(e,t){window.open("https://stackblitz.com/github/"+e+n(t))},openProject:function(e,t){!function(e,t){document.createElement("iframe");var i=s(e);i.action="https://stackblitz.com/run"+n(t),i.target="_blank",document.body.appendChild(i),i.submit(),document.body.removeChild(i)}(e,t)},openProjectId:function(e,t){window.open("https://stackblitz.com/edit/"+e+n(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),p.connect(d)},embedProject:function(e,t,r){var a,d,c,l,u=o(e),h=(a=t,d=r,c=document.createElement("iframe"),(l=s(a)).id="sb",l.action="https://stackblitz.com/run"+n(d),c.src="data:text/html;charset=utf-8,<html><head><title></title></head><body>"+encodeURI(l.outerHTML)+"<script>document.getElementById('sb').submit();<\/script></body></html>",c);return i(u,h,r),p.connect(h)},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),p.connect(d)}};return p}); | ||
!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"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"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=[];function s(e,t){var n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}function p(e){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 l={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(s),window.removeEventListener("message",i)}window.addEventListener("message",i),o();var a=0,s=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){!function(e,t){document.createElement("iframe");var i=p(e);i.action="https://stackblitz.com/run"+n(t),i.target=r(t),document.body.appendChild(i),i.submit(),document.body.removeChild(i)}(e,t)},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),l.connect(d)},embedProject:function(e,t,r){var a,d,c,s,u=o(e),h=(a=t,d=r,c=document.createElement("iframe"),(s=p(a)).id="sb",s.action="https://stackblitz.com/run"+n(d),c.src="data:text/html;charset=utf-8,<html><head><title></title></head><body>"+encodeURI(s.outerHTML)+"<script>document.getElementById('sb').submit();<\/script></body></html>",c);return i(u,h,r),l.connect(h)},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),l.connect(d)}};return l}); | ||
//# sourceMappingURL=sdk.umd.js.map |
{ | ||
"name": "@stackblitz/sdk", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"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 { |
@@ -1,3 +0,3 @@ | ||
import { Project, EmbedOptions, ProjectOptions } from './interfaces'; | ||
import { Project, EmbedOptions, OpenOptions } from './interfaces'; | ||
export declare function createProjectFrame(project: Project, options?: EmbedOptions): HTMLIFrameElement; | ||
export declare function createProjectBlank(project: Project, options?: ProjectOptions): void; | ||
export declare function createProjectBlank(project: Project, options?: OpenOptions): void; |
@@ -1,2 +0,2 @@ | ||
import { EmbedOptions } from './interfaces'; | ||
import { EmbedOptions, OpenOptions } from './interfaces'; | ||
export declare function genID(): string; | ||
@@ -6,1 +6,2 @@ export declare function buildProjectQuery(options?: EmbedOptions): string; | ||
export declare function elementFromElementOrId(elementOrId: string | HTMLElement): HTMLElement; | ||
export declare function openTarget(options?: OpenOptions): "_self" | "_blank"; |
import { VM } from './VM'; | ||
import { Project, ProjectOptions, EmbedOptions } from './interfaces'; | ||
import { Project, OpenOptions, EmbedOptions } from './interfaces'; | ||
declare const StackBlitzSDK: { | ||
connect: (frameEl: HTMLIFrameElement) => Promise<VM>; | ||
openGithubProject: (repoSlug: string, options?: ProjectOptions | undefined) => void; | ||
openProject: (project: Project, options?: ProjectOptions | undefined) => void; | ||
openProjectId: (projectId: string, options?: ProjectOptions | undefined) => void; | ||
openGithubProject: (repoSlug: string, options?: OpenOptions | undefined) => void; | ||
openProject: (project: Project, options?: OpenOptions | undefined) => void; | ||
openProjectId: (projectId: string, options?: OpenOptions | undefined) => void; | ||
embedGithubProject: (elementOrId: string | HTMLElement, repoSlug: string, options?: EmbedOptions | undefined) => Promise<VM>; | ||
@@ -9,0 +9,0 @@ embedProject: (elementOrId: string | HTMLElement, project: Project, options?: EmbedOptions | undefined) => Promise<VM>; |
@@ -23,2 +23,5 @@ export interface RequestData { | ||
} | ||
export interface OpenOptions extends ProjectOptions { | ||
newWindow?: boolean; | ||
} | ||
export interface EmbedOptions extends ProjectOptions { | ||
@@ -25,0 +28,0 @@ ctl?: boolean; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
18705
18
161
1