@archilogic/extension-sdk 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/extension-sdk.cjs +1 -1
- package/dist/extension-sdk.js +150 -143
- package/dist/index.d.ts +16 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @archilogic/extension-sdk
|
|
2
2
|
|
|
3
|
+
## 0.6.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b2178e2: fix(extension-sdk): fix types to support unsubscribe from all events and providing custom context
|
|
8
|
+
|
|
9
|
+
## 0.6.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- d3f3417: fix(extension-sdk): ensure all extension methods are defined
|
|
14
|
+
|
|
3
15
|
## 0.6.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/extension-sdk.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var We=Object.defineProperty;var fe=e=>{throw TypeError(e)};var Fe=(e,t,r)=>t in e?We(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var c=(e,t,r)=>Fe(e,typeof t!="symbol"?t+"":t,r),ve=(e,t,r)=>t.has(e)||fe("Cannot "+r);var n=(e,t,r)=>(ve(e,t,"read from private field"),r?r.call(e):t.get(e)),o=(e,t,r)=>t.has(e)?fe("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),p=(e,t,r,s)=>(ve(e,t,"write to private field"),s?s.call(e,r):t.set(e,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Ue=class extends Error{constructor(t,r){super(r);c(this,"code");this.name="PenpalError",this.code=t}},w=Ue,Ve=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof w?e.code:void 0}),Ye=({name:e,message:t,stack:r,penpalCode:s})=>{const a=s?new w(s,t):new Error(t);return a.name=e,a.stack=r,a},$e=Symbol("Reply"),le,me,je=(me=class{constructor(e,t){c(this,"value");c(this,"transferables");o(this,le,$e);this.value=e,this.transferables=t==null?void 0:t.transferables}},le=new WeakMap,me),ze=je,P="penpal",ae=e=>typeof e=="object"&&e!==null,Ne=e=>typeof e=="function",Ke=e=>ae(e)&&e.namespace===P,W=e=>e.type==="SYN",ie=e=>e.type==="ACK1",z=e=>e.type==="ACK2",Re=e=>e.type==="CALL",_e=e=>e.type==="REPLY",Ge=e=>e.type==="DESTROY",ke=(e,t=[])=>{const r=[];for(const s of Object.keys(e)){const a=e[s];Ne(a)?r.push([...t,s]):ae(a)&&r.push(...ke(a,[...t,s]))}return r},qe=(e,t)=>{const r=e.reduce((s,a)=>ae(s)?s[a]:void 0,t);return Ne(r)?r:void 0},R=e=>e.join("."),pe=(e,t,r)=>({namespace:P,channel:e,type:"REPLY",callId:t,isError:!0,...r instanceof Error?{value:Ve(r),isSerializedErrorInstance:!0}:{value:r}}),Be=(e,t,r,s)=>{let a=!1;const d=async i=>{if(a||!Re(i))return;s==null||s(`Received ${R(i.methodPath)}() call`,i);const{methodPath:u,args:v,id:l}=i;let h,A;try{const M=qe(u,t);if(!M)throw new w("METHOD_NOT_FOUND",`Method \`${R(u)}\` is not found.`);let y=await M(...v);y instanceof ze&&(A=y.transferables,y=await y.value),h={namespace:P,channel:r,type:"REPLY",callId:l,value:y}}catch(M){h=pe(r,l,M)}if(!a)try{s==null||s(`Sending ${R(u)}() reply`,h),e.sendMessage(h,A)}catch(M){throw M.name==="DataCloneError"&&(h=pe(r,l,M),s==null||s(`Sending ${R(u)}() reply`,h),e.sendMessage(h)),M}};return e.addMessageHandler(d),()=>{a=!0,e.removeMessageHandler(d)}},Je=Be,Pe,Le=((Pe=crypto.randomUUID)==null?void 0:Pe.bind(crypto))??(()=>new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")),Xe=Symbol("CallOptions"),he,Ae,Qe=(Ae=class{constructor(e){c(this,"transferables");c(this,"timeout");o(this,he,Xe);this.transferables=e==null?void 0:e.transferables,this.timeout=e==null?void 0:e.timeout}},he=new WeakMap,Ae),Ze=Qe,et=new Set(["apply","call","bind"]),Te=(e,t,r=[])=>new Proxy(r.length?()=>{}:Object.create(null),{get(s,a){if(a!=="then")return r.length&&et.has(a)?Reflect.get(s,a):Te(e,t,[...r,a])},apply(s,a,d){return e(r,d)}}),Me=e=>new w("CONNECTION_DESTROYED",`Method call ${R(e)}() failed due to destroyed connection`),tt=(e,t,r)=>{let s=!1;const a=new Map,d=v=>{if(!_e(v))return;const{callId:l,value:h,isError:A,isSerializedErrorInstance:M}=v,y=a.get(l);y&&(a.delete(l),r==null||r(`Received ${R(y.methodPath)}() call`,v),A?y.reject(M?Ye(h):h):y.resolve(h))};return e.addMessageHandler(d),{remoteProxy:Te((v,l)=>{if(s)throw Me(v);const h=Le(),A=l[l.length-1],M=A instanceof Ze,{timeout:y,transferables:oe}=M?A:{},ee=M?l.slice(0,-1):l;return new Promise((te,j)=>{const de=y!==void 0?window.setTimeout(()=>{a.delete(h),j(new w("METHOD_CALL_TIMEOUT",`Method call ${R(v)}() timed out after ${y}ms`))},y):void 0;a.set(h,{methodPath:v,resolve:te,reject:j,timeoutId:de});try{const O={namespace:P,channel:t,type:"CALL",id:h,methodPath:v,args:ee};r==null||r(`Sending ${R(v)}() call`,O),e.sendMessage(O,oe)}catch(O){j(new w("TRANSMISSION_FAILED",O.message))}})},r),destroy:()=>{s=!0,e.removeMessageHandler(d);for(const{methodPath:v,reject:l,timeoutId:h}of a.values())clearTimeout(h),l(Me(v));a.clear()}}},rt=tt,nt=()=>{let e,t;return{promise:new Promise((s,a)=>{e=s,t=a}),resolve:e,reject:t}},st=nt,at=class extends Error{constructor(e){super(`You've hit a bug in Penpal. Please file an issue with the following information: ${e}`)}},F=at,ce="deprecated-penpal",it=e=>ae(e)&&"penpal"in e,ot=e=>e.split("."),ye=e=>e.join("."),be=e=>new F(`Unexpected message to translate: ${JSON.stringify(e)}`),dt=e=>{if(e.penpal==="syn")return{namespace:P,channel:void 0,type:"SYN",participantId:ce};if(e.penpal==="ack")return{namespace:P,channel:void 0,type:"ACK2"};if(e.penpal==="call")return{namespace:P,channel:void 0,type:"CALL",id:e.id,methodPath:ot(e.methodName),args:e.args};if(e.penpal==="reply")return e.resolution==="fulfilled"?{namespace:P,channel:void 0,type:"REPLY",callId:e.id,value:e.returnValue}:{namespace:P,channel:void 0,type:"REPLY",callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw be(e)},ct=e=>{if(ie(e))return{penpal:"synAck",methodNames:e.methodPaths.map(ye)};if(Re(e))return{penpal:"call",id:e.id,methodName:ye(e.methodPath),args:e.args};if(_e(e))return e.isError?{penpal:"reply",id:e.callId,resolution:"rejected",...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:"reply",id:e.callId,resolution:"fulfilled",returnValue:e.value};throw be(e)},lt=({messenger:e,methods:t,timeout:r,channel:s,log:a})=>{const d=Le();let i;const u=[];let v=!1;const l=ke(t),{promise:h,resolve:A,reject:M}=st(),y=r!==void 0?setTimeout(()=>{M(new w("CONNECTION_TIMEOUT",`Connection timed out after ${r}ms`))},r):void 0,oe=()=>{for(const f of u)f()},ee=()=>{if(v)return;u.push(Je(e,t,s,a));const{remoteProxy:f,destroy:_}=rt(e,s,a);u.push(_),clearTimeout(y),v=!0,A({remoteProxy:f,destroy:oe})},te=()=>{const f={namespace:P,type:"SYN",channel:s,participantId:d};a==null||a("Sending handshake SYN",f);try{e.sendMessage(f)}catch(_){M(new w("TRANSMISSION_FAILED",_.message))}},j=f=>{if(a==null||a("Received handshake SYN",f),f.participantId===i&&i!==ce||(i=f.participantId,te(),!(d>i||i===ce)))return;const re={namespace:P,channel:s,type:"ACK1",methodPaths:l};a==null||a("Sending handshake ACK1",re);try{e.sendMessage(re)}catch(Oe){M(new w("TRANSMISSION_FAILED",Oe.message));return}},de=f=>{a==null||a("Received handshake ACK1",f);const _={namespace:P,channel:s,type:"ACK2"};a==null||a("Sending handshake ACK2",_);try{e.sendMessage(_)}catch(re){M(new w("TRANSMISSION_FAILED",re.message));return}ee()},O=f=>{a==null||a("Received handshake ACK2",f),ee()},ue=f=>{W(f)&&j(f),ie(f)&&de(f),z(f)&&O(f)};return e.addMessageHandler(ue),u.push(()=>e.removeMessageHandler(ue)),te(),h},ht=lt,ut=e=>{let t=!1,r;return(...s)=>(t||(t=!0,r=e(...s)),r)},ft=ut,we=new WeakSet,vt=({messenger:e,methods:t={},timeout:r,channel:s,log:a})=>{if(!e)throw new w("INVALID_ARGUMENT","messenger must be defined");if(we.has(e))throw new w("INVALID_ARGUMENT","A messenger can only be used for a single connection");we.add(e);const d=[e.destroy],i=ft(l=>{if(l){const h={namespace:P,channel:s,type:"DESTROY"};try{e.sendMessage(h)}catch{}}for(const h of d)h();a==null||a("Connection destroyed")}),u=l=>Ke(l)&&l.channel===s;return{promise:(async()=>{try{e.initialize({log:a,validateReceivedMessage:u}),e.addMessageHandler(A=>{Ge(A)&&i(!1)});const{remoteProxy:l,destroy:h}=await ht({messenger:e,methods:t,timeout:r,channel:s,log:a});return d.push(h),l}catch(l){throw i(!0),l}})(),destroy:()=>{i(!0)}}},He=vt,g,k,U,V,L,C,E,T,se,Y,K,G,$,Ie,pt=(Ie=class{constructor({remoteWindow:e,allowedOrigins:t}){o(this,g);o(this,k);o(this,U);o(this,V);o(this,L);o(this,C,new Set);o(this,E);o(this,T,!1);c(this,"initialize",({log:e,validateReceivedMessage:t})=>{p(this,U,e),p(this,V,t),window.addEventListener("message",n(this,G))});c(this,"sendMessage",(e,t)=>{if(W(e)){const r=n(this,Y).call(this,e);n(this,g).postMessage(e,{targetOrigin:r,transfer:t});return}if(ie(e)||n(this,T)){const r=n(this,T)?ct(e):e,s=n(this,Y).call(this,e);n(this,g).postMessage(r,{targetOrigin:s,transfer:t});return}if(z(e)){const{port1:r,port2:s}=new MessageChannel;p(this,E,r),r.addEventListener("message",n(this,$)),r.start();const a=[s,...t||[]],d=n(this,Y).call(this,e);n(this,g).postMessage(e,{targetOrigin:d,transfer:a});return}if(n(this,E)){n(this,E).postMessage(e,{transfer:t});return}throw new F("Port is undefined")});c(this,"addMessageHandler",e=>{n(this,C).add(e)});c(this,"removeMessageHandler",e=>{n(this,C).delete(e)});c(this,"destroy",()=>{window.removeEventListener("message",n(this,G)),n(this,K).call(this),n(this,C).clear()});o(this,se,e=>n(this,k).some(t=>t instanceof RegExp?t.test(e):t===e||t==="*"));o(this,Y,e=>{if(W(e))return"*";if(!n(this,L))throw new F("Concrete remote origin not set");return n(this,L)==="null"&&n(this,k).includes("*")?"*":n(this,L)});o(this,K,()=>{var e,t;(e=n(this,E))==null||e.removeEventListener("message",n(this,$)),(t=n(this,E))==null||t.close(),p(this,E,void 0)});o(this,G,({source:e,origin:t,ports:r,data:s})=>{var a,d,i;if(e===n(this,g)&&(it(s)&&((a=n(this,U))==null||a.call(this,"Please upgrade the child window to the latest version of Penpal."),p(this,T,!0),s=dt(s)),!!((d=n(this,V))!=null&&d.call(this,s)))){if(!n(this,se).call(this,t)){(i=n(this,U))==null||i.call(this,`Received a message from origin \`${t}\` which did not match allowed origins \`[${n(this,k).join(", ")}]\``);return}if(W(s)&&(n(this,K).call(this),p(this,L,t)),z(s)&&!n(this,T)){if(p(this,E,r[0]),!n(this,E))throw new F("No port received on ACK2");n(this,E).addEventListener("message",n(this,$)),n(this,E).start()}for(const u of n(this,C))u(s)}});o(this,$,({data:e})=>{var t;if((t=n(this,V))!=null&&t.call(this,e))for(const r of n(this,C))r(e)});if(!e)throw new w("INVALID_ARGUMENT","remoteWindow must be defined");p(this,g,e),p(this,k,t!=null&&t.length?t:[window.origin])}},g=new WeakMap,k=new WeakMap,U=new WeakMap,V=new WeakMap,L=new WeakMap,C=new WeakMap,E=new WeakMap,T=new WeakMap,se=new WeakMap,Y=new WeakMap,K=new WeakMap,G=new WeakMap,$=new WeakMap,Ie),De=pt,S,q,b,m,B,N,ge,Mt=(ge=class{constructor({worker:e}){o(this,S);o(this,q);o(this,b,new Set);o(this,m);c(this,"initialize",({validateReceivedMessage:e})=>{p(this,q,e),n(this,S).addEventListener("message",n(this,N))});c(this,"sendMessage",(e,t)=>{if(W(e)||ie(e)){n(this,S).postMessage(e,{transfer:t});return}if(z(e)){const{port1:r,port2:s}=new MessageChannel;p(this,m,r),r.addEventListener("message",n(this,N)),r.start(),n(this,S).postMessage(e,{transfer:[s,...t||[]]});return}if(n(this,m)){n(this,m).postMessage(e,{transfer:t});return}throw new F("Port is undefined")});c(this,"addMessageHandler",e=>{n(this,b).add(e)});c(this,"removeMessageHandler",e=>{n(this,b).delete(e)});c(this,"destroy",()=>{n(this,S).removeEventListener("message",n(this,N)),n(this,B).call(this),n(this,b).clear()});o(this,B,()=>{var e,t;(e=n(this,m))==null||e.removeEventListener("message",n(this,N)),(t=n(this,m))==null||t.close(),p(this,m,void 0)});o(this,N,({ports:e,data:t})=>{var r;if((r=n(this,q))!=null&&r.call(this,t)){if(W(t)&&n(this,B).call(this),z(t)){if(p(this,m,e[0]),!n(this,m))throw new F("No port received on ACK2");n(this,m).addEventListener("message",n(this,N)),n(this,m).start()}for(const s of n(this,b))s(t)}});if(!e)throw new w("INVALID_ARGUMENT","worker must be defined");p(this,S,e)}},S=new WeakMap,q=new WeakMap,b=new WeakMap,m=new WeakMap,B=new WeakMap,N=new WeakMap,ge),xe=Mt,H,J,D,X,Ce,yt=(Ce=class{constructor({worker:e}){o(this,H);o(this,J);o(this,D,new Set);c(this,"initialize",({validateReceivedMessage:e})=>{p(this,J,e),n(this,H).addListener("message",n(this,X))});c(this,"sendMessage",(e,t)=>{n(this,H).postMessage(e,t)});c(this,"addMessageHandler",e=>{n(this,D).add(e)});c(this,"removeMessageHandler",e=>{n(this,D).delete(e)});c(this,"destroy",()=>{n(this,H).removeListener("message",n(this,X)),n(this,D).clear()});o(this,X,e=>{var t;if((t=n(this,J))!=null&&t.call(this,e))for(const r of n(this,D))r(e)});if(!e)throw new w("INVALID_ARGUMENT","worker must be defined");p(this,H,e)}},H=new WeakMap,J=new WeakMap,D=new WeakMap,X=new WeakMap,Ce),wt=yt,I,Q,x,Z,Se,Et=(Se=class{constructor({port:e}){o(this,I);o(this,Q);o(this,x,new Set);c(this,"initialize",({validateReceivedMessage:e})=>{p(this,Q,e),n(this,I).addEventListener("message",n(this,Z)),n(this,I).start()});c(this,"sendMessage",(e,t)=>{var r;(r=n(this,I))==null||r.postMessage(e,{transfer:t})});c(this,"addMessageHandler",e=>{n(this,x).add(e)});c(this,"removeMessageHandler",e=>{n(this,x).delete(e)});c(this,"destroy",()=>{n(this,I).removeEventListener("message",n(this,Z)),n(this,I).close(),n(this,x).clear()});o(this,Z,({data:e})=>{var t;if((t=n(this,Q))!=null&&t.call(this,e))for(const r of n(this,x))r(e)});if(!e)throw new w("INVALID_ARGUMENT","port must be defined");p(this,I,e)}},I=new WeakMap,Q=new WeakMap,x=new WeakMap,Z=new WeakMap,Se),mt=Et;const Pt=(e,{iframe:t,worker:r,webWorker:s})=>{let a;if(t)a=new De({remoteWindow:t.contentWindow,allowedOrigins:[/^http:\/\/localhost(:\d+)/,"https://extensions.archilogic.io","https://testing-extensions.archilogic.io"]});else if(r)a=new wt({worker:r});else if(s)a=new xe({worker:s});else throw new Error("No iframe or worker to connect to");return He({messenger:a,methods:e})};var ne={exports:{}},Ee;function At(){if(Ee)return ne.exports;Ee=1;function e(){}return e.prototype={on:function(t,r,s){var a=this.e||(this.e={});return(a[t]||(a[t]=[])).push({fn:r,ctx:s}),this},once:function(t,r,s){var a=this;function d(){a.off(t,d),r.apply(s,arguments)}return d._=r,this.on(t,d,s)},emit:function(t){var r=[].slice.call(arguments,1),s=((this.e||(this.e={}))[t]||[]).slice(),a=0,d=s.length;for(a;a<d;a++)s[a].fn.apply(s[a].ctx,r);return this},off:function(t,r){var s=this.e||(this.e={}),a=s[t],d=[];if(a&&r)for(var i=0,u=a.length;i<u;i++)a[i].fn!==r&&a[i].fn._!==r&&d.push(a[i]);return d.length?s[t]=d:delete s[t],this}},ne.exports=e,ne.exports.TinyEmitter=e,ne.exports}var It=At();const gt=(e={},t)=>{let r;const s=new It.TinyEmitter;if((t==null?void 0:t.useWorker)==="node"){const i=require("node:worker_threads").parentPort;if(!i)throw new Error("No parent port found for worker thread");r=new mt({port:i})}else(t==null?void 0:t.useWorker)==="web"?r=new xe({worker:self}):r=new De({remoteWindow:window.parent,allowedOrigins:[/^http:\/\/localhost(:\d+)/,/^https:\/\/(.*)app.archilogic.com/,/^https:\/\/(.*).archilogic-frontend.com/]});const a=He({messenger:r,methods:{...e,onLayoutChange:i=>{s.emit("layout-change",i)},onSelectionChange:i=>{s.emit("selection-change",i)},onGraphicDrag:i=>{s.emit("graphic-crag",i)},onCanvasClick:i=>{s.emit("canvas-click",i)}}});return new Proxy({},{get(i,u){return u==="on"?s.on.bind(s):u==="once"?s.once.bind(s):u==="off"?s.off.bind(s):async(...v)=>(await a.promise)[u](...v)}})};exports.createExtensionConnection=Pt;exports.createHostConnection=gt;
|
|
1
|
+
"use strict";var We=Object.defineProperty;var fe=e=>{throw TypeError(e)};var Fe=(e,t,r)=>t in e?We(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var h=(e,t,r)=>Fe(e,typeof t!="symbol"?t+"":t,r),ve=(e,t,r)=>t.has(e)||fe("Cannot "+r);var n=(e,t,r)=>(ve(e,t,"read from private field"),r?r.call(e):t.get(e)),o=(e,t,r)=>t.has(e)?fe("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),p=(e,t,r,s)=>(ve(e,t,"write to private field"),s?s.call(e,r):t.set(e,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Ue=class extends Error{constructor(t,r){super(r);h(this,"code");this.name="PenpalError",this.code=t}},w=Ue,Ve=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof w?e.code:void 0}),Ye=({name:e,message:t,stack:r,penpalCode:s})=>{const a=s?new w(s,t):new Error(t);return a.name=e,a.stack=r,a},$e=Symbol("Reply"),le,me,je=(me=class{constructor(e,t){h(this,"value");h(this,"transferables");o(this,le,$e);this.value=e,this.transferables=t==null?void 0:t.transferables}},le=new WeakMap,me),ze=je,P="penpal",ae=e=>typeof e=="object"&&e!==null,Ne=e=>typeof e=="function",Ke=e=>ae(e)&&e.namespace===P,W=e=>e.type==="SYN",ie=e=>e.type==="ACK1",z=e=>e.type==="ACK2",Re=e=>e.type==="CALL",_e=e=>e.type==="REPLY",Ge=e=>e.type==="DESTROY",ke=(e,t=[])=>{const r=[];for(const s of Object.keys(e)){const a=e[s];Ne(a)?r.push([...t,s]):ae(a)&&r.push(...ke(a,[...t,s]))}return r},qe=(e,t)=>{const r=e.reduce((s,a)=>ae(s)?s[a]:void 0,t);return Ne(r)?r:void 0},R=e=>e.join("."),pe=(e,t,r)=>({namespace:P,channel:e,type:"REPLY",callId:t,isError:!0,...r instanceof Error?{value:Ve(r),isSerializedErrorInstance:!0}:{value:r}}),Be=(e,t,r,s)=>{let a=!1;const i=async u=>{if(a||!Re(u))return;s==null||s(`Received ${R(u.methodPath)}() call`,u);const{methodPath:d,args:f,id:c}=u;let l,A;try{const M=qe(d,t);if(!M)throw new w("METHOD_NOT_FOUND",`Method \`${R(d)}\` is not found.`);let y=await M(...f);y instanceof ze&&(A=y.transferables,y=await y.value),l={namespace:P,channel:r,type:"REPLY",callId:c,value:y}}catch(M){l=pe(r,c,M)}if(!a)try{s==null||s(`Sending ${R(d)}() reply`,l),e.sendMessage(l,A)}catch(M){throw M.name==="DataCloneError"&&(l=pe(r,c,M),s==null||s(`Sending ${R(d)}() reply`,l),e.sendMessage(l)),M}};return e.addMessageHandler(i),()=>{a=!0,e.removeMessageHandler(i)}},Je=Be,Pe,Le=((Pe=crypto.randomUUID)==null?void 0:Pe.bind(crypto))??(()=>new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")),Xe=Symbol("CallOptions"),he,Ae,Qe=(Ae=class{constructor(e){h(this,"transferables");h(this,"timeout");o(this,he,Xe);this.transferables=e==null?void 0:e.transferables,this.timeout=e==null?void 0:e.timeout}},he=new WeakMap,Ae),Ze=Qe,et=new Set(["apply","call","bind"]),Te=(e,t,r=[])=>new Proxy(r.length?()=>{}:Object.create(null),{get(s,a){if(a!=="then")return r.length&&et.has(a)?Reflect.get(s,a):Te(e,t,[...r,a])},apply(s,a,i){return e(r,i)}}),Me=e=>new w("CONNECTION_DESTROYED",`Method call ${R(e)}() failed due to destroyed connection`),tt=(e,t,r)=>{let s=!1;const a=new Map,i=f=>{if(!_e(f))return;const{callId:c,value:l,isError:A,isSerializedErrorInstance:M}=f,y=a.get(c);y&&(a.delete(c),r==null||r(`Received ${R(y.methodPath)}() call`,f),A?y.reject(M?Ye(l):l):y.resolve(l))};return e.addMessageHandler(i),{remoteProxy:Te((f,c)=>{if(s)throw Me(f);const l=Le(),A=c[c.length-1],M=A instanceof Ze,{timeout:y,transferables:oe}=M?A:{},ee=M?c.slice(0,-1):c;return new Promise((te,j)=>{const de=y!==void 0?window.setTimeout(()=>{a.delete(l),j(new w("METHOD_CALL_TIMEOUT",`Method call ${R(f)}() timed out after ${y}ms`))},y):void 0;a.set(l,{methodPath:f,resolve:te,reject:j,timeoutId:de});try{const O={namespace:P,channel:t,type:"CALL",id:l,methodPath:f,args:ee};r==null||r(`Sending ${R(f)}() call`,O),e.sendMessage(O,oe)}catch(O){j(new w("TRANSMISSION_FAILED",O.message))}})},r),destroy:()=>{s=!0,e.removeMessageHandler(i);for(const{methodPath:f,reject:c,timeoutId:l}of a.values())clearTimeout(l),c(Me(f));a.clear()}}},rt=tt,nt=()=>{let e,t;return{promise:new Promise((s,a)=>{e=s,t=a}),resolve:e,reject:t}},st=nt,at=class extends Error{constructor(e){super(`You've hit a bug in Penpal. Please file an issue with the following information: ${e}`)}},F=at,ce="deprecated-penpal",it=e=>ae(e)&&"penpal"in e,ot=e=>e.split("."),ye=e=>e.join("."),be=e=>new F(`Unexpected message to translate: ${JSON.stringify(e)}`),dt=e=>{if(e.penpal==="syn")return{namespace:P,channel:void 0,type:"SYN",participantId:ce};if(e.penpal==="ack")return{namespace:P,channel:void 0,type:"ACK2"};if(e.penpal==="call")return{namespace:P,channel:void 0,type:"CALL",id:e.id,methodPath:ot(e.methodName),args:e.args};if(e.penpal==="reply")return e.resolution==="fulfilled"?{namespace:P,channel:void 0,type:"REPLY",callId:e.id,value:e.returnValue}:{namespace:P,channel:void 0,type:"REPLY",callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw be(e)},ct=e=>{if(ie(e))return{penpal:"synAck",methodNames:e.methodPaths.map(ye)};if(Re(e))return{penpal:"call",id:e.id,methodName:ye(e.methodPath),args:e.args};if(_e(e))return e.isError?{penpal:"reply",id:e.callId,resolution:"rejected",...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:"reply",id:e.callId,resolution:"fulfilled",returnValue:e.value};throw be(e)},lt=({messenger:e,methods:t,timeout:r,channel:s,log:a})=>{const i=Le();let u;const d=[];let f=!1;const c=ke(t),{promise:l,resolve:A,reject:M}=st(),y=r!==void 0?setTimeout(()=>{M(new w("CONNECTION_TIMEOUT",`Connection timed out after ${r}ms`))},r):void 0,oe=()=>{for(const v of d)v()},ee=()=>{if(f)return;d.push(Je(e,t,s,a));const{remoteProxy:v,destroy:_}=rt(e,s,a);d.push(_),clearTimeout(y),f=!0,A({remoteProxy:v,destroy:oe})},te=()=>{const v={namespace:P,type:"SYN",channel:s,participantId:i};a==null||a("Sending handshake SYN",v);try{e.sendMessage(v)}catch(_){M(new w("TRANSMISSION_FAILED",_.message))}},j=v=>{if(a==null||a("Received handshake SYN",v),v.participantId===u&&u!==ce||(u=v.participantId,te(),!(i>u||u===ce)))return;const re={namespace:P,channel:s,type:"ACK1",methodPaths:c};a==null||a("Sending handshake ACK1",re);try{e.sendMessage(re)}catch(Oe){M(new w("TRANSMISSION_FAILED",Oe.message));return}},de=v=>{a==null||a("Received handshake ACK1",v);const _={namespace:P,channel:s,type:"ACK2"};a==null||a("Sending handshake ACK2",_);try{e.sendMessage(_)}catch(re){M(new w("TRANSMISSION_FAILED",re.message));return}ee()},O=v=>{a==null||a("Received handshake ACK2",v),ee()},ue=v=>{W(v)&&j(v),ie(v)&&de(v),z(v)&&O(v)};return e.addMessageHandler(ue),d.push(()=>e.removeMessageHandler(ue)),te(),l},ht=lt,ut=e=>{let t=!1,r;return(...s)=>(t||(t=!0,r=e(...s)),r)},ft=ut,we=new WeakSet,vt=({messenger:e,methods:t={},timeout:r,channel:s,log:a})=>{if(!e)throw new w("INVALID_ARGUMENT","messenger must be defined");if(we.has(e))throw new w("INVALID_ARGUMENT","A messenger can only be used for a single connection");we.add(e);const i=[e.destroy],u=ft(c=>{if(c){const l={namespace:P,channel:s,type:"DESTROY"};try{e.sendMessage(l)}catch{}}for(const l of i)l();a==null||a("Connection destroyed")}),d=c=>Ke(c)&&c.channel===s;return{promise:(async()=>{try{e.initialize({log:a,validateReceivedMessage:d}),e.addMessageHandler(A=>{Ge(A)&&u(!1)});const{remoteProxy:c,destroy:l}=await ht({messenger:e,methods:t,timeout:r,channel:s,log:a});return i.push(l),c}catch(c){throw u(!0),c}})(),destroy:()=>{u(!0)}}},De=vt,g,k,U,V,L,C,E,T,se,Y,K,G,$,Ie,pt=(Ie=class{constructor({remoteWindow:e,allowedOrigins:t}){o(this,g);o(this,k);o(this,U);o(this,V);o(this,L);o(this,C,new Set);o(this,E);o(this,T,!1);h(this,"initialize",({log:e,validateReceivedMessage:t})=>{p(this,U,e),p(this,V,t),window.addEventListener("message",n(this,G))});h(this,"sendMessage",(e,t)=>{if(W(e)){const r=n(this,Y).call(this,e);n(this,g).postMessage(e,{targetOrigin:r,transfer:t});return}if(ie(e)||n(this,T)){const r=n(this,T)?ct(e):e,s=n(this,Y).call(this,e);n(this,g).postMessage(r,{targetOrigin:s,transfer:t});return}if(z(e)){const{port1:r,port2:s}=new MessageChannel;p(this,E,r),r.addEventListener("message",n(this,$)),r.start();const a=[s,...t||[]],i=n(this,Y).call(this,e);n(this,g).postMessage(e,{targetOrigin:i,transfer:a});return}if(n(this,E)){n(this,E).postMessage(e,{transfer:t});return}throw new F("Port is undefined")});h(this,"addMessageHandler",e=>{n(this,C).add(e)});h(this,"removeMessageHandler",e=>{n(this,C).delete(e)});h(this,"destroy",()=>{window.removeEventListener("message",n(this,G)),n(this,K).call(this),n(this,C).clear()});o(this,se,e=>n(this,k).some(t=>t instanceof RegExp?t.test(e):t===e||t==="*"));o(this,Y,e=>{if(W(e))return"*";if(!n(this,L))throw new F("Concrete remote origin not set");return n(this,L)==="null"&&n(this,k).includes("*")?"*":n(this,L)});o(this,K,()=>{var e,t;(e=n(this,E))==null||e.removeEventListener("message",n(this,$)),(t=n(this,E))==null||t.close(),p(this,E,void 0)});o(this,G,({source:e,origin:t,ports:r,data:s})=>{var a,i,u;if(e===n(this,g)&&(it(s)&&((a=n(this,U))==null||a.call(this,"Please upgrade the child window to the latest version of Penpal."),p(this,T,!0),s=dt(s)),!!((i=n(this,V))!=null&&i.call(this,s)))){if(!n(this,se).call(this,t)){(u=n(this,U))==null||u.call(this,`Received a message from origin \`${t}\` which did not match allowed origins \`[${n(this,k).join(", ")}]\``);return}if(W(s)&&(n(this,K).call(this),p(this,L,t)),z(s)&&!n(this,T)){if(p(this,E,r[0]),!n(this,E))throw new F("No port received on ACK2");n(this,E).addEventListener("message",n(this,$)),n(this,E).start()}for(const d of n(this,C))d(s)}});o(this,$,({data:e})=>{var t;if((t=n(this,V))!=null&&t.call(this,e))for(const r of n(this,C))r(e)});if(!e)throw new w("INVALID_ARGUMENT","remoteWindow must be defined");p(this,g,e),p(this,k,t!=null&&t.length?t:[window.origin])}},g=new WeakMap,k=new WeakMap,U=new WeakMap,V=new WeakMap,L=new WeakMap,C=new WeakMap,E=new WeakMap,T=new WeakMap,se=new WeakMap,Y=new WeakMap,K=new WeakMap,G=new WeakMap,$=new WeakMap,Ie),He=pt,S,q,b,m,B,N,ge,Mt=(ge=class{constructor({worker:e}){o(this,S);o(this,q);o(this,b,new Set);o(this,m);h(this,"initialize",({validateReceivedMessage:e})=>{p(this,q,e),n(this,S).addEventListener("message",n(this,N))});h(this,"sendMessage",(e,t)=>{if(W(e)||ie(e)){n(this,S).postMessage(e,{transfer:t});return}if(z(e)){const{port1:r,port2:s}=new MessageChannel;p(this,m,r),r.addEventListener("message",n(this,N)),r.start(),n(this,S).postMessage(e,{transfer:[s,...t||[]]});return}if(n(this,m)){n(this,m).postMessage(e,{transfer:t});return}throw new F("Port is undefined")});h(this,"addMessageHandler",e=>{n(this,b).add(e)});h(this,"removeMessageHandler",e=>{n(this,b).delete(e)});h(this,"destroy",()=>{n(this,S).removeEventListener("message",n(this,N)),n(this,B).call(this),n(this,b).clear()});o(this,B,()=>{var e,t;(e=n(this,m))==null||e.removeEventListener("message",n(this,N)),(t=n(this,m))==null||t.close(),p(this,m,void 0)});o(this,N,({ports:e,data:t})=>{var r;if((r=n(this,q))!=null&&r.call(this,t)){if(W(t)&&n(this,B).call(this),z(t)){if(p(this,m,e[0]),!n(this,m))throw new F("No port received on ACK2");n(this,m).addEventListener("message",n(this,N)),n(this,m).start()}for(const s of n(this,b))s(t)}});if(!e)throw new w("INVALID_ARGUMENT","worker must be defined");p(this,S,e)}},S=new WeakMap,q=new WeakMap,b=new WeakMap,m=new WeakMap,B=new WeakMap,N=new WeakMap,ge),xe=Mt,D,J,H,X,Ce,yt=(Ce=class{constructor({worker:e}){o(this,D);o(this,J);o(this,H,new Set);h(this,"initialize",({validateReceivedMessage:e})=>{p(this,J,e),n(this,D).addListener("message",n(this,X))});h(this,"sendMessage",(e,t)=>{n(this,D).postMessage(e,t)});h(this,"addMessageHandler",e=>{n(this,H).add(e)});h(this,"removeMessageHandler",e=>{n(this,H).delete(e)});h(this,"destroy",()=>{n(this,D).removeListener("message",n(this,X)),n(this,H).clear()});o(this,X,e=>{var t;if((t=n(this,J))!=null&&t.call(this,e))for(const r of n(this,H))r(e)});if(!e)throw new w("INVALID_ARGUMENT","worker must be defined");p(this,D,e)}},D=new WeakMap,J=new WeakMap,H=new WeakMap,X=new WeakMap,Ce),wt=yt,I,Q,x,Z,Se,Et=(Se=class{constructor({port:e}){o(this,I);o(this,Q);o(this,x,new Set);h(this,"initialize",({validateReceivedMessage:e})=>{p(this,Q,e),n(this,I).addEventListener("message",n(this,Z)),n(this,I).start()});h(this,"sendMessage",(e,t)=>{var r;(r=n(this,I))==null||r.postMessage(e,{transfer:t})});h(this,"addMessageHandler",e=>{n(this,x).add(e)});h(this,"removeMessageHandler",e=>{n(this,x).delete(e)});h(this,"destroy",()=>{n(this,I).removeEventListener("message",n(this,Z)),n(this,I).close(),n(this,x).clear()});o(this,Z,({data:e})=>{var t;if((t=n(this,Q))!=null&&t.call(this,e))for(const r of n(this,x))r(e)});if(!e)throw new w("INVALID_ARGUMENT","port must be defined");p(this,I,e)}},I=new WeakMap,Q=new WeakMap,x=new WeakMap,Z=new WeakMap,Se),mt=Et;const Pt=(e,{iframe:t,worker:r,webWorker:s})=>{let a;if(t)a=new He({remoteWindow:t.contentWindow,allowedOrigins:[/^http:\/\/localhost(:\d+)/,"https://extensions.archilogic.io","https://testing-extensions.archilogic.io"]});else if(r)a=new wt({worker:r});else if(s)a=new xe({worker:s});else throw new Error("No iframe or worker to connect to");return De({messenger:a,methods:e})};var ne={exports:{}},Ee;function At(){if(Ee)return ne.exports;Ee=1;function e(){}return e.prototype={on:function(t,r,s){var a=this.e||(this.e={});return(a[t]||(a[t]=[])).push({fn:r,ctx:s}),this},once:function(t,r,s){var a=this;function i(){a.off(t,i),r.apply(s,arguments)}return i._=r,this.on(t,i,s)},emit:function(t){var r=[].slice.call(arguments,1),s=((this.e||(this.e={}))[t]||[]).slice(),a=0,i=s.length;for(a;a<i;a++)s[a].fn.apply(s[a].ctx,r);return this},off:function(t,r){var s=this.e||(this.e={}),a=s[t],i=[];if(a&&r)for(var u=0,d=a.length;u<d;u++)a[u].fn!==r&&a[u].fn._!==r&&i.push(a[u]);return i.length?s[t]=i:delete s[t],this}},ne.exports=e,ne.exports.TinyEmitter=e,ne.exports}var It=At();const gt=(e={},t)=>{let r;const s=new It.TinyEmitter;if((t==null?void 0:t.useWorker)==="node"){const d=require("node:worker_threads").parentPort;if(!d)throw new Error("No parent port found for worker thread");r=new mt({port:d})}else(t==null?void 0:t.useWorker)==="web"?r=new xe({worker:self}):r=new He({remoteWindow:window.parent,allowedOrigins:[/^http:\/\/localhost(:\d+)/,/^https:\/\/(.*)app.archilogic.com/,/^https:\/\/(.*).archilogic-frontend.com/]});const a={onConnect:()=>{},onDestroy:()=>{},...e,onLayoutChange:d=>{s.emit("layout-change",d)},onSelectionChange:d=>{s.emit("selection-change",d)},onGraphicDrag:d=>{s.emit("graphic-crag",d)},onCanvasClick:d=>{s.emit("canvas-click",d)}},i=De({messenger:r,methods:a});return new Proxy({},{get(d,f){return f==="on"?s.on.bind(s):f==="once"?s.once.bind(s):f==="off"?s.off.bind(s):async(...c)=>(await i.promise)[f](...c)}})};exports.createExtensionConnection=Pt;exports.createHostConnection=gt;
|
package/dist/extension-sdk.js
CHANGED
|
@@ -3,12 +3,12 @@ var fe = (e) => {
|
|
|
3
3
|
throw TypeError(e);
|
|
4
4
|
};
|
|
5
5
|
var Fe = (e, t, r) => t in e ? We(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
6
|
-
var
|
|
6
|
+
var l = (e, t, r) => Fe(e, typeof t != "symbol" ? t + "" : t, r), ve = (e, t, r) => t.has(e) || fe("Cannot " + r);
|
|
7
7
|
var n = (e, t, r) => (ve(e, t, "read from private field"), r ? r.call(e) : t.get(e)), o = (e, t, r) => t.has(e) ? fe("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), p = (e, t, r, s) => (ve(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
|
|
8
8
|
var Ue = class extends Error {
|
|
9
9
|
constructor(t, r) {
|
|
10
10
|
super(r);
|
|
11
|
-
|
|
11
|
+
l(this, "code");
|
|
12
12
|
this.name = "PenpalError", this.code = t;
|
|
13
13
|
}
|
|
14
14
|
}, w = Ue, Ve = (e) => ({
|
|
@@ -26,8 +26,8 @@ var Ue = class extends Error {
|
|
|
26
26
|
return a.name = e, a.stack = r, a;
|
|
27
27
|
}, $e = Symbol("Reply"), he, me, ze = (me = class {
|
|
28
28
|
constructor(e, t) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
l(this, "value");
|
|
30
|
+
l(this, "transferables");
|
|
31
31
|
// Allows TypeScript to distinguish between an actual instance of this
|
|
32
32
|
// class versus an object that looks structurally similar.
|
|
33
33
|
// eslint-disable-next-line no-unused-private-class-members
|
|
@@ -58,46 +58,46 @@ var Ue = class extends Error {
|
|
|
58
58
|
...r instanceof Error ? { value: Ve(r), isSerializedErrorInstance: !0 } : { value: r }
|
|
59
59
|
}), Be = (e, t, r, s) => {
|
|
60
60
|
let a = !1;
|
|
61
|
-
const
|
|
62
|
-
if (a || !Re(
|
|
61
|
+
const i = async (u) => {
|
|
62
|
+
if (a || !Re(u))
|
|
63
63
|
return;
|
|
64
|
-
s == null || s(`Received ${R(
|
|
65
|
-
const { methodPath:
|
|
66
|
-
let
|
|
64
|
+
s == null || s(`Received ${R(u.methodPath)}() call`, u);
|
|
65
|
+
const { methodPath: d, args: f, id: c } = u;
|
|
66
|
+
let h, I;
|
|
67
67
|
try {
|
|
68
|
-
const M = qe(
|
|
68
|
+
const M = qe(d, t);
|
|
69
69
|
if (!M)
|
|
70
70
|
throw new w(
|
|
71
71
|
"METHOD_NOT_FOUND",
|
|
72
|
-
`Method \`${R(
|
|
72
|
+
`Method \`${R(d)}\` is not found.`
|
|
73
73
|
);
|
|
74
|
-
let y = await M(...
|
|
75
|
-
y instanceof je && (I = y.transferables, y = await y.value),
|
|
74
|
+
let y = await M(...f);
|
|
75
|
+
y instanceof je && (I = y.transferables, y = await y.value), h = {
|
|
76
76
|
namespace: A,
|
|
77
77
|
channel: r,
|
|
78
78
|
type: "REPLY",
|
|
79
|
-
callId:
|
|
79
|
+
callId: c,
|
|
80
80
|
value: y
|
|
81
81
|
};
|
|
82
82
|
} catch (M) {
|
|
83
|
-
|
|
83
|
+
h = pe(r, c, M);
|
|
84
84
|
}
|
|
85
85
|
if (!a)
|
|
86
86
|
try {
|
|
87
|
-
s == null || s(`Sending ${R(
|
|
87
|
+
s == null || s(`Sending ${R(d)}() reply`, h), e.sendMessage(h, I);
|
|
88
88
|
} catch (M) {
|
|
89
|
-
throw M.name === "DataCloneError" && (
|
|
89
|
+
throw M.name === "DataCloneError" && (h = pe(r, c, M), s == null || s(`Sending ${R(d)}() reply`, h), e.sendMessage(h)), M;
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
return e.addMessageHandler(
|
|
93
|
-
a = !0, e.removeMessageHandler(
|
|
92
|
+
return e.addMessageHandler(i), () => {
|
|
93
|
+
a = !0, e.removeMessageHandler(i);
|
|
94
94
|
};
|
|
95
95
|
}, Je = Be, Ae, Le = ((Ae = crypto.randomUUID) == null ? void 0 : Ae.bind(crypto)) ?? (() => new Array(4).fill(0).map(
|
|
96
96
|
() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)
|
|
97
97
|
).join("-")), Xe = Symbol("CallOptions"), le, Ie, Qe = (Ie = class {
|
|
98
98
|
constructor(e) {
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
l(this, "transferables");
|
|
100
|
+
l(this, "timeout");
|
|
101
101
|
// Allows TypeScript to distinguish between an actual instance of this
|
|
102
102
|
// class versus an object that looks structurally similar.
|
|
103
103
|
// eslint-disable-next-line no-unused-private-class-members
|
|
@@ -112,8 +112,8 @@ var Ue = class extends Error {
|
|
|
112
112
|
if (a !== "then")
|
|
113
113
|
return r.length && et.has(a) ? Reflect.get(s, a) : Te(e, t, [...r, a]);
|
|
114
114
|
},
|
|
115
|
-
apply(s, a,
|
|
116
|
-
return e(r,
|
|
115
|
+
apply(s, a, i) {
|
|
116
|
+
return e(r, i);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
), Me = (e) => new w(
|
|
@@ -123,44 +123,44 @@ var Ue = class extends Error {
|
|
|
123
123
|
)}() failed due to destroyed connection`
|
|
124
124
|
), tt = (e, t, r) => {
|
|
125
125
|
let s = !1;
|
|
126
|
-
const a = /* @__PURE__ */ new Map(),
|
|
127
|
-
if (!_e(
|
|
126
|
+
const a = /* @__PURE__ */ new Map(), i = (f) => {
|
|
127
|
+
if (!_e(f))
|
|
128
128
|
return;
|
|
129
|
-
const { callId:
|
|
130
|
-
y && (a.delete(
|
|
129
|
+
const { callId: c, value: h, isError: I, isSerializedErrorInstance: M } = f, y = a.get(c);
|
|
130
|
+
y && (a.delete(c), r == null || r(
|
|
131
131
|
`Received ${R(y.methodPath)}() call`,
|
|
132
|
-
|
|
132
|
+
f
|
|
133
133
|
), I ? y.reject(
|
|
134
|
-
M ? Ye(
|
|
135
|
-
) : y.resolve(
|
|
134
|
+
M ? Ye(h) : h
|
|
135
|
+
) : y.resolve(h));
|
|
136
136
|
};
|
|
137
|
-
return e.addMessageHandler(
|
|
138
|
-
remoteProxy: Te((
|
|
137
|
+
return e.addMessageHandler(i), {
|
|
138
|
+
remoteProxy: Te((f, c) => {
|
|
139
139
|
if (s)
|
|
140
|
-
throw Me(
|
|
141
|
-
const
|
|
140
|
+
throw Me(f);
|
|
141
|
+
const h = Le(), I = c[c.length - 1], M = I instanceof Ze, { timeout: y, transferables: oe } = M ? I : {}, ee = M ? c.slice(0, -1) : c;
|
|
142
142
|
return new Promise((te, z) => {
|
|
143
143
|
const de = y !== void 0 ? window.setTimeout(() => {
|
|
144
|
-
a.delete(
|
|
144
|
+
a.delete(h), z(
|
|
145
145
|
new w(
|
|
146
146
|
"METHOD_CALL_TIMEOUT",
|
|
147
147
|
`Method call ${R(
|
|
148
|
-
|
|
148
|
+
f
|
|
149
149
|
)}() timed out after ${y}ms`
|
|
150
150
|
)
|
|
151
151
|
);
|
|
152
152
|
}, y) : void 0;
|
|
153
|
-
a.set(
|
|
153
|
+
a.set(h, { methodPath: f, resolve: te, reject: z, timeoutId: de });
|
|
154
154
|
try {
|
|
155
155
|
const O = {
|
|
156
156
|
namespace: A,
|
|
157
157
|
channel: t,
|
|
158
158
|
type: "CALL",
|
|
159
|
-
id:
|
|
160
|
-
methodPath:
|
|
159
|
+
id: h,
|
|
160
|
+
methodPath: f,
|
|
161
161
|
args: ee
|
|
162
162
|
};
|
|
163
|
-
r == null || r(`Sending ${R(
|
|
163
|
+
r == null || r(`Sending ${R(f)}() call`, O), e.sendMessage(O, oe);
|
|
164
164
|
} catch (O) {
|
|
165
165
|
z(
|
|
166
166
|
new w("TRANSMISSION_FAILED", O.message)
|
|
@@ -169,9 +169,9 @@ var Ue = class extends Error {
|
|
|
169
169
|
});
|
|
170
170
|
}, r),
|
|
171
171
|
destroy: () => {
|
|
172
|
-
s = !0, e.removeMessageHandler(
|
|
173
|
-
for (const { methodPath:
|
|
174
|
-
clearTimeout(
|
|
172
|
+
s = !0, e.removeMessageHandler(i);
|
|
173
|
+
for (const { methodPath: f, reject: c, timeoutId: h } of a.values())
|
|
174
|
+
clearTimeout(h), c(Me(f));
|
|
175
175
|
a.clear();
|
|
176
176
|
}
|
|
177
177
|
};
|
|
@@ -278,11 +278,11 @@ var Ue = class extends Error {
|
|
|
278
278
|
channel: s,
|
|
279
279
|
log: a
|
|
280
280
|
}) => {
|
|
281
|
-
const
|
|
282
|
-
let
|
|
283
|
-
const
|
|
284
|
-
let
|
|
285
|
-
const
|
|
281
|
+
const i = Le();
|
|
282
|
+
let u;
|
|
283
|
+
const d = [];
|
|
284
|
+
let f = !1;
|
|
285
|
+
const c = ke(t), { promise: h, resolve: I, reject: M } = st(), y = r !== void 0 ? setTimeout(() => {
|
|
286
286
|
M(
|
|
287
287
|
new w(
|
|
288
288
|
"CONNECTION_TIMEOUT",
|
|
@@ -290,40 +290,40 @@ var Ue = class extends Error {
|
|
|
290
290
|
)
|
|
291
291
|
);
|
|
292
292
|
}, r) : void 0, oe = () => {
|
|
293
|
-
for (const
|
|
294
|
-
|
|
293
|
+
for (const v of d)
|
|
294
|
+
v();
|
|
295
295
|
}, ee = () => {
|
|
296
|
-
if (
|
|
296
|
+
if (f)
|
|
297
297
|
return;
|
|
298
|
-
|
|
299
|
-
const { remoteProxy:
|
|
300
|
-
|
|
301
|
-
remoteProxy:
|
|
298
|
+
d.push(Je(e, t, s, a));
|
|
299
|
+
const { remoteProxy: v, destroy: _ } = rt(e, s, a);
|
|
300
|
+
d.push(_), clearTimeout(y), f = !0, I({
|
|
301
|
+
remoteProxy: v,
|
|
302
302
|
destroy: oe
|
|
303
303
|
});
|
|
304
304
|
}, te = () => {
|
|
305
|
-
const
|
|
305
|
+
const v = {
|
|
306
306
|
namespace: A,
|
|
307
307
|
type: "SYN",
|
|
308
308
|
channel: s,
|
|
309
|
-
participantId:
|
|
309
|
+
participantId: i
|
|
310
310
|
};
|
|
311
|
-
a == null || a("Sending handshake SYN",
|
|
311
|
+
a == null || a("Sending handshake SYN", v);
|
|
312
312
|
try {
|
|
313
|
-
e.sendMessage(
|
|
313
|
+
e.sendMessage(v);
|
|
314
314
|
} catch (_) {
|
|
315
315
|
M(new w("TRANSMISSION_FAILED", _.message));
|
|
316
316
|
}
|
|
317
|
-
}, z = (
|
|
318
|
-
if (a == null || a("Received handshake SYN",
|
|
319
|
-
|
|
320
|
-
|
|
317
|
+
}, z = (v) => {
|
|
318
|
+
if (a == null || a("Received handshake SYN", v), v.participantId === u && // TODO: Used for backward-compatibility. Remove in next major version.
|
|
319
|
+
u !== ce || (u = v.participantId, te(), !(i > u || // TODO: Used for backward-compatibility. Remove in next major version.
|
|
320
|
+
u === ce)))
|
|
321
321
|
return;
|
|
322
322
|
const re = {
|
|
323
323
|
namespace: A,
|
|
324
324
|
channel: s,
|
|
325
325
|
type: "ACK1",
|
|
326
|
-
methodPaths:
|
|
326
|
+
methodPaths: c
|
|
327
327
|
};
|
|
328
328
|
a == null || a("Sending handshake ACK1", re);
|
|
329
329
|
try {
|
|
@@ -332,8 +332,8 @@ var Ue = class extends Error {
|
|
|
332
332
|
M(new w("TRANSMISSION_FAILED", Oe.message));
|
|
333
333
|
return;
|
|
334
334
|
}
|
|
335
|
-
}, de = (
|
|
336
|
-
a == null || a("Received handshake ACK1",
|
|
335
|
+
}, de = (v) => {
|
|
336
|
+
a == null || a("Received handshake ACK1", v);
|
|
337
337
|
const _ = {
|
|
338
338
|
namespace: A,
|
|
339
339
|
channel: s,
|
|
@@ -347,12 +347,12 @@ var Ue = class extends Error {
|
|
|
347
347
|
return;
|
|
348
348
|
}
|
|
349
349
|
ee();
|
|
350
|
-
}, O = (
|
|
351
|
-
a == null || a("Received handshake ACK2",
|
|
352
|
-
}, ue = (
|
|
353
|
-
W(
|
|
350
|
+
}, O = (v) => {
|
|
351
|
+
a == null || a("Received handshake ACK2", v), ee();
|
|
352
|
+
}, ue = (v) => {
|
|
353
|
+
W(v) && z(v), ie(v) && de(v), j(v) && O(v);
|
|
354
354
|
};
|
|
355
|
-
return e.addMessageHandler(ue),
|
|
355
|
+
return e.addMessageHandler(ue), d.push(() => e.removeMessageHandler(ue)), te(), h;
|
|
356
356
|
}, lt = ht, ut = (e) => {
|
|
357
357
|
let t = !1, r;
|
|
358
358
|
return (...s) => (t || (t = !0, r = e(...s)), r);
|
|
@@ -371,44 +371,44 @@ var Ue = class extends Error {
|
|
|
371
371
|
"A messenger can only be used for a single connection"
|
|
372
372
|
);
|
|
373
373
|
we.add(e);
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
const
|
|
374
|
+
const i = [e.destroy], u = ft((c) => {
|
|
375
|
+
if (c) {
|
|
376
|
+
const h = {
|
|
377
377
|
namespace: A,
|
|
378
378
|
channel: s,
|
|
379
379
|
type: "DESTROY"
|
|
380
380
|
};
|
|
381
381
|
try {
|
|
382
|
-
e.sendMessage(
|
|
382
|
+
e.sendMessage(h);
|
|
383
383
|
} catch {
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
|
-
for (const
|
|
387
|
-
|
|
386
|
+
for (const h of i)
|
|
387
|
+
h();
|
|
388
388
|
a == null || a("Connection destroyed");
|
|
389
|
-
}),
|
|
389
|
+
}), d = (c) => Ke(c) && c.channel === s;
|
|
390
390
|
return {
|
|
391
391
|
promise: (async () => {
|
|
392
392
|
try {
|
|
393
|
-
e.initialize({ log: a, validateReceivedMessage:
|
|
394
|
-
Ge(I) &&
|
|
393
|
+
e.initialize({ log: a, validateReceivedMessage: d }), e.addMessageHandler((I) => {
|
|
394
|
+
Ge(I) && u(!1);
|
|
395
395
|
});
|
|
396
|
-
const { remoteProxy:
|
|
396
|
+
const { remoteProxy: c, destroy: h } = await lt({
|
|
397
397
|
messenger: e,
|
|
398
398
|
methods: t,
|
|
399
399
|
timeout: r,
|
|
400
400
|
channel: s,
|
|
401
401
|
log: a
|
|
402
402
|
});
|
|
403
|
-
return
|
|
404
|
-
} catch (
|
|
405
|
-
throw
|
|
403
|
+
return i.push(h), c;
|
|
404
|
+
} catch (c) {
|
|
405
|
+
throw u(!0), c;
|
|
406
406
|
}
|
|
407
407
|
})(),
|
|
408
408
|
// Why we don't reject the connection promise when consumer calls destroy():
|
|
409
409
|
// https://github.com/Aaronius/penpal/issues/51
|
|
410
410
|
destroy: () => {
|
|
411
|
-
|
|
411
|
+
u(!0);
|
|
412
412
|
}
|
|
413
413
|
};
|
|
414
414
|
}, De = vt, g, k, U, V, L, C, E, T, se, Y, K, G, $, Pe, pt = (Pe = class {
|
|
@@ -422,13 +422,13 @@ var Ue = class extends Error {
|
|
|
422
422
|
o(this, E);
|
|
423
423
|
// TODO: Used for backward-compatibility. Remove in next major version.
|
|
424
424
|
o(this, T, !1);
|
|
425
|
-
|
|
425
|
+
l(this, "initialize", ({
|
|
426
426
|
log: e,
|
|
427
427
|
validateReceivedMessage: t
|
|
428
428
|
}) => {
|
|
429
429
|
p(this, U, e), p(this, V, t), window.addEventListener("message", n(this, G));
|
|
430
430
|
});
|
|
431
|
-
|
|
431
|
+
l(this, "sendMessage", (e, t) => {
|
|
432
432
|
if (W(e)) {
|
|
433
433
|
const r = n(this, Y).call(this, e);
|
|
434
434
|
n(this, g).postMessage(e, {
|
|
@@ -451,9 +451,9 @@ var Ue = class extends Error {
|
|
|
451
451
|
if (j(e)) {
|
|
452
452
|
const { port1: r, port2: s } = new MessageChannel();
|
|
453
453
|
p(this, E, r), r.addEventListener("message", n(this, $)), r.start();
|
|
454
|
-
const a = [s, ...t || []],
|
|
454
|
+
const a = [s, ...t || []], i = n(this, Y).call(this, e);
|
|
455
455
|
n(this, g).postMessage(e, {
|
|
456
|
-
targetOrigin:
|
|
456
|
+
targetOrigin: i,
|
|
457
457
|
transfer: a
|
|
458
458
|
});
|
|
459
459
|
return;
|
|
@@ -466,13 +466,13 @@ var Ue = class extends Error {
|
|
|
466
466
|
}
|
|
467
467
|
throw new F("Port is undefined");
|
|
468
468
|
});
|
|
469
|
-
|
|
469
|
+
l(this, "addMessageHandler", (e) => {
|
|
470
470
|
n(this, C).add(e);
|
|
471
471
|
});
|
|
472
|
-
|
|
472
|
+
l(this, "removeMessageHandler", (e) => {
|
|
473
473
|
n(this, C).delete(e);
|
|
474
474
|
});
|
|
475
|
-
|
|
475
|
+
l(this, "destroy", () => {
|
|
476
476
|
window.removeEventListener("message", n(this, G)), n(this, K).call(this), n(this, C).clear();
|
|
477
477
|
});
|
|
478
478
|
o(this, se, (e) => n(this, k).some(
|
|
@@ -495,13 +495,13 @@ var Ue = class extends Error {
|
|
|
495
495
|
ports: r,
|
|
496
496
|
data: s
|
|
497
497
|
}) => {
|
|
498
|
-
var a,
|
|
498
|
+
var a, i, u;
|
|
499
499
|
if (e === n(this, g) && (it(s) && ((a = n(this, U)) == null || a.call(
|
|
500
500
|
this,
|
|
501
501
|
"Please upgrade the child window to the latest version of Penpal."
|
|
502
|
-
), p(this, T, !0), s = dt(s)), !!((
|
|
502
|
+
), p(this, T, !0), s = dt(s)), !!((i = n(this, V)) != null && i.call(this, s)))) {
|
|
503
503
|
if (!n(this, se).call(this, t)) {
|
|
504
|
-
(
|
|
504
|
+
(u = n(this, U)) == null || u.call(
|
|
505
505
|
this,
|
|
506
506
|
`Received a message from origin \`${t}\` which did not match allowed origins \`[${n(this, k).join(", ")}]\``
|
|
507
507
|
);
|
|
@@ -514,8 +514,8 @@ var Ue = class extends Error {
|
|
|
514
514
|
throw new F("No port received on ACK2");
|
|
515
515
|
n(this, E).addEventListener("message", n(this, $)), n(this, E).start();
|
|
516
516
|
}
|
|
517
|
-
for (const
|
|
518
|
-
|
|
517
|
+
for (const d of n(this, C))
|
|
518
|
+
d(s);
|
|
519
519
|
}
|
|
520
520
|
});
|
|
521
521
|
o(this, $, ({ data: e }) => {
|
|
@@ -534,10 +534,10 @@ var Ue = class extends Error {
|
|
|
534
534
|
o(this, q);
|
|
535
535
|
o(this, b, /* @__PURE__ */ new Set());
|
|
536
536
|
o(this, m);
|
|
537
|
-
|
|
537
|
+
l(this, "initialize", ({ validateReceivedMessage: e }) => {
|
|
538
538
|
p(this, q, e), n(this, S).addEventListener("message", n(this, N));
|
|
539
539
|
});
|
|
540
|
-
|
|
540
|
+
l(this, "sendMessage", (e, t) => {
|
|
541
541
|
if (W(e) || ie(e)) {
|
|
542
542
|
n(this, S).postMessage(e, { transfer: t });
|
|
543
543
|
return;
|
|
@@ -557,13 +557,13 @@ var Ue = class extends Error {
|
|
|
557
557
|
}
|
|
558
558
|
throw new F("Port is undefined");
|
|
559
559
|
});
|
|
560
|
-
|
|
560
|
+
l(this, "addMessageHandler", (e) => {
|
|
561
561
|
n(this, b).add(e);
|
|
562
562
|
});
|
|
563
|
-
|
|
563
|
+
l(this, "removeMessageHandler", (e) => {
|
|
564
564
|
n(this, b).delete(e);
|
|
565
565
|
});
|
|
566
|
-
|
|
566
|
+
l(this, "destroy", () => {
|
|
567
567
|
n(this, S).removeEventListener("message", n(this, N)), n(this, B).call(this), n(this, b).clear();
|
|
568
568
|
});
|
|
569
569
|
o(this, B, () => {
|
|
@@ -591,19 +591,19 @@ var Ue = class extends Error {
|
|
|
591
591
|
o(this, D);
|
|
592
592
|
o(this, J);
|
|
593
593
|
o(this, H, /* @__PURE__ */ new Set());
|
|
594
|
-
|
|
594
|
+
l(this, "initialize", ({ validateReceivedMessage: e }) => {
|
|
595
595
|
p(this, J, e), n(this, D).addListener("message", n(this, X));
|
|
596
596
|
});
|
|
597
|
-
|
|
597
|
+
l(this, "sendMessage", (e, t) => {
|
|
598
598
|
n(this, D).postMessage(e, t);
|
|
599
599
|
});
|
|
600
|
-
|
|
600
|
+
l(this, "addMessageHandler", (e) => {
|
|
601
601
|
n(this, H).add(e);
|
|
602
602
|
});
|
|
603
|
-
|
|
603
|
+
l(this, "removeMessageHandler", (e) => {
|
|
604
604
|
n(this, H).delete(e);
|
|
605
605
|
});
|
|
606
|
-
|
|
606
|
+
l(this, "destroy", () => {
|
|
607
607
|
n(this, D).removeListener("message", n(this, X)), n(this, H).clear();
|
|
608
608
|
});
|
|
609
609
|
o(this, X, (e) => {
|
|
@@ -621,22 +621,22 @@ var Ue = class extends Error {
|
|
|
621
621
|
o(this, P);
|
|
622
622
|
o(this, Q);
|
|
623
623
|
o(this, x, /* @__PURE__ */ new Set());
|
|
624
|
-
|
|
624
|
+
l(this, "initialize", ({ validateReceivedMessage: e }) => {
|
|
625
625
|
p(this, Q, e), n(this, P).addEventListener("message", n(this, Z)), n(this, P).start();
|
|
626
626
|
});
|
|
627
|
-
|
|
627
|
+
l(this, "sendMessage", (e, t) => {
|
|
628
628
|
var r;
|
|
629
629
|
(r = n(this, P)) == null || r.postMessage(e, {
|
|
630
630
|
transfer: t
|
|
631
631
|
});
|
|
632
632
|
});
|
|
633
|
-
|
|
633
|
+
l(this, "addMessageHandler", (e) => {
|
|
634
634
|
n(this, x).add(e);
|
|
635
635
|
});
|
|
636
|
-
|
|
636
|
+
l(this, "removeMessageHandler", (e) => {
|
|
637
637
|
n(this, x).delete(e);
|
|
638
638
|
});
|
|
639
|
-
|
|
639
|
+
l(this, "destroy", () => {
|
|
640
640
|
n(this, P).removeEventListener("message", n(this, Z)), n(this, P).close(), n(this, x).clear();
|
|
641
641
|
});
|
|
642
642
|
o(this, Z, ({ data: e }) => {
|
|
@@ -696,23 +696,23 @@ function At() {
|
|
|
696
696
|
},
|
|
697
697
|
once: function(t, r, s) {
|
|
698
698
|
var a = this;
|
|
699
|
-
function
|
|
700
|
-
a.off(t,
|
|
699
|
+
function i() {
|
|
700
|
+
a.off(t, i), r.apply(s, arguments);
|
|
701
701
|
}
|
|
702
|
-
return
|
|
702
|
+
return i._ = r, this.on(t, i, s);
|
|
703
703
|
},
|
|
704
704
|
emit: function(t) {
|
|
705
|
-
var r = [].slice.call(arguments, 1), s = ((this.e || (this.e = {}))[t] || []).slice(), a = 0,
|
|
706
|
-
for (a; a <
|
|
705
|
+
var r = [].slice.call(arguments, 1), s = ((this.e || (this.e = {}))[t] || []).slice(), a = 0, i = s.length;
|
|
706
|
+
for (a; a < i; a++)
|
|
707
707
|
s[a].fn.apply(s[a].ctx, r);
|
|
708
708
|
return this;
|
|
709
709
|
},
|
|
710
710
|
off: function(t, r) {
|
|
711
|
-
var s = this.e || (this.e = {}), a = s[t],
|
|
711
|
+
var s = this.e || (this.e = {}), a = s[t], i = [];
|
|
712
712
|
if (a && r)
|
|
713
|
-
for (var
|
|
714
|
-
a[
|
|
715
|
-
return
|
|
713
|
+
for (var u = 0, d = a.length; u < d; u++)
|
|
714
|
+
a[u].fn !== r && a[u].fn._ !== r && i.push(a[u]);
|
|
715
|
+
return i.length ? s[t] = i : delete s[t], this;
|
|
716
716
|
}
|
|
717
717
|
}, ne.exports = e, ne.exports.TinyEmitter = e, ne.exports;
|
|
718
718
|
}
|
|
@@ -721,10 +721,10 @@ const Ct = (e = {}, t) => {
|
|
|
721
721
|
let r;
|
|
722
722
|
const s = new It.TinyEmitter();
|
|
723
723
|
if ((t == null ? void 0 : t.useWorker) === "node") {
|
|
724
|
-
const
|
|
725
|
-
if (!
|
|
724
|
+
const d = require("node:worker_threads").parentPort;
|
|
725
|
+
if (!d)
|
|
726
726
|
throw new Error("No parent port found for worker thread");
|
|
727
|
-
r = new mt({ port:
|
|
727
|
+
r = new mt({ port: d });
|
|
728
728
|
} else (t == null ? void 0 : t.useWorker) === "web" ? r = new xe({ worker: self }) : r = new He({
|
|
729
729
|
remoteWindow: window.parent,
|
|
730
730
|
// Defaults to the current origin.
|
|
@@ -734,30 +734,37 @@ const Ct = (e = {}, t) => {
|
|
|
734
734
|
/^https:\/\/(.*).archilogic-frontend.com/
|
|
735
735
|
]
|
|
736
736
|
});
|
|
737
|
-
const a =
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
737
|
+
const a = {
|
|
738
|
+
/**
|
|
739
|
+
* event handler for initial connection of the extension
|
|
740
|
+
* for a headless extension ( without UI ) the host will await this method before it terminates the extension
|
|
741
|
+
*/
|
|
742
|
+
onConnect: () => {
|
|
743
|
+
},
|
|
744
|
+
onDestroy: () => {
|
|
745
|
+
},
|
|
746
|
+
...e,
|
|
747
|
+
onLayoutChange: (d) => {
|
|
748
|
+
s.emit("layout-change", d);
|
|
749
|
+
},
|
|
750
|
+
onSelectionChange: (d) => {
|
|
751
|
+
s.emit("selection-change", d);
|
|
752
|
+
},
|
|
753
|
+
onGraphicDrag: (d) => {
|
|
754
|
+
s.emit("graphic-crag", d);
|
|
755
|
+
},
|
|
756
|
+
onCanvasClick: (d) => {
|
|
757
|
+
s.emit("canvas-click", d);
|
|
754
758
|
}
|
|
759
|
+
}, i = De({
|
|
760
|
+
messenger: r,
|
|
761
|
+
methods: a
|
|
755
762
|
});
|
|
756
763
|
return new Proxy(
|
|
757
764
|
{},
|
|
758
765
|
{
|
|
759
|
-
get(
|
|
760
|
-
return
|
|
766
|
+
get(d, f) {
|
|
767
|
+
return f === "on" ? s.on.bind(s) : f === "once" ? s.once.bind(s) : f === "off" ? s.off.bind(s) : async (...c) => (await i.promise)[f](...c);
|
|
761
768
|
}
|
|
762
769
|
}
|
|
763
770
|
);
|
package/dist/index.d.ts
CHANGED
|
@@ -290,7 +290,7 @@ export declare const createExtensionConnection: (methods: any, { iframe, worker,
|
|
|
290
290
|
* hostApi.on('layout-change', () => console.log('layout updated'))
|
|
291
291
|
* const spaces = await hostApi.getSpaces()
|
|
292
292
|
*/
|
|
293
|
-
export declare const createHostConnection: (
|
|
293
|
+
export declare const createHostConnection: (extensionMethods?: Partial<ExtensionApi>, options?: ConnectionOptions) => HostApi;
|
|
294
294
|
|
|
295
295
|
declare class CuboidGeometry extends ParametricGeometryBase {
|
|
296
296
|
type: CuboidGeometryType;
|
|
@@ -1049,9 +1049,9 @@ export declare type HostApi = {
|
|
|
1049
1049
|
selectNodes: (args: {
|
|
1050
1050
|
nodeIds: string[];
|
|
1051
1051
|
}) => Promise<NodeResult[]>;
|
|
1052
|
-
on: <K extends ExtensionEventKey>(event: K, listener: ExtensionEventListener<K
|
|
1053
|
-
once: <K extends ExtensionEventKey>(event: K, listener: ExtensionEventListener<K
|
|
1054
|
-
off: <K extends ExtensionEventKey>(event: K, listener
|
|
1052
|
+
on: <K extends ExtensionEventKey>(event: K, listener: ExtensionEventListener<K>, ctx?: unknown) => void;
|
|
1053
|
+
once: <K extends ExtensionEventKey>(event: K, listener: ExtensionEventListener<K>, ctx?: unknown) => void;
|
|
1054
|
+
off: <K extends ExtensionEventKey>(event: K, listener?: ExtensionEventListener<K>) => void;
|
|
1055
1055
|
};
|
|
1056
1056
|
|
|
1057
1057
|
export declare type HostApiSync = {
|
|
@@ -2897,8 +2897,14 @@ declare class SpaceGraphBuilding extends SpaceGraphSpatialStructureBase {
|
|
|
2897
2897
|
type: SpaceGraphBuildingType;
|
|
2898
2898
|
location: SpaceGraphLocation;
|
|
2899
2899
|
floors: SpaceGraphFloor[];
|
|
2900
|
+
/** multiple floors can be on the same level */
|
|
2901
|
+
floorsByLevel: Record<string, SpaceGraphFloor[]>;
|
|
2900
2902
|
constructor(id: string);
|
|
2901
2903
|
copyForClone(building: SpaceGraphBuilding): void;
|
|
2904
|
+
/**
|
|
2905
|
+
* returns levels sorted by the vertical position of the first floor with that level
|
|
2906
|
+
*/
|
|
2907
|
+
getLevelOrder(): string[];
|
|
2902
2908
|
insertFloor(floor: SpaceGraphFloor): void;
|
|
2903
2909
|
removeFloor(floor: SpaceGraphFloor): void;
|
|
2904
2910
|
createFloor(id: string): SpaceGraphFloor;
|
|
@@ -2996,6 +3002,7 @@ declare const SpaceGraphEmbeddedMaterialTypeValue = "material:embedded";
|
|
|
2996
3002
|
declare interface SpaceGraphEventMap {
|
|
2997
3003
|
'spatial-structure-create': [SpaceGraphSpatialStructure];
|
|
2998
3004
|
'spatial-structure-delete': [SpaceGraphSpatialStructure];
|
|
3005
|
+
'floor-transform-change': [SpaceGraphFloor];
|
|
2999
3006
|
'product-create': [SpaceGraphProduct];
|
|
3000
3007
|
'product-delete': [SpaceGraphProduct];
|
|
3001
3008
|
'material-create': [SpaceGraphMaterial];
|
|
@@ -3042,9 +3049,13 @@ declare class SpaceGraphFloor extends SpaceGraphSpatialStructureBase {
|
|
|
3042
3049
|
parent: SpaceGraphBuilding | null;
|
|
3043
3050
|
position: Vector3;
|
|
3044
3051
|
rotation: number;
|
|
3052
|
+
level: string | null;
|
|
3045
3053
|
layouts: SpaceGraphLayout[];
|
|
3046
3054
|
constructor(id: string);
|
|
3047
3055
|
copyForClone(floor: SpaceGraphFloor): void;
|
|
3056
|
+
setPosition(position: Vector3): void;
|
|
3057
|
+
setRotation(rotation: number): void;
|
|
3058
|
+
setTransform(position: Vector3, rotation: number): void;
|
|
3048
3059
|
insertLayout(layout: SpaceGraphLayout): void;
|
|
3049
3060
|
removeLayout(layout: SpaceGraphLayout): void;
|
|
3050
3061
|
createLayout(id: string): SpaceGraphLayout;
|
|
@@ -3059,6 +3070,7 @@ declare interface SpaceGraphFloorJson extends SpaceGraphSpatialStructureBaseJson
|
|
|
3059
3070
|
type: SpaceGraphFloorType;
|
|
3060
3071
|
position: Vector3;
|
|
3061
3072
|
rotation: number;
|
|
3073
|
+
level?: string;
|
|
3062
3074
|
layouts: SpaceGraphLayoutJson[];
|
|
3063
3075
|
}
|
|
3064
3076
|
|
|
@@ -3246,7 +3258,6 @@ declare type SpaceGraphProductAttributesJson = {
|
|
|
3246
3258
|
};
|
|
3247
3259
|
|
|
3248
3260
|
declare class SpaceGraphProductBase extends SpaceGraphNodeWithCustomAttributesBase {
|
|
3249
|
-
#private;
|
|
3250
3261
|
type: SpaceGraphProductType;
|
|
3251
3262
|
attributes: SpaceGraphProductAttributes;
|
|
3252
3263
|
instances: Set<LayoutAsset>;
|