UNPKG

@attio/react-native-bottom-sheet-toolbox-dev-tools

Version:
2 lines 18.5 kB
"use strict";(self.webpackChunkweb_ui=self.webpackChunkweb_ui||[]).push([["688"],{399:function(e){var t=Object.prototype.hasOwnProperty,n="~";function s(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function i(e,t,s,i,o){if("function"!=typeof s)throw TypeError("The listener must be a function");var a=new r(s,i||e,o),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function o(e,t){0==--e._eventsCount?e._events=new s:delete e._events[t]}function a(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(n=!1)),a.prototype.eventNames=function(){var e,s,r=[];if(0===this._eventsCount)return r;for(s in e=this._events)t.call(e,s)&&r.push(n?s.slice(1):s);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},a.prototype.listeners=function(e){var t=n?n+e:e,s=this._events[t];if(!s)return[];if(s.fn)return[s.fn];for(var r=0,i=s.length,o=Array(i);r<i;r++)o[r]=s[r].fn;return o},a.prototype.listenerCount=function(e){var t=n?n+e:e,s=this._events[t];return s?s.fn?1:s.length:0},a.prototype.emit=function(e,t,s,r,i,o){var a=n?n+e:e;if(!this._events[a])return!1;var c,l,u=this._events[a],d=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),d){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,s),!0;case 4:return u.fn.call(u.context,t,s,r),!0;case 5:return u.fn.call(u.context,t,s,r,i),!0;case 6:return u.fn.call(u.context,t,s,r,i,o),!0}for(l=1,c=Array(d-1);l<d;l++)c[l-1]=arguments[l];u.fn.apply(u.context,c)}else{var h,f=u.length;for(l=0;l<f;l++)switch(u[l].once&&this.removeListener(e,u[l].fn,void 0,!0),d){case 1:u[l].fn.call(u[l].context);break;case 2:u[l].fn.call(u[l].context,t);break;case 3:u[l].fn.call(u[l].context,t,s);break;case 4:u[l].fn.call(u[l].context,t,s,r);break;default:if(!c)for(h=1,c=Array(d-1);h<d;h++)c[h-1]=arguments[h];u[l].fn.apply(u[l].context,c)}}return!0},a.prototype.on=function(e,t,n){return i(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return i(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,s,r){var i=n?n+e:e;if(!this._events[i])return this;if(!t)return o(this,i),this;var a=this._events[i];if(a.fn)a.fn!==t||r&&!a.once||s&&a.context!==s||o(this,i);else{for(var c=0,l=[],u=a.length;c<u;c++)(a[c].fn!==t||r&&!a[c].once||s&&a[c].context!==s)&&l.push(a[c]);l.length?this._events[i]=1===l.length?l[0]:l:o(this,i)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&o(this,t)):(this._events=new s,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a},803:function(e,t,n){n.d(t,{Z:()=>i});var s=n(735);function r(e,t,n){return e[t]?e[t][0]?e[t][0][n]:e[t][n]:"contentBoxSize"===t?e.contentRect["inlineSize"===n?"width":"height"]:void 0}function i(e){void 0===e&&(e={});var t,n,i,o,a,c,l=e.onResize,u=(0,s.useRef)(void 0);u.current=l;var d=e.round||Math.round,h=(0,s.useRef)(),f=(0,s.useState)({width:void 0,height:void 0}),v=f[0],p=f[1],w=(0,s.useRef)(!1);(0,s.useEffect)(function(){return w.current=!1,function(){w.current=!0}},[]);var y=(0,s.useRef)({width:void 0,height:void 0}),m=(t=(0,s.useCallback)(function(t){return h.current&&h.current.box===e.box&&h.current.round===d||(h.current={box:e.box,round:d,instance:new ResizeObserver(function(t){var n=t[0],s="border-box"===e.box?"borderBoxSize":"device-pixel-content-box"===e.box?"devicePixelContentBoxSize":"contentBoxSize",i=r(n,s,"inlineSize"),o=r(n,s,"blockSize"),a=i?d(i):void 0,c=o?d(o):void 0;if(y.current.width!==a||y.current.height!==c){var l={width:a,height:c};y.current.width=a,y.current.height=c,u.current?u.current(l):w.current||p(l)}})}),h.current.instance.observe(t,{box:e.box}),function(){h.current&&h.current.instance.unobserve(t)}},[e.box,d]),n=e.ref,i=(0,s.useRef)(null),(o=(0,s.useRef)(null)).current=n,a=(0,s.useRef)(null),(0,s.useEffect)(function(){c()}),c=(0,s.useCallback)(function(){var e=a.current,n=o.current,s=e||(n?n instanceof Element?n:n.current:null);i.current&&i.current.element===s&&i.current.subscriber===t||(i.current&&i.current.cleanup&&i.current.cleanup(),i.current={element:s,subscriber:t,cleanup:s?t(s):void 0})},[t]),(0,s.useEffect)(function(){return function(){i.current&&i.current.cleanup&&(i.current.cleanup(),i.current=null)}},[]),(0,s.useCallback)(function(e){a.current=e,c()},[c]));return(0,s.useMemo)(function(){return{ref:m,width:v.width,height:v.height}},[m,v.width,v.height])}},633:function(e,t,n){n.d(t,{yo:()=>p});var s=n(331);function r(e){return"function"==typeof e.arrayBuffer?e.arrayBuffer():i(e)}async function i(e){return new Promise((t,n)=>{let s=new FileReader;s.onload=()=>{t(s.result)},s.onerror=n,s.readAsArrayBuffer(e)})}class o{pack(e){let{messageKey:t,payload:n}=e;return this.isFastPathPayload(n)?JSON.stringify({messageKey:t,payload:n}):n instanceof Blob?new Promise(async(e,s)=>{try{let s=await r(n);e(this.packImpl({messageKey:t,payload:new Uint8Array(s)},8))}catch(e){s(e)}}):this.packImpl({messageKey:t,payload:n},void 0)}unpack(e){if("string"==typeof e)return JSON.parse(e);let t=new DataView(e,0,4).getUint32(0,!1),n=e.slice(4,4+t),s=JSON.parse(this.textDecoder.decode(n)),r=new DataView(e,4+t,1).getUint8(0),i=e.slice(4+t+1);return{messageKey:s,payload:this.deserializePayload(i,r)}}isFastPathPayload(e){if(null==e)return!0;let t=typeof e;return"string"===t||"number"===t||"object"===t&&e.constructor===Object}payloadToUint8Array(e){if(e instanceof Uint8Array)return e;if("string"==typeof e)return this.textEncoder.encode(e);if("number"==typeof e){let t=new ArrayBuffer(8);return new DataView(t).setFloat64(0,e,!1),new Uint8Array(t)}if(null===e)return new Uint8Array(0);if(void 0===e)return new Uint8Array(0);else if(e instanceof ArrayBuffer)return new Uint8Array(e);else if(!(e instanceof Blob))return this.textEncoder.encode(JSON.stringify(e));else throw Error("Blob is not supported in this callsite.")}packImpl(e,t){let{messageKey:n,payload:s}=e,r=JSON.stringify(n),i=this.textEncoder.encode(r),a=i.length,c=this.payloadToUint8Array(s),l=new ArrayBuffer(4+a+1+c.byteLength),u=new Uint8Array(l);return new DataView(l,0,4).setUint32(0,a,!1),u.set(i,4),new DataView(l,4+a,1).setUint8(0,t??o.getPayloadTypeIndicator(s)),u.set(c,4+a+1),u}deserializePayload(e,t){switch(t){case 1:return new Uint8Array(e);case 2:return this.textDecoder.decode(e);case 3:return new DataView(e).getFloat64(0,!1);case 4:return null;case 5:return;case 6:return JSON.parse(this.textDecoder.decode(e));case 7:return e;case 8:return new Blob([e]);default:throw Error("Unsupported payload type")}}static getPayloadTypeIndicator(e){if(e instanceof Uint8Array)return 1;if("string"==typeof e)return 2;if("number"==typeof e)return 3;if(null===e)return 4;if(void 0===e)return 5;else if(e instanceof ArrayBuffer)return 7;else if(e instanceof Blob)return 8;else if("object"==typeof e)return 6;else throw Error("Unsupported payload type")}constructor(){(0,s._)(this,"textEncoder",new TextEncoder),(0,s._)(this,"textDecoder",new TextDecoder)}}class a{close(e,t){if(this.clearConnectTimeoutIfNeeded(),this.emitEvent("close",this.lastCloseEvent??{code:e??1e3,reason:t??"Explicit closing",message:"Explicit closing"}),this.lastCloseEvent=null,this.isClosed=!0,this.eventListeners=Object.create(null),this.sendQueue=[],null!=this.ws){let e=this.ws;this.ws=null,this.wsClose(e)}}addEventListener(e,t){(this.eventListeners[e]||(this.eventListeners[e]=new Set)).add(t)}removeEventListener(e,t){var n;null==(n=this.eventListeners[e])||n.delete(t)}connect(){null==this.ws&&(this.connectTimeoutHandle=setTimeout(this.handleConnectTimeout,this.connectTimeout),this.ws=new WebSocket(this.url.toString()),null!=this.wsBinaryType&&(this.ws.binaryType=this.wsBinaryType),this.ws.addEventListener("message",this.handleMessage),this.ws.addEventListener("open",this.handleOpen),this.ws.addEventListener("error",this.handleError),this.ws.addEventListener("close",this.handleClose))}send(e){if(this.isClosed)return void this.onError(Error("Unable to send data: WebSocket is closed"));if(this.retries>=this.maxRetries)return void this.onError(Error(`Unable to send data: Exceeded max retries - retries[${this.retries}]`));let t=this.ws;null!=t&&t.readyState===WebSocket.OPEN?t.send(e):this.sendQueue.push(e)}emitEvent(e,t){let n=this.eventListeners[e];if(n)for(let e of n)e(t)}clearConnectTimeoutIfNeeded(){null!=this.connectTimeoutHandle&&(clearTimeout(this.connectTimeoutHandle),this.connectTimeoutHandle=null)}reconnectIfNeeded(e){if(null!=this.ws&&(this.wsClose(this.ws),this.ws=null),!this.isClosed){if(this.retries>=this.maxRetries){this.onError(Error("Exceeded max retries")),this.close();return}setTimeout(()=>{this.retries+=1,this.connect(),this.onReconnect(e)},this.retriesInterval)}}wsClose(e){try{e.removeEventListener("message",this.handleMessage),e.removeEventListener("open",this.handleOpen),e.removeEventListener("close",this.handleClose),e.onerror=()=>{},e.close()}catch{}}get readyState(){var e;if(this.isClosed)return WebSocket.CLOSED;let t=null==(e=this.ws)?void 0:e.readyState;return t===WebSocket.CLOSED?WebSocket.CONNECTING:t??WebSocket.CONNECTING}get binaryType(){var e;return(null==(e=this.ws)?void 0:e.binaryType)??"blob"}get bufferedAmount(){var e;return(null==(e=this.ws)?void 0:e.bufferedAmount)??0}get extensions(){var e;return(null==(e=this.ws)?void 0:e.extensions)??""}get protocol(){var e;return(null==(e=this.ws)?void 0:e.protocol)??""}ping(){var e;return null==(e=this.ws)?void 0:e.ping()}dispatchEvent(e){var t;return(null==(t=this.ws)?void 0:t.dispatchEvent(e))??!1}set onclose(e){throw Error("Unsupported legacy property, use addEventListener instead")}set onerror(e){throw Error("Unsupported legacy property, use addEventListener instead")}set onmessage(e){throw Error("Unsupported legacy property, use addEventListener instead")}set onopen(e){throw Error("Unsupported legacy property, use addEventListener instead")}constructor(e,t){(0,s._)(this,"url",void 0),(0,s._)(this,"retriesInterval",void 0),(0,s._)(this,"maxRetries",void 0),(0,s._)(this,"connectTimeout",void 0),(0,s._)(this,"onError",void 0),(0,s._)(this,"onReconnect",void 0),(0,s._)(this,"ws",void 0),(0,s._)(this,"retries",void 0),(0,s._)(this,"connectTimeoutHandle",void 0),(0,s._)(this,"isClosed",void 0),(0,s._)(this,"sendQueue",void 0),(0,s._)(this,"lastCloseEvent",void 0),(0,s._)(this,"eventListeners",void 0),(0,s._)(this,"wsBinaryType",void 0),(0,s._)(this,"handleOpen",void 0),(0,s._)(this,"handleMessage",void 0),(0,s._)(this,"handleError",void 0),(0,s._)(this,"handleClose",void 0),(0,s._)(this,"handleConnectTimeout",void 0),(0,s._)(this,"CONNECTING",void 0),(0,s._)(this,"OPEN",void 0),(0,s._)(this,"CLOSING",void 0),(0,s._)(this,"CLOSED",void 0),this.url=e,this.ws=null,this.retries=0,this.connectTimeoutHandle=null,this.isClosed=!1,this.sendQueue=[],this.lastCloseEvent=null,this.handleOpen=()=>{this.clearConnectTimeoutIfNeeded(),this.lastCloseEvent=null,this.emitEvent("open");let e=this.sendQueue;for(let t of(this.sendQueue=[],e))this.send(t)},this.handleMessage=e=>{this.emitEvent("message",e)},this.handleError=e=>{this.clearConnectTimeoutIfNeeded(),this.emitEvent("error",e),this.reconnectIfNeeded(`WebSocket error - ${e.message}`)},this.handleClose=e=>{this.clearConnectTimeoutIfNeeded(),this.lastCloseEvent={code:e.code,reason:e.reason,message:e.message},this.reconnectIfNeeded(`WebSocket closed - code[${e.code}] reason[${e.reason}]`)},this.handleConnectTimeout=()=>{this.reconnectIfNeeded("Timeout from connecting to the WebSocket")},this.CONNECTING=0,this.OPEN=1,this.CLOSING=2,this.CLOSED=3,this.retriesInterval=(null==t?void 0:t.retriesInterval)??1500,this.maxRetries=(null==t?void 0:t.maxRetries)??200,this.connectTimeout=(null==t?void 0:t.connectTimeout)??5e3,this.onError=(null==t?void 0:t.onError)??(e=>{throw e}),this.onReconnect=(null==t?void 0:t.onReconnect)??(()=>{}),this.wsBinaryType=null==t?void 0:t.binaryType,this.eventListeners=Object.create(null),this.connect()}}function c(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n]}function l(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n]}class u{async initAsync(){null==this.wsStore.ws&&(this.wsStore.ws=await this.connectAsync()),this.wsStore.refCount+=1,this.wsStore.ws.addEventListener("message",this.handleMessage)}async closeAsync(){var e,t;this.isClosed=!0,null==(e=this.wsStore.ws)||e.removeEventListener("message",this.handleMessage),this.wsStore.refCount-=1,this.wsStore.refCount<1&&(null==(t=this.wsStore.ws)||t.close(),this.wsStore.ws=null),this.listeners=Object.create(null)}sendMessage(e,t){var n,s;if((null==(n=this.wsStore.ws)?void 0:n.readyState)===WebSocket.CLOSED)return void l("Unable to send message in a disconnected state.");let r={pluginName:this.connectionInfo.pluginName,method:e},i=this.messageFramePacker.pack({messageKey:r,payload:t});if(!(i instanceof Promise)){null==(s=this.wsStore.ws)||s.send(i);return}i.then(e=>{var t;null==(t=this.wsStore.ws)||t.send(e)})}addMessageListener(e,t){return(this.listeners[e]||(this.listeners[e]=new Set)).add(t),{remove:()=>{var n;null==(n=this.listeners[e])||n.delete(t)}}}addMessageListenerOnce(e,t){let n=s=>{var r;t(s),null==(r=this.listeners[e])||r.delete(n)};this.addMessageListener(e,n)}sendHandshakeMessage(e){var t,n;if((null==(t=this.wsStore.ws)?void 0:t.readyState)===WebSocket.CLOSED)return void l("Unable to send message in a disconnected state.");null==(n=this.wsStore.ws)||n.send(JSON.stringify({...e,__isHandshakeMessages:!0}))}addHandskakeMessageListener(e){var t;let n=t=>{if("string"!=typeof t.data)return;let n=JSON.parse(t.data);n.__isHandshakeMessages&&(delete n.__isHandshakeMessages,n.pluginName&&n.pluginName!==this.connectionInfo.pluginName||e(n))};return null==(t=this.wsStore.ws)||t.addEventListener("message",n),{remove:()=>{var e;null==(e=this.wsStore.ws)||e.removeEventListener("message",n)}}}isConnected(){var e;return(null==(e=this.wsStore.ws)?void 0:e.readyState)===WebSocket.OPEN}connectAsync(){return new Promise((e,t)=>{var n;let s=new a(`ws://${this.connectionInfo.devServer}/expo-dev-plugins/broadcast`,{binaryType:null==(n=this.options)?void 0:n.websocketBinaryType,onError:e=>{e instanceof Error?console.warn(`Error happened from the WebSocket connection: ${e.message} ${e.stack}`):console.warn(`Error happened from the WebSocket connection: ${JSON.stringify(e)}`)}});s.addEventListener("open",()=>{e(s)}),s.addEventListener("error",e=>{t(e)}),s.addEventListener("close",e=>{c("WebSocket closed",e.code,e.reason)})})}getWebSocketBackingStore(){return this.wsStore}constructor(e,t){(0,s._)(this,"connectionInfo",void 0),(0,s._)(this,"options",void 0),(0,s._)(this,"listeners",void 0),(0,s._)(this,"wsStore",void 0),(0,s._)(this,"isClosed",void 0),(0,s._)(this,"retries",void 0),(0,s._)(this,"messageFramePacker",void 0),(0,s._)(this,"handleMessage",void 0),this.connectionInfo=e,this.options=t,this.wsStore=u.defaultWSStore,this.isClosed=!1,this.retries=0,this.messageFramePacker=new o,this.handleMessage=async e=>{let t;if("string"==typeof e.data)t=e.data;else if(e.data instanceof ArrayBuffer)t=e.data;else if(ArrayBuffer.isView(e.data))t=e.data.buffer;else{if(!(e.data instanceof Blob))return void l("Unsupported received data type in handleMessageImpl");t=await r(e.data)}let{messageKey:n,payload:s,...i}=this.messageFramePacker.unpack(t);if((null==i?void 0:i.__isHandshakeMessages)===!0||n.pluginName&&n.pluginName!==this.connectionInfo.pluginName)return;let o=this.listeners[n.method];if(o)for(let e of o)e(s)},this.wsStore=e.wsStore||u.defaultWSStore,this.listeners=Object.create(null)}}(0,s._)(u,"defaultWSStore",new class{constructor(e=null,t=0){(0,s._)(this,"ws",void 0),(0,s._)(this,"refCount",void 0),this.ws=e,this.refCount=t}});class d extends u{async initAsync(){await super.initAsync(),this.addHandshakeHandler()}addHandshakeHandler(){this.addHandskakeMessageListener(e=>{if("handshake"===e.method){let{pluginName:t,protocolVersion:n}=e;if(n!==this.connectionInfo.protocolVersion){console.warn(`Received an incompatible devtools plugin handshake message - pluginName[${t}]`),this.terminateBrowserClient(t,e.browserClientId);return}let s=this.browserClientMap[t];null!=s&&s!==e.browserClientId&&(c(`Terminate the previous browser client connection - previousBrowserClientId[${s}]`),this.terminateBrowserClient(t,s)),this.browserClientMap[t]=e.browserClientId}})}terminateBrowserClient(e,t){this.sendHandshakeMessage({protocolVersion:this.connectionInfo.protocolVersion,method:"terminateBrowserClient",browserClientId:t,pluginName:e})}constructor(...e){super(...e),(0,s._)(this,"browserClientMap",{})}}class h extends u{async initAsync(){await super.initAsync(),this.startHandshake()}startHandshake(){this.addHandskakeMessageListener(e=>{"terminateBrowserClient"===e.method&&this.browserClientId===e.browserClientId&&(c("Received terminateBrowserClient messages and terminate the current connection"),this.closeAsync())}),this.sendHandshakeMessage({protocolVersion:this.connectionInfo.protocolVersion,pluginName:this.connectionInfo.pluginName,method:"handshake",browserClientId:this.browserClientId})}constructor(...e){super(...e),(0,s._)(this,"browserClientId",Date.now().toString())}}let f={};async function v(e,t){let n;return n="app"===e.sender?new d(e,t):new h(e,t),await n.initAsync(),n}async function p(e,t){let n=function(){let e=new URLSearchParams(window.location.search).get("devServer"),t=window.location.origin.replace(/^https?:\/\//,"");return{protocolVersion:1,sender:"browser",devServer:e||t}}(),s=f[e];if(null!=s){if(s instanceof Promise)return s;(!1===s.isConnected()||s.connectionInfo.devServer!==n.devServer)&&(await s.closeAsync(),delete f[e],s=null)}if(null==s){let r=v({...n,pluginName:e},t);f[e]=r,s=await r,f[e]=s}return s}},331:function(e,t,n){n.d(t,{_:()=>s});function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},393:function(e,t,n){n.d(t,{W:()=>s});function s(){for(var e,t,n=0,s="",r=arguments.length;n<r;n++)(e=arguments[n])&&(t=function e(t){var n,s,r="";if("string"==typeof t||"number"==typeof t)r+=t;else if("object"==typeof t)if(Array.isArray(t)){var i=t.length;for(n=0;n<i;n++)t[n]&&(s=e(t[n]))&&(r&&(r+=" "),r+=s)}else for(s in t)t[s]&&(r&&(r+=" "),r+=s);return r}(e))&&(s&&(s+=" "),s+=t);return s}},565:function(e,t,n){n.d(t,{Z:()=>s});let s=n(399)}}]);