@chili-publish/publisher-interface
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
var e,t,r,n,i,o,s,c,a,d,u,l,h={};e=h,t="PublisherInterface",r=()=>V,n=e=>V=e,Object.defineProperty(e,t,{get:r,set:n,enumerable:!0,configurable:!0}),(o=i||(i={})).Call="call",o.Reply="reply",o.Syn="syn",o.SynAck="synAck",o.Ack="ack",(c=s||(s={})).Fulfilled="fulfilled",c.Rejected="rejected",(d=a||(a={})).ConnectionDestroyed="ConnectionDestroyed",d.ConnectionTimeout="ConnectionTimeout",d.NoIframeSrc="NoIframeSrc",(u||(u={})).DataCloneError="DataCloneError",(l||(l={})).Message="message";var g=(e,t)=>{const r=[];let n=!1;return{destroy(i){n||(n=!0,t(`${e}: Destroying connection`),r.forEach((e=>{e(i)})))},onDestroy(e){n?e():r.push(e)}}},f=e=>(...t)=>{e&&console.log("[Penpal]",...t)};const m={"http:":"80","https:":"443"},b=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,v=["file:","data:"];var w=e=>{if(e&&v.find((t=>e.startsWith(t))))return"null";const t=document.location,r=b.exec(e);let n,i,o;r?(n=r[1]?r[1]:t.protocol,i=r[2],o=r[4]):(n=t.protocol,i=t.hostname,o=t.port);return`${n}//${i}${o&&o!==m[n]?`:${o}`:""}`};const E=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),p=e=>{const t=new Error;return Object.keys(e).forEach((r=>t[r]=e[r])),t};var y=(e,t,r)=>{const{localName:n,local:o,remote:c,originForSending:a,originForReceiving:d}=e;let h=!1;const g=e=>{if(e.source!==c||e.data.penpal!==i.Call)return;if("*"!==d&&e.origin!==d)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${d}`);const o=e.data,{methodName:l,args:g,id:f}=o;r(`${n}: Received ${l}() call`);const m=e=>t=>{if(r(`${n}: Sending ${l}() reply`),h)return void r(`${n}: Unable to send ${l}() reply due to destroyed connection`);const o={penpal:i.Reply,id:f,resolution:e,returnValue:t};e===s.Rejected&&t instanceof Error&&(o.returnValue=E(t),o.returnValueIsError=!0);try{c.postMessage(o,a)}catch(e){if(e.name===u.DataCloneError){const t={penpal:i.Reply,id:f,resolution:s.Rejected,returnValue:E(e),returnValueIsError:!0};c.postMessage(t,a)}throw e}};new Promise((e=>e(t[l].apply(t,g)))).then(m(s.Fulfilled),m(s.Rejected))};return o.addEventListener(l.Message,g),()=>{h=!0,o.removeEventListener(l.Message,g)}};let S=0;const P=e=>e?e.split("."):[],L=(e,t,r)=>{const n=P(t);return n.reduce(((e,t,i)=>(void 0===e[t]&&(e[t]={}),i===n.length-1&&(e[t]=r),e[t])),e),e},j=(e,t)=>{const r={};return Object.keys(e).forEach((n=>{const i=e[n],o=((e,t)=>{const r=P(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof i&&Object.assign(r,j(i,o)),"function"==typeof i&&(r[o]=i)})),r},N=e=>{const t={};for(const r in e)L(t,r,e[r]);return t};var F=(e,t,r,n,o)=>{const{localName:c,local:d,remote:u,originForSending:h,originForReceiving:g}=t;let f=!1;o(`${c}: Connecting call sender`);const m=e=>(...t)=>{let r;o(`${c}: Sending ${e}() call`);try{u.closed&&(r=!0)}catch(e){r=!0}if(r&&n(),f){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=a.ConnectionDestroyed,t}return new Promise(((r,n)=>{const a=++S,f=t=>{if(t.source!==u||t.data.penpal!==i.Reply||t.data.id!==a)return;if("*"!==g&&t.origin!==g)return void o(`${c} received message from origin ${t.origin} which did not match expected origin ${g}`);const h=t.data;o(`${c}: Received ${e}() reply`),d.removeEventListener(l.Message,f);let m=h.returnValue;h.returnValueIsError&&(m=p(m)),(h.resolution===s.Fulfilled?r:n)(m)};d.addEventListener(l.Message,f);const m={penpal:i.Call,id:a,methodName:e,args:t};u.postMessage(m,h)}))},b=r.reduce(((e,t)=>(e[t]=m(t),e)),{});return Object.assign(e,N(b)),()=>{f=!0}},D=(e,t,r,n,i)=>{const{destroy:o,onDestroy:s}=n;let c,a;const d={};return n=>{if("*"!==t&&n.origin!==t)return void i(`Parent: Handshake - Received ACK message from origin ${n.origin} which did not match expected origin ${t}`);i("Parent: Handshake - Received ACK");const u={localName:"Parent",local:window,remote:n.source,originForSending:r,originForReceiving:t};c&&c(),c=y(u,e,i),s(c),a&&a.forEach((e=>{delete d[e]})),a=n.data.methodNames;const l=F(d,u,a,o,i);return s(l),d}},A=(e,t,r,n)=>o=>{if(!o.source)return;if("*"!==r&&o.origin!==r)return void e(`Parent: Handshake - Received SYN message from origin ${o.origin} which did not match expected origin ${r}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:i.SynAck,methodNames:Object.keys(t)};o.source.postMessage(s,n)};var I=(e,t)=>{const{destroy:r,onDestroy:n}=t,i=setInterval((()=>{e.isConnected||(clearInterval(i),r())}),6e4);n((()=>{clearInterval(i)}))},k=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout((()=>{const r=new Error(`Connection timed out after ${e}ms`);r.code=a.ConnectionTimeout,t(r)}),e)),()=>{clearTimeout(r)}},$=e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=a.NoIframeSrc,e}},C=e=>{let{iframe:t,methods:r={},childOrigin:n,timeout:o,debug:s=!1}=e;const c=f(s),a=g("Parent",c),{onDestroy:d,destroy:u}=a;n||($(t),n=w(t.src));const h="null"===n?"*":n,m=j(r),b=A(c,m,n,h),v=D(m,n,h,a,c);return{promise:new Promise(((e,r)=>{const n=k(o,u),s=r=>{if(r.source===t.contentWindow&&r.data)if(r.data.penpal!==i.Syn)if(r.data.penpal!==i.Ack);else{const t=v(r);t&&(n(),e(t))}else b(r)};window.addEventListener(l.Message,s),c("Parent: Awaiting handshake"),I(t,a),d((e=>{window.removeEventListener(l.Message,s),e&&r(e)}))})),destroy(){u()}}};var O,R=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))},x=function(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)},M=function(e,t,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?i.call(e,r):i?i.value=r:t.set(e,r),r};const T=function(e,t){return{register:function(r,n){return R(this,void 0,void 0,(function*(){t({functionName:"registerFunction()"});const i=yield e.registerFunction(r,n);if(i.isError)throw new Error(i.error)}))},registerOnEvent:function(r,n){return R(this,void 0,void 0,(function*(){t({functionName:"registerFunction()"});const i=yield e.registerFunctionOnEvent(r,n);if(i.isError)throw new Error(i.error)}))},execute:function(r,...n){return R(this,void 0,void 0,(function*(){t({functionName:"executeRegisteredFunction()"});const i=yield e.executeRegisteredFunction(r,n);if(i.isError)throw new Error(i.error);return i.ok}))}}};class V{constructor(){this.customFunction={register:function(e,t){throw new Error("Function not implemented.")},registerOnEvent:function(e,t){throw new Error("Function not implemented.")},execute:function(e,t){throw new Error("Function not implemented.")}},this.chiliEventListenerCallbacks=new Map,this.debug=!1,this.creationTime="",O.set(this,null),this.getProperty=this.getObject}static buildWithIframe(e,t){return R(this,void 0,void 0,(function*(){return V.build(Object.assign({targetIframe:e},t))}))}static buildOnElement(e,t,r){return R(this,void 0,void 0,(function*(){return V.build(Object.assign({parentElement:e,editorURL:t},r))}))}static build(e){var t,r,n,i;return R(this,arguments,void 0,(function*(){if("IFRAME"==arguments[0].tagName){const n=null!==(t=arguments[1])&&void 0!==t?t:{};e=Object.assign(Object.assign({},n),{targetIframe:arguments[0],debug:null!==(r=e.debug)&&void 0!==r?r:n.penpalDebug})}const o=new V;o.creationTime=(new Date).toLocaleString(),o.debug=null!==(n=e.debug)&&void 0!==n&&n,o.createDebugLog({functionName:"build()",customMessage:"Calling build() with options: "+JSON.stringify(e)});const s=null!==(i=e.targetIframe)&&void 0!==i?i:document.createElement("iframe");o.iframe=s,null!=e.editorURL&&(s.src=e.editorURL);const c=C({iframe:s,methods:{handleEvents:o.handleEvents.bind(o)},timeout:e.timeout,debug:e.debug});null!=e.parentElement&&e.parentElement.appendChild(s),o.child=yield c.promise,o.customFunction=T(o.child,o.createDebugLog.bind(o));const a=e.events;if(null!=a&&a.length>0)for(const e of a)"string"==typeof e?o.addListener(e):o.addListener(e.name,e.func);return o}))}handleEvents(e,t){var r;return this.chiliEventListenerCallbacks.has(e)&&(null===(r=this.chiliEventListenerCallbacks.get(e))||void 0===r||r(t)),e}createDebugLog({functionName:e,customMessage:t}){this.debug&&(null!=t?console.log(`[PublisherInterface - ${this.creationTime}]`,`${e} : ${t}`):console.log(`[PublisherInterface - ${this.creationTime}]`,`Creating ${e} call request`))}get editorObject(){return null==x(this,O,"f")&&M(this,O,{Alert:this.alert.bind(this),GetDirtyState:this.getDirtyState.bind(this),NextPage:this.nextPage.bind(this),PreviousPage:this.previousPage.bind(this),SetSelectedPage:this.setSelectedPage.bind(this),GetSelectedPage:this.getSelectedPage.bind(this),GetSelectedPageName:this.getSelectedPageName.bind(this),GetNumPages:this.getNumPages.bind(this),RemoveListener:this.removeListener.bind(this),AddListener:this.addListener.bind(this),GetObject:this.getObject.bind(this),SetProperty:this.setProperty.bind(this),ExecuteFunction:this.executeFunction.bind(this),GetPageSnapshot:this.getPageSnapshot.bind(this),GetFrameSnapshot:this.getFrameSnapshot.bind(this),GetFrameSubjectArea:this.getFrameSubjectArea.bind(this),SetFrameSubjectArea:this.setFrameSubjectArea.bind(this),ClearFrameSubjectArea:this.clearFrameSubjectArea.bind(this),GetAssetSubjectInfo:this.getAssetSubjectInfo.bind(this),SetAssetSubjectInfo:this.setAssetSubjectInfo.bind(this),ClearAssetSubjectInfo:this.clearAssetSubjectInfo.bind(this),SetVariableIsLocked:this.setVariableIsLocked.bind(this)},"f"),x(this,O,"f")}alert(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"alert()"});const r=yield this.child.alert(e,t);if(r.isError)throw new Error(r.error)}))}getDirtyState(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getDirtyState()"});const e=yield this.child.getDirtyState();if(e.isError)throw new Error(e.error);return e.ok}))}nextPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"nextPage()"});const e=yield this.child.nextPage();if(e.isError)throw new Error(e.error)}))}previousPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"previousPage()"});const e=yield this.child.previousPage();if(e.isError)throw new Error(e.error)}))}setSelectedPage(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setSelectedPage()"});const t=yield this.child.setSelectedPage(e);if(t.isError)throw new Error(t.error)}))}getSelectedPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getSelectedPage()"});const e=yield this.child.getSelectedPage();if(e.isError)throw new Error(e.error);return e.ok}))}getSelectedPageName(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getSelectedPageName()"});const e=yield this.child.getSelectedPageName();if(e.isError)throw new Error(e.error);return e.ok}))}getNumPages(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getNumPages()"});const e=yield this.child.getNumPages();if(e.isError)throw new Error(e.error);return e.ok}))}removeListener(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"removeListener()"}),this.chiliEventListenerCallbacks.delete(e);const t=yield this.child.removeListener(e);if(t.isError)throw new Error(t.error)}))}addListener(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"addListener()"}),this.chiliEventListenerCallbacks.set(e,null==t?t=>{null!=window.OnEditorEvent&&window.OnEditorEvent(e,t)}:t);const r=yield this.child.addListener(e);if(r.isError)throw new Error(r.error)}))}getObject(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getObject()"});const t=yield this.child.getObject(e);if(t.isError)throw new Error(t.error);return t.ok}))}setProperty(e,t,r){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setProperty()"});const n=yield this.child.setProperty(e,t,r);if(n.isError)throw new Error(n.error)}))}executeFunction(e,t,...r){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"executeFunction()"});const n=yield this.child.executeFunction(e,t,r);if(n.isError)throw new Error(n.error);return n.ok}))}getPageSnapshot(e,t,r,n,i,o){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getPageSnapshot()"});const s=yield this.child.getPageSnapshot(e,t,r,n,i,o);if(s.isError)throw new Error(s.error);return s.ok}))}getFrameSnapshot(e,t,r){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getFrameSnapshot()"});const n=yield this.child.getFrameSnapshot(e,t,r);if(n.isError)throw new Error(n.error);return n.ok}))}getFrameSubjectArea(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getFrameSubjectArea()"});const t=yield this.child.getFrameSubjectArea(e);if(t.isError)throw new Error(t.error);return t.ok}))}setFrameSubjectArea(e,t,r,n,i){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setFrameSubjectArea()"});const o=yield this.child.setFrameSubjectArea(e,t,r,n,i);if(o.isError)throw new Error(o.error)}))}clearFrameSubjectArea(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"clearFrameSubjectArea()"});const t=yield this.child.clearFrameSubjectArea(e);if(t.isError)throw new Error(t.error)}))}getAssetSubjectInfo(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getAssetSubjectInfo()"});const t=yield this.child.getAssetSubjectInfo(e);if(t.isError)throw new Error(t.error);return t.ok}))}setAssetSubjectInfo(e,t,r,n,i,o,s){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setAssetSubjectInfo()"});const c=yield this.child.setAssetSubjectInfo(e,t,r,n,i,o,s);if(c.isError)throw new Error(c.error)}))}clearAssetSubjectInfo(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"clearAssetSubjectInfo()"});const t=yield this.child.clearAssetSubjectInfo(e);if(t.isError)throw new Error(t.error)}))}setVariableIsLocked(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setVariableIsLocked()"});const r=yield this.child.setVariableIsLocked(e,t);if(r.isError)throw new Error(r.error)}))}}O=new WeakMap;export{V as PublisherInterface,h as default}; | ||
var e,t,r,n,i,o,s,c,a,u,d,l,h={};e=h,t="PublisherInterface",r=()=>V,n=e=>V=e,Object.defineProperty(e,t,{get:r,set:n,enumerable:!0,configurable:!0}),(o=i||(i={})).Call="call",o.Reply="reply",o.Syn="syn",o.SynAck="synAck",o.Ack="ack",(c=s||(s={})).Fulfilled="fulfilled",c.Rejected="rejected",(u=a||(a={})).ConnectionDestroyed="ConnectionDestroyed",u.ConnectionTimeout="ConnectionTimeout",u.NoIframeSrc="NoIframeSrc",(d||(d={})).DataCloneError="DataCloneError",(l||(l={})).Message="message";var g=(e,t)=>{const r=[];let n=!1;return{destroy(i){n||(n=!0,t(`${e}: Destroying connection`),r.forEach((e=>{e(i)})))},onDestroy(e){n?e():r.push(e)}}},f=e=>(...t)=>{e&&console.log("[Penpal]",...t)};const m={"http:":"80","https:":"443"},b=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,v=["file:","data:"];var w=e=>{if(e&&v.find((t=>e.startsWith(t))))return"null";const t=document.location,r=b.exec(e);let n,i,o;r?(n=r[1]?r[1]:t.protocol,i=r[2],o=r[4]):(n=t.protocol,i=t.hostname,o=t.port);return`${n}//${i}${o&&o!==m[n]?`:${o}`:""}`};const E=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),p=e=>{const t=new Error;return Object.keys(e).forEach((r=>t[r]=e[r])),t};var y=(e,t,r)=>{const{localName:n,local:o,remote:c,originForSending:a,originForReceiving:u}=e;let h=!1;const g=e=>{if(e.source!==c||e.data.penpal!==i.Call)return;if("*"!==u&&e.origin!==u)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${u}`);const o=e.data,{methodName:l,args:g,id:f}=o;r(`${n}: Received ${l}() call`);const m=e=>t=>{if(r(`${n}: Sending ${l}() reply`),h)return void r(`${n}: Unable to send ${l}() reply due to destroyed connection`);const o={penpal:i.Reply,id:f,resolution:e,returnValue:t};e===s.Rejected&&t instanceof Error&&(o.returnValue=E(t),o.returnValueIsError=!0);try{c.postMessage(o,a)}catch(e){if(e.name===d.DataCloneError){const t={penpal:i.Reply,id:f,resolution:s.Rejected,returnValue:E(e),returnValueIsError:!0};c.postMessage(t,a)}throw e}};new Promise((e=>e(t[l].apply(t,g)))).then(m(s.Fulfilled),m(s.Rejected))};return o.addEventListener(l.Message,g),()=>{h=!0,o.removeEventListener(l.Message,g)}};let S=0;const P=e=>e?e.split("."):[],L=(e,t,r)=>{const n=P(t);return n.reduce(((e,t,i)=>(void 0===e[t]&&(e[t]={}),i===n.length-1&&(e[t]=r),e[t])),e),e},j=(e,t)=>{const r={};return Object.keys(e).forEach((n=>{const i=e[n],o=((e,t)=>{const r=P(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof i&&Object.assign(r,j(i,o)),"function"==typeof i&&(r[o]=i)})),r},N=e=>{const t={};for(const r in e)L(t,r,e[r]);return t};var F=(e,t,r,n,o)=>{const{localName:c,local:u,remote:d,originForSending:h,originForReceiving:g}=t;let f=!1;o(`${c}: Connecting call sender`);const m=e=>(...t)=>{let r;o(`${c}: Sending ${e}() call`);try{d.closed&&(r=!0)}catch(e){r=!0}if(r&&n(),f){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=a.ConnectionDestroyed,t}return new Promise(((r,n)=>{const a=++S,f=t=>{if(t.source!==d||t.data.penpal!==i.Reply||t.data.id!==a)return;if("*"!==g&&t.origin!==g)return void o(`${c} received message from origin ${t.origin} which did not match expected origin ${g}`);const h=t.data;o(`${c}: Received ${e}() reply`),u.removeEventListener(l.Message,f);let m=h.returnValue;h.returnValueIsError&&(m=p(m)),(h.resolution===s.Fulfilled?r:n)(m)};u.addEventListener(l.Message,f);const m={penpal:i.Call,id:a,methodName:e,args:t};d.postMessage(m,h)}))},b=r.reduce(((e,t)=>(e[t]=m(t),e)),{});return Object.assign(e,N(b)),()=>{f=!0}},D=(e,t,r,n,i)=>{const{destroy:o,onDestroy:s}=n;let c,a;const u={};return n=>{if("*"!==t&&n.origin!==t)return void i(`Parent: Handshake - Received ACK message from origin ${n.origin} which did not match expected origin ${t}`);i("Parent: Handshake - Received ACK");const d={localName:"Parent",local:window,remote:n.source,originForSending:r,originForReceiving:t};c&&c(),c=y(d,e,i),s(c),a&&a.forEach((e=>{delete u[e]})),a=n.data.methodNames;const l=F(u,d,a,o,i);return s(l),u}},A=(e,t,r,n)=>o=>{if(!o.source)return;if("*"!==r&&o.origin!==r)return void e(`Parent: Handshake - Received SYN message from origin ${o.origin} which did not match expected origin ${r}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:i.SynAck,methodNames:Object.keys(t)};o.source.postMessage(s,n)};var I=(e,t)=>{const{destroy:r,onDestroy:n}=t,i=setInterval((()=>{e.isConnected||(clearInterval(i),r())}),6e4);n((()=>{clearInterval(i)}))},k=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout((()=>{const r=new Error(`Connection timed out after ${e}ms`);r.code=a.ConnectionTimeout,t(r)}),e)),()=>{clearTimeout(r)}},$=e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=a.NoIframeSrc,e}},C=e=>{let{iframe:t,methods:r={},childOrigin:n,timeout:o,debug:s=!1}=e;const c=f(s),a=g("Parent",c),{onDestroy:u,destroy:d}=a;n||($(t),n=w(t.src));const h="null"===n?"*":n,m=j(r),b=A(c,m,n,h),v=D(m,n,h,a,c);return{promise:new Promise(((e,r)=>{const n=k(o,d),s=r=>{if(r.source===t.contentWindow&&r.data)if(r.data.penpal!==i.Syn)if(r.data.penpal!==i.Ack);else{const t=v(r);t&&(n(),e(t))}else b(r)};window.addEventListener(l.Message,s),c("Parent: Awaiting handshake"),I(t,a),u((e=>{window.removeEventListener(l.Message,s),e&&r(e)}))})),destroy(){d()}}};var O,R=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))},x=function(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)},M=function(e,t,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?i.call(e,r):i?i.value=r:t.set(e,r),r};const T=function(e,t){return{register:function(r,n){return R(this,void 0,void 0,(function*(){t({functionName:"registerFunction()"});const i=yield e.registerFunction(r,n);if(i.isError)throw new Error(i.error)}))},registerOnEvent:function(r,n){return R(this,void 0,void 0,(function*(){t({functionName:"registerFunction()"});const i=yield e.registerFunctionOnEvent(r,n);if(i.isError)throw new Error(i.error)}))},execute:function(r,...n){return R(this,void 0,void 0,(function*(){t({functionName:"executeRegisteredFunction()"});const i=yield e.executeRegisteredFunction(r,n);if(i.isError)throw new Error(i.error);return i.ok}))}}};class V{constructor(){this.customFunction={register:function(e,t){throw new Error("Function not implemented.")},registerOnEvent:function(e,t){throw new Error("Function not implemented.")},execute:function(e,t){throw new Error("Function not implemented.")}},this.chiliEventListenerCallbacks=new Map,this.debug=!1,this.creationTime="",O.set(this,null),this.getProperty=this.getObject}static buildWithIframe(e,t){return R(this,void 0,void 0,(function*(){return V.build(Object.assign({targetIframe:e},t))}))}static buildOnElement(e,t,r){return R(this,void 0,void 0,(function*(){return V.build(Object.assign({parentElement:e,editorURL:t},r))}))}static build(e){var t,r,n,i;return R(this,arguments,void 0,(function*(){if("IFRAME"==arguments[0].tagName){const n=null!==(t=arguments[1])&&void 0!==t?t:{};e=Object.assign(Object.assign({},n),{targetIframe:arguments[0],debug:null!==(r=e.debug)&&void 0!==r?r:n.penpalDebug})}const o=(e=>{try{return JSON.stringify(e)}catch(e){return e.toString()}})(e),s=new V;s.creationTime=(new Date).toLocaleString(),s.debug=null!==(n=e.debug)&&void 0!==n&&n,s.createDebugLog({functionName:"build()",customMessage:"Calling build() with options: "+o});const c=null!==(i=e.targetIframe)&&void 0!==i?i:document.createElement("iframe");s.iframe=c,null!=e.editorURL&&(c.src=e.editorURL);const a=C({iframe:c,methods:{handleEvents:s.handleEvents.bind(s)},timeout:e.timeout,debug:e.debug});null!=e.parentElement&&e.parentElement.appendChild(c),s.child=yield a.promise,s.customFunction=T(s.child,s.createDebugLog.bind(s));const u=e.events;if(null!=u&&u.length>0)for(const e of u)"string"==typeof e?s.addListener(e):s.addListener(e.name,e.func);return s}))}handleEvents(e,t){var r;return this.chiliEventListenerCallbacks.has(e)&&(null===(r=this.chiliEventListenerCallbacks.get(e))||void 0===r||r(t)),e}createDebugLog({functionName:e,customMessage:t}){this.debug&&(null!=t?console.log(`[PublisherInterface - ${this.creationTime}]`,`${e} : ${t}`):console.log(`[PublisherInterface - ${this.creationTime}]`,`Creating ${e} call request`))}get editorObject(){return null==x(this,O,"f")&&M(this,O,{Alert:this.alert.bind(this),GetDirtyState:this.getDirtyState.bind(this),NextPage:this.nextPage.bind(this),PreviousPage:this.previousPage.bind(this),SetSelectedPage:this.setSelectedPage.bind(this),GetSelectedPage:this.getSelectedPage.bind(this),GetSelectedPageName:this.getSelectedPageName.bind(this),GetNumPages:this.getNumPages.bind(this),RemoveListener:this.removeListener.bind(this),AddListener:this.addListener.bind(this),GetObject:this.getObject.bind(this),SetProperty:this.setProperty.bind(this),ExecuteFunction:this.executeFunction.bind(this),GetPageSnapshot:this.getPageSnapshot.bind(this),GetFrameSnapshot:this.getFrameSnapshot.bind(this),GetFrameSubjectArea:this.getFrameSubjectArea.bind(this),SetFrameSubjectArea:this.setFrameSubjectArea.bind(this),ClearFrameSubjectArea:this.clearFrameSubjectArea.bind(this),GetAssetSubjectInfo:this.getAssetSubjectInfo.bind(this),SetAssetSubjectInfo:this.setAssetSubjectInfo.bind(this),ClearAssetSubjectInfo:this.clearAssetSubjectInfo.bind(this),SetVariableIsLocked:this.setVariableIsLocked.bind(this)},"f"),x(this,O,"f")}alert(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"alert()"});const r=yield this.child.alert(e,t);if(r.isError)throw new Error(r.error)}))}getDirtyState(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getDirtyState()"});const e=yield this.child.getDirtyState();if(e.isError)throw new Error(e.error);return e.ok}))}nextPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"nextPage()"});const e=yield this.child.nextPage();if(e.isError)throw new Error(e.error)}))}previousPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"previousPage()"});const e=yield this.child.previousPage();if(e.isError)throw new Error(e.error)}))}setSelectedPage(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setSelectedPage()"});const t=yield this.child.setSelectedPage(e);if(t.isError)throw new Error(t.error)}))}getSelectedPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getSelectedPage()"});const e=yield this.child.getSelectedPage();if(e.isError)throw new Error(e.error);return e.ok}))}getSelectedPageName(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getSelectedPageName()"});const e=yield this.child.getSelectedPageName();if(e.isError)throw new Error(e.error);return e.ok}))}getNumPages(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getNumPages()"});const e=yield this.child.getNumPages();if(e.isError)throw new Error(e.error);return e.ok}))}removeListener(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"removeListener()"}),this.chiliEventListenerCallbacks.delete(e);const t=yield this.child.removeListener(e);if(t.isError)throw new Error(t.error)}))}addListener(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"addListener()"}),this.chiliEventListenerCallbacks.set(e,null==t?t=>{null!=window.OnEditorEvent&&window.OnEditorEvent(e,t)}:t);const r=yield this.child.addListener(e);if(r.isError)throw new Error(r.error)}))}getObject(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getObject()"});const t=yield this.child.getObject(e);if(t.isError)throw new Error(t.error);return t.ok}))}setProperty(e,t,r){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setProperty()"});const n=yield this.child.setProperty(e,t,r);if(n.isError)throw new Error(n.error)}))}executeFunction(e,t,...r){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"executeFunction()"});const n=yield this.child.executeFunction(e,t,r);if(n.isError)throw new Error(n.error);return n.ok}))}getPageSnapshot(e,t,r,n,i,o){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getPageSnapshot()"});const s=yield this.child.getPageSnapshot(e,t,r,n,i,o);if(s.isError)throw new Error(s.error);return s.ok}))}getFrameSnapshot(e,t,r){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getFrameSnapshot()"});const n=yield this.child.getFrameSnapshot(e,t,r);if(n.isError)throw new Error(n.error);return n.ok}))}getFrameSubjectArea(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getFrameSubjectArea()"});const t=yield this.child.getFrameSubjectArea(e);if(t.isError)throw new Error(t.error);return t.ok}))}setFrameSubjectArea(e,t,r,n,i){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setFrameSubjectArea()"});const o=yield this.child.setFrameSubjectArea(e,t,r,n,i);if(o.isError)throw new Error(o.error)}))}clearFrameSubjectArea(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"clearFrameSubjectArea()"});const t=yield this.child.clearFrameSubjectArea(e);if(t.isError)throw new Error(t.error)}))}getAssetSubjectInfo(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getAssetSubjectInfo()"});const t=yield this.child.getAssetSubjectInfo(e);if(t.isError)throw new Error(t.error);return t.ok}))}setAssetSubjectInfo(e,t,r,n,i,o,s){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setAssetSubjectInfo()"});const c=yield this.child.setAssetSubjectInfo(e,t,r,n,i,o,s);if(c.isError)throw new Error(c.error)}))}clearAssetSubjectInfo(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"clearAssetSubjectInfo()"});const t=yield this.child.clearAssetSubjectInfo(e);if(t.isError)throw new Error(t.error)}))}setVariableIsLocked(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setVariableIsLocked()"});const r=yield this.child.setVariableIsLocked(e,t);if(r.isError)throw new Error(r.error)}))}}O=new WeakMap;export{V as PublisherInterface,h as default}; | ||
//# sourceMappingURL=PublisherInterface.min.js.map |
@@ -134,2 +134,9 @@ var $7i1sb$penpal = require("penpal"); | ||
} | ||
const stringifiedOptions = ((opts)=>{ | ||
try { | ||
return JSON.stringify(opts); | ||
} catch (e) { | ||
return e.toString(); | ||
} | ||
})(options); | ||
const publisherInterface = new $3db7bcc71a7ab568$export$a13915682e709c4f(); | ||
@@ -140,3 +147,3 @@ publisherInterface.creationTime = new Date().toLocaleString(); | ||
functionName: "build()", | ||
customMessage: "Calling build() with options: " + JSON.stringify(options) | ||
customMessage: "Calling build() with options: " + stringifiedOptions | ||
}); | ||
@@ -143,0 +150,0 @@ const iframe = (_d = options.targetIframe) !== null && _d !== void 0 ? _d : document.createElement("iframe"); |
{ | ||
"name": "@chili-publish/publisher-interface", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": "chili-publish", | ||
@@ -5,0 +5,0 @@ "description": "PublisherInterface is a class object that allows you to interact with the CHILI Publisher editorObject via postMessage without the complexity of postMessage.", |
Sorry, the diff of this file is not supported yet
163720
0.25%992
0.81%